]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.3.8-201206042136.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.3.8-201206042136.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 0c083c5..bf13011 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,9 +51,11 @@
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 @@ -69,6 +74,7 @@ Image
38 Module.markers
39 Module.symvers
40 PENDING
41 +PERF*
42 SCCS
43 System.map*
44 TAGS
45 @@ -92,19 +98,24 @@ bounds.h
46 bsetup
47 btfixupprep
48 build
49 +builtin-policy.h
50 bvmlinux
51 bzImage*
52 capability_names.h
53 capflags.c
54 classlist.h*
55 +clut_vga16.c
56 +common-cmds.h
57 comp*.log
58 compile.h*
59 conf
60 config
61 config-*
62 config_data.h*
63 +config.c
64 config.mak
65 config.mak.autogen
66 +config.tmp
67 conmakehash
68 consolemap_deftbl.c*
69 cpustr.h
70 @@ -115,9 +126,11 @@ devlist.h*
71 dnotify_test
72 docproc
73 dslm
74 +dtc-lexer.lex.c
75 elf2ecoff
76 elfconfig.h*
77 evergreen_reg_safe.h
78 +exception_policy.conf
79 fixdep
80 flask.h
81 fore200e_mkfirm
82 @@ -125,12 +138,15 @@ fore200e_pca_fw.c*
83 gconf
84 gconf.glade.h
85 gen-devlist
86 +gen-kdb_cmds.c
87 gen_crc32table
88 gen_init_cpio
89 generated
90 genheaders
91 genksyms
92 *_gray256.c
93 +hash
94 +hid-example
95 hpet_example
96 hugepage-mmap
97 hugepage-shm
98 @@ -145,7 +161,7 @@ int32.c
99 int4.c
100 int8.c
101 kallsyms
102 -kconfig
103 +kern_constants.h
104 keywords.c
105 ksym.c*
106 ksym.h*
107 @@ -153,7 +169,7 @@ kxgettext
108 lkc_defs.h
109 lex.c
110 lex.*.c
111 -linux
112 +lib1funcs.S
113 logo_*.c
114 logo_*_clut224.c
115 logo_*_mono.c
116 @@ -165,14 +181,15 @@ machtypes.h
117 map
118 map_hugetlb
119 maui_boot.h
120 -media
121 mconf
122 +mdp
123 miboot*
124 mk_elfconfig
125 mkboot
126 mkbugboot
127 mkcpustr
128 mkdep
129 +mkpiggy
130 mkprep
131 mkregtable
132 mktables
133 @@ -208,6 +225,7 @@ r300_reg_safe.h
134 r420_reg_safe.h
135 r600_reg_safe.h
136 recordmcount
137 +regdb.c
138 relocs
139 rlim_names.h
140 rn50_reg_safe.h
141 @@ -218,6 +236,7 @@ setup
142 setup.bin
143 setup.elf
144 sImage
145 +slabinfo
146 sm_tbl*
147 split-include
148 syscalltab.h
149 @@ -228,6 +247,7 @@ tftpboot.img
150 timeconst.h
151 times.h*
152 trix_boot.h
153 +user_constants.h
154 utsrelease.h*
155 vdso-syms.lds
156 vdso.lds
157 @@ -245,7 +265,9 @@ vmlinux
158 vmlinux-*
159 vmlinux.aout
160 vmlinux.bin.all
161 +vmlinux.bin.bz2
162 vmlinux.lds
163 +vmlinux.relocs
164 vmlinuz
165 voffset.h
166 vsyscall.lds
167 @@ -253,9 +275,11 @@ vsyscall_32.lds
168 wanxlfw.inc
169 uImage
170 unifdef
171 +utsrelease.h
172 wakeup.bin
173 wakeup.elf
174 wakeup.lds
175 zImage*
176 zconf.hash.c
177 +zconf.lex.c
178 zoffset.h
179 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
180 index d99fd9c..8689fef 100644
181 --- a/Documentation/kernel-parameters.txt
182 +++ b/Documentation/kernel-parameters.txt
183 @@ -1977,6 +1977,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
184 the specified number of seconds. This is to be used if
185 your oopses keep scrolling off the screen.
186
187 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
188 + virtualization environments that don't cope well with the
189 + expand down segment used by UDEREF on X86-32 or the frequent
190 + page table updates on X86-64.
191 +
192 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
193 +
194 pcbit= [HW,ISDN]
195
196 pcd. [PARIDE]
197 diff --git a/Makefile b/Makefile
198 index db96149..f101728 100644
199 --- a/Makefile
200 +++ b/Makefile
201 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
202
203 HOSTCC = gcc
204 HOSTCXX = g++
205 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
206 -HOSTCXXFLAGS = -O2
207 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
208 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
209 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
210
211 # Decide whether to build built-in, modular, or both.
212 # Normally, just do built-in.
213 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
214 # Rules shared between *config targets and build targets
215
216 # Basic helpers built in scripts/
217 -PHONY += scripts_basic
218 -scripts_basic:
219 +PHONY += scripts_basic gcc-plugins
220 +scripts_basic: gcc-plugins
221 $(Q)$(MAKE) $(build)=scripts/basic
222 $(Q)rm -f .tmp_quiet_recordmcount
223
224 @@ -564,6 +565,55 @@ else
225 KBUILD_CFLAGS += -O2
226 endif
227
228 +ifndef DISABLE_PAX_PLUGINS
229 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
230 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
231 +ifndef CONFIG_UML
232 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
233 +endif
234 +endif
235 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
236 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
237 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
238 +endif
239 +ifdef CONFIG_KALLOCSTAT_PLUGIN
240 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
241 +endif
242 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
243 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
244 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
245 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
246 +endif
247 +ifdef CONFIG_CHECKER_PLUGIN
248 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
249 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
250 +endif
251 +endif
252 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
253 +ifdef CONFIG_PAX_SIZE_OVERFLOW
254 +SIZE_OVERFLOW_PLUGIN := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
255 +endif
256 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
257 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS) $(SIZE_OVERFLOW_PLUGIN)
258 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
259 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN SIZE_OVERFLOW_PLUGIN
260 +ifeq ($(KBUILD_EXTMOD),)
261 +gcc-plugins:
262 + $(Q)$(MAKE) $(build)=tools/gcc
263 +else
264 +gcc-plugins: ;
265 +endif
266 +else
267 +gcc-plugins:
268 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
269 + $(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.))
270 +else
271 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
272 +endif
273 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
274 +endif
275 +endif
276 +
277 include $(srctree)/arch/$(SRCARCH)/Makefile
278
279 ifneq ($(CONFIG_FRAME_WARN),0)
280 @@ -708,7 +758,7 @@ export mod_strip_cmd
281
282
283 ifeq ($(KBUILD_EXTMOD),)
284 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
285 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
286
287 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
288 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
289 @@ -932,6 +982,8 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
290
291 # The actual objects are generated when descending,
292 # make sure no implicit rule kicks in
293 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
294 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
295 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
296
297 # Handle descending into subdirectories listed in $(vmlinux-dirs)
298 @@ -941,7 +993,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
299 # Error messages still appears in the original language
300
301 PHONY += $(vmlinux-dirs)
302 -$(vmlinux-dirs): prepare scripts
303 +$(vmlinux-dirs): gcc-plugins prepare scripts
304 $(Q)$(MAKE) $(build)=$@
305
306 # Store (new) KERNELRELASE string in include/config/kernel.release
307 @@ -985,6 +1037,7 @@ prepare0: archprepare FORCE
308 $(Q)$(MAKE) $(build)=.
309
310 # All the preparing..
311 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
312 prepare: prepare0
313
314 # Generate some files
315 @@ -1092,6 +1145,8 @@ all: modules
316 # using awk while concatenating to the final file.
317
318 PHONY += modules
319 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
320 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
321 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
322 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
323 @$(kecho) ' Building modules, stage 2.';
324 @@ -1107,7 +1162,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
325
326 # Target to prepare building external modules
327 PHONY += modules_prepare
328 -modules_prepare: prepare scripts
329 +modules_prepare: gcc-plugins prepare scripts
330
331 # Target to install modules
332 PHONY += modules_install
333 @@ -1204,6 +1259,7 @@ distclean: mrproper
334 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
335 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
336 -o -name '.*.rej' \
337 + -o -name '.*.rej' -o -name '*.so' \
338 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
339 -type f -print | xargs rm -f
340
341 @@ -1364,6 +1420,8 @@ PHONY += $(module-dirs) modules
342 $(module-dirs): crmodverdir $(objtree)/Module.symvers
343 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
344
345 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
346 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
347 modules: $(module-dirs)
348 @$(kecho) ' Building modules, stage 2.';
349 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
350 @@ -1490,17 +1548,21 @@ else
351 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
352 endif
353
354 -%.s: %.c prepare scripts FORCE
355 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
356 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
357 +%.s: %.c gcc-plugins prepare scripts FORCE
358 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
359 %.i: %.c prepare scripts FORCE
360 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
361 -%.o: %.c prepare scripts FORCE
362 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
363 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
364 +%.o: %.c gcc-plugins prepare scripts FORCE
365 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
366 %.lst: %.c prepare scripts FORCE
367 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
368 -%.s: %.S prepare scripts FORCE
369 +%.s: %.S gcc-plugins prepare scripts FORCE
370 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
371 -%.o: %.S prepare scripts FORCE
372 +%.o: %.S gcc-plugins prepare scripts FORCE
373 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
374 %.symtypes: %.c prepare scripts FORCE
375 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
376 @@ -1510,11 +1572,15 @@ endif
377 $(cmd_crmodverdir)
378 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
379 $(build)=$(build-dir)
380 -%/: prepare scripts FORCE
381 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
382 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
383 +%/: gcc-plugins prepare scripts FORCE
384 $(cmd_crmodverdir)
385 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
386 $(build)=$(build-dir)
387 -%.ko: prepare scripts FORCE
388 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
389 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
390 +%.ko: gcc-plugins prepare scripts FORCE
391 $(cmd_crmodverdir)
392 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
393 $(build)=$(build-dir) $(@:.ko=.o)
394 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
395 index 640f909..48b6597 100644
396 --- a/arch/alpha/include/asm/atomic.h
397 +++ b/arch/alpha/include/asm/atomic.h
398 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
399 #define atomic_dec(v) atomic_sub(1,(v))
400 #define atomic64_dec(v) atomic64_sub(1,(v))
401
402 +#define atomic64_read_unchecked(v) atomic64_read(v)
403 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
404 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
405 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
406 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
407 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
408 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
409 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
410 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
411 +
412 #define smp_mb__before_atomic_dec() smp_mb()
413 #define smp_mb__after_atomic_dec() smp_mb()
414 #define smp_mb__before_atomic_inc() smp_mb()
415 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
416 index ad368a9..fbe0f25 100644
417 --- a/arch/alpha/include/asm/cache.h
418 +++ b/arch/alpha/include/asm/cache.h
419 @@ -4,19 +4,19 @@
420 #ifndef __ARCH_ALPHA_CACHE_H
421 #define __ARCH_ALPHA_CACHE_H
422
423 +#include <linux/const.h>
424
425 /* Bytes per L1 (data) cache line. */
426 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
427 -# define L1_CACHE_BYTES 64
428 # define L1_CACHE_SHIFT 6
429 #else
430 /* Both EV4 and EV5 are write-through, read-allocate,
431 direct-mapped, physical.
432 */
433 -# define L1_CACHE_BYTES 32
434 # define L1_CACHE_SHIFT 5
435 #endif
436
437 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
438 #define SMP_CACHE_BYTES L1_CACHE_BYTES
439
440 #endif
441 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
442 index da5449e..7418343 100644
443 --- a/arch/alpha/include/asm/elf.h
444 +++ b/arch/alpha/include/asm/elf.h
445 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
446
447 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
448
449 +#ifdef CONFIG_PAX_ASLR
450 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
451 +
452 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
453 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
454 +#endif
455 +
456 /* $0 is set by ld.so to a pointer to a function which might be
457 registered using atexit. This provides a mean for the dynamic
458 linker to call DT_FINI functions for shared libraries that have
459 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
460 index bc2a0da..8ad11ee 100644
461 --- a/arch/alpha/include/asm/pgalloc.h
462 +++ b/arch/alpha/include/asm/pgalloc.h
463 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
464 pgd_set(pgd, pmd);
465 }
466
467 +static inline void
468 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
469 +{
470 + pgd_populate(mm, pgd, pmd);
471 +}
472 +
473 extern pgd_t *pgd_alloc(struct mm_struct *mm);
474
475 static inline void
476 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
477 index de98a73..bd4f1f8 100644
478 --- a/arch/alpha/include/asm/pgtable.h
479 +++ b/arch/alpha/include/asm/pgtable.h
480 @@ -101,6 +101,17 @@ struct vm_area_struct;
481 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
482 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
483 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
484 +
485 +#ifdef CONFIG_PAX_PAGEEXEC
486 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
487 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
488 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
489 +#else
490 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
491 +# define PAGE_COPY_NOEXEC PAGE_COPY
492 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
493 +#endif
494 +
495 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
496
497 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
498 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
499 index 2fd00b7..cfd5069 100644
500 --- a/arch/alpha/kernel/module.c
501 +++ b/arch/alpha/kernel/module.c
502 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
503
504 /* The small sections were sorted to the end of the segment.
505 The following should definitely cover them. */
506 - gp = (u64)me->module_core + me->core_size - 0x8000;
507 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
508 got = sechdrs[me->arch.gotsecindex].sh_addr;
509
510 for (i = 0; i < n; i++) {
511 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
512 index 01e8715..be0e80f 100644
513 --- a/arch/alpha/kernel/osf_sys.c
514 +++ b/arch/alpha/kernel/osf_sys.c
515 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
516 /* At this point: (!vma || addr < vma->vm_end). */
517 if (limit - len < addr)
518 return -ENOMEM;
519 - if (!vma || addr + len <= vma->vm_start)
520 + if (check_heap_stack_gap(vma, addr, len))
521 return addr;
522 addr = vma->vm_end;
523 vma = vma->vm_next;
524 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
525 merely specific addresses, but regions of memory -- perhaps
526 this feature should be incorporated into all ports? */
527
528 +#ifdef CONFIG_PAX_RANDMMAP
529 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
530 +#endif
531 +
532 if (addr) {
533 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
534 if (addr != (unsigned long) -ENOMEM)
535 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
536 }
537
538 /* Next, try allocating at TASK_UNMAPPED_BASE. */
539 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
540 - len, limit);
541 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
542 +
543 if (addr != (unsigned long) -ENOMEM)
544 return addr;
545
546 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
547 index fadd5f8..904e73a 100644
548 --- a/arch/alpha/mm/fault.c
549 +++ b/arch/alpha/mm/fault.c
550 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
551 __reload_thread(pcb);
552 }
553
554 +#ifdef CONFIG_PAX_PAGEEXEC
555 +/*
556 + * PaX: decide what to do with offenders (regs->pc = fault address)
557 + *
558 + * returns 1 when task should be killed
559 + * 2 when patched PLT trampoline was detected
560 + * 3 when unpatched PLT trampoline was detected
561 + */
562 +static int pax_handle_fetch_fault(struct pt_regs *regs)
563 +{
564 +
565 +#ifdef CONFIG_PAX_EMUPLT
566 + int err;
567 +
568 + do { /* PaX: patched PLT emulation #1 */
569 + unsigned int ldah, ldq, jmp;
570 +
571 + err = get_user(ldah, (unsigned int *)regs->pc);
572 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
573 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
574 +
575 + if (err)
576 + break;
577 +
578 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
579 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
580 + jmp == 0x6BFB0000U)
581 + {
582 + unsigned long r27, addr;
583 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
584 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
585 +
586 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
587 + err = get_user(r27, (unsigned long *)addr);
588 + if (err)
589 + break;
590 +
591 + regs->r27 = r27;
592 + regs->pc = r27;
593 + return 2;
594 + }
595 + } while (0);
596 +
597 + do { /* PaX: patched PLT emulation #2 */
598 + unsigned int ldah, lda, br;
599 +
600 + err = get_user(ldah, (unsigned int *)regs->pc);
601 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
602 + err |= get_user(br, (unsigned int *)(regs->pc+8));
603 +
604 + if (err)
605 + break;
606 +
607 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
608 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
609 + (br & 0xFFE00000U) == 0xC3E00000U)
610 + {
611 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
612 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
613 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
614 +
615 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
616 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
617 + return 2;
618 + }
619 + } while (0);
620 +
621 + do { /* PaX: unpatched PLT emulation */
622 + unsigned int br;
623 +
624 + err = get_user(br, (unsigned int *)regs->pc);
625 +
626 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
627 + unsigned int br2, ldq, nop, jmp;
628 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
629 +
630 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
631 + err = get_user(br2, (unsigned int *)addr);
632 + err |= get_user(ldq, (unsigned int *)(addr+4));
633 + err |= get_user(nop, (unsigned int *)(addr+8));
634 + err |= get_user(jmp, (unsigned int *)(addr+12));
635 + err |= get_user(resolver, (unsigned long *)(addr+16));
636 +
637 + if (err)
638 + break;
639 +
640 + if (br2 == 0xC3600000U &&
641 + ldq == 0xA77B000CU &&
642 + nop == 0x47FF041FU &&
643 + jmp == 0x6B7B0000U)
644 + {
645 + regs->r28 = regs->pc+4;
646 + regs->r27 = addr+16;
647 + regs->pc = resolver;
648 + return 3;
649 + }
650 + }
651 + } while (0);
652 +#endif
653 +
654 + return 1;
655 +}
656 +
657 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
658 +{
659 + unsigned long i;
660 +
661 + printk(KERN_ERR "PAX: bytes at PC: ");
662 + for (i = 0; i < 5; i++) {
663 + unsigned int c;
664 + if (get_user(c, (unsigned int *)pc+i))
665 + printk(KERN_CONT "???????? ");
666 + else
667 + printk(KERN_CONT "%08x ", c);
668 + }
669 + printk("\n");
670 +}
671 +#endif
672
673 /*
674 * This routine handles page faults. It determines the address,
675 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
676 good_area:
677 si_code = SEGV_ACCERR;
678 if (cause < 0) {
679 - if (!(vma->vm_flags & VM_EXEC))
680 + if (!(vma->vm_flags & VM_EXEC)) {
681 +
682 +#ifdef CONFIG_PAX_PAGEEXEC
683 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
684 + goto bad_area;
685 +
686 + up_read(&mm->mmap_sem);
687 + switch (pax_handle_fetch_fault(regs)) {
688 +
689 +#ifdef CONFIG_PAX_EMUPLT
690 + case 2:
691 + case 3:
692 + return;
693 +#endif
694 +
695 + }
696 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
697 + do_group_exit(SIGKILL);
698 +#else
699 goto bad_area;
700 +#endif
701 +
702 + }
703 } else if (!cause) {
704 /* Allow reads even for write-only mappings */
705 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
706 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
707 index 86976d0..c63ea6b 100644
708 --- a/arch/arm/include/asm/atomic.h
709 +++ b/arch/arm/include/asm/atomic.h
710 @@ -15,6 +15,10 @@
711 #include <linux/types.h>
712 #include <asm/system.h>
713
714 +#ifdef CONFIG_GENERIC_ATOMIC64
715 +#include <asm-generic/atomic64.h>
716 +#endif
717 +
718 #define ATOMIC_INIT(i) { (i) }
719
720 #ifdef __KERNEL__
721 @@ -25,7 +29,15 @@
722 * atomic_set() is the clrex or dummy strex done on every exception return.
723 */
724 #define atomic_read(v) (*(volatile int *)&(v)->counter)
725 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
726 +{
727 + return v->counter;
728 +}
729 #define atomic_set(v,i) (((v)->counter) = (i))
730 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
731 +{
732 + v->counter = i;
733 +}
734
735 #if __LINUX_ARM_ARCH__ >= 6
736
737 @@ -40,6 +52,35 @@ static inline void atomic_add(int i, atomic_t *v)
738 int result;
739
740 __asm__ __volatile__("@ atomic_add\n"
741 +"1: ldrex %1, [%3]\n"
742 +" adds %0, %1, %4\n"
743 +
744 +#ifdef CONFIG_PAX_REFCOUNT
745 +" bvc 3f\n"
746 +"2: bkpt 0xf103\n"
747 +"3:\n"
748 +#endif
749 +
750 +" strex %1, %0, [%3]\n"
751 +" teq %1, #0\n"
752 +" bne 1b"
753 +
754 +#ifdef CONFIG_PAX_REFCOUNT
755 +"\n4:\n"
756 + _ASM_EXTABLE(2b, 4b)
757 +#endif
758 +
759 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
760 + : "r" (&v->counter), "Ir" (i)
761 + : "cc");
762 +}
763 +
764 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
765 +{
766 + unsigned long tmp;
767 + int result;
768 +
769 + __asm__ __volatile__("@ atomic_add_unchecked\n"
770 "1: ldrex %0, [%3]\n"
771 " add %0, %0, %4\n"
772 " strex %1, %0, [%3]\n"
773 @@ -58,6 +99,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
774 smp_mb();
775
776 __asm__ __volatile__("@ atomic_add_return\n"
777 +"1: ldrex %1, [%3]\n"
778 +" adds %0, %1, %4\n"
779 +
780 +#ifdef CONFIG_PAX_REFCOUNT
781 +" bvc 3f\n"
782 +" mov %0, %1\n"
783 +"2: bkpt 0xf103\n"
784 +"3:\n"
785 +#endif
786 +
787 +" strex %1, %0, [%3]\n"
788 +" teq %1, #0\n"
789 +" bne 1b"
790 +
791 +#ifdef CONFIG_PAX_REFCOUNT
792 +"\n4:\n"
793 + _ASM_EXTABLE(2b, 4b)
794 +#endif
795 +
796 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
797 + : "r" (&v->counter), "Ir" (i)
798 + : "cc");
799 +
800 + smp_mb();
801 +
802 + return result;
803 +}
804 +
805 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
806 +{
807 + unsigned long tmp;
808 + int result;
809 +
810 + smp_mb();
811 +
812 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
813 "1: ldrex %0, [%3]\n"
814 " add %0, %0, %4\n"
815 " strex %1, %0, [%3]\n"
816 @@ -78,6 +155,35 @@ static inline void atomic_sub(int i, atomic_t *v)
817 int result;
818
819 __asm__ __volatile__("@ atomic_sub\n"
820 +"1: ldrex %1, [%3]\n"
821 +" subs %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_sub_unchecked(int i, atomic_unchecked_t *v)
844 +{
845 + unsigned long tmp;
846 + int result;
847 +
848 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
849 "1: ldrex %0, [%3]\n"
850 " sub %0, %0, %4\n"
851 " strex %1, %0, [%3]\n"
852 @@ -96,11 +202,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
853 smp_mb();
854
855 __asm__ __volatile__("@ atomic_sub_return\n"
856 -"1: ldrex %0, [%3]\n"
857 -" sub %0, %0, %4\n"
858 +"1: ldrex %1, [%3]\n"
859 +" sub %0, %1, %4\n"
860 +
861 +#ifdef CONFIG_PAX_REFCOUNT
862 +" bvc 3f\n"
863 +" mov %0, %1\n"
864 +"2: bkpt 0xf103\n"
865 +"3:\n"
866 +#endif
867 +
868 " strex %1, %0, [%3]\n"
869 " teq %1, #0\n"
870 " bne 1b"
871 +
872 +#ifdef CONFIG_PAX_REFCOUNT
873 +"\n4:\n"
874 + _ASM_EXTABLE(2b, 4b)
875 +#endif
876 +
877 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
878 : "r" (&v->counter), "Ir" (i)
879 : "cc");
880 @@ -132,6 +252,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
881 return oldval;
882 }
883
884 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
885 +{
886 + unsigned long oldval, res;
887 +
888 + smp_mb();
889 +
890 + do {
891 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
892 + "ldrex %1, [%3]\n"
893 + "mov %0, #0\n"
894 + "teq %1, %4\n"
895 + "strexeq %0, %5, [%3]\n"
896 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
897 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
898 + : "cc");
899 + } while (res);
900 +
901 + smp_mb();
902 +
903 + return oldval;
904 +}
905 +
906 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
907 {
908 unsigned long tmp, tmp2;
909 @@ -165,7 +307,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
910
911 return val;
912 }
913 +#define atomic_add_return_unchecked(i, v) atomic_add_return(i, v)
914 #define atomic_add(i, v) (void) atomic_add_return(i, v)
915 +#define atomic_add_unchecked(i, v) (void) atomic_add_return_unchecked(i, v)
916
917 static inline int atomic_sub_return(int i, atomic_t *v)
918 {
919 @@ -179,7 +323,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
920
921 return val;
922 }
923 +#define atomic_sub_return_unchecked(i, v) atomic_sub_return(i, v)
924 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
925 +#define atomic_sub_unchecked(i, v) (void) atomic_sub_return_unchecked(i, v)
926
927 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
928 {
929 @@ -194,6 +340,7 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
930
931 return ret;
932 }
933 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg(v, o, n)
934
935 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
936 {
937 @@ -207,6 +354,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
938 #endif /* __LINUX_ARM_ARCH__ */
939
940 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
941 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
942 +{
943 + return xchg(&v->counter, new);
944 +}
945
946 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
947 {
948 @@ -219,11 +370,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
949 }
950
951 #define atomic_inc(v) atomic_add(1, v)
952 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
953 +{
954 + atomic_add_unchecked(1, v);
955 +}
956 #define atomic_dec(v) atomic_sub(1, v)
957 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
958 +{
959 + atomic_sub_unchecked(1, v);
960 +}
961
962 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
963 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
964 +{
965 + return atomic_add_return_unchecked(1, v) == 0;
966 +}
967 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
968 #define atomic_inc_return(v) (atomic_add_return(1, v))
969 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
970 +{
971 + return atomic_add_return_unchecked(1, v);
972 +}
973 #define atomic_dec_return(v) (atomic_sub_return(1, v))
974 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
975
976 @@ -239,6 +406,14 @@ typedef struct {
977 u64 __aligned(8) counter;
978 } atomic64_t;
979
980 +#ifdef CONFIG_PAX_REFCOUNT
981 +typedef struct {
982 + u64 __aligned(8) counter;
983 +} atomic64_unchecked_t;
984 +#else
985 +typedef atomic64_t atomic64_unchecked_t;
986 +#endif
987 +
988 #define ATOMIC64_INIT(i) { (i) }
989
990 static inline u64 atomic64_read(atomic64_t *v)
991 @@ -254,6 +429,19 @@ static inline u64 atomic64_read(atomic64_t *v)
992 return result;
993 }
994
995 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
996 +{
997 + u64 result;
998 +
999 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1000 +" ldrexd %0, %H0, [%1]"
1001 + : "=&r" (result)
1002 + : "r" (&v->counter), "Qo" (v->counter)
1003 + );
1004 +
1005 + return result;
1006 +}
1007 +
1008 static inline void atomic64_set(atomic64_t *v, u64 i)
1009 {
1010 u64 tmp;
1011 @@ -268,6 +456,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1012 : "cc");
1013 }
1014
1015 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1016 +{
1017 + u64 tmp;
1018 +
1019 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1020 +"1: ldrexd %0, %H0, [%2]\n"
1021 +" strexd %0, %3, %H3, [%2]\n"
1022 +" teq %0, #0\n"
1023 +" bne 1b"
1024 + : "=&r" (tmp), "=Qo" (v->counter)
1025 + : "r" (&v->counter), "r" (i)
1026 + : "cc");
1027 +}
1028 +
1029 static inline void atomic64_add(u64 i, atomic64_t *v)
1030 {
1031 u64 result;
1032 @@ -276,6 +478,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1033 __asm__ __volatile__("@ atomic64_add\n"
1034 "1: ldrexd %0, %H0, [%3]\n"
1035 " adds %0, %0, %4\n"
1036 +" adcs %H0, %H0, %H4\n"
1037 +
1038 +#ifdef CONFIG_PAX_REFCOUNT
1039 +" bvc 3f\n"
1040 +"2: bkpt 0xf103\n"
1041 +"3:\n"
1042 +#endif
1043 +
1044 +" strexd %1, %0, %H0, [%3]\n"
1045 +" teq %1, #0\n"
1046 +" bne 1b"
1047 +
1048 +#ifdef CONFIG_PAX_REFCOUNT
1049 +"\n4:\n"
1050 + _ASM_EXTABLE(2b, 4b)
1051 +#endif
1052 +
1053 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1054 + : "r" (&v->counter), "r" (i)
1055 + : "cc");
1056 +}
1057 +
1058 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1059 +{
1060 + u64 result;
1061 + unsigned long tmp;
1062 +
1063 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1064 +"1: ldrexd %0, %H0, [%3]\n"
1065 +" adds %0, %0, %4\n"
1066 " adc %H0, %H0, %H4\n"
1067 " strexd %1, %0, %H0, [%3]\n"
1068 " teq %1, #0\n"
1069 @@ -287,12 +519,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1070
1071 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1072 {
1073 - u64 result;
1074 - unsigned long tmp;
1075 + u64 result, tmp;
1076
1077 smp_mb();
1078
1079 __asm__ __volatile__("@ atomic64_add_return\n"
1080 +"1: ldrexd %1, %H1, [%3]\n"
1081 +" adds %0, %1, %4\n"
1082 +" adcs %H0, %H1, %H4\n"
1083 +
1084 +#ifdef CONFIG_PAX_REFCOUNT
1085 +" bvc 3f\n"
1086 +" mov %0, %1\n"
1087 +" mov %H0, %H1\n"
1088 +"2: bkpt 0xf103\n"
1089 +"3:\n"
1090 +#endif
1091 +
1092 +" strexd %1, %0, %H0, [%3]\n"
1093 +" teq %1, #0\n"
1094 +" bne 1b"
1095 +
1096 +#ifdef CONFIG_PAX_REFCOUNT
1097 +"\n4:\n"
1098 + _ASM_EXTABLE(2b, 4b)
1099 +#endif
1100 +
1101 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1102 + : "r" (&v->counter), "r" (i)
1103 + : "cc");
1104 +
1105 + smp_mb();
1106 +
1107 + return result;
1108 +}
1109 +
1110 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1111 +{
1112 + u64 result;
1113 + unsigned long tmp;
1114 +
1115 + smp_mb();
1116 +
1117 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1118 "1: ldrexd %0, %H0, [%3]\n"
1119 " adds %0, %0, %4\n"
1120 " adc %H0, %H0, %H4\n"
1121 @@ -316,6 +585,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1122 __asm__ __volatile__("@ atomic64_sub\n"
1123 "1: ldrexd %0, %H0, [%3]\n"
1124 " subs %0, %0, %4\n"
1125 +" sbcs %H0, %H0, %H4\n"
1126 +
1127 +#ifdef CONFIG_PAX_REFCOUNT
1128 +" bvc 3f\n"
1129 +"2: bkpt 0xf103\n"
1130 +"3:\n"
1131 +#endif
1132 +
1133 +" strexd %1, %0, %H0, [%3]\n"
1134 +" teq %1, #0\n"
1135 +" bne 1b"
1136 +
1137 +#ifdef CONFIG_PAX_REFCOUNT
1138 +"\n4:\n"
1139 + _ASM_EXTABLE(2b, 4b)
1140 +#endif
1141 +
1142 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1143 + : "r" (&v->counter), "r" (i)
1144 + : "cc");
1145 +}
1146 +
1147 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1148 +{
1149 + u64 result;
1150 + unsigned long tmp;
1151 +
1152 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1153 +"1: ldrexd %0, %H0, [%3]\n"
1154 +" subs %0, %0, %4\n"
1155 " sbc %H0, %H0, %H4\n"
1156 " strexd %1, %0, %H0, [%3]\n"
1157 " teq %1, #0\n"
1158 @@ -327,18 +626,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1159
1160 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1161 {
1162 - u64 result;
1163 - unsigned long tmp;
1164 + u64 result, tmp;
1165
1166 smp_mb();
1167
1168 __asm__ __volatile__("@ atomic64_sub_return\n"
1169 -"1: ldrexd %0, %H0, [%3]\n"
1170 -" subs %0, %0, %4\n"
1171 -" sbc %H0, %H0, %H4\n"
1172 +"1: ldrexd %1, %H1, [%3]\n"
1173 +" subs %0, %1, %4\n"
1174 +" sbc %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 @@ -372,6 +685,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1197 return oldval;
1198 }
1199
1200 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1201 +{
1202 + u64 oldval;
1203 + unsigned long res;
1204 +
1205 + smp_mb();
1206 +
1207 + do {
1208 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1209 + "ldrexd %1, %H1, [%3]\n"
1210 + "mov %0, #0\n"
1211 + "teq %1, %4\n"
1212 + "teqeq %H1, %H4\n"
1213 + "strexdeq %0, %5, %H5, [%3]"
1214 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1215 + : "r" (&ptr->counter), "r" (old), "r" (new)
1216 + : "cc");
1217 + } while (res);
1218 +
1219 + smp_mb();
1220 +
1221 + return oldval;
1222 +}
1223 +
1224 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1225 {
1226 u64 result;
1227 @@ -395,21 +732,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1228
1229 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1230 {
1231 - u64 result;
1232 - unsigned long tmp;
1233 + u64 result, tmp;
1234
1235 smp_mb();
1236
1237 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1238 -"1: ldrexd %0, %H0, [%3]\n"
1239 -" subs %0, %0, #1\n"
1240 -" sbc %H0, %H0, #0\n"
1241 +"1: ldrexd %1, %H1, [%3]\n"
1242 +" subs %0, %1, #1\n"
1243 +" sbc %H0, %H1, #0\n"
1244 +
1245 +#ifdef CONFIG_PAX_REFCOUNT
1246 +" bvc 3f\n"
1247 +" mov %0, %1\n"
1248 +" mov %H0, %H1\n"
1249 +"2: bkpt 0xf103\n"
1250 +"3:\n"
1251 +#endif
1252 +
1253 " teq %H0, #0\n"
1254 -" bmi 2f\n"
1255 +" bmi 4f\n"
1256 " strexd %1, %0, %H0, [%3]\n"
1257 " teq %1, #0\n"
1258 " bne 1b\n"
1259 -"2:"
1260 +"4:\n"
1261 +
1262 +#ifdef CONFIG_PAX_REFCOUNT
1263 + _ASM_EXTABLE(2b, 4b)
1264 +#endif
1265 +
1266 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1267 : "r" (&v->counter)
1268 : "cc");
1269 @@ -432,13 +782,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1270 " teq %0, %5\n"
1271 " teqeq %H0, %H5\n"
1272 " moveq %1, #0\n"
1273 -" beq 2f\n"
1274 +" beq 4f\n"
1275 " adds %0, %0, %6\n"
1276 " adc %H0, %H0, %H6\n"
1277 +
1278 +#ifdef CONFIG_PAX_REFCOUNT
1279 +" bvc 3f\n"
1280 +"2: bkpt 0xf103\n"
1281 +"3:\n"
1282 +#endif
1283 +
1284 " strexd %2, %0, %H0, [%4]\n"
1285 " teq %2, #0\n"
1286 " bne 1b\n"
1287 -"2:"
1288 +"4:\n"
1289 +
1290 +#ifdef CONFIG_PAX_REFCOUNT
1291 + _ASM_EXTABLE(2b, 4b)
1292 +#endif
1293 +
1294 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1295 : "r" (&v->counter), "r" (u), "r" (a)
1296 : "cc");
1297 @@ -451,10 +813,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1298
1299 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1300 #define atomic64_inc(v) atomic64_add(1LL, (v))
1301 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1302 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1303 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1304 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1305 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1306 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1307 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1308 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1309 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1310 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1311 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1312 index 75fe66b..2255c86 100644
1313 --- a/arch/arm/include/asm/cache.h
1314 +++ b/arch/arm/include/asm/cache.h
1315 @@ -4,8 +4,10 @@
1316 #ifndef __ASMARM_CACHE_H
1317 #define __ASMARM_CACHE_H
1318
1319 +#include <linux/const.h>
1320 +
1321 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1322 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1323 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1324
1325 /*
1326 * Memory returned by kmalloc() may be used for DMA, so we must make
1327 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1328 index 1252a26..9dc17b5 100644
1329 --- a/arch/arm/include/asm/cacheflush.h
1330 +++ b/arch/arm/include/asm/cacheflush.h
1331 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1332 void (*dma_unmap_area)(const void *, size_t, int);
1333
1334 void (*dma_flush_range)(const void *, const void *);
1335 -};
1336 +} __no_const;
1337
1338 /*
1339 * Select the calling method
1340 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1341 index 0e9ce8d..6ef1e03 100644
1342 --- a/arch/arm/include/asm/elf.h
1343 +++ b/arch/arm/include/asm/elf.h
1344 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1345 the loader. We need to make sure that it is out of the way of the program
1346 that it will "exec", and that there is sufficient room for the brk. */
1347
1348 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1349 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1350 +
1351 +#ifdef CONFIG_PAX_ASLR
1352 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1353 +
1354 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1355 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1356 +#endif
1357
1358 /* When the program starts, a1 contains a pointer to a function to be
1359 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1360 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1361 extern void elf_set_personality(const struct elf32_hdr *);
1362 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1363
1364 -struct mm_struct;
1365 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1366 -#define arch_randomize_brk arch_randomize_brk
1367 -
1368 extern int vectors_user_mapping(void);
1369 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
1370 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
1371 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1372 index e51b1e8..32a3113 100644
1373 --- a/arch/arm/include/asm/kmap_types.h
1374 +++ b/arch/arm/include/asm/kmap_types.h
1375 @@ -21,6 +21,7 @@ enum km_type {
1376 KM_L1_CACHE,
1377 KM_L2_CACHE,
1378 KM_KDB,
1379 + KM_CLEARPAGE,
1380 KM_TYPE_NR
1381 };
1382
1383 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1384 index 53426c6..c7baff3 100644
1385 --- a/arch/arm/include/asm/outercache.h
1386 +++ b/arch/arm/include/asm/outercache.h
1387 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1388 #endif
1389 void (*set_debug)(unsigned long);
1390 void (*resume)(void);
1391 -};
1392 +} __no_const;
1393
1394 #ifdef CONFIG_OUTER_CACHE
1395
1396 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1397 index 97b440c..b7ff179 100644
1398 --- a/arch/arm/include/asm/page.h
1399 +++ b/arch/arm/include/asm/page.h
1400 @@ -123,7 +123,7 @@ struct cpu_user_fns {
1401 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1402 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1403 unsigned long vaddr, struct vm_area_struct *vma);
1404 -};
1405 +} __no_const;
1406
1407 #ifdef MULTI_USER
1408 extern struct cpu_user_fns cpu_user;
1409 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1410 index 943504f..bf8d667 100644
1411 --- a/arch/arm/include/asm/pgalloc.h
1412 +++ b/arch/arm/include/asm/pgalloc.h
1413 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1414 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1415 }
1416
1417 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1418 +{
1419 + pud_populate(mm, pud, pmd);
1420 +}
1421 +
1422 #else /* !CONFIG_ARM_LPAE */
1423
1424 /*
1425 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1426 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1427 #define pmd_free(mm, pmd) do { } while (0)
1428 #define pud_populate(mm,pmd,pte) BUG()
1429 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1430
1431 #endif /* CONFIG_ARM_LPAE */
1432
1433 diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h
1434 index e4c96cc..1145653 100644
1435 --- a/arch/arm/include/asm/system.h
1436 +++ b/arch/arm/include/asm/system.h
1437 @@ -98,6 +98,8 @@ void hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int,
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 extern asmlinkage void c_backtrace(unsigned long fp, int pmode);
1445
1446 @@ -534,6 +536,13 @@ static inline unsigned long long __cmpxchg64_mb(volatile void *ptr,
1447
1448 #endif /* __LINUX_ARM_ARCH__ >= 6 */
1449
1450 +#define _ASM_EXTABLE(from, to) \
1451 +" .pushsection __ex_table,\"a\"\n"\
1452 +" .align 3\n" \
1453 +" .long " #from ", " #to"\n" \
1454 +" .popsection"
1455 +
1456 +
1457 #endif /* __ASSEMBLY__ */
1458
1459 #define arch_align_stack(x) (x)
1460 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1461 index d4c24d4..4ac53e8 100644
1462 --- a/arch/arm/include/asm/thread_info.h
1463 +++ b/arch/arm/include/asm/thread_info.h
1464 @@ -141,6 +141,12 @@ extern void vfp_flush_hwstate(struct thread_info *);
1465 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1466 #define TIF_SYSCALL_TRACE 8
1467 #define TIF_SYSCALL_AUDIT 9
1468 +
1469 +/* within 8 bits of TIF_SYSCALL_TRACE
1470 + to meet flexible second operand requirements
1471 +*/
1472 +#define TIF_GRSEC_SETXID 10
1473 +
1474 #define TIF_POLLING_NRFLAG 16
1475 #define TIF_USING_IWMMXT 17
1476 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1477 @@ -156,9 +162,11 @@ extern void vfp_flush_hwstate(struct thread_info *);
1478 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1479 #define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK)
1480 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1481 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1482
1483 /* Checks for any syscall work in entry-common.S */
1484 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1485 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1486 + _TIF_GRSEC_SETXID)
1487
1488 /*
1489 * Change these and you break ASM code in entry-common.S
1490 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1491 index 2958976..12ccac4 100644
1492 --- a/arch/arm/include/asm/uaccess.h
1493 +++ b/arch/arm/include/asm/uaccess.h
1494 @@ -22,6 +22,8 @@
1495 #define VERIFY_READ 0
1496 #define VERIFY_WRITE 1
1497
1498 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1499 +
1500 /*
1501 * The exception table consists of pairs of addresses: the first is the
1502 * address of an instruction that is allowed to fault, and the second is
1503 @@ -387,8 +389,23 @@ do { \
1504
1505
1506 #ifdef CONFIG_MMU
1507 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1508 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1509 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1510 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1511 +
1512 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1513 +{
1514 + if (!__builtin_constant_p(n))
1515 + check_object_size(to, n, false);
1516 + return ___copy_from_user(to, from, n);
1517 +}
1518 +
1519 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1520 +{
1521 + if (!__builtin_constant_p(n))
1522 + check_object_size(from, n, true);
1523 + return ___copy_to_user(to, from, n);
1524 +}
1525 +
1526 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1527 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1528 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1529 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1530
1531 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1532 {
1533 + if ((long)n < 0)
1534 + return n;
1535 +
1536 if (access_ok(VERIFY_READ, from, n))
1537 n = __copy_from_user(to, from, n);
1538 else /* security hole - plug it */
1539 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1540
1541 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1542 {
1543 + if ((long)n < 0)
1544 + return n;
1545 +
1546 if (access_ok(VERIFY_WRITE, to, n))
1547 n = __copy_to_user(to, from, n);
1548 return n;
1549 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1550 index 5b0bce6..becd81c 100644
1551 --- a/arch/arm/kernel/armksyms.c
1552 +++ b/arch/arm/kernel/armksyms.c
1553 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1554 #ifdef CONFIG_MMU
1555 EXPORT_SYMBOL(copy_page);
1556
1557 -EXPORT_SYMBOL(__copy_from_user);
1558 -EXPORT_SYMBOL(__copy_to_user);
1559 +EXPORT_SYMBOL(___copy_from_user);
1560 +EXPORT_SYMBOL(___copy_to_user);
1561 EXPORT_SYMBOL(__clear_user);
1562
1563 EXPORT_SYMBOL(__get_user_1);
1564 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1565 index 971d65c..cc936fb 100644
1566 --- a/arch/arm/kernel/process.c
1567 +++ b/arch/arm/kernel/process.c
1568 @@ -28,7 +28,6 @@
1569 #include <linux/tick.h>
1570 #include <linux/utsname.h>
1571 #include <linux/uaccess.h>
1572 -#include <linux/random.h>
1573 #include <linux/hw_breakpoint.h>
1574 #include <linux/cpuidle.h>
1575
1576 @@ -273,9 +272,10 @@ void machine_power_off(void)
1577 machine_shutdown();
1578 if (pm_power_off)
1579 pm_power_off();
1580 + BUG();
1581 }
1582
1583 -void machine_restart(char *cmd)
1584 +__noreturn void machine_restart(char *cmd)
1585 {
1586 machine_shutdown();
1587
1588 @@ -517,12 +517,6 @@ unsigned long get_wchan(struct task_struct *p)
1589 return 0;
1590 }
1591
1592 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1593 -{
1594 - unsigned long range_end = mm->brk + 0x02000000;
1595 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1596 -}
1597 -
1598 #ifdef CONFIG_MMU
1599 /*
1600 * The vectors page is always readable from user space for the
1601 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1602 index f5ce8ab..4b73893 100644
1603 --- a/arch/arm/kernel/ptrace.c
1604 +++ b/arch/arm/kernel/ptrace.c
1605 @@ -905,10 +905,19 @@ long arch_ptrace(struct task_struct *child, long request,
1606 return ret;
1607 }
1608
1609 +#ifdef CONFIG_GRKERNSEC_SETXID
1610 +extern void gr_delayed_cred_worker(void);
1611 +#endif
1612 +
1613 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1614 {
1615 unsigned long ip;
1616
1617 +#ifdef CONFIG_GRKERNSEC_SETXID
1618 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1619 + gr_delayed_cred_worker();
1620 +#endif
1621 +
1622 if (why)
1623 audit_syscall_exit(regs);
1624 else
1625 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1626 index a255c39..4a19b25 100644
1627 --- a/arch/arm/kernel/setup.c
1628 +++ b/arch/arm/kernel/setup.c
1629 @@ -109,13 +109,13 @@ struct processor processor __read_mostly;
1630 struct cpu_tlb_fns cpu_tlb __read_mostly;
1631 #endif
1632 #ifdef MULTI_USER
1633 -struct cpu_user_fns cpu_user __read_mostly;
1634 +struct cpu_user_fns cpu_user __read_only;
1635 #endif
1636 #ifdef MULTI_CACHE
1637 -struct cpu_cache_fns cpu_cache __read_mostly;
1638 +struct cpu_cache_fns cpu_cache __read_only;
1639 #endif
1640 #ifdef CONFIG_OUTER_CACHE
1641 -struct outer_cache_fns outer_cache __read_mostly;
1642 +struct outer_cache_fns outer_cache __read_only;
1643 EXPORT_SYMBOL(outer_cache);
1644 #endif
1645
1646 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1647 index 504b28a..62f7a7d 100644
1648 --- a/arch/arm/kernel/traps.c
1649 +++ b/arch/arm/kernel/traps.c
1650 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1651
1652 static DEFINE_RAW_SPINLOCK(die_lock);
1653
1654 +extern void gr_handle_kernel_exploit(void);
1655 +
1656 /*
1657 * This function is protected against re-entrancy.
1658 */
1659 @@ -291,6 +293,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1660 panic("Fatal exception in interrupt");
1661 if (panic_on_oops)
1662 panic("Fatal exception");
1663 +
1664 + gr_handle_kernel_exploit();
1665 +
1666 if (ret != NOTIFY_STOP)
1667 do_exit(SIGSEGV);
1668 }
1669 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1670 index 66a477a..bee61d3 100644
1671 --- a/arch/arm/lib/copy_from_user.S
1672 +++ b/arch/arm/lib/copy_from_user.S
1673 @@ -16,7 +16,7 @@
1674 /*
1675 * Prototype:
1676 *
1677 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1678 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1679 *
1680 * Purpose:
1681 *
1682 @@ -84,11 +84,11 @@
1683
1684 .text
1685
1686 -ENTRY(__copy_from_user)
1687 +ENTRY(___copy_from_user)
1688
1689 #include "copy_template.S"
1690
1691 -ENDPROC(__copy_from_user)
1692 +ENDPROC(___copy_from_user)
1693
1694 .pushsection .fixup,"ax"
1695 .align 0
1696 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1697 index 6ee2f67..d1cce76 100644
1698 --- a/arch/arm/lib/copy_page.S
1699 +++ b/arch/arm/lib/copy_page.S
1700 @@ -10,6 +10,7 @@
1701 * ASM optimised string functions
1702 */
1703 #include <linux/linkage.h>
1704 +#include <linux/const.h>
1705 #include <asm/assembler.h>
1706 #include <asm/asm-offsets.h>
1707 #include <asm/cache.h>
1708 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1709 index d066df6..df28194 100644
1710 --- a/arch/arm/lib/copy_to_user.S
1711 +++ b/arch/arm/lib/copy_to_user.S
1712 @@ -16,7 +16,7 @@
1713 /*
1714 * Prototype:
1715 *
1716 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1717 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1718 *
1719 * Purpose:
1720 *
1721 @@ -88,11 +88,11 @@
1722 .text
1723
1724 ENTRY(__copy_to_user_std)
1725 -WEAK(__copy_to_user)
1726 +WEAK(___copy_to_user)
1727
1728 #include "copy_template.S"
1729
1730 -ENDPROC(__copy_to_user)
1731 +ENDPROC(___copy_to_user)
1732 ENDPROC(__copy_to_user_std)
1733
1734 .pushsection .fixup,"ax"
1735 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
1736 index 5c908b1..e712687 100644
1737 --- a/arch/arm/lib/uaccess.S
1738 +++ b/arch/arm/lib/uaccess.S
1739 @@ -20,7 +20,7 @@
1740
1741 #define PAGE_SHIFT 12
1742
1743 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
1744 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
1745 * Purpose : copy a block to user memory from kernel memory
1746 * Params : to - user memory
1747 * : from - kernel memory
1748 @@ -40,7 +40,7 @@ USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1749 sub r2, r2, ip
1750 b .Lc2u_dest_aligned
1751
1752 -ENTRY(__copy_to_user)
1753 +ENTRY(___copy_to_user)
1754 stmfd sp!, {r2, r4 - r7, lr}
1755 cmp r2, #4
1756 blt .Lc2u_not_enough
1757 @@ -278,14 +278,14 @@ USER( TUSER( strgeb) r3, [r0], #1) @ May fault
1758 ldrgtb r3, [r1], #0
1759 USER( TUSER( strgtb) r3, [r0], #1) @ May fault
1760 b .Lc2u_finished
1761 -ENDPROC(__copy_to_user)
1762 +ENDPROC(___copy_to_user)
1763
1764 .pushsection .fixup,"ax"
1765 .align 0
1766 9001: ldmfd sp!, {r0, r4 - r7, pc}
1767 .popsection
1768
1769 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
1770 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
1771 * Purpose : copy a block from user memory to kernel memory
1772 * Params : to - kernel memory
1773 * : from - user memory
1774 @@ -304,7 +304,7 @@ USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1775 sub r2, r2, ip
1776 b .Lcfu_dest_aligned
1777
1778 -ENTRY(__copy_from_user)
1779 +ENTRY(___copy_from_user)
1780 stmfd sp!, {r0, r2, r4 - r7, lr}
1781 cmp r2, #4
1782 blt .Lcfu_not_enough
1783 @@ -544,7 +544,7 @@ USER( TUSER( ldrgeb) r3, [r1], #1) @ May fault
1784 USER( TUSER( ldrgtb) r3, [r1], #1) @ May fault
1785 strgtb r3, [r0], #1
1786 b .Lcfu_finished
1787 -ENDPROC(__copy_from_user)
1788 +ENDPROC(___copy_from_user)
1789
1790 .pushsection .fixup,"ax"
1791 .align 0
1792 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1793 index 025f742..8432b08 100644
1794 --- a/arch/arm/lib/uaccess_with_memcpy.c
1795 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1796 @@ -104,7 +104,7 @@ out:
1797 }
1798
1799 unsigned long
1800 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1801 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1802 {
1803 /*
1804 * This test is stubbed out of the main function above to keep
1805 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1806 index 6722627..8f97548c 100644
1807 --- a/arch/arm/mach-omap2/board-n8x0.c
1808 +++ b/arch/arm/mach-omap2/board-n8x0.c
1809 @@ -597,7 +597,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1810 }
1811 #endif
1812
1813 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1814 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1815 .late_init = n8x0_menelaus_late_init,
1816 };
1817
1818 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
1819 index 2b2d51c..0127490 100644
1820 --- a/arch/arm/mach-ux500/mbox-db5500.c
1821 +++ b/arch/arm/mach-ux500/mbox-db5500.c
1822 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
1823 return sprintf(buf, "0x%X\n", mbox_value);
1824 }
1825
1826 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1827 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
1828
1829 static int mbox_show(struct seq_file *s, void *data)
1830 {
1831 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1832 index 90e366a..1b92505 100644
1833 --- a/arch/arm/mm/fault.c
1834 +++ b/arch/arm/mm/fault.c
1835 @@ -172,6 +172,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1836 }
1837 #endif
1838
1839 +#ifdef CONFIG_PAX_PAGEEXEC
1840 + if (fsr & FSR_LNX_PF) {
1841 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1842 + do_group_exit(SIGKILL);
1843 + }
1844 +#endif
1845 +
1846 tsk->thread.address = addr;
1847 tsk->thread.error_code = fsr;
1848 tsk->thread.trap_no = 14;
1849 @@ -395,6 +402,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1850 }
1851 #endif /* CONFIG_MMU */
1852
1853 +#ifdef CONFIG_PAX_PAGEEXEC
1854 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1855 +{
1856 + long i;
1857 +
1858 + printk(KERN_ERR "PAX: bytes at PC: ");
1859 + for (i = 0; i < 20; i++) {
1860 + unsigned char c;
1861 + if (get_user(c, (__force unsigned char __user *)pc+i))
1862 + printk(KERN_CONT "?? ");
1863 + else
1864 + printk(KERN_CONT "%02x ", c);
1865 + }
1866 + printk("\n");
1867 +
1868 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1869 + for (i = -1; i < 20; i++) {
1870 + unsigned long c;
1871 + if (get_user(c, (__force unsigned long __user *)sp+i))
1872 + printk(KERN_CONT "???????? ");
1873 + else
1874 + printk(KERN_CONT "%08lx ", c);
1875 + }
1876 + printk("\n");
1877 +}
1878 +#endif
1879 +
1880 /*
1881 * First Level Translation Fault Handler
1882 *
1883 @@ -575,6 +609,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1884 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1885 struct siginfo info;
1886
1887 +#ifdef CONFIG_PAX_REFCOUNT
1888 + if (fsr_fs(ifsr) == 2) {
1889 + unsigned int bkpt;
1890 +
1891 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1892 + current->thread.error_code = ifsr;
1893 + current->thread.trap_no = 0;
1894 + pax_report_refcount_overflow(regs);
1895 + fixup_exception(regs);
1896 + return;
1897 + }
1898 + }
1899 +#endif
1900 +
1901 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1902 return;
1903
1904 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1905 index ce8cb19..3ec539d 100644
1906 --- a/arch/arm/mm/mmap.c
1907 +++ b/arch/arm/mm/mmap.c
1908 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1909 if (len > TASK_SIZE)
1910 return -ENOMEM;
1911
1912 +#ifdef CONFIG_PAX_RANDMMAP
1913 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1914 +#endif
1915 +
1916 if (addr) {
1917 if (do_align)
1918 addr = COLOUR_ALIGN(addr, pgoff);
1919 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1920 addr = PAGE_ALIGN(addr);
1921
1922 vma = find_vma(mm, addr);
1923 - if (TASK_SIZE - len >= addr &&
1924 - (!vma || addr + len <= vma->vm_start))
1925 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1926 return addr;
1927 }
1928 if (len > mm->cached_hole_size) {
1929 - start_addr = addr = mm->free_area_cache;
1930 + start_addr = addr = mm->free_area_cache;
1931 } else {
1932 - start_addr = addr = mm->mmap_base;
1933 - mm->cached_hole_size = 0;
1934 + start_addr = addr = mm->mmap_base;
1935 + mm->cached_hole_size = 0;
1936 }
1937
1938 full_search:
1939 @@ -124,14 +127,14 @@ full_search:
1940 * Start a new search - just in case we missed
1941 * some holes.
1942 */
1943 - if (start_addr != TASK_UNMAPPED_BASE) {
1944 - start_addr = addr = TASK_UNMAPPED_BASE;
1945 + if (start_addr != mm->mmap_base) {
1946 + start_addr = addr = mm->mmap_base;
1947 mm->cached_hole_size = 0;
1948 goto full_search;
1949 }
1950 return -ENOMEM;
1951 }
1952 - if (!vma || addr + len <= vma->vm_start) {
1953 + if (check_heap_stack_gap(vma, addr, len)) {
1954 /*
1955 * Remember the place where we stopped the search:
1956 */
1957 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1958
1959 if (mmap_is_legacy()) {
1960 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1961 +
1962 +#ifdef CONFIG_PAX_RANDMMAP
1963 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1964 + mm->mmap_base += mm->delta_mmap;
1965 +#endif
1966 +
1967 mm->get_unmapped_area = arch_get_unmapped_area;
1968 mm->unmap_area = arch_unmap_area;
1969 } else {
1970 mm->mmap_base = mmap_base(random_factor);
1971 +
1972 +#ifdef CONFIG_PAX_RANDMMAP
1973 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1974 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1975 +#endif
1976 +
1977 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1978 mm->unmap_area = arch_unmap_area_topdown;
1979 }
1980 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
1981 index 71a6827..e7fbc23 100644
1982 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
1983 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
1984 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
1985 int (*started)(unsigned ch);
1986 int (*flush)(unsigned ch);
1987 int (*stop)(unsigned ch);
1988 -};
1989 +} __no_const;
1990
1991 extern void *samsung_dmadev_get_ops(void);
1992 extern void *s3c_dma_get_ops(void);
1993 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
1994 index 5f28cae..3d23723 100644
1995 --- a/arch/arm/plat-samsung/include/plat/ehci.h
1996 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
1997 @@ -14,7 +14,7 @@
1998 struct s5p_ehci_platdata {
1999 int (*phy_init)(struct platform_device *pdev, int type);
2000 int (*phy_exit)(struct platform_device *pdev, int type);
2001 -};
2002 +} __no_const;
2003
2004 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2005
2006 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2007 index c3a58a1..78fbf54 100644
2008 --- a/arch/avr32/include/asm/cache.h
2009 +++ b/arch/avr32/include/asm/cache.h
2010 @@ -1,8 +1,10 @@
2011 #ifndef __ASM_AVR32_CACHE_H
2012 #define __ASM_AVR32_CACHE_H
2013
2014 +#include <linux/const.h>
2015 +
2016 #define L1_CACHE_SHIFT 5
2017 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2018 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2019
2020 /*
2021 * Memory returned by kmalloc() may be used for DMA, so we must make
2022 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2023 index 3b3159b..425ea94 100644
2024 --- a/arch/avr32/include/asm/elf.h
2025 +++ b/arch/avr32/include/asm/elf.h
2026 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2027 the loader. We need to make sure that it is out of the way of the program
2028 that it will "exec", and that there is sufficient room for the brk. */
2029
2030 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2031 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2032
2033 +#ifdef CONFIG_PAX_ASLR
2034 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2035 +
2036 +#define PAX_DELTA_MMAP_LEN 15
2037 +#define PAX_DELTA_STACK_LEN 15
2038 +#endif
2039
2040 /* This yields a mask that user programs can use to figure out what
2041 instruction set this CPU supports. This could be done in user space,
2042 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2043 index b7f5c68..556135c 100644
2044 --- a/arch/avr32/include/asm/kmap_types.h
2045 +++ b/arch/avr32/include/asm/kmap_types.h
2046 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2047 D(11) KM_IRQ1,
2048 D(12) KM_SOFTIRQ0,
2049 D(13) KM_SOFTIRQ1,
2050 -D(14) KM_TYPE_NR
2051 +D(14) KM_CLEARPAGE,
2052 +D(15) KM_TYPE_NR
2053 };
2054
2055 #undef D
2056 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2057 index f7040a1..db9f300 100644
2058 --- a/arch/avr32/mm/fault.c
2059 +++ b/arch/avr32/mm/fault.c
2060 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2061
2062 int exception_trace = 1;
2063
2064 +#ifdef CONFIG_PAX_PAGEEXEC
2065 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2066 +{
2067 + unsigned long i;
2068 +
2069 + printk(KERN_ERR "PAX: bytes at PC: ");
2070 + for (i = 0; i < 20; i++) {
2071 + unsigned char c;
2072 + if (get_user(c, (unsigned char *)pc+i))
2073 + printk(KERN_CONT "???????? ");
2074 + else
2075 + printk(KERN_CONT "%02x ", c);
2076 + }
2077 + printk("\n");
2078 +}
2079 +#endif
2080 +
2081 /*
2082 * This routine handles page faults. It determines the address and the
2083 * problem, and then passes it off to one of the appropriate routines.
2084 @@ -156,6 +173,16 @@ bad_area:
2085 up_read(&mm->mmap_sem);
2086
2087 if (user_mode(regs)) {
2088 +
2089 +#ifdef CONFIG_PAX_PAGEEXEC
2090 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2091 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2092 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2093 + do_group_exit(SIGKILL);
2094 + }
2095 + }
2096 +#endif
2097 +
2098 if (exception_trace && printk_ratelimit())
2099 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2100 "sp %08lx ecr %lu\n",
2101 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2102 index 568885a..f8008df 100644
2103 --- a/arch/blackfin/include/asm/cache.h
2104 +++ b/arch/blackfin/include/asm/cache.h
2105 @@ -7,6 +7,7 @@
2106 #ifndef __ARCH_BLACKFIN_CACHE_H
2107 #define __ARCH_BLACKFIN_CACHE_H
2108
2109 +#include <linux/const.h>
2110 #include <linux/linkage.h> /* for asmlinkage */
2111
2112 /*
2113 @@ -14,7 +15,7 @@
2114 * Blackfin loads 32 bytes for cache
2115 */
2116 #define L1_CACHE_SHIFT 5
2117 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2118 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2119 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2120
2121 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2122 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2123 index aea2718..3639a60 100644
2124 --- a/arch/cris/include/arch-v10/arch/cache.h
2125 +++ b/arch/cris/include/arch-v10/arch/cache.h
2126 @@ -1,8 +1,9 @@
2127 #ifndef _ASM_ARCH_CACHE_H
2128 #define _ASM_ARCH_CACHE_H
2129
2130 +#include <linux/const.h>
2131 /* Etrax 100LX have 32-byte cache-lines. */
2132 -#define L1_CACHE_BYTES 32
2133 #define L1_CACHE_SHIFT 5
2134 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2135
2136 #endif /* _ASM_ARCH_CACHE_H */
2137 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2138 index 1de779f..336fad3 100644
2139 --- a/arch/cris/include/arch-v32/arch/cache.h
2140 +++ b/arch/cris/include/arch-v32/arch/cache.h
2141 @@ -1,11 +1,12 @@
2142 #ifndef _ASM_CRIS_ARCH_CACHE_H
2143 #define _ASM_CRIS_ARCH_CACHE_H
2144
2145 +#include <linux/const.h>
2146 #include <arch/hwregs/dma.h>
2147
2148 /* A cache-line is 32 bytes. */
2149 -#define L1_CACHE_BYTES 32
2150 #define L1_CACHE_SHIFT 5
2151 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2152
2153 #define __read_mostly __attribute__((__section__(".data.read_mostly")))
2154
2155 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2156 index 0d8a7d6..d0c9ff5 100644
2157 --- a/arch/frv/include/asm/atomic.h
2158 +++ b/arch/frv/include/asm/atomic.h
2159 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
2160 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2161 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2162
2163 +#define atomic64_read_unchecked(v) atomic64_read(v)
2164 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2165 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2166 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2167 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2168 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2169 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2170 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2171 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2172 +
2173 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2174 {
2175 int c, old;
2176 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2177 index 2797163..c2a401d 100644
2178 --- a/arch/frv/include/asm/cache.h
2179 +++ b/arch/frv/include/asm/cache.h
2180 @@ -12,10 +12,11 @@
2181 #ifndef __ASM_CACHE_H
2182 #define __ASM_CACHE_H
2183
2184 +#include <linux/const.h>
2185
2186 /* bytes per L1 cache line */
2187 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2188 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2189 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2190
2191 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2192 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2193 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2194 index f8e16b2..c73ff79 100644
2195 --- a/arch/frv/include/asm/kmap_types.h
2196 +++ b/arch/frv/include/asm/kmap_types.h
2197 @@ -23,6 +23,7 @@ enum km_type {
2198 KM_IRQ1,
2199 KM_SOFTIRQ0,
2200 KM_SOFTIRQ1,
2201 + KM_CLEARPAGE,
2202 KM_TYPE_NR
2203 };
2204
2205 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2206 index 385fd30..6c3d97e 100644
2207 --- a/arch/frv/mm/elf-fdpic.c
2208 +++ b/arch/frv/mm/elf-fdpic.c
2209 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2210 if (addr) {
2211 addr = PAGE_ALIGN(addr);
2212 vma = find_vma(current->mm, addr);
2213 - if (TASK_SIZE - len >= addr &&
2214 - (!vma || addr + len <= vma->vm_start))
2215 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2216 goto success;
2217 }
2218
2219 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2220 for (; vma; vma = vma->vm_next) {
2221 if (addr > limit)
2222 break;
2223 - if (addr + len <= vma->vm_start)
2224 + if (check_heap_stack_gap(vma, addr, len))
2225 goto success;
2226 addr = vma->vm_end;
2227 }
2228 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2229 for (; vma; vma = vma->vm_next) {
2230 if (addr > limit)
2231 break;
2232 - if (addr + len <= vma->vm_start)
2233 + if (check_heap_stack_gap(vma, addr, len))
2234 goto success;
2235 addr = vma->vm_end;
2236 }
2237 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2238 index c635028..6d9445a 100644
2239 --- a/arch/h8300/include/asm/cache.h
2240 +++ b/arch/h8300/include/asm/cache.h
2241 @@ -1,8 +1,10 @@
2242 #ifndef __ARCH_H8300_CACHE_H
2243 #define __ARCH_H8300_CACHE_H
2244
2245 +#include <linux/const.h>
2246 +
2247 /* bytes per L1 cache line */
2248 -#define L1_CACHE_BYTES 4
2249 +#define L1_CACHE_BYTES _AC(4,UL)
2250
2251 /* m68k-elf-gcc 2.95.2 doesn't like these */
2252
2253 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2254 index 0f01de2..d37d309 100644
2255 --- a/arch/hexagon/include/asm/cache.h
2256 +++ b/arch/hexagon/include/asm/cache.h
2257 @@ -21,9 +21,11 @@
2258 #ifndef __ASM_CACHE_H
2259 #define __ASM_CACHE_H
2260
2261 +#include <linux/const.h>
2262 +
2263 /* Bytes per L1 cache line */
2264 -#define L1_CACHE_SHIFT (5)
2265 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2266 +#define L1_CACHE_SHIFT 5
2267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2268
2269 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2270 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2271 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2272 index 3fad89e..3047da5 100644
2273 --- a/arch/ia64/include/asm/atomic.h
2274 +++ b/arch/ia64/include/asm/atomic.h
2275 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2276 #define atomic64_inc(v) atomic64_add(1, (v))
2277 #define atomic64_dec(v) atomic64_sub(1, (v))
2278
2279 +#define atomic64_read_unchecked(v) atomic64_read(v)
2280 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2281 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2282 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2283 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2284 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2285 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2286 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2287 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2288 +
2289 /* Atomic operations are already serializing */
2290 #define smp_mb__before_atomic_dec() barrier()
2291 #define smp_mb__after_atomic_dec() barrier()
2292 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2293 index 988254a..e1ee885 100644
2294 --- a/arch/ia64/include/asm/cache.h
2295 +++ b/arch/ia64/include/asm/cache.h
2296 @@ -1,6 +1,7 @@
2297 #ifndef _ASM_IA64_CACHE_H
2298 #define _ASM_IA64_CACHE_H
2299
2300 +#include <linux/const.h>
2301
2302 /*
2303 * Copyright (C) 1998-2000 Hewlett-Packard Co
2304 @@ -9,7 +10,7 @@
2305
2306 /* Bytes per L1 (data) cache line. */
2307 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2308 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2309 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2310
2311 #ifdef CONFIG_SMP
2312 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2313 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2314 index b5298eb..67c6e62 100644
2315 --- a/arch/ia64/include/asm/elf.h
2316 +++ b/arch/ia64/include/asm/elf.h
2317 @@ -42,6 +42,13 @@
2318 */
2319 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2320
2321 +#ifdef CONFIG_PAX_ASLR
2322 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2323 +
2324 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2325 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2326 +#endif
2327 +
2328 #define PT_IA_64_UNWIND 0x70000001
2329
2330 /* IA-64 relocations: */
2331 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2332 index 96a8d92..617a1cf 100644
2333 --- a/arch/ia64/include/asm/pgalloc.h
2334 +++ b/arch/ia64/include/asm/pgalloc.h
2335 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2336 pgd_val(*pgd_entry) = __pa(pud);
2337 }
2338
2339 +static inline void
2340 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2341 +{
2342 + pgd_populate(mm, pgd_entry, pud);
2343 +}
2344 +
2345 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2346 {
2347 return quicklist_alloc(0, GFP_KERNEL, NULL);
2348 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2349 pud_val(*pud_entry) = __pa(pmd);
2350 }
2351
2352 +static inline void
2353 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2354 +{
2355 + pud_populate(mm, pud_entry, pmd);
2356 +}
2357 +
2358 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2359 {
2360 return quicklist_alloc(0, GFP_KERNEL, NULL);
2361 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2362 index 1a97af3..7529d31 100644
2363 --- a/arch/ia64/include/asm/pgtable.h
2364 +++ b/arch/ia64/include/asm/pgtable.h
2365 @@ -12,7 +12,7 @@
2366 * David Mosberger-Tang <davidm@hpl.hp.com>
2367 */
2368
2369 -
2370 +#include <linux/const.h>
2371 #include <asm/mman.h>
2372 #include <asm/page.h>
2373 #include <asm/processor.h>
2374 @@ -143,6 +143,17 @@
2375 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2376 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2377 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2378 +
2379 +#ifdef CONFIG_PAX_PAGEEXEC
2380 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2381 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2382 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2383 +#else
2384 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2385 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2386 +# define PAGE_COPY_NOEXEC PAGE_COPY
2387 +#endif
2388 +
2389 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2390 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2391 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2392 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2393 index b77768d..e0795eb 100644
2394 --- a/arch/ia64/include/asm/spinlock.h
2395 +++ b/arch/ia64/include/asm/spinlock.h
2396 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2397 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2398
2399 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2400 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2401 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2402 }
2403
2404 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2405 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2406 index 449c8c0..432a3d2 100644
2407 --- a/arch/ia64/include/asm/uaccess.h
2408 +++ b/arch/ia64/include/asm/uaccess.h
2409 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2410 const void *__cu_from = (from); \
2411 long __cu_len = (n); \
2412 \
2413 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2414 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2415 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2416 __cu_len; \
2417 })
2418 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2419 long __cu_len = (n); \
2420 \
2421 __chk_user_ptr(__cu_from); \
2422 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2423 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2424 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2425 __cu_len; \
2426 })
2427 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2428 index 24603be..948052d 100644
2429 --- a/arch/ia64/kernel/module.c
2430 +++ b/arch/ia64/kernel/module.c
2431 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2432 void
2433 module_free (struct module *mod, void *module_region)
2434 {
2435 - if (mod && mod->arch.init_unw_table &&
2436 - module_region == mod->module_init) {
2437 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2438 unw_remove_unwind_table(mod->arch.init_unw_table);
2439 mod->arch.init_unw_table = NULL;
2440 }
2441 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2442 }
2443
2444 static inline int
2445 +in_init_rx (const struct module *mod, uint64_t addr)
2446 +{
2447 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2448 +}
2449 +
2450 +static inline int
2451 +in_init_rw (const struct module *mod, uint64_t addr)
2452 +{
2453 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2454 +}
2455 +
2456 +static inline int
2457 in_init (const struct module *mod, uint64_t addr)
2458 {
2459 - return addr - (uint64_t) mod->module_init < mod->init_size;
2460 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2461 +}
2462 +
2463 +static inline int
2464 +in_core_rx (const struct module *mod, uint64_t addr)
2465 +{
2466 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2467 +}
2468 +
2469 +static inline int
2470 +in_core_rw (const struct module *mod, uint64_t addr)
2471 +{
2472 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2473 }
2474
2475 static inline int
2476 in_core (const struct module *mod, uint64_t addr)
2477 {
2478 - return addr - (uint64_t) mod->module_core < mod->core_size;
2479 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2480 }
2481
2482 static inline int
2483 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2484 break;
2485
2486 case RV_BDREL:
2487 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2488 + if (in_init_rx(mod, val))
2489 + val -= (uint64_t) mod->module_init_rx;
2490 + else if (in_init_rw(mod, val))
2491 + val -= (uint64_t) mod->module_init_rw;
2492 + else if (in_core_rx(mod, val))
2493 + val -= (uint64_t) mod->module_core_rx;
2494 + else if (in_core_rw(mod, val))
2495 + val -= (uint64_t) mod->module_core_rw;
2496 break;
2497
2498 case RV_LTV:
2499 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2500 * addresses have been selected...
2501 */
2502 uint64_t gp;
2503 - if (mod->core_size > MAX_LTOFF)
2504 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2505 /*
2506 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2507 * at the end of the module.
2508 */
2509 - gp = mod->core_size - MAX_LTOFF / 2;
2510 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2511 else
2512 - gp = mod->core_size / 2;
2513 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2514 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2515 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2516 mod->arch.gp = gp;
2517 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2518 }
2519 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2520 index 609d500..7dde2a8 100644
2521 --- a/arch/ia64/kernel/sys_ia64.c
2522 +++ b/arch/ia64/kernel/sys_ia64.c
2523 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2524 if (REGION_NUMBER(addr) == RGN_HPAGE)
2525 addr = 0;
2526 #endif
2527 +
2528 +#ifdef CONFIG_PAX_RANDMMAP
2529 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2530 + addr = mm->free_area_cache;
2531 + else
2532 +#endif
2533 +
2534 if (!addr)
2535 addr = mm->free_area_cache;
2536
2537 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2538 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2539 /* At this point: (!vma || addr < vma->vm_end). */
2540 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2541 - if (start_addr != TASK_UNMAPPED_BASE) {
2542 + if (start_addr != mm->mmap_base) {
2543 /* Start a new search --- just in case we missed some holes. */
2544 - addr = TASK_UNMAPPED_BASE;
2545 + addr = mm->mmap_base;
2546 goto full_search;
2547 }
2548 return -ENOMEM;
2549 }
2550 - if (!vma || addr + len <= vma->vm_start) {
2551 + if (check_heap_stack_gap(vma, addr, len)) {
2552 /* Remember the address where we stopped this search: */
2553 mm->free_area_cache = addr + len;
2554 return addr;
2555 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2556 index 53c0ba0..2accdde 100644
2557 --- a/arch/ia64/kernel/vmlinux.lds.S
2558 +++ b/arch/ia64/kernel/vmlinux.lds.S
2559 @@ -199,7 +199,7 @@ SECTIONS {
2560 /* Per-cpu data: */
2561 . = ALIGN(PERCPU_PAGE_SIZE);
2562 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2563 - __phys_per_cpu_start = __per_cpu_load;
2564 + __phys_per_cpu_start = per_cpu_load;
2565 /*
2566 * ensure percpu data fits
2567 * into percpu page size
2568 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2569 index 20b3593..1ce77f0 100644
2570 --- a/arch/ia64/mm/fault.c
2571 +++ b/arch/ia64/mm/fault.c
2572 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
2573 return pte_present(pte);
2574 }
2575
2576 +#ifdef CONFIG_PAX_PAGEEXEC
2577 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2578 +{
2579 + unsigned long i;
2580 +
2581 + printk(KERN_ERR "PAX: bytes at PC: ");
2582 + for (i = 0; i < 8; i++) {
2583 + unsigned int c;
2584 + if (get_user(c, (unsigned int *)pc+i))
2585 + printk(KERN_CONT "???????? ");
2586 + else
2587 + printk(KERN_CONT "%08x ", c);
2588 + }
2589 + printk("\n");
2590 +}
2591 +#endif
2592 +
2593 void __kprobes
2594 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2595 {
2596 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2597 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2598 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2599
2600 - if ((vma->vm_flags & mask) != mask)
2601 + if ((vma->vm_flags & mask) != mask) {
2602 +
2603 +#ifdef CONFIG_PAX_PAGEEXEC
2604 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2605 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2606 + goto bad_area;
2607 +
2608 + up_read(&mm->mmap_sem);
2609 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2610 + do_group_exit(SIGKILL);
2611 + }
2612 +#endif
2613 +
2614 goto bad_area;
2615
2616 + }
2617 +
2618 /*
2619 * If for any reason at all we couldn't handle the fault, make
2620 * sure we exit gracefully rather than endlessly redo the
2621 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2622 index 5ca674b..e0e1b70 100644
2623 --- a/arch/ia64/mm/hugetlbpage.c
2624 +++ b/arch/ia64/mm/hugetlbpage.c
2625 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2626 /* At this point: (!vmm || addr < vmm->vm_end). */
2627 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2628 return -ENOMEM;
2629 - if (!vmm || (addr + len) <= vmm->vm_start)
2630 + if (check_heap_stack_gap(vmm, addr, len))
2631 return addr;
2632 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2633 }
2634 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2635 index 13df239d..cb52116 100644
2636 --- a/arch/ia64/mm/init.c
2637 +++ b/arch/ia64/mm/init.c
2638 @@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2639 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2640 vma->vm_end = vma->vm_start + PAGE_SIZE;
2641 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2642 +
2643 +#ifdef CONFIG_PAX_PAGEEXEC
2644 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2645 + vma->vm_flags &= ~VM_EXEC;
2646 +
2647 +#ifdef CONFIG_PAX_MPROTECT
2648 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2649 + vma->vm_flags &= ~VM_MAYEXEC;
2650 +#endif
2651 +
2652 + }
2653 +#endif
2654 +
2655 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2656 down_write(&current->mm->mmap_sem);
2657 if (insert_vm_struct(current->mm, vma)) {
2658 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2659 index 40b3ee9..8c2c112 100644
2660 --- a/arch/m32r/include/asm/cache.h
2661 +++ b/arch/m32r/include/asm/cache.h
2662 @@ -1,8 +1,10 @@
2663 #ifndef _ASM_M32R_CACHE_H
2664 #define _ASM_M32R_CACHE_H
2665
2666 +#include <linux/const.h>
2667 +
2668 /* L1 cache line size */
2669 #define L1_CACHE_SHIFT 4
2670 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2671 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2672
2673 #endif /* _ASM_M32R_CACHE_H */
2674 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2675 index 82abd15..d95ae5d 100644
2676 --- a/arch/m32r/lib/usercopy.c
2677 +++ b/arch/m32r/lib/usercopy.c
2678 @@ -14,6 +14,9 @@
2679 unsigned long
2680 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2681 {
2682 + if ((long)n < 0)
2683 + return n;
2684 +
2685 prefetch(from);
2686 if (access_ok(VERIFY_WRITE, to, n))
2687 __copy_user(to,from,n);
2688 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2689 unsigned long
2690 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2691 {
2692 + if ((long)n < 0)
2693 + return n;
2694 +
2695 prefetchw(to);
2696 if (access_ok(VERIFY_READ, from, n))
2697 __copy_user_zeroing(to,from,n);
2698 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2699 index 0395c51..5f26031 100644
2700 --- a/arch/m68k/include/asm/cache.h
2701 +++ b/arch/m68k/include/asm/cache.h
2702 @@ -4,9 +4,11 @@
2703 #ifndef __ARCH_M68K_CACHE_H
2704 #define __ARCH_M68K_CACHE_H
2705
2706 +#include <linux/const.h>
2707 +
2708 /* bytes per L1 cache line */
2709 #define L1_CACHE_SHIFT 4
2710 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2711 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2712
2713 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2714
2715 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2716 index 4efe96a..60e8699 100644
2717 --- a/arch/microblaze/include/asm/cache.h
2718 +++ b/arch/microblaze/include/asm/cache.h
2719 @@ -13,11 +13,12 @@
2720 #ifndef _ASM_MICROBLAZE_CACHE_H
2721 #define _ASM_MICROBLAZE_CACHE_H
2722
2723 +#include <linux/const.h>
2724 #include <asm/registers.h>
2725
2726 #define L1_CACHE_SHIFT 5
2727 /* word-granular cache in microblaze */
2728 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2729 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2730
2731 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2732
2733 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2734 index 1d93f81..67794d0 100644
2735 --- a/arch/mips/include/asm/atomic.h
2736 +++ b/arch/mips/include/asm/atomic.h
2737 @@ -21,6 +21,10 @@
2738 #include <asm/war.h>
2739 #include <asm/system.h>
2740
2741 +#ifdef CONFIG_GENERIC_ATOMIC64
2742 +#include <asm-generic/atomic64.h>
2743 +#endif
2744 +
2745 #define ATOMIC_INIT(i) { (i) }
2746
2747 /*
2748 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2749 */
2750 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2751
2752 +#define atomic64_read_unchecked(v) atomic64_read(v)
2753 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2754 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2755 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2756 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2757 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2758 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2759 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2760 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2761 +
2762 #endif /* CONFIG_64BIT */
2763
2764 /*
2765 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2766 index b4db69f..8f3b093 100644
2767 --- a/arch/mips/include/asm/cache.h
2768 +++ b/arch/mips/include/asm/cache.h
2769 @@ -9,10 +9,11 @@
2770 #ifndef _ASM_CACHE_H
2771 #define _ASM_CACHE_H
2772
2773 +#include <linux/const.h>
2774 #include <kmalloc.h>
2775
2776 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2777 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2778 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2779
2780 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2781 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2782 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2783 index 455c0ac..ad65fbe 100644
2784 --- a/arch/mips/include/asm/elf.h
2785 +++ b/arch/mips/include/asm/elf.h
2786 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2787 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2788 #endif
2789
2790 +#ifdef CONFIG_PAX_ASLR
2791 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2792 +
2793 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2794 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2795 +#endif
2796 +
2797 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2798 struct linux_binprm;
2799 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2800 int uses_interp);
2801
2802 -struct mm_struct;
2803 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2804 -#define arch_randomize_brk arch_randomize_brk
2805 -
2806 #endif /* _ASM_ELF_H */
2807 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2808 index da9bd7d..91aa7ab 100644
2809 --- a/arch/mips/include/asm/page.h
2810 +++ b/arch/mips/include/asm/page.h
2811 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2812 #ifdef CONFIG_CPU_MIPS32
2813 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2814 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2815 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2816 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2817 #else
2818 typedef struct { unsigned long long pte; } pte_t;
2819 #define pte_val(x) ((x).pte)
2820 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2821 index 881d18b..cea38bc 100644
2822 --- a/arch/mips/include/asm/pgalloc.h
2823 +++ b/arch/mips/include/asm/pgalloc.h
2824 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2825 {
2826 set_pud(pud, __pud((unsigned long)pmd));
2827 }
2828 +
2829 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2830 +{
2831 + pud_populate(mm, pud, pmd);
2832 +}
2833 #endif
2834
2835 /*
2836 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
2837 index 6018c80..7c37203 100644
2838 --- a/arch/mips/include/asm/system.h
2839 +++ b/arch/mips/include/asm/system.h
2840 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
2841 */
2842 #define __ARCH_WANT_UNLOCKED_CTXSW
2843
2844 -extern unsigned long arch_align_stack(unsigned long sp);
2845 +#define arch_align_stack(x) ((x) & ~0xfUL)
2846
2847 #endif /* _ASM_SYSTEM_H */
2848 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2849 index 0d85d8e..ec71487 100644
2850 --- a/arch/mips/include/asm/thread_info.h
2851 +++ b/arch/mips/include/asm/thread_info.h
2852 @@ -123,6 +123,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2853 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2854 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2855 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2856 +/* li takes a 32bit immediate */
2857 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2858 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2859
2860 #ifdef CONFIG_MIPS32_O32
2861 @@ -146,15 +148,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2862 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2863 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2864 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2865 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2866 +
2867 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2868
2869 /* work to do in syscall_trace_leave() */
2870 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2871 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2872
2873 /* work to do on interrupt/exception return */
2874 #define _TIF_WORK_MASK (0x0000ffef & \
2875 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2876 /* work to do on any return to u-space */
2877 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2878 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2879
2880 #endif /* __KERNEL__ */
2881
2882 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2883 index 9fdd8bc..4bd7f1a 100644
2884 --- a/arch/mips/kernel/binfmt_elfn32.c
2885 +++ b/arch/mips/kernel/binfmt_elfn32.c
2886 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2887 #undef ELF_ET_DYN_BASE
2888 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2889
2890 +#ifdef CONFIG_PAX_ASLR
2891 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2892 +
2893 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2894 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2895 +#endif
2896 +
2897 #include <asm/processor.h>
2898 #include <linux/module.h>
2899 #include <linux/elfcore.h>
2900 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2901 index ff44823..97f8906 100644
2902 --- a/arch/mips/kernel/binfmt_elfo32.c
2903 +++ b/arch/mips/kernel/binfmt_elfo32.c
2904 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2905 #undef ELF_ET_DYN_BASE
2906 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2907
2908 +#ifdef CONFIG_PAX_ASLR
2909 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2910 +
2911 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2912 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2913 +#endif
2914 +
2915 #include <asm/processor.h>
2916
2917 /*
2918 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2919 index 7955409..ceaea7c 100644
2920 --- a/arch/mips/kernel/process.c
2921 +++ b/arch/mips/kernel/process.c
2922 @@ -483,15 +483,3 @@ unsigned long get_wchan(struct task_struct *task)
2923 out:
2924 return pc;
2925 }
2926 -
2927 -/*
2928 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2929 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2930 - */
2931 -unsigned long arch_align_stack(unsigned long sp)
2932 -{
2933 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2934 - sp -= get_random_int() & ~PAGE_MASK;
2935 -
2936 - return sp & ALMASK;
2937 -}
2938 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2939 index 7786b60..3e38c72 100644
2940 --- a/arch/mips/kernel/ptrace.c
2941 +++ b/arch/mips/kernel/ptrace.c
2942 @@ -529,6 +529,10 @@ static inline int audit_arch(void)
2943 return arch;
2944 }
2945
2946 +#ifdef CONFIG_GRKERNSEC_SETXID
2947 +extern void gr_delayed_cred_worker(void);
2948 +#endif
2949 +
2950 /*
2951 * Notification of system call entry/exit
2952 * - triggered by current->work.syscall_trace
2953 @@ -538,6 +542,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2954 /* do the secure computing check first */
2955 secure_computing(regs->regs[2]);
2956
2957 +#ifdef CONFIG_GRKERNSEC_SETXID
2958 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2959 + gr_delayed_cred_worker();
2960 +#endif
2961 +
2962 if (!(current->ptrace & PT_PTRACED))
2963 goto out;
2964
2965 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
2966 index a632bc1..0b77c7c 100644
2967 --- a/arch/mips/kernel/scall32-o32.S
2968 +++ b/arch/mips/kernel/scall32-o32.S
2969 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
2970
2971 stack_done:
2972 lw t0, TI_FLAGS($28) # syscall tracing enabled?
2973 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
2974 + li t1, _TIF_SYSCALL_WORK
2975 and t0, t1
2976 bnez t0, syscall_trace_entry # -> yes
2977
2978 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
2979 index 3b5a5e9..e1ee86d 100644
2980 --- a/arch/mips/kernel/scall64-64.S
2981 +++ b/arch/mips/kernel/scall64-64.S
2982 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
2983
2984 sd a3, PT_R26(sp) # save a3 for syscall restarting
2985
2986 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
2987 + li t1, _TIF_SYSCALL_WORK
2988 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
2989 and t0, t1, t0
2990 bnez t0, syscall_trace_entry
2991 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
2992 index 6be6f70..1859577 100644
2993 --- a/arch/mips/kernel/scall64-n32.S
2994 +++ b/arch/mips/kernel/scall64-n32.S
2995 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
2996
2997 sd a3, PT_R26(sp) # save a3 for syscall restarting
2998
2999 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3000 + li t1, _TIF_SYSCALL_WORK
3001 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3002 and t0, t1, t0
3003 bnez t0, n32_syscall_trace_entry
3004 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3005 index 5422855..74e63a3 100644
3006 --- a/arch/mips/kernel/scall64-o32.S
3007 +++ b/arch/mips/kernel/scall64-o32.S
3008 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3009 PTR 4b, bad_stack
3010 .previous
3011
3012 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3013 + li t1, _TIF_SYSCALL_WORK
3014 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3015 and t0, t1, t0
3016 bnez t0, trace_a_syscall
3017 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3018 index 69ebd58..e4bff83 100644
3019 --- a/arch/mips/mm/fault.c
3020 +++ b/arch/mips/mm/fault.c
3021 @@ -28,6 +28,23 @@
3022 #include <asm/highmem.h> /* For VMALLOC_END */
3023 #include <linux/kdebug.h>
3024
3025 +#ifdef CONFIG_PAX_PAGEEXEC
3026 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3027 +{
3028 + unsigned long i;
3029 +
3030 + printk(KERN_ERR "PAX: bytes at PC: ");
3031 + for (i = 0; i < 5; i++) {
3032 + unsigned int c;
3033 + if (get_user(c, (unsigned int *)pc+i))
3034 + printk(KERN_CONT "???????? ");
3035 + else
3036 + printk(KERN_CONT "%08x ", c);
3037 + }
3038 + printk("\n");
3039 +}
3040 +#endif
3041 +
3042 /*
3043 * This routine handles page faults. It determines the address,
3044 * and the problem, and then passes it off to one of the appropriate
3045 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3046 index 302d779..7d35bf8 100644
3047 --- a/arch/mips/mm/mmap.c
3048 +++ b/arch/mips/mm/mmap.c
3049 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3050 do_color_align = 1;
3051
3052 /* requesting a specific address */
3053 +
3054 +#ifdef CONFIG_PAX_RANDMMAP
3055 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3056 +#endif
3057 +
3058 if (addr) {
3059 if (do_color_align)
3060 addr = COLOUR_ALIGN(addr, pgoff);
3061 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3062 addr = PAGE_ALIGN(addr);
3063
3064 vma = find_vma(mm, addr);
3065 - if (TASK_SIZE - len >= addr &&
3066 - (!vma || addr + len <= vma->vm_start))
3067 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3068 return addr;
3069 }
3070
3071 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3072 /* At this point: (!vma || addr < vma->vm_end). */
3073 if (TASK_SIZE - len < addr)
3074 return -ENOMEM;
3075 - if (!vma || addr + len <= vma->vm_start)
3076 + if (check_heap_stack_gap(vmm, addr, len))
3077 return addr;
3078 addr = vma->vm_end;
3079 if (do_color_align)
3080 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3081 /* make sure it can fit in the remaining address space */
3082 if (likely(addr > len)) {
3083 vma = find_vma(mm, addr - len);
3084 - if (!vma || addr <= vma->vm_start) {
3085 + if (check_heap_stack_gap(vmm, addr - len, len))
3086 /* cache the address as a hint for next time */
3087 return mm->free_area_cache = addr - len;
3088 }
3089 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3090 * return with success:
3091 */
3092 vma = find_vma(mm, addr);
3093 - if (likely(!vma || addr + len <= vma->vm_start)) {
3094 + if (check_heap_stack_gap(vmm, addr, len)) {
3095 /* cache the address as a hint for next time */
3096 return mm->free_area_cache = addr;
3097 }
3098 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3099 mm->unmap_area = arch_unmap_area_topdown;
3100 }
3101 }
3102 -
3103 -static inline unsigned long brk_rnd(void)
3104 -{
3105 - unsigned long rnd = get_random_int();
3106 -
3107 - rnd = rnd << PAGE_SHIFT;
3108 - /* 8MB for 32bit, 256MB for 64bit */
3109 - if (TASK_IS_32BIT_ADDR)
3110 - rnd = rnd & 0x7ffffful;
3111 - else
3112 - rnd = rnd & 0xffffffful;
3113 -
3114 - return rnd;
3115 -}
3116 -
3117 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3118 -{
3119 - unsigned long base = mm->brk;
3120 - unsigned long ret;
3121 -
3122 - ret = PAGE_ALIGN(base + brk_rnd());
3123 -
3124 - if (ret < mm->brk)
3125 - return mm->brk;
3126 -
3127 - return ret;
3128 -}
3129 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3130 index 967d144..db12197 100644
3131 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3132 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3133 @@ -11,12 +11,14 @@
3134 #ifndef _ASM_PROC_CACHE_H
3135 #define _ASM_PROC_CACHE_H
3136
3137 +#include <linux/const.h>
3138 +
3139 /* L1 cache */
3140
3141 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3142 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3143 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3144 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3145 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3146 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3147
3148 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3149 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3150 index bcb5df2..84fabd2 100644
3151 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3152 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3153 @@ -16,13 +16,15 @@
3154 #ifndef _ASM_PROC_CACHE_H
3155 #define _ASM_PROC_CACHE_H
3156
3157 +#include <linux/const.h>
3158 +
3159 /*
3160 * L1 cache
3161 */
3162 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3163 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3164 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3165 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3166 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3167 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3168
3169 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3170 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3171 index 4ce7a01..449202a 100644
3172 --- a/arch/openrisc/include/asm/cache.h
3173 +++ b/arch/openrisc/include/asm/cache.h
3174 @@ -19,11 +19,13 @@
3175 #ifndef __ASM_OPENRISC_CACHE_H
3176 #define __ASM_OPENRISC_CACHE_H
3177
3178 +#include <linux/const.h>
3179 +
3180 /* FIXME: How can we replace these with values from the CPU...
3181 * they shouldn't be hard-coded!
3182 */
3183
3184 -#define L1_CACHE_BYTES 16
3185 #define L1_CACHE_SHIFT 4
3186 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3187
3188 #endif /* __ASM_OPENRISC_CACHE_H */
3189 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3190 index 4054b31..a10c105 100644
3191 --- a/arch/parisc/include/asm/atomic.h
3192 +++ b/arch/parisc/include/asm/atomic.h
3193 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3194
3195 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3196
3197 +#define atomic64_read_unchecked(v) atomic64_read(v)
3198 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3199 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3200 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3201 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3202 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3203 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3204 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3205 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3206 +
3207 #endif /* !CONFIG_64BIT */
3208
3209
3210 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3211 index 47f11c7..3420df2 100644
3212 --- a/arch/parisc/include/asm/cache.h
3213 +++ b/arch/parisc/include/asm/cache.h
3214 @@ -5,6 +5,7 @@
3215 #ifndef __ARCH_PARISC_CACHE_H
3216 #define __ARCH_PARISC_CACHE_H
3217
3218 +#include <linux/const.h>
3219
3220 /*
3221 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3222 @@ -15,13 +16,13 @@
3223 * just ruin performance.
3224 */
3225 #ifdef CONFIG_PA20
3226 -#define L1_CACHE_BYTES 64
3227 #define L1_CACHE_SHIFT 6
3228 #else
3229 -#define L1_CACHE_BYTES 32
3230 #define L1_CACHE_SHIFT 5
3231 #endif
3232
3233 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3234 +
3235 #ifndef __ASSEMBLY__
3236
3237 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3238 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3239 index 19f6cb1..6c78cf2 100644
3240 --- a/arch/parisc/include/asm/elf.h
3241 +++ b/arch/parisc/include/asm/elf.h
3242 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3243
3244 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3245
3246 +#ifdef CONFIG_PAX_ASLR
3247 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3248 +
3249 +#define PAX_DELTA_MMAP_LEN 16
3250 +#define PAX_DELTA_STACK_LEN 16
3251 +#endif
3252 +
3253 /* This yields a mask that user programs can use to figure out what
3254 instruction set this CPU supports. This could be done in user space,
3255 but it's not easy, and we've already done it here. */
3256 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3257 index fc987a1..6e068ef 100644
3258 --- a/arch/parisc/include/asm/pgalloc.h
3259 +++ b/arch/parisc/include/asm/pgalloc.h
3260 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3261 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3262 }
3263
3264 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3265 +{
3266 + pgd_populate(mm, pgd, pmd);
3267 +}
3268 +
3269 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3270 {
3271 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3272 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3273 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3274 #define pmd_free(mm, x) do { } while (0)
3275 #define pgd_populate(mm, pmd, pte) BUG()
3276 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3277
3278 #endif
3279
3280 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3281 index 22dadeb..f6c2be4 100644
3282 --- a/arch/parisc/include/asm/pgtable.h
3283 +++ b/arch/parisc/include/asm/pgtable.h
3284 @@ -210,6 +210,17 @@ struct vm_area_struct;
3285 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3286 #define PAGE_COPY PAGE_EXECREAD
3287 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3288 +
3289 +#ifdef CONFIG_PAX_PAGEEXEC
3290 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3291 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3292 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3293 +#else
3294 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3295 +# define PAGE_COPY_NOEXEC PAGE_COPY
3296 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3297 +#endif
3298 +
3299 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3300 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3301 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3302 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3303 index 5e34ccf..672bc9c 100644
3304 --- a/arch/parisc/kernel/module.c
3305 +++ b/arch/parisc/kernel/module.c
3306 @@ -98,16 +98,38 @@
3307
3308 /* three functions to determine where in the module core
3309 * or init pieces the location is */
3310 +static inline int in_init_rx(struct module *me, void *loc)
3311 +{
3312 + return (loc >= me->module_init_rx &&
3313 + loc < (me->module_init_rx + me->init_size_rx));
3314 +}
3315 +
3316 +static inline int in_init_rw(struct module *me, void *loc)
3317 +{
3318 + return (loc >= me->module_init_rw &&
3319 + loc < (me->module_init_rw + me->init_size_rw));
3320 +}
3321 +
3322 static inline int in_init(struct module *me, void *loc)
3323 {
3324 - return (loc >= me->module_init &&
3325 - loc <= (me->module_init + me->init_size));
3326 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3327 +}
3328 +
3329 +static inline int in_core_rx(struct module *me, void *loc)
3330 +{
3331 + return (loc >= me->module_core_rx &&
3332 + loc < (me->module_core_rx + me->core_size_rx));
3333 +}
3334 +
3335 +static inline int in_core_rw(struct module *me, void *loc)
3336 +{
3337 + return (loc >= me->module_core_rw &&
3338 + loc < (me->module_core_rw + me->core_size_rw));
3339 }
3340
3341 static inline int in_core(struct module *me, void *loc)
3342 {
3343 - return (loc >= me->module_core &&
3344 - loc <= (me->module_core + me->core_size));
3345 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3346 }
3347
3348 static inline int in_local(struct module *me, void *loc)
3349 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3350 }
3351
3352 /* align things a bit */
3353 - me->core_size = ALIGN(me->core_size, 16);
3354 - me->arch.got_offset = me->core_size;
3355 - me->core_size += gots * sizeof(struct got_entry);
3356 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3357 + me->arch.got_offset = me->core_size_rw;
3358 + me->core_size_rw += gots * sizeof(struct got_entry);
3359
3360 - me->core_size = ALIGN(me->core_size, 16);
3361 - me->arch.fdesc_offset = me->core_size;
3362 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3363 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3364 + me->arch.fdesc_offset = me->core_size_rw;
3365 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3366
3367 me->arch.got_max = gots;
3368 me->arch.fdesc_max = fdescs;
3369 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3370
3371 BUG_ON(value == 0);
3372
3373 - got = me->module_core + me->arch.got_offset;
3374 + got = me->module_core_rw + me->arch.got_offset;
3375 for (i = 0; got[i].addr; i++)
3376 if (got[i].addr == value)
3377 goto out;
3378 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3379 #ifdef CONFIG_64BIT
3380 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3381 {
3382 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3383 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3384
3385 if (!value) {
3386 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3387 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3388
3389 /* Create new one */
3390 fdesc->addr = value;
3391 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3392 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3393 return (Elf_Addr)fdesc;
3394 }
3395 #endif /* CONFIG_64BIT */
3396 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3397
3398 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3399 end = table + sechdrs[me->arch.unwind_section].sh_size;
3400 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3401 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3402
3403 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3404 me->arch.unwind_section, table, end, gp);
3405 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3406 index c9b9322..02d8940 100644
3407 --- a/arch/parisc/kernel/sys_parisc.c
3408 +++ b/arch/parisc/kernel/sys_parisc.c
3409 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3410 /* At this point: (!vma || addr < vma->vm_end). */
3411 if (TASK_SIZE - len < addr)
3412 return -ENOMEM;
3413 - if (!vma || addr + len <= vma->vm_start)
3414 + if (check_heap_stack_gap(vma, addr, len))
3415 return addr;
3416 addr = vma->vm_end;
3417 }
3418 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3419 /* At this point: (!vma || addr < vma->vm_end). */
3420 if (TASK_SIZE - len < addr)
3421 return -ENOMEM;
3422 - if (!vma || addr + len <= vma->vm_start)
3423 + if (check_heap_stack_gap(vma, addr, len))
3424 return addr;
3425 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3426 if (addr < vma->vm_end) /* handle wraparound */
3427 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3428 if (flags & MAP_FIXED)
3429 return addr;
3430 if (!addr)
3431 - addr = TASK_UNMAPPED_BASE;
3432 + addr = current->mm->mmap_base;
3433
3434 if (filp) {
3435 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3436 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3437 index f19e660..414fe24 100644
3438 --- a/arch/parisc/kernel/traps.c
3439 +++ b/arch/parisc/kernel/traps.c
3440 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3441
3442 down_read(&current->mm->mmap_sem);
3443 vma = find_vma(current->mm,regs->iaoq[0]);
3444 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3445 - && (vma->vm_flags & VM_EXEC)) {
3446 -
3447 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3448 fault_address = regs->iaoq[0];
3449 fault_space = regs->iasq[0];
3450
3451 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3452 index 18162ce..94de376 100644
3453 --- a/arch/parisc/mm/fault.c
3454 +++ b/arch/parisc/mm/fault.c
3455 @@ -15,6 +15,7 @@
3456 #include <linux/sched.h>
3457 #include <linux/interrupt.h>
3458 #include <linux/module.h>
3459 +#include <linux/unistd.h>
3460
3461 #include <asm/uaccess.h>
3462 #include <asm/traps.h>
3463 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3464 static unsigned long
3465 parisc_acctyp(unsigned long code, unsigned int inst)
3466 {
3467 - if (code == 6 || code == 16)
3468 + if (code == 6 || code == 7 || code == 16)
3469 return VM_EXEC;
3470
3471 switch (inst & 0xf0000000) {
3472 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3473 }
3474 #endif
3475
3476 +#ifdef CONFIG_PAX_PAGEEXEC
3477 +/*
3478 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3479 + *
3480 + * returns 1 when task should be killed
3481 + * 2 when rt_sigreturn trampoline was detected
3482 + * 3 when unpatched PLT trampoline was detected
3483 + */
3484 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3485 +{
3486 +
3487 +#ifdef CONFIG_PAX_EMUPLT
3488 + int err;
3489 +
3490 + do { /* PaX: unpatched PLT emulation */
3491 + unsigned int bl, depwi;
3492 +
3493 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3494 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3495 +
3496 + if (err)
3497 + break;
3498 +
3499 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3500 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3501 +
3502 + err = get_user(ldw, (unsigned int *)addr);
3503 + err |= get_user(bv, (unsigned int *)(addr+4));
3504 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3505 +
3506 + if (err)
3507 + break;
3508 +
3509 + if (ldw == 0x0E801096U &&
3510 + bv == 0xEAC0C000U &&
3511 + ldw2 == 0x0E881095U)
3512 + {
3513 + unsigned int resolver, map;
3514 +
3515 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3516 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3517 + if (err)
3518 + break;
3519 +
3520 + regs->gr[20] = instruction_pointer(regs)+8;
3521 + regs->gr[21] = map;
3522 + regs->gr[22] = resolver;
3523 + regs->iaoq[0] = resolver | 3UL;
3524 + regs->iaoq[1] = regs->iaoq[0] + 4;
3525 + return 3;
3526 + }
3527 + }
3528 + } while (0);
3529 +#endif
3530 +
3531 +#ifdef CONFIG_PAX_EMUTRAMP
3532 +
3533 +#ifndef CONFIG_PAX_EMUSIGRT
3534 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3535 + return 1;
3536 +#endif
3537 +
3538 + do { /* PaX: rt_sigreturn emulation */
3539 + unsigned int ldi1, ldi2, bel, nop;
3540 +
3541 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3542 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3543 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3544 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3545 +
3546 + if (err)
3547 + break;
3548 +
3549 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3550 + ldi2 == 0x3414015AU &&
3551 + bel == 0xE4008200U &&
3552 + nop == 0x08000240U)
3553 + {
3554 + regs->gr[25] = (ldi1 & 2) >> 1;
3555 + regs->gr[20] = __NR_rt_sigreturn;
3556 + regs->gr[31] = regs->iaoq[1] + 16;
3557 + regs->sr[0] = regs->iasq[1];
3558 + regs->iaoq[0] = 0x100UL;
3559 + regs->iaoq[1] = regs->iaoq[0] + 4;
3560 + regs->iasq[0] = regs->sr[2];
3561 + regs->iasq[1] = regs->sr[2];
3562 + return 2;
3563 + }
3564 + } while (0);
3565 +#endif
3566 +
3567 + return 1;
3568 +}
3569 +
3570 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3571 +{
3572 + unsigned long i;
3573 +
3574 + printk(KERN_ERR "PAX: bytes at PC: ");
3575 + for (i = 0; i < 5; i++) {
3576 + unsigned int c;
3577 + if (get_user(c, (unsigned int *)pc+i))
3578 + printk(KERN_CONT "???????? ");
3579 + else
3580 + printk(KERN_CONT "%08x ", c);
3581 + }
3582 + printk("\n");
3583 +}
3584 +#endif
3585 +
3586 int fixup_exception(struct pt_regs *regs)
3587 {
3588 const struct exception_table_entry *fix;
3589 @@ -192,8 +303,33 @@ good_area:
3590
3591 acc_type = parisc_acctyp(code,regs->iir);
3592
3593 - if ((vma->vm_flags & acc_type) != acc_type)
3594 + if ((vma->vm_flags & acc_type) != acc_type) {
3595 +
3596 +#ifdef CONFIG_PAX_PAGEEXEC
3597 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3598 + (address & ~3UL) == instruction_pointer(regs))
3599 + {
3600 + up_read(&mm->mmap_sem);
3601 + switch (pax_handle_fetch_fault(regs)) {
3602 +
3603 +#ifdef CONFIG_PAX_EMUPLT
3604 + case 3:
3605 + return;
3606 +#endif
3607 +
3608 +#ifdef CONFIG_PAX_EMUTRAMP
3609 + case 2:
3610 + return;
3611 +#endif
3612 +
3613 + }
3614 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3615 + do_group_exit(SIGKILL);
3616 + }
3617 +#endif
3618 +
3619 goto bad_area;
3620 + }
3621
3622 /*
3623 * If for any reason at all we couldn't handle the fault, make
3624 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3625 index 02e41b5..ec6e26c 100644
3626 --- a/arch/powerpc/include/asm/atomic.h
3627 +++ b/arch/powerpc/include/asm/atomic.h
3628 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3629
3630 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3631
3632 +#define atomic64_read_unchecked(v) atomic64_read(v)
3633 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3634 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3635 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3636 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3637 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3638 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3639 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3640 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3641 +
3642 #endif /* __powerpc64__ */
3643
3644 #endif /* __KERNEL__ */
3645 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3646 index 4b50941..5605819 100644
3647 --- a/arch/powerpc/include/asm/cache.h
3648 +++ b/arch/powerpc/include/asm/cache.h
3649 @@ -3,6 +3,7 @@
3650
3651 #ifdef __KERNEL__
3652
3653 +#include <linux/const.h>
3654
3655 /* bytes per L1 cache line */
3656 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3657 @@ -22,7 +23,7 @@
3658 #define L1_CACHE_SHIFT 7
3659 #endif
3660
3661 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3662 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3663
3664 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3665
3666 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3667 index 3bf9cca..e7457d0 100644
3668 --- a/arch/powerpc/include/asm/elf.h
3669 +++ b/arch/powerpc/include/asm/elf.h
3670 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3671 the loader. We need to make sure that it is out of the way of the program
3672 that it will "exec", and that there is sufficient room for the brk. */
3673
3674 -extern unsigned long randomize_et_dyn(unsigned long base);
3675 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3676 +#define ELF_ET_DYN_BASE (0x20000000)
3677 +
3678 +#ifdef CONFIG_PAX_ASLR
3679 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3680 +
3681 +#ifdef __powerpc64__
3682 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3683 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3684 +#else
3685 +#define PAX_DELTA_MMAP_LEN 15
3686 +#define PAX_DELTA_STACK_LEN 15
3687 +#endif
3688 +#endif
3689
3690 /*
3691 * Our registers are always unsigned longs, whether we're a 32 bit
3692 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3693 (0x7ff >> (PAGE_SHIFT - 12)) : \
3694 (0x3ffff >> (PAGE_SHIFT - 12)))
3695
3696 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3697 -#define arch_randomize_brk arch_randomize_brk
3698 -
3699 #endif /* __KERNEL__ */
3700
3701 /*
3702 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3703 index bca8fdc..61e9580 100644
3704 --- a/arch/powerpc/include/asm/kmap_types.h
3705 +++ b/arch/powerpc/include/asm/kmap_types.h
3706 @@ -27,6 +27,7 @@ enum km_type {
3707 KM_PPC_SYNC_PAGE,
3708 KM_PPC_SYNC_ICACHE,
3709 KM_KDB,
3710 + KM_CLEARPAGE,
3711 KM_TYPE_NR
3712 };
3713
3714 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3715 index d4a7f64..451de1c 100644
3716 --- a/arch/powerpc/include/asm/mman.h
3717 +++ b/arch/powerpc/include/asm/mman.h
3718 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3719 }
3720 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3721
3722 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3723 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3724 {
3725 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3726 }
3727 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3728 index f072e97..b436dee 100644
3729 --- a/arch/powerpc/include/asm/page.h
3730 +++ b/arch/powerpc/include/asm/page.h
3731 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3732 * and needs to be executable. This means the whole heap ends
3733 * up being executable.
3734 */
3735 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3736 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3737 +#define VM_DATA_DEFAULT_FLAGS32 \
3738 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3739 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3740
3741 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3742 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3743 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3744 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3745 #endif
3746
3747 +#define ktla_ktva(addr) (addr)
3748 +#define ktva_ktla(addr) (addr)
3749 +
3750 /*
3751 * Use the top bit of the higher-level page table entries to indicate whether
3752 * the entries we point to contain hugepages. This works because we know that
3753 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3754 index fed85e6..da5c71b 100644
3755 --- a/arch/powerpc/include/asm/page_64.h
3756 +++ b/arch/powerpc/include/asm/page_64.h
3757 @@ -146,15 +146,18 @@ do { \
3758 * stack by default, so in the absence of a PT_GNU_STACK program header
3759 * we turn execute permission off.
3760 */
3761 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3762 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3763 +#define VM_STACK_DEFAULT_FLAGS32 \
3764 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3765 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3766
3767 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3768 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3769
3770 +#ifndef CONFIG_PAX_PAGEEXEC
3771 #define VM_STACK_DEFAULT_FLAGS \
3772 (is_32bit_task() ? \
3773 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3774 +#endif
3775
3776 #include <asm-generic/getorder.h>
3777
3778 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3779 index 292725c..f87ae14 100644
3780 --- a/arch/powerpc/include/asm/pgalloc-64.h
3781 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3782 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3783 #ifndef CONFIG_PPC_64K_PAGES
3784
3785 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3786 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3787
3788 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3789 {
3790 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3791 pud_set(pud, (unsigned long)pmd);
3792 }
3793
3794 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3795 +{
3796 + pud_populate(mm, pud, pmd);
3797 +}
3798 +
3799 #define pmd_populate(mm, pmd, pte_page) \
3800 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3801 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3802 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3803 #else /* CONFIG_PPC_64K_PAGES */
3804
3805 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3806 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3807
3808 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3809 pte_t *pte)
3810 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3811 index 2e0e411..7899c68 100644
3812 --- a/arch/powerpc/include/asm/pgtable.h
3813 +++ b/arch/powerpc/include/asm/pgtable.h
3814 @@ -2,6 +2,7 @@
3815 #define _ASM_POWERPC_PGTABLE_H
3816 #ifdef __KERNEL__
3817
3818 +#include <linux/const.h>
3819 #ifndef __ASSEMBLY__
3820 #include <asm/processor.h> /* For TASK_SIZE */
3821 #include <asm/mmu.h>
3822 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3823 index 4aad413..85d86bf 100644
3824 --- a/arch/powerpc/include/asm/pte-hash32.h
3825 +++ b/arch/powerpc/include/asm/pte-hash32.h
3826 @@ -21,6 +21,7 @@
3827 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3828 #define _PAGE_USER 0x004 /* usermode access allowed */
3829 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3830 +#define _PAGE_EXEC _PAGE_GUARDED
3831 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3832 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3833 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3834 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3835 index 7fdc2c0..e47a9b02d3 100644
3836 --- a/arch/powerpc/include/asm/reg.h
3837 +++ b/arch/powerpc/include/asm/reg.h
3838 @@ -212,6 +212,7 @@
3839 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3840 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3841 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3842 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3843 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3844 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3845 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3846 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
3847 index c377457..3c69fbc 100644
3848 --- a/arch/powerpc/include/asm/system.h
3849 +++ b/arch/powerpc/include/asm/system.h
3850 @@ -539,7 +539,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
3851 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
3852 #endif
3853
3854 -extern unsigned long arch_align_stack(unsigned long sp);
3855 +#define arch_align_stack(x) ((x) & ~0xfUL)
3856
3857 /* Used in very early kernel initialization. */
3858 extern unsigned long reloc_offset(void);
3859 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3860 index 96471494..60ed5a2 100644
3861 --- a/arch/powerpc/include/asm/thread_info.h
3862 +++ b/arch/powerpc/include/asm/thread_info.h
3863 @@ -104,13 +104,15 @@ static inline struct thread_info *current_thread_info(void)
3864 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3865 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3866 #define TIF_SINGLESTEP 8 /* singlestepping active */
3867 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3868 #define TIF_SECCOMP 10 /* secure computing */
3869 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3870 #define TIF_NOERROR 12 /* Force successful syscall return */
3871 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3872 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3873 #define TIF_RUNLATCH 16 /* Is the runlatch enabled? */
3874 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
3875 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3876 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3877
3878 /* as above, but as bit values */
3879 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3880 @@ -128,8 +130,11 @@ static inline struct thread_info *current_thread_info(void)
3881 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3882 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3883 #define _TIF_RUNLATCH (1<<TIF_RUNLATCH)
3884 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3885 +
3886 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3887 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3888 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT \
3889 + _TIF_GRSEC_SETXID)
3890
3891 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3892 _TIF_NOTIFY_RESUME)
3893 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3894 index bd0fb84..a42a14b 100644
3895 --- a/arch/powerpc/include/asm/uaccess.h
3896 +++ b/arch/powerpc/include/asm/uaccess.h
3897 @@ -13,6 +13,8 @@
3898 #define VERIFY_READ 0
3899 #define VERIFY_WRITE 1
3900
3901 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3902 +
3903 /*
3904 * The fs value determines whether argument validity checking should be
3905 * performed or not. If get_fs() == USER_DS, checking is performed, with
3906 @@ -327,52 +329,6 @@ do { \
3907 extern unsigned long __copy_tofrom_user(void __user *to,
3908 const void __user *from, unsigned long size);
3909
3910 -#ifndef __powerpc64__
3911 -
3912 -static inline unsigned long copy_from_user(void *to,
3913 - const void __user *from, unsigned long n)
3914 -{
3915 - unsigned long over;
3916 -
3917 - if (access_ok(VERIFY_READ, from, n))
3918 - return __copy_tofrom_user((__force void __user *)to, from, n);
3919 - if ((unsigned long)from < TASK_SIZE) {
3920 - over = (unsigned long)from + n - TASK_SIZE;
3921 - return __copy_tofrom_user((__force void __user *)to, from,
3922 - n - over) + over;
3923 - }
3924 - return n;
3925 -}
3926 -
3927 -static inline unsigned long copy_to_user(void __user *to,
3928 - const void *from, unsigned long n)
3929 -{
3930 - unsigned long over;
3931 -
3932 - if (access_ok(VERIFY_WRITE, to, n))
3933 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3934 - if ((unsigned long)to < TASK_SIZE) {
3935 - over = (unsigned long)to + n - TASK_SIZE;
3936 - return __copy_tofrom_user(to, (__force void __user *)from,
3937 - n - over) + over;
3938 - }
3939 - return n;
3940 -}
3941 -
3942 -#else /* __powerpc64__ */
3943 -
3944 -#define __copy_in_user(to, from, size) \
3945 - __copy_tofrom_user((to), (from), (size))
3946 -
3947 -extern unsigned long copy_from_user(void *to, const void __user *from,
3948 - unsigned long n);
3949 -extern unsigned long copy_to_user(void __user *to, const void *from,
3950 - unsigned long n);
3951 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
3952 - unsigned long n);
3953 -
3954 -#endif /* __powerpc64__ */
3955 -
3956 static inline unsigned long __copy_from_user_inatomic(void *to,
3957 const void __user *from, unsigned long n)
3958 {
3959 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
3960 if (ret == 0)
3961 return 0;
3962 }
3963 +
3964 + if (!__builtin_constant_p(n))
3965 + check_object_size(to, n, false);
3966 +
3967 return __copy_tofrom_user((__force void __user *)to, from, n);
3968 }
3969
3970 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
3971 if (ret == 0)
3972 return 0;
3973 }
3974 +
3975 + if (!__builtin_constant_p(n))
3976 + check_object_size(from, n, true);
3977 +
3978 return __copy_tofrom_user(to, (__force const void __user *)from, n);
3979 }
3980
3981 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
3982 return __copy_to_user_inatomic(to, from, size);
3983 }
3984
3985 +#ifndef __powerpc64__
3986 +
3987 +static inline unsigned long __must_check copy_from_user(void *to,
3988 + const void __user *from, unsigned long n)
3989 +{
3990 + unsigned long over;
3991 +
3992 + if ((long)n < 0)
3993 + return n;
3994 +
3995 + if (access_ok(VERIFY_READ, from, n)) {
3996 + if (!__builtin_constant_p(n))
3997 + check_object_size(to, n, false);
3998 + return __copy_tofrom_user((__force void __user *)to, from, n);
3999 + }
4000 + if ((unsigned long)from < TASK_SIZE) {
4001 + over = (unsigned long)from + n - TASK_SIZE;
4002 + if (!__builtin_constant_p(n - over))
4003 + check_object_size(to, n - over, false);
4004 + return __copy_tofrom_user((__force void __user *)to, from,
4005 + n - over) + over;
4006 + }
4007 + return n;
4008 +}
4009 +
4010 +static inline unsigned long __must_check copy_to_user(void __user *to,
4011 + const void *from, unsigned long n)
4012 +{
4013 + unsigned long over;
4014 +
4015 + if ((long)n < 0)
4016 + return n;
4017 +
4018 + if (access_ok(VERIFY_WRITE, to, n)) {
4019 + if (!__builtin_constant_p(n))
4020 + check_object_size(from, n, true);
4021 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4022 + }
4023 + if ((unsigned long)to < TASK_SIZE) {
4024 + over = (unsigned long)to + n - TASK_SIZE;
4025 + if (!__builtin_constant_p(n))
4026 + check_object_size(from, n - over, true);
4027 + return __copy_tofrom_user(to, (__force void __user *)from,
4028 + n - over) + over;
4029 + }
4030 + return n;
4031 +}
4032 +
4033 +#else /* __powerpc64__ */
4034 +
4035 +#define __copy_in_user(to, from, size) \
4036 + __copy_tofrom_user((to), (from), (size))
4037 +
4038 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4039 +{
4040 + if ((long)n < 0 || n > INT_MAX)
4041 + return n;
4042 +
4043 + if (!__builtin_constant_p(n))
4044 + check_object_size(to, n, false);
4045 +
4046 + if (likely(access_ok(VERIFY_READ, from, n)))
4047 + n = __copy_from_user(to, from, n);
4048 + else
4049 + memset(to, 0, n);
4050 + return n;
4051 +}
4052 +
4053 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4054 +{
4055 + if ((long)n < 0 || n > INT_MAX)
4056 + return n;
4057 +
4058 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4059 + if (!__builtin_constant_p(n))
4060 + check_object_size(from, n, true);
4061 + n = __copy_to_user(to, from, n);
4062 + }
4063 + return n;
4064 +}
4065 +
4066 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4067 + unsigned long n);
4068 +
4069 +#endif /* __powerpc64__ */
4070 +
4071 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4072
4073 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4074 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4075 index 429983c..7af363b 100644
4076 --- a/arch/powerpc/kernel/exceptions-64e.S
4077 +++ b/arch/powerpc/kernel/exceptions-64e.S
4078 @@ -587,6 +587,7 @@ storage_fault_common:
4079 std r14,_DAR(r1)
4080 std r15,_DSISR(r1)
4081 addi r3,r1,STACK_FRAME_OVERHEAD
4082 + bl .save_nvgprs
4083 mr r4,r14
4084 mr r5,r15
4085 ld r14,PACA_EXGEN+EX_R14(r13)
4086 @@ -596,8 +597,7 @@ storage_fault_common:
4087 cmpdi r3,0
4088 bne- 1f
4089 b .ret_from_except_lite
4090 -1: bl .save_nvgprs
4091 - mr r5,r3
4092 +1: mr r5,r3
4093 addi r3,r1,STACK_FRAME_OVERHEAD
4094 ld r4,_DAR(r1)
4095 bl .bad_page_fault
4096 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4097 index 15c5a4f..22a4000 100644
4098 --- a/arch/powerpc/kernel/exceptions-64s.S
4099 +++ b/arch/powerpc/kernel/exceptions-64s.S
4100 @@ -1004,10 +1004,10 @@ handle_page_fault:
4101 11: ld r4,_DAR(r1)
4102 ld r5,_DSISR(r1)
4103 addi r3,r1,STACK_FRAME_OVERHEAD
4104 + bl .save_nvgprs
4105 bl .do_page_fault
4106 cmpdi r3,0
4107 beq+ 13f
4108 - bl .save_nvgprs
4109 mr r5,r3
4110 addi r3,r1,STACK_FRAME_OVERHEAD
4111 lwz r4,_DAR(r1)
4112 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
4113 index 01e2877..a1ba360 100644
4114 --- a/arch/powerpc/kernel/irq.c
4115 +++ b/arch/powerpc/kernel/irq.c
4116 @@ -560,9 +560,6 @@ struct irq_host *irq_alloc_host(struct device_node *of_node,
4117 host->ops = ops;
4118 host->of_node = of_node_get(of_node);
4119
4120 - if (host->ops->match == NULL)
4121 - host->ops->match = default_irq_host_match;
4122 -
4123 raw_spin_lock_irqsave(&irq_big_lock, flags);
4124
4125 /* If it's a legacy controller, check for duplicates and
4126 @@ -635,7 +632,12 @@ struct irq_host *irq_find_host(struct device_node *node)
4127 */
4128 raw_spin_lock_irqsave(&irq_big_lock, flags);
4129 list_for_each_entry(h, &irq_hosts, link)
4130 - if (h->ops->match(h, node)) {
4131 + if (h->ops->match) {
4132 + if (h->ops->match(h, node)) {
4133 + found = h;
4134 + break;
4135 + }
4136 + } else if (default_irq_host_match(h, node)) {
4137 found = h;
4138 break;
4139 }
4140 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4141 index 0b6d796..d760ddb 100644
4142 --- a/arch/powerpc/kernel/module_32.c
4143 +++ b/arch/powerpc/kernel/module_32.c
4144 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4145 me->arch.core_plt_section = i;
4146 }
4147 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4148 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4149 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4150 return -ENOEXEC;
4151 }
4152
4153 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4154
4155 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4156 /* Init, or core PLT? */
4157 - if (location >= mod->module_core
4158 - && location < mod->module_core + mod->core_size)
4159 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4160 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4161 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4162 - else
4163 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4164 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4165 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4166 + else {
4167 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4168 + return ~0UL;
4169 + }
4170
4171 /* Find this entry, or if that fails, the next avail. entry */
4172 while (entry->jump[0]) {
4173 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4174 index d817ab0..b23b18e 100644
4175 --- a/arch/powerpc/kernel/process.c
4176 +++ b/arch/powerpc/kernel/process.c
4177 @@ -676,8 +676,8 @@ void show_regs(struct pt_regs * regs)
4178 * Lookup NIP late so we have the best change of getting the
4179 * above info out without failing
4180 */
4181 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4182 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4183 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4184 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4185 #endif
4186 show_stack(current, (unsigned long *) regs->gpr[1]);
4187 if (!user_mode(regs))
4188 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4189 newsp = stack[0];
4190 ip = stack[STACK_FRAME_LR_SAVE];
4191 if (!firstframe || ip != lr) {
4192 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4193 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4194 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4195 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4196 - printk(" (%pS)",
4197 + printk(" (%pA)",
4198 (void *)current->ret_stack[curr_frame].ret);
4199 curr_frame--;
4200 }
4201 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4202 struct pt_regs *regs = (struct pt_regs *)
4203 (sp + STACK_FRAME_OVERHEAD);
4204 lr = regs->link;
4205 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4206 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4207 regs->trap, (void *)regs->nip, (void *)lr);
4208 firstframe = 1;
4209 }
4210 @@ -1279,58 +1279,3 @@ void thread_info_cache_init(void)
4211 }
4212
4213 #endif /* THREAD_SHIFT < PAGE_SHIFT */
4214 -
4215 -unsigned long arch_align_stack(unsigned long sp)
4216 -{
4217 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4218 - sp -= get_random_int() & ~PAGE_MASK;
4219 - return sp & ~0xf;
4220 -}
4221 -
4222 -static inline unsigned long brk_rnd(void)
4223 -{
4224 - unsigned long rnd = 0;
4225 -
4226 - /* 8MB for 32bit, 1GB for 64bit */
4227 - if (is_32bit_task())
4228 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4229 - else
4230 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4231 -
4232 - return rnd << PAGE_SHIFT;
4233 -}
4234 -
4235 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4236 -{
4237 - unsigned long base = mm->brk;
4238 - unsigned long ret;
4239 -
4240 -#ifdef CONFIG_PPC_STD_MMU_64
4241 - /*
4242 - * If we are using 1TB segments and we are allowed to randomise
4243 - * the heap, we can put it above 1TB so it is backed by a 1TB
4244 - * segment. Otherwise the heap will be in the bottom 1TB
4245 - * which always uses 256MB segments and this may result in a
4246 - * performance penalty.
4247 - */
4248 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4249 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4250 -#endif
4251 -
4252 - ret = PAGE_ALIGN(base + brk_rnd());
4253 -
4254 - if (ret < mm->brk)
4255 - return mm->brk;
4256 -
4257 - return ret;
4258 -}
4259 -
4260 -unsigned long randomize_et_dyn(unsigned long base)
4261 -{
4262 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4263 -
4264 - if (ret < base)
4265 - return base;
4266 -
4267 - return ret;
4268 -}
4269 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4270 index 5b43325..94a5bb4 100644
4271 --- a/arch/powerpc/kernel/ptrace.c
4272 +++ b/arch/powerpc/kernel/ptrace.c
4273 @@ -1702,6 +1702,10 @@ long arch_ptrace(struct task_struct *child, long request,
4274 return ret;
4275 }
4276
4277 +#ifdef CONFIG_GRKERNSEC_SETXID
4278 +extern void gr_delayed_cred_worker(void);
4279 +#endif
4280 +
4281 /*
4282 * We must return the syscall number to actually look up in the table.
4283 * This can be -1L to skip running any syscall at all.
4284 @@ -1712,6 +1716,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4285
4286 secure_computing(regs->gpr[0]);
4287
4288 +#ifdef CONFIG_GRKERNSEC_SETXID
4289 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4290 + gr_delayed_cred_worker();
4291 +#endif
4292 +
4293 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4294 tracehook_report_syscall_entry(regs))
4295 /*
4296 @@ -1746,6 +1755,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4297 {
4298 int step;
4299
4300 +#ifdef CONFIG_GRKERNSEC_SETXID
4301 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4302 + gr_delayed_cred_worker();
4303 +#endif
4304 +
4305 audit_syscall_exit(regs);
4306
4307 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4308 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4309 index 836a5a1..27289a3 100644
4310 --- a/arch/powerpc/kernel/signal_32.c
4311 +++ b/arch/powerpc/kernel/signal_32.c
4312 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4313 /* Save user registers on the stack */
4314 frame = &rt_sf->uc.uc_mcontext;
4315 addr = frame;
4316 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4317 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4318 if (save_user_regs(regs, frame, 0, 1))
4319 goto badframe;
4320 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4321 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4322 index a50b5ec..547078a 100644
4323 --- a/arch/powerpc/kernel/signal_64.c
4324 +++ b/arch/powerpc/kernel/signal_64.c
4325 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4326 current->thread.fpscr.val = 0;
4327
4328 /* Set up to return from userspace. */
4329 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4330 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4331 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4332 } else {
4333 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4334 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4335 index c091527..5592625 100644
4336 --- a/arch/powerpc/kernel/traps.c
4337 +++ b/arch/powerpc/kernel/traps.c
4338 @@ -131,6 +131,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4339 return flags;
4340 }
4341
4342 +extern void gr_handle_kernel_exploit(void);
4343 +
4344 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4345 int signr)
4346 {
4347 @@ -178,6 +180,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4348 panic("Fatal exception in interrupt");
4349 if (panic_on_oops)
4350 panic("Fatal exception");
4351 +
4352 + gr_handle_kernel_exploit();
4353 +
4354 do_exit(signr);
4355 }
4356
4357 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4358 index 7d14bb6..1305601 100644
4359 --- a/arch/powerpc/kernel/vdso.c
4360 +++ b/arch/powerpc/kernel/vdso.c
4361 @@ -35,6 +35,7 @@
4362 #include <asm/firmware.h>
4363 #include <asm/vdso.h>
4364 #include <asm/vdso_datapage.h>
4365 +#include <asm/mman.h>
4366
4367 #include "setup.h"
4368
4369 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4370 vdso_base = VDSO32_MBASE;
4371 #endif
4372
4373 - current->mm->context.vdso_base = 0;
4374 + current->mm->context.vdso_base = ~0UL;
4375
4376 /* vDSO has a problem and was disabled, just don't "enable" it for the
4377 * process
4378 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4379 vdso_base = get_unmapped_area(NULL, vdso_base,
4380 (vdso_pages << PAGE_SHIFT) +
4381 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4382 - 0, 0);
4383 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4384 if (IS_ERR_VALUE(vdso_base)) {
4385 rc = vdso_base;
4386 goto fail_mmapsem;
4387 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4388 index 5eea6f3..5d10396 100644
4389 --- a/arch/powerpc/lib/usercopy_64.c
4390 +++ b/arch/powerpc/lib/usercopy_64.c
4391 @@ -9,22 +9,6 @@
4392 #include <linux/module.h>
4393 #include <asm/uaccess.h>
4394
4395 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4396 -{
4397 - if (likely(access_ok(VERIFY_READ, from, n)))
4398 - n = __copy_from_user(to, from, n);
4399 - else
4400 - memset(to, 0, n);
4401 - return n;
4402 -}
4403 -
4404 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4405 -{
4406 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4407 - n = __copy_to_user(to, from, n);
4408 - return n;
4409 -}
4410 -
4411 unsigned long copy_in_user(void __user *to, const void __user *from,
4412 unsigned long n)
4413 {
4414 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4415 return n;
4416 }
4417
4418 -EXPORT_SYMBOL(copy_from_user);
4419 -EXPORT_SYMBOL(copy_to_user);
4420 EXPORT_SYMBOL(copy_in_user);
4421
4422 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4423 index 2f0d1b0..36fb5cc 100644
4424 --- a/arch/powerpc/mm/fault.c
4425 +++ b/arch/powerpc/mm/fault.c
4426 @@ -32,6 +32,10 @@
4427 #include <linux/perf_event.h>
4428 #include <linux/magic.h>
4429 #include <linux/ratelimit.h>
4430 +#include <linux/slab.h>
4431 +#include <linux/pagemap.h>
4432 +#include <linux/compiler.h>
4433 +#include <linux/unistd.h>
4434
4435 #include <asm/firmware.h>
4436 #include <asm/page.h>
4437 @@ -43,6 +47,7 @@
4438 #include <asm/tlbflush.h>
4439 #include <asm/siginfo.h>
4440 #include <mm/mmu_decl.h>
4441 +#include <asm/ptrace.h>
4442
4443 #include "icswx.h"
4444
4445 @@ -68,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4446 }
4447 #endif
4448
4449 +#ifdef CONFIG_PAX_PAGEEXEC
4450 +/*
4451 + * PaX: decide what to do with offenders (regs->nip = fault address)
4452 + *
4453 + * returns 1 when task should be killed
4454 + */
4455 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4456 +{
4457 + return 1;
4458 +}
4459 +
4460 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4461 +{
4462 + unsigned long i;
4463 +
4464 + printk(KERN_ERR "PAX: bytes at PC: ");
4465 + for (i = 0; i < 5; i++) {
4466 + unsigned int c;
4467 + if (get_user(c, (unsigned int __user *)pc+i))
4468 + printk(KERN_CONT "???????? ");
4469 + else
4470 + printk(KERN_CONT "%08x ", c);
4471 + }
4472 + printk("\n");
4473 +}
4474 +#endif
4475 +
4476 /*
4477 * Check whether the instruction at regs->nip is a store using
4478 * an update addressing form which will update r1.
4479 @@ -138,7 +170,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4480 * indicate errors in DSISR but can validly be set in SRR1.
4481 */
4482 if (trap == 0x400)
4483 - error_code &= 0x48200000;
4484 + error_code &= 0x58200000;
4485 else
4486 is_write = error_code & DSISR_ISSTORE;
4487 #else
4488 @@ -276,7 +308,7 @@ good_area:
4489 * "undefined". Of those that can be set, this is the only
4490 * one which seems bad.
4491 */
4492 - if (error_code & 0x10000000)
4493 + if (error_code & DSISR_GUARDED)
4494 /* Guarded storage error. */
4495 goto bad_area;
4496 #endif /* CONFIG_8xx */
4497 @@ -291,7 +323,7 @@ good_area:
4498 * processors use the same I/D cache coherency mechanism
4499 * as embedded.
4500 */
4501 - if (error_code & DSISR_PROTFAULT)
4502 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4503 goto bad_area;
4504 #endif /* CONFIG_PPC_STD_MMU */
4505
4506 @@ -360,6 +392,23 @@ bad_area:
4507 bad_area_nosemaphore:
4508 /* User mode accesses cause a SIGSEGV */
4509 if (user_mode(regs)) {
4510 +
4511 +#ifdef CONFIG_PAX_PAGEEXEC
4512 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4513 +#ifdef CONFIG_PPC_STD_MMU
4514 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4515 +#else
4516 + if (is_exec && regs->nip == address) {
4517 +#endif
4518 + switch (pax_handle_fetch_fault(regs)) {
4519 + }
4520 +
4521 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4522 + do_group_exit(SIGKILL);
4523 + }
4524 + }
4525 +#endif
4526 +
4527 _exception(SIGSEGV, regs, code, address);
4528 return 0;
4529 }
4530 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4531 index 67a42ed..1c7210c 100644
4532 --- a/arch/powerpc/mm/mmap_64.c
4533 +++ b/arch/powerpc/mm/mmap_64.c
4534 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4535 */
4536 if (mmap_is_legacy()) {
4537 mm->mmap_base = TASK_UNMAPPED_BASE;
4538 +
4539 +#ifdef CONFIG_PAX_RANDMMAP
4540 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4541 + mm->mmap_base += mm->delta_mmap;
4542 +#endif
4543 +
4544 mm->get_unmapped_area = arch_get_unmapped_area;
4545 mm->unmap_area = arch_unmap_area;
4546 } else {
4547 mm->mmap_base = mmap_base();
4548 +
4549 +#ifdef CONFIG_PAX_RANDMMAP
4550 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4551 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4552 +#endif
4553 +
4554 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4555 mm->unmap_area = arch_unmap_area_topdown;
4556 }
4557 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4558 index 73709f7..6b90313 100644
4559 --- a/arch/powerpc/mm/slice.c
4560 +++ b/arch/powerpc/mm/slice.c
4561 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4562 if ((mm->task_size - len) < addr)
4563 return 0;
4564 vma = find_vma(mm, addr);
4565 - return (!vma || (addr + len) <= vma->vm_start);
4566 + return check_heap_stack_gap(vma, addr, len);
4567 }
4568
4569 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4570 @@ -256,7 +256,7 @@ full_search:
4571 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4572 continue;
4573 }
4574 - if (!vma || addr + len <= vma->vm_start) {
4575 + if (check_heap_stack_gap(vma, addr, len)) {
4576 /*
4577 * Remember the place where we stopped the search:
4578 */
4579 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4580 }
4581 }
4582
4583 - addr = mm->mmap_base;
4584 - while (addr > len) {
4585 + if (mm->mmap_base < len)
4586 + addr = -ENOMEM;
4587 + else
4588 + addr = mm->mmap_base - len;
4589 +
4590 + while (!IS_ERR_VALUE(addr)) {
4591 /* Go down by chunk size */
4592 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4593 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4594
4595 /* Check for hit with different page size */
4596 mask = slice_range_to_mask(addr, len);
4597 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4598 * return with success:
4599 */
4600 vma = find_vma(mm, addr);
4601 - if (!vma || (addr + len) <= vma->vm_start) {
4602 + if (check_heap_stack_gap(vma, addr, len)) {
4603 /* remember the address as a hint for next time */
4604 if (use_cache)
4605 mm->free_area_cache = addr;
4606 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4607 mm->cached_hole_size = vma->vm_start - addr;
4608
4609 /* try just below the current vma->vm_start */
4610 - addr = vma->vm_start;
4611 + addr = skip_heap_stack_gap(vma, len);
4612 }
4613
4614 /*
4615 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4616 if (fixed && addr > (mm->task_size - len))
4617 return -EINVAL;
4618
4619 +#ifdef CONFIG_PAX_RANDMMAP
4620 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4621 + addr = 0;
4622 +#endif
4623 +
4624 /* If hint, make sure it matches our alignment restrictions */
4625 if (!fixed && addr) {
4626 addr = _ALIGN_UP(addr, 1ul << pshift);
4627 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4628 index 8517d2a..d2738d4 100644
4629 --- a/arch/s390/include/asm/atomic.h
4630 +++ b/arch/s390/include/asm/atomic.h
4631 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4632 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4633 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4634
4635 +#define atomic64_read_unchecked(v) atomic64_read(v)
4636 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4637 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4638 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4639 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4640 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4641 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4642 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4643 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4644 +
4645 #define smp_mb__before_atomic_dec() smp_mb()
4646 #define smp_mb__after_atomic_dec() smp_mb()
4647 #define smp_mb__before_atomic_inc() smp_mb()
4648 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4649 index 2a30d5a..5e5586f 100644
4650 --- a/arch/s390/include/asm/cache.h
4651 +++ b/arch/s390/include/asm/cache.h
4652 @@ -11,8 +11,10 @@
4653 #ifndef __ARCH_S390_CACHE_H
4654 #define __ARCH_S390_CACHE_H
4655
4656 -#define L1_CACHE_BYTES 256
4657 +#include <linux/const.h>
4658 +
4659 #define L1_CACHE_SHIFT 8
4660 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4661 #define NET_SKB_PAD 32
4662
4663 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4664 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4665 index 547f1a6..0b22b53 100644
4666 --- a/arch/s390/include/asm/elf.h
4667 +++ b/arch/s390/include/asm/elf.h
4668 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
4669 the loader. We need to make sure that it is out of the way of the program
4670 that it will "exec", and that there is sufficient room for the brk. */
4671
4672 -extern unsigned long randomize_et_dyn(unsigned long base);
4673 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4674 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4675 +
4676 +#ifdef CONFIG_PAX_ASLR
4677 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4678 +
4679 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4680 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4681 +#endif
4682
4683 /* This yields a mask that user programs can use to figure out what
4684 instruction set this CPU supports. */
4685 @@ -211,7 +217,4 @@ struct linux_binprm;
4686 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4687 int arch_setup_additional_pages(struct linux_binprm *, int);
4688
4689 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4690 -#define arch_randomize_brk arch_randomize_brk
4691 -
4692 #endif
4693 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
4694 index d73cc6b..1a296ad 100644
4695 --- a/arch/s390/include/asm/system.h
4696 +++ b/arch/s390/include/asm/system.h
4697 @@ -260,7 +260,7 @@ extern void (*_machine_restart)(char *command);
4698 extern void (*_machine_halt)(void);
4699 extern void (*_machine_power_off)(void);
4700
4701 -extern unsigned long arch_align_stack(unsigned long sp);
4702 +#define arch_align_stack(x) ((x) & ~0xfUL)
4703
4704 static inline int tprot(unsigned long addr)
4705 {
4706 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4707 index 2b23885..e136e31 100644
4708 --- a/arch/s390/include/asm/uaccess.h
4709 +++ b/arch/s390/include/asm/uaccess.h
4710 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
4711 copy_to_user(void __user *to, const void *from, unsigned long n)
4712 {
4713 might_fault();
4714 +
4715 + if ((long)n < 0)
4716 + return n;
4717 +
4718 if (access_ok(VERIFY_WRITE, to, n))
4719 n = __copy_to_user(to, from, n);
4720 return n;
4721 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4722 static inline unsigned long __must_check
4723 __copy_from_user(void *to, const void __user *from, unsigned long n)
4724 {
4725 + if ((long)n < 0)
4726 + return n;
4727 +
4728 if (__builtin_constant_p(n) && (n <= 256))
4729 return uaccess.copy_from_user_small(n, from, to);
4730 else
4731 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
4732 unsigned int sz = __compiletime_object_size(to);
4733
4734 might_fault();
4735 +
4736 + if ((long)n < 0)
4737 + return n;
4738 +
4739 if (unlikely(sz != -1 && sz < n)) {
4740 copy_from_user_overflow();
4741 return n;
4742 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4743 index dfcb343..eda788a 100644
4744 --- a/arch/s390/kernel/module.c
4745 +++ b/arch/s390/kernel/module.c
4746 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4747
4748 /* Increase core size by size of got & plt and set start
4749 offsets for got and plt. */
4750 - me->core_size = ALIGN(me->core_size, 4);
4751 - me->arch.got_offset = me->core_size;
4752 - me->core_size += me->arch.got_size;
4753 - me->arch.plt_offset = me->core_size;
4754 - me->core_size += me->arch.plt_size;
4755 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4756 + me->arch.got_offset = me->core_size_rw;
4757 + me->core_size_rw += me->arch.got_size;
4758 + me->arch.plt_offset = me->core_size_rx;
4759 + me->core_size_rx += me->arch.plt_size;
4760 return 0;
4761 }
4762
4763 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4764 if (info->got_initialized == 0) {
4765 Elf_Addr *gotent;
4766
4767 - gotent = me->module_core + me->arch.got_offset +
4768 + gotent = me->module_core_rw + me->arch.got_offset +
4769 info->got_offset;
4770 *gotent = val;
4771 info->got_initialized = 1;
4772 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4773 else if (r_type == R_390_GOTENT ||
4774 r_type == R_390_GOTPLTENT)
4775 *(unsigned int *) loc =
4776 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4777 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4778 else if (r_type == R_390_GOT64 ||
4779 r_type == R_390_GOTPLT64)
4780 *(unsigned long *) loc = val;
4781 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4782 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4783 if (info->plt_initialized == 0) {
4784 unsigned int *ip;
4785 - ip = me->module_core + me->arch.plt_offset +
4786 + ip = me->module_core_rx + me->arch.plt_offset +
4787 info->plt_offset;
4788 #ifndef CONFIG_64BIT
4789 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4790 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4791 val - loc + 0xffffUL < 0x1ffffeUL) ||
4792 (r_type == R_390_PLT32DBL &&
4793 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4794 - val = (Elf_Addr) me->module_core +
4795 + val = (Elf_Addr) me->module_core_rx +
4796 me->arch.plt_offset +
4797 info->plt_offset;
4798 val += rela->r_addend - loc;
4799 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4800 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4801 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4802 val = val + rela->r_addend -
4803 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4804 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4805 if (r_type == R_390_GOTOFF16)
4806 *(unsigned short *) loc = val;
4807 else if (r_type == R_390_GOTOFF32)
4808 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4809 break;
4810 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4811 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4812 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4813 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4814 rela->r_addend - loc;
4815 if (r_type == R_390_GOTPC)
4816 *(unsigned int *) loc = val;
4817 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4818 index e795933..b32563c 100644
4819 --- a/arch/s390/kernel/process.c
4820 +++ b/arch/s390/kernel/process.c
4821 @@ -323,39 +323,3 @@ unsigned long get_wchan(struct task_struct *p)
4822 }
4823 return 0;
4824 }
4825 -
4826 -unsigned long arch_align_stack(unsigned long sp)
4827 -{
4828 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4829 - sp -= get_random_int() & ~PAGE_MASK;
4830 - return sp & ~0xf;
4831 -}
4832 -
4833 -static inline unsigned long brk_rnd(void)
4834 -{
4835 - /* 8MB for 32bit, 1GB for 64bit */
4836 - if (is_32bit_task())
4837 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4838 - else
4839 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4840 -}
4841 -
4842 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4843 -{
4844 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4845 -
4846 - if (ret < mm->brk)
4847 - return mm->brk;
4848 - return ret;
4849 -}
4850 -
4851 -unsigned long randomize_et_dyn(unsigned long base)
4852 -{
4853 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4854 -
4855 - if (!(current->flags & PF_RANDOMIZE))
4856 - return base;
4857 - if (ret < base)
4858 - return base;
4859 - return ret;
4860 -}
4861 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4862 index a0155c0..34cc491 100644
4863 --- a/arch/s390/mm/mmap.c
4864 +++ b/arch/s390/mm/mmap.c
4865 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4866 */
4867 if (mmap_is_legacy()) {
4868 mm->mmap_base = TASK_UNMAPPED_BASE;
4869 +
4870 +#ifdef CONFIG_PAX_RANDMMAP
4871 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4872 + mm->mmap_base += mm->delta_mmap;
4873 +#endif
4874 +
4875 mm->get_unmapped_area = arch_get_unmapped_area;
4876 mm->unmap_area = arch_unmap_area;
4877 } else {
4878 mm->mmap_base = mmap_base();
4879 +
4880 +#ifdef CONFIG_PAX_RANDMMAP
4881 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4882 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4883 +#endif
4884 +
4885 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4886 mm->unmap_area = arch_unmap_area_topdown;
4887 }
4888 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4889 */
4890 if (mmap_is_legacy()) {
4891 mm->mmap_base = TASK_UNMAPPED_BASE;
4892 +
4893 +#ifdef CONFIG_PAX_RANDMMAP
4894 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4895 + mm->mmap_base += mm->delta_mmap;
4896 +#endif
4897 +
4898 mm->get_unmapped_area = s390_get_unmapped_area;
4899 mm->unmap_area = arch_unmap_area;
4900 } else {
4901 mm->mmap_base = mmap_base();
4902 +
4903 +#ifdef CONFIG_PAX_RANDMMAP
4904 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4905 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4906 +#endif
4907 +
4908 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4909 mm->unmap_area = arch_unmap_area_topdown;
4910 }
4911 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4912 index ae3d59f..f65f075 100644
4913 --- a/arch/score/include/asm/cache.h
4914 +++ b/arch/score/include/asm/cache.h
4915 @@ -1,7 +1,9 @@
4916 #ifndef _ASM_SCORE_CACHE_H
4917 #define _ASM_SCORE_CACHE_H
4918
4919 +#include <linux/const.h>
4920 +
4921 #define L1_CACHE_SHIFT 4
4922 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4923 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4924
4925 #endif /* _ASM_SCORE_CACHE_H */
4926 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
4927 index 589d5c7..669e274 100644
4928 --- a/arch/score/include/asm/system.h
4929 +++ b/arch/score/include/asm/system.h
4930 @@ -17,7 +17,7 @@ do { \
4931 #define finish_arch_switch(prev) do {} while (0)
4932
4933 typedef void (*vi_handler_t)(void);
4934 -extern unsigned long arch_align_stack(unsigned long sp);
4935 +#define arch_align_stack(x) (x)
4936
4937 #define mb() barrier()
4938 #define rmb() barrier()
4939 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4940 index 25d0803..d6c8e36 100644
4941 --- a/arch/score/kernel/process.c
4942 +++ b/arch/score/kernel/process.c
4943 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4944
4945 return task_pt_regs(task)->cp0_epc;
4946 }
4947 -
4948 -unsigned long arch_align_stack(unsigned long sp)
4949 -{
4950 - return sp;
4951 -}
4952 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4953 index ef9e555..331bd29 100644
4954 --- a/arch/sh/include/asm/cache.h
4955 +++ b/arch/sh/include/asm/cache.h
4956 @@ -9,10 +9,11 @@
4957 #define __ASM_SH_CACHE_H
4958 #ifdef __KERNEL__
4959
4960 +#include <linux/const.h>
4961 #include <linux/init.h>
4962 #include <cpu/cache.h>
4963
4964 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4965 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4966
4967 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4968
4969 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4970 index afeb710..d1d1289 100644
4971 --- a/arch/sh/mm/mmap.c
4972 +++ b/arch/sh/mm/mmap.c
4973 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4974 addr = PAGE_ALIGN(addr);
4975
4976 vma = find_vma(mm, addr);
4977 - if (TASK_SIZE - len >= addr &&
4978 - (!vma || addr + len <= vma->vm_start))
4979 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4980 return addr;
4981 }
4982
4983 @@ -106,7 +105,7 @@ full_search:
4984 }
4985 return -ENOMEM;
4986 }
4987 - if (likely(!vma || addr + len <= vma->vm_start)) {
4988 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4989 /*
4990 * Remember the place where we stopped the search:
4991 */
4992 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4993 addr = PAGE_ALIGN(addr);
4994
4995 vma = find_vma(mm, addr);
4996 - if (TASK_SIZE - len >= addr &&
4997 - (!vma || addr + len <= vma->vm_start))
4998 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4999 return addr;
5000 }
5001
5002 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5003 /* make sure it can fit in the remaining address space */
5004 if (likely(addr > len)) {
5005 vma = find_vma(mm, addr-len);
5006 - if (!vma || addr <= vma->vm_start) {
5007 + if (check_heap_stack_gap(vma, addr - len, len)) {
5008 /* remember the address as a hint for next time */
5009 return (mm->free_area_cache = addr-len);
5010 }
5011 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5012 if (unlikely(mm->mmap_base < len))
5013 goto bottomup;
5014
5015 - addr = mm->mmap_base-len;
5016 - if (do_colour_align)
5017 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5018 + addr = mm->mmap_base - len;
5019
5020 do {
5021 + if (do_colour_align)
5022 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5023 /*
5024 * Lookup failure means no vma is above this address,
5025 * else if new region fits below vma->vm_start,
5026 * return with success:
5027 */
5028 vma = find_vma(mm, addr);
5029 - if (likely(!vma || addr+len <= vma->vm_start)) {
5030 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5031 /* remember the address as a hint for next time */
5032 return (mm->free_area_cache = addr);
5033 }
5034 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5035 mm->cached_hole_size = vma->vm_start - addr;
5036
5037 /* try just below the current vma->vm_start */
5038 - addr = vma->vm_start-len;
5039 - if (do_colour_align)
5040 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5041 - } while (likely(len < vma->vm_start));
5042 + addr = skip_heap_stack_gap(vma, len);
5043 + } while (!IS_ERR_VALUE(addr));
5044
5045 bottomup:
5046 /*
5047 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
5048 index eddcfb3..b117d90 100644
5049 --- a/arch/sparc/Makefile
5050 +++ b/arch/sparc/Makefile
5051 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
5052 # Export what is needed by arch/sparc/boot/Makefile
5053 export VMLINUX_INIT VMLINUX_MAIN
5054 VMLINUX_INIT := $(head-y) $(init-y)
5055 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
5056 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
5057 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
5058 VMLINUX_MAIN += $(drivers-y) $(net-y)
5059
5060 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5061 index 9f421df..b81fc12 100644
5062 --- a/arch/sparc/include/asm/atomic_64.h
5063 +++ b/arch/sparc/include/asm/atomic_64.h
5064 @@ -14,18 +14,40 @@
5065 #define ATOMIC64_INIT(i) { (i) }
5066
5067 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5068 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5069 +{
5070 + return v->counter;
5071 +}
5072 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5073 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5074 +{
5075 + return v->counter;
5076 +}
5077
5078 #define atomic_set(v, i) (((v)->counter) = i)
5079 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5080 +{
5081 + v->counter = i;
5082 +}
5083 #define atomic64_set(v, i) (((v)->counter) = i)
5084 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5085 +{
5086 + v->counter = i;
5087 +}
5088
5089 extern void atomic_add(int, atomic_t *);
5090 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5091 extern void atomic64_add(long, atomic64_t *);
5092 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5093 extern void atomic_sub(int, atomic_t *);
5094 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5095 extern void atomic64_sub(long, atomic64_t *);
5096 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5097
5098 extern int atomic_add_ret(int, atomic_t *);
5099 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5100 extern long atomic64_add_ret(long, atomic64_t *);
5101 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5102 extern int atomic_sub_ret(int, atomic_t *);
5103 extern long atomic64_sub_ret(long, atomic64_t *);
5104
5105 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5106 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5107
5108 #define atomic_inc_return(v) atomic_add_ret(1, v)
5109 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5110 +{
5111 + return atomic_add_ret_unchecked(1, v);
5112 +}
5113 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5114 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5115 +{
5116 + return atomic64_add_ret_unchecked(1, v);
5117 +}
5118
5119 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5120 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5121
5122 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5123 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5124 +{
5125 + return atomic_add_ret_unchecked(i, v);
5126 +}
5127 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5128 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5129 +{
5130 + return atomic64_add_ret_unchecked(i, v);
5131 +}
5132
5133 /*
5134 * atomic_inc_and_test - increment and test
5135 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5136 * other cases.
5137 */
5138 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5139 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5140 +{
5141 + return atomic_inc_return_unchecked(v) == 0;
5142 +}
5143 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5144
5145 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5146 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5147 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5148
5149 #define atomic_inc(v) atomic_add(1, v)
5150 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5151 +{
5152 + atomic_add_unchecked(1, v);
5153 +}
5154 #define atomic64_inc(v) atomic64_add(1, v)
5155 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5156 +{
5157 + atomic64_add_unchecked(1, v);
5158 +}
5159
5160 #define atomic_dec(v) atomic_sub(1, v)
5161 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5162 +{
5163 + atomic_sub_unchecked(1, v);
5164 +}
5165 #define atomic64_dec(v) atomic64_sub(1, v)
5166 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5167 +{
5168 + atomic64_sub_unchecked(1, v);
5169 +}
5170
5171 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5172 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5173
5174 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5175 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5176 +{
5177 + return cmpxchg(&v->counter, old, new);
5178 +}
5179 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5180 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5181 +{
5182 + return xchg(&v->counter, new);
5183 +}
5184
5185 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5186 {
5187 - int c, old;
5188 + int c, old, new;
5189 c = atomic_read(v);
5190 for (;;) {
5191 - if (unlikely(c == (u)))
5192 + if (unlikely(c == u))
5193 break;
5194 - old = atomic_cmpxchg((v), c, c + (a));
5195 +
5196 + asm volatile("addcc %2, %0, %0\n"
5197 +
5198 +#ifdef CONFIG_PAX_REFCOUNT
5199 + "tvs %%icc, 6\n"
5200 +#endif
5201 +
5202 + : "=r" (new)
5203 + : "0" (c), "ir" (a)
5204 + : "cc");
5205 +
5206 + old = atomic_cmpxchg(v, c, new);
5207 if (likely(old == c))
5208 break;
5209 c = old;
5210 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5211 #define atomic64_cmpxchg(v, o, n) \
5212 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5213 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5214 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5215 +{
5216 + return xchg(&v->counter, new);
5217 +}
5218
5219 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5220 {
5221 - long c, old;
5222 + long c, old, new;
5223 c = atomic64_read(v);
5224 for (;;) {
5225 - if (unlikely(c == (u)))
5226 + if (unlikely(c == u))
5227 break;
5228 - old = atomic64_cmpxchg((v), c, c + (a));
5229 +
5230 + asm volatile("addcc %2, %0, %0\n"
5231 +
5232 +#ifdef CONFIG_PAX_REFCOUNT
5233 + "tvs %%xcc, 6\n"
5234 +#endif
5235 +
5236 + : "=r" (new)
5237 + : "0" (c), "ir" (a)
5238 + : "cc");
5239 +
5240 + old = atomic64_cmpxchg(v, c, new);
5241 if (likely(old == c))
5242 break;
5243 c = old;
5244 }
5245 - return c != (u);
5246 + return c != u;
5247 }
5248
5249 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5250 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5251 index 69358b5..9d0d492 100644
5252 --- a/arch/sparc/include/asm/cache.h
5253 +++ b/arch/sparc/include/asm/cache.h
5254 @@ -7,10 +7,12 @@
5255 #ifndef _SPARC_CACHE_H
5256 #define _SPARC_CACHE_H
5257
5258 +#include <linux/const.h>
5259 +
5260 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5261
5262 #define L1_CACHE_SHIFT 5
5263 -#define L1_CACHE_BYTES 32
5264 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5265
5266 #ifdef CONFIG_SPARC32
5267 #define SMP_CACHE_BYTES_SHIFT 5
5268 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5269 index 4269ca6..e3da77f 100644
5270 --- a/arch/sparc/include/asm/elf_32.h
5271 +++ b/arch/sparc/include/asm/elf_32.h
5272 @@ -114,6 +114,13 @@ typedef struct {
5273
5274 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5275
5276 +#ifdef CONFIG_PAX_ASLR
5277 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5278 +
5279 +#define PAX_DELTA_MMAP_LEN 16
5280 +#define PAX_DELTA_STACK_LEN 16
5281 +#endif
5282 +
5283 /* This yields a mask that user programs can use to figure out what
5284 instruction set this cpu supports. This can NOT be done in userspace
5285 on Sparc. */
5286 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5287 index 7df8b7f..4946269 100644
5288 --- a/arch/sparc/include/asm/elf_64.h
5289 +++ b/arch/sparc/include/asm/elf_64.h
5290 @@ -180,6 +180,13 @@ typedef struct {
5291 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5292 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5293
5294 +#ifdef CONFIG_PAX_ASLR
5295 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5296 +
5297 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5298 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5299 +#endif
5300 +
5301 extern unsigned long sparc64_elf_hwcap;
5302 #define ELF_HWCAP sparc64_elf_hwcap
5303
5304 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5305 index ca2b344..c6084f89 100644
5306 --- a/arch/sparc/include/asm/pgalloc_32.h
5307 +++ b/arch/sparc/include/asm/pgalloc_32.h
5308 @@ -37,6 +37,7 @@ BTFIXUPDEF_CALL(void, free_pgd_fast, pgd_t *)
5309 BTFIXUPDEF_CALL(void, pgd_set, pgd_t *, pmd_t *)
5310 #define pgd_set(pgdp,pmdp) BTFIXUP_CALL(pgd_set)(pgdp,pmdp)
5311 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5312 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5313
5314 BTFIXUPDEF_CALL(pmd_t *, pmd_alloc_one, struct mm_struct *, unsigned long)
5315 #define pmd_alloc_one(mm, address) BTFIXUP_CALL(pmd_alloc_one)(mm, address)
5316 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5317 index 40b2d7a..22a665b 100644
5318 --- a/arch/sparc/include/asm/pgalloc_64.h
5319 +++ b/arch/sparc/include/asm/pgalloc_64.h
5320 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5321 }
5322
5323 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5324 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5325
5326 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5327 {
5328 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5329 index a790cc6..091ed94 100644
5330 --- a/arch/sparc/include/asm/pgtable_32.h
5331 +++ b/arch/sparc/include/asm/pgtable_32.h
5332 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
5333 BTFIXUPDEF_INT(page_none)
5334 BTFIXUPDEF_INT(page_copy)
5335 BTFIXUPDEF_INT(page_readonly)
5336 +
5337 +#ifdef CONFIG_PAX_PAGEEXEC
5338 +BTFIXUPDEF_INT(page_shared_noexec)
5339 +BTFIXUPDEF_INT(page_copy_noexec)
5340 +BTFIXUPDEF_INT(page_readonly_noexec)
5341 +#endif
5342 +
5343 BTFIXUPDEF_INT(page_kernel)
5344
5345 #define PMD_SHIFT SUN4C_PMD_SHIFT
5346 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
5347 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
5348 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
5349
5350 +#ifdef CONFIG_PAX_PAGEEXEC
5351 +extern pgprot_t PAGE_SHARED_NOEXEC;
5352 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
5353 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
5354 +#else
5355 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5356 +# define PAGE_COPY_NOEXEC PAGE_COPY
5357 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5358 +#endif
5359 +
5360 extern unsigned long page_kernel;
5361
5362 #ifdef MODULE
5363 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5364 index f6ae2b2..b03ffc7 100644
5365 --- a/arch/sparc/include/asm/pgtsrmmu.h
5366 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5367 @@ -115,6 +115,13 @@
5368 SRMMU_EXEC | SRMMU_REF)
5369 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5370 SRMMU_EXEC | SRMMU_REF)
5371 +
5372 +#ifdef CONFIG_PAX_PAGEEXEC
5373 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5374 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5375 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5376 +#endif
5377 +
5378 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5379 SRMMU_DIRTY | SRMMU_REF)
5380
5381 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5382 index 9689176..63c18ea 100644
5383 --- a/arch/sparc/include/asm/spinlock_64.h
5384 +++ b/arch/sparc/include/asm/spinlock_64.h
5385 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5386
5387 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5388
5389 -static void inline arch_read_lock(arch_rwlock_t *lock)
5390 +static inline void arch_read_lock(arch_rwlock_t *lock)
5391 {
5392 unsigned long tmp1, tmp2;
5393
5394 __asm__ __volatile__ (
5395 "1: ldsw [%2], %0\n"
5396 " brlz,pn %0, 2f\n"
5397 -"4: add %0, 1, %1\n"
5398 +"4: addcc %0, 1, %1\n"
5399 +
5400 +#ifdef CONFIG_PAX_REFCOUNT
5401 +" tvs %%icc, 6\n"
5402 +#endif
5403 +
5404 " cas [%2], %0, %1\n"
5405 " cmp %0, %1\n"
5406 " bne,pn %%icc, 1b\n"
5407 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5408 " .previous"
5409 : "=&r" (tmp1), "=&r" (tmp2)
5410 : "r" (lock)
5411 - : "memory");
5412 + : "memory", "cc");
5413 }
5414
5415 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5416 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5417 {
5418 int tmp1, tmp2;
5419
5420 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5421 "1: ldsw [%2], %0\n"
5422 " brlz,a,pn %0, 2f\n"
5423 " mov 0, %0\n"
5424 -" add %0, 1, %1\n"
5425 +" addcc %0, 1, %1\n"
5426 +
5427 +#ifdef CONFIG_PAX_REFCOUNT
5428 +" tvs %%icc, 6\n"
5429 +#endif
5430 +
5431 " cas [%2], %0, %1\n"
5432 " cmp %0, %1\n"
5433 " bne,pn %%icc, 1b\n"
5434 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5435 return tmp1;
5436 }
5437
5438 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5439 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5440 {
5441 unsigned long tmp1, tmp2;
5442
5443 __asm__ __volatile__(
5444 "1: lduw [%2], %0\n"
5445 -" sub %0, 1, %1\n"
5446 +" subcc %0, 1, %1\n"
5447 +
5448 +#ifdef CONFIG_PAX_REFCOUNT
5449 +" tvs %%icc, 6\n"
5450 +#endif
5451 +
5452 " cas [%2], %0, %1\n"
5453 " cmp %0, %1\n"
5454 " bne,pn %%xcc, 1b\n"
5455 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5456 : "memory");
5457 }
5458
5459 -static void inline arch_write_lock(arch_rwlock_t *lock)
5460 +static inline void arch_write_lock(arch_rwlock_t *lock)
5461 {
5462 unsigned long mask, tmp1, tmp2;
5463
5464 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5465 : "memory");
5466 }
5467
5468 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5469 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5470 {
5471 __asm__ __volatile__(
5472 " stw %%g0, [%0]"
5473 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5474 : "memory");
5475 }
5476
5477 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5478 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5479 {
5480 unsigned long mask, tmp1, tmp2, result;
5481
5482 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5483 index c2a1080..21ed218 100644
5484 --- a/arch/sparc/include/asm/thread_info_32.h
5485 +++ b/arch/sparc/include/asm/thread_info_32.h
5486 @@ -50,6 +50,8 @@ struct thread_info {
5487 unsigned long w_saved;
5488
5489 struct restart_block restart_block;
5490 +
5491 + unsigned long lowest_stack;
5492 };
5493
5494 /*
5495 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5496 index 01d057f..13a7d2f 100644
5497 --- a/arch/sparc/include/asm/thread_info_64.h
5498 +++ b/arch/sparc/include/asm/thread_info_64.h
5499 @@ -63,6 +63,8 @@ struct thread_info {
5500 struct pt_regs *kern_una_regs;
5501 unsigned int kern_una_insn;
5502
5503 + unsigned long lowest_stack;
5504 +
5505 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5506 };
5507
5508 @@ -214,10 +216,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5509 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5510 /* flag bit 6 is available */
5511 #define TIF_32BIT 7 /* 32-bit binary */
5512 -/* flag bit 8 is available */
5513 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5514 #define TIF_SECCOMP 9 /* secure computing */
5515 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5516 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5517 +
5518 /* NOTE: Thread flags >= 12 should be ones we have no interest
5519 * in using in assembly, else we can't use the mask as
5520 * an immediate value in instructions such as andcc.
5521 @@ -236,12 +239,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5522 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5523 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5524 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5525 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5526
5527 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5528 _TIF_DO_NOTIFY_RESUME_MASK | \
5529 _TIF_NEED_RESCHED)
5530 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5531
5532 +#define _TIF_WORK_SYSCALL \
5533 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5534 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5535 +
5536 +
5537 /*
5538 * Thread-synchronous status.
5539 *
5540 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5541 index e88fbe5..96b0ce5 100644
5542 --- a/arch/sparc/include/asm/uaccess.h
5543 +++ b/arch/sparc/include/asm/uaccess.h
5544 @@ -1,5 +1,13 @@
5545 #ifndef ___ASM_SPARC_UACCESS_H
5546 #define ___ASM_SPARC_UACCESS_H
5547 +
5548 +#ifdef __KERNEL__
5549 +#ifndef __ASSEMBLY__
5550 +#include <linux/types.h>
5551 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5552 +#endif
5553 +#endif
5554 +
5555 #if defined(__sparc__) && defined(__arch64__)
5556 #include <asm/uaccess_64.h>
5557 #else
5558 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5559 index 8303ac4..07f333d 100644
5560 --- a/arch/sparc/include/asm/uaccess_32.h
5561 +++ b/arch/sparc/include/asm/uaccess_32.h
5562 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5563
5564 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5565 {
5566 - if (n && __access_ok((unsigned long) to, n))
5567 + if ((long)n < 0)
5568 + return n;
5569 +
5570 + if (n && __access_ok((unsigned long) to, n)) {
5571 + if (!__builtin_constant_p(n))
5572 + check_object_size(from, n, true);
5573 return __copy_user(to, (__force void __user *) from, n);
5574 - else
5575 + } else
5576 return n;
5577 }
5578
5579 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5580 {
5581 + if ((long)n < 0)
5582 + return n;
5583 +
5584 + if (!__builtin_constant_p(n))
5585 + check_object_size(from, n, true);
5586 +
5587 return __copy_user(to, (__force void __user *) from, n);
5588 }
5589
5590 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5591 {
5592 - if (n && __access_ok((unsigned long) from, n))
5593 + if ((long)n < 0)
5594 + return n;
5595 +
5596 + if (n && __access_ok((unsigned long) from, n)) {
5597 + if (!__builtin_constant_p(n))
5598 + check_object_size(to, n, false);
5599 return __copy_user((__force void __user *) to, from, n);
5600 - else
5601 + } else
5602 return n;
5603 }
5604
5605 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5606 {
5607 + if ((long)n < 0)
5608 + return n;
5609 +
5610 return __copy_user((__force void __user *) to, from, n);
5611 }
5612
5613 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5614 index 3e1449f..5293a0e 100644
5615 --- a/arch/sparc/include/asm/uaccess_64.h
5616 +++ b/arch/sparc/include/asm/uaccess_64.h
5617 @@ -10,6 +10,7 @@
5618 #include <linux/compiler.h>
5619 #include <linux/string.h>
5620 #include <linux/thread_info.h>
5621 +#include <linux/kernel.h>
5622 #include <asm/asi.h>
5623 #include <asm/system.h>
5624 #include <asm/spitfire.h>
5625 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5626 static inline unsigned long __must_check
5627 copy_from_user(void *to, const void __user *from, unsigned long size)
5628 {
5629 - unsigned long ret = ___copy_from_user(to, from, size);
5630 + unsigned long ret;
5631
5632 + if ((long)size < 0 || size > INT_MAX)
5633 + return size;
5634 +
5635 + if (!__builtin_constant_p(size))
5636 + check_object_size(to, size, false);
5637 +
5638 + ret = ___copy_from_user(to, from, size);
5639 if (unlikely(ret))
5640 ret = copy_from_user_fixup(to, from, size);
5641
5642 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5643 static inline unsigned long __must_check
5644 copy_to_user(void __user *to, const void *from, unsigned long size)
5645 {
5646 - unsigned long ret = ___copy_to_user(to, from, size);
5647 + unsigned long ret;
5648
5649 + if ((long)size < 0 || size > INT_MAX)
5650 + return size;
5651 +
5652 + if (!__builtin_constant_p(size))
5653 + check_object_size(from, size, true);
5654 +
5655 + ret = ___copy_to_user(to, from, size);
5656 if (unlikely(ret))
5657 ret = copy_to_user_fixup(to, from, size);
5658 return ret;
5659 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5660 index cb85458..e063f17 100644
5661 --- a/arch/sparc/kernel/Makefile
5662 +++ b/arch/sparc/kernel/Makefile
5663 @@ -3,7 +3,7 @@
5664 #
5665
5666 asflags-y := -ansi
5667 -ccflags-y := -Werror
5668 +#ccflags-y := -Werror
5669
5670 extra-y := head_$(BITS).o
5671 extra-y += init_task.o
5672 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5673 index f793742..4d880af 100644
5674 --- a/arch/sparc/kernel/process_32.c
5675 +++ b/arch/sparc/kernel/process_32.c
5676 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
5677 rw->ins[4], rw->ins[5],
5678 rw->ins[6],
5679 rw->ins[7]);
5680 - printk("%pS\n", (void *) rw->ins[7]);
5681 + printk("%pA\n", (void *) rw->ins[7]);
5682 rw = (struct reg_window32 *) rw->ins[6];
5683 }
5684 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
5685 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
5686
5687 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5688 r->psr, r->pc, r->npc, r->y, print_tainted());
5689 - printk("PC: <%pS>\n", (void *) r->pc);
5690 + printk("PC: <%pA>\n", (void *) r->pc);
5691 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5692 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5693 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5694 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5695 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5696 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5697 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5698 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5699
5700 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5701 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5702 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5703 rw = (struct reg_window32 *) fp;
5704 pc = rw->ins[7];
5705 printk("[%08lx : ", pc);
5706 - printk("%pS ] ", (void *) pc);
5707 + printk("%pA ] ", (void *) pc);
5708 fp = rw->ins[6];
5709 } while (++count < 16);
5710 printk("\n");
5711 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5712 index 39d8b05..d1a7d90 100644
5713 --- a/arch/sparc/kernel/process_64.c
5714 +++ b/arch/sparc/kernel/process_64.c
5715 @@ -182,14 +182,14 @@ static void show_regwindow(struct pt_regs *regs)
5716 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5717 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5718 if (regs->tstate & TSTATE_PRIV)
5719 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5720 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5721 }
5722
5723 void show_regs(struct pt_regs *regs)
5724 {
5725 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5726 regs->tpc, regs->tnpc, regs->y, print_tainted());
5727 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5728 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5729 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5730 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5731 regs->u_regs[3]);
5732 @@ -202,7 +202,7 @@ void show_regs(struct pt_regs *regs)
5733 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5734 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5735 regs->u_regs[15]);
5736 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5737 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5738 show_regwindow(regs);
5739 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5740 }
5741 @@ -287,7 +287,7 @@ void arch_trigger_all_cpu_backtrace(void)
5742 ((tp && tp->task) ? tp->task->pid : -1));
5743
5744 if (gp->tstate & TSTATE_PRIV) {
5745 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5746 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5747 (void *) gp->tpc,
5748 (void *) gp->o7,
5749 (void *) gp->i7,
5750 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5751 index 9388844..0075fd2 100644
5752 --- a/arch/sparc/kernel/ptrace_64.c
5753 +++ b/arch/sparc/kernel/ptrace_64.c
5754 @@ -1058,6 +1058,10 @@ long arch_ptrace(struct task_struct *child, long request,
5755 return ret;
5756 }
5757
5758 +#ifdef CONFIG_GRKERNSEC_SETXID
5759 +extern void gr_delayed_cred_worker(void);
5760 +#endif
5761 +
5762 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5763 {
5764 int ret = 0;
5765 @@ -1065,6 +1069,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5766 /* do the secure computing check first */
5767 secure_computing(regs->u_regs[UREG_G1]);
5768
5769 +#ifdef CONFIG_GRKERNSEC_SETXID
5770 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5771 + gr_delayed_cred_worker();
5772 +#endif
5773 +
5774 if (test_thread_flag(TIF_SYSCALL_TRACE))
5775 ret = tracehook_report_syscall_entry(regs);
5776
5777 @@ -1085,6 +1094,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5778
5779 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5780 {
5781 +#ifdef CONFIG_GRKERNSEC_SETXID
5782 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5783 + gr_delayed_cred_worker();
5784 +#endif
5785 +
5786 audit_syscall_exit(regs);
5787
5788 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5789 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5790 index 42b282f..28ce9f2 100644
5791 --- a/arch/sparc/kernel/sys_sparc_32.c
5792 +++ b/arch/sparc/kernel/sys_sparc_32.c
5793 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5794 if (ARCH_SUN4C && len > 0x20000000)
5795 return -ENOMEM;
5796 if (!addr)
5797 - addr = TASK_UNMAPPED_BASE;
5798 + addr = current->mm->mmap_base;
5799
5800 if (flags & MAP_SHARED)
5801 addr = COLOUR_ALIGN(addr);
5802 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5803 }
5804 if (TASK_SIZE - PAGE_SIZE - len < addr)
5805 return -ENOMEM;
5806 - if (!vmm || addr + len <= vmm->vm_start)
5807 + if (check_heap_stack_gap(vmm, addr, len))
5808 return addr;
5809 addr = vmm->vm_end;
5810 if (flags & MAP_SHARED)
5811 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5812 index 232df99..cee1f9c 100644
5813 --- a/arch/sparc/kernel/sys_sparc_64.c
5814 +++ b/arch/sparc/kernel/sys_sparc_64.c
5815 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5816 /* We do not accept a shared mapping if it would violate
5817 * cache aliasing constraints.
5818 */
5819 - if ((flags & MAP_SHARED) &&
5820 + if ((filp || (flags & MAP_SHARED)) &&
5821 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5822 return -EINVAL;
5823 return addr;
5824 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5825 if (filp || (flags & MAP_SHARED))
5826 do_color_align = 1;
5827
5828 +#ifdef CONFIG_PAX_RANDMMAP
5829 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5830 +#endif
5831 +
5832 if (addr) {
5833 if (do_color_align)
5834 addr = COLOUR_ALIGN(addr, pgoff);
5835 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5836 addr = PAGE_ALIGN(addr);
5837
5838 vma = find_vma(mm, addr);
5839 - if (task_size - len >= addr &&
5840 - (!vma || addr + len <= vma->vm_start))
5841 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5842 return addr;
5843 }
5844
5845 if (len > mm->cached_hole_size) {
5846 - start_addr = addr = mm->free_area_cache;
5847 + start_addr = addr = mm->free_area_cache;
5848 } else {
5849 - start_addr = addr = TASK_UNMAPPED_BASE;
5850 + start_addr = addr = mm->mmap_base;
5851 mm->cached_hole_size = 0;
5852 }
5853
5854 @@ -174,14 +177,14 @@ full_search:
5855 vma = find_vma(mm, VA_EXCLUDE_END);
5856 }
5857 if (unlikely(task_size < addr)) {
5858 - if (start_addr != TASK_UNMAPPED_BASE) {
5859 - start_addr = addr = TASK_UNMAPPED_BASE;
5860 + if (start_addr != mm->mmap_base) {
5861 + start_addr = addr = mm->mmap_base;
5862 mm->cached_hole_size = 0;
5863 goto full_search;
5864 }
5865 return -ENOMEM;
5866 }
5867 - if (likely(!vma || addr + len <= vma->vm_start)) {
5868 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5869 /*
5870 * Remember the place where we stopped the search:
5871 */
5872 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5873 /* We do not accept a shared mapping if it would violate
5874 * cache aliasing constraints.
5875 */
5876 - if ((flags & MAP_SHARED) &&
5877 + if ((filp || (flags & MAP_SHARED)) &&
5878 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5879 return -EINVAL;
5880 return addr;
5881 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5882 addr = PAGE_ALIGN(addr);
5883
5884 vma = find_vma(mm, addr);
5885 - if (task_size - len >= addr &&
5886 - (!vma || addr + len <= vma->vm_start))
5887 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5888 return addr;
5889 }
5890
5891 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5892 /* make sure it can fit in the remaining address space */
5893 if (likely(addr > len)) {
5894 vma = find_vma(mm, addr-len);
5895 - if (!vma || addr <= vma->vm_start) {
5896 + if (check_heap_stack_gap(vma, addr - len, len)) {
5897 /* remember the address as a hint for next time */
5898 return (mm->free_area_cache = addr-len);
5899 }
5900 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5901 if (unlikely(mm->mmap_base < len))
5902 goto bottomup;
5903
5904 - addr = mm->mmap_base-len;
5905 - if (do_color_align)
5906 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5907 + addr = mm->mmap_base - len;
5908
5909 do {
5910 + if (do_color_align)
5911 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5912 /*
5913 * Lookup failure means no vma is above this address,
5914 * else if new region fits below vma->vm_start,
5915 * return with success:
5916 */
5917 vma = find_vma(mm, addr);
5918 - if (likely(!vma || addr+len <= vma->vm_start)) {
5919 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5920 /* remember the address as a hint for next time */
5921 return (mm->free_area_cache = addr);
5922 }
5923 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5924 mm->cached_hole_size = vma->vm_start - addr;
5925
5926 /* try just below the current vma->vm_start */
5927 - addr = vma->vm_start-len;
5928 - if (do_color_align)
5929 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5930 - } while (likely(len < vma->vm_start));
5931 + addr = skip_heap_stack_gap(vma, len);
5932 + } while (!IS_ERR_VALUE(addr));
5933
5934 bottomup:
5935 /*
5936 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5937 gap == RLIM_INFINITY ||
5938 sysctl_legacy_va_layout) {
5939 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5940 +
5941 +#ifdef CONFIG_PAX_RANDMMAP
5942 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5943 + mm->mmap_base += mm->delta_mmap;
5944 +#endif
5945 +
5946 mm->get_unmapped_area = arch_get_unmapped_area;
5947 mm->unmap_area = arch_unmap_area;
5948 } else {
5949 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5950 gap = (task_size / 6 * 5);
5951
5952 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5953 +
5954 +#ifdef CONFIG_PAX_RANDMMAP
5955 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5956 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5957 +#endif
5958 +
5959 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5960 mm->unmap_area = arch_unmap_area_topdown;
5961 }
5962 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5963 index 1d7e274..b39c527 100644
5964 --- a/arch/sparc/kernel/syscalls.S
5965 +++ b/arch/sparc/kernel/syscalls.S
5966 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5967 #endif
5968 .align 32
5969 1: ldx [%g6 + TI_FLAGS], %l5
5970 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5971 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5972 be,pt %icc, rtrap
5973 nop
5974 call syscall_trace_leave
5975 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5976
5977 srl %i5, 0, %o5 ! IEU1
5978 srl %i2, 0, %o2 ! IEU0 Group
5979 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5980 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5981 bne,pn %icc, linux_syscall_trace32 ! CTI
5982 mov %i0, %l5 ! IEU1
5983 call %l7 ! CTI Group brk forced
5984 @@ -202,7 +202,7 @@ linux_sparc_syscall:
5985
5986 mov %i3, %o3 ! IEU1
5987 mov %i4, %o4 ! IEU0 Group
5988 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5989 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5990 bne,pn %icc, linux_syscall_trace ! CTI Group
5991 mov %i0, %l5 ! IEU0
5992 2: call %l7 ! CTI Group brk forced
5993 @@ -226,7 +226,7 @@ ret_sys_call:
5994
5995 cmp %o0, -ERESTART_RESTARTBLOCK
5996 bgeu,pn %xcc, 1f
5997 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
5998 + andcc %l0, _TIF_WORK_SYSCALL, %l6
5999 80:
6000 /* System call success, clear Carry condition code. */
6001 andn %g3, %g2, %g3
6002 @@ -241,7 +241,7 @@ ret_sys_call:
6003 /* System call failure, set Carry condition code.
6004 * Also, get abs(errno) to return to the process.
6005 */
6006 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6007 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6008 sub %g0, %o0, %o0
6009 or %g3, %g2, %g3
6010 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6011 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6012 index 591f20c..0f1b925 100644
6013 --- a/arch/sparc/kernel/traps_32.c
6014 +++ b/arch/sparc/kernel/traps_32.c
6015 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
6016 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6017 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6018
6019 +extern void gr_handle_kernel_exploit(void);
6020 +
6021 void die_if_kernel(char *str, struct pt_regs *regs)
6022 {
6023 static int die_counter;
6024 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6025 count++ < 30 &&
6026 (((unsigned long) rw) >= PAGE_OFFSET) &&
6027 !(((unsigned long) rw) & 0x7)) {
6028 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6029 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6030 (void *) rw->ins[7]);
6031 rw = (struct reg_window32 *)rw->ins[6];
6032 }
6033 }
6034 printk("Instruction DUMP:");
6035 instruction_dump ((unsigned long *) regs->pc);
6036 - if(regs->psr & PSR_PS)
6037 + if(regs->psr & PSR_PS) {
6038 + gr_handle_kernel_exploit();
6039 do_exit(SIGKILL);
6040 + }
6041 do_exit(SIGSEGV);
6042 }
6043
6044 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6045 index 0cbdaa4..438e4c9 100644
6046 --- a/arch/sparc/kernel/traps_64.c
6047 +++ b/arch/sparc/kernel/traps_64.c
6048 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6049 i + 1,
6050 p->trapstack[i].tstate, p->trapstack[i].tpc,
6051 p->trapstack[i].tnpc, p->trapstack[i].tt);
6052 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6053 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6054 }
6055 }
6056
6057 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6058
6059 lvl -= 0x100;
6060 if (regs->tstate & TSTATE_PRIV) {
6061 +
6062 +#ifdef CONFIG_PAX_REFCOUNT
6063 + if (lvl == 6)
6064 + pax_report_refcount_overflow(regs);
6065 +#endif
6066 +
6067 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6068 die_if_kernel(buffer, regs);
6069 }
6070 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6071 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6072 {
6073 char buffer[32];
6074 -
6075 +
6076 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6077 0, lvl, SIGTRAP) == NOTIFY_STOP)
6078 return;
6079
6080 +#ifdef CONFIG_PAX_REFCOUNT
6081 + if (lvl == 6)
6082 + pax_report_refcount_overflow(regs);
6083 +#endif
6084 +
6085 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6086
6087 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6088 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6089 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6090 printk("%s" "ERROR(%d): ",
6091 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6092 - printk("TPC<%pS>\n", (void *) regs->tpc);
6093 + printk("TPC<%pA>\n", (void *) regs->tpc);
6094 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6095 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6096 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6097 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6098 smp_processor_id(),
6099 (type & 0x1) ? 'I' : 'D',
6100 regs->tpc);
6101 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6102 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6103 panic("Irrecoverable Cheetah+ parity error.");
6104 }
6105
6106 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6107 smp_processor_id(),
6108 (type & 0x1) ? 'I' : 'D',
6109 regs->tpc);
6110 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6111 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6112 }
6113
6114 struct sun4v_error_entry {
6115 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6116
6117 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6118 regs->tpc, tl);
6119 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6120 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6121 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6122 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6123 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6124 (void *) regs->u_regs[UREG_I7]);
6125 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6126 "pte[%lx] error[%lx]\n",
6127 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6128
6129 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6130 regs->tpc, tl);
6131 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6132 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6133 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6134 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6135 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6136 (void *) regs->u_regs[UREG_I7]);
6137 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6138 "pte[%lx] error[%lx]\n",
6139 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6140 fp = (unsigned long)sf->fp + STACK_BIAS;
6141 }
6142
6143 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6144 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6145 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6146 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6147 int index = tsk->curr_ret_stack;
6148 if (tsk->ret_stack && index >= graph) {
6149 pc = tsk->ret_stack[index - graph].ret;
6150 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6151 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6152 graph++;
6153 }
6154 }
6155 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6156 return (struct reg_window *) (fp + STACK_BIAS);
6157 }
6158
6159 +extern void gr_handle_kernel_exploit(void);
6160 +
6161 void die_if_kernel(char *str, struct pt_regs *regs)
6162 {
6163 static int die_counter;
6164 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6165 while (rw &&
6166 count++ < 30 &&
6167 kstack_valid(tp, (unsigned long) rw)) {
6168 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6169 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6170 (void *) rw->ins[7]);
6171
6172 rw = kernel_stack_up(rw);
6173 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6174 }
6175 user_instruction_dump ((unsigned int __user *) regs->tpc);
6176 }
6177 - if (regs->tstate & TSTATE_PRIV)
6178 + if (regs->tstate & TSTATE_PRIV) {
6179 + gr_handle_kernel_exploit();
6180 do_exit(SIGKILL);
6181 + }
6182 do_exit(SIGSEGV);
6183 }
6184 EXPORT_SYMBOL(die_if_kernel);
6185 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6186 index 76e4ac1..78f8bb1 100644
6187 --- a/arch/sparc/kernel/unaligned_64.c
6188 +++ b/arch/sparc/kernel/unaligned_64.c
6189 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
6190 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6191
6192 if (__ratelimit(&ratelimit)) {
6193 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6194 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6195 regs->tpc, (void *) regs->tpc);
6196 }
6197 }
6198 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6199 index a3fc437..fea9957 100644
6200 --- a/arch/sparc/lib/Makefile
6201 +++ b/arch/sparc/lib/Makefile
6202 @@ -2,7 +2,7 @@
6203 #
6204
6205 asflags-y := -ansi -DST_DIV0=0x02
6206 -ccflags-y := -Werror
6207 +#ccflags-y := -Werror
6208
6209 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
6210 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6211 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6212 index 59186e0..f747d7a 100644
6213 --- a/arch/sparc/lib/atomic_64.S
6214 +++ b/arch/sparc/lib/atomic_64.S
6215 @@ -18,7 +18,12 @@
6216 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6217 BACKOFF_SETUP(%o2)
6218 1: lduw [%o1], %g1
6219 - add %g1, %o0, %g7
6220 + addcc %g1, %o0, %g7
6221 +
6222 +#ifdef CONFIG_PAX_REFCOUNT
6223 + tvs %icc, 6
6224 +#endif
6225 +
6226 cas [%o1], %g1, %g7
6227 cmp %g1, %g7
6228 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6229 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
6230 2: BACKOFF_SPIN(%o2, %o3, 1b)
6231 .size atomic_add, .-atomic_add
6232
6233 + .globl atomic_add_unchecked
6234 + .type atomic_add_unchecked,#function
6235 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6236 + BACKOFF_SETUP(%o2)
6237 +1: lduw [%o1], %g1
6238 + add %g1, %o0, %g7
6239 + cas [%o1], %g1, %g7
6240 + cmp %g1, %g7
6241 + bne,pn %icc, 2f
6242 + nop
6243 + retl
6244 + nop
6245 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6246 + .size atomic_add_unchecked, .-atomic_add_unchecked
6247 +
6248 .globl atomic_sub
6249 .type atomic_sub,#function
6250 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6251 BACKOFF_SETUP(%o2)
6252 1: lduw [%o1], %g1
6253 - sub %g1, %o0, %g7
6254 + subcc %g1, %o0, %g7
6255 +
6256 +#ifdef CONFIG_PAX_REFCOUNT
6257 + tvs %icc, 6
6258 +#endif
6259 +
6260 cas [%o1], %g1, %g7
6261 cmp %g1, %g7
6262 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6263 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6264 2: BACKOFF_SPIN(%o2, %o3, 1b)
6265 .size atomic_sub, .-atomic_sub
6266
6267 + .globl atomic_sub_unchecked
6268 + .type atomic_sub_unchecked,#function
6269 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6270 + BACKOFF_SETUP(%o2)
6271 +1: lduw [%o1], %g1
6272 + sub %g1, %o0, %g7
6273 + cas [%o1], %g1, %g7
6274 + cmp %g1, %g7
6275 + bne,pn %icc, 2f
6276 + nop
6277 + retl
6278 + nop
6279 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6280 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
6281 +
6282 .globl atomic_add_ret
6283 .type atomic_add_ret,#function
6284 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6285 BACKOFF_SETUP(%o2)
6286 1: lduw [%o1], %g1
6287 - add %g1, %o0, %g7
6288 + addcc %g1, %o0, %g7
6289 +
6290 +#ifdef CONFIG_PAX_REFCOUNT
6291 + tvs %icc, 6
6292 +#endif
6293 +
6294 cas [%o1], %g1, %g7
6295 cmp %g1, %g7
6296 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6297 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6298 2: BACKOFF_SPIN(%o2, %o3, 1b)
6299 .size atomic_add_ret, .-atomic_add_ret
6300
6301 + .globl atomic_add_ret_unchecked
6302 + .type atomic_add_ret_unchecked,#function
6303 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6304 + BACKOFF_SETUP(%o2)
6305 +1: lduw [%o1], %g1
6306 + addcc %g1, %o0, %g7
6307 + cas [%o1], %g1, %g7
6308 + cmp %g1, %g7
6309 + bne,pn %icc, 2f
6310 + add %g7, %o0, %g7
6311 + sra %g7, 0, %o0
6312 + retl
6313 + nop
6314 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6315 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
6316 +
6317 .globl atomic_sub_ret
6318 .type atomic_sub_ret,#function
6319 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6320 BACKOFF_SETUP(%o2)
6321 1: lduw [%o1], %g1
6322 - sub %g1, %o0, %g7
6323 + subcc %g1, %o0, %g7
6324 +
6325 +#ifdef CONFIG_PAX_REFCOUNT
6326 + tvs %icc, 6
6327 +#endif
6328 +
6329 cas [%o1], %g1, %g7
6330 cmp %g1, %g7
6331 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6332 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6333 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6334 BACKOFF_SETUP(%o2)
6335 1: ldx [%o1], %g1
6336 - add %g1, %o0, %g7
6337 + addcc %g1, %o0, %g7
6338 +
6339 +#ifdef CONFIG_PAX_REFCOUNT
6340 + tvs %xcc, 6
6341 +#endif
6342 +
6343 casx [%o1], %g1, %g7
6344 cmp %g1, %g7
6345 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6346 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
6347 2: BACKOFF_SPIN(%o2, %o3, 1b)
6348 .size atomic64_add, .-atomic64_add
6349
6350 + .globl atomic64_add_unchecked
6351 + .type atomic64_add_unchecked,#function
6352 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6353 + BACKOFF_SETUP(%o2)
6354 +1: ldx [%o1], %g1
6355 + addcc %g1, %o0, %g7
6356 + casx [%o1], %g1, %g7
6357 + cmp %g1, %g7
6358 + bne,pn %xcc, 2f
6359 + nop
6360 + retl
6361 + nop
6362 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6363 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
6364 +
6365 .globl atomic64_sub
6366 .type atomic64_sub,#function
6367 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6368 BACKOFF_SETUP(%o2)
6369 1: ldx [%o1], %g1
6370 - sub %g1, %o0, %g7
6371 + subcc %g1, %o0, %g7
6372 +
6373 +#ifdef CONFIG_PAX_REFCOUNT
6374 + tvs %xcc, 6
6375 +#endif
6376 +
6377 casx [%o1], %g1, %g7
6378 cmp %g1, %g7
6379 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6380 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
6381 2: BACKOFF_SPIN(%o2, %o3, 1b)
6382 .size atomic64_sub, .-atomic64_sub
6383
6384 + .globl atomic64_sub_unchecked
6385 + .type atomic64_sub_unchecked,#function
6386 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
6387 + BACKOFF_SETUP(%o2)
6388 +1: ldx [%o1], %g1
6389 + subcc %g1, %o0, %g7
6390 + casx [%o1], %g1, %g7
6391 + cmp %g1, %g7
6392 + bne,pn %xcc, 2f
6393 + nop
6394 + retl
6395 + nop
6396 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6397 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
6398 +
6399 .globl atomic64_add_ret
6400 .type atomic64_add_ret,#function
6401 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6402 BACKOFF_SETUP(%o2)
6403 1: ldx [%o1], %g1
6404 - add %g1, %o0, %g7
6405 + addcc %g1, %o0, %g7
6406 +
6407 +#ifdef CONFIG_PAX_REFCOUNT
6408 + tvs %xcc, 6
6409 +#endif
6410 +
6411 casx [%o1], %g1, %g7
6412 cmp %g1, %g7
6413 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6414 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
6415 2: BACKOFF_SPIN(%o2, %o3, 1b)
6416 .size atomic64_add_ret, .-atomic64_add_ret
6417
6418 + .globl atomic64_add_ret_unchecked
6419 + .type atomic64_add_ret_unchecked,#function
6420 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
6421 + BACKOFF_SETUP(%o2)
6422 +1: ldx [%o1], %g1
6423 + addcc %g1, %o0, %g7
6424 + casx [%o1], %g1, %g7
6425 + cmp %g1, %g7
6426 + bne,pn %xcc, 2f
6427 + add %g7, %o0, %g7
6428 + mov %g7, %o0
6429 + retl
6430 + nop
6431 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6432 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
6433 +
6434 .globl atomic64_sub_ret
6435 .type atomic64_sub_ret,#function
6436 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
6437 BACKOFF_SETUP(%o2)
6438 1: ldx [%o1], %g1
6439 - sub %g1, %o0, %g7
6440 + subcc %g1, %o0, %g7
6441 +
6442 +#ifdef CONFIG_PAX_REFCOUNT
6443 + tvs %xcc, 6
6444 +#endif
6445 +
6446 casx [%o1], %g1, %g7
6447 cmp %g1, %g7
6448 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6449 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6450 index f73c224..662af10 100644
6451 --- a/arch/sparc/lib/ksyms.c
6452 +++ b/arch/sparc/lib/ksyms.c
6453 @@ -136,12 +136,18 @@ EXPORT_SYMBOL(__downgrade_write);
6454
6455 /* Atomic counter implementation. */
6456 EXPORT_SYMBOL(atomic_add);
6457 +EXPORT_SYMBOL(atomic_add_unchecked);
6458 EXPORT_SYMBOL(atomic_add_ret);
6459 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6460 EXPORT_SYMBOL(atomic_sub);
6461 +EXPORT_SYMBOL(atomic_sub_unchecked);
6462 EXPORT_SYMBOL(atomic_sub_ret);
6463 EXPORT_SYMBOL(atomic64_add);
6464 +EXPORT_SYMBOL(atomic64_add_unchecked);
6465 EXPORT_SYMBOL(atomic64_add_ret);
6466 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6467 EXPORT_SYMBOL(atomic64_sub);
6468 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6469 EXPORT_SYMBOL(atomic64_sub_ret);
6470
6471 /* Atomic bit operations. */
6472 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6473 index 301421c..e2535d1 100644
6474 --- a/arch/sparc/mm/Makefile
6475 +++ b/arch/sparc/mm/Makefile
6476 @@ -2,7 +2,7 @@
6477 #
6478
6479 asflags-y := -ansi
6480 -ccflags-y := -Werror
6481 +#ccflags-y := -Werror
6482
6483 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6484 obj-y += fault_$(BITS).o
6485 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6486 index 8023fd7..c8e89e9 100644
6487 --- a/arch/sparc/mm/fault_32.c
6488 +++ b/arch/sparc/mm/fault_32.c
6489 @@ -21,6 +21,9 @@
6490 #include <linux/perf_event.h>
6491 #include <linux/interrupt.h>
6492 #include <linux/kdebug.h>
6493 +#include <linux/slab.h>
6494 +#include <linux/pagemap.h>
6495 +#include <linux/compiler.h>
6496
6497 #include <asm/system.h>
6498 #include <asm/page.h>
6499 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6500 return safe_compute_effective_address(regs, insn);
6501 }
6502
6503 +#ifdef CONFIG_PAX_PAGEEXEC
6504 +#ifdef CONFIG_PAX_DLRESOLVE
6505 +static void pax_emuplt_close(struct vm_area_struct *vma)
6506 +{
6507 + vma->vm_mm->call_dl_resolve = 0UL;
6508 +}
6509 +
6510 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6511 +{
6512 + unsigned int *kaddr;
6513 +
6514 + vmf->page = alloc_page(GFP_HIGHUSER);
6515 + if (!vmf->page)
6516 + return VM_FAULT_OOM;
6517 +
6518 + kaddr = kmap(vmf->page);
6519 + memset(kaddr, 0, PAGE_SIZE);
6520 + kaddr[0] = 0x9DE3BFA8U; /* save */
6521 + flush_dcache_page(vmf->page);
6522 + kunmap(vmf->page);
6523 + return VM_FAULT_MAJOR;
6524 +}
6525 +
6526 +static const struct vm_operations_struct pax_vm_ops = {
6527 + .close = pax_emuplt_close,
6528 + .fault = pax_emuplt_fault
6529 +};
6530 +
6531 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6532 +{
6533 + int ret;
6534 +
6535 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6536 + vma->vm_mm = current->mm;
6537 + vma->vm_start = addr;
6538 + vma->vm_end = addr + PAGE_SIZE;
6539 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6540 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6541 + vma->vm_ops = &pax_vm_ops;
6542 +
6543 + ret = insert_vm_struct(current->mm, vma);
6544 + if (ret)
6545 + return ret;
6546 +
6547 + ++current->mm->total_vm;
6548 + return 0;
6549 +}
6550 +#endif
6551 +
6552 +/*
6553 + * PaX: decide what to do with offenders (regs->pc = fault address)
6554 + *
6555 + * returns 1 when task should be killed
6556 + * 2 when patched PLT trampoline was detected
6557 + * 3 when unpatched PLT trampoline was detected
6558 + */
6559 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6560 +{
6561 +
6562 +#ifdef CONFIG_PAX_EMUPLT
6563 + int err;
6564 +
6565 + do { /* PaX: patched PLT emulation #1 */
6566 + unsigned int sethi1, sethi2, jmpl;
6567 +
6568 + err = get_user(sethi1, (unsigned int *)regs->pc);
6569 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6570 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6571 +
6572 + if (err)
6573 + break;
6574 +
6575 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6576 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6577 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6578 + {
6579 + unsigned int addr;
6580 +
6581 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6582 + addr = regs->u_regs[UREG_G1];
6583 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6584 + regs->pc = addr;
6585 + regs->npc = addr+4;
6586 + return 2;
6587 + }
6588 + } while (0);
6589 +
6590 + { /* PaX: patched PLT emulation #2 */
6591 + unsigned int ba;
6592 +
6593 + err = get_user(ba, (unsigned int *)regs->pc);
6594 +
6595 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6596 + unsigned int addr;
6597 +
6598 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6599 + regs->pc = addr;
6600 + regs->npc = addr+4;
6601 + return 2;
6602 + }
6603 + }
6604 +
6605 + do { /* PaX: patched PLT emulation #3 */
6606 + unsigned int sethi, jmpl, nop;
6607 +
6608 + err = get_user(sethi, (unsigned int *)regs->pc);
6609 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
6610 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6611 +
6612 + if (err)
6613 + break;
6614 +
6615 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6616 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6617 + nop == 0x01000000U)
6618 + {
6619 + unsigned int addr;
6620 +
6621 + addr = (sethi & 0x003FFFFFU) << 10;
6622 + regs->u_regs[UREG_G1] = addr;
6623 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6624 + regs->pc = addr;
6625 + regs->npc = addr+4;
6626 + return 2;
6627 + }
6628 + } while (0);
6629 +
6630 + do { /* PaX: unpatched PLT emulation step 1 */
6631 + unsigned int sethi, ba, nop;
6632 +
6633 + err = get_user(sethi, (unsigned int *)regs->pc);
6634 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6635 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6636 +
6637 + if (err)
6638 + break;
6639 +
6640 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6641 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6642 + nop == 0x01000000U)
6643 + {
6644 + unsigned int addr, save, call;
6645 +
6646 + if ((ba & 0xFFC00000U) == 0x30800000U)
6647 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6648 + else
6649 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6650 +
6651 + err = get_user(save, (unsigned int *)addr);
6652 + err |= get_user(call, (unsigned int *)(addr+4));
6653 + err |= get_user(nop, (unsigned int *)(addr+8));
6654 + if (err)
6655 + break;
6656 +
6657 +#ifdef CONFIG_PAX_DLRESOLVE
6658 + if (save == 0x9DE3BFA8U &&
6659 + (call & 0xC0000000U) == 0x40000000U &&
6660 + nop == 0x01000000U)
6661 + {
6662 + struct vm_area_struct *vma;
6663 + unsigned long call_dl_resolve;
6664 +
6665 + down_read(&current->mm->mmap_sem);
6666 + call_dl_resolve = current->mm->call_dl_resolve;
6667 + up_read(&current->mm->mmap_sem);
6668 + if (likely(call_dl_resolve))
6669 + goto emulate;
6670 +
6671 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6672 +
6673 + down_write(&current->mm->mmap_sem);
6674 + if (current->mm->call_dl_resolve) {
6675 + call_dl_resolve = current->mm->call_dl_resolve;
6676 + up_write(&current->mm->mmap_sem);
6677 + if (vma)
6678 + kmem_cache_free(vm_area_cachep, vma);
6679 + goto emulate;
6680 + }
6681 +
6682 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6683 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6684 + up_write(&current->mm->mmap_sem);
6685 + if (vma)
6686 + kmem_cache_free(vm_area_cachep, vma);
6687 + return 1;
6688 + }
6689 +
6690 + if (pax_insert_vma(vma, call_dl_resolve)) {
6691 + up_write(&current->mm->mmap_sem);
6692 + kmem_cache_free(vm_area_cachep, vma);
6693 + return 1;
6694 + }
6695 +
6696 + current->mm->call_dl_resolve = call_dl_resolve;
6697 + up_write(&current->mm->mmap_sem);
6698 +
6699 +emulate:
6700 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6701 + regs->pc = call_dl_resolve;
6702 + regs->npc = addr+4;
6703 + return 3;
6704 + }
6705 +#endif
6706 +
6707 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6708 + if ((save & 0xFFC00000U) == 0x05000000U &&
6709 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6710 + nop == 0x01000000U)
6711 + {
6712 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6713 + regs->u_regs[UREG_G2] = addr + 4;
6714 + addr = (save & 0x003FFFFFU) << 10;
6715 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6716 + regs->pc = addr;
6717 + regs->npc = addr+4;
6718 + return 3;
6719 + }
6720 + }
6721 + } while (0);
6722 +
6723 + do { /* PaX: unpatched PLT emulation step 2 */
6724 + unsigned int save, call, nop;
6725 +
6726 + err = get_user(save, (unsigned int *)(regs->pc-4));
6727 + err |= get_user(call, (unsigned int *)regs->pc);
6728 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6729 + if (err)
6730 + break;
6731 +
6732 + if (save == 0x9DE3BFA8U &&
6733 + (call & 0xC0000000U) == 0x40000000U &&
6734 + nop == 0x01000000U)
6735 + {
6736 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6737 +
6738 + regs->u_regs[UREG_RETPC] = regs->pc;
6739 + regs->pc = dl_resolve;
6740 + regs->npc = dl_resolve+4;
6741 + return 3;
6742 + }
6743 + } while (0);
6744 +#endif
6745 +
6746 + return 1;
6747 +}
6748 +
6749 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6750 +{
6751 + unsigned long i;
6752 +
6753 + printk(KERN_ERR "PAX: bytes at PC: ");
6754 + for (i = 0; i < 8; i++) {
6755 + unsigned int c;
6756 + if (get_user(c, (unsigned int *)pc+i))
6757 + printk(KERN_CONT "???????? ");
6758 + else
6759 + printk(KERN_CONT "%08x ", c);
6760 + }
6761 + printk("\n");
6762 +}
6763 +#endif
6764 +
6765 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6766 int text_fault)
6767 {
6768 @@ -280,6 +545,24 @@ good_area:
6769 if(!(vma->vm_flags & VM_WRITE))
6770 goto bad_area;
6771 } else {
6772 +
6773 +#ifdef CONFIG_PAX_PAGEEXEC
6774 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6775 + up_read(&mm->mmap_sem);
6776 + switch (pax_handle_fetch_fault(regs)) {
6777 +
6778 +#ifdef CONFIG_PAX_EMUPLT
6779 + case 2:
6780 + case 3:
6781 + return;
6782 +#endif
6783 +
6784 + }
6785 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6786 + do_group_exit(SIGKILL);
6787 + }
6788 +#endif
6789 +
6790 /* Allow reads even for write-only mappings */
6791 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
6792 goto bad_area;
6793 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6794 index 504c062..6fcb9c6 100644
6795 --- a/arch/sparc/mm/fault_64.c
6796 +++ b/arch/sparc/mm/fault_64.c
6797 @@ -21,6 +21,9 @@
6798 #include <linux/kprobes.h>
6799 #include <linux/kdebug.h>
6800 #include <linux/percpu.h>
6801 +#include <linux/slab.h>
6802 +#include <linux/pagemap.h>
6803 +#include <linux/compiler.h>
6804
6805 #include <asm/page.h>
6806 #include <asm/pgtable.h>
6807 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6808 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6809 regs->tpc);
6810 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6811 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6812 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6813 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6814 dump_stack();
6815 unhandled_fault(regs->tpc, current, regs);
6816 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6817 show_regs(regs);
6818 }
6819
6820 +#ifdef CONFIG_PAX_PAGEEXEC
6821 +#ifdef CONFIG_PAX_DLRESOLVE
6822 +static void pax_emuplt_close(struct vm_area_struct *vma)
6823 +{
6824 + vma->vm_mm->call_dl_resolve = 0UL;
6825 +}
6826 +
6827 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6828 +{
6829 + unsigned int *kaddr;
6830 +
6831 + vmf->page = alloc_page(GFP_HIGHUSER);
6832 + if (!vmf->page)
6833 + return VM_FAULT_OOM;
6834 +
6835 + kaddr = kmap(vmf->page);
6836 + memset(kaddr, 0, PAGE_SIZE);
6837 + kaddr[0] = 0x9DE3BFA8U; /* save */
6838 + flush_dcache_page(vmf->page);
6839 + kunmap(vmf->page);
6840 + return VM_FAULT_MAJOR;
6841 +}
6842 +
6843 +static const struct vm_operations_struct pax_vm_ops = {
6844 + .close = pax_emuplt_close,
6845 + .fault = pax_emuplt_fault
6846 +};
6847 +
6848 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6849 +{
6850 + int ret;
6851 +
6852 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6853 + vma->vm_mm = current->mm;
6854 + vma->vm_start = addr;
6855 + vma->vm_end = addr + PAGE_SIZE;
6856 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6857 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6858 + vma->vm_ops = &pax_vm_ops;
6859 +
6860 + ret = insert_vm_struct(current->mm, vma);
6861 + if (ret)
6862 + return ret;
6863 +
6864 + ++current->mm->total_vm;
6865 + return 0;
6866 +}
6867 +#endif
6868 +
6869 +/*
6870 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6871 + *
6872 + * returns 1 when task should be killed
6873 + * 2 when patched PLT trampoline was detected
6874 + * 3 when unpatched PLT trampoline was detected
6875 + */
6876 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6877 +{
6878 +
6879 +#ifdef CONFIG_PAX_EMUPLT
6880 + int err;
6881 +
6882 + do { /* PaX: patched PLT emulation #1 */
6883 + unsigned int sethi1, sethi2, jmpl;
6884 +
6885 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6886 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6887 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6888 +
6889 + if (err)
6890 + break;
6891 +
6892 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6893 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6894 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6895 + {
6896 + unsigned long addr;
6897 +
6898 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6899 + addr = regs->u_regs[UREG_G1];
6900 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6901 +
6902 + if (test_thread_flag(TIF_32BIT))
6903 + addr &= 0xFFFFFFFFUL;
6904 +
6905 + regs->tpc = addr;
6906 + regs->tnpc = addr+4;
6907 + return 2;
6908 + }
6909 + } while (0);
6910 +
6911 + { /* PaX: patched PLT emulation #2 */
6912 + unsigned int ba;
6913 +
6914 + err = get_user(ba, (unsigned int *)regs->tpc);
6915 +
6916 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
6917 + unsigned long addr;
6918 +
6919 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6920 +
6921 + if (test_thread_flag(TIF_32BIT))
6922 + addr &= 0xFFFFFFFFUL;
6923 +
6924 + regs->tpc = addr;
6925 + regs->tnpc = addr+4;
6926 + return 2;
6927 + }
6928 + }
6929 +
6930 + do { /* PaX: patched PLT emulation #3 */
6931 + unsigned int sethi, jmpl, nop;
6932 +
6933 + err = get_user(sethi, (unsigned int *)regs->tpc);
6934 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
6935 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6936 +
6937 + if (err)
6938 + break;
6939 +
6940 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6941 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
6942 + nop == 0x01000000U)
6943 + {
6944 + unsigned long addr;
6945 +
6946 + addr = (sethi & 0x003FFFFFU) << 10;
6947 + regs->u_regs[UREG_G1] = addr;
6948 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6949 +
6950 + if (test_thread_flag(TIF_32BIT))
6951 + addr &= 0xFFFFFFFFUL;
6952 +
6953 + regs->tpc = addr;
6954 + regs->tnpc = addr+4;
6955 + return 2;
6956 + }
6957 + } while (0);
6958 +
6959 + do { /* PaX: patched PLT emulation #4 */
6960 + unsigned int sethi, mov1, call, mov2;
6961 +
6962 + err = get_user(sethi, (unsigned int *)regs->tpc);
6963 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6964 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6965 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6966 +
6967 + if (err)
6968 + break;
6969 +
6970 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6971 + mov1 == 0x8210000FU &&
6972 + (call & 0xC0000000U) == 0x40000000U &&
6973 + mov2 == 0x9E100001U)
6974 + {
6975 + unsigned long addr;
6976 +
6977 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6978 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6979 +
6980 + if (test_thread_flag(TIF_32BIT))
6981 + addr &= 0xFFFFFFFFUL;
6982 +
6983 + regs->tpc = addr;
6984 + regs->tnpc = addr+4;
6985 + return 2;
6986 + }
6987 + } while (0);
6988 +
6989 + do { /* PaX: patched PLT emulation #5 */
6990 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6991 +
6992 + err = get_user(sethi, (unsigned int *)regs->tpc);
6993 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6994 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6995 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6996 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6997 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6998 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6999 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7000 +
7001 + if (err)
7002 + break;
7003 +
7004 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7005 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7006 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7007 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7008 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7009 + sllx == 0x83287020U &&
7010 + jmpl == 0x81C04005U &&
7011 + nop == 0x01000000U)
7012 + {
7013 + unsigned long addr;
7014 +
7015 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7016 + regs->u_regs[UREG_G1] <<= 32;
7017 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7018 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7019 + regs->tpc = addr;
7020 + regs->tnpc = addr+4;
7021 + return 2;
7022 + }
7023 + } while (0);
7024 +
7025 + do { /* PaX: patched PLT emulation #6 */
7026 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7027 +
7028 + err = get_user(sethi, (unsigned int *)regs->tpc);
7029 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7030 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7031 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7032 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7033 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7034 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7035 +
7036 + if (err)
7037 + break;
7038 +
7039 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7040 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7041 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7042 + sllx == 0x83287020U &&
7043 + (or & 0xFFFFE000U) == 0x8A116000U &&
7044 + jmpl == 0x81C04005U &&
7045 + nop == 0x01000000U)
7046 + {
7047 + unsigned long addr;
7048 +
7049 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7050 + regs->u_regs[UREG_G1] <<= 32;
7051 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7052 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7053 + regs->tpc = addr;
7054 + regs->tnpc = addr+4;
7055 + return 2;
7056 + }
7057 + } while (0);
7058 +
7059 + do { /* PaX: unpatched PLT emulation step 1 */
7060 + unsigned int sethi, ba, nop;
7061 +
7062 + err = get_user(sethi, (unsigned int *)regs->tpc);
7063 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7064 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7065 +
7066 + if (err)
7067 + break;
7068 +
7069 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7070 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7071 + nop == 0x01000000U)
7072 + {
7073 + unsigned long addr;
7074 + unsigned int save, call;
7075 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7076 +
7077 + if ((ba & 0xFFC00000U) == 0x30800000U)
7078 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7079 + else
7080 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7081 +
7082 + if (test_thread_flag(TIF_32BIT))
7083 + addr &= 0xFFFFFFFFUL;
7084 +
7085 + err = get_user(save, (unsigned int *)addr);
7086 + err |= get_user(call, (unsigned int *)(addr+4));
7087 + err |= get_user(nop, (unsigned int *)(addr+8));
7088 + if (err)
7089 + break;
7090 +
7091 +#ifdef CONFIG_PAX_DLRESOLVE
7092 + if (save == 0x9DE3BFA8U &&
7093 + (call & 0xC0000000U) == 0x40000000U &&
7094 + nop == 0x01000000U)
7095 + {
7096 + struct vm_area_struct *vma;
7097 + unsigned long call_dl_resolve;
7098 +
7099 + down_read(&current->mm->mmap_sem);
7100 + call_dl_resolve = current->mm->call_dl_resolve;
7101 + up_read(&current->mm->mmap_sem);
7102 + if (likely(call_dl_resolve))
7103 + goto emulate;
7104 +
7105 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7106 +
7107 + down_write(&current->mm->mmap_sem);
7108 + if (current->mm->call_dl_resolve) {
7109 + call_dl_resolve = current->mm->call_dl_resolve;
7110 + up_write(&current->mm->mmap_sem);
7111 + if (vma)
7112 + kmem_cache_free(vm_area_cachep, vma);
7113 + goto emulate;
7114 + }
7115 +
7116 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7117 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7118 + up_write(&current->mm->mmap_sem);
7119 + if (vma)
7120 + kmem_cache_free(vm_area_cachep, vma);
7121 + return 1;
7122 + }
7123 +
7124 + if (pax_insert_vma(vma, call_dl_resolve)) {
7125 + up_write(&current->mm->mmap_sem);
7126 + kmem_cache_free(vm_area_cachep, vma);
7127 + return 1;
7128 + }
7129 +
7130 + current->mm->call_dl_resolve = call_dl_resolve;
7131 + up_write(&current->mm->mmap_sem);
7132 +
7133 +emulate:
7134 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7135 + regs->tpc = call_dl_resolve;
7136 + regs->tnpc = addr+4;
7137 + return 3;
7138 + }
7139 +#endif
7140 +
7141 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7142 + if ((save & 0xFFC00000U) == 0x05000000U &&
7143 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7144 + nop == 0x01000000U)
7145 + {
7146 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7147 + regs->u_regs[UREG_G2] = addr + 4;
7148 + addr = (save & 0x003FFFFFU) << 10;
7149 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7150 +
7151 + if (test_thread_flag(TIF_32BIT))
7152 + addr &= 0xFFFFFFFFUL;
7153 +
7154 + regs->tpc = addr;
7155 + regs->tnpc = addr+4;
7156 + return 3;
7157 + }
7158 +
7159 + /* PaX: 64-bit PLT stub */
7160 + err = get_user(sethi1, (unsigned int *)addr);
7161 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7162 + err |= get_user(or1, (unsigned int *)(addr+8));
7163 + err |= get_user(or2, (unsigned int *)(addr+12));
7164 + err |= get_user(sllx, (unsigned int *)(addr+16));
7165 + err |= get_user(add, (unsigned int *)(addr+20));
7166 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7167 + err |= get_user(nop, (unsigned int *)(addr+28));
7168 + if (err)
7169 + break;
7170 +
7171 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7172 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7173 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7174 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7175 + sllx == 0x89293020U &&
7176 + add == 0x8A010005U &&
7177 + jmpl == 0x89C14000U &&
7178 + nop == 0x01000000U)
7179 + {
7180 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7181 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7182 + regs->u_regs[UREG_G4] <<= 32;
7183 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7184 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7185 + regs->u_regs[UREG_G4] = addr + 24;
7186 + addr = regs->u_regs[UREG_G5];
7187 + regs->tpc = addr;
7188 + regs->tnpc = addr+4;
7189 + return 3;
7190 + }
7191 + }
7192 + } while (0);
7193 +
7194 +#ifdef CONFIG_PAX_DLRESOLVE
7195 + do { /* PaX: unpatched PLT emulation step 2 */
7196 + unsigned int save, call, nop;
7197 +
7198 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7199 + err |= get_user(call, (unsigned int *)regs->tpc);
7200 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7201 + if (err)
7202 + break;
7203 +
7204 + if (save == 0x9DE3BFA8U &&
7205 + (call & 0xC0000000U) == 0x40000000U &&
7206 + nop == 0x01000000U)
7207 + {
7208 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7209 +
7210 + if (test_thread_flag(TIF_32BIT))
7211 + dl_resolve &= 0xFFFFFFFFUL;
7212 +
7213 + regs->u_regs[UREG_RETPC] = regs->tpc;
7214 + regs->tpc = dl_resolve;
7215 + regs->tnpc = dl_resolve+4;
7216 + return 3;
7217 + }
7218 + } while (0);
7219 +#endif
7220 +
7221 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7222 + unsigned int sethi, ba, nop;
7223 +
7224 + err = get_user(sethi, (unsigned int *)regs->tpc);
7225 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7226 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7227 +
7228 + if (err)
7229 + break;
7230 +
7231 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7232 + (ba & 0xFFF00000U) == 0x30600000U &&
7233 + nop == 0x01000000U)
7234 + {
7235 + unsigned long addr;
7236 +
7237 + addr = (sethi & 0x003FFFFFU) << 10;
7238 + regs->u_regs[UREG_G1] = addr;
7239 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7240 +
7241 + if (test_thread_flag(TIF_32BIT))
7242 + addr &= 0xFFFFFFFFUL;
7243 +
7244 + regs->tpc = addr;
7245 + regs->tnpc = addr+4;
7246 + return 2;
7247 + }
7248 + } while (0);
7249 +
7250 +#endif
7251 +
7252 + return 1;
7253 +}
7254 +
7255 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7256 +{
7257 + unsigned long i;
7258 +
7259 + printk(KERN_ERR "PAX: bytes at PC: ");
7260 + for (i = 0; i < 8; i++) {
7261 + unsigned int c;
7262 + if (get_user(c, (unsigned int *)pc+i))
7263 + printk(KERN_CONT "???????? ");
7264 + else
7265 + printk(KERN_CONT "%08x ", c);
7266 + }
7267 + printk("\n");
7268 +}
7269 +#endif
7270 +
7271 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7272 {
7273 struct mm_struct *mm = current->mm;
7274 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7275 if (!vma)
7276 goto bad_area;
7277
7278 +#ifdef CONFIG_PAX_PAGEEXEC
7279 + /* PaX: detect ITLB misses on non-exec pages */
7280 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7281 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7282 + {
7283 + if (address != regs->tpc)
7284 + goto good_area;
7285 +
7286 + up_read(&mm->mmap_sem);
7287 + switch (pax_handle_fetch_fault(regs)) {
7288 +
7289 +#ifdef CONFIG_PAX_EMUPLT
7290 + case 2:
7291 + case 3:
7292 + return;
7293 +#endif
7294 +
7295 + }
7296 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7297 + do_group_exit(SIGKILL);
7298 + }
7299 +#endif
7300 +
7301 /* Pure DTLB misses do not tell us whether the fault causing
7302 * load/store/atomic was a write or not, it only says that there
7303 * was no match. So in such a case we (carefully) read the
7304 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7305 index 07e1453..0a7d9e9 100644
7306 --- a/arch/sparc/mm/hugetlbpage.c
7307 +++ b/arch/sparc/mm/hugetlbpage.c
7308 @@ -67,7 +67,7 @@ full_search:
7309 }
7310 return -ENOMEM;
7311 }
7312 - if (likely(!vma || addr + len <= vma->vm_start)) {
7313 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7314 /*
7315 * Remember the place where we stopped the search:
7316 */
7317 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7318 /* make sure it can fit in the remaining address space */
7319 if (likely(addr > len)) {
7320 vma = find_vma(mm, addr-len);
7321 - if (!vma || addr <= vma->vm_start) {
7322 + if (check_heap_stack_gap(vma, addr - len, len)) {
7323 /* remember the address as a hint for next time */
7324 return (mm->free_area_cache = addr-len);
7325 }
7326 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7327 if (unlikely(mm->mmap_base < len))
7328 goto bottomup;
7329
7330 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7331 + addr = mm->mmap_base - len;
7332
7333 do {
7334 + addr &= HPAGE_MASK;
7335 /*
7336 * Lookup failure means no vma is above this address,
7337 * else if new region fits below vma->vm_start,
7338 * return with success:
7339 */
7340 vma = find_vma(mm, addr);
7341 - if (likely(!vma || addr+len <= vma->vm_start)) {
7342 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7343 /* remember the address as a hint for next time */
7344 return (mm->free_area_cache = addr);
7345 }
7346 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7347 mm->cached_hole_size = vma->vm_start - addr;
7348
7349 /* try just below the current vma->vm_start */
7350 - addr = (vma->vm_start-len) & HPAGE_MASK;
7351 - } while (likely(len < vma->vm_start));
7352 + addr = skip_heap_stack_gap(vma, len);
7353 + } while (!IS_ERR_VALUE(addr));
7354
7355 bottomup:
7356 /*
7357 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7358 if (addr) {
7359 addr = ALIGN(addr, HPAGE_SIZE);
7360 vma = find_vma(mm, addr);
7361 - if (task_size - len >= addr &&
7362 - (!vma || addr + len <= vma->vm_start))
7363 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7364 return addr;
7365 }
7366 if (mm->get_unmapped_area == arch_get_unmapped_area)
7367 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
7368 index 7b00de6..78239f4 100644
7369 --- a/arch/sparc/mm/init_32.c
7370 +++ b/arch/sparc/mm/init_32.c
7371 @@ -316,6 +316,9 @@ extern void device_scan(void);
7372 pgprot_t PAGE_SHARED __read_mostly;
7373 EXPORT_SYMBOL(PAGE_SHARED);
7374
7375 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
7376 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
7377 +
7378 void __init paging_init(void)
7379 {
7380 switch(sparc_cpu_model) {
7381 @@ -344,17 +347,17 @@ void __init paging_init(void)
7382
7383 /* Initialize the protection map with non-constant, MMU dependent values. */
7384 protection_map[0] = PAGE_NONE;
7385 - protection_map[1] = PAGE_READONLY;
7386 - protection_map[2] = PAGE_COPY;
7387 - protection_map[3] = PAGE_COPY;
7388 + protection_map[1] = PAGE_READONLY_NOEXEC;
7389 + protection_map[2] = PAGE_COPY_NOEXEC;
7390 + protection_map[3] = PAGE_COPY_NOEXEC;
7391 protection_map[4] = PAGE_READONLY;
7392 protection_map[5] = PAGE_READONLY;
7393 protection_map[6] = PAGE_COPY;
7394 protection_map[7] = PAGE_COPY;
7395 protection_map[8] = PAGE_NONE;
7396 - protection_map[9] = PAGE_READONLY;
7397 - protection_map[10] = PAGE_SHARED;
7398 - protection_map[11] = PAGE_SHARED;
7399 + protection_map[9] = PAGE_READONLY_NOEXEC;
7400 + protection_map[10] = PAGE_SHARED_NOEXEC;
7401 + protection_map[11] = PAGE_SHARED_NOEXEC;
7402 protection_map[12] = PAGE_READONLY;
7403 protection_map[13] = PAGE_READONLY;
7404 protection_map[14] = PAGE_SHARED;
7405 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
7406 index cbef74e..c38fead 100644
7407 --- a/arch/sparc/mm/srmmu.c
7408 +++ b/arch/sparc/mm/srmmu.c
7409 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
7410 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
7411 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
7412 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
7413 +
7414 +#ifdef CONFIG_PAX_PAGEEXEC
7415 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
7416 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
7417 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
7418 +#endif
7419 +
7420 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
7421 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
7422
7423 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7424 index 27fe667..36d474c 100644
7425 --- a/arch/tile/include/asm/atomic_64.h
7426 +++ b/arch/tile/include/asm/atomic_64.h
7427 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7428
7429 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7430
7431 +#define atomic64_read_unchecked(v) atomic64_read(v)
7432 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7433 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7434 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7435 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7436 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7437 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7438 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7439 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7440 +
7441 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7442 #define smp_mb__before_atomic_dec() smp_mb()
7443 #define smp_mb__after_atomic_dec() smp_mb()
7444 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7445 index 392e533..536b092 100644
7446 --- a/arch/tile/include/asm/cache.h
7447 +++ b/arch/tile/include/asm/cache.h
7448 @@ -15,11 +15,12 @@
7449 #ifndef _ASM_TILE_CACHE_H
7450 #define _ASM_TILE_CACHE_H
7451
7452 +#include <linux/const.h>
7453 #include <arch/chip.h>
7454
7455 /* bytes per L1 data cache line */
7456 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7457 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7458 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7459
7460 /* bytes per L2 cache line */
7461 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7462 diff --git a/arch/um/Makefile b/arch/um/Makefile
7463 index 28688e6..4c0aa1c 100644
7464 --- a/arch/um/Makefile
7465 +++ b/arch/um/Makefile
7466 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7467 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7468 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7469
7470 +ifdef CONSTIFY_PLUGIN
7471 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7472 +endif
7473 +
7474 #This will adjust *FLAGS accordingly to the platform.
7475 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7476
7477 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7478 index 19e1bdd..3665b77 100644
7479 --- a/arch/um/include/asm/cache.h
7480 +++ b/arch/um/include/asm/cache.h
7481 @@ -1,6 +1,7 @@
7482 #ifndef __UM_CACHE_H
7483 #define __UM_CACHE_H
7484
7485 +#include <linux/const.h>
7486
7487 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7488 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7489 @@ -12,6 +13,6 @@
7490 # define L1_CACHE_SHIFT 5
7491 #endif
7492
7493 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7494 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7495
7496 #endif
7497 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7498 index 6c03acd..a5e0215 100644
7499 --- a/arch/um/include/asm/kmap_types.h
7500 +++ b/arch/um/include/asm/kmap_types.h
7501 @@ -23,6 +23,7 @@ enum km_type {
7502 KM_IRQ1,
7503 KM_SOFTIRQ0,
7504 KM_SOFTIRQ1,
7505 + KM_CLEARPAGE,
7506 KM_TYPE_NR
7507 };
7508
7509 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7510 index 7cfc3ce..cbd1a58 100644
7511 --- a/arch/um/include/asm/page.h
7512 +++ b/arch/um/include/asm/page.h
7513 @@ -14,6 +14,9 @@
7514 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7515 #define PAGE_MASK (~(PAGE_SIZE-1))
7516
7517 +#define ktla_ktva(addr) (addr)
7518 +#define ktva_ktla(addr) (addr)
7519 +
7520 #ifndef __ASSEMBLY__
7521
7522 struct page;
7523 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7524 index 0032f92..cd151e0 100644
7525 --- a/arch/um/include/asm/pgtable-3level.h
7526 +++ b/arch/um/include/asm/pgtable-3level.h
7527 @@ -58,6 +58,7 @@
7528 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7529 #define pud_populate(mm, pud, pmd) \
7530 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7531 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7532
7533 #ifdef CONFIG_64BIT
7534 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7535 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7536 index 69f2490..2634831 100644
7537 --- a/arch/um/kernel/process.c
7538 +++ b/arch/um/kernel/process.c
7539 @@ -408,22 +408,6 @@ int singlestepping(void * t)
7540 return 2;
7541 }
7542
7543 -/*
7544 - * Only x86 and x86_64 have an arch_align_stack().
7545 - * All other arches have "#define arch_align_stack(x) (x)"
7546 - * in their asm/system.h
7547 - * As this is included in UML from asm-um/system-generic.h,
7548 - * we can use it to behave as the subarch does.
7549 - */
7550 -#ifndef arch_align_stack
7551 -unsigned long arch_align_stack(unsigned long sp)
7552 -{
7553 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7554 - sp -= get_random_int() % 8192;
7555 - return sp & ~0xf;
7556 -}
7557 -#endif
7558 -
7559 unsigned long get_wchan(struct task_struct *p)
7560 {
7561 unsigned long stack_page, sp, ip;
7562 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7563 index ad8f795..2c7eec6 100644
7564 --- a/arch/unicore32/include/asm/cache.h
7565 +++ b/arch/unicore32/include/asm/cache.h
7566 @@ -12,8 +12,10 @@
7567 #ifndef __UNICORE_CACHE_H__
7568 #define __UNICORE_CACHE_H__
7569
7570 -#define L1_CACHE_SHIFT (5)
7571 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7572 +#include <linux/const.h>
7573 +
7574 +#define L1_CACHE_SHIFT 5
7575 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7576
7577 /*
7578 * Memory returned by kmalloc() may be used for DMA, so we must make
7579 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7580 index 5bed94e..fbcf200 100644
7581 --- a/arch/x86/Kconfig
7582 +++ b/arch/x86/Kconfig
7583 @@ -226,7 +226,7 @@ config X86_HT
7584
7585 config X86_32_LAZY_GS
7586 def_bool y
7587 - depends on X86_32 && !CC_STACKPROTECTOR
7588 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7589
7590 config ARCH_HWEIGHT_CFLAGS
7591 string
7592 @@ -1058,7 +1058,7 @@ choice
7593
7594 config NOHIGHMEM
7595 bool "off"
7596 - depends on !X86_NUMAQ
7597 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7598 ---help---
7599 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7600 However, the address space of 32-bit x86 processors is only 4
7601 @@ -1095,7 +1095,7 @@ config NOHIGHMEM
7602
7603 config HIGHMEM4G
7604 bool "4GB"
7605 - depends on !X86_NUMAQ
7606 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7607 ---help---
7608 Select this if you have a 32-bit processor and between 1 and 4
7609 gigabytes of physical RAM.
7610 @@ -1149,7 +1149,7 @@ config PAGE_OFFSET
7611 hex
7612 default 0xB0000000 if VMSPLIT_3G_OPT
7613 default 0x80000000 if VMSPLIT_2G
7614 - default 0x78000000 if VMSPLIT_2G_OPT
7615 + default 0x70000000 if VMSPLIT_2G_OPT
7616 default 0x40000000 if VMSPLIT_1G
7617 default 0xC0000000
7618 depends on X86_32
7619 @@ -1539,6 +1539,7 @@ config SECCOMP
7620
7621 config CC_STACKPROTECTOR
7622 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7623 + depends on X86_64 || !PAX_MEMORY_UDEREF
7624 ---help---
7625 This option turns on the -fstack-protector GCC feature. This
7626 feature puts, at the beginning of functions, a canary value on
7627 @@ -1596,6 +1597,7 @@ config KEXEC_JUMP
7628 config PHYSICAL_START
7629 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7630 default "0x1000000"
7631 + range 0x400000 0x40000000
7632 ---help---
7633 This gives the physical address where the kernel is loaded.
7634
7635 @@ -1659,6 +1661,7 @@ config X86_NEED_RELOCS
7636 config PHYSICAL_ALIGN
7637 hex "Alignment value to which kernel should be aligned" if X86_32
7638 default "0x1000000"
7639 + range 0x400000 0x1000000 if PAX_KERNEXEC
7640 range 0x2000 0x1000000
7641 ---help---
7642 This value puts the alignment restrictions on physical address
7643 @@ -1690,9 +1693,10 @@ config HOTPLUG_CPU
7644 Say N if you want to disable CPU hotplug.
7645
7646 config COMPAT_VDSO
7647 - def_bool y
7648 + def_bool n
7649 prompt "Compat VDSO support"
7650 depends on X86_32 || IA32_EMULATION
7651 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7652 ---help---
7653 Map the 32-bit VDSO to the predictable old-style address too.
7654
7655 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7656 index 3c57033..22d44aa 100644
7657 --- a/arch/x86/Kconfig.cpu
7658 +++ b/arch/x86/Kconfig.cpu
7659 @@ -335,7 +335,7 @@ config X86_PPRO_FENCE
7660
7661 config X86_F00F_BUG
7662 def_bool y
7663 - depends on M586MMX || M586TSC || M586 || M486 || M386
7664 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7665
7666 config X86_INVD_BUG
7667 def_bool y
7668 @@ -359,7 +359,7 @@ config X86_POPAD_OK
7669
7670 config X86_ALIGNMENT_16
7671 def_bool y
7672 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7673 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7674
7675 config X86_INTEL_USERCOPY
7676 def_bool y
7677 @@ -405,7 +405,7 @@ config X86_CMPXCHG64
7678 # generates cmov.
7679 config X86_CMOV
7680 def_bool y
7681 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7682 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7683
7684 config X86_MINIMUM_CPU_FAMILY
7685 int
7686 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7687 index e46c214..7c72b55 100644
7688 --- a/arch/x86/Kconfig.debug
7689 +++ b/arch/x86/Kconfig.debug
7690 @@ -84,7 +84,7 @@ config X86_PTDUMP
7691 config DEBUG_RODATA
7692 bool "Write protect kernel read-only data structures"
7693 default y
7694 - depends on DEBUG_KERNEL
7695 + depends on DEBUG_KERNEL && BROKEN
7696 ---help---
7697 Mark the kernel read-only data as write-protected in the pagetables,
7698 in order to catch accidental (and incorrect) writes to such const
7699 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7700
7701 config DEBUG_SET_MODULE_RONX
7702 bool "Set loadable kernel module data as NX and text as RO"
7703 - depends on MODULES
7704 + depends on MODULES && BROKEN
7705 ---help---
7706 This option helps catch unintended modifications to loadable
7707 kernel module's text and read-only data. It also prevents execution
7708 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7709 index 015f0c5..b405802 100644
7710 --- a/arch/x86/Makefile
7711 +++ b/arch/x86/Makefile
7712 @@ -46,6 +46,7 @@ else
7713 UTS_MACHINE := x86_64
7714 CHECKFLAGS += -D__x86_64__ -m64
7715
7716 + biarch := $(call cc-option,-m64)
7717 KBUILD_AFLAGS += -m64
7718 KBUILD_CFLAGS += -m64
7719
7720 @@ -205,3 +206,12 @@ define archhelp
7721 echo ' FDARGS="..." arguments for the booted kernel'
7722 echo ' FDINITRD=file initrd for the booted kernel'
7723 endef
7724 +
7725 +define OLD_LD
7726 +
7727 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7728 +*** Please upgrade your binutils to 2.18 or newer
7729 +endef
7730 +
7731 +archprepare:
7732 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7733 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7734 index 5a747dd..ff7b12c 100644
7735 --- a/arch/x86/boot/Makefile
7736 +++ b/arch/x86/boot/Makefile
7737 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7738 $(call cc-option, -fno-stack-protector) \
7739 $(call cc-option, -mpreferred-stack-boundary=2)
7740 KBUILD_CFLAGS += $(call cc-option, -m32)
7741 +ifdef CONSTIFY_PLUGIN
7742 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7743 +endif
7744 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7745 GCOV_PROFILE := n
7746
7747 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7748 index 878e4b9..20537ab 100644
7749 --- a/arch/x86/boot/bitops.h
7750 +++ b/arch/x86/boot/bitops.h
7751 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7752 u8 v;
7753 const u32 *p = (const u32 *)addr;
7754
7755 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7756 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7757 return v;
7758 }
7759
7760 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7761
7762 static inline void set_bit(int nr, void *addr)
7763 {
7764 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7765 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7766 }
7767
7768 #endif /* BOOT_BITOPS_H */
7769 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7770 index c7093bd..d4247ffe0 100644
7771 --- a/arch/x86/boot/boot.h
7772 +++ b/arch/x86/boot/boot.h
7773 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7774 static inline u16 ds(void)
7775 {
7776 u16 seg;
7777 - asm("movw %%ds,%0" : "=rm" (seg));
7778 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7779 return seg;
7780 }
7781
7782 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7783 static inline int memcmp(const void *s1, const void *s2, size_t len)
7784 {
7785 u8 diff;
7786 - asm("repe; cmpsb; setnz %0"
7787 + asm volatile("repe; cmpsb; setnz %0"
7788 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7789 return diff;
7790 }
7791 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7792 index e398bb5..3a382ca 100644
7793 --- a/arch/x86/boot/compressed/Makefile
7794 +++ b/arch/x86/boot/compressed/Makefile
7795 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7796 KBUILD_CFLAGS += $(cflags-y)
7797 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7798 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7799 +ifdef CONSTIFY_PLUGIN
7800 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
7801 +endif
7802
7803 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7804 GCOV_PROFILE := n
7805 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7806 index 0cdfc0d..6e79437 100644
7807 --- a/arch/x86/boot/compressed/eboot.c
7808 +++ b/arch/x86/boot/compressed/eboot.c
7809 @@ -122,7 +122,6 @@ again:
7810 *addr = max_addr;
7811 }
7812
7813 -free_pool:
7814 efi_call_phys1(sys_table->boottime->free_pool, map);
7815
7816 fail:
7817 @@ -186,7 +185,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7818 if (i == map_size / desc_size)
7819 status = EFI_NOT_FOUND;
7820
7821 -free_pool:
7822 efi_call_phys1(sys_table->boottime->free_pool, map);
7823 fail:
7824 return status;
7825 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7826 index c85e3ac..6f5aa80 100644
7827 --- a/arch/x86/boot/compressed/head_32.S
7828 +++ b/arch/x86/boot/compressed/head_32.S
7829 @@ -106,7 +106,7 @@ preferred_addr:
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 @@ -192,7 +192,7 @@ relocated:
7839 * and where it was actually loaded.
7840 */
7841 movl %ebp, %ebx
7842 - subl $LOAD_PHYSICAL_ADDR, %ebx
7843 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7844 jz 2f /* Nothing to be done if loaded at compiled addr. */
7845 /*
7846 * Process relocations.
7847 @@ -200,8 +200,7 @@ relocated:
7848
7849 1: subl $4, %edi
7850 movl (%edi), %ecx
7851 - testl %ecx, %ecx
7852 - jz 2f
7853 + jecxz 2f
7854 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7855 jmp 1b
7856 2:
7857 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7858 index 87e03a1..0d94c76 100644
7859 --- a/arch/x86/boot/compressed/head_64.S
7860 +++ b/arch/x86/boot/compressed/head_64.S
7861 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7862 notl %eax
7863 andl %eax, %ebx
7864 #else
7865 - movl $LOAD_PHYSICAL_ADDR, %ebx
7866 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7867 #endif
7868
7869 /* Target address to relocate to for decompression */
7870 @@ -263,7 +263,7 @@ preferred_addr:
7871 notq %rax
7872 andq %rax, %rbp
7873 #else
7874 - movq $LOAD_PHYSICAL_ADDR, %rbp
7875 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7876 #endif
7877
7878 /* Target address to relocate to for decompression */
7879 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7880 index 7116dcb..d9ae1d7 100644
7881 --- a/arch/x86/boot/compressed/misc.c
7882 +++ b/arch/x86/boot/compressed/misc.c
7883 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7884 case PT_LOAD:
7885 #ifdef CONFIG_RELOCATABLE
7886 dest = output;
7887 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7888 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7889 #else
7890 dest = (void *)(phdr->p_paddr);
7891 #endif
7892 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7893 error("Destination address too large");
7894 #endif
7895 #ifndef CONFIG_RELOCATABLE
7896 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7897 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7898 error("Wrong destination address");
7899 #endif
7900
7901 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7902 index 4d3ff03..e4972ff 100644
7903 --- a/arch/x86/boot/cpucheck.c
7904 +++ b/arch/x86/boot/cpucheck.c
7905 @@ -74,7 +74,7 @@ static int has_fpu(void)
7906 u16 fcw = -1, fsw = -1;
7907 u32 cr0;
7908
7909 - asm("movl %%cr0,%0" : "=r" (cr0));
7910 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7911 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7912 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7913 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7914 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7915 {
7916 u32 f0, f1;
7917
7918 - asm("pushfl ; "
7919 + asm volatile("pushfl ; "
7920 "pushfl ; "
7921 "popl %0 ; "
7922 "movl %0,%1 ; "
7923 @@ -115,7 +115,7 @@ static void get_flags(void)
7924 set_bit(X86_FEATURE_FPU, cpu.flags);
7925
7926 if (has_eflag(X86_EFLAGS_ID)) {
7927 - asm("cpuid"
7928 + asm volatile("cpuid"
7929 : "=a" (max_intel_level),
7930 "=b" (cpu_vendor[0]),
7931 "=d" (cpu_vendor[1]),
7932 @@ -124,7 +124,7 @@ static void get_flags(void)
7933
7934 if (max_intel_level >= 0x00000001 &&
7935 max_intel_level <= 0x0000ffff) {
7936 - asm("cpuid"
7937 + asm volatile("cpuid"
7938 : "=a" (tfms),
7939 "=c" (cpu.flags[4]),
7940 "=d" (cpu.flags[0])
7941 @@ -136,7 +136,7 @@ static void get_flags(void)
7942 cpu.model += ((tfms >> 16) & 0xf) << 4;
7943 }
7944
7945 - asm("cpuid"
7946 + asm volatile("cpuid"
7947 : "=a" (max_amd_level)
7948 : "a" (0x80000000)
7949 : "ebx", "ecx", "edx");
7950 @@ -144,7 +144,7 @@ static void get_flags(void)
7951 if (max_amd_level >= 0x80000001 &&
7952 max_amd_level <= 0x8000ffff) {
7953 u32 eax = 0x80000001;
7954 - asm("cpuid"
7955 + asm volatile("cpuid"
7956 : "+a" (eax),
7957 "=c" (cpu.flags[6]),
7958 "=d" (cpu.flags[1])
7959 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7960 u32 ecx = MSR_K7_HWCR;
7961 u32 eax, edx;
7962
7963 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7964 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7965 eax &= ~(1 << 15);
7966 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7967 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7968
7969 get_flags(); /* Make sure it really did something */
7970 err = check_flags();
7971 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7972 u32 ecx = MSR_VIA_FCR;
7973 u32 eax, edx;
7974
7975 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7976 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7977 eax |= (1<<1)|(1<<7);
7978 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7979 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7980
7981 set_bit(X86_FEATURE_CX8, cpu.flags);
7982 err = check_flags();
7983 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7984 u32 eax, edx;
7985 u32 level = 1;
7986
7987 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7988 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7989 - asm("cpuid"
7990 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7991 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7992 + asm volatile("cpuid"
7993 : "+a" (level), "=d" (cpu.flags[0])
7994 : : "ecx", "ebx");
7995 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7996 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7997
7998 err = check_flags();
7999 }
8000 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8001 index f1bbeeb..aff09cb 100644
8002 --- a/arch/x86/boot/header.S
8003 +++ b/arch/x86/boot/header.S
8004 @@ -372,7 +372,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
8005 # single linked list of
8006 # struct setup_data
8007
8008 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8009 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8010
8011 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8012 #define VO_INIT_SIZE (VO__end - VO__text)
8013 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8014 index db75d07..8e6d0af 100644
8015 --- a/arch/x86/boot/memory.c
8016 +++ b/arch/x86/boot/memory.c
8017 @@ -19,7 +19,7 @@
8018
8019 static int detect_memory_e820(void)
8020 {
8021 - int count = 0;
8022 + unsigned int count = 0;
8023 struct biosregs ireg, oreg;
8024 struct e820entry *desc = boot_params.e820_map;
8025 static struct e820entry buf; /* static so it is zeroed */
8026 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8027 index 11e8c6e..fdbb1ed 100644
8028 --- a/arch/x86/boot/video-vesa.c
8029 +++ b/arch/x86/boot/video-vesa.c
8030 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8031
8032 boot_params.screen_info.vesapm_seg = oreg.es;
8033 boot_params.screen_info.vesapm_off = oreg.di;
8034 + boot_params.screen_info.vesapm_size = oreg.cx;
8035 }
8036
8037 /*
8038 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8039 index 43eda28..5ab5fdb 100644
8040 --- a/arch/x86/boot/video.c
8041 +++ b/arch/x86/boot/video.c
8042 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8043 static unsigned int get_entry(void)
8044 {
8045 char entry_buf[4];
8046 - int i, len = 0;
8047 + unsigned int i, len = 0;
8048 int key;
8049 unsigned int v;
8050
8051 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8052 index 5b577d5..3c1fed4 100644
8053 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8054 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8055 @@ -8,6 +8,8 @@
8056 * including this sentence is retained in full.
8057 */
8058
8059 +#include <asm/alternative-asm.h>
8060 +
8061 .extern crypto_ft_tab
8062 .extern crypto_it_tab
8063 .extern crypto_fl_tab
8064 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8065 je B192; \
8066 leaq 32(r9),r9;
8067
8068 +#define ret pax_force_retaddr 0, 1; ret
8069 +
8070 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8071 movq r1,r2; \
8072 movq r3,r4; \
8073 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8074 index be6d9e3..21fbbca 100644
8075 --- a/arch/x86/crypto/aesni-intel_asm.S
8076 +++ b/arch/x86/crypto/aesni-intel_asm.S
8077 @@ -31,6 +31,7 @@
8078
8079 #include <linux/linkage.h>
8080 #include <asm/inst.h>
8081 +#include <asm/alternative-asm.h>
8082
8083 #ifdef __x86_64__
8084 .data
8085 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8086 pop %r14
8087 pop %r13
8088 pop %r12
8089 + pax_force_retaddr 0, 1
8090 ret
8091 +ENDPROC(aesni_gcm_dec)
8092
8093
8094 /*****************************************************************************
8095 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8096 pop %r14
8097 pop %r13
8098 pop %r12
8099 + pax_force_retaddr 0, 1
8100 ret
8101 +ENDPROC(aesni_gcm_enc)
8102
8103 #endif
8104
8105 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8106 pxor %xmm1, %xmm0
8107 movaps %xmm0, (TKEYP)
8108 add $0x10, TKEYP
8109 + pax_force_retaddr_bts
8110 ret
8111
8112 .align 4
8113 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8114 shufps $0b01001110, %xmm2, %xmm1
8115 movaps %xmm1, 0x10(TKEYP)
8116 add $0x20, TKEYP
8117 + pax_force_retaddr_bts
8118 ret
8119
8120 .align 4
8121 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8122
8123 movaps %xmm0, (TKEYP)
8124 add $0x10, TKEYP
8125 + pax_force_retaddr_bts
8126 ret
8127
8128 .align 4
8129 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8130 pxor %xmm1, %xmm2
8131 movaps %xmm2, (TKEYP)
8132 add $0x10, TKEYP
8133 + pax_force_retaddr_bts
8134 ret
8135
8136 /*
8137 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8138 #ifndef __x86_64__
8139 popl KEYP
8140 #endif
8141 + pax_force_retaddr 0, 1
8142 ret
8143 +ENDPROC(aesni_set_key)
8144
8145 /*
8146 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8147 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8148 popl KLEN
8149 popl KEYP
8150 #endif
8151 + pax_force_retaddr 0, 1
8152 ret
8153 +ENDPROC(aesni_enc)
8154
8155 /*
8156 * _aesni_enc1: internal ABI
8157 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8158 AESENC KEY STATE
8159 movaps 0x70(TKEYP), KEY
8160 AESENCLAST KEY STATE
8161 + pax_force_retaddr_bts
8162 ret
8163
8164 /*
8165 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8166 AESENCLAST KEY STATE2
8167 AESENCLAST KEY STATE3
8168 AESENCLAST KEY STATE4
8169 + pax_force_retaddr_bts
8170 ret
8171
8172 /*
8173 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8174 popl KLEN
8175 popl KEYP
8176 #endif
8177 + pax_force_retaddr 0, 1
8178 ret
8179 +ENDPROC(aesni_dec)
8180
8181 /*
8182 * _aesni_dec1: internal ABI
8183 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8184 AESDEC KEY STATE
8185 movaps 0x70(TKEYP), KEY
8186 AESDECLAST KEY STATE
8187 + pax_force_retaddr_bts
8188 ret
8189
8190 /*
8191 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8192 AESDECLAST KEY STATE2
8193 AESDECLAST KEY STATE3
8194 AESDECLAST KEY STATE4
8195 + pax_force_retaddr_bts
8196 ret
8197
8198 /*
8199 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8200 popl KEYP
8201 popl LEN
8202 #endif
8203 + pax_force_retaddr 0, 1
8204 ret
8205 +ENDPROC(aesni_ecb_enc)
8206
8207 /*
8208 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8209 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8210 popl KEYP
8211 popl LEN
8212 #endif
8213 + pax_force_retaddr 0, 1
8214 ret
8215 +ENDPROC(aesni_ecb_dec)
8216
8217 /*
8218 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8219 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8220 popl LEN
8221 popl IVP
8222 #endif
8223 + pax_force_retaddr 0, 1
8224 ret
8225 +ENDPROC(aesni_cbc_enc)
8226
8227 /*
8228 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8229 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
8230 popl LEN
8231 popl IVP
8232 #endif
8233 + pax_force_retaddr 0, 1
8234 ret
8235 +ENDPROC(aesni_cbc_dec)
8236
8237 #ifdef __x86_64__
8238 .align 16
8239 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
8240 mov $1, TCTR_LOW
8241 MOVQ_R64_XMM TCTR_LOW INC
8242 MOVQ_R64_XMM CTR TCTR_LOW
8243 + pax_force_retaddr_bts
8244 ret
8245
8246 /*
8247 @@ -2552,6 +2580,7 @@ _aesni_inc:
8248 .Linc_low:
8249 movaps CTR, IV
8250 PSHUFB_XMM BSWAP_MASK IV
8251 + pax_force_retaddr_bts
8252 ret
8253
8254 /*
8255 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
8256 .Lctr_enc_ret:
8257 movups IV, (IVP)
8258 .Lctr_enc_just_ret:
8259 + pax_force_retaddr 0, 1
8260 ret
8261 +ENDPROC(aesni_ctr_enc)
8262 #endif
8263 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8264 index 391d245..67f35c2 100644
8265 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8266 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8267 @@ -20,6 +20,8 @@
8268 *
8269 */
8270
8271 +#include <asm/alternative-asm.h>
8272 +
8273 .file "blowfish-x86_64-asm.S"
8274 .text
8275
8276 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8277 jnz __enc_xor;
8278
8279 write_block();
8280 + pax_force_retaddr 0, 1
8281 ret;
8282 __enc_xor:
8283 xor_block();
8284 + pax_force_retaddr 0, 1
8285 ret;
8286
8287 .align 8
8288 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8289
8290 movq %r11, %rbp;
8291
8292 + pax_force_retaddr 0, 1
8293 ret;
8294
8295 /**********************************************************************
8296 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8297
8298 popq %rbx;
8299 popq %rbp;
8300 + pax_force_retaddr 0, 1
8301 ret;
8302
8303 __enc_xor4:
8304 @@ -349,6 +355,7 @@ __enc_xor4:
8305
8306 popq %rbx;
8307 popq %rbp;
8308 + pax_force_retaddr 0, 1
8309 ret;
8310
8311 .align 8
8312 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8313 popq %rbx;
8314 popq %rbp;
8315
8316 + pax_force_retaddr 0, 1
8317 ret;
8318
8319 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8320 index 6214a9b..1f4fc9a 100644
8321 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8322 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8323 @@ -1,3 +1,5 @@
8324 +#include <asm/alternative-asm.h>
8325 +
8326 # enter ECRYPT_encrypt_bytes
8327 .text
8328 .p2align 5
8329 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8330 add %r11,%rsp
8331 mov %rdi,%rax
8332 mov %rsi,%rdx
8333 + pax_force_retaddr 0, 1
8334 ret
8335 # bytesatleast65:
8336 ._bytesatleast65:
8337 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8338 add %r11,%rsp
8339 mov %rdi,%rax
8340 mov %rsi,%rdx
8341 + pax_force_retaddr
8342 ret
8343 # enter ECRYPT_ivsetup
8344 .text
8345 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8346 add %r11,%rsp
8347 mov %rdi,%rax
8348 mov %rsi,%rdx
8349 + pax_force_retaddr
8350 ret
8351 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8352 index 7f24a15..9cd3ffe 100644
8353 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8354 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8355 @@ -24,6 +24,8 @@
8356 *
8357 */
8358
8359 +#include <asm/alternative-asm.h>
8360 +
8361 .file "serpent-sse2-x86_64-asm_64.S"
8362 .text
8363
8364 @@ -695,12 +697,14 @@ __serpent_enc_blk_8way:
8365 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8366 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8367
8368 + pax_force_retaddr
8369 ret;
8370
8371 __enc_xor8:
8372 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8373 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8374
8375 + pax_force_retaddr
8376 ret;
8377
8378 .align 8
8379 @@ -758,4 +762,5 @@ serpent_dec_blk_8way:
8380 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8381 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8382
8383 + pax_force_retaddr
8384 ret;
8385 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8386 index b2c2f57..8470cab 100644
8387 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8388 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8389 @@ -28,6 +28,8 @@
8390 * (at your option) any later version.
8391 */
8392
8393 +#include <asm/alternative-asm.h>
8394 +
8395 #define CTX %rdi // arg1
8396 #define BUF %rsi // arg2
8397 #define CNT %rdx // arg3
8398 @@ -104,6 +106,7 @@
8399 pop %r12
8400 pop %rbp
8401 pop %rbx
8402 + pax_force_retaddr 0, 1
8403 ret
8404
8405 .size \name, .-\name
8406 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8407 index 5b012a2..36d5364 100644
8408 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8409 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8410 @@ -20,6 +20,8 @@
8411 *
8412 */
8413
8414 +#include <asm/alternative-asm.h>
8415 +
8416 .file "twofish-x86_64-asm-3way.S"
8417 .text
8418
8419 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8420 popq %r13;
8421 popq %r14;
8422 popq %r15;
8423 + pax_force_retaddr 0, 1
8424 ret;
8425
8426 __enc_xor3:
8427 @@ -271,6 +274,7 @@ __enc_xor3:
8428 popq %r13;
8429 popq %r14;
8430 popq %r15;
8431 + pax_force_retaddr 0, 1
8432 ret;
8433
8434 .global twofish_dec_blk_3way
8435 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8436 popq %r13;
8437 popq %r14;
8438 popq %r15;
8439 + pax_force_retaddr 0, 1
8440 ret;
8441
8442 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8443 index 7bcf3fc..f53832f 100644
8444 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8445 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8446 @@ -21,6 +21,7 @@
8447 .text
8448
8449 #include <asm/asm-offsets.h>
8450 +#include <asm/alternative-asm.h>
8451
8452 #define a_offset 0
8453 #define b_offset 4
8454 @@ -268,6 +269,7 @@ twofish_enc_blk:
8455
8456 popq R1
8457 movq $1,%rax
8458 + pax_force_retaddr 0, 1
8459 ret
8460
8461 twofish_dec_blk:
8462 @@ -319,4 +321,5 @@ twofish_dec_blk:
8463
8464 popq R1
8465 movq $1,%rax
8466 + pax_force_retaddr 0, 1
8467 ret
8468 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8469 index 39e4909..887aa7e 100644
8470 --- a/arch/x86/ia32/ia32_aout.c
8471 +++ b/arch/x86/ia32/ia32_aout.c
8472 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8473 unsigned long dump_start, dump_size;
8474 struct user32 dump;
8475
8476 + memset(&dump, 0, sizeof(dump));
8477 +
8478 fs = get_fs();
8479 set_fs(KERNEL_DS);
8480 has_dumped = 1;
8481 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8482 index 6557769..ef6ae89 100644
8483 --- a/arch/x86/ia32/ia32_signal.c
8484 +++ b/arch/x86/ia32/ia32_signal.c
8485 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8486 }
8487 seg = get_fs();
8488 set_fs(KERNEL_DS);
8489 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8490 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8491 set_fs(seg);
8492 if (ret >= 0 && uoss_ptr) {
8493 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8494 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8495 */
8496 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8497 size_t frame_size,
8498 - void **fpstate)
8499 + void __user **fpstate)
8500 {
8501 unsigned long sp;
8502
8503 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8504
8505 if (used_math()) {
8506 sp = sp - sig_xstate_ia32_size;
8507 - *fpstate = (struct _fpstate_ia32 *) sp;
8508 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8509 if (save_i387_xstate_ia32(*fpstate) < 0)
8510 return (void __user *) -1L;
8511 }
8512 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8513 sp -= frame_size;
8514 /* Align the stack pointer according to the i386 ABI,
8515 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8516 - sp = ((sp + 4) & -16ul) - 4;
8517 + sp = ((sp - 12) & -16ul) - 4;
8518 return (void __user *) sp;
8519 }
8520
8521 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8522 * These are actually not used anymore, but left because some
8523 * gdb versions depend on them as a marker.
8524 */
8525 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8526 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8527 } put_user_catch(err);
8528
8529 if (err)
8530 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8531 0xb8,
8532 __NR_ia32_rt_sigreturn,
8533 0x80cd,
8534 - 0,
8535 + 0
8536 };
8537
8538 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8539 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8540
8541 if (ka->sa.sa_flags & SA_RESTORER)
8542 restorer = ka->sa.sa_restorer;
8543 + else if (current->mm->context.vdso)
8544 + /* Return stub is in 32bit vsyscall page */
8545 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8546 else
8547 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8548 - rt_sigreturn);
8549 + restorer = &frame->retcode;
8550 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8551
8552 /*
8553 * Not actually used anymore, but left because some gdb
8554 * versions need it.
8555 */
8556 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8557 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8558 } put_user_catch(err);
8559
8560 if (err)
8561 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8562 index e3e7340..05ed805 100644
8563 --- a/arch/x86/ia32/ia32entry.S
8564 +++ b/arch/x86/ia32/ia32entry.S
8565 @@ -13,8 +13,10 @@
8566 #include <asm/thread_info.h>
8567 #include <asm/segment.h>
8568 #include <asm/irqflags.h>
8569 +#include <asm/pgtable.h>
8570 #include <linux/linkage.h>
8571 #include <linux/err.h>
8572 +#include <asm/alternative-asm.h>
8573
8574 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8575 #include <linux/elf-em.h>
8576 @@ -94,6 +96,32 @@ ENTRY(native_irq_enable_sysexit)
8577 ENDPROC(native_irq_enable_sysexit)
8578 #endif
8579
8580 + .macro pax_enter_kernel_user
8581 + pax_set_fptr_mask
8582 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8583 + call pax_enter_kernel_user
8584 +#endif
8585 + .endm
8586 +
8587 + .macro pax_exit_kernel_user
8588 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8589 + call pax_exit_kernel_user
8590 +#endif
8591 +#ifdef CONFIG_PAX_RANDKSTACK
8592 + pushq %rax
8593 + pushq %r11
8594 + call pax_randomize_kstack
8595 + popq %r11
8596 + popq %rax
8597 +#endif
8598 + .endm
8599 +
8600 +.macro pax_erase_kstack
8601 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8602 + call pax_erase_kstack
8603 +#endif
8604 +.endm
8605 +
8606 /*
8607 * 32bit SYSENTER instruction entry.
8608 *
8609 @@ -120,12 +148,6 @@ ENTRY(ia32_sysenter_target)
8610 CFI_REGISTER rsp,rbp
8611 SWAPGS_UNSAFE_STACK
8612 movq PER_CPU_VAR(kernel_stack), %rsp
8613 - addq $(KERNEL_STACK_OFFSET),%rsp
8614 - /*
8615 - * No need to follow this irqs on/off section: the syscall
8616 - * disabled irqs, here we enable it straight after entry:
8617 - */
8618 - ENABLE_INTERRUPTS(CLBR_NONE)
8619 movl %ebp,%ebp /* zero extension */
8620 pushq_cfi $__USER32_DS
8621 /*CFI_REL_OFFSET ss,0*/
8622 @@ -133,24 +155,39 @@ ENTRY(ia32_sysenter_target)
8623 CFI_REL_OFFSET rsp,0
8624 pushfq_cfi
8625 /*CFI_REL_OFFSET rflags,0*/
8626 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8627 - CFI_REGISTER rip,r10
8628 + orl $X86_EFLAGS_IF,(%rsp)
8629 + GET_THREAD_INFO(%r11)
8630 + movl TI_sysenter_return(%r11), %r11d
8631 + CFI_REGISTER rip,r11
8632 pushq_cfi $__USER32_CS
8633 /*CFI_REL_OFFSET cs,0*/
8634 movl %eax, %eax
8635 - pushq_cfi %r10
8636 + pushq_cfi %r11
8637 CFI_REL_OFFSET rip,0
8638 pushq_cfi %rax
8639 cld
8640 SAVE_ARGS 0,1,0
8641 + pax_enter_kernel_user
8642 + /*
8643 + * No need to follow this irqs on/off section: the syscall
8644 + * disabled irqs, here we enable it straight after entry:
8645 + */
8646 + ENABLE_INTERRUPTS(CLBR_NONE)
8647 /* no need to do an access_ok check here because rbp has been
8648 32bit zero extended */
8649 +
8650 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8651 + mov $PAX_USER_SHADOW_BASE,%r11
8652 + add %r11,%rbp
8653 +#endif
8654 +
8655 1: movl (%rbp),%ebp
8656 .section __ex_table,"a"
8657 .quad 1b,ia32_badarg
8658 .previous
8659 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8660 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8661 + GET_THREAD_INFO(%r11)
8662 + orl $TS_COMPAT,TI_status(%r11)
8663 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8664 CFI_REMEMBER_STATE
8665 jnz sysenter_tracesys
8666 cmpq $(IA32_NR_syscalls-1),%rax
8667 @@ -160,12 +197,15 @@ sysenter_do_call:
8668 sysenter_dispatch:
8669 call *ia32_sys_call_table(,%rax,8)
8670 movq %rax,RAX-ARGOFFSET(%rsp)
8671 + GET_THREAD_INFO(%r11)
8672 DISABLE_INTERRUPTS(CLBR_NONE)
8673 TRACE_IRQS_OFF
8674 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8675 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8676 jnz sysexit_audit
8677 sysexit_from_sys_call:
8678 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8679 + pax_exit_kernel_user
8680 + pax_erase_kstack
8681 + andl $~TS_COMPAT,TI_status(%r11)
8682 /* clear IF, that popfq doesn't enable interrupts early */
8683 andl $~0x200,EFLAGS-R11(%rsp)
8684 movl RIP-R11(%rsp),%edx /* User %eip */
8685 @@ -191,6 +231,9 @@ sysexit_from_sys_call:
8686 movl %eax,%esi /* 2nd arg: syscall number */
8687 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8688 call __audit_syscall_entry
8689 +
8690 + pax_erase_kstack
8691 +
8692 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8693 cmpq $(IA32_NR_syscalls-1),%rax
8694 ja ia32_badsys
8695 @@ -202,7 +245,7 @@ sysexit_from_sys_call:
8696 .endm
8697
8698 .macro auditsys_exit exit
8699 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8700 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8701 jnz ia32_ret_from_sys_call
8702 TRACE_IRQS_ON
8703 sti
8704 @@ -213,11 +256,12 @@ sysexit_from_sys_call:
8705 1: setbe %al /* 1 if error, 0 if not */
8706 movzbl %al,%edi /* zero-extend that into %edi */
8707 call __audit_syscall_exit
8708 + GET_THREAD_INFO(%r11)
8709 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8710 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8711 cli
8712 TRACE_IRQS_OFF
8713 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8714 + testl %edi,TI_flags(%r11)
8715 jz \exit
8716 CLEAR_RREGS -ARGOFFSET
8717 jmp int_with_check
8718 @@ -235,7 +279,7 @@ sysexit_audit:
8719
8720 sysenter_tracesys:
8721 #ifdef CONFIG_AUDITSYSCALL
8722 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8723 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8724 jz sysenter_auditsys
8725 #endif
8726 SAVE_REST
8727 @@ -243,6 +287,9 @@ sysenter_tracesys:
8728 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
8729 movq %rsp,%rdi /* &pt_regs -> arg1 */
8730 call syscall_trace_enter
8731 +
8732 + pax_erase_kstack
8733 +
8734 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8735 RESTORE_REST
8736 cmpq $(IA32_NR_syscalls-1),%rax
8737 @@ -274,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
8738 ENTRY(ia32_cstar_target)
8739 CFI_STARTPROC32 simple
8740 CFI_SIGNAL_FRAME
8741 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8742 + CFI_DEF_CFA rsp,0
8743 CFI_REGISTER rip,rcx
8744 /*CFI_REGISTER rflags,r11*/
8745 SWAPGS_UNSAFE_STACK
8746 movl %esp,%r8d
8747 CFI_REGISTER rsp,r8
8748 movq PER_CPU_VAR(kernel_stack),%rsp
8749 + SAVE_ARGS 8*6,0,0
8750 + pax_enter_kernel_user
8751 /*
8752 * No need to follow this irqs on/off section: the syscall
8753 * disabled irqs and here we enable it straight after entry:
8754 */
8755 ENABLE_INTERRUPTS(CLBR_NONE)
8756 - SAVE_ARGS 8,0,0
8757 movl %eax,%eax /* zero extension */
8758 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8759 movq %rcx,RIP-ARGOFFSET(%rsp)
8760 @@ -302,12 +350,19 @@ ENTRY(ia32_cstar_target)
8761 /* no need to do an access_ok check here because r8 has been
8762 32bit zero extended */
8763 /* hardware stack frame is complete now */
8764 +
8765 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8766 + mov $PAX_USER_SHADOW_BASE,%r11
8767 + add %r11,%r8
8768 +#endif
8769 +
8770 1: movl (%r8),%r9d
8771 .section __ex_table,"a"
8772 .quad 1b,ia32_badarg
8773 .previous
8774 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8775 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8776 + GET_THREAD_INFO(%r11)
8777 + orl $TS_COMPAT,TI_status(%r11)
8778 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8779 CFI_REMEMBER_STATE
8780 jnz cstar_tracesys
8781 cmpq $IA32_NR_syscalls-1,%rax
8782 @@ -317,12 +372,15 @@ cstar_do_call:
8783 cstar_dispatch:
8784 call *ia32_sys_call_table(,%rax,8)
8785 movq %rax,RAX-ARGOFFSET(%rsp)
8786 + GET_THREAD_INFO(%r11)
8787 DISABLE_INTERRUPTS(CLBR_NONE)
8788 TRACE_IRQS_OFF
8789 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8790 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8791 jnz sysretl_audit
8792 sysretl_from_sys_call:
8793 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8794 + pax_exit_kernel_user
8795 + pax_erase_kstack
8796 + andl $~TS_COMPAT,TI_status(%r11)
8797 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8798 movl RIP-ARGOFFSET(%rsp),%ecx
8799 CFI_REGISTER rip,rcx
8800 @@ -350,7 +408,7 @@ sysretl_audit:
8801
8802 cstar_tracesys:
8803 #ifdef CONFIG_AUDITSYSCALL
8804 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8805 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8806 jz cstar_auditsys
8807 #endif
8808 xchgl %r9d,%ebp
8809 @@ -359,6 +417,9 @@ cstar_tracesys:
8810 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8811 movq %rsp,%rdi /* &pt_regs -> arg1 */
8812 call syscall_trace_enter
8813 +
8814 + pax_erase_kstack
8815 +
8816 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
8817 RESTORE_REST
8818 xchgl %ebp,%r9d
8819 @@ -404,19 +465,21 @@ ENTRY(ia32_syscall)
8820 CFI_REL_OFFSET rip,RIP-RIP
8821 PARAVIRT_ADJUST_EXCEPTION_FRAME
8822 SWAPGS
8823 - /*
8824 - * No need to follow this irqs on/off section: the syscall
8825 - * disabled irqs and here we enable it straight after entry:
8826 - */
8827 - ENABLE_INTERRUPTS(CLBR_NONE)
8828 movl %eax,%eax
8829 pushq_cfi %rax
8830 cld
8831 /* note the registers are not zero extended to the sf.
8832 this could be a problem. */
8833 SAVE_ARGS 0,1,0
8834 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8835 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8836 + pax_enter_kernel_user
8837 + /*
8838 + * No need to follow this irqs on/off section: the syscall
8839 + * disabled irqs and here we enable it straight after entry:
8840 + */
8841 + ENABLE_INTERRUPTS(CLBR_NONE)
8842 + GET_THREAD_INFO(%r11)
8843 + orl $TS_COMPAT,TI_status(%r11)
8844 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8845 jnz ia32_tracesys
8846 cmpq $(IA32_NR_syscalls-1),%rax
8847 ja ia32_badsys
8848 @@ -435,6 +498,9 @@ ia32_tracesys:
8849 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
8850 movq %rsp,%rdi /* &pt_regs -> arg1 */
8851 call syscall_trace_enter
8852 +
8853 + pax_erase_kstack
8854 +
8855 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
8856 RESTORE_REST
8857 cmpq $(IA32_NR_syscalls-1),%rax
8858 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8859 index f6f5c53..b358b28 100644
8860 --- a/arch/x86/ia32/sys_ia32.c
8861 +++ b/arch/x86/ia32/sys_ia32.c
8862 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8863 */
8864 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8865 {
8866 - typeof(ubuf->st_uid) uid = 0;
8867 - typeof(ubuf->st_gid) gid = 0;
8868 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8869 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8870 SET_UID(uid, stat->uid);
8871 SET_GID(gid, stat->gid);
8872 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8873 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
8874 }
8875 set_fs(KERNEL_DS);
8876 ret = sys_rt_sigprocmask(how,
8877 - set ? (sigset_t __user *)&s : NULL,
8878 - oset ? (sigset_t __user *)&s : NULL,
8879 + set ? (sigset_t __force_user *)&s : NULL,
8880 + oset ? (sigset_t __force_user *)&s : NULL,
8881 sigsetsize);
8882 set_fs(old_fs);
8883 if (ret)
8884 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
8885 return alarm_setitimer(seconds);
8886 }
8887
8888 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8889 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8890 int options)
8891 {
8892 return compat_sys_wait4(pid, stat_addr, options, NULL);
8893 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8894 mm_segment_t old_fs = get_fs();
8895
8896 set_fs(KERNEL_DS);
8897 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8898 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8899 set_fs(old_fs);
8900 if (put_compat_timespec(&t, interval))
8901 return -EFAULT;
8902 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8903 mm_segment_t old_fs = get_fs();
8904
8905 set_fs(KERNEL_DS);
8906 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8907 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8908 set_fs(old_fs);
8909 if (!ret) {
8910 switch (_NSIG_WORDS) {
8911 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8912 if (copy_siginfo_from_user32(&info, uinfo))
8913 return -EFAULT;
8914 set_fs(KERNEL_DS);
8915 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
8916 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
8917 set_fs(old_fs);
8918 return ret;
8919 }
8920 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
8921 return -EFAULT;
8922
8923 set_fs(KERNEL_DS);
8924 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
8925 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
8926 count);
8927 set_fs(old_fs);
8928
8929 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
8930 index 952bd01..7692c6f 100644
8931 --- a/arch/x86/include/asm/alternative-asm.h
8932 +++ b/arch/x86/include/asm/alternative-asm.h
8933 @@ -15,6 +15,45 @@
8934 .endm
8935 #endif
8936
8937 +#ifdef KERNEXEC_PLUGIN
8938 + .macro pax_force_retaddr_bts rip=0
8939 + btsq $63,\rip(%rsp)
8940 + .endm
8941 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
8942 + .macro pax_force_retaddr rip=0, reload=0
8943 + btsq $63,\rip(%rsp)
8944 + .endm
8945 + .macro pax_force_fptr ptr
8946 + btsq $63,\ptr
8947 + .endm
8948 + .macro pax_set_fptr_mask
8949 + .endm
8950 +#endif
8951 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
8952 + .macro pax_force_retaddr rip=0, reload=0
8953 + .if \reload
8954 + pax_set_fptr_mask
8955 + .endif
8956 + orq %r10,\rip(%rsp)
8957 + .endm
8958 + .macro pax_force_fptr ptr
8959 + orq %r10,\ptr
8960 + .endm
8961 + .macro pax_set_fptr_mask
8962 + movabs $0x8000000000000000,%r10
8963 + .endm
8964 +#endif
8965 +#else
8966 + .macro pax_force_retaddr rip=0, reload=0
8967 + .endm
8968 + .macro pax_force_fptr ptr
8969 + .endm
8970 + .macro pax_force_retaddr_bts rip=0
8971 + .endm
8972 + .macro pax_set_fptr_mask
8973 + .endm
8974 +#endif
8975 +
8976 .macro altinstruction_entry orig alt feature orig_len alt_len
8977 .long \orig - .
8978 .long \alt - .
8979 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
8980 index 37ad100..7d47faa 100644
8981 --- a/arch/x86/include/asm/alternative.h
8982 +++ b/arch/x86/include/asm/alternative.h
8983 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
8984 ".section .discard,\"aw\",@progbits\n" \
8985 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
8986 ".previous\n" \
8987 - ".section .altinstr_replacement, \"ax\"\n" \
8988 + ".section .altinstr_replacement, \"a\"\n" \
8989 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
8990 ".previous"
8991
8992 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
8993 index 3ab9bdd..238033e 100644
8994 --- a/arch/x86/include/asm/apic.h
8995 +++ b/arch/x86/include/asm/apic.h
8996 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
8997
8998 #ifdef CONFIG_X86_LOCAL_APIC
8999
9000 -extern unsigned int apic_verbosity;
9001 +extern int apic_verbosity;
9002 extern int local_apic_timer_c2_ok;
9003
9004 extern int disable_apic;
9005 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9006 index 20370c6..a2eb9b0 100644
9007 --- a/arch/x86/include/asm/apm.h
9008 +++ b/arch/x86/include/asm/apm.h
9009 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9010 __asm__ __volatile__(APM_DO_ZERO_SEGS
9011 "pushl %%edi\n\t"
9012 "pushl %%ebp\n\t"
9013 - "lcall *%%cs:apm_bios_entry\n\t"
9014 + "lcall *%%ss:apm_bios_entry\n\t"
9015 "setc %%al\n\t"
9016 "popl %%ebp\n\t"
9017 "popl %%edi\n\t"
9018 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9019 __asm__ __volatile__(APM_DO_ZERO_SEGS
9020 "pushl %%edi\n\t"
9021 "pushl %%ebp\n\t"
9022 - "lcall *%%cs:apm_bios_entry\n\t"
9023 + "lcall *%%ss:apm_bios_entry\n\t"
9024 "setc %%bl\n\t"
9025 "popl %%ebp\n\t"
9026 "popl %%edi\n\t"
9027 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9028 index 58cb6d4..ca9010d 100644
9029 --- a/arch/x86/include/asm/atomic.h
9030 +++ b/arch/x86/include/asm/atomic.h
9031 @@ -22,7 +22,18 @@
9032 */
9033 static inline int atomic_read(const atomic_t *v)
9034 {
9035 - return (*(volatile int *)&(v)->counter);
9036 + return (*(volatile const int *)&(v)->counter);
9037 +}
9038 +
9039 +/**
9040 + * atomic_read_unchecked - read atomic variable
9041 + * @v: pointer of type atomic_unchecked_t
9042 + *
9043 + * Atomically reads the value of @v.
9044 + */
9045 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9046 +{
9047 + return (*(volatile const int *)&(v)->counter);
9048 }
9049
9050 /**
9051 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9052 }
9053
9054 /**
9055 + * atomic_set_unchecked - set atomic variable
9056 + * @v: pointer of type atomic_unchecked_t
9057 + * @i: required value
9058 + *
9059 + * Atomically sets the value of @v to @i.
9060 + */
9061 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9062 +{
9063 + v->counter = i;
9064 +}
9065 +
9066 +/**
9067 * atomic_add - add integer to atomic variable
9068 * @i: integer value to add
9069 * @v: pointer of type atomic_t
9070 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9071 */
9072 static inline void atomic_add(int i, atomic_t *v)
9073 {
9074 - asm volatile(LOCK_PREFIX "addl %1,%0"
9075 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9076 +
9077 +#ifdef CONFIG_PAX_REFCOUNT
9078 + "jno 0f\n"
9079 + LOCK_PREFIX "subl %1,%0\n"
9080 + "int $4\n0:\n"
9081 + _ASM_EXTABLE(0b, 0b)
9082 +#endif
9083 +
9084 + : "+m" (v->counter)
9085 + : "ir" (i));
9086 +}
9087 +
9088 +/**
9089 + * atomic_add_unchecked - add integer to atomic variable
9090 + * @i: integer value to add
9091 + * @v: pointer of type atomic_unchecked_t
9092 + *
9093 + * Atomically adds @i to @v.
9094 + */
9095 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9096 +{
9097 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9098 : "+m" (v->counter)
9099 : "ir" (i));
9100 }
9101 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9102 */
9103 static inline void atomic_sub(int i, atomic_t *v)
9104 {
9105 - asm volatile(LOCK_PREFIX "subl %1,%0"
9106 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9107 +
9108 +#ifdef CONFIG_PAX_REFCOUNT
9109 + "jno 0f\n"
9110 + LOCK_PREFIX "addl %1,%0\n"
9111 + "int $4\n0:\n"
9112 + _ASM_EXTABLE(0b, 0b)
9113 +#endif
9114 +
9115 + : "+m" (v->counter)
9116 + : "ir" (i));
9117 +}
9118 +
9119 +/**
9120 + * atomic_sub_unchecked - subtract integer from atomic variable
9121 + * @i: integer value to subtract
9122 + * @v: pointer of type atomic_unchecked_t
9123 + *
9124 + * Atomically subtracts @i from @v.
9125 + */
9126 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9127 +{
9128 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9129 : "+m" (v->counter)
9130 : "ir" (i));
9131 }
9132 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9133 {
9134 unsigned char c;
9135
9136 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9137 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9138 +
9139 +#ifdef CONFIG_PAX_REFCOUNT
9140 + "jno 0f\n"
9141 + LOCK_PREFIX "addl %2,%0\n"
9142 + "int $4\n0:\n"
9143 + _ASM_EXTABLE(0b, 0b)
9144 +#endif
9145 +
9146 + "sete %1\n"
9147 : "+m" (v->counter), "=qm" (c)
9148 : "ir" (i) : "memory");
9149 return c;
9150 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9151 */
9152 static inline void atomic_inc(atomic_t *v)
9153 {
9154 - asm volatile(LOCK_PREFIX "incl %0"
9155 + asm volatile(LOCK_PREFIX "incl %0\n"
9156 +
9157 +#ifdef CONFIG_PAX_REFCOUNT
9158 + "jno 0f\n"
9159 + LOCK_PREFIX "decl %0\n"
9160 + "int $4\n0:\n"
9161 + _ASM_EXTABLE(0b, 0b)
9162 +#endif
9163 +
9164 + : "+m" (v->counter));
9165 +}
9166 +
9167 +/**
9168 + * atomic_inc_unchecked - increment atomic variable
9169 + * @v: pointer of type atomic_unchecked_t
9170 + *
9171 + * Atomically increments @v by 1.
9172 + */
9173 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9174 +{
9175 + asm volatile(LOCK_PREFIX "incl %0\n"
9176 : "+m" (v->counter));
9177 }
9178
9179 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9180 */
9181 static inline void atomic_dec(atomic_t *v)
9182 {
9183 - asm volatile(LOCK_PREFIX "decl %0"
9184 + asm volatile(LOCK_PREFIX "decl %0\n"
9185 +
9186 +#ifdef CONFIG_PAX_REFCOUNT
9187 + "jno 0f\n"
9188 + LOCK_PREFIX "incl %0\n"
9189 + "int $4\n0:\n"
9190 + _ASM_EXTABLE(0b, 0b)
9191 +#endif
9192 +
9193 + : "+m" (v->counter));
9194 +}
9195 +
9196 +/**
9197 + * atomic_dec_unchecked - decrement atomic variable
9198 + * @v: pointer of type atomic_unchecked_t
9199 + *
9200 + * Atomically decrements @v by 1.
9201 + */
9202 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9203 +{
9204 + asm volatile(LOCK_PREFIX "decl %0\n"
9205 : "+m" (v->counter));
9206 }
9207
9208 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9209 {
9210 unsigned char c;
9211
9212 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9213 + asm volatile(LOCK_PREFIX "decl %0\n"
9214 +
9215 +#ifdef CONFIG_PAX_REFCOUNT
9216 + "jno 0f\n"
9217 + LOCK_PREFIX "incl %0\n"
9218 + "int $4\n0:\n"
9219 + _ASM_EXTABLE(0b, 0b)
9220 +#endif
9221 +
9222 + "sete %1\n"
9223 : "+m" (v->counter), "=qm" (c)
9224 : : "memory");
9225 return c != 0;
9226 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9227 {
9228 unsigned char c;
9229
9230 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9231 + asm volatile(LOCK_PREFIX "incl %0\n"
9232 +
9233 +#ifdef CONFIG_PAX_REFCOUNT
9234 + "jno 0f\n"
9235 + LOCK_PREFIX "decl %0\n"
9236 + "int $4\n0:\n"
9237 + _ASM_EXTABLE(0b, 0b)
9238 +#endif
9239 +
9240 + "sete %1\n"
9241 + : "+m" (v->counter), "=qm" (c)
9242 + : : "memory");
9243 + return c != 0;
9244 +}
9245 +
9246 +/**
9247 + * atomic_inc_and_test_unchecked - increment and test
9248 + * @v: pointer of type atomic_unchecked_t
9249 + *
9250 + * Atomically increments @v by 1
9251 + * and returns true if the result is zero, or false for all
9252 + * other cases.
9253 + */
9254 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9255 +{
9256 + unsigned char c;
9257 +
9258 + asm volatile(LOCK_PREFIX "incl %0\n"
9259 + "sete %1\n"
9260 : "+m" (v->counter), "=qm" (c)
9261 : : "memory");
9262 return c != 0;
9263 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9264 {
9265 unsigned char c;
9266
9267 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9268 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9269 +
9270 +#ifdef CONFIG_PAX_REFCOUNT
9271 + "jno 0f\n"
9272 + LOCK_PREFIX "subl %2,%0\n"
9273 + "int $4\n0:\n"
9274 + _ASM_EXTABLE(0b, 0b)
9275 +#endif
9276 +
9277 + "sets %1\n"
9278 : "+m" (v->counter), "=qm" (c)
9279 : "ir" (i) : "memory");
9280 return c;
9281 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9282 goto no_xadd;
9283 #endif
9284 /* Modern 486+ processor */
9285 - return i + xadd(&v->counter, i);
9286 + return i + xadd_check_overflow(&v->counter, i);
9287
9288 #ifdef CONFIG_M386
9289 no_xadd: /* Legacy 386 processor */
9290 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9291 }
9292
9293 /**
9294 + * atomic_add_return_unchecked - add integer and return
9295 + * @i: integer value to add
9296 + * @v: pointer of type atomic_unchecked_t
9297 + *
9298 + * Atomically adds @i to @v and returns @i + @v
9299 + */
9300 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9301 +{
9302 +#ifdef CONFIG_M386
9303 + int __i;
9304 + unsigned long flags;
9305 + if (unlikely(boot_cpu_data.x86 <= 3))
9306 + goto no_xadd;
9307 +#endif
9308 + /* Modern 486+ processor */
9309 + return i + xadd(&v->counter, i);
9310 +
9311 +#ifdef CONFIG_M386
9312 +no_xadd: /* Legacy 386 processor */
9313 + raw_local_irq_save(flags);
9314 + __i = atomic_read_unchecked(v);
9315 + atomic_set_unchecked(v, i + __i);
9316 + raw_local_irq_restore(flags);
9317 + return i + __i;
9318 +#endif
9319 +}
9320 +
9321 +/**
9322 * atomic_sub_return - subtract integer and return
9323 * @v: pointer of type atomic_t
9324 * @i: integer value to subtract
9325 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9326 }
9327
9328 #define atomic_inc_return(v) (atomic_add_return(1, v))
9329 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9330 +{
9331 + return atomic_add_return_unchecked(1, v);
9332 +}
9333 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9334
9335 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9336 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9337 return cmpxchg(&v->counter, old, new);
9338 }
9339
9340 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9341 +{
9342 + return cmpxchg(&v->counter, old, new);
9343 +}
9344 +
9345 static inline int atomic_xchg(atomic_t *v, int new)
9346 {
9347 return xchg(&v->counter, new);
9348 }
9349
9350 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9351 +{
9352 + return xchg(&v->counter, new);
9353 +}
9354 +
9355 /**
9356 * __atomic_add_unless - add unless the number is already a given value
9357 * @v: pointer of type atomic_t
9358 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9359 */
9360 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9361 {
9362 - int c, old;
9363 + int c, old, new;
9364 c = atomic_read(v);
9365 for (;;) {
9366 - if (unlikely(c == (u)))
9367 + if (unlikely(c == u))
9368 break;
9369 - old = atomic_cmpxchg((v), c, c + (a));
9370 +
9371 + asm volatile("addl %2,%0\n"
9372 +
9373 +#ifdef CONFIG_PAX_REFCOUNT
9374 + "jno 0f\n"
9375 + "subl %2,%0\n"
9376 + "int $4\n0:\n"
9377 + _ASM_EXTABLE(0b, 0b)
9378 +#endif
9379 +
9380 + : "=r" (new)
9381 + : "0" (c), "ir" (a));
9382 +
9383 + old = atomic_cmpxchg(v, c, new);
9384 if (likely(old == c))
9385 break;
9386 c = old;
9387 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9388 return c;
9389 }
9390
9391 +/**
9392 + * atomic_inc_not_zero_hint - increment if not null
9393 + * @v: pointer of type atomic_t
9394 + * @hint: probable value of the atomic before the increment
9395 + *
9396 + * This version of atomic_inc_not_zero() gives a hint of probable
9397 + * value of the atomic. This helps processor to not read the memory
9398 + * before doing the atomic read/modify/write cycle, lowering
9399 + * number of bus transactions on some arches.
9400 + *
9401 + * Returns: 0 if increment was not done, 1 otherwise.
9402 + */
9403 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9404 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9405 +{
9406 + int val, c = hint, new;
9407 +
9408 + /* sanity test, should be removed by compiler if hint is a constant */
9409 + if (!hint)
9410 + return __atomic_add_unless(v, 1, 0);
9411 +
9412 + do {
9413 + asm volatile("incl %0\n"
9414 +
9415 +#ifdef CONFIG_PAX_REFCOUNT
9416 + "jno 0f\n"
9417 + "decl %0\n"
9418 + "int $4\n0:\n"
9419 + _ASM_EXTABLE(0b, 0b)
9420 +#endif
9421 +
9422 + : "=r" (new)
9423 + : "0" (c));
9424 +
9425 + val = atomic_cmpxchg(v, c, new);
9426 + if (val == c)
9427 + return 1;
9428 + c = val;
9429 + } while (c);
9430 +
9431 + return 0;
9432 +}
9433
9434 /*
9435 * atomic_dec_if_positive - decrement by 1 if old value positive
9436 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9437 index fa13f0e..27c2e08 100644
9438 --- a/arch/x86/include/asm/atomic64_32.h
9439 +++ b/arch/x86/include/asm/atomic64_32.h
9440 @@ -12,6 +12,14 @@ typedef struct {
9441 u64 __aligned(8) counter;
9442 } atomic64_t;
9443
9444 +#ifdef CONFIG_PAX_REFCOUNT
9445 +typedef struct {
9446 + u64 __aligned(8) counter;
9447 +} atomic64_unchecked_t;
9448 +#else
9449 +typedef atomic64_t atomic64_unchecked_t;
9450 +#endif
9451 +
9452 #define ATOMIC64_INIT(val) { (val) }
9453
9454 #ifdef CONFIG_X86_CMPXCHG64
9455 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9456 }
9457
9458 /**
9459 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9460 + * @p: pointer to type atomic64_unchecked_t
9461 + * @o: expected value
9462 + * @n: new value
9463 + *
9464 + * Atomically sets @v to @n if it was equal to @o and returns
9465 + * the old value.
9466 + */
9467 +
9468 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9469 +{
9470 + return cmpxchg64(&v->counter, o, n);
9471 +}
9472 +
9473 +/**
9474 * atomic64_xchg - xchg atomic64 variable
9475 * @v: pointer to type atomic64_t
9476 * @n: value to assign
9477 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9478 }
9479
9480 /**
9481 + * atomic64_set_unchecked - set atomic64 variable
9482 + * @v: pointer to type atomic64_unchecked_t
9483 + * @n: value to assign
9484 + *
9485 + * Atomically sets the value of @v to @n.
9486 + */
9487 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9488 +{
9489 + unsigned high = (unsigned)(i >> 32);
9490 + unsigned low = (unsigned)i;
9491 + asm volatile(ATOMIC64_ALTERNATIVE(set)
9492 + : "+b" (low), "+c" (high)
9493 + : "S" (v)
9494 + : "eax", "edx", "memory"
9495 + );
9496 +}
9497 +
9498 +/**
9499 * atomic64_read - read atomic64 variable
9500 * @v: pointer to type atomic64_t
9501 *
9502 @@ -93,6 +134,22 @@ static inline long long atomic64_read(const atomic64_t *v)
9503 }
9504
9505 /**
9506 + * atomic64_read_unchecked - read atomic64 variable
9507 + * @v: pointer to type atomic64_unchecked_t
9508 + *
9509 + * Atomically reads the value of @v and returns it.
9510 + */
9511 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9512 +{
9513 + long long r;
9514 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
9515 + : "=A" (r), "+c" (v)
9516 + : : "memory"
9517 + );
9518 + return r;
9519 + }
9520 +
9521 +/**
9522 * atomic64_add_return - add and return
9523 * @i: integer value to add
9524 * @v: pointer to type atomic64_t
9525 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9526 return i;
9527 }
9528
9529 +/**
9530 + * atomic64_add_return_unchecked - add and return
9531 + * @i: integer value to add
9532 + * @v: pointer to type atomic64_unchecked_t
9533 + *
9534 + * Atomically adds @i to @v and returns @i + *@v
9535 + */
9536 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9537 +{
9538 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
9539 + : "+A" (i), "+c" (v)
9540 + : : "memory"
9541 + );
9542 + return i;
9543 +}
9544 +
9545 /*
9546 * Other variants with different arithmetic operators:
9547 */
9548 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9549 return a;
9550 }
9551
9552 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9553 +{
9554 + long long a;
9555 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
9556 + : "=A" (a)
9557 + : "S" (v)
9558 + : "memory", "ecx"
9559 + );
9560 + return a;
9561 +}
9562 +
9563 static inline long long atomic64_dec_return(atomic64_t *v)
9564 {
9565 long long a;
9566 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9567 }
9568
9569 /**
9570 + * atomic64_add_unchecked - add integer to atomic64 variable
9571 + * @i: integer value to add
9572 + * @v: pointer to type atomic64_unchecked_t
9573 + *
9574 + * Atomically adds @i to @v.
9575 + */
9576 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9577 +{
9578 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
9579 + : "+A" (i), "+c" (v)
9580 + : : "memory"
9581 + );
9582 + return i;
9583 +}
9584 +
9585 +/**
9586 * atomic64_sub - subtract the atomic64 variable
9587 * @i: integer value to subtract
9588 * @v: pointer to type atomic64_t
9589 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9590 index 0e1cbfc..5623683 100644
9591 --- a/arch/x86/include/asm/atomic64_64.h
9592 +++ b/arch/x86/include/asm/atomic64_64.h
9593 @@ -18,7 +18,19 @@
9594 */
9595 static inline long atomic64_read(const atomic64_t *v)
9596 {
9597 - return (*(volatile long *)&(v)->counter);
9598 + return (*(volatile const long *)&(v)->counter);
9599 +}
9600 +
9601 +/**
9602 + * atomic64_read_unchecked - read atomic64 variable
9603 + * @v: pointer of type atomic64_unchecked_t
9604 + *
9605 + * Atomically reads the value of @v.
9606 + * Doesn't imply a read memory barrier.
9607 + */
9608 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9609 +{
9610 + return (*(volatile const long *)&(v)->counter);
9611 }
9612
9613 /**
9614 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9615 }
9616
9617 /**
9618 + * atomic64_set_unchecked - set atomic64 variable
9619 + * @v: pointer to type atomic64_unchecked_t
9620 + * @i: required value
9621 + *
9622 + * Atomically sets the value of @v to @i.
9623 + */
9624 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9625 +{
9626 + v->counter = i;
9627 +}
9628 +
9629 +/**
9630 * atomic64_add - add integer to atomic64 variable
9631 * @i: integer value to add
9632 * @v: pointer to type atomic64_t
9633 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9634 */
9635 static inline void atomic64_add(long i, atomic64_t *v)
9636 {
9637 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9638 +
9639 +#ifdef CONFIG_PAX_REFCOUNT
9640 + "jno 0f\n"
9641 + LOCK_PREFIX "subq %1,%0\n"
9642 + "int $4\n0:\n"
9643 + _ASM_EXTABLE(0b, 0b)
9644 +#endif
9645 +
9646 + : "=m" (v->counter)
9647 + : "er" (i), "m" (v->counter));
9648 +}
9649 +
9650 +/**
9651 + * atomic64_add_unchecked - add integer to atomic64 variable
9652 + * @i: integer value to add
9653 + * @v: pointer to type atomic64_unchecked_t
9654 + *
9655 + * Atomically adds @i to @v.
9656 + */
9657 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9658 +{
9659 asm volatile(LOCK_PREFIX "addq %1,%0"
9660 : "=m" (v->counter)
9661 : "er" (i), "m" (v->counter));
9662 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9663 */
9664 static inline void atomic64_sub(long i, atomic64_t *v)
9665 {
9666 - asm volatile(LOCK_PREFIX "subq %1,%0"
9667 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9668 +
9669 +#ifdef CONFIG_PAX_REFCOUNT
9670 + "jno 0f\n"
9671 + LOCK_PREFIX "addq %1,%0\n"
9672 + "int $4\n0:\n"
9673 + _ASM_EXTABLE(0b, 0b)
9674 +#endif
9675 +
9676 + : "=m" (v->counter)
9677 + : "er" (i), "m" (v->counter));
9678 +}
9679 +
9680 +/**
9681 + * atomic64_sub_unchecked - subtract the atomic64 variable
9682 + * @i: integer value to subtract
9683 + * @v: pointer to type atomic64_unchecked_t
9684 + *
9685 + * Atomically subtracts @i from @v.
9686 + */
9687 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9688 +{
9689 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9690 : "=m" (v->counter)
9691 : "er" (i), "m" (v->counter));
9692 }
9693 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9694 {
9695 unsigned char c;
9696
9697 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9698 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9699 +
9700 +#ifdef CONFIG_PAX_REFCOUNT
9701 + "jno 0f\n"
9702 + LOCK_PREFIX "addq %2,%0\n"
9703 + "int $4\n0:\n"
9704 + _ASM_EXTABLE(0b, 0b)
9705 +#endif
9706 +
9707 + "sete %1\n"
9708 : "=m" (v->counter), "=qm" (c)
9709 : "er" (i), "m" (v->counter) : "memory");
9710 return c;
9711 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9712 */
9713 static inline void atomic64_inc(atomic64_t *v)
9714 {
9715 + asm volatile(LOCK_PREFIX "incq %0\n"
9716 +
9717 +#ifdef CONFIG_PAX_REFCOUNT
9718 + "jno 0f\n"
9719 + LOCK_PREFIX "decq %0\n"
9720 + "int $4\n0:\n"
9721 + _ASM_EXTABLE(0b, 0b)
9722 +#endif
9723 +
9724 + : "=m" (v->counter)
9725 + : "m" (v->counter));
9726 +}
9727 +
9728 +/**
9729 + * atomic64_inc_unchecked - increment atomic64 variable
9730 + * @v: pointer to type atomic64_unchecked_t
9731 + *
9732 + * Atomically increments @v by 1.
9733 + */
9734 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9735 +{
9736 asm volatile(LOCK_PREFIX "incq %0"
9737 : "=m" (v->counter)
9738 : "m" (v->counter));
9739 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9740 */
9741 static inline void atomic64_dec(atomic64_t *v)
9742 {
9743 - asm volatile(LOCK_PREFIX "decq %0"
9744 + asm volatile(LOCK_PREFIX "decq %0\n"
9745 +
9746 +#ifdef CONFIG_PAX_REFCOUNT
9747 + "jno 0f\n"
9748 + LOCK_PREFIX "incq %0\n"
9749 + "int $4\n0:\n"
9750 + _ASM_EXTABLE(0b, 0b)
9751 +#endif
9752 +
9753 + : "=m" (v->counter)
9754 + : "m" (v->counter));
9755 +}
9756 +
9757 +/**
9758 + * atomic64_dec_unchecked - decrement atomic64 variable
9759 + * @v: pointer to type atomic64_t
9760 + *
9761 + * Atomically decrements @v by 1.
9762 + */
9763 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9764 +{
9765 + asm volatile(LOCK_PREFIX "decq %0\n"
9766 : "=m" (v->counter)
9767 : "m" (v->counter));
9768 }
9769 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9770 {
9771 unsigned char c;
9772
9773 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9774 + asm volatile(LOCK_PREFIX "decq %0\n"
9775 +
9776 +#ifdef CONFIG_PAX_REFCOUNT
9777 + "jno 0f\n"
9778 + LOCK_PREFIX "incq %0\n"
9779 + "int $4\n0:\n"
9780 + _ASM_EXTABLE(0b, 0b)
9781 +#endif
9782 +
9783 + "sete %1\n"
9784 : "=m" (v->counter), "=qm" (c)
9785 : "m" (v->counter) : "memory");
9786 return c != 0;
9787 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9788 {
9789 unsigned char c;
9790
9791 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9792 + asm volatile(LOCK_PREFIX "incq %0\n"
9793 +
9794 +#ifdef CONFIG_PAX_REFCOUNT
9795 + "jno 0f\n"
9796 + LOCK_PREFIX "decq %0\n"
9797 + "int $4\n0:\n"
9798 + _ASM_EXTABLE(0b, 0b)
9799 +#endif
9800 +
9801 + "sete %1\n"
9802 : "=m" (v->counter), "=qm" (c)
9803 : "m" (v->counter) : "memory");
9804 return c != 0;
9805 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9806 {
9807 unsigned char c;
9808
9809 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9810 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9811 +
9812 +#ifdef CONFIG_PAX_REFCOUNT
9813 + "jno 0f\n"
9814 + LOCK_PREFIX "subq %2,%0\n"
9815 + "int $4\n0:\n"
9816 + _ASM_EXTABLE(0b, 0b)
9817 +#endif
9818 +
9819 + "sets %1\n"
9820 : "=m" (v->counter), "=qm" (c)
9821 : "er" (i), "m" (v->counter) : "memory");
9822 return c;
9823 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9824 */
9825 static inline long atomic64_add_return(long i, atomic64_t *v)
9826 {
9827 + return i + xadd_check_overflow(&v->counter, i);
9828 +}
9829 +
9830 +/**
9831 + * atomic64_add_return_unchecked - add and return
9832 + * @i: integer value to add
9833 + * @v: pointer to type atomic64_unchecked_t
9834 + *
9835 + * Atomically adds @i to @v and returns @i + @v
9836 + */
9837 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9838 +{
9839 return i + xadd(&v->counter, i);
9840 }
9841
9842 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
9843 }
9844
9845 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
9846 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9847 +{
9848 + return atomic64_add_return_unchecked(1, v);
9849 +}
9850 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
9851
9852 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9853 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
9854 return cmpxchg(&v->counter, old, new);
9855 }
9856
9857 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
9858 +{
9859 + return cmpxchg(&v->counter, old, new);
9860 +}
9861 +
9862 static inline long atomic64_xchg(atomic64_t *v, long new)
9863 {
9864 return xchg(&v->counter, new);
9865 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
9866 */
9867 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
9868 {
9869 - long c, old;
9870 + long c, old, new;
9871 c = atomic64_read(v);
9872 for (;;) {
9873 - if (unlikely(c == (u)))
9874 + if (unlikely(c == u))
9875 break;
9876 - old = atomic64_cmpxchg((v), c, c + (a));
9877 +
9878 + asm volatile("add %2,%0\n"
9879 +
9880 +#ifdef CONFIG_PAX_REFCOUNT
9881 + "jno 0f\n"
9882 + "sub %2,%0\n"
9883 + "int $4\n0:\n"
9884 + _ASM_EXTABLE(0b, 0b)
9885 +#endif
9886 +
9887 + : "=r" (new)
9888 + : "0" (c), "ir" (a));
9889 +
9890 + old = atomic64_cmpxchg(v, c, new);
9891 if (likely(old == c))
9892 break;
9893 c = old;
9894 }
9895 - return c != (u);
9896 + return c != u;
9897 }
9898
9899 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9900 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
9901 index b97596e..9bd48b06 100644
9902 --- a/arch/x86/include/asm/bitops.h
9903 +++ b/arch/x86/include/asm/bitops.h
9904 @@ -38,7 +38,7 @@
9905 * a mask operation on a byte.
9906 */
9907 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
9908 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
9909 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
9910 #define CONST_MASK(nr) (1 << ((nr) & 7))
9911
9912 /**
9913 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
9914 index 5e1a2ee..c9f9533 100644
9915 --- a/arch/x86/include/asm/boot.h
9916 +++ b/arch/x86/include/asm/boot.h
9917 @@ -11,10 +11,15 @@
9918 #include <asm/pgtable_types.h>
9919
9920 /* Physical address where kernel should be loaded. */
9921 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9922 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
9923 + (CONFIG_PHYSICAL_ALIGN - 1)) \
9924 & ~(CONFIG_PHYSICAL_ALIGN - 1))
9925
9926 +#ifndef __ASSEMBLY__
9927 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
9928 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
9929 +#endif
9930 +
9931 /* Minimum kernel alignment, as a power of two */
9932 #ifdef CONFIG_X86_64
9933 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
9934 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
9935 index 48f99f1..d78ebf9 100644
9936 --- a/arch/x86/include/asm/cache.h
9937 +++ b/arch/x86/include/asm/cache.h
9938 @@ -5,12 +5,13 @@
9939
9940 /* L1 cache line size */
9941 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9942 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9943 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9944
9945 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9946 +#define __read_only __attribute__((__section__(".data..read_only")))
9947
9948 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
9949 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
9950 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
9951
9952 #ifdef CONFIG_X86_VSMP
9953 #ifdef CONFIG_SMP
9954 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
9955 index 4e12668..501d239 100644
9956 --- a/arch/x86/include/asm/cacheflush.h
9957 +++ b/arch/x86/include/asm/cacheflush.h
9958 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
9959 unsigned long pg_flags = pg->flags & _PGMT_MASK;
9960
9961 if (pg_flags == _PGMT_DEFAULT)
9962 - return -1;
9963 + return ~0UL;
9964 else if (pg_flags == _PGMT_WC)
9965 return _PAGE_CACHE_WC;
9966 else if (pg_flags == _PGMT_UC_MINUS)
9967 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
9968 index 46fc474..b02b0f9 100644
9969 --- a/arch/x86/include/asm/checksum_32.h
9970 +++ b/arch/x86/include/asm/checksum_32.h
9971 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
9972 int len, __wsum sum,
9973 int *src_err_ptr, int *dst_err_ptr);
9974
9975 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
9976 + int len, __wsum sum,
9977 + int *src_err_ptr, int *dst_err_ptr);
9978 +
9979 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
9980 + int len, __wsum sum,
9981 + int *src_err_ptr, int *dst_err_ptr);
9982 +
9983 /*
9984 * Note: when you get a NULL pointer exception here this means someone
9985 * passed in an incorrect kernel address to one of these functions.
9986 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
9987 int *err_ptr)
9988 {
9989 might_sleep();
9990 - return csum_partial_copy_generic((__force void *)src, dst,
9991 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
9992 len, sum, err_ptr, NULL);
9993 }
9994
9995 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
9996 {
9997 might_sleep();
9998 if (access_ok(VERIFY_WRITE, dst, len))
9999 - return csum_partial_copy_generic(src, (__force void *)dst,
10000 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10001 len, sum, NULL, err_ptr);
10002
10003 if (len)
10004 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10005 index 99480e5..d81165b 100644
10006 --- a/arch/x86/include/asm/cmpxchg.h
10007 +++ b/arch/x86/include/asm/cmpxchg.h
10008 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10009 __compiletime_error("Bad argument size for cmpxchg");
10010 extern void __xadd_wrong_size(void)
10011 __compiletime_error("Bad argument size for xadd");
10012 +extern void __xadd_check_overflow_wrong_size(void)
10013 + __compiletime_error("Bad argument size for xadd_check_overflow");
10014 extern void __add_wrong_size(void)
10015 __compiletime_error("Bad argument size for add");
10016 +extern void __add_check_overflow_wrong_size(void)
10017 + __compiletime_error("Bad argument size for add_check_overflow");
10018
10019 /*
10020 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10021 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10022 __ret; \
10023 })
10024
10025 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10026 + ({ \
10027 + __typeof__ (*(ptr)) __ret = (arg); \
10028 + switch (sizeof(*(ptr))) { \
10029 + case __X86_CASE_L: \
10030 + asm volatile (lock #op "l %0, %1\n" \
10031 + "jno 0f\n" \
10032 + "mov %0,%1\n" \
10033 + "int $4\n0:\n" \
10034 + _ASM_EXTABLE(0b, 0b) \
10035 + : "+r" (__ret), "+m" (*(ptr)) \
10036 + : : "memory", "cc"); \
10037 + break; \
10038 + case __X86_CASE_Q: \
10039 + asm volatile (lock #op "q %q0, %1\n" \
10040 + "jno 0f\n" \
10041 + "mov %0,%1\n" \
10042 + "int $4\n0:\n" \
10043 + _ASM_EXTABLE(0b, 0b) \
10044 + : "+r" (__ret), "+m" (*(ptr)) \
10045 + : : "memory", "cc"); \
10046 + break; \
10047 + default: \
10048 + __ ## op ## _check_overflow_wrong_size(); \
10049 + } \
10050 + __ret; \
10051 + })
10052 +
10053 /*
10054 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10055 * Since this is generally used to protect other memory information, we
10056 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10057 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10058 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10059
10060 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10061 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10062 +
10063 #define __add(ptr, inc, lock) \
10064 ({ \
10065 __typeof__ (*(ptr)) __ret = (inc); \
10066 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10067 index 8d67d42..183d0eb 100644
10068 --- a/arch/x86/include/asm/cpufeature.h
10069 +++ b/arch/x86/include/asm/cpufeature.h
10070 @@ -367,7 +367,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10071 ".section .discard,\"aw\",@progbits\n"
10072 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10073 ".previous\n"
10074 - ".section .altinstr_replacement,\"ax\"\n"
10075 + ".section .altinstr_replacement,\"a\"\n"
10076 "3: movb $1,%0\n"
10077 "4:\n"
10078 ".previous\n"
10079 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10080 index e95822d..a90010e 100644
10081 --- a/arch/x86/include/asm/desc.h
10082 +++ b/arch/x86/include/asm/desc.h
10083 @@ -4,6 +4,7 @@
10084 #include <asm/desc_defs.h>
10085 #include <asm/ldt.h>
10086 #include <asm/mmu.h>
10087 +#include <asm/pgtable.h>
10088
10089 #include <linux/smp.h>
10090
10091 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10092
10093 desc->type = (info->read_exec_only ^ 1) << 1;
10094 desc->type |= info->contents << 2;
10095 + desc->type |= info->seg_not_present ^ 1;
10096
10097 desc->s = 1;
10098 desc->dpl = 0x3;
10099 @@ -34,19 +36,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10100 }
10101
10102 extern struct desc_ptr idt_descr;
10103 -extern gate_desc idt_table[];
10104 extern struct desc_ptr nmi_idt_descr;
10105 -extern gate_desc nmi_idt_table[];
10106 -
10107 -struct gdt_page {
10108 - struct desc_struct gdt[GDT_ENTRIES];
10109 -} __attribute__((aligned(PAGE_SIZE)));
10110 -
10111 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10112 +extern gate_desc idt_table[256];
10113 +extern gate_desc nmi_idt_table[256];
10114
10115 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10116 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10117 {
10118 - return per_cpu(gdt_page, cpu).gdt;
10119 + return cpu_gdt_table[cpu];
10120 }
10121
10122 #ifdef CONFIG_X86_64
10123 @@ -71,8 +68,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10124 unsigned long base, unsigned dpl, unsigned flags,
10125 unsigned short seg)
10126 {
10127 - gate->a = (seg << 16) | (base & 0xffff);
10128 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10129 + gate->gate.offset_low = base;
10130 + gate->gate.seg = seg;
10131 + gate->gate.reserved = 0;
10132 + gate->gate.type = type;
10133 + gate->gate.s = 0;
10134 + gate->gate.dpl = dpl;
10135 + gate->gate.p = 1;
10136 + gate->gate.offset_high = base >> 16;
10137 }
10138
10139 #endif
10140 @@ -117,12 +120,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10141
10142 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10143 {
10144 + pax_open_kernel();
10145 memcpy(&idt[entry], gate, sizeof(*gate));
10146 + pax_close_kernel();
10147 }
10148
10149 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10150 {
10151 + pax_open_kernel();
10152 memcpy(&ldt[entry], desc, 8);
10153 + pax_close_kernel();
10154 }
10155
10156 static inline void
10157 @@ -136,7 +143,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10158 default: size = sizeof(*gdt); break;
10159 }
10160
10161 + pax_open_kernel();
10162 memcpy(&gdt[entry], desc, size);
10163 + pax_close_kernel();
10164 }
10165
10166 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10167 @@ -209,7 +218,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10168
10169 static inline void native_load_tr_desc(void)
10170 {
10171 + pax_open_kernel();
10172 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10173 + pax_close_kernel();
10174 }
10175
10176 static inline void native_load_gdt(const struct desc_ptr *dtr)
10177 @@ -246,8 +257,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10178 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10179 unsigned int i;
10180
10181 + pax_open_kernel();
10182 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10183 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10184 + pax_close_kernel();
10185 }
10186
10187 #define _LDT_empty(info) \
10188 @@ -310,7 +323,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10189 }
10190
10191 #ifdef CONFIG_X86_64
10192 -static inline void set_nmi_gate(int gate, void *addr)
10193 +static inline void set_nmi_gate(int gate, const void *addr)
10194 {
10195 gate_desc s;
10196
10197 @@ -319,7 +332,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10198 }
10199 #endif
10200
10201 -static inline void _set_gate(int gate, unsigned type, void *addr,
10202 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10203 unsigned dpl, unsigned ist, unsigned seg)
10204 {
10205 gate_desc s;
10206 @@ -338,7 +351,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10207 * Pentium F0 0F bugfix can have resulted in the mapped
10208 * IDT being write-protected.
10209 */
10210 -static inline void set_intr_gate(unsigned int n, void *addr)
10211 +static inline void set_intr_gate(unsigned int n, const void *addr)
10212 {
10213 BUG_ON((unsigned)n > 0xFF);
10214 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10215 @@ -368,19 +381,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10216 /*
10217 * This routine sets up an interrupt gate at directory privilege level 3.
10218 */
10219 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10220 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10221 {
10222 BUG_ON((unsigned)n > 0xFF);
10223 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10224 }
10225
10226 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10227 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10228 {
10229 BUG_ON((unsigned)n > 0xFF);
10230 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10231 }
10232
10233 -static inline void set_trap_gate(unsigned int n, void *addr)
10234 +static inline void set_trap_gate(unsigned int n, const void *addr)
10235 {
10236 BUG_ON((unsigned)n > 0xFF);
10237 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10238 @@ -389,19 +402,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10239 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10240 {
10241 BUG_ON((unsigned)n > 0xFF);
10242 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10243 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10244 }
10245
10246 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10247 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10248 {
10249 BUG_ON((unsigned)n > 0xFF);
10250 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10251 }
10252
10253 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10254 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10255 {
10256 BUG_ON((unsigned)n > 0xFF);
10257 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10258 }
10259
10260 +#ifdef CONFIG_X86_32
10261 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10262 +{
10263 + struct desc_struct d;
10264 +
10265 + if (likely(limit))
10266 + limit = (limit - 1UL) >> PAGE_SHIFT;
10267 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10268 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10269 +}
10270 +#endif
10271 +
10272 #endif /* _ASM_X86_DESC_H */
10273 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10274 index 278441f..b95a174 100644
10275 --- a/arch/x86/include/asm/desc_defs.h
10276 +++ b/arch/x86/include/asm/desc_defs.h
10277 @@ -31,6 +31,12 @@ struct desc_struct {
10278 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10279 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10280 };
10281 + struct {
10282 + u16 offset_low;
10283 + u16 seg;
10284 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10285 + unsigned offset_high: 16;
10286 + } gate;
10287 };
10288 } __attribute__((packed));
10289
10290 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10291 index 3778256..c5d4fce 100644
10292 --- a/arch/x86/include/asm/e820.h
10293 +++ b/arch/x86/include/asm/e820.h
10294 @@ -69,7 +69,7 @@ struct e820map {
10295 #define ISA_START_ADDRESS 0xa0000
10296 #define ISA_END_ADDRESS 0x100000
10297
10298 -#define BIOS_BEGIN 0x000a0000
10299 +#define BIOS_BEGIN 0x000c0000
10300 #define BIOS_END 0x00100000
10301
10302 #define BIOS_ROM_BASE 0xffe00000
10303 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10304 index 5f962df..7289f09 100644
10305 --- a/arch/x86/include/asm/elf.h
10306 +++ b/arch/x86/include/asm/elf.h
10307 @@ -238,7 +238,25 @@ extern int force_personality32;
10308 the loader. We need to make sure that it is out of the way of the program
10309 that it will "exec", and that there is sufficient room for the brk. */
10310
10311 +#ifdef CONFIG_PAX_SEGMEXEC
10312 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10313 +#else
10314 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10315 +#endif
10316 +
10317 +#ifdef CONFIG_PAX_ASLR
10318 +#ifdef CONFIG_X86_32
10319 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10320 +
10321 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10322 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10323 +#else
10324 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10325 +
10326 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10327 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10328 +#endif
10329 +#endif
10330
10331 /* This yields a mask that user programs can use to figure out what
10332 instruction set this CPU supports. This could be done in user space,
10333 @@ -291,9 +309,7 @@ do { \
10334
10335 #define ARCH_DLINFO \
10336 do { \
10337 - if (vdso_enabled) \
10338 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10339 - (unsigned long)current->mm->context.vdso); \
10340 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10341 } while (0)
10342
10343 #define AT_SYSINFO 32
10344 @@ -304,7 +320,7 @@ do { \
10345
10346 #endif /* !CONFIG_X86_32 */
10347
10348 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10349 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10350
10351 #define VDSO_ENTRY \
10352 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10353 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
10354 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10355 #define compat_arch_setup_additional_pages syscall32_setup_pages
10356
10357 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10358 -#define arch_randomize_brk arch_randomize_brk
10359 -
10360 /*
10361 * True on X86_32 or when emulating IA32 on X86_64
10362 */
10363 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10364 index cc70c1c..d96d011 100644
10365 --- a/arch/x86/include/asm/emergency-restart.h
10366 +++ b/arch/x86/include/asm/emergency-restart.h
10367 @@ -15,6 +15,6 @@ enum reboot_type {
10368
10369 extern enum reboot_type reboot_type;
10370
10371 -extern void machine_emergency_restart(void);
10372 +extern void machine_emergency_restart(void) __noreturn;
10373
10374 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10375 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10376 index d09bb03..4ea4194 100644
10377 --- a/arch/x86/include/asm/futex.h
10378 +++ b/arch/x86/include/asm/futex.h
10379 @@ -12,16 +12,18 @@
10380 #include <asm/system.h>
10381
10382 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10383 + typecheck(u32 __user *, uaddr); \
10384 asm volatile("1:\t" insn "\n" \
10385 "2:\t.section .fixup,\"ax\"\n" \
10386 "3:\tmov\t%3, %1\n" \
10387 "\tjmp\t2b\n" \
10388 "\t.previous\n" \
10389 _ASM_EXTABLE(1b, 3b) \
10390 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10391 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10392 : "i" (-EFAULT), "0" (oparg), "1" (0))
10393
10394 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10395 + typecheck(u32 __user *, uaddr); \
10396 asm volatile("1:\tmovl %2, %0\n" \
10397 "\tmovl\t%0, %3\n" \
10398 "\t" insn "\n" \
10399 @@ -34,7 +36,7 @@
10400 _ASM_EXTABLE(1b, 4b) \
10401 _ASM_EXTABLE(2b, 4b) \
10402 : "=&a" (oldval), "=&r" (ret), \
10403 - "+m" (*uaddr), "=&r" (tem) \
10404 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10405 : "r" (oparg), "i" (-EFAULT), "1" (0))
10406
10407 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10408 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10409
10410 switch (op) {
10411 case FUTEX_OP_SET:
10412 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10413 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10414 break;
10415 case FUTEX_OP_ADD:
10416 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10417 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10418 uaddr, oparg);
10419 break;
10420 case FUTEX_OP_OR:
10421 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10422 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10423 return -EFAULT;
10424
10425 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10426 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10427 "2:\t.section .fixup, \"ax\"\n"
10428 "3:\tmov %3, %0\n"
10429 "\tjmp 2b\n"
10430 "\t.previous\n"
10431 _ASM_EXTABLE(1b, 3b)
10432 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10433 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10434 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10435 : "memory"
10436 );
10437 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10438 index eb92a6e..b98b2f4 100644
10439 --- a/arch/x86/include/asm/hw_irq.h
10440 +++ b/arch/x86/include/asm/hw_irq.h
10441 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10442 extern void enable_IO_APIC(void);
10443
10444 /* Statistics */
10445 -extern atomic_t irq_err_count;
10446 -extern atomic_t irq_mis_count;
10447 +extern atomic_unchecked_t irq_err_count;
10448 +extern atomic_unchecked_t irq_mis_count;
10449
10450 /* EISA */
10451 extern void eisa_set_level_irq(unsigned int irq);
10452 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
10453 index 2479049..3fb9795 100644
10454 --- a/arch/x86/include/asm/i387.h
10455 +++ b/arch/x86/include/asm/i387.h
10456 @@ -93,6 +93,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10457 {
10458 int err;
10459
10460 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10461 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10462 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10463 +#endif
10464 +
10465 /* See comment in fxsave() below. */
10466 #ifdef CONFIG_AS_FXSAVEQ
10467 asm volatile("1: fxrstorq %[fx]\n\t"
10468 @@ -122,6 +127,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10469 {
10470 int err;
10471
10472 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10473 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10474 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10475 +#endif
10476 +
10477 /*
10478 * Clear the bytes not touched by the fxsave and reserved
10479 * for the SW usage.
10480 @@ -278,7 +288,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10481 "emms\n\t" /* clear stack tags */
10482 "fildl %P[addr]", /* set F?P to defined value */
10483 X86_FEATURE_FXSAVE_LEAK,
10484 - [addr] "m" (tsk->thread.fpu.has_fpu));
10485 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10486
10487 return fpu_restore_checking(&tsk->thread.fpu);
10488 }
10489 @@ -445,7 +455,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
10490 static inline bool interrupted_user_mode(void)
10491 {
10492 struct pt_regs *regs = get_irq_regs();
10493 - return regs && user_mode_vm(regs);
10494 + return regs && user_mode(regs);
10495 }
10496
10497 /*
10498 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10499 index d8e8eef..99f81ae 100644
10500 --- a/arch/x86/include/asm/io.h
10501 +++ b/arch/x86/include/asm/io.h
10502 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10503
10504 #include <linux/vmalloc.h>
10505
10506 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10507 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10508 +{
10509 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10510 +}
10511 +
10512 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10513 +{
10514 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10515 +}
10516 +
10517 /*
10518 * Convert a virtual cached pointer to an uncached pointer
10519 */
10520 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10521 index bba3cf8..06bc8da 100644
10522 --- a/arch/x86/include/asm/irqflags.h
10523 +++ b/arch/x86/include/asm/irqflags.h
10524 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10525 sti; \
10526 sysexit
10527
10528 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10529 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10530 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10531 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10532 +
10533 #else
10534 #define INTERRUPT_RETURN iret
10535 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10536 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10537 index 5478825..839e88c 100644
10538 --- a/arch/x86/include/asm/kprobes.h
10539 +++ b/arch/x86/include/asm/kprobes.h
10540 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10541 #define RELATIVEJUMP_SIZE 5
10542 #define RELATIVECALL_OPCODE 0xe8
10543 #define RELATIVE_ADDR_SIZE 4
10544 -#define MAX_STACK_SIZE 64
10545 -#define MIN_STACK_SIZE(ADDR) \
10546 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10547 - THREAD_SIZE - (unsigned long)(ADDR))) \
10548 - ? (MAX_STACK_SIZE) \
10549 - : (((unsigned long)current_thread_info()) + \
10550 - THREAD_SIZE - (unsigned long)(ADDR)))
10551 +#define MAX_STACK_SIZE 64UL
10552 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10553
10554 #define flush_insn_slot(p) do { } while (0)
10555
10556 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10557 index 52d6640..a013b87 100644
10558 --- a/arch/x86/include/asm/kvm_host.h
10559 +++ b/arch/x86/include/asm/kvm_host.h
10560 @@ -663,7 +663,7 @@ struct kvm_x86_ops {
10561 int (*check_intercept)(struct kvm_vcpu *vcpu,
10562 struct x86_instruction_info *info,
10563 enum x86_intercept_stage stage);
10564 -};
10565 +} __do_const;
10566
10567 struct kvm_arch_async_pf {
10568 u32 token;
10569 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10570 index 9cdae5d..300d20f 100644
10571 --- a/arch/x86/include/asm/local.h
10572 +++ b/arch/x86/include/asm/local.h
10573 @@ -18,26 +18,58 @@ typedef struct {
10574
10575 static inline void local_inc(local_t *l)
10576 {
10577 - asm volatile(_ASM_INC "%0"
10578 + asm volatile(_ASM_INC "%0\n"
10579 +
10580 +#ifdef CONFIG_PAX_REFCOUNT
10581 + "jno 0f\n"
10582 + _ASM_DEC "%0\n"
10583 + "int $4\n0:\n"
10584 + _ASM_EXTABLE(0b, 0b)
10585 +#endif
10586 +
10587 : "+m" (l->a.counter));
10588 }
10589
10590 static inline void local_dec(local_t *l)
10591 {
10592 - asm volatile(_ASM_DEC "%0"
10593 + asm volatile(_ASM_DEC "%0\n"
10594 +
10595 +#ifdef CONFIG_PAX_REFCOUNT
10596 + "jno 0f\n"
10597 + _ASM_INC "%0\n"
10598 + "int $4\n0:\n"
10599 + _ASM_EXTABLE(0b, 0b)
10600 +#endif
10601 +
10602 : "+m" (l->a.counter));
10603 }
10604
10605 static inline void local_add(long i, local_t *l)
10606 {
10607 - asm volatile(_ASM_ADD "%1,%0"
10608 + asm volatile(_ASM_ADD "%1,%0\n"
10609 +
10610 +#ifdef CONFIG_PAX_REFCOUNT
10611 + "jno 0f\n"
10612 + _ASM_SUB "%1,%0\n"
10613 + "int $4\n0:\n"
10614 + _ASM_EXTABLE(0b, 0b)
10615 +#endif
10616 +
10617 : "+m" (l->a.counter)
10618 : "ir" (i));
10619 }
10620
10621 static inline void local_sub(long i, local_t *l)
10622 {
10623 - asm volatile(_ASM_SUB "%1,%0"
10624 + asm volatile(_ASM_SUB "%1,%0\n"
10625 +
10626 +#ifdef CONFIG_PAX_REFCOUNT
10627 + "jno 0f\n"
10628 + _ASM_ADD "%1,%0\n"
10629 + "int $4\n0:\n"
10630 + _ASM_EXTABLE(0b, 0b)
10631 +#endif
10632 +
10633 : "+m" (l->a.counter)
10634 : "ir" (i));
10635 }
10636 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10637 {
10638 unsigned char c;
10639
10640 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10641 + asm volatile(_ASM_SUB "%2,%0\n"
10642 +
10643 +#ifdef CONFIG_PAX_REFCOUNT
10644 + "jno 0f\n"
10645 + _ASM_ADD "%2,%0\n"
10646 + "int $4\n0:\n"
10647 + _ASM_EXTABLE(0b, 0b)
10648 +#endif
10649 +
10650 + "sete %1\n"
10651 : "+m" (l->a.counter), "=qm" (c)
10652 : "ir" (i) : "memory");
10653 return c;
10654 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
10655 {
10656 unsigned char c;
10657
10658 - asm volatile(_ASM_DEC "%0; sete %1"
10659 + asm volatile(_ASM_DEC "%0\n"
10660 +
10661 +#ifdef CONFIG_PAX_REFCOUNT
10662 + "jno 0f\n"
10663 + _ASM_INC "%0\n"
10664 + "int $4\n0:\n"
10665 + _ASM_EXTABLE(0b, 0b)
10666 +#endif
10667 +
10668 + "sete %1\n"
10669 : "+m" (l->a.counter), "=qm" (c)
10670 : : "memory");
10671 return c != 0;
10672 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
10673 {
10674 unsigned char c;
10675
10676 - asm volatile(_ASM_INC "%0; sete %1"
10677 + asm volatile(_ASM_INC "%0\n"
10678 +
10679 +#ifdef CONFIG_PAX_REFCOUNT
10680 + "jno 0f\n"
10681 + _ASM_DEC "%0\n"
10682 + "int $4\n0:\n"
10683 + _ASM_EXTABLE(0b, 0b)
10684 +#endif
10685 +
10686 + "sete %1\n"
10687 : "+m" (l->a.counter), "=qm" (c)
10688 : : "memory");
10689 return c != 0;
10690 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
10691 {
10692 unsigned char c;
10693
10694 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10695 + asm volatile(_ASM_ADD "%2,%0\n"
10696 +
10697 +#ifdef CONFIG_PAX_REFCOUNT
10698 + "jno 0f\n"
10699 + _ASM_SUB "%2,%0\n"
10700 + "int $4\n0:\n"
10701 + _ASM_EXTABLE(0b, 0b)
10702 +#endif
10703 +
10704 + "sets %1\n"
10705 : "+m" (l->a.counter), "=qm" (c)
10706 : "ir" (i) : "memory");
10707 return c;
10708 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
10709 #endif
10710 /* Modern 486+ processor */
10711 __i = i;
10712 - asm volatile(_ASM_XADD "%0, %1;"
10713 + asm volatile(_ASM_XADD "%0, %1\n"
10714 +
10715 +#ifdef CONFIG_PAX_REFCOUNT
10716 + "jno 0f\n"
10717 + _ASM_MOV "%0,%1\n"
10718 + "int $4\n0:\n"
10719 + _ASM_EXTABLE(0b, 0b)
10720 +#endif
10721 +
10722 : "+r" (i), "+m" (l->a.counter)
10723 : : "memory");
10724 return i + __i;
10725 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10726 index 593e51d..fa69c9a 100644
10727 --- a/arch/x86/include/asm/mman.h
10728 +++ b/arch/x86/include/asm/mman.h
10729 @@ -5,4 +5,14 @@
10730
10731 #include <asm-generic/mman.h>
10732
10733 +#ifdef __KERNEL__
10734 +#ifndef __ASSEMBLY__
10735 +#ifdef CONFIG_X86_32
10736 +#define arch_mmap_check i386_mmap_check
10737 +int i386_mmap_check(unsigned long addr, unsigned long len,
10738 + unsigned long flags);
10739 +#endif
10740 +#endif
10741 +#endif
10742 +
10743 #endif /* _ASM_X86_MMAN_H */
10744 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10745 index 5f55e69..e20bfb1 100644
10746 --- a/arch/x86/include/asm/mmu.h
10747 +++ b/arch/x86/include/asm/mmu.h
10748 @@ -9,7 +9,7 @@
10749 * we put the segment information here.
10750 */
10751 typedef struct {
10752 - void *ldt;
10753 + struct desc_struct *ldt;
10754 int size;
10755
10756 #ifdef CONFIG_X86_64
10757 @@ -18,7 +18,19 @@ typedef struct {
10758 #endif
10759
10760 struct mutex lock;
10761 - void *vdso;
10762 + unsigned long vdso;
10763 +
10764 +#ifdef CONFIG_X86_32
10765 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10766 + unsigned long user_cs_base;
10767 + unsigned long user_cs_limit;
10768 +
10769 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10770 + cpumask_t cpu_user_cs_mask;
10771 +#endif
10772 +
10773 +#endif
10774 +#endif
10775 } mm_context_t;
10776
10777 #ifdef CONFIG_SMP
10778 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10779 index 6902152..da4283a 100644
10780 --- a/arch/x86/include/asm/mmu_context.h
10781 +++ b/arch/x86/include/asm/mmu_context.h
10782 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10783
10784 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10785 {
10786 +
10787 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10788 + unsigned int i;
10789 + pgd_t *pgd;
10790 +
10791 + pax_open_kernel();
10792 + pgd = get_cpu_pgd(smp_processor_id());
10793 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10794 + set_pgd_batched(pgd+i, native_make_pgd(0));
10795 + pax_close_kernel();
10796 +#endif
10797 +
10798 #ifdef CONFIG_SMP
10799 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10800 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10801 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10802 struct task_struct *tsk)
10803 {
10804 unsigned cpu = smp_processor_id();
10805 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10806 + int tlbstate = TLBSTATE_OK;
10807 +#endif
10808
10809 if (likely(prev != next)) {
10810 #ifdef CONFIG_SMP
10811 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10812 + tlbstate = percpu_read(cpu_tlbstate.state);
10813 +#endif
10814 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10815 percpu_write(cpu_tlbstate.active_mm, next);
10816 #endif
10817 cpumask_set_cpu(cpu, mm_cpumask(next));
10818
10819 /* Re-load page tables */
10820 +#ifdef CONFIG_PAX_PER_CPU_PGD
10821 + pax_open_kernel();
10822 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10823 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10824 + pax_close_kernel();
10825 + load_cr3(get_cpu_pgd(cpu));
10826 +#else
10827 load_cr3(next->pgd);
10828 +#endif
10829
10830 /* stop flush ipis for the previous mm */
10831 cpumask_clear_cpu(cpu, mm_cpumask(prev));
10832 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10833 */
10834 if (unlikely(prev->context.ldt != next->context.ldt))
10835 load_LDT_nolock(&next->context);
10836 - }
10837 +
10838 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10839 + if (!(__supported_pte_mask & _PAGE_NX)) {
10840 + smp_mb__before_clear_bit();
10841 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
10842 + smp_mb__after_clear_bit();
10843 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10844 + }
10845 +#endif
10846 +
10847 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10848 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
10849 + prev->context.user_cs_limit != next->context.user_cs_limit))
10850 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10851 #ifdef CONFIG_SMP
10852 + else if (unlikely(tlbstate != TLBSTATE_OK))
10853 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10854 +#endif
10855 +#endif
10856 +
10857 + }
10858 else {
10859 +
10860 +#ifdef CONFIG_PAX_PER_CPU_PGD
10861 + pax_open_kernel();
10862 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10863 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
10864 + pax_close_kernel();
10865 + load_cr3(get_cpu_pgd(cpu));
10866 +#endif
10867 +
10868 +#ifdef CONFIG_SMP
10869 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10870 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
10871
10872 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10873 * tlb flush IPI delivery. We must reload CR3
10874 * to make sure to use no freed page tables.
10875 */
10876 +
10877 +#ifndef CONFIG_PAX_PER_CPU_PGD
10878 load_cr3(next->pgd);
10879 +#endif
10880 +
10881 load_LDT_nolock(&next->context);
10882 +
10883 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
10884 + if (!(__supported_pte_mask & _PAGE_NX))
10885 + cpu_set(cpu, next->context.cpu_user_cs_mask);
10886 +#endif
10887 +
10888 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10889 +#ifdef CONFIG_PAX_PAGEEXEC
10890 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
10891 +#endif
10892 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
10893 +#endif
10894 +
10895 }
10896 +#endif
10897 }
10898 -#endif
10899 }
10900
10901 #define activate_mm(prev, next) \
10902 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
10903 index 9eae775..c914fea 100644
10904 --- a/arch/x86/include/asm/module.h
10905 +++ b/arch/x86/include/asm/module.h
10906 @@ -5,6 +5,7 @@
10907
10908 #ifdef CONFIG_X86_64
10909 /* X86_64 does not define MODULE_PROC_FAMILY */
10910 +#define MODULE_PROC_FAMILY ""
10911 #elif defined CONFIG_M386
10912 #define MODULE_PROC_FAMILY "386 "
10913 #elif defined CONFIG_M486
10914 @@ -59,8 +60,20 @@
10915 #error unknown processor family
10916 #endif
10917
10918 -#ifdef CONFIG_X86_32
10919 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
10920 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10921 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
10922 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
10923 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
10924 +#else
10925 +#define MODULE_PAX_KERNEXEC ""
10926 #endif
10927
10928 +#ifdef CONFIG_PAX_MEMORY_UDEREF
10929 +#define MODULE_PAX_UDEREF "UDEREF "
10930 +#else
10931 +#define MODULE_PAX_UDEREF ""
10932 +#endif
10933 +
10934 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
10935 +
10936 #endif /* _ASM_X86_MODULE_H */
10937 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
10938 index 7639dbf..e08a58c 100644
10939 --- a/arch/x86/include/asm/page_64_types.h
10940 +++ b/arch/x86/include/asm/page_64_types.h
10941 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
10942
10943 /* duplicated to the one in bootmem.h */
10944 extern unsigned long max_pfn;
10945 -extern unsigned long phys_base;
10946 +extern const unsigned long phys_base;
10947
10948 extern unsigned long __phys_addr(unsigned long);
10949 #define __phys_reloc_hide(x) (x)
10950 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
10951 index a7d2db9..edb023e 100644
10952 --- a/arch/x86/include/asm/paravirt.h
10953 +++ b/arch/x86/include/asm/paravirt.h
10954 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
10955 val);
10956 }
10957
10958 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
10959 +{
10960 + pgdval_t val = native_pgd_val(pgd);
10961 +
10962 + if (sizeof(pgdval_t) > sizeof(long))
10963 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
10964 + val, (u64)val >> 32);
10965 + else
10966 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
10967 + val);
10968 +}
10969 +
10970 static inline void pgd_clear(pgd_t *pgdp)
10971 {
10972 set_pgd(pgdp, __pgd(0));
10973 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
10974 pv_mmu_ops.set_fixmap(idx, phys, flags);
10975 }
10976
10977 +#ifdef CONFIG_PAX_KERNEXEC
10978 +static inline unsigned long pax_open_kernel(void)
10979 +{
10980 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
10981 +}
10982 +
10983 +static inline unsigned long pax_close_kernel(void)
10984 +{
10985 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
10986 +}
10987 +#else
10988 +static inline unsigned long pax_open_kernel(void) { return 0; }
10989 +static inline unsigned long pax_close_kernel(void) { return 0; }
10990 +#endif
10991 +
10992 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
10993
10994 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
10995 @@ -964,7 +991,7 @@ extern void default_banner(void);
10996
10997 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
10998 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
10999 -#define PARA_INDIRECT(addr) *%cs:addr
11000 +#define PARA_INDIRECT(addr) *%ss:addr
11001 #endif
11002
11003 #define INTERRUPT_RETURN \
11004 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
11005 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11006 CLBR_NONE, \
11007 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11008 +
11009 +#define GET_CR0_INTO_RDI \
11010 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11011 + mov %rax,%rdi
11012 +
11013 +#define SET_RDI_INTO_CR0 \
11014 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11015 +
11016 +#define GET_CR3_INTO_RDI \
11017 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11018 + mov %rax,%rdi
11019 +
11020 +#define SET_RDI_INTO_CR3 \
11021 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11022 +
11023 #endif /* CONFIG_X86_32 */
11024
11025 #endif /* __ASSEMBLY__ */
11026 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11027 index 8e8b9a4..f07d725 100644
11028 --- a/arch/x86/include/asm/paravirt_types.h
11029 +++ b/arch/x86/include/asm/paravirt_types.h
11030 @@ -84,20 +84,20 @@ struct pv_init_ops {
11031 */
11032 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11033 unsigned long addr, unsigned len);
11034 -};
11035 +} __no_const;
11036
11037
11038 struct pv_lazy_ops {
11039 /* Set deferred update mode, used for batching operations. */
11040 void (*enter)(void);
11041 void (*leave)(void);
11042 -};
11043 +} __no_const;
11044
11045 struct pv_time_ops {
11046 unsigned long long (*sched_clock)(void);
11047 unsigned long long (*steal_clock)(int cpu);
11048 unsigned long (*get_tsc_khz)(void);
11049 -};
11050 +} __no_const;
11051
11052 struct pv_cpu_ops {
11053 /* hooks for various privileged instructions */
11054 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11055
11056 void (*start_context_switch)(struct task_struct *prev);
11057 void (*end_context_switch)(struct task_struct *next);
11058 -};
11059 +} __no_const;
11060
11061 struct pv_irq_ops {
11062 /*
11063 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11064 unsigned long start_eip,
11065 unsigned long start_esp);
11066 #endif
11067 -};
11068 +} __no_const;
11069
11070 struct pv_mmu_ops {
11071 unsigned long (*read_cr2)(void);
11072 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11073 struct paravirt_callee_save make_pud;
11074
11075 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11076 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11077 #endif /* PAGETABLE_LEVELS == 4 */
11078 #endif /* PAGETABLE_LEVELS >= 3 */
11079
11080 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11081 an mfn. We can tell which is which from the index. */
11082 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11083 phys_addr_t phys, pgprot_t flags);
11084 +
11085 +#ifdef CONFIG_PAX_KERNEXEC
11086 + unsigned long (*pax_open_kernel)(void);
11087 + unsigned long (*pax_close_kernel)(void);
11088 +#endif
11089 +
11090 };
11091
11092 struct arch_spinlock;
11093 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11094 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11095 int (*spin_trylock)(struct arch_spinlock *lock);
11096 void (*spin_unlock)(struct arch_spinlock *lock);
11097 -};
11098 +} __no_const;
11099
11100 /* This contains all the paravirt structures: we get a convenient
11101 * number for each function using the offset which we use to indicate
11102 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11103 index b4389a4..7024269 100644
11104 --- a/arch/x86/include/asm/pgalloc.h
11105 +++ b/arch/x86/include/asm/pgalloc.h
11106 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11107 pmd_t *pmd, pte_t *pte)
11108 {
11109 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11110 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11111 +}
11112 +
11113 +static inline void pmd_populate_user(struct mm_struct *mm,
11114 + pmd_t *pmd, pte_t *pte)
11115 +{
11116 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11117 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11118 }
11119
11120 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11121
11122 #ifdef CONFIG_X86_PAE
11123 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11124 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11125 +{
11126 + pud_populate(mm, pudp, pmd);
11127 +}
11128 #else /* !CONFIG_X86_PAE */
11129 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11130 {
11131 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11132 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11133 }
11134 +
11135 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11136 +{
11137 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11138 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11139 +}
11140 #endif /* CONFIG_X86_PAE */
11141
11142 #if PAGETABLE_LEVELS > 3
11143 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11144 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11145 }
11146
11147 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11148 +{
11149 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11150 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11151 +}
11152 +
11153 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11154 {
11155 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11156 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11157 index 98391db..8f6984e 100644
11158 --- a/arch/x86/include/asm/pgtable-2level.h
11159 +++ b/arch/x86/include/asm/pgtable-2level.h
11160 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11161
11162 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11163 {
11164 + pax_open_kernel();
11165 *pmdp = pmd;
11166 + pax_close_kernel();
11167 }
11168
11169 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11170 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11171 index effff47..bbb8295 100644
11172 --- a/arch/x86/include/asm/pgtable-3level.h
11173 +++ b/arch/x86/include/asm/pgtable-3level.h
11174 @@ -31,6 +31,56 @@ static inline void native_set_pte(pte_t *ptep, pte_t pte)
11175 ptep->pte_low = pte.pte_low;
11176 }
11177
11178 +#define __HAVE_ARCH_READ_PMD_ATOMIC
11179 +/*
11180 + * pte_offset_map_lock on 32bit PAE kernels was reading the pmd_t with
11181 + * a "*pmdp" dereference done by gcc. Problem is, in certain places
11182 + * where pte_offset_map_lock is called, concurrent page faults are
11183 + * allowed, if the mmap_sem is hold for reading. An example is mincore
11184 + * vs page faults vs MADV_DONTNEED. On the page fault side
11185 + * pmd_populate rightfully does a set_64bit, but if we're reading the
11186 + * pmd_t with a "*pmdp" on the mincore side, a SMP race can happen
11187 + * because gcc will not read the 64bit of the pmd atomically. To fix
11188 + * this all places running pmd_offset_map_lock() while holding the
11189 + * mmap_sem in read mode, shall read the pmdp pointer using this
11190 + * function to know if the pmd is null nor not, and in turn to know if
11191 + * they can run pmd_offset_map_lock or pmd_trans_huge or other pmd
11192 + * operations.
11193 + *
11194 + * Without THP if the mmap_sem is hold for reading, the
11195 + * pmd can only transition from null to not null while read_pmd_atomic runs.
11196 + * So there's no need of literally reading it atomically.
11197 + *
11198 + * With THP if the mmap_sem is hold for reading, the pmd can become
11199 + * THP or null or point to a pte (and in turn become "stable") at any
11200 + * time under read_pmd_atomic, so it's mandatory to read it atomically
11201 + * with cmpxchg8b.
11202 + */
11203 +#ifndef CONFIG_TRANSPARENT_HUGEPAGE
11204 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11205 +{
11206 + pmdval_t ret;
11207 + u32 *tmp = (u32 *)pmdp;
11208 +
11209 + ret = (pmdval_t) (*tmp);
11210 + if (ret) {
11211 + /*
11212 + * If the low part is null, we must not read the high part
11213 + * or we can end up with a partial pmd.
11214 + */
11215 + smp_rmb();
11216 + ret |= ((pmdval_t)*(tmp + 1)) << 32;
11217 + }
11218 +
11219 + return __pmd(ret);
11220 +}
11221 +#else /* CONFIG_TRANSPARENT_HUGEPAGE */
11222 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
11223 +{
11224 + return __pmd(atomic64_read((atomic64_t *)pmdp));
11225 +}
11226 +#endif /* CONFIG_TRANSPARENT_HUGEPAGE */
11227 +
11228 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11229 {
11230 set_64bit((unsigned long long *)(ptep), native_pte_val(pte));
11231 @@ -38,12 +88,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11232
11233 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11234 {
11235 + pax_open_kernel();
11236 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11237 + pax_close_kernel();
11238 }
11239
11240 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11241 {
11242 + pax_open_kernel();
11243 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11244 + pax_close_kernel();
11245 }
11246
11247 /*
11248 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11249 index 49afb3f..91a8c63 100644
11250 --- a/arch/x86/include/asm/pgtable.h
11251 +++ b/arch/x86/include/asm/pgtable.h
11252 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11253
11254 #ifndef __PAGETABLE_PUD_FOLDED
11255 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11256 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11257 #define pgd_clear(pgd) native_pgd_clear(pgd)
11258 #endif
11259
11260 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11261
11262 #define arch_end_context_switch(prev) do {} while(0)
11263
11264 +#define pax_open_kernel() native_pax_open_kernel()
11265 +#define pax_close_kernel() native_pax_close_kernel()
11266 #endif /* CONFIG_PARAVIRT */
11267
11268 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11269 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11270 +
11271 +#ifdef CONFIG_PAX_KERNEXEC
11272 +static inline unsigned long native_pax_open_kernel(void)
11273 +{
11274 + unsigned long cr0;
11275 +
11276 + preempt_disable();
11277 + barrier();
11278 + cr0 = read_cr0() ^ X86_CR0_WP;
11279 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11280 + write_cr0(cr0);
11281 + return cr0 ^ X86_CR0_WP;
11282 +}
11283 +
11284 +static inline unsigned long native_pax_close_kernel(void)
11285 +{
11286 + unsigned long cr0;
11287 +
11288 + cr0 = read_cr0() ^ X86_CR0_WP;
11289 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11290 + write_cr0(cr0);
11291 + barrier();
11292 + preempt_enable_no_resched();
11293 + return cr0 ^ X86_CR0_WP;
11294 +}
11295 +#else
11296 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11297 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11298 +#endif
11299 +
11300 /*
11301 * The following only work if pte_present() is true.
11302 * Undefined behaviour if not..
11303 */
11304 +static inline int pte_user(pte_t pte)
11305 +{
11306 + return pte_val(pte) & _PAGE_USER;
11307 +}
11308 +
11309 static inline int pte_dirty(pte_t pte)
11310 {
11311 return pte_flags(pte) & _PAGE_DIRTY;
11312 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11313 return pte_clear_flags(pte, _PAGE_RW);
11314 }
11315
11316 +static inline pte_t pte_mkread(pte_t pte)
11317 +{
11318 + return __pte(pte_val(pte) | _PAGE_USER);
11319 +}
11320 +
11321 static inline pte_t pte_mkexec(pte_t pte)
11322 {
11323 - return pte_clear_flags(pte, _PAGE_NX);
11324 +#ifdef CONFIG_X86_PAE
11325 + if (__supported_pte_mask & _PAGE_NX)
11326 + return pte_clear_flags(pte, _PAGE_NX);
11327 + else
11328 +#endif
11329 + return pte_set_flags(pte, _PAGE_USER);
11330 +}
11331 +
11332 +static inline pte_t pte_exprotect(pte_t pte)
11333 +{
11334 +#ifdef CONFIG_X86_PAE
11335 + if (__supported_pte_mask & _PAGE_NX)
11336 + return pte_set_flags(pte, _PAGE_NX);
11337 + else
11338 +#endif
11339 + return pte_clear_flags(pte, _PAGE_USER);
11340 }
11341
11342 static inline pte_t pte_mkdirty(pte_t pte)
11343 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11344 #endif
11345
11346 #ifndef __ASSEMBLY__
11347 +
11348 +#ifdef CONFIG_PAX_PER_CPU_PGD
11349 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11350 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11351 +{
11352 + return cpu_pgd[cpu];
11353 +}
11354 +#endif
11355 +
11356 #include <linux/mm_types.h>
11357
11358 static inline int pte_none(pte_t pte)
11359 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11360
11361 static inline int pgd_bad(pgd_t pgd)
11362 {
11363 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11364 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11365 }
11366
11367 static inline int pgd_none(pgd_t pgd)
11368 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11369 * pgd_offset() returns a (pgd_t *)
11370 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11371 */
11372 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11373 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11374 +
11375 +#ifdef CONFIG_PAX_PER_CPU_PGD
11376 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11377 +#endif
11378 +
11379 /*
11380 * a shortcut which implies the use of the kernel's pgd, instead
11381 * of a process's
11382 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11383 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11384 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11385
11386 +#ifdef CONFIG_X86_32
11387 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11388 +#else
11389 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11390 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11391 +
11392 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11393 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11394 +#else
11395 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11396 +#endif
11397 +
11398 +#endif
11399 +
11400 #ifndef __ASSEMBLY__
11401
11402 extern int direct_gbpages;
11403 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11404 * dst and src can be on the same page, but the range must not overlap,
11405 * and must not cross a page boundary.
11406 */
11407 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11408 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11409 {
11410 - memcpy(dst, src, count * sizeof(pgd_t));
11411 + pax_open_kernel();
11412 + while (count--)
11413 + *dst++ = *src++;
11414 + pax_close_kernel();
11415 }
11416
11417 +#ifdef CONFIG_PAX_PER_CPU_PGD
11418 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11419 +#endif
11420 +
11421 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11422 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11423 +#else
11424 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11425 +#endif
11426
11427 #include <asm-generic/pgtable.h>
11428 #endif /* __ASSEMBLY__ */
11429 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11430 index 0c92113..34a77c6 100644
11431 --- a/arch/x86/include/asm/pgtable_32.h
11432 +++ b/arch/x86/include/asm/pgtable_32.h
11433 @@ -25,9 +25,6 @@
11434 struct mm_struct;
11435 struct vm_area_struct;
11436
11437 -extern pgd_t swapper_pg_dir[1024];
11438 -extern pgd_t initial_page_table[1024];
11439 -
11440 static inline void pgtable_cache_init(void) { }
11441 static inline void check_pgt_cache(void) { }
11442 void paging_init(void);
11443 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11444 # include <asm/pgtable-2level.h>
11445 #endif
11446
11447 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11448 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11449 +#ifdef CONFIG_X86_PAE
11450 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11451 +#endif
11452 +
11453 #if defined(CONFIG_HIGHPTE)
11454 #define pte_offset_map(dir, address) \
11455 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11456 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11457 /* Clear a kernel PTE and flush it from the TLB */
11458 #define kpte_clear_flush(ptep, vaddr) \
11459 do { \
11460 + pax_open_kernel(); \
11461 pte_clear(&init_mm, (vaddr), (ptep)); \
11462 + pax_close_kernel(); \
11463 __flush_tlb_one((vaddr)); \
11464 } while (0)
11465
11466 @@ -74,6 +79,9 @@ do { \
11467
11468 #endif /* !__ASSEMBLY__ */
11469
11470 +#define HAVE_ARCH_UNMAPPED_AREA
11471 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11472 +
11473 /*
11474 * kern_addr_valid() is (1) for FLATMEM and (0) for
11475 * SPARSEMEM and DISCONTIGMEM
11476 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11477 index ed5903b..c7fe163 100644
11478 --- a/arch/x86/include/asm/pgtable_32_types.h
11479 +++ b/arch/x86/include/asm/pgtable_32_types.h
11480 @@ -8,7 +8,7 @@
11481 */
11482 #ifdef CONFIG_X86_PAE
11483 # include <asm/pgtable-3level_types.h>
11484 -# define PMD_SIZE (1UL << PMD_SHIFT)
11485 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11486 # define PMD_MASK (~(PMD_SIZE - 1))
11487 #else
11488 # include <asm/pgtable-2level_types.h>
11489 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11490 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11491 #endif
11492
11493 +#ifdef CONFIG_PAX_KERNEXEC
11494 +#ifndef __ASSEMBLY__
11495 +extern unsigned char MODULES_EXEC_VADDR[];
11496 +extern unsigned char MODULES_EXEC_END[];
11497 +#endif
11498 +#include <asm/boot.h>
11499 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11500 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11501 +#else
11502 +#define ktla_ktva(addr) (addr)
11503 +#define ktva_ktla(addr) (addr)
11504 +#endif
11505 +
11506 #define MODULES_VADDR VMALLOC_START
11507 #define MODULES_END VMALLOC_END
11508 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11509 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11510 index 975f709..9f779c9 100644
11511 --- a/arch/x86/include/asm/pgtable_64.h
11512 +++ b/arch/x86/include/asm/pgtable_64.h
11513 @@ -16,10 +16,14 @@
11514
11515 extern pud_t level3_kernel_pgt[512];
11516 extern pud_t level3_ident_pgt[512];
11517 +extern pud_t level3_vmalloc_start_pgt[512];
11518 +extern pud_t level3_vmalloc_end_pgt[512];
11519 +extern pud_t level3_vmemmap_pgt[512];
11520 +extern pud_t level2_vmemmap_pgt[512];
11521 extern pmd_t level2_kernel_pgt[512];
11522 extern pmd_t level2_fixmap_pgt[512];
11523 -extern pmd_t level2_ident_pgt[512];
11524 -extern pgd_t init_level4_pgt[];
11525 +extern pmd_t level2_ident_pgt[512*2];
11526 +extern pgd_t init_level4_pgt[512];
11527
11528 #define swapper_pg_dir init_level4_pgt
11529
11530 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11531
11532 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11533 {
11534 + pax_open_kernel();
11535 *pmdp = pmd;
11536 + pax_close_kernel();
11537 }
11538
11539 static inline void native_pmd_clear(pmd_t *pmd)
11540 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11541
11542 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11543 {
11544 + pax_open_kernel();
11545 *pudp = pud;
11546 + pax_close_kernel();
11547 }
11548
11549 static inline void native_pud_clear(pud_t *pud)
11550 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11551
11552 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11553 {
11554 + pax_open_kernel();
11555 + *pgdp = pgd;
11556 + pax_close_kernel();
11557 +}
11558 +
11559 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11560 +{
11561 *pgdp = pgd;
11562 }
11563
11564 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11565 index 766ea16..5b96cb3 100644
11566 --- a/arch/x86/include/asm/pgtable_64_types.h
11567 +++ b/arch/x86/include/asm/pgtable_64_types.h
11568 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11569 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11570 #define MODULES_END _AC(0xffffffffff000000, UL)
11571 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11572 +#define MODULES_EXEC_VADDR MODULES_VADDR
11573 +#define MODULES_EXEC_END MODULES_END
11574 +
11575 +#define ktla_ktva(addr) (addr)
11576 +#define ktva_ktla(addr) (addr)
11577
11578 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11579 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11580 index 013286a..8b42f4f 100644
11581 --- a/arch/x86/include/asm/pgtable_types.h
11582 +++ b/arch/x86/include/asm/pgtable_types.h
11583 @@ -16,13 +16,12 @@
11584 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11585 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11586 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11587 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11588 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11589 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11590 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11591 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11592 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11593 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11594 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11595 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11596 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11597 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11598
11599 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11600 @@ -40,7 +39,6 @@
11601 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11602 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11603 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11604 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11605 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11606 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11607 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11608 @@ -57,8 +55,10 @@
11609
11610 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11611 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11612 -#else
11613 +#elif defined(CONFIG_KMEMCHECK)
11614 #define _PAGE_NX (_AT(pteval_t, 0))
11615 +#else
11616 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11617 #endif
11618
11619 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11620 @@ -96,6 +96,9 @@
11621 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11622 _PAGE_ACCESSED)
11623
11624 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11625 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11626 +
11627 #define __PAGE_KERNEL_EXEC \
11628 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11629 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11630 @@ -106,7 +109,7 @@
11631 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11632 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11633 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11634 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11635 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11636 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11637 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11638 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11639 @@ -168,8 +171,8 @@
11640 * bits are combined, this will alow user to access the high address mapped
11641 * VDSO in the presence of CONFIG_COMPAT_VDSO
11642 */
11643 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11644 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11645 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11646 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11647 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11648 #endif
11649
11650 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11651 {
11652 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11653 }
11654 +#endif
11655
11656 +#if PAGETABLE_LEVELS == 3
11657 +#include <asm-generic/pgtable-nopud.h>
11658 +#endif
11659 +
11660 +#if PAGETABLE_LEVELS == 2
11661 +#include <asm-generic/pgtable-nopmd.h>
11662 +#endif
11663 +
11664 +#ifndef __ASSEMBLY__
11665 #if PAGETABLE_LEVELS > 3
11666 typedef struct { pudval_t pud; } pud_t;
11667
11668 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11669 return pud.pud;
11670 }
11671 #else
11672 -#include <asm-generic/pgtable-nopud.h>
11673 -
11674 static inline pudval_t native_pud_val(pud_t pud)
11675 {
11676 return native_pgd_val(pud.pgd);
11677 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11678 return pmd.pmd;
11679 }
11680 #else
11681 -#include <asm-generic/pgtable-nopmd.h>
11682 -
11683 static inline pmdval_t native_pmd_val(pmd_t pmd)
11684 {
11685 return native_pgd_val(pmd.pud.pgd);
11686 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11687
11688 extern pteval_t __supported_pte_mask;
11689 extern void set_nx(void);
11690 -extern int nx_enabled;
11691
11692 #define pgprot_writecombine pgprot_writecombine
11693 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11694 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11695 index 58545c9..fe6fc38e 100644
11696 --- a/arch/x86/include/asm/processor.h
11697 +++ b/arch/x86/include/asm/processor.h
11698 @@ -266,7 +266,7 @@ struct tss_struct {
11699
11700 } ____cacheline_aligned;
11701
11702 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11703 +extern struct tss_struct init_tss[NR_CPUS];
11704
11705 /*
11706 * Save the original ist values for checking stack pointers during debugging
11707 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
11708 */
11709 #define TASK_SIZE PAGE_OFFSET
11710 #define TASK_SIZE_MAX TASK_SIZE
11711 +
11712 +#ifdef CONFIG_PAX_SEGMEXEC
11713 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11714 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11715 +#else
11716 #define STACK_TOP TASK_SIZE
11717 -#define STACK_TOP_MAX STACK_TOP
11718 +#endif
11719 +
11720 +#define STACK_TOP_MAX TASK_SIZE
11721
11722 #define INIT_THREAD { \
11723 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11724 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11725 .vm86_info = NULL, \
11726 .sysenter_cs = __KERNEL_CS, \
11727 .io_bitmap_ptr = NULL, \
11728 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
11729 */
11730 #define INIT_TSS { \
11731 .x86_tss = { \
11732 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11733 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11734 .ss0 = __KERNEL_DS, \
11735 .ss1 = __KERNEL_CS, \
11736 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11737 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
11738 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11739
11740 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11741 -#define KSTK_TOP(info) \
11742 -({ \
11743 - unsigned long *__ptr = (unsigned long *)(info); \
11744 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11745 -})
11746 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11747
11748 /*
11749 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11750 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11751 #define task_pt_regs(task) \
11752 ({ \
11753 struct pt_regs *__regs__; \
11754 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11755 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11756 __regs__ - 1; \
11757 })
11758
11759 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11760 /*
11761 * User space process size. 47bits minus one guard page.
11762 */
11763 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11764 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11765
11766 /* This decides where the kernel will search for a free chunk of vm
11767 * space during mmap's.
11768 */
11769 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11770 - 0xc0000000 : 0xFFFFe000)
11771 + 0xc0000000 : 0xFFFFf000)
11772
11773 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
11774 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11775 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11776 #define STACK_TOP_MAX TASK_SIZE_MAX
11777
11778 #define INIT_THREAD { \
11779 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11780 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11781 }
11782
11783 #define INIT_TSS { \
11784 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11785 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11786 }
11787
11788 /*
11789 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11790 */
11791 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11792
11793 +#ifdef CONFIG_PAX_SEGMEXEC
11794 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11795 +#endif
11796 +
11797 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11798
11799 /* Get/set a process' ability to use the timestamp counter instruction */
11800 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11801 index 3566454..4bdfb8c 100644
11802 --- a/arch/x86/include/asm/ptrace.h
11803 +++ b/arch/x86/include/asm/ptrace.h
11804 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11805 }
11806
11807 /*
11808 - * user_mode_vm(regs) determines whether a register set came from user mode.
11809 + * user_mode(regs) determines whether a register set came from user mode.
11810 * This is true if V8086 mode was enabled OR if the register set was from
11811 * protected mode with RPL-3 CS value. This tricky test checks that with
11812 * one comparison. Many places in the kernel can bypass this full check
11813 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11814 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11815 + * be used.
11816 */
11817 -static inline int user_mode(struct pt_regs *regs)
11818 +static inline int user_mode_novm(struct pt_regs *regs)
11819 {
11820 #ifdef CONFIG_X86_32
11821 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11822 #else
11823 - return !!(regs->cs & 3);
11824 + return !!(regs->cs & SEGMENT_RPL_MASK);
11825 #endif
11826 }
11827
11828 -static inline int user_mode_vm(struct pt_regs *regs)
11829 +static inline int user_mode(struct pt_regs *regs)
11830 {
11831 #ifdef CONFIG_X86_32
11832 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11833 USER_RPL;
11834 #else
11835 - return user_mode(regs);
11836 + return user_mode_novm(regs);
11837 #endif
11838 }
11839
11840 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11841 #ifdef CONFIG_X86_64
11842 static inline bool user_64bit_mode(struct pt_regs *regs)
11843 {
11844 + unsigned long cs = regs->cs & 0xffff;
11845 #ifndef CONFIG_PARAVIRT
11846 /*
11847 * On non-paravirt systems, this is the only long mode CPL 3
11848 * selector. We do not allow long mode selectors in the LDT.
11849 */
11850 - return regs->cs == __USER_CS;
11851 + return cs == __USER_CS;
11852 #else
11853 /* Headers are too twisted for this to go in paravirt.h. */
11854 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
11855 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
11856 #endif
11857 }
11858 #endif
11859 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
11860 index 92f29706..a79cbbb 100644
11861 --- a/arch/x86/include/asm/reboot.h
11862 +++ b/arch/x86/include/asm/reboot.h
11863 @@ -6,19 +6,19 @@
11864 struct pt_regs;
11865
11866 struct machine_ops {
11867 - void (*restart)(char *cmd);
11868 - void (*halt)(void);
11869 - void (*power_off)(void);
11870 + void (* __noreturn restart)(char *cmd);
11871 + void (* __noreturn halt)(void);
11872 + void (* __noreturn power_off)(void);
11873 void (*shutdown)(void);
11874 void (*crash_shutdown)(struct pt_regs *);
11875 - void (*emergency_restart)(void);
11876 -};
11877 + void (* __noreturn emergency_restart)(void);
11878 +} __no_const;
11879
11880 extern struct machine_ops machine_ops;
11881
11882 void native_machine_crash_shutdown(struct pt_regs *regs);
11883 void native_machine_shutdown(void);
11884 -void machine_real_restart(unsigned int type);
11885 +void machine_real_restart(unsigned int type) __noreturn;
11886 /* These must match dispatch_table in reboot_32.S */
11887 #define MRR_BIOS 0
11888 #define MRR_APM 1
11889 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
11890 index 2dbe4a7..ce1db00 100644
11891 --- a/arch/x86/include/asm/rwsem.h
11892 +++ b/arch/x86/include/asm/rwsem.h
11893 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
11894 {
11895 asm volatile("# beginning down_read\n\t"
11896 LOCK_PREFIX _ASM_INC "(%1)\n\t"
11897 +
11898 +#ifdef CONFIG_PAX_REFCOUNT
11899 + "jno 0f\n"
11900 + LOCK_PREFIX _ASM_DEC "(%1)\n"
11901 + "int $4\n0:\n"
11902 + _ASM_EXTABLE(0b, 0b)
11903 +#endif
11904 +
11905 /* adds 0x00000001 */
11906 " jns 1f\n"
11907 " call call_rwsem_down_read_failed\n"
11908 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
11909 "1:\n\t"
11910 " mov %1,%2\n\t"
11911 " add %3,%2\n\t"
11912 +
11913 +#ifdef CONFIG_PAX_REFCOUNT
11914 + "jno 0f\n"
11915 + "sub %3,%2\n"
11916 + "int $4\n0:\n"
11917 + _ASM_EXTABLE(0b, 0b)
11918 +#endif
11919 +
11920 " jle 2f\n\t"
11921 LOCK_PREFIX " cmpxchg %2,%0\n\t"
11922 " jnz 1b\n\t"
11923 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
11924 long tmp;
11925 asm volatile("# beginning down_write\n\t"
11926 LOCK_PREFIX " xadd %1,(%2)\n\t"
11927 +
11928 +#ifdef CONFIG_PAX_REFCOUNT
11929 + "jno 0f\n"
11930 + "mov %1,(%2)\n"
11931 + "int $4\n0:\n"
11932 + _ASM_EXTABLE(0b, 0b)
11933 +#endif
11934 +
11935 /* adds 0xffff0001, returns the old value */
11936 " test %1,%1\n\t"
11937 /* was the count 0 before? */
11938 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
11939 long tmp;
11940 asm volatile("# beginning __up_read\n\t"
11941 LOCK_PREFIX " xadd %1,(%2)\n\t"
11942 +
11943 +#ifdef CONFIG_PAX_REFCOUNT
11944 + "jno 0f\n"
11945 + "mov %1,(%2)\n"
11946 + "int $4\n0:\n"
11947 + _ASM_EXTABLE(0b, 0b)
11948 +#endif
11949 +
11950 /* subtracts 1, returns the old value */
11951 " jns 1f\n\t"
11952 " call call_rwsem_wake\n" /* expects old value in %edx */
11953 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
11954 long tmp;
11955 asm volatile("# beginning __up_write\n\t"
11956 LOCK_PREFIX " xadd %1,(%2)\n\t"
11957 +
11958 +#ifdef CONFIG_PAX_REFCOUNT
11959 + "jno 0f\n"
11960 + "mov %1,(%2)\n"
11961 + "int $4\n0:\n"
11962 + _ASM_EXTABLE(0b, 0b)
11963 +#endif
11964 +
11965 /* subtracts 0xffff0001, returns the old value */
11966 " jns 1f\n\t"
11967 " call call_rwsem_wake\n" /* expects old value in %edx */
11968 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11969 {
11970 asm volatile("# beginning __downgrade_write\n\t"
11971 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
11972 +
11973 +#ifdef CONFIG_PAX_REFCOUNT
11974 + "jno 0f\n"
11975 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
11976 + "int $4\n0:\n"
11977 + _ASM_EXTABLE(0b, 0b)
11978 +#endif
11979 +
11980 /*
11981 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
11982 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
11983 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
11984 */
11985 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
11986 {
11987 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
11988 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
11989 +
11990 +#ifdef CONFIG_PAX_REFCOUNT
11991 + "jno 0f\n"
11992 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
11993 + "int $4\n0:\n"
11994 + _ASM_EXTABLE(0b, 0b)
11995 +#endif
11996 +
11997 : "+m" (sem->count)
11998 : "er" (delta));
11999 }
12000 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12001 */
12002 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12003 {
12004 - return delta + xadd(&sem->count, delta);
12005 + return delta + xadd_check_overflow(&sem->count, delta);
12006 }
12007
12008 #endif /* __KERNEL__ */
12009 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12010 index 5e64171..f58957e 100644
12011 --- a/arch/x86/include/asm/segment.h
12012 +++ b/arch/x86/include/asm/segment.h
12013 @@ -64,10 +64,15 @@
12014 * 26 - ESPFIX small SS
12015 * 27 - per-cpu [ offset to per-cpu data area ]
12016 * 28 - stack_canary-20 [ for stack protector ]
12017 - * 29 - unused
12018 - * 30 - unused
12019 + * 29 - PCI BIOS CS
12020 + * 30 - PCI BIOS DS
12021 * 31 - TSS for double fault handler
12022 */
12023 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12024 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12025 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12026 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12027 +
12028 #define GDT_ENTRY_TLS_MIN 6
12029 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12030
12031 @@ -79,6 +84,8 @@
12032
12033 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12034
12035 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12036 +
12037 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12038
12039 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12040 @@ -104,6 +111,12 @@
12041 #define __KERNEL_STACK_CANARY 0
12042 #endif
12043
12044 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12045 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12046 +
12047 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12048 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12049 +
12050 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12051
12052 /*
12053 @@ -141,7 +154,7 @@
12054 */
12055
12056 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12057 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12058 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12059
12060
12061 #else
12062 @@ -165,6 +178,8 @@
12063 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12064 #define __USER32_DS __USER_DS
12065
12066 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12067 +
12068 #define GDT_ENTRY_TSS 8 /* needs two entries */
12069 #define GDT_ENTRY_LDT 10 /* needs two entries */
12070 #define GDT_ENTRY_TLS_MIN 12
12071 @@ -185,6 +200,7 @@
12072 #endif
12073
12074 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12075 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12076 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12077 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12078 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12079 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12080 index 0434c40..1714bf0 100644
12081 --- a/arch/x86/include/asm/smp.h
12082 +++ b/arch/x86/include/asm/smp.h
12083 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12084 /* cpus sharing the last level cache: */
12085 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12086 DECLARE_PER_CPU(u16, cpu_llc_id);
12087 -DECLARE_PER_CPU(int, cpu_number);
12088 +DECLARE_PER_CPU(unsigned int, cpu_number);
12089
12090 static inline struct cpumask *cpu_sibling_mask(int cpu)
12091 {
12092 @@ -77,7 +77,7 @@ struct smp_ops {
12093
12094 void (*send_call_func_ipi)(const struct cpumask *mask);
12095 void (*send_call_func_single_ipi)(int cpu);
12096 -};
12097 +} __no_const;
12098
12099 /* Globals due to paravirt */
12100 extern void set_cpu_sibling_map(int cpu);
12101 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12102 extern int safe_smp_processor_id(void);
12103
12104 #elif defined(CONFIG_X86_64_SMP)
12105 -#define raw_smp_processor_id() (percpu_read(cpu_number))
12106 -
12107 -#define stack_smp_processor_id() \
12108 -({ \
12109 - struct thread_info *ti; \
12110 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12111 - ti->cpu; \
12112 -})
12113 +#define raw_smp_processor_id() (percpu_read(cpu_number))
12114 +#define stack_smp_processor_id() raw_smp_processor_id()
12115 #define safe_smp_processor_id() smp_processor_id()
12116
12117 #endif
12118 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12119 index a82c2bf..2198f61 100644
12120 --- a/arch/x86/include/asm/spinlock.h
12121 +++ b/arch/x86/include/asm/spinlock.h
12122 @@ -175,6 +175,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12123 static inline void arch_read_lock(arch_rwlock_t *rw)
12124 {
12125 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12126 +
12127 +#ifdef CONFIG_PAX_REFCOUNT
12128 + "jno 0f\n"
12129 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12130 + "int $4\n0:\n"
12131 + _ASM_EXTABLE(0b, 0b)
12132 +#endif
12133 +
12134 "jns 1f\n"
12135 "call __read_lock_failed\n\t"
12136 "1:\n"
12137 @@ -184,6 +192,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12138 static inline void arch_write_lock(arch_rwlock_t *rw)
12139 {
12140 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12141 +
12142 +#ifdef CONFIG_PAX_REFCOUNT
12143 + "jno 0f\n"
12144 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12145 + "int $4\n0:\n"
12146 + _ASM_EXTABLE(0b, 0b)
12147 +#endif
12148 +
12149 "jz 1f\n"
12150 "call __write_lock_failed\n\t"
12151 "1:\n"
12152 @@ -213,13 +229,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12153
12154 static inline void arch_read_unlock(arch_rwlock_t *rw)
12155 {
12156 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12157 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12158 +
12159 +#ifdef CONFIG_PAX_REFCOUNT
12160 + "jno 0f\n"
12161 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12162 + "int $4\n0:\n"
12163 + _ASM_EXTABLE(0b, 0b)
12164 +#endif
12165 +
12166 :"+m" (rw->lock) : : "memory");
12167 }
12168
12169 static inline void arch_write_unlock(arch_rwlock_t *rw)
12170 {
12171 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12172 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12173 +
12174 +#ifdef CONFIG_PAX_REFCOUNT
12175 + "jno 0f\n"
12176 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12177 + "int $4\n0:\n"
12178 + _ASM_EXTABLE(0b, 0b)
12179 +#endif
12180 +
12181 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12182 }
12183
12184 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12185 index 1575177..cb23f52 100644
12186 --- a/arch/x86/include/asm/stackprotector.h
12187 +++ b/arch/x86/include/asm/stackprotector.h
12188 @@ -48,7 +48,7 @@
12189 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12190 */
12191 #define GDT_STACK_CANARY_INIT \
12192 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12193 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12194
12195 /*
12196 * Initialize the stackprotector canary value.
12197 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
12198
12199 static inline void load_stack_canary_segment(void)
12200 {
12201 -#ifdef CONFIG_X86_32
12202 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12203 asm volatile ("mov %0, %%gs" : : "r" (0));
12204 #endif
12205 }
12206 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12207 index 70bbe39..4ae2bd4 100644
12208 --- a/arch/x86/include/asm/stacktrace.h
12209 +++ b/arch/x86/include/asm/stacktrace.h
12210 @@ -11,28 +11,20 @@
12211
12212 extern int kstack_depth_to_print;
12213
12214 -struct thread_info;
12215 +struct task_struct;
12216 struct stacktrace_ops;
12217
12218 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12219 - unsigned long *stack,
12220 - unsigned long bp,
12221 - const struct stacktrace_ops *ops,
12222 - void *data,
12223 - unsigned long *end,
12224 - int *graph);
12225 +typedef unsigned long walk_stack_t(struct task_struct *task,
12226 + void *stack_start,
12227 + unsigned long *stack,
12228 + unsigned long bp,
12229 + const struct stacktrace_ops *ops,
12230 + void *data,
12231 + unsigned long *end,
12232 + int *graph);
12233
12234 -extern unsigned long
12235 -print_context_stack(struct thread_info *tinfo,
12236 - unsigned long *stack, unsigned long bp,
12237 - const struct stacktrace_ops *ops, void *data,
12238 - unsigned long *end, int *graph);
12239 -
12240 -extern unsigned long
12241 -print_context_stack_bp(struct thread_info *tinfo,
12242 - unsigned long *stack, unsigned long bp,
12243 - const struct stacktrace_ops *ops, void *data,
12244 - unsigned long *end, int *graph);
12245 +extern walk_stack_t print_context_stack;
12246 +extern walk_stack_t print_context_stack_bp;
12247
12248 /* Generic stack tracer with callbacks */
12249
12250 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12251 void (*address)(void *data, unsigned long address, int reliable);
12252 /* On negative return stop dumping */
12253 int (*stack)(void *data, char *name);
12254 - walk_stack_t walk_stack;
12255 + walk_stack_t *walk_stack;
12256 };
12257
12258 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12259 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12260 index cb23852..2dde194 100644
12261 --- a/arch/x86/include/asm/sys_ia32.h
12262 +++ b/arch/x86/include/asm/sys_ia32.h
12263 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
12264 compat_sigset_t __user *, unsigned int);
12265 asmlinkage long sys32_alarm(unsigned int);
12266
12267 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12268 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12269 asmlinkage long sys32_sysfs(int, u32, u32);
12270
12271 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12272 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
12273 index 2d2f01c..f985723 100644
12274 --- a/arch/x86/include/asm/system.h
12275 +++ b/arch/x86/include/asm/system.h
12276 @@ -129,7 +129,7 @@ do { \
12277 "call __switch_to\n\t" \
12278 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12279 __switch_canary \
12280 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12281 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12282 "movq %%rax,%%rdi\n\t" \
12283 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12284 "jnz ret_from_fork\n\t" \
12285 @@ -140,7 +140,7 @@ do { \
12286 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12287 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12288 [_tif_fork] "i" (_TIF_FORK), \
12289 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12290 + [thread_info] "m" (current_tinfo), \
12291 [current_task] "m" (current_task) \
12292 __switch_canary_iparam \
12293 : "memory", "cc" __EXTRA_CLOBBER)
12294 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
12295 {
12296 unsigned long __limit;
12297 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12298 - return __limit + 1;
12299 + return __limit;
12300 }
12301
12302 static inline void native_clts(void)
12303 @@ -397,13 +397,13 @@ void enable_hlt(void);
12304
12305 void cpu_idle_wait(void);
12306
12307 -extern unsigned long arch_align_stack(unsigned long sp);
12308 +#define arch_align_stack(x) ((x) & ~0xfUL)
12309 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
12310
12311 void default_idle(void);
12312 bool set_pm_idle_to_default(void);
12313
12314 -void stop_this_cpu(void *dummy);
12315 +void stop_this_cpu(void *dummy) __noreturn;
12316
12317 /*
12318 * Force strict CPU ordering.
12319 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12320 index cfd8144..664ac89 100644
12321 --- a/arch/x86/include/asm/thread_info.h
12322 +++ b/arch/x86/include/asm/thread_info.h
12323 @@ -10,6 +10,7 @@
12324 #include <linux/compiler.h>
12325 #include <asm/page.h>
12326 #include <asm/types.h>
12327 +#include <asm/percpu.h>
12328
12329 /*
12330 * low level task data that entry.S needs immediate access to
12331 @@ -24,7 +25,6 @@ struct exec_domain;
12332 #include <linux/atomic.h>
12333
12334 struct thread_info {
12335 - struct task_struct *task; /* main task structure */
12336 struct exec_domain *exec_domain; /* execution domain */
12337 __u32 flags; /* low level flags */
12338 __u32 status; /* thread synchronous flags */
12339 @@ -34,19 +34,13 @@ struct thread_info {
12340 mm_segment_t addr_limit;
12341 struct restart_block restart_block;
12342 void __user *sysenter_return;
12343 -#ifdef CONFIG_X86_32
12344 - unsigned long previous_esp; /* ESP of the previous stack in
12345 - case of nested (IRQ) stacks
12346 - */
12347 - __u8 supervisor_stack[0];
12348 -#endif
12349 + unsigned long lowest_stack;
12350 unsigned int sig_on_uaccess_error:1;
12351 unsigned int uaccess_err:1; /* uaccess failed */
12352 };
12353
12354 -#define INIT_THREAD_INFO(tsk) \
12355 +#define INIT_THREAD_INFO \
12356 { \
12357 - .task = &tsk, \
12358 .exec_domain = &default_exec_domain, \
12359 .flags = 0, \
12360 .cpu = 0, \
12361 @@ -57,7 +51,7 @@ struct thread_info {
12362 }, \
12363 }
12364
12365 -#define init_thread_info (init_thread_union.thread_info)
12366 +#define init_thread_info (init_thread_union.stack)
12367 #define init_stack (init_thread_union.stack)
12368
12369 #else /* !__ASSEMBLY__ */
12370 @@ -95,6 +89,7 @@ struct thread_info {
12371 #define TIF_BLOCKSTEP 25 /* set when we want DEBUGCTLMSR_BTF */
12372 #define TIF_LAZY_MMU_UPDATES 27 /* task is updating the mmu lazily */
12373 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12374 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
12375
12376 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12377 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12378 @@ -116,16 +111,17 @@ struct thread_info {
12379 #define _TIF_BLOCKSTEP (1 << TIF_BLOCKSTEP)
12380 #define _TIF_LAZY_MMU_UPDATES (1 << TIF_LAZY_MMU_UPDATES)
12381 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12382 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12383
12384 /* work to do in syscall_trace_enter() */
12385 #define _TIF_WORK_SYSCALL_ENTRY \
12386 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12387 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12388 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12389
12390 /* work to do in syscall_trace_leave() */
12391 #define _TIF_WORK_SYSCALL_EXIT \
12392 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12393 - _TIF_SYSCALL_TRACEPOINT)
12394 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12395
12396 /* work to do on interrupt/exception return */
12397 #define _TIF_WORK_MASK \
12398 @@ -135,7 +131,8 @@ struct thread_info {
12399
12400 /* work to do on any return to user space */
12401 #define _TIF_ALLWORK_MASK \
12402 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12403 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12404 + _TIF_GRSEC_SETXID)
12405
12406 /* Only used for 64 bit */
12407 #define _TIF_DO_NOTIFY_MASK \
12408 @@ -169,45 +166,40 @@ struct thread_info {
12409 ret; \
12410 })
12411
12412 -#ifdef CONFIG_X86_32
12413 -
12414 -#define STACK_WARN (THREAD_SIZE/8)
12415 -/*
12416 - * macros/functions for gaining access to the thread information structure
12417 - *
12418 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12419 - */
12420 -#ifndef __ASSEMBLY__
12421 -
12422 -
12423 -/* how to get the current stack pointer from C */
12424 -register unsigned long current_stack_pointer asm("esp") __used;
12425 -
12426 -/* how to get the thread information struct from C */
12427 -static inline struct thread_info *current_thread_info(void)
12428 -{
12429 - return (struct thread_info *)
12430 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12431 -}
12432 -
12433 -#else /* !__ASSEMBLY__ */
12434 -
12435 +#ifdef __ASSEMBLY__
12436 /* how to get the thread information struct from ASM */
12437 #define GET_THREAD_INFO(reg) \
12438 - movl $-THREAD_SIZE, reg; \
12439 - andl %esp, reg
12440 + mov PER_CPU_VAR(current_tinfo), reg
12441
12442 /* use this one if reg already contains %esp */
12443 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12444 - andl $-THREAD_SIZE, reg
12445 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12446 +#else
12447 +/* how to get the thread information struct from C */
12448 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12449 +
12450 +static __always_inline struct thread_info *current_thread_info(void)
12451 +{
12452 + return percpu_read_stable(current_tinfo);
12453 +}
12454 +#endif
12455 +
12456 +#ifdef CONFIG_X86_32
12457 +
12458 +#define STACK_WARN (THREAD_SIZE/8)
12459 +/*
12460 + * macros/functions for gaining access to the thread information structure
12461 + *
12462 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12463 + */
12464 +#ifndef __ASSEMBLY__
12465 +
12466 +/* how to get the current stack pointer from C */
12467 +register unsigned long current_stack_pointer asm("esp") __used;
12468
12469 #endif
12470
12471 #else /* X86_32 */
12472
12473 -#include <asm/percpu.h>
12474 -#define KERNEL_STACK_OFFSET (5*8)
12475 -
12476 /*
12477 * macros/functions for gaining access to the thread information structure
12478 * preempt_count needs to be 1 initially, until the scheduler is functional.
12479 @@ -215,27 +207,8 @@ static inline struct thread_info *current_thread_info(void)
12480 #ifndef __ASSEMBLY__
12481 DECLARE_PER_CPU(unsigned long, kernel_stack);
12482
12483 -static inline struct thread_info *current_thread_info(void)
12484 -{
12485 - struct thread_info *ti;
12486 - ti = (void *)(percpu_read_stable(kernel_stack) +
12487 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12488 - return ti;
12489 -}
12490 -
12491 -#else /* !__ASSEMBLY__ */
12492 -
12493 -/* how to get the thread information struct from ASM */
12494 -#define GET_THREAD_INFO(reg) \
12495 - movq PER_CPU_VAR(kernel_stack),reg ; \
12496 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12497 -
12498 -/*
12499 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12500 - * a certain register (to be used in assembler memory operands).
12501 - */
12502 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12503 -
12504 +/* how to get the current stack pointer from C */
12505 +register unsigned long current_stack_pointer asm("rsp") __used;
12506 #endif
12507
12508 #endif /* !X86_32 */
12509 @@ -269,5 +242,16 @@ extern void arch_task_cache_init(void);
12510 extern void free_thread_info(struct thread_info *ti);
12511 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12512 #define arch_task_cache_init arch_task_cache_init
12513 +
12514 +#define __HAVE_THREAD_FUNCTIONS
12515 +#define task_thread_info(task) (&(task)->tinfo)
12516 +#define task_stack_page(task) ((task)->stack)
12517 +#define setup_thread_stack(p, org) do {} while (0)
12518 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12519 +
12520 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
12521 +extern struct task_struct *alloc_task_struct_node(int node);
12522 +extern void free_task_struct(struct task_struct *);
12523 +
12524 #endif
12525 #endif /* _ASM_X86_THREAD_INFO_H */
12526 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12527 index 8be5f54..7ae826d 100644
12528 --- a/arch/x86/include/asm/uaccess.h
12529 +++ b/arch/x86/include/asm/uaccess.h
12530 @@ -7,12 +7,15 @@
12531 #include <linux/compiler.h>
12532 #include <linux/thread_info.h>
12533 #include <linux/string.h>
12534 +#include <linux/sched.h>
12535 #include <asm/asm.h>
12536 #include <asm/page.h>
12537
12538 #define VERIFY_READ 0
12539 #define VERIFY_WRITE 1
12540
12541 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12542 +
12543 /*
12544 * The fs value determines whether argument validity checking should be
12545 * performed or not. If get_fs() == USER_DS, checking is performed, with
12546 @@ -28,7 +31,12 @@
12547
12548 #define get_ds() (KERNEL_DS)
12549 #define get_fs() (current_thread_info()->addr_limit)
12550 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12551 +void __set_fs(mm_segment_t x);
12552 +void set_fs(mm_segment_t x);
12553 +#else
12554 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12555 +#endif
12556
12557 #define segment_eq(a, b) ((a).seg == (b).seg)
12558
12559 @@ -76,7 +84,33 @@
12560 * checks that the pointer is in the user space range - after calling
12561 * this function, memory access functions may still return -EFAULT.
12562 */
12563 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12564 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
12565 +#define access_ok(type, addr, size) \
12566 +({ \
12567 + long __size = size; \
12568 + unsigned long __addr = (unsigned long)addr; \
12569 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12570 + unsigned long __end_ao = __addr + __size - 1; \
12571 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
12572 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12573 + while(__addr_ao <= __end_ao) { \
12574 + char __c_ao; \
12575 + __addr_ao += PAGE_SIZE; \
12576 + if (__size > PAGE_SIZE) \
12577 + cond_resched(); \
12578 + if (__get_user(__c_ao, (char __user *)__addr)) \
12579 + break; \
12580 + if (type != VERIFY_WRITE) { \
12581 + __addr = __addr_ao; \
12582 + continue; \
12583 + } \
12584 + if (__put_user(__c_ao, (char __user *)__addr)) \
12585 + break; \
12586 + __addr = __addr_ao; \
12587 + } \
12588 + } \
12589 + __ret_ao; \
12590 +})
12591
12592 /*
12593 * The exception table consists of pairs of addresses: the first is the
12594 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
12595 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12596 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12597
12598 -
12599 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12600 +#define __copyuser_seg "gs;"
12601 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12602 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12603 +#else
12604 +#define __copyuser_seg
12605 +#define __COPYUSER_SET_ES
12606 +#define __COPYUSER_RESTORE_ES
12607 +#endif
12608
12609 #ifdef CONFIG_X86_32
12610 #define __put_user_asm_u64(x, addr, err, errret) \
12611 - asm volatile("1: movl %%eax,0(%2)\n" \
12612 - "2: movl %%edx,4(%2)\n" \
12613 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12614 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12615 "3:\n" \
12616 ".section .fixup,\"ax\"\n" \
12617 "4: movl %3,%0\n" \
12618 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
12619 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12620
12621 #define __put_user_asm_ex_u64(x, addr) \
12622 - asm volatile("1: movl %%eax,0(%1)\n" \
12623 - "2: movl %%edx,4(%1)\n" \
12624 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12625 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12626 "3:\n" \
12627 _ASM_EXTABLE(1b, 2b - 1b) \
12628 _ASM_EXTABLE(2b, 3b - 2b) \
12629 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
12630 __typeof__(*(ptr)) __pu_val; \
12631 __chk_user_ptr(ptr); \
12632 might_fault(); \
12633 - __pu_val = x; \
12634 + __pu_val = (x); \
12635 switch (sizeof(*(ptr))) { \
12636 case 1: \
12637 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12638 @@ -373,7 +415,7 @@ do { \
12639 } while (0)
12640
12641 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12642 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12643 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12644 "2:\n" \
12645 ".section .fixup,\"ax\"\n" \
12646 "3: mov %3,%0\n" \
12647 @@ -381,7 +423,7 @@ do { \
12648 " jmp 2b\n" \
12649 ".previous\n" \
12650 _ASM_EXTABLE(1b, 3b) \
12651 - : "=r" (err), ltype(x) \
12652 + : "=r" (err), ltype (x) \
12653 : "m" (__m(addr)), "i" (errret), "0" (err))
12654
12655 #define __get_user_size_ex(x, ptr, size) \
12656 @@ -406,7 +448,7 @@ do { \
12657 } while (0)
12658
12659 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12660 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12661 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12662 "2:\n" \
12663 _ASM_EXTABLE(1b, 2b - 1b) \
12664 : ltype(x) : "m" (__m(addr)))
12665 @@ -423,13 +465,24 @@ do { \
12666 int __gu_err; \
12667 unsigned long __gu_val; \
12668 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12669 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12670 + (x) = (__typeof__(*(ptr)))__gu_val; \
12671 __gu_err; \
12672 })
12673
12674 /* FIXME: this hack is definitely wrong -AK */
12675 struct __large_struct { unsigned long buf[100]; };
12676 -#define __m(x) (*(struct __large_struct __user *)(x))
12677 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12678 +#define ____m(x) \
12679 +({ \
12680 + unsigned long ____x = (unsigned long)(x); \
12681 + if (____x < PAX_USER_SHADOW_BASE) \
12682 + ____x += PAX_USER_SHADOW_BASE; \
12683 + (void __user *)____x; \
12684 +})
12685 +#else
12686 +#define ____m(x) (x)
12687 +#endif
12688 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12689
12690 /*
12691 * Tell gcc we read from memory instead of writing: this is because
12692 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
12693 * aliasing issues.
12694 */
12695 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12696 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12697 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12698 "2:\n" \
12699 ".section .fixup,\"ax\"\n" \
12700 "3: mov %3,%0\n" \
12701 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
12702 ".previous\n" \
12703 _ASM_EXTABLE(1b, 3b) \
12704 : "=r"(err) \
12705 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12706 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12707
12708 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12709 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12710 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12711 "2:\n" \
12712 _ASM_EXTABLE(1b, 2b - 1b) \
12713 : : ltype(x), "m" (__m(addr)))
12714 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
12715 * On error, the variable @x is set to zero.
12716 */
12717
12718 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12719 +#define __get_user(x, ptr) get_user((x), (ptr))
12720 +#else
12721 #define __get_user(x, ptr) \
12722 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12723 +#endif
12724
12725 /**
12726 * __put_user: - Write a simple value into user space, with less checking.
12727 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
12728 * Returns zero on success, or -EFAULT on error.
12729 */
12730
12731 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12732 +#define __put_user(x, ptr) put_user((x), (ptr))
12733 +#else
12734 #define __put_user(x, ptr) \
12735 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12736 +#endif
12737
12738 #define __get_user_unaligned __get_user
12739 #define __put_user_unaligned __put_user
12740 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
12741 #define get_user_ex(x, ptr) do { \
12742 unsigned long __gue_val; \
12743 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12744 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12745 + (x) = (__typeof__(*(ptr)))__gue_val; \
12746 } while (0)
12747
12748 #ifdef CONFIG_X86_WP_WORKS_OK
12749 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12750 index 566e803..1230707 100644
12751 --- a/arch/x86/include/asm/uaccess_32.h
12752 +++ b/arch/x86/include/asm/uaccess_32.h
12753 @@ -11,15 +11,15 @@
12754 #include <asm/page.h>
12755
12756 unsigned long __must_check __copy_to_user_ll
12757 - (void __user *to, const void *from, unsigned long n);
12758 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12759 unsigned long __must_check __copy_from_user_ll
12760 - (void *to, const void __user *from, unsigned long n);
12761 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12762 unsigned long __must_check __copy_from_user_ll_nozero
12763 - (void *to, const void __user *from, unsigned long n);
12764 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12765 unsigned long __must_check __copy_from_user_ll_nocache
12766 - (void *to, const void __user *from, unsigned long n);
12767 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12768 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12769 - (void *to, const void __user *from, unsigned long n);
12770 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12771
12772 /**
12773 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12774 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12775 static __always_inline unsigned long __must_check
12776 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12777 {
12778 + if ((long)n < 0)
12779 + return n;
12780 +
12781 if (__builtin_constant_p(n)) {
12782 unsigned long ret;
12783
12784 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12785 return ret;
12786 }
12787 }
12788 + if (!__builtin_constant_p(n))
12789 + check_object_size(from, n, true);
12790 return __copy_to_user_ll(to, from, n);
12791 }
12792
12793 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12794 __copy_to_user(void __user *to, const void *from, unsigned long n)
12795 {
12796 might_fault();
12797 +
12798 return __copy_to_user_inatomic(to, from, n);
12799 }
12800
12801 static __always_inline unsigned long
12802 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12803 {
12804 + if ((long)n < 0)
12805 + return n;
12806 +
12807 /* Avoid zeroing the tail if the copy fails..
12808 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12809 * but as the zeroing behaviour is only significant when n is not
12810 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12811 __copy_from_user(void *to, const void __user *from, unsigned long n)
12812 {
12813 might_fault();
12814 +
12815 + if ((long)n < 0)
12816 + return n;
12817 +
12818 if (__builtin_constant_p(n)) {
12819 unsigned long ret;
12820
12821 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12822 return ret;
12823 }
12824 }
12825 + if (!__builtin_constant_p(n))
12826 + check_object_size(to, n, false);
12827 return __copy_from_user_ll(to, from, n);
12828 }
12829
12830 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12831 const void __user *from, unsigned long n)
12832 {
12833 might_fault();
12834 +
12835 + if ((long)n < 0)
12836 + return n;
12837 +
12838 if (__builtin_constant_p(n)) {
12839 unsigned long ret;
12840
12841 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12842 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12843 unsigned long n)
12844 {
12845 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12846 + if ((long)n < 0)
12847 + return n;
12848 +
12849 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12850 }
12851
12852 -unsigned long __must_check copy_to_user(void __user *to,
12853 - const void *from, unsigned long n);
12854 -unsigned long __must_check _copy_from_user(void *to,
12855 - const void __user *from,
12856 - unsigned long n);
12857 -
12858 +extern void copy_to_user_overflow(void)
12859 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12860 + __compiletime_error("copy_to_user() buffer size is not provably correct")
12861 +#else
12862 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
12863 +#endif
12864 +;
12865
12866 extern void copy_from_user_overflow(void)
12867 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
12868 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
12869 #endif
12870 ;
12871
12872 -static inline unsigned long __must_check copy_from_user(void *to,
12873 - const void __user *from,
12874 - unsigned long n)
12875 +/**
12876 + * copy_to_user: - Copy a block of data into user space.
12877 + * @to: Destination address, in user space.
12878 + * @from: Source address, in kernel space.
12879 + * @n: Number of bytes to copy.
12880 + *
12881 + * Context: User context only. This function may sleep.
12882 + *
12883 + * Copy data from kernel space to user space.
12884 + *
12885 + * Returns number of bytes that could not be copied.
12886 + * On success, this will be zero.
12887 + */
12888 +static inline unsigned long __must_check
12889 +copy_to_user(void __user *to, const void *from, unsigned long n)
12890 +{
12891 + int sz = __compiletime_object_size(from);
12892 +
12893 + if (unlikely(sz != -1 && sz < n))
12894 + copy_to_user_overflow();
12895 + else if (access_ok(VERIFY_WRITE, to, n))
12896 + n = __copy_to_user(to, from, n);
12897 + return n;
12898 +}
12899 +
12900 +/**
12901 + * copy_from_user: - Copy a block of data from user space.
12902 + * @to: Destination address, in kernel space.
12903 + * @from: Source address, in user space.
12904 + * @n: Number of bytes to copy.
12905 + *
12906 + * Context: User context only. This function may sleep.
12907 + *
12908 + * Copy data from user space to kernel space.
12909 + *
12910 + * Returns number of bytes that could not be copied.
12911 + * On success, this will be zero.
12912 + *
12913 + * If some data could not be copied, this function will pad the copied
12914 + * data to the requested size using zero bytes.
12915 + */
12916 +static inline unsigned long __must_check
12917 +copy_from_user(void *to, const void __user *from, unsigned long n)
12918 {
12919 int sz = __compiletime_object_size(to);
12920
12921 - if (likely(sz == -1 || sz >= n))
12922 - n = _copy_from_user(to, from, n);
12923 - else
12924 + if (unlikely(sz != -1 && sz < n))
12925 copy_from_user_overflow();
12926 -
12927 + else if (access_ok(VERIFY_READ, from, n))
12928 + n = __copy_from_user(to, from, n);
12929 + else if ((long)n > 0) {
12930 + if (!__builtin_constant_p(n))
12931 + check_object_size(to, n, false);
12932 + memset(to, 0, n);
12933 + }
12934 return n;
12935 }
12936
12937 @@ -235,7 +302,7 @@ long __must_check __strncpy_from_user(char *dst,
12938 #define strlen_user(str) strnlen_user(str, LONG_MAX)
12939
12940 long strnlen_user(const char __user *str, long n);
12941 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
12942 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
12943 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12944 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
12945
12946 #endif /* _ASM_X86_UACCESS_32_H */
12947 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
12948 index 1c66d30..bf1a2cc 100644
12949 --- a/arch/x86/include/asm/uaccess_64.h
12950 +++ b/arch/x86/include/asm/uaccess_64.h
12951 @@ -10,6 +10,9 @@
12952 #include <asm/alternative.h>
12953 #include <asm/cpufeature.h>
12954 #include <asm/page.h>
12955 +#include <asm/pgtable.h>
12956 +
12957 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
12958
12959 /*
12960 * Copy To/From Userspace
12961 @@ -17,12 +20,14 @@
12962
12963 /* Handles exceptions in both to and from, but doesn't do access_ok */
12964 __must_check unsigned long
12965 -copy_user_generic_string(void *to, const void *from, unsigned len);
12966 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
12967 __must_check unsigned long
12968 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
12969 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
12970
12971 static __always_inline __must_check unsigned long
12972 -copy_user_generic(void *to, const void *from, unsigned len)
12973 +copy_user_generic(void *to, const void *from, unsigned long len) __size_overflow(3);
12974 +static __always_inline __must_check unsigned long
12975 +copy_user_generic(void *to, const void *from, unsigned long len)
12976 {
12977 unsigned ret;
12978
12979 @@ -32,142 +37,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
12980 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
12981 "=d" (len)),
12982 "1" (to), "2" (from), "3" (len)
12983 - : "memory", "rcx", "r8", "r9", "r10", "r11");
12984 + : "memory", "rcx", "r8", "r9", "r11");
12985 return ret;
12986 }
12987
12988 +static __always_inline __must_check unsigned long
12989 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
12990 +static __always_inline __must_check unsigned long
12991 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
12992 __must_check unsigned long
12993 -_copy_to_user(void __user *to, const void *from, unsigned len);
12994 -__must_check unsigned long
12995 -_copy_from_user(void *to, const void __user *from, unsigned len);
12996 -__must_check unsigned long
12997 -copy_in_user(void __user *to, const void __user *from, unsigned len);
12998 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
12999
13000 static inline unsigned long __must_check copy_from_user(void *to,
13001 const void __user *from,
13002 unsigned long n)
13003 {
13004 - int sz = __compiletime_object_size(to);
13005 -
13006 might_fault();
13007 - if (likely(sz == -1 || sz >= n))
13008 - n = _copy_from_user(to, from, n);
13009 -#ifdef CONFIG_DEBUG_VM
13010 - else
13011 - WARN(1, "Buffer overflow detected!\n");
13012 -#endif
13013 +
13014 + if (access_ok(VERIFY_READ, from, n))
13015 + n = __copy_from_user(to, from, n);
13016 + else if (n < INT_MAX) {
13017 + if (!__builtin_constant_p(n))
13018 + check_object_size(to, n, false);
13019 + memset(to, 0, n);
13020 + }
13021 return n;
13022 }
13023
13024 static __always_inline __must_check
13025 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13026 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13027 {
13028 might_fault();
13029
13030 - return _copy_to_user(dst, src, size);
13031 + if (access_ok(VERIFY_WRITE, dst, size))
13032 + size = __copy_to_user(dst, src, size);
13033 + return size;
13034 }
13035
13036 static __always_inline __must_check
13037 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13038 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13039 {
13040 - int ret = 0;
13041 + int sz = __compiletime_object_size(dst);
13042 + unsigned ret = 0;
13043
13044 might_fault();
13045 - if (!__builtin_constant_p(size))
13046 - return copy_user_generic(dst, (__force void *)src, size);
13047 +
13048 + if (size > INT_MAX)
13049 + return size;
13050 +
13051 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13052 + if (!__access_ok(VERIFY_READ, src, size))
13053 + return size;
13054 +#endif
13055 +
13056 + if (unlikely(sz != -1 && sz < size)) {
13057 +#ifdef CONFIG_DEBUG_VM
13058 + WARN(1, "Buffer overflow detected!\n");
13059 +#endif
13060 + return size;
13061 + }
13062 +
13063 + if (!__builtin_constant_p(size)) {
13064 + check_object_size(dst, size, false);
13065 +
13066 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13067 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13068 + src += PAX_USER_SHADOW_BASE;
13069 +#endif
13070 +
13071 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13072 + }
13073 switch (size) {
13074 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13075 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13076 ret, "b", "b", "=q", 1);
13077 return ret;
13078 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13079 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13080 ret, "w", "w", "=r", 2);
13081 return ret;
13082 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13083 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13084 ret, "l", "k", "=r", 4);
13085 return ret;
13086 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13087 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13088 ret, "q", "", "=r", 8);
13089 return ret;
13090 case 10:
13091 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13092 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13093 ret, "q", "", "=r", 10);
13094 if (unlikely(ret))
13095 return ret;
13096 __get_user_asm(*(u16 *)(8 + (char *)dst),
13097 - (u16 __user *)(8 + (char __user *)src),
13098 + (const u16 __user *)(8 + (const char __user *)src),
13099 ret, "w", "w", "=r", 2);
13100 return ret;
13101 case 16:
13102 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13103 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13104 ret, "q", "", "=r", 16);
13105 if (unlikely(ret))
13106 return ret;
13107 __get_user_asm(*(u64 *)(8 + (char *)dst),
13108 - (u64 __user *)(8 + (char __user *)src),
13109 + (const u64 __user *)(8 + (const char __user *)src),
13110 ret, "q", "", "=r", 8);
13111 return ret;
13112 default:
13113 - return copy_user_generic(dst, (__force void *)src, size);
13114 +
13115 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13116 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13117 + src += PAX_USER_SHADOW_BASE;
13118 +#endif
13119 +
13120 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13121 }
13122 }
13123
13124 static __always_inline __must_check
13125 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13126 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13127 {
13128 - int ret = 0;
13129 + int sz = __compiletime_object_size(src);
13130 + unsigned ret = 0;
13131
13132 might_fault();
13133 - if (!__builtin_constant_p(size))
13134 - return copy_user_generic((__force void *)dst, src, size);
13135 +
13136 + if (size > INT_MAX)
13137 + return size;
13138 +
13139 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13140 + if (!__access_ok(VERIFY_WRITE, dst, size))
13141 + return size;
13142 +#endif
13143 +
13144 + if (unlikely(sz != -1 && sz < size)) {
13145 +#ifdef CONFIG_DEBUG_VM
13146 + WARN(1, "Buffer overflow detected!\n");
13147 +#endif
13148 + return size;
13149 + }
13150 +
13151 + if (!__builtin_constant_p(size)) {
13152 + check_object_size(src, size, true);
13153 +
13154 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13155 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13156 + dst += PAX_USER_SHADOW_BASE;
13157 +#endif
13158 +
13159 + return copy_user_generic((__force_kernel void *)dst, src, size);
13160 + }
13161 switch (size) {
13162 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13163 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13164 ret, "b", "b", "iq", 1);
13165 return ret;
13166 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13167 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13168 ret, "w", "w", "ir", 2);
13169 return ret;
13170 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13171 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13172 ret, "l", "k", "ir", 4);
13173 return ret;
13174 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13175 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13176 ret, "q", "", "er", 8);
13177 return ret;
13178 case 10:
13179 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13180 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13181 ret, "q", "", "er", 10);
13182 if (unlikely(ret))
13183 return ret;
13184 asm("":::"memory");
13185 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13186 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13187 ret, "w", "w", "ir", 2);
13188 return ret;
13189 case 16:
13190 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13191 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13192 ret, "q", "", "er", 16);
13193 if (unlikely(ret))
13194 return ret;
13195 asm("":::"memory");
13196 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13197 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13198 ret, "q", "", "er", 8);
13199 return ret;
13200 default:
13201 - return copy_user_generic((__force void *)dst, src, size);
13202 +
13203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13204 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13205 + dst += PAX_USER_SHADOW_BASE;
13206 +#endif
13207 +
13208 + return copy_user_generic((__force_kernel void *)dst, src, size);
13209 }
13210 }
13211
13212 static __always_inline __must_check
13213 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13214 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13215 {
13216 - int ret = 0;
13217 + unsigned ret = 0;
13218
13219 might_fault();
13220 - if (!__builtin_constant_p(size))
13221 - return copy_user_generic((__force void *)dst,
13222 - (__force void *)src, size);
13223 +
13224 + if (size > INT_MAX)
13225 + return size;
13226 +
13227 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13228 + if (!__access_ok(VERIFY_READ, src, size))
13229 + return size;
13230 + if (!__access_ok(VERIFY_WRITE, dst, size))
13231 + return size;
13232 +#endif
13233 +
13234 + if (!__builtin_constant_p(size)) {
13235 +
13236 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13237 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13238 + src += PAX_USER_SHADOW_BASE;
13239 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13240 + dst += PAX_USER_SHADOW_BASE;
13241 +#endif
13242 +
13243 + return copy_user_generic((__force_kernel void *)dst,
13244 + (__force_kernel const void *)src, size);
13245 + }
13246 switch (size) {
13247 case 1: {
13248 u8 tmp;
13249 - __get_user_asm(tmp, (u8 __user *)src,
13250 + __get_user_asm(tmp, (const u8 __user *)src,
13251 ret, "b", "b", "=q", 1);
13252 if (likely(!ret))
13253 __put_user_asm(tmp, (u8 __user *)dst,
13254 @@ -176,7 +265,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13255 }
13256 case 2: {
13257 u16 tmp;
13258 - __get_user_asm(tmp, (u16 __user *)src,
13259 + __get_user_asm(tmp, (const u16 __user *)src,
13260 ret, "w", "w", "=r", 2);
13261 if (likely(!ret))
13262 __put_user_asm(tmp, (u16 __user *)dst,
13263 @@ -186,7 +275,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13264
13265 case 4: {
13266 u32 tmp;
13267 - __get_user_asm(tmp, (u32 __user *)src,
13268 + __get_user_asm(tmp, (const u32 __user *)src,
13269 ret, "l", "k", "=r", 4);
13270 if (likely(!ret))
13271 __put_user_asm(tmp, (u32 __user *)dst,
13272 @@ -195,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13273 }
13274 case 8: {
13275 u64 tmp;
13276 - __get_user_asm(tmp, (u64 __user *)src,
13277 + __get_user_asm(tmp, (const u64 __user *)src,
13278 ret, "q", "", "=r", 8);
13279 if (likely(!ret))
13280 __put_user_asm(tmp, (u64 __user *)dst,
13281 @@ -203,8 +292,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13282 return ret;
13283 }
13284 default:
13285 - return copy_user_generic((__force void *)dst,
13286 - (__force void *)src, size);
13287 +
13288 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13289 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13290 + src += PAX_USER_SHADOW_BASE;
13291 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13292 + dst += PAX_USER_SHADOW_BASE;
13293 +#endif
13294 +
13295 + return copy_user_generic((__force_kernel void *)dst,
13296 + (__force_kernel const void *)src, size);
13297 }
13298 }
13299
13300 @@ -215,39 +312,76 @@ __strncpy_from_user(char *dst, const char __user *src, long count);
13301 __must_check long strnlen_user(const char __user *str, long n);
13302 __must_check long __strnlen_user(const char __user *str, long n);
13303 __must_check long strlen_user(const char __user *str);
13304 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13305 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13306 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13307 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13308
13309 static __must_check __always_inline int
13310 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13311 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13312 {
13313 - return copy_user_generic(dst, (__force const void *)src, size);
13314 + if (size > INT_MAX)
13315 + return size;
13316 +
13317 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13318 + if (!__access_ok(VERIFY_READ, src, size))
13319 + return size;
13320 +
13321 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13322 + src += PAX_USER_SHADOW_BASE;
13323 +#endif
13324 +
13325 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13326 }
13327
13328 -static __must_check __always_inline int
13329 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13330 +static __must_check __always_inline unsigned long
13331 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13332 {
13333 - return copy_user_generic((__force void *)dst, src, size);
13334 + if (size > INT_MAX)
13335 + return size;
13336 +
13337 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13338 + if (!__access_ok(VERIFY_WRITE, dst, size))
13339 + return size;
13340 +
13341 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13342 + dst += PAX_USER_SHADOW_BASE;
13343 +#endif
13344 +
13345 + return copy_user_generic((__force_kernel void *)dst, src, size);
13346 }
13347
13348 -extern long __copy_user_nocache(void *dst, const void __user *src,
13349 - unsigned size, int zerorest);
13350 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13351 + unsigned long size, int zerorest) __size_overflow(3);
13352
13353 -static inline int
13354 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13355 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13356 {
13357 might_sleep();
13358 +
13359 + if (size > INT_MAX)
13360 + return size;
13361 +
13362 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13363 + if (!__access_ok(VERIFY_READ, src, size))
13364 + return size;
13365 +#endif
13366 +
13367 return __copy_user_nocache(dst, src, size, 1);
13368 }
13369
13370 -static inline int
13371 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13372 - unsigned size)
13373 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13374 + unsigned long size)
13375 {
13376 + if (size > INT_MAX)
13377 + return size;
13378 +
13379 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13380 + if (!__access_ok(VERIFY_READ, src, size))
13381 + return size;
13382 +#endif
13383 +
13384 return __copy_user_nocache(dst, src, size, 0);
13385 }
13386
13387 -unsigned long
13388 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13389 +extern unsigned long
13390 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13391
13392 #endif /* _ASM_X86_UACCESS_64_H */
13393 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13394 index bb05228..d763d5b 100644
13395 --- a/arch/x86/include/asm/vdso.h
13396 +++ b/arch/x86/include/asm/vdso.h
13397 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13398 #define VDSO32_SYMBOL(base, name) \
13399 ({ \
13400 extern const char VDSO32_##name[]; \
13401 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13402 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13403 })
13404 #endif
13405
13406 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13407 index a609c39..7a68dc7 100644
13408 --- a/arch/x86/include/asm/x86_init.h
13409 +++ b/arch/x86/include/asm/x86_init.h
13410 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13411 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13412 void (*find_smp_config)(void);
13413 void (*get_smp_config)(unsigned int early);
13414 -};
13415 +} __no_const;
13416
13417 /**
13418 * struct x86_init_resources - platform specific resource related ops
13419 @@ -43,7 +43,7 @@ struct x86_init_resources {
13420 void (*probe_roms)(void);
13421 void (*reserve_resources)(void);
13422 char *(*memory_setup)(void);
13423 -};
13424 +} __no_const;
13425
13426 /**
13427 * struct x86_init_irqs - platform specific interrupt setup
13428 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13429 void (*pre_vector_init)(void);
13430 void (*intr_init)(void);
13431 void (*trap_init)(void);
13432 -};
13433 +} __no_const;
13434
13435 /**
13436 * struct x86_init_oem - oem platform specific customizing functions
13437 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13438 struct x86_init_oem {
13439 void (*arch_setup)(void);
13440 void (*banner)(void);
13441 -};
13442 +} __no_const;
13443
13444 /**
13445 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13446 @@ -77,7 +77,7 @@ struct x86_init_oem {
13447 */
13448 struct x86_init_mapping {
13449 void (*pagetable_reserve)(u64 start, u64 end);
13450 -};
13451 +} __no_const;
13452
13453 /**
13454 * struct x86_init_paging - platform specific paging functions
13455 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13456 struct x86_init_paging {
13457 void (*pagetable_setup_start)(pgd_t *base);
13458 void (*pagetable_setup_done)(pgd_t *base);
13459 -};
13460 +} __no_const;
13461
13462 /**
13463 * struct x86_init_timers - platform specific timer setup
13464 @@ -102,7 +102,7 @@ struct x86_init_timers {
13465 void (*tsc_pre_init)(void);
13466 void (*timer_init)(void);
13467 void (*wallclock_init)(void);
13468 -};
13469 +} __no_const;
13470
13471 /**
13472 * struct x86_init_iommu - platform specific iommu setup
13473 @@ -110,7 +110,7 @@ struct x86_init_timers {
13474 */
13475 struct x86_init_iommu {
13476 int (*iommu_init)(void);
13477 -};
13478 +} __no_const;
13479
13480 /**
13481 * struct x86_init_pci - platform specific pci init functions
13482 @@ -124,7 +124,7 @@ struct x86_init_pci {
13483 int (*init)(void);
13484 void (*init_irq)(void);
13485 void (*fixup_irqs)(void);
13486 -};
13487 +} __no_const;
13488
13489 /**
13490 * struct x86_init_ops - functions for platform specific setup
13491 @@ -140,7 +140,7 @@ struct x86_init_ops {
13492 struct x86_init_timers timers;
13493 struct x86_init_iommu iommu;
13494 struct x86_init_pci pci;
13495 -};
13496 +} __no_const;
13497
13498 /**
13499 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13500 @@ -149,7 +149,7 @@ struct x86_init_ops {
13501 struct x86_cpuinit_ops {
13502 void (*setup_percpu_clockev)(void);
13503 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13504 -};
13505 +} __no_const;
13506
13507 /**
13508 * struct x86_platform_ops - platform specific runtime functions
13509 @@ -171,7 +171,7 @@ struct x86_platform_ops {
13510 void (*nmi_init)(void);
13511 unsigned char (*get_nmi_reason)(void);
13512 int (*i8042_detect)(void);
13513 -};
13514 +} __no_const;
13515
13516 struct pci_dev;
13517
13518 @@ -180,7 +180,7 @@ struct x86_msi_ops {
13519 void (*teardown_msi_irq)(unsigned int irq);
13520 void (*teardown_msi_irqs)(struct pci_dev *dev);
13521 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13522 -};
13523 +} __no_const;
13524
13525 extern struct x86_init_ops x86_init;
13526 extern struct x86_cpuinit_ops x86_cpuinit;
13527 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13528 index c6ce245..ffbdab7 100644
13529 --- a/arch/x86/include/asm/xsave.h
13530 +++ b/arch/x86/include/asm/xsave.h
13531 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13532 {
13533 int err;
13534
13535 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13536 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13537 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13538 +#endif
13539 +
13540 /*
13541 * Clear the xsave header first, so that reserved fields are
13542 * initialized to zero.
13543 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13544 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13545 {
13546 int err;
13547 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13548 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13549 u32 lmask = mask;
13550 u32 hmask = mask >> 32;
13551
13552 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13553 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13554 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13555 +#endif
13556 +
13557 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13558 "2:\n"
13559 ".section .fixup,\"ax\"\n"
13560 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
13561 index 6a564ac..9b1340c 100644
13562 --- a/arch/x86/kernel/acpi/realmode/Makefile
13563 +++ b/arch/x86/kernel/acpi/realmode/Makefile
13564 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
13565 $(call cc-option, -fno-stack-protector) \
13566 $(call cc-option, -mpreferred-stack-boundary=2)
13567 KBUILD_CFLAGS += $(call cc-option, -m32)
13568 +ifdef CONSTIFY_PLUGIN
13569 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
13570 +endif
13571 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13572 GCOV_PROFILE := n
13573
13574 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
13575 index b4fd836..4358fe3 100644
13576 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
13577 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
13578 @@ -108,6 +108,9 @@ wakeup_code:
13579 /* Do any other stuff... */
13580
13581 #ifndef CONFIG_64BIT
13582 + /* Recheck NX bit overrides (64bit path does this in trampoline */
13583 + call verify_cpu
13584 +
13585 /* This could also be done in C code... */
13586 movl pmode_cr3, %eax
13587 movl %eax, %cr3
13588 @@ -131,6 +134,7 @@ wakeup_code:
13589 movl pmode_cr0, %eax
13590 movl %eax, %cr0
13591 jmp pmode_return
13592 +# include "../../verify_cpu.S"
13593 #else
13594 pushw $0
13595 pushw trampoline_segment
13596 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13597 index 103b6ab..2004d0a 100644
13598 --- a/arch/x86/kernel/acpi/sleep.c
13599 +++ b/arch/x86/kernel/acpi/sleep.c
13600 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
13601 header->trampoline_segment = trampoline_address() >> 4;
13602 #ifdef CONFIG_SMP
13603 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13604 +
13605 + pax_open_kernel();
13606 early_gdt_descr.address =
13607 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13608 + pax_close_kernel();
13609 +
13610 initial_gs = per_cpu_offset(smp_processor_id());
13611 #endif
13612 initial_code = (unsigned long)wakeup_long64;
13613 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13614 index 13ab720..95d5442 100644
13615 --- a/arch/x86/kernel/acpi/wakeup_32.S
13616 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13617 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13618 # and restore the stack ... but you need gdt for this to work
13619 movl saved_context_esp, %esp
13620
13621 - movl %cs:saved_magic, %eax
13622 - cmpl $0x12345678, %eax
13623 + cmpl $0x12345678, saved_magic
13624 jne bogus_magic
13625
13626 # jump to place where we left off
13627 - movl saved_eip, %eax
13628 - jmp *%eax
13629 + jmp *(saved_eip)
13630
13631 bogus_magic:
13632 jmp bogus_magic
13633 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13634 index 1f84794..e23f862 100644
13635 --- a/arch/x86/kernel/alternative.c
13636 +++ b/arch/x86/kernel/alternative.c
13637 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13638 */
13639 for (a = start; a < end; a++) {
13640 instr = (u8 *)&a->instr_offset + a->instr_offset;
13641 +
13642 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13643 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13644 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13645 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13646 +#endif
13647 +
13648 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13649 BUG_ON(a->replacementlen > a->instrlen);
13650 BUG_ON(a->instrlen > sizeof(insnbuf));
13651 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13652 for (poff = start; poff < end; poff++) {
13653 u8 *ptr = (u8 *)poff + *poff;
13654
13655 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13656 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13657 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13658 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13659 +#endif
13660 +
13661 if (!*poff || ptr < text || ptr >= text_end)
13662 continue;
13663 /* turn DS segment override prefix into lock prefix */
13664 - if (*ptr == 0x3e)
13665 + if (*ktla_ktva(ptr) == 0x3e)
13666 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13667 };
13668 mutex_unlock(&text_mutex);
13669 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13670 for (poff = start; poff < end; poff++) {
13671 u8 *ptr = (u8 *)poff + *poff;
13672
13673 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13674 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13675 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13676 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13677 +#endif
13678 +
13679 if (!*poff || ptr < text || ptr >= text_end)
13680 continue;
13681 /* turn lock prefix into DS segment override prefix */
13682 - if (*ptr == 0xf0)
13683 + if (*ktla_ktva(ptr) == 0xf0)
13684 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13685 };
13686 mutex_unlock(&text_mutex);
13687 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13688
13689 BUG_ON(p->len > MAX_PATCH_LEN);
13690 /* prep the buffer with the original instructions */
13691 - memcpy(insnbuf, p->instr, p->len);
13692 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13693 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13694 (unsigned long)p->instr, p->len);
13695
13696 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13697 if (smp_alt_once)
13698 free_init_pages("SMP alternatives",
13699 (unsigned long)__smp_locks,
13700 - (unsigned long)__smp_locks_end);
13701 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13702
13703 restart_nmi();
13704 }
13705 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13706 * instructions. And on the local CPU you need to be protected again NMI or MCE
13707 * handlers seeing an inconsistent instruction while you patch.
13708 */
13709 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13710 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13711 size_t len)
13712 {
13713 unsigned long flags;
13714 local_irq_save(flags);
13715 - memcpy(addr, opcode, len);
13716 +
13717 + pax_open_kernel();
13718 + memcpy(ktla_ktva(addr), opcode, len);
13719 sync_core();
13720 + pax_close_kernel();
13721 +
13722 local_irq_restore(flags);
13723 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13724 that causes hangs on some VIA CPUs. */
13725 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13726 */
13727 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13728 {
13729 - unsigned long flags;
13730 - char *vaddr;
13731 + unsigned char *vaddr = ktla_ktva(addr);
13732 struct page *pages[2];
13733 - int i;
13734 + size_t i;
13735
13736 if (!core_kernel_text((unsigned long)addr)) {
13737 - pages[0] = vmalloc_to_page(addr);
13738 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13739 + pages[0] = vmalloc_to_page(vaddr);
13740 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13741 } else {
13742 - pages[0] = virt_to_page(addr);
13743 + pages[0] = virt_to_page(vaddr);
13744 WARN_ON(!PageReserved(pages[0]));
13745 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13746 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13747 }
13748 BUG_ON(!pages[0]);
13749 - local_irq_save(flags);
13750 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13751 - if (pages[1])
13752 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13753 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13754 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13755 - clear_fixmap(FIX_TEXT_POKE0);
13756 - if (pages[1])
13757 - clear_fixmap(FIX_TEXT_POKE1);
13758 - local_flush_tlb();
13759 - sync_core();
13760 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13761 - that causes hangs on some VIA CPUs. */
13762 + text_poke_early(addr, opcode, len);
13763 for (i = 0; i < len; i++)
13764 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13765 - local_irq_restore(flags);
13766 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13767 return addr;
13768 }
13769
13770 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13771 index 5b3f88e..61232b4 100644
13772 --- a/arch/x86/kernel/apic/apic.c
13773 +++ b/arch/x86/kernel/apic/apic.c
13774 @@ -184,7 +184,7 @@ int first_system_vector = 0xfe;
13775 /*
13776 * Debug level, exported for io_apic.c
13777 */
13778 -unsigned int apic_verbosity;
13779 +int apic_verbosity;
13780
13781 int pic_mode;
13782
13783 @@ -1912,7 +1912,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13784 apic_write(APIC_ESR, 0);
13785 v1 = apic_read(APIC_ESR);
13786 ack_APIC_irq();
13787 - atomic_inc(&irq_err_count);
13788 + atomic_inc_unchecked(&irq_err_count);
13789
13790 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13791 smp_processor_id(), v0 , v1);
13792 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13793 index fb07275..e06bb59 100644
13794 --- a/arch/x86/kernel/apic/io_apic.c
13795 +++ b/arch/x86/kernel/apic/io_apic.c
13796 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13797 }
13798 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13799
13800 -void lock_vector_lock(void)
13801 +void lock_vector_lock(void) __acquires(vector_lock)
13802 {
13803 /* Used to the online set of cpus does not change
13804 * during assign_irq_vector.
13805 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
13806 raw_spin_lock(&vector_lock);
13807 }
13808
13809 -void unlock_vector_lock(void)
13810 +void unlock_vector_lock(void) __releases(vector_lock)
13811 {
13812 raw_spin_unlock(&vector_lock);
13813 }
13814 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
13815 ack_APIC_irq();
13816 }
13817
13818 -atomic_t irq_mis_count;
13819 +atomic_unchecked_t irq_mis_count;
13820
13821 static void ack_apic_level(struct irq_data *data)
13822 {
13823 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
13824 * at the cpu.
13825 */
13826 if (!(v & (1 << (i & 0x1f)))) {
13827 - atomic_inc(&irq_mis_count);
13828 + atomic_inc_unchecked(&irq_mis_count);
13829
13830 eoi_ioapic_irq(irq, cfg);
13831 }
13832 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13833 index f76623c..aab694f 100644
13834 --- a/arch/x86/kernel/apm_32.c
13835 +++ b/arch/x86/kernel/apm_32.c
13836 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
13837 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13838 * even though they are called in protected mode.
13839 */
13840 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13841 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13842 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13843
13844 static const char driver_version[] = "1.16ac"; /* no spaces */
13845 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
13846 BUG_ON(cpu != 0);
13847 gdt = get_cpu_gdt_table(cpu);
13848 save_desc_40 = gdt[0x40 / 8];
13849 +
13850 + pax_open_kernel();
13851 gdt[0x40 / 8] = bad_bios_desc;
13852 + pax_close_kernel();
13853
13854 apm_irq_save(flags);
13855 APM_DO_SAVE_SEGS;
13856 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
13857 &call->esi);
13858 APM_DO_RESTORE_SEGS;
13859 apm_irq_restore(flags);
13860 +
13861 + pax_open_kernel();
13862 gdt[0x40 / 8] = save_desc_40;
13863 + pax_close_kernel();
13864 +
13865 put_cpu();
13866
13867 return call->eax & 0xff;
13868 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
13869 BUG_ON(cpu != 0);
13870 gdt = get_cpu_gdt_table(cpu);
13871 save_desc_40 = gdt[0x40 / 8];
13872 +
13873 + pax_open_kernel();
13874 gdt[0x40 / 8] = bad_bios_desc;
13875 + pax_close_kernel();
13876
13877 apm_irq_save(flags);
13878 APM_DO_SAVE_SEGS;
13879 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
13880 &call->eax);
13881 APM_DO_RESTORE_SEGS;
13882 apm_irq_restore(flags);
13883 +
13884 + pax_open_kernel();
13885 gdt[0x40 / 8] = save_desc_40;
13886 + pax_close_kernel();
13887 +
13888 put_cpu();
13889 return error;
13890 }
13891 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
13892 * code to that CPU.
13893 */
13894 gdt = get_cpu_gdt_table(0);
13895 +
13896 + pax_open_kernel();
13897 set_desc_base(&gdt[APM_CS >> 3],
13898 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
13899 set_desc_base(&gdt[APM_CS_16 >> 3],
13900 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
13901 set_desc_base(&gdt[APM_DS >> 3],
13902 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
13903 + pax_close_kernel();
13904
13905 proc_create("apm", 0, NULL, &apm_file_ops);
13906
13907 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
13908 index 68de2dc..1f3c720 100644
13909 --- a/arch/x86/kernel/asm-offsets.c
13910 +++ b/arch/x86/kernel/asm-offsets.c
13911 @@ -33,6 +33,8 @@ void common(void) {
13912 OFFSET(TI_status, thread_info, status);
13913 OFFSET(TI_addr_limit, thread_info, addr_limit);
13914 OFFSET(TI_preempt_count, thread_info, preempt_count);
13915 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
13916 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
13917
13918 BLANK();
13919 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
13920 @@ -53,8 +55,26 @@ void common(void) {
13921 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
13922 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
13923 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
13924 +
13925 +#ifdef CONFIG_PAX_KERNEXEC
13926 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
13927 #endif
13928
13929 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13930 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
13931 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
13932 +#ifdef CONFIG_X86_64
13933 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
13934 +#endif
13935 +#endif
13936 +
13937 +#endif
13938 +
13939 + BLANK();
13940 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
13941 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
13942 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
13943 +
13944 #ifdef CONFIG_XEN
13945 BLANK();
13946 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
13947 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
13948 index 834e897..dacddc8 100644
13949 --- a/arch/x86/kernel/asm-offsets_64.c
13950 +++ b/arch/x86/kernel/asm-offsets_64.c
13951 @@ -70,6 +70,7 @@ int main(void)
13952 BLANK();
13953 #undef ENTRY
13954
13955 + DEFINE(TSS_size, sizeof(struct tss_struct));
13956 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
13957 BLANK();
13958
13959 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
13960 index 25f24dc..4094a7f 100644
13961 --- a/arch/x86/kernel/cpu/Makefile
13962 +++ b/arch/x86/kernel/cpu/Makefile
13963 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
13964 CFLAGS_REMOVE_perf_event.o = -pg
13965 endif
13966
13967 -# Make sure load_percpu_segment has no stackprotector
13968 -nostackp := $(call cc-option, -fno-stack-protector)
13969 -CFLAGS_common.o := $(nostackp)
13970 -
13971 obj-y := intel_cacheinfo.o scattered.o topology.o
13972 obj-y += proc.o capflags.o powerflags.o common.o
13973 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
13974 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
13975 index 80ab83d..0a7b34e 100644
13976 --- a/arch/x86/kernel/cpu/amd.c
13977 +++ b/arch/x86/kernel/cpu/amd.c
13978 @@ -670,7 +670,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
13979 unsigned int size)
13980 {
13981 /* AMD errata T13 (order #21922) */
13982 - if ((c->x86 == 6)) {
13983 + if (c->x86 == 6) {
13984 /* Duron Rev A0 */
13985 if (c->x86_model == 3 && c->x86_mask == 0)
13986 size = 64;
13987 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
13988 index 1a810e4..9fa8201 100644
13989 --- a/arch/x86/kernel/cpu/common.c
13990 +++ b/arch/x86/kernel/cpu/common.c
13991 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
13992
13993 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
13994
13995 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
13996 -#ifdef CONFIG_X86_64
13997 - /*
13998 - * We need valid kernel segments for data and code in long mode too
13999 - * IRET will check the segment types kkeil 2000/10/28
14000 - * Also sysret mandates a special GDT layout
14001 - *
14002 - * TLS descriptors are currently at a different place compared to i386.
14003 - * Hopefully nobody expects them at a fixed place (Wine?)
14004 - */
14005 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14006 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14007 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14008 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14009 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14010 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14011 -#else
14012 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14013 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14014 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14015 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14016 - /*
14017 - * Segments used for calling PnP BIOS have byte granularity.
14018 - * They code segments and data segments have fixed 64k limits,
14019 - * the transfer segment sizes are set at run time.
14020 - */
14021 - /* 32-bit code */
14022 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14023 - /* 16-bit code */
14024 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14025 - /* 16-bit data */
14026 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14027 - /* 16-bit data */
14028 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14029 - /* 16-bit data */
14030 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14031 - /*
14032 - * The APM segments have byte granularity and their bases
14033 - * are set at run time. All have 64k limits.
14034 - */
14035 - /* 32-bit code */
14036 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14037 - /* 16-bit code */
14038 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14039 - /* data */
14040 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14041 -
14042 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14043 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14044 - GDT_STACK_CANARY_INIT
14045 -#endif
14046 -} };
14047 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14048 -
14049 static int __init x86_xsave_setup(char *s)
14050 {
14051 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14052 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
14053 {
14054 struct desc_ptr gdt_descr;
14055
14056 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14057 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14058 gdt_descr.size = GDT_SIZE - 1;
14059 load_gdt(&gdt_descr);
14060 /* Reload the per-cpu base */
14061 @@ -839,6 +785,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14062 /* Filter out anything that depends on CPUID levels we don't have */
14063 filter_cpuid_features(c, true);
14064
14065 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14066 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14067 +#endif
14068 +
14069 /* If the model name is still unset, do table lookup. */
14070 if (!c->x86_model_id[0]) {
14071 const char *p;
14072 @@ -1019,10 +969,12 @@ static __init int setup_disablecpuid(char *arg)
14073 }
14074 __setup("clearcpuid=", setup_disablecpuid);
14075
14076 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14077 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14078 +
14079 #ifdef CONFIG_X86_64
14080 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14081 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14082 - (unsigned long) nmi_idt_table };
14083 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14084
14085 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14086 irq_stack_union) __aligned(PAGE_SIZE);
14087 @@ -1036,7 +988,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14088 EXPORT_PER_CPU_SYMBOL(current_task);
14089
14090 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14091 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14092 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14093 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14094
14095 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14096 @@ -1126,7 +1078,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14097 {
14098 memset(regs, 0, sizeof(struct pt_regs));
14099 regs->fs = __KERNEL_PERCPU;
14100 - regs->gs = __KERNEL_STACK_CANARY;
14101 + savesegment(gs, regs->gs);
14102
14103 return regs;
14104 }
14105 @@ -1181,7 +1133,7 @@ void __cpuinit cpu_init(void)
14106 int i;
14107
14108 cpu = stack_smp_processor_id();
14109 - t = &per_cpu(init_tss, cpu);
14110 + t = init_tss + cpu;
14111 oist = &per_cpu(orig_ist, cpu);
14112
14113 #ifdef CONFIG_NUMA
14114 @@ -1207,7 +1159,7 @@ void __cpuinit cpu_init(void)
14115 switch_to_new_gdt(cpu);
14116 loadsegment(fs, 0);
14117
14118 - load_idt((const struct desc_ptr *)&idt_descr);
14119 + load_idt(&idt_descr);
14120
14121 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14122 syscall_init();
14123 @@ -1216,7 +1168,6 @@ void __cpuinit cpu_init(void)
14124 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14125 barrier();
14126
14127 - x86_configure_nx();
14128 if (cpu != 0)
14129 enable_x2apic();
14130
14131 @@ -1272,7 +1223,7 @@ void __cpuinit cpu_init(void)
14132 {
14133 int cpu = smp_processor_id();
14134 struct task_struct *curr = current;
14135 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14136 + struct tss_struct *t = init_tss + cpu;
14137 struct thread_struct *thread = &curr->thread;
14138
14139 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14140 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14141 index 3e6ff6c..54b4992 100644
14142 --- a/arch/x86/kernel/cpu/intel.c
14143 +++ b/arch/x86/kernel/cpu/intel.c
14144 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14145 * Update the IDT descriptor and reload the IDT so that
14146 * it uses the read-only mapped virtual address.
14147 */
14148 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14149 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14150 load_idt(&idt_descr);
14151 }
14152 #endif
14153 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14154 index dee004f..327a57e 100644
14155 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14156 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14157 @@ -42,6 +42,7 @@
14158 #include <asm/processor.h>
14159 #include <asm/mce.h>
14160 #include <asm/msr.h>
14161 +#include <asm/local.h>
14162
14163 #include "mce-internal.h"
14164
14165 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14166 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14167 m->cs, m->ip);
14168
14169 - if (m->cs == __KERNEL_CS)
14170 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14171 print_symbol("{%s}", m->ip);
14172 pr_cont("\n");
14173 }
14174 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14175
14176 #define PANIC_TIMEOUT 5 /* 5 seconds */
14177
14178 -static atomic_t mce_paniced;
14179 +static atomic_unchecked_t mce_paniced;
14180
14181 static int fake_panic;
14182 -static atomic_t mce_fake_paniced;
14183 +static atomic_unchecked_t mce_fake_paniced;
14184
14185 /* Panic in progress. Enable interrupts and wait for final IPI */
14186 static void wait_for_panic(void)
14187 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14188 /*
14189 * Make sure only one CPU runs in machine check panic
14190 */
14191 - if (atomic_inc_return(&mce_paniced) > 1)
14192 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14193 wait_for_panic();
14194 barrier();
14195
14196 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14197 console_verbose();
14198 } else {
14199 /* Don't log too much for fake panic */
14200 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14201 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14202 return;
14203 }
14204 /* First print corrected ones that are still unlogged */
14205 @@ -666,7 +667,7 @@ static int mce_timed_out(u64 *t)
14206 * might have been modified by someone else.
14207 */
14208 rmb();
14209 - if (atomic_read(&mce_paniced))
14210 + if (atomic_read_unchecked(&mce_paniced))
14211 wait_for_panic();
14212 if (!monarch_timeout)
14213 goto out;
14214 @@ -1454,7 +1455,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14215 }
14216
14217 /* Call the installed machine check handler for this CPU setup. */
14218 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14219 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14220 unexpected_machine_check;
14221
14222 /*
14223 @@ -1477,7 +1478,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14224 return;
14225 }
14226
14227 + pax_open_kernel();
14228 machine_check_vector = do_machine_check;
14229 + pax_close_kernel();
14230
14231 __mcheck_cpu_init_generic();
14232 __mcheck_cpu_init_vendor(c);
14233 @@ -1491,7 +1494,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14234 */
14235
14236 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14237 -static int mce_chrdev_open_count; /* #times opened */
14238 +static local_t mce_chrdev_open_count; /* #times opened */
14239 static int mce_chrdev_open_exclu; /* already open exclusive? */
14240
14241 static int mce_chrdev_open(struct inode *inode, struct file *file)
14242 @@ -1499,7 +1502,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14243 spin_lock(&mce_chrdev_state_lock);
14244
14245 if (mce_chrdev_open_exclu ||
14246 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14247 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14248 spin_unlock(&mce_chrdev_state_lock);
14249
14250 return -EBUSY;
14251 @@ -1507,7 +1510,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14252
14253 if (file->f_flags & O_EXCL)
14254 mce_chrdev_open_exclu = 1;
14255 - mce_chrdev_open_count++;
14256 + local_inc(&mce_chrdev_open_count);
14257
14258 spin_unlock(&mce_chrdev_state_lock);
14259
14260 @@ -1518,7 +1521,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14261 {
14262 spin_lock(&mce_chrdev_state_lock);
14263
14264 - mce_chrdev_open_count--;
14265 + local_dec(&mce_chrdev_open_count);
14266 mce_chrdev_open_exclu = 0;
14267
14268 spin_unlock(&mce_chrdev_state_lock);
14269 @@ -2237,7 +2240,7 @@ struct dentry *mce_get_debugfs_dir(void)
14270 static void mce_reset(void)
14271 {
14272 cpu_missing = 0;
14273 - atomic_set(&mce_fake_paniced, 0);
14274 + atomic_set_unchecked(&mce_fake_paniced, 0);
14275 atomic_set(&mce_executing, 0);
14276 atomic_set(&mce_callin, 0);
14277 atomic_set(&global_nwo, 0);
14278 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14279 index 5c0e653..0882b0a 100644
14280 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14281 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14282 @@ -12,6 +12,7 @@
14283 #include <asm/system.h>
14284 #include <asm/mce.h>
14285 #include <asm/msr.h>
14286 +#include <asm/pgtable.h>
14287
14288 /* By default disabled */
14289 int mce_p5_enabled __read_mostly;
14290 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14291 if (!cpu_has(c, X86_FEATURE_MCE))
14292 return;
14293
14294 + pax_open_kernel();
14295 machine_check_vector = pentium_machine_check;
14296 + pax_close_kernel();
14297 /* Make sure the vector pointer is visible before we enable MCEs: */
14298 wmb();
14299
14300 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14301 index 54060f5..c1a7577 100644
14302 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14303 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14304 @@ -11,6 +11,7 @@
14305 #include <asm/system.h>
14306 #include <asm/mce.h>
14307 #include <asm/msr.h>
14308 +#include <asm/pgtable.h>
14309
14310 /* Machine check handler for WinChip C6: */
14311 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14312 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14313 {
14314 u32 lo, hi;
14315
14316 + pax_open_kernel();
14317 machine_check_vector = winchip_machine_check;
14318 + pax_close_kernel();
14319 /* Make sure the vector pointer is visible before we enable MCEs: */
14320 wmb();
14321
14322 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14323 index 6b96110..0da73eb 100644
14324 --- a/arch/x86/kernel/cpu/mtrr/main.c
14325 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14326 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14327 u64 size_or_mask, size_and_mask;
14328 static bool mtrr_aps_delayed_init;
14329
14330 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14331 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14332
14333 const struct mtrr_ops *mtrr_if;
14334
14335 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14336 index df5e41f..816c719 100644
14337 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14338 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14339 @@ -25,7 +25,7 @@ struct mtrr_ops {
14340 int (*validate_add_page)(unsigned long base, unsigned long size,
14341 unsigned int type);
14342 int (*have_wrcomb)(void);
14343 -};
14344 +} __do_const;
14345
14346 extern int generic_get_free_region(unsigned long base, unsigned long size,
14347 int replace_reg);
14348 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14349 index 5adce10..99284ec 100644
14350 --- a/arch/x86/kernel/cpu/perf_event.c
14351 +++ b/arch/x86/kernel/cpu/perf_event.c
14352 @@ -1665,7 +1665,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14353 break;
14354
14355 perf_callchain_store(entry, frame.return_address);
14356 - fp = frame.next_frame;
14357 + fp = (const void __force_user *)frame.next_frame;
14358 }
14359 }
14360
14361 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14362 index 13ad899..f642b9a 100644
14363 --- a/arch/x86/kernel/crash.c
14364 +++ b/arch/x86/kernel/crash.c
14365 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14366 {
14367 #ifdef CONFIG_X86_32
14368 struct pt_regs fixed_regs;
14369 -#endif
14370
14371 -#ifdef CONFIG_X86_32
14372 - if (!user_mode_vm(regs)) {
14373 + if (!user_mode(regs)) {
14374 crash_fixup_ss_esp(&fixed_regs, regs);
14375 regs = &fixed_regs;
14376 }
14377 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14378 index 37250fe..bf2ec74 100644
14379 --- a/arch/x86/kernel/doublefault_32.c
14380 +++ b/arch/x86/kernel/doublefault_32.c
14381 @@ -11,7 +11,7 @@
14382
14383 #define DOUBLEFAULT_STACKSIZE (1024)
14384 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14385 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14386 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14387
14388 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14389
14390 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14391 unsigned long gdt, tss;
14392
14393 store_gdt(&gdt_desc);
14394 - gdt = gdt_desc.address;
14395 + gdt = (unsigned long)gdt_desc.address;
14396
14397 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14398
14399 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14400 /* 0x2 bit is always set */
14401 .flags = X86_EFLAGS_SF | 0x2,
14402 .sp = STACK_START,
14403 - .es = __USER_DS,
14404 + .es = __KERNEL_DS,
14405 .cs = __KERNEL_CS,
14406 .ss = __KERNEL_DS,
14407 - .ds = __USER_DS,
14408 + .ds = __KERNEL_DS,
14409 .fs = __KERNEL_PERCPU,
14410
14411 .__cr3 = __pa_nodebug(swapper_pg_dir),
14412 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14413 index 4025fe4..d8451c6 100644
14414 --- a/arch/x86/kernel/dumpstack.c
14415 +++ b/arch/x86/kernel/dumpstack.c
14416 @@ -2,6 +2,9 @@
14417 * Copyright (C) 1991, 1992 Linus Torvalds
14418 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14419 */
14420 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14421 +#define __INCLUDED_BY_HIDESYM 1
14422 +#endif
14423 #include <linux/kallsyms.h>
14424 #include <linux/kprobes.h>
14425 #include <linux/uaccess.h>
14426 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
14427 static void
14428 print_ftrace_graph_addr(unsigned long addr, void *data,
14429 const struct stacktrace_ops *ops,
14430 - struct thread_info *tinfo, int *graph)
14431 + struct task_struct *task, int *graph)
14432 {
14433 - struct task_struct *task = tinfo->task;
14434 unsigned long ret_addr;
14435 int index = task->curr_ret_stack;
14436
14437 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14438 static inline void
14439 print_ftrace_graph_addr(unsigned long addr, void *data,
14440 const struct stacktrace_ops *ops,
14441 - struct thread_info *tinfo, int *graph)
14442 + struct task_struct *task, int *graph)
14443 { }
14444 #endif
14445
14446 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14447 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14448 */
14449
14450 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14451 - void *p, unsigned int size, void *end)
14452 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14453 {
14454 - void *t = tinfo;
14455 if (end) {
14456 if (p < end && p >= (end-THREAD_SIZE))
14457 return 1;
14458 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14459 }
14460
14461 unsigned long
14462 -print_context_stack(struct thread_info *tinfo,
14463 +print_context_stack(struct task_struct *task, void *stack_start,
14464 unsigned long *stack, unsigned long bp,
14465 const struct stacktrace_ops *ops, void *data,
14466 unsigned long *end, int *graph)
14467 {
14468 struct stack_frame *frame = (struct stack_frame *)bp;
14469
14470 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14471 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14472 unsigned long addr;
14473
14474 addr = *stack;
14475 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
14476 } else {
14477 ops->address(data, addr, 0);
14478 }
14479 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14480 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14481 }
14482 stack++;
14483 }
14484 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
14485 EXPORT_SYMBOL_GPL(print_context_stack);
14486
14487 unsigned long
14488 -print_context_stack_bp(struct thread_info *tinfo,
14489 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14490 unsigned long *stack, unsigned long bp,
14491 const struct stacktrace_ops *ops, void *data,
14492 unsigned long *end, int *graph)
14493 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14494 struct stack_frame *frame = (struct stack_frame *)bp;
14495 unsigned long *ret_addr = &frame->return_address;
14496
14497 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14498 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14499 unsigned long addr = *ret_addr;
14500
14501 if (!__kernel_text_address(addr))
14502 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14503 ops->address(data, addr, 1);
14504 frame = frame->next_frame;
14505 ret_addr = &frame->return_address;
14506 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14507 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14508 }
14509
14510 return (unsigned long)frame;
14511 @@ -186,7 +186,7 @@ void dump_stack(void)
14512
14513 bp = stack_frame(current, NULL);
14514 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14515 - current->pid, current->comm, print_tainted(),
14516 + task_pid_nr(current), current->comm, print_tainted(),
14517 init_utsname()->release,
14518 (int)strcspn(init_utsname()->version, " "),
14519 init_utsname()->version);
14520 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
14521 }
14522 EXPORT_SYMBOL_GPL(oops_begin);
14523
14524 +extern void gr_handle_kernel_exploit(void);
14525 +
14526 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14527 {
14528 if (regs && kexec_should_crash(current))
14529 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14530 panic("Fatal exception in interrupt");
14531 if (panic_on_oops)
14532 panic("Fatal exception");
14533 - do_exit(signr);
14534 +
14535 + gr_handle_kernel_exploit();
14536 +
14537 + do_group_exit(signr);
14538 }
14539
14540 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14541 @@ -270,7 +275,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14542
14543 show_registers(regs);
14544 #ifdef CONFIG_X86_32
14545 - if (user_mode_vm(regs)) {
14546 + if (user_mode(regs)) {
14547 sp = regs->sp;
14548 ss = regs->ss & 0xffff;
14549 } else {
14550 @@ -298,7 +303,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14551 unsigned long flags = oops_begin();
14552 int sig = SIGSEGV;
14553
14554 - if (!user_mode_vm(regs))
14555 + if (!user_mode(regs))
14556 report_bug(regs->ip, regs);
14557
14558 if (__die(str, regs, err))
14559 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14560 index c99f9ed..2a15d80 100644
14561 --- a/arch/x86/kernel/dumpstack_32.c
14562 +++ b/arch/x86/kernel/dumpstack_32.c
14563 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14564 bp = stack_frame(task, regs);
14565
14566 for (;;) {
14567 - struct thread_info *context;
14568 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14569
14570 - context = (struct thread_info *)
14571 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14572 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14573 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14574
14575 - stack = (unsigned long *)context->previous_esp;
14576 - if (!stack)
14577 + if (stack_start == task_stack_page(task))
14578 break;
14579 + stack = *(unsigned long **)stack_start;
14580 if (ops->stack(data, "IRQ") < 0)
14581 break;
14582 touch_nmi_watchdog();
14583 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
14584 * When in-kernel, we also print out the stack and code at the
14585 * time of the fault..
14586 */
14587 - if (!user_mode_vm(regs)) {
14588 + if (!user_mode(regs)) {
14589 unsigned int code_prologue = code_bytes * 43 / 64;
14590 unsigned int code_len = code_bytes;
14591 unsigned char c;
14592 u8 *ip;
14593 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14594
14595 printk(KERN_EMERG "Stack:\n");
14596 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14597
14598 printk(KERN_EMERG "Code: ");
14599
14600 - ip = (u8 *)regs->ip - code_prologue;
14601 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14602 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14603 /* try starting at IP */
14604 - ip = (u8 *)regs->ip;
14605 + ip = (u8 *)regs->ip + cs_base;
14606 code_len = code_len - code_prologue + 1;
14607 }
14608 for (i = 0; i < code_len; i++, ip++) {
14609 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
14610 printk(KERN_CONT " Bad EIP value.");
14611 break;
14612 }
14613 - if (ip == (u8 *)regs->ip)
14614 + if (ip == (u8 *)regs->ip + cs_base)
14615 printk(KERN_CONT "<%02x> ", c);
14616 else
14617 printk(KERN_CONT "%02x ", c);
14618 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14619 {
14620 unsigned short ud2;
14621
14622 + ip = ktla_ktva(ip);
14623 if (ip < PAGE_OFFSET)
14624 return 0;
14625 if (probe_kernel_address((unsigned short *)ip, ud2))
14626 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14627
14628 return ud2 == 0x0b0f;
14629 }
14630 +
14631 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14632 +void pax_check_alloca(unsigned long size)
14633 +{
14634 + unsigned long sp = (unsigned long)&sp, stack_left;
14635 +
14636 + /* all kernel stacks are of the same size */
14637 + stack_left = sp & (THREAD_SIZE - 1);
14638 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14639 +}
14640 +EXPORT_SYMBOL(pax_check_alloca);
14641 +#endif
14642 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14643 index 17107bd..9623722 100644
14644 --- a/arch/x86/kernel/dumpstack_64.c
14645 +++ b/arch/x86/kernel/dumpstack_64.c
14646 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14647 unsigned long *irq_stack_end =
14648 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14649 unsigned used = 0;
14650 - struct thread_info *tinfo;
14651 int graph = 0;
14652 unsigned long dummy;
14653 + void *stack_start;
14654
14655 if (!task)
14656 task = current;
14657 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14658 * current stack address. If the stacks consist of nested
14659 * exceptions
14660 */
14661 - tinfo = task_thread_info(task);
14662 for (;;) {
14663 char *id;
14664 unsigned long *estack_end;
14665 +
14666 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14667 &used, &id);
14668
14669 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14670 if (ops->stack(data, id) < 0)
14671 break;
14672
14673 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14674 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14675 data, estack_end, &graph);
14676 ops->stack(data, "<EOE>");
14677 /*
14678 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14679 * second-to-last pointer (index -2 to end) in the
14680 * exception stack:
14681 */
14682 + if ((u16)estack_end[-1] != __KERNEL_DS)
14683 + goto out;
14684 stack = (unsigned long *) estack_end[-2];
14685 continue;
14686 }
14687 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14688 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14689 if (ops->stack(data, "IRQ") < 0)
14690 break;
14691 - bp = ops->walk_stack(tinfo, stack, bp,
14692 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14693 ops, data, irq_stack_end, &graph);
14694 /*
14695 * We link to the next stack (which would be
14696 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14697 /*
14698 * This handles the process stack:
14699 */
14700 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14701 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14702 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14703 +out:
14704 put_cpu();
14705 }
14706 EXPORT_SYMBOL(dump_trace);
14707 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14708
14709 return ud2 == 0x0b0f;
14710 }
14711 +
14712 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14713 +void pax_check_alloca(unsigned long size)
14714 +{
14715 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14716 + unsigned cpu, used;
14717 + char *id;
14718 +
14719 + /* check the process stack first */
14720 + stack_start = (unsigned long)task_stack_page(current);
14721 + stack_end = stack_start + THREAD_SIZE;
14722 + if (likely(stack_start <= sp && sp < stack_end)) {
14723 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14724 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14725 + return;
14726 + }
14727 +
14728 + cpu = get_cpu();
14729 +
14730 + /* check the irq stacks */
14731 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14732 + stack_start = stack_end - IRQ_STACK_SIZE;
14733 + if (stack_start <= sp && sp < stack_end) {
14734 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14735 + put_cpu();
14736 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14737 + return;
14738 + }
14739 +
14740 + /* check the exception stacks */
14741 + used = 0;
14742 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14743 + stack_start = stack_end - EXCEPTION_STKSZ;
14744 + if (stack_end && stack_start <= sp && sp < stack_end) {
14745 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14746 + put_cpu();
14747 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14748 + return;
14749 + }
14750 +
14751 + put_cpu();
14752 +
14753 + /* unknown stack */
14754 + BUG();
14755 +}
14756 +EXPORT_SYMBOL(pax_check_alloca);
14757 +#endif
14758 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14759 index 9b9f18b..9fcaa04 100644
14760 --- a/arch/x86/kernel/early_printk.c
14761 +++ b/arch/x86/kernel/early_printk.c
14762 @@ -7,6 +7,7 @@
14763 #include <linux/pci_regs.h>
14764 #include <linux/pci_ids.h>
14765 #include <linux/errno.h>
14766 +#include <linux/sched.h>
14767 #include <asm/io.h>
14768 #include <asm/processor.h>
14769 #include <asm/fcntl.h>
14770 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14771 index 7b784f4..db6b628 100644
14772 --- a/arch/x86/kernel/entry_32.S
14773 +++ b/arch/x86/kernel/entry_32.S
14774 @@ -179,13 +179,146 @@
14775 /*CFI_REL_OFFSET gs, PT_GS*/
14776 .endm
14777 .macro SET_KERNEL_GS reg
14778 +
14779 +#ifdef CONFIG_CC_STACKPROTECTOR
14780 movl $(__KERNEL_STACK_CANARY), \reg
14781 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14782 + movl $(__USER_DS), \reg
14783 +#else
14784 + xorl \reg, \reg
14785 +#endif
14786 +
14787 movl \reg, %gs
14788 .endm
14789
14790 #endif /* CONFIG_X86_32_LAZY_GS */
14791
14792 -.macro SAVE_ALL
14793 +.macro pax_enter_kernel
14794 +#ifdef CONFIG_PAX_KERNEXEC
14795 + call pax_enter_kernel
14796 +#endif
14797 +.endm
14798 +
14799 +.macro pax_exit_kernel
14800 +#ifdef CONFIG_PAX_KERNEXEC
14801 + call pax_exit_kernel
14802 +#endif
14803 +.endm
14804 +
14805 +#ifdef CONFIG_PAX_KERNEXEC
14806 +ENTRY(pax_enter_kernel)
14807 +#ifdef CONFIG_PARAVIRT
14808 + pushl %eax
14809 + pushl %ecx
14810 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14811 + mov %eax, %esi
14812 +#else
14813 + mov %cr0, %esi
14814 +#endif
14815 + bts $16, %esi
14816 + jnc 1f
14817 + mov %cs, %esi
14818 + cmp $__KERNEL_CS, %esi
14819 + jz 3f
14820 + ljmp $__KERNEL_CS, $3f
14821 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14822 +2:
14823 +#ifdef CONFIG_PARAVIRT
14824 + mov %esi, %eax
14825 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14826 +#else
14827 + mov %esi, %cr0
14828 +#endif
14829 +3:
14830 +#ifdef CONFIG_PARAVIRT
14831 + popl %ecx
14832 + popl %eax
14833 +#endif
14834 + ret
14835 +ENDPROC(pax_enter_kernel)
14836 +
14837 +ENTRY(pax_exit_kernel)
14838 +#ifdef CONFIG_PARAVIRT
14839 + pushl %eax
14840 + pushl %ecx
14841 +#endif
14842 + mov %cs, %esi
14843 + cmp $__KERNEXEC_KERNEL_CS, %esi
14844 + jnz 2f
14845 +#ifdef CONFIG_PARAVIRT
14846 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
14847 + mov %eax, %esi
14848 +#else
14849 + mov %cr0, %esi
14850 +#endif
14851 + btr $16, %esi
14852 + ljmp $__KERNEL_CS, $1f
14853 +1:
14854 +#ifdef CONFIG_PARAVIRT
14855 + mov %esi, %eax
14856 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
14857 +#else
14858 + mov %esi, %cr0
14859 +#endif
14860 +2:
14861 +#ifdef CONFIG_PARAVIRT
14862 + popl %ecx
14863 + popl %eax
14864 +#endif
14865 + ret
14866 +ENDPROC(pax_exit_kernel)
14867 +#endif
14868 +
14869 +.macro pax_erase_kstack
14870 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14871 + call pax_erase_kstack
14872 +#endif
14873 +.endm
14874 +
14875 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14876 +/*
14877 + * ebp: thread_info
14878 + * ecx, edx: can be clobbered
14879 + */
14880 +ENTRY(pax_erase_kstack)
14881 + pushl %edi
14882 + pushl %eax
14883 +
14884 + mov TI_lowest_stack(%ebp), %edi
14885 + mov $-0xBEEF, %eax
14886 + std
14887 +
14888 +1: mov %edi, %ecx
14889 + and $THREAD_SIZE_asm - 1, %ecx
14890 + shr $2, %ecx
14891 + repne scasl
14892 + jecxz 2f
14893 +
14894 + cmp $2*16, %ecx
14895 + jc 2f
14896 +
14897 + mov $2*16, %ecx
14898 + repe scasl
14899 + jecxz 2f
14900 + jne 1b
14901 +
14902 +2: cld
14903 + mov %esp, %ecx
14904 + sub %edi, %ecx
14905 + shr $2, %ecx
14906 + rep stosl
14907 +
14908 + mov TI_task_thread_sp0(%ebp), %edi
14909 + sub $128, %edi
14910 + mov %edi, TI_lowest_stack(%ebp)
14911 +
14912 + popl %eax
14913 + popl %edi
14914 + ret
14915 +ENDPROC(pax_erase_kstack)
14916 +#endif
14917 +
14918 +.macro __SAVE_ALL _DS
14919 cld
14920 PUSH_GS
14921 pushl_cfi %fs
14922 @@ -208,7 +341,7 @@
14923 CFI_REL_OFFSET ecx, 0
14924 pushl_cfi %ebx
14925 CFI_REL_OFFSET ebx, 0
14926 - movl $(__USER_DS), %edx
14927 + movl $\_DS, %edx
14928 movl %edx, %ds
14929 movl %edx, %es
14930 movl $(__KERNEL_PERCPU), %edx
14931 @@ -216,6 +349,15 @@
14932 SET_KERNEL_GS %edx
14933 .endm
14934
14935 +.macro SAVE_ALL
14936 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
14937 + __SAVE_ALL __KERNEL_DS
14938 + pax_enter_kernel
14939 +#else
14940 + __SAVE_ALL __USER_DS
14941 +#endif
14942 +.endm
14943 +
14944 .macro RESTORE_INT_REGS
14945 popl_cfi %ebx
14946 CFI_RESTORE ebx
14947 @@ -301,7 +443,7 @@ ENTRY(ret_from_fork)
14948 popfl_cfi
14949 jmp syscall_exit
14950 CFI_ENDPROC
14951 -END(ret_from_fork)
14952 +ENDPROC(ret_from_fork)
14953
14954 /*
14955 * Interrupt exit functions should be protected against kprobes
14956 @@ -335,7 +477,15 @@ resume_userspace_sig:
14957 andl $SEGMENT_RPL_MASK, %eax
14958 #endif
14959 cmpl $USER_RPL, %eax
14960 +
14961 +#ifdef CONFIG_PAX_KERNEXEC
14962 + jae resume_userspace
14963 +
14964 + pax_exit_kernel
14965 + jmp resume_kernel
14966 +#else
14967 jb resume_kernel # not returning to v8086 or userspace
14968 +#endif
14969
14970 ENTRY(resume_userspace)
14971 LOCKDEP_SYS_EXIT
14972 @@ -347,8 +497,8 @@ ENTRY(resume_userspace)
14973 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
14974 # int/exception return?
14975 jne work_pending
14976 - jmp restore_all
14977 -END(ret_from_exception)
14978 + jmp restore_all_pax
14979 +ENDPROC(ret_from_exception)
14980
14981 #ifdef CONFIG_PREEMPT
14982 ENTRY(resume_kernel)
14983 @@ -363,7 +513,7 @@ need_resched:
14984 jz restore_all
14985 call preempt_schedule_irq
14986 jmp need_resched
14987 -END(resume_kernel)
14988 +ENDPROC(resume_kernel)
14989 #endif
14990 CFI_ENDPROC
14991 /*
14992 @@ -397,23 +547,34 @@ sysenter_past_esp:
14993 /*CFI_REL_OFFSET cs, 0*/
14994 /*
14995 * Push current_thread_info()->sysenter_return to the stack.
14996 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
14997 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
14998 */
14999 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15000 + pushl_cfi $0
15001 CFI_REL_OFFSET eip, 0
15002
15003 pushl_cfi %eax
15004 SAVE_ALL
15005 + GET_THREAD_INFO(%ebp)
15006 + movl TI_sysenter_return(%ebp),%ebp
15007 + movl %ebp,PT_EIP(%esp)
15008 ENABLE_INTERRUPTS(CLBR_NONE)
15009
15010 /*
15011 * Load the potential sixth argument from user stack.
15012 * Careful about security.
15013 */
15014 + movl PT_OLDESP(%esp),%ebp
15015 +
15016 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15017 + mov PT_OLDSS(%esp),%ds
15018 +1: movl %ds:(%ebp),%ebp
15019 + push %ss
15020 + pop %ds
15021 +#else
15022 cmpl $__PAGE_OFFSET-3,%ebp
15023 jae syscall_fault
15024 1: movl (%ebp),%ebp
15025 +#endif
15026 +
15027 movl %ebp,PT_EBP(%esp)
15028 .section __ex_table,"a"
15029 .align 4
15030 @@ -436,12 +597,24 @@ sysenter_do_call:
15031 testl $_TIF_ALLWORK_MASK, %ecx
15032 jne sysexit_audit
15033 sysenter_exit:
15034 +
15035 +#ifdef CONFIG_PAX_RANDKSTACK
15036 + pushl_cfi %eax
15037 + movl %esp, %eax
15038 + call pax_randomize_kstack
15039 + popl_cfi %eax
15040 +#endif
15041 +
15042 + pax_erase_kstack
15043 +
15044 /* if something modifies registers it must also disable sysexit */
15045 movl PT_EIP(%esp), %edx
15046 movl PT_OLDESP(%esp), %ecx
15047 xorl %ebp,%ebp
15048 TRACE_IRQS_ON
15049 1: mov PT_FS(%esp), %fs
15050 +2: mov PT_DS(%esp), %ds
15051 +3: mov PT_ES(%esp), %es
15052 PTGS_TO_GS
15053 ENABLE_INTERRUPTS_SYSEXIT
15054
15055 @@ -458,6 +631,9 @@ sysenter_audit:
15056 movl %eax,%edx /* 2nd arg: syscall number */
15057 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15058 call __audit_syscall_entry
15059 +
15060 + pax_erase_kstack
15061 +
15062 pushl_cfi %ebx
15063 movl PT_EAX(%esp),%eax /* reload syscall number */
15064 jmp sysenter_do_call
15065 @@ -483,11 +659,17 @@ sysexit_audit:
15066
15067 CFI_ENDPROC
15068 .pushsection .fixup,"ax"
15069 -2: movl $0,PT_FS(%esp)
15070 +4: movl $0,PT_FS(%esp)
15071 + jmp 1b
15072 +5: movl $0,PT_DS(%esp)
15073 + jmp 1b
15074 +6: movl $0,PT_ES(%esp)
15075 jmp 1b
15076 .section __ex_table,"a"
15077 .align 4
15078 - .long 1b,2b
15079 + .long 1b,4b
15080 + .long 2b,5b
15081 + .long 3b,6b
15082 .popsection
15083 PTGS_TO_GS_EX
15084 ENDPROC(ia32_sysenter_target)
15085 @@ -520,6 +702,15 @@ syscall_exit:
15086 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15087 jne syscall_exit_work
15088
15089 +restore_all_pax:
15090 +
15091 +#ifdef CONFIG_PAX_RANDKSTACK
15092 + movl %esp, %eax
15093 + call pax_randomize_kstack
15094 +#endif
15095 +
15096 + pax_erase_kstack
15097 +
15098 restore_all:
15099 TRACE_IRQS_IRET
15100 restore_all_notrace:
15101 @@ -579,14 +770,34 @@ ldt_ss:
15102 * compensating for the offset by changing to the ESPFIX segment with
15103 * a base address that matches for the difference.
15104 */
15105 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15106 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15107 mov %esp, %edx /* load kernel esp */
15108 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15109 mov %dx, %ax /* eax: new kernel esp */
15110 sub %eax, %edx /* offset (low word is 0) */
15111 +#ifdef CONFIG_SMP
15112 + movl PER_CPU_VAR(cpu_number), %ebx
15113 + shll $PAGE_SHIFT_asm, %ebx
15114 + addl $cpu_gdt_table, %ebx
15115 +#else
15116 + movl $cpu_gdt_table, %ebx
15117 +#endif
15118 shr $16, %edx
15119 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15120 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15121 +
15122 +#ifdef CONFIG_PAX_KERNEXEC
15123 + mov %cr0, %esi
15124 + btr $16, %esi
15125 + mov %esi, %cr0
15126 +#endif
15127 +
15128 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15129 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15130 +
15131 +#ifdef CONFIG_PAX_KERNEXEC
15132 + bts $16, %esi
15133 + mov %esi, %cr0
15134 +#endif
15135 +
15136 pushl_cfi $__ESPFIX_SS
15137 pushl_cfi %eax /* new kernel esp */
15138 /* Disable interrupts, but do not irqtrace this section: we
15139 @@ -615,38 +826,30 @@ work_resched:
15140 movl TI_flags(%ebp), %ecx
15141 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15142 # than syscall tracing?
15143 - jz restore_all
15144 + jz restore_all_pax
15145 testb $_TIF_NEED_RESCHED, %cl
15146 jnz work_resched
15147
15148 work_notifysig: # deal with pending signals and
15149 # notify-resume requests
15150 + movl %esp, %eax
15151 #ifdef CONFIG_VM86
15152 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15153 - movl %esp, %eax
15154 - jne work_notifysig_v86 # returning to kernel-space or
15155 + jz 1f # returning to kernel-space or
15156 # vm86-space
15157 - TRACE_IRQS_ON
15158 - ENABLE_INTERRUPTS(CLBR_NONE)
15159 - xorl %edx, %edx
15160 - call do_notify_resume
15161 - jmp resume_userspace_sig
15162
15163 - ALIGN
15164 -work_notifysig_v86:
15165 pushl_cfi %ecx # save ti_flags for do_notify_resume
15166 call save_v86_state # %eax contains pt_regs pointer
15167 popl_cfi %ecx
15168 movl %eax, %esp
15169 -#else
15170 - movl %esp, %eax
15171 +1:
15172 #endif
15173 TRACE_IRQS_ON
15174 ENABLE_INTERRUPTS(CLBR_NONE)
15175 xorl %edx, %edx
15176 call do_notify_resume
15177 jmp resume_userspace_sig
15178 -END(work_pending)
15179 +ENDPROC(work_pending)
15180
15181 # perform syscall exit tracing
15182 ALIGN
15183 @@ -654,11 +857,14 @@ syscall_trace_entry:
15184 movl $-ENOSYS,PT_EAX(%esp)
15185 movl %esp, %eax
15186 call syscall_trace_enter
15187 +
15188 + pax_erase_kstack
15189 +
15190 /* What it returned is what we'll actually use. */
15191 cmpl $(NR_syscalls), %eax
15192 jnae syscall_call
15193 jmp syscall_exit
15194 -END(syscall_trace_entry)
15195 +ENDPROC(syscall_trace_entry)
15196
15197 # perform syscall exit tracing
15198 ALIGN
15199 @@ -671,20 +877,24 @@ syscall_exit_work:
15200 movl %esp, %eax
15201 call syscall_trace_leave
15202 jmp resume_userspace
15203 -END(syscall_exit_work)
15204 +ENDPROC(syscall_exit_work)
15205 CFI_ENDPROC
15206
15207 RING0_INT_FRAME # can't unwind into user space anyway
15208 syscall_fault:
15209 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15210 + push %ss
15211 + pop %ds
15212 +#endif
15213 GET_THREAD_INFO(%ebp)
15214 movl $-EFAULT,PT_EAX(%esp)
15215 jmp resume_userspace
15216 -END(syscall_fault)
15217 +ENDPROC(syscall_fault)
15218
15219 syscall_badsys:
15220 movl $-ENOSYS,PT_EAX(%esp)
15221 jmp resume_userspace
15222 -END(syscall_badsys)
15223 +ENDPROC(syscall_badsys)
15224 CFI_ENDPROC
15225 /*
15226 * End of kprobes section
15227 @@ -756,6 +966,36 @@ ENTRY(ptregs_clone)
15228 CFI_ENDPROC
15229 ENDPROC(ptregs_clone)
15230
15231 + ALIGN;
15232 +ENTRY(kernel_execve)
15233 + CFI_STARTPROC
15234 + pushl_cfi %ebp
15235 + sub $PT_OLDSS+4,%esp
15236 + pushl_cfi %edi
15237 + pushl_cfi %ecx
15238 + pushl_cfi %eax
15239 + lea 3*4(%esp),%edi
15240 + mov $PT_OLDSS/4+1,%ecx
15241 + xorl %eax,%eax
15242 + rep stosl
15243 + popl_cfi %eax
15244 + popl_cfi %ecx
15245 + popl_cfi %edi
15246 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15247 + pushl_cfi %esp
15248 + call sys_execve
15249 + add $4,%esp
15250 + CFI_ADJUST_CFA_OFFSET -4
15251 + GET_THREAD_INFO(%ebp)
15252 + test %eax,%eax
15253 + jz syscall_exit
15254 + add $PT_OLDSS+4,%esp
15255 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15256 + popl_cfi %ebp
15257 + ret
15258 + CFI_ENDPROC
15259 +ENDPROC(kernel_execve)
15260 +
15261 .macro FIXUP_ESPFIX_STACK
15262 /*
15263 * Switch back for ESPFIX stack to the normal zerobased stack
15264 @@ -765,8 +1005,15 @@ ENDPROC(ptregs_clone)
15265 * normal stack and adjusts ESP with the matching offset.
15266 */
15267 /* fixup the stack */
15268 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15269 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15270 +#ifdef CONFIG_SMP
15271 + movl PER_CPU_VAR(cpu_number), %ebx
15272 + shll $PAGE_SHIFT_asm, %ebx
15273 + addl $cpu_gdt_table, %ebx
15274 +#else
15275 + movl $cpu_gdt_table, %ebx
15276 +#endif
15277 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15278 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15279 shl $16, %eax
15280 addl %esp, %eax /* the adjusted stack pointer */
15281 pushl_cfi $__KERNEL_DS
15282 @@ -819,7 +1066,7 @@ vector=vector+1
15283 .endr
15284 2: jmp common_interrupt
15285 .endr
15286 -END(irq_entries_start)
15287 +ENDPROC(irq_entries_start)
15288
15289 .previous
15290 END(interrupt)
15291 @@ -867,7 +1114,7 @@ ENTRY(coprocessor_error)
15292 pushl_cfi $do_coprocessor_error
15293 jmp error_code
15294 CFI_ENDPROC
15295 -END(coprocessor_error)
15296 +ENDPROC(coprocessor_error)
15297
15298 ENTRY(simd_coprocessor_error)
15299 RING0_INT_FRAME
15300 @@ -888,7 +1135,7 @@ ENTRY(simd_coprocessor_error)
15301 #endif
15302 jmp error_code
15303 CFI_ENDPROC
15304 -END(simd_coprocessor_error)
15305 +ENDPROC(simd_coprocessor_error)
15306
15307 ENTRY(device_not_available)
15308 RING0_INT_FRAME
15309 @@ -896,7 +1143,7 @@ ENTRY(device_not_available)
15310 pushl_cfi $do_device_not_available
15311 jmp error_code
15312 CFI_ENDPROC
15313 -END(device_not_available)
15314 +ENDPROC(device_not_available)
15315
15316 #ifdef CONFIG_PARAVIRT
15317 ENTRY(native_iret)
15318 @@ -905,12 +1152,12 @@ ENTRY(native_iret)
15319 .align 4
15320 .long native_iret, iret_exc
15321 .previous
15322 -END(native_iret)
15323 +ENDPROC(native_iret)
15324
15325 ENTRY(native_irq_enable_sysexit)
15326 sti
15327 sysexit
15328 -END(native_irq_enable_sysexit)
15329 +ENDPROC(native_irq_enable_sysexit)
15330 #endif
15331
15332 ENTRY(overflow)
15333 @@ -919,7 +1166,7 @@ ENTRY(overflow)
15334 pushl_cfi $do_overflow
15335 jmp error_code
15336 CFI_ENDPROC
15337 -END(overflow)
15338 +ENDPROC(overflow)
15339
15340 ENTRY(bounds)
15341 RING0_INT_FRAME
15342 @@ -927,7 +1174,7 @@ ENTRY(bounds)
15343 pushl_cfi $do_bounds
15344 jmp error_code
15345 CFI_ENDPROC
15346 -END(bounds)
15347 +ENDPROC(bounds)
15348
15349 ENTRY(invalid_op)
15350 RING0_INT_FRAME
15351 @@ -935,7 +1182,7 @@ ENTRY(invalid_op)
15352 pushl_cfi $do_invalid_op
15353 jmp error_code
15354 CFI_ENDPROC
15355 -END(invalid_op)
15356 +ENDPROC(invalid_op)
15357
15358 ENTRY(coprocessor_segment_overrun)
15359 RING0_INT_FRAME
15360 @@ -943,35 +1190,35 @@ ENTRY(coprocessor_segment_overrun)
15361 pushl_cfi $do_coprocessor_segment_overrun
15362 jmp error_code
15363 CFI_ENDPROC
15364 -END(coprocessor_segment_overrun)
15365 +ENDPROC(coprocessor_segment_overrun)
15366
15367 ENTRY(invalid_TSS)
15368 RING0_EC_FRAME
15369 pushl_cfi $do_invalid_TSS
15370 jmp error_code
15371 CFI_ENDPROC
15372 -END(invalid_TSS)
15373 +ENDPROC(invalid_TSS)
15374
15375 ENTRY(segment_not_present)
15376 RING0_EC_FRAME
15377 pushl_cfi $do_segment_not_present
15378 jmp error_code
15379 CFI_ENDPROC
15380 -END(segment_not_present)
15381 +ENDPROC(segment_not_present)
15382
15383 ENTRY(stack_segment)
15384 RING0_EC_FRAME
15385 pushl_cfi $do_stack_segment
15386 jmp error_code
15387 CFI_ENDPROC
15388 -END(stack_segment)
15389 +ENDPROC(stack_segment)
15390
15391 ENTRY(alignment_check)
15392 RING0_EC_FRAME
15393 pushl_cfi $do_alignment_check
15394 jmp error_code
15395 CFI_ENDPROC
15396 -END(alignment_check)
15397 +ENDPROC(alignment_check)
15398
15399 ENTRY(divide_error)
15400 RING0_INT_FRAME
15401 @@ -979,7 +1226,7 @@ ENTRY(divide_error)
15402 pushl_cfi $do_divide_error
15403 jmp error_code
15404 CFI_ENDPROC
15405 -END(divide_error)
15406 +ENDPROC(divide_error)
15407
15408 #ifdef CONFIG_X86_MCE
15409 ENTRY(machine_check)
15410 @@ -988,7 +1235,7 @@ ENTRY(machine_check)
15411 pushl_cfi machine_check_vector
15412 jmp error_code
15413 CFI_ENDPROC
15414 -END(machine_check)
15415 +ENDPROC(machine_check)
15416 #endif
15417
15418 ENTRY(spurious_interrupt_bug)
15419 @@ -997,7 +1244,7 @@ ENTRY(spurious_interrupt_bug)
15420 pushl_cfi $do_spurious_interrupt_bug
15421 jmp error_code
15422 CFI_ENDPROC
15423 -END(spurious_interrupt_bug)
15424 +ENDPROC(spurious_interrupt_bug)
15425 /*
15426 * End of kprobes section
15427 */
15428 @@ -1112,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15429
15430 ENTRY(mcount)
15431 ret
15432 -END(mcount)
15433 +ENDPROC(mcount)
15434
15435 ENTRY(ftrace_caller)
15436 cmpl $0, function_trace_stop
15437 @@ -1141,7 +1388,7 @@ ftrace_graph_call:
15438 .globl ftrace_stub
15439 ftrace_stub:
15440 ret
15441 -END(ftrace_caller)
15442 +ENDPROC(ftrace_caller)
15443
15444 #else /* ! CONFIG_DYNAMIC_FTRACE */
15445
15446 @@ -1177,7 +1424,7 @@ trace:
15447 popl %ecx
15448 popl %eax
15449 jmp ftrace_stub
15450 -END(mcount)
15451 +ENDPROC(mcount)
15452 #endif /* CONFIG_DYNAMIC_FTRACE */
15453 #endif /* CONFIG_FUNCTION_TRACER */
15454
15455 @@ -1198,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15456 popl %ecx
15457 popl %eax
15458 ret
15459 -END(ftrace_graph_caller)
15460 +ENDPROC(ftrace_graph_caller)
15461
15462 .globl return_to_handler
15463 return_to_handler:
15464 @@ -1253,15 +1500,18 @@ error_code:
15465 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15466 REG_TO_PTGS %ecx
15467 SET_KERNEL_GS %ecx
15468 - movl $(__USER_DS), %ecx
15469 + movl $(__KERNEL_DS), %ecx
15470 movl %ecx, %ds
15471 movl %ecx, %es
15472 +
15473 + pax_enter_kernel
15474 +
15475 TRACE_IRQS_OFF
15476 movl %esp,%eax # pt_regs pointer
15477 call *%edi
15478 jmp ret_from_exception
15479 CFI_ENDPROC
15480 -END(page_fault)
15481 +ENDPROC(page_fault)
15482
15483 /*
15484 * Debug traps and NMI can happen at the one SYSENTER instruction
15485 @@ -1303,7 +1553,7 @@ debug_stack_correct:
15486 call do_debug
15487 jmp ret_from_exception
15488 CFI_ENDPROC
15489 -END(debug)
15490 +ENDPROC(debug)
15491
15492 /*
15493 * NMI is doubly nasty. It can happen _while_ we're handling
15494 @@ -1340,6 +1590,9 @@ nmi_stack_correct:
15495 xorl %edx,%edx # zero error code
15496 movl %esp,%eax # pt_regs pointer
15497 call do_nmi
15498 +
15499 + pax_exit_kernel
15500 +
15501 jmp restore_all_notrace
15502 CFI_ENDPROC
15503
15504 @@ -1376,12 +1629,15 @@ nmi_espfix_stack:
15505 FIXUP_ESPFIX_STACK # %eax == %esp
15506 xorl %edx,%edx # zero error code
15507 call do_nmi
15508 +
15509 + pax_exit_kernel
15510 +
15511 RESTORE_REGS
15512 lss 12+4(%esp), %esp # back to espfix stack
15513 CFI_ADJUST_CFA_OFFSET -24
15514 jmp irq_return
15515 CFI_ENDPROC
15516 -END(nmi)
15517 +ENDPROC(nmi)
15518
15519 ENTRY(int3)
15520 RING0_INT_FRAME
15521 @@ -1393,14 +1649,14 @@ ENTRY(int3)
15522 call do_int3
15523 jmp ret_from_exception
15524 CFI_ENDPROC
15525 -END(int3)
15526 +ENDPROC(int3)
15527
15528 ENTRY(general_protection)
15529 RING0_EC_FRAME
15530 pushl_cfi $do_general_protection
15531 jmp error_code
15532 CFI_ENDPROC
15533 -END(general_protection)
15534 +ENDPROC(general_protection)
15535
15536 #ifdef CONFIG_KVM_GUEST
15537 ENTRY(async_page_fault)
15538 @@ -1408,7 +1664,7 @@ ENTRY(async_page_fault)
15539 pushl_cfi $do_async_page_fault
15540 jmp error_code
15541 CFI_ENDPROC
15542 -END(async_page_fault)
15543 +ENDPROC(async_page_fault)
15544 #endif
15545
15546 /*
15547 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15548 index 1333d98..b340ca2 100644
15549 --- a/arch/x86/kernel/entry_64.S
15550 +++ b/arch/x86/kernel/entry_64.S
15551 @@ -56,6 +56,8 @@
15552 #include <asm/ftrace.h>
15553 #include <asm/percpu.h>
15554 #include <linux/err.h>
15555 +#include <asm/pgtable.h>
15556 +#include <asm/alternative-asm.h>
15557
15558 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15559 #include <linux/elf-em.h>
15560 @@ -69,8 +71,9 @@
15561 #ifdef CONFIG_FUNCTION_TRACER
15562 #ifdef CONFIG_DYNAMIC_FTRACE
15563 ENTRY(mcount)
15564 + pax_force_retaddr
15565 retq
15566 -END(mcount)
15567 +ENDPROC(mcount)
15568
15569 ENTRY(ftrace_caller)
15570 cmpl $0, function_trace_stop
15571 @@ -93,8 +96,9 @@ GLOBAL(ftrace_graph_call)
15572 #endif
15573
15574 GLOBAL(ftrace_stub)
15575 + pax_force_retaddr
15576 retq
15577 -END(ftrace_caller)
15578 +ENDPROC(ftrace_caller)
15579
15580 #else /* ! CONFIG_DYNAMIC_FTRACE */
15581 ENTRY(mcount)
15582 @@ -113,6 +117,7 @@ ENTRY(mcount)
15583 #endif
15584
15585 GLOBAL(ftrace_stub)
15586 + pax_force_retaddr
15587 retq
15588
15589 trace:
15590 @@ -122,12 +127,13 @@ trace:
15591 movq 8(%rbp), %rsi
15592 subq $MCOUNT_INSN_SIZE, %rdi
15593
15594 + pax_force_fptr ftrace_trace_function
15595 call *ftrace_trace_function
15596
15597 MCOUNT_RESTORE_FRAME
15598
15599 jmp ftrace_stub
15600 -END(mcount)
15601 +ENDPROC(mcount)
15602 #endif /* CONFIG_DYNAMIC_FTRACE */
15603 #endif /* CONFIG_FUNCTION_TRACER */
15604
15605 @@ -147,8 +153,9 @@ ENTRY(ftrace_graph_caller)
15606
15607 MCOUNT_RESTORE_FRAME
15608
15609 + pax_force_retaddr
15610 retq
15611 -END(ftrace_graph_caller)
15612 +ENDPROC(ftrace_graph_caller)
15613
15614 GLOBAL(return_to_handler)
15615 subq $24, %rsp
15616 @@ -164,6 +171,7 @@ GLOBAL(return_to_handler)
15617 movq 8(%rsp), %rdx
15618 movq (%rsp), %rax
15619 addq $24, %rsp
15620 + pax_force_fptr %rdi
15621 jmp *%rdi
15622 #endif
15623
15624 @@ -179,6 +187,282 @@ ENTRY(native_usergs_sysret64)
15625 ENDPROC(native_usergs_sysret64)
15626 #endif /* CONFIG_PARAVIRT */
15627
15628 + .macro ljmpq sel, off
15629 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15630 + .byte 0x48; ljmp *1234f(%rip)
15631 + .pushsection .rodata
15632 + .align 16
15633 + 1234: .quad \off; .word \sel
15634 + .popsection
15635 +#else
15636 + pushq $\sel
15637 + pushq $\off
15638 + lretq
15639 +#endif
15640 + .endm
15641 +
15642 + .macro pax_enter_kernel
15643 + pax_set_fptr_mask
15644 +#ifdef CONFIG_PAX_KERNEXEC
15645 + call pax_enter_kernel
15646 +#endif
15647 + .endm
15648 +
15649 + .macro pax_exit_kernel
15650 +#ifdef CONFIG_PAX_KERNEXEC
15651 + call pax_exit_kernel
15652 +#endif
15653 + .endm
15654 +
15655 +#ifdef CONFIG_PAX_KERNEXEC
15656 +ENTRY(pax_enter_kernel)
15657 + pushq %rdi
15658 +
15659 +#ifdef CONFIG_PARAVIRT
15660 + PV_SAVE_REGS(CLBR_RDI)
15661 +#endif
15662 +
15663 + GET_CR0_INTO_RDI
15664 + bts $16,%rdi
15665 + jnc 3f
15666 + mov %cs,%edi
15667 + cmp $__KERNEL_CS,%edi
15668 + jnz 2f
15669 +1:
15670 +
15671 +#ifdef CONFIG_PARAVIRT
15672 + PV_RESTORE_REGS(CLBR_RDI)
15673 +#endif
15674 +
15675 + popq %rdi
15676 + pax_force_retaddr
15677 + retq
15678 +
15679 +2: ljmpq __KERNEL_CS,1f
15680 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15681 +4: SET_RDI_INTO_CR0
15682 + jmp 1b
15683 +ENDPROC(pax_enter_kernel)
15684 +
15685 +ENTRY(pax_exit_kernel)
15686 + pushq %rdi
15687 +
15688 +#ifdef CONFIG_PARAVIRT
15689 + PV_SAVE_REGS(CLBR_RDI)
15690 +#endif
15691 +
15692 + mov %cs,%rdi
15693 + cmp $__KERNEXEC_KERNEL_CS,%edi
15694 + jz 2f
15695 +1:
15696 +
15697 +#ifdef CONFIG_PARAVIRT
15698 + PV_RESTORE_REGS(CLBR_RDI);
15699 +#endif
15700 +
15701 + popq %rdi
15702 + pax_force_retaddr
15703 + retq
15704 +
15705 +2: GET_CR0_INTO_RDI
15706 + btr $16,%rdi
15707 + ljmpq __KERNEL_CS,3f
15708 +3: SET_RDI_INTO_CR0
15709 + jmp 1b
15710 +#ifdef CONFIG_PARAVIRT
15711 + PV_RESTORE_REGS(CLBR_RDI);
15712 +#endif
15713 +
15714 + popq %rdi
15715 + pax_force_retaddr
15716 + retq
15717 +ENDPROC(pax_exit_kernel)
15718 +#endif
15719 +
15720 + .macro pax_enter_kernel_user
15721 + pax_set_fptr_mask
15722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15723 + call pax_enter_kernel_user
15724 +#endif
15725 + .endm
15726 +
15727 + .macro pax_exit_kernel_user
15728 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15729 + call pax_exit_kernel_user
15730 +#endif
15731 +#ifdef CONFIG_PAX_RANDKSTACK
15732 + pushq %rax
15733 + call pax_randomize_kstack
15734 + popq %rax
15735 +#endif
15736 + .endm
15737 +
15738 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15739 +ENTRY(pax_enter_kernel_user)
15740 + pushq %rdi
15741 + pushq %rbx
15742 +
15743 +#ifdef CONFIG_PARAVIRT
15744 + PV_SAVE_REGS(CLBR_RDI)
15745 +#endif
15746 +
15747 + GET_CR3_INTO_RDI
15748 + mov %rdi,%rbx
15749 + add $__START_KERNEL_map,%rbx
15750 + sub phys_base(%rip),%rbx
15751 +
15752 +#ifdef CONFIG_PARAVIRT
15753 + pushq %rdi
15754 + cmpl $0, pv_info+PARAVIRT_enabled
15755 + jz 1f
15756 + i = 0
15757 + .rept USER_PGD_PTRS
15758 + mov i*8(%rbx),%rsi
15759 + mov $0,%sil
15760 + lea i*8(%rbx),%rdi
15761 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15762 + i = i + 1
15763 + .endr
15764 + jmp 2f
15765 +1:
15766 +#endif
15767 +
15768 + i = 0
15769 + .rept USER_PGD_PTRS
15770 + movb $0,i*8(%rbx)
15771 + i = i + 1
15772 + .endr
15773 +
15774 +#ifdef CONFIG_PARAVIRT
15775 +2: popq %rdi
15776 +#endif
15777 + SET_RDI_INTO_CR3
15778 +
15779 +#ifdef CONFIG_PAX_KERNEXEC
15780 + GET_CR0_INTO_RDI
15781 + bts $16,%rdi
15782 + SET_RDI_INTO_CR0
15783 +#endif
15784 +
15785 +#ifdef CONFIG_PARAVIRT
15786 + PV_RESTORE_REGS(CLBR_RDI)
15787 +#endif
15788 +
15789 + popq %rbx
15790 + popq %rdi
15791 + pax_force_retaddr
15792 + retq
15793 +ENDPROC(pax_enter_kernel_user)
15794 +
15795 +ENTRY(pax_exit_kernel_user)
15796 + push %rdi
15797 +
15798 +#ifdef CONFIG_PARAVIRT
15799 + pushq %rbx
15800 + PV_SAVE_REGS(CLBR_RDI)
15801 +#endif
15802 +
15803 +#ifdef CONFIG_PAX_KERNEXEC
15804 + GET_CR0_INTO_RDI
15805 + btr $16,%rdi
15806 + SET_RDI_INTO_CR0
15807 +#endif
15808 +
15809 + GET_CR3_INTO_RDI
15810 + add $__START_KERNEL_map,%rdi
15811 + sub phys_base(%rip),%rdi
15812 +
15813 +#ifdef CONFIG_PARAVIRT
15814 + cmpl $0, pv_info+PARAVIRT_enabled
15815 + jz 1f
15816 + mov %rdi,%rbx
15817 + i = 0
15818 + .rept USER_PGD_PTRS
15819 + mov i*8(%rbx),%rsi
15820 + mov $0x67,%sil
15821 + lea i*8(%rbx),%rdi
15822 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15823 + i = i + 1
15824 + .endr
15825 + jmp 2f
15826 +1:
15827 +#endif
15828 +
15829 + i = 0
15830 + .rept USER_PGD_PTRS
15831 + movb $0x67,i*8(%rdi)
15832 + i = i + 1
15833 + .endr
15834 +
15835 +#ifdef CONFIG_PARAVIRT
15836 +2: PV_RESTORE_REGS(CLBR_RDI)
15837 + popq %rbx
15838 +#endif
15839 +
15840 + popq %rdi
15841 + pax_force_retaddr
15842 + retq
15843 +ENDPROC(pax_exit_kernel_user)
15844 +#endif
15845 +
15846 +.macro pax_erase_kstack
15847 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15848 + call pax_erase_kstack
15849 +#endif
15850 +.endm
15851 +
15852 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15853 +/*
15854 + * r11: thread_info
15855 + * rcx, rdx: can be clobbered
15856 + */
15857 +ENTRY(pax_erase_kstack)
15858 + pushq %rdi
15859 + pushq %rax
15860 + pushq %r11
15861 +
15862 + GET_THREAD_INFO(%r11)
15863 + mov TI_lowest_stack(%r11), %rdi
15864 + mov $-0xBEEF, %rax
15865 + std
15866 +
15867 +1: mov %edi, %ecx
15868 + and $THREAD_SIZE_asm - 1, %ecx
15869 + shr $3, %ecx
15870 + repne scasq
15871 + jecxz 2f
15872 +
15873 + cmp $2*8, %ecx
15874 + jc 2f
15875 +
15876 + mov $2*8, %ecx
15877 + repe scasq
15878 + jecxz 2f
15879 + jne 1b
15880 +
15881 +2: cld
15882 + mov %esp, %ecx
15883 + sub %edi, %ecx
15884 +
15885 + cmp $THREAD_SIZE_asm, %rcx
15886 + jb 3f
15887 + ud2
15888 +3:
15889 +
15890 + shr $3, %ecx
15891 + rep stosq
15892 +
15893 + mov TI_task_thread_sp0(%r11), %rdi
15894 + sub $256, %rdi
15895 + mov %rdi, TI_lowest_stack(%r11)
15896 +
15897 + popq %r11
15898 + popq %rax
15899 + popq %rdi
15900 + pax_force_retaddr
15901 + ret
15902 +ENDPROC(pax_erase_kstack)
15903 +#endif
15904
15905 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
15906 #ifdef CONFIG_TRACE_IRQFLAGS
15907 @@ -232,8 +516,8 @@ ENDPROC(native_usergs_sysret64)
15908 .endm
15909
15910 .macro UNFAKE_STACK_FRAME
15911 - addq $8*6, %rsp
15912 - CFI_ADJUST_CFA_OFFSET -(6*8)
15913 + addq $8*6 + ARG_SKIP, %rsp
15914 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
15915 .endm
15916
15917 /*
15918 @@ -320,7 +604,7 @@ ENDPROC(native_usergs_sysret64)
15919 movq %rsp, %rsi
15920
15921 leaq -RBP(%rsp),%rdi /* arg1 for handler */
15922 - testl $3, CS(%rdi)
15923 + testb $3, CS(%rdi)
15924 je 1f
15925 SWAPGS
15926 /*
15927 @@ -356,9 +640,10 @@ ENTRY(save_rest)
15928 movq_cfi r15, R15+16
15929 movq %r11, 8(%rsp) /* return address */
15930 FIXUP_TOP_OF_STACK %r11, 16
15931 + pax_force_retaddr
15932 ret
15933 CFI_ENDPROC
15934 -END(save_rest)
15935 +ENDPROC(save_rest)
15936
15937 /* save complete stack frame */
15938 .pushsection .kprobes.text, "ax"
15939 @@ -387,9 +672,10 @@ ENTRY(save_paranoid)
15940 js 1f /* negative -> in kernel */
15941 SWAPGS
15942 xorl %ebx,%ebx
15943 -1: ret
15944 +1: pax_force_retaddr_bts
15945 + ret
15946 CFI_ENDPROC
15947 -END(save_paranoid)
15948 +ENDPROC(save_paranoid)
15949 .popsection
15950
15951 /*
15952 @@ -411,7 +697,7 @@ ENTRY(ret_from_fork)
15953
15954 RESTORE_REST
15955
15956 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15957 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
15958 jz retint_restore_args
15959
15960 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
15961 @@ -421,7 +707,7 @@ ENTRY(ret_from_fork)
15962 jmp ret_from_sys_call # go to the SYSRET fastpath
15963
15964 CFI_ENDPROC
15965 -END(ret_from_fork)
15966 +ENDPROC(ret_from_fork)
15967
15968 /*
15969 * System call entry. Up to 6 arguments in registers are supported.
15970 @@ -457,7 +743,7 @@ END(ret_from_fork)
15971 ENTRY(system_call)
15972 CFI_STARTPROC simple
15973 CFI_SIGNAL_FRAME
15974 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15975 + CFI_DEF_CFA rsp,0
15976 CFI_REGISTER rip,rcx
15977 /*CFI_REGISTER rflags,r11*/
15978 SWAPGS_UNSAFE_STACK
15979 @@ -470,21 +756,23 @@ GLOBAL(system_call_after_swapgs)
15980
15981 movq %rsp,PER_CPU_VAR(old_rsp)
15982 movq PER_CPU_VAR(kernel_stack),%rsp
15983 + SAVE_ARGS 8*6,0
15984 + pax_enter_kernel_user
15985 /*
15986 * No need to follow this irqs off/on section - it's straight
15987 * and short:
15988 */
15989 ENABLE_INTERRUPTS(CLBR_NONE)
15990 - SAVE_ARGS 8,0
15991 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15992 movq %rcx,RIP-ARGOFFSET(%rsp)
15993 CFI_REL_OFFSET rip,RIP-ARGOFFSET
15994 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15995 + GET_THREAD_INFO(%rcx)
15996 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
15997 jnz tracesys
15998 system_call_fastpath:
15999 cmpq $__NR_syscall_max,%rax
16000 ja badsys
16001 - movq %r10,%rcx
16002 + movq R10-ARGOFFSET(%rsp),%rcx
16003 call *sys_call_table(,%rax,8) # XXX: rip relative
16004 movq %rax,RAX-ARGOFFSET(%rsp)
16005 /*
16006 @@ -498,10 +786,13 @@ sysret_check:
16007 LOCKDEP_SYS_EXIT
16008 DISABLE_INTERRUPTS(CLBR_NONE)
16009 TRACE_IRQS_OFF
16010 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16011 + GET_THREAD_INFO(%rcx)
16012 + movl TI_flags(%rcx),%edx
16013 andl %edi,%edx
16014 jnz sysret_careful
16015 CFI_REMEMBER_STATE
16016 + pax_exit_kernel_user
16017 + pax_erase_kstack
16018 /*
16019 * sysretq will re-enable interrupts:
16020 */
16021 @@ -553,14 +844,18 @@ badsys:
16022 * jump back to the normal fast path.
16023 */
16024 auditsys:
16025 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16026 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16027 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16028 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16029 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16030 movq %rax,%rsi /* 2nd arg: syscall number */
16031 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16032 call __audit_syscall_entry
16033 +
16034 + pax_erase_kstack
16035 +
16036 LOAD_ARGS 0 /* reload call-clobbered registers */
16037 + pax_set_fptr_mask
16038 jmp system_call_fastpath
16039
16040 /*
16041 @@ -581,7 +876,7 @@ sysret_audit:
16042 /* Do syscall tracing */
16043 tracesys:
16044 #ifdef CONFIG_AUDITSYSCALL
16045 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16046 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16047 jz auditsys
16048 #endif
16049 SAVE_REST
16050 @@ -589,16 +884,20 @@ tracesys:
16051 FIXUP_TOP_OF_STACK %rdi
16052 movq %rsp,%rdi
16053 call syscall_trace_enter
16054 +
16055 + pax_erase_kstack
16056 +
16057 /*
16058 * Reload arg registers from stack in case ptrace changed them.
16059 * We don't reload %rax because syscall_trace_enter() returned
16060 * the value it wants us to use in the table lookup.
16061 */
16062 LOAD_ARGS ARGOFFSET, 1
16063 + pax_set_fptr_mask
16064 RESTORE_REST
16065 cmpq $__NR_syscall_max,%rax
16066 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16067 - movq %r10,%rcx /* fixup for C */
16068 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16069 call *sys_call_table(,%rax,8)
16070 movq %rax,RAX-ARGOFFSET(%rsp)
16071 /* Use IRET because user could have changed frame */
16072 @@ -619,6 +918,7 @@ GLOBAL(int_with_check)
16073 andl %edi,%edx
16074 jnz int_careful
16075 andl $~TS_COMPAT,TI_status(%rcx)
16076 + pax_erase_kstack
16077 jmp retint_swapgs
16078
16079 /* Either reschedule or signal or syscall exit tracking needed. */
16080 @@ -665,7 +965,7 @@ int_restore_rest:
16081 TRACE_IRQS_OFF
16082 jmp int_with_check
16083 CFI_ENDPROC
16084 -END(system_call)
16085 +ENDPROC(system_call)
16086
16087 /*
16088 * Certain special system calls that need to save a complete full stack frame.
16089 @@ -681,7 +981,7 @@ ENTRY(\label)
16090 call \func
16091 jmp ptregscall_common
16092 CFI_ENDPROC
16093 -END(\label)
16094 +ENDPROC(\label)
16095 .endm
16096
16097 PTREGSCALL stub_clone, sys_clone, %r8
16098 @@ -699,9 +999,10 @@ ENTRY(ptregscall_common)
16099 movq_cfi_restore R12+8, r12
16100 movq_cfi_restore RBP+8, rbp
16101 movq_cfi_restore RBX+8, rbx
16102 + pax_force_retaddr
16103 ret $REST_SKIP /* pop extended registers */
16104 CFI_ENDPROC
16105 -END(ptregscall_common)
16106 +ENDPROC(ptregscall_common)
16107
16108 ENTRY(stub_execve)
16109 CFI_STARTPROC
16110 @@ -716,7 +1017,7 @@ ENTRY(stub_execve)
16111 RESTORE_REST
16112 jmp int_ret_from_sys_call
16113 CFI_ENDPROC
16114 -END(stub_execve)
16115 +ENDPROC(stub_execve)
16116
16117 /*
16118 * sigreturn is special because it needs to restore all registers on return.
16119 @@ -734,7 +1035,7 @@ ENTRY(stub_rt_sigreturn)
16120 RESTORE_REST
16121 jmp int_ret_from_sys_call
16122 CFI_ENDPROC
16123 -END(stub_rt_sigreturn)
16124 +ENDPROC(stub_rt_sigreturn)
16125
16126 /*
16127 * Build the entry stubs and pointer table with some assembler magic.
16128 @@ -769,7 +1070,7 @@ vector=vector+1
16129 2: jmp common_interrupt
16130 .endr
16131 CFI_ENDPROC
16132 -END(irq_entries_start)
16133 +ENDPROC(irq_entries_start)
16134
16135 .previous
16136 END(interrupt)
16137 @@ -789,6 +1090,16 @@ END(interrupt)
16138 subq $ORIG_RAX-RBP, %rsp
16139 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16140 SAVE_ARGS_IRQ
16141 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16142 + testb $3, CS(%rdi)
16143 + jnz 1f
16144 + pax_enter_kernel
16145 + jmp 2f
16146 +1: pax_enter_kernel_user
16147 +2:
16148 +#else
16149 + pax_enter_kernel
16150 +#endif
16151 call \func
16152 .endm
16153
16154 @@ -820,7 +1131,7 @@ ret_from_intr:
16155
16156 exit_intr:
16157 GET_THREAD_INFO(%rcx)
16158 - testl $3,CS-ARGOFFSET(%rsp)
16159 + testb $3,CS-ARGOFFSET(%rsp)
16160 je retint_kernel
16161
16162 /* Interrupt came from user space */
16163 @@ -842,12 +1153,15 @@ retint_swapgs: /* return to user-space */
16164 * The iretq could re-enable interrupts:
16165 */
16166 DISABLE_INTERRUPTS(CLBR_ANY)
16167 + pax_exit_kernel_user
16168 TRACE_IRQS_IRETQ
16169 SWAPGS
16170 jmp restore_args
16171
16172 retint_restore_args: /* return to kernel space */
16173 DISABLE_INTERRUPTS(CLBR_ANY)
16174 + pax_exit_kernel
16175 + pax_force_retaddr RIP-ARGOFFSET
16176 /*
16177 * The iretq could re-enable interrupts:
16178 */
16179 @@ -936,7 +1250,7 @@ ENTRY(retint_kernel)
16180 #endif
16181
16182 CFI_ENDPROC
16183 -END(common_interrupt)
16184 +ENDPROC(common_interrupt)
16185 /*
16186 * End of kprobes section
16187 */
16188 @@ -953,7 +1267,7 @@ ENTRY(\sym)
16189 interrupt \do_sym
16190 jmp ret_from_intr
16191 CFI_ENDPROC
16192 -END(\sym)
16193 +ENDPROC(\sym)
16194 .endm
16195
16196 #ifdef CONFIG_SMP
16197 @@ -1026,12 +1340,22 @@ ENTRY(\sym)
16198 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16199 call error_entry
16200 DEFAULT_FRAME 0
16201 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16202 + testb $3, CS(%rsp)
16203 + jnz 1f
16204 + pax_enter_kernel
16205 + jmp 2f
16206 +1: pax_enter_kernel_user
16207 +2:
16208 +#else
16209 + pax_enter_kernel
16210 +#endif
16211 movq %rsp,%rdi /* pt_regs pointer */
16212 xorl %esi,%esi /* no error code */
16213 call \do_sym
16214 jmp error_exit /* %ebx: no swapgs flag */
16215 CFI_ENDPROC
16216 -END(\sym)
16217 +ENDPROC(\sym)
16218 .endm
16219
16220 .macro paranoidzeroentry sym do_sym
16221 @@ -1043,15 +1367,25 @@ ENTRY(\sym)
16222 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16223 call save_paranoid
16224 TRACE_IRQS_OFF
16225 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16226 + testb $3, CS(%rsp)
16227 + jnz 1f
16228 + pax_enter_kernel
16229 + jmp 2f
16230 +1: pax_enter_kernel_user
16231 +2:
16232 +#else
16233 + pax_enter_kernel
16234 +#endif
16235 movq %rsp,%rdi /* pt_regs pointer */
16236 xorl %esi,%esi /* no error code */
16237 call \do_sym
16238 jmp paranoid_exit /* %ebx: no swapgs flag */
16239 CFI_ENDPROC
16240 -END(\sym)
16241 +ENDPROC(\sym)
16242 .endm
16243
16244 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16245 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16246 .macro paranoidzeroentry_ist sym do_sym ist
16247 ENTRY(\sym)
16248 INTR_FRAME
16249 @@ -1061,14 +1395,30 @@ ENTRY(\sym)
16250 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16251 call save_paranoid
16252 TRACE_IRQS_OFF
16253 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16254 + testb $3, CS(%rsp)
16255 + jnz 1f
16256 + pax_enter_kernel
16257 + jmp 2f
16258 +1: pax_enter_kernel_user
16259 +2:
16260 +#else
16261 + pax_enter_kernel
16262 +#endif
16263 movq %rsp,%rdi /* pt_regs pointer */
16264 xorl %esi,%esi /* no error code */
16265 +#ifdef CONFIG_SMP
16266 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16267 + lea init_tss(%r12), %r12
16268 +#else
16269 + lea init_tss(%rip), %r12
16270 +#endif
16271 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16272 call \do_sym
16273 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16274 jmp paranoid_exit /* %ebx: no swapgs flag */
16275 CFI_ENDPROC
16276 -END(\sym)
16277 +ENDPROC(\sym)
16278 .endm
16279
16280 .macro errorentry sym do_sym
16281 @@ -1079,13 +1429,23 @@ ENTRY(\sym)
16282 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16283 call error_entry
16284 DEFAULT_FRAME 0
16285 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16286 + testb $3, CS(%rsp)
16287 + jnz 1f
16288 + pax_enter_kernel
16289 + jmp 2f
16290 +1: pax_enter_kernel_user
16291 +2:
16292 +#else
16293 + pax_enter_kernel
16294 +#endif
16295 movq %rsp,%rdi /* pt_regs pointer */
16296 movq ORIG_RAX(%rsp),%rsi /* get error code */
16297 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16298 call \do_sym
16299 jmp error_exit /* %ebx: no swapgs flag */
16300 CFI_ENDPROC
16301 -END(\sym)
16302 +ENDPROC(\sym)
16303 .endm
16304
16305 /* error code is on the stack already */
16306 @@ -1098,13 +1458,23 @@ ENTRY(\sym)
16307 call save_paranoid
16308 DEFAULT_FRAME 0
16309 TRACE_IRQS_OFF
16310 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16311 + testb $3, CS(%rsp)
16312 + jnz 1f
16313 + pax_enter_kernel
16314 + jmp 2f
16315 +1: pax_enter_kernel_user
16316 +2:
16317 +#else
16318 + pax_enter_kernel
16319 +#endif
16320 movq %rsp,%rdi /* pt_regs pointer */
16321 movq ORIG_RAX(%rsp),%rsi /* get error code */
16322 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16323 call \do_sym
16324 jmp paranoid_exit /* %ebx: no swapgs flag */
16325 CFI_ENDPROC
16326 -END(\sym)
16327 +ENDPROC(\sym)
16328 .endm
16329
16330 zeroentry divide_error do_divide_error
16331 @@ -1134,9 +1504,10 @@ gs_change:
16332 2: mfence /* workaround */
16333 SWAPGS
16334 popfq_cfi
16335 + pax_force_retaddr
16336 ret
16337 CFI_ENDPROC
16338 -END(native_load_gs_index)
16339 +ENDPROC(native_load_gs_index)
16340
16341 .section __ex_table,"a"
16342 .align 8
16343 @@ -1158,13 +1529,14 @@ ENTRY(kernel_thread_helper)
16344 * Here we are in the child and the registers are set as they were
16345 * at kernel_thread() invocation in the parent.
16346 */
16347 + pax_force_fptr %rsi
16348 call *%rsi
16349 # exit
16350 mov %eax, %edi
16351 call do_exit
16352 ud2 # padding for call trace
16353 CFI_ENDPROC
16354 -END(kernel_thread_helper)
16355 +ENDPROC(kernel_thread_helper)
16356
16357 /*
16358 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16359 @@ -1191,11 +1563,11 @@ ENTRY(kernel_execve)
16360 RESTORE_REST
16361 testq %rax,%rax
16362 je int_ret_from_sys_call
16363 - RESTORE_ARGS
16364 UNFAKE_STACK_FRAME
16365 + pax_force_retaddr
16366 ret
16367 CFI_ENDPROC
16368 -END(kernel_execve)
16369 +ENDPROC(kernel_execve)
16370
16371 /* Call softirq on interrupt stack. Interrupts are off. */
16372 ENTRY(call_softirq)
16373 @@ -1213,9 +1585,10 @@ ENTRY(call_softirq)
16374 CFI_DEF_CFA_REGISTER rsp
16375 CFI_ADJUST_CFA_OFFSET -8
16376 decl PER_CPU_VAR(irq_count)
16377 + pax_force_retaddr
16378 ret
16379 CFI_ENDPROC
16380 -END(call_softirq)
16381 +ENDPROC(call_softirq)
16382
16383 #ifdef CONFIG_XEN
16384 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16385 @@ -1253,7 +1626,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16386 decl PER_CPU_VAR(irq_count)
16387 jmp error_exit
16388 CFI_ENDPROC
16389 -END(xen_do_hypervisor_callback)
16390 +ENDPROC(xen_do_hypervisor_callback)
16391
16392 /*
16393 * Hypervisor uses this for application faults while it executes.
16394 @@ -1312,7 +1685,7 @@ ENTRY(xen_failsafe_callback)
16395 SAVE_ALL
16396 jmp error_exit
16397 CFI_ENDPROC
16398 -END(xen_failsafe_callback)
16399 +ENDPROC(xen_failsafe_callback)
16400
16401 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16402 xen_hvm_callback_vector xen_evtchn_do_upcall
16403 @@ -1361,16 +1734,31 @@ ENTRY(paranoid_exit)
16404 TRACE_IRQS_OFF
16405 testl %ebx,%ebx /* swapgs needed? */
16406 jnz paranoid_restore
16407 - testl $3,CS(%rsp)
16408 + testb $3,CS(%rsp)
16409 jnz paranoid_userspace
16410 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16411 + pax_exit_kernel
16412 + TRACE_IRQS_IRETQ 0
16413 + SWAPGS_UNSAFE_STACK
16414 + RESTORE_ALL 8
16415 + pax_force_retaddr_bts
16416 + jmp irq_return
16417 +#endif
16418 paranoid_swapgs:
16419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16420 + pax_exit_kernel_user
16421 +#else
16422 + pax_exit_kernel
16423 +#endif
16424 TRACE_IRQS_IRETQ 0
16425 SWAPGS_UNSAFE_STACK
16426 RESTORE_ALL 8
16427 jmp irq_return
16428 paranoid_restore:
16429 + pax_exit_kernel
16430 TRACE_IRQS_IRETQ 0
16431 RESTORE_ALL 8
16432 + pax_force_retaddr_bts
16433 jmp irq_return
16434 paranoid_userspace:
16435 GET_THREAD_INFO(%rcx)
16436 @@ -1399,7 +1787,7 @@ paranoid_schedule:
16437 TRACE_IRQS_OFF
16438 jmp paranoid_userspace
16439 CFI_ENDPROC
16440 -END(paranoid_exit)
16441 +ENDPROC(paranoid_exit)
16442
16443 /*
16444 * Exception entry point. This expects an error code/orig_rax on the stack.
16445 @@ -1426,12 +1814,13 @@ ENTRY(error_entry)
16446 movq_cfi r14, R14+8
16447 movq_cfi r15, R15+8
16448 xorl %ebx,%ebx
16449 - testl $3,CS+8(%rsp)
16450 + testb $3,CS+8(%rsp)
16451 je error_kernelspace
16452 error_swapgs:
16453 SWAPGS
16454 error_sti:
16455 TRACE_IRQS_OFF
16456 + pax_force_retaddr_bts
16457 ret
16458
16459 /*
16460 @@ -1458,7 +1847,7 @@ bstep_iret:
16461 movq %rcx,RIP+8(%rsp)
16462 jmp error_swapgs
16463 CFI_ENDPROC
16464 -END(error_entry)
16465 +ENDPROC(error_entry)
16466
16467
16468 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16469 @@ -1478,7 +1867,7 @@ ENTRY(error_exit)
16470 jnz retint_careful
16471 jmp retint_swapgs
16472 CFI_ENDPROC
16473 -END(error_exit)
16474 +ENDPROC(error_exit)
16475
16476 /*
16477 * Test if a given stack is an NMI stack or not.
16478 @@ -1535,9 +1924,11 @@ ENTRY(nmi)
16479 * If %cs was not the kernel segment, then the NMI triggered in user
16480 * space, which means it is definitely not nested.
16481 */
16482 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16483 + je 1f
16484 cmpl $__KERNEL_CS, 16(%rsp)
16485 jne first_nmi
16486 -
16487 +1:
16488 /*
16489 * Check the special variable on the stack to see if NMIs are
16490 * executing.
16491 @@ -1659,6 +2050,16 @@ restart_nmi:
16492 */
16493 call save_paranoid
16494 DEFAULT_FRAME 0
16495 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16496 + testb $3, CS(%rsp)
16497 + jnz 1f
16498 + pax_enter_kernel
16499 + jmp 2f
16500 +1: pax_enter_kernel_user
16501 +2:
16502 +#else
16503 + pax_enter_kernel
16504 +#endif
16505 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16506 movq %rsp,%rdi
16507 movq $-1,%rsi
16508 @@ -1666,14 +2067,25 @@ restart_nmi:
16509 testl %ebx,%ebx /* swapgs needed? */
16510 jnz nmi_restore
16511 nmi_swapgs:
16512 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16513 + pax_exit_kernel_user
16514 +#else
16515 + pax_exit_kernel
16516 +#endif
16517 SWAPGS_UNSAFE_STACK
16518 + RESTORE_ALL 8
16519 + /* Clear the NMI executing stack variable */
16520 + movq $0, 10*8(%rsp)
16521 + jmp irq_return
16522 nmi_restore:
16523 + pax_exit_kernel
16524 RESTORE_ALL 8
16525 + pax_force_retaddr_bts
16526 /* Clear the NMI executing stack variable */
16527 movq $0, 10*8(%rsp)
16528 jmp irq_return
16529 CFI_ENDPROC
16530 -END(nmi)
16531 +ENDPROC(nmi)
16532
16533 /*
16534 * If an NMI hit an iret because of an exception or breakpoint,
16535 @@ -1700,7 +2112,7 @@ ENTRY(ignore_sysret)
16536 mov $-ENOSYS,%eax
16537 sysret
16538 CFI_ENDPROC
16539 -END(ignore_sysret)
16540 +ENDPROC(ignore_sysret)
16541
16542 /*
16543 * End of kprobes section
16544 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16545 index c9a281f..ce2f317 100644
16546 --- a/arch/x86/kernel/ftrace.c
16547 +++ b/arch/x86/kernel/ftrace.c
16548 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
16549 static const void *mod_code_newcode; /* holds the text to write to the IP */
16550
16551 static unsigned nmi_wait_count;
16552 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
16553 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
16554
16555 int ftrace_arch_read_dyn_info(char *buf, int size)
16556 {
16557 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
16558
16559 r = snprintf(buf, size, "%u %u",
16560 nmi_wait_count,
16561 - atomic_read(&nmi_update_count));
16562 + atomic_read_unchecked(&nmi_update_count));
16563 return r;
16564 }
16565
16566 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
16567
16568 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
16569 smp_rmb();
16570 + pax_open_kernel();
16571 ftrace_mod_code();
16572 - atomic_inc(&nmi_update_count);
16573 + pax_close_kernel();
16574 + atomic_inc_unchecked(&nmi_update_count);
16575 }
16576 /* Must have previous changes seen before executions */
16577 smp_mb();
16578 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
16579 {
16580 unsigned char replaced[MCOUNT_INSN_SIZE];
16581
16582 + ip = ktla_ktva(ip);
16583 +
16584 /*
16585 * Note: Due to modules and __init, code can
16586 * disappear and change, we need to protect against faulting
16587 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16588 unsigned char old[MCOUNT_INSN_SIZE], *new;
16589 int ret;
16590
16591 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16592 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16593 new = ftrace_call_replace(ip, (unsigned long)func);
16594 ret = ftrace_modify_code(ip, old, new);
16595
16596 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16597 {
16598 unsigned char code[MCOUNT_INSN_SIZE];
16599
16600 + ip = ktla_ktva(ip);
16601 +
16602 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16603 return -EFAULT;
16604
16605 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16606 index 51ff186..9e77418 100644
16607 --- a/arch/x86/kernel/head32.c
16608 +++ b/arch/x86/kernel/head32.c
16609 @@ -19,6 +19,7 @@
16610 #include <asm/io_apic.h>
16611 #include <asm/bios_ebda.h>
16612 #include <asm/tlbflush.h>
16613 +#include <asm/boot.h>
16614
16615 static void __init i386_default_early_setup(void)
16616 {
16617 @@ -31,8 +32,7 @@ static void __init i386_default_early_setup(void)
16618
16619 void __init i386_start_kernel(void)
16620 {
16621 - memblock_reserve(__pa_symbol(&_text),
16622 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16623 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16624
16625 #ifdef CONFIG_BLK_DEV_INITRD
16626 /* Reserve INITRD */
16627 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16628 index ce0be7c..c41476e 100644
16629 --- a/arch/x86/kernel/head_32.S
16630 +++ b/arch/x86/kernel/head_32.S
16631 @@ -25,6 +25,12 @@
16632 /* Physical address */
16633 #define pa(X) ((X) - __PAGE_OFFSET)
16634
16635 +#ifdef CONFIG_PAX_KERNEXEC
16636 +#define ta(X) (X)
16637 +#else
16638 +#define ta(X) ((X) - __PAGE_OFFSET)
16639 +#endif
16640 +
16641 /*
16642 * References to members of the new_cpu_data structure.
16643 */
16644 @@ -54,11 +60,7 @@
16645 * and small than max_low_pfn, otherwise will waste some page table entries
16646 */
16647
16648 -#if PTRS_PER_PMD > 1
16649 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16650 -#else
16651 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16652 -#endif
16653 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16654
16655 /* Number of possible pages in the lowmem region */
16656 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16657 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16658 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16659
16660 /*
16661 + * Real beginning of normal "text" segment
16662 + */
16663 +ENTRY(stext)
16664 +ENTRY(_stext)
16665 +
16666 +/*
16667 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16668 * %esi points to the real-mode code as a 32-bit pointer.
16669 * CS and DS must be 4 GB flat segments, but we don't depend on
16670 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16671 * can.
16672 */
16673 __HEAD
16674 +
16675 +#ifdef CONFIG_PAX_KERNEXEC
16676 + jmp startup_32
16677 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16678 +.fill PAGE_SIZE-5,1,0xcc
16679 +#endif
16680 +
16681 ENTRY(startup_32)
16682 movl pa(stack_start),%ecx
16683
16684 @@ -105,6 +120,57 @@ ENTRY(startup_32)
16685 2:
16686 leal -__PAGE_OFFSET(%ecx),%esp
16687
16688 +#ifdef CONFIG_SMP
16689 + movl $pa(cpu_gdt_table),%edi
16690 + movl $__per_cpu_load,%eax
16691 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16692 + rorl $16,%eax
16693 + movb %al,__KERNEL_PERCPU + 4(%edi)
16694 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16695 + movl $__per_cpu_end - 1,%eax
16696 + subl $__per_cpu_start,%eax
16697 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16698 +#endif
16699 +
16700 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16701 + movl $NR_CPUS,%ecx
16702 + movl $pa(cpu_gdt_table),%edi
16703 +1:
16704 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16705 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16706 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16707 + addl $PAGE_SIZE_asm,%edi
16708 + loop 1b
16709 +#endif
16710 +
16711 +#ifdef CONFIG_PAX_KERNEXEC
16712 + movl $pa(boot_gdt),%edi
16713 + movl $__LOAD_PHYSICAL_ADDR,%eax
16714 + movw %ax,__BOOT_CS + 2(%edi)
16715 + rorl $16,%eax
16716 + movb %al,__BOOT_CS + 4(%edi)
16717 + movb %ah,__BOOT_CS + 7(%edi)
16718 + rorl $16,%eax
16719 +
16720 + ljmp $(__BOOT_CS),$1f
16721 +1:
16722 +
16723 + movl $NR_CPUS,%ecx
16724 + movl $pa(cpu_gdt_table),%edi
16725 + addl $__PAGE_OFFSET,%eax
16726 +1:
16727 + movw %ax,__KERNEL_CS + 2(%edi)
16728 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16729 + rorl $16,%eax
16730 + movb %al,__KERNEL_CS + 4(%edi)
16731 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16732 + movb %ah,__KERNEL_CS + 7(%edi)
16733 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16734 + rorl $16,%eax
16735 + addl $PAGE_SIZE_asm,%edi
16736 + loop 1b
16737 +#endif
16738 +
16739 /*
16740 * Clear BSS first so that there are no surprises...
16741 */
16742 @@ -195,8 +261,11 @@ ENTRY(startup_32)
16743 movl %eax, pa(max_pfn_mapped)
16744
16745 /* Do early initialization of the fixmap area */
16746 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16747 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16748 +#ifdef CONFIG_COMPAT_VDSO
16749 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16750 +#else
16751 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16752 +#endif
16753 #else /* Not PAE */
16754
16755 page_pde_offset = (__PAGE_OFFSET >> 20);
16756 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16757 movl %eax, pa(max_pfn_mapped)
16758
16759 /* Do early initialization of the fixmap area */
16760 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16761 - movl %eax,pa(initial_page_table+0xffc)
16762 +#ifdef CONFIG_COMPAT_VDSO
16763 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16764 +#else
16765 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16766 +#endif
16767 #endif
16768
16769 #ifdef CONFIG_PARAVIRT
16770 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16771 cmpl $num_subarch_entries, %eax
16772 jae bad_subarch
16773
16774 - movl pa(subarch_entries)(,%eax,4), %eax
16775 - subl $__PAGE_OFFSET, %eax
16776 - jmp *%eax
16777 + jmp *pa(subarch_entries)(,%eax,4)
16778
16779 bad_subarch:
16780 WEAK(lguest_entry)
16781 @@ -255,10 +325,10 @@ WEAK(xen_entry)
16782 __INITDATA
16783
16784 subarch_entries:
16785 - .long default_entry /* normal x86/PC */
16786 - .long lguest_entry /* lguest hypervisor */
16787 - .long xen_entry /* Xen hypervisor */
16788 - .long default_entry /* Moorestown MID */
16789 + .long ta(default_entry) /* normal x86/PC */
16790 + .long ta(lguest_entry) /* lguest hypervisor */
16791 + .long ta(xen_entry) /* Xen hypervisor */
16792 + .long ta(default_entry) /* Moorestown MID */
16793 num_subarch_entries = (. - subarch_entries) / 4
16794 .previous
16795 #else
16796 @@ -312,6 +382,7 @@ default_entry:
16797 orl %edx,%eax
16798 movl %eax,%cr4
16799
16800 +#ifdef CONFIG_X86_PAE
16801 testb $X86_CR4_PAE, %al # check if PAE is enabled
16802 jz 6f
16803
16804 @@ -340,6 +411,9 @@ default_entry:
16805 /* Make changes effective */
16806 wrmsr
16807
16808 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16809 +#endif
16810 +
16811 6:
16812
16813 /*
16814 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
16815 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
16816 movl %eax,%ss # after changing gdt.
16817
16818 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
16819 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
16820 movl %eax,%ds
16821 movl %eax,%es
16822
16823 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
16824 */
16825 cmpb $0,ready
16826 jne 1f
16827 - movl $gdt_page,%eax
16828 + movl $cpu_gdt_table,%eax
16829 movl $stack_canary,%ecx
16830 +#ifdef CONFIG_SMP
16831 + addl $__per_cpu_load,%ecx
16832 +#endif
16833 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
16834 shrl $16, %ecx
16835 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
16836 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
16837 1:
16838 -#endif
16839 movl $(__KERNEL_STACK_CANARY),%eax
16840 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16841 + movl $(__USER_DS),%eax
16842 +#else
16843 + xorl %eax,%eax
16844 +#endif
16845 movl %eax,%gs
16846
16847 xorl %eax,%eax # Clear LDT
16848 @@ -558,22 +639,22 @@ early_page_fault:
16849 jmp early_fault
16850
16851 early_fault:
16852 - cld
16853 #ifdef CONFIG_PRINTK
16854 + cmpl $1,%ss:early_recursion_flag
16855 + je hlt_loop
16856 + incl %ss:early_recursion_flag
16857 + cld
16858 pusha
16859 movl $(__KERNEL_DS),%eax
16860 movl %eax,%ds
16861 movl %eax,%es
16862 - cmpl $2,early_recursion_flag
16863 - je hlt_loop
16864 - incl early_recursion_flag
16865 movl %cr2,%eax
16866 pushl %eax
16867 pushl %edx /* trapno */
16868 pushl $fault_msg
16869 call printk
16870 +; call dump_stack
16871 #endif
16872 - call dump_stack
16873 hlt_loop:
16874 hlt
16875 jmp hlt_loop
16876 @@ -581,8 +662,11 @@ hlt_loop:
16877 /* This is the default interrupt "handler" :-) */
16878 ALIGN
16879 ignore_int:
16880 - cld
16881 #ifdef CONFIG_PRINTK
16882 + cmpl $2,%ss:early_recursion_flag
16883 + je hlt_loop
16884 + incl %ss:early_recursion_flag
16885 + cld
16886 pushl %eax
16887 pushl %ecx
16888 pushl %edx
16889 @@ -591,9 +675,6 @@ ignore_int:
16890 movl $(__KERNEL_DS),%eax
16891 movl %eax,%ds
16892 movl %eax,%es
16893 - cmpl $2,early_recursion_flag
16894 - je hlt_loop
16895 - incl early_recursion_flag
16896 pushl 16(%esp)
16897 pushl 24(%esp)
16898 pushl 32(%esp)
16899 @@ -622,29 +703,43 @@ ENTRY(initial_code)
16900 /*
16901 * BSS section
16902 */
16903 -__PAGE_ALIGNED_BSS
16904 - .align PAGE_SIZE
16905 #ifdef CONFIG_X86_PAE
16906 +.section .initial_pg_pmd,"a",@progbits
16907 initial_pg_pmd:
16908 .fill 1024*KPMDS,4,0
16909 #else
16910 +.section .initial_page_table,"a",@progbits
16911 ENTRY(initial_page_table)
16912 .fill 1024,4,0
16913 #endif
16914 +.section .initial_pg_fixmap,"a",@progbits
16915 initial_pg_fixmap:
16916 .fill 1024,4,0
16917 +.section .empty_zero_page,"a",@progbits
16918 ENTRY(empty_zero_page)
16919 .fill 4096,1,0
16920 +.section .swapper_pg_dir,"a",@progbits
16921 ENTRY(swapper_pg_dir)
16922 +#ifdef CONFIG_X86_PAE
16923 + .fill 4,8,0
16924 +#else
16925 .fill 1024,4,0
16926 +#endif
16927 +
16928 +/*
16929 + * The IDT has to be page-aligned to simplify the Pentium
16930 + * F0 0F bug workaround.. We have a special link segment
16931 + * for this.
16932 + */
16933 +.section .idt,"a",@progbits
16934 +ENTRY(idt_table)
16935 + .fill 256,8,0
16936
16937 /*
16938 * This starts the data section.
16939 */
16940 #ifdef CONFIG_X86_PAE
16941 -__PAGE_ALIGNED_DATA
16942 - /* Page-aligned for the benefit of paravirt? */
16943 - .align PAGE_SIZE
16944 +.section .initial_page_table,"a",@progbits
16945 ENTRY(initial_page_table)
16946 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
16947 # if KPMDS == 3
16948 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
16949 # error "Kernel PMDs should be 1, 2 or 3"
16950 # endif
16951 .align PAGE_SIZE /* needs to be page-sized too */
16952 +
16953 +#ifdef CONFIG_PAX_PER_CPU_PGD
16954 +ENTRY(cpu_pgd)
16955 + .rept NR_CPUS
16956 + .fill 4,8,0
16957 + .endr
16958 +#endif
16959 +
16960 #endif
16961
16962 .data
16963 .balign 4
16964 ENTRY(stack_start)
16965 - .long init_thread_union+THREAD_SIZE
16966 + .long init_thread_union+THREAD_SIZE-8
16967
16968 +ready: .byte 0
16969 +
16970 +.section .rodata,"a",@progbits
16971 early_recursion_flag:
16972 .long 0
16973
16974 -ready: .byte 0
16975 -
16976 int_msg:
16977 .asciz "Unknown interrupt or fault at: %p %p %p\n"
16978
16979 @@ -707,7 +811,7 @@ fault_msg:
16980 .word 0 # 32 bit align gdt_desc.address
16981 boot_gdt_descr:
16982 .word __BOOT_DS+7
16983 - .long boot_gdt - __PAGE_OFFSET
16984 + .long pa(boot_gdt)
16985
16986 .word 0 # 32-bit align idt_desc.address
16987 idt_descr:
16988 @@ -718,7 +822,7 @@ idt_descr:
16989 .word 0 # 32 bit align gdt_desc.address
16990 ENTRY(early_gdt_descr)
16991 .word GDT_ENTRIES*8-1
16992 - .long gdt_page /* Overwritten for secondary CPUs */
16993 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
16994
16995 /*
16996 * The boot_gdt must mirror the equivalent in setup.S and is
16997 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
16998 .align L1_CACHE_BYTES
16999 ENTRY(boot_gdt)
17000 .fill GDT_ENTRY_BOOT_CS,8,0
17001 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17002 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17003 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17004 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17005 +
17006 + .align PAGE_SIZE_asm
17007 +ENTRY(cpu_gdt_table)
17008 + .rept NR_CPUS
17009 + .quad 0x0000000000000000 /* NULL descriptor */
17010 + .quad 0x0000000000000000 /* 0x0b reserved */
17011 + .quad 0x0000000000000000 /* 0x13 reserved */
17012 + .quad 0x0000000000000000 /* 0x1b reserved */
17013 +
17014 +#ifdef CONFIG_PAX_KERNEXEC
17015 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17016 +#else
17017 + .quad 0x0000000000000000 /* 0x20 unused */
17018 +#endif
17019 +
17020 + .quad 0x0000000000000000 /* 0x28 unused */
17021 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17022 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17023 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17024 + .quad 0x0000000000000000 /* 0x4b reserved */
17025 + .quad 0x0000000000000000 /* 0x53 reserved */
17026 + .quad 0x0000000000000000 /* 0x5b reserved */
17027 +
17028 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17029 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17030 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17031 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17032 +
17033 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17034 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17035 +
17036 + /*
17037 + * Segments used for calling PnP BIOS have byte granularity.
17038 + * The code segments and data segments have fixed 64k limits,
17039 + * the transfer segment sizes are set at run time.
17040 + */
17041 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17042 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17043 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17044 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17045 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17046 +
17047 + /*
17048 + * The APM segments have byte granularity and their bases
17049 + * are set at run time. All have 64k limits.
17050 + */
17051 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17052 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17053 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17054 +
17055 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17056 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17057 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17058 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17059 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17060 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17061 +
17062 + /* Be sure this is zeroed to avoid false validations in Xen */
17063 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17064 + .endr
17065 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17066 index 40f4eb3..6d24d9d 100644
17067 --- a/arch/x86/kernel/head_64.S
17068 +++ b/arch/x86/kernel/head_64.S
17069 @@ -19,6 +19,8 @@
17070 #include <asm/cache.h>
17071 #include <asm/processor-flags.h>
17072 #include <asm/percpu.h>
17073 +#include <asm/cpufeature.h>
17074 +#include <asm/alternative-asm.h>
17075
17076 #ifdef CONFIG_PARAVIRT
17077 #include <asm/asm-offsets.h>
17078 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17079 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17080 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17081 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17082 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17083 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17084 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17085 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17086 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17087 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17088
17089 .text
17090 __HEAD
17091 @@ -85,35 +93,23 @@ startup_64:
17092 */
17093 addq %rbp, init_level4_pgt + 0(%rip)
17094 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17095 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17096 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17097 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17098 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17099
17100 addq %rbp, level3_ident_pgt + 0(%rip)
17101 +#ifndef CONFIG_XEN
17102 + addq %rbp, level3_ident_pgt + 8(%rip)
17103 +#endif
17104
17105 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17106 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17107 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17108 +
17109 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17110 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17111
17112 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17113 -
17114 - /* Add an Identity mapping if I am above 1G */
17115 - leaq _text(%rip), %rdi
17116 - andq $PMD_PAGE_MASK, %rdi
17117 -
17118 - movq %rdi, %rax
17119 - shrq $PUD_SHIFT, %rax
17120 - andq $(PTRS_PER_PUD - 1), %rax
17121 - jz ident_complete
17122 -
17123 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17124 - leaq level3_ident_pgt(%rip), %rbx
17125 - movq %rdx, 0(%rbx, %rax, 8)
17126 -
17127 - movq %rdi, %rax
17128 - shrq $PMD_SHIFT, %rax
17129 - andq $(PTRS_PER_PMD - 1), %rax
17130 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17131 - leaq level2_spare_pgt(%rip), %rbx
17132 - movq %rdx, 0(%rbx, %rax, 8)
17133 -ident_complete:
17134 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17135
17136 /*
17137 * Fixup the kernel text+data virtual addresses. Note that
17138 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
17139 * after the boot processor executes this code.
17140 */
17141
17142 - /* Enable PAE mode and PGE */
17143 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17144 + /* Enable PAE mode and PSE/PGE */
17145 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17146 movq %rax, %cr4
17147
17148 /* Setup early boot stage 4 level pagetables. */
17149 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
17150 movl $MSR_EFER, %ecx
17151 rdmsr
17152 btsl $_EFER_SCE, %eax /* Enable System Call */
17153 - btl $20,%edi /* No Execute supported? */
17154 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17155 jnc 1f
17156 btsl $_EFER_NX, %eax
17157 + leaq init_level4_pgt(%rip), %rdi
17158 +#ifndef CONFIG_EFI
17159 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17160 +#endif
17161 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17162 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17163 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17164 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17165 1: wrmsr /* Make changes effective */
17166
17167 /* Setup cr0 */
17168 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
17169 * jump. In addition we need to ensure %cs is set so we make this
17170 * a far return.
17171 */
17172 + pax_set_fptr_mask
17173 movq initial_code(%rip),%rax
17174 pushq $0 # fake return address to stop unwinder
17175 pushq $__KERNEL_CS # set correct cs
17176 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
17177 bad_address:
17178 jmp bad_address
17179
17180 - .section ".init.text","ax"
17181 + __INIT
17182 #ifdef CONFIG_EARLY_PRINTK
17183 .globl early_idt_handlers
17184 early_idt_handlers:
17185 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
17186 #endif /* EARLY_PRINTK */
17187 1: hlt
17188 jmp 1b
17189 + .previous
17190
17191 #ifdef CONFIG_EARLY_PRINTK
17192 + __INITDATA
17193 early_recursion_flag:
17194 .long 0
17195 + .previous
17196
17197 + .section .rodata,"a",@progbits
17198 early_idt_msg:
17199 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17200 early_idt_ripmsg:
17201 .asciz "RIP %s\n"
17202 + .previous
17203 #endif /* CONFIG_EARLY_PRINTK */
17204 - .previous
17205
17206 + .section .rodata,"a",@progbits
17207 #define NEXT_PAGE(name) \
17208 .balign PAGE_SIZE; \
17209 ENTRY(name)
17210 @@ -338,7 +348,6 @@ ENTRY(name)
17211 i = i + 1 ; \
17212 .endr
17213
17214 - .data
17215 /*
17216 * This default setting generates an ident mapping at address 0x100000
17217 * and a mapping for the kernel that precisely maps virtual address
17218 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
17219 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17220 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17221 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17222 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17223 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17224 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17225 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17226 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17227 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17228 .org init_level4_pgt + L4_START_KERNEL*8, 0
17229 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17230 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17231
17232 +#ifdef CONFIG_PAX_PER_CPU_PGD
17233 +NEXT_PAGE(cpu_pgd)
17234 + .rept NR_CPUS
17235 + .fill 512,8,0
17236 + .endr
17237 +#endif
17238 +
17239 NEXT_PAGE(level3_ident_pgt)
17240 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17241 +#ifdef CONFIG_XEN
17242 .fill 511,8,0
17243 +#else
17244 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17245 + .fill 510,8,0
17246 +#endif
17247 +
17248 +NEXT_PAGE(level3_vmalloc_start_pgt)
17249 + .fill 512,8,0
17250 +
17251 +NEXT_PAGE(level3_vmalloc_end_pgt)
17252 + .fill 512,8,0
17253 +
17254 +NEXT_PAGE(level3_vmemmap_pgt)
17255 + .fill L3_VMEMMAP_START,8,0
17256 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17257
17258 NEXT_PAGE(level3_kernel_pgt)
17259 .fill L3_START_KERNEL,8,0
17260 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
17261 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17262 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17263
17264 +NEXT_PAGE(level2_vmemmap_pgt)
17265 + .fill 512,8,0
17266 +
17267 NEXT_PAGE(level2_fixmap_pgt)
17268 - .fill 506,8,0
17269 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17270 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17271 - .fill 5,8,0
17272 + .fill 507,8,0
17273 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17274 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17275 + .fill 4,8,0
17276
17277 -NEXT_PAGE(level1_fixmap_pgt)
17278 +NEXT_PAGE(level1_vsyscall_pgt)
17279 .fill 512,8,0
17280
17281 -NEXT_PAGE(level2_ident_pgt)
17282 - /* Since I easily can, map the first 1G.
17283 + /* Since I easily can, map the first 2G.
17284 * Don't set NX because code runs from these pages.
17285 */
17286 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17287 +NEXT_PAGE(level2_ident_pgt)
17288 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17289
17290 NEXT_PAGE(level2_kernel_pgt)
17291 /*
17292 @@ -389,37 +429,59 @@ NEXT_PAGE(level2_kernel_pgt)
17293 * If you want to increase this then increase MODULES_VADDR
17294 * too.)
17295 */
17296 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17297 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17298 -
17299 -NEXT_PAGE(level2_spare_pgt)
17300 - .fill 512, 8, 0
17301 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17302
17303 #undef PMDS
17304 #undef NEXT_PAGE
17305
17306 - .data
17307 + .align PAGE_SIZE
17308 +ENTRY(cpu_gdt_table)
17309 + .rept NR_CPUS
17310 + .quad 0x0000000000000000 /* NULL descriptor */
17311 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17312 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17313 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17314 + .quad 0x00cffb000000ffff /* __USER32_CS */
17315 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17316 + .quad 0x00affb000000ffff /* __USER_CS */
17317 +
17318 +#ifdef CONFIG_PAX_KERNEXEC
17319 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17320 +#else
17321 + .quad 0x0 /* unused */
17322 +#endif
17323 +
17324 + .quad 0,0 /* TSS */
17325 + .quad 0,0 /* LDT */
17326 + .quad 0,0,0 /* three TLS descriptors */
17327 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17328 + /* asm/segment.h:GDT_ENTRIES must match this */
17329 +
17330 + /* zero the remaining page */
17331 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17332 + .endr
17333 +
17334 .align 16
17335 .globl early_gdt_descr
17336 early_gdt_descr:
17337 .word GDT_ENTRIES*8-1
17338 early_gdt_descr_base:
17339 - .quad INIT_PER_CPU_VAR(gdt_page)
17340 + .quad cpu_gdt_table
17341
17342 ENTRY(phys_base)
17343 /* This must match the first entry in level2_kernel_pgt */
17344 .quad 0x0000000000000000
17345
17346 #include "../../x86/xen/xen-head.S"
17347 -
17348 - .section .bss, "aw", @nobits
17349 +
17350 + .section .rodata,"a",@progbits
17351 .align L1_CACHE_BYTES
17352 ENTRY(idt_table)
17353 - .skip IDT_ENTRIES * 16
17354 + .fill 512,8,0
17355
17356 .align L1_CACHE_BYTES
17357 ENTRY(nmi_idt_table)
17358 - .skip IDT_ENTRIES * 16
17359 + .fill 512,8,0
17360
17361 __PAGE_ALIGNED_BSS
17362 .align PAGE_SIZE
17363 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17364 index 9c3bd4a..e1d9b35 100644
17365 --- a/arch/x86/kernel/i386_ksyms_32.c
17366 +++ b/arch/x86/kernel/i386_ksyms_32.c
17367 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17368 EXPORT_SYMBOL(cmpxchg8b_emu);
17369 #endif
17370
17371 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17372 +
17373 /* Networking helper routines. */
17374 EXPORT_SYMBOL(csum_partial_copy_generic);
17375 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17376 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17377
17378 EXPORT_SYMBOL(__get_user_1);
17379 EXPORT_SYMBOL(__get_user_2);
17380 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17381
17382 EXPORT_SYMBOL(csum_partial);
17383 EXPORT_SYMBOL(empty_zero_page);
17384 +
17385 +#ifdef CONFIG_PAX_KERNEXEC
17386 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17387 +#endif
17388 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17389 index 6104852..6114160 100644
17390 --- a/arch/x86/kernel/i8259.c
17391 +++ b/arch/x86/kernel/i8259.c
17392 @@ -210,7 +210,7 @@ spurious_8259A_irq:
17393 "spurious 8259A interrupt: IRQ%d.\n", irq);
17394 spurious_irq_mask |= irqmask;
17395 }
17396 - atomic_inc(&irq_err_count);
17397 + atomic_inc_unchecked(&irq_err_count);
17398 /*
17399 * Theoretically we do not have to handle this IRQ,
17400 * but in Linux this does not cause problems and is
17401 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
17402 index 43e9ccf..44ccf6f 100644
17403 --- a/arch/x86/kernel/init_task.c
17404 +++ b/arch/x86/kernel/init_task.c
17405 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
17406 * way process stacks are handled. This is done by having a special
17407 * "init_task" linker map entry..
17408 */
17409 -union thread_union init_thread_union __init_task_data =
17410 - { INIT_THREAD_INFO(init_task) };
17411 +union thread_union init_thread_union __init_task_data;
17412
17413 /*
17414 * Initial task structure.
17415 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
17416 * section. Since TSS's are completely CPU-local, we want them
17417 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
17418 */
17419 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
17420 -
17421 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
17422 +EXPORT_SYMBOL(init_tss);
17423 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17424 index 8c96897..be66bfa 100644
17425 --- a/arch/x86/kernel/ioport.c
17426 +++ b/arch/x86/kernel/ioport.c
17427 @@ -6,6 +6,7 @@
17428 #include <linux/sched.h>
17429 #include <linux/kernel.h>
17430 #include <linux/capability.h>
17431 +#include <linux/security.h>
17432 #include <linux/errno.h>
17433 #include <linux/types.h>
17434 #include <linux/ioport.h>
17435 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17436
17437 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17438 return -EINVAL;
17439 +#ifdef CONFIG_GRKERNSEC_IO
17440 + if (turn_on && grsec_disable_privio) {
17441 + gr_handle_ioperm();
17442 + return -EPERM;
17443 + }
17444 +#endif
17445 if (turn_on && !capable(CAP_SYS_RAWIO))
17446 return -EPERM;
17447
17448 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17449 * because the ->io_bitmap_max value must match the bitmap
17450 * contents:
17451 */
17452 - tss = &per_cpu(init_tss, get_cpu());
17453 + tss = init_tss + get_cpu();
17454
17455 if (turn_on)
17456 bitmap_clear(t->io_bitmap_ptr, from, num);
17457 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17458 return -EINVAL;
17459 /* Trying to gain more privileges? */
17460 if (level > old) {
17461 +#ifdef CONFIG_GRKERNSEC_IO
17462 + if (grsec_disable_privio) {
17463 + gr_handle_iopl();
17464 + return -EPERM;
17465 + }
17466 +#endif
17467 if (!capable(CAP_SYS_RAWIO))
17468 return -EPERM;
17469 }
17470 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17471 index 7943e0c..dd32c5c 100644
17472 --- a/arch/x86/kernel/irq.c
17473 +++ b/arch/x86/kernel/irq.c
17474 @@ -18,7 +18,7 @@
17475 #include <asm/mce.h>
17476 #include <asm/hw_irq.h>
17477
17478 -atomic_t irq_err_count;
17479 +atomic_unchecked_t irq_err_count;
17480
17481 /* Function pointer for generic interrupt vector handling */
17482 void (*x86_platform_ipi_callback)(void) = NULL;
17483 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17484 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17485 seq_printf(p, " Machine check polls\n");
17486 #endif
17487 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17488 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17489 #if defined(CONFIG_X86_IO_APIC)
17490 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17491 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17492 #endif
17493 return 0;
17494 }
17495 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17496
17497 u64 arch_irq_stat(void)
17498 {
17499 - u64 sum = atomic_read(&irq_err_count);
17500 + u64 sum = atomic_read_unchecked(&irq_err_count);
17501
17502 #ifdef CONFIG_X86_IO_APIC
17503 - sum += atomic_read(&irq_mis_count);
17504 + sum += atomic_read_unchecked(&irq_mis_count);
17505 #endif
17506 return sum;
17507 }
17508 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17509 index 40fc861..9b8739b 100644
17510 --- a/arch/x86/kernel/irq_32.c
17511 +++ b/arch/x86/kernel/irq_32.c
17512 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17513 __asm__ __volatile__("andl %%esp,%0" :
17514 "=r" (sp) : "0" (THREAD_SIZE - 1));
17515
17516 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17517 + return sp < STACK_WARN;
17518 }
17519
17520 static void print_stack_overflow(void)
17521 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17522 * per-CPU IRQ handling contexts (thread information and stack)
17523 */
17524 union irq_ctx {
17525 - struct thread_info tinfo;
17526 - u32 stack[THREAD_SIZE/sizeof(u32)];
17527 + unsigned long previous_esp;
17528 + u32 stack[THREAD_SIZE/sizeof(u32)];
17529 } __attribute__((aligned(THREAD_SIZE)));
17530
17531 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17532 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17533 static inline int
17534 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17535 {
17536 - union irq_ctx *curctx, *irqctx;
17537 + union irq_ctx *irqctx;
17538 u32 *isp, arg1, arg2;
17539
17540 - curctx = (union irq_ctx *) current_thread_info();
17541 irqctx = __this_cpu_read(hardirq_ctx);
17542
17543 /*
17544 @@ -92,21 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17545 * handler) we can't do that and just have to keep using the
17546 * current stack (which is the irq stack already after all)
17547 */
17548 - if (unlikely(curctx == irqctx))
17549 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17550 return 0;
17551
17552 /* build the stack frame on the IRQ stack */
17553 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17554 - irqctx->tinfo.task = curctx->tinfo.task;
17555 - irqctx->tinfo.previous_esp = current_stack_pointer;
17556 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17557 + irqctx->previous_esp = current_stack_pointer;
17558
17559 - /*
17560 - * Copy the softirq bits in preempt_count so that the
17561 - * softirq checks work in the hardirq context.
17562 - */
17563 - irqctx->tinfo.preempt_count =
17564 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
17565 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
17566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17567 + __set_fs(MAKE_MM_SEG(0));
17568 +#endif
17569
17570 if (unlikely(overflow))
17571 call_on_stack(print_stack_overflow, isp);
17572 @@ -118,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17573 : "0" (irq), "1" (desc), "2" (isp),
17574 "D" (desc->handle_irq)
17575 : "memory", "cc", "ecx");
17576 +
17577 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17578 + __set_fs(current_thread_info()->addr_limit);
17579 +#endif
17580 +
17581 return 1;
17582 }
17583
17584 @@ -126,29 +125,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17585 */
17586 void __cpuinit irq_ctx_init(int cpu)
17587 {
17588 - union irq_ctx *irqctx;
17589 -
17590 if (per_cpu(hardirq_ctx, cpu))
17591 return;
17592
17593 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17594 - THREAD_FLAGS,
17595 - THREAD_ORDER));
17596 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17597 - irqctx->tinfo.cpu = cpu;
17598 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17599 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17600 -
17601 - per_cpu(hardirq_ctx, cpu) = irqctx;
17602 -
17603 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17604 - THREAD_FLAGS,
17605 - THREAD_ORDER));
17606 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17607 - irqctx->tinfo.cpu = cpu;
17608 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17609 -
17610 - per_cpu(softirq_ctx, cpu) = irqctx;
17611 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17612 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
17613
17614 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17615 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17616 @@ -157,7 +138,6 @@ void __cpuinit irq_ctx_init(int cpu)
17617 asmlinkage void do_softirq(void)
17618 {
17619 unsigned long flags;
17620 - struct thread_info *curctx;
17621 union irq_ctx *irqctx;
17622 u32 *isp;
17623
17624 @@ -167,15 +147,22 @@ asmlinkage void do_softirq(void)
17625 local_irq_save(flags);
17626
17627 if (local_softirq_pending()) {
17628 - curctx = current_thread_info();
17629 irqctx = __this_cpu_read(softirq_ctx);
17630 - irqctx->tinfo.task = curctx->task;
17631 - irqctx->tinfo.previous_esp = current_stack_pointer;
17632 + irqctx->previous_esp = current_stack_pointer;
17633
17634 /* build the stack frame on the softirq stack */
17635 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17636 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17637 +
17638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17639 + __set_fs(MAKE_MM_SEG(0));
17640 +#endif
17641
17642 call_on_stack(__do_softirq, isp);
17643 +
17644 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17645 + __set_fs(current_thread_info()->addr_limit);
17646 +#endif
17647 +
17648 /*
17649 * Shouldn't happen, we returned above if in_interrupt():
17650 */
17651 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17652 index d04d3ec..ea4b374 100644
17653 --- a/arch/x86/kernel/irq_64.c
17654 +++ b/arch/x86/kernel/irq_64.c
17655 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17656 u64 estack_top, estack_bottom;
17657 u64 curbase = (u64)task_stack_page(current);
17658
17659 - if (user_mode_vm(regs))
17660 + if (user_mode(regs))
17661 return;
17662
17663 if (regs->sp >= curbase + sizeof(struct thread_info) +
17664 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17665 index 90fcf62..e682cdd 100644
17666 --- a/arch/x86/kernel/kdebugfs.c
17667 +++ b/arch/x86/kernel/kdebugfs.c
17668 @@ -28,6 +28,8 @@ struct setup_data_node {
17669 };
17670
17671 static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17672 + size_t count, loff_t *ppos) __size_overflow(3);
17673 +static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17674 size_t count, loff_t *ppos)
17675 {
17676 struct setup_data_node *node = file->private_data;
17677 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17678 index 2f45c4c..d95504f 100644
17679 --- a/arch/x86/kernel/kgdb.c
17680 +++ b/arch/x86/kernel/kgdb.c
17681 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17682 #ifdef CONFIG_X86_32
17683 switch (regno) {
17684 case GDB_SS:
17685 - if (!user_mode_vm(regs))
17686 + if (!user_mode(regs))
17687 *(unsigned long *)mem = __KERNEL_DS;
17688 break;
17689 case GDB_SP:
17690 - if (!user_mode_vm(regs))
17691 + if (!user_mode(regs))
17692 *(unsigned long *)mem = kernel_stack_pointer(regs);
17693 break;
17694 case GDB_GS:
17695 @@ -475,12 +475,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17696 case 'k':
17697 /* clear the trace bit */
17698 linux_regs->flags &= ~X86_EFLAGS_TF;
17699 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17700 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17701
17702 /* set the trace bit if we're stepping */
17703 if (remcomInBuffer[0] == 's') {
17704 linux_regs->flags |= X86_EFLAGS_TF;
17705 - atomic_set(&kgdb_cpu_doing_single_step,
17706 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17707 raw_smp_processor_id());
17708 }
17709
17710 @@ -545,7 +545,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17711
17712 switch (cmd) {
17713 case DIE_DEBUG:
17714 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17715 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17716 if (user_mode(regs))
17717 return single_step_cont(regs, args);
17718 break;
17719 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17720 index 7da647d..56fe348 100644
17721 --- a/arch/x86/kernel/kprobes.c
17722 +++ b/arch/x86/kernel/kprobes.c
17723 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17724 } __attribute__((packed)) *insn;
17725
17726 insn = (struct __arch_relative_insn *)from;
17727 +
17728 + pax_open_kernel();
17729 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17730 insn->op = op;
17731 + pax_close_kernel();
17732 }
17733
17734 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17735 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
17736 kprobe_opcode_t opcode;
17737 kprobe_opcode_t *orig_opcodes = opcodes;
17738
17739 - if (search_exception_tables((unsigned long)opcodes))
17740 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17741 return 0; /* Page fault may occur on this address. */
17742
17743 retry:
17744 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17745 }
17746 }
17747 insn_get_length(&insn);
17748 + pax_open_kernel();
17749 memcpy(dest, insn.kaddr, insn.length);
17750 + pax_close_kernel();
17751
17752 #ifdef CONFIG_X86_64
17753 if (insn_rip_relative(&insn)) {
17754 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
17755 (u8 *) dest;
17756 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17757 disp = (u8 *) dest + insn_offset_displacement(&insn);
17758 + pax_open_kernel();
17759 *(s32 *) disp = (s32) newdisp;
17760 + pax_close_kernel();
17761 }
17762 #endif
17763 return insn.length;
17764 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
17765 */
17766 __copy_instruction(p->ainsn.insn, p->addr, 0);
17767
17768 - if (can_boost(p->addr))
17769 + if (can_boost(ktla_ktva(p->addr)))
17770 p->ainsn.boostable = 0;
17771 else
17772 p->ainsn.boostable = -1;
17773
17774 - p->opcode = *p->addr;
17775 + p->opcode = *(ktla_ktva(p->addr));
17776 }
17777
17778 int __kprobes arch_prepare_kprobe(struct kprobe *p)
17779 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17780 * nor set current_kprobe, because it doesn't use single
17781 * stepping.
17782 */
17783 - regs->ip = (unsigned long)p->ainsn.insn;
17784 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17785 preempt_enable_no_resched();
17786 return;
17787 }
17788 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
17789 if (p->opcode == BREAKPOINT_INSTRUCTION)
17790 regs->ip = (unsigned long)p->addr;
17791 else
17792 - regs->ip = (unsigned long)p->ainsn.insn;
17793 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17794 }
17795
17796 /*
17797 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17798 setup_singlestep(p, regs, kcb, 0);
17799 return 1;
17800 }
17801 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
17802 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
17803 /*
17804 * The breakpoint instruction was removed right
17805 * after we hit it. Another cpu has removed
17806 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
17807 " movq %rax, 152(%rsp)\n"
17808 RESTORE_REGS_STRING
17809 " popfq\n"
17810 +#ifdef KERNEXEC_PLUGIN
17811 + " btsq $63,(%rsp)\n"
17812 +#endif
17813 #else
17814 " pushf\n"
17815 SAVE_REGS_STRING
17816 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
17817 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
17818 {
17819 unsigned long *tos = stack_addr(regs);
17820 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
17821 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
17822 unsigned long orig_ip = (unsigned long)p->addr;
17823 kprobe_opcode_t *insn = p->ainsn.insn;
17824
17825 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
17826 struct die_args *args = data;
17827 int ret = NOTIFY_DONE;
17828
17829 - if (args->regs && user_mode_vm(args->regs))
17830 + if (args->regs && user_mode(args->regs))
17831 return ret;
17832
17833 switch (val) {
17834 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17835 * Verify if the address gap is in 2GB range, because this uses
17836 * a relative jump.
17837 */
17838 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17839 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17840 if (abs(rel) > 0x7fffffff)
17841 return -ERANGE;
17842
17843 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17844 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17845
17846 /* Set probe function call */
17847 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17848 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17849
17850 /* Set returning jmp instruction at the tail of out-of-line buffer */
17851 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17852 - (u8 *)op->kp.addr + op->optinsn.size);
17853 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17854
17855 flush_icache_range((unsigned long) buf,
17856 (unsigned long) buf + TMPL_END_IDX +
17857 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17858 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17859
17860 /* Backup instructions which will be replaced by jump address */
17861 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17862 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17863 RELATIVE_ADDR_SIZE);
17864
17865 insn_buf[0] = RELATIVEJUMP_OPCODE;
17866 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
17867 index ea69726..604d066 100644
17868 --- a/arch/x86/kernel/ldt.c
17869 +++ b/arch/x86/kernel/ldt.c
17870 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
17871 if (reload) {
17872 #ifdef CONFIG_SMP
17873 preempt_disable();
17874 - load_LDT(pc);
17875 + load_LDT_nolock(pc);
17876 if (!cpumask_equal(mm_cpumask(current->mm),
17877 cpumask_of(smp_processor_id())))
17878 smp_call_function(flush_ldt, current->mm, 1);
17879 preempt_enable();
17880 #else
17881 - load_LDT(pc);
17882 + load_LDT_nolock(pc);
17883 #endif
17884 }
17885 if (oldsize) {
17886 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
17887 return err;
17888
17889 for (i = 0; i < old->size; i++)
17890 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
17891 + write_ldt_entry(new->ldt, i, old->ldt + i);
17892 return 0;
17893 }
17894
17895 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
17896 retval = copy_ldt(&mm->context, &old_mm->context);
17897 mutex_unlock(&old_mm->context.lock);
17898 }
17899 +
17900 + if (tsk == current) {
17901 + mm->context.vdso = 0;
17902 +
17903 +#ifdef CONFIG_X86_32
17904 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17905 + mm->context.user_cs_base = 0UL;
17906 + mm->context.user_cs_limit = ~0UL;
17907 +
17908 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17909 + cpus_clear(mm->context.cpu_user_cs_mask);
17910 +#endif
17911 +
17912 +#endif
17913 +#endif
17914 +
17915 + }
17916 +
17917 return retval;
17918 }
17919
17920 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
17921 }
17922 }
17923
17924 +#ifdef CONFIG_PAX_SEGMEXEC
17925 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
17926 + error = -EINVAL;
17927 + goto out_unlock;
17928 + }
17929 +#endif
17930 +
17931 fill_ldt(&ldt, &ldt_info);
17932 if (oldmode)
17933 ldt.avl = 0;
17934 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
17935 index a3fa43b..8966f4c 100644
17936 --- a/arch/x86/kernel/machine_kexec_32.c
17937 +++ b/arch/x86/kernel/machine_kexec_32.c
17938 @@ -27,7 +27,7 @@
17939 #include <asm/cacheflush.h>
17940 #include <asm/debugreg.h>
17941
17942 -static void set_idt(void *newidt, __u16 limit)
17943 +static void set_idt(struct desc_struct *newidt, __u16 limit)
17944 {
17945 struct desc_ptr curidt;
17946
17947 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
17948 }
17949
17950
17951 -static void set_gdt(void *newgdt, __u16 limit)
17952 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
17953 {
17954 struct desc_ptr curgdt;
17955
17956 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
17957 }
17958
17959 control_page = page_address(image->control_code_page);
17960 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
17961 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
17962
17963 relocate_kernel_ptr = control_page;
17964 page_list[PA_CONTROL_PAGE] = __pa(control_page);
17965 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
17966 index 3ca42d0..7cff8cc 100644
17967 --- a/arch/x86/kernel/microcode_intel.c
17968 +++ b/arch/x86/kernel/microcode_intel.c
17969 @@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
17970
17971 static int get_ucode_user(void *to, const void *from, size_t n)
17972 {
17973 - return copy_from_user(to, from, n);
17974 + return copy_from_user(to, (const void __force_user *)from, n);
17975 }
17976
17977 static enum ucode_state
17978 request_microcode_user(int cpu, const void __user *buf, size_t size)
17979 {
17980 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
17981 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
17982 }
17983
17984 static void microcode_fini_cpu(int cpu)
17985 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
17986 index 925179f..267ac7a 100644
17987 --- a/arch/x86/kernel/module.c
17988 +++ b/arch/x86/kernel/module.c
17989 @@ -36,15 +36,60 @@
17990 #define DEBUGP(fmt...)
17991 #endif
17992
17993 -void *module_alloc(unsigned long size)
17994 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
17995 {
17996 - if (PAGE_ALIGN(size) > MODULES_LEN)
17997 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
17998 return NULL;
17999 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18000 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18001 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18002 -1, __builtin_return_address(0));
18003 }
18004
18005 +void *module_alloc(unsigned long size)
18006 +{
18007 +
18008 +#ifdef CONFIG_PAX_KERNEXEC
18009 + return __module_alloc(size, PAGE_KERNEL);
18010 +#else
18011 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18012 +#endif
18013 +
18014 +}
18015 +
18016 +#ifdef CONFIG_PAX_KERNEXEC
18017 +#ifdef CONFIG_X86_32
18018 +void *module_alloc_exec(unsigned long size)
18019 +{
18020 + struct vm_struct *area;
18021 +
18022 + if (size == 0)
18023 + return NULL;
18024 +
18025 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18026 + return area ? area->addr : NULL;
18027 +}
18028 +EXPORT_SYMBOL(module_alloc_exec);
18029 +
18030 +void module_free_exec(struct module *mod, void *module_region)
18031 +{
18032 + vunmap(module_region);
18033 +}
18034 +EXPORT_SYMBOL(module_free_exec);
18035 +#else
18036 +void module_free_exec(struct module *mod, void *module_region)
18037 +{
18038 + module_free(mod, module_region);
18039 +}
18040 +EXPORT_SYMBOL(module_free_exec);
18041 +
18042 +void *module_alloc_exec(unsigned long size)
18043 +{
18044 + return __module_alloc(size, PAGE_KERNEL_RX);
18045 +}
18046 +EXPORT_SYMBOL(module_alloc_exec);
18047 +#endif
18048 +#endif
18049 +
18050 #ifdef CONFIG_X86_32
18051 int apply_relocate(Elf32_Shdr *sechdrs,
18052 const char *strtab,
18053 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18054 unsigned int i;
18055 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18056 Elf32_Sym *sym;
18057 - uint32_t *location;
18058 + uint32_t *plocation, location;
18059
18060 DEBUGP("Applying relocate section %u to %u\n", relsec,
18061 sechdrs[relsec].sh_info);
18062 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18063 /* This is where to make the change */
18064 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18065 - + rel[i].r_offset;
18066 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18067 + location = (uint32_t)plocation;
18068 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18069 + plocation = ktla_ktva((void *)plocation);
18070 /* This is the symbol it is referring to. Note that all
18071 undefined symbols have been resolved. */
18072 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18073 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18074 switch (ELF32_R_TYPE(rel[i].r_info)) {
18075 case R_386_32:
18076 /* We add the value into the location given */
18077 - *location += sym->st_value;
18078 + pax_open_kernel();
18079 + *plocation += sym->st_value;
18080 + pax_close_kernel();
18081 break;
18082 case R_386_PC32:
18083 /* Add the value, subtract its postition */
18084 - *location += sym->st_value - (uint32_t)location;
18085 + pax_open_kernel();
18086 + *plocation += sym->st_value - location;
18087 + pax_close_kernel();
18088 break;
18089 default:
18090 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18091 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18092 case R_X86_64_NONE:
18093 break;
18094 case R_X86_64_64:
18095 + pax_open_kernel();
18096 *(u64 *)loc = val;
18097 + pax_close_kernel();
18098 break;
18099 case R_X86_64_32:
18100 + pax_open_kernel();
18101 *(u32 *)loc = val;
18102 + pax_close_kernel();
18103 if (val != *(u32 *)loc)
18104 goto overflow;
18105 break;
18106 case R_X86_64_32S:
18107 + pax_open_kernel();
18108 *(s32 *)loc = val;
18109 + pax_close_kernel();
18110 if ((s64)val != *(s32 *)loc)
18111 goto overflow;
18112 break;
18113 case R_X86_64_PC32:
18114 val -= (u64)loc;
18115 + pax_open_kernel();
18116 *(u32 *)loc = val;
18117 + pax_close_kernel();
18118 +
18119 #if 0
18120 if ((s64)val != *(s32 *)loc)
18121 goto overflow;
18122 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18123 index 47acaf3..ec48ab6 100644
18124 --- a/arch/x86/kernel/nmi.c
18125 +++ b/arch/x86/kernel/nmi.c
18126 @@ -505,6 +505,17 @@ static inline void nmi_nesting_postprocess(void)
18127 dotraplinkage notrace __kprobes void
18128 do_nmi(struct pt_regs *regs, long error_code)
18129 {
18130 +
18131 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18132 + if (!user_mode(regs)) {
18133 + unsigned long cs = regs->cs & 0xFFFF;
18134 + unsigned long ip = ktva_ktla(regs->ip);
18135 +
18136 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18137 + regs->ip = ip;
18138 + }
18139 +#endif
18140 +
18141 nmi_nesting_preprocess(regs);
18142
18143 nmi_enter();
18144 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18145 index 676b8c7..870ba04 100644
18146 --- a/arch/x86/kernel/paravirt-spinlocks.c
18147 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18148 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18149 arch_spin_lock(lock);
18150 }
18151
18152 -struct pv_lock_ops pv_lock_ops = {
18153 +struct pv_lock_ops pv_lock_ops __read_only = {
18154 #ifdef CONFIG_SMP
18155 .spin_is_locked = __ticket_spin_is_locked,
18156 .spin_is_contended = __ticket_spin_is_contended,
18157 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18158 index d90272e..6bb013b 100644
18159 --- a/arch/x86/kernel/paravirt.c
18160 +++ b/arch/x86/kernel/paravirt.c
18161 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
18162 {
18163 return x;
18164 }
18165 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18166 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18167 +#endif
18168
18169 void __init default_banner(void)
18170 {
18171 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18172 if (opfunc == NULL)
18173 /* If there's no function, patch it with a ud2a (BUG) */
18174 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18175 - else if (opfunc == _paravirt_nop)
18176 + else if (opfunc == (void *)_paravirt_nop)
18177 /* If the operation is a nop, then nop the callsite */
18178 ret = paravirt_patch_nop();
18179
18180 /* identity functions just return their single argument */
18181 - else if (opfunc == _paravirt_ident_32)
18182 + else if (opfunc == (void *)_paravirt_ident_32)
18183 ret = paravirt_patch_ident_32(insnbuf, len);
18184 - else if (opfunc == _paravirt_ident_64)
18185 + else if (opfunc == (void *)_paravirt_ident_64)
18186 ret = paravirt_patch_ident_64(insnbuf, len);
18187 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18188 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18189 + ret = paravirt_patch_ident_64(insnbuf, len);
18190 +#endif
18191
18192 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18193 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18194 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18195 if (insn_len > len || start == NULL)
18196 insn_len = len;
18197 else
18198 - memcpy(insnbuf, start, insn_len);
18199 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18200
18201 return insn_len;
18202 }
18203 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
18204 preempt_enable();
18205 }
18206
18207 -struct pv_info pv_info = {
18208 +struct pv_info pv_info __read_only = {
18209 .name = "bare hardware",
18210 .paravirt_enabled = 0,
18211 .kernel_rpl = 0,
18212 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
18213 #endif
18214 };
18215
18216 -struct pv_init_ops pv_init_ops = {
18217 +struct pv_init_ops pv_init_ops __read_only = {
18218 .patch = native_patch,
18219 };
18220
18221 -struct pv_time_ops pv_time_ops = {
18222 +struct pv_time_ops pv_time_ops __read_only = {
18223 .sched_clock = native_sched_clock,
18224 .steal_clock = native_steal_clock,
18225 };
18226
18227 -struct pv_irq_ops pv_irq_ops = {
18228 +struct pv_irq_ops pv_irq_ops __read_only = {
18229 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18230 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18231 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18232 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
18233 #endif
18234 };
18235
18236 -struct pv_cpu_ops pv_cpu_ops = {
18237 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18238 .cpuid = native_cpuid,
18239 .get_debugreg = native_get_debugreg,
18240 .set_debugreg = native_set_debugreg,
18241 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18242 .end_context_switch = paravirt_nop,
18243 };
18244
18245 -struct pv_apic_ops pv_apic_ops = {
18246 +struct pv_apic_ops pv_apic_ops __read_only = {
18247 #ifdef CONFIG_X86_LOCAL_APIC
18248 .startup_ipi_hook = paravirt_nop,
18249 #endif
18250 };
18251
18252 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18253 +#ifdef CONFIG_X86_32
18254 +#ifdef CONFIG_X86_PAE
18255 +/* 64-bit pagetable entries */
18256 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18257 +#else
18258 /* 32-bit pagetable entries */
18259 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18260 +#endif
18261 #else
18262 /* 64-bit pagetable entries */
18263 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18264 #endif
18265
18266 -struct pv_mmu_ops pv_mmu_ops = {
18267 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18268
18269 .read_cr2 = native_read_cr2,
18270 .write_cr2 = native_write_cr2,
18271 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18272 .make_pud = PTE_IDENT,
18273
18274 .set_pgd = native_set_pgd,
18275 + .set_pgd_batched = native_set_pgd_batched,
18276 #endif
18277 #endif /* PAGETABLE_LEVELS >= 3 */
18278
18279 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18280 },
18281
18282 .set_fixmap = native_set_fixmap,
18283 +
18284 +#ifdef CONFIG_PAX_KERNEXEC
18285 + .pax_open_kernel = native_pax_open_kernel,
18286 + .pax_close_kernel = native_pax_close_kernel,
18287 +#endif
18288 +
18289 };
18290
18291 EXPORT_SYMBOL_GPL(pv_time_ops);
18292 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18293 index 35ccf75..7a15747 100644
18294 --- a/arch/x86/kernel/pci-iommu_table.c
18295 +++ b/arch/x86/kernel/pci-iommu_table.c
18296 @@ -2,7 +2,7 @@
18297 #include <asm/iommu_table.h>
18298 #include <linux/string.h>
18299 #include <linux/kallsyms.h>
18300 -
18301 +#include <linux/sched.h>
18302
18303 #define DEBUG 1
18304
18305 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18306 index 15763af..da59ada 100644
18307 --- a/arch/x86/kernel/process.c
18308 +++ b/arch/x86/kernel/process.c
18309 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
18310
18311 void free_thread_info(struct thread_info *ti)
18312 {
18313 - free_thread_xstate(ti->task);
18314 free_pages((unsigned long)ti, THREAD_ORDER);
18315 }
18316
18317 +static struct kmem_cache *task_struct_cachep;
18318 +
18319 void arch_task_cache_init(void)
18320 {
18321 - task_xstate_cachep =
18322 - kmem_cache_create("task_xstate", xstate_size,
18323 + /* create a slab on which task_structs can be allocated */
18324 + task_struct_cachep =
18325 + kmem_cache_create("task_struct", sizeof(struct task_struct),
18326 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
18327 +
18328 + task_xstate_cachep =
18329 + kmem_cache_create("task_xstate", xstate_size,
18330 __alignof__(union thread_xstate),
18331 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18332 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18333 +}
18334 +
18335 +struct task_struct *alloc_task_struct_node(int node)
18336 +{
18337 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
18338 +}
18339 +
18340 +void free_task_struct(struct task_struct *task)
18341 +{
18342 + free_thread_xstate(task);
18343 + kmem_cache_free(task_struct_cachep, task);
18344 }
18345
18346 /*
18347 @@ -70,7 +87,7 @@ void exit_thread(void)
18348 unsigned long *bp = t->io_bitmap_ptr;
18349
18350 if (bp) {
18351 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18352 + struct tss_struct *tss = init_tss + get_cpu();
18353
18354 t->io_bitmap_ptr = NULL;
18355 clear_thread_flag(TIF_IO_BITMAP);
18356 @@ -106,7 +123,7 @@ void show_regs_common(void)
18357
18358 printk(KERN_CONT "\n");
18359 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18360 - current->pid, current->comm, print_tainted(),
18361 + task_pid_nr(current), current->comm, print_tainted(),
18362 init_utsname()->release,
18363 (int)strcspn(init_utsname()->version, " "),
18364 init_utsname()->version);
18365 @@ -120,6 +137,9 @@ void flush_thread(void)
18366 {
18367 struct task_struct *tsk = current;
18368
18369 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18370 + loadsegment(gs, 0);
18371 +#endif
18372 flush_ptrace_hw_breakpoint(tsk);
18373 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18374 /*
18375 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18376 regs.di = (unsigned long) arg;
18377
18378 #ifdef CONFIG_X86_32
18379 - regs.ds = __USER_DS;
18380 - regs.es = __USER_DS;
18381 + regs.ds = __KERNEL_DS;
18382 + regs.es = __KERNEL_DS;
18383 regs.fs = __KERNEL_PERCPU;
18384 - regs.gs = __KERNEL_STACK_CANARY;
18385 + savesegment(gs, regs.gs);
18386 #else
18387 regs.ss = __KERNEL_DS;
18388 #endif
18389 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
18390
18391 return ret;
18392 }
18393 -void stop_this_cpu(void *dummy)
18394 +__noreturn void stop_this_cpu(void *dummy)
18395 {
18396 local_irq_disable();
18397 /*
18398 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
18399 }
18400 early_param("idle", idle_setup);
18401
18402 -unsigned long arch_align_stack(unsigned long sp)
18403 +#ifdef CONFIG_PAX_RANDKSTACK
18404 +void pax_randomize_kstack(struct pt_regs *regs)
18405 {
18406 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18407 - sp -= get_random_int() % 8192;
18408 - return sp & ~0xf;
18409 -}
18410 + struct thread_struct *thread = &current->thread;
18411 + unsigned long time;
18412
18413 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18414 -{
18415 - unsigned long range_end = mm->brk + 0x02000000;
18416 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18417 -}
18418 + if (!randomize_va_space)
18419 + return;
18420 +
18421 + if (v8086_mode(regs))
18422 + return;
18423
18424 + rdtscl(time);
18425 +
18426 + /* P4 seems to return a 0 LSB, ignore it */
18427 +#ifdef CONFIG_MPENTIUM4
18428 + time &= 0x3EUL;
18429 + time <<= 2;
18430 +#elif defined(CONFIG_X86_64)
18431 + time &= 0xFUL;
18432 + time <<= 4;
18433 +#else
18434 + time &= 0x1FUL;
18435 + time <<= 3;
18436 +#endif
18437 +
18438 + thread->sp0 ^= time;
18439 + load_sp0(init_tss + smp_processor_id(), thread);
18440 +
18441 +#ifdef CONFIG_X86_64
18442 + percpu_write(kernel_stack, thread->sp0);
18443 +#endif
18444 +}
18445 +#endif
18446 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18447 index c08d1ff..6ae1c81 100644
18448 --- a/arch/x86/kernel/process_32.c
18449 +++ b/arch/x86/kernel/process_32.c
18450 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18451 unsigned long thread_saved_pc(struct task_struct *tsk)
18452 {
18453 return ((unsigned long *)tsk->thread.sp)[3];
18454 +//XXX return tsk->thread.eip;
18455 }
18456
18457 #ifndef CONFIG_SMP
18458 @@ -132,15 +133,14 @@ void __show_regs(struct pt_regs *regs, int all)
18459 unsigned long sp;
18460 unsigned short ss, gs;
18461
18462 - if (user_mode_vm(regs)) {
18463 + if (user_mode(regs)) {
18464 sp = regs->sp;
18465 ss = regs->ss & 0xffff;
18466 - gs = get_user_gs(regs);
18467 } else {
18468 sp = kernel_stack_pointer(regs);
18469 savesegment(ss, ss);
18470 - savesegment(gs, gs);
18471 }
18472 + gs = get_user_gs(regs);
18473
18474 show_regs_common();
18475
18476 @@ -202,13 +202,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18477 struct task_struct *tsk;
18478 int err;
18479
18480 - childregs = task_pt_regs(p);
18481 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18482 *childregs = *regs;
18483 childregs->ax = 0;
18484 childregs->sp = sp;
18485
18486 p->thread.sp = (unsigned long) childregs;
18487 p->thread.sp0 = (unsigned long) (childregs+1);
18488 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18489
18490 p->thread.ip = (unsigned long) ret_from_fork;
18491
18492 @@ -299,7 +300,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18493 struct thread_struct *prev = &prev_p->thread,
18494 *next = &next_p->thread;
18495 int cpu = smp_processor_id();
18496 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18497 + struct tss_struct *tss = init_tss + cpu;
18498 fpu_switch_t fpu;
18499
18500 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18501 @@ -323,6 +324,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18502 */
18503 lazy_save_gs(prev->gs);
18504
18505 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18506 + __set_fs(task_thread_info(next_p)->addr_limit);
18507 +#endif
18508 +
18509 /*
18510 * Load the per-thread Thread-Local Storage descriptor.
18511 */
18512 @@ -353,6 +358,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18513 */
18514 arch_end_context_switch(next_p);
18515
18516 + percpu_write(current_task, next_p);
18517 + percpu_write(current_tinfo, &next_p->tinfo);
18518 +
18519 /*
18520 * Restore %gs if needed (which is common)
18521 */
18522 @@ -361,8 +369,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18523
18524 switch_fpu_finish(next_p, fpu);
18525
18526 - percpu_write(current_task, next_p);
18527 -
18528 return prev_p;
18529 }
18530
18531 @@ -392,4 +398,3 @@ unsigned long get_wchan(struct task_struct *p)
18532 } while (count++ < 16);
18533 return 0;
18534 }
18535 -
18536 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18537 index cfa5c90..4facd28 100644
18538 --- a/arch/x86/kernel/process_64.c
18539 +++ b/arch/x86/kernel/process_64.c
18540 @@ -89,7 +89,7 @@ static void __exit_idle(void)
18541 void exit_idle(void)
18542 {
18543 /* idle loop has pid 0 */
18544 - if (current->pid)
18545 + if (task_pid_nr(current))
18546 return;
18547 __exit_idle();
18548 }
18549 @@ -270,8 +270,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18550 struct pt_regs *childregs;
18551 struct task_struct *me = current;
18552
18553 - childregs = ((struct pt_regs *)
18554 - (THREAD_SIZE + task_stack_page(p))) - 1;
18555 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18556 *childregs = *regs;
18557
18558 childregs->ax = 0;
18559 @@ -283,6 +282,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18560 p->thread.sp = (unsigned long) childregs;
18561 p->thread.sp0 = (unsigned long) (childregs+1);
18562 p->thread.usersp = me->thread.usersp;
18563 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18564
18565 set_tsk_thread_flag(p, TIF_FORK);
18566
18567 @@ -385,7 +385,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18568 struct thread_struct *prev = &prev_p->thread;
18569 struct thread_struct *next = &next_p->thread;
18570 int cpu = smp_processor_id();
18571 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18572 + struct tss_struct *tss = init_tss + cpu;
18573 unsigned fsindex, gsindex;
18574 fpu_switch_t fpu;
18575
18576 @@ -467,10 +467,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18577 prev->usersp = percpu_read(old_rsp);
18578 percpu_write(old_rsp, next->usersp);
18579 percpu_write(current_task, next_p);
18580 + percpu_write(current_tinfo, &next_p->tinfo);
18581
18582 - percpu_write(kernel_stack,
18583 - (unsigned long)task_stack_page(next_p) +
18584 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18585 + percpu_write(kernel_stack, next->sp0);
18586
18587 /*
18588 * Now maybe reload the debug registers and handle I/O bitmaps
18589 @@ -525,12 +524,11 @@ unsigned long get_wchan(struct task_struct *p)
18590 if (!p || p == current || p->state == TASK_RUNNING)
18591 return 0;
18592 stack = (unsigned long)task_stack_page(p);
18593 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18594 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18595 return 0;
18596 fp = *(u64 *)(p->thread.sp);
18597 do {
18598 - if (fp < (unsigned long)stack ||
18599 - fp >= (unsigned long)stack+THREAD_SIZE)
18600 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18601 return 0;
18602 ip = *(u64 *)(fp+8);
18603 if (!in_sched_functions(ip))
18604 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18605 index 5026738..c5925c0 100644
18606 --- a/arch/x86/kernel/ptrace.c
18607 +++ b/arch/x86/kernel/ptrace.c
18608 @@ -823,7 +823,7 @@ long arch_ptrace(struct task_struct *child, long request,
18609 unsigned long addr, unsigned long data)
18610 {
18611 int ret;
18612 - unsigned long __user *datap = (unsigned long __user *)data;
18613 + unsigned long __user *datap = (__force unsigned long __user *)data;
18614
18615 switch (request) {
18616 /* read the word at location addr in the USER area. */
18617 @@ -908,14 +908,14 @@ long arch_ptrace(struct task_struct *child, long request,
18618 if ((int) addr < 0)
18619 return -EIO;
18620 ret = do_get_thread_area(child, addr,
18621 - (struct user_desc __user *)data);
18622 + (__force struct user_desc __user *) data);
18623 break;
18624
18625 case PTRACE_SET_THREAD_AREA:
18626 if ((int) addr < 0)
18627 return -EIO;
18628 ret = do_set_thread_area(child, addr,
18629 - (struct user_desc __user *)data, 0);
18630 + (__force struct user_desc __user *) data, 0);
18631 break;
18632 #endif
18633
18634 @@ -1332,7 +1332,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18635 memset(info, 0, sizeof(*info));
18636 info->si_signo = SIGTRAP;
18637 info->si_code = si_code;
18638 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18639 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18640 }
18641
18642 void user_single_step_siginfo(struct task_struct *tsk,
18643 @@ -1361,6 +1361,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18644 # define IS_IA32 0
18645 #endif
18646
18647 +#ifdef CONFIG_GRKERNSEC_SETXID
18648 +extern void gr_delayed_cred_worker(void);
18649 +#endif
18650 +
18651 /*
18652 * We must return the syscall number to actually look up in the table.
18653 * This can be -1L to skip running any syscall at all.
18654 @@ -1369,6 +1373,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18655 {
18656 long ret = 0;
18657
18658 +#ifdef CONFIG_GRKERNSEC_SETXID
18659 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18660 + gr_delayed_cred_worker();
18661 +#endif
18662 +
18663 /*
18664 * If we stepped into a sysenter/syscall insn, it trapped in
18665 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18666 @@ -1412,6 +1421,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18667 {
18668 bool step;
18669
18670 +#ifdef CONFIG_GRKERNSEC_SETXID
18671 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18672 + gr_delayed_cred_worker();
18673 +#endif
18674 +
18675 audit_syscall_exit(regs);
18676
18677 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18678 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18679 index 42eb330..139955c 100644
18680 --- a/arch/x86/kernel/pvclock.c
18681 +++ b/arch/x86/kernel/pvclock.c
18682 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18683 return pv_tsc_khz;
18684 }
18685
18686 -static atomic64_t last_value = ATOMIC64_INIT(0);
18687 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18688
18689 void pvclock_resume(void)
18690 {
18691 - atomic64_set(&last_value, 0);
18692 + atomic64_set_unchecked(&last_value, 0);
18693 }
18694
18695 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18696 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18697 * updating at the same time, and one of them could be slightly behind,
18698 * making the assumption that last_value always go forward fail to hold.
18699 */
18700 - last = atomic64_read(&last_value);
18701 + last = atomic64_read_unchecked(&last_value);
18702 do {
18703 if (ret < last)
18704 return last;
18705 - last = atomic64_cmpxchg(&last_value, last, ret);
18706 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18707 } while (unlikely(last != ret));
18708
18709 return ret;
18710 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18711 index d840e69..98e9581 100644
18712 --- a/arch/x86/kernel/reboot.c
18713 +++ b/arch/x86/kernel/reboot.c
18714 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
18715 EXPORT_SYMBOL(pm_power_off);
18716
18717 static const struct desc_ptr no_idt = {};
18718 -static int reboot_mode;
18719 +static unsigned short reboot_mode;
18720 enum reboot_type reboot_type = BOOT_ACPI;
18721 int reboot_force;
18722
18723 @@ -335,13 +335,17 @@ core_initcall(reboot_init);
18724 extern const unsigned char machine_real_restart_asm[];
18725 extern const u64 machine_real_restart_gdt[3];
18726
18727 -void machine_real_restart(unsigned int type)
18728 +__noreturn void machine_real_restart(unsigned int type)
18729 {
18730 void *restart_va;
18731 unsigned long restart_pa;
18732 - void (*restart_lowmem)(unsigned int);
18733 + void (* __noreturn restart_lowmem)(unsigned int);
18734 u64 *lowmem_gdt;
18735
18736 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18737 + struct desc_struct *gdt;
18738 +#endif
18739 +
18740 local_irq_disable();
18741
18742 /* Write zero to CMOS register number 0x0f, which the BIOS POST
18743 @@ -367,14 +371,14 @@ void machine_real_restart(unsigned int type)
18744 boot)". This seems like a fairly standard thing that gets set by
18745 REBOOT.COM programs, and the previous reset routine did this
18746 too. */
18747 - *((unsigned short *)0x472) = reboot_mode;
18748 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18749
18750 /* Patch the GDT in the low memory trampoline */
18751 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
18752
18753 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
18754 restart_pa = virt_to_phys(restart_va);
18755 - restart_lowmem = (void (*)(unsigned int))restart_pa;
18756 + restart_lowmem = (void *)restart_pa;
18757
18758 /* GDT[0]: GDT self-pointer */
18759 lowmem_gdt[0] =
18760 @@ -385,7 +389,33 @@ void machine_real_restart(unsigned int type)
18761 GDT_ENTRY(0x009b, restart_pa, 0xffff);
18762
18763 /* Jump to the identity-mapped low memory code */
18764 +
18765 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18766 + gdt = get_cpu_gdt_table(smp_processor_id());
18767 + pax_open_kernel();
18768 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18769 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18770 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18771 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
18772 +#endif
18773 +#ifdef CONFIG_PAX_KERNEXEC
18774 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18775 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18776 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18777 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18778 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18779 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18780 +#endif
18781 + pax_close_kernel();
18782 +#endif
18783 +
18784 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18785 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18786 + unreachable();
18787 +#else
18788 restart_lowmem(type);
18789 +#endif
18790 +
18791 }
18792 #ifdef CONFIG_APM_MODULE
18793 EXPORT_SYMBOL(machine_real_restart);
18794 @@ -556,7 +586,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18795 * try to force a triple fault and then cycle between hitting the keyboard
18796 * controller and doing that
18797 */
18798 -static void native_machine_emergency_restart(void)
18799 +__noreturn static void native_machine_emergency_restart(void)
18800 {
18801 int i;
18802 int attempt = 0;
18803 @@ -680,13 +710,13 @@ void native_machine_shutdown(void)
18804 #endif
18805 }
18806
18807 -static void __machine_emergency_restart(int emergency)
18808 +static __noreturn void __machine_emergency_restart(int emergency)
18809 {
18810 reboot_emergency = emergency;
18811 machine_ops.emergency_restart();
18812 }
18813
18814 -static void native_machine_restart(char *__unused)
18815 +static __noreturn void native_machine_restart(char *__unused)
18816 {
18817 printk("machine restart\n");
18818
18819 @@ -695,7 +725,7 @@ static void native_machine_restart(char *__unused)
18820 __machine_emergency_restart(0);
18821 }
18822
18823 -static void native_machine_halt(void)
18824 +static __noreturn void native_machine_halt(void)
18825 {
18826 /* stop other cpus and apics */
18827 machine_shutdown();
18828 @@ -706,7 +736,7 @@ static void native_machine_halt(void)
18829 stop_this_cpu(NULL);
18830 }
18831
18832 -static void native_machine_power_off(void)
18833 +__noreturn static void native_machine_power_off(void)
18834 {
18835 if (pm_power_off) {
18836 if (!reboot_force)
18837 @@ -715,6 +745,7 @@ static void native_machine_power_off(void)
18838 }
18839 /* a fallback in case there is no PM info available */
18840 tboot_shutdown(TB_SHUTDOWN_HALT);
18841 + unreachable();
18842 }
18843
18844 struct machine_ops machine_ops = {
18845 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18846 index 7a6f3b3..bed145d7 100644
18847 --- a/arch/x86/kernel/relocate_kernel_64.S
18848 +++ b/arch/x86/kernel/relocate_kernel_64.S
18849 @@ -11,6 +11,7 @@
18850 #include <asm/kexec.h>
18851 #include <asm/processor-flags.h>
18852 #include <asm/pgtable_types.h>
18853 +#include <asm/alternative-asm.h>
18854
18855 /*
18856 * Must be relocatable PIC code callable as a C function
18857 @@ -160,13 +161,14 @@ identity_mapped:
18858 xorq %rbp, %rbp
18859 xorq %r8, %r8
18860 xorq %r9, %r9
18861 - xorq %r10, %r9
18862 + xorq %r10, %r10
18863 xorq %r11, %r11
18864 xorq %r12, %r12
18865 xorq %r13, %r13
18866 xorq %r14, %r14
18867 xorq %r15, %r15
18868
18869 + pax_force_retaddr 0, 1
18870 ret
18871
18872 1:
18873 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
18874 index d7d5099..28555d0 100644
18875 --- a/arch/x86/kernel/setup.c
18876 +++ b/arch/x86/kernel/setup.c
18877 @@ -448,7 +448,7 @@ static void __init parse_setup_data(void)
18878
18879 switch (data->type) {
18880 case SETUP_E820_EXT:
18881 - parse_e820_ext(data);
18882 + parse_e820_ext((struct setup_data __force_kernel *)data);
18883 break;
18884 case SETUP_DTB:
18885 add_dtb(pa_data);
18886 @@ -649,7 +649,7 @@ static void __init trim_bios_range(void)
18887 * area (640->1Mb) as ram even though it is not.
18888 * take them out.
18889 */
18890 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
18891 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
18892 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
18893 }
18894
18895 @@ -767,14 +767,14 @@ void __init setup_arch(char **cmdline_p)
18896
18897 if (!boot_params.hdr.root_flags)
18898 root_mountflags &= ~MS_RDONLY;
18899 - init_mm.start_code = (unsigned long) _text;
18900 - init_mm.end_code = (unsigned long) _etext;
18901 + init_mm.start_code = ktla_ktva((unsigned long) _text);
18902 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
18903 init_mm.end_data = (unsigned long) _edata;
18904 init_mm.brk = _brk_end;
18905
18906 - code_resource.start = virt_to_phys(_text);
18907 - code_resource.end = virt_to_phys(_etext)-1;
18908 - data_resource.start = virt_to_phys(_etext);
18909 + code_resource.start = virt_to_phys(ktla_ktva(_text));
18910 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
18911 + data_resource.start = virt_to_phys(_sdata);
18912 data_resource.end = virt_to_phys(_edata)-1;
18913 bss_resource.start = virt_to_phys(&__bss_start);
18914 bss_resource.end = virt_to_phys(&__bss_stop)-1;
18915 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
18916 index 5a98aa2..2f9288d 100644
18917 --- a/arch/x86/kernel/setup_percpu.c
18918 +++ b/arch/x86/kernel/setup_percpu.c
18919 @@ -21,19 +21,17 @@
18920 #include <asm/cpu.h>
18921 #include <asm/stackprotector.h>
18922
18923 -DEFINE_PER_CPU(int, cpu_number);
18924 +#ifdef CONFIG_SMP
18925 +DEFINE_PER_CPU(unsigned int, cpu_number);
18926 EXPORT_PER_CPU_SYMBOL(cpu_number);
18927 +#endif
18928
18929 -#ifdef CONFIG_X86_64
18930 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
18931 -#else
18932 -#define BOOT_PERCPU_OFFSET 0
18933 -#endif
18934
18935 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
18936 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
18937
18938 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
18939 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
18940 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
18941 };
18942 EXPORT_SYMBOL(__per_cpu_offset);
18943 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
18944 {
18945 #ifdef CONFIG_X86_32
18946 struct desc_struct gdt;
18947 + unsigned long base = per_cpu_offset(cpu);
18948
18949 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
18950 - 0x2 | DESCTYPE_S, 0x8);
18951 - gdt.s = 1;
18952 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
18953 + 0x83 | DESCTYPE_S, 0xC);
18954 write_gdt_entry(get_cpu_gdt_table(cpu),
18955 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
18956 #endif
18957 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
18958 /* alrighty, percpu areas up and running */
18959 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
18960 for_each_possible_cpu(cpu) {
18961 +#ifdef CONFIG_CC_STACKPROTECTOR
18962 +#ifdef CONFIG_X86_32
18963 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
18964 +#endif
18965 +#endif
18966 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
18967 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
18968 per_cpu(cpu_number, cpu) = cpu;
18969 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
18970 */
18971 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
18972 #endif
18973 +#ifdef CONFIG_CC_STACKPROTECTOR
18974 +#ifdef CONFIG_X86_32
18975 + if (!cpu)
18976 + per_cpu(stack_canary.canary, cpu) = canary;
18977 +#endif
18978 +#endif
18979 /*
18980 * Up to this point, the boot CPU has been using .init.data
18981 * area. Reload any changed state for the boot CPU.
18982 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
18983 index 46a01bd..2e88e6d 100644
18984 --- a/arch/x86/kernel/signal.c
18985 +++ b/arch/x86/kernel/signal.c
18986 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
18987 * Align the stack pointer according to the i386 ABI,
18988 * i.e. so that on function entry ((sp + 4) & 15) == 0.
18989 */
18990 - sp = ((sp + 4) & -16ul) - 4;
18991 + sp = ((sp - 12) & -16ul) - 4;
18992 #else /* !CONFIG_X86_32 */
18993 sp = round_down(sp, 16) - 8;
18994 #endif
18995 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
18996 * Return an always-bogus address instead so we will die with SIGSEGV.
18997 */
18998 if (onsigstack && !likely(on_sig_stack(sp)))
18999 - return (void __user *)-1L;
19000 + return (__force void __user *)-1L;
19001
19002 /* save i387 state */
19003 if (used_math() && save_i387_xstate(*fpstate) < 0)
19004 - return (void __user *)-1L;
19005 + return (__force void __user *)-1L;
19006
19007 return (void __user *)sp;
19008 }
19009 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19010 }
19011
19012 if (current->mm->context.vdso)
19013 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19014 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19015 else
19016 - restorer = &frame->retcode;
19017 + restorer = (void __user *)&frame->retcode;
19018 if (ka->sa.sa_flags & SA_RESTORER)
19019 restorer = ka->sa.sa_restorer;
19020
19021 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19022 * reasons and because gdb uses it as a signature to notice
19023 * signal handler stack frames.
19024 */
19025 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19026 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19027
19028 if (err)
19029 return -EFAULT;
19030 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19031 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19032
19033 /* Set up to return from userspace. */
19034 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19035 + if (current->mm->context.vdso)
19036 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19037 + else
19038 + restorer = (void __user *)&frame->retcode;
19039 if (ka->sa.sa_flags & SA_RESTORER)
19040 restorer = ka->sa.sa_restorer;
19041 put_user_ex(restorer, &frame->pretcode);
19042 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19043 * reasons and because gdb uses it as a signature to notice
19044 * signal handler stack frames.
19045 */
19046 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19047 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19048 } put_user_catch(err);
19049
19050 if (err)
19051 @@ -765,7 +768,7 @@ static void do_signal(struct pt_regs *regs)
19052 * X86_32: vm86 regs switched out by assembly code before reaching
19053 * here, so testing against kernel CS suffices.
19054 */
19055 - if (!user_mode(regs))
19056 + if (!user_mode_novm(regs))
19057 return;
19058
19059 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
19060 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19061 index 66d250c..f1b10bd 100644
19062 --- a/arch/x86/kernel/smpboot.c
19063 +++ b/arch/x86/kernel/smpboot.c
19064 @@ -715,17 +715,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
19065 set_idle_for_cpu(cpu, c_idle.idle);
19066 do_rest:
19067 per_cpu(current_task, cpu) = c_idle.idle;
19068 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
19069 #ifdef CONFIG_X86_32
19070 /* Stack for startup_32 can be just as for start_secondary onwards */
19071 irq_ctx_init(cpu);
19072 #else
19073 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
19074 initial_gs = per_cpu_offset(cpu);
19075 - per_cpu(kernel_stack, cpu) =
19076 - (unsigned long)task_stack_page(c_idle.idle) -
19077 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19078 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
19079 #endif
19080 +
19081 + pax_open_kernel();
19082 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19083 + pax_close_kernel();
19084 +
19085 initial_code = (unsigned long)start_secondary;
19086 stack_start = c_idle.idle->thread.sp;
19087
19088 @@ -868,6 +871,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
19089
19090 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19091
19092 +#ifdef CONFIG_PAX_PER_CPU_PGD
19093 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19094 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19095 + KERNEL_PGD_PTRS);
19096 +#endif
19097 +
19098 err = do_boot_cpu(apicid, cpu);
19099 if (err) {
19100 pr_debug("do_boot_cpu failed %d\n", err);
19101 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19102 index c346d11..d43b163 100644
19103 --- a/arch/x86/kernel/step.c
19104 +++ b/arch/x86/kernel/step.c
19105 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19106 struct desc_struct *desc;
19107 unsigned long base;
19108
19109 - seg &= ~7UL;
19110 + seg >>= 3;
19111
19112 mutex_lock(&child->mm->context.lock);
19113 - if (unlikely((seg >> 3) >= child->mm->context.size))
19114 + if (unlikely(seg >= child->mm->context.size))
19115 addr = -1L; /* bogus selector, access would fault */
19116 else {
19117 desc = child->mm->context.ldt + seg;
19118 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19119 addr += base;
19120 }
19121 mutex_unlock(&child->mm->context.lock);
19122 - }
19123 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19124 + addr = ktla_ktva(addr);
19125
19126 return addr;
19127 }
19128 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19129 unsigned char opcode[15];
19130 unsigned long addr = convert_ip_to_linear(child, regs);
19131
19132 + if (addr == -EINVAL)
19133 + return 0;
19134 +
19135 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19136 for (i = 0; i < copied; i++) {
19137 switch (opcode[i]) {
19138 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19139 index 0b0cb5f..db6b9ed 100644
19140 --- a/arch/x86/kernel/sys_i386_32.c
19141 +++ b/arch/x86/kernel/sys_i386_32.c
19142 @@ -24,17 +24,224 @@
19143
19144 #include <asm/syscalls.h>
19145
19146 -/*
19147 - * Do a system call from kernel instead of calling sys_execve so we
19148 - * end up with proper pt_regs.
19149 - */
19150 -int kernel_execve(const char *filename,
19151 - const char *const argv[],
19152 - const char *const envp[])
19153 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19154 {
19155 - long __res;
19156 - asm volatile ("int $0x80"
19157 - : "=a" (__res)
19158 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19159 - return __res;
19160 + unsigned long pax_task_size = TASK_SIZE;
19161 +
19162 +#ifdef CONFIG_PAX_SEGMEXEC
19163 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19164 + pax_task_size = SEGMEXEC_TASK_SIZE;
19165 +#endif
19166 +
19167 + if (len > pax_task_size || addr > pax_task_size - len)
19168 + return -EINVAL;
19169 +
19170 + return 0;
19171 +}
19172 +
19173 +unsigned long
19174 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19175 + unsigned long len, unsigned long pgoff, unsigned long flags)
19176 +{
19177 + struct mm_struct *mm = current->mm;
19178 + struct vm_area_struct *vma;
19179 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19180 +
19181 +#ifdef CONFIG_PAX_SEGMEXEC
19182 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19183 + pax_task_size = SEGMEXEC_TASK_SIZE;
19184 +#endif
19185 +
19186 + pax_task_size -= PAGE_SIZE;
19187 +
19188 + if (len > pax_task_size)
19189 + return -ENOMEM;
19190 +
19191 + if (flags & MAP_FIXED)
19192 + return addr;
19193 +
19194 +#ifdef CONFIG_PAX_RANDMMAP
19195 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19196 +#endif
19197 +
19198 + if (addr) {
19199 + addr = PAGE_ALIGN(addr);
19200 + if (pax_task_size - len >= addr) {
19201 + vma = find_vma(mm, addr);
19202 + if (check_heap_stack_gap(vma, addr, len))
19203 + return addr;
19204 + }
19205 + }
19206 + if (len > mm->cached_hole_size) {
19207 + start_addr = addr = mm->free_area_cache;
19208 + } else {
19209 + start_addr = addr = mm->mmap_base;
19210 + mm->cached_hole_size = 0;
19211 + }
19212 +
19213 +#ifdef CONFIG_PAX_PAGEEXEC
19214 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19215 + start_addr = 0x00110000UL;
19216 +
19217 +#ifdef CONFIG_PAX_RANDMMAP
19218 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19219 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19220 +#endif
19221 +
19222 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19223 + start_addr = addr = mm->mmap_base;
19224 + else
19225 + addr = start_addr;
19226 + }
19227 +#endif
19228 +
19229 +full_search:
19230 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19231 + /* At this point: (!vma || addr < vma->vm_end). */
19232 + if (pax_task_size - len < addr) {
19233 + /*
19234 + * Start a new search - just in case we missed
19235 + * some holes.
19236 + */
19237 + if (start_addr != mm->mmap_base) {
19238 + start_addr = addr = mm->mmap_base;
19239 + mm->cached_hole_size = 0;
19240 + goto full_search;
19241 + }
19242 + return -ENOMEM;
19243 + }
19244 + if (check_heap_stack_gap(vma, addr, len))
19245 + break;
19246 + if (addr + mm->cached_hole_size < vma->vm_start)
19247 + mm->cached_hole_size = vma->vm_start - addr;
19248 + addr = vma->vm_end;
19249 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19250 + start_addr = addr = mm->mmap_base;
19251 + mm->cached_hole_size = 0;
19252 + goto full_search;
19253 + }
19254 + }
19255 +
19256 + /*
19257 + * Remember the place where we stopped the search:
19258 + */
19259 + mm->free_area_cache = addr + len;
19260 + return addr;
19261 +}
19262 +
19263 +unsigned long
19264 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19265 + const unsigned long len, const unsigned long pgoff,
19266 + const unsigned long flags)
19267 +{
19268 + struct vm_area_struct *vma;
19269 + struct mm_struct *mm = current->mm;
19270 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19271 +
19272 +#ifdef CONFIG_PAX_SEGMEXEC
19273 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19274 + pax_task_size = SEGMEXEC_TASK_SIZE;
19275 +#endif
19276 +
19277 + pax_task_size -= PAGE_SIZE;
19278 +
19279 + /* requested length too big for entire address space */
19280 + if (len > pax_task_size)
19281 + return -ENOMEM;
19282 +
19283 + if (flags & MAP_FIXED)
19284 + return addr;
19285 +
19286 +#ifdef CONFIG_PAX_PAGEEXEC
19287 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19288 + goto bottomup;
19289 +#endif
19290 +
19291 +#ifdef CONFIG_PAX_RANDMMAP
19292 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19293 +#endif
19294 +
19295 + /* requesting a specific address */
19296 + if (addr) {
19297 + addr = PAGE_ALIGN(addr);
19298 + if (pax_task_size - len >= addr) {
19299 + vma = find_vma(mm, addr);
19300 + if (check_heap_stack_gap(vma, addr, len))
19301 + return addr;
19302 + }
19303 + }
19304 +
19305 + /* check if free_area_cache is useful for us */
19306 + if (len <= mm->cached_hole_size) {
19307 + mm->cached_hole_size = 0;
19308 + mm->free_area_cache = mm->mmap_base;
19309 + }
19310 +
19311 + /* either no address requested or can't fit in requested address hole */
19312 + addr = mm->free_area_cache;
19313 +
19314 + /* make sure it can fit in the remaining address space */
19315 + if (addr > len) {
19316 + vma = find_vma(mm, addr-len);
19317 + if (check_heap_stack_gap(vma, addr - len, len))
19318 + /* remember the address as a hint for next time */
19319 + return (mm->free_area_cache = addr-len);
19320 + }
19321 +
19322 + if (mm->mmap_base < len)
19323 + goto bottomup;
19324 +
19325 + addr = mm->mmap_base-len;
19326 +
19327 + do {
19328 + /*
19329 + * Lookup failure means no vma is above this address,
19330 + * else if new region fits below vma->vm_start,
19331 + * return with success:
19332 + */
19333 + vma = find_vma(mm, addr);
19334 + if (check_heap_stack_gap(vma, addr, len))
19335 + /* remember the address as a hint for next time */
19336 + return (mm->free_area_cache = addr);
19337 +
19338 + /* remember the largest hole we saw so far */
19339 + if (addr + mm->cached_hole_size < vma->vm_start)
19340 + mm->cached_hole_size = vma->vm_start - addr;
19341 +
19342 + /* try just below the current vma->vm_start */
19343 + addr = skip_heap_stack_gap(vma, len);
19344 + } while (!IS_ERR_VALUE(addr));
19345 +
19346 +bottomup:
19347 + /*
19348 + * A failed mmap() very likely causes application failure,
19349 + * so fall back to the bottom-up function here. This scenario
19350 + * can happen with large stack limits and large mmap()
19351 + * allocations.
19352 + */
19353 +
19354 +#ifdef CONFIG_PAX_SEGMEXEC
19355 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19356 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19357 + else
19358 +#endif
19359 +
19360 + mm->mmap_base = TASK_UNMAPPED_BASE;
19361 +
19362 +#ifdef CONFIG_PAX_RANDMMAP
19363 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19364 + mm->mmap_base += mm->delta_mmap;
19365 +#endif
19366 +
19367 + mm->free_area_cache = mm->mmap_base;
19368 + mm->cached_hole_size = ~0UL;
19369 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19370 + /*
19371 + * Restore the topdown base:
19372 + */
19373 + mm->mmap_base = base;
19374 + mm->free_area_cache = base;
19375 + mm->cached_hole_size = ~0UL;
19376 +
19377 + return addr;
19378 }
19379 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19380 index 0514890..3dbebce 100644
19381 --- a/arch/x86/kernel/sys_x86_64.c
19382 +++ b/arch/x86/kernel/sys_x86_64.c
19383 @@ -95,8 +95,8 @@ out:
19384 return error;
19385 }
19386
19387 -static void find_start_end(unsigned long flags, unsigned long *begin,
19388 - unsigned long *end)
19389 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19390 + unsigned long *begin, unsigned long *end)
19391 {
19392 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
19393 unsigned long new_begin;
19394 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19395 *begin = new_begin;
19396 }
19397 } else {
19398 - *begin = TASK_UNMAPPED_BASE;
19399 + *begin = mm->mmap_base;
19400 *end = TASK_SIZE;
19401 }
19402 }
19403 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19404 if (flags & MAP_FIXED)
19405 return addr;
19406
19407 - find_start_end(flags, &begin, &end);
19408 + find_start_end(mm, flags, &begin, &end);
19409
19410 if (len > end)
19411 return -ENOMEM;
19412
19413 +#ifdef CONFIG_PAX_RANDMMAP
19414 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19415 +#endif
19416 +
19417 if (addr) {
19418 addr = PAGE_ALIGN(addr);
19419 vma = find_vma(mm, addr);
19420 - if (end - len >= addr &&
19421 - (!vma || addr + len <= vma->vm_start))
19422 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19423 return addr;
19424 }
19425 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
19426 @@ -172,7 +175,7 @@ full_search:
19427 }
19428 return -ENOMEM;
19429 }
19430 - if (!vma || addr + len <= vma->vm_start) {
19431 + if (check_heap_stack_gap(vma, addr, len)) {
19432 /*
19433 * Remember the place where we stopped the search:
19434 */
19435 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19436 {
19437 struct vm_area_struct *vma;
19438 struct mm_struct *mm = current->mm;
19439 - unsigned long addr = addr0;
19440 + unsigned long base = mm->mmap_base, addr = addr0;
19441
19442 /* requested length too big for entire address space */
19443 if (len > TASK_SIZE)
19444 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19445 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
19446 goto bottomup;
19447
19448 +#ifdef CONFIG_PAX_RANDMMAP
19449 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19450 +#endif
19451 +
19452 /* requesting a specific address */
19453 if (addr) {
19454 addr = PAGE_ALIGN(addr);
19455 - vma = find_vma(mm, addr);
19456 - if (TASK_SIZE - len >= addr &&
19457 - (!vma || addr + len <= vma->vm_start))
19458 - return addr;
19459 + if (TASK_SIZE - len >= addr) {
19460 + vma = find_vma(mm, addr);
19461 + if (check_heap_stack_gap(vma, addr, len))
19462 + return addr;
19463 + }
19464 }
19465
19466 /* check if free_area_cache is useful for us */
19467 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19468 ALIGN_TOPDOWN);
19469
19470 vma = find_vma(mm, tmp_addr);
19471 - if (!vma || tmp_addr + len <= vma->vm_start)
19472 + if (check_heap_stack_gap(vma, tmp_addr, len))
19473 /* remember the address as a hint for next time */
19474 return mm->free_area_cache = tmp_addr;
19475 }
19476 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19477 * return with success:
19478 */
19479 vma = find_vma(mm, addr);
19480 - if (!vma || addr+len <= vma->vm_start)
19481 + if (check_heap_stack_gap(vma, addr, len))
19482 /* remember the address as a hint for next time */
19483 return mm->free_area_cache = addr;
19484
19485 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19486 mm->cached_hole_size = vma->vm_start - addr;
19487
19488 /* try just below the current vma->vm_start */
19489 - addr = vma->vm_start-len;
19490 - } while (len < vma->vm_start);
19491 + addr = skip_heap_stack_gap(vma, len);
19492 + } while (!IS_ERR_VALUE(addr));
19493
19494 bottomup:
19495 /*
19496 @@ -270,13 +278,21 @@ bottomup:
19497 * can happen with large stack limits and large mmap()
19498 * allocations.
19499 */
19500 + mm->mmap_base = TASK_UNMAPPED_BASE;
19501 +
19502 +#ifdef CONFIG_PAX_RANDMMAP
19503 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19504 + mm->mmap_base += mm->delta_mmap;
19505 +#endif
19506 +
19507 + mm->free_area_cache = mm->mmap_base;
19508 mm->cached_hole_size = ~0UL;
19509 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19510 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19511 /*
19512 * Restore the topdown base:
19513 */
19514 - mm->free_area_cache = mm->mmap_base;
19515 + mm->mmap_base = base;
19516 + mm->free_area_cache = base;
19517 mm->cached_hole_size = ~0UL;
19518
19519 return addr;
19520 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19521 index e2410e2..4fe3fbc 100644
19522 --- a/arch/x86/kernel/tboot.c
19523 +++ b/arch/x86/kernel/tboot.c
19524 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
19525
19526 void tboot_shutdown(u32 shutdown_type)
19527 {
19528 - void (*shutdown)(void);
19529 + void (* __noreturn shutdown)(void);
19530
19531 if (!tboot_enabled())
19532 return;
19533 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
19534
19535 switch_to_tboot_pt();
19536
19537 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19538 + shutdown = (void *)tboot->shutdown_entry;
19539 shutdown();
19540
19541 /* should not reach here */
19542 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19543 tboot_shutdown(acpi_shutdown_map[sleep_state]);
19544 }
19545
19546 -static atomic_t ap_wfs_count;
19547 +static atomic_unchecked_t ap_wfs_count;
19548
19549 static int tboot_wait_for_aps(int num_aps)
19550 {
19551 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19552 {
19553 switch (action) {
19554 case CPU_DYING:
19555 - atomic_inc(&ap_wfs_count);
19556 + atomic_inc_unchecked(&ap_wfs_count);
19557 if (num_online_cpus() == 1)
19558 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19559 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19560 return NOTIFY_BAD;
19561 break;
19562 }
19563 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
19564
19565 tboot_create_trampoline();
19566
19567 - atomic_set(&ap_wfs_count, 0);
19568 + atomic_set_unchecked(&ap_wfs_count, 0);
19569 register_hotcpu_notifier(&tboot_cpu_notifier);
19570 return 0;
19571 }
19572 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19573 index dd5fbf4..b7f2232 100644
19574 --- a/arch/x86/kernel/time.c
19575 +++ b/arch/x86/kernel/time.c
19576 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19577 {
19578 unsigned long pc = instruction_pointer(regs);
19579
19580 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19581 + if (!user_mode(regs) && in_lock_functions(pc)) {
19582 #ifdef CONFIG_FRAME_POINTER
19583 - return *(unsigned long *)(regs->bp + sizeof(long));
19584 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19585 #else
19586 unsigned long *sp =
19587 (unsigned long *)kernel_stack_pointer(regs);
19588 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19589 * or above a saved flags. Eflags has bits 22-31 zero,
19590 * kernel addresses don't.
19591 */
19592 +
19593 +#ifdef CONFIG_PAX_KERNEXEC
19594 + return ktla_ktva(sp[0]);
19595 +#else
19596 if (sp[0] >> 22)
19597 return sp[0];
19598 if (sp[1] >> 22)
19599 return sp[1];
19600 #endif
19601 +
19602 +#endif
19603 }
19604 return pc;
19605 }
19606 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19607 index bcfec2d..8f88b4a 100644
19608 --- a/arch/x86/kernel/tls.c
19609 +++ b/arch/x86/kernel/tls.c
19610 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19611 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19612 return -EINVAL;
19613
19614 +#ifdef CONFIG_PAX_SEGMEXEC
19615 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19616 + return -EINVAL;
19617 +#endif
19618 +
19619 set_tls_desc(p, idx, &info, 1);
19620
19621 return 0;
19622 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
19623 index 451c0a7..e57f551 100644
19624 --- a/arch/x86/kernel/trampoline_32.S
19625 +++ b/arch/x86/kernel/trampoline_32.S
19626 @@ -32,6 +32,12 @@
19627 #include <asm/segment.h>
19628 #include <asm/page_types.h>
19629
19630 +#ifdef CONFIG_PAX_KERNEXEC
19631 +#define ta(X) (X)
19632 +#else
19633 +#define ta(X) ((X) - __PAGE_OFFSET)
19634 +#endif
19635 +
19636 #ifdef CONFIG_SMP
19637
19638 .section ".x86_trampoline","a"
19639 @@ -62,7 +68,7 @@ r_base = .
19640 inc %ax # protected mode (PE) bit
19641 lmsw %ax # into protected mode
19642 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
19643 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
19644 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
19645
19646 # These need to be in the same 64K segment as the above;
19647 # hence we don't use the boot_gdt_descr defined in head.S
19648 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
19649 index 09ff517..df19fbff 100644
19650 --- a/arch/x86/kernel/trampoline_64.S
19651 +++ b/arch/x86/kernel/trampoline_64.S
19652 @@ -90,7 +90,7 @@ startup_32:
19653 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
19654 movl %eax, %ds
19655
19656 - movl $X86_CR4_PAE, %eax
19657 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19658 movl %eax, %cr4 # Enable PAE mode
19659
19660 # Setup trampoline 4 level pagetables
19661 @@ -138,7 +138,7 @@ tidt:
19662 # so the kernel can live anywhere
19663 .balign 4
19664 tgdt:
19665 - .short tgdt_end - tgdt # gdt limit
19666 + .short tgdt_end - tgdt - 1 # gdt limit
19667 .long tgdt - r_base
19668 .short 0
19669 .quad 0x00cf9b000000ffff # __KERNEL32_CS
19670 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19671 index 4bbe04d..41d0943 100644
19672 --- a/arch/x86/kernel/traps.c
19673 +++ b/arch/x86/kernel/traps.c
19674 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19675
19676 /* Do we ignore FPU interrupts ? */
19677 char ignore_fpu_irq;
19678 -
19679 -/*
19680 - * The IDT has to be page-aligned to simplify the Pentium
19681 - * F0 0F bug workaround.
19682 - */
19683 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19684 #endif
19685
19686 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19687 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19688 }
19689
19690 static void __kprobes
19691 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19692 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19693 long error_code, siginfo_t *info)
19694 {
19695 struct task_struct *tsk = current;
19696
19697 #ifdef CONFIG_X86_32
19698 - if (regs->flags & X86_VM_MASK) {
19699 + if (v8086_mode(regs)) {
19700 /*
19701 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19702 * On nmi (interrupt 2), do_trap should not be called.
19703 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19704 }
19705 #endif
19706
19707 - if (!user_mode(regs))
19708 + if (!user_mode_novm(regs))
19709 goto kernel_trap;
19710
19711 #ifdef CONFIG_X86_32
19712 @@ -148,7 +142,7 @@ trap_signal:
19713 printk_ratelimit()) {
19714 printk(KERN_INFO
19715 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19716 - tsk->comm, tsk->pid, str,
19717 + tsk->comm, task_pid_nr(tsk), str,
19718 regs->ip, regs->sp, error_code);
19719 print_vma_addr(" in ", regs->ip);
19720 printk("\n");
19721 @@ -165,8 +159,20 @@ kernel_trap:
19722 if (!fixup_exception(regs)) {
19723 tsk->thread.error_code = error_code;
19724 tsk->thread.trap_no = trapnr;
19725 +
19726 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19727 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19728 + str = "PAX: suspicious stack segment fault";
19729 +#endif
19730 +
19731 die(str, regs, error_code);
19732 }
19733 +
19734 +#ifdef CONFIG_PAX_REFCOUNT
19735 + if (trapnr == 4)
19736 + pax_report_refcount_overflow(regs);
19737 +#endif
19738 +
19739 return;
19740
19741 #ifdef CONFIG_X86_32
19742 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19743 conditional_sti(regs);
19744
19745 #ifdef CONFIG_X86_32
19746 - if (regs->flags & X86_VM_MASK)
19747 + if (v8086_mode(regs))
19748 goto gp_in_vm86;
19749 #endif
19750
19751 tsk = current;
19752 - if (!user_mode(regs))
19753 + if (!user_mode_novm(regs))
19754 goto gp_in_kernel;
19755
19756 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19757 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19758 + struct mm_struct *mm = tsk->mm;
19759 + unsigned long limit;
19760 +
19761 + down_write(&mm->mmap_sem);
19762 + limit = mm->context.user_cs_limit;
19763 + if (limit < TASK_SIZE) {
19764 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19765 + up_write(&mm->mmap_sem);
19766 + return;
19767 + }
19768 + up_write(&mm->mmap_sem);
19769 + }
19770 +#endif
19771 +
19772 tsk->thread.error_code = error_code;
19773 tsk->thread.trap_no = 13;
19774
19775 @@ -295,6 +317,13 @@ gp_in_kernel:
19776 if (notify_die(DIE_GPF, "general protection fault", regs,
19777 error_code, 13, SIGSEGV) == NOTIFY_STOP)
19778 return;
19779 +
19780 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19781 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19782 + die("PAX: suspicious general protection fault", regs, error_code);
19783 + else
19784 +#endif
19785 +
19786 die("general protection fault", regs, error_code);
19787 }
19788
19789 @@ -421,7 +450,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19790 /* It's safe to allow irq's after DR6 has been saved */
19791 preempt_conditional_sti(regs);
19792
19793 - if (regs->flags & X86_VM_MASK) {
19794 + if (v8086_mode(regs)) {
19795 handle_vm86_trap((struct kernel_vm86_regs *) regs,
19796 error_code, 1);
19797 preempt_conditional_cli(regs);
19798 @@ -436,7 +465,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19799 * We already checked v86 mode above, so we can check for kernel mode
19800 * by just checking the CPL of CS.
19801 */
19802 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19803 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19804 tsk->thread.debugreg6 &= ~DR_STEP;
19805 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19806 regs->flags &= ~X86_EFLAGS_TF;
19807 @@ -466,7 +495,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19808 return;
19809 conditional_sti(regs);
19810
19811 - if (!user_mode_vm(regs))
19812 + if (!user_mode(regs))
19813 {
19814 if (!fixup_exception(regs)) {
19815 task->thread.error_code = error_code;
19816 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19817 index b9242ba..50c5edd 100644
19818 --- a/arch/x86/kernel/verify_cpu.S
19819 +++ b/arch/x86/kernel/verify_cpu.S
19820 @@ -20,6 +20,7 @@
19821 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19822 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19823 * arch/x86/kernel/head_32.S: processor startup
19824 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19825 *
19826 * verify_cpu, returns the status of longmode and SSE in register %eax.
19827 * 0: Success 1: Failure
19828 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19829 index 328cb37..56556b4 100644
19830 --- a/arch/x86/kernel/vm86_32.c
19831 +++ b/arch/x86/kernel/vm86_32.c
19832 @@ -41,6 +41,7 @@
19833 #include <linux/ptrace.h>
19834 #include <linux/audit.h>
19835 #include <linux/stddef.h>
19836 +#include <linux/grsecurity.h>
19837
19838 #include <asm/uaccess.h>
19839 #include <asm/io.h>
19840 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19841 do_exit(SIGSEGV);
19842 }
19843
19844 - tss = &per_cpu(init_tss, get_cpu());
19845 + tss = init_tss + get_cpu();
19846 current->thread.sp0 = current->thread.saved_sp0;
19847 current->thread.sysenter_cs = __KERNEL_CS;
19848 load_sp0(tss, &current->thread);
19849 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19850 struct task_struct *tsk;
19851 int tmp, ret = -EPERM;
19852
19853 +#ifdef CONFIG_GRKERNSEC_VM86
19854 + if (!capable(CAP_SYS_RAWIO)) {
19855 + gr_handle_vm86();
19856 + goto out;
19857 + }
19858 +#endif
19859 +
19860 tsk = current;
19861 if (tsk->thread.saved_sp0)
19862 goto out;
19863 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19864 int tmp, ret;
19865 struct vm86plus_struct __user *v86;
19866
19867 +#ifdef CONFIG_GRKERNSEC_VM86
19868 + if (!capable(CAP_SYS_RAWIO)) {
19869 + gr_handle_vm86();
19870 + ret = -EPERM;
19871 + goto out;
19872 + }
19873 +#endif
19874 +
19875 tsk = current;
19876 switch (cmd) {
19877 case VM86_REQUEST_IRQ:
19878 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19879 tsk->thread.saved_fs = info->regs32->fs;
19880 tsk->thread.saved_gs = get_user_gs(info->regs32);
19881
19882 - tss = &per_cpu(init_tss, get_cpu());
19883 + tss = init_tss + get_cpu();
19884 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19885 if (cpu_has_sep)
19886 tsk->thread.sysenter_cs = 0;
19887 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19888 goto cannot_handle;
19889 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19890 goto cannot_handle;
19891 - intr_ptr = (unsigned long __user *) (i << 2);
19892 + intr_ptr = (__force unsigned long __user *) (i << 2);
19893 if (get_user(segoffs, intr_ptr))
19894 goto cannot_handle;
19895 if ((segoffs >> 16) == BIOSSEG)
19896 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19897 index 0f703f1..9e15f64 100644
19898 --- a/arch/x86/kernel/vmlinux.lds.S
19899 +++ b/arch/x86/kernel/vmlinux.lds.S
19900 @@ -26,6 +26,13 @@
19901 #include <asm/page_types.h>
19902 #include <asm/cache.h>
19903 #include <asm/boot.h>
19904 +#include <asm/segment.h>
19905 +
19906 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19907 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
19908 +#else
19909 +#define __KERNEL_TEXT_OFFSET 0
19910 +#endif
19911
19912 #undef i386 /* in case the preprocessor is a 32bit one */
19913
19914 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
19915
19916 PHDRS {
19917 text PT_LOAD FLAGS(5); /* R_E */
19918 +#ifdef CONFIG_X86_32
19919 + module PT_LOAD FLAGS(5); /* R_E */
19920 +#endif
19921 +#ifdef CONFIG_XEN
19922 + rodata PT_LOAD FLAGS(5); /* R_E */
19923 +#else
19924 + rodata PT_LOAD FLAGS(4); /* R__ */
19925 +#endif
19926 data PT_LOAD FLAGS(6); /* RW_ */
19927 -#ifdef CONFIG_X86_64
19928 + init.begin PT_LOAD FLAGS(6); /* RW_ */
19929 #ifdef CONFIG_SMP
19930 percpu PT_LOAD FLAGS(6); /* RW_ */
19931 #endif
19932 + text.init PT_LOAD FLAGS(5); /* R_E */
19933 + text.exit PT_LOAD FLAGS(5); /* R_E */
19934 init PT_LOAD FLAGS(7); /* RWE */
19935 -#endif
19936 note PT_NOTE FLAGS(0); /* ___ */
19937 }
19938
19939 SECTIONS
19940 {
19941 #ifdef CONFIG_X86_32
19942 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
19943 - phys_startup_32 = startup_32 - LOAD_OFFSET;
19944 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
19945 #else
19946 - . = __START_KERNEL;
19947 - phys_startup_64 = startup_64 - LOAD_OFFSET;
19948 + . = __START_KERNEL;
19949 #endif
19950
19951 /* Text and read-only data */
19952 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
19953 - _text = .;
19954 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
19955 /* bootstrapping code */
19956 +#ifdef CONFIG_X86_32
19957 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19958 +#else
19959 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19960 +#endif
19961 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
19962 + _text = .;
19963 HEAD_TEXT
19964 #ifdef CONFIG_X86_32
19965 . = ALIGN(PAGE_SIZE);
19966 @@ -108,13 +128,47 @@ SECTIONS
19967 IRQENTRY_TEXT
19968 *(.fixup)
19969 *(.gnu.warning)
19970 - /* End of text section */
19971 - _etext = .;
19972 } :text = 0x9090
19973
19974 - NOTES :text :note
19975 + . += __KERNEL_TEXT_OFFSET;
19976
19977 - EXCEPTION_TABLE(16) :text = 0x9090
19978 +#ifdef CONFIG_X86_32
19979 + . = ALIGN(PAGE_SIZE);
19980 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
19981 +
19982 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
19983 + MODULES_EXEC_VADDR = .;
19984 + BYTE(0)
19985 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
19986 + . = ALIGN(HPAGE_SIZE);
19987 + MODULES_EXEC_END = . - 1;
19988 +#endif
19989 +
19990 + } :module
19991 +#endif
19992 +
19993 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
19994 + /* End of text section */
19995 + _etext = . - __KERNEL_TEXT_OFFSET;
19996 + }
19997 +
19998 +#ifdef CONFIG_X86_32
19999 + . = ALIGN(PAGE_SIZE);
20000 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20001 + *(.idt)
20002 + . = ALIGN(PAGE_SIZE);
20003 + *(.empty_zero_page)
20004 + *(.initial_pg_fixmap)
20005 + *(.initial_pg_pmd)
20006 + *(.initial_page_table)
20007 + *(.swapper_pg_dir)
20008 + } :rodata
20009 +#endif
20010 +
20011 + . = ALIGN(PAGE_SIZE);
20012 + NOTES :rodata :note
20013 +
20014 + EXCEPTION_TABLE(16) :rodata
20015
20016 #if defined(CONFIG_DEBUG_RODATA)
20017 /* .text should occupy whole number of pages */
20018 @@ -126,16 +180,20 @@ SECTIONS
20019
20020 /* Data */
20021 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20022 +
20023 +#ifdef CONFIG_PAX_KERNEXEC
20024 + . = ALIGN(HPAGE_SIZE);
20025 +#else
20026 + . = ALIGN(PAGE_SIZE);
20027 +#endif
20028 +
20029 /* Start of data section */
20030 _sdata = .;
20031
20032 /* init_task */
20033 INIT_TASK_DATA(THREAD_SIZE)
20034
20035 -#ifdef CONFIG_X86_32
20036 - /* 32 bit has nosave before _edata */
20037 NOSAVE_DATA
20038 -#endif
20039
20040 PAGE_ALIGNED_DATA(PAGE_SIZE)
20041
20042 @@ -176,12 +234,19 @@ SECTIONS
20043 #endif /* CONFIG_X86_64 */
20044
20045 /* Init code and data - will be freed after init */
20046 - . = ALIGN(PAGE_SIZE);
20047 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20048 + BYTE(0)
20049 +
20050 +#ifdef CONFIG_PAX_KERNEXEC
20051 + . = ALIGN(HPAGE_SIZE);
20052 +#else
20053 + . = ALIGN(PAGE_SIZE);
20054 +#endif
20055 +
20056 __init_begin = .; /* paired with __init_end */
20057 - }
20058 + } :init.begin
20059
20060 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20061 +#ifdef CONFIG_SMP
20062 /*
20063 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20064 * output PHDR, so the next output section - .init.text - should
20065 @@ -190,12 +255,27 @@ SECTIONS
20066 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20067 #endif
20068
20069 - INIT_TEXT_SECTION(PAGE_SIZE)
20070 -#ifdef CONFIG_X86_64
20071 - :init
20072 -#endif
20073 + . = ALIGN(PAGE_SIZE);
20074 + init_begin = .;
20075 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20076 + VMLINUX_SYMBOL(_sinittext) = .;
20077 + INIT_TEXT
20078 + VMLINUX_SYMBOL(_einittext) = .;
20079 + . = ALIGN(PAGE_SIZE);
20080 + } :text.init
20081
20082 - INIT_DATA_SECTION(16)
20083 + /*
20084 + * .exit.text is discard at runtime, not link time, to deal with
20085 + * references from .altinstructions and .eh_frame
20086 + */
20087 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20088 + EXIT_TEXT
20089 + . = ALIGN(16);
20090 + } :text.exit
20091 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20092 +
20093 + . = ALIGN(PAGE_SIZE);
20094 + INIT_DATA_SECTION(16) :init
20095
20096 /*
20097 * Code and data for a variety of lowlevel trampolines, to be
20098 @@ -269,19 +349,12 @@ SECTIONS
20099 }
20100
20101 . = ALIGN(8);
20102 - /*
20103 - * .exit.text is discard at runtime, not link time, to deal with
20104 - * references from .altinstructions and .eh_frame
20105 - */
20106 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20107 - EXIT_TEXT
20108 - }
20109
20110 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20111 EXIT_DATA
20112 }
20113
20114 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20115 +#ifndef CONFIG_SMP
20116 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20117 #endif
20118
20119 @@ -300,16 +373,10 @@ SECTIONS
20120 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20121 __smp_locks = .;
20122 *(.smp_locks)
20123 - . = ALIGN(PAGE_SIZE);
20124 __smp_locks_end = .;
20125 + . = ALIGN(PAGE_SIZE);
20126 }
20127
20128 -#ifdef CONFIG_X86_64
20129 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20130 - NOSAVE_DATA
20131 - }
20132 -#endif
20133 -
20134 /* BSS */
20135 . = ALIGN(PAGE_SIZE);
20136 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20137 @@ -325,6 +392,7 @@ SECTIONS
20138 __brk_base = .;
20139 . += 64 * 1024; /* 64k alignment slop space */
20140 *(.brk_reservation) /* areas brk users have reserved */
20141 + . = ALIGN(HPAGE_SIZE);
20142 __brk_limit = .;
20143 }
20144
20145 @@ -351,13 +419,12 @@ SECTIONS
20146 * for the boot processor.
20147 */
20148 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20149 -INIT_PER_CPU(gdt_page);
20150 INIT_PER_CPU(irq_stack_union);
20151
20152 /*
20153 * Build-time check on the image size:
20154 */
20155 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20156 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20157 "kernel image bigger than KERNEL_IMAGE_SIZE");
20158
20159 #ifdef CONFIG_SMP
20160 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20161 index b07ba93..a212969 100644
20162 --- a/arch/x86/kernel/vsyscall_64.c
20163 +++ b/arch/x86/kernel/vsyscall_64.c
20164 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
20165 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
20166 };
20167
20168 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20169 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20170
20171 static int __init vsyscall_setup(char *str)
20172 {
20173 if (str) {
20174 if (!strcmp("emulate", str))
20175 vsyscall_mode = EMULATE;
20176 - else if (!strcmp("native", str))
20177 - vsyscall_mode = NATIVE;
20178 else if (!strcmp("none", str))
20179 vsyscall_mode = NONE;
20180 else
20181 @@ -207,7 +205,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20182
20183 tsk = current;
20184 if (seccomp_mode(&tsk->seccomp))
20185 - do_exit(SIGKILL);
20186 + do_group_exit(SIGKILL);
20187
20188 /*
20189 * With a real vsyscall, page faults cause SIGSEGV. We want to
20190 @@ -279,8 +277,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
20191 return true;
20192
20193 sigsegv:
20194 - force_sig(SIGSEGV, current);
20195 - return true;
20196 + do_group_exit(SIGKILL);
20197 }
20198
20199 /*
20200 @@ -333,10 +330,7 @@ void __init map_vsyscall(void)
20201 extern char __vvar_page;
20202 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20203
20204 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20205 - vsyscall_mode == NATIVE
20206 - ? PAGE_KERNEL_VSYSCALL
20207 - : PAGE_KERNEL_VVAR);
20208 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20209 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20210 (unsigned long)VSYSCALL_START);
20211
20212 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20213 index 9796c2f..f686fbf 100644
20214 --- a/arch/x86/kernel/x8664_ksyms_64.c
20215 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20216 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20217 EXPORT_SYMBOL(copy_user_generic_string);
20218 EXPORT_SYMBOL(copy_user_generic_unrolled);
20219 EXPORT_SYMBOL(__copy_user_nocache);
20220 -EXPORT_SYMBOL(_copy_from_user);
20221 -EXPORT_SYMBOL(_copy_to_user);
20222
20223 EXPORT_SYMBOL(copy_page);
20224 EXPORT_SYMBOL(clear_page);
20225 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20226 index 7110911..e8cdee5 100644
20227 --- a/arch/x86/kernel/xsave.c
20228 +++ b/arch/x86/kernel/xsave.c
20229 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20230 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20231 return -EINVAL;
20232
20233 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20234 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20235 fx_sw_user->extended_size -
20236 FP_XSTATE_MAGIC2_SIZE));
20237 if (err)
20238 @@ -266,7 +266,7 @@ fx_only:
20239 * the other extended state.
20240 */
20241 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20242 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20243 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20244 }
20245
20246 /*
20247 @@ -295,7 +295,7 @@ int restore_i387_xstate(void __user *buf)
20248 if (use_xsave())
20249 err = restore_user_xstate(buf);
20250 else
20251 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20252 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20253 buf);
20254 if (unlikely(err)) {
20255 /*
20256 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20257 index 89b02bf..0f6511d 100644
20258 --- a/arch/x86/kvm/cpuid.c
20259 +++ b/arch/x86/kvm/cpuid.c
20260 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20261 struct kvm_cpuid2 *cpuid,
20262 struct kvm_cpuid_entry2 __user *entries)
20263 {
20264 - int r;
20265 + int r, i;
20266
20267 r = -E2BIG;
20268 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20269 goto out;
20270 r = -EFAULT;
20271 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20272 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20273 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20274 goto out;
20275 + for (i = 0; i < cpuid->nent; ++i) {
20276 + struct kvm_cpuid_entry2 cpuid_entry;
20277 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20278 + goto out;
20279 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20280 + }
20281 vcpu->arch.cpuid_nent = cpuid->nent;
20282 kvm_apic_set_version(vcpu);
20283 kvm_x86_ops->cpuid_update(vcpu);
20284 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20285 struct kvm_cpuid2 *cpuid,
20286 struct kvm_cpuid_entry2 __user *entries)
20287 {
20288 - int r;
20289 + int r, i;
20290
20291 r = -E2BIG;
20292 if (cpuid->nent < vcpu->arch.cpuid_nent)
20293 goto out;
20294 r = -EFAULT;
20295 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20296 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20297 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20298 goto out;
20299 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20300 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20301 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20302 + goto out;
20303 + }
20304 return 0;
20305
20306 out:
20307 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20308 index 0982507..7f6d72f 100644
20309 --- a/arch/x86/kvm/emulate.c
20310 +++ b/arch/x86/kvm/emulate.c
20311 @@ -250,6 +250,7 @@ struct gprefix {
20312
20313 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20314 do { \
20315 + unsigned long _tmp; \
20316 __asm__ __volatile__ ( \
20317 _PRE_EFLAGS("0", "4", "2") \
20318 _op _suffix " %"_x"3,%1; " \
20319 @@ -264,8 +265,6 @@ struct gprefix {
20320 /* Raw emulation: instruction has two explicit operands. */
20321 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20322 do { \
20323 - unsigned long _tmp; \
20324 - \
20325 switch ((ctxt)->dst.bytes) { \
20326 case 2: \
20327 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20328 @@ -281,7 +280,6 @@ struct gprefix {
20329
20330 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20331 do { \
20332 - unsigned long _tmp; \
20333 switch ((ctxt)->dst.bytes) { \
20334 case 1: \
20335 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20336 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20337 index cfdc6e0..ab92e84 100644
20338 --- a/arch/x86/kvm/lapic.c
20339 +++ b/arch/x86/kvm/lapic.c
20340 @@ -54,7 +54,7 @@
20341 #define APIC_BUS_CYCLE_NS 1
20342
20343 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20344 -#define apic_debug(fmt, arg...)
20345 +#define apic_debug(fmt, arg...) do {} while (0)
20346
20347 #define APIC_LVT_NUM 6
20348 /* 14 is the version for Xeon and Pentium 8.4.8*/
20349 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20350 index 1561028..0ed7f14 100644
20351 --- a/arch/x86/kvm/paging_tmpl.h
20352 +++ b/arch/x86/kvm/paging_tmpl.h
20353 @@ -197,7 +197,7 @@ retry_walk:
20354 if (unlikely(kvm_is_error_hva(host_addr)))
20355 goto error;
20356
20357 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20358 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20359 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20360 goto error;
20361
20362 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20363 index e385214..f8df033 100644
20364 --- a/arch/x86/kvm/svm.c
20365 +++ b/arch/x86/kvm/svm.c
20366 @@ -3420,7 +3420,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20367 int cpu = raw_smp_processor_id();
20368
20369 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20370 +
20371 + pax_open_kernel();
20372 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20373 + pax_close_kernel();
20374 +
20375 load_TR_desc();
20376 }
20377
20378 @@ -3798,6 +3802,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20379 #endif
20380 #endif
20381
20382 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20383 + __set_fs(current_thread_info()->addr_limit);
20384 +#endif
20385 +
20386 reload_tss(vcpu);
20387
20388 local_irq_disable();
20389 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20390 index a7a6f60..04b745a 100644
20391 --- a/arch/x86/kvm/vmx.c
20392 +++ b/arch/x86/kvm/vmx.c
20393 @@ -1306,7 +1306,11 @@ static void reload_tss(void)
20394 struct desc_struct *descs;
20395
20396 descs = (void *)gdt->address;
20397 +
20398 + pax_open_kernel();
20399 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20400 + pax_close_kernel();
20401 +
20402 load_TR_desc();
20403 }
20404
20405 @@ -2637,8 +2641,11 @@ static __init int hardware_setup(void)
20406 if (!cpu_has_vmx_flexpriority())
20407 flexpriority_enabled = 0;
20408
20409 - if (!cpu_has_vmx_tpr_shadow())
20410 - kvm_x86_ops->update_cr8_intercept = NULL;
20411 + if (!cpu_has_vmx_tpr_shadow()) {
20412 + pax_open_kernel();
20413 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20414 + pax_close_kernel();
20415 + }
20416
20417 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20418 kvm_disable_largepages();
20419 @@ -3654,7 +3661,7 @@ static void vmx_set_constant_host_state(void)
20420 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20421
20422 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20423 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20424 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20425
20426 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20427 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20428 @@ -6192,6 +6199,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20429 "jmp .Lkvm_vmx_return \n\t"
20430 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20431 ".Lkvm_vmx_return: "
20432 +
20433 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20434 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20435 + ".Lkvm_vmx_return2: "
20436 +#endif
20437 +
20438 /* Save guest registers, load host registers, keep flags */
20439 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20440 "pop %0 \n\t"
20441 @@ -6240,6 +6253,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20442 #endif
20443 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20444 [wordsize]"i"(sizeof(ulong))
20445 +
20446 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20447 + ,[cs]"i"(__KERNEL_CS)
20448 +#endif
20449 +
20450 : "cc", "memory"
20451 , R"ax", R"bx", R"di", R"si"
20452 #ifdef CONFIG_X86_64
20453 @@ -6268,7 +6286,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20454 }
20455 }
20456
20457 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
20458 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
20459 +
20460 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20461 + loadsegment(fs, __KERNEL_PERCPU);
20462 +#endif
20463 +
20464 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20465 + __set_fs(current_thread_info()->addr_limit);
20466 +#endif
20467 +
20468 vmx->loaded_vmcs->launched = 1;
20469
20470 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
20471 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20472 index 8d1c6c6..99c2d5f 100644
20473 --- a/arch/x86/kvm/x86.c
20474 +++ b/arch/x86/kvm/x86.c
20475 @@ -1311,8 +1311,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20476 {
20477 struct kvm *kvm = vcpu->kvm;
20478 int lm = is_long_mode(vcpu);
20479 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20480 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20481 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20482 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20483 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20484 : kvm->arch.xen_hvm_config.blob_size_32;
20485 u32 page_num = data & ~PAGE_MASK;
20486 @@ -2145,6 +2145,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20487 if (n < msr_list.nmsrs)
20488 goto out;
20489 r = -EFAULT;
20490 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20491 + goto out;
20492 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20493 num_msrs_to_save * sizeof(u32)))
20494 goto out;
20495 @@ -2266,7 +2268,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20496 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20497 struct kvm_interrupt *irq)
20498 {
20499 - if (irq->irq < 0 || irq->irq >= 256)
20500 + if (irq->irq >= 256)
20501 return -EINVAL;
20502 if (irqchip_in_kernel(vcpu->kvm))
20503 return -ENXIO;
20504 @@ -4782,7 +4784,7 @@ static void kvm_set_mmio_spte_mask(void)
20505 kvm_mmu_set_mmio_spte_mask(mask);
20506 }
20507
20508 -int kvm_arch_init(void *opaque)
20509 +int kvm_arch_init(const void *opaque)
20510 {
20511 int r;
20512 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20513 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20514 index 642d880..44e0f3f 100644
20515 --- a/arch/x86/lguest/boot.c
20516 +++ b/arch/x86/lguest/boot.c
20517 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20518 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20519 * Launcher to reboot us.
20520 */
20521 -static void lguest_restart(char *reason)
20522 +static __noreturn void lguest_restart(char *reason)
20523 {
20524 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20525 + BUG();
20526 }
20527
20528 /*G:050
20529 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
20530 index 042f682..c92afb6 100644
20531 --- a/arch/x86/lib/atomic64_32.c
20532 +++ b/arch/x86/lib/atomic64_32.c
20533 @@ -8,18 +8,30 @@
20534
20535 long long atomic64_read_cx8(long long, const atomic64_t *v);
20536 EXPORT_SYMBOL(atomic64_read_cx8);
20537 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20538 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
20539 long long atomic64_set_cx8(long long, const atomic64_t *v);
20540 EXPORT_SYMBOL(atomic64_set_cx8);
20541 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
20542 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
20543 long long atomic64_xchg_cx8(long long, unsigned high);
20544 EXPORT_SYMBOL(atomic64_xchg_cx8);
20545 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
20546 EXPORT_SYMBOL(atomic64_add_return_cx8);
20547 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20548 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
20549 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
20550 EXPORT_SYMBOL(atomic64_sub_return_cx8);
20551 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20552 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
20553 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
20554 EXPORT_SYMBOL(atomic64_inc_return_cx8);
20555 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20556 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
20557 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
20558 EXPORT_SYMBOL(atomic64_dec_return_cx8);
20559 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
20560 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
20561 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
20562 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
20563 int atomic64_inc_not_zero_cx8(atomic64_t *v);
20564 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
20565 #ifndef CONFIG_X86_CMPXCHG64
20566 long long atomic64_read_386(long long, const atomic64_t *v);
20567 EXPORT_SYMBOL(atomic64_read_386);
20568 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
20569 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
20570 long long atomic64_set_386(long long, const atomic64_t *v);
20571 EXPORT_SYMBOL(atomic64_set_386);
20572 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
20573 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
20574 long long atomic64_xchg_386(long long, unsigned high);
20575 EXPORT_SYMBOL(atomic64_xchg_386);
20576 long long atomic64_add_return_386(long long a, atomic64_t *v);
20577 EXPORT_SYMBOL(atomic64_add_return_386);
20578 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20579 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
20580 long long atomic64_sub_return_386(long long a, atomic64_t *v);
20581 EXPORT_SYMBOL(atomic64_sub_return_386);
20582 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20583 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
20584 long long atomic64_inc_return_386(long long a, atomic64_t *v);
20585 EXPORT_SYMBOL(atomic64_inc_return_386);
20586 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20587 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
20588 long long atomic64_dec_return_386(long long a, atomic64_t *v);
20589 EXPORT_SYMBOL(atomic64_dec_return_386);
20590 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
20591 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
20592 long long atomic64_add_386(long long a, atomic64_t *v);
20593 EXPORT_SYMBOL(atomic64_add_386);
20594 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
20595 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
20596 long long atomic64_sub_386(long long a, atomic64_t *v);
20597 EXPORT_SYMBOL(atomic64_sub_386);
20598 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
20599 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
20600 long long atomic64_inc_386(long long a, atomic64_t *v);
20601 EXPORT_SYMBOL(atomic64_inc_386);
20602 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
20603 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
20604 long long atomic64_dec_386(long long a, atomic64_t *v);
20605 EXPORT_SYMBOL(atomic64_dec_386);
20606 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
20607 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
20608 long long atomic64_dec_if_positive_386(atomic64_t *v);
20609 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
20610 int atomic64_inc_not_zero_386(atomic64_t *v);
20611 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20612 index e8e7e0d..56fd1b0 100644
20613 --- a/arch/x86/lib/atomic64_386_32.S
20614 +++ b/arch/x86/lib/atomic64_386_32.S
20615 @@ -48,6 +48,10 @@ BEGIN(read)
20616 movl (v), %eax
20617 movl 4(v), %edx
20618 RET_ENDP
20619 +BEGIN(read_unchecked)
20620 + movl (v), %eax
20621 + movl 4(v), %edx
20622 +RET_ENDP
20623 #undef v
20624
20625 #define v %esi
20626 @@ -55,6 +59,10 @@ BEGIN(set)
20627 movl %ebx, (v)
20628 movl %ecx, 4(v)
20629 RET_ENDP
20630 +BEGIN(set_unchecked)
20631 + movl %ebx, (v)
20632 + movl %ecx, 4(v)
20633 +RET_ENDP
20634 #undef v
20635
20636 #define v %esi
20637 @@ -70,6 +78,20 @@ RET_ENDP
20638 BEGIN(add)
20639 addl %eax, (v)
20640 adcl %edx, 4(v)
20641 +
20642 +#ifdef CONFIG_PAX_REFCOUNT
20643 + jno 0f
20644 + subl %eax, (v)
20645 + sbbl %edx, 4(v)
20646 + int $4
20647 +0:
20648 + _ASM_EXTABLE(0b, 0b)
20649 +#endif
20650 +
20651 +RET_ENDP
20652 +BEGIN(add_unchecked)
20653 + addl %eax, (v)
20654 + adcl %edx, 4(v)
20655 RET_ENDP
20656 #undef v
20657
20658 @@ -77,6 +99,24 @@ RET_ENDP
20659 BEGIN(add_return)
20660 addl (v), %eax
20661 adcl 4(v), %edx
20662 +
20663 +#ifdef CONFIG_PAX_REFCOUNT
20664 + into
20665 +1234:
20666 + _ASM_EXTABLE(1234b, 2f)
20667 +#endif
20668 +
20669 + movl %eax, (v)
20670 + movl %edx, 4(v)
20671 +
20672 +#ifdef CONFIG_PAX_REFCOUNT
20673 +2:
20674 +#endif
20675 +
20676 +RET_ENDP
20677 +BEGIN(add_return_unchecked)
20678 + addl (v), %eax
20679 + adcl 4(v), %edx
20680 movl %eax, (v)
20681 movl %edx, 4(v)
20682 RET_ENDP
20683 @@ -86,6 +126,20 @@ RET_ENDP
20684 BEGIN(sub)
20685 subl %eax, (v)
20686 sbbl %edx, 4(v)
20687 +
20688 +#ifdef CONFIG_PAX_REFCOUNT
20689 + jno 0f
20690 + addl %eax, (v)
20691 + adcl %edx, 4(v)
20692 + int $4
20693 +0:
20694 + _ASM_EXTABLE(0b, 0b)
20695 +#endif
20696 +
20697 +RET_ENDP
20698 +BEGIN(sub_unchecked)
20699 + subl %eax, (v)
20700 + sbbl %edx, 4(v)
20701 RET_ENDP
20702 #undef v
20703
20704 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20705 sbbl $0, %edx
20706 addl (v), %eax
20707 adcl 4(v), %edx
20708 +
20709 +#ifdef CONFIG_PAX_REFCOUNT
20710 + into
20711 +1234:
20712 + _ASM_EXTABLE(1234b, 2f)
20713 +#endif
20714 +
20715 + movl %eax, (v)
20716 + movl %edx, 4(v)
20717 +
20718 +#ifdef CONFIG_PAX_REFCOUNT
20719 +2:
20720 +#endif
20721 +
20722 +RET_ENDP
20723 +BEGIN(sub_return_unchecked)
20724 + negl %edx
20725 + negl %eax
20726 + sbbl $0, %edx
20727 + addl (v), %eax
20728 + adcl 4(v), %edx
20729 movl %eax, (v)
20730 movl %edx, 4(v)
20731 RET_ENDP
20732 @@ -105,6 +180,20 @@ RET_ENDP
20733 BEGIN(inc)
20734 addl $1, (v)
20735 adcl $0, 4(v)
20736 +
20737 +#ifdef CONFIG_PAX_REFCOUNT
20738 + jno 0f
20739 + subl $1, (v)
20740 + sbbl $0, 4(v)
20741 + int $4
20742 +0:
20743 + _ASM_EXTABLE(0b, 0b)
20744 +#endif
20745 +
20746 +RET_ENDP
20747 +BEGIN(inc_unchecked)
20748 + addl $1, (v)
20749 + adcl $0, 4(v)
20750 RET_ENDP
20751 #undef v
20752
20753 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20754 movl 4(v), %edx
20755 addl $1, %eax
20756 adcl $0, %edx
20757 +
20758 +#ifdef CONFIG_PAX_REFCOUNT
20759 + into
20760 +1234:
20761 + _ASM_EXTABLE(1234b, 2f)
20762 +#endif
20763 +
20764 + movl %eax, (v)
20765 + movl %edx, 4(v)
20766 +
20767 +#ifdef CONFIG_PAX_REFCOUNT
20768 +2:
20769 +#endif
20770 +
20771 +RET_ENDP
20772 +BEGIN(inc_return_unchecked)
20773 + movl (v), %eax
20774 + movl 4(v), %edx
20775 + addl $1, %eax
20776 + adcl $0, %edx
20777 movl %eax, (v)
20778 movl %edx, 4(v)
20779 RET_ENDP
20780 @@ -123,6 +232,20 @@ RET_ENDP
20781 BEGIN(dec)
20782 subl $1, (v)
20783 sbbl $0, 4(v)
20784 +
20785 +#ifdef CONFIG_PAX_REFCOUNT
20786 + jno 0f
20787 + addl $1, (v)
20788 + adcl $0, 4(v)
20789 + int $4
20790 +0:
20791 + _ASM_EXTABLE(0b, 0b)
20792 +#endif
20793 +
20794 +RET_ENDP
20795 +BEGIN(dec_unchecked)
20796 + subl $1, (v)
20797 + sbbl $0, 4(v)
20798 RET_ENDP
20799 #undef v
20800
20801 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20802 movl 4(v), %edx
20803 subl $1, %eax
20804 sbbl $0, %edx
20805 +
20806 +#ifdef CONFIG_PAX_REFCOUNT
20807 + into
20808 +1234:
20809 + _ASM_EXTABLE(1234b, 2f)
20810 +#endif
20811 +
20812 + movl %eax, (v)
20813 + movl %edx, 4(v)
20814 +
20815 +#ifdef CONFIG_PAX_REFCOUNT
20816 +2:
20817 +#endif
20818 +
20819 +RET_ENDP
20820 +BEGIN(dec_return_unchecked)
20821 + movl (v), %eax
20822 + movl 4(v), %edx
20823 + subl $1, %eax
20824 + sbbl $0, %edx
20825 movl %eax, (v)
20826 movl %edx, 4(v)
20827 RET_ENDP
20828 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20829 adcl %edx, %edi
20830 addl (v), %eax
20831 adcl 4(v), %edx
20832 +
20833 +#ifdef CONFIG_PAX_REFCOUNT
20834 + into
20835 +1234:
20836 + _ASM_EXTABLE(1234b, 2f)
20837 +#endif
20838 +
20839 cmpl %eax, %esi
20840 je 3f
20841 1:
20842 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20843 1:
20844 addl $1, %eax
20845 adcl $0, %edx
20846 +
20847 +#ifdef CONFIG_PAX_REFCOUNT
20848 + into
20849 +1234:
20850 + _ASM_EXTABLE(1234b, 2f)
20851 +#endif
20852 +
20853 movl %eax, (v)
20854 movl %edx, 4(v)
20855 movl $1, %eax
20856 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20857 movl 4(v), %edx
20858 subl $1, %eax
20859 sbbl $0, %edx
20860 +
20861 +#ifdef CONFIG_PAX_REFCOUNT
20862 + into
20863 +1234:
20864 + _ASM_EXTABLE(1234b, 1f)
20865 +#endif
20866 +
20867 js 1f
20868 movl %eax, (v)
20869 movl %edx, 4(v)
20870 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20871 index 391a083..3a2cf39 100644
20872 --- a/arch/x86/lib/atomic64_cx8_32.S
20873 +++ b/arch/x86/lib/atomic64_cx8_32.S
20874 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20875 CFI_STARTPROC
20876
20877 read64 %ecx
20878 + pax_force_retaddr
20879 ret
20880 CFI_ENDPROC
20881 ENDPROC(atomic64_read_cx8)
20882
20883 +ENTRY(atomic64_read_unchecked_cx8)
20884 + CFI_STARTPROC
20885 +
20886 + read64 %ecx
20887 + pax_force_retaddr
20888 + ret
20889 + CFI_ENDPROC
20890 +ENDPROC(atomic64_read_unchecked_cx8)
20891 +
20892 ENTRY(atomic64_set_cx8)
20893 CFI_STARTPROC
20894
20895 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20896 cmpxchg8b (%esi)
20897 jne 1b
20898
20899 + pax_force_retaddr
20900 ret
20901 CFI_ENDPROC
20902 ENDPROC(atomic64_set_cx8)
20903
20904 +ENTRY(atomic64_set_unchecked_cx8)
20905 + CFI_STARTPROC
20906 +
20907 +1:
20908 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20909 + * are atomic on 586 and newer */
20910 + cmpxchg8b (%esi)
20911 + jne 1b
20912 +
20913 + pax_force_retaddr
20914 + ret
20915 + CFI_ENDPROC
20916 +ENDPROC(atomic64_set_unchecked_cx8)
20917 +
20918 ENTRY(atomic64_xchg_cx8)
20919 CFI_STARTPROC
20920
20921 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
20922 cmpxchg8b (%esi)
20923 jne 1b
20924
20925 + pax_force_retaddr
20926 ret
20927 CFI_ENDPROC
20928 ENDPROC(atomic64_xchg_cx8)
20929
20930 -.macro addsub_return func ins insc
20931 -ENTRY(atomic64_\func\()_return_cx8)
20932 +.macro addsub_return func ins insc unchecked=""
20933 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20934 CFI_STARTPROC
20935 SAVE ebp
20936 SAVE ebx
20937 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20938 movl %edx, %ecx
20939 \ins\()l %esi, %ebx
20940 \insc\()l %edi, %ecx
20941 +
20942 +.ifb \unchecked
20943 +#ifdef CONFIG_PAX_REFCOUNT
20944 + into
20945 +2:
20946 + _ASM_EXTABLE(2b, 3f)
20947 +#endif
20948 +.endif
20949 +
20950 LOCK_PREFIX
20951 cmpxchg8b (%ebp)
20952 jne 1b
20953 -
20954 -10:
20955 movl %ebx, %eax
20956 movl %ecx, %edx
20957 +
20958 +.ifb \unchecked
20959 +#ifdef CONFIG_PAX_REFCOUNT
20960 +3:
20961 +#endif
20962 +.endif
20963 +
20964 RESTORE edi
20965 RESTORE esi
20966 RESTORE ebx
20967 RESTORE ebp
20968 + pax_force_retaddr
20969 ret
20970 CFI_ENDPROC
20971 -ENDPROC(atomic64_\func\()_return_cx8)
20972 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
20973 .endm
20974
20975 addsub_return add add adc
20976 addsub_return sub sub sbb
20977 +addsub_return add add adc _unchecked
20978 +addsub_return sub sub sbb _unchecked
20979
20980 -.macro incdec_return func ins insc
20981 -ENTRY(atomic64_\func\()_return_cx8)
20982 +.macro incdec_return func ins insc unchecked=""
20983 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20984 CFI_STARTPROC
20985 SAVE ebx
20986
20987 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
20988 movl %edx, %ecx
20989 \ins\()l $1, %ebx
20990 \insc\()l $0, %ecx
20991 +
20992 +.ifb \unchecked
20993 +#ifdef CONFIG_PAX_REFCOUNT
20994 + into
20995 +2:
20996 + _ASM_EXTABLE(2b, 3f)
20997 +#endif
20998 +.endif
20999 +
21000 LOCK_PREFIX
21001 cmpxchg8b (%esi)
21002 jne 1b
21003
21004 -10:
21005 movl %ebx, %eax
21006 movl %ecx, %edx
21007 +
21008 +.ifb \unchecked
21009 +#ifdef CONFIG_PAX_REFCOUNT
21010 +3:
21011 +#endif
21012 +.endif
21013 +
21014 RESTORE ebx
21015 + pax_force_retaddr
21016 ret
21017 CFI_ENDPROC
21018 -ENDPROC(atomic64_\func\()_return_cx8)
21019 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21020 .endm
21021
21022 incdec_return inc add adc
21023 incdec_return dec sub sbb
21024 +incdec_return inc add adc _unchecked
21025 +incdec_return dec sub sbb _unchecked
21026
21027 ENTRY(atomic64_dec_if_positive_cx8)
21028 CFI_STARTPROC
21029 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21030 movl %edx, %ecx
21031 subl $1, %ebx
21032 sbb $0, %ecx
21033 +
21034 +#ifdef CONFIG_PAX_REFCOUNT
21035 + into
21036 +1234:
21037 + _ASM_EXTABLE(1234b, 2f)
21038 +#endif
21039 +
21040 js 2f
21041 LOCK_PREFIX
21042 cmpxchg8b (%esi)
21043 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21044 movl %ebx, %eax
21045 movl %ecx, %edx
21046 RESTORE ebx
21047 + pax_force_retaddr
21048 ret
21049 CFI_ENDPROC
21050 ENDPROC(atomic64_dec_if_positive_cx8)
21051 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
21052 movl %edx, %ecx
21053 addl %esi, %ebx
21054 adcl %edi, %ecx
21055 +
21056 +#ifdef CONFIG_PAX_REFCOUNT
21057 + into
21058 +1234:
21059 + _ASM_EXTABLE(1234b, 3f)
21060 +#endif
21061 +
21062 LOCK_PREFIX
21063 cmpxchg8b (%ebp)
21064 jne 1b
21065 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
21066 CFI_ADJUST_CFA_OFFSET -8
21067 RESTORE ebx
21068 RESTORE ebp
21069 + pax_force_retaddr
21070 ret
21071 4:
21072 cmpl %edx, 4(%esp)
21073 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21074 movl %edx, %ecx
21075 addl $1, %ebx
21076 adcl $0, %ecx
21077 +
21078 +#ifdef CONFIG_PAX_REFCOUNT
21079 + into
21080 +1234:
21081 + _ASM_EXTABLE(1234b, 3f)
21082 +#endif
21083 +
21084 LOCK_PREFIX
21085 cmpxchg8b (%esi)
21086 jne 1b
21087 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21088 movl $1, %eax
21089 3:
21090 RESTORE ebx
21091 + pax_force_retaddr
21092 ret
21093 4:
21094 testl %edx, %edx
21095 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21096 index 78d16a5..fbcf666 100644
21097 --- a/arch/x86/lib/checksum_32.S
21098 +++ b/arch/x86/lib/checksum_32.S
21099 @@ -28,7 +28,8 @@
21100 #include <linux/linkage.h>
21101 #include <asm/dwarf2.h>
21102 #include <asm/errno.h>
21103 -
21104 +#include <asm/segment.h>
21105 +
21106 /*
21107 * computes a partial checksum, e.g. for TCP/UDP fragments
21108 */
21109 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21110
21111 #define ARGBASE 16
21112 #define FP 12
21113 -
21114 -ENTRY(csum_partial_copy_generic)
21115 +
21116 +ENTRY(csum_partial_copy_generic_to_user)
21117 CFI_STARTPROC
21118 +
21119 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21120 + pushl_cfi %gs
21121 + popl_cfi %es
21122 + jmp csum_partial_copy_generic
21123 +#endif
21124 +
21125 +ENTRY(csum_partial_copy_generic_from_user)
21126 +
21127 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21128 + pushl_cfi %gs
21129 + popl_cfi %ds
21130 +#endif
21131 +
21132 +ENTRY(csum_partial_copy_generic)
21133 subl $4,%esp
21134 CFI_ADJUST_CFA_OFFSET 4
21135 pushl_cfi %edi
21136 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
21137 jmp 4f
21138 SRC(1: movw (%esi), %bx )
21139 addl $2, %esi
21140 -DST( movw %bx, (%edi) )
21141 +DST( movw %bx, %es:(%edi) )
21142 addl $2, %edi
21143 addw %bx, %ax
21144 adcl $0, %eax
21145 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
21146 SRC(1: movl (%esi), %ebx )
21147 SRC( movl 4(%esi), %edx )
21148 adcl %ebx, %eax
21149 -DST( movl %ebx, (%edi) )
21150 +DST( movl %ebx, %es:(%edi) )
21151 adcl %edx, %eax
21152 -DST( movl %edx, 4(%edi) )
21153 +DST( movl %edx, %es:4(%edi) )
21154
21155 SRC( movl 8(%esi), %ebx )
21156 SRC( movl 12(%esi), %edx )
21157 adcl %ebx, %eax
21158 -DST( movl %ebx, 8(%edi) )
21159 +DST( movl %ebx, %es:8(%edi) )
21160 adcl %edx, %eax
21161 -DST( movl %edx, 12(%edi) )
21162 +DST( movl %edx, %es:12(%edi) )
21163
21164 SRC( movl 16(%esi), %ebx )
21165 SRC( movl 20(%esi), %edx )
21166 adcl %ebx, %eax
21167 -DST( movl %ebx, 16(%edi) )
21168 +DST( movl %ebx, %es:16(%edi) )
21169 adcl %edx, %eax
21170 -DST( movl %edx, 20(%edi) )
21171 +DST( movl %edx, %es:20(%edi) )
21172
21173 SRC( movl 24(%esi), %ebx )
21174 SRC( movl 28(%esi), %edx )
21175 adcl %ebx, %eax
21176 -DST( movl %ebx, 24(%edi) )
21177 +DST( movl %ebx, %es:24(%edi) )
21178 adcl %edx, %eax
21179 -DST( movl %edx, 28(%edi) )
21180 +DST( movl %edx, %es:28(%edi) )
21181
21182 lea 32(%esi), %esi
21183 lea 32(%edi), %edi
21184 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
21185 shrl $2, %edx # This clears CF
21186 SRC(3: movl (%esi), %ebx )
21187 adcl %ebx, %eax
21188 -DST( movl %ebx, (%edi) )
21189 +DST( movl %ebx, %es:(%edi) )
21190 lea 4(%esi), %esi
21191 lea 4(%edi), %edi
21192 dec %edx
21193 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
21194 jb 5f
21195 SRC( movw (%esi), %cx )
21196 leal 2(%esi), %esi
21197 -DST( movw %cx, (%edi) )
21198 +DST( movw %cx, %es:(%edi) )
21199 leal 2(%edi), %edi
21200 je 6f
21201 shll $16,%ecx
21202 SRC(5: movb (%esi), %cl )
21203 -DST( movb %cl, (%edi) )
21204 +DST( movb %cl, %es:(%edi) )
21205 6: addl %ecx, %eax
21206 adcl $0, %eax
21207 7:
21208 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
21209
21210 6001:
21211 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21212 - movl $-EFAULT, (%ebx)
21213 + movl $-EFAULT, %ss:(%ebx)
21214
21215 # zero the complete destination - computing the rest
21216 # is too much work
21217 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
21218
21219 6002:
21220 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21221 - movl $-EFAULT,(%ebx)
21222 + movl $-EFAULT,%ss:(%ebx)
21223 jmp 5000b
21224
21225 .previous
21226
21227 + pushl_cfi %ss
21228 + popl_cfi %ds
21229 + pushl_cfi %ss
21230 + popl_cfi %es
21231 popl_cfi %ebx
21232 CFI_RESTORE ebx
21233 popl_cfi %esi
21234 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
21235 popl_cfi %ecx # equivalent to addl $4,%esp
21236 ret
21237 CFI_ENDPROC
21238 -ENDPROC(csum_partial_copy_generic)
21239 +ENDPROC(csum_partial_copy_generic_to_user)
21240
21241 #else
21242
21243 /* Version for PentiumII/PPro */
21244
21245 #define ROUND1(x) \
21246 + nop; nop; nop; \
21247 SRC(movl x(%esi), %ebx ) ; \
21248 addl %ebx, %eax ; \
21249 - DST(movl %ebx, x(%edi) ) ;
21250 + DST(movl %ebx, %es:x(%edi)) ;
21251
21252 #define ROUND(x) \
21253 + nop; nop; nop; \
21254 SRC(movl x(%esi), %ebx ) ; \
21255 adcl %ebx, %eax ; \
21256 - DST(movl %ebx, x(%edi) ) ;
21257 + DST(movl %ebx, %es:x(%edi)) ;
21258
21259 #define ARGBASE 12
21260 -
21261 -ENTRY(csum_partial_copy_generic)
21262 +
21263 +ENTRY(csum_partial_copy_generic_to_user)
21264 CFI_STARTPROC
21265 +
21266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21267 + pushl_cfi %gs
21268 + popl_cfi %es
21269 + jmp csum_partial_copy_generic
21270 +#endif
21271 +
21272 +ENTRY(csum_partial_copy_generic_from_user)
21273 +
21274 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21275 + pushl_cfi %gs
21276 + popl_cfi %ds
21277 +#endif
21278 +
21279 +ENTRY(csum_partial_copy_generic)
21280 pushl_cfi %ebx
21281 CFI_REL_OFFSET ebx, 0
21282 pushl_cfi %edi
21283 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
21284 subl %ebx, %edi
21285 lea -1(%esi),%edx
21286 andl $-32,%edx
21287 - lea 3f(%ebx,%ebx), %ebx
21288 + lea 3f(%ebx,%ebx,2), %ebx
21289 testl %esi, %esi
21290 jmp *%ebx
21291 1: addl $64,%esi
21292 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
21293 jb 5f
21294 SRC( movw (%esi), %dx )
21295 leal 2(%esi), %esi
21296 -DST( movw %dx, (%edi) )
21297 +DST( movw %dx, %es:(%edi) )
21298 leal 2(%edi), %edi
21299 je 6f
21300 shll $16,%edx
21301 5:
21302 SRC( movb (%esi), %dl )
21303 -DST( movb %dl, (%edi) )
21304 +DST( movb %dl, %es:(%edi) )
21305 6: addl %edx, %eax
21306 adcl $0, %eax
21307 7:
21308 .section .fixup, "ax"
21309 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21310 - movl $-EFAULT, (%ebx)
21311 + movl $-EFAULT, %ss:(%ebx)
21312 # zero the complete destination (computing the rest is too much work)
21313 movl ARGBASE+8(%esp),%edi # dst
21314 movl ARGBASE+12(%esp),%ecx # len
21315 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
21316 rep; stosb
21317 jmp 7b
21318 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21319 - movl $-EFAULT, (%ebx)
21320 + movl $-EFAULT, %ss:(%ebx)
21321 jmp 7b
21322 .previous
21323
21324 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21325 + pushl_cfi %ss
21326 + popl_cfi %ds
21327 + pushl_cfi %ss
21328 + popl_cfi %es
21329 +#endif
21330 +
21331 popl_cfi %esi
21332 CFI_RESTORE esi
21333 popl_cfi %edi
21334 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
21335 CFI_RESTORE ebx
21336 ret
21337 CFI_ENDPROC
21338 -ENDPROC(csum_partial_copy_generic)
21339 +ENDPROC(csum_partial_copy_generic_to_user)
21340
21341 #undef ROUND
21342 #undef ROUND1
21343 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21344 index f2145cf..cea889d 100644
21345 --- a/arch/x86/lib/clear_page_64.S
21346 +++ b/arch/x86/lib/clear_page_64.S
21347 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21348 movl $4096/8,%ecx
21349 xorl %eax,%eax
21350 rep stosq
21351 + pax_force_retaddr
21352 ret
21353 CFI_ENDPROC
21354 ENDPROC(clear_page_c)
21355 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21356 movl $4096,%ecx
21357 xorl %eax,%eax
21358 rep stosb
21359 + pax_force_retaddr
21360 ret
21361 CFI_ENDPROC
21362 ENDPROC(clear_page_c_e)
21363 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21364 leaq 64(%rdi),%rdi
21365 jnz .Lloop
21366 nop
21367 + pax_force_retaddr
21368 ret
21369 CFI_ENDPROC
21370 .Lclear_page_end:
21371 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21372
21373 #include <asm/cpufeature.h>
21374
21375 - .section .altinstr_replacement,"ax"
21376 + .section .altinstr_replacement,"a"
21377 1: .byte 0xeb /* jmp <disp8> */
21378 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21379 2: .byte 0xeb /* jmp <disp8> */
21380 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21381 index 1e572c5..2a162cd 100644
21382 --- a/arch/x86/lib/cmpxchg16b_emu.S
21383 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21384 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21385
21386 popf
21387 mov $1, %al
21388 + pax_force_retaddr
21389 ret
21390
21391 not_same:
21392 popf
21393 xor %al,%al
21394 + pax_force_retaddr
21395 ret
21396
21397 CFI_ENDPROC
21398 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21399 index 01c805b..dccb07f 100644
21400 --- a/arch/x86/lib/copy_page_64.S
21401 +++ b/arch/x86/lib/copy_page_64.S
21402 @@ -9,6 +9,7 @@ copy_page_c:
21403 CFI_STARTPROC
21404 movl $4096/8,%ecx
21405 rep movsq
21406 + pax_force_retaddr
21407 ret
21408 CFI_ENDPROC
21409 ENDPROC(copy_page_c)
21410 @@ -39,7 +40,7 @@ ENTRY(copy_page)
21411 movq 16 (%rsi), %rdx
21412 movq 24 (%rsi), %r8
21413 movq 32 (%rsi), %r9
21414 - movq 40 (%rsi), %r10
21415 + movq 40 (%rsi), %r13
21416 movq 48 (%rsi), %r11
21417 movq 56 (%rsi), %r12
21418
21419 @@ -50,7 +51,7 @@ ENTRY(copy_page)
21420 movq %rdx, 16 (%rdi)
21421 movq %r8, 24 (%rdi)
21422 movq %r9, 32 (%rdi)
21423 - movq %r10, 40 (%rdi)
21424 + movq %r13, 40 (%rdi)
21425 movq %r11, 48 (%rdi)
21426 movq %r12, 56 (%rdi)
21427
21428 @@ -69,7 +70,7 @@ ENTRY(copy_page)
21429 movq 16 (%rsi), %rdx
21430 movq 24 (%rsi), %r8
21431 movq 32 (%rsi), %r9
21432 - movq 40 (%rsi), %r10
21433 + movq 40 (%rsi), %r13
21434 movq 48 (%rsi), %r11
21435 movq 56 (%rsi), %r12
21436
21437 @@ -78,7 +79,7 @@ ENTRY(copy_page)
21438 movq %rdx, 16 (%rdi)
21439 movq %r8, 24 (%rdi)
21440 movq %r9, 32 (%rdi)
21441 - movq %r10, 40 (%rdi)
21442 + movq %r13, 40 (%rdi)
21443 movq %r11, 48 (%rdi)
21444 movq %r12, 56 (%rdi)
21445
21446 @@ -95,6 +96,7 @@ ENTRY(copy_page)
21447 CFI_RESTORE r13
21448 addq $3*8,%rsp
21449 CFI_ADJUST_CFA_OFFSET -3*8
21450 + pax_force_retaddr
21451 ret
21452 .Lcopy_page_end:
21453 CFI_ENDPROC
21454 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
21455
21456 #include <asm/cpufeature.h>
21457
21458 - .section .altinstr_replacement,"ax"
21459 + .section .altinstr_replacement,"a"
21460 1: .byte 0xeb /* jmp <disp8> */
21461 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21462 2:
21463 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21464 index 0248402..821c786 100644
21465 --- a/arch/x86/lib/copy_user_64.S
21466 +++ b/arch/x86/lib/copy_user_64.S
21467 @@ -16,6 +16,7 @@
21468 #include <asm/thread_info.h>
21469 #include <asm/cpufeature.h>
21470 #include <asm/alternative-asm.h>
21471 +#include <asm/pgtable.h>
21472
21473 /*
21474 * By placing feature2 after feature1 in altinstructions section, we logically
21475 @@ -29,7 +30,7 @@
21476 .byte 0xe9 /* 32bit jump */
21477 .long \orig-1f /* by default jump to orig */
21478 1:
21479 - .section .altinstr_replacement,"ax"
21480 + .section .altinstr_replacement,"a"
21481 2: .byte 0xe9 /* near jump with 32bit immediate */
21482 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21483 3: .byte 0xe9 /* near jump with 32bit immediate */
21484 @@ -71,47 +72,20 @@
21485 #endif
21486 .endm
21487
21488 -/* Standard copy_to_user with segment limit checking */
21489 -ENTRY(_copy_to_user)
21490 - CFI_STARTPROC
21491 - GET_THREAD_INFO(%rax)
21492 - movq %rdi,%rcx
21493 - addq %rdx,%rcx
21494 - jc bad_to_user
21495 - cmpq TI_addr_limit(%rax),%rcx
21496 - ja bad_to_user
21497 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21498 - copy_user_generic_unrolled,copy_user_generic_string, \
21499 - copy_user_enhanced_fast_string
21500 - CFI_ENDPROC
21501 -ENDPROC(_copy_to_user)
21502 -
21503 -/* Standard copy_from_user with segment limit checking */
21504 -ENTRY(_copy_from_user)
21505 - CFI_STARTPROC
21506 - GET_THREAD_INFO(%rax)
21507 - movq %rsi,%rcx
21508 - addq %rdx,%rcx
21509 - jc bad_from_user
21510 - cmpq TI_addr_limit(%rax),%rcx
21511 - ja bad_from_user
21512 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21513 - copy_user_generic_unrolled,copy_user_generic_string, \
21514 - copy_user_enhanced_fast_string
21515 - CFI_ENDPROC
21516 -ENDPROC(_copy_from_user)
21517 -
21518 .section .fixup,"ax"
21519 /* must zero dest */
21520 ENTRY(bad_from_user)
21521 bad_from_user:
21522 CFI_STARTPROC
21523 + testl %edx,%edx
21524 + js bad_to_user
21525 movl %edx,%ecx
21526 xorl %eax,%eax
21527 rep
21528 stosb
21529 bad_to_user:
21530 movl %edx,%eax
21531 + pax_force_retaddr
21532 ret
21533 CFI_ENDPROC
21534 ENDPROC(bad_from_user)
21535 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
21536 jz 17f
21537 1: movq (%rsi),%r8
21538 2: movq 1*8(%rsi),%r9
21539 -3: movq 2*8(%rsi),%r10
21540 +3: movq 2*8(%rsi),%rax
21541 4: movq 3*8(%rsi),%r11
21542 5: movq %r8,(%rdi)
21543 6: movq %r9,1*8(%rdi)
21544 -7: movq %r10,2*8(%rdi)
21545 +7: movq %rax,2*8(%rdi)
21546 8: movq %r11,3*8(%rdi)
21547 9: movq 4*8(%rsi),%r8
21548 10: movq 5*8(%rsi),%r9
21549 -11: movq 6*8(%rsi),%r10
21550 +11: movq 6*8(%rsi),%rax
21551 12: movq 7*8(%rsi),%r11
21552 13: movq %r8,4*8(%rdi)
21553 14: movq %r9,5*8(%rdi)
21554 -15: movq %r10,6*8(%rdi)
21555 +15: movq %rax,6*8(%rdi)
21556 16: movq %r11,7*8(%rdi)
21557 leaq 64(%rsi),%rsi
21558 leaq 64(%rdi),%rdi
21559 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
21560 decl %ecx
21561 jnz 21b
21562 23: xor %eax,%eax
21563 + pax_force_retaddr
21564 ret
21565
21566 .section .fixup,"ax"
21567 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
21568 3: rep
21569 movsb
21570 4: xorl %eax,%eax
21571 + pax_force_retaddr
21572 ret
21573
21574 .section .fixup,"ax"
21575 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
21576 1: rep
21577 movsb
21578 2: xorl %eax,%eax
21579 + pax_force_retaddr
21580 ret
21581
21582 .section .fixup,"ax"
21583 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21584 index cb0c112..e3a6895 100644
21585 --- a/arch/x86/lib/copy_user_nocache_64.S
21586 +++ b/arch/x86/lib/copy_user_nocache_64.S
21587 @@ -8,12 +8,14 @@
21588
21589 #include <linux/linkage.h>
21590 #include <asm/dwarf2.h>
21591 +#include <asm/alternative-asm.h>
21592
21593 #define FIX_ALIGNMENT 1
21594
21595 #include <asm/current.h>
21596 #include <asm/asm-offsets.h>
21597 #include <asm/thread_info.h>
21598 +#include <asm/pgtable.h>
21599
21600 .macro ALIGN_DESTINATION
21601 #ifdef FIX_ALIGNMENT
21602 @@ -50,6 +52,15 @@
21603 */
21604 ENTRY(__copy_user_nocache)
21605 CFI_STARTPROC
21606 +
21607 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21608 + mov $PAX_USER_SHADOW_BASE,%rcx
21609 + cmp %rcx,%rsi
21610 + jae 1f
21611 + add %rcx,%rsi
21612 +1:
21613 +#endif
21614 +
21615 cmpl $8,%edx
21616 jb 20f /* less then 8 bytes, go to byte copy loop */
21617 ALIGN_DESTINATION
21618 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
21619 jz 17f
21620 1: movq (%rsi),%r8
21621 2: movq 1*8(%rsi),%r9
21622 -3: movq 2*8(%rsi),%r10
21623 +3: movq 2*8(%rsi),%rax
21624 4: movq 3*8(%rsi),%r11
21625 5: movnti %r8,(%rdi)
21626 6: movnti %r9,1*8(%rdi)
21627 -7: movnti %r10,2*8(%rdi)
21628 +7: movnti %rax,2*8(%rdi)
21629 8: movnti %r11,3*8(%rdi)
21630 9: movq 4*8(%rsi),%r8
21631 10: movq 5*8(%rsi),%r9
21632 -11: movq 6*8(%rsi),%r10
21633 +11: movq 6*8(%rsi),%rax
21634 12: movq 7*8(%rsi),%r11
21635 13: movnti %r8,4*8(%rdi)
21636 14: movnti %r9,5*8(%rdi)
21637 -15: movnti %r10,6*8(%rdi)
21638 +15: movnti %rax,6*8(%rdi)
21639 16: movnti %r11,7*8(%rdi)
21640 leaq 64(%rsi),%rsi
21641 leaq 64(%rdi),%rdi
21642 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
21643 jnz 21b
21644 23: xorl %eax,%eax
21645 sfence
21646 + pax_force_retaddr
21647 ret
21648
21649 .section .fixup,"ax"
21650 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21651 index fb903b7..c92b7f7 100644
21652 --- a/arch/x86/lib/csum-copy_64.S
21653 +++ b/arch/x86/lib/csum-copy_64.S
21654 @@ -8,6 +8,7 @@
21655 #include <linux/linkage.h>
21656 #include <asm/dwarf2.h>
21657 #include <asm/errno.h>
21658 +#include <asm/alternative-asm.h>
21659
21660 /*
21661 * Checksum copy with exception handling.
21662 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
21663 CFI_RESTORE rbp
21664 addq $7*8, %rsp
21665 CFI_ADJUST_CFA_OFFSET -7*8
21666 + pax_force_retaddr 0, 1
21667 ret
21668 CFI_RESTORE_STATE
21669
21670 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21671 index 459b58a..9570bc7 100644
21672 --- a/arch/x86/lib/csum-wrappers_64.c
21673 +++ b/arch/x86/lib/csum-wrappers_64.c
21674 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21675 len -= 2;
21676 }
21677 }
21678 - isum = csum_partial_copy_generic((__force const void *)src,
21679 +
21680 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21681 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21682 + src += PAX_USER_SHADOW_BASE;
21683 +#endif
21684 +
21685 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21686 dst, len, isum, errp, NULL);
21687 if (unlikely(*errp))
21688 goto out_err;
21689 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21690 }
21691
21692 *errp = 0;
21693 - return csum_partial_copy_generic(src, (void __force *)dst,
21694 +
21695 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21696 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21697 + dst += PAX_USER_SHADOW_BASE;
21698 +#endif
21699 +
21700 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21701 len, isum, NULL, errp);
21702 }
21703 EXPORT_SYMBOL(csum_partial_copy_to_user);
21704 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21705 index 51f1504..ddac4c1 100644
21706 --- a/arch/x86/lib/getuser.S
21707 +++ b/arch/x86/lib/getuser.S
21708 @@ -33,15 +33,38 @@
21709 #include <asm/asm-offsets.h>
21710 #include <asm/thread_info.h>
21711 #include <asm/asm.h>
21712 +#include <asm/segment.h>
21713 +#include <asm/pgtable.h>
21714 +#include <asm/alternative-asm.h>
21715 +
21716 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21717 +#define __copyuser_seg gs;
21718 +#else
21719 +#define __copyuser_seg
21720 +#endif
21721
21722 .text
21723 ENTRY(__get_user_1)
21724 CFI_STARTPROC
21725 +
21726 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21727 GET_THREAD_INFO(%_ASM_DX)
21728 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21729 jae bad_get_user
21730 -1: movzb (%_ASM_AX),%edx
21731 +
21732 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21733 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21734 + cmp %_ASM_DX,%_ASM_AX
21735 + jae 1234f
21736 + add %_ASM_DX,%_ASM_AX
21737 +1234:
21738 +#endif
21739 +
21740 +#endif
21741 +
21742 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21743 xor %eax,%eax
21744 + pax_force_retaddr
21745 ret
21746 CFI_ENDPROC
21747 ENDPROC(__get_user_1)
21748 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21749 ENTRY(__get_user_2)
21750 CFI_STARTPROC
21751 add $1,%_ASM_AX
21752 +
21753 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21754 jc bad_get_user
21755 GET_THREAD_INFO(%_ASM_DX)
21756 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21757 jae bad_get_user
21758 -2: movzwl -1(%_ASM_AX),%edx
21759 +
21760 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21761 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21762 + cmp %_ASM_DX,%_ASM_AX
21763 + jae 1234f
21764 + add %_ASM_DX,%_ASM_AX
21765 +1234:
21766 +#endif
21767 +
21768 +#endif
21769 +
21770 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21771 xor %eax,%eax
21772 + pax_force_retaddr
21773 ret
21774 CFI_ENDPROC
21775 ENDPROC(__get_user_2)
21776 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21777 ENTRY(__get_user_4)
21778 CFI_STARTPROC
21779 add $3,%_ASM_AX
21780 +
21781 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21782 jc bad_get_user
21783 GET_THREAD_INFO(%_ASM_DX)
21784 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21785 jae bad_get_user
21786 -3: mov -3(%_ASM_AX),%edx
21787 +
21788 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21789 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21790 + cmp %_ASM_DX,%_ASM_AX
21791 + jae 1234f
21792 + add %_ASM_DX,%_ASM_AX
21793 +1234:
21794 +#endif
21795 +
21796 +#endif
21797 +
21798 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21799 xor %eax,%eax
21800 + pax_force_retaddr
21801 ret
21802 CFI_ENDPROC
21803 ENDPROC(__get_user_4)
21804 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21805 GET_THREAD_INFO(%_ASM_DX)
21806 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21807 jae bad_get_user
21808 +
21809 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21810 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21811 + cmp %_ASM_DX,%_ASM_AX
21812 + jae 1234f
21813 + add %_ASM_DX,%_ASM_AX
21814 +1234:
21815 +#endif
21816 +
21817 4: movq -7(%_ASM_AX),%_ASM_DX
21818 xor %eax,%eax
21819 + pax_force_retaddr
21820 ret
21821 CFI_ENDPROC
21822 ENDPROC(__get_user_8)
21823 @@ -91,6 +152,7 @@ bad_get_user:
21824 CFI_STARTPROC
21825 xor %edx,%edx
21826 mov $(-EFAULT),%_ASM_AX
21827 + pax_force_retaddr
21828 ret
21829 CFI_ENDPROC
21830 END(bad_get_user)
21831 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21832 index 5a1f9f3..ba9f577 100644
21833 --- a/arch/x86/lib/insn.c
21834 +++ b/arch/x86/lib/insn.c
21835 @@ -21,6 +21,11 @@
21836 #include <linux/string.h>
21837 #include <asm/inat.h>
21838 #include <asm/insn.h>
21839 +#ifdef __KERNEL__
21840 +#include <asm/pgtable_types.h>
21841 +#else
21842 +#define ktla_ktva(addr) addr
21843 +#endif
21844
21845 /* Verify next sizeof(t) bytes can be on the same instruction */
21846 #define validate_next(t, insn, n) \
21847 @@ -49,8 +54,8 @@
21848 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21849 {
21850 memset(insn, 0, sizeof(*insn));
21851 - insn->kaddr = kaddr;
21852 - insn->next_byte = kaddr;
21853 + insn->kaddr = ktla_ktva(kaddr);
21854 + insn->next_byte = ktla_ktva(kaddr);
21855 insn->x86_64 = x86_64 ? 1 : 0;
21856 insn->opnd_bytes = 4;
21857 if (x86_64)
21858 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21859 index 05a95e7..326f2fa 100644
21860 --- a/arch/x86/lib/iomap_copy_64.S
21861 +++ b/arch/x86/lib/iomap_copy_64.S
21862 @@ -17,6 +17,7 @@
21863
21864 #include <linux/linkage.h>
21865 #include <asm/dwarf2.h>
21866 +#include <asm/alternative-asm.h>
21867
21868 /*
21869 * override generic version in lib/iomap_copy.c
21870 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21871 CFI_STARTPROC
21872 movl %edx,%ecx
21873 rep movsd
21874 + pax_force_retaddr
21875 ret
21876 CFI_ENDPROC
21877 ENDPROC(__iowrite32_copy)
21878 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21879 index efbf2a0..8893637 100644
21880 --- a/arch/x86/lib/memcpy_64.S
21881 +++ b/arch/x86/lib/memcpy_64.S
21882 @@ -34,6 +34,7 @@
21883 rep movsq
21884 movl %edx, %ecx
21885 rep movsb
21886 + pax_force_retaddr
21887 ret
21888 .Lmemcpy_e:
21889 .previous
21890 @@ -51,6 +52,7 @@
21891
21892 movl %edx, %ecx
21893 rep movsb
21894 + pax_force_retaddr
21895 ret
21896 .Lmemcpy_e_e:
21897 .previous
21898 @@ -81,13 +83,13 @@ ENTRY(memcpy)
21899 */
21900 movq 0*8(%rsi), %r8
21901 movq 1*8(%rsi), %r9
21902 - movq 2*8(%rsi), %r10
21903 + movq 2*8(%rsi), %rcx
21904 movq 3*8(%rsi), %r11
21905 leaq 4*8(%rsi), %rsi
21906
21907 movq %r8, 0*8(%rdi)
21908 movq %r9, 1*8(%rdi)
21909 - movq %r10, 2*8(%rdi)
21910 + movq %rcx, 2*8(%rdi)
21911 movq %r11, 3*8(%rdi)
21912 leaq 4*8(%rdi), %rdi
21913 jae .Lcopy_forward_loop
21914 @@ -110,12 +112,12 @@ ENTRY(memcpy)
21915 subq $0x20, %rdx
21916 movq -1*8(%rsi), %r8
21917 movq -2*8(%rsi), %r9
21918 - movq -3*8(%rsi), %r10
21919 + movq -3*8(%rsi), %rcx
21920 movq -4*8(%rsi), %r11
21921 leaq -4*8(%rsi), %rsi
21922 movq %r8, -1*8(%rdi)
21923 movq %r9, -2*8(%rdi)
21924 - movq %r10, -3*8(%rdi)
21925 + movq %rcx, -3*8(%rdi)
21926 movq %r11, -4*8(%rdi)
21927 leaq -4*8(%rdi), %rdi
21928 jae .Lcopy_backward_loop
21929 @@ -135,12 +137,13 @@ ENTRY(memcpy)
21930 */
21931 movq 0*8(%rsi), %r8
21932 movq 1*8(%rsi), %r9
21933 - movq -2*8(%rsi, %rdx), %r10
21934 + movq -2*8(%rsi, %rdx), %rcx
21935 movq -1*8(%rsi, %rdx), %r11
21936 movq %r8, 0*8(%rdi)
21937 movq %r9, 1*8(%rdi)
21938 - movq %r10, -2*8(%rdi, %rdx)
21939 + movq %rcx, -2*8(%rdi, %rdx)
21940 movq %r11, -1*8(%rdi, %rdx)
21941 + pax_force_retaddr
21942 retq
21943 .p2align 4
21944 .Lless_16bytes:
21945 @@ -153,6 +156,7 @@ ENTRY(memcpy)
21946 movq -1*8(%rsi, %rdx), %r9
21947 movq %r8, 0*8(%rdi)
21948 movq %r9, -1*8(%rdi, %rdx)
21949 + pax_force_retaddr
21950 retq
21951 .p2align 4
21952 .Lless_8bytes:
21953 @@ -166,6 +170,7 @@ ENTRY(memcpy)
21954 movl -4(%rsi, %rdx), %r8d
21955 movl %ecx, (%rdi)
21956 movl %r8d, -4(%rdi, %rdx)
21957 + pax_force_retaddr
21958 retq
21959 .p2align 4
21960 .Lless_3bytes:
21961 @@ -183,6 +188,7 @@ ENTRY(memcpy)
21962 jnz .Lloop_1
21963
21964 .Lend:
21965 + pax_force_retaddr
21966 retq
21967 CFI_ENDPROC
21968 ENDPROC(memcpy)
21969 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
21970 index ee16461..c39c199 100644
21971 --- a/arch/x86/lib/memmove_64.S
21972 +++ b/arch/x86/lib/memmove_64.S
21973 @@ -61,13 +61,13 @@ ENTRY(memmove)
21974 5:
21975 sub $0x20, %rdx
21976 movq 0*8(%rsi), %r11
21977 - movq 1*8(%rsi), %r10
21978 + movq 1*8(%rsi), %rcx
21979 movq 2*8(%rsi), %r9
21980 movq 3*8(%rsi), %r8
21981 leaq 4*8(%rsi), %rsi
21982
21983 movq %r11, 0*8(%rdi)
21984 - movq %r10, 1*8(%rdi)
21985 + movq %rcx, 1*8(%rdi)
21986 movq %r9, 2*8(%rdi)
21987 movq %r8, 3*8(%rdi)
21988 leaq 4*8(%rdi), %rdi
21989 @@ -81,10 +81,10 @@ ENTRY(memmove)
21990 4:
21991 movq %rdx, %rcx
21992 movq -8(%rsi, %rdx), %r11
21993 - lea -8(%rdi, %rdx), %r10
21994 + lea -8(%rdi, %rdx), %r9
21995 shrq $3, %rcx
21996 rep movsq
21997 - movq %r11, (%r10)
21998 + movq %r11, (%r9)
21999 jmp 13f
22000 .Lmemmove_end_forward:
22001
22002 @@ -95,14 +95,14 @@ ENTRY(memmove)
22003 7:
22004 movq %rdx, %rcx
22005 movq (%rsi), %r11
22006 - movq %rdi, %r10
22007 + movq %rdi, %r9
22008 leaq -8(%rsi, %rdx), %rsi
22009 leaq -8(%rdi, %rdx), %rdi
22010 shrq $3, %rcx
22011 std
22012 rep movsq
22013 cld
22014 - movq %r11, (%r10)
22015 + movq %r11, (%r9)
22016 jmp 13f
22017
22018 /*
22019 @@ -127,13 +127,13 @@ ENTRY(memmove)
22020 8:
22021 subq $0x20, %rdx
22022 movq -1*8(%rsi), %r11
22023 - movq -2*8(%rsi), %r10
22024 + movq -2*8(%rsi), %rcx
22025 movq -3*8(%rsi), %r9
22026 movq -4*8(%rsi), %r8
22027 leaq -4*8(%rsi), %rsi
22028
22029 movq %r11, -1*8(%rdi)
22030 - movq %r10, -2*8(%rdi)
22031 + movq %rcx, -2*8(%rdi)
22032 movq %r9, -3*8(%rdi)
22033 movq %r8, -4*8(%rdi)
22034 leaq -4*8(%rdi), %rdi
22035 @@ -151,11 +151,11 @@ ENTRY(memmove)
22036 * Move data from 16 bytes to 31 bytes.
22037 */
22038 movq 0*8(%rsi), %r11
22039 - movq 1*8(%rsi), %r10
22040 + movq 1*8(%rsi), %rcx
22041 movq -2*8(%rsi, %rdx), %r9
22042 movq -1*8(%rsi, %rdx), %r8
22043 movq %r11, 0*8(%rdi)
22044 - movq %r10, 1*8(%rdi)
22045 + movq %rcx, 1*8(%rdi)
22046 movq %r9, -2*8(%rdi, %rdx)
22047 movq %r8, -1*8(%rdi, %rdx)
22048 jmp 13f
22049 @@ -167,9 +167,9 @@ ENTRY(memmove)
22050 * Move data from 8 bytes to 15 bytes.
22051 */
22052 movq 0*8(%rsi), %r11
22053 - movq -1*8(%rsi, %rdx), %r10
22054 + movq -1*8(%rsi, %rdx), %r9
22055 movq %r11, 0*8(%rdi)
22056 - movq %r10, -1*8(%rdi, %rdx)
22057 + movq %r9, -1*8(%rdi, %rdx)
22058 jmp 13f
22059 10:
22060 cmpq $4, %rdx
22061 @@ -178,9 +178,9 @@ ENTRY(memmove)
22062 * Move data from 4 bytes to 7 bytes.
22063 */
22064 movl (%rsi), %r11d
22065 - movl -4(%rsi, %rdx), %r10d
22066 + movl -4(%rsi, %rdx), %r9d
22067 movl %r11d, (%rdi)
22068 - movl %r10d, -4(%rdi, %rdx)
22069 + movl %r9d, -4(%rdi, %rdx)
22070 jmp 13f
22071 11:
22072 cmp $2, %rdx
22073 @@ -189,9 +189,9 @@ ENTRY(memmove)
22074 * Move data from 2 bytes to 3 bytes.
22075 */
22076 movw (%rsi), %r11w
22077 - movw -2(%rsi, %rdx), %r10w
22078 + movw -2(%rsi, %rdx), %r9w
22079 movw %r11w, (%rdi)
22080 - movw %r10w, -2(%rdi, %rdx)
22081 + movw %r9w, -2(%rdi, %rdx)
22082 jmp 13f
22083 12:
22084 cmp $1, %rdx
22085 @@ -202,6 +202,7 @@ ENTRY(memmove)
22086 movb (%rsi), %r11b
22087 movb %r11b, (%rdi)
22088 13:
22089 + pax_force_retaddr
22090 retq
22091 CFI_ENDPROC
22092
22093 @@ -210,6 +211,7 @@ ENTRY(memmove)
22094 /* Forward moving data. */
22095 movq %rdx, %rcx
22096 rep movsb
22097 + pax_force_retaddr
22098 retq
22099 .Lmemmove_end_forward_efs:
22100 .previous
22101 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22102 index 79bd454..dff325a 100644
22103 --- a/arch/x86/lib/memset_64.S
22104 +++ b/arch/x86/lib/memset_64.S
22105 @@ -31,6 +31,7 @@
22106 movl %r8d,%ecx
22107 rep stosb
22108 movq %r9,%rax
22109 + pax_force_retaddr
22110 ret
22111 .Lmemset_e:
22112 .previous
22113 @@ -53,6 +54,7 @@
22114 movl %edx,%ecx
22115 rep stosb
22116 movq %r9,%rax
22117 + pax_force_retaddr
22118 ret
22119 .Lmemset_e_e:
22120 .previous
22121 @@ -60,13 +62,13 @@
22122 ENTRY(memset)
22123 ENTRY(__memset)
22124 CFI_STARTPROC
22125 - movq %rdi,%r10
22126 movq %rdx,%r11
22127
22128 /* expand byte value */
22129 movzbl %sil,%ecx
22130 movabs $0x0101010101010101,%rax
22131 mul %rcx /* with rax, clobbers rdx */
22132 + movq %rdi,%rdx
22133
22134 /* align dst */
22135 movl %edi,%r9d
22136 @@ -120,7 +122,8 @@ ENTRY(__memset)
22137 jnz .Lloop_1
22138
22139 .Lende:
22140 - movq %r10,%rax
22141 + movq %rdx,%rax
22142 + pax_force_retaddr
22143 ret
22144
22145 CFI_RESTORE_STATE
22146 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22147 index c9f2d9b..e7fd2c0 100644
22148 --- a/arch/x86/lib/mmx_32.c
22149 +++ b/arch/x86/lib/mmx_32.c
22150 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22151 {
22152 void *p;
22153 int i;
22154 + unsigned long cr0;
22155
22156 if (unlikely(in_interrupt()))
22157 return __memcpy(to, from, len);
22158 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22159 kernel_fpu_begin();
22160
22161 __asm__ __volatile__ (
22162 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22163 - " prefetch 64(%0)\n"
22164 - " prefetch 128(%0)\n"
22165 - " prefetch 192(%0)\n"
22166 - " prefetch 256(%0)\n"
22167 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22168 + " prefetch 64(%1)\n"
22169 + " prefetch 128(%1)\n"
22170 + " prefetch 192(%1)\n"
22171 + " prefetch 256(%1)\n"
22172 "2: \n"
22173 ".section .fixup, \"ax\"\n"
22174 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22175 + "3: \n"
22176 +
22177 +#ifdef CONFIG_PAX_KERNEXEC
22178 + " movl %%cr0, %0\n"
22179 + " movl %0, %%eax\n"
22180 + " andl $0xFFFEFFFF, %%eax\n"
22181 + " movl %%eax, %%cr0\n"
22182 +#endif
22183 +
22184 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22185 +
22186 +#ifdef CONFIG_PAX_KERNEXEC
22187 + " movl %0, %%cr0\n"
22188 +#endif
22189 +
22190 " jmp 2b\n"
22191 ".previous\n"
22192 _ASM_EXTABLE(1b, 3b)
22193 - : : "r" (from));
22194 + : "=&r" (cr0) : "r" (from) : "ax");
22195
22196 for ( ; i > 5; i--) {
22197 __asm__ __volatile__ (
22198 - "1: prefetch 320(%0)\n"
22199 - "2: movq (%0), %%mm0\n"
22200 - " movq 8(%0), %%mm1\n"
22201 - " movq 16(%0), %%mm2\n"
22202 - " movq 24(%0), %%mm3\n"
22203 - " movq %%mm0, (%1)\n"
22204 - " movq %%mm1, 8(%1)\n"
22205 - " movq %%mm2, 16(%1)\n"
22206 - " movq %%mm3, 24(%1)\n"
22207 - " movq 32(%0), %%mm0\n"
22208 - " movq 40(%0), %%mm1\n"
22209 - " movq 48(%0), %%mm2\n"
22210 - " movq 56(%0), %%mm3\n"
22211 - " movq %%mm0, 32(%1)\n"
22212 - " movq %%mm1, 40(%1)\n"
22213 - " movq %%mm2, 48(%1)\n"
22214 - " movq %%mm3, 56(%1)\n"
22215 + "1: prefetch 320(%1)\n"
22216 + "2: movq (%1), %%mm0\n"
22217 + " movq 8(%1), %%mm1\n"
22218 + " movq 16(%1), %%mm2\n"
22219 + " movq 24(%1), %%mm3\n"
22220 + " movq %%mm0, (%2)\n"
22221 + " movq %%mm1, 8(%2)\n"
22222 + " movq %%mm2, 16(%2)\n"
22223 + " movq %%mm3, 24(%2)\n"
22224 + " movq 32(%1), %%mm0\n"
22225 + " movq 40(%1), %%mm1\n"
22226 + " movq 48(%1), %%mm2\n"
22227 + " movq 56(%1), %%mm3\n"
22228 + " movq %%mm0, 32(%2)\n"
22229 + " movq %%mm1, 40(%2)\n"
22230 + " movq %%mm2, 48(%2)\n"
22231 + " movq %%mm3, 56(%2)\n"
22232 ".section .fixup, \"ax\"\n"
22233 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22234 + "3:\n"
22235 +
22236 +#ifdef CONFIG_PAX_KERNEXEC
22237 + " movl %%cr0, %0\n"
22238 + " movl %0, %%eax\n"
22239 + " andl $0xFFFEFFFF, %%eax\n"
22240 + " movl %%eax, %%cr0\n"
22241 +#endif
22242 +
22243 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22244 +
22245 +#ifdef CONFIG_PAX_KERNEXEC
22246 + " movl %0, %%cr0\n"
22247 +#endif
22248 +
22249 " jmp 2b\n"
22250 ".previous\n"
22251 _ASM_EXTABLE(1b, 3b)
22252 - : : "r" (from), "r" (to) : "memory");
22253 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22254
22255 from += 64;
22256 to += 64;
22257 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22258 static void fast_copy_page(void *to, void *from)
22259 {
22260 int i;
22261 + unsigned long cr0;
22262
22263 kernel_fpu_begin();
22264
22265 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22266 * but that is for later. -AV
22267 */
22268 __asm__ __volatile__(
22269 - "1: prefetch (%0)\n"
22270 - " prefetch 64(%0)\n"
22271 - " prefetch 128(%0)\n"
22272 - " prefetch 192(%0)\n"
22273 - " prefetch 256(%0)\n"
22274 + "1: prefetch (%1)\n"
22275 + " prefetch 64(%1)\n"
22276 + " prefetch 128(%1)\n"
22277 + " prefetch 192(%1)\n"
22278 + " prefetch 256(%1)\n"
22279 "2: \n"
22280 ".section .fixup, \"ax\"\n"
22281 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22282 + "3: \n"
22283 +
22284 +#ifdef CONFIG_PAX_KERNEXEC
22285 + " movl %%cr0, %0\n"
22286 + " movl %0, %%eax\n"
22287 + " andl $0xFFFEFFFF, %%eax\n"
22288 + " movl %%eax, %%cr0\n"
22289 +#endif
22290 +
22291 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22292 +
22293 +#ifdef CONFIG_PAX_KERNEXEC
22294 + " movl %0, %%cr0\n"
22295 +#endif
22296 +
22297 " jmp 2b\n"
22298 ".previous\n"
22299 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22300 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22301
22302 for (i = 0; i < (4096-320)/64; i++) {
22303 __asm__ __volatile__ (
22304 - "1: prefetch 320(%0)\n"
22305 - "2: movq (%0), %%mm0\n"
22306 - " movntq %%mm0, (%1)\n"
22307 - " movq 8(%0), %%mm1\n"
22308 - " movntq %%mm1, 8(%1)\n"
22309 - " movq 16(%0), %%mm2\n"
22310 - " movntq %%mm2, 16(%1)\n"
22311 - " movq 24(%0), %%mm3\n"
22312 - " movntq %%mm3, 24(%1)\n"
22313 - " movq 32(%0), %%mm4\n"
22314 - " movntq %%mm4, 32(%1)\n"
22315 - " movq 40(%0), %%mm5\n"
22316 - " movntq %%mm5, 40(%1)\n"
22317 - " movq 48(%0), %%mm6\n"
22318 - " movntq %%mm6, 48(%1)\n"
22319 - " movq 56(%0), %%mm7\n"
22320 - " movntq %%mm7, 56(%1)\n"
22321 + "1: prefetch 320(%1)\n"
22322 + "2: movq (%1), %%mm0\n"
22323 + " movntq %%mm0, (%2)\n"
22324 + " movq 8(%1), %%mm1\n"
22325 + " movntq %%mm1, 8(%2)\n"
22326 + " movq 16(%1), %%mm2\n"
22327 + " movntq %%mm2, 16(%2)\n"
22328 + " movq 24(%1), %%mm3\n"
22329 + " movntq %%mm3, 24(%2)\n"
22330 + " movq 32(%1), %%mm4\n"
22331 + " movntq %%mm4, 32(%2)\n"
22332 + " movq 40(%1), %%mm5\n"
22333 + " movntq %%mm5, 40(%2)\n"
22334 + " movq 48(%1), %%mm6\n"
22335 + " movntq %%mm6, 48(%2)\n"
22336 + " movq 56(%1), %%mm7\n"
22337 + " movntq %%mm7, 56(%2)\n"
22338 ".section .fixup, \"ax\"\n"
22339 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22340 + "3:\n"
22341 +
22342 +#ifdef CONFIG_PAX_KERNEXEC
22343 + " movl %%cr0, %0\n"
22344 + " movl %0, %%eax\n"
22345 + " andl $0xFFFEFFFF, %%eax\n"
22346 + " movl %%eax, %%cr0\n"
22347 +#endif
22348 +
22349 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22350 +
22351 +#ifdef CONFIG_PAX_KERNEXEC
22352 + " movl %0, %%cr0\n"
22353 +#endif
22354 +
22355 " jmp 2b\n"
22356 ".previous\n"
22357 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22358 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22359
22360 from += 64;
22361 to += 64;
22362 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22363 static void fast_copy_page(void *to, void *from)
22364 {
22365 int i;
22366 + unsigned long cr0;
22367
22368 kernel_fpu_begin();
22369
22370 __asm__ __volatile__ (
22371 - "1: prefetch (%0)\n"
22372 - " prefetch 64(%0)\n"
22373 - " prefetch 128(%0)\n"
22374 - " prefetch 192(%0)\n"
22375 - " prefetch 256(%0)\n"
22376 + "1: prefetch (%1)\n"
22377 + " prefetch 64(%1)\n"
22378 + " prefetch 128(%1)\n"
22379 + " prefetch 192(%1)\n"
22380 + " prefetch 256(%1)\n"
22381 "2: \n"
22382 ".section .fixup, \"ax\"\n"
22383 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22384 + "3: \n"
22385 +
22386 +#ifdef CONFIG_PAX_KERNEXEC
22387 + " movl %%cr0, %0\n"
22388 + " movl %0, %%eax\n"
22389 + " andl $0xFFFEFFFF, %%eax\n"
22390 + " movl %%eax, %%cr0\n"
22391 +#endif
22392 +
22393 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22394 +
22395 +#ifdef CONFIG_PAX_KERNEXEC
22396 + " movl %0, %%cr0\n"
22397 +#endif
22398 +
22399 " jmp 2b\n"
22400 ".previous\n"
22401 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22402 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22403
22404 for (i = 0; i < 4096/64; i++) {
22405 __asm__ __volatile__ (
22406 - "1: prefetch 320(%0)\n"
22407 - "2: movq (%0), %%mm0\n"
22408 - " movq 8(%0), %%mm1\n"
22409 - " movq 16(%0), %%mm2\n"
22410 - " movq 24(%0), %%mm3\n"
22411 - " movq %%mm0, (%1)\n"
22412 - " movq %%mm1, 8(%1)\n"
22413 - " movq %%mm2, 16(%1)\n"
22414 - " movq %%mm3, 24(%1)\n"
22415 - " movq 32(%0), %%mm0\n"
22416 - " movq 40(%0), %%mm1\n"
22417 - " movq 48(%0), %%mm2\n"
22418 - " movq 56(%0), %%mm3\n"
22419 - " movq %%mm0, 32(%1)\n"
22420 - " movq %%mm1, 40(%1)\n"
22421 - " movq %%mm2, 48(%1)\n"
22422 - " movq %%mm3, 56(%1)\n"
22423 + "1: prefetch 320(%1)\n"
22424 + "2: movq (%1), %%mm0\n"
22425 + " movq 8(%1), %%mm1\n"
22426 + " movq 16(%1), %%mm2\n"
22427 + " movq 24(%1), %%mm3\n"
22428 + " movq %%mm0, (%2)\n"
22429 + " movq %%mm1, 8(%2)\n"
22430 + " movq %%mm2, 16(%2)\n"
22431 + " movq %%mm3, 24(%2)\n"
22432 + " movq 32(%1), %%mm0\n"
22433 + " movq 40(%1), %%mm1\n"
22434 + " movq 48(%1), %%mm2\n"
22435 + " movq 56(%1), %%mm3\n"
22436 + " movq %%mm0, 32(%2)\n"
22437 + " movq %%mm1, 40(%2)\n"
22438 + " movq %%mm2, 48(%2)\n"
22439 + " movq %%mm3, 56(%2)\n"
22440 ".section .fixup, \"ax\"\n"
22441 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22442 + "3:\n"
22443 +
22444 +#ifdef CONFIG_PAX_KERNEXEC
22445 + " movl %%cr0, %0\n"
22446 + " movl %0, %%eax\n"
22447 + " andl $0xFFFEFFFF, %%eax\n"
22448 + " movl %%eax, %%cr0\n"
22449 +#endif
22450 +
22451 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22452 +
22453 +#ifdef CONFIG_PAX_KERNEXEC
22454 + " movl %0, %%cr0\n"
22455 +#endif
22456 +
22457 " jmp 2b\n"
22458 ".previous\n"
22459 _ASM_EXTABLE(1b, 3b)
22460 - : : "r" (from), "r" (to) : "memory");
22461 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22462
22463 from += 64;
22464 to += 64;
22465 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22466 index 69fa106..adda88b 100644
22467 --- a/arch/x86/lib/msr-reg.S
22468 +++ b/arch/x86/lib/msr-reg.S
22469 @@ -3,6 +3,7 @@
22470 #include <asm/dwarf2.h>
22471 #include <asm/asm.h>
22472 #include <asm/msr.h>
22473 +#include <asm/alternative-asm.h>
22474
22475 #ifdef CONFIG_X86_64
22476 /*
22477 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22478 CFI_STARTPROC
22479 pushq_cfi %rbx
22480 pushq_cfi %rbp
22481 - movq %rdi, %r10 /* Save pointer */
22482 + movq %rdi, %r9 /* Save pointer */
22483 xorl %r11d, %r11d /* Return value */
22484 movl (%rdi), %eax
22485 movl 4(%rdi), %ecx
22486 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22487 movl 28(%rdi), %edi
22488 CFI_REMEMBER_STATE
22489 1: \op
22490 -2: movl %eax, (%r10)
22491 +2: movl %eax, (%r9)
22492 movl %r11d, %eax /* Return value */
22493 - movl %ecx, 4(%r10)
22494 - movl %edx, 8(%r10)
22495 - movl %ebx, 12(%r10)
22496 - movl %ebp, 20(%r10)
22497 - movl %esi, 24(%r10)
22498 - movl %edi, 28(%r10)
22499 + movl %ecx, 4(%r9)
22500 + movl %edx, 8(%r9)
22501 + movl %ebx, 12(%r9)
22502 + movl %ebp, 20(%r9)
22503 + movl %esi, 24(%r9)
22504 + movl %edi, 28(%r9)
22505 popq_cfi %rbp
22506 popq_cfi %rbx
22507 + pax_force_retaddr
22508 ret
22509 3:
22510 CFI_RESTORE_STATE
22511 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22512 index 36b0d15..d381858 100644
22513 --- a/arch/x86/lib/putuser.S
22514 +++ b/arch/x86/lib/putuser.S
22515 @@ -15,7 +15,9 @@
22516 #include <asm/thread_info.h>
22517 #include <asm/errno.h>
22518 #include <asm/asm.h>
22519 -
22520 +#include <asm/segment.h>
22521 +#include <asm/pgtable.h>
22522 +#include <asm/alternative-asm.h>
22523
22524 /*
22525 * __put_user_X
22526 @@ -29,52 +31,119 @@
22527 * as they get called from within inline assembly.
22528 */
22529
22530 -#define ENTER CFI_STARTPROC ; \
22531 - GET_THREAD_INFO(%_ASM_BX)
22532 -#define EXIT ret ; \
22533 +#define ENTER CFI_STARTPROC
22534 +#define EXIT pax_force_retaddr; ret ; \
22535 CFI_ENDPROC
22536
22537 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22538 +#define _DEST %_ASM_CX,%_ASM_BX
22539 +#else
22540 +#define _DEST %_ASM_CX
22541 +#endif
22542 +
22543 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22544 +#define __copyuser_seg gs;
22545 +#else
22546 +#define __copyuser_seg
22547 +#endif
22548 +
22549 .text
22550 ENTRY(__put_user_1)
22551 ENTER
22552 +
22553 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22554 + GET_THREAD_INFO(%_ASM_BX)
22555 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22556 jae bad_put_user
22557 -1: movb %al,(%_ASM_CX)
22558 +
22559 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22560 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22561 + cmp %_ASM_BX,%_ASM_CX
22562 + jb 1234f
22563 + xor %ebx,%ebx
22564 +1234:
22565 +#endif
22566 +
22567 +#endif
22568 +
22569 +1: __copyuser_seg movb %al,(_DEST)
22570 xor %eax,%eax
22571 EXIT
22572 ENDPROC(__put_user_1)
22573
22574 ENTRY(__put_user_2)
22575 ENTER
22576 +
22577 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22578 + GET_THREAD_INFO(%_ASM_BX)
22579 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22580 sub $1,%_ASM_BX
22581 cmp %_ASM_BX,%_ASM_CX
22582 jae bad_put_user
22583 -2: movw %ax,(%_ASM_CX)
22584 +
22585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22586 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22587 + cmp %_ASM_BX,%_ASM_CX
22588 + jb 1234f
22589 + xor %ebx,%ebx
22590 +1234:
22591 +#endif
22592 +
22593 +#endif
22594 +
22595 +2: __copyuser_seg movw %ax,(_DEST)
22596 xor %eax,%eax
22597 EXIT
22598 ENDPROC(__put_user_2)
22599
22600 ENTRY(__put_user_4)
22601 ENTER
22602 +
22603 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22604 + GET_THREAD_INFO(%_ASM_BX)
22605 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22606 sub $3,%_ASM_BX
22607 cmp %_ASM_BX,%_ASM_CX
22608 jae bad_put_user
22609 -3: movl %eax,(%_ASM_CX)
22610 +
22611 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22612 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22613 + cmp %_ASM_BX,%_ASM_CX
22614 + jb 1234f
22615 + xor %ebx,%ebx
22616 +1234:
22617 +#endif
22618 +
22619 +#endif
22620 +
22621 +3: __copyuser_seg movl %eax,(_DEST)
22622 xor %eax,%eax
22623 EXIT
22624 ENDPROC(__put_user_4)
22625
22626 ENTRY(__put_user_8)
22627 ENTER
22628 +
22629 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22630 + GET_THREAD_INFO(%_ASM_BX)
22631 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22632 sub $7,%_ASM_BX
22633 cmp %_ASM_BX,%_ASM_CX
22634 jae bad_put_user
22635 -4: mov %_ASM_AX,(%_ASM_CX)
22636 +
22637 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22638 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22639 + cmp %_ASM_BX,%_ASM_CX
22640 + jb 1234f
22641 + xor %ebx,%ebx
22642 +1234:
22643 +#endif
22644 +
22645 +#endif
22646 +
22647 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22648 #ifdef CONFIG_X86_32
22649 -5: movl %edx,4(%_ASM_CX)
22650 +5: __copyuser_seg movl %edx,4(_DEST)
22651 #endif
22652 xor %eax,%eax
22653 EXIT
22654 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22655 index 1cad221..de671ee 100644
22656 --- a/arch/x86/lib/rwlock.S
22657 +++ b/arch/x86/lib/rwlock.S
22658 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22659 FRAME
22660 0: LOCK_PREFIX
22661 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22662 +
22663 +#ifdef CONFIG_PAX_REFCOUNT
22664 + jno 1234f
22665 + LOCK_PREFIX
22666 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22667 + int $4
22668 +1234:
22669 + _ASM_EXTABLE(1234b, 1234b)
22670 +#endif
22671 +
22672 1: rep; nop
22673 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22674 jne 1b
22675 LOCK_PREFIX
22676 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22677 +
22678 +#ifdef CONFIG_PAX_REFCOUNT
22679 + jno 1234f
22680 + LOCK_PREFIX
22681 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22682 + int $4
22683 +1234:
22684 + _ASM_EXTABLE(1234b, 1234b)
22685 +#endif
22686 +
22687 jnz 0b
22688 ENDFRAME
22689 + pax_force_retaddr
22690 ret
22691 CFI_ENDPROC
22692 END(__write_lock_failed)
22693 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22694 FRAME
22695 0: LOCK_PREFIX
22696 READ_LOCK_SIZE(inc) (%__lock_ptr)
22697 +
22698 +#ifdef CONFIG_PAX_REFCOUNT
22699 + jno 1234f
22700 + LOCK_PREFIX
22701 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22702 + int $4
22703 +1234:
22704 + _ASM_EXTABLE(1234b, 1234b)
22705 +#endif
22706 +
22707 1: rep; nop
22708 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22709 js 1b
22710 LOCK_PREFIX
22711 READ_LOCK_SIZE(dec) (%__lock_ptr)
22712 +
22713 +#ifdef CONFIG_PAX_REFCOUNT
22714 + jno 1234f
22715 + LOCK_PREFIX
22716 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22717 + int $4
22718 +1234:
22719 + _ASM_EXTABLE(1234b, 1234b)
22720 +#endif
22721 +
22722 js 0b
22723 ENDFRAME
22724 + pax_force_retaddr
22725 ret
22726 CFI_ENDPROC
22727 END(__read_lock_failed)
22728 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22729 index 5dff5f0..cadebf4 100644
22730 --- a/arch/x86/lib/rwsem.S
22731 +++ b/arch/x86/lib/rwsem.S
22732 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22733 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22734 CFI_RESTORE __ASM_REG(dx)
22735 restore_common_regs
22736 + pax_force_retaddr
22737 ret
22738 CFI_ENDPROC
22739 ENDPROC(call_rwsem_down_read_failed)
22740 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22741 movq %rax,%rdi
22742 call rwsem_down_write_failed
22743 restore_common_regs
22744 + pax_force_retaddr
22745 ret
22746 CFI_ENDPROC
22747 ENDPROC(call_rwsem_down_write_failed)
22748 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22749 movq %rax,%rdi
22750 call rwsem_wake
22751 restore_common_regs
22752 -1: ret
22753 +1: pax_force_retaddr
22754 + ret
22755 CFI_ENDPROC
22756 ENDPROC(call_rwsem_wake)
22757
22758 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22759 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22760 CFI_RESTORE __ASM_REG(dx)
22761 restore_common_regs
22762 + pax_force_retaddr
22763 ret
22764 CFI_ENDPROC
22765 ENDPROC(call_rwsem_downgrade_wake)
22766 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22767 index a63efd6..ccecad8 100644
22768 --- a/arch/x86/lib/thunk_64.S
22769 +++ b/arch/x86/lib/thunk_64.S
22770 @@ -8,6 +8,7 @@
22771 #include <linux/linkage.h>
22772 #include <asm/dwarf2.h>
22773 #include <asm/calling.h>
22774 +#include <asm/alternative-asm.h>
22775
22776 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22777 .macro THUNK name, func, put_ret_addr_in_rdi=0
22778 @@ -41,5 +42,6 @@
22779 SAVE_ARGS
22780 restore:
22781 RESTORE_ARGS
22782 + pax_force_retaddr
22783 ret
22784 CFI_ENDPROC
22785 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22786 index e218d5d..a99a1eb 100644
22787 --- a/arch/x86/lib/usercopy_32.c
22788 +++ b/arch/x86/lib/usercopy_32.c
22789 @@ -43,7 +43,7 @@ do { \
22790 __asm__ __volatile__( \
22791 " testl %1,%1\n" \
22792 " jz 2f\n" \
22793 - "0: lodsb\n" \
22794 + "0: "__copyuser_seg"lodsb\n" \
22795 " stosb\n" \
22796 " testb %%al,%%al\n" \
22797 " jz 1f\n" \
22798 @@ -128,10 +128,12 @@ do { \
22799 int __d0; \
22800 might_fault(); \
22801 __asm__ __volatile__( \
22802 + __COPYUSER_SET_ES \
22803 "0: rep; stosl\n" \
22804 " movl %2,%0\n" \
22805 "1: rep; stosb\n" \
22806 "2:\n" \
22807 + __COPYUSER_RESTORE_ES \
22808 ".section .fixup,\"ax\"\n" \
22809 "3: lea 0(%2,%0,4),%0\n" \
22810 " jmp 2b\n" \
22811 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
22812 might_fault();
22813
22814 __asm__ __volatile__(
22815 + __COPYUSER_SET_ES
22816 " testl %0, %0\n"
22817 " jz 3f\n"
22818 " andl %0,%%ecx\n"
22819 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
22820 " subl %%ecx,%0\n"
22821 " addl %0,%%eax\n"
22822 "1:\n"
22823 + __COPYUSER_RESTORE_ES
22824 ".section .fixup,\"ax\"\n"
22825 "2: xorl %%eax,%%eax\n"
22826 " jmp 1b\n"
22827 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
22828
22829 #ifdef CONFIG_X86_INTEL_USERCOPY
22830 static unsigned long
22831 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22832 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22833 {
22834 int d0, d1;
22835 __asm__ __volatile__(
22836 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22837 " .align 2,0x90\n"
22838 "3: movl 0(%4), %%eax\n"
22839 "4: movl 4(%4), %%edx\n"
22840 - "5: movl %%eax, 0(%3)\n"
22841 - "6: movl %%edx, 4(%3)\n"
22842 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22843 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22844 "7: movl 8(%4), %%eax\n"
22845 "8: movl 12(%4),%%edx\n"
22846 - "9: movl %%eax, 8(%3)\n"
22847 - "10: movl %%edx, 12(%3)\n"
22848 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22849 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22850 "11: movl 16(%4), %%eax\n"
22851 "12: movl 20(%4), %%edx\n"
22852 - "13: movl %%eax, 16(%3)\n"
22853 - "14: movl %%edx, 20(%3)\n"
22854 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22855 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22856 "15: movl 24(%4), %%eax\n"
22857 "16: movl 28(%4), %%edx\n"
22858 - "17: movl %%eax, 24(%3)\n"
22859 - "18: movl %%edx, 28(%3)\n"
22860 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22861 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22862 "19: movl 32(%4), %%eax\n"
22863 "20: movl 36(%4), %%edx\n"
22864 - "21: movl %%eax, 32(%3)\n"
22865 - "22: movl %%edx, 36(%3)\n"
22866 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22867 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22868 "23: movl 40(%4), %%eax\n"
22869 "24: movl 44(%4), %%edx\n"
22870 - "25: movl %%eax, 40(%3)\n"
22871 - "26: movl %%edx, 44(%3)\n"
22872 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22873 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22874 "27: movl 48(%4), %%eax\n"
22875 "28: movl 52(%4), %%edx\n"
22876 - "29: movl %%eax, 48(%3)\n"
22877 - "30: movl %%edx, 52(%3)\n"
22878 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22879 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22880 "31: movl 56(%4), %%eax\n"
22881 "32: movl 60(%4), %%edx\n"
22882 - "33: movl %%eax, 56(%3)\n"
22883 - "34: movl %%edx, 60(%3)\n"
22884 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22885 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22886 " addl $-64, %0\n"
22887 " addl $64, %4\n"
22888 " addl $64, %3\n"
22889 @@ -278,10 +282,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22890 " shrl $2, %0\n"
22891 " andl $3, %%eax\n"
22892 " cld\n"
22893 + __COPYUSER_SET_ES
22894 "99: rep; movsl\n"
22895 "36: movl %%eax, %0\n"
22896 "37: rep; movsb\n"
22897 "100:\n"
22898 + __COPYUSER_RESTORE_ES
22899 ".section .fixup,\"ax\"\n"
22900 "101: lea 0(%%eax,%0,4),%0\n"
22901 " jmp 100b\n"
22902 @@ -334,46 +340,155 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22903 }
22904
22905 static unsigned long
22906 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22907 +{
22908 + int d0, d1;
22909 + __asm__ __volatile__(
22910 + " .align 2,0x90\n"
22911 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22912 + " cmpl $67, %0\n"
22913 + " jbe 3f\n"
22914 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22915 + " .align 2,0x90\n"
22916 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22917 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22918 + "5: movl %%eax, 0(%3)\n"
22919 + "6: movl %%edx, 4(%3)\n"
22920 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22921 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22922 + "9: movl %%eax, 8(%3)\n"
22923 + "10: movl %%edx, 12(%3)\n"
22924 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22925 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22926 + "13: movl %%eax, 16(%3)\n"
22927 + "14: movl %%edx, 20(%3)\n"
22928 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22929 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22930 + "17: movl %%eax, 24(%3)\n"
22931 + "18: movl %%edx, 28(%3)\n"
22932 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22933 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22934 + "21: movl %%eax, 32(%3)\n"
22935 + "22: movl %%edx, 36(%3)\n"
22936 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22937 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22938 + "25: movl %%eax, 40(%3)\n"
22939 + "26: movl %%edx, 44(%3)\n"
22940 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22941 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22942 + "29: movl %%eax, 48(%3)\n"
22943 + "30: movl %%edx, 52(%3)\n"
22944 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22945 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22946 + "33: movl %%eax, 56(%3)\n"
22947 + "34: movl %%edx, 60(%3)\n"
22948 + " addl $-64, %0\n"
22949 + " addl $64, %4\n"
22950 + " addl $64, %3\n"
22951 + " cmpl $63, %0\n"
22952 + " ja 1b\n"
22953 + "35: movl %0, %%eax\n"
22954 + " shrl $2, %0\n"
22955 + " andl $3, %%eax\n"
22956 + " cld\n"
22957 + "99: rep; "__copyuser_seg" movsl\n"
22958 + "36: movl %%eax, %0\n"
22959 + "37: rep; "__copyuser_seg" movsb\n"
22960 + "100:\n"
22961 + ".section .fixup,\"ax\"\n"
22962 + "101: lea 0(%%eax,%0,4),%0\n"
22963 + " jmp 100b\n"
22964 + ".previous\n"
22965 + ".section __ex_table,\"a\"\n"
22966 + " .align 4\n"
22967 + " .long 1b,100b\n"
22968 + " .long 2b,100b\n"
22969 + " .long 3b,100b\n"
22970 + " .long 4b,100b\n"
22971 + " .long 5b,100b\n"
22972 + " .long 6b,100b\n"
22973 + " .long 7b,100b\n"
22974 + " .long 8b,100b\n"
22975 + " .long 9b,100b\n"
22976 + " .long 10b,100b\n"
22977 + " .long 11b,100b\n"
22978 + " .long 12b,100b\n"
22979 + " .long 13b,100b\n"
22980 + " .long 14b,100b\n"
22981 + " .long 15b,100b\n"
22982 + " .long 16b,100b\n"
22983 + " .long 17b,100b\n"
22984 + " .long 18b,100b\n"
22985 + " .long 19b,100b\n"
22986 + " .long 20b,100b\n"
22987 + " .long 21b,100b\n"
22988 + " .long 22b,100b\n"
22989 + " .long 23b,100b\n"
22990 + " .long 24b,100b\n"
22991 + " .long 25b,100b\n"
22992 + " .long 26b,100b\n"
22993 + " .long 27b,100b\n"
22994 + " .long 28b,100b\n"
22995 + " .long 29b,100b\n"
22996 + " .long 30b,100b\n"
22997 + " .long 31b,100b\n"
22998 + " .long 32b,100b\n"
22999 + " .long 33b,100b\n"
23000 + " .long 34b,100b\n"
23001 + " .long 35b,100b\n"
23002 + " .long 36b,100b\n"
23003 + " .long 37b,100b\n"
23004 + " .long 99b,101b\n"
23005 + ".previous"
23006 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23007 + : "1"(to), "2"(from), "0"(size)
23008 + : "eax", "edx", "memory");
23009 + return size;
23010 +}
23011 +
23012 +static unsigned long
23013 +__copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size) __size_overflow(3);
23014 +static unsigned long
23015 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23016 {
23017 int d0, d1;
23018 __asm__ __volatile__(
23019 " .align 2,0x90\n"
23020 - "0: movl 32(%4), %%eax\n"
23021 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23022 " cmpl $67, %0\n"
23023 " jbe 2f\n"
23024 - "1: movl 64(%4), %%eax\n"
23025 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23026 " .align 2,0x90\n"
23027 - "2: movl 0(%4), %%eax\n"
23028 - "21: movl 4(%4), %%edx\n"
23029 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23030 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23031 " movl %%eax, 0(%3)\n"
23032 " movl %%edx, 4(%3)\n"
23033 - "3: movl 8(%4), %%eax\n"
23034 - "31: movl 12(%4),%%edx\n"
23035 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23036 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23037 " movl %%eax, 8(%3)\n"
23038 " movl %%edx, 12(%3)\n"
23039 - "4: movl 16(%4), %%eax\n"
23040 - "41: movl 20(%4), %%edx\n"
23041 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23042 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23043 " movl %%eax, 16(%3)\n"
23044 " movl %%edx, 20(%3)\n"
23045 - "10: movl 24(%4), %%eax\n"
23046 - "51: movl 28(%4), %%edx\n"
23047 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23048 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23049 " movl %%eax, 24(%3)\n"
23050 " movl %%edx, 28(%3)\n"
23051 - "11: movl 32(%4), %%eax\n"
23052 - "61: movl 36(%4), %%edx\n"
23053 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23054 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23055 " movl %%eax, 32(%3)\n"
23056 " movl %%edx, 36(%3)\n"
23057 - "12: movl 40(%4), %%eax\n"
23058 - "71: movl 44(%4), %%edx\n"
23059 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23060 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23061 " movl %%eax, 40(%3)\n"
23062 " movl %%edx, 44(%3)\n"
23063 - "13: movl 48(%4), %%eax\n"
23064 - "81: movl 52(%4), %%edx\n"
23065 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23066 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23067 " movl %%eax, 48(%3)\n"
23068 " movl %%edx, 52(%3)\n"
23069 - "14: movl 56(%4), %%eax\n"
23070 - "91: movl 60(%4), %%edx\n"
23071 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23072 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23073 " movl %%eax, 56(%3)\n"
23074 " movl %%edx, 60(%3)\n"
23075 " addl $-64, %0\n"
23076 @@ -385,9 +500,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23077 " shrl $2, %0\n"
23078 " andl $3, %%eax\n"
23079 " cld\n"
23080 - "6: rep; movsl\n"
23081 + "6: rep; "__copyuser_seg" movsl\n"
23082 " movl %%eax,%0\n"
23083 - "7: rep; movsb\n"
23084 + "7: rep; "__copyuser_seg" movsb\n"
23085 "8:\n"
23086 ".section .fixup,\"ax\"\n"
23087 "9: lea 0(%%eax,%0,4),%0\n"
23088 @@ -434,47 +549,49 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23089 */
23090
23091 static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23092 + const void __user *from, unsigned long size) __size_overflow(3);
23093 +static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23094 const void __user *from, unsigned long size)
23095 {
23096 int d0, d1;
23097
23098 __asm__ __volatile__(
23099 " .align 2,0x90\n"
23100 - "0: movl 32(%4), %%eax\n"
23101 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23102 " cmpl $67, %0\n"
23103 " jbe 2f\n"
23104 - "1: movl 64(%4), %%eax\n"
23105 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23106 " .align 2,0x90\n"
23107 - "2: movl 0(%4), %%eax\n"
23108 - "21: movl 4(%4), %%edx\n"
23109 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23110 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23111 " movnti %%eax, 0(%3)\n"
23112 " movnti %%edx, 4(%3)\n"
23113 - "3: movl 8(%4), %%eax\n"
23114 - "31: movl 12(%4),%%edx\n"
23115 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23116 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23117 " movnti %%eax, 8(%3)\n"
23118 " movnti %%edx, 12(%3)\n"
23119 - "4: movl 16(%4), %%eax\n"
23120 - "41: movl 20(%4), %%edx\n"
23121 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23122 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23123 " movnti %%eax, 16(%3)\n"
23124 " movnti %%edx, 20(%3)\n"
23125 - "10: movl 24(%4), %%eax\n"
23126 - "51: movl 28(%4), %%edx\n"
23127 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23128 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23129 " movnti %%eax, 24(%3)\n"
23130 " movnti %%edx, 28(%3)\n"
23131 - "11: movl 32(%4), %%eax\n"
23132 - "61: movl 36(%4), %%edx\n"
23133 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23134 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23135 " movnti %%eax, 32(%3)\n"
23136 " movnti %%edx, 36(%3)\n"
23137 - "12: movl 40(%4), %%eax\n"
23138 - "71: movl 44(%4), %%edx\n"
23139 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23140 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23141 " movnti %%eax, 40(%3)\n"
23142 " movnti %%edx, 44(%3)\n"
23143 - "13: movl 48(%4), %%eax\n"
23144 - "81: movl 52(%4), %%edx\n"
23145 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23146 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23147 " movnti %%eax, 48(%3)\n"
23148 " movnti %%edx, 52(%3)\n"
23149 - "14: movl 56(%4), %%eax\n"
23150 - "91: movl 60(%4), %%edx\n"
23151 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23152 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23153 " movnti %%eax, 56(%3)\n"
23154 " movnti %%edx, 60(%3)\n"
23155 " addl $-64, %0\n"
23156 @@ -487,9 +604,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23157 " shrl $2, %0\n"
23158 " andl $3, %%eax\n"
23159 " cld\n"
23160 - "6: rep; movsl\n"
23161 + "6: rep; "__copyuser_seg" movsl\n"
23162 " movl %%eax,%0\n"
23163 - "7: rep; movsb\n"
23164 + "7: rep; "__copyuser_seg" movsb\n"
23165 "8:\n"
23166 ".section .fixup,\"ax\"\n"
23167 "9: lea 0(%%eax,%0,4),%0\n"
23168 @@ -531,47 +648,49 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23169 }
23170
23171 static unsigned long __copy_user_intel_nocache(void *to,
23172 + const void __user *from, unsigned long size) __size_overflow(3);
23173 +static unsigned long __copy_user_intel_nocache(void *to,
23174 const void __user *from, unsigned long size)
23175 {
23176 int d0, d1;
23177
23178 __asm__ __volatile__(
23179 " .align 2,0x90\n"
23180 - "0: movl 32(%4), %%eax\n"
23181 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23182 " cmpl $67, %0\n"
23183 " jbe 2f\n"
23184 - "1: movl 64(%4), %%eax\n"
23185 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23186 " .align 2,0x90\n"
23187 - "2: movl 0(%4), %%eax\n"
23188 - "21: movl 4(%4), %%edx\n"
23189 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23190 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23191 " movnti %%eax, 0(%3)\n"
23192 " movnti %%edx, 4(%3)\n"
23193 - "3: movl 8(%4), %%eax\n"
23194 - "31: movl 12(%4),%%edx\n"
23195 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23196 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23197 " movnti %%eax, 8(%3)\n"
23198 " movnti %%edx, 12(%3)\n"
23199 - "4: movl 16(%4), %%eax\n"
23200 - "41: movl 20(%4), %%edx\n"
23201 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23202 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23203 " movnti %%eax, 16(%3)\n"
23204 " movnti %%edx, 20(%3)\n"
23205 - "10: movl 24(%4), %%eax\n"
23206 - "51: movl 28(%4), %%edx\n"
23207 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23208 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23209 " movnti %%eax, 24(%3)\n"
23210 " movnti %%edx, 28(%3)\n"
23211 - "11: movl 32(%4), %%eax\n"
23212 - "61: movl 36(%4), %%edx\n"
23213 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23214 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23215 " movnti %%eax, 32(%3)\n"
23216 " movnti %%edx, 36(%3)\n"
23217 - "12: movl 40(%4), %%eax\n"
23218 - "71: movl 44(%4), %%edx\n"
23219 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23220 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23221 " movnti %%eax, 40(%3)\n"
23222 " movnti %%edx, 44(%3)\n"
23223 - "13: movl 48(%4), %%eax\n"
23224 - "81: movl 52(%4), %%edx\n"
23225 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23226 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23227 " movnti %%eax, 48(%3)\n"
23228 " movnti %%edx, 52(%3)\n"
23229 - "14: movl 56(%4), %%eax\n"
23230 - "91: movl 60(%4), %%edx\n"
23231 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23232 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23233 " movnti %%eax, 56(%3)\n"
23234 " movnti %%edx, 60(%3)\n"
23235 " addl $-64, %0\n"
23236 @@ -584,9 +703,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23237 " shrl $2, %0\n"
23238 " andl $3, %%eax\n"
23239 " cld\n"
23240 - "6: rep; movsl\n"
23241 + "6: rep; "__copyuser_seg" movsl\n"
23242 " movl %%eax,%0\n"
23243 - "7: rep; movsb\n"
23244 + "7: rep; "__copyuser_seg" movsb\n"
23245 "8:\n"
23246 ".section .fixup,\"ax\"\n"
23247 "9: lea 0(%%eax,%0,4),%0\n"
23248 @@ -629,32 +748,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23249 */
23250 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23251 unsigned long size);
23252 -unsigned long __copy_user_intel(void __user *to, const void *from,
23253 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23254 + unsigned long size);
23255 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23256 unsigned long size);
23257 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23258 const void __user *from, unsigned long size);
23259 #endif /* CONFIG_X86_INTEL_USERCOPY */
23260
23261 /* Generic arbitrary sized copy. */
23262 -#define __copy_user(to, from, size) \
23263 +#define __copy_user(to, from, size, prefix, set, restore) \
23264 do { \
23265 int __d0, __d1, __d2; \
23266 __asm__ __volatile__( \
23267 + set \
23268 " cmp $7,%0\n" \
23269 " jbe 1f\n" \
23270 " movl %1,%0\n" \
23271 " negl %0\n" \
23272 " andl $7,%0\n" \
23273 " subl %0,%3\n" \
23274 - "4: rep; movsb\n" \
23275 + "4: rep; "prefix"movsb\n" \
23276 " movl %3,%0\n" \
23277 " shrl $2,%0\n" \
23278 " andl $3,%3\n" \
23279 " .align 2,0x90\n" \
23280 - "0: rep; movsl\n" \
23281 + "0: rep; "prefix"movsl\n" \
23282 " movl %3,%0\n" \
23283 - "1: rep; movsb\n" \
23284 + "1: rep; "prefix"movsb\n" \
23285 "2:\n" \
23286 + restore \
23287 ".section .fixup,\"ax\"\n" \
23288 "5: addl %3,%0\n" \
23289 " jmp 2b\n" \
23290 @@ -682,14 +805,14 @@ do { \
23291 " negl %0\n" \
23292 " andl $7,%0\n" \
23293 " subl %0,%3\n" \
23294 - "4: rep; movsb\n" \
23295 + "4: rep; "__copyuser_seg"movsb\n" \
23296 " movl %3,%0\n" \
23297 " shrl $2,%0\n" \
23298 " andl $3,%3\n" \
23299 " .align 2,0x90\n" \
23300 - "0: rep; movsl\n" \
23301 + "0: rep; "__copyuser_seg"movsl\n" \
23302 " movl %3,%0\n" \
23303 - "1: rep; movsb\n" \
23304 + "1: rep; "__copyuser_seg"movsb\n" \
23305 "2:\n" \
23306 ".section .fixup,\"ax\"\n" \
23307 "5: addl %3,%0\n" \
23308 @@ -775,9 +898,9 @@ survive:
23309 }
23310 #endif
23311 if (movsl_is_ok(to, from, n))
23312 - __copy_user(to, from, n);
23313 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23314 else
23315 - n = __copy_user_intel(to, from, n);
23316 + n = __generic_copy_to_user_intel(to, from, n);
23317 return n;
23318 }
23319 EXPORT_SYMBOL(__copy_to_user_ll);
23320 @@ -797,10 +920,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23321 unsigned long n)
23322 {
23323 if (movsl_is_ok(to, from, n))
23324 - __copy_user(to, from, n);
23325 + __copy_user(to, from, n, __copyuser_seg, "", "");
23326 else
23327 - n = __copy_user_intel((void __user *)to,
23328 - (const void *)from, n);
23329 + n = __generic_copy_from_user_intel(to, from, n);
23330 return n;
23331 }
23332 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23333 @@ -827,65 +949,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23334 if (n > 64 && cpu_has_xmm2)
23335 n = __copy_user_intel_nocache(to, from, n);
23336 else
23337 - __copy_user(to, from, n);
23338 + __copy_user(to, from, n, __copyuser_seg, "", "");
23339 #else
23340 - __copy_user(to, from, n);
23341 + __copy_user(to, from, n, __copyuser_seg, "", "");
23342 #endif
23343 return n;
23344 }
23345 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23346
23347 -/**
23348 - * copy_to_user: - Copy a block of data into user space.
23349 - * @to: Destination address, in user space.
23350 - * @from: Source address, in kernel space.
23351 - * @n: Number of bytes to copy.
23352 - *
23353 - * Context: User context only. This function may sleep.
23354 - *
23355 - * Copy data from kernel space to user space.
23356 - *
23357 - * Returns number of bytes that could not be copied.
23358 - * On success, this will be zero.
23359 - */
23360 -unsigned long
23361 -copy_to_user(void __user *to, const void *from, unsigned long n)
23362 -{
23363 - if (access_ok(VERIFY_WRITE, to, n))
23364 - n = __copy_to_user(to, from, n);
23365 - return n;
23366 -}
23367 -EXPORT_SYMBOL(copy_to_user);
23368 -
23369 -/**
23370 - * copy_from_user: - Copy a block of data from user space.
23371 - * @to: Destination address, in kernel space.
23372 - * @from: Source address, in user space.
23373 - * @n: Number of bytes to copy.
23374 - *
23375 - * Context: User context only. This function may sleep.
23376 - *
23377 - * Copy data from user space to kernel space.
23378 - *
23379 - * Returns number of bytes that could not be copied.
23380 - * On success, this will be zero.
23381 - *
23382 - * If some data could not be copied, this function will pad the copied
23383 - * data to the requested size using zero bytes.
23384 - */
23385 -unsigned long
23386 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23387 -{
23388 - if (access_ok(VERIFY_READ, from, n))
23389 - n = __copy_from_user(to, from, n);
23390 - else
23391 - memset(to, 0, n);
23392 - return n;
23393 -}
23394 -EXPORT_SYMBOL(_copy_from_user);
23395 -
23396 void copy_from_user_overflow(void)
23397 {
23398 WARN(1, "Buffer overflow detected!\n");
23399 }
23400 EXPORT_SYMBOL(copy_from_user_overflow);
23401 +
23402 +void copy_to_user_overflow(void)
23403 +{
23404 + WARN(1, "Buffer overflow detected!\n");
23405 +}
23406 +EXPORT_SYMBOL(copy_to_user_overflow);
23407 +
23408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23409 +void __set_fs(mm_segment_t x)
23410 +{
23411 + switch (x.seg) {
23412 + case 0:
23413 + loadsegment(gs, 0);
23414 + break;
23415 + case TASK_SIZE_MAX:
23416 + loadsegment(gs, __USER_DS);
23417 + break;
23418 + case -1UL:
23419 + loadsegment(gs, __KERNEL_DS);
23420 + break;
23421 + default:
23422 + BUG();
23423 + }
23424 + return;
23425 +}
23426 +EXPORT_SYMBOL(__set_fs);
23427 +
23428 +void set_fs(mm_segment_t x)
23429 +{
23430 + current_thread_info()->addr_limit = x;
23431 + __set_fs(x);
23432 +}
23433 +EXPORT_SYMBOL(set_fs);
23434 +#endif
23435 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23436 index b7c2849..8633ad8 100644
23437 --- a/arch/x86/lib/usercopy_64.c
23438 +++ b/arch/x86/lib/usercopy_64.c
23439 @@ -42,6 +42,12 @@ long
23440 __strncpy_from_user(char *dst, const char __user *src, long count)
23441 {
23442 long res;
23443 +
23444 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23445 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
23446 + src += PAX_USER_SHADOW_BASE;
23447 +#endif
23448 +
23449 __do_strncpy_from_user(dst, src, count, res);
23450 return res;
23451 }
23452 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23453 {
23454 long __d0;
23455 might_fault();
23456 +
23457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23458 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23459 + addr += PAX_USER_SHADOW_BASE;
23460 +#endif
23461 +
23462 /* no memory constraint because it doesn't change any memory gcc knows
23463 about */
23464 asm volatile(
23465 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
23466 }
23467 EXPORT_SYMBOL(strlen_user);
23468
23469 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23470 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23471 {
23472 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23473 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23474 - }
23475 - return len;
23476 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23477 +
23478 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23479 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23480 + to += PAX_USER_SHADOW_BASE;
23481 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23482 + from += PAX_USER_SHADOW_BASE;
23483 +#endif
23484 +
23485 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23486 + }
23487 + return len;
23488 }
23489 EXPORT_SYMBOL(copy_in_user);
23490
23491 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
23492 * it is not necessary to optimize tail handling.
23493 */
23494 unsigned long
23495 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23496 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23497 {
23498 char c;
23499 unsigned zero_len;
23500 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23501 index 1fb85db..8b3540b 100644
23502 --- a/arch/x86/mm/extable.c
23503 +++ b/arch/x86/mm/extable.c
23504 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
23505 const struct exception_table_entry *fixup;
23506
23507 #ifdef CONFIG_PNPBIOS
23508 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23509 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23510 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23511 extern u32 pnp_bios_is_utter_crap;
23512 pnp_bios_is_utter_crap = 1;
23513 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23514 index f0b4caf..d92fd42 100644
23515 --- a/arch/x86/mm/fault.c
23516 +++ b/arch/x86/mm/fault.c
23517 @@ -13,11 +13,18 @@
23518 #include <linux/perf_event.h> /* perf_sw_event */
23519 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23520 #include <linux/prefetch.h> /* prefetchw */
23521 +#include <linux/unistd.h>
23522 +#include <linux/compiler.h>
23523
23524 #include <asm/traps.h> /* dotraplinkage, ... */
23525 #include <asm/pgalloc.h> /* pgd_*(), ... */
23526 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23527 #include <asm/fixmap.h> /* VSYSCALL_START */
23528 +#include <asm/tlbflush.h>
23529 +
23530 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23531 +#include <asm/stacktrace.h>
23532 +#endif
23533
23534 /*
23535 * Page fault error code bits:
23536 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23537 int ret = 0;
23538
23539 /* kprobe_running() needs smp_processor_id() */
23540 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23541 + if (kprobes_built_in() && !user_mode(regs)) {
23542 preempt_disable();
23543 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23544 ret = 1;
23545 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23546 return !instr_lo || (instr_lo>>1) == 1;
23547 case 0x00:
23548 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23549 - if (probe_kernel_address(instr, opcode))
23550 + if (user_mode(regs)) {
23551 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23552 + return 0;
23553 + } else if (probe_kernel_address(instr, opcode))
23554 return 0;
23555
23556 *prefetch = (instr_lo == 0xF) &&
23557 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23558 while (instr < max_instr) {
23559 unsigned char opcode;
23560
23561 - if (probe_kernel_address(instr, opcode))
23562 + if (user_mode(regs)) {
23563 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23564 + break;
23565 + } else if (probe_kernel_address(instr, opcode))
23566 break;
23567
23568 instr++;
23569 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23570 force_sig_info(si_signo, &info, tsk);
23571 }
23572
23573 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23574 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23575 +#endif
23576 +
23577 +#ifdef CONFIG_PAX_EMUTRAMP
23578 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23579 +#endif
23580 +
23581 +#ifdef CONFIG_PAX_PAGEEXEC
23582 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23583 +{
23584 + pgd_t *pgd;
23585 + pud_t *pud;
23586 + pmd_t *pmd;
23587 +
23588 + pgd = pgd_offset(mm, address);
23589 + if (!pgd_present(*pgd))
23590 + return NULL;
23591 + pud = pud_offset(pgd, address);
23592 + if (!pud_present(*pud))
23593 + return NULL;
23594 + pmd = pmd_offset(pud, address);
23595 + if (!pmd_present(*pmd))
23596 + return NULL;
23597 + return pmd;
23598 +}
23599 +#endif
23600 +
23601 DEFINE_SPINLOCK(pgd_lock);
23602 LIST_HEAD(pgd_list);
23603
23604 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23605 for (address = VMALLOC_START & PMD_MASK;
23606 address >= TASK_SIZE && address < FIXADDR_TOP;
23607 address += PMD_SIZE) {
23608 +
23609 +#ifdef CONFIG_PAX_PER_CPU_PGD
23610 + unsigned long cpu;
23611 +#else
23612 struct page *page;
23613 +#endif
23614
23615 spin_lock(&pgd_lock);
23616 +
23617 +#ifdef CONFIG_PAX_PER_CPU_PGD
23618 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23619 + pgd_t *pgd = get_cpu_pgd(cpu);
23620 + pmd_t *ret;
23621 +#else
23622 list_for_each_entry(page, &pgd_list, lru) {
23623 + pgd_t *pgd = page_address(page);
23624 spinlock_t *pgt_lock;
23625 pmd_t *ret;
23626
23627 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23628 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23629
23630 spin_lock(pgt_lock);
23631 - ret = vmalloc_sync_one(page_address(page), address);
23632 +#endif
23633 +
23634 + ret = vmalloc_sync_one(pgd, address);
23635 +
23636 +#ifndef CONFIG_PAX_PER_CPU_PGD
23637 spin_unlock(pgt_lock);
23638 +#endif
23639
23640 if (!ret)
23641 break;
23642 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23643 * an interrupt in the middle of a task switch..
23644 */
23645 pgd_paddr = read_cr3();
23646 +
23647 +#ifdef CONFIG_PAX_PER_CPU_PGD
23648 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23649 +#endif
23650 +
23651 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23652 if (!pmd_k)
23653 return -1;
23654 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23655 * happen within a race in page table update. In the later
23656 * case just flush:
23657 */
23658 +
23659 +#ifdef CONFIG_PAX_PER_CPU_PGD
23660 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23661 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23662 +#else
23663 pgd = pgd_offset(current->active_mm, address);
23664 +#endif
23665 +
23666 pgd_ref = pgd_offset_k(address);
23667 if (pgd_none(*pgd_ref))
23668 return -1;
23669 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23670 static int is_errata100(struct pt_regs *regs, unsigned long address)
23671 {
23672 #ifdef CONFIG_X86_64
23673 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23674 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23675 return 1;
23676 #endif
23677 return 0;
23678 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23679 }
23680
23681 static const char nx_warning[] = KERN_CRIT
23682 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23683 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23684
23685 static void
23686 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23687 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23688 if (!oops_may_print())
23689 return;
23690
23691 - if (error_code & PF_INSTR) {
23692 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23693 unsigned int level;
23694
23695 pte_t *pte = lookup_address(address, &level);
23696
23697 if (pte && pte_present(*pte) && !pte_exec(*pte))
23698 - printk(nx_warning, current_uid());
23699 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
23700 }
23701
23702 +#ifdef CONFIG_PAX_KERNEXEC
23703 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23704 + if (current->signal->curr_ip)
23705 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23706 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23707 + else
23708 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23709 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23710 + }
23711 +#endif
23712 +
23713 printk(KERN_ALERT "BUG: unable to handle kernel ");
23714 if (address < PAGE_SIZE)
23715 printk(KERN_CONT "NULL pointer dereference");
23716 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23717 }
23718 #endif
23719
23720 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23721 + if (pax_is_fetch_fault(regs, error_code, address)) {
23722 +
23723 +#ifdef CONFIG_PAX_EMUTRAMP
23724 + switch (pax_handle_fetch_fault(regs)) {
23725 + case 2:
23726 + return;
23727 + }
23728 +#endif
23729 +
23730 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23731 + do_group_exit(SIGKILL);
23732 + }
23733 +#endif
23734 +
23735 if (unlikely(show_unhandled_signals))
23736 show_signal_msg(regs, error_code, address, tsk);
23737
23738 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23739 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23740 printk(KERN_ERR
23741 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23742 - tsk->comm, tsk->pid, address);
23743 + tsk->comm, task_pid_nr(tsk), address);
23744 code = BUS_MCEERR_AR;
23745 }
23746 #endif
23747 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23748 return 1;
23749 }
23750
23751 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23752 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23753 +{
23754 + pte_t *pte;
23755 + pmd_t *pmd;
23756 + spinlock_t *ptl;
23757 + unsigned char pte_mask;
23758 +
23759 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23760 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23761 + return 0;
23762 +
23763 + /* PaX: it's our fault, let's handle it if we can */
23764 +
23765 + /* PaX: take a look at read faults before acquiring any locks */
23766 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23767 + /* instruction fetch attempt from a protected page in user mode */
23768 + up_read(&mm->mmap_sem);
23769 +
23770 +#ifdef CONFIG_PAX_EMUTRAMP
23771 + switch (pax_handle_fetch_fault(regs)) {
23772 + case 2:
23773 + return 1;
23774 + }
23775 +#endif
23776 +
23777 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23778 + do_group_exit(SIGKILL);
23779 + }
23780 +
23781 + pmd = pax_get_pmd(mm, address);
23782 + if (unlikely(!pmd))
23783 + return 0;
23784 +
23785 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23786 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23787 + pte_unmap_unlock(pte, ptl);
23788 + return 0;
23789 + }
23790 +
23791 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23792 + /* write attempt to a protected page in user mode */
23793 + pte_unmap_unlock(pte, ptl);
23794 + return 0;
23795 + }
23796 +
23797 +#ifdef CONFIG_SMP
23798 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23799 +#else
23800 + if (likely(address > get_limit(regs->cs)))
23801 +#endif
23802 + {
23803 + set_pte(pte, pte_mkread(*pte));
23804 + __flush_tlb_one(address);
23805 + pte_unmap_unlock(pte, ptl);
23806 + up_read(&mm->mmap_sem);
23807 + return 1;
23808 + }
23809 +
23810 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23811 +
23812 + /*
23813 + * PaX: fill DTLB with user rights and retry
23814 + */
23815 + __asm__ __volatile__ (
23816 + "orb %2,(%1)\n"
23817 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23818 +/*
23819 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23820 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23821 + * page fault when examined during a TLB load attempt. this is true not only
23822 + * for PTEs holding a non-present entry but also present entries that will
23823 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23824 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23825 + * for our target pages since their PTEs are simply not in the TLBs at all.
23826 +
23827 + * the best thing in omitting it is that we gain around 15-20% speed in the
23828 + * fast path of the page fault handler and can get rid of tracing since we
23829 + * can no longer flush unintended entries.
23830 + */
23831 + "invlpg (%0)\n"
23832 +#endif
23833 + __copyuser_seg"testb $0,(%0)\n"
23834 + "xorb %3,(%1)\n"
23835 + :
23836 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23837 + : "memory", "cc");
23838 + pte_unmap_unlock(pte, ptl);
23839 + up_read(&mm->mmap_sem);
23840 + return 1;
23841 +}
23842 +#endif
23843 +
23844 /*
23845 * Handle a spurious fault caused by a stale TLB entry.
23846 *
23847 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23848 static inline int
23849 access_error(unsigned long error_code, struct vm_area_struct *vma)
23850 {
23851 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23852 + return 1;
23853 +
23854 if (error_code & PF_WRITE) {
23855 /* write, present and write, not present: */
23856 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23857 @@ -1005,18 +1197,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23858 {
23859 struct vm_area_struct *vma;
23860 struct task_struct *tsk;
23861 - unsigned long address;
23862 struct mm_struct *mm;
23863 int fault;
23864 int write = error_code & PF_WRITE;
23865 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23866 (write ? FAULT_FLAG_WRITE : 0);
23867
23868 - tsk = current;
23869 - mm = tsk->mm;
23870 -
23871 /* Get the faulting address: */
23872 - address = read_cr2();
23873 + unsigned long address = read_cr2();
23874 +
23875 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23876 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23877 + if (!search_exception_tables(regs->ip)) {
23878 + bad_area_nosemaphore(regs, error_code, address);
23879 + return;
23880 + }
23881 + if (address < PAX_USER_SHADOW_BASE) {
23882 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23883 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23884 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23885 + } else
23886 + address -= PAX_USER_SHADOW_BASE;
23887 + }
23888 +#endif
23889 +
23890 + tsk = current;
23891 + mm = tsk->mm;
23892
23893 /*
23894 * Detect and handle instructions that would cause a page fault for
23895 @@ -1077,7 +1283,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23896 * User-mode registers count as a user access even for any
23897 * potential system fault or CPU buglet:
23898 */
23899 - if (user_mode_vm(regs)) {
23900 + if (user_mode(regs)) {
23901 local_irq_enable();
23902 error_code |= PF_USER;
23903 } else {
23904 @@ -1132,6 +1338,11 @@ retry:
23905 might_sleep();
23906 }
23907
23908 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23909 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23910 + return;
23911 +#endif
23912 +
23913 vma = find_vma(mm, address);
23914 if (unlikely(!vma)) {
23915 bad_area(regs, error_code, address);
23916 @@ -1143,18 +1354,24 @@ retry:
23917 bad_area(regs, error_code, address);
23918 return;
23919 }
23920 - if (error_code & PF_USER) {
23921 - /*
23922 - * Accessing the stack below %sp is always a bug.
23923 - * The large cushion allows instructions like enter
23924 - * and pusha to work. ("enter $65535, $31" pushes
23925 - * 32 pointers and then decrements %sp by 65535.)
23926 - */
23927 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
23928 - bad_area(regs, error_code, address);
23929 - return;
23930 - }
23931 + /*
23932 + * Accessing the stack below %sp is always a bug.
23933 + * The large cushion allows instructions like enter
23934 + * and pusha to work. ("enter $65535, $31" pushes
23935 + * 32 pointers and then decrements %sp by 65535.)
23936 + */
23937 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
23938 + bad_area(regs, error_code, address);
23939 + return;
23940 }
23941 +
23942 +#ifdef CONFIG_PAX_SEGMEXEC
23943 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
23944 + bad_area(regs, error_code, address);
23945 + return;
23946 + }
23947 +#endif
23948 +
23949 if (unlikely(expand_stack(vma, address))) {
23950 bad_area(regs, error_code, address);
23951 return;
23952 @@ -1209,3 +1426,292 @@ good_area:
23953
23954 up_read(&mm->mmap_sem);
23955 }
23956 +
23957 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23958 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
23959 +{
23960 + struct mm_struct *mm = current->mm;
23961 + unsigned long ip = regs->ip;
23962 +
23963 + if (v8086_mode(regs))
23964 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
23965 +
23966 +#ifdef CONFIG_PAX_PAGEEXEC
23967 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
23968 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
23969 + return true;
23970 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
23971 + return true;
23972 + return false;
23973 + }
23974 +#endif
23975 +
23976 +#ifdef CONFIG_PAX_SEGMEXEC
23977 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
23978 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
23979 + return true;
23980 + return false;
23981 + }
23982 +#endif
23983 +
23984 + return false;
23985 +}
23986 +#endif
23987 +
23988 +#ifdef CONFIG_PAX_EMUTRAMP
23989 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
23990 +{
23991 + int err;
23992 +
23993 + do { /* PaX: libffi trampoline emulation */
23994 + unsigned char mov, jmp;
23995 + unsigned int addr1, addr2;
23996 +
23997 +#ifdef CONFIG_X86_64
23998 + if ((regs->ip + 9) >> 32)
23999 + break;
24000 +#endif
24001 +
24002 + err = get_user(mov, (unsigned char __user *)regs->ip);
24003 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24004 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24005 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24006 +
24007 + if (err)
24008 + break;
24009 +
24010 + if (mov == 0xB8 && jmp == 0xE9) {
24011 + regs->ax = addr1;
24012 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24013 + return 2;
24014 + }
24015 + } while (0);
24016 +
24017 + do { /* PaX: gcc trampoline emulation #1 */
24018 + unsigned char mov1, mov2;
24019 + unsigned short jmp;
24020 + unsigned int addr1, addr2;
24021 +
24022 +#ifdef CONFIG_X86_64
24023 + if ((regs->ip + 11) >> 32)
24024 + break;
24025 +#endif
24026 +
24027 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24028 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24029 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24030 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24031 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24032 +
24033 + if (err)
24034 + break;
24035 +
24036 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24037 + regs->cx = addr1;
24038 + regs->ax = addr2;
24039 + regs->ip = addr2;
24040 + return 2;
24041 + }
24042 + } while (0);
24043 +
24044 + do { /* PaX: gcc trampoline emulation #2 */
24045 + unsigned char mov, jmp;
24046 + unsigned int addr1, addr2;
24047 +
24048 +#ifdef CONFIG_X86_64
24049 + if ((regs->ip + 9) >> 32)
24050 + break;
24051 +#endif
24052 +
24053 + err = get_user(mov, (unsigned char __user *)regs->ip);
24054 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24055 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24056 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24057 +
24058 + if (err)
24059 + break;
24060 +
24061 + if (mov == 0xB9 && jmp == 0xE9) {
24062 + regs->cx = addr1;
24063 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24064 + return 2;
24065 + }
24066 + } while (0);
24067 +
24068 + return 1; /* PaX in action */
24069 +}
24070 +
24071 +#ifdef CONFIG_X86_64
24072 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24073 +{
24074 + int err;
24075 +
24076 + do { /* PaX: libffi trampoline emulation */
24077 + unsigned short mov1, mov2, jmp1;
24078 + unsigned char stcclc, jmp2;
24079 + unsigned long addr1, addr2;
24080 +
24081 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24082 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24083 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24084 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24085 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24086 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24087 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24088 +
24089 + if (err)
24090 + break;
24091 +
24092 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24093 + regs->r11 = addr1;
24094 + regs->r10 = addr2;
24095 + if (stcclc == 0xF8)
24096 + regs->flags &= ~X86_EFLAGS_CF;
24097 + else
24098 + regs->flags |= X86_EFLAGS_CF;
24099 + regs->ip = addr1;
24100 + return 2;
24101 + }
24102 + } while (0);
24103 +
24104 + do { /* PaX: gcc trampoline emulation #1 */
24105 + unsigned short mov1, mov2, jmp1;
24106 + unsigned char jmp2;
24107 + unsigned int addr1;
24108 + unsigned long addr2;
24109 +
24110 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24111 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24112 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24113 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24114 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24115 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24116 +
24117 + if (err)
24118 + break;
24119 +
24120 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24121 + regs->r11 = addr1;
24122 + regs->r10 = addr2;
24123 + regs->ip = addr1;
24124 + return 2;
24125 + }
24126 + } while (0);
24127 +
24128 + do { /* PaX: gcc trampoline emulation #2 */
24129 + unsigned short mov1, mov2, jmp1;
24130 + unsigned char jmp2;
24131 + unsigned long addr1, addr2;
24132 +
24133 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24134 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24135 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24136 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24137 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24138 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24139 +
24140 + if (err)
24141 + break;
24142 +
24143 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24144 + regs->r11 = addr1;
24145 + regs->r10 = addr2;
24146 + regs->ip = addr1;
24147 + return 2;
24148 + }
24149 + } while (0);
24150 +
24151 + return 1; /* PaX in action */
24152 +}
24153 +#endif
24154 +
24155 +/*
24156 + * PaX: decide what to do with offenders (regs->ip = fault address)
24157 + *
24158 + * returns 1 when task should be killed
24159 + * 2 when gcc trampoline was detected
24160 + */
24161 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24162 +{
24163 + if (v8086_mode(regs))
24164 + return 1;
24165 +
24166 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24167 + return 1;
24168 +
24169 +#ifdef CONFIG_X86_32
24170 + return pax_handle_fetch_fault_32(regs);
24171 +#else
24172 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24173 + return pax_handle_fetch_fault_32(regs);
24174 + else
24175 + return pax_handle_fetch_fault_64(regs);
24176 +#endif
24177 +}
24178 +#endif
24179 +
24180 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24181 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24182 +{
24183 + long i;
24184 +
24185 + printk(KERN_ERR "PAX: bytes at PC: ");
24186 + for (i = 0; i < 20; i++) {
24187 + unsigned char c;
24188 + if (get_user(c, (unsigned char __force_user *)pc+i))
24189 + printk(KERN_CONT "?? ");
24190 + else
24191 + printk(KERN_CONT "%02x ", c);
24192 + }
24193 + printk("\n");
24194 +
24195 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24196 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24197 + unsigned long c;
24198 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24199 +#ifdef CONFIG_X86_32
24200 + printk(KERN_CONT "???????? ");
24201 +#else
24202 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24203 + printk(KERN_CONT "???????? ???????? ");
24204 + else
24205 + printk(KERN_CONT "???????????????? ");
24206 +#endif
24207 + } else {
24208 +#ifdef CONFIG_X86_64
24209 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24210 + printk(KERN_CONT "%08x ", (unsigned int)c);
24211 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24212 + } else
24213 +#endif
24214 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24215 + }
24216 + }
24217 + printk("\n");
24218 +}
24219 +#endif
24220 +
24221 +/**
24222 + * probe_kernel_write(): safely attempt to write to a location
24223 + * @dst: address to write to
24224 + * @src: pointer to the data that shall be written
24225 + * @size: size of the data chunk
24226 + *
24227 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24228 + * happens, handle that and return -EFAULT.
24229 + */
24230 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24231 +{
24232 + long ret;
24233 + mm_segment_t old_fs = get_fs();
24234 +
24235 + set_fs(KERNEL_DS);
24236 + pagefault_disable();
24237 + pax_open_kernel();
24238 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24239 + pax_close_kernel();
24240 + pagefault_enable();
24241 + set_fs(old_fs);
24242 +
24243 + return ret ? -EFAULT : 0;
24244 +}
24245 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24246 index dd74e46..7d26398 100644
24247 --- a/arch/x86/mm/gup.c
24248 +++ b/arch/x86/mm/gup.c
24249 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24250 addr = start;
24251 len = (unsigned long) nr_pages << PAGE_SHIFT;
24252 end = start + len;
24253 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24254 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24255 (void __user *)start, len)))
24256 return 0;
24257
24258 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24259 index f4f29b1..5cac4fb 100644
24260 --- a/arch/x86/mm/highmem_32.c
24261 +++ b/arch/x86/mm/highmem_32.c
24262 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24263 idx = type + KM_TYPE_NR*smp_processor_id();
24264 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24265 BUG_ON(!pte_none(*(kmap_pte-idx)));
24266 +
24267 + pax_open_kernel();
24268 set_pte(kmap_pte-idx, mk_pte(page, prot));
24269 + pax_close_kernel();
24270 +
24271 arch_flush_lazy_mmu_mode();
24272
24273 return (void *)vaddr;
24274 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24275 index 8ecbb4b..a269cab 100644
24276 --- a/arch/x86/mm/hugetlbpage.c
24277 +++ b/arch/x86/mm/hugetlbpage.c
24278 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24279 struct hstate *h = hstate_file(file);
24280 struct mm_struct *mm = current->mm;
24281 struct vm_area_struct *vma;
24282 - unsigned long start_addr;
24283 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24284 +
24285 +#ifdef CONFIG_PAX_SEGMEXEC
24286 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24287 + pax_task_size = SEGMEXEC_TASK_SIZE;
24288 +#endif
24289 +
24290 + pax_task_size -= PAGE_SIZE;
24291
24292 if (len > mm->cached_hole_size) {
24293 - start_addr = mm->free_area_cache;
24294 + start_addr = mm->free_area_cache;
24295 } else {
24296 - start_addr = TASK_UNMAPPED_BASE;
24297 - mm->cached_hole_size = 0;
24298 + start_addr = mm->mmap_base;
24299 + mm->cached_hole_size = 0;
24300 }
24301
24302 full_search:
24303 @@ -280,26 +287,27 @@ full_search:
24304
24305 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24306 /* At this point: (!vma || addr < vma->vm_end). */
24307 - if (TASK_SIZE - len < addr) {
24308 + if (pax_task_size - len < addr) {
24309 /*
24310 * Start a new search - just in case we missed
24311 * some holes.
24312 */
24313 - if (start_addr != TASK_UNMAPPED_BASE) {
24314 - start_addr = TASK_UNMAPPED_BASE;
24315 + if (start_addr != mm->mmap_base) {
24316 + start_addr = mm->mmap_base;
24317 mm->cached_hole_size = 0;
24318 goto full_search;
24319 }
24320 return -ENOMEM;
24321 }
24322 - if (!vma || addr + len <= vma->vm_start) {
24323 - mm->free_area_cache = addr + len;
24324 - return addr;
24325 - }
24326 + if (check_heap_stack_gap(vma, addr, len))
24327 + break;
24328 if (addr + mm->cached_hole_size < vma->vm_start)
24329 mm->cached_hole_size = vma->vm_start - addr;
24330 addr = ALIGN(vma->vm_end, huge_page_size(h));
24331 }
24332 +
24333 + mm->free_area_cache = addr + len;
24334 + return addr;
24335 }
24336
24337 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24338 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24339 {
24340 struct hstate *h = hstate_file(file);
24341 struct mm_struct *mm = current->mm;
24342 - struct vm_area_struct *vma, *prev_vma;
24343 - unsigned long base = mm->mmap_base, addr = addr0;
24344 + struct vm_area_struct *vma;
24345 + unsigned long base = mm->mmap_base, addr;
24346 unsigned long largest_hole = mm->cached_hole_size;
24347 - int first_time = 1;
24348
24349 /* don't allow allocations above current base */
24350 if (mm->free_area_cache > base)
24351 @@ -321,14 +328,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24352 largest_hole = 0;
24353 mm->free_area_cache = base;
24354 }
24355 -try_again:
24356 +
24357 /* make sure it can fit in the remaining address space */
24358 if (mm->free_area_cache < len)
24359 goto fail;
24360
24361 /* either no address requested or can't fit in requested address hole */
24362 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24363 + addr = (mm->free_area_cache - len);
24364 do {
24365 + addr &= huge_page_mask(h);
24366 /*
24367 * Lookup failure means no vma is above this address,
24368 * i.e. return with success:
24369 @@ -341,46 +349,47 @@ try_again:
24370 * new region fits between prev_vma->vm_end and
24371 * vma->vm_start, use it:
24372 */
24373 - prev_vma = vma->vm_prev;
24374 - if (addr + len <= vma->vm_start &&
24375 - (!prev_vma || (addr >= prev_vma->vm_end))) {
24376 + if (check_heap_stack_gap(vma, addr, len)) {
24377 /* remember the address as a hint for next time */
24378 - mm->cached_hole_size = largest_hole;
24379 - return (mm->free_area_cache = addr);
24380 - } else {
24381 - /* pull free_area_cache down to the first hole */
24382 - if (mm->free_area_cache == vma->vm_end) {
24383 - mm->free_area_cache = vma->vm_start;
24384 - mm->cached_hole_size = largest_hole;
24385 - }
24386 + mm->cached_hole_size = largest_hole;
24387 + return (mm->free_area_cache = addr);
24388 + }
24389 + /* pull free_area_cache down to the first hole */
24390 + if (mm->free_area_cache == vma->vm_end) {
24391 + mm->free_area_cache = vma->vm_start;
24392 + mm->cached_hole_size = largest_hole;
24393 }
24394
24395 /* remember the largest hole we saw so far */
24396 if (addr + largest_hole < vma->vm_start)
24397 - largest_hole = vma->vm_start - addr;
24398 + largest_hole = vma->vm_start - addr;
24399
24400 /* try just below the current vma->vm_start */
24401 - addr = (vma->vm_start - len) & huge_page_mask(h);
24402 - } while (len <= vma->vm_start);
24403 + addr = skip_heap_stack_gap(vma, len);
24404 + } while (!IS_ERR_VALUE(addr));
24405
24406 fail:
24407 /*
24408 - * if hint left us with no space for the requested
24409 - * mapping then try again:
24410 - */
24411 - if (first_time) {
24412 - mm->free_area_cache = base;
24413 - largest_hole = 0;
24414 - first_time = 0;
24415 - goto try_again;
24416 - }
24417 - /*
24418 * A failed mmap() very likely causes application failure,
24419 * so fall back to the bottom-up function here. This scenario
24420 * can happen with large stack limits and large mmap()
24421 * allocations.
24422 */
24423 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24424 +
24425 +#ifdef CONFIG_PAX_SEGMEXEC
24426 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24427 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24428 + else
24429 +#endif
24430 +
24431 + mm->mmap_base = TASK_UNMAPPED_BASE;
24432 +
24433 +#ifdef CONFIG_PAX_RANDMMAP
24434 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24435 + mm->mmap_base += mm->delta_mmap;
24436 +#endif
24437 +
24438 + mm->free_area_cache = mm->mmap_base;
24439 mm->cached_hole_size = ~0UL;
24440 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24441 len, pgoff, flags);
24442 @@ -388,6 +397,7 @@ fail:
24443 /*
24444 * Restore the topdown base:
24445 */
24446 + mm->mmap_base = base;
24447 mm->free_area_cache = base;
24448 mm->cached_hole_size = ~0UL;
24449
24450 @@ -401,10 +411,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24451 struct hstate *h = hstate_file(file);
24452 struct mm_struct *mm = current->mm;
24453 struct vm_area_struct *vma;
24454 + unsigned long pax_task_size = TASK_SIZE;
24455
24456 if (len & ~huge_page_mask(h))
24457 return -EINVAL;
24458 - if (len > TASK_SIZE)
24459 +
24460 +#ifdef CONFIG_PAX_SEGMEXEC
24461 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24462 + pax_task_size = SEGMEXEC_TASK_SIZE;
24463 +#endif
24464 +
24465 + pax_task_size -= PAGE_SIZE;
24466 +
24467 + if (len > pax_task_size)
24468 return -ENOMEM;
24469
24470 if (flags & MAP_FIXED) {
24471 @@ -416,8 +435,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24472 if (addr) {
24473 addr = ALIGN(addr, huge_page_size(h));
24474 vma = find_vma(mm, addr);
24475 - if (TASK_SIZE - len >= addr &&
24476 - (!vma || addr + len <= vma->vm_start))
24477 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24478 return addr;
24479 }
24480 if (mm->get_unmapped_area == arch_get_unmapped_area)
24481 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24482 index 6cabf65..74565da 100644
24483 --- a/arch/x86/mm/init.c
24484 +++ b/arch/x86/mm/init.c
24485 @@ -17,6 +17,8 @@
24486 #include <asm/tlb.h>
24487 #include <asm/proto.h>
24488 #include <asm/dma.h> /* for MAX_DMA_PFN */
24489 +#include <asm/desc.h>
24490 +#include <asm/bios_ebda.h>
24491
24492 unsigned long __initdata pgt_buf_start;
24493 unsigned long __meminitdata pgt_buf_end;
24494 @@ -33,7 +35,7 @@ int direct_gbpages
24495 static void __init find_early_table_space(unsigned long end, int use_pse,
24496 int use_gbpages)
24497 {
24498 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24499 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24500 phys_addr_t base;
24501
24502 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24503 @@ -312,10 +314,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24504 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24505 * mmio resources as well as potential bios/acpi data regions.
24506 */
24507 +
24508 +#ifdef CONFIG_GRKERNSEC_KMEM
24509 +static unsigned int ebda_start __read_only;
24510 +static unsigned int ebda_end __read_only;
24511 +#endif
24512 +
24513 int devmem_is_allowed(unsigned long pagenr)
24514 {
24515 +#ifdef CONFIG_GRKERNSEC_KMEM
24516 + /* allow BDA */
24517 + if (!pagenr)
24518 + return 1;
24519 + /* allow EBDA */
24520 + if (pagenr >= ebda_start && pagenr < ebda_end)
24521 + return 1;
24522 +#else
24523 + if (!pagenr)
24524 + return 1;
24525 +#ifdef CONFIG_VM86
24526 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24527 + return 1;
24528 +#endif
24529 +#endif
24530 +
24531 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24532 + return 1;
24533 +#ifdef CONFIG_GRKERNSEC_KMEM
24534 + /* throw out everything else below 1MB */
24535 if (pagenr <= 256)
24536 - return 1;
24537 + return 0;
24538 +#endif
24539 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24540 return 0;
24541 if (!page_is_ram(pagenr))
24542 @@ -372,8 +401,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24543 #endif
24544 }
24545
24546 +#ifdef CONFIG_GRKERNSEC_KMEM
24547 +static inline void gr_init_ebda(void)
24548 +{
24549 + unsigned int ebda_addr;
24550 + unsigned int ebda_size = 0;
24551 +
24552 + ebda_addr = get_bios_ebda();
24553 + if (ebda_addr) {
24554 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24555 + ebda_size <<= 10;
24556 + }
24557 + if (ebda_addr && ebda_size) {
24558 + ebda_start = ebda_addr >> PAGE_SHIFT;
24559 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24560 + } else {
24561 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24562 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24563 + }
24564 +}
24565 +#else
24566 +static inline void gr_init_ebda(void) { }
24567 +#endif
24568 +
24569 void free_initmem(void)
24570 {
24571 +#ifdef CONFIG_PAX_KERNEXEC
24572 +#ifdef CONFIG_X86_32
24573 + /* PaX: limit KERNEL_CS to actual size */
24574 + unsigned long addr, limit;
24575 + struct desc_struct d;
24576 + int cpu;
24577 +#else
24578 + pgd_t *pgd;
24579 + pud_t *pud;
24580 + pmd_t *pmd;
24581 + unsigned long addr, end;
24582 +#endif
24583 +#endif
24584 +
24585 + gr_init_ebda();
24586 +
24587 +#ifdef CONFIG_PAX_KERNEXEC
24588 +#ifdef CONFIG_X86_32
24589 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24590 + limit = (limit - 1UL) >> PAGE_SHIFT;
24591 +
24592 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24593 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24594 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24595 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24596 + }
24597 +
24598 + /* PaX: make KERNEL_CS read-only */
24599 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24600 + if (!paravirt_enabled())
24601 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24602 +/*
24603 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24604 + pgd = pgd_offset_k(addr);
24605 + pud = pud_offset(pgd, addr);
24606 + pmd = pmd_offset(pud, addr);
24607 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24608 + }
24609 +*/
24610 +#ifdef CONFIG_X86_PAE
24611 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24612 +/*
24613 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24614 + pgd = pgd_offset_k(addr);
24615 + pud = pud_offset(pgd, addr);
24616 + pmd = pmd_offset(pud, addr);
24617 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24618 + }
24619 +*/
24620 +#endif
24621 +
24622 +#ifdef CONFIG_MODULES
24623 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24624 +#endif
24625 +
24626 +#else
24627 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24628 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24629 + pgd = pgd_offset_k(addr);
24630 + pud = pud_offset(pgd, addr);
24631 + pmd = pmd_offset(pud, addr);
24632 + if (!pmd_present(*pmd))
24633 + continue;
24634 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24635 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24636 + else
24637 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24638 + }
24639 +
24640 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24641 + end = addr + KERNEL_IMAGE_SIZE;
24642 + for (; addr < end; addr += PMD_SIZE) {
24643 + pgd = pgd_offset_k(addr);
24644 + pud = pud_offset(pgd, addr);
24645 + pmd = pmd_offset(pud, addr);
24646 + if (!pmd_present(*pmd))
24647 + continue;
24648 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24649 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24650 + }
24651 +#endif
24652 +
24653 + flush_tlb_all();
24654 +#endif
24655 +
24656 free_init_pages("unused kernel memory",
24657 (unsigned long)(&__init_begin),
24658 (unsigned long)(&__init_end));
24659 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24660 index 8663f6c..829ae76 100644
24661 --- a/arch/x86/mm/init_32.c
24662 +++ b/arch/x86/mm/init_32.c
24663 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
24664 }
24665
24666 /*
24667 - * Creates a middle page table and puts a pointer to it in the
24668 - * given global directory entry. This only returns the gd entry
24669 - * in non-PAE compilation mode, since the middle layer is folded.
24670 - */
24671 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24672 -{
24673 - pud_t *pud;
24674 - pmd_t *pmd_table;
24675 -
24676 -#ifdef CONFIG_X86_PAE
24677 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24678 - if (after_bootmem)
24679 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24680 - else
24681 - pmd_table = (pmd_t *)alloc_low_page();
24682 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24683 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24684 - pud = pud_offset(pgd, 0);
24685 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24686 -
24687 - return pmd_table;
24688 - }
24689 -#endif
24690 - pud = pud_offset(pgd, 0);
24691 - pmd_table = pmd_offset(pud, 0);
24692 -
24693 - return pmd_table;
24694 -}
24695 -
24696 -/*
24697 * Create a page table and place a pointer to it in a middle page
24698 * directory entry:
24699 */
24700 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24701 page_table = (pte_t *)alloc_low_page();
24702
24703 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24704 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24705 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24706 +#else
24707 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24708 +#endif
24709 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24710 }
24711
24712 return pte_offset_kernel(pmd, 0);
24713 }
24714
24715 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24716 +{
24717 + pud_t *pud;
24718 + pmd_t *pmd_table;
24719 +
24720 + pud = pud_offset(pgd, 0);
24721 + pmd_table = pmd_offset(pud, 0);
24722 +
24723 + return pmd_table;
24724 +}
24725 +
24726 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24727 {
24728 int pgd_idx = pgd_index(vaddr);
24729 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24730 int pgd_idx, pmd_idx;
24731 unsigned long vaddr;
24732 pgd_t *pgd;
24733 + pud_t *pud;
24734 pmd_t *pmd;
24735 pte_t *pte = NULL;
24736
24737 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24738 pgd = pgd_base + pgd_idx;
24739
24740 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24741 - pmd = one_md_table_init(pgd);
24742 - pmd = pmd + pmd_index(vaddr);
24743 + pud = pud_offset(pgd, vaddr);
24744 + pmd = pmd_offset(pud, vaddr);
24745 +
24746 +#ifdef CONFIG_X86_PAE
24747 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24748 +#endif
24749 +
24750 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24751 pmd++, pmd_idx++) {
24752 pte = page_table_kmap_check(one_page_table_init(pmd),
24753 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24754 }
24755 }
24756
24757 -static inline int is_kernel_text(unsigned long addr)
24758 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24759 {
24760 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24761 - return 1;
24762 - return 0;
24763 + if ((start > ktla_ktva((unsigned long)_etext) ||
24764 + end <= ktla_ktva((unsigned long)_stext)) &&
24765 + (start > ktla_ktva((unsigned long)_einittext) ||
24766 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24767 +
24768 +#ifdef CONFIG_ACPI_SLEEP
24769 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24770 +#endif
24771 +
24772 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24773 + return 0;
24774 + return 1;
24775 }
24776
24777 /*
24778 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
24779 unsigned long last_map_addr = end;
24780 unsigned long start_pfn, end_pfn;
24781 pgd_t *pgd_base = swapper_pg_dir;
24782 - int pgd_idx, pmd_idx, pte_ofs;
24783 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24784 unsigned long pfn;
24785 pgd_t *pgd;
24786 + pud_t *pud;
24787 pmd_t *pmd;
24788 pte_t *pte;
24789 unsigned pages_2m, pages_4k;
24790 @@ -281,8 +282,13 @@ repeat:
24791 pfn = start_pfn;
24792 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24793 pgd = pgd_base + pgd_idx;
24794 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24795 - pmd = one_md_table_init(pgd);
24796 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24797 + pud = pud_offset(pgd, 0);
24798 + pmd = pmd_offset(pud, 0);
24799 +
24800 +#ifdef CONFIG_X86_PAE
24801 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24802 +#endif
24803
24804 if (pfn >= end_pfn)
24805 continue;
24806 @@ -294,14 +300,13 @@ repeat:
24807 #endif
24808 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24809 pmd++, pmd_idx++) {
24810 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24811 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24812
24813 /*
24814 * Map with big pages if possible, otherwise
24815 * create normal page tables:
24816 */
24817 if (use_pse) {
24818 - unsigned int addr2;
24819 pgprot_t prot = PAGE_KERNEL_LARGE;
24820 /*
24821 * first pass will use the same initial
24822 @@ -311,11 +316,7 @@ repeat:
24823 __pgprot(PTE_IDENT_ATTR |
24824 _PAGE_PSE);
24825
24826 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24827 - PAGE_OFFSET + PAGE_SIZE-1;
24828 -
24829 - if (is_kernel_text(addr) ||
24830 - is_kernel_text(addr2))
24831 + if (is_kernel_text(address, address + PMD_SIZE))
24832 prot = PAGE_KERNEL_LARGE_EXEC;
24833
24834 pages_2m++;
24835 @@ -332,7 +333,7 @@ repeat:
24836 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24837 pte += pte_ofs;
24838 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24839 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24840 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24841 pgprot_t prot = PAGE_KERNEL;
24842 /*
24843 * first pass will use the same initial
24844 @@ -340,7 +341,7 @@ repeat:
24845 */
24846 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24847
24848 - if (is_kernel_text(addr))
24849 + if (is_kernel_text(address, address + PAGE_SIZE))
24850 prot = PAGE_KERNEL_EXEC;
24851
24852 pages_4k++;
24853 @@ -466,7 +467,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24854
24855 pud = pud_offset(pgd, va);
24856 pmd = pmd_offset(pud, va);
24857 - if (!pmd_present(*pmd))
24858 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24859 break;
24860
24861 pte = pte_offset_kernel(pmd, va);
24862 @@ -518,12 +519,10 @@ void __init early_ioremap_page_table_range_init(void)
24863
24864 static void __init pagetable_init(void)
24865 {
24866 - pgd_t *pgd_base = swapper_pg_dir;
24867 -
24868 - permanent_kmaps_init(pgd_base);
24869 + permanent_kmaps_init(swapper_pg_dir);
24870 }
24871
24872 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24873 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24874 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24875
24876 /* user-defined highmem size */
24877 @@ -735,6 +734,12 @@ void __init mem_init(void)
24878
24879 pci_iommu_alloc();
24880
24881 +#ifdef CONFIG_PAX_PER_CPU_PGD
24882 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24883 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24884 + KERNEL_PGD_PTRS);
24885 +#endif
24886 +
24887 #ifdef CONFIG_FLATMEM
24888 BUG_ON(!mem_map);
24889 #endif
24890 @@ -761,7 +766,7 @@ void __init mem_init(void)
24891 reservedpages++;
24892
24893 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24894 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24895 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24896 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24897
24898 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24899 @@ -802,10 +807,10 @@ void __init mem_init(void)
24900 ((unsigned long)&__init_end -
24901 (unsigned long)&__init_begin) >> 10,
24902
24903 - (unsigned long)&_etext, (unsigned long)&_edata,
24904 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24905 + (unsigned long)&_sdata, (unsigned long)&_edata,
24906 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24907
24908 - (unsigned long)&_text, (unsigned long)&_etext,
24909 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24910 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24911
24912 /*
24913 @@ -883,6 +888,7 @@ void set_kernel_text_rw(void)
24914 if (!kernel_set_to_readonly)
24915 return;
24916
24917 + start = ktla_ktva(start);
24918 pr_debug("Set kernel text: %lx - %lx for read write\n",
24919 start, start+size);
24920
24921 @@ -897,6 +903,7 @@ void set_kernel_text_ro(void)
24922 if (!kernel_set_to_readonly)
24923 return;
24924
24925 + start = ktla_ktva(start);
24926 pr_debug("Set kernel text: %lx - %lx for read only\n",
24927 start, start+size);
24928
24929 @@ -925,6 +932,7 @@ void mark_rodata_ro(void)
24930 unsigned long start = PFN_ALIGN(_text);
24931 unsigned long size = PFN_ALIGN(_etext) - start;
24932
24933 + start = ktla_ktva(start);
24934 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
24935 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
24936 size >> 10);
24937 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
24938 index 436a030..4f97ffc 100644
24939 --- a/arch/x86/mm/init_64.c
24940 +++ b/arch/x86/mm/init_64.c
24941 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
24942 * around without checking the pgd every time.
24943 */
24944
24945 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
24946 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
24947 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24948
24949 int force_personality32;
24950 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24951
24952 for (address = start; address <= end; address += PGDIR_SIZE) {
24953 const pgd_t *pgd_ref = pgd_offset_k(address);
24954 +
24955 +#ifdef CONFIG_PAX_PER_CPU_PGD
24956 + unsigned long cpu;
24957 +#else
24958 struct page *page;
24959 +#endif
24960
24961 if (pgd_none(*pgd_ref))
24962 continue;
24963
24964 spin_lock(&pgd_lock);
24965 +
24966 +#ifdef CONFIG_PAX_PER_CPU_PGD
24967 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
24968 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
24969 +#else
24970 list_for_each_entry(page, &pgd_list, lru) {
24971 pgd_t *pgd;
24972 spinlock_t *pgt_lock;
24973 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24974 /* the pgt_lock only for Xen */
24975 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
24976 spin_lock(pgt_lock);
24977 +#endif
24978
24979 if (pgd_none(*pgd))
24980 set_pgd(pgd, *pgd_ref);
24981 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
24982 BUG_ON(pgd_page_vaddr(*pgd)
24983 != pgd_page_vaddr(*pgd_ref));
24984
24985 +#ifndef CONFIG_PAX_PER_CPU_PGD
24986 spin_unlock(pgt_lock);
24987 +#endif
24988 +
24989 }
24990 spin_unlock(&pgd_lock);
24991 }
24992 @@ -162,7 +176,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
24993 {
24994 if (pgd_none(*pgd)) {
24995 pud_t *pud = (pud_t *)spp_getpage();
24996 - pgd_populate(&init_mm, pgd, pud);
24997 + pgd_populate_kernel(&init_mm, pgd, pud);
24998 if (pud != pud_offset(pgd, 0))
24999 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25000 pud, pud_offset(pgd, 0));
25001 @@ -174,7 +188,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25002 {
25003 if (pud_none(*pud)) {
25004 pmd_t *pmd = (pmd_t *) spp_getpage();
25005 - pud_populate(&init_mm, pud, pmd);
25006 + pud_populate_kernel(&init_mm, pud, pmd);
25007 if (pmd != pmd_offset(pud, 0))
25008 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25009 pmd, pmd_offset(pud, 0));
25010 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25011 pmd = fill_pmd(pud, vaddr);
25012 pte = fill_pte(pmd, vaddr);
25013
25014 + pax_open_kernel();
25015 set_pte(pte, new_pte);
25016 + pax_close_kernel();
25017
25018 /*
25019 * It's enough to flush this one mapping.
25020 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25021 pgd = pgd_offset_k((unsigned long)__va(phys));
25022 if (pgd_none(*pgd)) {
25023 pud = (pud_t *) spp_getpage();
25024 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25025 - _PAGE_USER));
25026 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25027 }
25028 pud = pud_offset(pgd, (unsigned long)__va(phys));
25029 if (pud_none(*pud)) {
25030 pmd = (pmd_t *) spp_getpage();
25031 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25032 - _PAGE_USER));
25033 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25034 }
25035 pmd = pmd_offset(pud, phys);
25036 BUG_ON(!pmd_none(*pmd));
25037 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25038 if (pfn >= pgt_buf_top)
25039 panic("alloc_low_page: ran out of memory");
25040
25041 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25042 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25043 clear_page(adr);
25044 *phys = pfn * PAGE_SIZE;
25045 return adr;
25046 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
25047
25048 phys = __pa(virt);
25049 left = phys & (PAGE_SIZE - 1);
25050 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25051 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25052 adr = (void *)(((unsigned long)adr) | left);
25053
25054 return adr;
25055 @@ -546,7 +560,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25056 unmap_low_page(pmd);
25057
25058 spin_lock(&init_mm.page_table_lock);
25059 - pud_populate(&init_mm, pud, __va(pmd_phys));
25060 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25061 spin_unlock(&init_mm.page_table_lock);
25062 }
25063 __flush_tlb_all();
25064 @@ -592,7 +606,7 @@ kernel_physical_mapping_init(unsigned long start,
25065 unmap_low_page(pud);
25066
25067 spin_lock(&init_mm.page_table_lock);
25068 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25069 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25070 spin_unlock(&init_mm.page_table_lock);
25071 pgd_changed = true;
25072 }
25073 @@ -684,6 +698,12 @@ void __init mem_init(void)
25074
25075 pci_iommu_alloc();
25076
25077 +#ifdef CONFIG_PAX_PER_CPU_PGD
25078 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25079 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25080 + KERNEL_PGD_PTRS);
25081 +#endif
25082 +
25083 /* clear_bss() already clear the empty_zero_page */
25084
25085 reservedpages = 0;
25086 @@ -844,8 +864,8 @@ int kern_addr_valid(unsigned long addr)
25087 static struct vm_area_struct gate_vma = {
25088 .vm_start = VSYSCALL_START,
25089 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25090 - .vm_page_prot = PAGE_READONLY_EXEC,
25091 - .vm_flags = VM_READ | VM_EXEC
25092 + .vm_page_prot = PAGE_READONLY,
25093 + .vm_flags = VM_READ
25094 };
25095
25096 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25097 @@ -879,7 +899,7 @@ int in_gate_area_no_mm(unsigned long addr)
25098
25099 const char *arch_vma_name(struct vm_area_struct *vma)
25100 {
25101 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25102 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25103 return "[vdso]";
25104 if (vma == &gate_vma)
25105 return "[vsyscall]";
25106 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25107 index 7b179b4..6bd1777 100644
25108 --- a/arch/x86/mm/iomap_32.c
25109 +++ b/arch/x86/mm/iomap_32.c
25110 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25111 type = kmap_atomic_idx_push();
25112 idx = type + KM_TYPE_NR * smp_processor_id();
25113 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25114 +
25115 + pax_open_kernel();
25116 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25117 + pax_close_kernel();
25118 +
25119 arch_flush_lazy_mmu_mode();
25120
25121 return (void *)vaddr;
25122 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25123 index be1ef57..55f0160 100644
25124 --- a/arch/x86/mm/ioremap.c
25125 +++ b/arch/x86/mm/ioremap.c
25126 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25127 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25128 int is_ram = page_is_ram(pfn);
25129
25130 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25131 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25132 return NULL;
25133 WARN_ON_ONCE(is_ram);
25134 }
25135 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25136
25137 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25138 if (page_is_ram(start >> PAGE_SHIFT))
25139 +#ifdef CONFIG_HIGHMEM
25140 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25141 +#endif
25142 return __va(phys);
25143
25144 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25145 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25146 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25147
25148 static __initdata int after_paging_init;
25149 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25150 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25151
25152 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25153 {
25154 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25155 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25156
25157 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25158 - memset(bm_pte, 0, sizeof(bm_pte));
25159 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25160 + pmd_populate_user(&init_mm, pmd, bm_pte);
25161
25162 /*
25163 * The boot-ioremap range spans multiple pmds, for which
25164 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25165 index d87dd6d..bf3fa66 100644
25166 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25167 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25168 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25169 * memory (e.g. tracked pages)? For now, we need this to avoid
25170 * invoking kmemcheck for PnP BIOS calls.
25171 */
25172 - if (regs->flags & X86_VM_MASK)
25173 + if (v8086_mode(regs))
25174 return false;
25175 - if (regs->cs != __KERNEL_CS)
25176 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25177 return false;
25178
25179 pte = kmemcheck_pte_lookup(address);
25180 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25181 index 845df68..1d8d29f 100644
25182 --- a/arch/x86/mm/mmap.c
25183 +++ b/arch/x86/mm/mmap.c
25184 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25185 * Leave an at least ~128 MB hole with possible stack randomization.
25186 */
25187 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25188 -#define MAX_GAP (TASK_SIZE/6*5)
25189 +#define MAX_GAP (pax_task_size/6*5)
25190
25191 static int mmap_is_legacy(void)
25192 {
25193 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25194 return rnd << PAGE_SHIFT;
25195 }
25196
25197 -static unsigned long mmap_base(void)
25198 +static unsigned long mmap_base(struct mm_struct *mm)
25199 {
25200 unsigned long gap = rlimit(RLIMIT_STACK);
25201 + unsigned long pax_task_size = TASK_SIZE;
25202 +
25203 +#ifdef CONFIG_PAX_SEGMEXEC
25204 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25205 + pax_task_size = SEGMEXEC_TASK_SIZE;
25206 +#endif
25207
25208 if (gap < MIN_GAP)
25209 gap = MIN_GAP;
25210 else if (gap > MAX_GAP)
25211 gap = MAX_GAP;
25212
25213 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25214 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25215 }
25216
25217 /*
25218 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25219 * does, but not when emulating X86_32
25220 */
25221 -static unsigned long mmap_legacy_base(void)
25222 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25223 {
25224 - if (mmap_is_ia32())
25225 + if (mmap_is_ia32()) {
25226 +
25227 +#ifdef CONFIG_PAX_SEGMEXEC
25228 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25229 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25230 + else
25231 +#endif
25232 +
25233 return TASK_UNMAPPED_BASE;
25234 - else
25235 + } else
25236 return TASK_UNMAPPED_BASE + mmap_rnd();
25237 }
25238
25239 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25240 void arch_pick_mmap_layout(struct mm_struct *mm)
25241 {
25242 if (mmap_is_legacy()) {
25243 - mm->mmap_base = mmap_legacy_base();
25244 + mm->mmap_base = mmap_legacy_base(mm);
25245 +
25246 +#ifdef CONFIG_PAX_RANDMMAP
25247 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25248 + mm->mmap_base += mm->delta_mmap;
25249 +#endif
25250 +
25251 mm->get_unmapped_area = arch_get_unmapped_area;
25252 mm->unmap_area = arch_unmap_area;
25253 } else {
25254 - mm->mmap_base = mmap_base();
25255 + mm->mmap_base = mmap_base(mm);
25256 +
25257 +#ifdef CONFIG_PAX_RANDMMAP
25258 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25259 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25260 +#endif
25261 +
25262 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25263 mm->unmap_area = arch_unmap_area_topdown;
25264 }
25265 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25266 index dc0b727..dc9d71a 100644
25267 --- a/arch/x86/mm/mmio-mod.c
25268 +++ b/arch/x86/mm/mmio-mod.c
25269 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25270 break;
25271 default:
25272 {
25273 - unsigned char *ip = (unsigned char *)instptr;
25274 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25275 my_trace->opcode = MMIO_UNKNOWN_OP;
25276 my_trace->width = 0;
25277 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25278 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25279 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25280 void __iomem *addr)
25281 {
25282 - static atomic_t next_id;
25283 + static atomic_unchecked_t next_id;
25284 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25285 /* These are page-unaligned. */
25286 struct mmiotrace_map map = {
25287 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25288 .private = trace
25289 },
25290 .phys = offset,
25291 - .id = atomic_inc_return(&next_id)
25292 + .id = atomic_inc_return_unchecked(&next_id)
25293 };
25294 map.map_id = trace->id;
25295
25296 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25297 index b008656..773eac2 100644
25298 --- a/arch/x86/mm/pageattr-test.c
25299 +++ b/arch/x86/mm/pageattr-test.c
25300 @@ -36,7 +36,7 @@ enum {
25301
25302 static int pte_testbit(pte_t pte)
25303 {
25304 - return pte_flags(pte) & _PAGE_UNUSED1;
25305 + return pte_flags(pte) & _PAGE_CPA_TEST;
25306 }
25307
25308 struct split_state {
25309 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25310 index e1ebde3..b1e1db38 100644
25311 --- a/arch/x86/mm/pageattr.c
25312 +++ b/arch/x86/mm/pageattr.c
25313 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25314 */
25315 #ifdef CONFIG_PCI_BIOS
25316 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25317 - pgprot_val(forbidden) |= _PAGE_NX;
25318 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25319 #endif
25320
25321 /*
25322 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25323 * Does not cover __inittext since that is gone later on. On
25324 * 64bit we do not enforce !NX on the low mapping
25325 */
25326 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25327 - pgprot_val(forbidden) |= _PAGE_NX;
25328 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25329 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25330
25331 +#ifdef CONFIG_DEBUG_RODATA
25332 /*
25333 * The .rodata section needs to be read-only. Using the pfn
25334 * catches all aliases.
25335 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25336 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25337 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25338 pgprot_val(forbidden) |= _PAGE_RW;
25339 +#endif
25340
25341 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25342 /*
25343 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25344 }
25345 #endif
25346
25347 +#ifdef CONFIG_PAX_KERNEXEC
25348 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25349 + pgprot_val(forbidden) |= _PAGE_RW;
25350 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25351 + }
25352 +#endif
25353 +
25354 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25355
25356 return prot;
25357 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25358 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25359 {
25360 /* change init_mm */
25361 + pax_open_kernel();
25362 set_pte_atomic(kpte, pte);
25363 +
25364 #ifdef CONFIG_X86_32
25365 if (!SHARED_KERNEL_PMD) {
25366 +
25367 +#ifdef CONFIG_PAX_PER_CPU_PGD
25368 + unsigned long cpu;
25369 +#else
25370 struct page *page;
25371 +#endif
25372
25373 +#ifdef CONFIG_PAX_PER_CPU_PGD
25374 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25375 + pgd_t *pgd = get_cpu_pgd(cpu);
25376 +#else
25377 list_for_each_entry(page, &pgd_list, lru) {
25378 - pgd_t *pgd;
25379 + pgd_t *pgd = (pgd_t *)page_address(page);
25380 +#endif
25381 +
25382 pud_t *pud;
25383 pmd_t *pmd;
25384
25385 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25386 + pgd += pgd_index(address);
25387 pud = pud_offset(pgd, address);
25388 pmd = pmd_offset(pud, address);
25389 set_pte_atomic((pte_t *)pmd, pte);
25390 }
25391 }
25392 #endif
25393 + pax_close_kernel();
25394 }
25395
25396 static int
25397 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25398 index f6ff57b..481690f 100644
25399 --- a/arch/x86/mm/pat.c
25400 +++ b/arch/x86/mm/pat.c
25401 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
25402
25403 if (!entry) {
25404 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
25405 - current->comm, current->pid, start, end);
25406 + current->comm, task_pid_nr(current), start, end);
25407 return -EINVAL;
25408 }
25409
25410 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25411 while (cursor < to) {
25412 if (!devmem_is_allowed(pfn)) {
25413 printk(KERN_INFO
25414 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
25415 - current->comm, from, to);
25416 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
25417 + current->comm, from, to, cursor);
25418 return 0;
25419 }
25420 cursor += PAGE_SIZE;
25421 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25422 printk(KERN_INFO
25423 "%s:%d ioremap_change_attr failed %s "
25424 "for %Lx-%Lx\n",
25425 - current->comm, current->pid,
25426 + current->comm, task_pid_nr(current),
25427 cattr_name(flags),
25428 base, (unsigned long long)(base + size));
25429 return -EINVAL;
25430 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25431 if (want_flags != flags) {
25432 printk(KERN_WARNING
25433 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
25434 - current->comm, current->pid,
25435 + current->comm, task_pid_nr(current),
25436 cattr_name(want_flags),
25437 (unsigned long long)paddr,
25438 (unsigned long long)(paddr + size),
25439 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25440 free_memtype(paddr, paddr + size);
25441 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25442 " for %Lx-%Lx, got %s\n",
25443 - current->comm, current->pid,
25444 + current->comm, task_pid_nr(current),
25445 cattr_name(want_flags),
25446 (unsigned long long)paddr,
25447 (unsigned long long)(paddr + size),
25448 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25449 index 9f0614d..92ae64a 100644
25450 --- a/arch/x86/mm/pf_in.c
25451 +++ b/arch/x86/mm/pf_in.c
25452 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25453 int i;
25454 enum reason_type rv = OTHERS;
25455
25456 - p = (unsigned char *)ins_addr;
25457 + p = (unsigned char *)ktla_ktva(ins_addr);
25458 p += skip_prefix(p, &prf);
25459 p += get_opcode(p, &opcode);
25460
25461 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25462 struct prefix_bits prf;
25463 int i;
25464
25465 - p = (unsigned char *)ins_addr;
25466 + p = (unsigned char *)ktla_ktva(ins_addr);
25467 p += skip_prefix(p, &prf);
25468 p += get_opcode(p, &opcode);
25469
25470 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25471 struct prefix_bits prf;
25472 int i;
25473
25474 - p = (unsigned char *)ins_addr;
25475 + p = (unsigned char *)ktla_ktva(ins_addr);
25476 p += skip_prefix(p, &prf);
25477 p += get_opcode(p, &opcode);
25478
25479 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25480 struct prefix_bits prf;
25481 int i;
25482
25483 - p = (unsigned char *)ins_addr;
25484 + p = (unsigned char *)ktla_ktva(ins_addr);
25485 p += skip_prefix(p, &prf);
25486 p += get_opcode(p, &opcode);
25487 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25488 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25489 struct prefix_bits prf;
25490 int i;
25491
25492 - p = (unsigned char *)ins_addr;
25493 + p = (unsigned char *)ktla_ktva(ins_addr);
25494 p += skip_prefix(p, &prf);
25495 p += get_opcode(p, &opcode);
25496 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25497 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25498 index 8573b83..4f3ed7e 100644
25499 --- a/arch/x86/mm/pgtable.c
25500 +++ b/arch/x86/mm/pgtable.c
25501 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25502 list_del(&page->lru);
25503 }
25504
25505 -#define UNSHARED_PTRS_PER_PGD \
25506 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25507 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25508 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25509
25510 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25511 +{
25512 + unsigned int count = USER_PGD_PTRS;
25513
25514 + while (count--)
25515 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25516 +}
25517 +#endif
25518 +
25519 +#ifdef CONFIG_PAX_PER_CPU_PGD
25520 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25521 +{
25522 + unsigned int count = USER_PGD_PTRS;
25523 +
25524 + while (count--) {
25525 + pgd_t pgd;
25526 +
25527 +#ifdef CONFIG_X86_64
25528 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25529 +#else
25530 + pgd = *src++;
25531 +#endif
25532 +
25533 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25534 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25535 +#endif
25536 +
25537 + *dst++ = pgd;
25538 + }
25539 +
25540 +}
25541 +#endif
25542 +
25543 +#ifdef CONFIG_X86_64
25544 +#define pxd_t pud_t
25545 +#define pyd_t pgd_t
25546 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25547 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25548 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25549 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25550 +#define PYD_SIZE PGDIR_SIZE
25551 +#else
25552 +#define pxd_t pmd_t
25553 +#define pyd_t pud_t
25554 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25555 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25556 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25557 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25558 +#define PYD_SIZE PUD_SIZE
25559 +#endif
25560 +
25561 +#ifdef CONFIG_PAX_PER_CPU_PGD
25562 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25563 +static inline void pgd_dtor(pgd_t *pgd) {}
25564 +#else
25565 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25566 {
25567 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25568 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25569 pgd_list_del(pgd);
25570 spin_unlock(&pgd_lock);
25571 }
25572 +#endif
25573
25574 /*
25575 * List of all pgd's needed for non-PAE so it can invalidate entries
25576 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25577 * -- wli
25578 */
25579
25580 -#ifdef CONFIG_X86_PAE
25581 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25582 /*
25583 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25584 * updating the top-level pagetable entries to guarantee the
25585 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25586 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25587 * and initialize the kernel pmds here.
25588 */
25589 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25590 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25591
25592 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25593 {
25594 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25595 */
25596 flush_tlb_mm(mm);
25597 }
25598 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25599 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25600 #else /* !CONFIG_X86_PAE */
25601
25602 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25603 -#define PREALLOCATED_PMDS 0
25604 +#define PREALLOCATED_PXDS 0
25605
25606 #endif /* CONFIG_X86_PAE */
25607
25608 -static void free_pmds(pmd_t *pmds[])
25609 +static void free_pxds(pxd_t *pxds[])
25610 {
25611 int i;
25612
25613 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25614 - if (pmds[i])
25615 - free_page((unsigned long)pmds[i]);
25616 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25617 + if (pxds[i])
25618 + free_page((unsigned long)pxds[i]);
25619 }
25620
25621 -static int preallocate_pmds(pmd_t *pmds[])
25622 +static int preallocate_pxds(pxd_t *pxds[])
25623 {
25624 int i;
25625 bool failed = false;
25626
25627 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25628 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25629 - if (pmd == NULL)
25630 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25631 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25632 + if (pxd == NULL)
25633 failed = true;
25634 - pmds[i] = pmd;
25635 + pxds[i] = pxd;
25636 }
25637
25638 if (failed) {
25639 - free_pmds(pmds);
25640 + free_pxds(pxds);
25641 return -ENOMEM;
25642 }
25643
25644 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25645 * preallocate which never got a corresponding vma will need to be
25646 * freed manually.
25647 */
25648 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25649 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25650 {
25651 int i;
25652
25653 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25654 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25655 pgd_t pgd = pgdp[i];
25656
25657 if (pgd_val(pgd) != 0) {
25658 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25659 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25660
25661 - pgdp[i] = native_make_pgd(0);
25662 + set_pgd(pgdp + i, native_make_pgd(0));
25663
25664 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25665 - pmd_free(mm, pmd);
25666 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25667 + pxd_free(mm, pxd);
25668 }
25669 }
25670 }
25671
25672 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25673 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25674 {
25675 - pud_t *pud;
25676 + pyd_t *pyd;
25677 unsigned long addr;
25678 int i;
25679
25680 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25681 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25682 return;
25683
25684 - pud = pud_offset(pgd, 0);
25685 +#ifdef CONFIG_X86_64
25686 + pyd = pyd_offset(mm, 0L);
25687 +#else
25688 + pyd = pyd_offset(pgd, 0L);
25689 +#endif
25690
25691 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25692 - i++, pud++, addr += PUD_SIZE) {
25693 - pmd_t *pmd = pmds[i];
25694 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25695 + i++, pyd++, addr += PYD_SIZE) {
25696 + pxd_t *pxd = pxds[i];
25697
25698 if (i >= KERNEL_PGD_BOUNDARY)
25699 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25700 - sizeof(pmd_t) * PTRS_PER_PMD);
25701 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25702 + sizeof(pxd_t) * PTRS_PER_PMD);
25703
25704 - pud_populate(mm, pud, pmd);
25705 + pyd_populate(mm, pyd, pxd);
25706 }
25707 }
25708
25709 pgd_t *pgd_alloc(struct mm_struct *mm)
25710 {
25711 pgd_t *pgd;
25712 - pmd_t *pmds[PREALLOCATED_PMDS];
25713 + pxd_t *pxds[PREALLOCATED_PXDS];
25714
25715 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25716
25717 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25718
25719 mm->pgd = pgd;
25720
25721 - if (preallocate_pmds(pmds) != 0)
25722 + if (preallocate_pxds(pxds) != 0)
25723 goto out_free_pgd;
25724
25725 if (paravirt_pgd_alloc(mm) != 0)
25726 - goto out_free_pmds;
25727 + goto out_free_pxds;
25728
25729 /*
25730 * Make sure that pre-populating the pmds is atomic with
25731 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25732 spin_lock(&pgd_lock);
25733
25734 pgd_ctor(mm, pgd);
25735 - pgd_prepopulate_pmd(mm, pgd, pmds);
25736 + pgd_prepopulate_pxd(mm, pgd, pxds);
25737
25738 spin_unlock(&pgd_lock);
25739
25740 return pgd;
25741
25742 -out_free_pmds:
25743 - free_pmds(pmds);
25744 +out_free_pxds:
25745 + free_pxds(pxds);
25746 out_free_pgd:
25747 free_page((unsigned long)pgd);
25748 out:
25749 @@ -295,7 +356,7 @@ out:
25750
25751 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25752 {
25753 - pgd_mop_up_pmds(mm, pgd);
25754 + pgd_mop_up_pxds(mm, pgd);
25755 pgd_dtor(pgd);
25756 paravirt_pgd_free(mm, pgd);
25757 free_page((unsigned long)pgd);
25758 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25759 index cac7184..09a39fa 100644
25760 --- a/arch/x86/mm/pgtable_32.c
25761 +++ b/arch/x86/mm/pgtable_32.c
25762 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25763 return;
25764 }
25765 pte = pte_offset_kernel(pmd, vaddr);
25766 +
25767 + pax_open_kernel();
25768 if (pte_val(pteval))
25769 set_pte_at(&init_mm, vaddr, pte, pteval);
25770 else
25771 pte_clear(&init_mm, vaddr, pte);
25772 + pax_close_kernel();
25773
25774 /*
25775 * It's enough to flush this one mapping.
25776 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25777 index 410531d..0f16030 100644
25778 --- a/arch/x86/mm/setup_nx.c
25779 +++ b/arch/x86/mm/setup_nx.c
25780 @@ -5,8 +5,10 @@
25781 #include <asm/pgtable.h>
25782 #include <asm/proto.h>
25783
25784 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25785 static int disable_nx __cpuinitdata;
25786
25787 +#ifndef CONFIG_PAX_PAGEEXEC
25788 /*
25789 * noexec = on|off
25790 *
25791 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25792 return 0;
25793 }
25794 early_param("noexec", noexec_setup);
25795 +#endif
25796 +
25797 +#endif
25798
25799 void __cpuinit x86_configure_nx(void)
25800 {
25801 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25802 if (cpu_has_nx && !disable_nx)
25803 __supported_pte_mask |= _PAGE_NX;
25804 else
25805 +#endif
25806 __supported_pte_mask &= ~_PAGE_NX;
25807 }
25808
25809 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25810 index d6c0418..06a0ad5 100644
25811 --- a/arch/x86/mm/tlb.c
25812 +++ b/arch/x86/mm/tlb.c
25813 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
25814 BUG();
25815 cpumask_clear_cpu(cpu,
25816 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
25817 +
25818 +#ifndef CONFIG_PAX_PER_CPU_PGD
25819 load_cr3(swapper_pg_dir);
25820 +#endif
25821 +
25822 }
25823 EXPORT_SYMBOL_GPL(leave_mm);
25824
25825 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25826 index 6687022..ceabcfa 100644
25827 --- a/arch/x86/net/bpf_jit.S
25828 +++ b/arch/x86/net/bpf_jit.S
25829 @@ -9,6 +9,7 @@
25830 */
25831 #include <linux/linkage.h>
25832 #include <asm/dwarf2.h>
25833 +#include <asm/alternative-asm.h>
25834
25835 /*
25836 * Calling convention :
25837 @@ -35,6 +36,7 @@ sk_load_word:
25838 jle bpf_slow_path_word
25839 mov (SKBDATA,%rsi),%eax
25840 bswap %eax /* ntohl() */
25841 + pax_force_retaddr
25842 ret
25843
25844
25845 @@ -53,6 +55,7 @@ sk_load_half:
25846 jle bpf_slow_path_half
25847 movzwl (SKBDATA,%rsi),%eax
25848 rol $8,%ax # ntohs()
25849 + pax_force_retaddr
25850 ret
25851
25852 sk_load_byte_ind:
25853 @@ -66,6 +69,7 @@ sk_load_byte:
25854 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25855 jle bpf_slow_path_byte
25856 movzbl (SKBDATA,%rsi),%eax
25857 + pax_force_retaddr
25858 ret
25859
25860 /**
25861 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
25862 movzbl (SKBDATA,%rsi),%ebx
25863 and $15,%bl
25864 shl $2,%bl
25865 + pax_force_retaddr
25866 ret
25867 CFI_ENDPROC
25868 ENDPROC(sk_load_byte_msh)
25869 @@ -91,6 +96,7 @@ bpf_error:
25870 xor %eax,%eax
25871 mov -8(%rbp),%rbx
25872 leaveq
25873 + pax_force_retaddr
25874 ret
25875
25876 /* rsi contains offset and can be scratched */
25877 @@ -113,6 +119,7 @@ bpf_slow_path_word:
25878 js bpf_error
25879 mov -12(%rbp),%eax
25880 bswap %eax
25881 + pax_force_retaddr
25882 ret
25883
25884 bpf_slow_path_half:
25885 @@ -121,12 +128,14 @@ bpf_slow_path_half:
25886 mov -12(%rbp),%ax
25887 rol $8,%ax
25888 movzwl %ax,%eax
25889 + pax_force_retaddr
25890 ret
25891
25892 bpf_slow_path_byte:
25893 bpf_slow_path_common(1)
25894 js bpf_error
25895 movzbl -12(%rbp),%eax
25896 + pax_force_retaddr
25897 ret
25898
25899 bpf_slow_path_byte_msh:
25900 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
25901 and $15,%al
25902 shl $2,%al
25903 xchg %eax,%ebx
25904 + pax_force_retaddr
25905 ret
25906 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
25907 index 5a5b6e4..201d42e 100644
25908 --- a/arch/x86/net/bpf_jit_comp.c
25909 +++ b/arch/x86/net/bpf_jit_comp.c
25910 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
25911 set_fs(old_fs);
25912 }
25913
25914 +struct bpf_jit_work {
25915 + struct work_struct work;
25916 + void *image;
25917 +};
25918
25919 void bpf_jit_compile(struct sk_filter *fp)
25920 {
25921 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
25922 if (addrs == NULL)
25923 return;
25924
25925 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
25926 + if (!fp->work)
25927 + goto out;
25928 +
25929 /* Before first pass, make a rough estimation of addrs[]
25930 * each bpf instruction is translated to less than 64 bytes
25931 */
25932 @@ -477,7 +485,7 @@ void bpf_jit_compile(struct sk_filter *fp)
25933 common_load: seen |= SEEN_DATAREF;
25934 if ((int)K < 0) {
25935 /* Abort the JIT because __load_pointer() is needed. */
25936 - goto out;
25937 + goto error;
25938 }
25939 t_offset = func - (image + addrs[i]);
25940 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
25941 @@ -492,7 +500,7 @@ common_load: seen |= SEEN_DATAREF;
25942 case BPF_S_LDX_B_MSH:
25943 if ((int)K < 0) {
25944 /* Abort the JIT because __load_pointer() is needed. */
25945 - goto out;
25946 + goto error;
25947 }
25948 seen |= SEEN_DATAREF | SEEN_XREG;
25949 t_offset = sk_load_byte_msh - (image + addrs[i]);
25950 @@ -582,17 +590,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25951 break;
25952 default:
25953 /* hmm, too complex filter, give up with jit compiler */
25954 - goto out;
25955 + goto error;
25956 }
25957 ilen = prog - temp;
25958 if (image) {
25959 if (unlikely(proglen + ilen > oldproglen)) {
25960 pr_err("bpb_jit_compile fatal error\n");
25961 - kfree(addrs);
25962 - module_free(NULL, image);
25963 - return;
25964 + module_free_exec(NULL, image);
25965 + goto error;
25966 }
25967 + pax_open_kernel();
25968 memcpy(image + proglen, temp, ilen);
25969 + pax_close_kernel();
25970 }
25971 proglen += ilen;
25972 addrs[i] = proglen;
25973 @@ -613,11 +622,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25974 break;
25975 }
25976 if (proglen == oldproglen) {
25977 - image = module_alloc(max_t(unsigned int,
25978 - proglen,
25979 - sizeof(struct work_struct)));
25980 + image = module_alloc_exec(proglen);
25981 if (!image)
25982 - goto out;
25983 + goto error;
25984 }
25985 oldproglen = proglen;
25986 }
25987 @@ -633,7 +640,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
25988 bpf_flush_icache(image, image + proglen);
25989
25990 fp->bpf_func = (void *)image;
25991 - }
25992 + } else
25993 +error:
25994 + kfree(fp->work);
25995 +
25996 out:
25997 kfree(addrs);
25998 return;
25999 @@ -641,18 +651,20 @@ out:
26000
26001 static void jit_free_defer(struct work_struct *arg)
26002 {
26003 - module_free(NULL, arg);
26004 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26005 + kfree(arg);
26006 }
26007
26008 /* run from softirq, we must use a work_struct to call
26009 - * module_free() from process context
26010 + * module_free_exec() from process context
26011 */
26012 void bpf_jit_free(struct sk_filter *fp)
26013 {
26014 if (fp->bpf_func != sk_run_filter) {
26015 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26016 + struct work_struct *work = &fp->work->work;
26017
26018 INIT_WORK(work, jit_free_defer);
26019 + fp->work->image = fp->bpf_func;
26020 schedule_work(work);
26021 }
26022 }
26023 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26024 index bff89df..377758a 100644
26025 --- a/arch/x86/oprofile/backtrace.c
26026 +++ b/arch/x86/oprofile/backtrace.c
26027 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26028 struct stack_frame_ia32 *fp;
26029 unsigned long bytes;
26030
26031 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26032 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26033 if (bytes != sizeof(bufhead))
26034 return NULL;
26035
26036 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26037 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26038
26039 oprofile_add_trace(bufhead[0].return_address);
26040
26041 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26042 struct stack_frame bufhead[2];
26043 unsigned long bytes;
26044
26045 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26046 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26047 if (bytes != sizeof(bufhead))
26048 return NULL;
26049
26050 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26051 {
26052 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26053
26054 - if (!user_mode_vm(regs)) {
26055 + if (!user_mode(regs)) {
26056 unsigned long stack = kernel_stack_pointer(regs);
26057 if (depth)
26058 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26059 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26060 index cb29191..036766d 100644
26061 --- a/arch/x86/pci/mrst.c
26062 +++ b/arch/x86/pci/mrst.c
26063 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
26064 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
26065 pci_mmcfg_late_init();
26066 pcibios_enable_irq = mrst_pci_irq_enable;
26067 - pci_root_ops = pci_mrst_ops;
26068 + pax_open_kernel();
26069 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26070 + pax_close_kernel();
26071 /* Continue with standard init */
26072 return 1;
26073 }
26074 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26075 index da8fe05..7ee6704 100644
26076 --- a/arch/x86/pci/pcbios.c
26077 +++ b/arch/x86/pci/pcbios.c
26078 @@ -79,50 +79,93 @@ union bios32 {
26079 static struct {
26080 unsigned long address;
26081 unsigned short segment;
26082 -} bios32_indirect = { 0, __KERNEL_CS };
26083 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26084
26085 /*
26086 * Returns the entry point for the given service, NULL on error
26087 */
26088
26089 -static unsigned long bios32_service(unsigned long service)
26090 +static unsigned long __devinit bios32_service(unsigned long service)
26091 {
26092 unsigned char return_code; /* %al */
26093 unsigned long address; /* %ebx */
26094 unsigned long length; /* %ecx */
26095 unsigned long entry; /* %edx */
26096 unsigned long flags;
26097 + struct desc_struct d, *gdt;
26098
26099 local_irq_save(flags);
26100 - __asm__("lcall *(%%edi); cld"
26101 +
26102 + gdt = get_cpu_gdt_table(smp_processor_id());
26103 +
26104 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26105 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26106 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26107 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26108 +
26109 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26110 : "=a" (return_code),
26111 "=b" (address),
26112 "=c" (length),
26113 "=d" (entry)
26114 : "0" (service),
26115 "1" (0),
26116 - "D" (&bios32_indirect));
26117 + "D" (&bios32_indirect),
26118 + "r"(__PCIBIOS_DS)
26119 + : "memory");
26120 +
26121 + pax_open_kernel();
26122 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26123 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26124 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26125 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26126 + pax_close_kernel();
26127 +
26128 local_irq_restore(flags);
26129
26130 switch (return_code) {
26131 - case 0:
26132 - return address + entry;
26133 - case 0x80: /* Not present */
26134 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26135 - return 0;
26136 - default: /* Shouldn't happen */
26137 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26138 - service, return_code);
26139 + case 0: {
26140 + int cpu;
26141 + unsigned char flags;
26142 +
26143 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26144 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26145 + printk(KERN_WARNING "bios32_service: not valid\n");
26146 return 0;
26147 + }
26148 + address = address + PAGE_OFFSET;
26149 + length += 16UL; /* some BIOSs underreport this... */
26150 + flags = 4;
26151 + if (length >= 64*1024*1024) {
26152 + length >>= PAGE_SHIFT;
26153 + flags |= 8;
26154 + }
26155 +
26156 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26157 + gdt = get_cpu_gdt_table(cpu);
26158 + pack_descriptor(&d, address, length, 0x9b, flags);
26159 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26160 + pack_descriptor(&d, address, length, 0x93, flags);
26161 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26162 + }
26163 + return entry;
26164 + }
26165 + case 0x80: /* Not present */
26166 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26167 + return 0;
26168 + default: /* Shouldn't happen */
26169 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26170 + service, return_code);
26171 + return 0;
26172 }
26173 }
26174
26175 static struct {
26176 unsigned long address;
26177 unsigned short segment;
26178 -} pci_indirect = { 0, __KERNEL_CS };
26179 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26180
26181 -static int pci_bios_present;
26182 +static int pci_bios_present __read_only;
26183
26184 static int __devinit check_pcibios(void)
26185 {
26186 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26187 unsigned long flags, pcibios_entry;
26188
26189 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26190 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26191 + pci_indirect.address = pcibios_entry;
26192
26193 local_irq_save(flags);
26194 - __asm__(
26195 - "lcall *(%%edi); cld\n\t"
26196 + __asm__("movw %w6, %%ds\n\t"
26197 + "lcall *%%ss:(%%edi); cld\n\t"
26198 + "push %%ss\n\t"
26199 + "pop %%ds\n\t"
26200 "jc 1f\n\t"
26201 "xor %%ah, %%ah\n"
26202 "1:"
26203 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26204 "=b" (ebx),
26205 "=c" (ecx)
26206 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26207 - "D" (&pci_indirect)
26208 + "D" (&pci_indirect),
26209 + "r" (__PCIBIOS_DS)
26210 : "memory");
26211 local_irq_restore(flags);
26212
26213 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26214
26215 switch (len) {
26216 case 1:
26217 - __asm__("lcall *(%%esi); cld\n\t"
26218 + __asm__("movw %w6, %%ds\n\t"
26219 + "lcall *%%ss:(%%esi); cld\n\t"
26220 + "push %%ss\n\t"
26221 + "pop %%ds\n\t"
26222 "jc 1f\n\t"
26223 "xor %%ah, %%ah\n"
26224 "1:"
26225 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26226 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26227 "b" (bx),
26228 "D" ((long)reg),
26229 - "S" (&pci_indirect));
26230 + "S" (&pci_indirect),
26231 + "r" (__PCIBIOS_DS));
26232 /*
26233 * Zero-extend the result beyond 8 bits, do not trust the
26234 * BIOS having done it:
26235 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26236 *value &= 0xff;
26237 break;
26238 case 2:
26239 - __asm__("lcall *(%%esi); cld\n\t"
26240 + __asm__("movw %w6, %%ds\n\t"
26241 + "lcall *%%ss:(%%esi); cld\n\t"
26242 + "push %%ss\n\t"
26243 + "pop %%ds\n\t"
26244 "jc 1f\n\t"
26245 "xor %%ah, %%ah\n"
26246 "1:"
26247 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26248 : "1" (PCIBIOS_READ_CONFIG_WORD),
26249 "b" (bx),
26250 "D" ((long)reg),
26251 - "S" (&pci_indirect));
26252 + "S" (&pci_indirect),
26253 + "r" (__PCIBIOS_DS));
26254 /*
26255 * Zero-extend the result beyond 16 bits, do not trust the
26256 * BIOS having done it:
26257 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26258 *value &= 0xffff;
26259 break;
26260 case 4:
26261 - __asm__("lcall *(%%esi); cld\n\t"
26262 + __asm__("movw %w6, %%ds\n\t"
26263 + "lcall *%%ss:(%%esi); cld\n\t"
26264 + "push %%ss\n\t"
26265 + "pop %%ds\n\t"
26266 "jc 1f\n\t"
26267 "xor %%ah, %%ah\n"
26268 "1:"
26269 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26270 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26271 "b" (bx),
26272 "D" ((long)reg),
26273 - "S" (&pci_indirect));
26274 + "S" (&pci_indirect),
26275 + "r" (__PCIBIOS_DS));
26276 break;
26277 }
26278
26279 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26280
26281 switch (len) {
26282 case 1:
26283 - __asm__("lcall *(%%esi); cld\n\t"
26284 + __asm__("movw %w6, %%ds\n\t"
26285 + "lcall *%%ss:(%%esi); cld\n\t"
26286 + "push %%ss\n\t"
26287 + "pop %%ds\n\t"
26288 "jc 1f\n\t"
26289 "xor %%ah, %%ah\n"
26290 "1:"
26291 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26292 "c" (value),
26293 "b" (bx),
26294 "D" ((long)reg),
26295 - "S" (&pci_indirect));
26296 + "S" (&pci_indirect),
26297 + "r" (__PCIBIOS_DS));
26298 break;
26299 case 2:
26300 - __asm__("lcall *(%%esi); cld\n\t"
26301 + __asm__("movw %w6, %%ds\n\t"
26302 + "lcall *%%ss:(%%esi); cld\n\t"
26303 + "push %%ss\n\t"
26304 + "pop %%ds\n\t"
26305 "jc 1f\n\t"
26306 "xor %%ah, %%ah\n"
26307 "1:"
26308 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26309 "c" (value),
26310 "b" (bx),
26311 "D" ((long)reg),
26312 - "S" (&pci_indirect));
26313 + "S" (&pci_indirect),
26314 + "r" (__PCIBIOS_DS));
26315 break;
26316 case 4:
26317 - __asm__("lcall *(%%esi); cld\n\t"
26318 + __asm__("movw %w6, %%ds\n\t"
26319 + "lcall *%%ss:(%%esi); cld\n\t"
26320 + "push %%ss\n\t"
26321 + "pop %%ds\n\t"
26322 "jc 1f\n\t"
26323 "xor %%ah, %%ah\n"
26324 "1:"
26325 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26326 "c" (value),
26327 "b" (bx),
26328 "D" ((long)reg),
26329 - "S" (&pci_indirect));
26330 + "S" (&pci_indirect),
26331 + "r" (__PCIBIOS_DS));
26332 break;
26333 }
26334
26335 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26336
26337 DBG("PCI: Fetching IRQ routing table... ");
26338 __asm__("push %%es\n\t"
26339 + "movw %w8, %%ds\n\t"
26340 "push %%ds\n\t"
26341 "pop %%es\n\t"
26342 - "lcall *(%%esi); cld\n\t"
26343 + "lcall *%%ss:(%%esi); cld\n\t"
26344 "pop %%es\n\t"
26345 + "push %%ss\n\t"
26346 + "pop %%ds\n"
26347 "jc 1f\n\t"
26348 "xor %%ah, %%ah\n"
26349 "1:"
26350 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26351 "1" (0),
26352 "D" ((long) &opt),
26353 "S" (&pci_indirect),
26354 - "m" (opt)
26355 + "m" (opt),
26356 + "r" (__PCIBIOS_DS)
26357 : "memory");
26358 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26359 if (ret & 0xff00)
26360 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26361 {
26362 int ret;
26363
26364 - __asm__("lcall *(%%esi); cld\n\t"
26365 + __asm__("movw %w5, %%ds\n\t"
26366 + "lcall *%%ss:(%%esi); cld\n\t"
26367 + "push %%ss\n\t"
26368 + "pop %%ds\n"
26369 "jc 1f\n\t"
26370 "xor %%ah, %%ah\n"
26371 "1:"
26372 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26373 : "0" (PCIBIOS_SET_PCI_HW_INT),
26374 "b" ((dev->bus->number << 8) | dev->devfn),
26375 "c" ((irq << 8) | (pin + 10)),
26376 - "S" (&pci_indirect));
26377 + "S" (&pci_indirect),
26378 + "r" (__PCIBIOS_DS));
26379 return !(ret & 0xff00);
26380 }
26381 EXPORT_SYMBOL(pcibios_set_irq_routing);
26382 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26383 index 40e4469..1ab536e 100644
26384 --- a/arch/x86/platform/efi/efi_32.c
26385 +++ b/arch/x86/platform/efi/efi_32.c
26386 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26387 {
26388 struct desc_ptr gdt_descr;
26389
26390 +#ifdef CONFIG_PAX_KERNEXEC
26391 + struct desc_struct d;
26392 +#endif
26393 +
26394 local_irq_save(efi_rt_eflags);
26395
26396 load_cr3(initial_page_table);
26397 __flush_tlb_all();
26398
26399 +#ifdef CONFIG_PAX_KERNEXEC
26400 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26401 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26402 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26403 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26404 +#endif
26405 +
26406 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26407 gdt_descr.size = GDT_SIZE - 1;
26408 load_gdt(&gdt_descr);
26409 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26410 {
26411 struct desc_ptr gdt_descr;
26412
26413 +#ifdef CONFIG_PAX_KERNEXEC
26414 + struct desc_struct d;
26415 +
26416 + memset(&d, 0, sizeof d);
26417 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26418 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26419 +#endif
26420 +
26421 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26422 gdt_descr.size = GDT_SIZE - 1;
26423 load_gdt(&gdt_descr);
26424 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26425 index fbe66e6..c5c0dd2 100644
26426 --- a/arch/x86/platform/efi/efi_stub_32.S
26427 +++ b/arch/x86/platform/efi/efi_stub_32.S
26428 @@ -6,7 +6,9 @@
26429 */
26430
26431 #include <linux/linkage.h>
26432 +#include <linux/init.h>
26433 #include <asm/page_types.h>
26434 +#include <asm/segment.h>
26435
26436 /*
26437 * efi_call_phys(void *, ...) is a function with variable parameters.
26438 @@ -20,7 +22,7 @@
26439 * service functions will comply with gcc calling convention, too.
26440 */
26441
26442 -.text
26443 +__INIT
26444 ENTRY(efi_call_phys)
26445 /*
26446 * 0. The function can only be called in Linux kernel. So CS has been
26447 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
26448 * The mapping of lower virtual memory has been created in prelog and
26449 * epilog.
26450 */
26451 - movl $1f, %edx
26452 - subl $__PAGE_OFFSET, %edx
26453 - jmp *%edx
26454 + movl $(__KERNEXEC_EFI_DS), %edx
26455 + mov %edx, %ds
26456 + mov %edx, %es
26457 + mov %edx, %ss
26458 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
26459 1:
26460
26461 /*
26462 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
26463 * parameter 2, ..., param n. To make things easy, we save the return
26464 * address of efi_call_phys in a global variable.
26465 */
26466 - popl %edx
26467 - movl %edx, saved_return_addr
26468 - /* get the function pointer into ECX*/
26469 - popl %ecx
26470 - movl %ecx, efi_rt_function_ptr
26471 - movl $2f, %edx
26472 - subl $__PAGE_OFFSET, %edx
26473 - pushl %edx
26474 + popl (saved_return_addr)
26475 + popl (efi_rt_function_ptr)
26476
26477 /*
26478 * 3. Clear PG bit in %CR0.
26479 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
26480 /*
26481 * 5. Call the physical function.
26482 */
26483 - jmp *%ecx
26484 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26485
26486 -2:
26487 /*
26488 * 6. After EFI runtime service returns, control will return to
26489 * following instruction. We'd better readjust stack pointer first.
26490 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
26491 movl %cr0, %edx
26492 orl $0x80000000, %edx
26493 movl %edx, %cr0
26494 - jmp 1f
26495 -1:
26496 +
26497 /*
26498 * 8. Now restore the virtual mode from flat mode by
26499 * adding EIP with PAGE_OFFSET.
26500 */
26501 - movl $1f, %edx
26502 - jmp *%edx
26503 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
26504 1:
26505 + movl $(__KERNEL_DS), %edx
26506 + mov %edx, %ds
26507 + mov %edx, %es
26508 + mov %edx, %ss
26509
26510 /*
26511 * 9. Balance the stack. And because EAX contain the return value,
26512 * we'd better not clobber it.
26513 */
26514 - leal efi_rt_function_ptr, %edx
26515 - movl (%edx), %ecx
26516 - pushl %ecx
26517 + pushl (efi_rt_function_ptr)
26518
26519 /*
26520 - * 10. Push the saved return address onto the stack and return.
26521 + * 10. Return to the saved return address.
26522 */
26523 - leal saved_return_addr, %edx
26524 - movl (%edx), %ecx
26525 - pushl %ecx
26526 - ret
26527 + jmpl *(saved_return_addr)
26528 ENDPROC(efi_call_phys)
26529 .previous
26530
26531 -.data
26532 +__INITDATA
26533 saved_return_addr:
26534 .long 0
26535 efi_rt_function_ptr:
26536 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26537 index 4c07cca..2c8427d 100644
26538 --- a/arch/x86/platform/efi/efi_stub_64.S
26539 +++ b/arch/x86/platform/efi/efi_stub_64.S
26540 @@ -7,6 +7,7 @@
26541 */
26542
26543 #include <linux/linkage.h>
26544 +#include <asm/alternative-asm.h>
26545
26546 #define SAVE_XMM \
26547 mov %rsp, %rax; \
26548 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26549 call *%rdi
26550 addq $32, %rsp
26551 RESTORE_XMM
26552 + pax_force_retaddr 0, 1
26553 ret
26554 ENDPROC(efi_call0)
26555
26556 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26557 call *%rdi
26558 addq $32, %rsp
26559 RESTORE_XMM
26560 + pax_force_retaddr 0, 1
26561 ret
26562 ENDPROC(efi_call1)
26563
26564 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26565 call *%rdi
26566 addq $32, %rsp
26567 RESTORE_XMM
26568 + pax_force_retaddr 0, 1
26569 ret
26570 ENDPROC(efi_call2)
26571
26572 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26573 call *%rdi
26574 addq $32, %rsp
26575 RESTORE_XMM
26576 + pax_force_retaddr 0, 1
26577 ret
26578 ENDPROC(efi_call3)
26579
26580 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26581 call *%rdi
26582 addq $32, %rsp
26583 RESTORE_XMM
26584 + pax_force_retaddr 0, 1
26585 ret
26586 ENDPROC(efi_call4)
26587
26588 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26589 call *%rdi
26590 addq $48, %rsp
26591 RESTORE_XMM
26592 + pax_force_retaddr 0, 1
26593 ret
26594 ENDPROC(efi_call5)
26595
26596 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26597 call *%rdi
26598 addq $48, %rsp
26599 RESTORE_XMM
26600 + pax_force_retaddr 0, 1
26601 ret
26602 ENDPROC(efi_call6)
26603 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26604 index 475e2cd..1b8e708 100644
26605 --- a/arch/x86/platform/mrst/mrst.c
26606 +++ b/arch/x86/platform/mrst/mrst.c
26607 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26608 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26609 int sfi_mrtc_num;
26610
26611 -static void mrst_power_off(void)
26612 +static __noreturn void mrst_power_off(void)
26613 {
26614 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26615 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
26616 + BUG();
26617 }
26618
26619 -static void mrst_reboot(void)
26620 +static __noreturn void mrst_reboot(void)
26621 {
26622 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
26623 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
26624 else
26625 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26626 + BUG();
26627 }
26628
26629 /* parse all the mtimer info to a static mtimer array */
26630 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26631 index f10c0af..3ec1f95 100644
26632 --- a/arch/x86/power/cpu.c
26633 +++ b/arch/x86/power/cpu.c
26634 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
26635 static void fix_processor_context(void)
26636 {
26637 int cpu = smp_processor_id();
26638 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26639 + struct tss_struct *t = init_tss + cpu;
26640
26641 set_tss_desc(cpu, t); /*
26642 * This just modifies memory; should not be
26643 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
26644 */
26645
26646 #ifdef CONFIG_X86_64
26647 + pax_open_kernel();
26648 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26649 + pax_close_kernel();
26650
26651 syscall_init(); /* This sets MSR_*STAR and related */
26652 #endif
26653 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26654 index b685296..5cdc8ad 100644
26655 --- a/arch/x86/tools/relocs.c
26656 +++ b/arch/x86/tools/relocs.c
26657 @@ -14,8 +14,16 @@
26658
26659 static void die(char *fmt, ...);
26660
26661 +#include "../../../include/generated/autoconf.h"
26662 +#ifdef CONFIG_X86_32
26663 +#define __PAGE_OFFSET CONFIG_PAGE_OFFSET
26664 +#else
26665 +#define __PAGE_OFFSET 0
26666 +#endif
26667 +
26668 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26669 static Elf32_Ehdr ehdr;
26670 +static Elf32_Phdr *phdr;
26671 static unsigned long reloc_count, reloc_idx;
26672 static unsigned long *relocs;
26673 static unsigned long reloc16_count, reloc16_idx;
26674 @@ -323,9 +331,39 @@ static void read_ehdr(FILE *fp)
26675 }
26676 }
26677
26678 +static void read_phdrs(FILE *fp)
26679 +{
26680 + unsigned int i;
26681 +
26682 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26683 + if (!phdr) {
26684 + die("Unable to allocate %d program headers\n",
26685 + ehdr.e_phnum);
26686 + }
26687 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26688 + die("Seek to %d failed: %s\n",
26689 + ehdr.e_phoff, strerror(errno));
26690 + }
26691 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26692 + die("Cannot read ELF program headers: %s\n",
26693 + strerror(errno));
26694 + }
26695 + for(i = 0; i < ehdr.e_phnum; i++) {
26696 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26697 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26698 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26699 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26700 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26701 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26702 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26703 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26704 + }
26705 +
26706 +}
26707 +
26708 static void read_shdrs(FILE *fp)
26709 {
26710 - int i;
26711 + unsigned int i;
26712 Elf32_Shdr shdr;
26713
26714 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26715 @@ -360,7 +398,7 @@ static void read_shdrs(FILE *fp)
26716
26717 static void read_strtabs(FILE *fp)
26718 {
26719 - int i;
26720 + unsigned int i;
26721 for (i = 0; i < ehdr.e_shnum; i++) {
26722 struct section *sec = &secs[i];
26723 if (sec->shdr.sh_type != SHT_STRTAB) {
26724 @@ -385,7 +423,7 @@ static void read_strtabs(FILE *fp)
26725
26726 static void read_symtabs(FILE *fp)
26727 {
26728 - int i,j;
26729 + unsigned int i,j;
26730 for (i = 0; i < ehdr.e_shnum; i++) {
26731 struct section *sec = &secs[i];
26732 if (sec->shdr.sh_type != SHT_SYMTAB) {
26733 @@ -418,7 +456,9 @@ static void read_symtabs(FILE *fp)
26734
26735 static void read_relocs(FILE *fp)
26736 {
26737 - int i,j;
26738 + unsigned int i,j;
26739 + uint32_t base;
26740 +
26741 for (i = 0; i < ehdr.e_shnum; i++) {
26742 struct section *sec = &secs[i];
26743 if (sec->shdr.sh_type != SHT_REL) {
26744 @@ -438,9 +478,18 @@ static void read_relocs(FILE *fp)
26745 die("Cannot read symbol table: %s\n",
26746 strerror(errno));
26747 }
26748 + base = 0;
26749 + for (j = 0; j < ehdr.e_phnum; j++) {
26750 + if (phdr[j].p_type != PT_LOAD )
26751 + continue;
26752 + 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)
26753 + continue;
26754 + base = __PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26755 + break;
26756 + }
26757 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26758 Elf32_Rel *rel = &sec->reltab[j];
26759 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26760 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26761 rel->r_info = elf32_to_cpu(rel->r_info);
26762 }
26763 }
26764 @@ -449,13 +498,13 @@ static void read_relocs(FILE *fp)
26765
26766 static void print_absolute_symbols(void)
26767 {
26768 - int i;
26769 + unsigned int i;
26770 printf("Absolute symbols\n");
26771 printf(" Num: Value Size Type Bind Visibility Name\n");
26772 for (i = 0; i < ehdr.e_shnum; i++) {
26773 struct section *sec = &secs[i];
26774 char *sym_strtab;
26775 - int j;
26776 + unsigned int j;
26777
26778 if (sec->shdr.sh_type != SHT_SYMTAB) {
26779 continue;
26780 @@ -482,14 +531,14 @@ static void print_absolute_symbols(void)
26781
26782 static void print_absolute_relocs(void)
26783 {
26784 - int i, printed = 0;
26785 + unsigned int i, printed = 0;
26786
26787 for (i = 0; i < ehdr.e_shnum; i++) {
26788 struct section *sec = &secs[i];
26789 struct section *sec_applies, *sec_symtab;
26790 char *sym_strtab;
26791 Elf32_Sym *sh_symtab;
26792 - int j;
26793 + unsigned int j;
26794 if (sec->shdr.sh_type != SHT_REL) {
26795 continue;
26796 }
26797 @@ -551,13 +600,13 @@ static void print_absolute_relocs(void)
26798 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26799 int use_real_mode)
26800 {
26801 - int i;
26802 + unsigned int i;
26803 /* Walk through the relocations */
26804 for (i = 0; i < ehdr.e_shnum; i++) {
26805 char *sym_strtab;
26806 Elf32_Sym *sh_symtab;
26807 struct section *sec_applies, *sec_symtab;
26808 - int j;
26809 + unsigned int j;
26810 struct section *sec = &secs[i];
26811
26812 if (sec->shdr.sh_type != SHT_REL) {
26813 @@ -583,6 +632,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26814
26815 shn_abs = sym->st_shndx == SHN_ABS;
26816
26817 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
26818 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
26819 + continue;
26820 +
26821 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
26822 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
26823 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
26824 + continue;
26825 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
26826 + continue;
26827 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
26828 + continue;
26829 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
26830 + continue;
26831 +#endif
26832 +
26833 switch (r_type) {
26834 case R_386_NONE:
26835 case R_386_PC32:
26836 @@ -674,7 +739,7 @@ static int write32(unsigned int v, FILE *f)
26837
26838 static void emit_relocs(int as_text, int use_real_mode)
26839 {
26840 - int i;
26841 + unsigned int i;
26842 /* Count how many relocations I have and allocate space for them. */
26843 reloc_count = 0;
26844 walk_relocs(count_reloc, use_real_mode);
26845 @@ -801,6 +866,7 @@ int main(int argc, char **argv)
26846 fname, strerror(errno));
26847 }
26848 read_ehdr(fp);
26849 + read_phdrs(fp);
26850 read_shdrs(fp);
26851 read_strtabs(fp);
26852 read_symtabs(fp);
26853 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
26854 index 5d17950..2253fc9 100644
26855 --- a/arch/x86/vdso/Makefile
26856 +++ b/arch/x86/vdso/Makefile
26857 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
26858 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
26859 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
26860
26861 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26862 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
26863 GCOV_PROFILE := n
26864
26865 #
26866 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
26867 index 468d591..8e80a0a 100644
26868 --- a/arch/x86/vdso/vdso32-setup.c
26869 +++ b/arch/x86/vdso/vdso32-setup.c
26870 @@ -25,6 +25,7 @@
26871 #include <asm/tlbflush.h>
26872 #include <asm/vdso.h>
26873 #include <asm/proto.h>
26874 +#include <asm/mman.h>
26875
26876 enum {
26877 VDSO_DISABLED = 0,
26878 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
26879 void enable_sep_cpu(void)
26880 {
26881 int cpu = get_cpu();
26882 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26883 + struct tss_struct *tss = init_tss + cpu;
26884
26885 if (!boot_cpu_has(X86_FEATURE_SEP)) {
26886 put_cpu();
26887 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
26888 gate_vma.vm_start = FIXADDR_USER_START;
26889 gate_vma.vm_end = FIXADDR_USER_END;
26890 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
26891 - gate_vma.vm_page_prot = __P101;
26892 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
26893 /*
26894 * Make sure the vDSO gets into every core dump.
26895 * Dumping its contents makes post-mortem fully interpretable later
26896 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26897 if (compat)
26898 addr = VDSO_HIGH_BASE;
26899 else {
26900 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
26901 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
26902 if (IS_ERR_VALUE(addr)) {
26903 ret = addr;
26904 goto up_fail;
26905 }
26906 }
26907
26908 - current->mm->context.vdso = (void *)addr;
26909 + current->mm->context.vdso = addr;
26910
26911 if (compat_uses_vma || !compat) {
26912 /*
26913 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26914 }
26915
26916 current_thread_info()->sysenter_return =
26917 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26918 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
26919
26920 up_fail:
26921 if (ret)
26922 - current->mm->context.vdso = NULL;
26923 + current->mm->context.vdso = 0;
26924
26925 up_write(&mm->mmap_sem);
26926
26927 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
26928
26929 const char *arch_vma_name(struct vm_area_struct *vma)
26930 {
26931 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26932 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26933 return "[vdso]";
26934 +
26935 +#ifdef CONFIG_PAX_SEGMEXEC
26936 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
26937 + return "[vdso]";
26938 +#endif
26939 +
26940 return NULL;
26941 }
26942
26943 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26944 * Check to see if the corresponding task was created in compat vdso
26945 * mode.
26946 */
26947 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
26948 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
26949 return &gate_vma;
26950 return NULL;
26951 }
26952 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
26953 index 153407c..611cba9 100644
26954 --- a/arch/x86/vdso/vma.c
26955 +++ b/arch/x86/vdso/vma.c
26956 @@ -16,8 +16,6 @@
26957 #include <asm/vdso.h>
26958 #include <asm/page.h>
26959
26960 -unsigned int __read_mostly vdso_enabled = 1;
26961 -
26962 extern char vdso_start[], vdso_end[];
26963 extern unsigned short vdso_sync_cpuid;
26964
26965 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26966 * unaligned here as a result of stack start randomization.
26967 */
26968 addr = PAGE_ALIGN(addr);
26969 - addr = align_addr(addr, NULL, ALIGN_VDSO);
26970
26971 return addr;
26972 }
26973 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
26974 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
26975 {
26976 struct mm_struct *mm = current->mm;
26977 - unsigned long addr;
26978 + unsigned long addr = 0;
26979 int ret;
26980
26981 - if (!vdso_enabled)
26982 - return 0;
26983 -
26984 down_write(&mm->mmap_sem);
26985 +
26986 +#ifdef CONFIG_PAX_RANDMMAP
26987 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26988 +#endif
26989 +
26990 addr = vdso_addr(mm->start_stack, vdso_size);
26991 + addr = align_addr(addr, NULL, ALIGN_VDSO);
26992 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
26993 if (IS_ERR_VALUE(addr)) {
26994 ret = addr;
26995 goto up_fail;
26996 }
26997
26998 - current->mm->context.vdso = (void *)addr;
26999 + mm->context.vdso = addr;
27000
27001 ret = install_special_mapping(mm, addr, vdso_size,
27002 VM_READ|VM_EXEC|
27003 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
27004 VM_ALWAYSDUMP,
27005 vdso_pages);
27006 - if (ret) {
27007 - current->mm->context.vdso = NULL;
27008 - goto up_fail;
27009 - }
27010 +
27011 + if (ret)
27012 + mm->context.vdso = 0;
27013
27014 up_fail:
27015 up_write(&mm->mmap_sem);
27016 return ret;
27017 }
27018 -
27019 -static __init int vdso_setup(char *s)
27020 -{
27021 - vdso_enabled = simple_strtoul(s, NULL, 0);
27022 - return 0;
27023 -}
27024 -__setup("vdso=", vdso_setup);
27025 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27026 index 4e517d4..8426127 100644
27027 --- a/arch/x86/xen/enlighten.c
27028 +++ b/arch/x86/xen/enlighten.c
27029 @@ -86,8 +86,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27030
27031 struct shared_info xen_dummy_shared_info;
27032
27033 -void *xen_initial_gdt;
27034 -
27035 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27036 __read_mostly int xen_have_vector_callback;
27037 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27038 @@ -982,7 +980,10 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
27039 .wbinvd = native_wbinvd,
27040
27041 .read_msr = native_read_msr_safe,
27042 + .rdmsr_regs = native_rdmsr_safe_regs,
27043 .write_msr = xen_write_msr_safe,
27044 + .wrmsr_regs = native_wrmsr_safe_regs,
27045 +
27046 .read_tsc = native_read_tsc,
27047 .read_pmc = native_read_pmc,
27048
27049 @@ -1030,30 +1031,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27050 #endif
27051 };
27052
27053 -static void xen_reboot(int reason)
27054 +static __noreturn void xen_reboot(int reason)
27055 {
27056 struct sched_shutdown r = { .reason = reason };
27057
27058 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27059 - BUG();
27060 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27061 + BUG();
27062 }
27063
27064 -static void xen_restart(char *msg)
27065 +static __noreturn void xen_restart(char *msg)
27066 {
27067 xen_reboot(SHUTDOWN_reboot);
27068 }
27069
27070 -static void xen_emergency_restart(void)
27071 +static __noreturn void xen_emergency_restart(void)
27072 {
27073 xen_reboot(SHUTDOWN_reboot);
27074 }
27075
27076 -static void xen_machine_halt(void)
27077 +static __noreturn void xen_machine_halt(void)
27078 {
27079 xen_reboot(SHUTDOWN_poweroff);
27080 }
27081
27082 -static void xen_machine_power_off(void)
27083 +static __noreturn void xen_machine_power_off(void)
27084 {
27085 if (pm_power_off)
27086 pm_power_off();
27087 @@ -1156,7 +1157,17 @@ asmlinkage void __init xen_start_kernel(void)
27088 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27089
27090 /* Work out if we support NX */
27091 - x86_configure_nx();
27092 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27093 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27094 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27095 + unsigned l, h;
27096 +
27097 + __supported_pte_mask |= _PAGE_NX;
27098 + rdmsr(MSR_EFER, l, h);
27099 + l |= EFER_NX;
27100 + wrmsr(MSR_EFER, l, h);
27101 + }
27102 +#endif
27103
27104 xen_setup_features();
27105
27106 @@ -1187,13 +1198,6 @@ asmlinkage void __init xen_start_kernel(void)
27107
27108 machine_ops = xen_machine_ops;
27109
27110 - /*
27111 - * The only reliable way to retain the initial address of the
27112 - * percpu gdt_page is to remember it here, so we can go and
27113 - * mark it RW later, when the initial percpu area is freed.
27114 - */
27115 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27116 -
27117 xen_smp_init();
27118
27119 #ifdef CONFIG_ACPI_NUMA
27120 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27121 index dc19347..1b07a2c 100644
27122 --- a/arch/x86/xen/mmu.c
27123 +++ b/arch/x86/xen/mmu.c
27124 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27125 convert_pfn_mfn(init_level4_pgt);
27126 convert_pfn_mfn(level3_ident_pgt);
27127 convert_pfn_mfn(level3_kernel_pgt);
27128 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27129 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27130 + convert_pfn_mfn(level3_vmemmap_pgt);
27131
27132 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27133 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27134 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27135 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27136 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27137 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27138 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27139 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27140 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27141 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27142 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27143 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27144 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27145
27146 @@ -1963,6 +1970,7 @@ static void __init xen_post_allocator_init(void)
27147 pv_mmu_ops.set_pud = xen_set_pud;
27148 #if PAGETABLE_LEVELS == 4
27149 pv_mmu_ops.set_pgd = xen_set_pgd;
27150 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27151 #endif
27152
27153 /* This will work as long as patching hasn't happened yet
27154 @@ -2044,6 +2052,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27155 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27156 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27157 .set_pgd = xen_set_pgd_hyper,
27158 + .set_pgd_batched = xen_set_pgd_hyper,
27159
27160 .alloc_pud = xen_alloc_pmd_init,
27161 .release_pud = xen_release_pmd_init,
27162 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27163 index f2ce60a..14e08dc 100644
27164 --- a/arch/x86/xen/smp.c
27165 +++ b/arch/x86/xen/smp.c
27166 @@ -209,11 +209,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27167 {
27168 BUG_ON(smp_processor_id() != 0);
27169 native_smp_prepare_boot_cpu();
27170 -
27171 - /* We've switched to the "real" per-cpu gdt, so make sure the
27172 - old memory can be recycled */
27173 - make_lowmem_page_readwrite(xen_initial_gdt);
27174 -
27175 xen_filter_cpu_maps();
27176 xen_setup_vcpu_info_placement();
27177 }
27178 @@ -290,12 +285,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27179 gdt = get_cpu_gdt_table(cpu);
27180
27181 ctxt->flags = VGCF_IN_KERNEL;
27182 - ctxt->user_regs.ds = __USER_DS;
27183 - ctxt->user_regs.es = __USER_DS;
27184 + ctxt->user_regs.ds = __KERNEL_DS;
27185 + ctxt->user_regs.es = __KERNEL_DS;
27186 ctxt->user_regs.ss = __KERNEL_DS;
27187 #ifdef CONFIG_X86_32
27188 ctxt->user_regs.fs = __KERNEL_PERCPU;
27189 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27190 + savesegment(gs, ctxt->user_regs.gs);
27191 #else
27192 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27193 #endif
27194 @@ -346,13 +341,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
27195 int rc;
27196
27197 per_cpu(current_task, cpu) = idle;
27198 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27199 #ifdef CONFIG_X86_32
27200 irq_ctx_init(cpu);
27201 #else
27202 clear_tsk_thread_flag(idle, TIF_FORK);
27203 - per_cpu(kernel_stack, cpu) =
27204 - (unsigned long)task_stack_page(idle) -
27205 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27206 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27207 #endif
27208 xen_setup_runstate_info(cpu);
27209 xen_setup_timer(cpu);
27210 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27211 index b040b0e..8cc4fe0 100644
27212 --- a/arch/x86/xen/xen-asm_32.S
27213 +++ b/arch/x86/xen/xen-asm_32.S
27214 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
27215 ESP_OFFSET=4 # bytes pushed onto stack
27216
27217 /*
27218 - * Store vcpu_info pointer for easy access. Do it this way to
27219 - * avoid having to reload %fs
27220 + * Store vcpu_info pointer for easy access.
27221 */
27222 #ifdef CONFIG_SMP
27223 - GET_THREAD_INFO(%eax)
27224 - movl TI_cpu(%eax), %eax
27225 - movl __per_cpu_offset(,%eax,4), %eax
27226 - mov xen_vcpu(%eax), %eax
27227 + push %fs
27228 + mov $(__KERNEL_PERCPU), %eax
27229 + mov %eax, %fs
27230 + mov PER_CPU_VAR(xen_vcpu), %eax
27231 + pop %fs
27232 #else
27233 movl xen_vcpu, %eax
27234 #endif
27235 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27236 index aaa7291..3f77960 100644
27237 --- a/arch/x86/xen/xen-head.S
27238 +++ b/arch/x86/xen/xen-head.S
27239 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27240 #ifdef CONFIG_X86_32
27241 mov %esi,xen_start_info
27242 mov $init_thread_union+THREAD_SIZE,%esp
27243 +#ifdef CONFIG_SMP
27244 + movl $cpu_gdt_table,%edi
27245 + movl $__per_cpu_load,%eax
27246 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27247 + rorl $16,%eax
27248 + movb %al,__KERNEL_PERCPU + 4(%edi)
27249 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27250 + movl $__per_cpu_end - 1,%eax
27251 + subl $__per_cpu_start,%eax
27252 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27253 +#endif
27254 #else
27255 mov %rsi,xen_start_info
27256 mov $init_thread_union+THREAD_SIZE,%rsp
27257 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27258 index b095739..8c17bcd 100644
27259 --- a/arch/x86/xen/xen-ops.h
27260 +++ b/arch/x86/xen/xen-ops.h
27261 @@ -10,8 +10,6 @@
27262 extern const char xen_hypervisor_callback[];
27263 extern const char xen_failsafe_callback[];
27264
27265 -extern void *xen_initial_gdt;
27266 -
27267 struct trap_info;
27268 void xen_copy_trap_info(struct trap_info *traps);
27269
27270 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27271 index 525bd3d..ef888b1 100644
27272 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27273 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27274 @@ -119,9 +119,9 @@
27275 ----------------------------------------------------------------------*/
27276
27277 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27278 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27279 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27280 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27281 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27282
27283 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27284 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27285 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27286 index 2f33760..835e50a 100644
27287 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27288 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27289 @@ -11,6 +11,7 @@
27290 #ifndef _XTENSA_CORE_H
27291 #define _XTENSA_CORE_H
27292
27293 +#include <linux/const.h>
27294
27295 /****************************************************************************
27296 Parameters Useful for Any Code, USER or PRIVILEGED
27297 @@ -112,9 +113,9 @@
27298 ----------------------------------------------------------------------*/
27299
27300 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27301 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27302 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27303 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27304 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27305
27306 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27307 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27308 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27309 index af00795..2bb8105 100644
27310 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27311 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27312 @@ -11,6 +11,7 @@
27313 #ifndef _XTENSA_CORE_CONFIGURATION_H
27314 #define _XTENSA_CORE_CONFIGURATION_H
27315
27316 +#include <linux/const.h>
27317
27318 /****************************************************************************
27319 Parameters Useful for Any Code, USER or PRIVILEGED
27320 @@ -118,9 +119,9 @@
27321 ----------------------------------------------------------------------*/
27322
27323 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27324 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27325 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27326 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27327 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27328
27329 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27330 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27331 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27332 index 58916af..9cb880b 100644
27333 --- a/block/blk-iopoll.c
27334 +++ b/block/blk-iopoll.c
27335 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27336 }
27337 EXPORT_SYMBOL(blk_iopoll_complete);
27338
27339 -static void blk_iopoll_softirq(struct softirq_action *h)
27340 +static void blk_iopoll_softirq(void)
27341 {
27342 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27343 int rearm = 0, budget = blk_iopoll_budget;
27344 diff --git a/block/blk-map.c b/block/blk-map.c
27345 index 623e1cd..ca1e109 100644
27346 --- a/block/blk-map.c
27347 +++ b/block/blk-map.c
27348 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27349 if (!len || !kbuf)
27350 return -EINVAL;
27351
27352 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27353 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27354 if (do_copy)
27355 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27356 else
27357 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27358 index 1366a89..e17f54b 100644
27359 --- a/block/blk-softirq.c
27360 +++ b/block/blk-softirq.c
27361 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27362 * Softirq action handler - move entries to local list and loop over them
27363 * while passing them to the queue registered handler.
27364 */
27365 -static void blk_done_softirq(struct softirq_action *h)
27366 +static void blk_done_softirq(void)
27367 {
27368 struct list_head *cpu_list, local_list;
27369
27370 diff --git a/block/bsg.c b/block/bsg.c
27371 index ff64ae3..593560c 100644
27372 --- a/block/bsg.c
27373 +++ b/block/bsg.c
27374 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27375 struct sg_io_v4 *hdr, struct bsg_device *bd,
27376 fmode_t has_write_perm)
27377 {
27378 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27379 + unsigned char *cmdptr;
27380 +
27381 if (hdr->request_len > BLK_MAX_CDB) {
27382 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27383 if (!rq->cmd)
27384 return -ENOMEM;
27385 - }
27386 + cmdptr = rq->cmd;
27387 + } else
27388 + cmdptr = tmpcmd;
27389
27390 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27391 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27392 hdr->request_len))
27393 return -EFAULT;
27394
27395 + if (cmdptr != rq->cmd)
27396 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27397 +
27398 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27399 if (blk_verify_command(rq->cmd, has_write_perm))
27400 return -EPERM;
27401 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27402 index 7c668c8..db3521c 100644
27403 --- a/block/compat_ioctl.c
27404 +++ b/block/compat_ioctl.c
27405 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27406 err |= __get_user(f->spec1, &uf->spec1);
27407 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27408 err |= __get_user(name, &uf->name);
27409 - f->name = compat_ptr(name);
27410 + f->name = (void __force_kernel *)compat_ptr(name);
27411 if (err) {
27412 err = -EFAULT;
27413 goto out;
27414 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27415 index 6296b40..417c00f 100644
27416 --- a/block/partitions/efi.c
27417 +++ b/block/partitions/efi.c
27418 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27419 if (!gpt)
27420 return NULL;
27421
27422 + if (!le32_to_cpu(gpt->num_partition_entries))
27423 + return NULL;
27424 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27425 + if (!pte)
27426 + return NULL;
27427 +
27428 count = le32_to_cpu(gpt->num_partition_entries) *
27429 le32_to_cpu(gpt->sizeof_partition_entry);
27430 - if (!count)
27431 - return NULL;
27432 - pte = kzalloc(count, GFP_KERNEL);
27433 - if (!pte)
27434 - return NULL;
27435 -
27436 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27437 (u8 *) pte,
27438 count) < count) {
27439 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27440 index 260fa80..e8f3caf 100644
27441 --- a/block/scsi_ioctl.c
27442 +++ b/block/scsi_ioctl.c
27443 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27444 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27445 struct sg_io_hdr *hdr, fmode_t mode)
27446 {
27447 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27448 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27449 + unsigned char *cmdptr;
27450 +
27451 + if (rq->cmd != rq->__cmd)
27452 + cmdptr = rq->cmd;
27453 + else
27454 + cmdptr = tmpcmd;
27455 +
27456 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27457 return -EFAULT;
27458 +
27459 + if (cmdptr != rq->cmd)
27460 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27461 +
27462 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27463 return -EPERM;
27464
27465 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27466 int err;
27467 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27468 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27469 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27470 + unsigned char *cmdptr;
27471
27472 if (!sic)
27473 return -EINVAL;
27474 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27475 */
27476 err = -EFAULT;
27477 rq->cmd_len = cmdlen;
27478 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27479 +
27480 + if (rq->cmd != rq->__cmd)
27481 + cmdptr = rq->cmd;
27482 + else
27483 + cmdptr = tmpcmd;
27484 +
27485 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27486 goto error;
27487
27488 + if (rq->cmd != cmdptr)
27489 + memcpy(rq->cmd, cmdptr, cmdlen);
27490 +
27491 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27492 goto error;
27493
27494 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27495 index 671d4d6..5f24030 100644
27496 --- a/crypto/cryptd.c
27497 +++ b/crypto/cryptd.c
27498 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27499
27500 struct cryptd_blkcipher_request_ctx {
27501 crypto_completion_t complete;
27502 -};
27503 +} __no_const;
27504
27505 struct cryptd_hash_ctx {
27506 struct crypto_shash *child;
27507 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27508
27509 struct cryptd_aead_request_ctx {
27510 crypto_completion_t complete;
27511 -};
27512 +} __no_const;
27513
27514 static void cryptd_queue_worker(struct work_struct *work);
27515
27516 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27517 index 5d41894..22021e4 100644
27518 --- a/drivers/acpi/apei/cper.c
27519 +++ b/drivers/acpi/apei/cper.c
27520 @@ -38,12 +38,12 @@
27521 */
27522 u64 cper_next_record_id(void)
27523 {
27524 - static atomic64_t seq;
27525 + static atomic64_unchecked_t seq;
27526
27527 - if (!atomic64_read(&seq))
27528 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27529 + if (!atomic64_read_unchecked(&seq))
27530 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27531
27532 - return atomic64_inc_return(&seq);
27533 + return atomic64_inc_return_unchecked(&seq);
27534 }
27535 EXPORT_SYMBOL_GPL(cper_next_record_id);
27536
27537 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27538 index b258cab..3fb7da7 100644
27539 --- a/drivers/acpi/ec_sys.c
27540 +++ b/drivers/acpi/ec_sys.c
27541 @@ -12,6 +12,7 @@
27542 #include <linux/acpi.h>
27543 #include <linux/debugfs.h>
27544 #include <linux/module.h>
27545 +#include <linux/uaccess.h>
27546 #include "internal.h"
27547
27548 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27549 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27550 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27551 */
27552 unsigned int size = EC_SPACE_SIZE;
27553 - u8 *data = (u8 *) buf;
27554 + u8 data;
27555 loff_t init_off = *off;
27556 int err = 0;
27557
27558 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27559 size = count;
27560
27561 while (size) {
27562 - err = ec_read(*off, &data[*off - init_off]);
27563 + err = ec_read(*off, &data);
27564 if (err)
27565 return err;
27566 + if (put_user(data, &buf[*off - init_off]))
27567 + return -EFAULT;
27568 *off += 1;
27569 size--;
27570 }
27571 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27572
27573 unsigned int size = count;
27574 loff_t init_off = *off;
27575 - u8 *data = (u8 *) buf;
27576 int err = 0;
27577
27578 if (*off >= EC_SPACE_SIZE)
27579 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27580 }
27581
27582 while (size) {
27583 - u8 byte_write = data[*off - init_off];
27584 + u8 byte_write;
27585 + if (get_user(byte_write, &buf[*off - init_off]))
27586 + return -EFAULT;
27587 err = ec_write(*off, byte_write);
27588 if (err)
27589 return err;
27590 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27591 index 251c7b62..000462d 100644
27592 --- a/drivers/acpi/proc.c
27593 +++ b/drivers/acpi/proc.c
27594 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27595 size_t count, loff_t * ppos)
27596 {
27597 struct list_head *node, *next;
27598 - char strbuf[5];
27599 - char str[5] = "";
27600 - unsigned int len = count;
27601 + char strbuf[5] = {0};
27602
27603 - if (len > 4)
27604 - len = 4;
27605 - if (len < 0)
27606 + if (count > 4)
27607 + count = 4;
27608 + if (copy_from_user(strbuf, buffer, count))
27609 return -EFAULT;
27610 -
27611 - if (copy_from_user(strbuf, buffer, len))
27612 - return -EFAULT;
27613 - strbuf[len] = '\0';
27614 - sscanf(strbuf, "%s", str);
27615 + strbuf[count] = '\0';
27616
27617 mutex_lock(&acpi_device_lock);
27618 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27619 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27620 if (!dev->wakeup.flags.valid)
27621 continue;
27622
27623 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27624 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27625 if (device_can_wakeup(&dev->dev)) {
27626 bool enable = !device_may_wakeup(&dev->dev);
27627 device_set_wakeup_enable(&dev->dev, enable);
27628 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27629 index 8ae05ce..7dbbed9 100644
27630 --- a/drivers/acpi/processor_driver.c
27631 +++ b/drivers/acpi/processor_driver.c
27632 @@ -555,7 +555,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27633 return 0;
27634 #endif
27635
27636 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27637 + BUG_ON(pr->id >= nr_cpu_ids);
27638
27639 /*
27640 * Buggy BIOS check
27641 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27642 index c06e0ec..a2c06ba 100644
27643 --- a/drivers/ata/libata-core.c
27644 +++ b/drivers/ata/libata-core.c
27645 @@ -4736,7 +4736,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27646 struct ata_port *ap;
27647 unsigned int tag;
27648
27649 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27650 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27651 ap = qc->ap;
27652
27653 qc->flags = 0;
27654 @@ -4752,7 +4752,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27655 struct ata_port *ap;
27656 struct ata_link *link;
27657
27658 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27659 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27660 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27661 ap = qc->ap;
27662 link = qc->dev->link;
27663 @@ -5816,6 +5816,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27664 return;
27665
27666 spin_lock(&lock);
27667 + pax_open_kernel();
27668
27669 for (cur = ops->inherits; cur; cur = cur->inherits) {
27670 void **inherit = (void **)cur;
27671 @@ -5829,8 +5830,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27672 if (IS_ERR(*pp))
27673 *pp = NULL;
27674
27675 - ops->inherits = NULL;
27676 + *(struct ata_port_operations **)&ops->inherits = NULL;
27677
27678 + pax_close_kernel();
27679 spin_unlock(&lock);
27680 }
27681
27682 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27683 index 048589f..4002b98 100644
27684 --- a/drivers/ata/pata_arasan_cf.c
27685 +++ b/drivers/ata/pata_arasan_cf.c
27686 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27687 /* Handle platform specific quirks */
27688 if (pdata->quirk) {
27689 if (pdata->quirk & CF_BROKEN_PIO) {
27690 - ap->ops->set_piomode = NULL;
27691 + pax_open_kernel();
27692 + *(void **)&ap->ops->set_piomode = NULL;
27693 + pax_close_kernel();
27694 ap->pio_mask = 0;
27695 }
27696 if (pdata->quirk & CF_BROKEN_MWDMA)
27697 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27698 index f9b983a..887b9d8 100644
27699 --- a/drivers/atm/adummy.c
27700 +++ b/drivers/atm/adummy.c
27701 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27702 vcc->pop(vcc, skb);
27703 else
27704 dev_kfree_skb_any(skb);
27705 - atomic_inc(&vcc->stats->tx);
27706 + atomic_inc_unchecked(&vcc->stats->tx);
27707
27708 return 0;
27709 }
27710 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27711 index f8f41e0..1f987dd 100644
27712 --- a/drivers/atm/ambassador.c
27713 +++ b/drivers/atm/ambassador.c
27714 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27715 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27716
27717 // VC layer stats
27718 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27719 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27720
27721 // free the descriptor
27722 kfree (tx_descr);
27723 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27724 dump_skb ("<<<", vc, skb);
27725
27726 // VC layer stats
27727 - atomic_inc(&atm_vcc->stats->rx);
27728 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27729 __net_timestamp(skb);
27730 // end of our responsibility
27731 atm_vcc->push (atm_vcc, skb);
27732 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27733 } else {
27734 PRINTK (KERN_INFO, "dropped over-size frame");
27735 // should we count this?
27736 - atomic_inc(&atm_vcc->stats->rx_drop);
27737 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27738 }
27739
27740 } else {
27741 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27742 }
27743
27744 if (check_area (skb->data, skb->len)) {
27745 - atomic_inc(&atm_vcc->stats->tx_err);
27746 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27747 return -ENOMEM; // ?
27748 }
27749
27750 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27751 index b22d71c..d6e1049 100644
27752 --- a/drivers/atm/atmtcp.c
27753 +++ b/drivers/atm/atmtcp.c
27754 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27755 if (vcc->pop) vcc->pop(vcc,skb);
27756 else dev_kfree_skb(skb);
27757 if (dev_data) return 0;
27758 - atomic_inc(&vcc->stats->tx_err);
27759 + atomic_inc_unchecked(&vcc->stats->tx_err);
27760 return -ENOLINK;
27761 }
27762 size = skb->len+sizeof(struct atmtcp_hdr);
27763 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27764 if (!new_skb) {
27765 if (vcc->pop) vcc->pop(vcc,skb);
27766 else dev_kfree_skb(skb);
27767 - atomic_inc(&vcc->stats->tx_err);
27768 + atomic_inc_unchecked(&vcc->stats->tx_err);
27769 return -ENOBUFS;
27770 }
27771 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27772 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27773 if (vcc->pop) vcc->pop(vcc,skb);
27774 else dev_kfree_skb(skb);
27775 out_vcc->push(out_vcc,new_skb);
27776 - atomic_inc(&vcc->stats->tx);
27777 - atomic_inc(&out_vcc->stats->rx);
27778 + atomic_inc_unchecked(&vcc->stats->tx);
27779 + atomic_inc_unchecked(&out_vcc->stats->rx);
27780 return 0;
27781 }
27782
27783 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27784 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
27785 read_unlock(&vcc_sklist_lock);
27786 if (!out_vcc) {
27787 - atomic_inc(&vcc->stats->tx_err);
27788 + atomic_inc_unchecked(&vcc->stats->tx_err);
27789 goto done;
27790 }
27791 skb_pull(skb,sizeof(struct atmtcp_hdr));
27792 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
27793 __net_timestamp(new_skb);
27794 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
27795 out_vcc->push(out_vcc,new_skb);
27796 - atomic_inc(&vcc->stats->tx);
27797 - atomic_inc(&out_vcc->stats->rx);
27798 + atomic_inc_unchecked(&vcc->stats->tx);
27799 + atomic_inc_unchecked(&out_vcc->stats->rx);
27800 done:
27801 if (vcc->pop) vcc->pop(vcc,skb);
27802 else dev_kfree_skb(skb);
27803 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
27804 index 956e9ac..133516d 100644
27805 --- a/drivers/atm/eni.c
27806 +++ b/drivers/atm/eni.c
27807 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
27808 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
27809 vcc->dev->number);
27810 length = 0;
27811 - atomic_inc(&vcc->stats->rx_err);
27812 + atomic_inc_unchecked(&vcc->stats->rx_err);
27813 }
27814 else {
27815 length = ATM_CELL_SIZE-1; /* no HEC */
27816 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27817 size);
27818 }
27819 eff = length = 0;
27820 - atomic_inc(&vcc->stats->rx_err);
27821 + atomic_inc_unchecked(&vcc->stats->rx_err);
27822 }
27823 else {
27824 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
27825 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
27826 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
27827 vcc->dev->number,vcc->vci,length,size << 2,descr);
27828 length = eff = 0;
27829 - atomic_inc(&vcc->stats->rx_err);
27830 + atomic_inc_unchecked(&vcc->stats->rx_err);
27831 }
27832 }
27833 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
27834 @@ -771,7 +771,7 @@ rx_dequeued++;
27835 vcc->push(vcc,skb);
27836 pushed++;
27837 }
27838 - atomic_inc(&vcc->stats->rx);
27839 + atomic_inc_unchecked(&vcc->stats->rx);
27840 }
27841 wake_up(&eni_dev->rx_wait);
27842 }
27843 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
27844 PCI_DMA_TODEVICE);
27845 if (vcc->pop) vcc->pop(vcc,skb);
27846 else dev_kfree_skb_irq(skb);
27847 - atomic_inc(&vcc->stats->tx);
27848 + atomic_inc_unchecked(&vcc->stats->tx);
27849 wake_up(&eni_dev->tx_wait);
27850 dma_complete++;
27851 }
27852 @@ -1569,7 +1569,7 @@ tx_complete++;
27853 /*--------------------------------- entries ---------------------------------*/
27854
27855
27856 -static const char *media_name[] __devinitdata = {
27857 +static const char *media_name[] __devinitconst = {
27858 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
27859 "UTP", "05?", "06?", "07?", /* 4- 7 */
27860 "TAXI","09?", "10?", "11?", /* 8-11 */
27861 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
27862 index 5072f8a..fa52520d 100644
27863 --- a/drivers/atm/firestream.c
27864 +++ b/drivers/atm/firestream.c
27865 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
27866 }
27867 }
27868
27869 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27870 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27871
27872 fs_dprintk (FS_DEBUG_TXMEM, "i");
27873 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
27874 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27875 #endif
27876 skb_put (skb, qe->p1 & 0xffff);
27877 ATM_SKB(skb)->vcc = atm_vcc;
27878 - atomic_inc(&atm_vcc->stats->rx);
27879 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27880 __net_timestamp(skb);
27881 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
27882 atm_vcc->push (atm_vcc, skb);
27883 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
27884 kfree (pe);
27885 }
27886 if (atm_vcc)
27887 - atomic_inc(&atm_vcc->stats->rx_drop);
27888 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27889 break;
27890 case 0x1f: /* Reassembly abort: no buffers. */
27891 /* Silently increment error counter. */
27892 if (atm_vcc)
27893 - atomic_inc(&atm_vcc->stats->rx_drop);
27894 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27895 break;
27896 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
27897 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
27898 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
27899 index 361f5ae..7fc552d 100644
27900 --- a/drivers/atm/fore200e.c
27901 +++ b/drivers/atm/fore200e.c
27902 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
27903 #endif
27904 /* check error condition */
27905 if (*entry->status & STATUS_ERROR)
27906 - atomic_inc(&vcc->stats->tx_err);
27907 + atomic_inc_unchecked(&vcc->stats->tx_err);
27908 else
27909 - atomic_inc(&vcc->stats->tx);
27910 + atomic_inc_unchecked(&vcc->stats->tx);
27911 }
27912 }
27913
27914 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27915 if (skb == NULL) {
27916 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
27917
27918 - atomic_inc(&vcc->stats->rx_drop);
27919 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27920 return -ENOMEM;
27921 }
27922
27923 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
27924
27925 dev_kfree_skb_any(skb);
27926
27927 - atomic_inc(&vcc->stats->rx_drop);
27928 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27929 return -ENOMEM;
27930 }
27931
27932 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27933
27934 vcc->push(vcc, skb);
27935 - atomic_inc(&vcc->stats->rx);
27936 + atomic_inc_unchecked(&vcc->stats->rx);
27937
27938 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
27939
27940 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
27941 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
27942 fore200e->atm_dev->number,
27943 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
27944 - atomic_inc(&vcc->stats->rx_err);
27945 + atomic_inc_unchecked(&vcc->stats->rx_err);
27946 }
27947 }
27948
27949 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
27950 goto retry_here;
27951 }
27952
27953 - atomic_inc(&vcc->stats->tx_err);
27954 + atomic_inc_unchecked(&vcc->stats->tx_err);
27955
27956 fore200e->tx_sat++;
27957 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
27958 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
27959 index b182c2f..1c6fa8a 100644
27960 --- a/drivers/atm/he.c
27961 +++ b/drivers/atm/he.c
27962 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27963
27964 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
27965 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
27966 - atomic_inc(&vcc->stats->rx_drop);
27967 + atomic_inc_unchecked(&vcc->stats->rx_drop);
27968 goto return_host_buffers;
27969 }
27970
27971 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27972 RBRQ_LEN_ERR(he_dev->rbrq_head)
27973 ? "LEN_ERR" : "",
27974 vcc->vpi, vcc->vci);
27975 - atomic_inc(&vcc->stats->rx_err);
27976 + atomic_inc_unchecked(&vcc->stats->rx_err);
27977 goto return_host_buffers;
27978 }
27979
27980 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
27981 vcc->push(vcc, skb);
27982 spin_lock(&he_dev->global_lock);
27983
27984 - atomic_inc(&vcc->stats->rx);
27985 + atomic_inc_unchecked(&vcc->stats->rx);
27986
27987 return_host_buffers:
27988 ++pdus_assembled;
27989 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
27990 tpd->vcc->pop(tpd->vcc, tpd->skb);
27991 else
27992 dev_kfree_skb_any(tpd->skb);
27993 - atomic_inc(&tpd->vcc->stats->tx_err);
27994 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
27995 }
27996 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
27997 return;
27998 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
27999 vcc->pop(vcc, skb);
28000 else
28001 dev_kfree_skb_any(skb);
28002 - atomic_inc(&vcc->stats->tx_err);
28003 + atomic_inc_unchecked(&vcc->stats->tx_err);
28004 return -EINVAL;
28005 }
28006
28007 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28008 vcc->pop(vcc, skb);
28009 else
28010 dev_kfree_skb_any(skb);
28011 - atomic_inc(&vcc->stats->tx_err);
28012 + atomic_inc_unchecked(&vcc->stats->tx_err);
28013 return -EINVAL;
28014 }
28015 #endif
28016 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28017 vcc->pop(vcc, skb);
28018 else
28019 dev_kfree_skb_any(skb);
28020 - atomic_inc(&vcc->stats->tx_err);
28021 + atomic_inc_unchecked(&vcc->stats->tx_err);
28022 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28023 return -ENOMEM;
28024 }
28025 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28026 vcc->pop(vcc, skb);
28027 else
28028 dev_kfree_skb_any(skb);
28029 - atomic_inc(&vcc->stats->tx_err);
28030 + atomic_inc_unchecked(&vcc->stats->tx_err);
28031 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28032 return -ENOMEM;
28033 }
28034 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28035 __enqueue_tpd(he_dev, tpd, cid);
28036 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28037
28038 - atomic_inc(&vcc->stats->tx);
28039 + atomic_inc_unchecked(&vcc->stats->tx);
28040
28041 return 0;
28042 }
28043 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28044 index b812103..e391a49 100644
28045 --- a/drivers/atm/horizon.c
28046 +++ b/drivers/atm/horizon.c
28047 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28048 {
28049 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28050 // VC layer stats
28051 - atomic_inc(&vcc->stats->rx);
28052 + atomic_inc_unchecked(&vcc->stats->rx);
28053 __net_timestamp(skb);
28054 // end of our responsibility
28055 vcc->push (vcc, skb);
28056 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28057 dev->tx_iovec = NULL;
28058
28059 // VC layer stats
28060 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28061 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28062
28063 // free the skb
28064 hrz_kfree_skb (skb);
28065 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28066 index 1c05212..c28e200 100644
28067 --- a/drivers/atm/idt77252.c
28068 +++ b/drivers/atm/idt77252.c
28069 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28070 else
28071 dev_kfree_skb(skb);
28072
28073 - atomic_inc(&vcc->stats->tx);
28074 + atomic_inc_unchecked(&vcc->stats->tx);
28075 }
28076
28077 atomic_dec(&scq->used);
28078 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28079 if ((sb = dev_alloc_skb(64)) == NULL) {
28080 printk("%s: Can't allocate buffers for aal0.\n",
28081 card->name);
28082 - atomic_add(i, &vcc->stats->rx_drop);
28083 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28084 break;
28085 }
28086 if (!atm_charge(vcc, sb->truesize)) {
28087 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28088 card->name);
28089 - atomic_add(i - 1, &vcc->stats->rx_drop);
28090 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28091 dev_kfree_skb(sb);
28092 break;
28093 }
28094 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28095 ATM_SKB(sb)->vcc = vcc;
28096 __net_timestamp(sb);
28097 vcc->push(vcc, sb);
28098 - atomic_inc(&vcc->stats->rx);
28099 + atomic_inc_unchecked(&vcc->stats->rx);
28100
28101 cell += ATM_CELL_PAYLOAD;
28102 }
28103 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28104 "(CDC: %08x)\n",
28105 card->name, len, rpp->len, readl(SAR_REG_CDC));
28106 recycle_rx_pool_skb(card, rpp);
28107 - atomic_inc(&vcc->stats->rx_err);
28108 + atomic_inc_unchecked(&vcc->stats->rx_err);
28109 return;
28110 }
28111 if (stat & SAR_RSQE_CRC) {
28112 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28113 recycle_rx_pool_skb(card, rpp);
28114 - atomic_inc(&vcc->stats->rx_err);
28115 + atomic_inc_unchecked(&vcc->stats->rx_err);
28116 return;
28117 }
28118 if (skb_queue_len(&rpp->queue) > 1) {
28119 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28120 RXPRINTK("%s: Can't alloc RX skb.\n",
28121 card->name);
28122 recycle_rx_pool_skb(card, rpp);
28123 - atomic_inc(&vcc->stats->rx_err);
28124 + atomic_inc_unchecked(&vcc->stats->rx_err);
28125 return;
28126 }
28127 if (!atm_charge(vcc, skb->truesize)) {
28128 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28129 __net_timestamp(skb);
28130
28131 vcc->push(vcc, skb);
28132 - atomic_inc(&vcc->stats->rx);
28133 + atomic_inc_unchecked(&vcc->stats->rx);
28134
28135 return;
28136 }
28137 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28138 __net_timestamp(skb);
28139
28140 vcc->push(vcc, skb);
28141 - atomic_inc(&vcc->stats->rx);
28142 + atomic_inc_unchecked(&vcc->stats->rx);
28143
28144 if (skb->truesize > SAR_FB_SIZE_3)
28145 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28146 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28147 if (vcc->qos.aal != ATM_AAL0) {
28148 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28149 card->name, vpi, vci);
28150 - atomic_inc(&vcc->stats->rx_drop);
28151 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28152 goto drop;
28153 }
28154
28155 if ((sb = dev_alloc_skb(64)) == NULL) {
28156 printk("%s: Can't allocate buffers for AAL0.\n",
28157 card->name);
28158 - atomic_inc(&vcc->stats->rx_err);
28159 + atomic_inc_unchecked(&vcc->stats->rx_err);
28160 goto drop;
28161 }
28162
28163 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28164 ATM_SKB(sb)->vcc = vcc;
28165 __net_timestamp(sb);
28166 vcc->push(vcc, sb);
28167 - atomic_inc(&vcc->stats->rx);
28168 + atomic_inc_unchecked(&vcc->stats->rx);
28169
28170 drop:
28171 skb_pull(queue, 64);
28172 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28173
28174 if (vc == NULL) {
28175 printk("%s: NULL connection in send().\n", card->name);
28176 - atomic_inc(&vcc->stats->tx_err);
28177 + atomic_inc_unchecked(&vcc->stats->tx_err);
28178 dev_kfree_skb(skb);
28179 return -EINVAL;
28180 }
28181 if (!test_bit(VCF_TX, &vc->flags)) {
28182 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28183 - atomic_inc(&vcc->stats->tx_err);
28184 + atomic_inc_unchecked(&vcc->stats->tx_err);
28185 dev_kfree_skb(skb);
28186 return -EINVAL;
28187 }
28188 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28189 break;
28190 default:
28191 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28192 - atomic_inc(&vcc->stats->tx_err);
28193 + atomic_inc_unchecked(&vcc->stats->tx_err);
28194 dev_kfree_skb(skb);
28195 return -EINVAL;
28196 }
28197
28198 if (skb_shinfo(skb)->nr_frags != 0) {
28199 printk("%s: No scatter-gather yet.\n", card->name);
28200 - atomic_inc(&vcc->stats->tx_err);
28201 + atomic_inc_unchecked(&vcc->stats->tx_err);
28202 dev_kfree_skb(skb);
28203 return -EINVAL;
28204 }
28205 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28206
28207 err = queue_skb(card, vc, skb, oam);
28208 if (err) {
28209 - atomic_inc(&vcc->stats->tx_err);
28210 + atomic_inc_unchecked(&vcc->stats->tx_err);
28211 dev_kfree_skb(skb);
28212 return err;
28213 }
28214 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28215 skb = dev_alloc_skb(64);
28216 if (!skb) {
28217 printk("%s: Out of memory in send_oam().\n", card->name);
28218 - atomic_inc(&vcc->stats->tx_err);
28219 + atomic_inc_unchecked(&vcc->stats->tx_err);
28220 return -ENOMEM;
28221 }
28222 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28223 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28224 index 9e373ba..cf93727 100644
28225 --- a/drivers/atm/iphase.c
28226 +++ b/drivers/atm/iphase.c
28227 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
28228 status = (u_short) (buf_desc_ptr->desc_mode);
28229 if (status & (RX_CER | RX_PTE | RX_OFL))
28230 {
28231 - atomic_inc(&vcc->stats->rx_err);
28232 + atomic_inc_unchecked(&vcc->stats->rx_err);
28233 IF_ERR(printk("IA: bad packet, dropping it");)
28234 if (status & RX_CER) {
28235 IF_ERR(printk(" cause: packet CRC error\n");)
28236 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
28237 len = dma_addr - buf_addr;
28238 if (len > iadev->rx_buf_sz) {
28239 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28240 - atomic_inc(&vcc->stats->rx_err);
28241 + atomic_inc_unchecked(&vcc->stats->rx_err);
28242 goto out_free_desc;
28243 }
28244
28245 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28246 ia_vcc = INPH_IA_VCC(vcc);
28247 if (ia_vcc == NULL)
28248 {
28249 - atomic_inc(&vcc->stats->rx_err);
28250 + atomic_inc_unchecked(&vcc->stats->rx_err);
28251 atm_return(vcc, skb->truesize);
28252 dev_kfree_skb_any(skb);
28253 goto INCR_DLE;
28254 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28255 if ((length > iadev->rx_buf_sz) || (length >
28256 (skb->len - sizeof(struct cpcs_trailer))))
28257 {
28258 - atomic_inc(&vcc->stats->rx_err);
28259 + atomic_inc_unchecked(&vcc->stats->rx_err);
28260 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28261 length, skb->len);)
28262 atm_return(vcc, skb->truesize);
28263 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28264
28265 IF_RX(printk("rx_dle_intr: skb push");)
28266 vcc->push(vcc,skb);
28267 - atomic_inc(&vcc->stats->rx);
28268 + atomic_inc_unchecked(&vcc->stats->rx);
28269 iadev->rx_pkt_cnt++;
28270 }
28271 INCR_DLE:
28272 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28273 {
28274 struct k_sonet_stats *stats;
28275 stats = &PRIV(_ia_dev[board])->sonet_stats;
28276 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28277 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28278 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28279 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28280 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28281 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28282 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28283 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28284 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28285 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28286 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28287 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28288 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28289 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28290 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28291 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28292 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28293 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28294 }
28295 ia_cmds.status = 0;
28296 break;
28297 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28298 if ((desc == 0) || (desc > iadev->num_tx_desc))
28299 {
28300 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28301 - atomic_inc(&vcc->stats->tx);
28302 + atomic_inc_unchecked(&vcc->stats->tx);
28303 if (vcc->pop)
28304 vcc->pop(vcc, skb);
28305 else
28306 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28307 ATM_DESC(skb) = vcc->vci;
28308 skb_queue_tail(&iadev->tx_dma_q, skb);
28309
28310 - atomic_inc(&vcc->stats->tx);
28311 + atomic_inc_unchecked(&vcc->stats->tx);
28312 iadev->tx_pkt_cnt++;
28313 /* Increment transaction counter */
28314 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28315
28316 #if 0
28317 /* add flow control logic */
28318 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28319 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28320 if (iavcc->vc_desc_cnt > 10) {
28321 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28322 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28323 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28324 index f556969..0da15eb 100644
28325 --- a/drivers/atm/lanai.c
28326 +++ b/drivers/atm/lanai.c
28327 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28328 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28329 lanai_endtx(lanai, lvcc);
28330 lanai_free_skb(lvcc->tx.atmvcc, skb);
28331 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28332 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28333 }
28334
28335 /* Try to fill the buffer - don't call unless there is backlog */
28336 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28337 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28338 __net_timestamp(skb);
28339 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28340 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28341 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28342 out:
28343 lvcc->rx.buf.ptr = end;
28344 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28345 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28346 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28347 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28348 lanai->stats.service_rxnotaal5++;
28349 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28350 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28351 return 0;
28352 }
28353 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28354 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28355 int bytes;
28356 read_unlock(&vcc_sklist_lock);
28357 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28358 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28359 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28360 lvcc->stats.x.aal5.service_trash++;
28361 bytes = (SERVICE_GET_END(s) * 16) -
28362 (((unsigned long) lvcc->rx.buf.ptr) -
28363 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28364 }
28365 if (s & SERVICE_STREAM) {
28366 read_unlock(&vcc_sklist_lock);
28367 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28368 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28369 lvcc->stats.x.aal5.service_stream++;
28370 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28371 "PDU on VCI %d!\n", lanai->number, vci);
28372 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28373 return 0;
28374 }
28375 DPRINTK("got rx crc error on vci %d\n", vci);
28376 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28377 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28378 lvcc->stats.x.aal5.service_rxcrc++;
28379 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28380 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28381 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28382 index 1c70c45..300718d 100644
28383 --- a/drivers/atm/nicstar.c
28384 +++ b/drivers/atm/nicstar.c
28385 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28386 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28387 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28388 card->index);
28389 - atomic_inc(&vcc->stats->tx_err);
28390 + atomic_inc_unchecked(&vcc->stats->tx_err);
28391 dev_kfree_skb_any(skb);
28392 return -EINVAL;
28393 }
28394 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28395 if (!vc->tx) {
28396 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28397 card->index);
28398 - atomic_inc(&vcc->stats->tx_err);
28399 + atomic_inc_unchecked(&vcc->stats->tx_err);
28400 dev_kfree_skb_any(skb);
28401 return -EINVAL;
28402 }
28403 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28404 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28405 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28406 card->index);
28407 - atomic_inc(&vcc->stats->tx_err);
28408 + atomic_inc_unchecked(&vcc->stats->tx_err);
28409 dev_kfree_skb_any(skb);
28410 return -EINVAL;
28411 }
28412
28413 if (skb_shinfo(skb)->nr_frags != 0) {
28414 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28415 - atomic_inc(&vcc->stats->tx_err);
28416 + atomic_inc_unchecked(&vcc->stats->tx_err);
28417 dev_kfree_skb_any(skb);
28418 return -EINVAL;
28419 }
28420 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28421 }
28422
28423 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28424 - atomic_inc(&vcc->stats->tx_err);
28425 + atomic_inc_unchecked(&vcc->stats->tx_err);
28426 dev_kfree_skb_any(skb);
28427 return -EIO;
28428 }
28429 - atomic_inc(&vcc->stats->tx);
28430 + atomic_inc_unchecked(&vcc->stats->tx);
28431
28432 return 0;
28433 }
28434 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28435 printk
28436 ("nicstar%d: Can't allocate buffers for aal0.\n",
28437 card->index);
28438 - atomic_add(i, &vcc->stats->rx_drop);
28439 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28440 break;
28441 }
28442 if (!atm_charge(vcc, sb->truesize)) {
28443 RXPRINTK
28444 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28445 card->index);
28446 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28447 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28448 dev_kfree_skb_any(sb);
28449 break;
28450 }
28451 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28452 ATM_SKB(sb)->vcc = vcc;
28453 __net_timestamp(sb);
28454 vcc->push(vcc, sb);
28455 - atomic_inc(&vcc->stats->rx);
28456 + atomic_inc_unchecked(&vcc->stats->rx);
28457 cell += ATM_CELL_PAYLOAD;
28458 }
28459
28460 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28461 if (iovb == NULL) {
28462 printk("nicstar%d: Out of iovec buffers.\n",
28463 card->index);
28464 - atomic_inc(&vcc->stats->rx_drop);
28465 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28466 recycle_rx_buf(card, skb);
28467 return;
28468 }
28469 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28470 small or large buffer itself. */
28471 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28472 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28473 - atomic_inc(&vcc->stats->rx_err);
28474 + atomic_inc_unchecked(&vcc->stats->rx_err);
28475 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28476 NS_MAX_IOVECS);
28477 NS_PRV_IOVCNT(iovb) = 0;
28478 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28479 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28480 card->index);
28481 which_list(card, skb);
28482 - atomic_inc(&vcc->stats->rx_err);
28483 + atomic_inc_unchecked(&vcc->stats->rx_err);
28484 recycle_rx_buf(card, skb);
28485 vc->rx_iov = NULL;
28486 recycle_iov_buf(card, iovb);
28487 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28488 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28489 card->index);
28490 which_list(card, skb);
28491 - atomic_inc(&vcc->stats->rx_err);
28492 + atomic_inc_unchecked(&vcc->stats->rx_err);
28493 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28494 NS_PRV_IOVCNT(iovb));
28495 vc->rx_iov = NULL;
28496 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28497 printk(" - PDU size mismatch.\n");
28498 else
28499 printk(".\n");
28500 - atomic_inc(&vcc->stats->rx_err);
28501 + atomic_inc_unchecked(&vcc->stats->rx_err);
28502 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28503 NS_PRV_IOVCNT(iovb));
28504 vc->rx_iov = NULL;
28505 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28506 /* skb points to a small buffer */
28507 if (!atm_charge(vcc, skb->truesize)) {
28508 push_rxbufs(card, skb);
28509 - atomic_inc(&vcc->stats->rx_drop);
28510 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28511 } else {
28512 skb_put(skb, len);
28513 dequeue_sm_buf(card, skb);
28514 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28515 ATM_SKB(skb)->vcc = vcc;
28516 __net_timestamp(skb);
28517 vcc->push(vcc, skb);
28518 - atomic_inc(&vcc->stats->rx);
28519 + atomic_inc_unchecked(&vcc->stats->rx);
28520 }
28521 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28522 struct sk_buff *sb;
28523 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28524 if (len <= NS_SMBUFSIZE) {
28525 if (!atm_charge(vcc, sb->truesize)) {
28526 push_rxbufs(card, sb);
28527 - atomic_inc(&vcc->stats->rx_drop);
28528 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28529 } else {
28530 skb_put(sb, len);
28531 dequeue_sm_buf(card, sb);
28532 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28533 ATM_SKB(sb)->vcc = vcc;
28534 __net_timestamp(sb);
28535 vcc->push(vcc, sb);
28536 - atomic_inc(&vcc->stats->rx);
28537 + atomic_inc_unchecked(&vcc->stats->rx);
28538 }
28539
28540 push_rxbufs(card, skb);
28541 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28542
28543 if (!atm_charge(vcc, skb->truesize)) {
28544 push_rxbufs(card, skb);
28545 - atomic_inc(&vcc->stats->rx_drop);
28546 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28547 } else {
28548 dequeue_lg_buf(card, skb);
28549 #ifdef NS_USE_DESTRUCTORS
28550 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28551 ATM_SKB(skb)->vcc = vcc;
28552 __net_timestamp(skb);
28553 vcc->push(vcc, skb);
28554 - atomic_inc(&vcc->stats->rx);
28555 + atomic_inc_unchecked(&vcc->stats->rx);
28556 }
28557
28558 push_rxbufs(card, sb);
28559 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28560 printk
28561 ("nicstar%d: Out of huge buffers.\n",
28562 card->index);
28563 - atomic_inc(&vcc->stats->rx_drop);
28564 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28565 recycle_iovec_rx_bufs(card,
28566 (struct iovec *)
28567 iovb->data,
28568 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28569 card->hbpool.count++;
28570 } else
28571 dev_kfree_skb_any(hb);
28572 - atomic_inc(&vcc->stats->rx_drop);
28573 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28574 } else {
28575 /* Copy the small buffer to the huge buffer */
28576 sb = (struct sk_buff *)iov->iov_base;
28577 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28578 #endif /* NS_USE_DESTRUCTORS */
28579 __net_timestamp(hb);
28580 vcc->push(vcc, hb);
28581 - atomic_inc(&vcc->stats->rx);
28582 + atomic_inc_unchecked(&vcc->stats->rx);
28583 }
28584 }
28585
28586 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28587 index e8cd652..bbbd1fc 100644
28588 --- a/drivers/atm/solos-pci.c
28589 +++ b/drivers/atm/solos-pci.c
28590 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28591 }
28592 atm_charge(vcc, skb->truesize);
28593 vcc->push(vcc, skb);
28594 - atomic_inc(&vcc->stats->rx);
28595 + atomic_inc_unchecked(&vcc->stats->rx);
28596 break;
28597
28598 case PKT_STATUS:
28599 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28600 vcc = SKB_CB(oldskb)->vcc;
28601
28602 if (vcc) {
28603 - atomic_inc(&vcc->stats->tx);
28604 + atomic_inc_unchecked(&vcc->stats->tx);
28605 solos_pop(vcc, oldskb);
28606 } else
28607 dev_kfree_skb_irq(oldskb);
28608 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28609 index 90f1ccc..04c4a1e 100644
28610 --- a/drivers/atm/suni.c
28611 +++ b/drivers/atm/suni.c
28612 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28613
28614
28615 #define ADD_LIMITED(s,v) \
28616 - atomic_add((v),&stats->s); \
28617 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28618 + atomic_add_unchecked((v),&stats->s); \
28619 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28620
28621
28622 static void suni_hz(unsigned long from_timer)
28623 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28624 index 5120a96..e2572bd 100644
28625 --- a/drivers/atm/uPD98402.c
28626 +++ b/drivers/atm/uPD98402.c
28627 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28628 struct sonet_stats tmp;
28629 int error = 0;
28630
28631 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28632 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28633 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28634 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28635 if (zero && !error) {
28636 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28637
28638
28639 #define ADD_LIMITED(s,v) \
28640 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28641 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28642 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28643 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28644 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28645 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28646
28647
28648 static void stat_event(struct atm_dev *dev)
28649 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28650 if (reason & uPD98402_INT_PFM) stat_event(dev);
28651 if (reason & uPD98402_INT_PCO) {
28652 (void) GET(PCOCR); /* clear interrupt cause */
28653 - atomic_add(GET(HECCT),
28654 + atomic_add_unchecked(GET(HECCT),
28655 &PRIV(dev)->sonet_stats.uncorr_hcs);
28656 }
28657 if ((reason & uPD98402_INT_RFO) &&
28658 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28659 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28660 uPD98402_INT_LOS),PIMR); /* enable them */
28661 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28662 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28663 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28664 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28665 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28666 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28667 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28668 return 0;
28669 }
28670
28671 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28672 index d889f56..17eb71e 100644
28673 --- a/drivers/atm/zatm.c
28674 +++ b/drivers/atm/zatm.c
28675 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28676 }
28677 if (!size) {
28678 dev_kfree_skb_irq(skb);
28679 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28680 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28681 continue;
28682 }
28683 if (!atm_charge(vcc,skb->truesize)) {
28684 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28685 skb->len = size;
28686 ATM_SKB(skb)->vcc = vcc;
28687 vcc->push(vcc,skb);
28688 - atomic_inc(&vcc->stats->rx);
28689 + atomic_inc_unchecked(&vcc->stats->rx);
28690 }
28691 zout(pos & 0xffff,MTA(mbx));
28692 #if 0 /* probably a stupid idea */
28693 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28694 skb_queue_head(&zatm_vcc->backlog,skb);
28695 break;
28696 }
28697 - atomic_inc(&vcc->stats->tx);
28698 + atomic_inc_unchecked(&vcc->stats->tx);
28699 wake_up(&zatm_vcc->tx_wait);
28700 }
28701
28702 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28703 index 8493536..31adee0 100644
28704 --- a/drivers/base/devtmpfs.c
28705 +++ b/drivers/base/devtmpfs.c
28706 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28707 if (!thread)
28708 return 0;
28709
28710 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28711 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28712 if (err)
28713 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28714 else
28715 diff --git a/drivers/base/node.c b/drivers/base/node.c
28716 index 90aa2a1..af1a177 100644
28717 --- a/drivers/base/node.c
28718 +++ b/drivers/base/node.c
28719 @@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
28720 {
28721 int n;
28722
28723 - n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
28724 - if (n > 0 && PAGE_SIZE > n + 1) {
28725 - *(buf + n++) = '\n';
28726 - *(buf + n++) = '\0';
28727 - }
28728 + n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
28729 + buf[n++] = '\n';
28730 + buf[n] = '\0';
28731 return n;
28732 }
28733
28734 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28735 index caf995f..6f76697 100644
28736 --- a/drivers/base/power/wakeup.c
28737 +++ b/drivers/base/power/wakeup.c
28738 @@ -30,14 +30,14 @@ bool events_check_enabled;
28739 * They need to be modified together atomically, so it's better to use one
28740 * atomic variable to hold them both.
28741 */
28742 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28743 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28744
28745 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28746 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28747
28748 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28749 {
28750 - unsigned int comb = atomic_read(&combined_event_count);
28751 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28752
28753 *cnt = (comb >> IN_PROGRESS_BITS);
28754 *inpr = comb & MAX_IN_PROGRESS;
28755 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28756 ws->last_time = ktime_get();
28757
28758 /* Increment the counter of events in progress. */
28759 - atomic_inc(&combined_event_count);
28760 + atomic_inc_unchecked(&combined_event_count);
28761 }
28762
28763 /**
28764 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28765 * Increment the counter of registered wakeup events and decrement the
28766 * couter of wakeup events in progress simultaneously.
28767 */
28768 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
28769 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28770 }
28771
28772 /**
28773 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28774 index b0f553b..77b928b 100644
28775 --- a/drivers/block/cciss.c
28776 +++ b/drivers/block/cciss.c
28777 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28778 int err;
28779 u32 cp;
28780
28781 + memset(&arg64, 0, sizeof(arg64));
28782 +
28783 err = 0;
28784 err |=
28785 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28786 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28787 while (!list_empty(&h->reqQ)) {
28788 c = list_entry(h->reqQ.next, CommandList_struct, list);
28789 /* can't do anything if fifo is full */
28790 - if ((h->access.fifo_full(h))) {
28791 + if ((h->access->fifo_full(h))) {
28792 dev_warn(&h->pdev->dev, "fifo full\n");
28793 break;
28794 }
28795 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
28796 h->Qdepth--;
28797
28798 /* Tell the controller execute command */
28799 - h->access.submit_command(h, c);
28800 + h->access->submit_command(h, c);
28801
28802 /* Put job onto the completed Q */
28803 addQ(&h->cmpQ, c);
28804 @@ -3443,17 +3445,17 @@ startio:
28805
28806 static inline unsigned long get_next_completion(ctlr_info_t *h)
28807 {
28808 - return h->access.command_completed(h);
28809 + return h->access->command_completed(h);
28810 }
28811
28812 static inline int interrupt_pending(ctlr_info_t *h)
28813 {
28814 - return h->access.intr_pending(h);
28815 + return h->access->intr_pending(h);
28816 }
28817
28818 static inline long interrupt_not_for_us(ctlr_info_t *h)
28819 {
28820 - return ((h->access.intr_pending(h) == 0) ||
28821 + return ((h->access->intr_pending(h) == 0) ||
28822 (h->interrupts_enabled == 0));
28823 }
28824
28825 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
28826 u32 a;
28827
28828 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
28829 - return h->access.command_completed(h);
28830 + return h->access->command_completed(h);
28831
28832 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
28833 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
28834 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
28835 trans_support & CFGTBL_Trans_use_short_tags);
28836
28837 /* Change the access methods to the performant access methods */
28838 - h->access = SA5_performant_access;
28839 + h->access = &SA5_performant_access;
28840 h->transMethod = CFGTBL_Trans_Performant;
28841
28842 return;
28843 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
28844 if (prod_index < 0)
28845 return -ENODEV;
28846 h->product_name = products[prod_index].product_name;
28847 - h->access = *(products[prod_index].access);
28848 + h->access = products[prod_index].access;
28849
28850 if (cciss_board_disabled(h)) {
28851 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
28852 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
28853 }
28854
28855 /* make sure the board interrupts are off */
28856 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28857 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28858 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
28859 if (rc)
28860 goto clean2;
28861 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
28862 * fake ones to scoop up any residual completions.
28863 */
28864 spin_lock_irqsave(&h->lock, flags);
28865 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28866 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28867 spin_unlock_irqrestore(&h->lock, flags);
28868 free_irq(h->intr[h->intr_mode], h);
28869 rc = cciss_request_irq(h, cciss_msix_discard_completions,
28870 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
28871 dev_info(&h->pdev->dev, "Board READY.\n");
28872 dev_info(&h->pdev->dev,
28873 "Waiting for stale completions to drain.\n");
28874 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28875 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28876 msleep(10000);
28877 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28878 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28879
28880 rc = controller_reset_failed(h->cfgtable);
28881 if (rc)
28882 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
28883 cciss_scsi_setup(h);
28884
28885 /* Turn the interrupts on so we can service requests */
28886 - h->access.set_intr_mask(h, CCISS_INTR_ON);
28887 + h->access->set_intr_mask(h, CCISS_INTR_ON);
28888
28889 /* Get the firmware version */
28890 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
28891 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
28892 kfree(flush_buf);
28893 if (return_code != IO_OK)
28894 dev_warn(&h->pdev->dev, "Error flushing cache\n");
28895 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
28896 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
28897 free_irq(h->intr[h->intr_mode], h);
28898 }
28899
28900 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
28901 index 7fda30e..eb5dfe0 100644
28902 --- a/drivers/block/cciss.h
28903 +++ b/drivers/block/cciss.h
28904 @@ -101,7 +101,7 @@ struct ctlr_info
28905 /* information about each logical volume */
28906 drive_info_struct *drv[CISS_MAX_LUN];
28907
28908 - struct access_method access;
28909 + struct access_method *access;
28910
28911 /* queue and queue Info */
28912 struct list_head reqQ;
28913 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
28914 index 9125bbe..eede5c8 100644
28915 --- a/drivers/block/cpqarray.c
28916 +++ b/drivers/block/cpqarray.c
28917 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28918 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
28919 goto Enomem4;
28920 }
28921 - hba[i]->access.set_intr_mask(hba[i], 0);
28922 + hba[i]->access->set_intr_mask(hba[i], 0);
28923 if (request_irq(hba[i]->intr, do_ida_intr,
28924 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
28925 {
28926 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
28927 add_timer(&hba[i]->timer);
28928
28929 /* Enable IRQ now that spinlock and rate limit timer are set up */
28930 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28931 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
28932
28933 for(j=0; j<NWD; j++) {
28934 struct gendisk *disk = ida_gendisk[i][j];
28935 @@ -694,7 +694,7 @@ DBGINFO(
28936 for(i=0; i<NR_PRODUCTS; i++) {
28937 if (board_id == products[i].board_id) {
28938 c->product_name = products[i].product_name;
28939 - c->access = *(products[i].access);
28940 + c->access = products[i].access;
28941 break;
28942 }
28943 }
28944 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
28945 hba[ctlr]->intr = intr;
28946 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
28947 hba[ctlr]->product_name = products[j].product_name;
28948 - hba[ctlr]->access = *(products[j].access);
28949 + hba[ctlr]->access = products[j].access;
28950 hba[ctlr]->ctlr = ctlr;
28951 hba[ctlr]->board_id = board_id;
28952 hba[ctlr]->pci_dev = NULL; /* not PCI */
28953 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
28954
28955 while((c = h->reqQ) != NULL) {
28956 /* Can't do anything if we're busy */
28957 - if (h->access.fifo_full(h) == 0)
28958 + if (h->access->fifo_full(h) == 0)
28959 return;
28960
28961 /* Get the first entry from the request Q */
28962 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
28963 h->Qdepth--;
28964
28965 /* Tell the controller to do our bidding */
28966 - h->access.submit_command(h, c);
28967 + h->access->submit_command(h, c);
28968
28969 /* Get onto the completion Q */
28970 addQ(&h->cmpQ, c);
28971 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28972 unsigned long flags;
28973 __u32 a,a1;
28974
28975 - istat = h->access.intr_pending(h);
28976 + istat = h->access->intr_pending(h);
28977 /* Is this interrupt for us? */
28978 if (istat == 0)
28979 return IRQ_NONE;
28980 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
28981 */
28982 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
28983 if (istat & FIFO_NOT_EMPTY) {
28984 - while((a = h->access.command_completed(h))) {
28985 + while((a = h->access->command_completed(h))) {
28986 a1 = a; a &= ~3;
28987 if ((c = h->cmpQ) == NULL)
28988 {
28989 @@ -1449,11 +1449,11 @@ static int sendcmd(
28990 /*
28991 * Disable interrupt
28992 */
28993 - info_p->access.set_intr_mask(info_p, 0);
28994 + info_p->access->set_intr_mask(info_p, 0);
28995 /* Make sure there is room in the command FIFO */
28996 /* Actually it should be completely empty at this time. */
28997 for (i = 200000; i > 0; i--) {
28998 - temp = info_p->access.fifo_full(info_p);
28999 + temp = info_p->access->fifo_full(info_p);
29000 if (temp != 0) {
29001 break;
29002 }
29003 @@ -1466,7 +1466,7 @@ DBG(
29004 /*
29005 * Send the cmd
29006 */
29007 - info_p->access.submit_command(info_p, c);
29008 + info_p->access->submit_command(info_p, c);
29009 complete = pollcomplete(ctlr);
29010
29011 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29012 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29013 * we check the new geometry. Then turn interrupts back on when
29014 * we're done.
29015 */
29016 - host->access.set_intr_mask(host, 0);
29017 + host->access->set_intr_mask(host, 0);
29018 getgeometry(ctlr);
29019 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29020 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29021
29022 for(i=0; i<NWD; i++) {
29023 struct gendisk *disk = ida_gendisk[ctlr][i];
29024 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29025 /* Wait (up to 2 seconds) for a command to complete */
29026
29027 for (i = 200000; i > 0; i--) {
29028 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29029 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29030 if (done == 0) {
29031 udelay(10); /* a short fixed delay */
29032 } else
29033 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29034 index be73e9d..7fbf140 100644
29035 --- a/drivers/block/cpqarray.h
29036 +++ b/drivers/block/cpqarray.h
29037 @@ -99,7 +99,7 @@ struct ctlr_info {
29038 drv_info_t drv[NWD];
29039 struct proc_dir_entry *proc;
29040
29041 - struct access_method access;
29042 + struct access_method *access;
29043
29044 cmdlist_t *reqQ;
29045 cmdlist_t *cmpQ;
29046 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29047 index 8d68056..e67050f 100644
29048 --- a/drivers/block/drbd/drbd_int.h
29049 +++ b/drivers/block/drbd/drbd_int.h
29050 @@ -736,7 +736,7 @@ struct drbd_request;
29051 struct drbd_epoch {
29052 struct list_head list;
29053 unsigned int barrier_nr;
29054 - atomic_t epoch_size; /* increased on every request added. */
29055 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29056 atomic_t active; /* increased on every req. added, and dec on every finished. */
29057 unsigned long flags;
29058 };
29059 @@ -1108,7 +1108,7 @@ struct drbd_conf {
29060 void *int_dig_in;
29061 void *int_dig_vv;
29062 wait_queue_head_t seq_wait;
29063 - atomic_t packet_seq;
29064 + atomic_unchecked_t packet_seq;
29065 unsigned int peer_seq;
29066 spinlock_t peer_seq_lock;
29067 unsigned int minor;
29068 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29069
29070 static inline void drbd_tcp_cork(struct socket *sock)
29071 {
29072 - int __user val = 1;
29073 + int val = 1;
29074 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29075 - (char __user *)&val, sizeof(val));
29076 + (char __force_user *)&val, sizeof(val));
29077 }
29078
29079 static inline void drbd_tcp_uncork(struct socket *sock)
29080 {
29081 - int __user val = 0;
29082 + int val = 0;
29083 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29084 - (char __user *)&val, sizeof(val));
29085 + (char __force_user *)&val, sizeof(val));
29086 }
29087
29088 static inline void drbd_tcp_nodelay(struct socket *sock)
29089 {
29090 - int __user val = 1;
29091 + int val = 1;
29092 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29093 - (char __user *)&val, sizeof(val));
29094 + (char __force_user *)&val, sizeof(val));
29095 }
29096
29097 static inline void drbd_tcp_quickack(struct socket *sock)
29098 {
29099 - int __user val = 2;
29100 + int val = 2;
29101 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29102 - (char __user *)&val, sizeof(val));
29103 + (char __force_user *)&val, sizeof(val));
29104 }
29105
29106 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29107 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29108 index 211fc44..c5116f1 100644
29109 --- a/drivers/block/drbd/drbd_main.c
29110 +++ b/drivers/block/drbd/drbd_main.c
29111 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29112 p.sector = sector;
29113 p.block_id = block_id;
29114 p.blksize = blksize;
29115 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29116 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29117
29118 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29119 return false;
29120 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29121 p.sector = cpu_to_be64(req->sector);
29122 p.block_id = (unsigned long)req;
29123 p.seq_num = cpu_to_be32(req->seq_num =
29124 - atomic_add_return(1, &mdev->packet_seq));
29125 + atomic_add_return_unchecked(1, &mdev->packet_seq));
29126
29127 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29128
29129 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29130 atomic_set(&mdev->unacked_cnt, 0);
29131 atomic_set(&mdev->local_cnt, 0);
29132 atomic_set(&mdev->net_cnt, 0);
29133 - atomic_set(&mdev->packet_seq, 0);
29134 + atomic_set_unchecked(&mdev->packet_seq, 0);
29135 atomic_set(&mdev->pp_in_use, 0);
29136 atomic_set(&mdev->pp_in_use_by_net, 0);
29137 atomic_set(&mdev->rs_sect_in, 0);
29138 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29139 mdev->receiver.t_state);
29140
29141 /* no need to lock it, I'm the only thread alive */
29142 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29143 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29144 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29145 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29146 mdev->al_writ_cnt =
29147 mdev->bm_writ_cnt =
29148 mdev->read_cnt =
29149 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29150 index af2a250..0fdeb75 100644
29151 --- a/drivers/block/drbd/drbd_nl.c
29152 +++ b/drivers/block/drbd/drbd_nl.c
29153 @@ -2297,7 +2297,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29154 return;
29155 }
29156
29157 - if (!cap_raised(current_cap(), CAP_SYS_ADMIN)) {
29158 + if (!capable(CAP_SYS_ADMIN)) {
29159 retcode = ERR_PERM;
29160 goto fail;
29161 }
29162 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29163 module_put(THIS_MODULE);
29164 }
29165
29166 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29167 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29168
29169 static unsigned short *
29170 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29171 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29172 cn_reply->id.idx = CN_IDX_DRBD;
29173 cn_reply->id.val = CN_VAL_DRBD;
29174
29175 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29176 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29177 cn_reply->ack = 0; /* not used here. */
29178 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29179 (int)((char *)tl - (char *)reply->tag_list);
29180 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29181 cn_reply->id.idx = CN_IDX_DRBD;
29182 cn_reply->id.val = CN_VAL_DRBD;
29183
29184 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29185 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29186 cn_reply->ack = 0; /* not used here. */
29187 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29188 (int)((char *)tl - (char *)reply->tag_list);
29189 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29190 cn_reply->id.idx = CN_IDX_DRBD;
29191 cn_reply->id.val = CN_VAL_DRBD;
29192
29193 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29194 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29195 cn_reply->ack = 0; // not used here.
29196 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29197 (int)((char*)tl - (char*)reply->tag_list);
29198 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29199 cn_reply->id.idx = CN_IDX_DRBD;
29200 cn_reply->id.val = CN_VAL_DRBD;
29201
29202 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29203 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29204 cn_reply->ack = 0; /* not used here. */
29205 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29206 (int)((char *)tl - (char *)reply->tag_list);
29207 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29208 index 43beaca..4a5b1dd 100644
29209 --- a/drivers/block/drbd/drbd_receiver.c
29210 +++ b/drivers/block/drbd/drbd_receiver.c
29211 @@ -894,7 +894,7 @@ retry:
29212 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29213 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29214
29215 - atomic_set(&mdev->packet_seq, 0);
29216 + atomic_set_unchecked(&mdev->packet_seq, 0);
29217 mdev->peer_seq = 0;
29218
29219 drbd_thread_start(&mdev->asender);
29220 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29221 do {
29222 next_epoch = NULL;
29223
29224 - epoch_size = atomic_read(&epoch->epoch_size);
29225 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29226
29227 switch (ev & ~EV_CLEANUP) {
29228 case EV_PUT:
29229 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29230 rv = FE_DESTROYED;
29231 } else {
29232 epoch->flags = 0;
29233 - atomic_set(&epoch->epoch_size, 0);
29234 + atomic_set_unchecked(&epoch->epoch_size, 0);
29235 /* atomic_set(&epoch->active, 0); is already zero */
29236 if (rv == FE_STILL_LIVE)
29237 rv = FE_RECYCLED;
29238 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29239 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29240 drbd_flush(mdev);
29241
29242 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29243 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29244 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29245 if (epoch)
29246 break;
29247 }
29248
29249 epoch = mdev->current_epoch;
29250 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29251 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29252
29253 D_ASSERT(atomic_read(&epoch->active) == 0);
29254 D_ASSERT(epoch->flags == 0);
29255 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29256 }
29257
29258 epoch->flags = 0;
29259 - atomic_set(&epoch->epoch_size, 0);
29260 + atomic_set_unchecked(&epoch->epoch_size, 0);
29261 atomic_set(&epoch->active, 0);
29262
29263 spin_lock(&mdev->epoch_lock);
29264 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29265 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29266 list_add(&epoch->list, &mdev->current_epoch->list);
29267 mdev->current_epoch = epoch;
29268 mdev->epochs++;
29269 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29270 spin_unlock(&mdev->peer_seq_lock);
29271
29272 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29273 - atomic_inc(&mdev->current_epoch->epoch_size);
29274 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29275 return drbd_drain_block(mdev, data_size);
29276 }
29277
29278 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29279
29280 spin_lock(&mdev->epoch_lock);
29281 e->epoch = mdev->current_epoch;
29282 - atomic_inc(&e->epoch->epoch_size);
29283 + atomic_inc_unchecked(&e->epoch->epoch_size);
29284 atomic_inc(&e->epoch->active);
29285 spin_unlock(&mdev->epoch_lock);
29286
29287 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29288 D_ASSERT(list_empty(&mdev->done_ee));
29289
29290 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29291 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29292 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29293 D_ASSERT(list_empty(&mdev->current_epoch->list));
29294 }
29295
29296 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29297 index cd50435..ba1ffb5 100644
29298 --- a/drivers/block/loop.c
29299 +++ b/drivers/block/loop.c
29300 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29301 mm_segment_t old_fs = get_fs();
29302
29303 set_fs(get_ds());
29304 - bw = file->f_op->write(file, buf, len, &pos);
29305 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29306 set_fs(old_fs);
29307 if (likely(bw == len))
29308 return 0;
29309 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29310 index 4364303..9adf4ee 100644
29311 --- a/drivers/char/Kconfig
29312 +++ b/drivers/char/Kconfig
29313 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29314
29315 config DEVKMEM
29316 bool "/dev/kmem virtual device support"
29317 - default y
29318 + default n
29319 + depends on !GRKERNSEC_KMEM
29320 help
29321 Say Y here if you want to support the /dev/kmem device. The
29322 /dev/kmem device is rarely used, but can be used for certain
29323 @@ -596,6 +597,7 @@ config DEVPORT
29324 bool
29325 depends on !M68K
29326 depends on ISA || PCI
29327 + depends on !GRKERNSEC_KMEM
29328 default y
29329
29330 source "drivers/s390/char/Kconfig"
29331 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29332 index 2e04433..22afc64 100644
29333 --- a/drivers/char/agp/frontend.c
29334 +++ b/drivers/char/agp/frontend.c
29335 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29336 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29337 return -EFAULT;
29338
29339 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29340 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29341 return -EFAULT;
29342
29343 client = agp_find_client_by_pid(reserve.pid);
29344 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
29345 index 095ab90..afad0a4 100644
29346 --- a/drivers/char/briq_panel.c
29347 +++ b/drivers/char/briq_panel.c
29348 @@ -9,6 +9,7 @@
29349 #include <linux/types.h>
29350 #include <linux/errno.h>
29351 #include <linux/tty.h>
29352 +#include <linux/mutex.h>
29353 #include <linux/timer.h>
29354 #include <linux/kernel.h>
29355 #include <linux/wait.h>
29356 @@ -34,6 +35,7 @@ static int vfd_is_open;
29357 static unsigned char vfd[40];
29358 static int vfd_cursor;
29359 static unsigned char ledpb, led;
29360 +static DEFINE_MUTEX(vfd_mutex);
29361
29362 static void update_vfd(void)
29363 {
29364 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29365 if (!vfd_is_open)
29366 return -EBUSY;
29367
29368 + mutex_lock(&vfd_mutex);
29369 for (;;) {
29370 char c;
29371 if (!indx)
29372 break;
29373 - if (get_user(c, buf))
29374 + if (get_user(c, buf)) {
29375 + mutex_unlock(&vfd_mutex);
29376 return -EFAULT;
29377 + }
29378 if (esc) {
29379 set_led(c);
29380 esc = 0;
29381 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
29382 buf++;
29383 }
29384 update_vfd();
29385 + mutex_unlock(&vfd_mutex);
29386
29387 return len;
29388 }
29389 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29390 index f773a9d..65cd683 100644
29391 --- a/drivers/char/genrtc.c
29392 +++ b/drivers/char/genrtc.c
29393 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
29394 switch (cmd) {
29395
29396 case RTC_PLL_GET:
29397 + memset(&pll, 0, sizeof(pll));
29398 if (get_rtc_pll(&pll))
29399 return -EINVAL;
29400 else
29401 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29402 index 0833896..cccce52 100644
29403 --- a/drivers/char/hpet.c
29404 +++ b/drivers/char/hpet.c
29405 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29406 }
29407
29408 static int
29409 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29410 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29411 struct hpet_info *info)
29412 {
29413 struct hpet_timer __iomem *timer;
29414 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29415 index 58c0e63..46c16bf 100644
29416 --- a/drivers/char/ipmi/ipmi_msghandler.c
29417 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29418 @@ -415,7 +415,7 @@ struct ipmi_smi {
29419 struct proc_dir_entry *proc_dir;
29420 char proc_dir_name[10];
29421
29422 - atomic_t stats[IPMI_NUM_STATS];
29423 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29424
29425 /*
29426 * run_to_completion duplicate of smb_info, smi_info
29427 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29428
29429
29430 #define ipmi_inc_stat(intf, stat) \
29431 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29432 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29433 #define ipmi_get_stat(intf, stat) \
29434 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29435 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29436
29437 static int is_lan_addr(struct ipmi_addr *addr)
29438 {
29439 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29440 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29441 init_waitqueue_head(&intf->waitq);
29442 for (i = 0; i < IPMI_NUM_STATS; i++)
29443 - atomic_set(&intf->stats[i], 0);
29444 + atomic_set_unchecked(&intf->stats[i], 0);
29445
29446 intf->proc_dir = NULL;
29447
29448 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29449 index 50fcf9c..91b5528 100644
29450 --- a/drivers/char/ipmi/ipmi_si_intf.c
29451 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29452 @@ -277,7 +277,7 @@ struct smi_info {
29453 unsigned char slave_addr;
29454
29455 /* Counters and things for the proc filesystem. */
29456 - atomic_t stats[SI_NUM_STATS];
29457 + atomic_unchecked_t stats[SI_NUM_STATS];
29458
29459 struct task_struct *thread;
29460
29461 @@ -286,9 +286,9 @@ struct smi_info {
29462 };
29463
29464 #define smi_inc_stat(smi, stat) \
29465 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29466 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29467 #define smi_get_stat(smi, stat) \
29468 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29469 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29470
29471 #define SI_MAX_PARMS 4
29472
29473 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
29474 atomic_set(&new_smi->req_events, 0);
29475 new_smi->run_to_completion = 0;
29476 for (i = 0; i < SI_NUM_STATS; i++)
29477 - atomic_set(&new_smi->stats[i], 0);
29478 + atomic_set_unchecked(&new_smi->stats[i], 0);
29479
29480 new_smi->interrupt_disabled = 1;
29481 atomic_set(&new_smi->stop_operation, 0);
29482 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29483 index 1aeaaba..e018570 100644
29484 --- a/drivers/char/mbcs.c
29485 +++ b/drivers/char/mbcs.c
29486 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
29487 return 0;
29488 }
29489
29490 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29491 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29492 {
29493 .part_num = MBCS_PART_NUM,
29494 .mfg_num = MBCS_MFG_NUM,
29495 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29496 index d6e9d08..4493e89 100644
29497 --- a/drivers/char/mem.c
29498 +++ b/drivers/char/mem.c
29499 @@ -18,6 +18,7 @@
29500 #include <linux/raw.h>
29501 #include <linux/tty.h>
29502 #include <linux/capability.h>
29503 +#include <linux/security.h>
29504 #include <linux/ptrace.h>
29505 #include <linux/device.h>
29506 #include <linux/highmem.h>
29507 @@ -35,6 +36,10 @@
29508 # include <linux/efi.h>
29509 #endif
29510
29511 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29512 +extern const struct file_operations grsec_fops;
29513 +#endif
29514 +
29515 static inline unsigned long size_inside_page(unsigned long start,
29516 unsigned long size)
29517 {
29518 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29519
29520 while (cursor < to) {
29521 if (!devmem_is_allowed(pfn)) {
29522 +#ifdef CONFIG_GRKERNSEC_KMEM
29523 + gr_handle_mem_readwrite(from, to);
29524 +#else
29525 printk(KERN_INFO
29526 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29527 current->comm, from, to);
29528 +#endif
29529 return 0;
29530 }
29531 cursor += PAGE_SIZE;
29532 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29533 }
29534 return 1;
29535 }
29536 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29537 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29538 +{
29539 + return 0;
29540 +}
29541 #else
29542 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29543 {
29544 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29545
29546 while (count > 0) {
29547 unsigned long remaining;
29548 + char *temp;
29549
29550 sz = size_inside_page(p, count);
29551
29552 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29553 if (!ptr)
29554 return -EFAULT;
29555
29556 - remaining = copy_to_user(buf, ptr, sz);
29557 +#ifdef CONFIG_PAX_USERCOPY
29558 + temp = kmalloc(sz, GFP_KERNEL);
29559 + if (!temp) {
29560 + unxlate_dev_mem_ptr(p, ptr);
29561 + return -ENOMEM;
29562 + }
29563 + memcpy(temp, ptr, sz);
29564 +#else
29565 + temp = ptr;
29566 +#endif
29567 +
29568 + remaining = copy_to_user(buf, temp, sz);
29569 +
29570 +#ifdef CONFIG_PAX_USERCOPY
29571 + kfree(temp);
29572 +#endif
29573 +
29574 unxlate_dev_mem_ptr(p, ptr);
29575 if (remaining)
29576 return -EFAULT;
29577 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29578 size_t count, loff_t *ppos)
29579 {
29580 unsigned long p = *ppos;
29581 - ssize_t low_count, read, sz;
29582 + ssize_t low_count, read, sz, err = 0;
29583 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29584 - int err = 0;
29585
29586 read = 0;
29587 if (p < (unsigned long) high_memory) {
29588 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29589 }
29590 #endif
29591 while (low_count > 0) {
29592 + char *temp;
29593 +
29594 sz = size_inside_page(p, low_count);
29595
29596 /*
29597 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29598 */
29599 kbuf = xlate_dev_kmem_ptr((char *)p);
29600
29601 - if (copy_to_user(buf, kbuf, sz))
29602 +#ifdef CONFIG_PAX_USERCOPY
29603 + temp = kmalloc(sz, GFP_KERNEL);
29604 + if (!temp)
29605 + return -ENOMEM;
29606 + memcpy(temp, kbuf, sz);
29607 +#else
29608 + temp = kbuf;
29609 +#endif
29610 +
29611 + err = copy_to_user(buf, temp, sz);
29612 +
29613 +#ifdef CONFIG_PAX_USERCOPY
29614 + kfree(temp);
29615 +#endif
29616 +
29617 + if (err)
29618 return -EFAULT;
29619 buf += sz;
29620 p += sz;
29621 @@ -867,6 +914,9 @@ static const struct memdev {
29622 #ifdef CONFIG_CRASH_DUMP
29623 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29624 #endif
29625 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29626 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29627 +#endif
29628 };
29629
29630 static int memory_open(struct inode *inode, struct file *filp)
29631 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29632 index da3cfee..a5a6606 100644
29633 --- a/drivers/char/nvram.c
29634 +++ b/drivers/char/nvram.c
29635 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29636
29637 spin_unlock_irq(&rtc_lock);
29638
29639 - if (copy_to_user(buf, contents, tmp - contents))
29640 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29641 return -EFAULT;
29642
29643 *ppos = i;
29644 diff --git a/drivers/char/random.c b/drivers/char/random.c
29645 index 54ca8b2..4a092ed 100644
29646 --- a/drivers/char/random.c
29647 +++ b/drivers/char/random.c
29648 @@ -261,8 +261,13 @@
29649 /*
29650 * Configuration information
29651 */
29652 +#ifdef CONFIG_GRKERNSEC_RANDNET
29653 +#define INPUT_POOL_WORDS 512
29654 +#define OUTPUT_POOL_WORDS 128
29655 +#else
29656 #define INPUT_POOL_WORDS 128
29657 #define OUTPUT_POOL_WORDS 32
29658 +#endif
29659 #define SEC_XFER_SIZE 512
29660 #define EXTRACT_SIZE 10
29661
29662 @@ -300,10 +305,17 @@ static struct poolinfo {
29663 int poolwords;
29664 int tap1, tap2, tap3, tap4, tap5;
29665 } poolinfo_table[] = {
29666 +#ifdef CONFIG_GRKERNSEC_RANDNET
29667 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29668 + { 512, 411, 308, 208, 104, 1 },
29669 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29670 + { 128, 103, 76, 51, 25, 1 },
29671 +#else
29672 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29673 { 128, 103, 76, 51, 25, 1 },
29674 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29675 { 32, 26, 20, 14, 7, 1 },
29676 +#endif
29677 #if 0
29678 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29679 { 2048, 1638, 1231, 819, 411, 1 },
29680 @@ -913,7 +925,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29681
29682 extract_buf(r, tmp);
29683 i = min_t(int, nbytes, EXTRACT_SIZE);
29684 - if (copy_to_user(buf, tmp, i)) {
29685 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29686 ret = -EFAULT;
29687 break;
29688 }
29689 @@ -1238,7 +1250,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29690 #include <linux/sysctl.h>
29691
29692 static int min_read_thresh = 8, min_write_thresh;
29693 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29694 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29695 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29696 static char sysctl_bootid[16];
29697
29698 @@ -1260,10 +1272,15 @@ static int proc_do_uuid(ctl_table *table, int write,
29699 uuid = table->data;
29700 if (!uuid) {
29701 uuid = tmp_uuid;
29702 - uuid[8] = 0;
29703 - }
29704 - if (uuid[8] == 0)
29705 generate_random_uuid(uuid);
29706 + } else {
29707 + static DEFINE_SPINLOCK(bootid_spinlock);
29708 +
29709 + spin_lock(&bootid_spinlock);
29710 + if (!uuid[8])
29711 + generate_random_uuid(uuid);
29712 + spin_unlock(&bootid_spinlock);
29713 + }
29714
29715 sprintf(buf, "%pU", uuid);
29716
29717 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29718 index 1ee8ce7..b778bef 100644
29719 --- a/drivers/char/sonypi.c
29720 +++ b/drivers/char/sonypi.c
29721 @@ -55,6 +55,7 @@
29722 #include <asm/uaccess.h>
29723 #include <asm/io.h>
29724 #include <asm/system.h>
29725 +#include <asm/local.h>
29726
29727 #include <linux/sonypi.h>
29728
29729 @@ -491,7 +492,7 @@ static struct sonypi_device {
29730 spinlock_t fifo_lock;
29731 wait_queue_head_t fifo_proc_list;
29732 struct fasync_struct *fifo_async;
29733 - int open_count;
29734 + local_t open_count;
29735 int model;
29736 struct input_dev *input_jog_dev;
29737 struct input_dev *input_key_dev;
29738 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29739 static int sonypi_misc_release(struct inode *inode, struct file *file)
29740 {
29741 mutex_lock(&sonypi_device.lock);
29742 - sonypi_device.open_count--;
29743 + local_dec(&sonypi_device.open_count);
29744 mutex_unlock(&sonypi_device.lock);
29745 return 0;
29746 }
29747 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29748 {
29749 mutex_lock(&sonypi_device.lock);
29750 /* Flush input queue on first open */
29751 - if (!sonypi_device.open_count)
29752 + if (!local_read(&sonypi_device.open_count))
29753 kfifo_reset(&sonypi_device.fifo);
29754 - sonypi_device.open_count++;
29755 + local_inc(&sonypi_device.open_count);
29756 mutex_unlock(&sonypi_device.lock);
29757
29758 return 0;
29759 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29760 index ad7c732..5aa8054 100644
29761 --- a/drivers/char/tpm/tpm.c
29762 +++ b/drivers/char/tpm/tpm.c
29763 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
29764 chip->vendor.req_complete_val)
29765 goto out_recv;
29766
29767 - if ((status == chip->vendor.req_canceled)) {
29768 + if (status == chip->vendor.req_canceled) {
29769 dev_err(chip->dev, "Operation Canceled\n");
29770 rc = -ECANCELED;
29771 goto out;
29772 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
29773 index 0636520..169c1d0 100644
29774 --- a/drivers/char/tpm/tpm_bios.c
29775 +++ b/drivers/char/tpm/tpm_bios.c
29776 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
29777 event = addr;
29778
29779 if ((event->event_type == 0 && event->event_size == 0) ||
29780 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
29781 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
29782 return NULL;
29783
29784 return addr;
29785 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
29786 return NULL;
29787
29788 if ((event->event_type == 0 && event->event_size == 0) ||
29789 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
29790 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
29791 return NULL;
29792
29793 (*pos)++;
29794 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
29795 int i;
29796
29797 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
29798 - seq_putc(m, data[i]);
29799 + if (!seq_putc(m, data[i]))
29800 + return -EFAULT;
29801
29802 return 0;
29803 }
29804 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
29805 log->bios_event_log_end = log->bios_event_log + len;
29806
29807 virt = acpi_os_map_memory(start, len);
29808 + if (!virt) {
29809 + kfree(log->bios_event_log);
29810 + log->bios_event_log = NULL;
29811 + return -EFAULT;
29812 + }
29813
29814 - memcpy(log->bios_event_log, virt, len);
29815 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
29816
29817 acpi_os_unmap_memory(virt, len);
29818 return 0;
29819 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
29820 index 41fc148..0dba6dd 100644
29821 --- a/drivers/char/virtio_console.c
29822 +++ b/drivers/char/virtio_console.c
29823 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
29824 if (to_user) {
29825 ssize_t ret;
29826
29827 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
29828 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
29829 if (ret)
29830 return -EFAULT;
29831 } else {
29832 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
29833 if (!port_has_data(port) && !port->host_connected)
29834 return 0;
29835
29836 - return fill_readbuf(port, ubuf, count, true);
29837 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
29838 }
29839
29840 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
29841 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
29842 index c9eee6d..f9d5280 100644
29843 --- a/drivers/edac/amd64_edac.c
29844 +++ b/drivers/edac/amd64_edac.c
29845 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
29846 * PCI core identifies what devices are on a system during boot, and then
29847 * inquiry this table to see if this driver is for a given device found.
29848 */
29849 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
29850 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
29851 {
29852 .vendor = PCI_VENDOR_ID_AMD,
29853 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
29854 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
29855 index e47e73b..348e0bd 100644
29856 --- a/drivers/edac/amd76x_edac.c
29857 +++ b/drivers/edac/amd76x_edac.c
29858 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
29859 edac_mc_free(mci);
29860 }
29861
29862 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
29863 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
29864 {
29865 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29866 AMD762},
29867 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
29868 index 1af531a..3a8ff27 100644
29869 --- a/drivers/edac/e752x_edac.c
29870 +++ b/drivers/edac/e752x_edac.c
29871 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
29872 edac_mc_free(mci);
29873 }
29874
29875 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
29876 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
29877 {
29878 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29879 E7520},
29880 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
29881 index 6ffb6d2..383d8d7 100644
29882 --- a/drivers/edac/e7xxx_edac.c
29883 +++ b/drivers/edac/e7xxx_edac.c
29884 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
29885 edac_mc_free(mci);
29886 }
29887
29888 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
29889 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
29890 {
29891 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29892 E7205},
29893 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
29894 index 97f5064..202b6e6 100644
29895 --- a/drivers/edac/edac_pci_sysfs.c
29896 +++ b/drivers/edac/edac_pci_sysfs.c
29897 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
29898 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
29899 static int edac_pci_poll_msec = 1000; /* one second workq period */
29900
29901 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
29902 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
29903 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
29904 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
29905
29906 static struct kobject *edac_pci_top_main_kobj;
29907 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
29908 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29909 edac_printk(KERN_CRIT, EDAC_PCI,
29910 "Signaled System Error on %s\n",
29911 pci_name(dev));
29912 - atomic_inc(&pci_nonparity_count);
29913 + atomic_inc_unchecked(&pci_nonparity_count);
29914 }
29915
29916 if (status & (PCI_STATUS_PARITY)) {
29917 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29918 "Master Data Parity Error on %s\n",
29919 pci_name(dev));
29920
29921 - atomic_inc(&pci_parity_count);
29922 + atomic_inc_unchecked(&pci_parity_count);
29923 }
29924
29925 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29926 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29927 "Detected Parity Error on %s\n",
29928 pci_name(dev));
29929
29930 - atomic_inc(&pci_parity_count);
29931 + atomic_inc_unchecked(&pci_parity_count);
29932 }
29933 }
29934
29935 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29936 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
29937 "Signaled System Error on %s\n",
29938 pci_name(dev));
29939 - atomic_inc(&pci_nonparity_count);
29940 + atomic_inc_unchecked(&pci_nonparity_count);
29941 }
29942
29943 if (status & (PCI_STATUS_PARITY)) {
29944 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29945 "Master Data Parity Error on "
29946 "%s\n", pci_name(dev));
29947
29948 - atomic_inc(&pci_parity_count);
29949 + atomic_inc_unchecked(&pci_parity_count);
29950 }
29951
29952 if (status & (PCI_STATUS_DETECTED_PARITY)) {
29953 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
29954 "Detected Parity Error on %s\n",
29955 pci_name(dev));
29956
29957 - atomic_inc(&pci_parity_count);
29958 + atomic_inc_unchecked(&pci_parity_count);
29959 }
29960 }
29961 }
29962 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
29963 if (!check_pci_errors)
29964 return;
29965
29966 - before_count = atomic_read(&pci_parity_count);
29967 + before_count = atomic_read_unchecked(&pci_parity_count);
29968
29969 /* scan all PCI devices looking for a Parity Error on devices and
29970 * bridges.
29971 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
29972 /* Only if operator has selected panic on PCI Error */
29973 if (edac_pci_get_panic_on_pe()) {
29974 /* If the count is different 'after' from 'before' */
29975 - if (before_count != atomic_read(&pci_parity_count))
29976 + if (before_count != atomic_read_unchecked(&pci_parity_count))
29977 panic("EDAC: PCI Parity Error");
29978 }
29979 }
29980 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
29981 index c0510b3..6e2a954 100644
29982 --- a/drivers/edac/i3000_edac.c
29983 +++ b/drivers/edac/i3000_edac.c
29984 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
29985 edac_mc_free(mci);
29986 }
29987
29988 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
29989 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
29990 {
29991 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
29992 I3000},
29993 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
29994 index 73f55e200..5faaf59 100644
29995 --- a/drivers/edac/i3200_edac.c
29996 +++ b/drivers/edac/i3200_edac.c
29997 @@ -445,7 +445,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
29998 edac_mc_free(mci);
29999 }
30000
30001 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
30002 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
30003 {
30004 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30005 I3200},
30006 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
30007 index 4dc3ac2..67d05a6 100644
30008 --- a/drivers/edac/i5000_edac.c
30009 +++ b/drivers/edac/i5000_edac.c
30010 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
30011 *
30012 * The "E500P" device is the first device supported.
30013 */
30014 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
30015 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
30016 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
30017 .driver_data = I5000P},
30018
30019 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
30020 index bcbdeec..9886d16 100644
30021 --- a/drivers/edac/i5100_edac.c
30022 +++ b/drivers/edac/i5100_edac.c
30023 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
30024 edac_mc_free(mci);
30025 }
30026
30027 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
30028 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
30029 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
30030 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
30031 { 0, }
30032 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
30033 index 74d6ec34..baff517 100644
30034 --- a/drivers/edac/i5400_edac.c
30035 +++ b/drivers/edac/i5400_edac.c
30036 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
30037 *
30038 * The "E500P" device is the first device supported.
30039 */
30040 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
30041 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
30042 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
30043 {0,} /* 0 terminated list. */
30044 };
30045 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
30046 index 6104dba..e7ea8e1 100644
30047 --- a/drivers/edac/i7300_edac.c
30048 +++ b/drivers/edac/i7300_edac.c
30049 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
30050 *
30051 * Has only 8086:360c PCI ID
30052 */
30053 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
30054 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
30055 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
30056 {0,} /* 0 terminated list. */
30057 };
30058 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
30059 index 8568d9b..42b2fa8 100644
30060 --- a/drivers/edac/i7core_edac.c
30061 +++ b/drivers/edac/i7core_edac.c
30062 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
30063 /*
30064 * pci_device_id table for which devices we are looking for
30065 */
30066 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
30067 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
30068 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
30069 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
30070 {0,} /* 0 terminated list. */
30071 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
30072 index 4329d39..f3022ef 100644
30073 --- a/drivers/edac/i82443bxgx_edac.c
30074 +++ b/drivers/edac/i82443bxgx_edac.c
30075 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
30076
30077 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
30078
30079 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
30080 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
30081 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
30082 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
30083 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
30084 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
30085 index 931a057..fd28340 100644
30086 --- a/drivers/edac/i82860_edac.c
30087 +++ b/drivers/edac/i82860_edac.c
30088 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
30089 edac_mc_free(mci);
30090 }
30091
30092 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
30093 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
30094 {
30095 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30096 I82860},
30097 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
30098 index 33864c6..01edc61 100644
30099 --- a/drivers/edac/i82875p_edac.c
30100 +++ b/drivers/edac/i82875p_edac.c
30101 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
30102 edac_mc_free(mci);
30103 }
30104
30105 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
30106 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
30107 {
30108 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30109 I82875P},
30110 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
30111 index 4184e01..dcb2cd3 100644
30112 --- a/drivers/edac/i82975x_edac.c
30113 +++ b/drivers/edac/i82975x_edac.c
30114 @@ -612,7 +612,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
30115 edac_mc_free(mci);
30116 }
30117
30118 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
30119 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
30120 {
30121 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30122 I82975X
30123 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30124 index 0106747..0b40417 100644
30125 --- a/drivers/edac/mce_amd.h
30126 +++ b/drivers/edac/mce_amd.h
30127 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
30128 bool (*dc_mce)(u16, u8);
30129 bool (*ic_mce)(u16, u8);
30130 bool (*nb_mce)(u16, u8);
30131 -};
30132 +} __no_const;
30133
30134 void amd_report_gart_errors(bool);
30135 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30136 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
30137 index e294e1b..a41b05b 100644
30138 --- a/drivers/edac/r82600_edac.c
30139 +++ b/drivers/edac/r82600_edac.c
30140 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
30141 edac_mc_free(mci);
30142 }
30143
30144 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
30145 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
30146 {
30147 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
30148 },
30149 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
30150 index 1dc118d..8c68af9 100644
30151 --- a/drivers/edac/sb_edac.c
30152 +++ b/drivers/edac/sb_edac.c
30153 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
30154 /*
30155 * pci_device_id table for which devices we are looking for
30156 */
30157 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
30158 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
30159 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
30160 {0,} /* 0 terminated list. */
30161 };
30162 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
30163 index b6f47de..c5acf3a 100644
30164 --- a/drivers/edac/x38_edac.c
30165 +++ b/drivers/edac/x38_edac.c
30166 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
30167 edac_mc_free(mci);
30168 }
30169
30170 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
30171 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
30172 {
30173 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
30174 X38},
30175 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30176 index 85661b0..c784559a 100644
30177 --- a/drivers/firewire/core-card.c
30178 +++ b/drivers/firewire/core-card.c
30179 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
30180
30181 void fw_core_remove_card(struct fw_card *card)
30182 {
30183 - struct fw_card_driver dummy_driver = dummy_driver_template;
30184 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30185
30186 card->driver->update_phy_reg(card, 4,
30187 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30188 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30189 index 4799393..37bd3ab 100644
30190 --- a/drivers/firewire/core-cdev.c
30191 +++ b/drivers/firewire/core-cdev.c
30192 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
30193 int ret;
30194
30195 if ((request->channels == 0 && request->bandwidth == 0) ||
30196 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30197 - request->bandwidth < 0)
30198 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30199 return -EINVAL;
30200
30201 r = kmalloc(sizeof(*r), GFP_KERNEL);
30202 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30203 index 855ab3f..11f4bbd 100644
30204 --- a/drivers/firewire/core-transaction.c
30205 +++ b/drivers/firewire/core-transaction.c
30206 @@ -37,6 +37,7 @@
30207 #include <linux/timer.h>
30208 #include <linux/types.h>
30209 #include <linux/workqueue.h>
30210 +#include <linux/sched.h>
30211
30212 #include <asm/byteorder.h>
30213
30214 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30215 index b45be57..5fad18b 100644
30216 --- a/drivers/firewire/core.h
30217 +++ b/drivers/firewire/core.h
30218 @@ -101,6 +101,7 @@ struct fw_card_driver {
30219
30220 int (*stop_iso)(struct fw_iso_context *ctx);
30221 };
30222 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30223
30224 void fw_card_initialize(struct fw_card *card,
30225 const struct fw_card_driver *driver, struct device *device);
30226 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30227 index 153980b..4b4d046 100644
30228 --- a/drivers/firmware/dmi_scan.c
30229 +++ b/drivers/firmware/dmi_scan.c
30230 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
30231 }
30232 }
30233 else {
30234 - /*
30235 - * no iounmap() for that ioremap(); it would be a no-op, but
30236 - * it's so early in setup that sucker gets confused into doing
30237 - * what it shouldn't if we actually call it.
30238 - */
30239 p = dmi_ioremap(0xF0000, 0x10000);
30240 if (p == NULL)
30241 goto error;
30242 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30243 if (buf == NULL)
30244 return -1;
30245
30246 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30247 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30248
30249 iounmap(buf);
30250 return 0;
30251 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30252 index 82d5c20..44a7177 100644
30253 --- a/drivers/gpio/gpio-vr41xx.c
30254 +++ b/drivers/gpio/gpio-vr41xx.c
30255 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30256 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30257 maskl, pendl, maskh, pendh);
30258
30259 - atomic_inc(&irq_err_count);
30260 + atomic_inc_unchecked(&irq_err_count);
30261
30262 return -EINVAL;
30263 }
30264 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30265 index 84a4a80..ce0306e 100644
30266 --- a/drivers/gpu/drm/drm_crtc_helper.c
30267 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30268 @@ -280,7 +280,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30269 struct drm_crtc *tmp;
30270 int crtc_mask = 1;
30271
30272 - WARN(!crtc, "checking null crtc?\n");
30273 + BUG_ON(!crtc);
30274
30275 dev = crtc->dev;
30276
30277 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30278 index ebf7d3f..d64c436 100644
30279 --- a/drivers/gpu/drm/drm_drv.c
30280 +++ b/drivers/gpu/drm/drm_drv.c
30281 @@ -312,7 +312,7 @@ module_exit(drm_core_exit);
30282 /**
30283 * Copy and IOCTL return string to user space
30284 */
30285 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30286 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30287 {
30288 int len;
30289
30290 @@ -391,7 +391,7 @@ long drm_ioctl(struct file *filp,
30291
30292 dev = file_priv->minor->dev;
30293 atomic_inc(&dev->ioctl_count);
30294 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30295 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30296 ++file_priv->ioctl_count;
30297
30298 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30299 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30300 index 6263b01..7987f55 100644
30301 --- a/drivers/gpu/drm/drm_fops.c
30302 +++ b/drivers/gpu/drm/drm_fops.c
30303 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30304 }
30305
30306 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30307 - atomic_set(&dev->counts[i], 0);
30308 + atomic_set_unchecked(&dev->counts[i], 0);
30309
30310 dev->sigdata.lock = NULL;
30311
30312 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
30313
30314 retcode = drm_open_helper(inode, filp, dev);
30315 if (!retcode) {
30316 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30317 - if (!dev->open_count++)
30318 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30319 + if (local_inc_return(&dev->open_count) == 1)
30320 retcode = drm_setup(dev);
30321 }
30322 if (!retcode) {
30323 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
30324
30325 mutex_lock(&drm_global_mutex);
30326
30327 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30328 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30329
30330 if (dev->driver->preclose)
30331 dev->driver->preclose(dev, file_priv);
30332 @@ -482,10 +482,10 @@ int drm_release(struct inode *inode, struct file *filp)
30333 * Begin inline drm_release
30334 */
30335
30336 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30337 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30338 task_pid_nr(current),
30339 (long)old_encode_dev(file_priv->minor->device),
30340 - dev->open_count);
30341 + local_read(&dev->open_count));
30342
30343 /* Release any auth tokens that might point to this file_priv,
30344 (do that under the drm_global_mutex) */
30345 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
30346 * End inline drm_release
30347 */
30348
30349 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30350 - if (!--dev->open_count) {
30351 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30352 + if (local_dec_and_test(&dev->open_count)) {
30353 if (atomic_read(&dev->ioctl_count)) {
30354 DRM_ERROR("Device busy: %d\n",
30355 atomic_read(&dev->ioctl_count));
30356 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30357 index c87dc96..326055d 100644
30358 --- a/drivers/gpu/drm/drm_global.c
30359 +++ b/drivers/gpu/drm/drm_global.c
30360 @@ -36,7 +36,7 @@
30361 struct drm_global_item {
30362 struct mutex mutex;
30363 void *object;
30364 - int refcount;
30365 + atomic_t refcount;
30366 };
30367
30368 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30369 @@ -49,7 +49,7 @@ void drm_global_init(void)
30370 struct drm_global_item *item = &glob[i];
30371 mutex_init(&item->mutex);
30372 item->object = NULL;
30373 - item->refcount = 0;
30374 + atomic_set(&item->refcount, 0);
30375 }
30376 }
30377
30378 @@ -59,7 +59,7 @@ void drm_global_release(void)
30379 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30380 struct drm_global_item *item = &glob[i];
30381 BUG_ON(item->object != NULL);
30382 - BUG_ON(item->refcount != 0);
30383 + BUG_ON(atomic_read(&item->refcount) != 0);
30384 }
30385 }
30386
30387 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30388 void *object;
30389
30390 mutex_lock(&item->mutex);
30391 - if (item->refcount == 0) {
30392 + if (atomic_read(&item->refcount) == 0) {
30393 item->object = kzalloc(ref->size, GFP_KERNEL);
30394 if (unlikely(item->object == NULL)) {
30395 ret = -ENOMEM;
30396 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30397 goto out_err;
30398
30399 }
30400 - ++item->refcount;
30401 + atomic_inc(&item->refcount);
30402 ref->object = item->object;
30403 object = item->object;
30404 mutex_unlock(&item->mutex);
30405 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30406 struct drm_global_item *item = &glob[ref->global_type];
30407
30408 mutex_lock(&item->mutex);
30409 - BUG_ON(item->refcount == 0);
30410 + BUG_ON(atomic_read(&item->refcount) == 0);
30411 BUG_ON(ref->object != item->object);
30412 - if (--item->refcount == 0) {
30413 + if (atomic_dec_and_test(&item->refcount)) {
30414 ref->release(ref);
30415 item->object = NULL;
30416 }
30417 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30418 index ab1162d..42587b2 100644
30419 --- a/drivers/gpu/drm/drm_info.c
30420 +++ b/drivers/gpu/drm/drm_info.c
30421 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30422 struct drm_local_map *map;
30423 struct drm_map_list *r_list;
30424
30425 - /* Hardcoded from _DRM_FRAME_BUFFER,
30426 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30427 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30428 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30429 + static const char * const types[] = {
30430 + [_DRM_FRAME_BUFFER] = "FB",
30431 + [_DRM_REGISTERS] = "REG",
30432 + [_DRM_SHM] = "SHM",
30433 + [_DRM_AGP] = "AGP",
30434 + [_DRM_SCATTER_GATHER] = "SG",
30435 + [_DRM_CONSISTENT] = "PCI",
30436 + [_DRM_GEM] = "GEM" };
30437 const char *type;
30438 int i;
30439
30440 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30441 map = r_list->map;
30442 if (!map)
30443 continue;
30444 - if (map->type < 0 || map->type > 5)
30445 + if (map->type >= ARRAY_SIZE(types))
30446 type = "??";
30447 else
30448 type = types[map->type];
30449 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30450 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30451 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30452 vma->vm_flags & VM_IO ? 'i' : '-',
30453 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30454 + 0);
30455 +#else
30456 vma->vm_pgoff);
30457 +#endif
30458
30459 #if defined(__i386__)
30460 pgprot = pgprot_val(vma->vm_page_prot);
30461 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30462 index 637fcc3..e890b33 100644
30463 --- a/drivers/gpu/drm/drm_ioc32.c
30464 +++ b/drivers/gpu/drm/drm_ioc32.c
30465 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30466 request = compat_alloc_user_space(nbytes);
30467 if (!access_ok(VERIFY_WRITE, request, nbytes))
30468 return -EFAULT;
30469 - list = (struct drm_buf_desc *) (request + 1);
30470 + list = (struct drm_buf_desc __user *) (request + 1);
30471
30472 if (__put_user(count, &request->count)
30473 || __put_user(list, &request->list))
30474 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30475 request = compat_alloc_user_space(nbytes);
30476 if (!access_ok(VERIFY_WRITE, request, nbytes))
30477 return -EFAULT;
30478 - list = (struct drm_buf_pub *) (request + 1);
30479 + list = (struct drm_buf_pub __user *) (request + 1);
30480
30481 if (__put_user(count, &request->count)
30482 || __put_user(list, &request->list))
30483 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30484 index 956fd38..e52167a 100644
30485 --- a/drivers/gpu/drm/drm_ioctl.c
30486 +++ b/drivers/gpu/drm/drm_ioctl.c
30487 @@ -251,7 +251,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30488 stats->data[i].value =
30489 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30490 else
30491 - stats->data[i].value = atomic_read(&dev->counts[i]);
30492 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30493 stats->data[i].type = dev->types[i];
30494 }
30495
30496 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30497 index c79c713..2048588 100644
30498 --- a/drivers/gpu/drm/drm_lock.c
30499 +++ b/drivers/gpu/drm/drm_lock.c
30500 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30501 if (drm_lock_take(&master->lock, lock->context)) {
30502 master->lock.file_priv = file_priv;
30503 master->lock.lock_time = jiffies;
30504 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30505 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30506 break; /* Got lock */
30507 }
30508
30509 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30510 return -EINVAL;
30511 }
30512
30513 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30514 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30515
30516 if (drm_lock_free(&master->lock, lock->context)) {
30517 /* FIXME: Should really bail out here. */
30518 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30519 index 7f4b4e1..bf4def2 100644
30520 --- a/drivers/gpu/drm/i810/i810_dma.c
30521 +++ b/drivers/gpu/drm/i810/i810_dma.c
30522 @@ -948,8 +948,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30523 dma->buflist[vertex->idx],
30524 vertex->discard, vertex->used);
30525
30526 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30527 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30528 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30529 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30530 sarea_priv->last_enqueue = dev_priv->counter - 1;
30531 sarea_priv->last_dispatch = (int)hw_status[5];
30532
30533 @@ -1109,8 +1109,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30534 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30535 mc->last_render);
30536
30537 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30538 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30539 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30540 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30541 sarea_priv->last_enqueue = dev_priv->counter - 1;
30542 sarea_priv->last_dispatch = (int)hw_status[5];
30543
30544 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30545 index c9339f4..f5e1b9d 100644
30546 --- a/drivers/gpu/drm/i810/i810_drv.h
30547 +++ b/drivers/gpu/drm/i810/i810_drv.h
30548 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30549 int page_flipping;
30550
30551 wait_queue_head_t irq_queue;
30552 - atomic_t irq_received;
30553 - atomic_t irq_emitted;
30554 + atomic_unchecked_t irq_received;
30555 + atomic_unchecked_t irq_emitted;
30556
30557 int front_offset;
30558 } drm_i810_private_t;
30559 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30560 index deaa657..e0fd296 100644
30561 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30562 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30563 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30564 I915_READ(GTIMR));
30565 }
30566 seq_printf(m, "Interrupts received: %d\n",
30567 - atomic_read(&dev_priv->irq_received));
30568 + atomic_read_unchecked(&dev_priv->irq_received));
30569 for (i = 0; i < I915_NUM_RINGS; i++) {
30570 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30571 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30572 @@ -1321,7 +1321,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
30573 return ret;
30574
30575 if (opregion->header)
30576 - seq_write(m, opregion->header, OPREGION_SIZE);
30577 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
30578
30579 mutex_unlock(&dev->struct_mutex);
30580
30581 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30582 index ddfe3d9..f6e6b21 100644
30583 --- a/drivers/gpu/drm/i915/i915_dma.c
30584 +++ b/drivers/gpu/drm/i915/i915_dma.c
30585 @@ -1175,7 +1175,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30586 bool can_switch;
30587
30588 spin_lock(&dev->count_lock);
30589 - can_switch = (dev->open_count == 0);
30590 + can_switch = (local_read(&dev->open_count) == 0);
30591 spin_unlock(&dev->count_lock);
30592 return can_switch;
30593 }
30594 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30595 index 9689ca3..294f9c1 100644
30596 --- a/drivers/gpu/drm/i915/i915_drv.h
30597 +++ b/drivers/gpu/drm/i915/i915_drv.h
30598 @@ -231,7 +231,7 @@ struct drm_i915_display_funcs {
30599 /* render clock increase/decrease */
30600 /* display clock increase/decrease */
30601 /* pll clock increase/decrease */
30602 -};
30603 +} __no_const;
30604
30605 struct intel_device_info {
30606 u8 gen;
30607 @@ -320,7 +320,7 @@ typedef struct drm_i915_private {
30608 int current_page;
30609 int page_flipping;
30610
30611 - atomic_t irq_received;
30612 + atomic_unchecked_t irq_received;
30613
30614 /* protects the irq masks */
30615 spinlock_t irq_lock;
30616 @@ -896,7 +896,7 @@ struct drm_i915_gem_object {
30617 * will be page flipped away on the next vblank. When it
30618 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30619 */
30620 - atomic_t pending_flip;
30621 + atomic_unchecked_t pending_flip;
30622 };
30623
30624 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30625 @@ -1276,7 +1276,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
30626 extern void intel_teardown_gmbus(struct drm_device *dev);
30627 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30628 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30629 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30630 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30631 {
30632 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30633 }
30634 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30635 index e159e33..cdcc663 100644
30636 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30637 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30638 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30639 i915_gem_clflush_object(obj);
30640
30641 if (obj->base.pending_write_domain)
30642 - cd->flips |= atomic_read(&obj->pending_flip);
30643 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30644
30645 /* The actual obj->write_domain will be updated with
30646 * pending_write_domain after we emit the accumulated flush for all
30647 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30648
30649 static int
30650 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30651 - int count)
30652 + unsigned int count)
30653 {
30654 - int i;
30655 + unsigned int i;
30656
30657 for (i = 0; i < count; i++) {
30658 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30659 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30660 index 307c5e6..a1e4216 100644
30661 --- a/drivers/gpu/drm/i915/i915_irq.c
30662 +++ b/drivers/gpu/drm/i915/i915_irq.c
30663 @@ -472,7 +472,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30664 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30665 struct drm_i915_master_private *master_priv;
30666
30667 - atomic_inc(&dev_priv->irq_received);
30668 + atomic_inc_unchecked(&dev_priv->irq_received);
30669
30670 /* disable master interrupt before clearing iir */
30671 de_ier = I915_READ(DEIER);
30672 @@ -563,7 +563,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30673 struct drm_i915_master_private *master_priv;
30674 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
30675
30676 - atomic_inc(&dev_priv->irq_received);
30677 + atomic_inc_unchecked(&dev_priv->irq_received);
30678
30679 if (IS_GEN6(dev))
30680 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
30681 @@ -1228,7 +1228,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
30682 int ret = IRQ_NONE, pipe;
30683 bool blc_event = false;
30684
30685 - atomic_inc(&dev_priv->irq_received);
30686 + atomic_inc_unchecked(&dev_priv->irq_received);
30687
30688 iir = I915_READ(IIR);
30689
30690 @@ -1740,7 +1740,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30691 {
30692 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30693
30694 - atomic_set(&dev_priv->irq_received, 0);
30695 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30696
30697 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30698 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30699 @@ -1929,7 +1929,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
30700 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30701 int pipe;
30702
30703 - atomic_set(&dev_priv->irq_received, 0);
30704 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30705
30706 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
30707 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
30708 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30709 index 9ab9b16..e5b1b8d 100644
30710 --- a/drivers/gpu/drm/i915/intel_display.c
30711 +++ b/drivers/gpu/drm/i915/intel_display.c
30712 @@ -2238,7 +2238,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
30713
30714 wait_event(dev_priv->pending_flip_queue,
30715 atomic_read(&dev_priv->mm.wedged) ||
30716 - atomic_read(&obj->pending_flip) == 0);
30717 + atomic_read_unchecked(&obj->pending_flip) == 0);
30718
30719 /* Big Hammer, we also need to ensure that any pending
30720 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30721 @@ -2859,7 +2859,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
30722 obj = to_intel_framebuffer(crtc->fb)->obj;
30723 dev_priv = crtc->dev->dev_private;
30724 wait_event(dev_priv->pending_flip_queue,
30725 - atomic_read(&obj->pending_flip) == 0);
30726 + atomic_read_unchecked(&obj->pending_flip) == 0);
30727 }
30728
30729 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
30730 @@ -7171,7 +7171,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30731
30732 atomic_clear_mask(1 << intel_crtc->plane,
30733 &obj->pending_flip.counter);
30734 - if (atomic_read(&obj->pending_flip) == 0)
30735 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30736 wake_up(&dev_priv->pending_flip_queue);
30737
30738 schedule_work(&work->work);
30739 @@ -7354,7 +7354,13 @@ static int intel_gen6_queue_flip(struct drm_device *dev,
30740 OUT_RING(fb->pitches[0] | obj->tiling_mode);
30741 OUT_RING(obj->gtt_offset);
30742
30743 - pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
30744 + /* Contrary to the suggestions in the documentation,
30745 + * "Enable Panel Fitter" does not seem to be required when page
30746 + * flipping with a non-native mode, and worse causes a normal
30747 + * modeset to fail.
30748 + * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
30749 + */
30750 + pf = 0;
30751 pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
30752 OUT_RING(pf | pipesrc);
30753 ADVANCE_LP_RING();
30754 @@ -7461,7 +7467,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30755 /* Block clients from rendering to the new back buffer until
30756 * the flip occurs and the object is no longer visible.
30757 */
30758 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30759 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30760
30761 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30762 if (ret)
30763 @@ -7475,7 +7481,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30764 return 0;
30765
30766 cleanup_pending:
30767 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30768 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30769 drm_gem_object_unreference(&work->old_fb_obj->base);
30770 drm_gem_object_unreference(&obj->base);
30771 mutex_unlock(&dev->struct_mutex);
30772 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30773 index 54558a0..2d97005 100644
30774 --- a/drivers/gpu/drm/mga/mga_drv.h
30775 +++ b/drivers/gpu/drm/mga/mga_drv.h
30776 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30777 u32 clear_cmd;
30778 u32 maccess;
30779
30780 - atomic_t vbl_received; /**< Number of vblanks received. */
30781 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30782 wait_queue_head_t fence_queue;
30783 - atomic_t last_fence_retired;
30784 + atomic_unchecked_t last_fence_retired;
30785 u32 next_fence_to_post;
30786
30787 unsigned int fb_cpp;
30788 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30789 index 2581202..f230a8d9 100644
30790 --- a/drivers/gpu/drm/mga/mga_irq.c
30791 +++ b/drivers/gpu/drm/mga/mga_irq.c
30792 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30793 if (crtc != 0)
30794 return 0;
30795
30796 - return atomic_read(&dev_priv->vbl_received);
30797 + return atomic_read_unchecked(&dev_priv->vbl_received);
30798 }
30799
30800
30801 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30802 /* VBLANK interrupt */
30803 if (status & MGA_VLINEPEN) {
30804 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30805 - atomic_inc(&dev_priv->vbl_received);
30806 + atomic_inc_unchecked(&dev_priv->vbl_received);
30807 drm_handle_vblank(dev, 0);
30808 handled = 1;
30809 }
30810 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30811 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30812 MGA_WRITE(MGA_PRIMEND, prim_end);
30813
30814 - atomic_inc(&dev_priv->last_fence_retired);
30815 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30816 DRM_WAKEUP(&dev_priv->fence_queue);
30817 handled = 1;
30818 }
30819 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30820 * using fences.
30821 */
30822 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30823 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30824 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30825 - *sequence) <= (1 << 23)));
30826
30827 *sequence = cur_fence;
30828 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30829 index e5cbead..6c354a3 100644
30830 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30831 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30832 @@ -199,7 +199,7 @@ struct methods {
30833 const char desc[8];
30834 void (*loadbios)(struct drm_device *, uint8_t *);
30835 const bool rw;
30836 -};
30837 +} __do_const;
30838
30839 static struct methods shadow_methods[] = {
30840 { "PRAMIN", load_vbios_pramin, true },
30841 @@ -5290,7 +5290,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30842 struct bit_table {
30843 const char id;
30844 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30845 -};
30846 +} __no_const;
30847
30848 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30849
30850 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30851 index b827098..c31a797 100644
30852 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30853 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30854 @@ -242,7 +242,7 @@ struct nouveau_channel {
30855 struct list_head pending;
30856 uint32_t sequence;
30857 uint32_t sequence_ack;
30858 - atomic_t last_sequence_irq;
30859 + atomic_unchecked_t last_sequence_irq;
30860 struct nouveau_vma vma;
30861 } fence;
30862
30863 @@ -323,7 +323,7 @@ struct nouveau_exec_engine {
30864 u32 handle, u16 class);
30865 void (*set_tile_region)(struct drm_device *dev, int i);
30866 void (*tlb_flush)(struct drm_device *, int engine);
30867 -};
30868 +} __no_const;
30869
30870 struct nouveau_instmem_engine {
30871 void *priv;
30872 @@ -345,13 +345,13 @@ struct nouveau_instmem_engine {
30873 struct nouveau_mc_engine {
30874 int (*init)(struct drm_device *dev);
30875 void (*takedown)(struct drm_device *dev);
30876 -};
30877 +} __no_const;
30878
30879 struct nouveau_timer_engine {
30880 int (*init)(struct drm_device *dev);
30881 void (*takedown)(struct drm_device *dev);
30882 uint64_t (*read)(struct drm_device *dev);
30883 -};
30884 +} __no_const;
30885
30886 struct nouveau_fb_engine {
30887 int num_tiles;
30888 @@ -566,7 +566,7 @@ struct nouveau_vram_engine {
30889 void (*put)(struct drm_device *, struct nouveau_mem **);
30890
30891 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30892 -};
30893 +} __no_const;
30894
30895 struct nouveau_engine {
30896 struct nouveau_instmem_engine instmem;
30897 @@ -714,7 +714,7 @@ struct drm_nouveau_private {
30898 struct drm_global_reference mem_global_ref;
30899 struct ttm_bo_global_ref bo_global_ref;
30900 struct ttm_bo_device bdev;
30901 - atomic_t validate_sequence;
30902 + atomic_unchecked_t validate_sequence;
30903 } ttm;
30904
30905 struct {
30906 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
30907 index 2f6daae..c9d7b9e 100644
30908 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
30909 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
30910 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
30911 if (USE_REFCNT(dev))
30912 sequence = nvchan_rd32(chan, 0x48);
30913 else
30914 - sequence = atomic_read(&chan->fence.last_sequence_irq);
30915 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
30916
30917 if (chan->fence.sequence_ack == sequence)
30918 goto out;
30919 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
30920 return ret;
30921 }
30922
30923 - atomic_set(&chan->fence.last_sequence_irq, 0);
30924 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
30925 return 0;
30926 }
30927
30928 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30929 index 7ce3fde..cb3ea04 100644
30930 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30931 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30932 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30933 int trycnt = 0;
30934 int ret, i;
30935
30936 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30937 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30938 retry:
30939 if (++trycnt > 100000) {
30940 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30941 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30942 index f80c5e0..936baa7 100644
30943 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30944 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30945 @@ -543,7 +543,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30946 bool can_switch;
30947
30948 spin_lock(&dev->count_lock);
30949 - can_switch = (dev->open_count == 0);
30950 + can_switch = (local_read(&dev->open_count) == 0);
30951 spin_unlock(&dev->count_lock);
30952 return can_switch;
30953 }
30954 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
30955 index dbdea8e..cd6eeeb 100644
30956 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
30957 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
30958 @@ -554,7 +554,7 @@ static int
30959 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
30960 u32 class, u32 mthd, u32 data)
30961 {
30962 - atomic_set(&chan->fence.last_sequence_irq, data);
30963 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
30964 return 0;
30965 }
30966
30967 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30968 index bcac90b..53bfc76 100644
30969 --- a/drivers/gpu/drm/r128/r128_cce.c
30970 +++ b/drivers/gpu/drm/r128/r128_cce.c
30971 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30972
30973 /* GH: Simple idle check.
30974 */
30975 - atomic_set(&dev_priv->idle_count, 0);
30976 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30977
30978 /* We don't support anything other than bus-mastering ring mode,
30979 * but the ring can be in either AGP or PCI space for the ring
30980 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30981 index 930c71b..499aded 100644
30982 --- a/drivers/gpu/drm/r128/r128_drv.h
30983 +++ b/drivers/gpu/drm/r128/r128_drv.h
30984 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
30985 int is_pci;
30986 unsigned long cce_buffers_offset;
30987
30988 - atomic_t idle_count;
30989 + atomic_unchecked_t idle_count;
30990
30991 int page_flipping;
30992 int current_page;
30993 u32 crtc_offset;
30994 u32 crtc_offset_cntl;
30995
30996 - atomic_t vbl_received;
30997 + atomic_unchecked_t vbl_received;
30998
30999 u32 color_fmt;
31000 unsigned int front_offset;
31001 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31002 index 429d5a0..7e899ed 100644
31003 --- a/drivers/gpu/drm/r128/r128_irq.c
31004 +++ b/drivers/gpu/drm/r128/r128_irq.c
31005 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31006 if (crtc != 0)
31007 return 0;
31008
31009 - return atomic_read(&dev_priv->vbl_received);
31010 + return atomic_read_unchecked(&dev_priv->vbl_received);
31011 }
31012
31013 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31014 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31015 /* VBLANK interrupt */
31016 if (status & R128_CRTC_VBLANK_INT) {
31017 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31018 - atomic_inc(&dev_priv->vbl_received);
31019 + atomic_inc_unchecked(&dev_priv->vbl_received);
31020 drm_handle_vblank(dev, 0);
31021 return IRQ_HANDLED;
31022 }
31023 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31024 index a9e33ce..09edd4b 100644
31025 --- a/drivers/gpu/drm/r128/r128_state.c
31026 +++ b/drivers/gpu/drm/r128/r128_state.c
31027 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31028
31029 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31030 {
31031 - if (atomic_read(&dev_priv->idle_count) == 0)
31032 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31033 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31034 else
31035 - atomic_set(&dev_priv->idle_count, 0);
31036 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31037 }
31038
31039 #endif
31040 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31041 index 5a82b6b..9e69c73 100644
31042 --- a/drivers/gpu/drm/radeon/mkregtable.c
31043 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31044 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31045 regex_t mask_rex;
31046 regmatch_t match[4];
31047 char buf[1024];
31048 - size_t end;
31049 + long end;
31050 int len;
31051 int done = 0;
31052 int r;
31053 unsigned o;
31054 struct offset *offset;
31055 char last_reg_s[10];
31056 - int last_reg;
31057 + unsigned long last_reg;
31058
31059 if (regcomp
31060 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31061 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31062 index 1668ec1..30ebdab 100644
31063 --- a/drivers/gpu/drm/radeon/radeon.h
31064 +++ b/drivers/gpu/drm/radeon/radeon.h
31065 @@ -250,7 +250,7 @@ struct radeon_fence_driver {
31066 uint32_t scratch_reg;
31067 uint64_t gpu_addr;
31068 volatile uint32_t *cpu_addr;
31069 - atomic_t seq;
31070 + atomic_unchecked_t seq;
31071 uint32_t last_seq;
31072 unsigned long last_jiffies;
31073 unsigned long last_timeout;
31074 @@ -752,7 +752,7 @@ struct r600_blit_cp_primitives {
31075 int x2, int y2);
31076 void (*draw_auto)(struct radeon_device *rdev);
31077 void (*set_default_state)(struct radeon_device *rdev);
31078 -};
31079 +} __no_const;
31080
31081 struct r600_blit {
31082 struct mutex mutex;
31083 @@ -1201,7 +1201,7 @@ struct radeon_asic {
31084 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
31085 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31086 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31087 -};
31088 +} __no_const;
31089
31090 /*
31091 * Asic structures
31092 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31093 index 49f7cb7..2fcb48f 100644
31094 --- a/drivers/gpu/drm/radeon/radeon_device.c
31095 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31096 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31097 bool can_switch;
31098
31099 spin_lock(&dev->count_lock);
31100 - can_switch = (dev->open_count == 0);
31101 + can_switch = (local_read(&dev->open_count) == 0);
31102 spin_unlock(&dev->count_lock);
31103 return can_switch;
31104 }
31105 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31106 index a1b59ca..86f2d44 100644
31107 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31108 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31109 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31110
31111 /* SW interrupt */
31112 wait_queue_head_t swi_queue;
31113 - atomic_t swi_emitted;
31114 + atomic_unchecked_t swi_emitted;
31115 int vblank_crtc;
31116 uint32_t irq_enable_reg;
31117 uint32_t r500_disp_irq_reg;
31118 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
31119 index 4bd36a3..e66fe9c 100644
31120 --- a/drivers/gpu/drm/radeon/radeon_fence.c
31121 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
31122 @@ -70,7 +70,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
31123 write_unlock_irqrestore(&rdev->fence_lock, irq_flags);
31124 return 0;
31125 }
31126 - fence->seq = atomic_add_return(1, &rdev->fence_drv[fence->ring].seq);
31127 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv[fence->ring].seq);
31128 if (!rdev->ring[fence->ring].ready)
31129 /* FIXME: cp is not running assume everythings is done right
31130 * away
31131 @@ -405,7 +405,7 @@ int radeon_fence_driver_start_ring(struct radeon_device *rdev, int ring)
31132 }
31133 rdev->fence_drv[ring].cpu_addr = &rdev->wb.wb[index/4];
31134 rdev->fence_drv[ring].gpu_addr = rdev->wb.gpu_addr + index;
31135 - radeon_fence_write(rdev, atomic_read(&rdev->fence_drv[ring].seq), ring);
31136 + radeon_fence_write(rdev, atomic_read_unchecked(&rdev->fence_drv[ring].seq), ring);
31137 rdev->fence_drv[ring].initialized = true;
31138 DRM_INFO("fence driver on ring %d use gpu addr 0x%08Lx and cpu addr 0x%p\n",
31139 ring, rdev->fence_drv[ring].gpu_addr, rdev->fence_drv[ring].cpu_addr);
31140 @@ -418,7 +418,7 @@ static void radeon_fence_driver_init_ring(struct radeon_device *rdev, int ring)
31141 rdev->fence_drv[ring].scratch_reg = -1;
31142 rdev->fence_drv[ring].cpu_addr = NULL;
31143 rdev->fence_drv[ring].gpu_addr = 0;
31144 - atomic_set(&rdev->fence_drv[ring].seq, 0);
31145 + atomic_set_unchecked(&rdev->fence_drv[ring].seq, 0);
31146 INIT_LIST_HEAD(&rdev->fence_drv[ring].created);
31147 INIT_LIST_HEAD(&rdev->fence_drv[ring].emitted);
31148 INIT_LIST_HEAD(&rdev->fence_drv[ring].signaled);
31149 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31150 index 48b7cea..342236f 100644
31151 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31152 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31153 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31154 request = compat_alloc_user_space(sizeof(*request));
31155 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31156 || __put_user(req32.param, &request->param)
31157 - || __put_user((void __user *)(unsigned long)req32.value,
31158 + || __put_user((unsigned long)req32.value,
31159 &request->value))
31160 return -EFAULT;
31161
31162 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31163 index 00da384..32f972d 100644
31164 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31165 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31166 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31167 unsigned int ret;
31168 RING_LOCALS;
31169
31170 - atomic_inc(&dev_priv->swi_emitted);
31171 - ret = atomic_read(&dev_priv->swi_emitted);
31172 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31173 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31174
31175 BEGIN_RING(4);
31176 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31177 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31178 drm_radeon_private_t *dev_priv =
31179 (drm_radeon_private_t *) dev->dev_private;
31180
31181 - atomic_set(&dev_priv->swi_emitted, 0);
31182 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31183 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31184
31185 dev->max_vblank_count = 0x001fffff;
31186 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31187 index e8422ae..d22d4a8 100644
31188 --- a/drivers/gpu/drm/radeon/radeon_state.c
31189 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31190 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31191 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31192 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31193
31194 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31195 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31196 sarea_priv->nbox * sizeof(depth_boxes[0])))
31197 return -EFAULT;
31198
31199 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31200 {
31201 drm_radeon_private_t *dev_priv = dev->dev_private;
31202 drm_radeon_getparam_t *param = data;
31203 - int value;
31204 + int value = 0;
31205
31206 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31207
31208 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31209 index c421e77..e6bf2e8 100644
31210 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31211 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31212 @@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31213 }
31214 if (unlikely(ttm_vm_ops == NULL)) {
31215 ttm_vm_ops = vma->vm_ops;
31216 - radeon_ttm_vm_ops = *ttm_vm_ops;
31217 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31218 + pax_open_kernel();
31219 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31220 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31221 + pax_close_kernel();
31222 }
31223 vma->vm_ops = &radeon_ttm_vm_ops;
31224 return 0;
31225 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31226 index f68dff2..8df955c 100644
31227 --- a/drivers/gpu/drm/radeon/rs690.c
31228 +++ b/drivers/gpu/drm/radeon/rs690.c
31229 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31230 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31231 rdev->pm.sideport_bandwidth.full)
31232 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31233 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31234 + read_delay_latency.full = dfixed_const(800 * 1000);
31235 read_delay_latency.full = dfixed_div(read_delay_latency,
31236 rdev->pm.igp_sideport_mclk);
31237 + a.full = dfixed_const(370);
31238 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31239 } else {
31240 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31241 rdev->pm.k8_bandwidth.full)
31242 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31243 index 499debd..66fce72 100644
31244 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31245 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31246 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
31247 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31248 struct shrink_control *sc)
31249 {
31250 - static atomic_t start_pool = ATOMIC_INIT(0);
31251 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31252 unsigned i;
31253 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31254 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31255 struct ttm_page_pool *pool;
31256 int shrink_pages = sc->nr_to_scan;
31257
31258 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31259 index 88edacc..1e5412b 100644
31260 --- a/drivers/gpu/drm/via/via_drv.h
31261 +++ b/drivers/gpu/drm/via/via_drv.h
31262 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31263 typedef uint32_t maskarray_t[5];
31264
31265 typedef struct drm_via_irq {
31266 - atomic_t irq_received;
31267 + atomic_unchecked_t irq_received;
31268 uint32_t pending_mask;
31269 uint32_t enable_mask;
31270 wait_queue_head_t irq_queue;
31271 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31272 struct timeval last_vblank;
31273 int last_vblank_valid;
31274 unsigned usec_per_vblank;
31275 - atomic_t vbl_received;
31276 + atomic_unchecked_t vbl_received;
31277 drm_via_state_t hc_state;
31278 char pci_buf[VIA_PCI_BUF_SIZE];
31279 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31280 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31281 index d391f48..10c8ca3 100644
31282 --- a/drivers/gpu/drm/via/via_irq.c
31283 +++ b/drivers/gpu/drm/via/via_irq.c
31284 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31285 if (crtc != 0)
31286 return 0;
31287
31288 - return atomic_read(&dev_priv->vbl_received);
31289 + return atomic_read_unchecked(&dev_priv->vbl_received);
31290 }
31291
31292 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31293 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31294
31295 status = VIA_READ(VIA_REG_INTERRUPT);
31296 if (status & VIA_IRQ_VBLANK_PENDING) {
31297 - atomic_inc(&dev_priv->vbl_received);
31298 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31299 + atomic_inc_unchecked(&dev_priv->vbl_received);
31300 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31301 do_gettimeofday(&cur_vblank);
31302 if (dev_priv->last_vblank_valid) {
31303 dev_priv->usec_per_vblank =
31304 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31305 dev_priv->last_vblank = cur_vblank;
31306 dev_priv->last_vblank_valid = 1;
31307 }
31308 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31309 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31310 DRM_DEBUG("US per vblank is: %u\n",
31311 dev_priv->usec_per_vblank);
31312 }
31313 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31314
31315 for (i = 0; i < dev_priv->num_irqs; ++i) {
31316 if (status & cur_irq->pending_mask) {
31317 - atomic_inc(&cur_irq->irq_received);
31318 + atomic_inc_unchecked(&cur_irq->irq_received);
31319 DRM_WAKEUP(&cur_irq->irq_queue);
31320 handled = 1;
31321 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31322 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31323 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31324 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31325 masks[irq][4]));
31326 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31327 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31328 } else {
31329 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31330 (((cur_irq_sequence =
31331 - atomic_read(&cur_irq->irq_received)) -
31332 + atomic_read_unchecked(&cur_irq->irq_received)) -
31333 *sequence) <= (1 << 23)));
31334 }
31335 *sequence = cur_irq_sequence;
31336 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31337 }
31338
31339 for (i = 0; i < dev_priv->num_irqs; ++i) {
31340 - atomic_set(&cur_irq->irq_received, 0);
31341 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31342 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31343 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31344 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31345 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31346 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31347 case VIA_IRQ_RELATIVE:
31348 irqwait->request.sequence +=
31349 - atomic_read(&cur_irq->irq_received);
31350 + atomic_read_unchecked(&cur_irq->irq_received);
31351 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31352 case VIA_IRQ_ABSOLUTE:
31353 break;
31354 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31355 index dc27970..f18b008 100644
31356 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31357 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31358 @@ -260,7 +260,7 @@ struct vmw_private {
31359 * Fencing and IRQs.
31360 */
31361
31362 - atomic_t marker_seq;
31363 + atomic_unchecked_t marker_seq;
31364 wait_queue_head_t fence_queue;
31365 wait_queue_head_t fifo_queue;
31366 int fence_queue_waiters; /* Protected by hw_mutex */
31367 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31368 index a0c2f12..68ae6cb 100644
31369 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31370 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31371 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31372 (unsigned int) min,
31373 (unsigned int) fifo->capabilities);
31374
31375 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31376 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31377 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31378 vmw_marker_queue_init(&fifo->marker_queue);
31379 return vmw_fifo_send_fence(dev_priv, &dummy);
31380 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31381 if (reserveable)
31382 iowrite32(bytes, fifo_mem +
31383 SVGA_FIFO_RESERVED);
31384 - return fifo_mem + (next_cmd >> 2);
31385 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31386 } else {
31387 need_bounce = true;
31388 }
31389 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31390
31391 fm = vmw_fifo_reserve(dev_priv, bytes);
31392 if (unlikely(fm == NULL)) {
31393 - *seqno = atomic_read(&dev_priv->marker_seq);
31394 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31395 ret = -ENOMEM;
31396 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31397 false, 3*HZ);
31398 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31399 }
31400
31401 do {
31402 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31403 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31404 } while (*seqno == 0);
31405
31406 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31407 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31408 index cabc95f..14b3d77 100644
31409 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31410 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31411 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31412 * emitted. Then the fence is stale and signaled.
31413 */
31414
31415 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31416 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31417 > VMW_FENCE_WRAP);
31418
31419 return ret;
31420 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31421
31422 if (fifo_idle)
31423 down_read(&fifo_state->rwsem);
31424 - signal_seq = atomic_read(&dev_priv->marker_seq);
31425 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31426 ret = 0;
31427
31428 for (;;) {
31429 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31430 index 8a8725c..afed796 100644
31431 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31432 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31433 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31434 while (!vmw_lag_lt(queue, us)) {
31435 spin_lock(&queue->lock);
31436 if (list_empty(&queue->head))
31437 - seqno = atomic_read(&dev_priv->marker_seq);
31438 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31439 else {
31440 marker = list_first_entry(&queue->head,
31441 struct vmw_marker, head);
31442 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31443 index 75dbe34..f9204a8 100644
31444 --- a/drivers/hid/hid-core.c
31445 +++ b/drivers/hid/hid-core.c
31446 @@ -2021,7 +2021,7 @@ static bool hid_ignore(struct hid_device *hdev)
31447
31448 int hid_add_device(struct hid_device *hdev)
31449 {
31450 - static atomic_t id = ATOMIC_INIT(0);
31451 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31452 int ret;
31453
31454 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31455 @@ -2036,7 +2036,7 @@ int hid_add_device(struct hid_device *hdev)
31456 /* XXX hack, any other cleaner solution after the driver core
31457 * is converted to allow more than 20 bytes as the device name? */
31458 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31459 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31460 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31461
31462 hid_debug_register(hdev, dev_name(&hdev->dev));
31463 ret = device_add(&hdev->dev);
31464 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31465 index 17dabc1..bf248eb 100644
31466 --- a/drivers/hid/hid-wiimote-debug.c
31467 +++ b/drivers/hid/hid-wiimote-debug.c
31468 @@ -72,7 +72,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31469 else if (size == 0)
31470 return -EIO;
31471
31472 - if (copy_to_user(u, buf, size))
31473 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31474 return -EFAULT;
31475
31476 *off += size;
31477 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31478 index b1ec0e2..c295a61 100644
31479 --- a/drivers/hid/usbhid/hiddev.c
31480 +++ b/drivers/hid/usbhid/hiddev.c
31481 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31482 break;
31483
31484 case HIDIOCAPPLICATION:
31485 - if (arg < 0 || arg >= hid->maxapplication)
31486 + if (arg >= hid->maxapplication)
31487 break;
31488
31489 for (i = 0; i < hid->maxcollection; i++)
31490 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31491 index 4065374..10ed7dc 100644
31492 --- a/drivers/hv/channel.c
31493 +++ b/drivers/hv/channel.c
31494 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31495 int ret = 0;
31496 int t;
31497
31498 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31499 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31500 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31501 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31502
31503 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31504 if (ret)
31505 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31506 index 12aa97f..c0679f7 100644
31507 --- a/drivers/hv/hv.c
31508 +++ b/drivers/hv/hv.c
31509 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31510 u64 output_address = (output) ? virt_to_phys(output) : 0;
31511 u32 output_address_hi = output_address >> 32;
31512 u32 output_address_lo = output_address & 0xFFFFFFFF;
31513 - void *hypercall_page = hv_context.hypercall_page;
31514 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31515
31516 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31517 "=a"(hv_status_lo) : "d" (control_hi),
31518 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31519 index 6d7d286..92b0873 100644
31520 --- a/drivers/hv/hyperv_vmbus.h
31521 +++ b/drivers/hv/hyperv_vmbus.h
31522 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
31523 struct vmbus_connection {
31524 enum vmbus_connect_state conn_state;
31525
31526 - atomic_t next_gpadl_handle;
31527 + atomic_unchecked_t next_gpadl_handle;
31528
31529 /*
31530 * Represents channel interrupts. Each bit position represents a
31531 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31532 index a220e57..428f54d 100644
31533 --- a/drivers/hv/vmbus_drv.c
31534 +++ b/drivers/hv/vmbus_drv.c
31535 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31536 {
31537 int ret = 0;
31538
31539 - static atomic_t device_num = ATOMIC_INIT(0);
31540 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31541
31542 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31543 - atomic_inc_return(&device_num));
31544 + atomic_inc_return_unchecked(&device_num));
31545
31546 child_device_obj->device.bus = &hv_bus;
31547 child_device_obj->device.parent = &hv_acpi_dev->dev;
31548 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31549 index 554f046..f8b4729 100644
31550 --- a/drivers/hwmon/acpi_power_meter.c
31551 +++ b/drivers/hwmon/acpi_power_meter.c
31552 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31553 return res;
31554
31555 temp /= 1000;
31556 - if (temp < 0)
31557 - return -EINVAL;
31558
31559 mutex_lock(&resource->lock);
31560 resource->trip[attr->index - 7] = temp;
31561 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31562 index 91fdd1f..b66a686 100644
31563 --- a/drivers/hwmon/sht15.c
31564 +++ b/drivers/hwmon/sht15.c
31565 @@ -166,7 +166,7 @@ struct sht15_data {
31566 int supply_uV;
31567 bool supply_uV_valid;
31568 struct work_struct update_supply_work;
31569 - atomic_t interrupt_handled;
31570 + atomic_unchecked_t interrupt_handled;
31571 };
31572
31573 /**
31574 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31575 return ret;
31576
31577 gpio_direction_input(data->pdata->gpio_data);
31578 - atomic_set(&data->interrupt_handled, 0);
31579 + atomic_set_unchecked(&data->interrupt_handled, 0);
31580
31581 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31582 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31583 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31584 /* Only relevant if the interrupt hasn't occurred. */
31585 - if (!atomic_read(&data->interrupt_handled))
31586 + if (!atomic_read_unchecked(&data->interrupt_handled))
31587 schedule_work(&data->read_work);
31588 }
31589 ret = wait_event_timeout(data->wait_queue,
31590 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31591
31592 /* First disable the interrupt */
31593 disable_irq_nosync(irq);
31594 - atomic_inc(&data->interrupt_handled);
31595 + atomic_inc_unchecked(&data->interrupt_handled);
31596 /* Then schedule a reading work struct */
31597 if (data->state != SHT15_READING_NOTHING)
31598 schedule_work(&data->read_work);
31599 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31600 * If not, then start the interrupt again - care here as could
31601 * have gone low in meantime so verify it hasn't!
31602 */
31603 - atomic_set(&data->interrupt_handled, 0);
31604 + atomic_set_unchecked(&data->interrupt_handled, 0);
31605 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31606 /* If still not occurred or another handler has been scheduled */
31607 if (gpio_get_value(data->pdata->gpio_data)
31608 - || atomic_read(&data->interrupt_handled))
31609 + || atomic_read_unchecked(&data->interrupt_handled))
31610 return;
31611 }
31612
31613 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31614 index 378fcb5..5e91fa8 100644
31615 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31616 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31617 @@ -43,7 +43,7 @@
31618 extern struct i2c_adapter amd756_smbus;
31619
31620 static struct i2c_adapter *s4882_adapter;
31621 -static struct i2c_algorithm *s4882_algo;
31622 +static i2c_algorithm_no_const *s4882_algo;
31623
31624 /* Wrapper access functions for multiplexed SMBus */
31625 static DEFINE_MUTEX(amd756_lock);
31626 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31627 index 29015eb..af2d8e9 100644
31628 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31629 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31630 @@ -41,7 +41,7 @@
31631 extern struct i2c_adapter *nforce2_smbus;
31632
31633 static struct i2c_adapter *s4985_adapter;
31634 -static struct i2c_algorithm *s4985_algo;
31635 +static i2c_algorithm_no_const *s4985_algo;
31636
31637 /* Wrapper access functions for multiplexed SMBus */
31638 static DEFINE_MUTEX(nforce2_lock);
31639 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31640 index d7a4833..7fae376 100644
31641 --- a/drivers/i2c/i2c-mux.c
31642 +++ b/drivers/i2c/i2c-mux.c
31643 @@ -28,7 +28,7 @@
31644 /* multiplexer per channel data */
31645 struct i2c_mux_priv {
31646 struct i2c_adapter adap;
31647 - struct i2c_algorithm algo;
31648 + i2c_algorithm_no_const algo;
31649
31650 struct i2c_adapter *parent;
31651 void *mux_dev; /* the mux chip/device */
31652 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31653 index 57d00ca..0145194 100644
31654 --- a/drivers/ide/aec62xx.c
31655 +++ b/drivers/ide/aec62xx.c
31656 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31657 .cable_detect = atp86x_cable_detect,
31658 };
31659
31660 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31661 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31662 { /* 0: AEC6210 */
31663 .name = DRV_NAME,
31664 .init_chipset = init_chipset_aec62xx,
31665 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31666 index 2c8016a..911a27c 100644
31667 --- a/drivers/ide/alim15x3.c
31668 +++ b/drivers/ide/alim15x3.c
31669 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31670 .dma_sff_read_status = ide_dma_sff_read_status,
31671 };
31672
31673 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31674 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31675 .name = DRV_NAME,
31676 .init_chipset = init_chipset_ali15x3,
31677 .init_hwif = init_hwif_ali15x3,
31678 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31679 index 3747b25..56fc995 100644
31680 --- a/drivers/ide/amd74xx.c
31681 +++ b/drivers/ide/amd74xx.c
31682 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31683 .udma_mask = udma, \
31684 }
31685
31686 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31687 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31688 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31689 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31690 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31691 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31692 index 15f0ead..cb43480 100644
31693 --- a/drivers/ide/atiixp.c
31694 +++ b/drivers/ide/atiixp.c
31695 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31696 .cable_detect = atiixp_cable_detect,
31697 };
31698
31699 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31700 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31701 { /* 0: IXP200/300/400/700 */
31702 .name = DRV_NAME,
31703 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31704 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31705 index 5f80312..d1fc438 100644
31706 --- a/drivers/ide/cmd64x.c
31707 +++ b/drivers/ide/cmd64x.c
31708 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31709 .dma_sff_read_status = ide_dma_sff_read_status,
31710 };
31711
31712 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31713 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31714 { /* 0: CMD643 */
31715 .name = DRV_NAME,
31716 .init_chipset = init_chipset_cmd64x,
31717 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31718 index 2c1e5f7..1444762 100644
31719 --- a/drivers/ide/cs5520.c
31720 +++ b/drivers/ide/cs5520.c
31721 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31722 .set_dma_mode = cs5520_set_dma_mode,
31723 };
31724
31725 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31726 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31727 .name = DRV_NAME,
31728 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31729 .port_ops = &cs5520_port_ops,
31730 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31731 index 4dc4eb9..49b40ad 100644
31732 --- a/drivers/ide/cs5530.c
31733 +++ b/drivers/ide/cs5530.c
31734 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31735 .udma_filter = cs5530_udma_filter,
31736 };
31737
31738 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31739 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31740 .name = DRV_NAME,
31741 .init_chipset = init_chipset_cs5530,
31742 .init_hwif = init_hwif_cs5530,
31743 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31744 index 5059faf..18d4c85 100644
31745 --- a/drivers/ide/cs5535.c
31746 +++ b/drivers/ide/cs5535.c
31747 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31748 .cable_detect = cs5535_cable_detect,
31749 };
31750
31751 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31752 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31753 .name = DRV_NAME,
31754 .port_ops = &cs5535_port_ops,
31755 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31756 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31757 index 847553f..3ffb49d 100644
31758 --- a/drivers/ide/cy82c693.c
31759 +++ b/drivers/ide/cy82c693.c
31760 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31761 .set_dma_mode = cy82c693_set_dma_mode,
31762 };
31763
31764 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31765 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31766 .name = DRV_NAME,
31767 .init_iops = init_iops_cy82c693,
31768 .port_ops = &cy82c693_port_ops,
31769 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31770 index 58c51cd..4aec3b8 100644
31771 --- a/drivers/ide/hpt366.c
31772 +++ b/drivers/ide/hpt366.c
31773 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31774 }
31775 };
31776
31777 -static const struct hpt_info hpt36x __devinitdata = {
31778 +static const struct hpt_info hpt36x __devinitconst = {
31779 .chip_name = "HPT36x",
31780 .chip_type = HPT36x,
31781 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31782 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31783 .timings = &hpt36x_timings
31784 };
31785
31786 -static const struct hpt_info hpt370 __devinitdata = {
31787 +static const struct hpt_info hpt370 __devinitconst = {
31788 .chip_name = "HPT370",
31789 .chip_type = HPT370,
31790 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31791 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31792 .timings = &hpt37x_timings
31793 };
31794
31795 -static const struct hpt_info hpt370a __devinitdata = {
31796 +static const struct hpt_info hpt370a __devinitconst = {
31797 .chip_name = "HPT370A",
31798 .chip_type = HPT370A,
31799 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31800 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31801 .timings = &hpt37x_timings
31802 };
31803
31804 -static const struct hpt_info hpt374 __devinitdata = {
31805 +static const struct hpt_info hpt374 __devinitconst = {
31806 .chip_name = "HPT374",
31807 .chip_type = HPT374,
31808 .udma_mask = ATA_UDMA5,
31809 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31810 .timings = &hpt37x_timings
31811 };
31812
31813 -static const struct hpt_info hpt372 __devinitdata = {
31814 +static const struct hpt_info hpt372 __devinitconst = {
31815 .chip_name = "HPT372",
31816 .chip_type = HPT372,
31817 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31818 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31819 .timings = &hpt37x_timings
31820 };
31821
31822 -static const struct hpt_info hpt372a __devinitdata = {
31823 +static const struct hpt_info hpt372a __devinitconst = {
31824 .chip_name = "HPT372A",
31825 .chip_type = HPT372A,
31826 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31827 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31828 .timings = &hpt37x_timings
31829 };
31830
31831 -static const struct hpt_info hpt302 __devinitdata = {
31832 +static const struct hpt_info hpt302 __devinitconst = {
31833 .chip_name = "HPT302",
31834 .chip_type = HPT302,
31835 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31836 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31837 .timings = &hpt37x_timings
31838 };
31839
31840 -static const struct hpt_info hpt371 __devinitdata = {
31841 +static const struct hpt_info hpt371 __devinitconst = {
31842 .chip_name = "HPT371",
31843 .chip_type = HPT371,
31844 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31845 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31846 .timings = &hpt37x_timings
31847 };
31848
31849 -static const struct hpt_info hpt372n __devinitdata = {
31850 +static const struct hpt_info hpt372n __devinitconst = {
31851 .chip_name = "HPT372N",
31852 .chip_type = HPT372N,
31853 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31854 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31855 .timings = &hpt37x_timings
31856 };
31857
31858 -static const struct hpt_info hpt302n __devinitdata = {
31859 +static const struct hpt_info hpt302n __devinitconst = {
31860 .chip_name = "HPT302N",
31861 .chip_type = HPT302N,
31862 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31863 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31864 .timings = &hpt37x_timings
31865 };
31866
31867 -static const struct hpt_info hpt371n __devinitdata = {
31868 +static const struct hpt_info hpt371n __devinitconst = {
31869 .chip_name = "HPT371N",
31870 .chip_type = HPT371N,
31871 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31872 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31873 .dma_sff_read_status = ide_dma_sff_read_status,
31874 };
31875
31876 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31877 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31878 { /* 0: HPT36x */
31879 .name = DRV_NAME,
31880 .init_chipset = init_chipset_hpt366,
31881 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31882 index 8126824..55a2798 100644
31883 --- a/drivers/ide/ide-cd.c
31884 +++ b/drivers/ide/ide-cd.c
31885 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31886 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31887 if ((unsigned long)buf & alignment
31888 || blk_rq_bytes(rq) & q->dma_pad_mask
31889 - || object_is_on_stack(buf))
31890 + || object_starts_on_stack(buf))
31891 drive->dma = 0;
31892 }
31893 }
31894 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31895 index 7f56b73..dab5b67 100644
31896 --- a/drivers/ide/ide-pci-generic.c
31897 +++ b/drivers/ide/ide-pci-generic.c
31898 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31899 .udma_mask = ATA_UDMA6, \
31900 }
31901
31902 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31903 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31904 /* 0: Unknown */
31905 DECLARE_GENERIC_PCI_DEV(0),
31906
31907 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31908 index 560e66d..d5dd180 100644
31909 --- a/drivers/ide/it8172.c
31910 +++ b/drivers/ide/it8172.c
31911 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31912 .set_dma_mode = it8172_set_dma_mode,
31913 };
31914
31915 -static const struct ide_port_info it8172_port_info __devinitdata = {
31916 +static const struct ide_port_info it8172_port_info __devinitconst = {
31917 .name = DRV_NAME,
31918 .port_ops = &it8172_port_ops,
31919 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31920 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31921 index 46816ba..1847aeb 100644
31922 --- a/drivers/ide/it8213.c
31923 +++ b/drivers/ide/it8213.c
31924 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31925 .cable_detect = it8213_cable_detect,
31926 };
31927
31928 -static const struct ide_port_info it8213_chipset __devinitdata = {
31929 +static const struct ide_port_info it8213_chipset __devinitconst = {
31930 .name = DRV_NAME,
31931 .enablebits = { {0x41, 0x80, 0x80} },
31932 .port_ops = &it8213_port_ops,
31933 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31934 index 2e3169f..c5611db 100644
31935 --- a/drivers/ide/it821x.c
31936 +++ b/drivers/ide/it821x.c
31937 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31938 .cable_detect = it821x_cable_detect,
31939 };
31940
31941 -static const struct ide_port_info it821x_chipset __devinitdata = {
31942 +static const struct ide_port_info it821x_chipset __devinitconst = {
31943 .name = DRV_NAME,
31944 .init_chipset = init_chipset_it821x,
31945 .init_hwif = init_hwif_it821x,
31946 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31947 index 74c2c4a..efddd7d 100644
31948 --- a/drivers/ide/jmicron.c
31949 +++ b/drivers/ide/jmicron.c
31950 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31951 .cable_detect = jmicron_cable_detect,
31952 };
31953
31954 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31955 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31956 .name = DRV_NAME,
31957 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31958 .port_ops = &jmicron_port_ops,
31959 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31960 index 95327a2..73f78d8 100644
31961 --- a/drivers/ide/ns87415.c
31962 +++ b/drivers/ide/ns87415.c
31963 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31964 .dma_sff_read_status = superio_dma_sff_read_status,
31965 };
31966
31967 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31968 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31969 .name = DRV_NAME,
31970 .init_hwif = init_hwif_ns87415,
31971 .tp_ops = &ns87415_tp_ops,
31972 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31973 index 1a53a4c..39edc66 100644
31974 --- a/drivers/ide/opti621.c
31975 +++ b/drivers/ide/opti621.c
31976 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31977 .set_pio_mode = opti621_set_pio_mode,
31978 };
31979
31980 -static const struct ide_port_info opti621_chipset __devinitdata = {
31981 +static const struct ide_port_info opti621_chipset __devinitconst = {
31982 .name = DRV_NAME,
31983 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31984 .port_ops = &opti621_port_ops,
31985 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31986 index 9546fe2..2e5ceb6 100644
31987 --- a/drivers/ide/pdc202xx_new.c
31988 +++ b/drivers/ide/pdc202xx_new.c
31989 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31990 .udma_mask = udma, \
31991 }
31992
31993 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31994 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31995 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31996 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31997 };
31998 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31999 index 3a35ec6..5634510 100644
32000 --- a/drivers/ide/pdc202xx_old.c
32001 +++ b/drivers/ide/pdc202xx_old.c
32002 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32003 .max_sectors = sectors, \
32004 }
32005
32006 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32007 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32008 { /* 0: PDC20246 */
32009 .name = DRV_NAME,
32010 .init_chipset = init_chipset_pdc202xx,
32011 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32012 index 1892e81..fe0fd60 100644
32013 --- a/drivers/ide/piix.c
32014 +++ b/drivers/ide/piix.c
32015 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32016 .udma_mask = udma, \
32017 }
32018
32019 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32020 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32021 /* 0: MPIIX */
32022 { /*
32023 * MPIIX actually has only a single IDE channel mapped to
32024 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32025 index a6414a8..c04173e 100644
32026 --- a/drivers/ide/rz1000.c
32027 +++ b/drivers/ide/rz1000.c
32028 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32029 }
32030 }
32031
32032 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32033 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32034 .name = DRV_NAME,
32035 .host_flags = IDE_HFLAG_NO_DMA,
32036 };
32037 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32038 index 356b9b5..d4758eb 100644
32039 --- a/drivers/ide/sc1200.c
32040 +++ b/drivers/ide/sc1200.c
32041 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32042 .dma_sff_read_status = ide_dma_sff_read_status,
32043 };
32044
32045 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32046 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32047 .name = DRV_NAME,
32048 .port_ops = &sc1200_port_ops,
32049 .dma_ops = &sc1200_dma_ops,
32050 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32051 index b7f5b0c..9701038 100644
32052 --- a/drivers/ide/scc_pata.c
32053 +++ b/drivers/ide/scc_pata.c
32054 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32055 .dma_sff_read_status = scc_dma_sff_read_status,
32056 };
32057
32058 -static const struct ide_port_info scc_chipset __devinitdata = {
32059 +static const struct ide_port_info scc_chipset __devinitconst = {
32060 .name = "sccIDE",
32061 .init_iops = init_iops_scc,
32062 .init_dma = scc_init_dma,
32063 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32064 index 35fb8da..24d72ef 100644
32065 --- a/drivers/ide/serverworks.c
32066 +++ b/drivers/ide/serverworks.c
32067 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32068 .cable_detect = svwks_cable_detect,
32069 };
32070
32071 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32072 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32073 { /* 0: OSB4 */
32074 .name = DRV_NAME,
32075 .init_chipset = init_chipset_svwks,
32076 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32077 index ddeda44..46f7e30 100644
32078 --- a/drivers/ide/siimage.c
32079 +++ b/drivers/ide/siimage.c
32080 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32081 .udma_mask = ATA_UDMA6, \
32082 }
32083
32084 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32085 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32086 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32087 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32088 };
32089 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32090 index 4a00225..09e61b4 100644
32091 --- a/drivers/ide/sis5513.c
32092 +++ b/drivers/ide/sis5513.c
32093 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32094 .cable_detect = sis_cable_detect,
32095 };
32096
32097 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32098 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32099 .name = DRV_NAME,
32100 .init_chipset = init_chipset_sis5513,
32101 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32102 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32103 index f21dc2a..d051cd2 100644
32104 --- a/drivers/ide/sl82c105.c
32105 +++ b/drivers/ide/sl82c105.c
32106 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32107 .dma_sff_read_status = ide_dma_sff_read_status,
32108 };
32109
32110 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32111 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32112 .name = DRV_NAME,
32113 .init_chipset = init_chipset_sl82c105,
32114 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32115 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32116 index 864ffe0..863a5e9 100644
32117 --- a/drivers/ide/slc90e66.c
32118 +++ b/drivers/ide/slc90e66.c
32119 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32120 .cable_detect = slc90e66_cable_detect,
32121 };
32122
32123 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32124 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32125 .name = DRV_NAME,
32126 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32127 .port_ops = &slc90e66_port_ops,
32128 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32129 index 4799d5c..1794678 100644
32130 --- a/drivers/ide/tc86c001.c
32131 +++ b/drivers/ide/tc86c001.c
32132 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32133 .dma_sff_read_status = ide_dma_sff_read_status,
32134 };
32135
32136 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32137 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32138 .name = DRV_NAME,
32139 .init_hwif = init_hwif_tc86c001,
32140 .port_ops = &tc86c001_port_ops,
32141 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32142 index 281c914..55ce1b8 100644
32143 --- a/drivers/ide/triflex.c
32144 +++ b/drivers/ide/triflex.c
32145 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32146 .set_dma_mode = triflex_set_mode,
32147 };
32148
32149 -static const struct ide_port_info triflex_device __devinitdata = {
32150 +static const struct ide_port_info triflex_device __devinitconst = {
32151 .name = DRV_NAME,
32152 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32153 .port_ops = &triflex_port_ops,
32154 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32155 index 4b42ca0..e494a98 100644
32156 --- a/drivers/ide/trm290.c
32157 +++ b/drivers/ide/trm290.c
32158 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32159 .dma_check = trm290_dma_check,
32160 };
32161
32162 -static const struct ide_port_info trm290_chipset __devinitdata = {
32163 +static const struct ide_port_info trm290_chipset __devinitconst = {
32164 .name = DRV_NAME,
32165 .init_hwif = init_hwif_trm290,
32166 .tp_ops = &trm290_tp_ops,
32167 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32168 index f46f49c..eb77678 100644
32169 --- a/drivers/ide/via82cxxx.c
32170 +++ b/drivers/ide/via82cxxx.c
32171 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32172 .cable_detect = via82cxxx_cable_detect,
32173 };
32174
32175 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32176 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32177 .name = DRV_NAME,
32178 .init_chipset = init_chipset_via82cxxx,
32179 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32180 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32181 index 73d4531..c90cd2d 100644
32182 --- a/drivers/ieee802154/fakehard.c
32183 +++ b/drivers/ieee802154/fakehard.c
32184 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32185 phy->transmit_power = 0xbf;
32186
32187 dev->netdev_ops = &fake_ops;
32188 - dev->ml_priv = &fake_mlme;
32189 + dev->ml_priv = (void *)&fake_mlme;
32190
32191 priv = netdev_priv(dev);
32192 priv->phy = phy;
32193 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32194 index c889aae..6cf5aa7 100644
32195 --- a/drivers/infiniband/core/cm.c
32196 +++ b/drivers/infiniband/core/cm.c
32197 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32198
32199 struct cm_counter_group {
32200 struct kobject obj;
32201 - atomic_long_t counter[CM_ATTR_COUNT];
32202 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32203 };
32204
32205 struct cm_counter_attribute {
32206 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32207 struct ib_mad_send_buf *msg = NULL;
32208 int ret;
32209
32210 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32211 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32212 counter[CM_REQ_COUNTER]);
32213
32214 /* Quick state check to discard duplicate REQs. */
32215 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32216 if (!cm_id_priv)
32217 return;
32218
32219 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32220 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32221 counter[CM_REP_COUNTER]);
32222 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32223 if (ret)
32224 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32225 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32226 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32227 spin_unlock_irq(&cm_id_priv->lock);
32228 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32229 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32230 counter[CM_RTU_COUNTER]);
32231 goto out;
32232 }
32233 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32234 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32235 dreq_msg->local_comm_id);
32236 if (!cm_id_priv) {
32237 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32238 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32239 counter[CM_DREQ_COUNTER]);
32240 cm_issue_drep(work->port, work->mad_recv_wc);
32241 return -EINVAL;
32242 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32243 case IB_CM_MRA_REP_RCVD:
32244 break;
32245 case IB_CM_TIMEWAIT:
32246 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32247 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32248 counter[CM_DREQ_COUNTER]);
32249 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32250 goto unlock;
32251 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32252 cm_free_msg(msg);
32253 goto deref;
32254 case IB_CM_DREQ_RCVD:
32255 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32256 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32257 counter[CM_DREQ_COUNTER]);
32258 goto unlock;
32259 default:
32260 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32261 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32262 cm_id_priv->msg, timeout)) {
32263 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32264 - atomic_long_inc(&work->port->
32265 + atomic_long_inc_unchecked(&work->port->
32266 counter_group[CM_RECV_DUPLICATES].
32267 counter[CM_MRA_COUNTER]);
32268 goto out;
32269 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32270 break;
32271 case IB_CM_MRA_REQ_RCVD:
32272 case IB_CM_MRA_REP_RCVD:
32273 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32274 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32275 counter[CM_MRA_COUNTER]);
32276 /* fall through */
32277 default:
32278 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32279 case IB_CM_LAP_IDLE:
32280 break;
32281 case IB_CM_MRA_LAP_SENT:
32282 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32283 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32284 counter[CM_LAP_COUNTER]);
32285 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32286 goto unlock;
32287 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32288 cm_free_msg(msg);
32289 goto deref;
32290 case IB_CM_LAP_RCVD:
32291 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32292 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32293 counter[CM_LAP_COUNTER]);
32294 goto unlock;
32295 default:
32296 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32297 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32298 if (cur_cm_id_priv) {
32299 spin_unlock_irq(&cm.lock);
32300 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32301 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32302 counter[CM_SIDR_REQ_COUNTER]);
32303 goto out; /* Duplicate message. */
32304 }
32305 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32306 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32307 msg->retries = 1;
32308
32309 - atomic_long_add(1 + msg->retries,
32310 + atomic_long_add_unchecked(1 + msg->retries,
32311 &port->counter_group[CM_XMIT].counter[attr_index]);
32312 if (msg->retries)
32313 - atomic_long_add(msg->retries,
32314 + atomic_long_add_unchecked(msg->retries,
32315 &port->counter_group[CM_XMIT_RETRIES].
32316 counter[attr_index]);
32317
32318 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32319 }
32320
32321 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32322 - atomic_long_inc(&port->counter_group[CM_RECV].
32323 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32324 counter[attr_id - CM_ATTR_ID_OFFSET]);
32325
32326 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32327 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32328 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32329
32330 return sprintf(buf, "%ld\n",
32331 - atomic_long_read(&group->counter[cm_attr->index]));
32332 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32333 }
32334
32335 static const struct sysfs_ops cm_counter_ops = {
32336 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32337 index 176c8f9..2627b62 100644
32338 --- a/drivers/infiniband/core/fmr_pool.c
32339 +++ b/drivers/infiniband/core/fmr_pool.c
32340 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32341
32342 struct task_struct *thread;
32343
32344 - atomic_t req_ser;
32345 - atomic_t flush_ser;
32346 + atomic_unchecked_t req_ser;
32347 + atomic_unchecked_t flush_ser;
32348
32349 wait_queue_head_t force_wait;
32350 };
32351 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32352 struct ib_fmr_pool *pool = pool_ptr;
32353
32354 do {
32355 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32356 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32357 ib_fmr_batch_release(pool);
32358
32359 - atomic_inc(&pool->flush_ser);
32360 + atomic_inc_unchecked(&pool->flush_ser);
32361 wake_up_interruptible(&pool->force_wait);
32362
32363 if (pool->flush_function)
32364 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32365 }
32366
32367 set_current_state(TASK_INTERRUPTIBLE);
32368 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32369 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32370 !kthread_should_stop())
32371 schedule();
32372 __set_current_state(TASK_RUNNING);
32373 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32374 pool->dirty_watermark = params->dirty_watermark;
32375 pool->dirty_len = 0;
32376 spin_lock_init(&pool->pool_lock);
32377 - atomic_set(&pool->req_ser, 0);
32378 - atomic_set(&pool->flush_ser, 0);
32379 + atomic_set_unchecked(&pool->req_ser, 0);
32380 + atomic_set_unchecked(&pool->flush_ser, 0);
32381 init_waitqueue_head(&pool->force_wait);
32382
32383 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32384 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32385 }
32386 spin_unlock_irq(&pool->pool_lock);
32387
32388 - serial = atomic_inc_return(&pool->req_ser);
32389 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32390 wake_up_process(pool->thread);
32391
32392 if (wait_event_interruptible(pool->force_wait,
32393 - atomic_read(&pool->flush_ser) - serial >= 0))
32394 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32395 return -EINTR;
32396
32397 return 0;
32398 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32399 } else {
32400 list_add_tail(&fmr->list, &pool->dirty_list);
32401 if (++pool->dirty_len >= pool->dirty_watermark) {
32402 - atomic_inc(&pool->req_ser);
32403 + atomic_inc_unchecked(&pool->req_ser);
32404 wake_up_process(pool->thread);
32405 }
32406 }
32407 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32408 index 40c8353..946b0e4 100644
32409 --- a/drivers/infiniband/hw/cxgb4/mem.c
32410 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32411 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32412 int err;
32413 struct fw_ri_tpte tpt;
32414 u32 stag_idx;
32415 - static atomic_t key;
32416 + static atomic_unchecked_t key;
32417
32418 if (c4iw_fatal_error(rdev))
32419 return -EIO;
32420 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32421 &rdev->resource.tpt_fifo_lock);
32422 if (!stag_idx)
32423 return -ENOMEM;
32424 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32425 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32426 }
32427 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32428 __func__, stag_state, type, pdid, stag_idx);
32429 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32430 index 79b3dbc..96e5fcc 100644
32431 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32432 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32433 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32434 struct ib_atomic_eth *ateth;
32435 struct ipath_ack_entry *e;
32436 u64 vaddr;
32437 - atomic64_t *maddr;
32438 + atomic64_unchecked_t *maddr;
32439 u64 sdata;
32440 u32 rkey;
32441 u8 next;
32442 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32443 IB_ACCESS_REMOTE_ATOMIC)))
32444 goto nack_acc_unlck;
32445 /* Perform atomic OP and save result. */
32446 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32447 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32448 sdata = be64_to_cpu(ateth->swap_data);
32449 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32450 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32451 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32452 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32453 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32454 be64_to_cpu(ateth->compare_data),
32455 sdata);
32456 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32457 index 1f95bba..9530f87 100644
32458 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32459 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32460 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32461 unsigned long flags;
32462 struct ib_wc wc;
32463 u64 sdata;
32464 - atomic64_t *maddr;
32465 + atomic64_unchecked_t *maddr;
32466 enum ib_wc_status send_status;
32467
32468 /*
32469 @@ -382,11 +382,11 @@ again:
32470 IB_ACCESS_REMOTE_ATOMIC)))
32471 goto acc_err;
32472 /* Perform atomic OP and save result. */
32473 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32474 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32475 sdata = wqe->wr.wr.atomic.compare_add;
32476 *(u64 *) sqp->s_sge.sge.vaddr =
32477 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32478 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32479 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32480 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32481 sdata, wqe->wr.wr.atomic.swap);
32482 goto send_comp;
32483 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32484 index 7140199..da60063 100644
32485 --- a/drivers/infiniband/hw/nes/nes.c
32486 +++ b/drivers/infiniband/hw/nes/nes.c
32487 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32488 LIST_HEAD(nes_adapter_list);
32489 static LIST_HEAD(nes_dev_list);
32490
32491 -atomic_t qps_destroyed;
32492 +atomic_unchecked_t qps_destroyed;
32493
32494 static unsigned int ee_flsh_adapter;
32495 static unsigned int sysfs_nonidx_addr;
32496 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32497 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32498 struct nes_adapter *nesadapter = nesdev->nesadapter;
32499
32500 - atomic_inc(&qps_destroyed);
32501 + atomic_inc_unchecked(&qps_destroyed);
32502
32503 /* Free the control structures */
32504
32505 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32506 index c438e46..ca30356 100644
32507 --- a/drivers/infiniband/hw/nes/nes.h
32508 +++ b/drivers/infiniband/hw/nes/nes.h
32509 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32510 extern unsigned int wqm_quanta;
32511 extern struct list_head nes_adapter_list;
32512
32513 -extern atomic_t cm_connects;
32514 -extern atomic_t cm_accepts;
32515 -extern atomic_t cm_disconnects;
32516 -extern atomic_t cm_closes;
32517 -extern atomic_t cm_connecteds;
32518 -extern atomic_t cm_connect_reqs;
32519 -extern atomic_t cm_rejects;
32520 -extern atomic_t mod_qp_timouts;
32521 -extern atomic_t qps_created;
32522 -extern atomic_t qps_destroyed;
32523 -extern atomic_t sw_qps_destroyed;
32524 +extern atomic_unchecked_t cm_connects;
32525 +extern atomic_unchecked_t cm_accepts;
32526 +extern atomic_unchecked_t cm_disconnects;
32527 +extern atomic_unchecked_t cm_closes;
32528 +extern atomic_unchecked_t cm_connecteds;
32529 +extern atomic_unchecked_t cm_connect_reqs;
32530 +extern atomic_unchecked_t cm_rejects;
32531 +extern atomic_unchecked_t mod_qp_timouts;
32532 +extern atomic_unchecked_t qps_created;
32533 +extern atomic_unchecked_t qps_destroyed;
32534 +extern atomic_unchecked_t sw_qps_destroyed;
32535 extern u32 mh_detected;
32536 extern u32 mh_pauses_sent;
32537 extern u32 cm_packets_sent;
32538 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32539 extern u32 cm_packets_received;
32540 extern u32 cm_packets_dropped;
32541 extern u32 cm_packets_retrans;
32542 -extern atomic_t cm_listens_created;
32543 -extern atomic_t cm_listens_destroyed;
32544 +extern atomic_unchecked_t cm_listens_created;
32545 +extern atomic_unchecked_t cm_listens_destroyed;
32546 extern u32 cm_backlog_drops;
32547 -extern atomic_t cm_loopbacks;
32548 -extern atomic_t cm_nodes_created;
32549 -extern atomic_t cm_nodes_destroyed;
32550 -extern atomic_t cm_accel_dropped_pkts;
32551 -extern atomic_t cm_resets_recvd;
32552 -extern atomic_t pau_qps_created;
32553 -extern atomic_t pau_qps_destroyed;
32554 +extern atomic_unchecked_t cm_loopbacks;
32555 +extern atomic_unchecked_t cm_nodes_created;
32556 +extern atomic_unchecked_t cm_nodes_destroyed;
32557 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32558 +extern atomic_unchecked_t cm_resets_recvd;
32559 +extern atomic_unchecked_t pau_qps_created;
32560 +extern atomic_unchecked_t pau_qps_destroyed;
32561
32562 extern u32 int_mod_timer_init;
32563 extern u32 int_mod_cq_depth_256;
32564 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32565 index a4972ab..1bcfc31 100644
32566 --- a/drivers/infiniband/hw/nes/nes_cm.c
32567 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32568 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32569 u32 cm_packets_retrans;
32570 u32 cm_packets_created;
32571 u32 cm_packets_received;
32572 -atomic_t cm_listens_created;
32573 -atomic_t cm_listens_destroyed;
32574 +atomic_unchecked_t cm_listens_created;
32575 +atomic_unchecked_t cm_listens_destroyed;
32576 u32 cm_backlog_drops;
32577 -atomic_t cm_loopbacks;
32578 -atomic_t cm_nodes_created;
32579 -atomic_t cm_nodes_destroyed;
32580 -atomic_t cm_accel_dropped_pkts;
32581 -atomic_t cm_resets_recvd;
32582 +atomic_unchecked_t cm_loopbacks;
32583 +atomic_unchecked_t cm_nodes_created;
32584 +atomic_unchecked_t cm_nodes_destroyed;
32585 +atomic_unchecked_t cm_accel_dropped_pkts;
32586 +atomic_unchecked_t cm_resets_recvd;
32587
32588 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32589 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32590 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32591
32592 static struct nes_cm_core *g_cm_core;
32593
32594 -atomic_t cm_connects;
32595 -atomic_t cm_accepts;
32596 -atomic_t cm_disconnects;
32597 -atomic_t cm_closes;
32598 -atomic_t cm_connecteds;
32599 -atomic_t cm_connect_reqs;
32600 -atomic_t cm_rejects;
32601 +atomic_unchecked_t cm_connects;
32602 +atomic_unchecked_t cm_accepts;
32603 +atomic_unchecked_t cm_disconnects;
32604 +atomic_unchecked_t cm_closes;
32605 +atomic_unchecked_t cm_connecteds;
32606 +atomic_unchecked_t cm_connect_reqs;
32607 +atomic_unchecked_t cm_rejects;
32608
32609 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32610 {
32611 @@ -1274,7 +1274,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32612 kfree(listener);
32613 listener = NULL;
32614 ret = 0;
32615 - atomic_inc(&cm_listens_destroyed);
32616 + atomic_inc_unchecked(&cm_listens_destroyed);
32617 } else {
32618 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32619 }
32620 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32621 cm_node->rem_mac);
32622
32623 add_hte_node(cm_core, cm_node);
32624 - atomic_inc(&cm_nodes_created);
32625 + atomic_inc_unchecked(&cm_nodes_created);
32626
32627 return cm_node;
32628 }
32629 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32630 }
32631
32632 atomic_dec(&cm_core->node_cnt);
32633 - atomic_inc(&cm_nodes_destroyed);
32634 + atomic_inc_unchecked(&cm_nodes_destroyed);
32635 nesqp = cm_node->nesqp;
32636 if (nesqp) {
32637 nesqp->cm_node = NULL;
32638 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32639
32640 static void drop_packet(struct sk_buff *skb)
32641 {
32642 - atomic_inc(&cm_accel_dropped_pkts);
32643 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32644 dev_kfree_skb_any(skb);
32645 }
32646
32647 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32648 {
32649
32650 int reset = 0; /* whether to send reset in case of err.. */
32651 - atomic_inc(&cm_resets_recvd);
32652 + atomic_inc_unchecked(&cm_resets_recvd);
32653 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32654 " refcnt=%d\n", cm_node, cm_node->state,
32655 atomic_read(&cm_node->ref_count));
32656 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32657 rem_ref_cm_node(cm_node->cm_core, cm_node);
32658 return NULL;
32659 }
32660 - atomic_inc(&cm_loopbacks);
32661 + atomic_inc_unchecked(&cm_loopbacks);
32662 loopbackremotenode->loopbackpartner = cm_node;
32663 loopbackremotenode->tcp_cntxt.rcv_wscale =
32664 NES_CM_DEFAULT_RCV_WND_SCALE;
32665 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32666 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32667 else {
32668 rem_ref_cm_node(cm_core, cm_node);
32669 - atomic_inc(&cm_accel_dropped_pkts);
32670 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32671 dev_kfree_skb_any(skb);
32672 }
32673 break;
32674 @@ -2881,7 +2881,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32675
32676 if ((cm_id) && (cm_id->event_handler)) {
32677 if (issue_disconn) {
32678 - atomic_inc(&cm_disconnects);
32679 + atomic_inc_unchecked(&cm_disconnects);
32680 cm_event.event = IW_CM_EVENT_DISCONNECT;
32681 cm_event.status = disconn_status;
32682 cm_event.local_addr = cm_id->local_addr;
32683 @@ -2903,7 +2903,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32684 }
32685
32686 if (issue_close) {
32687 - atomic_inc(&cm_closes);
32688 + atomic_inc_unchecked(&cm_closes);
32689 nes_disconnect(nesqp, 1);
32690
32691 cm_id->provider_data = nesqp;
32692 @@ -3039,7 +3039,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32693
32694 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32695 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32696 - atomic_inc(&cm_accepts);
32697 + atomic_inc_unchecked(&cm_accepts);
32698
32699 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32700 netdev_refcnt_read(nesvnic->netdev));
32701 @@ -3241,7 +3241,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32702 struct nes_cm_core *cm_core;
32703 u8 *start_buff;
32704
32705 - atomic_inc(&cm_rejects);
32706 + atomic_inc_unchecked(&cm_rejects);
32707 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32708 loopback = cm_node->loopbackpartner;
32709 cm_core = cm_node->cm_core;
32710 @@ -3301,7 +3301,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32711 ntohl(cm_id->local_addr.sin_addr.s_addr),
32712 ntohs(cm_id->local_addr.sin_port));
32713
32714 - atomic_inc(&cm_connects);
32715 + atomic_inc_unchecked(&cm_connects);
32716 nesqp->active_conn = 1;
32717
32718 /* cache the cm_id in the qp */
32719 @@ -3407,7 +3407,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32720 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32721 return err;
32722 }
32723 - atomic_inc(&cm_listens_created);
32724 + atomic_inc_unchecked(&cm_listens_created);
32725 }
32726
32727 cm_id->add_ref(cm_id);
32728 @@ -3508,7 +3508,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32729
32730 if (nesqp->destroyed)
32731 return;
32732 - atomic_inc(&cm_connecteds);
32733 + atomic_inc_unchecked(&cm_connecteds);
32734 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32735 " local port 0x%04X. jiffies = %lu.\n",
32736 nesqp->hwqp.qp_id,
32737 @@ -3695,7 +3695,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32738
32739 cm_id->add_ref(cm_id);
32740 ret = cm_id->event_handler(cm_id, &cm_event);
32741 - atomic_inc(&cm_closes);
32742 + atomic_inc_unchecked(&cm_closes);
32743 cm_event.event = IW_CM_EVENT_CLOSE;
32744 cm_event.status = 0;
32745 cm_event.provider_data = cm_id->provider_data;
32746 @@ -3731,7 +3731,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32747 return;
32748 cm_id = cm_node->cm_id;
32749
32750 - atomic_inc(&cm_connect_reqs);
32751 + atomic_inc_unchecked(&cm_connect_reqs);
32752 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32753 cm_node, cm_id, jiffies);
32754
32755 @@ -3771,7 +3771,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32756 return;
32757 cm_id = cm_node->cm_id;
32758
32759 - atomic_inc(&cm_connect_reqs);
32760 + atomic_inc_unchecked(&cm_connect_reqs);
32761 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32762 cm_node, cm_id, jiffies);
32763
32764 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32765 index 3ba7be3..c81f6ff 100644
32766 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32767 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32768 @@ -40,8 +40,8 @@
32769 #include "nes.h"
32770 #include "nes_mgt.h"
32771
32772 -atomic_t pau_qps_created;
32773 -atomic_t pau_qps_destroyed;
32774 +atomic_unchecked_t pau_qps_created;
32775 +atomic_unchecked_t pau_qps_destroyed;
32776
32777 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32778 {
32779 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32780 {
32781 struct sk_buff *skb;
32782 unsigned long flags;
32783 - atomic_inc(&pau_qps_destroyed);
32784 + atomic_inc_unchecked(&pau_qps_destroyed);
32785
32786 /* Free packets that have not yet been forwarded */
32787 /* Lock is acquired by skb_dequeue when removing the skb */
32788 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32789 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32790 skb_queue_head_init(&nesqp->pau_list);
32791 spin_lock_init(&nesqp->pau_lock);
32792 - atomic_inc(&pau_qps_created);
32793 + atomic_inc_unchecked(&pau_qps_created);
32794 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32795 }
32796
32797 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32798 index f3a3ecf..57d311d 100644
32799 --- a/drivers/infiniband/hw/nes/nes_nic.c
32800 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32801 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32802 target_stat_values[++index] = mh_detected;
32803 target_stat_values[++index] = mh_pauses_sent;
32804 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32805 - target_stat_values[++index] = atomic_read(&cm_connects);
32806 - target_stat_values[++index] = atomic_read(&cm_accepts);
32807 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32808 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32809 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32810 - target_stat_values[++index] = atomic_read(&cm_rejects);
32811 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32812 - target_stat_values[++index] = atomic_read(&qps_created);
32813 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32814 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32815 - target_stat_values[++index] = atomic_read(&cm_closes);
32816 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32817 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32818 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32819 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32820 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32821 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32822 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32823 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32824 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32825 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32826 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32827 target_stat_values[++index] = cm_packets_sent;
32828 target_stat_values[++index] = cm_packets_bounced;
32829 target_stat_values[++index] = cm_packets_created;
32830 target_stat_values[++index] = cm_packets_received;
32831 target_stat_values[++index] = cm_packets_dropped;
32832 target_stat_values[++index] = cm_packets_retrans;
32833 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32834 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32835 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32836 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32837 target_stat_values[++index] = cm_backlog_drops;
32838 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32839 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32840 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32841 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32842 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32843 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32844 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32845 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32846 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32847 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32848 target_stat_values[++index] = nesadapter->free_4kpbl;
32849 target_stat_values[++index] = nesadapter->free_256pbl;
32850 target_stat_values[++index] = int_mod_timer_init;
32851 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32852 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32853 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32854 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32855 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32856 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32857 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32858 }
32859
32860 /**
32861 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32862 index 0927b5c..ed67986 100644
32863 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32864 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32865 @@ -46,9 +46,9 @@
32866
32867 #include <rdma/ib_umem.h>
32868
32869 -atomic_t mod_qp_timouts;
32870 -atomic_t qps_created;
32871 -atomic_t sw_qps_destroyed;
32872 +atomic_unchecked_t mod_qp_timouts;
32873 +atomic_unchecked_t qps_created;
32874 +atomic_unchecked_t sw_qps_destroyed;
32875
32876 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32877
32878 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32879 if (init_attr->create_flags)
32880 return ERR_PTR(-EINVAL);
32881
32882 - atomic_inc(&qps_created);
32883 + atomic_inc_unchecked(&qps_created);
32884 switch (init_attr->qp_type) {
32885 case IB_QPT_RC:
32886 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32887 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32888 struct iw_cm_event cm_event;
32889 int ret = 0;
32890
32891 - atomic_inc(&sw_qps_destroyed);
32892 + atomic_inc_unchecked(&sw_qps_destroyed);
32893 nesqp->destroyed = 1;
32894
32895 /* Blow away the connection if it exists. */
32896 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32897 index b881bdc..c2e360c 100644
32898 --- a/drivers/infiniband/hw/qib/qib.h
32899 +++ b/drivers/infiniband/hw/qib/qib.h
32900 @@ -51,6 +51,7 @@
32901 #include <linux/completion.h>
32902 #include <linux/kref.h>
32903 #include <linux/sched.h>
32904 +#include <linux/slab.h>
32905
32906 #include "qib_common.h"
32907 #include "qib_verbs.h"
32908 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32909 index c351aa4..e6967c2 100644
32910 --- a/drivers/input/gameport/gameport.c
32911 +++ b/drivers/input/gameport/gameport.c
32912 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32913 */
32914 static void gameport_init_port(struct gameport *gameport)
32915 {
32916 - static atomic_t gameport_no = ATOMIC_INIT(0);
32917 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32918
32919 __module_get(THIS_MODULE);
32920
32921 mutex_init(&gameport->drv_mutex);
32922 device_initialize(&gameport->dev);
32923 dev_set_name(&gameport->dev, "gameport%lu",
32924 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32925 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32926 gameport->dev.bus = &gameport_bus;
32927 gameport->dev.release = gameport_release_port;
32928 if (gameport->parent)
32929 diff --git a/drivers/input/input.c b/drivers/input/input.c
32930 index 1f78c95..3cddc6c 100644
32931 --- a/drivers/input/input.c
32932 +++ b/drivers/input/input.c
32933 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32934 */
32935 int input_register_device(struct input_dev *dev)
32936 {
32937 - static atomic_t input_no = ATOMIC_INIT(0);
32938 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32939 struct input_handler *handler;
32940 const char *path;
32941 int error;
32942 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32943 dev->setkeycode = input_default_setkeycode;
32944
32945 dev_set_name(&dev->dev, "input%ld",
32946 - (unsigned long) atomic_inc_return(&input_no) - 1);
32947 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32948
32949 error = device_add(&dev->dev);
32950 if (error)
32951 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32952 index b8d8611..7a4a04b 100644
32953 --- a/drivers/input/joystick/sidewinder.c
32954 +++ b/drivers/input/joystick/sidewinder.c
32955 @@ -30,6 +30,7 @@
32956 #include <linux/kernel.h>
32957 #include <linux/module.h>
32958 #include <linux/slab.h>
32959 +#include <linux/sched.h>
32960 #include <linux/init.h>
32961 #include <linux/input.h>
32962 #include <linux/gameport.h>
32963 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32964 index fd7a0d5..a4af10c 100644
32965 --- a/drivers/input/joystick/xpad.c
32966 +++ b/drivers/input/joystick/xpad.c
32967 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32968
32969 static int xpad_led_probe(struct usb_xpad *xpad)
32970 {
32971 - static atomic_t led_seq = ATOMIC_INIT(0);
32972 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32973 long led_no;
32974 struct xpad_led *led;
32975 struct led_classdev *led_cdev;
32976 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32977 if (!led)
32978 return -ENOMEM;
32979
32980 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32981 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32982
32983 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32984 led->xpad = xpad;
32985 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32986 index 0110b5a..d3ad144 100644
32987 --- a/drivers/input/mousedev.c
32988 +++ b/drivers/input/mousedev.c
32989 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32990
32991 spin_unlock_irq(&client->packet_lock);
32992
32993 - if (copy_to_user(buffer, data, count))
32994 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32995 return -EFAULT;
32996
32997 return count;
32998 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32999 index ba70058..571d25d 100644
33000 --- a/drivers/input/serio/serio.c
33001 +++ b/drivers/input/serio/serio.c
33002 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
33003 */
33004 static void serio_init_port(struct serio *serio)
33005 {
33006 - static atomic_t serio_no = ATOMIC_INIT(0);
33007 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33008
33009 __module_get(THIS_MODULE);
33010
33011 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
33012 mutex_init(&serio->drv_mutex);
33013 device_initialize(&serio->dev);
33014 dev_set_name(&serio->dev, "serio%ld",
33015 - (long)atomic_inc_return(&serio_no) - 1);
33016 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33017 serio->dev.bus = &serio_bus;
33018 serio->dev.release = serio_release_port;
33019 serio->dev.groups = serio_device_attr_groups;
33020 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33021 index e44933d..9ba484a 100644
33022 --- a/drivers/isdn/capi/capi.c
33023 +++ b/drivers/isdn/capi/capi.c
33024 @@ -83,8 +83,8 @@ struct capiminor {
33025
33026 struct capi20_appl *ap;
33027 u32 ncci;
33028 - atomic_t datahandle;
33029 - atomic_t msgid;
33030 + atomic_unchecked_t datahandle;
33031 + atomic_unchecked_t msgid;
33032
33033 struct tty_port port;
33034 int ttyinstop;
33035 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33036 capimsg_setu16(s, 2, mp->ap->applid);
33037 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33038 capimsg_setu8 (s, 5, CAPI_RESP);
33039 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33040 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33041 capimsg_setu32(s, 8, mp->ncci);
33042 capimsg_setu16(s, 12, datahandle);
33043 }
33044 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
33045 mp->outbytes -= len;
33046 spin_unlock_bh(&mp->outlock);
33047
33048 - datahandle = atomic_inc_return(&mp->datahandle);
33049 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33050 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33051 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33052 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33053 capimsg_setu16(skb->data, 2, mp->ap->applid);
33054 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33055 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33056 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33057 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33058 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33059 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33060 capimsg_setu16(skb->data, 16, len); /* Data length */
33061 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
33062 index db621db..825ea1a 100644
33063 --- a/drivers/isdn/gigaset/common.c
33064 +++ b/drivers/isdn/gigaset/common.c
33065 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
33066 cs->commands_pending = 0;
33067 cs->cur_at_seq = 0;
33068 cs->gotfwver = -1;
33069 - cs->open_count = 0;
33070 + local_set(&cs->open_count, 0);
33071 cs->dev = NULL;
33072 cs->tty = NULL;
33073 cs->tty_dev = NULL;
33074 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
33075 index 212efaf..f187c6b 100644
33076 --- a/drivers/isdn/gigaset/gigaset.h
33077 +++ b/drivers/isdn/gigaset/gigaset.h
33078 @@ -35,6 +35,7 @@
33079 #include <linux/tty_driver.h>
33080 #include <linux/list.h>
33081 #include <linux/atomic.h>
33082 +#include <asm/local.h>
33083
33084 #define GIG_VERSION {0, 5, 0, 0}
33085 #define GIG_COMPAT {0, 4, 0, 0}
33086 @@ -433,7 +434,7 @@ struct cardstate {
33087 spinlock_t cmdlock;
33088 unsigned curlen, cmdbytes;
33089
33090 - unsigned open_count;
33091 + local_t open_count;
33092 struct tty_struct *tty;
33093 struct tasklet_struct if_wake_tasklet;
33094 unsigned control_state;
33095 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33096 index ee0a549..a7c9798 100644
33097 --- a/drivers/isdn/gigaset/interface.c
33098 +++ b/drivers/isdn/gigaset/interface.c
33099 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33100 }
33101 tty->driver_data = cs;
33102
33103 - ++cs->open_count;
33104 -
33105 - if (cs->open_count == 1) {
33106 + if (local_inc_return(&cs->open_count) == 1) {
33107 spin_lock_irqsave(&cs->lock, flags);
33108 cs->tty = tty;
33109 spin_unlock_irqrestore(&cs->lock, flags);
33110 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33111
33112 if (!cs->connected)
33113 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33114 - else if (!cs->open_count)
33115 + else if (!local_read(&cs->open_count))
33116 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33117 else {
33118 - if (!--cs->open_count) {
33119 + if (!local_dec_return(&cs->open_count)) {
33120 spin_lock_irqsave(&cs->lock, flags);
33121 cs->tty = NULL;
33122 spin_unlock_irqrestore(&cs->lock, flags);
33123 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
33124 if (!cs->connected) {
33125 gig_dbg(DEBUG_IF, "not connected");
33126 retval = -ENODEV;
33127 - } else if (!cs->open_count)
33128 + } else if (!local_read(&cs->open_count))
33129 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33130 else {
33131 retval = 0;
33132 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
33133 retval = -ENODEV;
33134 goto done;
33135 }
33136 - if (!cs->open_count) {
33137 + if (!local_read(&cs->open_count)) {
33138 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33139 retval = -ENODEV;
33140 goto done;
33141 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
33142 if (!cs->connected) {
33143 gig_dbg(DEBUG_IF, "not connected");
33144 retval = -ENODEV;
33145 - } else if (!cs->open_count)
33146 + } else if (!local_read(&cs->open_count))
33147 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33148 else if (cs->mstate != MS_LOCKED) {
33149 dev_warn(cs->dev, "can't write to unlocked device\n");
33150 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
33151
33152 if (!cs->connected)
33153 gig_dbg(DEBUG_IF, "not connected");
33154 - else if (!cs->open_count)
33155 + else if (!local_read(&cs->open_count))
33156 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33157 else if (cs->mstate != MS_LOCKED)
33158 dev_warn(cs->dev, "can't write to unlocked device\n");
33159 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
33160
33161 if (!cs->connected)
33162 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33163 - else if (!cs->open_count)
33164 + else if (!local_read(&cs->open_count))
33165 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33166 else
33167 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33168 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
33169
33170 if (!cs->connected)
33171 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33172 - else if (!cs->open_count)
33173 + else if (!local_read(&cs->open_count))
33174 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33175 else
33176 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
33177 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
33178 goto out;
33179 }
33180
33181 - if (!cs->open_count) {
33182 + if (!local_read(&cs->open_count)) {
33183 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33184 goto out;
33185 }
33186 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33187 index 2a57da59..e7a12ed 100644
33188 --- a/drivers/isdn/hardware/avm/b1.c
33189 +++ b/drivers/isdn/hardware/avm/b1.c
33190 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
33191 }
33192 if (left) {
33193 if (t4file->user) {
33194 - if (copy_from_user(buf, dp, left))
33195 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33196 return -EFAULT;
33197 } else {
33198 memcpy(buf, dp, left);
33199 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
33200 }
33201 if (left) {
33202 if (config->user) {
33203 - if (copy_from_user(buf, dp, left))
33204 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33205 return -EFAULT;
33206 } else {
33207 memcpy(buf, dp, left);
33208 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33209 index 85784a7..a19ca98 100644
33210 --- a/drivers/isdn/hardware/eicon/divasync.h
33211 +++ b/drivers/isdn/hardware/eicon/divasync.h
33212 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33213 } diva_didd_add_adapter_t;
33214 typedef struct _diva_didd_remove_adapter {
33215 IDI_CALL p_request;
33216 -} diva_didd_remove_adapter_t;
33217 +} __no_const diva_didd_remove_adapter_t;
33218 typedef struct _diva_didd_read_adapter_array {
33219 void * buffer;
33220 dword length;
33221 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33222 index a3bd163..8956575 100644
33223 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33224 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33225 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33226 typedef struct _diva_os_idi_adapter_interface {
33227 diva_init_card_proc_t cleanup_adapter_proc;
33228 diva_cmd_card_proc_t cmd_proc;
33229 -} diva_os_idi_adapter_interface_t;
33230 +} __no_const diva_os_idi_adapter_interface_t;
33231
33232 typedef struct _diva_os_xdi_adapter {
33233 struct list_head link;
33234 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33235 index 1f355bb..43f1fea 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/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
33248 index 8bc4915..4cc6a2e 100644
33249 --- a/drivers/leds/leds-mc13783.c
33250 +++ b/drivers/leds/leds-mc13783.c
33251 @@ -280,7 +280,7 @@ static int __devinit mc13783_led_probe(struct platform_device *pdev)
33252 return -EINVAL;
33253 }
33254
33255 - led = kzalloc(sizeof(*led) * pdata->num_leds, GFP_KERNEL);
33256 + led = kcalloc(pdata->num_leds, sizeof(*led), GFP_KERNEL);
33257 if (led == NULL) {
33258 dev_err(&pdev->dev, "failed to alloc memory\n");
33259 return -ENOMEM;
33260 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33261 index b5fdcb7..5b6c59f 100644
33262 --- a/drivers/lguest/core.c
33263 +++ b/drivers/lguest/core.c
33264 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33265 * it's worked so far. The end address needs +1 because __get_vm_area
33266 * allocates an extra guard page, so we need space for that.
33267 */
33268 +
33269 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33270 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33271 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33272 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33273 +#else
33274 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33275 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33276 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33277 +#endif
33278 +
33279 if (!switcher_vma) {
33280 err = -ENOMEM;
33281 printk("lguest: could not map switcher pages high\n");
33282 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33283 * Now the Switcher is mapped at the right address, we can't fail!
33284 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33285 */
33286 - memcpy(switcher_vma->addr, start_switcher_text,
33287 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33288 end_switcher_text - start_switcher_text);
33289
33290 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33291 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33292 index 3980903..ce25c5e 100644
33293 --- a/drivers/lguest/x86/core.c
33294 +++ b/drivers/lguest/x86/core.c
33295 @@ -59,7 +59,7 @@ static struct {
33296 /* Offset from where switcher.S was compiled to where we've copied it */
33297 static unsigned long switcher_offset(void)
33298 {
33299 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33300 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33301 }
33302
33303 /* This cpu's struct lguest_pages. */
33304 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33305 * These copies are pretty cheap, so we do them unconditionally: */
33306 /* Save the current Host top-level page directory.
33307 */
33308 +
33309 +#ifdef CONFIG_PAX_PER_CPU_PGD
33310 + pages->state.host_cr3 = read_cr3();
33311 +#else
33312 pages->state.host_cr3 = __pa(current->mm->pgd);
33313 +#endif
33314 +
33315 /*
33316 * Set up the Guest's page tables to see this CPU's pages (and no
33317 * other CPU's pages).
33318 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33319 * compiled-in switcher code and the high-mapped copy we just made.
33320 */
33321 for (i = 0; i < IDT_ENTRIES; i++)
33322 - default_idt_entries[i] += switcher_offset();
33323 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33324
33325 /*
33326 * Set up the Switcher's per-cpu areas.
33327 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33328 * it will be undisturbed when we switch. To change %cs and jump we
33329 * need this structure to feed to Intel's "lcall" instruction.
33330 */
33331 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33332 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33333 lguest_entry.segment = LGUEST_CS;
33334
33335 /*
33336 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33337 index 40634b0..4f5855e 100644
33338 --- a/drivers/lguest/x86/switcher_32.S
33339 +++ b/drivers/lguest/x86/switcher_32.S
33340 @@ -87,6 +87,7 @@
33341 #include <asm/page.h>
33342 #include <asm/segment.h>
33343 #include <asm/lguest.h>
33344 +#include <asm/processor-flags.h>
33345
33346 // We mark the start of the code to copy
33347 // It's placed in .text tho it's never run here
33348 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33349 // Changes type when we load it: damn Intel!
33350 // For after we switch over our page tables
33351 // That entry will be read-only: we'd crash.
33352 +
33353 +#ifdef CONFIG_PAX_KERNEXEC
33354 + mov %cr0, %edx
33355 + xor $X86_CR0_WP, %edx
33356 + mov %edx, %cr0
33357 +#endif
33358 +
33359 movl $(GDT_ENTRY_TSS*8), %edx
33360 ltr %dx
33361
33362 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33363 // Let's clear it again for our return.
33364 // The GDT descriptor of the Host
33365 // Points to the table after two "size" bytes
33366 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33367 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33368 // Clear "used" from type field (byte 5, bit 2)
33369 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33370 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33371 +
33372 +#ifdef CONFIG_PAX_KERNEXEC
33373 + mov %cr0, %eax
33374 + xor $X86_CR0_WP, %eax
33375 + mov %eax, %cr0
33376 +#endif
33377
33378 // Once our page table's switched, the Guest is live!
33379 // The Host fades as we run this final step.
33380 @@ -295,13 +309,12 @@ deliver_to_host:
33381 // I consulted gcc, and it gave
33382 // These instructions, which I gladly credit:
33383 leal (%edx,%ebx,8), %eax
33384 - movzwl (%eax),%edx
33385 - movl 4(%eax), %eax
33386 - xorw %ax, %ax
33387 - orl %eax, %edx
33388 + movl 4(%eax), %edx
33389 + movw (%eax), %dx
33390 // Now the address of the handler's in %edx
33391 // We call it now: its "iret" drops us home.
33392 - jmp *%edx
33393 + ljmp $__KERNEL_CS, $1f
33394 +1: jmp *%edx
33395
33396 // Every interrupt can come to us here
33397 // But we must truly tell each apart.
33398 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33399 index 4daf9e5..b8d1d0f 100644
33400 --- a/drivers/macintosh/macio_asic.c
33401 +++ b/drivers/macintosh/macio_asic.c
33402 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33403 * MacIO is matched against any Apple ID, it's probe() function
33404 * will then decide wether it applies or not
33405 */
33406 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33407 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33408 .vendor = PCI_VENDOR_ID_APPLE,
33409 .device = PCI_ANY_ID,
33410 .subvendor = PCI_ANY_ID,
33411 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33412 index 1ce84ed..0fdd40a 100644
33413 --- a/drivers/md/dm-ioctl.c
33414 +++ b/drivers/md/dm-ioctl.c
33415 @@ -1589,7 +1589,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-log-userspace-transfer.c b/drivers/md/dm-log-userspace-transfer.c
33425 index 1f23e04..08d9a20 100644
33426 --- a/drivers/md/dm-log-userspace-transfer.c
33427 +++ b/drivers/md/dm-log-userspace-transfer.c
33428 @@ -134,7 +134,7 @@ static void cn_ulog_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp)
33429 {
33430 struct dm_ulog_request *tfr = (struct dm_ulog_request *)(msg + 1);
33431
33432 - if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
33433 + if (!capable(CAP_SYS_ADMIN))
33434 return;
33435
33436 spin_lock(&receiving_list_lock);
33437 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33438 index 9bfd057..01180bc 100644
33439 --- a/drivers/md/dm-raid1.c
33440 +++ b/drivers/md/dm-raid1.c
33441 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33442
33443 struct mirror {
33444 struct mirror_set *ms;
33445 - atomic_t error_count;
33446 + atomic_unchecked_t error_count;
33447 unsigned long error_type;
33448 struct dm_dev *dev;
33449 sector_t offset;
33450 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33451 struct mirror *m;
33452
33453 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33454 - if (!atomic_read(&m->error_count))
33455 + if (!atomic_read_unchecked(&m->error_count))
33456 return m;
33457
33458 return NULL;
33459 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33460 * simple way to tell if a device has encountered
33461 * errors.
33462 */
33463 - atomic_inc(&m->error_count);
33464 + atomic_inc_unchecked(&m->error_count);
33465
33466 if (test_and_set_bit(error_type, &m->error_type))
33467 return;
33468 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33469 struct mirror *m = get_default_mirror(ms);
33470
33471 do {
33472 - if (likely(!atomic_read(&m->error_count)))
33473 + if (likely(!atomic_read_unchecked(&m->error_count)))
33474 return m;
33475
33476 if (m-- == ms->mirror)
33477 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33478 {
33479 struct mirror *default_mirror = get_default_mirror(m->ms);
33480
33481 - return !atomic_read(&default_mirror->error_count);
33482 + return !atomic_read_unchecked(&default_mirror->error_count);
33483 }
33484
33485 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33486 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33487 */
33488 if (likely(region_in_sync(ms, region, 1)))
33489 m = choose_mirror(ms, bio->bi_sector);
33490 - else if (m && atomic_read(&m->error_count))
33491 + else if (m && atomic_read_unchecked(&m->error_count))
33492 m = NULL;
33493
33494 if (likely(m))
33495 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33496 }
33497
33498 ms->mirror[mirror].ms = ms;
33499 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33500 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33501 ms->mirror[mirror].error_type = 0;
33502 ms->mirror[mirror].offset = offset;
33503
33504 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
33505 */
33506 static char device_status_char(struct mirror *m)
33507 {
33508 - if (!atomic_read(&(m->error_count)))
33509 + if (!atomic_read_unchecked(&(m->error_count)))
33510 return 'A';
33511
33512 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33513 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33514 index 3d80cf0..b77cc47 100644
33515 --- a/drivers/md/dm-stripe.c
33516 +++ b/drivers/md/dm-stripe.c
33517 @@ -20,7 +20,7 @@ struct stripe {
33518 struct dm_dev *dev;
33519 sector_t physical_start;
33520
33521 - atomic_t error_count;
33522 + atomic_unchecked_t error_count;
33523 };
33524
33525 struct stripe_c {
33526 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33527 kfree(sc);
33528 return r;
33529 }
33530 - atomic_set(&(sc->stripe[i].error_count), 0);
33531 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33532 }
33533
33534 ti->private = sc;
33535 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
33536 DMEMIT("%d ", sc->stripes);
33537 for (i = 0; i < sc->stripes; i++) {
33538 DMEMIT("%s ", sc->stripe[i].dev->name);
33539 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33540 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33541 'D' : 'A';
33542 }
33543 buffer[i] = '\0';
33544 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33545 */
33546 for (i = 0; i < sc->stripes; i++)
33547 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33548 - atomic_inc(&(sc->stripe[i].error_count));
33549 - if (atomic_read(&(sc->stripe[i].error_count)) <
33550 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33551 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33552 DM_IO_ERROR_THRESHOLD)
33553 schedule_work(&sc->trigger_event);
33554 }
33555 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33556 index 63cc542..8d45caf3 100644
33557 --- a/drivers/md/dm-table.c
33558 +++ b/drivers/md/dm-table.c
33559 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33560 if (!dev_size)
33561 return 0;
33562
33563 - if ((start >= dev_size) || (start + len > dev_size)) {
33564 + if ((start >= dev_size) || (len > dev_size - start)) {
33565 DMWARN("%s: %s too small for target: "
33566 "start=%llu, len=%llu, dev_size=%llu",
33567 dm_device_name(ti->table->md), bdevname(bdev, b),
33568 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33569 index 237571a..fb6d19b 100644
33570 --- a/drivers/md/dm-thin-metadata.c
33571 +++ b/drivers/md/dm-thin-metadata.c
33572 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33573
33574 pmd->info.tm = tm;
33575 pmd->info.levels = 2;
33576 - pmd->info.value_type.context = pmd->data_sm;
33577 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33578 pmd->info.value_type.size = sizeof(__le64);
33579 pmd->info.value_type.inc = data_block_inc;
33580 pmd->info.value_type.dec = data_block_dec;
33581 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33582
33583 pmd->bl_info.tm = tm;
33584 pmd->bl_info.levels = 1;
33585 - pmd->bl_info.value_type.context = pmd->data_sm;
33586 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33587 pmd->bl_info.value_type.size = sizeof(__le64);
33588 pmd->bl_info.value_type.inc = data_block_inc;
33589 pmd->bl_info.value_type.dec = data_block_dec;
33590 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33591 index b89c548..2af3ce4 100644
33592 --- a/drivers/md/dm.c
33593 +++ b/drivers/md/dm.c
33594 @@ -176,9 +176,9 @@ struct mapped_device {
33595 /*
33596 * Event handling.
33597 */
33598 - atomic_t event_nr;
33599 + atomic_unchecked_t event_nr;
33600 wait_queue_head_t eventq;
33601 - atomic_t uevent_seq;
33602 + atomic_unchecked_t uevent_seq;
33603 struct list_head uevent_list;
33604 spinlock_t uevent_lock; /* Protect access to uevent_list */
33605
33606 @@ -1844,8 +1844,8 @@ static struct mapped_device *alloc_dev(int minor)
33607 rwlock_init(&md->map_lock);
33608 atomic_set(&md->holders, 1);
33609 atomic_set(&md->open_count, 0);
33610 - atomic_set(&md->event_nr, 0);
33611 - atomic_set(&md->uevent_seq, 0);
33612 + atomic_set_unchecked(&md->event_nr, 0);
33613 + atomic_set_unchecked(&md->uevent_seq, 0);
33614 INIT_LIST_HEAD(&md->uevent_list);
33615 spin_lock_init(&md->uevent_lock);
33616
33617 @@ -1979,7 +1979,7 @@ static void event_callback(void *context)
33618
33619 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33620
33621 - atomic_inc(&md->event_nr);
33622 + atomic_inc_unchecked(&md->event_nr);
33623 wake_up(&md->eventq);
33624 }
33625
33626 @@ -2621,18 +2621,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33627
33628 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33629 {
33630 - return atomic_add_return(1, &md->uevent_seq);
33631 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33632 }
33633
33634 uint32_t dm_get_event_nr(struct mapped_device *md)
33635 {
33636 - return atomic_read(&md->event_nr);
33637 + return atomic_read_unchecked(&md->event_nr);
33638 }
33639
33640 int dm_wait_event(struct mapped_device *md, int event_nr)
33641 {
33642 return wait_event_interruptible(md->eventq,
33643 - (event_nr != atomic_read(&md->event_nr)));
33644 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33645 }
33646
33647 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33648 diff --git a/drivers/md/md.c b/drivers/md/md.c
33649 index 1ae4327..4ecabb5 100644
33650 --- a/drivers/md/md.c
33651 +++ b/drivers/md/md.c
33652 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33653 * start build, activate spare
33654 */
33655 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33656 -static atomic_t md_event_count;
33657 +static atomic_unchecked_t md_event_count;
33658 void md_new_event(struct mddev *mddev)
33659 {
33660 - atomic_inc(&md_event_count);
33661 + atomic_inc_unchecked(&md_event_count);
33662 wake_up(&md_event_waiters);
33663 }
33664 EXPORT_SYMBOL_GPL(md_new_event);
33665 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33666 */
33667 static void md_new_event_inintr(struct mddev *mddev)
33668 {
33669 - atomic_inc(&md_event_count);
33670 + atomic_inc_unchecked(&md_event_count);
33671 wake_up(&md_event_waiters);
33672 }
33673
33674 @@ -1526,7 +1526,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33675
33676 rdev->preferred_minor = 0xffff;
33677 rdev->data_offset = le64_to_cpu(sb->data_offset);
33678 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33679 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33680
33681 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33682 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33683 @@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33684 else
33685 sb->resync_offset = cpu_to_le64(0);
33686
33687 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33688 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33689
33690 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33691 sb->size = cpu_to_le64(mddev->dev_sectors);
33692 @@ -2691,7 +2691,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33693 static ssize_t
33694 errors_show(struct md_rdev *rdev, char *page)
33695 {
33696 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33697 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33698 }
33699
33700 static ssize_t
33701 @@ -2700,7 +2700,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33702 char *e;
33703 unsigned long n = simple_strtoul(buf, &e, 10);
33704 if (*buf && (*e == 0 || *e == '\n')) {
33705 - atomic_set(&rdev->corrected_errors, n);
33706 + atomic_set_unchecked(&rdev->corrected_errors, n);
33707 return len;
33708 }
33709 return -EINVAL;
33710 @@ -3086,8 +3086,8 @@ int md_rdev_init(struct md_rdev *rdev)
33711 rdev->sb_loaded = 0;
33712 rdev->bb_page = NULL;
33713 atomic_set(&rdev->nr_pending, 0);
33714 - atomic_set(&rdev->read_errors, 0);
33715 - atomic_set(&rdev->corrected_errors, 0);
33716 + atomic_set_unchecked(&rdev->read_errors, 0);
33717 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33718
33719 INIT_LIST_HEAD(&rdev->same_set);
33720 init_waitqueue_head(&rdev->blocked_wait);
33721 @@ -6738,7 +6738,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33722
33723 spin_unlock(&pers_lock);
33724 seq_printf(seq, "\n");
33725 - seq->poll_event = atomic_read(&md_event_count);
33726 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33727 return 0;
33728 }
33729 if (v == (void*)2) {
33730 @@ -6830,7 +6830,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33731 chunk_kb ? "KB" : "B");
33732 if (bitmap->file) {
33733 seq_printf(seq, ", file: ");
33734 - seq_path(seq, &bitmap->file->f_path, " \t\n");
33735 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
33736 }
33737
33738 seq_printf(seq, "\n");
33739 @@ -6861,7 +6861,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33740 return error;
33741
33742 seq = file->private_data;
33743 - seq->poll_event = atomic_read(&md_event_count);
33744 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33745 return error;
33746 }
33747
33748 @@ -6875,7 +6875,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33749 /* always allow read */
33750 mask = POLLIN | POLLRDNORM;
33751
33752 - if (seq->poll_event != atomic_read(&md_event_count))
33753 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33754 mask |= POLLERR | POLLPRI;
33755 return mask;
33756 }
33757 @@ -6919,7 +6919,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33758 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33759 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33760 (int)part_stat_read(&disk->part0, sectors[1]) -
33761 - atomic_read(&disk->sync_io);
33762 + atomic_read_unchecked(&disk->sync_io);
33763 /* sync IO will cause sync_io to increase before the disk_stats
33764 * as sync_io is counted when a request starts, and
33765 * disk_stats is counted when it completes.
33766 diff --git a/drivers/md/md.h b/drivers/md/md.h
33767 index 44c63df..b795d1a 100644
33768 --- a/drivers/md/md.h
33769 +++ b/drivers/md/md.h
33770 @@ -93,13 +93,13 @@ struct md_rdev {
33771 * only maintained for arrays that
33772 * support hot removal
33773 */
33774 - atomic_t read_errors; /* number of consecutive read errors that
33775 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33776 * we have tried to ignore.
33777 */
33778 struct timespec last_read_error; /* monotonic time since our
33779 * last read error
33780 */
33781 - atomic_t corrected_errors; /* number of corrected read errors,
33782 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33783 * for reporting to userspace and storing
33784 * in superblock.
33785 */
33786 @@ -421,7 +421,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33787
33788 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33789 {
33790 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33791 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33792 }
33793
33794 struct md_personality
33795 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33796 index 50ed53b..4f29d7d 100644
33797 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33798 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33799 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
33800 /*----------------------------------------------------------------*/
33801
33802 struct sm_checker {
33803 - struct dm_space_map sm;
33804 + dm_space_map_no_const sm;
33805
33806 struct count_array old_counts;
33807 struct count_array counts;
33808 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33809 index fc469ba..2d91555 100644
33810 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33811 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33812 @@ -23,7 +23,7 @@
33813 * Space map interface.
33814 */
33815 struct sm_disk {
33816 - struct dm_space_map sm;
33817 + dm_space_map_no_const sm;
33818
33819 struct ll_disk ll;
33820 struct ll_disk old_ll;
33821 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33822 index e89ae5e..062e4c2 100644
33823 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33824 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33825 @@ -43,7 +43,7 @@ struct block_op {
33826 };
33827
33828 struct sm_metadata {
33829 - struct dm_space_map sm;
33830 + dm_space_map_no_const sm;
33831
33832 struct ll_disk ll;
33833 struct ll_disk old_ll;
33834 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33835 index 1cbfc6b..56e1dbb 100644
33836 --- a/drivers/md/persistent-data/dm-space-map.h
33837 +++ b/drivers/md/persistent-data/dm-space-map.h
33838 @@ -60,6 +60,7 @@ struct dm_space_map {
33839 int (*root_size)(struct dm_space_map *sm, size_t *result);
33840 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33841 };
33842 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33843
33844 /*----------------------------------------------------------------*/
33845
33846 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33847 index edc735a..e9b97f1 100644
33848 --- a/drivers/md/raid1.c
33849 +++ b/drivers/md/raid1.c
33850 @@ -1645,7 +1645,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33851 if (r1_sync_page_io(rdev, sect, s,
33852 bio->bi_io_vec[idx].bv_page,
33853 READ) != 0)
33854 - atomic_add(s, &rdev->corrected_errors);
33855 + atomic_add_unchecked(s, &rdev->corrected_errors);
33856 }
33857 sectors -= s;
33858 sect += s;
33859 @@ -1859,7 +1859,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33860 test_bit(In_sync, &rdev->flags)) {
33861 if (r1_sync_page_io(rdev, sect, s,
33862 conf->tmppage, READ)) {
33863 - atomic_add(s, &rdev->corrected_errors);
33864 + atomic_add_unchecked(s, &rdev->corrected_errors);
33865 printk(KERN_INFO
33866 "md/raid1:%s: read error corrected "
33867 "(%d sectors at %llu on %s)\n",
33868 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33869 index 1898389..a3aa617 100644
33870 --- a/drivers/md/raid10.c
33871 +++ b/drivers/md/raid10.c
33872 @@ -1636,7 +1636,7 @@ static void end_sync_read(struct bio *bio, int error)
33873 /* The write handler will notice the lack of
33874 * R10BIO_Uptodate and record any errors etc
33875 */
33876 - atomic_add(r10_bio->sectors,
33877 + atomic_add_unchecked(r10_bio->sectors,
33878 &conf->mirrors[d].rdev->corrected_errors);
33879
33880 /* for reconstruct, we always reschedule after a read.
33881 @@ -1987,7 +1987,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33882 {
33883 struct timespec cur_time_mon;
33884 unsigned long hours_since_last;
33885 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33886 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33887
33888 ktime_get_ts(&cur_time_mon);
33889
33890 @@ -2009,9 +2009,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33891 * overflowing the shift of read_errors by hours_since_last.
33892 */
33893 if (hours_since_last >= 8 * sizeof(read_errors))
33894 - atomic_set(&rdev->read_errors, 0);
33895 + atomic_set_unchecked(&rdev->read_errors, 0);
33896 else
33897 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33898 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33899 }
33900
33901 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33902 @@ -2065,8 +2065,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33903 return;
33904
33905 check_decay_read_errors(mddev, rdev);
33906 - atomic_inc(&rdev->read_errors);
33907 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33908 + atomic_inc_unchecked(&rdev->read_errors);
33909 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33910 char b[BDEVNAME_SIZE];
33911 bdevname(rdev->bdev, b);
33912
33913 @@ -2074,7 +2074,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33914 "md/raid10:%s: %s: Raid device exceeded "
33915 "read_error threshold [cur %d:max %d]\n",
33916 mdname(mddev), b,
33917 - atomic_read(&rdev->read_errors), max_read_errors);
33918 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33919 printk(KERN_NOTICE
33920 "md/raid10:%s: %s: Failing raid device\n",
33921 mdname(mddev), b);
33922 @@ -2223,7 +2223,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33923 (unsigned long long)(
33924 sect + rdev->data_offset),
33925 bdevname(rdev->bdev, b));
33926 - atomic_add(s, &rdev->corrected_errors);
33927 + atomic_add_unchecked(s, &rdev->corrected_errors);
33928 }
33929
33930 rdev_dec_pending(rdev, mddev);
33931 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33932 index d1162e5..c7cd902 100644
33933 --- a/drivers/md/raid5.c
33934 +++ b/drivers/md/raid5.c
33935 @@ -1687,18 +1687,18 @@ static void raid5_end_read_request(struct bio * bi, int error)
33936 (unsigned long long)(sh->sector
33937 + rdev->data_offset),
33938 bdevname(rdev->bdev, b));
33939 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33940 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33941 clear_bit(R5_ReadError, &sh->dev[i].flags);
33942 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33943 }
33944 - if (atomic_read(&rdev->read_errors))
33945 - atomic_set(&rdev->read_errors, 0);
33946 + if (atomic_read_unchecked(&rdev->read_errors))
33947 + atomic_set_unchecked(&rdev->read_errors, 0);
33948 } else {
33949 const char *bdn = bdevname(rdev->bdev, b);
33950 int retry = 0;
33951
33952 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33953 - atomic_inc(&rdev->read_errors);
33954 + atomic_inc_unchecked(&rdev->read_errors);
33955 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33956 printk_ratelimited(
33957 KERN_WARNING
33958 @@ -1727,7 +1727,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33959 (unsigned long long)(sh->sector
33960 + rdev->data_offset),
33961 bdn);
33962 - else if (atomic_read(&rdev->read_errors)
33963 + else if (atomic_read_unchecked(&rdev->read_errors)
33964 > conf->max_nr_stripes)
33965 printk(KERN_WARNING
33966 "md/raid:%s: Too many read errors, failing device %s.\n",
33967 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33968 index ce4f858..7bcfb46 100644
33969 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33970 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33971 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33972 .subvendor = _subvend, .subdevice = _subdev, \
33973 .driver_data = (unsigned long)&_driverdata }
33974
33975 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33976 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33977 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33978 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33979 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33980 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33981 index a7d876f..8c21b61 100644
33982 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33983 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33984 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33985 union {
33986 dmx_ts_cb ts;
33987 dmx_section_cb sec;
33988 - } cb;
33989 + } __no_const cb;
33990
33991 struct dvb_demux *demux;
33992 void *priv;
33993 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33994 index 00a6732..70a682e 100644
33995 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33996 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33997 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33998 const struct dvb_device *template, void *priv, int type)
33999 {
34000 struct dvb_device *dvbdev;
34001 - struct file_operations *dvbdevfops;
34002 + file_operations_no_const *dvbdevfops;
34003 struct device *clsdev;
34004 int minor;
34005 int id;
34006 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
34007 index 3940bb0..fb3952a 100644
34008 --- a/drivers/media/dvb/dvb-usb/cxusb.c
34009 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
34010 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
34011
34012 struct dib0700_adapter_state {
34013 int (*set_param_save) (struct dvb_frontend *);
34014 -};
34015 +} __no_const;
34016
34017 static int dib7070_set_param_override(struct dvb_frontend *fe)
34018 {
34019 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
34020 index 451c5a7..649f711 100644
34021 --- a/drivers/media/dvb/dvb-usb/dw2102.c
34022 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
34023 @@ -95,7 +95,7 @@ struct su3000_state {
34024
34025 struct s6x0_state {
34026 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
34027 -};
34028 +} __no_const;
34029
34030 /* debug */
34031 static int dvb_usb_dw2102_debug;
34032 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
34033 index 404f63a..4796533 100644
34034 --- a/drivers/media/dvb/frontends/dib3000.h
34035 +++ b/drivers/media/dvb/frontends/dib3000.h
34036 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
34037 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
34038 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
34039 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
34040 -};
34041 +} __no_const;
34042
34043 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
34044 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
34045 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
34046 index 8418c02..8555013 100644
34047 --- a/drivers/media/dvb/ngene/ngene-cards.c
34048 +++ b/drivers/media/dvb/ngene/ngene-cards.c
34049 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
34050
34051 /****************************************************************************/
34052
34053 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
34054 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34055 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34056 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34057 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34058 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34059 index 16a089f..1661b11 100644
34060 --- a/drivers/media/radio/radio-cadet.c
34061 +++ b/drivers/media/radio/radio-cadet.c
34062 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34063 unsigned char readbuf[RDS_BUFFER];
34064 int i = 0;
34065
34066 + if (count > RDS_BUFFER)
34067 + return -EFAULT;
34068 mutex_lock(&dev->lock);
34069 if (dev->rdsstat == 0) {
34070 dev->rdsstat = 1;
34071 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34072 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34073 mutex_unlock(&dev->lock);
34074
34075 - if (copy_to_user(data, readbuf, i))
34076 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34077 return -EFAULT;
34078 return i;
34079 }
34080 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34081 index 9cde353..8c6a1c3 100644
34082 --- a/drivers/media/video/au0828/au0828.h
34083 +++ b/drivers/media/video/au0828/au0828.h
34084 @@ -191,7 +191,7 @@ struct au0828_dev {
34085
34086 /* I2C */
34087 struct i2c_adapter i2c_adap;
34088 - struct i2c_algorithm i2c_algo;
34089 + i2c_algorithm_no_const i2c_algo;
34090 struct i2c_client i2c_client;
34091 u32 i2c_rc;
34092
34093 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34094 index 04bf662..e0ac026 100644
34095 --- a/drivers/media/video/cx88/cx88-alsa.c
34096 +++ b/drivers/media/video/cx88/cx88-alsa.c
34097 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34098 * Only boards with eeprom and byte 1 at eeprom=1 have it
34099 */
34100
34101 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34102 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34103 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34104 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34105 {0, }
34106 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34107 index 1fb7d5b..3901e77 100644
34108 --- a/drivers/media/video/omap/omap_vout.c
34109 +++ b/drivers/media/video/omap/omap_vout.c
34110 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34111 OMAP_VIDEO2,
34112 };
34113
34114 -static struct videobuf_queue_ops video_vbq_ops;
34115 /* Variables configurable through module params*/
34116 static u32 video1_numbuffers = 3;
34117 static u32 video2_numbuffers = 3;
34118 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34119 {
34120 struct videobuf_queue *q;
34121 struct omap_vout_device *vout = NULL;
34122 + static struct videobuf_queue_ops video_vbq_ops = {
34123 + .buf_setup = omap_vout_buffer_setup,
34124 + .buf_prepare = omap_vout_buffer_prepare,
34125 + .buf_release = omap_vout_buffer_release,
34126 + .buf_queue = omap_vout_buffer_queue,
34127 + };
34128
34129 vout = video_drvdata(file);
34130 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34131 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34132 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34133
34134 q = &vout->vbq;
34135 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34136 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34137 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34138 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34139 spin_lock_init(&vout->vbq_lock);
34140
34141 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34142 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34143 index 305e6aa..0143317 100644
34144 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34145 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34146 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34147
34148 /* I2C stuff */
34149 struct i2c_adapter i2c_adap;
34150 - struct i2c_algorithm i2c_algo;
34151 + i2c_algorithm_no_const i2c_algo;
34152 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34153 int i2c_cx25840_hack_state;
34154 int i2c_linked;
34155 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34156 index 4ed1c7c2..8f15e13 100644
34157 --- a/drivers/media/video/timblogiw.c
34158 +++ b/drivers/media/video/timblogiw.c
34159 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34160
34161 /* Platform device functions */
34162
34163 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34164 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34165 .vidioc_querycap = timblogiw_querycap,
34166 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34167 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34168 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34169 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34170 };
34171
34172 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34173 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34174 .owner = THIS_MODULE,
34175 .open = timblogiw_open,
34176 .release = timblogiw_close,
34177 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34178 index a7dc467..a55c423 100644
34179 --- a/drivers/message/fusion/mptbase.c
34180 +++ b/drivers/message/fusion/mptbase.c
34181 @@ -6754,8 +6754,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34182 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34183 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34184
34185 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34186 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34187 +#else
34188 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34189 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34190 +#endif
34191 +
34192 /*
34193 * Rounding UP to nearest 4-kB boundary here...
34194 */
34195 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34196 index 551262e..7551198 100644
34197 --- a/drivers/message/fusion/mptsas.c
34198 +++ b/drivers/message/fusion/mptsas.c
34199 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34200 return 0;
34201 }
34202
34203 +static inline void
34204 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34205 +{
34206 + if (phy_info->port_details) {
34207 + phy_info->port_details->rphy = rphy;
34208 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34209 + ioc->name, rphy));
34210 + }
34211 +
34212 + if (rphy) {
34213 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34214 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34215 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34216 + ioc->name, rphy, rphy->dev.release));
34217 + }
34218 +}
34219 +
34220 /* no mutex */
34221 static void
34222 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34223 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34224 return NULL;
34225 }
34226
34227 -static inline void
34228 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34229 -{
34230 - if (phy_info->port_details) {
34231 - phy_info->port_details->rphy = rphy;
34232 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34233 - ioc->name, rphy));
34234 - }
34235 -
34236 - if (rphy) {
34237 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34238 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34239 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34240 - ioc->name, rphy, rphy->dev.release));
34241 - }
34242 -}
34243 -
34244 static inline struct sas_port *
34245 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34246 {
34247 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34248 index 0c3ced7..1fe34ec 100644
34249 --- a/drivers/message/fusion/mptscsih.c
34250 +++ b/drivers/message/fusion/mptscsih.c
34251 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34252
34253 h = shost_priv(SChost);
34254
34255 - if (h) {
34256 - if (h->info_kbuf == NULL)
34257 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34258 - return h->info_kbuf;
34259 - h->info_kbuf[0] = '\0';
34260 + if (!h)
34261 + return NULL;
34262
34263 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34264 - h->info_kbuf[size-1] = '\0';
34265 - }
34266 + if (h->info_kbuf == NULL)
34267 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34268 + return h->info_kbuf;
34269 + h->info_kbuf[0] = '\0';
34270 +
34271 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34272 + h->info_kbuf[size-1] = '\0';
34273
34274 return h->info_kbuf;
34275 }
34276 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34277 index 6d115c7..58ff7fd 100644
34278 --- a/drivers/message/i2o/i2o_proc.c
34279 +++ b/drivers/message/i2o/i2o_proc.c
34280 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34281 "Array Controller Device"
34282 };
34283
34284 -static char *chtostr(u8 * chars, int n)
34285 -{
34286 - char tmp[256];
34287 - tmp[0] = 0;
34288 - return strncat(tmp, (char *)chars, n);
34289 -}
34290 -
34291 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34292 char *group)
34293 {
34294 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34295
34296 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34297 seq_printf(seq, "%-#8x", ddm_table.module_id);
34298 - seq_printf(seq, "%-29s",
34299 - chtostr(ddm_table.module_name_version, 28));
34300 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34301 seq_printf(seq, "%9d ", ddm_table.data_size);
34302 seq_printf(seq, "%8d", ddm_table.code_size);
34303
34304 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34305
34306 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34307 seq_printf(seq, "%-#8x", dst->module_id);
34308 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34309 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34310 + seq_printf(seq, "%-.28s", dst->module_name_version);
34311 + seq_printf(seq, "%-.8s", dst->date);
34312 seq_printf(seq, "%8d ", dst->module_size);
34313 seq_printf(seq, "%8d ", dst->mpb_size);
34314 seq_printf(seq, "0x%04x", dst->module_flags);
34315 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34316 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34317 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34318 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34319 - seq_printf(seq, "Vendor info : %s\n",
34320 - chtostr((u8 *) (work32 + 2), 16));
34321 - seq_printf(seq, "Product info : %s\n",
34322 - chtostr((u8 *) (work32 + 6), 16));
34323 - seq_printf(seq, "Description : %s\n",
34324 - chtostr((u8 *) (work32 + 10), 16));
34325 - seq_printf(seq, "Product rev. : %s\n",
34326 - chtostr((u8 *) (work32 + 14), 8));
34327 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34328 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34329 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34330 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34331
34332 seq_printf(seq, "Serial number : ");
34333 print_serial_number(seq, (u8 *) (work32 + 16),
34334 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34335 }
34336
34337 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34338 - seq_printf(seq, "Module name : %s\n",
34339 - chtostr(result.module_name, 24));
34340 - seq_printf(seq, "Module revision : %s\n",
34341 - chtostr(result.module_rev, 8));
34342 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34343 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34344
34345 seq_printf(seq, "Serial number : ");
34346 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34347 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34348 return 0;
34349 }
34350
34351 - seq_printf(seq, "Device name : %s\n",
34352 - chtostr(result.device_name, 64));
34353 - seq_printf(seq, "Service name : %s\n",
34354 - chtostr(result.service_name, 64));
34355 - seq_printf(seq, "Physical name : %s\n",
34356 - chtostr(result.physical_location, 64));
34357 - seq_printf(seq, "Instance number : %s\n",
34358 - chtostr(result.instance_number, 4));
34359 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34360 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34361 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34362 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34363
34364 return 0;
34365 }
34366 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34367 index a8c08f3..155fe3d 100644
34368 --- a/drivers/message/i2o/iop.c
34369 +++ b/drivers/message/i2o/iop.c
34370 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34371
34372 spin_lock_irqsave(&c->context_list_lock, flags);
34373
34374 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34375 - atomic_inc(&c->context_list_counter);
34376 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34377 + atomic_inc_unchecked(&c->context_list_counter);
34378
34379 - entry->context = atomic_read(&c->context_list_counter);
34380 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34381
34382 list_add(&entry->list, &c->context_list);
34383
34384 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34385
34386 #if BITS_PER_LONG == 64
34387 spin_lock_init(&c->context_list_lock);
34388 - atomic_set(&c->context_list_counter, 0);
34389 + atomic_set_unchecked(&c->context_list_counter, 0);
34390 INIT_LIST_HEAD(&c->context_list);
34391 #endif
34392
34393 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34394 index 7ce65f4..e66e9bc 100644
34395 --- a/drivers/mfd/abx500-core.c
34396 +++ b/drivers/mfd/abx500-core.c
34397 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34398
34399 struct abx500_device_entry {
34400 struct list_head list;
34401 - struct abx500_ops ops;
34402 + abx500_ops_no_const ops;
34403 struct device *dev;
34404 };
34405
34406 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34407 index a9223ed..4127b13 100644
34408 --- a/drivers/mfd/janz-cmodio.c
34409 +++ b/drivers/mfd/janz-cmodio.c
34410 @@ -13,6 +13,7 @@
34411
34412 #include <linux/kernel.h>
34413 #include <linux/module.h>
34414 +#include <linux/slab.h>
34415 #include <linux/init.h>
34416 #include <linux/pci.h>
34417 #include <linux/interrupt.h>
34418 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34419 index a981e2a..5ca0c8b 100644
34420 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34421 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34422 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34423 * the lid is closed. This leads to interrupts as soon as a little move
34424 * is done.
34425 */
34426 - atomic_inc(&lis3->count);
34427 + atomic_inc_unchecked(&lis3->count);
34428
34429 wake_up_interruptible(&lis3->misc_wait);
34430 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34431 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34432 if (lis3->pm_dev)
34433 pm_runtime_get_sync(lis3->pm_dev);
34434
34435 - atomic_set(&lis3->count, 0);
34436 + atomic_set_unchecked(&lis3->count, 0);
34437 return 0;
34438 }
34439
34440 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34441 add_wait_queue(&lis3->misc_wait, &wait);
34442 while (true) {
34443 set_current_state(TASK_INTERRUPTIBLE);
34444 - data = atomic_xchg(&lis3->count, 0);
34445 + data = atomic_xchg_unchecked(&lis3->count, 0);
34446 if (data)
34447 break;
34448
34449 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34450 struct lis3lv02d, miscdev);
34451
34452 poll_wait(file, &lis3->misc_wait, wait);
34453 - if (atomic_read(&lis3->count))
34454 + if (atomic_read_unchecked(&lis3->count))
34455 return POLLIN | POLLRDNORM;
34456 return 0;
34457 }
34458 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34459 index 2b1482a..5d33616 100644
34460 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34461 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34462 @@ -266,7 +266,7 @@ struct lis3lv02d {
34463 struct input_polled_dev *idev; /* input device */
34464 struct platform_device *pdev; /* platform device */
34465 struct regulator_bulk_data regulators[2];
34466 - atomic_t count; /* interrupt count after last read */
34467 + atomic_unchecked_t count; /* interrupt count after last read */
34468 union axis_conversion ac; /* hw -> logical axis */
34469 int mapped_btns[3];
34470
34471 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34472 index 2f30bad..c4c13d0 100644
34473 --- a/drivers/misc/sgi-gru/gruhandles.c
34474 +++ b/drivers/misc/sgi-gru/gruhandles.c
34475 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34476 unsigned long nsec;
34477
34478 nsec = CLKS2NSEC(clks);
34479 - atomic_long_inc(&mcs_op_statistics[op].count);
34480 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34481 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34482 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34483 if (mcs_op_statistics[op].max < nsec)
34484 mcs_op_statistics[op].max = nsec;
34485 }
34486 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34487 index 950dbe9..eeef0f8 100644
34488 --- a/drivers/misc/sgi-gru/gruprocfs.c
34489 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34490 @@ -32,9 +32,9 @@
34491
34492 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34493
34494 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34495 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34496 {
34497 - unsigned long val = atomic_long_read(v);
34498 + unsigned long val = atomic_long_read_unchecked(v);
34499
34500 seq_printf(s, "%16lu %s\n", val, id);
34501 }
34502 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34503
34504 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34505 for (op = 0; op < mcsop_last; op++) {
34506 - count = atomic_long_read(&mcs_op_statistics[op].count);
34507 - total = atomic_long_read(&mcs_op_statistics[op].total);
34508 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34509 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34510 max = mcs_op_statistics[op].max;
34511 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34512 count ? total / count : 0, max);
34513 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34514 index 5c3ce24..4915ccb 100644
34515 --- a/drivers/misc/sgi-gru/grutables.h
34516 +++ b/drivers/misc/sgi-gru/grutables.h
34517 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34518 * GRU statistics.
34519 */
34520 struct gru_stats_s {
34521 - atomic_long_t vdata_alloc;
34522 - atomic_long_t vdata_free;
34523 - atomic_long_t gts_alloc;
34524 - atomic_long_t gts_free;
34525 - atomic_long_t gms_alloc;
34526 - atomic_long_t gms_free;
34527 - atomic_long_t gts_double_allocate;
34528 - atomic_long_t assign_context;
34529 - atomic_long_t assign_context_failed;
34530 - atomic_long_t free_context;
34531 - atomic_long_t load_user_context;
34532 - atomic_long_t load_kernel_context;
34533 - atomic_long_t lock_kernel_context;
34534 - atomic_long_t unlock_kernel_context;
34535 - atomic_long_t steal_user_context;
34536 - atomic_long_t steal_kernel_context;
34537 - atomic_long_t steal_context_failed;
34538 - atomic_long_t nopfn;
34539 - atomic_long_t asid_new;
34540 - atomic_long_t asid_next;
34541 - atomic_long_t asid_wrap;
34542 - atomic_long_t asid_reuse;
34543 - atomic_long_t intr;
34544 - atomic_long_t intr_cbr;
34545 - atomic_long_t intr_tfh;
34546 - atomic_long_t intr_spurious;
34547 - atomic_long_t intr_mm_lock_failed;
34548 - atomic_long_t call_os;
34549 - atomic_long_t call_os_wait_queue;
34550 - atomic_long_t user_flush_tlb;
34551 - atomic_long_t user_unload_context;
34552 - atomic_long_t user_exception;
34553 - atomic_long_t set_context_option;
34554 - atomic_long_t check_context_retarget_intr;
34555 - atomic_long_t check_context_unload;
34556 - atomic_long_t tlb_dropin;
34557 - atomic_long_t tlb_preload_page;
34558 - atomic_long_t tlb_dropin_fail_no_asid;
34559 - atomic_long_t tlb_dropin_fail_upm;
34560 - atomic_long_t tlb_dropin_fail_invalid;
34561 - atomic_long_t tlb_dropin_fail_range_active;
34562 - atomic_long_t tlb_dropin_fail_idle;
34563 - atomic_long_t tlb_dropin_fail_fmm;
34564 - atomic_long_t tlb_dropin_fail_no_exception;
34565 - atomic_long_t tfh_stale_on_fault;
34566 - atomic_long_t mmu_invalidate_range;
34567 - atomic_long_t mmu_invalidate_page;
34568 - atomic_long_t flush_tlb;
34569 - atomic_long_t flush_tlb_gru;
34570 - atomic_long_t flush_tlb_gru_tgh;
34571 - atomic_long_t flush_tlb_gru_zero_asid;
34572 + atomic_long_unchecked_t vdata_alloc;
34573 + atomic_long_unchecked_t vdata_free;
34574 + atomic_long_unchecked_t gts_alloc;
34575 + atomic_long_unchecked_t gts_free;
34576 + atomic_long_unchecked_t gms_alloc;
34577 + atomic_long_unchecked_t gms_free;
34578 + atomic_long_unchecked_t gts_double_allocate;
34579 + atomic_long_unchecked_t assign_context;
34580 + atomic_long_unchecked_t assign_context_failed;
34581 + atomic_long_unchecked_t free_context;
34582 + atomic_long_unchecked_t load_user_context;
34583 + atomic_long_unchecked_t load_kernel_context;
34584 + atomic_long_unchecked_t lock_kernel_context;
34585 + atomic_long_unchecked_t unlock_kernel_context;
34586 + atomic_long_unchecked_t steal_user_context;
34587 + atomic_long_unchecked_t steal_kernel_context;
34588 + atomic_long_unchecked_t steal_context_failed;
34589 + atomic_long_unchecked_t nopfn;
34590 + atomic_long_unchecked_t asid_new;
34591 + atomic_long_unchecked_t asid_next;
34592 + atomic_long_unchecked_t asid_wrap;
34593 + atomic_long_unchecked_t asid_reuse;
34594 + atomic_long_unchecked_t intr;
34595 + atomic_long_unchecked_t intr_cbr;
34596 + atomic_long_unchecked_t intr_tfh;
34597 + atomic_long_unchecked_t intr_spurious;
34598 + atomic_long_unchecked_t intr_mm_lock_failed;
34599 + atomic_long_unchecked_t call_os;
34600 + atomic_long_unchecked_t call_os_wait_queue;
34601 + atomic_long_unchecked_t user_flush_tlb;
34602 + atomic_long_unchecked_t user_unload_context;
34603 + atomic_long_unchecked_t user_exception;
34604 + atomic_long_unchecked_t set_context_option;
34605 + atomic_long_unchecked_t check_context_retarget_intr;
34606 + atomic_long_unchecked_t check_context_unload;
34607 + atomic_long_unchecked_t tlb_dropin;
34608 + atomic_long_unchecked_t tlb_preload_page;
34609 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34610 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34611 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34612 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34613 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34614 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34615 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34616 + atomic_long_unchecked_t tfh_stale_on_fault;
34617 + atomic_long_unchecked_t mmu_invalidate_range;
34618 + atomic_long_unchecked_t mmu_invalidate_page;
34619 + atomic_long_unchecked_t flush_tlb;
34620 + atomic_long_unchecked_t flush_tlb_gru;
34621 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34622 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34623
34624 - atomic_long_t copy_gpa;
34625 - atomic_long_t read_gpa;
34626 + atomic_long_unchecked_t copy_gpa;
34627 + atomic_long_unchecked_t read_gpa;
34628
34629 - atomic_long_t mesq_receive;
34630 - atomic_long_t mesq_receive_none;
34631 - atomic_long_t mesq_send;
34632 - atomic_long_t mesq_send_failed;
34633 - atomic_long_t mesq_noop;
34634 - atomic_long_t mesq_send_unexpected_error;
34635 - atomic_long_t mesq_send_lb_overflow;
34636 - atomic_long_t mesq_send_qlimit_reached;
34637 - atomic_long_t mesq_send_amo_nacked;
34638 - atomic_long_t mesq_send_put_nacked;
34639 - atomic_long_t mesq_page_overflow;
34640 - atomic_long_t mesq_qf_locked;
34641 - atomic_long_t mesq_qf_noop_not_full;
34642 - atomic_long_t mesq_qf_switch_head_failed;
34643 - atomic_long_t mesq_qf_unexpected_error;
34644 - atomic_long_t mesq_noop_unexpected_error;
34645 - atomic_long_t mesq_noop_lb_overflow;
34646 - atomic_long_t mesq_noop_qlimit_reached;
34647 - atomic_long_t mesq_noop_amo_nacked;
34648 - atomic_long_t mesq_noop_put_nacked;
34649 - atomic_long_t mesq_noop_page_overflow;
34650 + atomic_long_unchecked_t mesq_receive;
34651 + atomic_long_unchecked_t mesq_receive_none;
34652 + atomic_long_unchecked_t mesq_send;
34653 + atomic_long_unchecked_t mesq_send_failed;
34654 + atomic_long_unchecked_t mesq_noop;
34655 + atomic_long_unchecked_t mesq_send_unexpected_error;
34656 + atomic_long_unchecked_t mesq_send_lb_overflow;
34657 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34658 + atomic_long_unchecked_t mesq_send_amo_nacked;
34659 + atomic_long_unchecked_t mesq_send_put_nacked;
34660 + atomic_long_unchecked_t mesq_page_overflow;
34661 + atomic_long_unchecked_t mesq_qf_locked;
34662 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34663 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34664 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34665 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34666 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34667 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34668 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34669 + atomic_long_unchecked_t mesq_noop_put_nacked;
34670 + atomic_long_unchecked_t mesq_noop_page_overflow;
34671
34672 };
34673
34674 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34675 tghop_invalidate, mcsop_last};
34676
34677 struct mcs_op_statistic {
34678 - atomic_long_t count;
34679 - atomic_long_t total;
34680 + atomic_long_unchecked_t count;
34681 + atomic_long_unchecked_t total;
34682 unsigned long max;
34683 };
34684
34685 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34686
34687 #define STAT(id) do { \
34688 if (gru_options & OPT_STATS) \
34689 - atomic_long_inc(&gru_stats.id); \
34690 + atomic_long_inc_unchecked(&gru_stats.id); \
34691 } while (0)
34692
34693 #ifdef CONFIG_SGI_GRU_DEBUG
34694 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34695 index 851b2f2..a4ec097 100644
34696 --- a/drivers/misc/sgi-xp/xp.h
34697 +++ b/drivers/misc/sgi-xp/xp.h
34698 @@ -289,7 +289,7 @@ struct xpc_interface {
34699 xpc_notify_func, void *);
34700 void (*received) (short, int, void *);
34701 enum xp_retval (*partid_to_nasids) (short, void *);
34702 -};
34703 +} __no_const;
34704
34705 extern struct xpc_interface xpc_interface;
34706
34707 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34708 index b94d5f7..7f494c5 100644
34709 --- a/drivers/misc/sgi-xp/xpc.h
34710 +++ b/drivers/misc/sgi-xp/xpc.h
34711 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34712 void (*received_payload) (struct xpc_channel *, void *);
34713 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34714 };
34715 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34716
34717 /* struct xpc_partition act_state values (for XPC HB) */
34718
34719 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34720 /* found in xpc_main.c */
34721 extern struct device *xpc_part;
34722 extern struct device *xpc_chan;
34723 -extern struct xpc_arch_operations xpc_arch_ops;
34724 +extern xpc_arch_operations_no_const xpc_arch_ops;
34725 extern int xpc_disengage_timelimit;
34726 extern int xpc_disengage_timedout;
34727 extern int xpc_activate_IRQ_rcvd;
34728 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34729 index 8d082b4..aa749ae 100644
34730 --- a/drivers/misc/sgi-xp/xpc_main.c
34731 +++ b/drivers/misc/sgi-xp/xpc_main.c
34732 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34733 .notifier_call = xpc_system_die,
34734 };
34735
34736 -struct xpc_arch_operations xpc_arch_ops;
34737 +xpc_arch_operations_no_const xpc_arch_ops;
34738
34739 /*
34740 * Timer function to enforce the timelimit on the partition disengage.
34741 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34742 index 6ebdc40..9edf5d8 100644
34743 --- a/drivers/mmc/host/sdhci-pci.c
34744 +++ b/drivers/mmc/host/sdhci-pci.c
34745 @@ -631,7 +631,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34746 .probe = via_probe,
34747 };
34748
34749 -static const struct pci_device_id pci_ids[] __devinitdata = {
34750 +static const struct pci_device_id pci_ids[] __devinitconst = {
34751 {
34752 .vendor = PCI_VENDOR_ID_RICOH,
34753 .device = PCI_DEVICE_ID_RICOH_R5C822,
34754 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34755 index 87a431c..4959b43 100644
34756 --- a/drivers/mtd/devices/doc2000.c
34757 +++ b/drivers/mtd/devices/doc2000.c
34758 @@ -764,7 +764,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34759
34760 /* The ECC will not be calculated correctly if less than 512 is written */
34761 /* DBB-
34762 - if (len != 0x200 && eccbuf)
34763 + if (len != 0x200)
34764 printk(KERN_WARNING
34765 "ECC needs a full sector write (adr: %lx size %lx)\n",
34766 (long) to, (long) len);
34767 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
34768 index 9eacf67..4534b5b 100644
34769 --- a/drivers/mtd/devices/doc2001.c
34770 +++ b/drivers/mtd/devices/doc2001.c
34771 @@ -384,7 +384,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
34772 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
34773
34774 /* Don't allow read past end of device */
34775 - if (from >= this->totlen)
34776 + if (from >= this->totlen || !len)
34777 return -EINVAL;
34778
34779 /* Don't allow a single read to cross a 512-byte block boundary */
34780 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34781 index 3984d48..28aa897 100644
34782 --- a/drivers/mtd/nand/denali.c
34783 +++ b/drivers/mtd/nand/denali.c
34784 @@ -26,6 +26,7 @@
34785 #include <linux/pci.h>
34786 #include <linux/mtd/mtd.h>
34787 #include <linux/module.h>
34788 +#include <linux/slab.h>
34789
34790 #include "denali.h"
34791
34792 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34793 index 51b9d6a..52af9a7 100644
34794 --- a/drivers/mtd/nftlmount.c
34795 +++ b/drivers/mtd/nftlmount.c
34796 @@ -24,6 +24,7 @@
34797 #include <asm/errno.h>
34798 #include <linux/delay.h>
34799 #include <linux/slab.h>
34800 +#include <linux/sched.h>
34801 #include <linux/mtd/mtd.h>
34802 #include <linux/mtd/nand.h>
34803 #include <linux/mtd/nftl.h>
34804 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34805 index 071f4c8..440862e 100644
34806 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34807 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34808 @@ -2862,7 +2862,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34809 */
34810
34811 #define ATL2_PARAM(X, desc) \
34812 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34813 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34814 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34815 MODULE_PARM_DESC(X, desc);
34816 #else
34817 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34818 index 66da39f..5dc436d 100644
34819 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34820 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34821 @@ -473,7 +473,7 @@ struct bnx2x_rx_mode_obj {
34822
34823 int (*wait_comp)(struct bnx2x *bp,
34824 struct bnx2x_rx_mode_ramrod_params *p);
34825 -};
34826 +} __no_const;
34827
34828 /********************** Set multicast group ***********************************/
34829
34830 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34831 index aea8f72..fcebf75 100644
34832 --- a/drivers/net/ethernet/broadcom/tg3.h
34833 +++ b/drivers/net/ethernet/broadcom/tg3.h
34834 @@ -140,6 +140,7 @@
34835 #define CHIPREV_ID_5750_A0 0x4000
34836 #define CHIPREV_ID_5750_A1 0x4001
34837 #define CHIPREV_ID_5750_A3 0x4003
34838 +#define CHIPREV_ID_5750_C1 0x4201
34839 #define CHIPREV_ID_5750_C2 0x4202
34840 #define CHIPREV_ID_5752_A0_HW 0x5000
34841 #define CHIPREV_ID_5752_A0 0x6000
34842 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34843 index c4e8643..0979484 100644
34844 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34845 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34846 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34847 */
34848 struct l2t_skb_cb {
34849 arp_failure_handler_func arp_failure_handler;
34850 -};
34851 +} __no_const;
34852
34853 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34854
34855 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34856 index 4d71f5a..8004440 100644
34857 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34858 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34859 @@ -5392,7 +5392,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34860 for (i=0; i<ETH_ALEN; i++) {
34861 tmp.addr[i] = dev->dev_addr[i];
34862 }
34863 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34864 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34865 break;
34866
34867 case DE4X5_SET_HWADDR: /* Set the hardware address */
34868 @@ -5432,7 +5432,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34869 spin_lock_irqsave(&lp->lock, flags);
34870 memcpy(&statbuf, &lp->pktStats, ioc->len);
34871 spin_unlock_irqrestore(&lp->lock, flags);
34872 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34873 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34874 return -EFAULT;
34875 break;
34876 }
34877 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34878 index 14d5b61..1398636 100644
34879 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34880 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34881 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34882 {NULL}};
34883
34884
34885 -static const char *block_name[] __devinitdata = {
34886 +static const char *block_name[] __devinitconst = {
34887 "21140 non-MII",
34888 "21140 MII PHY",
34889 "21142 Serial PHY",
34890 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34891 index 52da7b2..4ddfe1c 100644
34892 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34893 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34894 @@ -236,7 +236,7 @@ struct pci_id_info {
34895 int drv_flags; /* Driver use, intended as capability flags. */
34896 };
34897
34898 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34899 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34900 { /* Sometime a Level-One switch card. */
34901 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34902 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34903 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34904 index 28a3a9b..d96cb63 100644
34905 --- a/drivers/net/ethernet/dlink/sundance.c
34906 +++ b/drivers/net/ethernet/dlink/sundance.c
34907 @@ -218,7 +218,7 @@ enum {
34908 struct pci_id_info {
34909 const char *name;
34910 };
34911 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34912 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34913 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34914 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34915 {"D-Link DFE-580TX 4 port Server Adapter"},
34916 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34917 index e703d64..d62ecf9 100644
34918 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34919 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34920 @@ -402,7 +402,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34921
34922 if (wrapped)
34923 newacc += 65536;
34924 - ACCESS_ONCE(*acc) = newacc;
34925 + ACCESS_ONCE_RW(*acc) = newacc;
34926 }
34927
34928 void be_parse_stats(struct be_adapter *adapter)
34929 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34930 index 47f85c3..82ab6c4 100644
34931 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34932 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34933 @@ -31,6 +31,8 @@
34934 #include <linux/netdevice.h>
34935 #include <linux/phy.h>
34936 #include <linux/platform_device.h>
34937 +#include <linux/interrupt.h>
34938 +#include <linux/irqreturn.h>
34939 #include <net/ip.h>
34940
34941 #include "ftgmac100.h"
34942 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34943 index bb336a0..4b472da 100644
34944 --- a/drivers/net/ethernet/faraday/ftmac100.c
34945 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34946 @@ -31,6 +31,8 @@
34947 #include <linux/module.h>
34948 #include <linux/netdevice.h>
34949 #include <linux/platform_device.h>
34950 +#include <linux/interrupt.h>
34951 +#include <linux/irqreturn.h>
34952
34953 #include "ftmac100.h"
34954
34955 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34956 index c82d444..0007fb4 100644
34957 --- a/drivers/net/ethernet/fealnx.c
34958 +++ b/drivers/net/ethernet/fealnx.c
34959 @@ -150,7 +150,7 @@ struct chip_info {
34960 int flags;
34961 };
34962
34963 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34964 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34965 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34966 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34967 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34968 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34969 index e1159e5..e18684d 100644
34970 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34971 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
34972 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
34973 {
34974 struct e1000_hw *hw = &adapter->hw;
34975 struct e1000_mac_info *mac = &hw->mac;
34976 - struct e1000_mac_operations *func = &mac->ops;
34977 + e1000_mac_operations_no_const *func = &mac->ops;
34978
34979 /* Set media type */
34980 switch (adapter->pdev->device) {
34981 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
34982 index a3e65fd..f451444 100644
34983 --- a/drivers/net/ethernet/intel/e1000e/82571.c
34984 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
34985 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
34986 {
34987 struct e1000_hw *hw = &adapter->hw;
34988 struct e1000_mac_info *mac = &hw->mac;
34989 - struct e1000_mac_operations *func = &mac->ops;
34990 + e1000_mac_operations_no_const *func = &mac->ops;
34991 u32 swsm = 0;
34992 u32 swsm2 = 0;
34993 bool force_clear_smbi = false;
34994 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34995 index 2967039..ca8c40c 100644
34996 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34997 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34998 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
34999 void (*write_vfta)(struct e1000_hw *, u32, u32);
35000 s32 (*read_mac_addr)(struct e1000_hw *);
35001 };
35002 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35003
35004 /*
35005 * When to use various PHY register access functions:
35006 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
35007 void (*power_up)(struct e1000_hw *);
35008 void (*power_down)(struct e1000_hw *);
35009 };
35010 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35011
35012 /* Function pointers for the NVM. */
35013 struct e1000_nvm_operations {
35014 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
35015 s32 (*validate)(struct e1000_hw *);
35016 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35017 };
35018 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35019
35020 struct e1000_mac_info {
35021 - struct e1000_mac_operations ops;
35022 + e1000_mac_operations_no_const ops;
35023 u8 addr[ETH_ALEN];
35024 u8 perm_addr[ETH_ALEN];
35025
35026 @@ -872,7 +875,7 @@ struct e1000_mac_info {
35027 };
35028
35029 struct e1000_phy_info {
35030 - struct e1000_phy_operations ops;
35031 + e1000_phy_operations_no_const ops;
35032
35033 enum e1000_phy_type type;
35034
35035 @@ -906,7 +909,7 @@ struct e1000_phy_info {
35036 };
35037
35038 struct e1000_nvm_info {
35039 - struct e1000_nvm_operations ops;
35040 + e1000_nvm_operations_no_const ops;
35041
35042 enum e1000_nvm_type type;
35043 enum e1000_nvm_override override;
35044 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35045 index f67cbd3..cef9e3d 100644
35046 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35047 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35048 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
35049 s32 (*read_mac_addr)(struct e1000_hw *);
35050 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
35051 };
35052 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35053
35054 struct e1000_phy_operations {
35055 s32 (*acquire)(struct e1000_hw *);
35056 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
35057 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35058 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35059 };
35060 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35061
35062 struct e1000_nvm_operations {
35063 s32 (*acquire)(struct e1000_hw *);
35064 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
35065 s32 (*update)(struct e1000_hw *);
35066 s32 (*validate)(struct e1000_hw *);
35067 };
35068 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35069
35070 struct e1000_info {
35071 s32 (*get_invariants)(struct e1000_hw *);
35072 @@ -350,7 +353,7 @@ struct e1000_info {
35073 extern const struct e1000_info e1000_82575_info;
35074
35075 struct e1000_mac_info {
35076 - struct e1000_mac_operations ops;
35077 + e1000_mac_operations_no_const ops;
35078
35079 u8 addr[6];
35080 u8 perm_addr[6];
35081 @@ -388,7 +391,7 @@ struct e1000_mac_info {
35082 };
35083
35084 struct e1000_phy_info {
35085 - struct e1000_phy_operations ops;
35086 + e1000_phy_operations_no_const ops;
35087
35088 enum e1000_phy_type type;
35089
35090 @@ -423,7 +426,7 @@ struct e1000_phy_info {
35091 };
35092
35093 struct e1000_nvm_info {
35094 - struct e1000_nvm_operations ops;
35095 + e1000_nvm_operations_no_const ops;
35096 enum e1000_nvm_type type;
35097 enum e1000_nvm_override override;
35098
35099 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
35100 s32 (*check_for_ack)(struct e1000_hw *, u16);
35101 s32 (*check_for_rst)(struct e1000_hw *, u16);
35102 };
35103 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35104
35105 struct e1000_mbx_stats {
35106 u32 msgs_tx;
35107 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
35108 };
35109
35110 struct e1000_mbx_info {
35111 - struct e1000_mbx_operations ops;
35112 + e1000_mbx_operations_no_const ops;
35113 struct e1000_mbx_stats stats;
35114 u32 timeout;
35115 u32 usec_delay;
35116 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35117 index 57db3c6..aa825fc 100644
35118 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35119 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35120 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35121 s32 (*read_mac_addr)(struct e1000_hw *);
35122 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35123 };
35124 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35125
35126 struct e1000_mac_info {
35127 - struct e1000_mac_operations ops;
35128 + e1000_mac_operations_no_const ops;
35129 u8 addr[6];
35130 u8 perm_addr[6];
35131
35132 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35133 s32 (*check_for_ack)(struct e1000_hw *);
35134 s32 (*check_for_rst)(struct e1000_hw *);
35135 };
35136 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35137
35138 struct e1000_mbx_stats {
35139 u32 msgs_tx;
35140 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35141 };
35142
35143 struct e1000_mbx_info {
35144 - struct e1000_mbx_operations ops;
35145 + e1000_mbx_operations_no_const ops;
35146 struct e1000_mbx_stats stats;
35147 u32 timeout;
35148 u32 usec_delay;
35149 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35150 index 9b95bef..7e254ee 100644
35151 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35152 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35153 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
35154 s32 (*update_checksum)(struct ixgbe_hw *);
35155 u16 (*calc_checksum)(struct ixgbe_hw *);
35156 };
35157 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35158
35159 struct ixgbe_mac_operations {
35160 s32 (*init_hw)(struct ixgbe_hw *);
35161 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
35162 /* Manageability interface */
35163 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
35164 };
35165 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35166
35167 struct ixgbe_phy_operations {
35168 s32 (*identify)(struct ixgbe_hw *);
35169 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
35170 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35171 s32 (*check_overtemp)(struct ixgbe_hw *);
35172 };
35173 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35174
35175 struct ixgbe_eeprom_info {
35176 - struct ixgbe_eeprom_operations ops;
35177 + ixgbe_eeprom_operations_no_const ops;
35178 enum ixgbe_eeprom_type type;
35179 u32 semaphore_delay;
35180 u16 word_size;
35181 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
35182
35183 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35184 struct ixgbe_mac_info {
35185 - struct ixgbe_mac_operations ops;
35186 + ixgbe_mac_operations_no_const ops;
35187 enum ixgbe_mac_type type;
35188 u8 addr[ETH_ALEN];
35189 u8 perm_addr[ETH_ALEN];
35190 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
35191 };
35192
35193 struct ixgbe_phy_info {
35194 - struct ixgbe_phy_operations ops;
35195 + ixgbe_phy_operations_no_const ops;
35196 struct mdio_if_info mdio;
35197 enum ixgbe_phy_type type;
35198 u32 id;
35199 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
35200 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35201 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35202 };
35203 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35204
35205 struct ixgbe_mbx_stats {
35206 u32 msgs_tx;
35207 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
35208 };
35209
35210 struct ixgbe_mbx_info {
35211 - struct ixgbe_mbx_operations ops;
35212 + ixgbe_mbx_operations_no_const ops;
35213 struct ixgbe_mbx_stats stats;
35214 u32 timeout;
35215 u32 usec_delay;
35216 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35217 index 25c951d..cc7cf33 100644
35218 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35219 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35220 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35221 s32 (*clear_vfta)(struct ixgbe_hw *);
35222 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35223 };
35224 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35225
35226 enum ixgbe_mac_type {
35227 ixgbe_mac_unknown = 0,
35228 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35229 };
35230
35231 struct ixgbe_mac_info {
35232 - struct ixgbe_mac_operations ops;
35233 + ixgbe_mac_operations_no_const ops;
35234 u8 addr[6];
35235 u8 perm_addr[6];
35236
35237 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35238 s32 (*check_for_ack)(struct ixgbe_hw *);
35239 s32 (*check_for_rst)(struct ixgbe_hw *);
35240 };
35241 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35242
35243 struct ixgbe_mbx_stats {
35244 u32 msgs_tx;
35245 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35246 };
35247
35248 struct ixgbe_mbx_info {
35249 - struct ixgbe_mbx_operations ops;
35250 + ixgbe_mbx_operations_no_const ops;
35251 struct ixgbe_mbx_stats stats;
35252 u32 timeout;
35253 u32 udelay;
35254 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35255 index 8bf22b6..7f5baaa 100644
35256 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35257 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35258 @@ -41,6 +41,7 @@
35259 #include <linux/slab.h>
35260 #include <linux/io-mapping.h>
35261 #include <linux/delay.h>
35262 +#include <linux/sched.h>
35263
35264 #include <linux/mlx4/device.h>
35265 #include <linux/mlx4/doorbell.h>
35266 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35267 index 5046a64..71ca936 100644
35268 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35269 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35270 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35271 void (*link_down)(struct __vxge_hw_device *devh);
35272 void (*crit_err)(struct __vxge_hw_device *devh,
35273 enum vxge_hw_event type, u64 ext_data);
35274 -};
35275 +} __no_const;
35276
35277 /*
35278 * struct __vxge_hw_blockpool_entry - Block private data structure
35279 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35280 index 4a518a3..936b334 100644
35281 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35282 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35283 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35284 struct vxge_hw_mempool_dma *dma_object,
35285 u32 index,
35286 u32 is_last);
35287 -};
35288 +} __no_const;
35289
35290 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35291 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35292 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35293 index bbacb37..d60887d 100644
35294 --- a/drivers/net/ethernet/realtek/r8169.c
35295 +++ b/drivers/net/ethernet/realtek/r8169.c
35296 @@ -695,17 +695,17 @@ struct rtl8169_private {
35297 struct mdio_ops {
35298 void (*write)(void __iomem *, int, int);
35299 int (*read)(void __iomem *, int);
35300 - } mdio_ops;
35301 + } __no_const mdio_ops;
35302
35303 struct pll_power_ops {
35304 void (*down)(struct rtl8169_private *);
35305 void (*up)(struct rtl8169_private *);
35306 - } pll_power_ops;
35307 + } __no_const pll_power_ops;
35308
35309 struct jumbo_ops {
35310 void (*enable)(struct rtl8169_private *);
35311 void (*disable)(struct rtl8169_private *);
35312 - } jumbo_ops;
35313 + } __no_const jumbo_ops;
35314
35315 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35316 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35317 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35318 index 5b118cd..858b523 100644
35319 --- a/drivers/net/ethernet/sis/sis190.c
35320 +++ b/drivers/net/ethernet/sis/sis190.c
35321 @@ -1622,7 +1622,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35322 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35323 struct net_device *dev)
35324 {
35325 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35326 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35327 struct sis190_private *tp = netdev_priv(dev);
35328 struct pci_dev *isa_bridge;
35329 u8 reg, tmp8;
35330 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35331 index c07cfe9..81cbf7e 100644
35332 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35333 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35334 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35335
35336 writel(value, ioaddr + MMC_CNTRL);
35337
35338 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35339 - MMC_CNTRL, value);
35340 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35341 +// MMC_CNTRL, value);
35342 }
35343
35344 /* To mask all all interrupts.*/
35345 diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35346 index 6ee593a..3f513b1 100644
35347 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35348 +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
35349 @@ -1585,7 +1585,7 @@ static const struct file_operations stmmac_rings_status_fops = {
35350 .open = stmmac_sysfs_ring_open,
35351 .read = seq_read,
35352 .llseek = seq_lseek,
35353 - .release = seq_release,
35354 + .release = single_release,
35355 };
35356
35357 static int stmmac_sysfs_dma_cap_read(struct seq_file *seq, void *v)
35358 @@ -1657,7 +1657,7 @@ static const struct file_operations stmmac_dma_cap_fops = {
35359 .open = stmmac_sysfs_dma_cap_open,
35360 .read = seq_read,
35361 .llseek = seq_lseek,
35362 - .release = seq_release,
35363 + .release = single_release,
35364 };
35365
35366 static int stmmac_init_fs(struct net_device *dev)
35367 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35368 index dec5836..6d4db7d 100644
35369 --- a/drivers/net/hyperv/hyperv_net.h
35370 +++ b/drivers/net/hyperv/hyperv_net.h
35371 @@ -97,7 +97,7 @@ struct rndis_device {
35372
35373 enum rndis_device_state state;
35374 bool link_state;
35375 - atomic_t new_req_id;
35376 + atomic_unchecked_t new_req_id;
35377
35378 spinlock_t request_lock;
35379 struct list_head req_list;
35380 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35381 index 133b7fb..d58c559 100644
35382 --- a/drivers/net/hyperv/rndis_filter.c
35383 +++ b/drivers/net/hyperv/rndis_filter.c
35384 @@ -96,7 +96,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35385 * template
35386 */
35387 set = &rndis_msg->msg.set_req;
35388 - set->req_id = atomic_inc_return(&dev->new_req_id);
35389 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35390
35391 /* Add to the request list */
35392 spin_lock_irqsave(&dev->request_lock, flags);
35393 @@ -627,7 +627,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35394
35395 /* Setup the rndis set */
35396 halt = &request->request_msg.msg.halt_req;
35397 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35398 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35399
35400 /* Ignore return since this msg is optional. */
35401 rndis_filter_send_request(dev, request);
35402 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
35403 index 58dc117..f140c77 100644
35404 --- a/drivers/net/macvtap.c
35405 +++ b/drivers/net/macvtap.c
35406 @@ -526,6 +526,8 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
35407 }
35408 base = (unsigned long)from->iov_base + offset1;
35409 size = ((base & ~PAGE_MASK) + len + ~PAGE_MASK) >> PAGE_SHIFT;
35410 + if (i + size >= MAX_SKB_FRAGS)
35411 + return -EFAULT;
35412 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
35413 if ((num_pages != size) ||
35414 (num_pages > MAX_SKB_FRAGS - skb_shinfo(skb)->nr_frags))
35415 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35416 index 3ed983c..a1bb418 100644
35417 --- a/drivers/net/ppp/ppp_generic.c
35418 +++ b/drivers/net/ppp/ppp_generic.c
35419 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35420 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35421 struct ppp_stats stats;
35422 struct ppp_comp_stats cstats;
35423 - char *vers;
35424
35425 switch (cmd) {
35426 case SIOCGPPPSTATS:
35427 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35428 break;
35429
35430 case SIOCGPPPVER:
35431 - vers = PPP_VERSION;
35432 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35433 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35434 break;
35435 err = 0;
35436 break;
35437 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
35438 index 515f122..41dd273 100644
35439 --- a/drivers/net/tokenring/abyss.c
35440 +++ b/drivers/net/tokenring/abyss.c
35441 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
35442
35443 static int __init abyss_init (void)
35444 {
35445 - abyss_netdev_ops = tms380tr_netdev_ops;
35446 + pax_open_kernel();
35447 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35448
35449 - abyss_netdev_ops.ndo_open = abyss_open;
35450 - abyss_netdev_ops.ndo_stop = abyss_close;
35451 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
35452 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
35453 + pax_close_kernel();
35454
35455 return pci_register_driver(&abyss_driver);
35456 }
35457 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
35458 index 6153cfd..cf69c1c 100644
35459 --- a/drivers/net/tokenring/madgemc.c
35460 +++ b/drivers/net/tokenring/madgemc.c
35461 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
35462
35463 static int __init madgemc_init (void)
35464 {
35465 - madgemc_netdev_ops = tms380tr_netdev_ops;
35466 - madgemc_netdev_ops.ndo_open = madgemc_open;
35467 - madgemc_netdev_ops.ndo_stop = madgemc_close;
35468 + pax_open_kernel();
35469 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35470 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
35471 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
35472 + pax_close_kernel();
35473
35474 return mca_register_driver (&madgemc_driver);
35475 }
35476 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
35477 index 8d362e6..f91cc52 100644
35478 --- a/drivers/net/tokenring/proteon.c
35479 +++ b/drivers/net/tokenring/proteon.c
35480 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
35481 struct platform_device *pdev;
35482 int i, num = 0, err = 0;
35483
35484 - proteon_netdev_ops = tms380tr_netdev_ops;
35485 - proteon_netdev_ops.ndo_open = proteon_open;
35486 - proteon_netdev_ops.ndo_stop = tms380tr_close;
35487 + pax_open_kernel();
35488 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35489 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
35490 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
35491 + pax_close_kernel();
35492
35493 err = platform_driver_register(&proteon_driver);
35494 if (err)
35495 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
35496 index 46db5c5..37c1536 100644
35497 --- a/drivers/net/tokenring/skisa.c
35498 +++ b/drivers/net/tokenring/skisa.c
35499 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
35500 struct platform_device *pdev;
35501 int i, num = 0, err = 0;
35502
35503 - sk_isa_netdev_ops = tms380tr_netdev_ops;
35504 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
35505 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35506 + pax_open_kernel();
35507 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
35508 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
35509 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
35510 + pax_close_kernel();
35511
35512 err = platform_driver_register(&sk_isa_driver);
35513 if (err)
35514 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35515 index e1324b4..e1b0041 100644
35516 --- a/drivers/net/usb/hso.c
35517 +++ b/drivers/net/usb/hso.c
35518 @@ -71,7 +71,7 @@
35519 #include <asm/byteorder.h>
35520 #include <linux/serial_core.h>
35521 #include <linux/serial.h>
35522 -
35523 +#include <asm/local.h>
35524
35525 #define MOD_AUTHOR "Option Wireless"
35526 #define MOD_DESCRIPTION "USB High Speed Option driver"
35527 @@ -257,7 +257,7 @@ struct hso_serial {
35528
35529 /* from usb_serial_port */
35530 struct tty_struct *tty;
35531 - int open_count;
35532 + local_t open_count;
35533 spinlock_t serial_lock;
35534
35535 int (*write_data) (struct hso_serial *serial);
35536 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35537 struct urb *urb;
35538
35539 urb = serial->rx_urb[0];
35540 - if (serial->open_count > 0) {
35541 + if (local_read(&serial->open_count) > 0) {
35542 count = put_rxbuf_data(urb, serial);
35543 if (count == -1)
35544 return;
35545 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35546 DUMP1(urb->transfer_buffer, urb->actual_length);
35547
35548 /* Anyone listening? */
35549 - if (serial->open_count == 0)
35550 + if (local_read(&serial->open_count) == 0)
35551 return;
35552
35553 if (status == 0) {
35554 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35555 spin_unlock_irq(&serial->serial_lock);
35556
35557 /* check for port already opened, if not set the termios */
35558 - serial->open_count++;
35559 - if (serial->open_count == 1) {
35560 + if (local_inc_return(&serial->open_count) == 1) {
35561 serial->rx_state = RX_IDLE;
35562 /* Force default termio settings */
35563 _hso_serial_set_termios(tty, NULL);
35564 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35565 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35566 if (result) {
35567 hso_stop_serial_device(serial->parent);
35568 - serial->open_count--;
35569 + local_dec(&serial->open_count);
35570 kref_put(&serial->parent->ref, hso_serial_ref_free);
35571 }
35572 } else {
35573 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35574
35575 /* reset the rts and dtr */
35576 /* do the actual close */
35577 - serial->open_count--;
35578 + local_dec(&serial->open_count);
35579
35580 - if (serial->open_count <= 0) {
35581 - serial->open_count = 0;
35582 + if (local_read(&serial->open_count) <= 0) {
35583 + local_set(&serial->open_count, 0);
35584 spin_lock_irq(&serial->serial_lock);
35585 if (serial->tty == tty) {
35586 serial->tty->driver_data = NULL;
35587 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35588
35589 /* the actual setup */
35590 spin_lock_irqsave(&serial->serial_lock, flags);
35591 - if (serial->open_count)
35592 + if (local_read(&serial->open_count))
35593 _hso_serial_set_termios(tty, old);
35594 else
35595 tty->termios = old;
35596 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
35597 D1("Pending read interrupt on port %d\n", i);
35598 spin_lock(&serial->serial_lock);
35599 if (serial->rx_state == RX_IDLE &&
35600 - serial->open_count > 0) {
35601 + local_read(&serial->open_count) > 0) {
35602 /* Setup and send a ctrl req read on
35603 * port i */
35604 if (!serial->rx_urb_filled[0]) {
35605 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
35606 /* Start all serial ports */
35607 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35608 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35609 - if (dev2ser(serial_table[i])->open_count) {
35610 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
35611 result =
35612 hso_start_serial_device(serial_table[i], GFP_NOIO);
35613 hso_kick_transmit(dev2ser(serial_table[i]));
35614 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35615 index efc0111..79c8f5b 100644
35616 --- a/drivers/net/wireless/ath/ath.h
35617 +++ b/drivers/net/wireless/ath/ath.h
35618 @@ -119,6 +119,7 @@ struct ath_ops {
35619 void (*write_flush) (void *);
35620 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35621 };
35622 +typedef struct ath_ops __no_const ath_ops_no_const;
35623
35624 struct ath_common;
35625 struct ath_bus_ops;
35626 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35627 index 7b6417b..ab5db98 100644
35628 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35629 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35630 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35631 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35632 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35633
35634 - ACCESS_ONCE(ads->ds_link) = i->link;
35635 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35636 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35637 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35638
35639 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35640 ctl6 = SM(i->keytype, AR_EncrType);
35641 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35642
35643 if ((i->is_first || i->is_last) &&
35644 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35645 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35646 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35647 | set11nTries(i->rates, 1)
35648 | set11nTries(i->rates, 2)
35649 | set11nTries(i->rates, 3)
35650 | (i->dur_update ? AR_DurUpdateEna : 0)
35651 | SM(0, AR_BurstDur);
35652
35653 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35654 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35655 | set11nRate(i->rates, 1)
35656 | set11nRate(i->rates, 2)
35657 | set11nRate(i->rates, 3);
35658 } else {
35659 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35660 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35661 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35662 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35663 }
35664
35665 if (!i->is_first) {
35666 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35667 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35668 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35669 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35670 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35671 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35672 return;
35673 }
35674
35675 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35676 break;
35677 }
35678
35679 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35680 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35681 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35682 | SM(i->txpower, AR_XmitPower)
35683 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35684 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35685 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35686 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35687
35688 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35689 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35690 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35691 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35692
35693 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35694 return;
35695
35696 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35697 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35698 | set11nPktDurRTSCTS(i->rates, 1);
35699
35700 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35701 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35702 | set11nPktDurRTSCTS(i->rates, 3);
35703
35704 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35705 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35706 | set11nRateFlags(i->rates, 1)
35707 | set11nRateFlags(i->rates, 2)
35708 | set11nRateFlags(i->rates, 3)
35709 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35710 index 09b8c9d..905339e 100644
35711 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35712 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35713 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35714 (i->qcu << AR_TxQcuNum_S) | 0x17;
35715
35716 checksum += val;
35717 - ACCESS_ONCE(ads->info) = val;
35718 + ACCESS_ONCE_RW(ads->info) = val;
35719
35720 checksum += i->link;
35721 - ACCESS_ONCE(ads->link) = i->link;
35722 + ACCESS_ONCE_RW(ads->link) = i->link;
35723
35724 checksum += i->buf_addr[0];
35725 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35726 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35727 checksum += i->buf_addr[1];
35728 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35729 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35730 checksum += i->buf_addr[2];
35731 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35732 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35733 checksum += i->buf_addr[3];
35734 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35735 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35736
35737 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35738 - ACCESS_ONCE(ads->ctl3) = val;
35739 + ACCESS_ONCE_RW(ads->ctl3) = val;
35740 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35741 - ACCESS_ONCE(ads->ctl5) = val;
35742 + ACCESS_ONCE_RW(ads->ctl5) = val;
35743 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35744 - ACCESS_ONCE(ads->ctl7) = val;
35745 + ACCESS_ONCE_RW(ads->ctl7) = val;
35746 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35747 - ACCESS_ONCE(ads->ctl9) = val;
35748 + ACCESS_ONCE_RW(ads->ctl9) = val;
35749
35750 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35751 - ACCESS_ONCE(ads->ctl10) = checksum;
35752 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35753
35754 if (i->is_first || i->is_last) {
35755 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35756 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35757 | set11nTries(i->rates, 1)
35758 | set11nTries(i->rates, 2)
35759 | set11nTries(i->rates, 3)
35760 | (i->dur_update ? AR_DurUpdateEna : 0)
35761 | SM(0, AR_BurstDur);
35762
35763 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35764 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35765 | set11nRate(i->rates, 1)
35766 | set11nRate(i->rates, 2)
35767 | set11nRate(i->rates, 3);
35768 } else {
35769 - ACCESS_ONCE(ads->ctl13) = 0;
35770 - ACCESS_ONCE(ads->ctl14) = 0;
35771 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35772 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35773 }
35774
35775 ads->ctl20 = 0;
35776 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35777
35778 ctl17 = SM(i->keytype, AR_EncrType);
35779 if (!i->is_first) {
35780 - ACCESS_ONCE(ads->ctl11) = 0;
35781 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35782 - ACCESS_ONCE(ads->ctl15) = 0;
35783 - ACCESS_ONCE(ads->ctl16) = 0;
35784 - ACCESS_ONCE(ads->ctl17) = ctl17;
35785 - ACCESS_ONCE(ads->ctl18) = 0;
35786 - ACCESS_ONCE(ads->ctl19) = 0;
35787 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35788 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35789 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35790 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35791 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35792 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35793 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35794 return;
35795 }
35796
35797 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35798 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35799 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35800 | SM(i->txpower, AR_XmitPower)
35801 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35802 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35803 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35804 ctl12 |= SM(val, AR_PAPRDChainMask);
35805
35806 - ACCESS_ONCE(ads->ctl12) = ctl12;
35807 - ACCESS_ONCE(ads->ctl17) = ctl17;
35808 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35809 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35810
35811 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35812 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35813 | set11nPktDurRTSCTS(i->rates, 1);
35814
35815 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35816 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35817 | set11nPktDurRTSCTS(i->rates, 3);
35818
35819 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35820 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35821 | set11nRateFlags(i->rates, 1)
35822 | set11nRateFlags(i->rates, 2)
35823 | set11nRateFlags(i->rates, 3)
35824 | SM(i->rtscts_rate, AR_RTSCTSRate);
35825
35826 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35827 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35828 }
35829
35830 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35831 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35832 index c8261d4..8d88929 100644
35833 --- a/drivers/net/wireless/ath/ath9k/hw.h
35834 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35835 @@ -773,7 +773,7 @@ struct ath_hw_private_ops {
35836
35837 /* ANI */
35838 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35839 -};
35840 +} __no_const;
35841
35842 /**
35843 * struct ath_hw_ops - callbacks used by hardware code and driver code
35844 @@ -803,7 +803,7 @@ struct ath_hw_ops {
35845 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35846 struct ath_hw_antcomb_conf *antconf);
35847
35848 -};
35849 +} __no_const;
35850
35851 struct ath_nf_limits {
35852 s16 max;
35853 @@ -823,7 +823,7 @@ enum ath_cal_list {
35854 #define AH_FASTCC 0x4
35855
35856 struct ath_hw {
35857 - struct ath_ops reg_ops;
35858 + ath_ops_no_const reg_ops;
35859
35860 struct ieee80211_hw *hw;
35861 struct ath_common common;
35862 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35863 index af00e2c..ab04d34 100644
35864 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35865 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35866 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35867 void (*carrsuppr)(struct brcms_phy *);
35868 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35869 void (*detach)(struct brcms_phy *);
35870 -};
35871 +} __no_const;
35872
35873 struct brcms_phy {
35874 struct brcms_phy_pub pubpi_ro;
35875 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35876 index a2ec369..36fdf14 100644
35877 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35878 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35879 @@ -3646,7 +3646,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35880 */
35881 if (il3945_mod_params.disable_hw_scan) {
35882 D_INFO("Disabling hw_scan\n");
35883 - il3945_hw_ops.hw_scan = NULL;
35884 + pax_open_kernel();
35885 + *(void **)&il3945_hw_ops.hw_scan = NULL;
35886 + pax_close_kernel();
35887 }
35888
35889 D_INFO("*** LOAD DRIVER ***\n");
35890 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
35891 index f8fc239..8cade22 100644
35892 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
35893 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
35894 @@ -86,8 +86,8 @@ do { \
35895 } while (0)
35896
35897 #else
35898 -#define IWL_DEBUG(m, level, fmt, args...)
35899 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
35900 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
35901 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
35902 #define iwl_print_hex_dump(m, level, p, len)
35903 #define IWL_DEBUG_QUIET_RFKILL(p, fmt, args...) \
35904 do { \
35905 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35906 index 4b9e730..7603659 100644
35907 --- a/drivers/net/wireless/mac80211_hwsim.c
35908 +++ b/drivers/net/wireless/mac80211_hwsim.c
35909 @@ -1677,9 +1677,11 @@ static int __init init_mac80211_hwsim(void)
35910 return -EINVAL;
35911
35912 if (fake_hw_scan) {
35913 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35914 - mac80211_hwsim_ops.sw_scan_start = NULL;
35915 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35916 + pax_open_kernel();
35917 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35918 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35919 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35920 + pax_close_kernel();
35921 }
35922
35923 spin_lock_init(&hwsim_radio_lock);
35924 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35925 index 3186aa4..b35b09f 100644
35926 --- a/drivers/net/wireless/mwifiex/main.h
35927 +++ b/drivers/net/wireless/mwifiex/main.h
35928 @@ -536,7 +536,7 @@ struct mwifiex_if_ops {
35929 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
35930 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
35931 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35932 -};
35933 +} __no_const;
35934
35935 struct mwifiex_adapter {
35936 u8 iface_type;
35937 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35938 index a330c69..a81540f 100644
35939 --- a/drivers/net/wireless/rndis_wlan.c
35940 +++ b/drivers/net/wireless/rndis_wlan.c
35941 @@ -1278,7 +1278,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35942
35943 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35944
35945 - if (rts_threshold < 0 || rts_threshold > 2347)
35946 + if (rts_threshold > 2347)
35947 rts_threshold = 2347;
35948
35949 tmp = cpu_to_le32(rts_threshold);
35950 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
35951 index a77f1bb..c608b2b 100644
35952 --- a/drivers/net/wireless/wl1251/wl1251.h
35953 +++ b/drivers/net/wireless/wl1251/wl1251.h
35954 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35955 void (*reset)(struct wl1251 *wl);
35956 void (*enable_irq)(struct wl1251 *wl);
35957 void (*disable_irq)(struct wl1251 *wl);
35958 -};
35959 +} __no_const;
35960
35961 struct wl1251 {
35962 struct ieee80211_hw *hw;
35963 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
35964 index f34b5b2..b5abb9f 100644
35965 --- a/drivers/oprofile/buffer_sync.c
35966 +++ b/drivers/oprofile/buffer_sync.c
35967 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
35968 if (cookie == NO_COOKIE)
35969 offset = pc;
35970 if (cookie == INVALID_COOKIE) {
35971 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35972 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35973 offset = pc;
35974 }
35975 if (cookie != last_cookie) {
35976 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
35977 /* add userspace sample */
35978
35979 if (!mm) {
35980 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
35981 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
35982 return 0;
35983 }
35984
35985 cookie = lookup_dcookie(mm, s->eip, &offset);
35986
35987 if (cookie == INVALID_COOKIE) {
35988 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
35989 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
35990 return 0;
35991 }
35992
35993 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
35994 /* ignore backtraces if failed to add a sample */
35995 if (state == sb_bt_start) {
35996 state = sb_bt_ignore;
35997 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
35998 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
35999 }
36000 }
36001 release_mm(mm);
36002 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36003 index c0cc4e7..44d4e54 100644
36004 --- a/drivers/oprofile/event_buffer.c
36005 +++ b/drivers/oprofile/event_buffer.c
36006 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36007 }
36008
36009 if (buffer_pos == buffer_size) {
36010 - atomic_inc(&oprofile_stats.event_lost_overflow);
36011 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36012 return;
36013 }
36014
36015 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36016 index ed2c3ec..deda85a 100644
36017 --- a/drivers/oprofile/oprof.c
36018 +++ b/drivers/oprofile/oprof.c
36019 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36020 if (oprofile_ops.switch_events())
36021 return;
36022
36023 - atomic_inc(&oprofile_stats.multiplex_counter);
36024 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36025 start_switch_worker();
36026 }
36027
36028 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36029 index 917d28e..d62d981 100644
36030 --- a/drivers/oprofile/oprofile_stats.c
36031 +++ b/drivers/oprofile/oprofile_stats.c
36032 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36033 cpu_buf->sample_invalid_eip = 0;
36034 }
36035
36036 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36037 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36038 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36039 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36040 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36041 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36042 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36043 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36044 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36045 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36046 }
36047
36048
36049 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36050 index 38b6fc0..b5cbfce 100644
36051 --- a/drivers/oprofile/oprofile_stats.h
36052 +++ b/drivers/oprofile/oprofile_stats.h
36053 @@ -13,11 +13,11 @@
36054 #include <linux/atomic.h>
36055
36056 struct oprofile_stat_struct {
36057 - atomic_t sample_lost_no_mm;
36058 - atomic_t sample_lost_no_mapping;
36059 - atomic_t bt_lost_no_mapping;
36060 - atomic_t event_lost_overflow;
36061 - atomic_t multiplex_counter;
36062 + atomic_unchecked_t sample_lost_no_mm;
36063 + atomic_unchecked_t sample_lost_no_mapping;
36064 + atomic_unchecked_t bt_lost_no_mapping;
36065 + atomic_unchecked_t event_lost_overflow;
36066 + atomic_unchecked_t multiplex_counter;
36067 };
36068
36069 extern struct oprofile_stat_struct oprofile_stats;
36070 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36071 index 2f0aa0f..90fab02 100644
36072 --- a/drivers/oprofile/oprofilefs.c
36073 +++ b/drivers/oprofile/oprofilefs.c
36074 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
36075
36076
36077 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36078 - char const *name, atomic_t *val)
36079 + char const *name, atomic_unchecked_t *val)
36080 {
36081 return __oprofilefs_create_file(sb, root, name,
36082 &atomic_ro_fops, 0444, val);
36083 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36084 index 3f56bc0..707d642 100644
36085 --- a/drivers/parport/procfs.c
36086 +++ b/drivers/parport/procfs.c
36087 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36088
36089 *ppos += len;
36090
36091 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36092 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36093 }
36094
36095 #ifdef CONFIG_PARPORT_1284
36096 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36097
36098 *ppos += len;
36099
36100 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36101 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36102 }
36103 #endif /* IEEE1284.3 support. */
36104
36105 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36106 index 9fff878..ad0ad53 100644
36107 --- a/drivers/pci/hotplug/cpci_hotplug.h
36108 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36109 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36110 int (*hardware_test) (struct slot* slot, u32 value);
36111 u8 (*get_power) (struct slot* slot);
36112 int (*set_power) (struct slot* slot, int value);
36113 -};
36114 +} __no_const;
36115
36116 struct cpci_hp_controller {
36117 unsigned int irq;
36118 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36119 index 76ba8a1..20ca857 100644
36120 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36121 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36122 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36123
36124 void compaq_nvram_init (void __iomem *rom_start)
36125 {
36126 +
36127 +#ifndef CONFIG_PAX_KERNEXEC
36128 if (rom_start) {
36129 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36130 }
36131 +#endif
36132 +
36133 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36134
36135 /* initialize our int15 lock */
36136 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36137 index 2275162..95f1a92 100644
36138 --- a/drivers/pci/pcie/aspm.c
36139 +++ b/drivers/pci/pcie/aspm.c
36140 @@ -27,9 +27,9 @@
36141 #define MODULE_PARAM_PREFIX "pcie_aspm."
36142
36143 /* Note: those are not register definitions */
36144 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36145 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36146 -#define ASPM_STATE_L1 (4) /* L1 state */
36147 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36148 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36149 +#define ASPM_STATE_L1 (4U) /* L1 state */
36150 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36151 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36152
36153 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36154 index 71eac9c..2de27ef 100644
36155 --- a/drivers/pci/probe.c
36156 +++ b/drivers/pci/probe.c
36157 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36158 u32 l, sz, mask;
36159 u16 orig_cmd;
36160
36161 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36162 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36163
36164 if (!dev->mmio_always_on) {
36165 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36166 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36167 index 27911b5..5b6db88 100644
36168 --- a/drivers/pci/proc.c
36169 +++ b/drivers/pci/proc.c
36170 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36171 static int __init pci_proc_init(void)
36172 {
36173 struct pci_dev *dev = NULL;
36174 +
36175 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36176 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36177 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36178 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36179 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36180 +#endif
36181 +#else
36182 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36183 +#endif
36184 proc_create("devices", 0, proc_bus_pci_dir,
36185 &proc_bus_pci_dev_operations);
36186 proc_initialized = 1;
36187 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36188 index ea0c607..58c4628 100644
36189 --- a/drivers/platform/x86/thinkpad_acpi.c
36190 +++ b/drivers/platform/x86/thinkpad_acpi.c
36191 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36192 return 0;
36193 }
36194
36195 -void static hotkey_mask_warn_incomplete_mask(void)
36196 +static void hotkey_mask_warn_incomplete_mask(void)
36197 {
36198 /* log only what the user can fix... */
36199 const u32 wantedmask = hotkey_driver_mask &
36200 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36201 }
36202 }
36203
36204 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36205 - struct tp_nvram_state *newn,
36206 - const u32 event_mask)
36207 -{
36208 -
36209 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36210 do { \
36211 if ((event_mask & (1 << __scancode)) && \
36212 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36213 tpacpi_hotkey_send_key(__scancode); \
36214 } while (0)
36215
36216 - void issue_volchange(const unsigned int oldvol,
36217 - const unsigned int newvol)
36218 - {
36219 - unsigned int i = oldvol;
36220 +static void issue_volchange(const unsigned int oldvol,
36221 + const unsigned int newvol,
36222 + const u32 event_mask)
36223 +{
36224 + unsigned int i = oldvol;
36225
36226 - while (i > newvol) {
36227 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36228 - i--;
36229 - }
36230 - while (i < newvol) {
36231 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36232 - i++;
36233 - }
36234 + while (i > newvol) {
36235 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36236 + i--;
36237 }
36238 + while (i < newvol) {
36239 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36240 + i++;
36241 + }
36242 +}
36243
36244 - void issue_brightnesschange(const unsigned int oldbrt,
36245 - const unsigned int newbrt)
36246 - {
36247 - unsigned int i = oldbrt;
36248 +static void issue_brightnesschange(const unsigned int oldbrt,
36249 + const unsigned int newbrt,
36250 + const u32 event_mask)
36251 +{
36252 + unsigned int i = oldbrt;
36253
36254 - while (i > newbrt) {
36255 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36256 - i--;
36257 - }
36258 - while (i < newbrt) {
36259 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36260 - i++;
36261 - }
36262 + while (i > newbrt) {
36263 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36264 + i--;
36265 + }
36266 + while (i < newbrt) {
36267 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36268 + i++;
36269 }
36270 +}
36271
36272 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36273 + struct tp_nvram_state *newn,
36274 + const u32 event_mask)
36275 +{
36276 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36277 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36278 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36279 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36280 oldn->volume_level != newn->volume_level) {
36281 /* recently muted, or repeated mute keypress, or
36282 * multiple presses ending in mute */
36283 - issue_volchange(oldn->volume_level, newn->volume_level);
36284 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36285 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36286 }
36287 } else {
36288 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36289 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36290 }
36291 if (oldn->volume_level != newn->volume_level) {
36292 - issue_volchange(oldn->volume_level, newn->volume_level);
36293 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36294 } else if (oldn->volume_toggle != newn->volume_toggle) {
36295 /* repeated vol up/down keypress at end of scale ? */
36296 if (newn->volume_level == 0)
36297 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36298 /* handle brightness */
36299 if (oldn->brightness_level != newn->brightness_level) {
36300 issue_brightnesschange(oldn->brightness_level,
36301 - newn->brightness_level);
36302 + newn->brightness_level,
36303 + event_mask);
36304 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36305 /* repeated key presses that didn't change state */
36306 if (newn->brightness_level == 0)
36307 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36308 && !tp_features.bright_unkfw)
36309 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36310 }
36311 +}
36312
36313 #undef TPACPI_COMPARE_KEY
36314 #undef TPACPI_MAY_SEND_KEY
36315 -}
36316
36317 /*
36318 * Polling driver
36319 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36320 index b859d16..5cc6b1a 100644
36321 --- a/drivers/pnp/pnpbios/bioscalls.c
36322 +++ b/drivers/pnp/pnpbios/bioscalls.c
36323 @@ -59,7 +59,7 @@ do { \
36324 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36325 } while(0)
36326
36327 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36328 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36329 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36330
36331 /*
36332 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36333
36334 cpu = get_cpu();
36335 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36336 +
36337 + pax_open_kernel();
36338 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36339 + pax_close_kernel();
36340
36341 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36342 spin_lock_irqsave(&pnp_bios_lock, flags);
36343 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36344 :"memory");
36345 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36346
36347 + pax_open_kernel();
36348 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36349 + pax_close_kernel();
36350 +
36351 put_cpu();
36352
36353 /* If we get here and this is set then the PnP BIOS faulted on us. */
36354 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36355 return status;
36356 }
36357
36358 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36359 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36360 {
36361 int i;
36362
36363 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36364 pnp_bios_callpoint.offset = header->fields.pm16offset;
36365 pnp_bios_callpoint.segment = PNP_CS16;
36366
36367 + pax_open_kernel();
36368 +
36369 for_each_possible_cpu(i) {
36370 struct desc_struct *gdt = get_cpu_gdt_table(i);
36371 if (!gdt)
36372 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36373 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36374 (unsigned long)__va(header->fields.pm16dseg));
36375 }
36376 +
36377 + pax_close_kernel();
36378 }
36379 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36380 index b0ecacb..7c9da2e 100644
36381 --- a/drivers/pnp/resource.c
36382 +++ b/drivers/pnp/resource.c
36383 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36384 return 1;
36385
36386 /* check if the resource is valid */
36387 - if (*irq < 0 || *irq > 15)
36388 + if (*irq > 15)
36389 return 0;
36390
36391 /* check if the resource is reserved */
36392 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36393 return 1;
36394
36395 /* check if the resource is valid */
36396 - if (*dma < 0 || *dma == 4 || *dma > 7)
36397 + if (*dma == 4 || *dma > 7)
36398 return 0;
36399
36400 /* check if the resource is reserved */
36401 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36402 index 1ed6ea0..77c0bd2 100644
36403 --- a/drivers/power/bq27x00_battery.c
36404 +++ b/drivers/power/bq27x00_battery.c
36405 @@ -72,7 +72,7 @@
36406 struct bq27x00_device_info;
36407 struct bq27x00_access_methods {
36408 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36409 -};
36410 +} __no_const;
36411
36412 enum bq27x00_chip { BQ27000, BQ27500 };
36413
36414 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36415 index a838e66..a9e1665 100644
36416 --- a/drivers/regulator/max8660.c
36417 +++ b/drivers/regulator/max8660.c
36418 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36419 max8660->shadow_regs[MAX8660_OVER1] = 5;
36420 } else {
36421 /* Otherwise devices can be toggled via software */
36422 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36423 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36424 + pax_open_kernel();
36425 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36426 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36427 + pax_close_kernel();
36428 }
36429
36430 /*
36431 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36432 index e8cfc99..072aee2 100644
36433 --- a/drivers/regulator/mc13892-regulator.c
36434 +++ b/drivers/regulator/mc13892-regulator.c
36435 @@ -574,10 +574,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36436 }
36437 mc13xxx_unlock(mc13892);
36438
36439 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36440 + pax_open_kernel();
36441 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36442 = mc13892_vcam_set_mode;
36443 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36444 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36445 = mc13892_vcam_get_mode;
36446 + pax_close_kernel();
36447
36448 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36449 ARRAY_SIZE(mc13892_regulators));
36450 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36451 index cace6d3..f623fda 100644
36452 --- a/drivers/rtc/rtc-dev.c
36453 +++ b/drivers/rtc/rtc-dev.c
36454 @@ -14,6 +14,7 @@
36455 #include <linux/module.h>
36456 #include <linux/rtc.h>
36457 #include <linux/sched.h>
36458 +#include <linux/grsecurity.h>
36459 #include "rtc-core.h"
36460
36461 static dev_t rtc_devt;
36462 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36463 if (copy_from_user(&tm, uarg, sizeof(tm)))
36464 return -EFAULT;
36465
36466 + gr_log_timechange();
36467 +
36468 return rtc_set_time(rtc, &tm);
36469
36470 case RTC_PIE_ON:
36471 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36472 index ffb5878..e6d785c 100644
36473 --- a/drivers/scsi/aacraid/aacraid.h
36474 +++ b/drivers/scsi/aacraid/aacraid.h
36475 @@ -492,7 +492,7 @@ struct adapter_ops
36476 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36477 /* Administrative operations */
36478 int (*adapter_comm)(struct aac_dev * dev, int comm);
36479 -};
36480 +} __no_const;
36481
36482 /*
36483 * Define which interrupt handler needs to be installed
36484 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36485 index 705e13e..91c873c 100644
36486 --- a/drivers/scsi/aacraid/linit.c
36487 +++ b/drivers/scsi/aacraid/linit.c
36488 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36489 #elif defined(__devinitconst)
36490 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36491 #else
36492 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36493 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36494 #endif
36495 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36496 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36497 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36498 index d5ff142..49c0ebb 100644
36499 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36500 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36501 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36502 .lldd_control_phy = asd_control_phy,
36503 };
36504
36505 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36506 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36507 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36508 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36509 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36510 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36511 index a796de9..1ef20e1 100644
36512 --- a/drivers/scsi/bfa/bfa.h
36513 +++ b/drivers/scsi/bfa/bfa.h
36514 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36515 u32 *end);
36516 int cpe_vec_q0;
36517 int rme_vec_q0;
36518 -};
36519 +} __no_const;
36520 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36521
36522 struct bfa_faa_cbfn_s {
36523 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36524 index f0f80e2..8ec946b 100644
36525 --- a/drivers/scsi/bfa/bfa_fcpim.c
36526 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36527 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36528
36529 bfa_iotag_attach(fcp);
36530
36531 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36532 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36533 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36534 (fcp->num_itns * sizeof(struct bfa_itn_s));
36535 memset(fcp->itn_arr, 0,
36536 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36537 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36538 {
36539 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36540 - struct bfa_itn_s *itn;
36541 + bfa_itn_s_no_const *itn;
36542
36543 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36544 itn->isr = isr;
36545 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36546 index 36f26da..38a34a8 100644
36547 --- a/drivers/scsi/bfa/bfa_fcpim.h
36548 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36549 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36550 struct bfa_itn_s {
36551 bfa_isr_func_t isr;
36552 };
36553 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36554
36555 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36556 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36557 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36558 struct list_head iotag_tio_free_q; /* free IO resources */
36559 struct list_head iotag_unused_q; /* unused IO resources*/
36560 struct bfa_iotag_s *iotag_arr;
36561 - struct bfa_itn_s *itn_arr;
36562 + bfa_itn_s_no_const *itn_arr;
36563 int num_ioim_reqs;
36564 int num_fwtio_reqs;
36565 int num_itns;
36566 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36567 index 546d46b..642fa5b 100644
36568 --- a/drivers/scsi/bfa/bfa_ioc.h
36569 +++ b/drivers/scsi/bfa/bfa_ioc.h
36570 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36571 bfa_ioc_disable_cbfn_t disable_cbfn;
36572 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36573 bfa_ioc_reset_cbfn_t reset_cbfn;
36574 -};
36575 +} __no_const;
36576
36577 /*
36578 * IOC event notification mechanism.
36579 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36580 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36581 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36582 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36583 -};
36584 +} __no_const;
36585
36586 /*
36587 * Queue element to wait for room in request queue. FIFO order is
36588 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36589 index 351dc0b..951dc32 100644
36590 --- a/drivers/scsi/hosts.c
36591 +++ b/drivers/scsi/hosts.c
36592 @@ -42,7 +42,7 @@
36593 #include "scsi_logging.h"
36594
36595
36596 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36597 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36598
36599
36600 static void scsi_host_cls_release(struct device *dev)
36601 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36602 * subtract one because we increment first then return, but we need to
36603 * know what the next host number was before increment
36604 */
36605 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36606 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36607 shost->dma_channel = 0xff;
36608
36609 /* These three are default values which can be overridden */
36610 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36611 index e640b73..2f68432 100644
36612 --- a/drivers/scsi/hpsa.c
36613 +++ b/drivers/scsi/hpsa.c
36614 @@ -507,7 +507,7 @@ static inline u32 next_command(struct ctlr_info *h)
36615 u32 a;
36616
36617 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36618 - return h->access.command_completed(h);
36619 + return h->access->command_completed(h);
36620
36621 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36622 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36623 @@ -2987,7 +2987,7 @@ static void start_io(struct ctlr_info *h)
36624 while (!list_empty(&h->reqQ)) {
36625 c = list_entry(h->reqQ.next, struct CommandList, list);
36626 /* can't do anything if fifo is full */
36627 - if ((h->access.fifo_full(h))) {
36628 + if ((h->access->fifo_full(h))) {
36629 dev_warn(&h->pdev->dev, "fifo full\n");
36630 break;
36631 }
36632 @@ -2997,7 +2997,7 @@ static void start_io(struct ctlr_info *h)
36633 h->Qdepth--;
36634
36635 /* Tell the controller execute command */
36636 - h->access.submit_command(h, c);
36637 + h->access->submit_command(h, c);
36638
36639 /* Put job onto the completed Q */
36640 addQ(&h->cmpQ, c);
36641 @@ -3006,17 +3006,17 @@ static void start_io(struct ctlr_info *h)
36642
36643 static inline unsigned long get_next_completion(struct ctlr_info *h)
36644 {
36645 - return h->access.command_completed(h);
36646 + return h->access->command_completed(h);
36647 }
36648
36649 static inline bool interrupt_pending(struct ctlr_info *h)
36650 {
36651 - return h->access.intr_pending(h);
36652 + return h->access->intr_pending(h);
36653 }
36654
36655 static inline long interrupt_not_for_us(struct ctlr_info *h)
36656 {
36657 - return (h->access.intr_pending(h) == 0) ||
36658 + return (h->access->intr_pending(h) == 0) ||
36659 (h->interrupts_enabled == 0);
36660 }
36661
36662 @@ -3915,7 +3915,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36663 if (prod_index < 0)
36664 return -ENODEV;
36665 h->product_name = products[prod_index].product_name;
36666 - h->access = *(products[prod_index].access);
36667 + h->access = products[prod_index].access;
36668
36669 if (hpsa_board_disabled(h->pdev)) {
36670 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36671 @@ -4160,7 +4160,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36672
36673 assert_spin_locked(&lockup_detector_lock);
36674 remove_ctlr_from_lockup_detector_list(h);
36675 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36676 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36677 spin_lock_irqsave(&h->lock, flags);
36678 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36679 spin_unlock_irqrestore(&h->lock, flags);
36680 @@ -4340,7 +4340,7 @@ reinit_after_soft_reset:
36681 }
36682
36683 /* make sure the board interrupts are off */
36684 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36685 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36686
36687 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36688 goto clean2;
36689 @@ -4374,7 +4374,7 @@ reinit_after_soft_reset:
36690 * fake ones to scoop up any residual completions.
36691 */
36692 spin_lock_irqsave(&h->lock, flags);
36693 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36694 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36695 spin_unlock_irqrestore(&h->lock, flags);
36696 free_irq(h->intr[h->intr_mode], h);
36697 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36698 @@ -4393,9 +4393,9 @@ reinit_after_soft_reset:
36699 dev_info(&h->pdev->dev, "Board READY.\n");
36700 dev_info(&h->pdev->dev,
36701 "Waiting for stale completions to drain.\n");
36702 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36703 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36704 msleep(10000);
36705 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36706 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36707
36708 rc = controller_reset_failed(h->cfgtable);
36709 if (rc)
36710 @@ -4416,7 +4416,7 @@ reinit_after_soft_reset:
36711 }
36712
36713 /* Turn the interrupts on so we can service requests */
36714 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36715 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36716
36717 hpsa_hba_inquiry(h);
36718 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36719 @@ -4468,7 +4468,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36720 * To write all data in the battery backed cache to disks
36721 */
36722 hpsa_flush_cache(h);
36723 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36724 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36725 free_irq(h->intr[h->intr_mode], h);
36726 #ifdef CONFIG_PCI_MSI
36727 if (h->msix_vector)
36728 @@ -4632,7 +4632,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36729 return;
36730 }
36731 /* Change the access methods to the performant access methods */
36732 - h->access = SA5_performant_access;
36733 + h->access = &SA5_performant_access;
36734 h->transMethod = CFGTBL_Trans_Performant;
36735 }
36736
36737 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36738 index 91edafb..a9b88ec 100644
36739 --- a/drivers/scsi/hpsa.h
36740 +++ b/drivers/scsi/hpsa.h
36741 @@ -73,7 +73,7 @@ struct ctlr_info {
36742 unsigned int msix_vector;
36743 unsigned int msi_vector;
36744 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36745 - struct access_method access;
36746 + struct access_method *access;
36747
36748 /* queue and queue Info */
36749 struct list_head reqQ;
36750 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36751 index f2df059..a3a9930 100644
36752 --- a/drivers/scsi/ips.h
36753 +++ b/drivers/scsi/ips.h
36754 @@ -1027,7 +1027,7 @@ typedef struct {
36755 int (*intr)(struct ips_ha *);
36756 void (*enableint)(struct ips_ha *);
36757 uint32_t (*statupd)(struct ips_ha *);
36758 -} ips_hw_func_t;
36759 +} __no_const ips_hw_func_t;
36760
36761 typedef struct ips_ha {
36762 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36763 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36764 index 4d70d96..84d0573 100644
36765 --- a/drivers/scsi/libfc/fc_exch.c
36766 +++ b/drivers/scsi/libfc/fc_exch.c
36767 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36768 * all together if not used XXX
36769 */
36770 struct {
36771 - atomic_t no_free_exch;
36772 - atomic_t no_free_exch_xid;
36773 - atomic_t xid_not_found;
36774 - atomic_t xid_busy;
36775 - atomic_t seq_not_found;
36776 - atomic_t non_bls_resp;
36777 + atomic_unchecked_t no_free_exch;
36778 + atomic_unchecked_t no_free_exch_xid;
36779 + atomic_unchecked_t xid_not_found;
36780 + atomic_unchecked_t xid_busy;
36781 + atomic_unchecked_t seq_not_found;
36782 + atomic_unchecked_t non_bls_resp;
36783 } stats;
36784 };
36785
36786 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36787 /* allocate memory for exchange */
36788 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36789 if (!ep) {
36790 - atomic_inc(&mp->stats.no_free_exch);
36791 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36792 goto out;
36793 }
36794 memset(ep, 0, sizeof(*ep));
36795 @@ -780,7 +780,7 @@ out:
36796 return ep;
36797 err:
36798 spin_unlock_bh(&pool->lock);
36799 - atomic_inc(&mp->stats.no_free_exch_xid);
36800 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36801 mempool_free(ep, mp->ep_pool);
36802 return NULL;
36803 }
36804 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36805 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36806 ep = fc_exch_find(mp, xid);
36807 if (!ep) {
36808 - atomic_inc(&mp->stats.xid_not_found);
36809 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36810 reject = FC_RJT_OX_ID;
36811 goto out;
36812 }
36813 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36814 ep = fc_exch_find(mp, xid);
36815 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36816 if (ep) {
36817 - atomic_inc(&mp->stats.xid_busy);
36818 + atomic_inc_unchecked(&mp->stats.xid_busy);
36819 reject = FC_RJT_RX_ID;
36820 goto rel;
36821 }
36822 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36823 }
36824 xid = ep->xid; /* get our XID */
36825 } else if (!ep) {
36826 - atomic_inc(&mp->stats.xid_not_found);
36827 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36828 reject = FC_RJT_RX_ID; /* XID not found */
36829 goto out;
36830 }
36831 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36832 } else {
36833 sp = &ep->seq;
36834 if (sp->id != fh->fh_seq_id) {
36835 - atomic_inc(&mp->stats.seq_not_found);
36836 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36837 if (f_ctl & FC_FC_END_SEQ) {
36838 /*
36839 * Update sequence_id based on incoming last
36840 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36841
36842 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36843 if (!ep) {
36844 - atomic_inc(&mp->stats.xid_not_found);
36845 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36846 goto out;
36847 }
36848 if (ep->esb_stat & ESB_ST_COMPLETE) {
36849 - atomic_inc(&mp->stats.xid_not_found);
36850 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36851 goto rel;
36852 }
36853 if (ep->rxid == FC_XID_UNKNOWN)
36854 ep->rxid = ntohs(fh->fh_rx_id);
36855 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36856 - atomic_inc(&mp->stats.xid_not_found);
36857 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36858 goto rel;
36859 }
36860 if (ep->did != ntoh24(fh->fh_s_id) &&
36861 ep->did != FC_FID_FLOGI) {
36862 - atomic_inc(&mp->stats.xid_not_found);
36863 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36864 goto rel;
36865 }
36866 sof = fr_sof(fp);
36867 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36868 sp->ssb_stat |= SSB_ST_RESP;
36869 sp->id = fh->fh_seq_id;
36870 } else if (sp->id != fh->fh_seq_id) {
36871 - atomic_inc(&mp->stats.seq_not_found);
36872 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36873 goto rel;
36874 }
36875
36876 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36877 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36878
36879 if (!sp)
36880 - atomic_inc(&mp->stats.xid_not_found);
36881 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36882 else
36883 - atomic_inc(&mp->stats.non_bls_resp);
36884 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36885
36886 fc_frame_free(fp);
36887 }
36888 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36889 index db9238f..4378ed2 100644
36890 --- a/drivers/scsi/libsas/sas_ata.c
36891 +++ b/drivers/scsi/libsas/sas_ata.c
36892 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
36893 .postreset = ata_std_postreset,
36894 .error_handler = ata_std_error_handler,
36895 .post_internal_cmd = sas_ata_post_internal,
36896 - .qc_defer = ata_std_qc_defer,
36897 + .qc_defer = ata_std_qc_defer,
36898 .qc_prep = ata_noop_qc_prep,
36899 .qc_issue = sas_ata_qc_issue,
36900 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36901 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36902 index 825f930..ce42672 100644
36903 --- a/drivers/scsi/lpfc/lpfc.h
36904 +++ b/drivers/scsi/lpfc/lpfc.h
36905 @@ -413,7 +413,7 @@ struct lpfc_vport {
36906 struct dentry *debug_nodelist;
36907 struct dentry *vport_debugfs_root;
36908 struct lpfc_debugfs_trc *disc_trc;
36909 - atomic_t disc_trc_cnt;
36910 + atomic_unchecked_t disc_trc_cnt;
36911 #endif
36912 uint8_t stat_data_enabled;
36913 uint8_t stat_data_blocked;
36914 @@ -821,8 +821,8 @@ struct lpfc_hba {
36915 struct timer_list fabric_block_timer;
36916 unsigned long bit_flags;
36917 #define FABRIC_COMANDS_BLOCKED 0
36918 - atomic_t num_rsrc_err;
36919 - atomic_t num_cmd_success;
36920 + atomic_unchecked_t num_rsrc_err;
36921 + atomic_unchecked_t num_cmd_success;
36922 unsigned long last_rsrc_error_time;
36923 unsigned long last_ramp_down_time;
36924 unsigned long last_ramp_up_time;
36925 @@ -852,7 +852,7 @@ struct lpfc_hba {
36926
36927 struct dentry *debug_slow_ring_trc;
36928 struct lpfc_debugfs_trc *slow_ring_trc;
36929 - atomic_t slow_ring_trc_cnt;
36930 + atomic_unchecked_t slow_ring_trc_cnt;
36931 /* iDiag debugfs sub-directory */
36932 struct dentry *idiag_root;
36933 struct dentry *idiag_pci_cfg;
36934 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
36935 index 3587a3f..d45b81b 100644
36936 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
36937 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
36938 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
36939
36940 #include <linux/debugfs.h>
36941
36942 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36943 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
36944 static unsigned long lpfc_debugfs_start_time = 0L;
36945
36946 /* iDiag */
36947 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
36948 lpfc_debugfs_enable = 0;
36949
36950 len = 0;
36951 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
36952 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
36953 (lpfc_debugfs_max_disc_trc - 1);
36954 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
36955 dtp = vport->disc_trc + i;
36956 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
36957 lpfc_debugfs_enable = 0;
36958
36959 len = 0;
36960 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
36961 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
36962 (lpfc_debugfs_max_slow_ring_trc - 1);
36963 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
36964 dtp = phba->slow_ring_trc + i;
36965 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
36966 !vport || !vport->disc_trc)
36967 return;
36968
36969 - index = atomic_inc_return(&vport->disc_trc_cnt) &
36970 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
36971 (lpfc_debugfs_max_disc_trc - 1);
36972 dtp = vport->disc_trc + index;
36973 dtp->fmt = fmt;
36974 dtp->data1 = data1;
36975 dtp->data2 = data2;
36976 dtp->data3 = data3;
36977 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36978 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36979 dtp->jif = jiffies;
36980 #endif
36981 return;
36982 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
36983 !phba || !phba->slow_ring_trc)
36984 return;
36985
36986 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
36987 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
36988 (lpfc_debugfs_max_slow_ring_trc - 1);
36989 dtp = phba->slow_ring_trc + index;
36990 dtp->fmt = fmt;
36991 dtp->data1 = data1;
36992 dtp->data2 = data2;
36993 dtp->data3 = data3;
36994 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
36995 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
36996 dtp->jif = jiffies;
36997 #endif
36998 return;
36999 @@ -4040,7 +4040,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37000 "slow_ring buffer\n");
37001 goto debug_failed;
37002 }
37003 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37004 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37005 memset(phba->slow_ring_trc, 0,
37006 (sizeof(struct lpfc_debugfs_trc) *
37007 lpfc_debugfs_max_slow_ring_trc));
37008 @@ -4086,7 +4086,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37009 "buffer\n");
37010 goto debug_failed;
37011 }
37012 - atomic_set(&vport->disc_trc_cnt, 0);
37013 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37014
37015 snprintf(name, sizeof(name), "discovery_trace");
37016 vport->debug_disc_trc =
37017 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37018 index dfea2da..8e17227 100644
37019 --- a/drivers/scsi/lpfc/lpfc_init.c
37020 +++ b/drivers/scsi/lpfc/lpfc_init.c
37021 @@ -10145,8 +10145,10 @@ lpfc_init(void)
37022 printk(LPFC_COPYRIGHT "\n");
37023
37024 if (lpfc_enable_npiv) {
37025 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37026 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37027 + pax_open_kernel();
37028 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37029 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37030 + pax_close_kernel();
37031 }
37032 lpfc_transport_template =
37033 fc_attach_transport(&lpfc_transport_functions);
37034 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37035 index c60f5d0..751535c 100644
37036 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37037 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37038 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37039 uint32_t evt_posted;
37040
37041 spin_lock_irqsave(&phba->hbalock, flags);
37042 - atomic_inc(&phba->num_rsrc_err);
37043 + atomic_inc_unchecked(&phba->num_rsrc_err);
37044 phba->last_rsrc_error_time = jiffies;
37045
37046 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37047 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37048 unsigned long flags;
37049 struct lpfc_hba *phba = vport->phba;
37050 uint32_t evt_posted;
37051 - atomic_inc(&phba->num_cmd_success);
37052 + atomic_inc_unchecked(&phba->num_cmd_success);
37053
37054 if (vport->cfg_lun_queue_depth <= queue_depth)
37055 return;
37056 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37057 unsigned long num_rsrc_err, num_cmd_success;
37058 int i;
37059
37060 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37061 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37062 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37063 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37064
37065 vports = lpfc_create_vport_work_array(phba);
37066 if (vports != NULL)
37067 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37068 }
37069 }
37070 lpfc_destroy_vport_work_array(phba, vports);
37071 - atomic_set(&phba->num_rsrc_err, 0);
37072 - atomic_set(&phba->num_cmd_success, 0);
37073 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37074 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37075 }
37076
37077 /**
37078 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37079 }
37080 }
37081 lpfc_destroy_vport_work_array(phba, vports);
37082 - atomic_set(&phba->num_rsrc_err, 0);
37083 - atomic_set(&phba->num_cmd_success, 0);
37084 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37085 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37086 }
37087
37088 /**
37089 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37090 index ea8a0b4..812a124 100644
37091 --- a/drivers/scsi/pmcraid.c
37092 +++ b/drivers/scsi/pmcraid.c
37093 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37094 res->scsi_dev = scsi_dev;
37095 scsi_dev->hostdata = res;
37096 res->change_detected = 0;
37097 - atomic_set(&res->read_failures, 0);
37098 - atomic_set(&res->write_failures, 0);
37099 + atomic_set_unchecked(&res->read_failures, 0);
37100 + atomic_set_unchecked(&res->write_failures, 0);
37101 rc = 0;
37102 }
37103 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37104 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37105
37106 /* If this was a SCSI read/write command keep count of errors */
37107 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37108 - atomic_inc(&res->read_failures);
37109 + atomic_inc_unchecked(&res->read_failures);
37110 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37111 - atomic_inc(&res->write_failures);
37112 + atomic_inc_unchecked(&res->write_failures);
37113
37114 if (!RES_IS_GSCSI(res->cfg_entry) &&
37115 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37116 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37117 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37118 * hrrq_id assigned here in queuecommand
37119 */
37120 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37121 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37122 pinstance->num_hrrq;
37123 cmd->cmd_done = pmcraid_io_done;
37124
37125 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37126 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37127 * hrrq_id assigned here in queuecommand
37128 */
37129 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37130 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37131 pinstance->num_hrrq;
37132
37133 if (request_size) {
37134 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37135
37136 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37137 /* add resources only after host is added into system */
37138 - if (!atomic_read(&pinstance->expose_resources))
37139 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37140 return;
37141
37142 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37143 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37144 init_waitqueue_head(&pinstance->reset_wait_q);
37145
37146 atomic_set(&pinstance->outstanding_cmds, 0);
37147 - atomic_set(&pinstance->last_message_id, 0);
37148 - atomic_set(&pinstance->expose_resources, 0);
37149 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37150 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37151
37152 INIT_LIST_HEAD(&pinstance->free_res_q);
37153 INIT_LIST_HEAD(&pinstance->used_res_q);
37154 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37155 /* Schedule worker thread to handle CCN and take care of adding and
37156 * removing devices to OS
37157 */
37158 - atomic_set(&pinstance->expose_resources, 1);
37159 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37160 schedule_work(&pinstance->worker_q);
37161 return rc;
37162
37163 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37164 index ca496c7..9c791d5 100644
37165 --- a/drivers/scsi/pmcraid.h
37166 +++ b/drivers/scsi/pmcraid.h
37167 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37168 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37169
37170 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37171 - atomic_t last_message_id;
37172 + atomic_unchecked_t last_message_id;
37173
37174 /* configuration table */
37175 struct pmcraid_config_table *cfg_table;
37176 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37177 atomic_t outstanding_cmds;
37178
37179 /* should add/delete resources to mid-layer now ?*/
37180 - atomic_t expose_resources;
37181 + atomic_unchecked_t expose_resources;
37182
37183
37184
37185 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37186 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37187 };
37188 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37189 - atomic_t read_failures; /* count of failed READ commands */
37190 - atomic_t write_failures; /* count of failed WRITE commands */
37191 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37192 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37193
37194 /* To indicate add/delete/modify during CCN */
37195 u8 change_detected;
37196 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37197 index af1003f..be55a75 100644
37198 --- a/drivers/scsi/qla2xxx/qla_def.h
37199 +++ b/drivers/scsi/qla2xxx/qla_def.h
37200 @@ -2247,7 +2247,7 @@ struct isp_operations {
37201 int (*start_scsi) (srb_t *);
37202 int (*abort_isp) (struct scsi_qla_host *);
37203 int (*iospace_config)(struct qla_hw_data*);
37204 -};
37205 +} __no_const;
37206
37207 /* MSI-X Support *************************************************************/
37208
37209 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37210 index bfe6854..ceac088 100644
37211 --- a/drivers/scsi/qla4xxx/ql4_def.h
37212 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37213 @@ -261,7 +261,7 @@ struct ddb_entry {
37214 * (4000 only) */
37215 atomic_t relogin_timer; /* Max Time to wait for
37216 * relogin to complete */
37217 - atomic_t relogin_retry_count; /* Num of times relogin has been
37218 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37219 * retried */
37220 uint32_t default_time2wait; /* Default Min time between
37221 * relogins (+aens) */
37222 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37223 index ce6d3b7..73fac54 100644
37224 --- a/drivers/scsi/qla4xxx/ql4_os.c
37225 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37226 @@ -2178,12 +2178,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37227 */
37228 if (!iscsi_is_session_online(cls_sess)) {
37229 /* Reset retry relogin timer */
37230 - atomic_inc(&ddb_entry->relogin_retry_count);
37231 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37232 DEBUG2(ql4_printk(KERN_INFO, ha,
37233 "%s: index[%d] relogin timed out-retrying"
37234 " relogin (%d), retry (%d)\n", __func__,
37235 ddb_entry->fw_ddb_index,
37236 - atomic_read(&ddb_entry->relogin_retry_count),
37237 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37238 ddb_entry->default_time2wait + 4));
37239 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37240 atomic_set(&ddb_entry->retry_relogin_timer,
37241 @@ -3953,7 +3953,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37242
37243 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37244 atomic_set(&ddb_entry->relogin_timer, 0);
37245 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37246 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37247 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37248 ddb_entry->default_relogin_timeout =
37249 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37250 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37251 index 2aeb2e9..46e3925 100644
37252 --- a/drivers/scsi/scsi.c
37253 +++ b/drivers/scsi/scsi.c
37254 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37255 unsigned long timeout;
37256 int rtn = 0;
37257
37258 - atomic_inc(&cmd->device->iorequest_cnt);
37259 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37260
37261 /* check if the device is still usable */
37262 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37263 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37264 index b2c95db..227d74e 100644
37265 --- a/drivers/scsi/scsi_lib.c
37266 +++ b/drivers/scsi/scsi_lib.c
37267 @@ -1411,7 +1411,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37268 shost = sdev->host;
37269 scsi_init_cmd_errh(cmd);
37270 cmd->result = DID_NO_CONNECT << 16;
37271 - atomic_inc(&cmd->device->iorequest_cnt);
37272 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37273
37274 /*
37275 * SCSI request completion path will do scsi_device_unbusy(),
37276 @@ -1437,9 +1437,9 @@ static void scsi_softirq_done(struct request *rq)
37277
37278 INIT_LIST_HEAD(&cmd->eh_entry);
37279
37280 - atomic_inc(&cmd->device->iodone_cnt);
37281 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37282 if (cmd->result)
37283 - atomic_inc(&cmd->device->ioerr_cnt);
37284 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37285
37286 disposition = scsi_decide_disposition(cmd);
37287 if (disposition != SUCCESS &&
37288 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37289 index 04c2a27..9d8bd66 100644
37290 --- a/drivers/scsi/scsi_sysfs.c
37291 +++ b/drivers/scsi/scsi_sysfs.c
37292 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37293 char *buf) \
37294 { \
37295 struct scsi_device *sdev = to_scsi_device(dev); \
37296 - unsigned long long count = atomic_read(&sdev->field); \
37297 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37298 return snprintf(buf, 20, "0x%llx\n", count); \
37299 } \
37300 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37301 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37302 index 84a1fdf..693b0d6 100644
37303 --- a/drivers/scsi/scsi_tgt_lib.c
37304 +++ b/drivers/scsi/scsi_tgt_lib.c
37305 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37306 int err;
37307
37308 dprintk("%lx %u\n", uaddr, len);
37309 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37310 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37311 if (err) {
37312 /*
37313 * TODO: need to fixup sg_tablesize, max_segment_size,
37314 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37315 index f59d4a0..1d89407 100644
37316 --- a/drivers/scsi/scsi_transport_fc.c
37317 +++ b/drivers/scsi/scsi_transport_fc.c
37318 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37319 * Netlink Infrastructure
37320 */
37321
37322 -static atomic_t fc_event_seq;
37323 +static atomic_unchecked_t fc_event_seq;
37324
37325 /**
37326 * fc_get_event_number - Obtain the next sequential FC event number
37327 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
37328 u32
37329 fc_get_event_number(void)
37330 {
37331 - return atomic_add_return(1, &fc_event_seq);
37332 + return atomic_add_return_unchecked(1, &fc_event_seq);
37333 }
37334 EXPORT_SYMBOL(fc_get_event_number);
37335
37336 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
37337 {
37338 int error;
37339
37340 - atomic_set(&fc_event_seq, 0);
37341 + atomic_set_unchecked(&fc_event_seq, 0);
37342
37343 error = transport_class_register(&fc_host_class);
37344 if (error)
37345 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37346 char *cp;
37347
37348 *val = simple_strtoul(buf, &cp, 0);
37349 - if ((*cp && (*cp != '\n')) || (*val < 0))
37350 + if (*cp && (*cp != '\n'))
37351 return -EINVAL;
37352 /*
37353 * Check for overflow; dev_loss_tmo is u32
37354 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37355 index e3e3c7d..ebdab62 100644
37356 --- a/drivers/scsi/scsi_transport_iscsi.c
37357 +++ b/drivers/scsi/scsi_transport_iscsi.c
37358 @@ -79,7 +79,7 @@ struct iscsi_internal {
37359 struct transport_container session_cont;
37360 };
37361
37362 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37363 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37364 static struct workqueue_struct *iscsi_eh_timer_workq;
37365
37366 static DEFINE_IDA(iscsi_sess_ida);
37367 @@ -1063,7 +1063,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37368 int err;
37369
37370 ihost = shost->shost_data;
37371 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37372 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37373
37374 if (target_id == ISCSI_MAX_TARGET) {
37375 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37376 @@ -2680,7 +2680,7 @@ static __init int iscsi_transport_init(void)
37377 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37378 ISCSI_TRANSPORT_VERSION);
37379
37380 - atomic_set(&iscsi_session_nr, 0);
37381 + atomic_set_unchecked(&iscsi_session_nr, 0);
37382
37383 err = class_register(&iscsi_transport_class);
37384 if (err)
37385 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37386 index 21a045e..ec89e03 100644
37387 --- a/drivers/scsi/scsi_transport_srp.c
37388 +++ b/drivers/scsi/scsi_transport_srp.c
37389 @@ -33,7 +33,7 @@
37390 #include "scsi_transport_srp_internal.h"
37391
37392 struct srp_host_attrs {
37393 - atomic_t next_port_id;
37394 + atomic_unchecked_t next_port_id;
37395 };
37396 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37397
37398 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37399 struct Scsi_Host *shost = dev_to_shost(dev);
37400 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37401
37402 - atomic_set(&srp_host->next_port_id, 0);
37403 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37404 return 0;
37405 }
37406
37407 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37408 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37409 rport->roles = ids->roles;
37410
37411 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37412 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37413 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37414
37415 transport_setup_device(&rport->dev);
37416 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37417 index eacd46b..e3f4d62 100644
37418 --- a/drivers/scsi/sg.c
37419 +++ b/drivers/scsi/sg.c
37420 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37421 sdp->disk->disk_name,
37422 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37423 NULL,
37424 - (char *)arg);
37425 + (char __user *)arg);
37426 case BLKTRACESTART:
37427 return blk_trace_startstop(sdp->device->request_queue, 1);
37428 case BLKTRACESTOP:
37429 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
37430 const struct file_operations * fops;
37431 };
37432
37433 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
37434 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
37435 {"allow_dio", &adio_fops},
37436 {"debug", &debug_fops},
37437 {"def_reserved_size", &dressz_fops},
37438 @@ -2332,7 +2332,7 @@ sg_proc_init(void)
37439 if (!sg_proc_sgp)
37440 return 1;
37441 for (k = 0; k < num_leaves; ++k) {
37442 - struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37443 + const struct sg_proc_leaf *leaf = &sg_proc_leaf_arr[k];
37444 umode_t mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
37445 proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
37446 }
37447 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
37448 index f64250e..1ee3049 100644
37449 --- a/drivers/spi/spi-dw-pci.c
37450 +++ b/drivers/spi/spi-dw-pci.c
37451 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
37452 #define spi_resume NULL
37453 #endif
37454
37455 -static const struct pci_device_id pci_ids[] __devinitdata = {
37456 +static const struct pci_device_id pci_ids[] __devinitconst = {
37457 /* Intel MID platform SPI controller 0 */
37458 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
37459 {},
37460 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37461 index b2ccdea..84cde75 100644
37462 --- a/drivers/spi/spi.c
37463 +++ b/drivers/spi/spi.c
37464 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
37465 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37466
37467 /* portable code must never pass more than 32 bytes */
37468 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37469 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37470
37471 static u8 *buf;
37472
37473 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37474 index 400df8c..065d4f4 100644
37475 --- a/drivers/staging/octeon/ethernet-rx.c
37476 +++ b/drivers/staging/octeon/ethernet-rx.c
37477 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37478 /* Increment RX stats for virtual ports */
37479 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37480 #ifdef CONFIG_64BIT
37481 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37482 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37483 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37484 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37485 #else
37486 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37487 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37488 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37489 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37490 #endif
37491 }
37492 netif_receive_skb(skb);
37493 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37494 dev->name);
37495 */
37496 #ifdef CONFIG_64BIT
37497 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37498 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37499 #else
37500 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37501 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37502 #endif
37503 dev_kfree_skb_irq(skb);
37504 }
37505 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37506 index 9112cd8..92f8d51 100644
37507 --- a/drivers/staging/octeon/ethernet.c
37508 +++ b/drivers/staging/octeon/ethernet.c
37509 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37510 * since the RX tasklet also increments it.
37511 */
37512 #ifdef CONFIG_64BIT
37513 - atomic64_add(rx_status.dropped_packets,
37514 - (atomic64_t *)&priv->stats.rx_dropped);
37515 + atomic64_add_unchecked(rx_status.dropped_packets,
37516 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37517 #else
37518 - atomic_add(rx_status.dropped_packets,
37519 - (atomic_t *)&priv->stats.rx_dropped);
37520 + atomic_add_unchecked(rx_status.dropped_packets,
37521 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37522 #endif
37523 }
37524
37525 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37526 index 86308a0..feaa925 100644
37527 --- a/drivers/staging/rtl8712/rtl871x_io.h
37528 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37529 @@ -108,7 +108,7 @@ struct _io_ops {
37530 u8 *pmem);
37531 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37532 u8 *pmem);
37533 -};
37534 +} __no_const;
37535
37536 struct io_req {
37537 struct list_head list;
37538 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37539 index c7b5e8b..783d6cb 100644
37540 --- a/drivers/staging/sbe-2t3e3/netdev.c
37541 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37542 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37543 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37544
37545 if (rlen)
37546 - if (copy_to_user(data, &resp, rlen))
37547 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37548 return -EFAULT;
37549
37550 return 0;
37551 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37552 index 42cdafe..2769103 100644
37553 --- a/drivers/staging/speakup/speakup_soft.c
37554 +++ b/drivers/staging/speakup/speakup_soft.c
37555 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37556 break;
37557 } else if (!initialized) {
37558 if (*init) {
37559 - ch = *init;
37560 init++;
37561 } else {
37562 initialized = 1;
37563 }
37564 + ch = *init;
37565 } else {
37566 ch = synth_buffer_getc();
37567 }
37568 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37569 index b8f8c48..1fc5025 100644
37570 --- a/drivers/staging/usbip/usbip_common.h
37571 +++ b/drivers/staging/usbip/usbip_common.h
37572 @@ -289,7 +289,7 @@ struct usbip_device {
37573 void (*shutdown)(struct usbip_device *);
37574 void (*reset)(struct usbip_device *);
37575 void (*unusable)(struct usbip_device *);
37576 - } eh_ops;
37577 + } __no_const eh_ops;
37578 };
37579
37580 /* usbip_common.c */
37581 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37582 index 88b3298..3783eee 100644
37583 --- a/drivers/staging/usbip/vhci.h
37584 +++ b/drivers/staging/usbip/vhci.h
37585 @@ -88,7 +88,7 @@ struct vhci_hcd {
37586 unsigned resuming:1;
37587 unsigned long re_timeout;
37588
37589 - atomic_t seqnum;
37590 + atomic_unchecked_t seqnum;
37591
37592 /*
37593 * NOTE:
37594 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37595 index 2ee97e2..0420b86 100644
37596 --- a/drivers/staging/usbip/vhci_hcd.c
37597 +++ b/drivers/staging/usbip/vhci_hcd.c
37598 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
37599 return;
37600 }
37601
37602 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37603 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37604 if (priv->seqnum == 0xffff)
37605 dev_info(&urb->dev->dev, "seqnum max\n");
37606
37607 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37608 return -ENOMEM;
37609 }
37610
37611 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37612 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37613 if (unlink->seqnum == 0xffff)
37614 pr_info("seqnum max\n");
37615
37616 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
37617 vdev->rhport = rhport;
37618 }
37619
37620 - atomic_set(&vhci->seqnum, 0);
37621 + atomic_set_unchecked(&vhci->seqnum, 0);
37622 spin_lock_init(&vhci->lock);
37623
37624 hcd->power_budget = 0; /* no limit */
37625 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37626 index 3f511b4..d3dbc1e 100644
37627 --- a/drivers/staging/usbip/vhci_rx.c
37628 +++ b/drivers/staging/usbip/vhci_rx.c
37629 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37630 if (!urb) {
37631 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37632 pr_info("max seqnum %d\n",
37633 - atomic_read(&the_controller->seqnum));
37634 + atomic_read_unchecked(&the_controller->seqnum));
37635 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37636 return;
37637 }
37638 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37639 index 7735027..30eed13 100644
37640 --- a/drivers/staging/vt6655/hostap.c
37641 +++ b/drivers/staging/vt6655/hostap.c
37642 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37643 *
37644 */
37645
37646 +static net_device_ops_no_const apdev_netdev_ops;
37647 +
37648 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37649 {
37650 PSDevice apdev_priv;
37651 struct net_device *dev = pDevice->dev;
37652 int ret;
37653 - const struct net_device_ops apdev_netdev_ops = {
37654 - .ndo_start_xmit = pDevice->tx_80211,
37655 - };
37656
37657 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37658
37659 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37660 *apdev_priv = *pDevice;
37661 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37662
37663 + /* only half broken now */
37664 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37665 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37666
37667 pDevice->apdev->type = ARPHRD_IEEE80211;
37668 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37669 index 51b5adf..098e320 100644
37670 --- a/drivers/staging/vt6656/hostap.c
37671 +++ b/drivers/staging/vt6656/hostap.c
37672 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37673 *
37674 */
37675
37676 +static net_device_ops_no_const apdev_netdev_ops;
37677 +
37678 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37679 {
37680 PSDevice apdev_priv;
37681 struct net_device *dev = pDevice->dev;
37682 int ret;
37683 - const struct net_device_ops apdev_netdev_ops = {
37684 - .ndo_start_xmit = pDevice->tx_80211,
37685 - };
37686
37687 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37688
37689 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37690 *apdev_priv = *pDevice;
37691 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37692
37693 + /* only half broken now */
37694 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37695 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37696
37697 pDevice->apdev->type = ARPHRD_IEEE80211;
37698 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37699 index 7843dfd..3db105f 100644
37700 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37701 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37702 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37703
37704 struct usbctlx_completor {
37705 int (*complete) (struct usbctlx_completor *);
37706 -};
37707 +} __no_const;
37708
37709 static int
37710 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37711 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37712 index 1ca66ea..76f1343 100644
37713 --- a/drivers/staging/zcache/tmem.c
37714 +++ b/drivers/staging/zcache/tmem.c
37715 @@ -39,7 +39,7 @@
37716 * A tmem host implementation must use this function to register callbacks
37717 * for memory allocation.
37718 */
37719 -static struct tmem_hostops tmem_hostops;
37720 +static tmem_hostops_no_const tmem_hostops;
37721
37722 static void tmem_objnode_tree_init(void);
37723
37724 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37725 * A tmem host implementation must use this function to register
37726 * callbacks for a page-accessible memory (PAM) implementation
37727 */
37728 -static struct tmem_pamops tmem_pamops;
37729 +static tmem_pamops_no_const tmem_pamops;
37730
37731 void tmem_register_pamops(struct tmem_pamops *m)
37732 {
37733 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37734 index ed147c4..94fc3c6 100644
37735 --- a/drivers/staging/zcache/tmem.h
37736 +++ b/drivers/staging/zcache/tmem.h
37737 @@ -180,6 +180,7 @@ struct tmem_pamops {
37738 void (*new_obj)(struct tmem_obj *);
37739 int (*replace_in_obj)(void *, struct tmem_obj *);
37740 };
37741 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37742 extern void tmem_register_pamops(struct tmem_pamops *m);
37743
37744 /* memory allocation methods provided by the host implementation */
37745 @@ -189,6 +190,7 @@ struct tmem_hostops {
37746 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37747 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37748 };
37749 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37750 extern void tmem_register_hostops(struct tmem_hostops *m);
37751
37752 /* core tmem accessor functions */
37753 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
37754 index 97c74ee..7f6d77d 100644
37755 --- a/drivers/target/iscsi/iscsi_target.c
37756 +++ b/drivers/target/iscsi/iscsi_target.c
37757 @@ -1361,7 +1361,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
37758 * outstanding_r2ts reaches zero, go ahead and send the delayed
37759 * TASK_ABORTED status.
37760 */
37761 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
37762 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
37763 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
37764 if (--cmd->outstanding_r2ts < 1) {
37765 iscsit_stop_dataout_timer(cmd);
37766 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
37767 index dcb0618..97e3d85 100644
37768 --- a/drivers/target/target_core_tmr.c
37769 +++ b/drivers/target/target_core_tmr.c
37770 @@ -260,7 +260,7 @@ static void core_tmr_drain_task_list(
37771 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
37772 cmd->t_task_list_num,
37773 atomic_read(&cmd->t_task_cdbs_left),
37774 - atomic_read(&cmd->t_task_cdbs_sent),
37775 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37776 atomic_read(&cmd->t_transport_active),
37777 atomic_read(&cmd->t_transport_stop),
37778 atomic_read(&cmd->t_transport_sent));
37779 @@ -291,7 +291,7 @@ static void core_tmr_drain_task_list(
37780 pr_debug("LUN_RESET: got t_transport_active = 1 for"
37781 " task: %p, t_fe_count: %d dev: %p\n", task,
37782 fe_count, dev);
37783 - atomic_set(&cmd->t_transport_aborted, 1);
37784 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37785 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37786
37787 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37788 @@ -299,7 +299,7 @@ static void core_tmr_drain_task_list(
37789 }
37790 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
37791 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
37792 - atomic_set(&cmd->t_transport_aborted, 1);
37793 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
37794 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37795
37796 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
37797 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37798 index cd5cd95..5249d30 100644
37799 --- a/drivers/target/target_core_transport.c
37800 +++ b/drivers/target/target_core_transport.c
37801 @@ -1330,7 +1330,7 @@ struct se_device *transport_add_device_to_core_hba(
37802 spin_lock_init(&dev->se_port_lock);
37803 spin_lock_init(&dev->se_tmr_lock);
37804 spin_lock_init(&dev->qf_cmd_lock);
37805 - atomic_set(&dev->dev_ordered_id, 0);
37806 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37807
37808 se_dev_set_default_attribs(dev, dev_limits);
37809
37810 @@ -1517,7 +1517,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37811 * Used to determine when ORDERED commands should go from
37812 * Dormant to Active status.
37813 */
37814 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37815 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37816 smp_mb__after_atomic_inc();
37817 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37818 cmd->se_ordered_id, cmd->sam_task_attr,
37819 @@ -1862,7 +1862,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
37820 " t_transport_active: %d t_transport_stop: %d"
37821 " t_transport_sent: %d\n", cmd->t_task_list_num,
37822 atomic_read(&cmd->t_task_cdbs_left),
37823 - atomic_read(&cmd->t_task_cdbs_sent),
37824 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
37825 atomic_read(&cmd->t_task_cdbs_ex_left),
37826 atomic_read(&cmd->t_transport_active),
37827 atomic_read(&cmd->t_transport_stop),
37828 @@ -2121,9 +2121,9 @@ check_depth:
37829 cmd = task->task_se_cmd;
37830 spin_lock_irqsave(&cmd->t_state_lock, flags);
37831 task->task_flags |= (TF_ACTIVE | TF_SENT);
37832 - atomic_inc(&cmd->t_task_cdbs_sent);
37833 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
37834
37835 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
37836 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
37837 cmd->t_task_list_num)
37838 atomic_set(&cmd->t_transport_sent, 1);
37839
37840 @@ -4348,7 +4348,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
37841 atomic_set(&cmd->transport_lun_stop, 0);
37842 }
37843 if (!atomic_read(&cmd->t_transport_active) ||
37844 - atomic_read(&cmd->t_transport_aborted)) {
37845 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
37846 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
37847 return false;
37848 }
37849 @@ -4597,7 +4597,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
37850 {
37851 int ret = 0;
37852
37853 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
37854 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
37855 if (!send_status ||
37856 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
37857 return 1;
37858 @@ -4634,7 +4634,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
37859 */
37860 if (cmd->data_direction == DMA_TO_DEVICE) {
37861 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
37862 - atomic_inc(&cmd->t_transport_aborted);
37863 + atomic_inc_unchecked(&cmd->t_transport_aborted);
37864 smp_mb__after_atomic_inc();
37865 }
37866 }
37867 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37868 index b9040be..e3f5aab 100644
37869 --- a/drivers/tty/hvc/hvcs.c
37870 +++ b/drivers/tty/hvc/hvcs.c
37871 @@ -83,6 +83,7 @@
37872 #include <asm/hvcserver.h>
37873 #include <asm/uaccess.h>
37874 #include <asm/vio.h>
37875 +#include <asm/local.h>
37876
37877 /*
37878 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37879 @@ -270,7 +271,7 @@ struct hvcs_struct {
37880 unsigned int index;
37881
37882 struct tty_struct *tty;
37883 - int open_count;
37884 + local_t open_count;
37885
37886 /*
37887 * Used to tell the driver kernel_thread what operations need to take
37888 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37889
37890 spin_lock_irqsave(&hvcsd->lock, flags);
37891
37892 - if (hvcsd->open_count > 0) {
37893 + if (local_read(&hvcsd->open_count) > 0) {
37894 spin_unlock_irqrestore(&hvcsd->lock, flags);
37895 printk(KERN_INFO "HVCS: vterm state unchanged. "
37896 "The hvcs device node is still in use.\n");
37897 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37898 if ((retval = hvcs_partner_connect(hvcsd)))
37899 goto error_release;
37900
37901 - hvcsd->open_count = 1;
37902 + local_set(&hvcsd->open_count, 1);
37903 hvcsd->tty = tty;
37904 tty->driver_data = hvcsd;
37905
37906 @@ -1179,7 +1180,7 @@ fast_open:
37907
37908 spin_lock_irqsave(&hvcsd->lock, flags);
37909 kref_get(&hvcsd->kref);
37910 - hvcsd->open_count++;
37911 + local_inc(&hvcsd->open_count);
37912 hvcsd->todo_mask |= HVCS_SCHED_READ;
37913 spin_unlock_irqrestore(&hvcsd->lock, flags);
37914
37915 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37916 hvcsd = tty->driver_data;
37917
37918 spin_lock_irqsave(&hvcsd->lock, flags);
37919 - if (--hvcsd->open_count == 0) {
37920 + if (local_dec_and_test(&hvcsd->open_count)) {
37921
37922 vio_disable_interrupts(hvcsd->vdev);
37923
37924 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37925 free_irq(irq, hvcsd);
37926 kref_put(&hvcsd->kref, destroy_hvcs_struct);
37927 return;
37928 - } else if (hvcsd->open_count < 0) {
37929 + } else if (local_read(&hvcsd->open_count) < 0) {
37930 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37931 " is missmanaged.\n",
37932 - hvcsd->vdev->unit_address, hvcsd->open_count);
37933 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
37934 }
37935
37936 spin_unlock_irqrestore(&hvcsd->lock, flags);
37937 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37938
37939 spin_lock_irqsave(&hvcsd->lock, flags);
37940 /* Preserve this so that we know how many kref refs to put */
37941 - temp_open_count = hvcsd->open_count;
37942 + temp_open_count = local_read(&hvcsd->open_count);
37943
37944 /*
37945 * Don't kref put inside the spinlock because the destruction
37946 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37947 hvcsd->tty->driver_data = NULL;
37948 hvcsd->tty = NULL;
37949
37950 - hvcsd->open_count = 0;
37951 + local_set(&hvcsd->open_count, 0);
37952
37953 /* This will drop any buffered data on the floor which is OK in a hangup
37954 * scenario. */
37955 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
37956 * the middle of a write operation? This is a crummy place to do this
37957 * but we want to keep it all in the spinlock.
37958 */
37959 - if (hvcsd->open_count <= 0) {
37960 + if (local_read(&hvcsd->open_count) <= 0) {
37961 spin_unlock_irqrestore(&hvcsd->lock, flags);
37962 return -ENODEV;
37963 }
37964 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
37965 {
37966 struct hvcs_struct *hvcsd = tty->driver_data;
37967
37968 - if (!hvcsd || hvcsd->open_count <= 0)
37969 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
37970 return 0;
37971
37972 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
37973 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
37974 index ef92869..f4ebd88 100644
37975 --- a/drivers/tty/ipwireless/tty.c
37976 +++ b/drivers/tty/ipwireless/tty.c
37977 @@ -29,6 +29,7 @@
37978 #include <linux/tty_driver.h>
37979 #include <linux/tty_flip.h>
37980 #include <linux/uaccess.h>
37981 +#include <asm/local.h>
37982
37983 #include "tty.h"
37984 #include "network.h"
37985 @@ -51,7 +52,7 @@ struct ipw_tty {
37986 int tty_type;
37987 struct ipw_network *network;
37988 struct tty_struct *linux_tty;
37989 - int open_count;
37990 + local_t open_count;
37991 unsigned int control_lines;
37992 struct mutex ipw_tty_mutex;
37993 int tx_bytes_queued;
37994 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
37995 mutex_unlock(&tty->ipw_tty_mutex);
37996 return -ENODEV;
37997 }
37998 - if (tty->open_count == 0)
37999 + if (local_read(&tty->open_count) == 0)
38000 tty->tx_bytes_queued = 0;
38001
38002 - tty->open_count++;
38003 + local_inc(&tty->open_count);
38004
38005 tty->linux_tty = linux_tty;
38006 linux_tty->driver_data = tty;
38007 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38008
38009 static void do_ipw_close(struct ipw_tty *tty)
38010 {
38011 - tty->open_count--;
38012 -
38013 - if (tty->open_count == 0) {
38014 + if (local_dec_return(&tty->open_count) == 0) {
38015 struct tty_struct *linux_tty = tty->linux_tty;
38016
38017 if (linux_tty != NULL) {
38018 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38019 return;
38020
38021 mutex_lock(&tty->ipw_tty_mutex);
38022 - if (tty->open_count == 0) {
38023 + if (local_read(&tty->open_count) == 0) {
38024 mutex_unlock(&tty->ipw_tty_mutex);
38025 return;
38026 }
38027 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38028 return;
38029 }
38030
38031 - if (!tty->open_count) {
38032 + if (!local_read(&tty->open_count)) {
38033 mutex_unlock(&tty->ipw_tty_mutex);
38034 return;
38035 }
38036 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38037 return -ENODEV;
38038
38039 mutex_lock(&tty->ipw_tty_mutex);
38040 - if (!tty->open_count) {
38041 + if (!local_read(&tty->open_count)) {
38042 mutex_unlock(&tty->ipw_tty_mutex);
38043 return -EINVAL;
38044 }
38045 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38046 if (!tty)
38047 return -ENODEV;
38048
38049 - if (!tty->open_count)
38050 + if (!local_read(&tty->open_count))
38051 return -EINVAL;
38052
38053 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38054 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38055 if (!tty)
38056 return 0;
38057
38058 - if (!tty->open_count)
38059 + if (!local_read(&tty->open_count))
38060 return 0;
38061
38062 return tty->tx_bytes_queued;
38063 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38064 if (!tty)
38065 return -ENODEV;
38066
38067 - if (!tty->open_count)
38068 + if (!local_read(&tty->open_count))
38069 return -EINVAL;
38070
38071 return get_control_lines(tty);
38072 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38073 if (!tty)
38074 return -ENODEV;
38075
38076 - if (!tty->open_count)
38077 + if (!local_read(&tty->open_count))
38078 return -EINVAL;
38079
38080 return set_control_lines(tty, set, clear);
38081 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38082 if (!tty)
38083 return -ENODEV;
38084
38085 - if (!tty->open_count)
38086 + if (!local_read(&tty->open_count))
38087 return -EINVAL;
38088
38089 /* FIXME: Exactly how is the tty object locked here .. */
38090 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38091 against a parallel ioctl etc */
38092 mutex_lock(&ttyj->ipw_tty_mutex);
38093 }
38094 - while (ttyj->open_count)
38095 + while (local_read(&ttyj->open_count))
38096 do_ipw_close(ttyj);
38097 ipwireless_disassociate_network_ttys(network,
38098 ttyj->channel_idx);
38099 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38100 index fc7bbba..9527e93 100644
38101 --- a/drivers/tty/n_gsm.c
38102 +++ b/drivers/tty/n_gsm.c
38103 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38104 kref_init(&dlci->ref);
38105 mutex_init(&dlci->mutex);
38106 dlci->fifo = &dlci->_fifo;
38107 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38108 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38109 kfree(dlci);
38110 return NULL;
38111 }
38112 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38113 index d2256d0..97476fa 100644
38114 --- a/drivers/tty/n_tty.c
38115 +++ b/drivers/tty/n_tty.c
38116 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38117 {
38118 *ops = tty_ldisc_N_TTY;
38119 ops->owner = NULL;
38120 - ops->refcount = ops->flags = 0;
38121 + atomic_set(&ops->refcount, 0);
38122 + ops->flags = 0;
38123 }
38124 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38125 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38126 index d8653ab..f8afd9d 100644
38127 --- a/drivers/tty/pty.c
38128 +++ b/drivers/tty/pty.c
38129 @@ -765,8 +765,10 @@ static void __init unix98_pty_init(void)
38130 register_sysctl_table(pty_root_table);
38131
38132 /* Now create the /dev/ptmx special device */
38133 + pax_open_kernel();
38134 tty_default_fops(&ptmx_fops);
38135 - ptmx_fops.open = ptmx_open;
38136 + *(void **)&ptmx_fops.open = ptmx_open;
38137 + pax_close_kernel();
38138
38139 cdev_init(&ptmx_cdev, &ptmx_fops);
38140 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38141 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38142 index 2b42a01..32a2ed3 100644
38143 --- a/drivers/tty/serial/kgdboc.c
38144 +++ b/drivers/tty/serial/kgdboc.c
38145 @@ -24,8 +24,9 @@
38146 #define MAX_CONFIG_LEN 40
38147
38148 static struct kgdb_io kgdboc_io_ops;
38149 +static struct kgdb_io kgdboc_io_ops_console;
38150
38151 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38152 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38153 static int configured = -1;
38154
38155 static char config[MAX_CONFIG_LEN];
38156 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38157 kgdboc_unregister_kbd();
38158 if (configured == 1)
38159 kgdb_unregister_io_module(&kgdboc_io_ops);
38160 + else if (configured == 2)
38161 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38162 }
38163
38164 static int configure_kgdboc(void)
38165 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38166 int err;
38167 char *cptr = config;
38168 struct console *cons;
38169 + int is_console = 0;
38170
38171 err = kgdboc_option_setup(config);
38172 if (err || !strlen(config) || isspace(config[0]))
38173 goto noconfig;
38174
38175 err = -ENODEV;
38176 - kgdboc_io_ops.is_console = 0;
38177 kgdb_tty_driver = NULL;
38178
38179 kgdboc_use_kms = 0;
38180 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38181 int idx;
38182 if (cons->device && cons->device(cons, &idx) == p &&
38183 idx == tty_line) {
38184 - kgdboc_io_ops.is_console = 1;
38185 + is_console = 1;
38186 break;
38187 }
38188 cons = cons->next;
38189 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38190 kgdb_tty_line = tty_line;
38191
38192 do_register:
38193 - err = kgdb_register_io_module(&kgdboc_io_ops);
38194 + if (is_console) {
38195 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38196 + configured = 2;
38197 + } else {
38198 + err = kgdb_register_io_module(&kgdboc_io_ops);
38199 + configured = 1;
38200 + }
38201 if (err)
38202 goto noconfig;
38203
38204 - configured = 1;
38205 -
38206 return 0;
38207
38208 noconfig:
38209 @@ -213,7 +220,7 @@ noconfig:
38210 static int __init init_kgdboc(void)
38211 {
38212 /* Already configured? */
38213 - if (configured == 1)
38214 + if (configured >= 1)
38215 return 0;
38216
38217 return configure_kgdboc();
38218 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38219 if (config[len - 1] == '\n')
38220 config[len - 1] = '\0';
38221
38222 - if (configured == 1)
38223 + if (configured >= 1)
38224 cleanup_kgdboc();
38225
38226 /* Go and configure with the new params. */
38227 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38228 .post_exception = kgdboc_post_exp_handler,
38229 };
38230
38231 +static struct kgdb_io kgdboc_io_ops_console = {
38232 + .name = "kgdboc",
38233 + .read_char = kgdboc_get_char,
38234 + .write_char = kgdboc_put_char,
38235 + .pre_exception = kgdboc_pre_exp_handler,
38236 + .post_exception = kgdboc_post_exp_handler,
38237 + .is_console = 1
38238 +};
38239 +
38240 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38241 /* This is only available if kgdboc is a built in for early debugging */
38242 static int __init kgdboc_early_init(char *opt)
38243 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38244 index 7867b7c..b3c119d 100644
38245 --- a/drivers/tty/sysrq.c
38246 +++ b/drivers/tty/sysrq.c
38247 @@ -862,7 +862,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38248 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38249 size_t count, loff_t *ppos)
38250 {
38251 - if (count) {
38252 + if (count && capable(CAP_SYS_ADMIN)) {
38253 char c;
38254
38255 if (get_user(c, buf))
38256 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38257 index e41b9bb..84002fb 100644
38258 --- a/drivers/tty/tty_io.c
38259 +++ b/drivers/tty/tty_io.c
38260 @@ -3291,7 +3291,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38261
38262 void tty_default_fops(struct file_operations *fops)
38263 {
38264 - *fops = tty_fops;
38265 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38266 }
38267
38268 /*
38269 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38270 index 24b95db..9c078d0 100644
38271 --- a/drivers/tty/tty_ldisc.c
38272 +++ b/drivers/tty/tty_ldisc.c
38273 @@ -57,7 +57,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38274 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38275 struct tty_ldisc_ops *ldo = ld->ops;
38276
38277 - ldo->refcount--;
38278 + atomic_dec(&ldo->refcount);
38279 module_put(ldo->owner);
38280 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38281
38282 @@ -92,7 +92,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38283 spin_lock_irqsave(&tty_ldisc_lock, flags);
38284 tty_ldiscs[disc] = new_ldisc;
38285 new_ldisc->num = disc;
38286 - new_ldisc->refcount = 0;
38287 + atomic_set(&new_ldisc->refcount, 0);
38288 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38289
38290 return ret;
38291 @@ -120,7 +120,7 @@ int tty_unregister_ldisc(int disc)
38292 return -EINVAL;
38293
38294 spin_lock_irqsave(&tty_ldisc_lock, flags);
38295 - if (tty_ldiscs[disc]->refcount)
38296 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38297 ret = -EBUSY;
38298 else
38299 tty_ldiscs[disc] = NULL;
38300 @@ -141,7 +141,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38301 if (ldops) {
38302 ret = ERR_PTR(-EAGAIN);
38303 if (try_module_get(ldops->owner)) {
38304 - ldops->refcount++;
38305 + atomic_inc(&ldops->refcount);
38306 ret = ldops;
38307 }
38308 }
38309 @@ -154,7 +154,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38310 unsigned long flags;
38311
38312 spin_lock_irqsave(&tty_ldisc_lock, flags);
38313 - ldops->refcount--;
38314 + atomic_dec(&ldops->refcount);
38315 module_put(ldops->owner);
38316 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38317 }
38318 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38319 index a605549..6bd3c96 100644
38320 --- a/drivers/tty/vt/keyboard.c
38321 +++ b/drivers/tty/vt/keyboard.c
38322 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38323 kbd->kbdmode == VC_OFF) &&
38324 value != KVAL(K_SAK))
38325 return; /* SAK is allowed even in raw mode */
38326 +
38327 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38328 + {
38329 + void *func = fn_handler[value];
38330 + if (func == fn_show_state || func == fn_show_ptregs ||
38331 + func == fn_show_mem)
38332 + return;
38333 + }
38334 +#endif
38335 +
38336 fn_handler[value](vc);
38337 }
38338
38339 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
38340 index 65447c5..0526f0a 100644
38341 --- a/drivers/tty/vt/vt_ioctl.c
38342 +++ b/drivers/tty/vt/vt_ioctl.c
38343 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38344 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38345 return -EFAULT;
38346
38347 - if (!capable(CAP_SYS_TTY_CONFIG))
38348 - perm = 0;
38349 -
38350 switch (cmd) {
38351 case KDGKBENT:
38352 key_map = key_maps[s];
38353 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
38354 val = (i ? K_HOLE : K_NOSUCHMAP);
38355 return put_user(val, &user_kbe->kb_value);
38356 case KDSKBENT:
38357 + if (!capable(CAP_SYS_TTY_CONFIG))
38358 + perm = 0;
38359 +
38360 if (!perm)
38361 return -EPERM;
38362 if (!i && v == K_NOSUCHMAP) {
38363 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38364 int i, j, k;
38365 int ret;
38366
38367 - if (!capable(CAP_SYS_TTY_CONFIG))
38368 - perm = 0;
38369 -
38370 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38371 if (!kbs) {
38372 ret = -ENOMEM;
38373 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38374 kfree(kbs);
38375 return ((p && *p) ? -EOVERFLOW : 0);
38376 case KDSKBSENT:
38377 + if (!capable(CAP_SYS_TTY_CONFIG))
38378 + perm = 0;
38379 +
38380 if (!perm) {
38381 ret = -EPERM;
38382 goto reterr;
38383 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38384 index a783d53..cb30d94 100644
38385 --- a/drivers/uio/uio.c
38386 +++ b/drivers/uio/uio.c
38387 @@ -25,6 +25,7 @@
38388 #include <linux/kobject.h>
38389 #include <linux/cdev.h>
38390 #include <linux/uio_driver.h>
38391 +#include <asm/local.h>
38392
38393 #define UIO_MAX_DEVICES (1U << MINORBITS)
38394
38395 @@ -32,10 +33,10 @@ struct uio_device {
38396 struct module *owner;
38397 struct device *dev;
38398 int minor;
38399 - atomic_t event;
38400 + atomic_unchecked_t event;
38401 struct fasync_struct *async_queue;
38402 wait_queue_head_t wait;
38403 - int vma_count;
38404 + local_t vma_count;
38405 struct uio_info *info;
38406 struct kobject *map_dir;
38407 struct kobject *portio_dir;
38408 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
38409 struct device_attribute *attr, char *buf)
38410 {
38411 struct uio_device *idev = dev_get_drvdata(dev);
38412 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
38413 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
38414 }
38415
38416 static struct device_attribute uio_class_attributes[] = {
38417 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
38418 {
38419 struct uio_device *idev = info->uio_dev;
38420
38421 - atomic_inc(&idev->event);
38422 + atomic_inc_unchecked(&idev->event);
38423 wake_up_interruptible(&idev->wait);
38424 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
38425 }
38426 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
38427 }
38428
38429 listener->dev = idev;
38430 - listener->event_count = atomic_read(&idev->event);
38431 + listener->event_count = atomic_read_unchecked(&idev->event);
38432 filep->private_data = listener;
38433
38434 if (idev->info->open) {
38435 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
38436 return -EIO;
38437
38438 poll_wait(filep, &idev->wait, wait);
38439 - if (listener->event_count != atomic_read(&idev->event))
38440 + if (listener->event_count != atomic_read_unchecked(&idev->event))
38441 return POLLIN | POLLRDNORM;
38442 return 0;
38443 }
38444 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
38445 do {
38446 set_current_state(TASK_INTERRUPTIBLE);
38447
38448 - event_count = atomic_read(&idev->event);
38449 + event_count = atomic_read_unchecked(&idev->event);
38450 if (event_count != listener->event_count) {
38451 if (copy_to_user(buf, &event_count, count))
38452 retval = -EFAULT;
38453 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
38454 static void uio_vma_open(struct vm_area_struct *vma)
38455 {
38456 struct uio_device *idev = vma->vm_private_data;
38457 - idev->vma_count++;
38458 + local_inc(&idev->vma_count);
38459 }
38460
38461 static void uio_vma_close(struct vm_area_struct *vma)
38462 {
38463 struct uio_device *idev = vma->vm_private_data;
38464 - idev->vma_count--;
38465 + local_dec(&idev->vma_count);
38466 }
38467
38468 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38469 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
38470 idev->owner = owner;
38471 idev->info = info;
38472 init_waitqueue_head(&idev->wait);
38473 - atomic_set(&idev->event, 0);
38474 + atomic_set_unchecked(&idev->event, 0);
38475
38476 ret = uio_get_minor(idev);
38477 if (ret)
38478 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
38479 index 98b89fe..aff824e 100644
38480 --- a/drivers/usb/atm/cxacru.c
38481 +++ b/drivers/usb/atm/cxacru.c
38482 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
38483 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
38484 if (ret < 2)
38485 return -EINVAL;
38486 - if (index < 0 || index > 0x7f)
38487 + if (index > 0x7f)
38488 return -EINVAL;
38489 pos += tmp;
38490
38491 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
38492 index d3448ca..d2864ca 100644
38493 --- a/drivers/usb/atm/usbatm.c
38494 +++ b/drivers/usb/atm/usbatm.c
38495 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38496 if (printk_ratelimit())
38497 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
38498 __func__, vpi, vci);
38499 - atomic_inc(&vcc->stats->rx_err);
38500 + atomic_inc_unchecked(&vcc->stats->rx_err);
38501 return;
38502 }
38503
38504 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38505 if (length > ATM_MAX_AAL5_PDU) {
38506 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
38507 __func__, length, vcc);
38508 - atomic_inc(&vcc->stats->rx_err);
38509 + atomic_inc_unchecked(&vcc->stats->rx_err);
38510 goto out;
38511 }
38512
38513 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38514 if (sarb->len < pdu_length) {
38515 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
38516 __func__, pdu_length, sarb->len, vcc);
38517 - atomic_inc(&vcc->stats->rx_err);
38518 + atomic_inc_unchecked(&vcc->stats->rx_err);
38519 goto out;
38520 }
38521
38522 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
38523 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
38524 __func__, vcc);
38525 - atomic_inc(&vcc->stats->rx_err);
38526 + atomic_inc_unchecked(&vcc->stats->rx_err);
38527 goto out;
38528 }
38529
38530 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38531 if (printk_ratelimit())
38532 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
38533 __func__, length);
38534 - atomic_inc(&vcc->stats->rx_drop);
38535 + atomic_inc_unchecked(&vcc->stats->rx_drop);
38536 goto out;
38537 }
38538
38539 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
38540
38541 vcc->push(vcc, skb);
38542
38543 - atomic_inc(&vcc->stats->rx);
38544 + atomic_inc_unchecked(&vcc->stats->rx);
38545 out:
38546 skb_trim(sarb, 0);
38547 }
38548 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
38549 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
38550
38551 usbatm_pop(vcc, skb);
38552 - atomic_inc(&vcc->stats->tx);
38553 + atomic_inc_unchecked(&vcc->stats->tx);
38554
38555 skb = skb_dequeue(&instance->sndqueue);
38556 }
38557 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
38558 if (!left--)
38559 return sprintf(page,
38560 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
38561 - atomic_read(&atm_dev->stats.aal5.tx),
38562 - atomic_read(&atm_dev->stats.aal5.tx_err),
38563 - atomic_read(&atm_dev->stats.aal5.rx),
38564 - atomic_read(&atm_dev->stats.aal5.rx_err),
38565 - atomic_read(&atm_dev->stats.aal5.rx_drop));
38566 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
38567 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
38568 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
38569 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
38570 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
38571
38572 if (!left--) {
38573 if (instance->disconnected)
38574 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
38575 index d956965..4179a77 100644
38576 --- a/drivers/usb/core/devices.c
38577 +++ b/drivers/usb/core/devices.c
38578 @@ -126,7 +126,7 @@ static const char format_endpt[] =
38579 * time it gets called.
38580 */
38581 static struct device_connect_event {
38582 - atomic_t count;
38583 + atomic_unchecked_t count;
38584 wait_queue_head_t wait;
38585 } device_event = {
38586 .count = ATOMIC_INIT(1),
38587 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
38588
38589 void usbfs_conn_disc_event(void)
38590 {
38591 - atomic_add(2, &device_event.count);
38592 + atomic_add_unchecked(2, &device_event.count);
38593 wake_up(&device_event.wait);
38594 }
38595
38596 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
38597
38598 poll_wait(file, &device_event.wait, wait);
38599
38600 - event_count = atomic_read(&device_event.count);
38601 + event_count = atomic_read_unchecked(&device_event.count);
38602 if (file->f_version != event_count) {
38603 file->f_version = event_count;
38604 return POLLIN | POLLRDNORM;
38605 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
38606 index 1fc8f12..20647c1 100644
38607 --- a/drivers/usb/early/ehci-dbgp.c
38608 +++ b/drivers/usb/early/ehci-dbgp.c
38609 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
38610
38611 #ifdef CONFIG_KGDB
38612 static struct kgdb_io kgdbdbgp_io_ops;
38613 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
38614 +static struct kgdb_io kgdbdbgp_io_ops_console;
38615 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
38616 #else
38617 #define dbgp_kgdb_mode (0)
38618 #endif
38619 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
38620 .write_char = kgdbdbgp_write_char,
38621 };
38622
38623 +static struct kgdb_io kgdbdbgp_io_ops_console = {
38624 + .name = "kgdbdbgp",
38625 + .read_char = kgdbdbgp_read_char,
38626 + .write_char = kgdbdbgp_write_char,
38627 + .is_console = 1
38628 +};
38629 +
38630 static int kgdbdbgp_wait_time;
38631
38632 static int __init kgdbdbgp_parse_config(char *str)
38633 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
38634 ptr++;
38635 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
38636 }
38637 - kgdb_register_io_module(&kgdbdbgp_io_ops);
38638 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
38639 + if (early_dbgp_console.index != -1)
38640 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
38641 + else
38642 + kgdb_register_io_module(&kgdbdbgp_io_ops);
38643
38644 return 0;
38645 }
38646 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
38647 index d6bea3e..60b250e 100644
38648 --- a/drivers/usb/wusbcore/wa-hc.h
38649 +++ b/drivers/usb/wusbcore/wa-hc.h
38650 @@ -192,7 +192,7 @@ struct wahc {
38651 struct list_head xfer_delayed_list;
38652 spinlock_t xfer_list_lock;
38653 struct work_struct xfer_work;
38654 - atomic_t xfer_id_count;
38655 + atomic_unchecked_t xfer_id_count;
38656 };
38657
38658
38659 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
38660 INIT_LIST_HEAD(&wa->xfer_delayed_list);
38661 spin_lock_init(&wa->xfer_list_lock);
38662 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
38663 - atomic_set(&wa->xfer_id_count, 1);
38664 + atomic_set_unchecked(&wa->xfer_id_count, 1);
38665 }
38666
38667 /**
38668 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
38669 index 57c01ab..8a05959 100644
38670 --- a/drivers/usb/wusbcore/wa-xfer.c
38671 +++ b/drivers/usb/wusbcore/wa-xfer.c
38672 @@ -296,7 +296,7 @@ out:
38673 */
38674 static void wa_xfer_id_init(struct wa_xfer *xfer)
38675 {
38676 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
38677 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
38678 }
38679
38680 /*
38681 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
38682 index c14c42b..f955cc2 100644
38683 --- a/drivers/vhost/vhost.c
38684 +++ b/drivers/vhost/vhost.c
38685 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
38686 return 0;
38687 }
38688
38689 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
38690 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
38691 {
38692 struct file *eventfp, *filep = NULL,
38693 *pollstart = NULL, *pollstop = NULL;
38694 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
38695 index b0b2ac3..89a4399 100644
38696 --- a/drivers/video/aty/aty128fb.c
38697 +++ b/drivers/video/aty/aty128fb.c
38698 @@ -148,7 +148,7 @@ enum {
38699 };
38700
38701 /* Must match above enum */
38702 -static const char *r128_family[] __devinitdata = {
38703 +static const char *r128_family[] __devinitconst = {
38704 "AGP",
38705 "PCI",
38706 "PRO AGP",
38707 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
38708 index 5c3960d..15cf8fc 100644
38709 --- a/drivers/video/fbcmap.c
38710 +++ b/drivers/video/fbcmap.c
38711 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
38712 rc = -ENODEV;
38713 goto out;
38714 }
38715 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
38716 - !info->fbops->fb_setcmap)) {
38717 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
38718 rc = -EINVAL;
38719 goto out1;
38720 }
38721 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
38722 index c6ce416..3b9b642 100644
38723 --- a/drivers/video/fbmem.c
38724 +++ b/drivers/video/fbmem.c
38725 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38726 image->dx += image->width + 8;
38727 }
38728 } else if (rotate == FB_ROTATE_UD) {
38729 - for (x = 0; x < num && image->dx >= 0; x++) {
38730 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
38731 info->fbops->fb_imageblit(info, image);
38732 image->dx -= image->width + 8;
38733 }
38734 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
38735 image->dy += image->height + 8;
38736 }
38737 } else if (rotate == FB_ROTATE_CCW) {
38738 - for (x = 0; x < num && image->dy >= 0; x++) {
38739 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
38740 info->fbops->fb_imageblit(info, image);
38741 image->dy -= image->height + 8;
38742 }
38743 @@ -1157,7 +1157,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
38744 return -EFAULT;
38745 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
38746 return -EINVAL;
38747 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
38748 + if (con2fb.framebuffer >= FB_MAX)
38749 return -EINVAL;
38750 if (!registered_fb[con2fb.framebuffer])
38751 request_module("fb%d", con2fb.framebuffer);
38752 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
38753 index 5a5d092..265c5ed 100644
38754 --- a/drivers/video/geode/gx1fb_core.c
38755 +++ b/drivers/video/geode/gx1fb_core.c
38756 @@ -29,7 +29,7 @@ static int crt_option = 1;
38757 static char panel_option[32] = "";
38758
38759 /* Modes relevant to the GX1 (taken from modedb.c) */
38760 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
38761 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
38762 /* 640x480-60 VESA */
38763 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
38764 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
38765 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
38766 index 0fad23f..0e9afa4 100644
38767 --- a/drivers/video/gxt4500.c
38768 +++ b/drivers/video/gxt4500.c
38769 @@ -156,7 +156,7 @@ struct gxt4500_par {
38770 static char *mode_option;
38771
38772 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
38773 -static const struct fb_videomode defaultmode __devinitdata = {
38774 +static const struct fb_videomode defaultmode __devinitconst = {
38775 .refresh = 60,
38776 .xres = 1280,
38777 .yres = 1024,
38778 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
38779 return 0;
38780 }
38781
38782 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
38783 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
38784 .id = "IBM GXT4500P",
38785 .type = FB_TYPE_PACKED_PIXELS,
38786 .visual = FB_VISUAL_PSEUDOCOLOR,
38787 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
38788 index 7672d2e..b56437f 100644
38789 --- a/drivers/video/i810/i810_accel.c
38790 +++ b/drivers/video/i810/i810_accel.c
38791 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
38792 }
38793 }
38794 printk("ringbuffer lockup!!!\n");
38795 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
38796 i810_report_error(mmio);
38797 par->dev_flags |= LOCKUP;
38798 info->pixmap.scan_align = 1;
38799 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
38800 index b83f361..2b05a91 100644
38801 --- a/drivers/video/i810/i810_main.c
38802 +++ b/drivers/video/i810/i810_main.c
38803 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
38804 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
38805
38806 /* PCI */
38807 -static const char *i810_pci_list[] __devinitdata = {
38808 +static const char *i810_pci_list[] __devinitconst = {
38809 "Intel(R) 810 Framebuffer Device" ,
38810 "Intel(R) 810-DC100 Framebuffer Device" ,
38811 "Intel(R) 810E Framebuffer Device" ,
38812 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
38813 index de36693..3c63fc2 100644
38814 --- a/drivers/video/jz4740_fb.c
38815 +++ b/drivers/video/jz4740_fb.c
38816 @@ -136,7 +136,7 @@ struct jzfb {
38817 uint32_t pseudo_palette[16];
38818 };
38819
38820 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
38821 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
38822 .id = "JZ4740 FB",
38823 .type = FB_TYPE_PACKED_PIXELS,
38824 .visual = FB_VISUAL_TRUECOLOR,
38825 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
38826 index 3c14e43..eafa544 100644
38827 --- a/drivers/video/logo/logo_linux_clut224.ppm
38828 +++ b/drivers/video/logo/logo_linux_clut224.ppm
38829 @@ -1,1604 +1,1123 @@
38830 P3
38831 -# Standard 224-color Linux logo
38832 80 80
38833 255
38834 - 0 0 0 0 0 0 0 0 0 0 0 0
38835 - 0 0 0 0 0 0 0 0 0 0 0 0
38836 - 0 0 0 0 0 0 0 0 0 0 0 0
38837 - 0 0 0 0 0 0 0 0 0 0 0 0
38838 - 0 0 0 0 0 0 0 0 0 0 0 0
38839 - 0 0 0 0 0 0 0 0 0 0 0 0
38840 - 0 0 0 0 0 0 0 0 0 0 0 0
38841 - 0 0 0 0 0 0 0 0 0 0 0 0
38842 - 0 0 0 0 0 0 0 0 0 0 0 0
38843 - 6 6 6 6 6 6 10 10 10 10 10 10
38844 - 10 10 10 6 6 6 6 6 6 6 6 6
38845 - 0 0 0 0 0 0 0 0 0 0 0 0
38846 - 0 0 0 0 0 0 0 0 0 0 0 0
38847 - 0 0 0 0 0 0 0 0 0 0 0 0
38848 - 0 0 0 0 0 0 0 0 0 0 0 0
38849 - 0 0 0 0 0 0 0 0 0 0 0 0
38850 - 0 0 0 0 0 0 0 0 0 0 0 0
38851 - 0 0 0 0 0 0 0 0 0 0 0 0
38852 - 0 0 0 0 0 0 0 0 0 0 0 0
38853 - 0 0 0 0 0 0 0 0 0 0 0 0
38854 - 0 0 0 0 0 0 0 0 0 0 0 0
38855 - 0 0 0 0 0 0 0 0 0 0 0 0
38856 - 0 0 0 0 0 0 0 0 0 0 0 0
38857 - 0 0 0 0 0 0 0 0 0 0 0 0
38858 - 0 0 0 0 0 0 0 0 0 0 0 0
38859 - 0 0 0 0 0 0 0 0 0 0 0 0
38860 - 0 0 0 0 0 0 0 0 0 0 0 0
38861 - 0 0 0 0 0 0 0 0 0 0 0 0
38862 - 0 0 0 6 6 6 10 10 10 14 14 14
38863 - 22 22 22 26 26 26 30 30 30 34 34 34
38864 - 30 30 30 30 30 30 26 26 26 18 18 18
38865 - 14 14 14 10 10 10 6 6 6 0 0 0
38866 - 0 0 0 0 0 0 0 0 0 0 0 0
38867 - 0 0 0 0 0 0 0 0 0 0 0 0
38868 - 0 0 0 0 0 0 0 0 0 0 0 0
38869 - 0 0 0 0 0 0 0 0 0 0 0 0
38870 - 0 0 0 0 0 0 0 0 0 0 0 0
38871 - 0 0 0 0 0 0 0 0 0 0 0 0
38872 - 0 0 0 0 0 0 0 0 0 0 0 0
38873 - 0 0 0 0 0 0 0 0 0 0 0 0
38874 - 0 0 0 0 0 0 0 0 0 0 0 0
38875 - 0 0 0 0 0 1 0 0 1 0 0 0
38876 - 0 0 0 0 0 0 0 0 0 0 0 0
38877 - 0 0 0 0 0 0 0 0 0 0 0 0
38878 - 0 0 0 0 0 0 0 0 0 0 0 0
38879 - 0 0 0 0 0 0 0 0 0 0 0 0
38880 - 0 0 0 0 0 0 0 0 0 0 0 0
38881 - 0 0 0 0 0 0 0 0 0 0 0 0
38882 - 6 6 6 14 14 14 26 26 26 42 42 42
38883 - 54 54 54 66 66 66 78 78 78 78 78 78
38884 - 78 78 78 74 74 74 66 66 66 54 54 54
38885 - 42 42 42 26 26 26 18 18 18 10 10 10
38886 - 6 6 6 0 0 0 0 0 0 0 0 0
38887 - 0 0 0 0 0 0 0 0 0 0 0 0
38888 - 0 0 0 0 0 0 0 0 0 0 0 0
38889 - 0 0 0 0 0 0 0 0 0 0 0 0
38890 - 0 0 0 0 0 0 0 0 0 0 0 0
38891 - 0 0 0 0 0 0 0 0 0 0 0 0
38892 - 0 0 0 0 0 0 0 0 0 0 0 0
38893 - 0 0 0 0 0 0 0 0 0 0 0 0
38894 - 0 0 0 0 0 0 0 0 0 0 0 0
38895 - 0 0 1 0 0 0 0 0 0 0 0 0
38896 - 0 0 0 0 0 0 0 0 0 0 0 0
38897 - 0 0 0 0 0 0 0 0 0 0 0 0
38898 - 0 0 0 0 0 0 0 0 0 0 0 0
38899 - 0 0 0 0 0 0 0 0 0 0 0 0
38900 - 0 0 0 0 0 0 0 0 0 0 0 0
38901 - 0 0 0 0 0 0 0 0 0 10 10 10
38902 - 22 22 22 42 42 42 66 66 66 86 86 86
38903 - 66 66 66 38 38 38 38 38 38 22 22 22
38904 - 26 26 26 34 34 34 54 54 54 66 66 66
38905 - 86 86 86 70 70 70 46 46 46 26 26 26
38906 - 14 14 14 6 6 6 0 0 0 0 0 0
38907 - 0 0 0 0 0 0 0 0 0 0 0 0
38908 - 0 0 0 0 0 0 0 0 0 0 0 0
38909 - 0 0 0 0 0 0 0 0 0 0 0 0
38910 - 0 0 0 0 0 0 0 0 0 0 0 0
38911 - 0 0 0 0 0 0 0 0 0 0 0 0
38912 - 0 0 0 0 0 0 0 0 0 0 0 0
38913 - 0 0 0 0 0 0 0 0 0 0 0 0
38914 - 0 0 0 0 0 0 0 0 0 0 0 0
38915 - 0 0 1 0 0 1 0 0 1 0 0 0
38916 - 0 0 0 0 0 0 0 0 0 0 0 0
38917 - 0 0 0 0 0 0 0 0 0 0 0 0
38918 - 0 0 0 0 0 0 0 0 0 0 0 0
38919 - 0 0 0 0 0 0 0 0 0 0 0 0
38920 - 0 0 0 0 0 0 0 0 0 0 0 0
38921 - 0 0 0 0 0 0 10 10 10 26 26 26
38922 - 50 50 50 82 82 82 58 58 58 6 6 6
38923 - 2 2 6 2 2 6 2 2 6 2 2 6
38924 - 2 2 6 2 2 6 2 2 6 2 2 6
38925 - 6 6 6 54 54 54 86 86 86 66 66 66
38926 - 38 38 38 18 18 18 6 6 6 0 0 0
38927 - 0 0 0 0 0 0 0 0 0 0 0 0
38928 - 0 0 0 0 0 0 0 0 0 0 0 0
38929 - 0 0 0 0 0 0 0 0 0 0 0 0
38930 - 0 0 0 0 0 0 0 0 0 0 0 0
38931 - 0 0 0 0 0 0 0 0 0 0 0 0
38932 - 0 0 0 0 0 0 0 0 0 0 0 0
38933 - 0 0 0 0 0 0 0 0 0 0 0 0
38934 - 0 0 0 0 0 0 0 0 0 0 0 0
38935 - 0 0 0 0 0 0 0 0 0 0 0 0
38936 - 0 0 0 0 0 0 0 0 0 0 0 0
38937 - 0 0 0 0 0 0 0 0 0 0 0 0
38938 - 0 0 0 0 0 0 0 0 0 0 0 0
38939 - 0 0 0 0 0 0 0 0 0 0 0 0
38940 - 0 0 0 0 0 0 0 0 0 0 0 0
38941 - 0 0 0 6 6 6 22 22 22 50 50 50
38942 - 78 78 78 34 34 34 2 2 6 2 2 6
38943 - 2 2 6 2 2 6 2 2 6 2 2 6
38944 - 2 2 6 2 2 6 2 2 6 2 2 6
38945 - 2 2 6 2 2 6 6 6 6 70 70 70
38946 - 78 78 78 46 46 46 22 22 22 6 6 6
38947 - 0 0 0 0 0 0 0 0 0 0 0 0
38948 - 0 0 0 0 0 0 0 0 0 0 0 0
38949 - 0 0 0 0 0 0 0 0 0 0 0 0
38950 - 0 0 0 0 0 0 0 0 0 0 0 0
38951 - 0 0 0 0 0 0 0 0 0 0 0 0
38952 - 0 0 0 0 0 0 0 0 0 0 0 0
38953 - 0 0 0 0 0 0 0 0 0 0 0 0
38954 - 0 0 0 0 0 0 0 0 0 0 0 0
38955 - 0 0 1 0 0 1 0 0 1 0 0 0
38956 - 0 0 0 0 0 0 0 0 0 0 0 0
38957 - 0 0 0 0 0 0 0 0 0 0 0 0
38958 - 0 0 0 0 0 0 0 0 0 0 0 0
38959 - 0 0 0 0 0 0 0 0 0 0 0 0
38960 - 0 0 0 0 0 0 0 0 0 0 0 0
38961 - 6 6 6 18 18 18 42 42 42 82 82 82
38962 - 26 26 26 2 2 6 2 2 6 2 2 6
38963 - 2 2 6 2 2 6 2 2 6 2 2 6
38964 - 2 2 6 2 2 6 2 2 6 14 14 14
38965 - 46 46 46 34 34 34 6 6 6 2 2 6
38966 - 42 42 42 78 78 78 42 42 42 18 18 18
38967 - 6 6 6 0 0 0 0 0 0 0 0 0
38968 - 0 0 0 0 0 0 0 0 0 0 0 0
38969 - 0 0 0 0 0 0 0 0 0 0 0 0
38970 - 0 0 0 0 0 0 0 0 0 0 0 0
38971 - 0 0 0 0 0 0 0 0 0 0 0 0
38972 - 0 0 0 0 0 0 0 0 0 0 0 0
38973 - 0 0 0 0 0 0 0 0 0 0 0 0
38974 - 0 0 0 0 0 0 0 0 0 0 0 0
38975 - 0 0 1 0 0 0 0 0 1 0 0 0
38976 - 0 0 0 0 0 0 0 0 0 0 0 0
38977 - 0 0 0 0 0 0 0 0 0 0 0 0
38978 - 0 0 0 0 0 0 0 0 0 0 0 0
38979 - 0 0 0 0 0 0 0 0 0 0 0 0
38980 - 0 0 0 0 0 0 0 0 0 0 0 0
38981 - 10 10 10 30 30 30 66 66 66 58 58 58
38982 - 2 2 6 2 2 6 2 2 6 2 2 6
38983 - 2 2 6 2 2 6 2 2 6 2 2 6
38984 - 2 2 6 2 2 6 2 2 6 26 26 26
38985 - 86 86 86 101 101 101 46 46 46 10 10 10
38986 - 2 2 6 58 58 58 70 70 70 34 34 34
38987 - 10 10 10 0 0 0 0 0 0 0 0 0
38988 - 0 0 0 0 0 0 0 0 0 0 0 0
38989 - 0 0 0 0 0 0 0 0 0 0 0 0
38990 - 0 0 0 0 0 0 0 0 0 0 0 0
38991 - 0 0 0 0 0 0 0 0 0 0 0 0
38992 - 0 0 0 0 0 0 0 0 0 0 0 0
38993 - 0 0 0 0 0 0 0 0 0 0 0 0
38994 - 0 0 0 0 0 0 0 0 0 0 0 0
38995 - 0 0 1 0 0 1 0 0 1 0 0 0
38996 - 0 0 0 0 0 0 0 0 0 0 0 0
38997 - 0 0 0 0 0 0 0 0 0 0 0 0
38998 - 0 0 0 0 0 0 0 0 0 0 0 0
38999 - 0 0 0 0 0 0 0 0 0 0 0 0
39000 - 0 0 0 0 0 0 0 0 0 0 0 0
39001 - 14 14 14 42 42 42 86 86 86 10 10 10
39002 - 2 2 6 2 2 6 2 2 6 2 2 6
39003 - 2 2 6 2 2 6 2 2 6 2 2 6
39004 - 2 2 6 2 2 6 2 2 6 30 30 30
39005 - 94 94 94 94 94 94 58 58 58 26 26 26
39006 - 2 2 6 6 6 6 78 78 78 54 54 54
39007 - 22 22 22 6 6 6 0 0 0 0 0 0
39008 - 0 0 0 0 0 0 0 0 0 0 0 0
39009 - 0 0 0 0 0 0 0 0 0 0 0 0
39010 - 0 0 0 0 0 0 0 0 0 0 0 0
39011 - 0 0 0 0 0 0 0 0 0 0 0 0
39012 - 0 0 0 0 0 0 0 0 0 0 0 0
39013 - 0 0 0 0 0 0 0 0 0 0 0 0
39014 - 0 0 0 0 0 0 0 0 0 0 0 0
39015 - 0 0 0 0 0 0 0 0 0 0 0 0
39016 - 0 0 0 0 0 0 0 0 0 0 0 0
39017 - 0 0 0 0 0 0 0 0 0 0 0 0
39018 - 0 0 0 0 0 0 0 0 0 0 0 0
39019 - 0 0 0 0 0 0 0 0 0 0 0 0
39020 - 0 0 0 0 0 0 0 0 0 6 6 6
39021 - 22 22 22 62 62 62 62 62 62 2 2 6
39022 - 2 2 6 2 2 6 2 2 6 2 2 6
39023 - 2 2 6 2 2 6 2 2 6 2 2 6
39024 - 2 2 6 2 2 6 2 2 6 26 26 26
39025 - 54 54 54 38 38 38 18 18 18 10 10 10
39026 - 2 2 6 2 2 6 34 34 34 82 82 82
39027 - 38 38 38 14 14 14 0 0 0 0 0 0
39028 - 0 0 0 0 0 0 0 0 0 0 0 0
39029 - 0 0 0 0 0 0 0 0 0 0 0 0
39030 - 0 0 0 0 0 0 0 0 0 0 0 0
39031 - 0 0 0 0 0 0 0 0 0 0 0 0
39032 - 0 0 0 0 0 0 0 0 0 0 0 0
39033 - 0 0 0 0 0 0 0 0 0 0 0 0
39034 - 0 0 0 0 0 0 0 0 0 0 0 0
39035 - 0 0 0 0 0 1 0 0 1 0 0 0
39036 - 0 0 0 0 0 0 0 0 0 0 0 0
39037 - 0 0 0 0 0 0 0 0 0 0 0 0
39038 - 0 0 0 0 0 0 0 0 0 0 0 0
39039 - 0 0 0 0 0 0 0 0 0 0 0 0
39040 - 0 0 0 0 0 0 0 0 0 6 6 6
39041 - 30 30 30 78 78 78 30 30 30 2 2 6
39042 - 2 2 6 2 2 6 2 2 6 2 2 6
39043 - 2 2 6 2 2 6 2 2 6 2 2 6
39044 - 2 2 6 2 2 6 2 2 6 10 10 10
39045 - 10 10 10 2 2 6 2 2 6 2 2 6
39046 - 2 2 6 2 2 6 2 2 6 78 78 78
39047 - 50 50 50 18 18 18 6 6 6 0 0 0
39048 - 0 0 0 0 0 0 0 0 0 0 0 0
39049 - 0 0 0 0 0 0 0 0 0 0 0 0
39050 - 0 0 0 0 0 0 0 0 0 0 0 0
39051 - 0 0 0 0 0 0 0 0 0 0 0 0
39052 - 0 0 0 0 0 0 0 0 0 0 0 0
39053 - 0 0 0 0 0 0 0 0 0 0 0 0
39054 - 0 0 0 0 0 0 0 0 0 0 0 0
39055 - 0 0 1 0 0 0 0 0 0 0 0 0
39056 - 0 0 0 0 0 0 0 0 0 0 0 0
39057 - 0 0 0 0 0 0 0 0 0 0 0 0
39058 - 0 0 0 0 0 0 0 0 0 0 0 0
39059 - 0 0 0 0 0 0 0 0 0 0 0 0
39060 - 0 0 0 0 0 0 0 0 0 10 10 10
39061 - 38 38 38 86 86 86 14 14 14 2 2 6
39062 - 2 2 6 2 2 6 2 2 6 2 2 6
39063 - 2 2 6 2 2 6 2 2 6 2 2 6
39064 - 2 2 6 2 2 6 2 2 6 2 2 6
39065 - 2 2 6 2 2 6 2 2 6 2 2 6
39066 - 2 2 6 2 2 6 2 2 6 54 54 54
39067 - 66 66 66 26 26 26 6 6 6 0 0 0
39068 - 0 0 0 0 0 0 0 0 0 0 0 0
39069 - 0 0 0 0 0 0 0 0 0 0 0 0
39070 - 0 0 0 0 0 0 0 0 0 0 0 0
39071 - 0 0 0 0 0 0 0 0 0 0 0 0
39072 - 0 0 0 0 0 0 0 0 0 0 0 0
39073 - 0 0 0 0 0 0 0 0 0 0 0 0
39074 - 0 0 0 0 0 0 0 0 0 0 0 0
39075 - 0 0 0 0 0 1 0 0 1 0 0 0
39076 - 0 0 0 0 0 0 0 0 0 0 0 0
39077 - 0 0 0 0 0 0 0 0 0 0 0 0
39078 - 0 0 0 0 0 0 0 0 0 0 0 0
39079 - 0 0 0 0 0 0 0 0 0 0 0 0
39080 - 0 0 0 0 0 0 0 0 0 14 14 14
39081 - 42 42 42 82 82 82 2 2 6 2 2 6
39082 - 2 2 6 6 6 6 10 10 10 2 2 6
39083 - 2 2 6 2 2 6 2 2 6 2 2 6
39084 - 2 2 6 2 2 6 2 2 6 6 6 6
39085 - 14 14 14 10 10 10 2 2 6 2 2 6
39086 - 2 2 6 2 2 6 2 2 6 18 18 18
39087 - 82 82 82 34 34 34 10 10 10 0 0 0
39088 - 0 0 0 0 0 0 0 0 0 0 0 0
39089 - 0 0 0 0 0 0 0 0 0 0 0 0
39090 - 0 0 0 0 0 0 0 0 0 0 0 0
39091 - 0 0 0 0 0 0 0 0 0 0 0 0
39092 - 0 0 0 0 0 0 0 0 0 0 0 0
39093 - 0 0 0 0 0 0 0 0 0 0 0 0
39094 - 0 0 0 0 0 0 0 0 0 0 0 0
39095 - 0 0 1 0 0 0 0 0 0 0 0 0
39096 - 0 0 0 0 0 0 0 0 0 0 0 0
39097 - 0 0 0 0 0 0 0 0 0 0 0 0
39098 - 0 0 0 0 0 0 0 0 0 0 0 0
39099 - 0 0 0 0 0 0 0 0 0 0 0 0
39100 - 0 0 0 0 0 0 0 0 0 14 14 14
39101 - 46 46 46 86 86 86 2 2 6 2 2 6
39102 - 6 6 6 6 6 6 22 22 22 34 34 34
39103 - 6 6 6 2 2 6 2 2 6 2 2 6
39104 - 2 2 6 2 2 6 18 18 18 34 34 34
39105 - 10 10 10 50 50 50 22 22 22 2 2 6
39106 - 2 2 6 2 2 6 2 2 6 10 10 10
39107 - 86 86 86 42 42 42 14 14 14 0 0 0
39108 - 0 0 0 0 0 0 0 0 0 0 0 0
39109 - 0 0 0 0 0 0 0 0 0 0 0 0
39110 - 0 0 0 0 0 0 0 0 0 0 0 0
39111 - 0 0 0 0 0 0 0 0 0 0 0 0
39112 - 0 0 0 0 0 0 0 0 0 0 0 0
39113 - 0 0 0 0 0 0 0 0 0 0 0 0
39114 - 0 0 0 0 0 0 0 0 0 0 0 0
39115 - 0 0 1 0 0 1 0 0 1 0 0 0
39116 - 0 0 0 0 0 0 0 0 0 0 0 0
39117 - 0 0 0 0 0 0 0 0 0 0 0 0
39118 - 0 0 0 0 0 0 0 0 0 0 0 0
39119 - 0 0 0 0 0 0 0 0 0 0 0 0
39120 - 0 0 0 0 0 0 0 0 0 14 14 14
39121 - 46 46 46 86 86 86 2 2 6 2 2 6
39122 - 38 38 38 116 116 116 94 94 94 22 22 22
39123 - 22 22 22 2 2 6 2 2 6 2 2 6
39124 - 14 14 14 86 86 86 138 138 138 162 162 162
39125 -154 154 154 38 38 38 26 26 26 6 6 6
39126 - 2 2 6 2 2 6 2 2 6 2 2 6
39127 - 86 86 86 46 46 46 14 14 14 0 0 0
39128 - 0 0 0 0 0 0 0 0 0 0 0 0
39129 - 0 0 0 0 0 0 0 0 0 0 0 0
39130 - 0 0 0 0 0 0 0 0 0 0 0 0
39131 - 0 0 0 0 0 0 0 0 0 0 0 0
39132 - 0 0 0 0 0 0 0 0 0 0 0 0
39133 - 0 0 0 0 0 0 0 0 0 0 0 0
39134 - 0 0 0 0 0 0 0 0 0 0 0 0
39135 - 0 0 0 0 0 0 0 0 0 0 0 0
39136 - 0 0 0 0 0 0 0 0 0 0 0 0
39137 - 0 0 0 0 0 0 0 0 0 0 0 0
39138 - 0 0 0 0 0 0 0 0 0 0 0 0
39139 - 0 0 0 0 0 0 0 0 0 0 0 0
39140 - 0 0 0 0 0 0 0 0 0 14 14 14
39141 - 46 46 46 86 86 86 2 2 6 14 14 14
39142 -134 134 134 198 198 198 195 195 195 116 116 116
39143 - 10 10 10 2 2 6 2 2 6 6 6 6
39144 -101 98 89 187 187 187 210 210 210 218 218 218
39145 -214 214 214 134 134 134 14 14 14 6 6 6
39146 - 2 2 6 2 2 6 2 2 6 2 2 6
39147 - 86 86 86 50 50 50 18 18 18 6 6 6
39148 - 0 0 0 0 0 0 0 0 0 0 0 0
39149 - 0 0 0 0 0 0 0 0 0 0 0 0
39150 - 0 0 0 0 0 0 0 0 0 0 0 0
39151 - 0 0 0 0 0 0 0 0 0 0 0 0
39152 - 0 0 0 0 0 0 0 0 0 0 0 0
39153 - 0 0 0 0 0 0 0 0 0 0 0 0
39154 - 0 0 0 0 0 0 0 0 1 0 0 0
39155 - 0 0 1 0 0 1 0 0 1 0 0 0
39156 - 0 0 0 0 0 0 0 0 0 0 0 0
39157 - 0 0 0 0 0 0 0 0 0 0 0 0
39158 - 0 0 0 0 0 0 0 0 0 0 0 0
39159 - 0 0 0 0 0 0 0 0 0 0 0 0
39160 - 0 0 0 0 0 0 0 0 0 14 14 14
39161 - 46 46 46 86 86 86 2 2 6 54 54 54
39162 -218 218 218 195 195 195 226 226 226 246 246 246
39163 - 58 58 58 2 2 6 2 2 6 30 30 30
39164 -210 210 210 253 253 253 174 174 174 123 123 123
39165 -221 221 221 234 234 234 74 74 74 2 2 6
39166 - 2 2 6 2 2 6 2 2 6 2 2 6
39167 - 70 70 70 58 58 58 22 22 22 6 6 6
39168 - 0 0 0 0 0 0 0 0 0 0 0 0
39169 - 0 0 0 0 0 0 0 0 0 0 0 0
39170 - 0 0 0 0 0 0 0 0 0 0 0 0
39171 - 0 0 0 0 0 0 0 0 0 0 0 0
39172 - 0 0 0 0 0 0 0 0 0 0 0 0
39173 - 0 0 0 0 0 0 0 0 0 0 0 0
39174 - 0 0 0 0 0 0 0 0 0 0 0 0
39175 - 0 0 0 0 0 0 0 0 0 0 0 0
39176 - 0 0 0 0 0 0 0 0 0 0 0 0
39177 - 0 0 0 0 0 0 0 0 0 0 0 0
39178 - 0 0 0 0 0 0 0 0 0 0 0 0
39179 - 0 0 0 0 0 0 0 0 0 0 0 0
39180 - 0 0 0 0 0 0 0 0 0 14 14 14
39181 - 46 46 46 82 82 82 2 2 6 106 106 106
39182 -170 170 170 26 26 26 86 86 86 226 226 226
39183 -123 123 123 10 10 10 14 14 14 46 46 46
39184 -231 231 231 190 190 190 6 6 6 70 70 70
39185 - 90 90 90 238 238 238 158 158 158 2 2 6
39186 - 2 2 6 2 2 6 2 2 6 2 2 6
39187 - 70 70 70 58 58 58 22 22 22 6 6 6
39188 - 0 0 0 0 0 0 0 0 0 0 0 0
39189 - 0 0 0 0 0 0 0 0 0 0 0 0
39190 - 0 0 0 0 0 0 0 0 0 0 0 0
39191 - 0 0 0 0 0 0 0 0 0 0 0 0
39192 - 0 0 0 0 0 0 0 0 0 0 0 0
39193 - 0 0 0 0 0 0 0 0 0 0 0 0
39194 - 0 0 0 0 0 0 0 0 1 0 0 0
39195 - 0 0 1 0 0 1 0 0 1 0 0 0
39196 - 0 0 0 0 0 0 0 0 0 0 0 0
39197 - 0 0 0 0 0 0 0 0 0 0 0 0
39198 - 0 0 0 0 0 0 0 0 0 0 0 0
39199 - 0 0 0 0 0 0 0 0 0 0 0 0
39200 - 0 0 0 0 0 0 0 0 0 14 14 14
39201 - 42 42 42 86 86 86 6 6 6 116 116 116
39202 -106 106 106 6 6 6 70 70 70 149 149 149
39203 -128 128 128 18 18 18 38 38 38 54 54 54
39204 -221 221 221 106 106 106 2 2 6 14 14 14
39205 - 46 46 46 190 190 190 198 198 198 2 2 6
39206 - 2 2 6 2 2 6 2 2 6 2 2 6
39207 - 74 74 74 62 62 62 22 22 22 6 6 6
39208 - 0 0 0 0 0 0 0 0 0 0 0 0
39209 - 0 0 0 0 0 0 0 0 0 0 0 0
39210 - 0 0 0 0 0 0 0 0 0 0 0 0
39211 - 0 0 0 0 0 0 0 0 0 0 0 0
39212 - 0 0 0 0 0 0 0 0 0 0 0 0
39213 - 0 0 0 0 0 0 0 0 0 0 0 0
39214 - 0 0 0 0 0 0 0 0 1 0 0 0
39215 - 0 0 1 0 0 0 0 0 1 0 0 0
39216 - 0 0 0 0 0 0 0 0 0 0 0 0
39217 - 0 0 0 0 0 0 0 0 0 0 0 0
39218 - 0 0 0 0 0 0 0 0 0 0 0 0
39219 - 0 0 0 0 0 0 0 0 0 0 0 0
39220 - 0 0 0 0 0 0 0 0 0 14 14 14
39221 - 42 42 42 94 94 94 14 14 14 101 101 101
39222 -128 128 128 2 2 6 18 18 18 116 116 116
39223 -118 98 46 121 92 8 121 92 8 98 78 10
39224 -162 162 162 106 106 106 2 2 6 2 2 6
39225 - 2 2 6 195 195 195 195 195 195 6 6 6
39226 - 2 2 6 2 2 6 2 2 6 2 2 6
39227 - 74 74 74 62 62 62 22 22 22 6 6 6
39228 - 0 0 0 0 0 0 0 0 0 0 0 0
39229 - 0 0 0 0 0 0 0 0 0 0 0 0
39230 - 0 0 0 0 0 0 0 0 0 0 0 0
39231 - 0 0 0 0 0 0 0 0 0 0 0 0
39232 - 0 0 0 0 0 0 0 0 0 0 0 0
39233 - 0 0 0 0 0 0 0 0 0 0 0 0
39234 - 0 0 0 0 0 0 0 0 1 0 0 1
39235 - 0 0 1 0 0 0 0 0 1 0 0 0
39236 - 0 0 0 0 0 0 0 0 0 0 0 0
39237 - 0 0 0 0 0 0 0 0 0 0 0 0
39238 - 0 0 0 0 0 0 0 0 0 0 0 0
39239 - 0 0 0 0 0 0 0 0 0 0 0 0
39240 - 0 0 0 0 0 0 0 0 0 10 10 10
39241 - 38 38 38 90 90 90 14 14 14 58 58 58
39242 -210 210 210 26 26 26 54 38 6 154 114 10
39243 -226 170 11 236 186 11 225 175 15 184 144 12
39244 -215 174 15 175 146 61 37 26 9 2 2 6
39245 - 70 70 70 246 246 246 138 138 138 2 2 6
39246 - 2 2 6 2 2 6 2 2 6 2 2 6
39247 - 70 70 70 66 66 66 26 26 26 6 6 6
39248 - 0 0 0 0 0 0 0 0 0 0 0 0
39249 - 0 0 0 0 0 0 0 0 0 0 0 0
39250 - 0 0 0 0 0 0 0 0 0 0 0 0
39251 - 0 0 0 0 0 0 0 0 0 0 0 0
39252 - 0 0 0 0 0 0 0 0 0 0 0 0
39253 - 0 0 0 0 0 0 0 0 0 0 0 0
39254 - 0 0 0 0 0 0 0 0 0 0 0 0
39255 - 0 0 0 0 0 0 0 0 0 0 0 0
39256 - 0 0 0 0 0 0 0 0 0 0 0 0
39257 - 0 0 0 0 0 0 0 0 0 0 0 0
39258 - 0 0 0 0 0 0 0 0 0 0 0 0
39259 - 0 0 0 0 0 0 0 0 0 0 0 0
39260 - 0 0 0 0 0 0 0 0 0 10 10 10
39261 - 38 38 38 86 86 86 14 14 14 10 10 10
39262 -195 195 195 188 164 115 192 133 9 225 175 15
39263 -239 182 13 234 190 10 232 195 16 232 200 30
39264 -245 207 45 241 208 19 232 195 16 184 144 12
39265 -218 194 134 211 206 186 42 42 42 2 2 6
39266 - 2 2 6 2 2 6 2 2 6 2 2 6
39267 - 50 50 50 74 74 74 30 30 30 6 6 6
39268 - 0 0 0 0 0 0 0 0 0 0 0 0
39269 - 0 0 0 0 0 0 0 0 0 0 0 0
39270 - 0 0 0 0 0 0 0 0 0 0 0 0
39271 - 0 0 0 0 0 0 0 0 0 0 0 0
39272 - 0 0 0 0 0 0 0 0 0 0 0 0
39273 - 0 0 0 0 0 0 0 0 0 0 0 0
39274 - 0 0 0 0 0 0 0 0 0 0 0 0
39275 - 0 0 0 0 0 0 0 0 0 0 0 0
39276 - 0 0 0 0 0 0 0 0 0 0 0 0
39277 - 0 0 0 0 0 0 0 0 0 0 0 0
39278 - 0 0 0 0 0 0 0 0 0 0 0 0
39279 - 0 0 0 0 0 0 0 0 0 0 0 0
39280 - 0 0 0 0 0 0 0 0 0 10 10 10
39281 - 34 34 34 86 86 86 14 14 14 2 2 6
39282 -121 87 25 192 133 9 219 162 10 239 182 13
39283 -236 186 11 232 195 16 241 208 19 244 214 54
39284 -246 218 60 246 218 38 246 215 20 241 208 19
39285 -241 208 19 226 184 13 121 87 25 2 2 6
39286 - 2 2 6 2 2 6 2 2 6 2 2 6
39287 - 50 50 50 82 82 82 34 34 34 10 10 10
39288 - 0 0 0 0 0 0 0 0 0 0 0 0
39289 - 0 0 0 0 0 0 0 0 0 0 0 0
39290 - 0 0 0 0 0 0 0 0 0 0 0 0
39291 - 0 0 0 0 0 0 0 0 0 0 0 0
39292 - 0 0 0 0 0 0 0 0 0 0 0 0
39293 - 0 0 0 0 0 0 0 0 0 0 0 0
39294 - 0 0 0 0 0 0 0 0 0 0 0 0
39295 - 0 0 0 0 0 0 0 0 0 0 0 0
39296 - 0 0 0 0 0 0 0 0 0 0 0 0
39297 - 0 0 0 0 0 0 0 0 0 0 0 0
39298 - 0 0 0 0 0 0 0 0 0 0 0 0
39299 - 0 0 0 0 0 0 0 0 0 0 0 0
39300 - 0 0 0 0 0 0 0 0 0 10 10 10
39301 - 34 34 34 82 82 82 30 30 30 61 42 6
39302 -180 123 7 206 145 10 230 174 11 239 182 13
39303 -234 190 10 238 202 15 241 208 19 246 218 74
39304 -246 218 38 246 215 20 246 215 20 246 215 20
39305 -226 184 13 215 174 15 184 144 12 6 6 6
39306 - 2 2 6 2 2 6 2 2 6 2 2 6
39307 - 26 26 26 94 94 94 42 42 42 14 14 14
39308 - 0 0 0 0 0 0 0 0 0 0 0 0
39309 - 0 0 0 0 0 0 0 0 0 0 0 0
39310 - 0 0 0 0 0 0 0 0 0 0 0 0
39311 - 0 0 0 0 0 0 0 0 0 0 0 0
39312 - 0 0 0 0 0 0 0 0 0 0 0 0
39313 - 0 0 0 0 0 0 0 0 0 0 0 0
39314 - 0 0 0 0 0 0 0 0 0 0 0 0
39315 - 0 0 0 0 0 0 0 0 0 0 0 0
39316 - 0 0 0 0 0 0 0 0 0 0 0 0
39317 - 0 0 0 0 0 0 0 0 0 0 0 0
39318 - 0 0 0 0 0 0 0 0 0 0 0 0
39319 - 0 0 0 0 0 0 0 0 0 0 0 0
39320 - 0 0 0 0 0 0 0 0 0 10 10 10
39321 - 30 30 30 78 78 78 50 50 50 104 69 6
39322 -192 133 9 216 158 10 236 178 12 236 186 11
39323 -232 195 16 241 208 19 244 214 54 245 215 43
39324 -246 215 20 246 215 20 241 208 19 198 155 10
39325 -200 144 11 216 158 10 156 118 10 2 2 6
39326 - 2 2 6 2 2 6 2 2 6 2 2 6
39327 - 6 6 6 90 90 90 54 54 54 18 18 18
39328 - 6 6 6 0 0 0 0 0 0 0 0 0
39329 - 0 0 0 0 0 0 0 0 0 0 0 0
39330 - 0 0 0 0 0 0 0 0 0 0 0 0
39331 - 0 0 0 0 0 0 0 0 0 0 0 0
39332 - 0 0 0 0 0 0 0 0 0 0 0 0
39333 - 0 0 0 0 0 0 0 0 0 0 0 0
39334 - 0 0 0 0 0 0 0 0 0 0 0 0
39335 - 0 0 0 0 0 0 0 0 0 0 0 0
39336 - 0 0 0 0 0 0 0 0 0 0 0 0
39337 - 0 0 0 0 0 0 0 0 0 0 0 0
39338 - 0 0 0 0 0 0 0 0 0 0 0 0
39339 - 0 0 0 0 0 0 0 0 0 0 0 0
39340 - 0 0 0 0 0 0 0 0 0 10 10 10
39341 - 30 30 30 78 78 78 46 46 46 22 22 22
39342 -137 92 6 210 162 10 239 182 13 238 190 10
39343 -238 202 15 241 208 19 246 215 20 246 215 20
39344 -241 208 19 203 166 17 185 133 11 210 150 10
39345 -216 158 10 210 150 10 102 78 10 2 2 6
39346 - 6 6 6 54 54 54 14 14 14 2 2 6
39347 - 2 2 6 62 62 62 74 74 74 30 30 30
39348 - 10 10 10 0 0 0 0 0 0 0 0 0
39349 - 0 0 0 0 0 0 0 0 0 0 0 0
39350 - 0 0 0 0 0 0 0 0 0 0 0 0
39351 - 0 0 0 0 0 0 0 0 0 0 0 0
39352 - 0 0 0 0 0 0 0 0 0 0 0 0
39353 - 0 0 0 0 0 0 0 0 0 0 0 0
39354 - 0 0 0 0 0 0 0 0 0 0 0 0
39355 - 0 0 0 0 0 0 0 0 0 0 0 0
39356 - 0 0 0 0 0 0 0 0 0 0 0 0
39357 - 0 0 0 0 0 0 0 0 0 0 0 0
39358 - 0 0 0 0 0 0 0 0 0 0 0 0
39359 - 0 0 0 0 0 0 0 0 0 0 0 0
39360 - 0 0 0 0 0 0 0 0 0 10 10 10
39361 - 34 34 34 78 78 78 50 50 50 6 6 6
39362 - 94 70 30 139 102 15 190 146 13 226 184 13
39363 -232 200 30 232 195 16 215 174 15 190 146 13
39364 -168 122 10 192 133 9 210 150 10 213 154 11
39365 -202 150 34 182 157 106 101 98 89 2 2 6
39366 - 2 2 6 78 78 78 116 116 116 58 58 58
39367 - 2 2 6 22 22 22 90 90 90 46 46 46
39368 - 18 18 18 6 6 6 0 0 0 0 0 0
39369 - 0 0 0 0 0 0 0 0 0 0 0 0
39370 - 0 0 0 0 0 0 0 0 0 0 0 0
39371 - 0 0 0 0 0 0 0 0 0 0 0 0
39372 - 0 0 0 0 0 0 0 0 0 0 0 0
39373 - 0 0 0 0 0 0 0 0 0 0 0 0
39374 - 0 0 0 0 0 0 0 0 0 0 0 0
39375 - 0 0 0 0 0 0 0 0 0 0 0 0
39376 - 0 0 0 0 0 0 0 0 0 0 0 0
39377 - 0 0 0 0 0 0 0 0 0 0 0 0
39378 - 0 0 0 0 0 0 0 0 0 0 0 0
39379 - 0 0 0 0 0 0 0 0 0 0 0 0
39380 - 0 0 0 0 0 0 0 0 0 10 10 10
39381 - 38 38 38 86 86 86 50 50 50 6 6 6
39382 -128 128 128 174 154 114 156 107 11 168 122 10
39383 -198 155 10 184 144 12 197 138 11 200 144 11
39384 -206 145 10 206 145 10 197 138 11 188 164 115
39385 -195 195 195 198 198 198 174 174 174 14 14 14
39386 - 2 2 6 22 22 22 116 116 116 116 116 116
39387 - 22 22 22 2 2 6 74 74 74 70 70 70
39388 - 30 30 30 10 10 10 0 0 0 0 0 0
39389 - 0 0 0 0 0 0 0 0 0 0 0 0
39390 - 0 0 0 0 0 0 0 0 0 0 0 0
39391 - 0 0 0 0 0 0 0 0 0 0 0 0
39392 - 0 0 0 0 0 0 0 0 0 0 0 0
39393 - 0 0 0 0 0 0 0 0 0 0 0 0
39394 - 0 0 0 0 0 0 0 0 0 0 0 0
39395 - 0 0 0 0 0 0 0 0 0 0 0 0
39396 - 0 0 0 0 0 0 0 0 0 0 0 0
39397 - 0 0 0 0 0 0 0 0 0 0 0 0
39398 - 0 0 0 0 0 0 0 0 0 0 0 0
39399 - 0 0 0 0 0 0 0 0 0 0 0 0
39400 - 0 0 0 0 0 0 6 6 6 18 18 18
39401 - 50 50 50 101 101 101 26 26 26 10 10 10
39402 -138 138 138 190 190 190 174 154 114 156 107 11
39403 -197 138 11 200 144 11 197 138 11 192 133 9
39404 -180 123 7 190 142 34 190 178 144 187 187 187
39405 -202 202 202 221 221 221 214 214 214 66 66 66
39406 - 2 2 6 2 2 6 50 50 50 62 62 62
39407 - 6 6 6 2 2 6 10 10 10 90 90 90
39408 - 50 50 50 18 18 18 6 6 6 0 0 0
39409 - 0 0 0 0 0 0 0 0 0 0 0 0
39410 - 0 0 0 0 0 0 0 0 0 0 0 0
39411 - 0 0 0 0 0 0 0 0 0 0 0 0
39412 - 0 0 0 0 0 0 0 0 0 0 0 0
39413 - 0 0 0 0 0 0 0 0 0 0 0 0
39414 - 0 0 0 0 0 0 0 0 0 0 0 0
39415 - 0 0 0 0 0 0 0 0 0 0 0 0
39416 - 0 0 0 0 0 0 0 0 0 0 0 0
39417 - 0 0 0 0 0 0 0 0 0 0 0 0
39418 - 0 0 0 0 0 0 0 0 0 0 0 0
39419 - 0 0 0 0 0 0 0 0 0 0 0 0
39420 - 0 0 0 0 0 0 10 10 10 34 34 34
39421 - 74 74 74 74 74 74 2 2 6 6 6 6
39422 -144 144 144 198 198 198 190 190 190 178 166 146
39423 -154 121 60 156 107 11 156 107 11 168 124 44
39424 -174 154 114 187 187 187 190 190 190 210 210 210
39425 -246 246 246 253 253 253 253 253 253 182 182 182
39426 - 6 6 6 2 2 6 2 2 6 2 2 6
39427 - 2 2 6 2 2 6 2 2 6 62 62 62
39428 - 74 74 74 34 34 34 14 14 14 0 0 0
39429 - 0 0 0 0 0 0 0 0 0 0 0 0
39430 - 0 0 0 0 0 0 0 0 0 0 0 0
39431 - 0 0 0 0 0 0 0 0 0 0 0 0
39432 - 0 0 0 0 0 0 0 0 0 0 0 0
39433 - 0 0 0 0 0 0 0 0 0 0 0 0
39434 - 0 0 0 0 0 0 0 0 0 0 0 0
39435 - 0 0 0 0 0 0 0 0 0 0 0 0
39436 - 0 0 0 0 0 0 0 0 0 0 0 0
39437 - 0 0 0 0 0 0 0 0 0 0 0 0
39438 - 0 0 0 0 0 0 0 0 0 0 0 0
39439 - 0 0 0 0 0 0 0 0 0 0 0 0
39440 - 0 0 0 10 10 10 22 22 22 54 54 54
39441 - 94 94 94 18 18 18 2 2 6 46 46 46
39442 -234 234 234 221 221 221 190 190 190 190 190 190
39443 -190 190 190 187 187 187 187 187 187 190 190 190
39444 -190 190 190 195 195 195 214 214 214 242 242 242
39445 -253 253 253 253 253 253 253 253 253 253 253 253
39446 - 82 82 82 2 2 6 2 2 6 2 2 6
39447 - 2 2 6 2 2 6 2 2 6 14 14 14
39448 - 86 86 86 54 54 54 22 22 22 6 6 6
39449 - 0 0 0 0 0 0 0 0 0 0 0 0
39450 - 0 0 0 0 0 0 0 0 0 0 0 0
39451 - 0 0 0 0 0 0 0 0 0 0 0 0
39452 - 0 0 0 0 0 0 0 0 0 0 0 0
39453 - 0 0 0 0 0 0 0 0 0 0 0 0
39454 - 0 0 0 0 0 0 0 0 0 0 0 0
39455 - 0 0 0 0 0 0 0 0 0 0 0 0
39456 - 0 0 0 0 0 0 0 0 0 0 0 0
39457 - 0 0 0 0 0 0 0 0 0 0 0 0
39458 - 0 0 0 0 0 0 0 0 0 0 0 0
39459 - 0 0 0 0 0 0 0 0 0 0 0 0
39460 - 6 6 6 18 18 18 46 46 46 90 90 90
39461 - 46 46 46 18 18 18 6 6 6 182 182 182
39462 -253 253 253 246 246 246 206 206 206 190 190 190
39463 -190 190 190 190 190 190 190 190 190 190 190 190
39464 -206 206 206 231 231 231 250 250 250 253 253 253
39465 -253 253 253 253 253 253 253 253 253 253 253 253
39466 -202 202 202 14 14 14 2 2 6 2 2 6
39467 - 2 2 6 2 2 6 2 2 6 2 2 6
39468 - 42 42 42 86 86 86 42 42 42 18 18 18
39469 - 6 6 6 0 0 0 0 0 0 0 0 0
39470 - 0 0 0 0 0 0 0 0 0 0 0 0
39471 - 0 0 0 0 0 0 0 0 0 0 0 0
39472 - 0 0 0 0 0 0 0 0 0 0 0 0
39473 - 0 0 0 0 0 0 0 0 0 0 0 0
39474 - 0 0 0 0 0 0 0 0 0 0 0 0
39475 - 0 0 0 0 0 0 0 0 0 0 0 0
39476 - 0 0 0 0 0 0 0 0 0 0 0 0
39477 - 0 0 0 0 0 0 0 0 0 0 0 0
39478 - 0 0 0 0 0 0 0 0 0 0 0 0
39479 - 0 0 0 0 0 0 0 0 0 6 6 6
39480 - 14 14 14 38 38 38 74 74 74 66 66 66
39481 - 2 2 6 6 6 6 90 90 90 250 250 250
39482 -253 253 253 253 253 253 238 238 238 198 198 198
39483 -190 190 190 190 190 190 195 195 195 221 221 221
39484 -246 246 246 253 253 253 253 253 253 253 253 253
39485 -253 253 253 253 253 253 253 253 253 253 253 253
39486 -253 253 253 82 82 82 2 2 6 2 2 6
39487 - 2 2 6 2 2 6 2 2 6 2 2 6
39488 - 2 2 6 78 78 78 70 70 70 34 34 34
39489 - 14 14 14 6 6 6 0 0 0 0 0 0
39490 - 0 0 0 0 0 0 0 0 0 0 0 0
39491 - 0 0 0 0 0 0 0 0 0 0 0 0
39492 - 0 0 0 0 0 0 0 0 0 0 0 0
39493 - 0 0 0 0 0 0 0 0 0 0 0 0
39494 - 0 0 0 0 0 0 0 0 0 0 0 0
39495 - 0 0 0 0 0 0 0 0 0 0 0 0
39496 - 0 0 0 0 0 0 0 0 0 0 0 0
39497 - 0 0 0 0 0 0 0 0 0 0 0 0
39498 - 0 0 0 0 0 0 0 0 0 0 0 0
39499 - 0 0 0 0 0 0 0 0 0 14 14 14
39500 - 34 34 34 66 66 66 78 78 78 6 6 6
39501 - 2 2 6 18 18 18 218 218 218 253 253 253
39502 -253 253 253 253 253 253 253 253 253 246 246 246
39503 -226 226 226 231 231 231 246 246 246 253 253 253
39504 -253 253 253 253 253 253 253 253 253 253 253 253
39505 -253 253 253 253 253 253 253 253 253 253 253 253
39506 -253 253 253 178 178 178 2 2 6 2 2 6
39507 - 2 2 6 2 2 6 2 2 6 2 2 6
39508 - 2 2 6 18 18 18 90 90 90 62 62 62
39509 - 30 30 30 10 10 10 0 0 0 0 0 0
39510 - 0 0 0 0 0 0 0 0 0 0 0 0
39511 - 0 0 0 0 0 0 0 0 0 0 0 0
39512 - 0 0 0 0 0 0 0 0 0 0 0 0
39513 - 0 0 0 0 0 0 0 0 0 0 0 0
39514 - 0 0 0 0 0 0 0 0 0 0 0 0
39515 - 0 0 0 0 0 0 0 0 0 0 0 0
39516 - 0 0 0 0 0 0 0 0 0 0 0 0
39517 - 0 0 0 0 0 0 0 0 0 0 0 0
39518 - 0 0 0 0 0 0 0 0 0 0 0 0
39519 - 0 0 0 0 0 0 10 10 10 26 26 26
39520 - 58 58 58 90 90 90 18 18 18 2 2 6
39521 - 2 2 6 110 110 110 253 253 253 253 253 253
39522 -253 253 253 253 253 253 253 253 253 253 253 253
39523 -250 250 250 253 253 253 253 253 253 253 253 253
39524 -253 253 253 253 253 253 253 253 253 253 253 253
39525 -253 253 253 253 253 253 253 253 253 253 253 253
39526 -253 253 253 231 231 231 18 18 18 2 2 6
39527 - 2 2 6 2 2 6 2 2 6 2 2 6
39528 - 2 2 6 2 2 6 18 18 18 94 94 94
39529 - 54 54 54 26 26 26 10 10 10 0 0 0
39530 - 0 0 0 0 0 0 0 0 0 0 0 0
39531 - 0 0 0 0 0 0 0 0 0 0 0 0
39532 - 0 0 0 0 0 0 0 0 0 0 0 0
39533 - 0 0 0 0 0 0 0 0 0 0 0 0
39534 - 0 0 0 0 0 0 0 0 0 0 0 0
39535 - 0 0 0 0 0 0 0 0 0 0 0 0
39536 - 0 0 0 0 0 0 0 0 0 0 0 0
39537 - 0 0 0 0 0 0 0 0 0 0 0 0
39538 - 0 0 0 0 0 0 0 0 0 0 0 0
39539 - 0 0 0 6 6 6 22 22 22 50 50 50
39540 - 90 90 90 26 26 26 2 2 6 2 2 6
39541 - 14 14 14 195 195 195 250 250 250 253 253 253
39542 -253 253 253 253 253 253 253 253 253 253 253 253
39543 -253 253 253 253 253 253 253 253 253 253 253 253
39544 -253 253 253 253 253 253 253 253 253 253 253 253
39545 -253 253 253 253 253 253 253 253 253 253 253 253
39546 -250 250 250 242 242 242 54 54 54 2 2 6
39547 - 2 2 6 2 2 6 2 2 6 2 2 6
39548 - 2 2 6 2 2 6 2 2 6 38 38 38
39549 - 86 86 86 50 50 50 22 22 22 6 6 6
39550 - 0 0 0 0 0 0 0 0 0 0 0 0
39551 - 0 0 0 0 0 0 0 0 0 0 0 0
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 0 0 0
39555 - 0 0 0 0 0 0 0 0 0 0 0 0
39556 - 0 0 0 0 0 0 0 0 0 0 0 0
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 6 6 6 14 14 14 38 38 38 82 82 82
39560 - 34 34 34 2 2 6 2 2 6 2 2 6
39561 - 42 42 42 195 195 195 246 246 246 253 253 253
39562 -253 253 253 253 253 253 253 253 253 250 250 250
39563 -242 242 242 242 242 242 250 250 250 253 253 253
39564 -253 253 253 253 253 253 253 253 253 253 253 253
39565 -253 253 253 250 250 250 246 246 246 238 238 238
39566 -226 226 226 231 231 231 101 101 101 6 6 6
39567 - 2 2 6 2 2 6 2 2 6 2 2 6
39568 - 2 2 6 2 2 6 2 2 6 2 2 6
39569 - 38 38 38 82 82 82 42 42 42 14 14 14
39570 - 6 6 6 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 0 0 0 0 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 0 0 0 0 0 0 0 0 0
39575 - 0 0 0 0 0 0 0 0 0 0 0 0
39576 - 0 0 0 0 0 0 0 0 0 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 10 10 10 26 26 26 62 62 62 66 66 66
39580 - 2 2 6 2 2 6 2 2 6 6 6 6
39581 - 70 70 70 170 170 170 206 206 206 234 234 234
39582 -246 246 246 250 250 250 250 250 250 238 238 238
39583 -226 226 226 231 231 231 238 238 238 250 250 250
39584 -250 250 250 250 250 250 246 246 246 231 231 231
39585 -214 214 214 206 206 206 202 202 202 202 202 202
39586 -198 198 198 202 202 202 182 182 182 18 18 18
39587 - 2 2 6 2 2 6 2 2 6 2 2 6
39588 - 2 2 6 2 2 6 2 2 6 2 2 6
39589 - 2 2 6 62 62 62 66 66 66 30 30 30
39590 - 10 10 10 0 0 0 0 0 0 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 0 0 0 0 0 0 0 0 0
39594 - 0 0 0 0 0 0 0 0 0 0 0 0
39595 - 0 0 0 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 0 0 0 0 0 0 0 0 0
39599 - 14 14 14 42 42 42 82 82 82 18 18 18
39600 - 2 2 6 2 2 6 2 2 6 10 10 10
39601 - 94 94 94 182 182 182 218 218 218 242 242 242
39602 -250 250 250 253 253 253 253 253 253 250 250 250
39603 -234 234 234 253 253 253 253 253 253 253 253 253
39604 -253 253 253 253 253 253 253 253 253 246 246 246
39605 -238 238 238 226 226 226 210 210 210 202 202 202
39606 -195 195 195 195 195 195 210 210 210 158 158 158
39607 - 6 6 6 14 14 14 50 50 50 14 14 14
39608 - 2 2 6 2 2 6 2 2 6 2 2 6
39609 - 2 2 6 6 6 6 86 86 86 46 46 46
39610 - 18 18 18 6 6 6 0 0 0 0 0 0
39611 - 0 0 0 0 0 0 0 0 0 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 0 0 0 0 0 0
39614 - 0 0 0 0 0 0 0 0 0 0 0 0
39615 - 0 0 0 0 0 0 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 0 0 0 6 6 6
39619 - 22 22 22 54 54 54 70 70 70 2 2 6
39620 - 2 2 6 10 10 10 2 2 6 22 22 22
39621 -166 166 166 231 231 231 250 250 250 253 253 253
39622 -253 253 253 253 253 253 253 253 253 250 250 250
39623 -242 242 242 253 253 253 253 253 253 253 253 253
39624 -253 253 253 253 253 253 253 253 253 253 253 253
39625 -253 253 253 253 253 253 253 253 253 246 246 246
39626 -231 231 231 206 206 206 198 198 198 226 226 226
39627 - 94 94 94 2 2 6 6 6 6 38 38 38
39628 - 30 30 30 2 2 6 2 2 6 2 2 6
39629 - 2 2 6 2 2 6 62 62 62 66 66 66
39630 - 26 26 26 10 10 10 0 0 0 0 0 0
39631 - 0 0 0 0 0 0 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 10 10 10
39639 - 30 30 30 74 74 74 50 50 50 2 2 6
39640 - 26 26 26 26 26 26 2 2 6 106 106 106
39641 -238 238 238 253 253 253 253 253 253 253 253 253
39642 -253 253 253 253 253 253 253 253 253 253 253 253
39643 -253 253 253 253 253 253 253 253 253 253 253 253
39644 -253 253 253 253 253 253 253 253 253 253 253 253
39645 -253 253 253 253 253 253 253 253 253 253 253 253
39646 -253 253 253 246 246 246 218 218 218 202 202 202
39647 -210 210 210 14 14 14 2 2 6 2 2 6
39648 - 30 30 30 22 22 22 2 2 6 2 2 6
39649 - 2 2 6 2 2 6 18 18 18 86 86 86
39650 - 42 42 42 14 14 14 0 0 0 0 0 0
39651 - 0 0 0 0 0 0 0 0 0 0 0 0
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 0 0 0 0 0 0 0 0 0
39655 - 0 0 0 0 0 0 0 0 0 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 14 14 14
39659 - 42 42 42 90 90 90 22 22 22 2 2 6
39660 - 42 42 42 2 2 6 18 18 18 218 218 218
39661 -253 253 253 253 253 253 253 253 253 253 253 253
39662 -253 253 253 253 253 253 253 253 253 253 253 253
39663 -253 253 253 253 253 253 253 253 253 253 253 253
39664 -253 253 253 253 253 253 253 253 253 253 253 253
39665 -253 253 253 253 253 253 253 253 253 253 253 253
39666 -253 253 253 253 253 253 250 250 250 221 221 221
39667 -218 218 218 101 101 101 2 2 6 14 14 14
39668 - 18 18 18 38 38 38 10 10 10 2 2 6
39669 - 2 2 6 2 2 6 2 2 6 78 78 78
39670 - 58 58 58 22 22 22 6 6 6 0 0 0
39671 - 0 0 0 0 0 0 0 0 0 0 0 0
39672 - 0 0 0 0 0 0 0 0 0 0 0 0
39673 - 0 0 0 0 0 0 0 0 0 0 0 0
39674 - 0 0 0 0 0 0 0 0 0 0 0 0
39675 - 0 0 0 0 0 0 0 0 0 0 0 0
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 0 0 0 0 0 0 6 6 6 18 18 18
39679 - 54 54 54 82 82 82 2 2 6 26 26 26
39680 - 22 22 22 2 2 6 123 123 123 253 253 253
39681 -253 253 253 253 253 253 253 253 253 253 253 253
39682 -253 253 253 253 253 253 253 253 253 253 253 253
39683 -253 253 253 253 253 253 253 253 253 253 253 253
39684 -253 253 253 253 253 253 253 253 253 253 253 253
39685 -253 253 253 253 253 253 253 253 253 253 253 253
39686 -253 253 253 253 253 253 253 253 253 250 250 250
39687 -238 238 238 198 198 198 6 6 6 38 38 38
39688 - 58 58 58 26 26 26 38 38 38 2 2 6
39689 - 2 2 6 2 2 6 2 2 6 46 46 46
39690 - 78 78 78 30 30 30 10 10 10 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 10 10 10 30 30 30
39699 - 74 74 74 58 58 58 2 2 6 42 42 42
39700 - 2 2 6 22 22 22 231 231 231 253 253 253
39701 -253 253 253 253 253 253 253 253 253 253 253 253
39702 -253 253 253 253 253 253 253 253 253 250 250 250
39703 -253 253 253 253 253 253 253 253 253 253 253 253
39704 -253 253 253 253 253 253 253 253 253 253 253 253
39705 -253 253 253 253 253 253 253 253 253 253 253 253
39706 -253 253 253 253 253 253 253 253 253 253 253 253
39707 -253 253 253 246 246 246 46 46 46 38 38 38
39708 - 42 42 42 14 14 14 38 38 38 14 14 14
39709 - 2 2 6 2 2 6 2 2 6 6 6 6
39710 - 86 86 86 46 46 46 14 14 14 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 6 6 6 14 14 14 42 42 42
39719 - 90 90 90 18 18 18 18 18 18 26 26 26
39720 - 2 2 6 116 116 116 253 253 253 253 253 253
39721 -253 253 253 253 253 253 253 253 253 253 253 253
39722 -253 253 253 253 253 253 250 250 250 238 238 238
39723 -253 253 253 253 253 253 253 253 253 253 253 253
39724 -253 253 253 253 253 253 253 253 253 253 253 253
39725 -253 253 253 253 253 253 253 253 253 253 253 253
39726 -253 253 253 253 253 253 253 253 253 253 253 253
39727 -253 253 253 253 253 253 94 94 94 6 6 6
39728 - 2 2 6 2 2 6 10 10 10 34 34 34
39729 - 2 2 6 2 2 6 2 2 6 2 2 6
39730 - 74 74 74 58 58 58 22 22 22 6 6 6
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 10 10 10 26 26 26 66 66 66
39739 - 82 82 82 2 2 6 38 38 38 6 6 6
39740 - 14 14 14 210 210 210 253 253 253 253 253 253
39741 -253 253 253 253 253 253 253 253 253 253 253 253
39742 -253 253 253 253 253 253 246 246 246 242 242 242
39743 -253 253 253 253 253 253 253 253 253 253 253 253
39744 -253 253 253 253 253 253 253 253 253 253 253 253
39745 -253 253 253 253 253 253 253 253 253 253 253 253
39746 -253 253 253 253 253 253 253 253 253 253 253 253
39747 -253 253 253 253 253 253 144 144 144 2 2 6
39748 - 2 2 6 2 2 6 2 2 6 46 46 46
39749 - 2 2 6 2 2 6 2 2 6 2 2 6
39750 - 42 42 42 74 74 74 30 30 30 10 10 10
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 - 6 6 6 14 14 14 42 42 42 90 90 90
39759 - 26 26 26 6 6 6 42 42 42 2 2 6
39760 - 74 74 74 250 250 250 253 253 253 253 253 253
39761 -253 253 253 253 253 253 253 253 253 253 253 253
39762 -253 253 253 253 253 253 242 242 242 242 242 242
39763 -253 253 253 253 253 253 253 253 253 253 253 253
39764 -253 253 253 253 253 253 253 253 253 253 253 253
39765 -253 253 253 253 253 253 253 253 253 253 253 253
39766 -253 253 253 253 253 253 253 253 253 253 253 253
39767 -253 253 253 253 253 253 182 182 182 2 2 6
39768 - 2 2 6 2 2 6 2 2 6 46 46 46
39769 - 2 2 6 2 2 6 2 2 6 2 2 6
39770 - 10 10 10 86 86 86 38 38 38 10 10 10
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 - 10 10 10 26 26 26 66 66 66 82 82 82
39779 - 2 2 6 22 22 22 18 18 18 2 2 6
39780 -149 149 149 253 253 253 253 253 253 253 253 253
39781 -253 253 253 253 253 253 253 253 253 253 253 253
39782 -253 253 253 253 253 253 234 234 234 242 242 242
39783 -253 253 253 253 253 253 253 253 253 253 253 253
39784 -253 253 253 253 253 253 253 253 253 253 253 253
39785 -253 253 253 253 253 253 253 253 253 253 253 253
39786 -253 253 253 253 253 253 253 253 253 253 253 253
39787 -253 253 253 253 253 253 206 206 206 2 2 6
39788 - 2 2 6 2 2 6 2 2 6 38 38 38
39789 - 2 2 6 2 2 6 2 2 6 2 2 6
39790 - 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
39798 - 18 18 18 46 46 46 86 86 86 18 18 18
39799 - 2 2 6 34 34 34 10 10 10 6 6 6
39800 -210 210 210 253 253 253 253 253 253 253 253 253
39801 -253 253 253 253 253 253 253 253 253 253 253 253
39802 -253 253 253 253 253 253 234 234 234 242 242 242
39803 -253 253 253 253 253 253 253 253 253 253 253 253
39804 -253 253 253 253 253 253 253 253 253 253 253 253
39805 -253 253 253 253 253 253 253 253 253 253 253 253
39806 -253 253 253 253 253 253 253 253 253 253 253 253
39807 -253 253 253 253 253 253 221 221 221 6 6 6
39808 - 2 2 6 2 2 6 6 6 6 30 30 30
39809 - 2 2 6 2 2 6 2 2 6 2 2 6
39810 - 2 2 6 82 82 82 54 54 54 18 18 18
39811 - 6 6 6 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 10 10 10
39818 - 26 26 26 66 66 66 62 62 62 2 2 6
39819 - 2 2 6 38 38 38 10 10 10 26 26 26
39820 -238 238 238 253 253 253 253 253 253 253 253 253
39821 -253 253 253 253 253 253 253 253 253 253 253 253
39822 -253 253 253 253 253 253 231 231 231 238 238 238
39823 -253 253 253 253 253 253 253 253 253 253 253 253
39824 -253 253 253 253 253 253 253 253 253 253 253 253
39825 -253 253 253 253 253 253 253 253 253 253 253 253
39826 -253 253 253 253 253 253 253 253 253 253 253 253
39827 -253 253 253 253 253 253 231 231 231 6 6 6
39828 - 2 2 6 2 2 6 10 10 10 30 30 30
39829 - 2 2 6 2 2 6 2 2 6 2 2 6
39830 - 2 2 6 66 66 66 58 58 58 22 22 22
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 10 10 10
39838 - 38 38 38 78 78 78 6 6 6 2 2 6
39839 - 2 2 6 46 46 46 14 14 14 42 42 42
39840 -246 246 246 253 253 253 253 253 253 253 253 253
39841 -253 253 253 253 253 253 253 253 253 253 253 253
39842 -253 253 253 253 253 253 231 231 231 242 242 242
39843 -253 253 253 253 253 253 253 253 253 253 253 253
39844 -253 253 253 253 253 253 253 253 253 253 253 253
39845 -253 253 253 253 253 253 253 253 253 253 253 253
39846 -253 253 253 253 253 253 253 253 253 253 253 253
39847 -253 253 253 253 253 253 234 234 234 10 10 10
39848 - 2 2 6 2 2 6 22 22 22 14 14 14
39849 - 2 2 6 2 2 6 2 2 6 2 2 6
39850 - 2 2 6 66 66 66 62 62 62 22 22 22
39851 - 6 6 6 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 6 6 6 18 18 18
39858 - 50 50 50 74 74 74 2 2 6 2 2 6
39859 - 14 14 14 70 70 70 34 34 34 62 62 62
39860 -250 250 250 253 253 253 253 253 253 253 253 253
39861 -253 253 253 253 253 253 253 253 253 253 253 253
39862 -253 253 253 253 253 253 231 231 231 246 246 246
39863 -253 253 253 253 253 253 253 253 253 253 253 253
39864 -253 253 253 253 253 253 253 253 253 253 253 253
39865 -253 253 253 253 253 253 253 253 253 253 253 253
39866 -253 253 253 253 253 253 253 253 253 253 253 253
39867 -253 253 253 253 253 253 234 234 234 14 14 14
39868 - 2 2 6 2 2 6 30 30 30 2 2 6
39869 - 2 2 6 2 2 6 2 2 6 2 2 6
39870 - 2 2 6 66 66 66 62 62 62 22 22 22
39871 - 6 6 6 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 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 6 6 6 18 18 18
39878 - 54 54 54 62 62 62 2 2 6 2 2 6
39879 - 2 2 6 30 30 30 46 46 46 70 70 70
39880 -250 250 250 253 253 253 253 253 253 253 253 253
39881 -253 253 253 253 253 253 253 253 253 253 253 253
39882 -253 253 253 253 253 253 231 231 231 246 246 246
39883 -253 253 253 253 253 253 253 253 253 253 253 253
39884 -253 253 253 253 253 253 253 253 253 253 253 253
39885 -253 253 253 253 253 253 253 253 253 253 253 253
39886 -253 253 253 253 253 253 253 253 253 253 253 253
39887 -253 253 253 253 253 253 226 226 226 10 10 10
39888 - 2 2 6 6 6 6 30 30 30 2 2 6
39889 - 2 2 6 2 2 6 2 2 6 2 2 6
39890 - 2 2 6 66 66 66 58 58 58 22 22 22
39891 - 6 6 6 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22
39898 - 58 58 58 62 62 62 2 2 6 2 2 6
39899 - 2 2 6 2 2 6 30 30 30 78 78 78
39900 -250 250 250 253 253 253 253 253 253 253 253 253
39901 -253 253 253 253 253 253 253 253 253 253 253 253
39902 -253 253 253 253 253 253 231 231 231 246 246 246
39903 -253 253 253 253 253 253 253 253 253 253 253 253
39904 -253 253 253 253 253 253 253 253 253 253 253 253
39905 -253 253 253 253 253 253 253 253 253 253 253 253
39906 -253 253 253 253 253 253 253 253 253 253 253 253
39907 -253 253 253 253 253 253 206 206 206 2 2 6
39908 - 22 22 22 34 34 34 18 14 6 22 22 22
39909 - 26 26 26 18 18 18 6 6 6 2 2 6
39910 - 2 2 6 82 82 82 54 54 54 18 18 18
39911 - 6 6 6 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 0 0 0
39913 - 0 0 0 0 0 0 0 0 0 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 6 6 6 26 26 26
39918 - 62 62 62 106 106 106 74 54 14 185 133 11
39919 -210 162 10 121 92 8 6 6 6 62 62 62
39920 -238 238 238 253 253 253 253 253 253 253 253 253
39921 -253 253 253 253 253 253 253 253 253 253 253 253
39922 -253 253 253 253 253 253 231 231 231 246 246 246
39923 -253 253 253 253 253 253 253 253 253 253 253 253
39924 -253 253 253 253 253 253 253 253 253 253 253 253
39925 -253 253 253 253 253 253 253 253 253 253 253 253
39926 -253 253 253 253 253 253 253 253 253 253 253 253
39927 -253 253 253 253 253 253 158 158 158 18 18 18
39928 - 14 14 14 2 2 6 2 2 6 2 2 6
39929 - 6 6 6 18 18 18 66 66 66 38 38 38
39930 - 6 6 6 94 94 94 50 50 50 18 18 18
39931 - 6 6 6 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 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 6 6 6
39937 - 10 10 10 10 10 10 18 18 18 38 38 38
39938 - 78 78 78 142 134 106 216 158 10 242 186 14
39939 -246 190 14 246 190 14 156 118 10 10 10 10
39940 - 90 90 90 238 238 238 253 253 253 253 253 253
39941 -253 253 253 253 253 253 253 253 253 253 253 253
39942 -253 253 253 253 253 253 231 231 231 250 250 250
39943 -253 253 253 253 253 253 253 253 253 253 253 253
39944 -253 253 253 253 253 253 253 253 253 253 253 253
39945 -253 253 253 253 253 253 253 253 253 253 253 253
39946 -253 253 253 253 253 253 253 253 253 246 230 190
39947 -238 204 91 238 204 91 181 142 44 37 26 9
39948 - 2 2 6 2 2 6 2 2 6 2 2 6
39949 - 2 2 6 2 2 6 38 38 38 46 46 46
39950 - 26 26 26 106 106 106 54 54 54 18 18 18
39951 - 6 6 6 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 0 0 0 0 0 0 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 6 6 6 14 14 14 22 22 22
39957 - 30 30 30 38 38 38 50 50 50 70 70 70
39958 -106 106 106 190 142 34 226 170 11 242 186 14
39959 -246 190 14 246 190 14 246 190 14 154 114 10
39960 - 6 6 6 74 74 74 226 226 226 253 253 253
39961 -253 253 253 253 253 253 253 253 253 253 253 253
39962 -253 253 253 253 253 253 231 231 231 250 250 250
39963 -253 253 253 253 253 253 253 253 253 253 253 253
39964 -253 253 253 253 253 253 253 253 253 253 253 253
39965 -253 253 253 253 253 253 253 253 253 253 253 253
39966 -253 253 253 253 253 253 253 253 253 228 184 62
39967 -241 196 14 241 208 19 232 195 16 38 30 10
39968 - 2 2 6 2 2 6 2 2 6 2 2 6
39969 - 2 2 6 6 6 6 30 30 30 26 26 26
39970 -203 166 17 154 142 90 66 66 66 26 26 26
39971 - 6 6 6 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 38 38 38 58 58 58
39977 - 78 78 78 86 86 86 101 101 101 123 123 123
39978 -175 146 61 210 150 10 234 174 13 246 186 14
39979 -246 190 14 246 190 14 246 190 14 238 190 10
39980 -102 78 10 2 2 6 46 46 46 198 198 198
39981 -253 253 253 253 253 253 253 253 253 253 253 253
39982 -253 253 253 253 253 253 234 234 234 242 242 242
39983 -253 253 253 253 253 253 253 253 253 253 253 253
39984 -253 253 253 253 253 253 253 253 253 253 253 253
39985 -253 253 253 253 253 253 253 253 253 253 253 253
39986 -253 253 253 253 253 253 253 253 253 224 178 62
39987 -242 186 14 241 196 14 210 166 10 22 18 6
39988 - 2 2 6 2 2 6 2 2 6 2 2 6
39989 - 2 2 6 2 2 6 6 6 6 121 92 8
39990 -238 202 15 232 195 16 82 82 82 34 34 34
39991 - 10 10 10 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 14 14 14 38 38 38 70 70 70 154 122 46
39997 -190 142 34 200 144 11 197 138 11 197 138 11
39998 -213 154 11 226 170 11 242 186 14 246 190 14
39999 -246 190 14 246 190 14 246 190 14 246 190 14
40000 -225 175 15 46 32 6 2 2 6 22 22 22
40001 -158 158 158 250 250 250 253 253 253 253 253 253
40002 -253 253 253 253 253 253 253 253 253 253 253 253
40003 -253 253 253 253 253 253 253 253 253 253 253 253
40004 -253 253 253 253 253 253 253 253 253 253 253 253
40005 -253 253 253 253 253 253 253 253 253 253 253 253
40006 -253 253 253 250 250 250 242 242 242 224 178 62
40007 -239 182 13 236 186 11 213 154 11 46 32 6
40008 - 2 2 6 2 2 6 2 2 6 2 2 6
40009 - 2 2 6 2 2 6 61 42 6 225 175 15
40010 -238 190 10 236 186 11 112 100 78 42 42 42
40011 - 14 14 14 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 6 6 6
40016 - 22 22 22 54 54 54 154 122 46 213 154 11
40017 -226 170 11 230 174 11 226 170 11 226 170 11
40018 -236 178 12 242 186 14 246 190 14 246 190 14
40019 -246 190 14 246 190 14 246 190 14 246 190 14
40020 -241 196 14 184 144 12 10 10 10 2 2 6
40021 - 6 6 6 116 116 116 242 242 242 253 253 253
40022 -253 253 253 253 253 253 253 253 253 253 253 253
40023 -253 253 253 253 253 253 253 253 253 253 253 253
40024 -253 253 253 253 253 253 253 253 253 253 253 253
40025 -253 253 253 253 253 253 253 253 253 253 253 253
40026 -253 253 253 231 231 231 198 198 198 214 170 54
40027 -236 178 12 236 178 12 210 150 10 137 92 6
40028 - 18 14 6 2 2 6 2 2 6 2 2 6
40029 - 6 6 6 70 47 6 200 144 11 236 178 12
40030 -239 182 13 239 182 13 124 112 88 58 58 58
40031 - 22 22 22 6 6 6 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 0 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 10 10 10
40036 - 30 30 30 70 70 70 180 133 36 226 170 11
40037 -239 182 13 242 186 14 242 186 14 246 186 14
40038 -246 190 14 246 190 14 246 190 14 246 190 14
40039 -246 190 14 246 190 14 246 190 14 246 190 14
40040 -246 190 14 232 195 16 98 70 6 2 2 6
40041 - 2 2 6 2 2 6 66 66 66 221 221 221
40042 -253 253 253 253 253 253 253 253 253 253 253 253
40043 -253 253 253 253 253 253 253 253 253 253 253 253
40044 -253 253 253 253 253 253 253 253 253 253 253 253
40045 -253 253 253 253 253 253 253 253 253 253 253 253
40046 -253 253 253 206 206 206 198 198 198 214 166 58
40047 -230 174 11 230 174 11 216 158 10 192 133 9
40048 -163 110 8 116 81 8 102 78 10 116 81 8
40049 -167 114 7 197 138 11 226 170 11 239 182 13
40050 -242 186 14 242 186 14 162 146 94 78 78 78
40051 - 34 34 34 14 14 14 6 6 6 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 6 6 6
40056 - 30 30 30 78 78 78 190 142 34 226 170 11
40057 -239 182 13 246 190 14 246 190 14 246 190 14
40058 -246 190 14 246 190 14 246 190 14 246 190 14
40059 -246 190 14 246 190 14 246 190 14 246 190 14
40060 -246 190 14 241 196 14 203 166 17 22 18 6
40061 - 2 2 6 2 2 6 2 2 6 38 38 38
40062 -218 218 218 253 253 253 253 253 253 253 253 253
40063 -253 253 253 253 253 253 253 253 253 253 253 253
40064 -253 253 253 253 253 253 253 253 253 253 253 253
40065 -253 253 253 253 253 253 253 253 253 253 253 253
40066 -250 250 250 206 206 206 198 198 198 202 162 69
40067 -226 170 11 236 178 12 224 166 10 210 150 10
40068 -200 144 11 197 138 11 192 133 9 197 138 11
40069 -210 150 10 226 170 11 242 186 14 246 190 14
40070 -246 190 14 246 186 14 225 175 15 124 112 88
40071 - 62 62 62 30 30 30 14 14 14 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 10 10 10
40076 - 30 30 30 78 78 78 174 135 50 224 166 10
40077 -239 182 13 246 190 14 246 190 14 246 190 14
40078 -246 190 14 246 190 14 246 190 14 246 190 14
40079 -246 190 14 246 190 14 246 190 14 246 190 14
40080 -246 190 14 246 190 14 241 196 14 139 102 15
40081 - 2 2 6 2 2 6 2 2 6 2 2 6
40082 - 78 78 78 250 250 250 253 253 253 253 253 253
40083 -253 253 253 253 253 253 253 253 253 253 253 253
40084 -253 253 253 253 253 253 253 253 253 253 253 253
40085 -253 253 253 253 253 253 253 253 253 253 253 253
40086 -250 250 250 214 214 214 198 198 198 190 150 46
40087 -219 162 10 236 178 12 234 174 13 224 166 10
40088 -216 158 10 213 154 11 213 154 11 216 158 10
40089 -226 170 11 239 182 13 246 190 14 246 190 14
40090 -246 190 14 246 190 14 242 186 14 206 162 42
40091 -101 101 101 58 58 58 30 30 30 14 14 14
40092 - 6 6 6 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 10 10 10
40096 - 30 30 30 74 74 74 174 135 50 216 158 10
40097 -236 178 12 246 190 14 246 190 14 246 190 14
40098 -246 190 14 246 190 14 246 190 14 246 190 14
40099 -246 190 14 246 190 14 246 190 14 246 190 14
40100 -246 190 14 246 190 14 241 196 14 226 184 13
40101 - 61 42 6 2 2 6 2 2 6 2 2 6
40102 - 22 22 22 238 238 238 253 253 253 253 253 253
40103 -253 253 253 253 253 253 253 253 253 253 253 253
40104 -253 253 253 253 253 253 253 253 253 253 253 253
40105 -253 253 253 253 253 253 253 253 253 253 253 253
40106 -253 253 253 226 226 226 187 187 187 180 133 36
40107 -216 158 10 236 178 12 239 182 13 236 178 12
40108 -230 174 11 226 170 11 226 170 11 230 174 11
40109 -236 178 12 242 186 14 246 190 14 246 190 14
40110 -246 190 14 246 190 14 246 186 14 239 182 13
40111 -206 162 42 106 106 106 66 66 66 34 34 34
40112 - 14 14 14 6 6 6 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 6 6 6
40116 - 26 26 26 70 70 70 163 133 67 213 154 11
40117 -236 178 12 246 190 14 246 190 14 246 190 14
40118 -246 190 14 246 190 14 246 190 14 246 190 14
40119 -246 190 14 246 190 14 246 190 14 246 190 14
40120 -246 190 14 246 190 14 246 190 14 241 196 14
40121 -190 146 13 18 14 6 2 2 6 2 2 6
40122 - 46 46 46 246 246 246 253 253 253 253 253 253
40123 -253 253 253 253 253 253 253 253 253 253 253 253
40124 -253 253 253 253 253 253 253 253 253 253 253 253
40125 -253 253 253 253 253 253 253 253 253 253 253 253
40126 -253 253 253 221 221 221 86 86 86 156 107 11
40127 -216 158 10 236 178 12 242 186 14 246 186 14
40128 -242 186 14 239 182 13 239 182 13 242 186 14
40129 -242 186 14 246 186 14 246 190 14 246 190 14
40130 -246 190 14 246 190 14 246 190 14 246 190 14
40131 -242 186 14 225 175 15 142 122 72 66 66 66
40132 - 30 30 30 10 10 10 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 6 6 6
40136 - 26 26 26 70 70 70 163 133 67 210 150 10
40137 -236 178 12 246 190 14 246 190 14 246 190 14
40138 -246 190 14 246 190 14 246 190 14 246 190 14
40139 -246 190 14 246 190 14 246 190 14 246 190 14
40140 -246 190 14 246 190 14 246 190 14 246 190 14
40141 -232 195 16 121 92 8 34 34 34 106 106 106
40142 -221 221 221 253 253 253 253 253 253 253 253 253
40143 -253 253 253 253 253 253 253 253 253 253 253 253
40144 -253 253 253 253 253 253 253 253 253 253 253 253
40145 -253 253 253 253 253 253 253 253 253 253 253 253
40146 -242 242 242 82 82 82 18 14 6 163 110 8
40147 -216 158 10 236 178 12 242 186 14 246 190 14
40148 -246 190 14 246 190 14 246 190 14 246 190 14
40149 -246 190 14 246 190 14 246 190 14 246 190 14
40150 -246 190 14 246 190 14 246 190 14 246 190 14
40151 -246 190 14 246 190 14 242 186 14 163 133 67
40152 - 46 46 46 18 18 18 6 6 6 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 10 10 10
40156 - 30 30 30 78 78 78 163 133 67 210 150 10
40157 -236 178 12 246 186 14 246 190 14 246 190 14
40158 -246 190 14 246 190 14 246 190 14 246 190 14
40159 -246 190 14 246 190 14 246 190 14 246 190 14
40160 -246 190 14 246 190 14 246 190 14 246 190 14
40161 -241 196 14 215 174 15 190 178 144 253 253 253
40162 -253 253 253 253 253 253 253 253 253 253 253 253
40163 -253 253 253 253 253 253 253 253 253 253 253 253
40164 -253 253 253 253 253 253 253 253 253 253 253 253
40165 -253 253 253 253 253 253 253 253 253 218 218 218
40166 - 58 58 58 2 2 6 22 18 6 167 114 7
40167 -216 158 10 236 178 12 246 186 14 246 190 14
40168 -246 190 14 246 190 14 246 190 14 246 190 14
40169 -246 190 14 246 190 14 246 190 14 246 190 14
40170 -246 190 14 246 190 14 246 190 14 246 190 14
40171 -246 190 14 246 186 14 242 186 14 190 150 46
40172 - 54 54 54 22 22 22 6 6 6 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 14 14 14
40176 - 38 38 38 86 86 86 180 133 36 213 154 11
40177 -236 178 12 246 186 14 246 190 14 246 190 14
40178 -246 190 14 246 190 14 246 190 14 246 190 14
40179 -246 190 14 246 190 14 246 190 14 246 190 14
40180 -246 190 14 246 190 14 246 190 14 246 190 14
40181 -246 190 14 232 195 16 190 146 13 214 214 214
40182 -253 253 253 253 253 253 253 253 253 253 253 253
40183 -253 253 253 253 253 253 253 253 253 253 253 253
40184 -253 253 253 253 253 253 253 253 253 253 253 253
40185 -253 253 253 250 250 250 170 170 170 26 26 26
40186 - 2 2 6 2 2 6 37 26 9 163 110 8
40187 -219 162 10 239 182 13 246 186 14 246 190 14
40188 -246 190 14 246 190 14 246 190 14 246 190 14
40189 -246 190 14 246 190 14 246 190 14 246 190 14
40190 -246 190 14 246 190 14 246 190 14 246 190 14
40191 -246 186 14 236 178 12 224 166 10 142 122 72
40192 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
40196 - 50 50 50 109 106 95 192 133 9 224 166 10
40197 -242 186 14 246 190 14 246 190 14 246 190 14
40198 -246 190 14 246 190 14 246 190 14 246 190 14
40199 -246 190 14 246 190 14 246 190 14 246 190 14
40200 -246 190 14 246 190 14 246 190 14 246 190 14
40201 -242 186 14 226 184 13 210 162 10 142 110 46
40202 -226 226 226 253 253 253 253 253 253 253 253 253
40203 -253 253 253 253 253 253 253 253 253 253 253 253
40204 -253 253 253 253 253 253 253 253 253 253 253 253
40205 -198 198 198 66 66 66 2 2 6 2 2 6
40206 - 2 2 6 2 2 6 50 34 6 156 107 11
40207 -219 162 10 239 182 13 246 186 14 246 190 14
40208 -246 190 14 246 190 14 246 190 14 246 190 14
40209 -246 190 14 246 190 14 246 190 14 246 190 14
40210 -246 190 14 246 190 14 246 190 14 242 186 14
40211 -234 174 13 213 154 11 154 122 46 66 66 66
40212 - 30 30 30 10 10 10 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 6 6 6 22 22 22
40216 - 58 58 58 154 121 60 206 145 10 234 174 13
40217 -242 186 14 246 186 14 246 190 14 246 190 14
40218 -246 190 14 246 190 14 246 190 14 246 190 14
40219 -246 190 14 246 190 14 246 190 14 246 190 14
40220 -246 190 14 246 190 14 246 190 14 246 190 14
40221 -246 186 14 236 178 12 210 162 10 163 110 8
40222 - 61 42 6 138 138 138 218 218 218 250 250 250
40223 -253 253 253 253 253 253 253 253 253 250 250 250
40224 -242 242 242 210 210 210 144 144 144 66 66 66
40225 - 6 6 6 2 2 6 2 2 6 2 2 6
40226 - 2 2 6 2 2 6 61 42 6 163 110 8
40227 -216 158 10 236 178 12 246 190 14 246 190 14
40228 -246 190 14 246 190 14 246 190 14 246 190 14
40229 -246 190 14 246 190 14 246 190 14 246 190 14
40230 -246 190 14 239 182 13 230 174 11 216 158 10
40231 -190 142 34 124 112 88 70 70 70 38 38 38
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 6 6 6 22 22 22
40236 - 62 62 62 168 124 44 206 145 10 224 166 10
40237 -236 178 12 239 182 13 242 186 14 242 186 14
40238 -246 186 14 246 190 14 246 190 14 246 190 14
40239 -246 190 14 246 190 14 246 190 14 246 190 14
40240 -246 190 14 246 190 14 246 190 14 246 190 14
40241 -246 190 14 236 178 12 216 158 10 175 118 6
40242 - 80 54 7 2 2 6 6 6 6 30 30 30
40243 - 54 54 54 62 62 62 50 50 50 38 38 38
40244 - 14 14 14 2 2 6 2 2 6 2 2 6
40245 - 2 2 6 2 2 6 2 2 6 2 2 6
40246 - 2 2 6 6 6 6 80 54 7 167 114 7
40247 -213 154 11 236 178 12 246 190 14 246 190 14
40248 -246 190 14 246 190 14 246 190 14 246 190 14
40249 -246 190 14 242 186 14 239 182 13 239 182 13
40250 -230 174 11 210 150 10 174 135 50 124 112 88
40251 - 82 82 82 54 54 54 34 34 34 18 18 18
40252 - 6 6 6 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 0 0 0 0 0 0 0 0 0 0
40255 - 0 0 0 0 0 0 6 6 6 18 18 18
40256 - 50 50 50 158 118 36 192 133 9 200 144 11
40257 -216 158 10 219 162 10 224 166 10 226 170 11
40258 -230 174 11 236 178 12 239 182 13 239 182 13
40259 -242 186 14 246 186 14 246 190 14 246 190 14
40260 -246 190 14 246 190 14 246 190 14 246 190 14
40261 -246 186 14 230 174 11 210 150 10 163 110 8
40262 -104 69 6 10 10 10 2 2 6 2 2 6
40263 - 2 2 6 2 2 6 2 2 6 2 2 6
40264 - 2 2 6 2 2 6 2 2 6 2 2 6
40265 - 2 2 6 2 2 6 2 2 6 2 2 6
40266 - 2 2 6 6 6 6 91 60 6 167 114 7
40267 -206 145 10 230 174 11 242 186 14 246 190 14
40268 -246 190 14 246 190 14 246 186 14 242 186 14
40269 -239 182 13 230 174 11 224 166 10 213 154 11
40270 -180 133 36 124 112 88 86 86 86 58 58 58
40271 - 38 38 38 22 22 22 10 10 10 6 6 6
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 0 0 0
40274 - 0 0 0 0 0 0 0 0 0 0 0 0
40275 - 0 0 0 0 0 0 0 0 0 14 14 14
40276 - 34 34 34 70 70 70 138 110 50 158 118 36
40277 -167 114 7 180 123 7 192 133 9 197 138 11
40278 -200 144 11 206 145 10 213 154 11 219 162 10
40279 -224 166 10 230 174 11 239 182 13 242 186 14
40280 -246 186 14 246 186 14 246 186 14 246 186 14
40281 -239 182 13 216 158 10 185 133 11 152 99 6
40282 -104 69 6 18 14 6 2 2 6 2 2 6
40283 - 2 2 6 2 2 6 2 2 6 2 2 6
40284 - 2 2 6 2 2 6 2 2 6 2 2 6
40285 - 2 2 6 2 2 6 2 2 6 2 2 6
40286 - 2 2 6 6 6 6 80 54 7 152 99 6
40287 -192 133 9 219 162 10 236 178 12 239 182 13
40288 -246 186 14 242 186 14 239 182 13 236 178 12
40289 -224 166 10 206 145 10 192 133 9 154 121 60
40290 - 94 94 94 62 62 62 42 42 42 22 22 22
40291 - 14 14 14 6 6 6 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
40294 - 0 0 0 0 0 0 0 0 0 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 6 6 6
40296 - 18 18 18 34 34 34 58 58 58 78 78 78
40297 -101 98 89 124 112 88 142 110 46 156 107 11
40298 -163 110 8 167 114 7 175 118 6 180 123 7
40299 -185 133 11 197 138 11 210 150 10 219 162 10
40300 -226 170 11 236 178 12 236 178 12 234 174 13
40301 -219 162 10 197 138 11 163 110 8 130 83 6
40302 - 91 60 6 10 10 10 2 2 6 2 2 6
40303 - 18 18 18 38 38 38 38 38 38 38 38 38
40304 - 38 38 38 38 38 38 38 38 38 38 38 38
40305 - 38 38 38 38 38 38 26 26 26 2 2 6
40306 - 2 2 6 6 6 6 70 47 6 137 92 6
40307 -175 118 6 200 144 11 219 162 10 230 174 11
40308 -234 174 13 230 174 11 219 162 10 210 150 10
40309 -192 133 9 163 110 8 124 112 88 82 82 82
40310 - 50 50 50 30 30 30 14 14 14 6 6 6
40311 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 0 0 0 0 0 0 0 0 0 0 0 0
40316 - 6 6 6 14 14 14 22 22 22 34 34 34
40317 - 42 42 42 58 58 58 74 74 74 86 86 86
40318 -101 98 89 122 102 70 130 98 46 121 87 25
40319 -137 92 6 152 99 6 163 110 8 180 123 7
40320 -185 133 11 197 138 11 206 145 10 200 144 11
40321 -180 123 7 156 107 11 130 83 6 104 69 6
40322 - 50 34 6 54 54 54 110 110 110 101 98 89
40323 - 86 86 86 82 82 82 78 78 78 78 78 78
40324 - 78 78 78 78 78 78 78 78 78 78 78 78
40325 - 78 78 78 82 82 82 86 86 86 94 94 94
40326 -106 106 106 101 101 101 86 66 34 124 80 6
40327 -156 107 11 180 123 7 192 133 9 200 144 11
40328 -206 145 10 200 144 11 192 133 9 175 118 6
40329 -139 102 15 109 106 95 70 70 70 42 42 42
40330 - 22 22 22 10 10 10 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 6 6 6 10 10 10
40337 - 14 14 14 22 22 22 30 30 30 38 38 38
40338 - 50 50 50 62 62 62 74 74 74 90 90 90
40339 -101 98 89 112 100 78 121 87 25 124 80 6
40340 -137 92 6 152 99 6 152 99 6 152 99 6
40341 -138 86 6 124 80 6 98 70 6 86 66 30
40342 -101 98 89 82 82 82 58 58 58 46 46 46
40343 - 38 38 38 34 34 34 34 34 34 34 34 34
40344 - 34 34 34 34 34 34 34 34 34 34 34 34
40345 - 34 34 34 34 34 34 38 38 38 42 42 42
40346 - 54 54 54 82 82 82 94 86 76 91 60 6
40347 -134 86 6 156 107 11 167 114 7 175 118 6
40348 -175 118 6 167 114 7 152 99 6 121 87 25
40349 -101 98 89 62 62 62 34 34 34 18 18 18
40350 - 6 6 6 0 0 0 0 0 0 0 0 0
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 6 6 6 6 6 6 10 10 10
40358 - 18 18 18 22 22 22 30 30 30 42 42 42
40359 - 50 50 50 66 66 66 86 86 86 101 98 89
40360 -106 86 58 98 70 6 104 69 6 104 69 6
40361 -104 69 6 91 60 6 82 62 34 90 90 90
40362 - 62 62 62 38 38 38 22 22 22 14 14 14
40363 - 10 10 10 10 10 10 10 10 10 10 10 10
40364 - 10 10 10 10 10 10 6 6 6 10 10 10
40365 - 10 10 10 10 10 10 10 10 10 14 14 14
40366 - 22 22 22 42 42 42 70 70 70 89 81 66
40367 - 80 54 7 104 69 6 124 80 6 137 92 6
40368 -134 86 6 116 81 8 100 82 52 86 86 86
40369 - 58 58 58 30 30 30 14 14 14 6 6 6
40370 - 0 0 0 0 0 0 0 0 0 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
40379 - 18 18 18 26 26 26 38 38 38 54 54 54
40380 - 70 70 70 86 86 86 94 86 76 89 81 66
40381 - 89 81 66 86 86 86 74 74 74 50 50 50
40382 - 30 30 30 14 14 14 6 6 6 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 0 0 0 0 0 0
40386 - 6 6 6 18 18 18 34 34 34 58 58 58
40387 - 82 82 82 89 81 66 89 81 66 89 81 66
40388 - 94 86 66 94 86 76 74 74 74 50 50 50
40389 - 26 26 26 14 14 14 6 6 6 0 0 0
40390 - 0 0 0 0 0 0 0 0 0 0 0 0
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 6 6 6 6 6 6 14 14 14 18 18 18
40400 - 30 30 30 38 38 38 46 46 46 54 54 54
40401 - 50 50 50 42 42 42 30 30 30 18 18 18
40402 - 10 10 10 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 0 0 0 0 0 0
40406 - 0 0 0 6 6 6 14 14 14 26 26 26
40407 - 38 38 38 50 50 50 58 58 58 58 58 58
40408 - 54 54 54 42 42 42 30 30 30 18 18 18
40409 - 10 10 10 0 0 0 0 0 0 0 0 0
40410 - 0 0 0 0 0 0 0 0 0 0 0 0
40411 - 0 0 0 0 0 0 0 0 0 0 0 0
40412 - 0 0 0 0 0 0 0 0 0 0 0 0
40413 - 0 0 0 0 0 0 0 0 0 0 0 0
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 6 6 6
40420 - 6 6 6 10 10 10 14 14 14 18 18 18
40421 - 18 18 18 14 14 14 10 10 10 6 6 6
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 0 0 0 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 0 0 0 0 0 0 0 0 0
40426 - 0 0 0 0 0 0 0 0 0 6 6 6
40427 - 14 14 14 18 18 18 22 22 22 22 22 22
40428 - 18 18 18 14 14 14 10 10 10 6 6 6
40429 - 0 0 0 0 0 0 0 0 0 0 0 0
40430 - 0 0 0 0 0 0 0 0 0 0 0 0
40431 - 0 0 0 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 0 0 0 0 0 0 0 0 0
40433 - 0 0 0 0 0 0 0 0 0 0 0 0
40434 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40437 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40447 +4 4 4 4 4 4
40448 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40451 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40461 +4 4 4 4 4 4
40462 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40465 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40475 +4 4 4 4 4 4
40476 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40479 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40489 +4 4 4 4 4 4
40490 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40493 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40503 +4 4 4 4 4 4
40504 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40507 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40509 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40510 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40517 +4 4 4 4 4 4
40518 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40521 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40522 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
40523 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
40524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40527 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
40528 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40529 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
40530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40531 +4 4 4 4 4 4
40532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40535 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40536 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
40537 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
40538 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40541 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
40542 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
40543 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
40544 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40545 +4 4 4 4 4 4
40546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40550 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
40551 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
40552 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40555 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
40556 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
40557 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
40558 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
40559 +4 4 4 4 4 4
40560 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40561 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40562 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40563 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
40564 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
40565 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
40566 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
40567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40568 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40569 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
40570 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
40571 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
40572 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
40573 +4 4 4 4 4 4
40574 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40575 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40576 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40577 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
40578 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
40579 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
40580 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
40581 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
40582 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
40583 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
40584 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
40585 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
40586 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
40587 +4 4 4 4 4 4
40588 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40589 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40590 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
40591 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
40592 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
40593 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
40594 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
40595 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
40596 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
40597 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
40598 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
40599 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
40600 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
40601 +4 4 4 4 4 4
40602 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40603 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40604 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
40605 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
40606 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
40607 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
40608 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
40609 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
40610 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
40611 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
40612 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
40613 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
40614 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
40615 +4 4 4 4 4 4
40616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40617 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40618 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
40619 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
40620 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
40621 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
40622 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
40623 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
40624 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
40625 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
40626 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
40627 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
40628 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
40629 +4 4 4 4 4 4
40630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40631 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40632 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
40633 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
40634 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
40635 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
40636 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
40637 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
40638 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
40639 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
40640 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
40641 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
40642 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
40643 +4 4 4 4 4 4
40644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40645 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40646 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
40647 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
40648 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
40649 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
40650 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
40651 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
40652 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
40653 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
40654 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
40655 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
40656 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
40657 +4 4 4 4 4 4
40658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40659 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
40660 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
40661 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
40662 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
40663 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
40664 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
40665 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
40666 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
40667 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
40668 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
40669 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
40670 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
40671 +4 4 4 4 4 4
40672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40673 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
40674 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
40675 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
40676 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
40677 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
40678 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
40679 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
40680 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
40681 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
40682 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
40683 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
40684 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
40685 +0 0 0 4 4 4
40686 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
40687 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
40688 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
40689 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
40690 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
40691 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
40692 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
40693 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
40694 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
40695 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
40696 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
40697 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
40698 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
40699 +2 0 0 0 0 0
40700 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
40701 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
40702 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
40703 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
40704 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
40705 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
40706 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
40707 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
40708 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
40709 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
40710 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
40711 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
40712 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
40713 +37 38 37 0 0 0
40714 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40715 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
40716 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
40717 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
40718 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
40719 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
40720 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
40721 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
40722 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
40723 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
40724 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
40725 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
40726 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
40727 +85 115 134 4 0 0
40728 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
40729 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
40730 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
40731 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
40732 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
40733 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
40734 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
40735 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
40736 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
40737 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
40738 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
40739 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
40740 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
40741 +60 73 81 4 0 0
40742 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
40743 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
40744 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
40745 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
40746 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
40747 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
40748 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
40749 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
40750 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
40751 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
40752 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
40753 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
40754 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
40755 +16 19 21 4 0 0
40756 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
40757 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
40758 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
40759 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
40760 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
40761 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
40762 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
40763 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
40764 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
40765 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
40766 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
40767 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
40768 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
40769 +4 0 0 4 3 3
40770 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
40771 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
40772 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
40773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
40774 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
40775 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
40776 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
40777 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
40778 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
40779 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
40780 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
40781 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
40782 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
40783 +3 2 2 4 4 4
40784 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
40785 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
40786 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
40787 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
40788 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
40789 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
40790 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
40791 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
40792 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
40793 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
40794 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
40795 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
40796 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
40797 +4 4 4 4 4 4
40798 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
40799 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
40800 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
40801 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
40802 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
40803 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
40804 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
40805 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
40806 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
40807 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
40808 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
40809 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
40810 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
40811 +4 4 4 4 4 4
40812 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
40813 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
40814 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
40815 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
40816 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
40817 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40818 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
40819 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
40820 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
40821 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
40822 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
40823 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
40824 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
40825 +5 5 5 5 5 5
40826 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
40827 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
40828 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
40829 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
40830 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
40831 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40832 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
40833 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
40834 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
40835 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
40836 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
40837 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
40838 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
40839 +5 5 5 4 4 4
40840 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
40841 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
40842 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
40843 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
40844 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40845 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
40846 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
40847 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
40848 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
40849 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
40850 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
40851 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
40852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40853 +4 4 4 4 4 4
40854 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
40855 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
40856 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
40857 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
40858 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
40859 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40860 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40861 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
40862 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
40863 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
40864 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
40865 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
40866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40867 +4 4 4 4 4 4
40868 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
40869 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
40870 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
40871 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
40872 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40873 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
40874 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
40875 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
40876 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
40877 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
40878 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
40879 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40881 +4 4 4 4 4 4
40882 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
40883 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
40884 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
40885 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
40886 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40887 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40888 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
40889 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
40890 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
40891 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
40892 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
40893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40895 +4 4 4 4 4 4
40896 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
40897 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
40898 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
40899 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
40900 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40901 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
40902 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
40903 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
40904 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
40905 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
40906 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40909 +4 4 4 4 4 4
40910 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
40911 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
40912 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
40913 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
40914 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
40915 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
40916 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
40917 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
40918 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
40919 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
40920 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
40921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40923 +4 4 4 4 4 4
40924 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
40925 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
40926 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
40927 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
40928 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
40929 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
40930 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
40931 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
40932 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
40933 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
40934 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
40935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40937 +4 4 4 4 4 4
40938 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
40939 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
40940 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
40941 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40942 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
40943 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
40944 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
40945 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
40946 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
40947 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
40948 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40951 +4 4 4 4 4 4
40952 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
40953 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
40954 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
40955 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40956 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40957 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
40958 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
40959 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
40960 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
40961 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
40962 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40965 +4 4 4 4 4 4
40966 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
40967 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
40968 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40969 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
40970 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40971 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
40972 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
40973 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
40974 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
40975 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
40976 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40979 +4 4 4 4 4 4
40980 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
40981 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
40982 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
40983 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
40984 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
40985 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
40986 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
40987 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
40988 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
40989 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
40990 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
40991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
40993 +4 4 4 4 4 4
40994 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
40995 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
40996 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
40997 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
40998 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
40999 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41000 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41001 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41002 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41003 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41004 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41007 +4 4 4 4 4 4
41008 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41009 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41010 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41011 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41012 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41013 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41014 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41015 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41016 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41017 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41018 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41021 +4 4 4 4 4 4
41022 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41023 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41024 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41025 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41026 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41027 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41028 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41029 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41030 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41031 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41032 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41035 +4 4 4 4 4 4
41036 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41037 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41038 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41039 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41040 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41041 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41042 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41043 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41044 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41045 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41046 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41049 +4 4 4 4 4 4
41050 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41051 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41052 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41053 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41054 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41055 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41056 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41057 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41058 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41059 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41060 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41063 +4 4 4 4 4 4
41064 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41065 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41066 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41067 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41068 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41069 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41070 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41071 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41072 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41073 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41074 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41077 +4 4 4 4 4 4
41078 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41079 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41080 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41081 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41082 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41083 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41084 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41085 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41086 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41087 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41088 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41091 +4 4 4 4 4 4
41092 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41093 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41094 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41095 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41096 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41097 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41098 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41099 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41100 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41101 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41102 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41105 +4 4 4 4 4 4
41106 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41107 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41108 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41109 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41110 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41111 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41112 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41113 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41114 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41115 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41116 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41119 +4 4 4 4 4 4
41120 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41121 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41122 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41123 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41124 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41125 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41126 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41127 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41128 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41129 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41130 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41133 +4 4 4 4 4 4
41134 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41135 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41136 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41137 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41138 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41139 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41140 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41141 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41142 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41143 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41144 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147 +4 4 4 4 4 4
41148 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41149 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41150 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41151 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41152 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41153 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41154 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41155 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41156 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41157 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41158 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161 +4 4 4 4 4 4
41162 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41163 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41164 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41165 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41166 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41167 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41168 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41169 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41170 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41171 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41172 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175 +4 4 4 4 4 4
41176 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41177 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41178 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41179 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41180 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41181 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41182 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41183 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41184 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41185 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41186 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189 +4 4 4 4 4 4
41190 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41191 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41192 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41193 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41194 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41195 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41196 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41197 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41198 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41199 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41200 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203 +4 4 4 4 4 4
41204 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41205 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41206 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41207 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41208 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41209 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41210 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41211 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41212 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41213 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41214 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217 +4 4 4 4 4 4
41218 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41219 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41220 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41221 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41222 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41223 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41224 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41225 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41226 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41227 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41228 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41231 +4 4 4 4 4 4
41232 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41233 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41234 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41235 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41236 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41237 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41238 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41239 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41240 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41241 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41242 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4
41246 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41247 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41248 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41249 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41250 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41251 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41252 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41253 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41254 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41255 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4
41260 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41261 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41262 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41263 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41264 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41265 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41266 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41267 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41268 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41269 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4
41274 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41275 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41276 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41277 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41278 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41279 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41280 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41281 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41282 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41283 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4
41288 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41289 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41290 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41291 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41292 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
41293 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
41294 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
41295 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
41296 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41297 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4
41302 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
41303 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41304 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
41305 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41306 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
41307 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
41308 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
41309 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
41310 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4
41316 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
41317 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
41318 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
41319 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
41320 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
41321 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
41322 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
41323 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
41324 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4
41330 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41331 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
41332 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
41333 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
41334 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
41335 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
41336 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
41337 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
41338 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4
41344 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
41345 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
41346 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41347 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
41348 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
41349 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
41350 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
41351 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4
41358 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41359 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
41360 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
41361 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
41362 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
41363 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
41364 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
41365 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4
41372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41373 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
41374 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41375 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
41376 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
41377 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
41378 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
41379 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 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
41386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
41388 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
41389 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
41390 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
41391 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
41392 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
41393 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
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 4 4 4 4 4 4 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
41400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41402 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
41403 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41404 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
41405 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
41406 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
41407 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 4 4 4 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
41414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41416 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41417 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
41418 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
41419 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
41420 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
41421 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41422 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 4 4 4 4 4 4 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
41428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41431 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41432 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
41433 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
41434 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
41435 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41436 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41437 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
41442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
41446 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
41447 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
41448 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
41449 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41450 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41451 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
41455 +4 4 4 4 4 4
41456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41459 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
41460 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41461 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
41462 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
41463 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41464 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41465 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
41469 +4 4 4 4 4 4
41470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41473 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
41474 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
41475 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
41476 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
41477 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41478 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41479 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
41483 +4 4 4 4 4 4
41484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41488 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
41489 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
41490 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41491 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41492 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41493 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41497 +4 4 4 4 4 4
41498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41502 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
41503 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
41504 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41505 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41506 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41507 +4 4 4 4 4 4 4 4 4 4 4 4 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 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41511 +4 4 4 4 4 4
41512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41516 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
41517 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
41518 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41519 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41520 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41521 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
41524 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41525 +4 4 4 4 4 4
41526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41527 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41530 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
41531 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
41532 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41534 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41535 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41538 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41539 +4 4 4 4 4 4
41540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41541 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41544 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
41545 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
41546 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41547 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41548 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41549 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41550 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41551 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41552 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41553 +4 4 4 4 4 4
41554 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
41555 index 5fd95e0..b4a96f8 100644
41556 --- a/drivers/video/udlfb.c
41557 +++ b/drivers/video/udlfb.c
41558 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
41559 dlfb_urb_completion(urb);
41560
41561 error:
41562 - atomic_add(bytes_sent, &dev->bytes_sent);
41563 - atomic_add(bytes_identical, &dev->bytes_identical);
41564 - atomic_add(width*height*2, &dev->bytes_rendered);
41565 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41566 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41567 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
41568 end_cycles = get_cycles();
41569 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41570 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41571 >> 10)), /* Kcycles */
41572 &dev->cpu_kcycles_used);
41573
41574 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
41575 dlfb_urb_completion(urb);
41576
41577 error:
41578 - atomic_add(bytes_sent, &dev->bytes_sent);
41579 - atomic_add(bytes_identical, &dev->bytes_identical);
41580 - atomic_add(bytes_rendered, &dev->bytes_rendered);
41581 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
41582 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
41583 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
41584 end_cycles = get_cycles();
41585 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
41586 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
41587 >> 10)), /* Kcycles */
41588 &dev->cpu_kcycles_used);
41589 }
41590 @@ -1371,7 +1371,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
41591 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41592 struct dlfb_data *dev = fb_info->par;
41593 return snprintf(buf, PAGE_SIZE, "%u\n",
41594 - atomic_read(&dev->bytes_rendered));
41595 + atomic_read_unchecked(&dev->bytes_rendered));
41596 }
41597
41598 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41599 @@ -1379,7 +1379,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
41600 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41601 struct dlfb_data *dev = fb_info->par;
41602 return snprintf(buf, PAGE_SIZE, "%u\n",
41603 - atomic_read(&dev->bytes_identical));
41604 + atomic_read_unchecked(&dev->bytes_identical));
41605 }
41606
41607 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41608 @@ -1387,7 +1387,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
41609 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41610 struct dlfb_data *dev = fb_info->par;
41611 return snprintf(buf, PAGE_SIZE, "%u\n",
41612 - atomic_read(&dev->bytes_sent));
41613 + atomic_read_unchecked(&dev->bytes_sent));
41614 }
41615
41616 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41617 @@ -1395,7 +1395,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
41618 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41619 struct dlfb_data *dev = fb_info->par;
41620 return snprintf(buf, PAGE_SIZE, "%u\n",
41621 - atomic_read(&dev->cpu_kcycles_used));
41622 + atomic_read_unchecked(&dev->cpu_kcycles_used));
41623 }
41624
41625 static ssize_t edid_show(
41626 @@ -1452,10 +1452,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
41627 struct fb_info *fb_info = dev_get_drvdata(fbdev);
41628 struct dlfb_data *dev = fb_info->par;
41629
41630 - atomic_set(&dev->bytes_rendered, 0);
41631 - atomic_set(&dev->bytes_identical, 0);
41632 - atomic_set(&dev->bytes_sent, 0);
41633 - atomic_set(&dev->cpu_kcycles_used, 0);
41634 + atomic_set_unchecked(&dev->bytes_rendered, 0);
41635 + atomic_set_unchecked(&dev->bytes_identical, 0);
41636 + atomic_set_unchecked(&dev->bytes_sent, 0);
41637 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
41638
41639 return count;
41640 }
41641 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
41642 index 8408543..d6f20f1 100644
41643 --- a/drivers/video/uvesafb.c
41644 +++ b/drivers/video/uvesafb.c
41645 @@ -19,6 +19,7 @@
41646 #include <linux/io.h>
41647 #include <linux/mutex.h>
41648 #include <linux/slab.h>
41649 +#include <linux/moduleloader.h>
41650 #include <video/edid.h>
41651 #include <video/uvesafb.h>
41652 #ifdef CONFIG_X86
41653 @@ -73,7 +74,7 @@ static void uvesafb_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *ns
41654 struct uvesafb_task *utask;
41655 struct uvesafb_ktask *task;
41656
41657 - if (!cap_raised(current_cap(), CAP_SYS_ADMIN))
41658 + if (!capable(CAP_SYS_ADMIN))
41659 return;
41660
41661 if (msg->seq >= UVESAFB_TASKS_MAX)
41662 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
41663 NULL,
41664 };
41665
41666 - return call_usermodehelper(v86d_path, argv, envp, 1);
41667 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
41668 }
41669
41670 /*
41671 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
41672 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
41673 par->pmi_setpal = par->ypan = 0;
41674 } else {
41675 +
41676 +#ifdef CONFIG_PAX_KERNEXEC
41677 +#ifdef CONFIG_MODULES
41678 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
41679 +#endif
41680 + if (!par->pmi_code) {
41681 + par->pmi_setpal = par->ypan = 0;
41682 + return 0;
41683 + }
41684 +#endif
41685 +
41686 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
41687 + task->t.regs.edi);
41688 +
41689 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41690 + pax_open_kernel();
41691 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
41692 + pax_close_kernel();
41693 +
41694 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
41695 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
41696 +#else
41697 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
41698 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
41699 +#endif
41700 +
41701 printk(KERN_INFO "uvesafb: protected mode interface info at "
41702 "%04x:%04x\n",
41703 (u16)task->t.regs.es, (u16)task->t.regs.edi);
41704 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
41705 par->ypan = ypan;
41706
41707 if (par->pmi_setpal || par->ypan) {
41708 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
41709 if (__supported_pte_mask & _PAGE_NX) {
41710 par->pmi_setpal = par->ypan = 0;
41711 printk(KERN_WARNING "uvesafb: NX protection is actively."
41712 "We have better not to use the PMI.\n");
41713 - } else {
41714 + } else
41715 +#endif
41716 uvesafb_vbe_getpmi(task, par);
41717 - }
41718 }
41719 #else
41720 /* The protected mode interface is not available on non-x86. */
41721 @@ -1828,6 +1852,11 @@ out:
41722 if (par->vbe_modes)
41723 kfree(par->vbe_modes);
41724
41725 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41726 + if (par->pmi_code)
41727 + module_free_exec(NULL, par->pmi_code);
41728 +#endif
41729 +
41730 framebuffer_release(info);
41731 return err;
41732 }
41733 @@ -1854,6 +1883,12 @@ static int uvesafb_remove(struct platform_device *dev)
41734 kfree(par->vbe_state_orig);
41735 if (par->vbe_state_saved)
41736 kfree(par->vbe_state_saved);
41737 +
41738 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41739 + if (par->pmi_code)
41740 + module_free_exec(NULL, par->pmi_code);
41741 +#endif
41742 +
41743 }
41744
41745 framebuffer_release(info);
41746 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
41747 index 501b340..86bd4cf 100644
41748 --- a/drivers/video/vesafb.c
41749 +++ b/drivers/video/vesafb.c
41750 @@ -9,6 +9,7 @@
41751 */
41752
41753 #include <linux/module.h>
41754 +#include <linux/moduleloader.h>
41755 #include <linux/kernel.h>
41756 #include <linux/errno.h>
41757 #include <linux/string.h>
41758 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
41759 static int vram_total __initdata; /* Set total amount of memory */
41760 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
41761 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
41762 -static void (*pmi_start)(void) __read_mostly;
41763 -static void (*pmi_pal) (void) __read_mostly;
41764 +static void (*pmi_start)(void) __read_only;
41765 +static void (*pmi_pal) (void) __read_only;
41766 static int depth __read_mostly;
41767 static int vga_compat __read_mostly;
41768 /* --------------------------------------------------------------------- */
41769 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
41770 unsigned int size_vmode;
41771 unsigned int size_remap;
41772 unsigned int size_total;
41773 + void *pmi_code = NULL;
41774
41775 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
41776 return -ENODEV;
41777 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
41778 size_remap = size_total;
41779 vesafb_fix.smem_len = size_remap;
41780
41781 -#ifndef __i386__
41782 - screen_info.vesapm_seg = 0;
41783 -#endif
41784 -
41785 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
41786 printk(KERN_WARNING
41787 "vesafb: cannot reserve video memory at 0x%lx\n",
41788 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
41789 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
41790 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
41791
41792 +#ifdef __i386__
41793 +
41794 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41795 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
41796 + if (!pmi_code)
41797 +#elif !defined(CONFIG_PAX_KERNEXEC)
41798 + if (0)
41799 +#endif
41800 +
41801 +#endif
41802 + screen_info.vesapm_seg = 0;
41803 +
41804 if (screen_info.vesapm_seg) {
41805 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
41806 - screen_info.vesapm_seg,screen_info.vesapm_off);
41807 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
41808 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
41809 }
41810
41811 if (screen_info.vesapm_seg < 0xc000)
41812 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
41813
41814 if (ypan || pmi_setpal) {
41815 unsigned short *pmi_base;
41816 +
41817 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
41818 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
41819 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
41820 +
41821 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41822 + pax_open_kernel();
41823 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
41824 +#else
41825 + pmi_code = pmi_base;
41826 +#endif
41827 +
41828 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
41829 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
41830 +
41831 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41832 + pmi_start = ktva_ktla(pmi_start);
41833 + pmi_pal = ktva_ktla(pmi_pal);
41834 + pax_close_kernel();
41835 +#endif
41836 +
41837 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
41838 if (pmi_base[3]) {
41839 printk(KERN_INFO "vesafb: pmi: ports = ");
41840 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
41841 info->node, info->fix.id);
41842 return 0;
41843 err:
41844 +
41845 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
41846 + module_free_exec(NULL, pmi_code);
41847 +#endif
41848 +
41849 if (info->screen_base)
41850 iounmap(info->screen_base);
41851 framebuffer_release(info);
41852 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
41853 index 88714ae..16c2e11 100644
41854 --- a/drivers/video/via/via_clock.h
41855 +++ b/drivers/video/via/via_clock.h
41856 @@ -56,7 +56,7 @@ struct via_clock {
41857
41858 void (*set_engine_pll_state)(u8 state);
41859 void (*set_engine_pll)(struct via_pll_config config);
41860 -};
41861 +} __no_const;
41862
41863
41864 static inline u32 get_pll_internal_frequency(u32 ref_freq,
41865 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
41866 index e56c934..fc22f4b 100644
41867 --- a/drivers/xen/xen-pciback/conf_space.h
41868 +++ b/drivers/xen/xen-pciback/conf_space.h
41869 @@ -44,15 +44,15 @@ struct config_field {
41870 struct {
41871 conf_dword_write write;
41872 conf_dword_read read;
41873 - } dw;
41874 + } __no_const dw;
41875 struct {
41876 conf_word_write write;
41877 conf_word_read read;
41878 - } w;
41879 + } __no_const w;
41880 struct {
41881 conf_byte_write write;
41882 conf_byte_read read;
41883 - } b;
41884 + } __no_const b;
41885 } u;
41886 struct list_head list;
41887 };
41888 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
41889 index 014c8dd..6f3dfe6 100644
41890 --- a/fs/9p/vfs_inode.c
41891 +++ b/fs/9p/vfs_inode.c
41892 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41893 void
41894 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41895 {
41896 - char *s = nd_get_link(nd);
41897 + const char *s = nd_get_link(nd);
41898
41899 p9_debug(P9_DEBUG_VFS, " %s %s\n",
41900 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
41901 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
41902 index e95d1b6..3454244 100644
41903 --- a/fs/Kconfig.binfmt
41904 +++ b/fs/Kconfig.binfmt
41905 @@ -89,7 +89,7 @@ config HAVE_AOUT
41906
41907 config BINFMT_AOUT
41908 tristate "Kernel support for a.out and ECOFF binaries"
41909 - depends on HAVE_AOUT
41910 + depends on HAVE_AOUT && BROKEN
41911 ---help---
41912 A.out (Assembler.OUTput) is a set of formats for libraries and
41913 executables used in the earliest versions of UNIX. Linux used
41914 diff --git a/fs/aio.c b/fs/aio.c
41915 index 3b65ee7..aa6ec34 100644
41916 --- a/fs/aio.c
41917 +++ b/fs/aio.c
41918 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
41919 size += sizeof(struct io_event) * nr_events;
41920 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
41921
41922 - if (nr_pages < 0)
41923 + if (nr_pages <= 0)
41924 return -EINVAL;
41925
41926 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
41927 @@ -1461,18 +1461,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
41928 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41929 {
41930 ssize_t ret;
41931 + struct iovec iovstack;
41932
41933 #ifdef CONFIG_COMPAT
41934 if (compat)
41935 ret = compat_rw_copy_check_uvector(type,
41936 (struct compat_iovec __user *)kiocb->ki_buf,
41937 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41938 + kiocb->ki_nbytes, 1, &iovstack,
41939 &kiocb->ki_iovec, 1);
41940 else
41941 #endif
41942 ret = rw_copy_check_uvector(type,
41943 (struct iovec __user *)kiocb->ki_buf,
41944 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
41945 + kiocb->ki_nbytes, 1, &iovstack,
41946 &kiocb->ki_iovec, 1);
41947 if (ret < 0)
41948 goto out;
41949 @@ -1481,6 +1482,11 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
41950 if (ret < 0)
41951 goto out;
41952
41953 + if (kiocb->ki_iovec == &iovstack) {
41954 + kiocb->ki_inline_vec = iovstack;
41955 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
41956 + }
41957 +
41958 kiocb->ki_nr_segs = kiocb->ki_nbytes;
41959 kiocb->ki_cur_seg = 0;
41960 /* ki_nbytes/left now reflect bytes instead of segs */
41961 diff --git a/fs/attr.c b/fs/attr.c
41962 index 95053ad..2cc93ca 100644
41963 --- a/fs/attr.c
41964 +++ b/fs/attr.c
41965 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
41966 unsigned long limit;
41967
41968 limit = rlimit(RLIMIT_FSIZE);
41969 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
41970 if (limit != RLIM_INFINITY && offset > limit)
41971 goto out_sig;
41972 if (offset > inode->i_sb->s_maxbytes)
41973 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
41974 index f624cd0..3d9a559 100644
41975 --- a/fs/autofs4/waitq.c
41976 +++ b/fs/autofs4/waitq.c
41977 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
41978 {
41979 unsigned long sigpipe, flags;
41980 mm_segment_t fs;
41981 - const char *data = (const char *)addr;
41982 + const char __user *data = (const char __force_user *)addr;
41983 ssize_t wr = 0;
41984
41985 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
41986 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
41987 index 6e6d536..457113a 100644
41988 --- a/fs/befs/linuxvfs.c
41989 +++ b/fs/befs/linuxvfs.c
41990 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
41991 {
41992 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
41993 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
41994 - char *link = nd_get_link(nd);
41995 + const char *link = nd_get_link(nd);
41996 if (!IS_ERR(link))
41997 kfree(link);
41998 }
41999 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42000 index 1ff9405..f1e376a 100644
42001 --- a/fs/binfmt_aout.c
42002 +++ b/fs/binfmt_aout.c
42003 @@ -16,6 +16,7 @@
42004 #include <linux/string.h>
42005 #include <linux/fs.h>
42006 #include <linux/file.h>
42007 +#include <linux/security.h>
42008 #include <linux/stat.h>
42009 #include <linux/fcntl.h>
42010 #include <linux/ptrace.h>
42011 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42012 #endif
42013 # define START_STACK(u) ((void __user *)u.start_stack)
42014
42015 + memset(&dump, 0, sizeof(dump));
42016 +
42017 fs = get_fs();
42018 set_fs(KERNEL_DS);
42019 has_dumped = 1;
42020 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42021
42022 /* If the size of the dump file exceeds the rlimit, then see what would happen
42023 if we wrote the stack, but not the data area. */
42024 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42025 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42026 dump.u_dsize = 0;
42027
42028 /* Make sure we have enough room to write the stack and data areas. */
42029 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42030 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42031 dump.u_ssize = 0;
42032
42033 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42034 rlim = rlimit(RLIMIT_DATA);
42035 if (rlim >= RLIM_INFINITY)
42036 rlim = ~0;
42037 +
42038 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42039 if (ex.a_data + ex.a_bss > rlim)
42040 return -ENOMEM;
42041
42042 @@ -269,6 +276,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42043 install_exec_creds(bprm);
42044 current->flags &= ~PF_FORKNOEXEC;
42045
42046 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42047 + current->mm->pax_flags = 0UL;
42048 +#endif
42049 +
42050 +#ifdef CONFIG_PAX_PAGEEXEC
42051 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42052 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42053 +
42054 +#ifdef CONFIG_PAX_EMUTRAMP
42055 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42056 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42057 +#endif
42058 +
42059 +#ifdef CONFIG_PAX_MPROTECT
42060 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42061 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42062 +#endif
42063 +
42064 + }
42065 +#endif
42066 +
42067 if (N_MAGIC(ex) == OMAGIC) {
42068 unsigned long text_addr, map_size;
42069 loff_t pos;
42070 @@ -341,7 +369,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42071
42072 down_write(&current->mm->mmap_sem);
42073 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42074 - PROT_READ | PROT_WRITE | PROT_EXEC,
42075 + PROT_READ | PROT_WRITE,
42076 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42077 fd_offset + ex.a_text);
42078 up_write(&current->mm->mmap_sem);
42079 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42080 index 07d096c..25762af 100644
42081 --- a/fs/binfmt_elf.c
42082 +++ b/fs/binfmt_elf.c
42083 @@ -32,6 +32,7 @@
42084 #include <linux/elf.h>
42085 #include <linux/utsname.h>
42086 #include <linux/coredump.h>
42087 +#include <linux/xattr.h>
42088 #include <asm/uaccess.h>
42089 #include <asm/param.h>
42090 #include <asm/page.h>
42091 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42092 #define elf_core_dump NULL
42093 #endif
42094
42095 +#ifdef CONFIG_PAX_MPROTECT
42096 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42097 +#endif
42098 +
42099 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42100 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42101 #else
42102 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
42103 .load_binary = load_elf_binary,
42104 .load_shlib = load_elf_library,
42105 .core_dump = elf_core_dump,
42106 +
42107 +#ifdef CONFIG_PAX_MPROTECT
42108 + .handle_mprotect= elf_handle_mprotect,
42109 +#endif
42110 +
42111 .min_coredump = ELF_EXEC_PAGESIZE,
42112 };
42113
42114 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
42115
42116 static int set_brk(unsigned long start, unsigned long end)
42117 {
42118 + unsigned long e = end;
42119 +
42120 start = ELF_PAGEALIGN(start);
42121 end = ELF_PAGEALIGN(end);
42122 if (end > start) {
42123 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
42124 if (BAD_ADDR(addr))
42125 return addr;
42126 }
42127 - current->mm->start_brk = current->mm->brk = end;
42128 + current->mm->start_brk = current->mm->brk = e;
42129 return 0;
42130 }
42131
42132 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42133 elf_addr_t __user *u_rand_bytes;
42134 const char *k_platform = ELF_PLATFORM;
42135 const char *k_base_platform = ELF_BASE_PLATFORM;
42136 - unsigned char k_rand_bytes[16];
42137 + u32 k_rand_bytes[4];
42138 int items;
42139 elf_addr_t *elf_info;
42140 int ei_index = 0;
42141 const struct cred *cred = current_cred();
42142 struct vm_area_struct *vma;
42143 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42144
42145 /*
42146 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42147 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42148 * Generate 16 random bytes for userspace PRNG seeding.
42149 */
42150 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42151 - u_rand_bytes = (elf_addr_t __user *)
42152 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42153 + srandom32(k_rand_bytes[0] ^ random32());
42154 + srandom32(k_rand_bytes[1] ^ random32());
42155 + srandom32(k_rand_bytes[2] ^ random32());
42156 + srandom32(k_rand_bytes[3] ^ random32());
42157 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42158 + u_rand_bytes = (elf_addr_t __user *) p;
42159 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42160 return -EFAULT;
42161
42162 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42163 return -EFAULT;
42164 current->mm->env_end = p;
42165
42166 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42167 +
42168 /* Put the elf_info on the stack in the right place. */
42169 sp = (elf_addr_t __user *)envp + 1;
42170 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42171 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42172 return -EFAULT;
42173 return 0;
42174 }
42175 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42176 {
42177 struct elf_phdr *elf_phdata;
42178 struct elf_phdr *eppnt;
42179 - unsigned long load_addr = 0;
42180 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42181 int load_addr_set = 0;
42182 unsigned long last_bss = 0, elf_bss = 0;
42183 - unsigned long error = ~0UL;
42184 + unsigned long error = -EINVAL;
42185 unsigned long total_size;
42186 int retval, i, size;
42187
42188 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42189 goto out_close;
42190 }
42191
42192 +#ifdef CONFIG_PAX_SEGMEXEC
42193 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42194 + pax_task_size = SEGMEXEC_TASK_SIZE;
42195 +#endif
42196 +
42197 eppnt = elf_phdata;
42198 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42199 if (eppnt->p_type == PT_LOAD) {
42200 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42201 k = load_addr + eppnt->p_vaddr;
42202 if (BAD_ADDR(k) ||
42203 eppnt->p_filesz > eppnt->p_memsz ||
42204 - eppnt->p_memsz > TASK_SIZE ||
42205 - TASK_SIZE - eppnt->p_memsz < k) {
42206 + eppnt->p_memsz > pax_task_size ||
42207 + pax_task_size - eppnt->p_memsz < k) {
42208 error = -ENOMEM;
42209 goto out_close;
42210 }
42211 @@ -528,6 +552,351 @@ out:
42212 return error;
42213 }
42214
42215 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42216 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42217 +{
42218 + unsigned long pax_flags = 0UL;
42219 +
42220 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42221 +
42222 +#ifdef CONFIG_PAX_PAGEEXEC
42223 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42224 + pax_flags |= MF_PAX_PAGEEXEC;
42225 +#endif
42226 +
42227 +#ifdef CONFIG_PAX_SEGMEXEC
42228 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42229 + pax_flags |= MF_PAX_SEGMEXEC;
42230 +#endif
42231 +
42232 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42233 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42234 + if ((__supported_pte_mask & _PAGE_NX))
42235 + pax_flags &= ~MF_PAX_SEGMEXEC;
42236 + else
42237 + pax_flags &= ~MF_PAX_PAGEEXEC;
42238 + }
42239 +#endif
42240 +
42241 +#ifdef CONFIG_PAX_EMUTRAMP
42242 + if (elf_phdata->p_flags & PF_EMUTRAMP)
42243 + pax_flags |= MF_PAX_EMUTRAMP;
42244 +#endif
42245 +
42246 +#ifdef CONFIG_PAX_MPROTECT
42247 + if (elf_phdata->p_flags & PF_MPROTECT)
42248 + pax_flags |= MF_PAX_MPROTECT;
42249 +#endif
42250 +
42251 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42252 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42253 + pax_flags |= MF_PAX_RANDMMAP;
42254 +#endif
42255 +
42256 +#endif
42257 +
42258 + return pax_flags;
42259 +}
42260 +
42261 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42262 +{
42263 + unsigned long pax_flags = 0UL;
42264 +
42265 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42266 +
42267 +#ifdef CONFIG_PAX_PAGEEXEC
42268 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42269 + pax_flags |= MF_PAX_PAGEEXEC;
42270 +#endif
42271 +
42272 +#ifdef CONFIG_PAX_SEGMEXEC
42273 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
42274 + pax_flags |= MF_PAX_SEGMEXEC;
42275 +#endif
42276 +
42277 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42278 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42279 + if ((__supported_pte_mask & _PAGE_NX))
42280 + pax_flags &= ~MF_PAX_SEGMEXEC;
42281 + else
42282 + pax_flags &= ~MF_PAX_PAGEEXEC;
42283 + }
42284 +#endif
42285 +
42286 +#ifdef CONFIG_PAX_EMUTRAMP
42287 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
42288 + pax_flags |= MF_PAX_EMUTRAMP;
42289 +#endif
42290 +
42291 +#ifdef CONFIG_PAX_MPROTECT
42292 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
42293 + pax_flags |= MF_PAX_MPROTECT;
42294 +#endif
42295 +
42296 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42297 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
42298 + pax_flags |= MF_PAX_RANDMMAP;
42299 +#endif
42300 +
42301 +#endif
42302 +
42303 + return pax_flags;
42304 +}
42305 +
42306 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
42307 +{
42308 + unsigned long pax_flags = 0UL;
42309 +
42310 +#ifdef CONFIG_PAX_EI_PAX
42311 +
42312 +#ifdef CONFIG_PAX_PAGEEXEC
42313 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
42314 + pax_flags |= MF_PAX_PAGEEXEC;
42315 +#endif
42316 +
42317 +#ifdef CONFIG_PAX_SEGMEXEC
42318 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
42319 + pax_flags |= MF_PAX_SEGMEXEC;
42320 +#endif
42321 +
42322 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42323 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42324 + if ((__supported_pte_mask & _PAGE_NX))
42325 + pax_flags &= ~MF_PAX_SEGMEXEC;
42326 + else
42327 + pax_flags &= ~MF_PAX_PAGEEXEC;
42328 + }
42329 +#endif
42330 +
42331 +#ifdef CONFIG_PAX_EMUTRAMP
42332 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
42333 + pax_flags |= MF_PAX_EMUTRAMP;
42334 +#endif
42335 +
42336 +#ifdef CONFIG_PAX_MPROTECT
42337 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
42338 + pax_flags |= MF_PAX_MPROTECT;
42339 +#endif
42340 +
42341 +#ifdef CONFIG_PAX_ASLR
42342 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
42343 + pax_flags |= MF_PAX_RANDMMAP;
42344 +#endif
42345 +
42346 +#else
42347 +
42348 +#ifdef CONFIG_PAX_PAGEEXEC
42349 + pax_flags |= MF_PAX_PAGEEXEC;
42350 +#endif
42351 +
42352 +#ifdef CONFIG_PAX_MPROTECT
42353 + pax_flags |= MF_PAX_MPROTECT;
42354 +#endif
42355 +
42356 +#ifdef CONFIG_PAX_RANDMMAP
42357 + pax_flags |= MF_PAX_RANDMMAP;
42358 +#endif
42359 +
42360 +#ifdef CONFIG_PAX_SEGMEXEC
42361 + if (!(pax_flags & MF_PAX_PAGEEXEC) || !(__supported_pte_mask & _PAGE_NX)) {
42362 + pax_flags &= ~MF_PAX_PAGEEXEC;
42363 + pax_flags |= MF_PAX_SEGMEXEC;
42364 + }
42365 +#endif
42366 +
42367 +#endif
42368 +
42369 + return pax_flags;
42370 +}
42371 +
42372 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
42373 +{
42374 +
42375 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42376 + unsigned long i;
42377 +
42378 + for (i = 0UL; i < elf_ex->e_phnum; i++)
42379 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
42380 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
42381 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
42382 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
42383 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
42384 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
42385 + return ~0UL;
42386 +
42387 +#ifdef CONFIG_PAX_SOFTMODE
42388 + if (pax_softmode)
42389 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
42390 + else
42391 +#endif
42392 +
42393 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
42394 + break;
42395 + }
42396 +#endif
42397 +
42398 + return ~0UL;
42399 +}
42400 +
42401 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42402 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
42403 +{
42404 + unsigned long pax_flags = 0UL;
42405 +
42406 +#ifdef CONFIG_PAX_PAGEEXEC
42407 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
42408 + pax_flags |= MF_PAX_PAGEEXEC;
42409 +#endif
42410 +
42411 +#ifdef CONFIG_PAX_SEGMEXEC
42412 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
42413 + pax_flags |= MF_PAX_SEGMEXEC;
42414 +#endif
42415 +
42416 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42417 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42418 + if ((__supported_pte_mask & _PAGE_NX))
42419 + pax_flags &= ~MF_PAX_SEGMEXEC;
42420 + else
42421 + pax_flags &= ~MF_PAX_PAGEEXEC;
42422 + }
42423 +#endif
42424 +
42425 +#ifdef CONFIG_PAX_EMUTRAMP
42426 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
42427 + pax_flags |= MF_PAX_EMUTRAMP;
42428 +#endif
42429 +
42430 +#ifdef CONFIG_PAX_MPROTECT
42431 + if (pax_flags_softmode & MF_PAX_MPROTECT)
42432 + pax_flags |= MF_PAX_MPROTECT;
42433 +#endif
42434 +
42435 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42436 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
42437 + pax_flags |= MF_PAX_RANDMMAP;
42438 +#endif
42439 +
42440 + return pax_flags;
42441 +}
42442 +
42443 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
42444 +{
42445 + unsigned long pax_flags = 0UL;
42446 +
42447 +#ifdef CONFIG_PAX_PAGEEXEC
42448 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
42449 + pax_flags |= MF_PAX_PAGEEXEC;
42450 +#endif
42451 +
42452 +#ifdef CONFIG_PAX_SEGMEXEC
42453 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
42454 + pax_flags |= MF_PAX_SEGMEXEC;
42455 +#endif
42456 +
42457 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
42458 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42459 + if ((__supported_pte_mask & _PAGE_NX))
42460 + pax_flags &= ~MF_PAX_SEGMEXEC;
42461 + else
42462 + pax_flags &= ~MF_PAX_PAGEEXEC;
42463 + }
42464 +#endif
42465 +
42466 +#ifdef CONFIG_PAX_EMUTRAMP
42467 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
42468 + pax_flags |= MF_PAX_EMUTRAMP;
42469 +#endif
42470 +
42471 +#ifdef CONFIG_PAX_MPROTECT
42472 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
42473 + pax_flags |= MF_PAX_MPROTECT;
42474 +#endif
42475 +
42476 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42477 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
42478 + pax_flags |= MF_PAX_RANDMMAP;
42479 +#endif
42480 +
42481 + return pax_flags;
42482 +}
42483 +#endif
42484 +
42485 +static unsigned long pax_parse_xattr_pax(struct file * const file)
42486 +{
42487 +
42488 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
42489 + ssize_t xattr_size, i;
42490 + unsigned char xattr_value[5];
42491 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
42492 +
42493 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
42494 + if (xattr_size <= 0)
42495 + return ~0UL;
42496 +
42497 + for (i = 0; i < xattr_size; i++)
42498 + switch (xattr_value[i]) {
42499 + default:
42500 + return ~0UL;
42501 +
42502 +#define parse_flag(option1, option2, flag) \
42503 + case option1: \
42504 + pax_flags_hardmode |= MF_PAX_##flag; \
42505 + break; \
42506 + case option2: \
42507 + pax_flags_softmode |= MF_PAX_##flag; \
42508 + break;
42509 +
42510 + parse_flag('p', 'P', PAGEEXEC);
42511 + parse_flag('e', 'E', EMUTRAMP);
42512 + parse_flag('m', 'M', MPROTECT);
42513 + parse_flag('r', 'R', RANDMMAP);
42514 + parse_flag('s', 'S', SEGMEXEC);
42515 +
42516 +#undef parse_flag
42517 + }
42518 +
42519 + if (pax_flags_hardmode & pax_flags_softmode)
42520 + return ~0UL;
42521 +
42522 +#ifdef CONFIG_PAX_SOFTMODE
42523 + if (pax_softmode)
42524 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
42525 + else
42526 +#endif
42527 +
42528 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
42529 +#else
42530 + return ~0UL;
42531 +#endif
42532 +
42533 +}
42534 +
42535 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
42536 +{
42537 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
42538 +
42539 + pax_flags = pax_parse_ei_pax(elf_ex);
42540 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
42541 + xattr_pax_flags = pax_parse_xattr_pax(file);
42542 +
42543 + if (pt_pax_flags == ~0UL)
42544 + pt_pax_flags = xattr_pax_flags;
42545 + else if (xattr_pax_flags == ~0UL)
42546 + xattr_pax_flags = pt_pax_flags;
42547 + if (pt_pax_flags != xattr_pax_flags)
42548 + return -EINVAL;
42549 + if (pt_pax_flags != ~0UL)
42550 + pax_flags = pt_pax_flags;
42551 +
42552 + if (0 > pax_check_flags(&pax_flags))
42553 + return -EINVAL;
42554 +
42555 + current->mm->pax_flags = pax_flags;
42556 + return 0;
42557 +}
42558 +#endif
42559 +
42560 /*
42561 * These are the functions used to load ELF style executables and shared
42562 * libraries. There is no binary dependent code anywhere else.
42563 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
42564 {
42565 unsigned int random_variable = 0;
42566
42567 +#ifdef CONFIG_PAX_RANDUSTACK
42568 + if (randomize_va_space)
42569 + return stack_top - current->mm->delta_stack;
42570 +#endif
42571 +
42572 if ((current->flags & PF_RANDOMIZE) &&
42573 !(current->personality & ADDR_NO_RANDOMIZE)) {
42574 random_variable = get_random_int() & STACK_RND_MASK;
42575 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42576 unsigned long load_addr = 0, load_bias = 0;
42577 int load_addr_set = 0;
42578 char * elf_interpreter = NULL;
42579 - unsigned long error;
42580 + unsigned long error = 0;
42581 struct elf_phdr *elf_ppnt, *elf_phdata;
42582 unsigned long elf_bss, elf_brk;
42583 int retval, i;
42584 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42585 unsigned long start_code, end_code, start_data, end_data;
42586 unsigned long reloc_func_desc __maybe_unused = 0;
42587 int executable_stack = EXSTACK_DEFAULT;
42588 - unsigned long def_flags = 0;
42589 struct {
42590 struct elfhdr elf_ex;
42591 struct elfhdr interp_elf_ex;
42592 } *loc;
42593 + unsigned long pax_task_size = TASK_SIZE;
42594
42595 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
42596 if (!loc) {
42597 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42598
42599 /* OK, This is the point of no return */
42600 current->flags &= ~PF_FORKNOEXEC;
42601 - current->mm->def_flags = def_flags;
42602 +
42603 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42604 + current->mm->pax_flags = 0UL;
42605 +#endif
42606 +
42607 +#ifdef CONFIG_PAX_DLRESOLVE
42608 + current->mm->call_dl_resolve = 0UL;
42609 +#endif
42610 +
42611 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
42612 + current->mm->call_syscall = 0UL;
42613 +#endif
42614 +
42615 +#ifdef CONFIG_PAX_ASLR
42616 + current->mm->delta_mmap = 0UL;
42617 + current->mm->delta_stack = 0UL;
42618 +#endif
42619 +
42620 + current->mm->def_flags = 0;
42621 +
42622 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
42623 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
42624 + send_sig(SIGKILL, current, 0);
42625 + goto out_free_dentry;
42626 + }
42627 +#endif
42628 +
42629 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
42630 + pax_set_initial_flags(bprm);
42631 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
42632 + if (pax_set_initial_flags_func)
42633 + (pax_set_initial_flags_func)(bprm);
42634 +#endif
42635 +
42636 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
42637 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
42638 + current->mm->context.user_cs_limit = PAGE_SIZE;
42639 + current->mm->def_flags |= VM_PAGEEXEC;
42640 + }
42641 +#endif
42642 +
42643 +#ifdef CONFIG_PAX_SEGMEXEC
42644 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
42645 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
42646 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
42647 + pax_task_size = SEGMEXEC_TASK_SIZE;
42648 + current->mm->def_flags |= VM_NOHUGEPAGE;
42649 + }
42650 +#endif
42651 +
42652 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
42653 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42654 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
42655 + put_cpu();
42656 + }
42657 +#endif
42658
42659 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
42660 may depend on the personality. */
42661 SET_PERSONALITY(loc->elf_ex);
42662 +
42663 +#ifdef CONFIG_PAX_ASLR
42664 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42665 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
42666 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
42667 + }
42668 +#endif
42669 +
42670 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42671 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
42672 + executable_stack = EXSTACK_DISABLE_X;
42673 + current->personality &= ~READ_IMPLIES_EXEC;
42674 + } else
42675 +#endif
42676 +
42677 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
42678 current->personality |= READ_IMPLIES_EXEC;
42679
42680 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42681 #else
42682 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
42683 #endif
42684 +
42685 +#ifdef CONFIG_PAX_RANDMMAP
42686 + /* PaX: randomize base address at the default exe base if requested */
42687 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
42688 +#ifdef CONFIG_SPARC64
42689 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
42690 +#else
42691 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
42692 +#endif
42693 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
42694 + elf_flags |= MAP_FIXED;
42695 + }
42696 +#endif
42697 +
42698 }
42699
42700 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
42701 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42702 * allowed task size. Note that p_filesz must always be
42703 * <= p_memsz so it is only necessary to check p_memsz.
42704 */
42705 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42706 - elf_ppnt->p_memsz > TASK_SIZE ||
42707 - TASK_SIZE - elf_ppnt->p_memsz < k) {
42708 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
42709 + elf_ppnt->p_memsz > pax_task_size ||
42710 + pax_task_size - elf_ppnt->p_memsz < k) {
42711 /* set_brk can never work. Avoid overflows. */
42712 send_sig(SIGKILL, current, 0);
42713 retval = -EINVAL;
42714 @@ -881,11 +1339,40 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
42715 goto out_free_dentry;
42716 }
42717 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
42718 - send_sig(SIGSEGV, current, 0);
42719 - retval = -EFAULT; /* Nobody gets to see this, but.. */
42720 - goto out_free_dentry;
42721 + /*
42722 + * This bss-zeroing can fail if the ELF
42723 + * file specifies odd protections. So
42724 + * we don't check the return value
42725 + */
42726 }
42727
42728 +#ifdef CONFIG_PAX_RANDMMAP
42729 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
42730 + unsigned long start, size;
42731 +
42732 + start = ELF_PAGEALIGN(elf_brk);
42733 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
42734 + down_write(&current->mm->mmap_sem);
42735 + retval = -ENOMEM;
42736 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
42737 + unsigned long prot = PROT_NONE;
42738 +
42739 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
42740 +// if (current->personality & ADDR_NO_RANDOMIZE)
42741 +// prot = PROT_READ;
42742 + start = do_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
42743 + retval = IS_ERR_VALUE(start) ? start : 0;
42744 + }
42745 + up_write(&current->mm->mmap_sem);
42746 + if (retval == 0)
42747 + retval = set_brk(start + size, start + size + PAGE_SIZE);
42748 + if (retval < 0) {
42749 + send_sig(SIGKILL, current, 0);
42750 + goto out_free_dentry;
42751 + }
42752 + }
42753 +#endif
42754 +
42755 if (elf_interpreter) {
42756 unsigned long uninitialized_var(interp_map_addr);
42757
42758 @@ -1098,7 +1585,7 @@ out:
42759 * Decide what to dump of a segment, part, all or none.
42760 */
42761 static unsigned long vma_dump_size(struct vm_area_struct *vma,
42762 - unsigned long mm_flags)
42763 + unsigned long mm_flags, long signr)
42764 {
42765 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
42766
42767 @@ -1132,7 +1619,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
42768 if (vma->vm_file == NULL)
42769 return 0;
42770
42771 - if (FILTER(MAPPED_PRIVATE))
42772 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
42773 goto whole;
42774
42775 /*
42776 @@ -1354,9 +1841,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
42777 {
42778 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
42779 int i = 0;
42780 - do
42781 + do {
42782 i += 2;
42783 - while (auxv[i - 2] != AT_NULL);
42784 + } while (auxv[i - 2] != AT_NULL);
42785 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
42786 }
42787
42788 @@ -1862,14 +2349,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
42789 }
42790
42791 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
42792 - unsigned long mm_flags)
42793 + struct coredump_params *cprm)
42794 {
42795 struct vm_area_struct *vma;
42796 size_t size = 0;
42797
42798 for (vma = first_vma(current, gate_vma); vma != NULL;
42799 vma = next_vma(vma, gate_vma))
42800 - size += vma_dump_size(vma, mm_flags);
42801 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42802 return size;
42803 }
42804
42805 @@ -1963,7 +2450,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42806
42807 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
42808
42809 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
42810 + offset += elf_core_vma_data_size(gate_vma, cprm);
42811 offset += elf_core_extra_data_size();
42812 e_shoff = offset;
42813
42814 @@ -1977,10 +2464,12 @@ static int elf_core_dump(struct coredump_params *cprm)
42815 offset = dataoff;
42816
42817 size += sizeof(*elf);
42818 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42819 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
42820 goto end_coredump;
42821
42822 size += sizeof(*phdr4note);
42823 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42824 if (size > cprm->limit
42825 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
42826 goto end_coredump;
42827 @@ -1994,7 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42828 phdr.p_offset = offset;
42829 phdr.p_vaddr = vma->vm_start;
42830 phdr.p_paddr = 0;
42831 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
42832 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42833 phdr.p_memsz = vma->vm_end - vma->vm_start;
42834 offset += phdr.p_filesz;
42835 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
42836 @@ -2005,6 +2494,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42837 phdr.p_align = ELF_EXEC_PAGESIZE;
42838
42839 size += sizeof(phdr);
42840 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42841 if (size > cprm->limit
42842 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
42843 goto end_coredump;
42844 @@ -2029,7 +2519,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42845 unsigned long addr;
42846 unsigned long end;
42847
42848 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
42849 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
42850
42851 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
42852 struct page *page;
42853 @@ -2038,6 +2528,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42854 page = get_dump_page(addr);
42855 if (page) {
42856 void *kaddr = kmap(page);
42857 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
42858 stop = ((size += PAGE_SIZE) > cprm->limit) ||
42859 !dump_write(cprm->file, kaddr,
42860 PAGE_SIZE);
42861 @@ -2055,6 +2546,7 @@ static int elf_core_dump(struct coredump_params *cprm)
42862
42863 if (e_phnum == PN_XNUM) {
42864 size += sizeof(*shdr4extnum);
42865 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
42866 if (size > cprm->limit
42867 || !dump_write(cprm->file, shdr4extnum,
42868 sizeof(*shdr4extnum)))
42869 @@ -2075,6 +2567,97 @@ out:
42870
42871 #endif /* CONFIG_ELF_CORE */
42872
42873 +#ifdef CONFIG_PAX_MPROTECT
42874 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
42875 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
42876 + * we'll remove VM_MAYWRITE for good on RELRO segments.
42877 + *
42878 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
42879 + * basis because we want to allow the common case and not the special ones.
42880 + */
42881 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
42882 +{
42883 + struct elfhdr elf_h;
42884 + struct elf_phdr elf_p;
42885 + unsigned long i;
42886 + unsigned long oldflags;
42887 + bool is_textrel_rw, is_textrel_rx, is_relro;
42888 +
42889 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
42890 + return;
42891 +
42892 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
42893 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
42894 +
42895 +#ifdef CONFIG_PAX_ELFRELOCS
42896 + /* possible TEXTREL */
42897 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
42898 + 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);
42899 +#else
42900 + is_textrel_rw = false;
42901 + is_textrel_rx = false;
42902 +#endif
42903 +
42904 + /* possible RELRO */
42905 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
42906 +
42907 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
42908 + return;
42909 +
42910 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
42911 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
42912 +
42913 +#ifdef CONFIG_PAX_ETEXECRELOCS
42914 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42915 +#else
42916 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
42917 +#endif
42918 +
42919 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
42920 + !elf_check_arch(&elf_h) ||
42921 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
42922 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
42923 + return;
42924 +
42925 + for (i = 0UL; i < elf_h.e_phnum; i++) {
42926 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
42927 + return;
42928 + switch (elf_p.p_type) {
42929 + case PT_DYNAMIC:
42930 + if (!is_textrel_rw && !is_textrel_rx)
42931 + continue;
42932 + i = 0UL;
42933 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
42934 + elf_dyn dyn;
42935 +
42936 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
42937 + return;
42938 + if (dyn.d_tag == DT_NULL)
42939 + return;
42940 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
42941 + gr_log_textrel(vma);
42942 + if (is_textrel_rw)
42943 + vma->vm_flags |= VM_MAYWRITE;
42944 + else
42945 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
42946 + vma->vm_flags &= ~VM_MAYWRITE;
42947 + return;
42948 + }
42949 + i++;
42950 + }
42951 + return;
42952 +
42953 + case PT_GNU_RELRO:
42954 + if (!is_relro)
42955 + continue;
42956 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
42957 + vma->vm_flags &= ~VM_MAYWRITE;
42958 + return;
42959 + }
42960 + }
42961 +}
42962 +#endif
42963 +
42964 static int __init init_elf_binfmt(void)
42965 {
42966 return register_binfmt(&elf_format);
42967 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
42968 index 1bffbe0..c8c283e 100644
42969 --- a/fs/binfmt_flat.c
42970 +++ b/fs/binfmt_flat.c
42971 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
42972 realdatastart = (unsigned long) -ENOMEM;
42973 printk("Unable to allocate RAM for process data, errno %d\n",
42974 (int)-realdatastart);
42975 + down_write(&current->mm->mmap_sem);
42976 do_munmap(current->mm, textpos, text_len);
42977 + up_write(&current->mm->mmap_sem);
42978 ret = realdatastart;
42979 goto err;
42980 }
42981 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42982 }
42983 if (IS_ERR_VALUE(result)) {
42984 printk("Unable to read data+bss, errno %d\n", (int)-result);
42985 + down_write(&current->mm->mmap_sem);
42986 do_munmap(current->mm, textpos, text_len);
42987 do_munmap(current->mm, realdatastart, len);
42988 + up_write(&current->mm->mmap_sem);
42989 ret = result;
42990 goto err;
42991 }
42992 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
42993 }
42994 if (IS_ERR_VALUE(result)) {
42995 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
42996 + down_write(&current->mm->mmap_sem);
42997 do_munmap(current->mm, textpos, text_len + data_len + extra +
42998 MAX_SHARED_LIBS * sizeof(unsigned long));
42999 + up_write(&current->mm->mmap_sem);
43000 ret = result;
43001 goto err;
43002 }
43003 diff --git a/fs/bio.c b/fs/bio.c
43004 index 4fc4dbb..d3a5b93 100644
43005 --- a/fs/bio.c
43006 +++ b/fs/bio.c
43007 @@ -838,7 +838,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43008 /*
43009 * Overflow, abort
43010 */
43011 - if (end < start)
43012 + if (end < start || end - start > INT_MAX - nr_pages)
43013 return ERR_PTR(-EINVAL);
43014
43015 nr_pages += end - start;
43016 @@ -1234,7 +1234,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43017 const int read = bio_data_dir(bio) == READ;
43018 struct bio_map_data *bmd = bio->bi_private;
43019 int i;
43020 - char *p = bmd->sgvecs[0].iov_base;
43021 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43022
43023 __bio_for_each_segment(bvec, bio, i, 0) {
43024 char *addr = page_address(bvec->bv_page);
43025 diff --git a/fs/block_dev.c b/fs/block_dev.c
43026 index 236dd6c..46c6530 100644
43027 --- a/fs/block_dev.c
43028 +++ b/fs/block_dev.c
43029 @@ -703,7 +703,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43030 else if (bdev->bd_contains == bdev)
43031 return true; /* is a whole device which isn't held */
43032
43033 - else if (whole->bd_holder == bd_may_claim)
43034 + else if (whole->bd_holder == (void *)bd_may_claim)
43035 return true; /* is a partition of a device that is being partitioned */
43036 else if (whole->bd_holder != NULL)
43037 return false; /* is a partition of a held device */
43038 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43039 index d986824..af1befd 100644
43040 --- a/fs/btrfs/check-integrity.c
43041 +++ b/fs/btrfs/check-integrity.c
43042 @@ -157,7 +157,7 @@ struct btrfsic_block {
43043 union {
43044 bio_end_io_t *bio;
43045 bh_end_io_t *bh;
43046 - } orig_bio_bh_end_io;
43047 + } __no_const orig_bio_bh_end_io;
43048 int submit_bio_bh_rw;
43049 u64 flush_gen; /* only valid if !never_written */
43050 };
43051 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43052 index 0639a55..7d9e07f 100644
43053 --- a/fs/btrfs/ctree.c
43054 +++ b/fs/btrfs/ctree.c
43055 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43056 free_extent_buffer(buf);
43057 add_root_to_dirty_list(root);
43058 } else {
43059 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43060 - parent_start = parent->start;
43061 - else
43062 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43063 + if (parent)
43064 + parent_start = parent->start;
43065 + else
43066 + parent_start = 0;
43067 + } else
43068 parent_start = 0;
43069
43070 WARN_ON(trans->transid != btrfs_header_generation(parent));
43071 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43072 index 892b347..b3db246 100644
43073 --- a/fs/btrfs/inode.c
43074 +++ b/fs/btrfs/inode.c
43075 @@ -6930,7 +6930,7 @@ fail:
43076 return -ENOMEM;
43077 }
43078
43079 -static int btrfs_getattr(struct vfsmount *mnt,
43080 +int btrfs_getattr(struct vfsmount *mnt,
43081 struct dentry *dentry, struct kstat *stat)
43082 {
43083 struct inode *inode = dentry->d_inode;
43084 @@ -6944,6 +6944,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43085 return 0;
43086 }
43087
43088 +EXPORT_SYMBOL(btrfs_getattr);
43089 +
43090 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43091 +{
43092 + return BTRFS_I(inode)->root->anon_dev;
43093 +}
43094 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43095 +
43096 /*
43097 * If a file is moved, it will inherit the cow and compression flags of the new
43098 * directory.
43099 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43100 index 1b36f19..5ac7360 100644
43101 --- a/fs/btrfs/ioctl.c
43102 +++ b/fs/btrfs/ioctl.c
43103 @@ -2783,9 +2783,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43104 for (i = 0; i < num_types; i++) {
43105 struct btrfs_space_info *tmp;
43106
43107 + /* Don't copy in more than we allocated */
43108 if (!slot_count)
43109 break;
43110
43111 + slot_count--;
43112 +
43113 info = NULL;
43114 rcu_read_lock();
43115 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43116 @@ -2807,15 +2810,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43117 memcpy(dest, &space, sizeof(space));
43118 dest++;
43119 space_args.total_spaces++;
43120 - slot_count--;
43121 }
43122 - if (!slot_count)
43123 - break;
43124 }
43125 up_read(&info->groups_sem);
43126 }
43127
43128 - user_dest = (struct btrfs_ioctl_space_info *)
43129 + user_dest = (struct btrfs_ioctl_space_info __user *)
43130 (arg + sizeof(struct btrfs_ioctl_space_args));
43131
43132 if (copy_to_user(user_dest, dest_orig, alloc_size))
43133 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43134 index 8c1aae2..1e46446 100644
43135 --- a/fs/btrfs/relocation.c
43136 +++ b/fs/btrfs/relocation.c
43137 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43138 }
43139 spin_unlock(&rc->reloc_root_tree.lock);
43140
43141 - BUG_ON((struct btrfs_root *)node->data != root);
43142 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43143
43144 if (!del) {
43145 spin_lock(&rc->reloc_root_tree.lock);
43146 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43147 index 622f469..e8d2d55 100644
43148 --- a/fs/cachefiles/bind.c
43149 +++ b/fs/cachefiles/bind.c
43150 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43151 args);
43152
43153 /* start by checking things over */
43154 - ASSERT(cache->fstop_percent >= 0 &&
43155 - cache->fstop_percent < cache->fcull_percent &&
43156 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43157 cache->fcull_percent < cache->frun_percent &&
43158 cache->frun_percent < 100);
43159
43160 - ASSERT(cache->bstop_percent >= 0 &&
43161 - cache->bstop_percent < cache->bcull_percent &&
43162 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43163 cache->bcull_percent < cache->brun_percent &&
43164 cache->brun_percent < 100);
43165
43166 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43167 index 0a1467b..6a53245 100644
43168 --- a/fs/cachefiles/daemon.c
43169 +++ b/fs/cachefiles/daemon.c
43170 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43171 if (n > buflen)
43172 return -EMSGSIZE;
43173
43174 - if (copy_to_user(_buffer, buffer, n) != 0)
43175 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43176 return -EFAULT;
43177
43178 return n;
43179 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43180 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43181 return -EIO;
43182
43183 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43184 + if (datalen > PAGE_SIZE - 1)
43185 return -EOPNOTSUPP;
43186
43187 /* drag the command string into the kernel so we can parse it */
43188 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43189 if (args[0] != '%' || args[1] != '\0')
43190 return -EINVAL;
43191
43192 - if (fstop < 0 || fstop >= cache->fcull_percent)
43193 + if (fstop >= cache->fcull_percent)
43194 return cachefiles_daemon_range_error(cache, args);
43195
43196 cache->fstop_percent = fstop;
43197 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43198 if (args[0] != '%' || args[1] != '\0')
43199 return -EINVAL;
43200
43201 - if (bstop < 0 || bstop >= cache->bcull_percent)
43202 + if (bstop >= cache->bcull_percent)
43203 return cachefiles_daemon_range_error(cache, args);
43204
43205 cache->bstop_percent = bstop;
43206 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43207 index bd6bc1b..b627b53 100644
43208 --- a/fs/cachefiles/internal.h
43209 +++ b/fs/cachefiles/internal.h
43210 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43211 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43212 struct rb_root active_nodes; /* active nodes (can't be culled) */
43213 rwlock_t active_lock; /* lock for active_nodes */
43214 - atomic_t gravecounter; /* graveyard uniquifier */
43215 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43216 unsigned frun_percent; /* when to stop culling (% files) */
43217 unsigned fcull_percent; /* when to start culling (% files) */
43218 unsigned fstop_percent; /* when to stop allocating (% files) */
43219 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43220 * proc.c
43221 */
43222 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43223 -extern atomic_t cachefiles_lookup_histogram[HZ];
43224 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43225 -extern atomic_t cachefiles_create_histogram[HZ];
43226 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43227 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43228 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43229
43230 extern int __init cachefiles_proc_init(void);
43231 extern void cachefiles_proc_cleanup(void);
43232 static inline
43233 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43234 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43235 {
43236 unsigned long jif = jiffies - start_jif;
43237 if (jif >= HZ)
43238 jif = HZ - 1;
43239 - atomic_inc(&histogram[jif]);
43240 + atomic_inc_unchecked(&histogram[jif]);
43241 }
43242
43243 #else
43244 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43245 index a0358c2..d6137f2 100644
43246 --- a/fs/cachefiles/namei.c
43247 +++ b/fs/cachefiles/namei.c
43248 @@ -318,7 +318,7 @@ try_again:
43249 /* first step is to make up a grave dentry in the graveyard */
43250 sprintf(nbuffer, "%08x%08x",
43251 (uint32_t) get_seconds(),
43252 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43253 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43254
43255 /* do the multiway lock magic */
43256 trap = lock_rename(cache->graveyard, dir);
43257 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43258 index eccd339..4c1d995 100644
43259 --- a/fs/cachefiles/proc.c
43260 +++ b/fs/cachefiles/proc.c
43261 @@ -14,9 +14,9 @@
43262 #include <linux/seq_file.h>
43263 #include "internal.h"
43264
43265 -atomic_t cachefiles_lookup_histogram[HZ];
43266 -atomic_t cachefiles_mkdir_histogram[HZ];
43267 -atomic_t cachefiles_create_histogram[HZ];
43268 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43269 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43270 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43271
43272 /*
43273 * display the latency histogram
43274 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43275 return 0;
43276 default:
43277 index = (unsigned long) v - 3;
43278 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43279 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43280 - z = atomic_read(&cachefiles_create_histogram[index]);
43281 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43282 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43283 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43284 if (x == 0 && y == 0 && z == 0)
43285 return 0;
43286
43287 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43288 index 0e3c092..818480e 100644
43289 --- a/fs/cachefiles/rdwr.c
43290 +++ b/fs/cachefiles/rdwr.c
43291 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43292 old_fs = get_fs();
43293 set_fs(KERNEL_DS);
43294 ret = file->f_op->write(
43295 - file, (const void __user *) data, len, &pos);
43296 + file, (const void __force_user *) data, len, &pos);
43297 set_fs(old_fs);
43298 kunmap(page);
43299 if (ret != len)
43300 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
43301 index 3e8094b..cb3ff3d 100644
43302 --- a/fs/ceph/dir.c
43303 +++ b/fs/ceph/dir.c
43304 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
43305 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
43306 struct ceph_mds_client *mdsc = fsc->mdsc;
43307 unsigned frag = fpos_frag(filp->f_pos);
43308 - int off = fpos_off(filp->f_pos);
43309 + unsigned int off = fpos_off(filp->f_pos);
43310 int err;
43311 u32 ftype;
43312 struct ceph_mds_reply_info_parsed *rinfo;
43313 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
43314 if (nd &&
43315 (nd->flags & LOOKUP_OPEN) &&
43316 !(nd->intent.open.flags & O_CREAT)) {
43317 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
43318 + int mode = nd->intent.open.create_mode & ~current_umask();
43319 return ceph_lookup_open(dir, dentry, nd, mode, 1);
43320 }
43321
43322 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
43323 index 24b3dfc..3cd5454 100644
43324 --- a/fs/cifs/cifs_debug.c
43325 +++ b/fs/cifs/cifs_debug.c
43326 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43327
43328 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
43329 #ifdef CONFIG_CIFS_STATS2
43330 - atomic_set(&totBufAllocCount, 0);
43331 - atomic_set(&totSmBufAllocCount, 0);
43332 + atomic_set_unchecked(&totBufAllocCount, 0);
43333 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43334 #endif /* CONFIG_CIFS_STATS2 */
43335 spin_lock(&cifs_tcp_ses_lock);
43336 list_for_each(tmp1, &cifs_tcp_ses_list) {
43337 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
43338 tcon = list_entry(tmp3,
43339 struct cifs_tcon,
43340 tcon_list);
43341 - atomic_set(&tcon->num_smbs_sent, 0);
43342 - atomic_set(&tcon->num_writes, 0);
43343 - atomic_set(&tcon->num_reads, 0);
43344 - atomic_set(&tcon->num_oplock_brks, 0);
43345 - atomic_set(&tcon->num_opens, 0);
43346 - atomic_set(&tcon->num_posixopens, 0);
43347 - atomic_set(&tcon->num_posixmkdirs, 0);
43348 - atomic_set(&tcon->num_closes, 0);
43349 - atomic_set(&tcon->num_deletes, 0);
43350 - atomic_set(&tcon->num_mkdirs, 0);
43351 - atomic_set(&tcon->num_rmdirs, 0);
43352 - atomic_set(&tcon->num_renames, 0);
43353 - atomic_set(&tcon->num_t2renames, 0);
43354 - atomic_set(&tcon->num_ffirst, 0);
43355 - atomic_set(&tcon->num_fnext, 0);
43356 - atomic_set(&tcon->num_fclose, 0);
43357 - atomic_set(&tcon->num_hardlinks, 0);
43358 - atomic_set(&tcon->num_symlinks, 0);
43359 - atomic_set(&tcon->num_locks, 0);
43360 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
43361 + atomic_set_unchecked(&tcon->num_writes, 0);
43362 + atomic_set_unchecked(&tcon->num_reads, 0);
43363 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
43364 + atomic_set_unchecked(&tcon->num_opens, 0);
43365 + atomic_set_unchecked(&tcon->num_posixopens, 0);
43366 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
43367 + atomic_set_unchecked(&tcon->num_closes, 0);
43368 + atomic_set_unchecked(&tcon->num_deletes, 0);
43369 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
43370 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
43371 + atomic_set_unchecked(&tcon->num_renames, 0);
43372 + atomic_set_unchecked(&tcon->num_t2renames, 0);
43373 + atomic_set_unchecked(&tcon->num_ffirst, 0);
43374 + atomic_set_unchecked(&tcon->num_fnext, 0);
43375 + atomic_set_unchecked(&tcon->num_fclose, 0);
43376 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
43377 + atomic_set_unchecked(&tcon->num_symlinks, 0);
43378 + atomic_set_unchecked(&tcon->num_locks, 0);
43379 }
43380 }
43381 }
43382 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43383 smBufAllocCount.counter, cifs_min_small);
43384 #ifdef CONFIG_CIFS_STATS2
43385 seq_printf(m, "Total Large %d Small %d Allocations\n",
43386 - atomic_read(&totBufAllocCount),
43387 - atomic_read(&totSmBufAllocCount));
43388 + atomic_read_unchecked(&totBufAllocCount),
43389 + atomic_read_unchecked(&totSmBufAllocCount));
43390 #endif /* CONFIG_CIFS_STATS2 */
43391
43392 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
43393 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
43394 if (tcon->need_reconnect)
43395 seq_puts(m, "\tDISCONNECTED ");
43396 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
43397 - atomic_read(&tcon->num_smbs_sent),
43398 - atomic_read(&tcon->num_oplock_brks));
43399 + atomic_read_unchecked(&tcon->num_smbs_sent),
43400 + atomic_read_unchecked(&tcon->num_oplock_brks));
43401 seq_printf(m, "\nReads: %d Bytes: %lld",
43402 - atomic_read(&tcon->num_reads),
43403 + atomic_read_unchecked(&tcon->num_reads),
43404 (long long)(tcon->bytes_read));
43405 seq_printf(m, "\nWrites: %d Bytes: %lld",
43406 - atomic_read(&tcon->num_writes),
43407 + atomic_read_unchecked(&tcon->num_writes),
43408 (long long)(tcon->bytes_written));
43409 seq_printf(m, "\nFlushes: %d",
43410 - atomic_read(&tcon->num_flushes));
43411 + atomic_read_unchecked(&tcon->num_flushes));
43412 seq_printf(m, "\nLocks: %d HardLinks: %d "
43413 "Symlinks: %d",
43414 - atomic_read(&tcon->num_locks),
43415 - atomic_read(&tcon->num_hardlinks),
43416 - atomic_read(&tcon->num_symlinks));
43417 + atomic_read_unchecked(&tcon->num_locks),
43418 + atomic_read_unchecked(&tcon->num_hardlinks),
43419 + atomic_read_unchecked(&tcon->num_symlinks));
43420 seq_printf(m, "\nOpens: %d Closes: %d "
43421 "Deletes: %d",
43422 - atomic_read(&tcon->num_opens),
43423 - atomic_read(&tcon->num_closes),
43424 - atomic_read(&tcon->num_deletes));
43425 + atomic_read_unchecked(&tcon->num_opens),
43426 + atomic_read_unchecked(&tcon->num_closes),
43427 + atomic_read_unchecked(&tcon->num_deletes));
43428 seq_printf(m, "\nPosix Opens: %d "
43429 "Posix Mkdirs: %d",
43430 - atomic_read(&tcon->num_posixopens),
43431 - atomic_read(&tcon->num_posixmkdirs));
43432 + atomic_read_unchecked(&tcon->num_posixopens),
43433 + atomic_read_unchecked(&tcon->num_posixmkdirs));
43434 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
43435 - atomic_read(&tcon->num_mkdirs),
43436 - atomic_read(&tcon->num_rmdirs));
43437 + atomic_read_unchecked(&tcon->num_mkdirs),
43438 + atomic_read_unchecked(&tcon->num_rmdirs));
43439 seq_printf(m, "\nRenames: %d T2 Renames %d",
43440 - atomic_read(&tcon->num_renames),
43441 - atomic_read(&tcon->num_t2renames));
43442 + atomic_read_unchecked(&tcon->num_renames),
43443 + atomic_read_unchecked(&tcon->num_t2renames));
43444 seq_printf(m, "\nFindFirst: %d FNext %d "
43445 "FClose %d",
43446 - atomic_read(&tcon->num_ffirst),
43447 - atomic_read(&tcon->num_fnext),
43448 - atomic_read(&tcon->num_fclose));
43449 + atomic_read_unchecked(&tcon->num_ffirst),
43450 + atomic_read_unchecked(&tcon->num_fnext),
43451 + atomic_read_unchecked(&tcon->num_fclose));
43452 }
43453 }
43454 }
43455 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
43456 index 70dd381..b8ce03b 100644
43457 --- a/fs/cifs/cifsfs.c
43458 +++ b/fs/cifs/cifsfs.c
43459 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
43460 cifs_req_cachep = kmem_cache_create("cifs_request",
43461 CIFSMaxBufSize +
43462 MAX_CIFS_HDR_SIZE, 0,
43463 - SLAB_HWCACHE_ALIGN, NULL);
43464 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
43465 if (cifs_req_cachep == NULL)
43466 return -ENOMEM;
43467
43468 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
43469 efficient to alloc 1 per page off the slab compared to 17K (5page)
43470 alloc of large cifs buffers even when page debugging is on */
43471 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
43472 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
43473 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
43474 NULL);
43475 if (cifs_sm_req_cachep == NULL) {
43476 mempool_destroy(cifs_req_poolp);
43477 @@ -1101,8 +1101,8 @@ init_cifs(void)
43478 atomic_set(&bufAllocCount, 0);
43479 atomic_set(&smBufAllocCount, 0);
43480 #ifdef CONFIG_CIFS_STATS2
43481 - atomic_set(&totBufAllocCount, 0);
43482 - atomic_set(&totSmBufAllocCount, 0);
43483 + atomic_set_unchecked(&totBufAllocCount, 0);
43484 + atomic_set_unchecked(&totSmBufAllocCount, 0);
43485 #endif /* CONFIG_CIFS_STATS2 */
43486
43487 atomic_set(&midCount, 0);
43488 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
43489 index d47d20a..77e8b33 100644
43490 --- a/fs/cifs/cifsglob.h
43491 +++ b/fs/cifs/cifsglob.h
43492 @@ -388,28 +388,28 @@ struct cifs_tcon {
43493 __u16 Flags; /* optional support bits */
43494 enum statusEnum tidStatus;
43495 #ifdef CONFIG_CIFS_STATS
43496 - atomic_t num_smbs_sent;
43497 - atomic_t num_writes;
43498 - atomic_t num_reads;
43499 - atomic_t num_flushes;
43500 - atomic_t num_oplock_brks;
43501 - atomic_t num_opens;
43502 - atomic_t num_closes;
43503 - atomic_t num_deletes;
43504 - atomic_t num_mkdirs;
43505 - atomic_t num_posixopens;
43506 - atomic_t num_posixmkdirs;
43507 - atomic_t num_rmdirs;
43508 - atomic_t num_renames;
43509 - atomic_t num_t2renames;
43510 - atomic_t num_ffirst;
43511 - atomic_t num_fnext;
43512 - atomic_t num_fclose;
43513 - atomic_t num_hardlinks;
43514 - atomic_t num_symlinks;
43515 - atomic_t num_locks;
43516 - atomic_t num_acl_get;
43517 - atomic_t num_acl_set;
43518 + atomic_unchecked_t num_smbs_sent;
43519 + atomic_unchecked_t num_writes;
43520 + atomic_unchecked_t num_reads;
43521 + atomic_unchecked_t num_flushes;
43522 + atomic_unchecked_t num_oplock_brks;
43523 + atomic_unchecked_t num_opens;
43524 + atomic_unchecked_t num_closes;
43525 + atomic_unchecked_t num_deletes;
43526 + atomic_unchecked_t num_mkdirs;
43527 + atomic_unchecked_t num_posixopens;
43528 + atomic_unchecked_t num_posixmkdirs;
43529 + atomic_unchecked_t num_rmdirs;
43530 + atomic_unchecked_t num_renames;
43531 + atomic_unchecked_t num_t2renames;
43532 + atomic_unchecked_t num_ffirst;
43533 + atomic_unchecked_t num_fnext;
43534 + atomic_unchecked_t num_fclose;
43535 + atomic_unchecked_t num_hardlinks;
43536 + atomic_unchecked_t num_symlinks;
43537 + atomic_unchecked_t num_locks;
43538 + atomic_unchecked_t num_acl_get;
43539 + atomic_unchecked_t num_acl_set;
43540 #ifdef CONFIG_CIFS_STATS2
43541 unsigned long long time_writes;
43542 unsigned long long time_reads;
43543 @@ -624,7 +624,7 @@ convert_delimiter(char *path, char delim)
43544 }
43545
43546 #ifdef CONFIG_CIFS_STATS
43547 -#define cifs_stats_inc atomic_inc
43548 +#define cifs_stats_inc atomic_inc_unchecked
43549
43550 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
43551 unsigned int bytes)
43552 @@ -983,8 +983,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
43553 /* Various Debug counters */
43554 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
43555 #ifdef CONFIG_CIFS_STATS2
43556 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
43557 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
43558 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
43559 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
43560 #endif
43561 GLOBAL_EXTERN atomic_t smBufAllocCount;
43562 GLOBAL_EXTERN atomic_t midCount;
43563 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
43564 index 6b0e064..94e6c3c 100644
43565 --- a/fs/cifs/link.c
43566 +++ b/fs/cifs/link.c
43567 @@ -600,7 +600,7 @@ symlink_exit:
43568
43569 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
43570 {
43571 - char *p = nd_get_link(nd);
43572 + const char *p = nd_get_link(nd);
43573 if (!IS_ERR(p))
43574 kfree(p);
43575 }
43576 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
43577 index 703ef5c..2a44ed5 100644
43578 --- a/fs/cifs/misc.c
43579 +++ b/fs/cifs/misc.c
43580 @@ -156,7 +156,7 @@ cifs_buf_get(void)
43581 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
43582 atomic_inc(&bufAllocCount);
43583 #ifdef CONFIG_CIFS_STATS2
43584 - atomic_inc(&totBufAllocCount);
43585 + atomic_inc_unchecked(&totBufAllocCount);
43586 #endif /* CONFIG_CIFS_STATS2 */
43587 }
43588
43589 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
43590 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
43591 atomic_inc(&smBufAllocCount);
43592 #ifdef CONFIG_CIFS_STATS2
43593 - atomic_inc(&totSmBufAllocCount);
43594 + atomic_inc_unchecked(&totSmBufAllocCount);
43595 #endif /* CONFIG_CIFS_STATS2 */
43596
43597 }
43598 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
43599 index 6901578..d402eb5 100644
43600 --- a/fs/coda/cache.c
43601 +++ b/fs/coda/cache.c
43602 @@ -24,7 +24,7 @@
43603 #include "coda_linux.h"
43604 #include "coda_cache.h"
43605
43606 -static atomic_t permission_epoch = ATOMIC_INIT(0);
43607 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
43608
43609 /* replace or extend an acl cache hit */
43610 void coda_cache_enter(struct inode *inode, int mask)
43611 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
43612 struct coda_inode_info *cii = ITOC(inode);
43613
43614 spin_lock(&cii->c_lock);
43615 - cii->c_cached_epoch = atomic_read(&permission_epoch);
43616 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
43617 if (cii->c_uid != current_fsuid()) {
43618 cii->c_uid = current_fsuid();
43619 cii->c_cached_perm = mask;
43620 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
43621 {
43622 struct coda_inode_info *cii = ITOC(inode);
43623 spin_lock(&cii->c_lock);
43624 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
43625 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
43626 spin_unlock(&cii->c_lock);
43627 }
43628
43629 /* remove all acl caches */
43630 void coda_cache_clear_all(struct super_block *sb)
43631 {
43632 - atomic_inc(&permission_epoch);
43633 + atomic_inc_unchecked(&permission_epoch);
43634 }
43635
43636
43637 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
43638 spin_lock(&cii->c_lock);
43639 hit = (mask & cii->c_cached_perm) == mask &&
43640 cii->c_uid == current_fsuid() &&
43641 - cii->c_cached_epoch == atomic_read(&permission_epoch);
43642 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
43643 spin_unlock(&cii->c_lock);
43644
43645 return hit;
43646 diff --git a/fs/compat.c b/fs/compat.c
43647 index 07880ba..3fb2862 100644
43648 --- a/fs/compat.c
43649 +++ b/fs/compat.c
43650 @@ -491,7 +491,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
43651
43652 set_fs(KERNEL_DS);
43653 /* The __user pointer cast is valid because of the set_fs() */
43654 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
43655 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
43656 set_fs(oldfs);
43657 /* truncating is ok because it's a user address */
43658 if (!ret)
43659 @@ -549,7 +549,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
43660 goto out;
43661
43662 ret = -EINVAL;
43663 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
43664 + if (nr_segs > UIO_MAXIOV)
43665 goto out;
43666 if (nr_segs > fast_segs) {
43667 ret = -ENOMEM;
43668 @@ -832,6 +832,7 @@ struct compat_old_linux_dirent {
43669
43670 struct compat_readdir_callback {
43671 struct compat_old_linux_dirent __user *dirent;
43672 + struct file * file;
43673 int result;
43674 };
43675
43676 @@ -849,6 +850,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
43677 buf->result = -EOVERFLOW;
43678 return -EOVERFLOW;
43679 }
43680 +
43681 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43682 + return 0;
43683 +
43684 buf->result++;
43685 dirent = buf->dirent;
43686 if (!access_ok(VERIFY_WRITE, dirent,
43687 @@ -881,6 +886,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
43688
43689 buf.result = 0;
43690 buf.dirent = dirent;
43691 + buf.file = file;
43692
43693 error = vfs_readdir(file, compat_fillonedir, &buf);
43694 if (buf.result)
43695 @@ -901,6 +907,7 @@ struct compat_linux_dirent {
43696 struct compat_getdents_callback {
43697 struct compat_linux_dirent __user *current_dir;
43698 struct compat_linux_dirent __user *previous;
43699 + struct file * file;
43700 int count;
43701 int error;
43702 };
43703 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
43704 buf->error = -EOVERFLOW;
43705 return -EOVERFLOW;
43706 }
43707 +
43708 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43709 + return 0;
43710 +
43711 dirent = buf->previous;
43712 if (dirent) {
43713 if (__put_user(offset, &dirent->d_off))
43714 @@ -969,6 +980,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
43715 buf.previous = NULL;
43716 buf.count = count;
43717 buf.error = 0;
43718 + buf.file = file;
43719
43720 error = vfs_readdir(file, compat_filldir, &buf);
43721 if (error >= 0)
43722 @@ -990,6 +1002,7 @@ out:
43723 struct compat_getdents_callback64 {
43724 struct linux_dirent64 __user *current_dir;
43725 struct linux_dirent64 __user *previous;
43726 + struct file * file;
43727 int count;
43728 int error;
43729 };
43730 @@ -1006,6 +1019,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
43731 buf->error = -EINVAL; /* only used if we fail.. */
43732 if (reclen > buf->count)
43733 return -EINVAL;
43734 +
43735 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
43736 + return 0;
43737 +
43738 dirent = buf->previous;
43739
43740 if (dirent) {
43741 @@ -1057,13 +1074,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
43742 buf.previous = NULL;
43743 buf.count = count;
43744 buf.error = 0;
43745 + buf.file = file;
43746
43747 error = vfs_readdir(file, compat_filldir64, &buf);
43748 if (error >= 0)
43749 error = buf.error;
43750 lastdirent = buf.previous;
43751 if (lastdirent) {
43752 - typeof(lastdirent->d_off) d_off = file->f_pos;
43753 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
43754 if (__put_user_unaligned(d_off, &lastdirent->d_off))
43755 error = -EFAULT;
43756 else
43757 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
43758 index 112e45a..b59845b 100644
43759 --- a/fs/compat_binfmt_elf.c
43760 +++ b/fs/compat_binfmt_elf.c
43761 @@ -30,11 +30,13 @@
43762 #undef elf_phdr
43763 #undef elf_shdr
43764 #undef elf_note
43765 +#undef elf_dyn
43766 #undef elf_addr_t
43767 #define elfhdr elf32_hdr
43768 #define elf_phdr elf32_phdr
43769 #define elf_shdr elf32_shdr
43770 #define elf_note elf32_note
43771 +#define elf_dyn Elf32_Dyn
43772 #define elf_addr_t Elf32_Addr
43773
43774 /*
43775 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
43776 index a26bea1..ae23e72 100644
43777 --- a/fs/compat_ioctl.c
43778 +++ b/fs/compat_ioctl.c
43779 @@ -211,6 +211,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
43780
43781 err = get_user(palp, &up->palette);
43782 err |= get_user(length, &up->length);
43783 + if (err)
43784 + return -EFAULT;
43785
43786 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
43787 err = put_user(compat_ptr(palp), &up_native->palette);
43788 @@ -622,7 +624,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
43789 return -EFAULT;
43790 if (__get_user(udata, &ss32->iomem_base))
43791 return -EFAULT;
43792 - ss.iomem_base = compat_ptr(udata);
43793 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
43794 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
43795 __get_user(ss.port_high, &ss32->port_high))
43796 return -EFAULT;
43797 @@ -797,7 +799,7 @@ static int compat_ioctl_preallocate(struct file *file,
43798 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
43799 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
43800 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
43801 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43802 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
43803 return -EFAULT;
43804
43805 return ioctl_preallocate(file, p);
43806 @@ -1611,8 +1613,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
43807 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
43808 {
43809 unsigned int a, b;
43810 - a = *(unsigned int *)p;
43811 - b = *(unsigned int *)q;
43812 + a = *(const unsigned int *)p;
43813 + b = *(const unsigned int *)q;
43814 if (a > b)
43815 return 1;
43816 if (a < b)
43817 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
43818 index 5ddd7eb..c18bf04 100644
43819 --- a/fs/configfs/dir.c
43820 +++ b/fs/configfs/dir.c
43821 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43822 }
43823 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
43824 struct configfs_dirent *next;
43825 - const char * name;
43826 + const unsigned char * name;
43827 + char d_name[sizeof(next->s_dentry->d_iname)];
43828 int len;
43829 struct inode *inode = NULL;
43830
43831 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
43832 continue;
43833
43834 name = configfs_get_name(next);
43835 - len = strlen(name);
43836 + if (next->s_dentry && name == next->s_dentry->d_iname) {
43837 + len = next->s_dentry->d_name.len;
43838 + memcpy(d_name, name, len);
43839 + name = d_name;
43840 + } else
43841 + len = strlen(name);
43842
43843 /*
43844 * We'll have a dentry and an inode for
43845 diff --git a/fs/dcache.c b/fs/dcache.c
43846 index 2576d14..0cec38d 100644
43847 --- a/fs/dcache.c
43848 +++ b/fs/dcache.c
43849 @@ -105,10 +105,10 @@ static unsigned int d_hash_shift __read_mostly;
43850 static struct hlist_bl_head *dentry_hashtable __read_mostly;
43851
43852 static inline struct hlist_bl_head *d_hash(const struct dentry *parent,
43853 - unsigned long hash)
43854 + unsigned int hash)
43855 {
43856 - hash += ((unsigned long) parent ^ GOLDEN_RATIO_PRIME) / L1_CACHE_BYTES;
43857 - hash = hash ^ ((hash ^ GOLDEN_RATIO_PRIME) >> D_HASHBITS);
43858 + hash += (unsigned long) parent / L1_CACHE_BYTES;
43859 + hash = hash + (hash >> D_HASHBITS);
43860 return dentry_hashtable + (hash & D_HASHMASK);
43861 }
43862
43863 @@ -3067,7 +3067,7 @@ void __init vfs_caches_init(unsigned long mempages)
43864 mempages -= reserve;
43865
43866 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
43867 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
43868 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
43869
43870 dcache_init();
43871 inode_init();
43872 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
43873 index 956d5dd..e755e04 100644
43874 --- a/fs/debugfs/inode.c
43875 +++ b/fs/debugfs/inode.c
43876 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
43877 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
43878 {
43879 return debugfs_create_file(name,
43880 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
43881 + S_IFDIR | S_IRWXU,
43882 +#else
43883 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
43884 +#endif
43885 parent, NULL, NULL);
43886 }
43887 EXPORT_SYMBOL_GPL(debugfs_create_dir);
43888 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
43889 index ab35b11..b30af66 100644
43890 --- a/fs/ecryptfs/inode.c
43891 +++ b/fs/ecryptfs/inode.c
43892 @@ -672,7 +672,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
43893 old_fs = get_fs();
43894 set_fs(get_ds());
43895 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
43896 - (char __user *)lower_buf,
43897 + (char __force_user *)lower_buf,
43898 lower_bufsiz);
43899 set_fs(old_fs);
43900 if (rc < 0)
43901 @@ -718,7 +718,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
43902 }
43903 old_fs = get_fs();
43904 set_fs(get_ds());
43905 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
43906 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
43907 set_fs(old_fs);
43908 if (rc < 0) {
43909 kfree(buf);
43910 @@ -733,7 +733,7 @@ out:
43911 static void
43912 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
43913 {
43914 - char *buf = nd_get_link(nd);
43915 + const char *buf = nd_get_link(nd);
43916 if (!IS_ERR(buf)) {
43917 /* Free the char* */
43918 kfree(buf);
43919 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
43920 index 3a06f40..f7af544 100644
43921 --- a/fs/ecryptfs/miscdev.c
43922 +++ b/fs/ecryptfs/miscdev.c
43923 @@ -345,7 +345,7 @@ check_list:
43924 goto out_unlock_msg_ctx;
43925 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
43926 if (msg_ctx->msg) {
43927 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
43928 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
43929 goto out_unlock_msg_ctx;
43930 i += packet_length_size;
43931 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
43932 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
43933 index b2a34a1..162fa69 100644
43934 --- a/fs/ecryptfs/read_write.c
43935 +++ b/fs/ecryptfs/read_write.c
43936 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
43937 return -EIO;
43938 fs_save = get_fs();
43939 set_fs(get_ds());
43940 - rc = vfs_write(lower_file, data, size, &offset);
43941 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
43942 set_fs(fs_save);
43943 mark_inode_dirty_sync(ecryptfs_inode);
43944 return rc;
43945 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
43946 return -EIO;
43947 fs_save = get_fs();
43948 set_fs(get_ds());
43949 - rc = vfs_read(lower_file, data, size, &offset);
43950 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
43951 set_fs(fs_save);
43952 return rc;
43953 }
43954 diff --git a/fs/exec.c b/fs/exec.c
43955 index ae42277..32c9035 100644
43956 --- a/fs/exec.c
43957 +++ b/fs/exec.c
43958 @@ -55,6 +55,13 @@
43959 #include <linux/pipe_fs_i.h>
43960 #include <linux/oom.h>
43961 #include <linux/compat.h>
43962 +#include <linux/random.h>
43963 +#include <linux/seq_file.h>
43964 +
43965 +#ifdef CONFIG_PAX_REFCOUNT
43966 +#include <linux/kallsyms.h>
43967 +#include <linux/kdebug.h>
43968 +#endif
43969
43970 #include <asm/uaccess.h>
43971 #include <asm/mmu_context.h>
43972 @@ -63,6 +70,15 @@
43973 #include <trace/events/task.h>
43974 #include "internal.h"
43975
43976 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
43977 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
43978 +#endif
43979 +
43980 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
43981 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
43982 +EXPORT_SYMBOL(pax_set_initial_flags_func);
43983 +#endif
43984 +
43985 int core_uses_pid;
43986 char core_pattern[CORENAME_MAX_SIZE] = "core";
43987 unsigned int core_pipe_limit;
43988 @@ -72,7 +88,7 @@ struct core_name {
43989 char *corename;
43990 int used, size;
43991 };
43992 -static atomic_t call_count = ATOMIC_INIT(1);
43993 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
43994
43995 /* The maximal length of core_pattern is also specified in sysctl.c */
43996
43997 @@ -190,18 +206,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
43998 int write)
43999 {
44000 struct page *page;
44001 - int ret;
44002
44003 -#ifdef CONFIG_STACK_GROWSUP
44004 - if (write) {
44005 - ret = expand_downwards(bprm->vma, pos);
44006 - if (ret < 0)
44007 - return NULL;
44008 - }
44009 -#endif
44010 - ret = get_user_pages(current, bprm->mm, pos,
44011 - 1, write, 1, &page, NULL);
44012 - if (ret <= 0)
44013 + if (0 > expand_downwards(bprm->vma, pos))
44014 + return NULL;
44015 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44016 return NULL;
44017
44018 if (write) {
44019 @@ -217,6 +225,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44020 if (size <= ARG_MAX)
44021 return page;
44022
44023 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44024 + // only allow 512KB for argv+env on suid/sgid binaries
44025 + // to prevent easy ASLR exhaustion
44026 + if (((bprm->cred->euid != current_euid()) ||
44027 + (bprm->cred->egid != current_egid())) &&
44028 + (size > (512 * 1024))) {
44029 + put_page(page);
44030 + return NULL;
44031 + }
44032 +#endif
44033 +
44034 /*
44035 * Limit to 1/4-th the stack size for the argv+env strings.
44036 * This ensures that:
44037 @@ -276,6 +295,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44038 vma->vm_end = STACK_TOP_MAX;
44039 vma->vm_start = vma->vm_end - PAGE_SIZE;
44040 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44041 +
44042 +#ifdef CONFIG_PAX_SEGMEXEC
44043 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44044 +#endif
44045 +
44046 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44047 INIT_LIST_HEAD(&vma->anon_vma_chain);
44048
44049 @@ -290,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44050 mm->stack_vm = mm->total_vm = 1;
44051 up_write(&mm->mmap_sem);
44052 bprm->p = vma->vm_end - sizeof(void *);
44053 +
44054 +#ifdef CONFIG_PAX_RANDUSTACK
44055 + if (randomize_va_space)
44056 + bprm->p ^= random32() & ~PAGE_MASK;
44057 +#endif
44058 +
44059 return 0;
44060 err:
44061 up_write(&mm->mmap_sem);
44062 @@ -398,19 +428,7 @@ err:
44063 return err;
44064 }
44065
44066 -struct user_arg_ptr {
44067 -#ifdef CONFIG_COMPAT
44068 - bool is_compat;
44069 -#endif
44070 - union {
44071 - const char __user *const __user *native;
44072 -#ifdef CONFIG_COMPAT
44073 - compat_uptr_t __user *compat;
44074 -#endif
44075 - } ptr;
44076 -};
44077 -
44078 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44079 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44080 {
44081 const char __user *native;
44082
44083 @@ -419,14 +437,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44084 compat_uptr_t compat;
44085
44086 if (get_user(compat, argv.ptr.compat + nr))
44087 - return ERR_PTR(-EFAULT);
44088 + return (const char __force_user *)ERR_PTR(-EFAULT);
44089
44090 return compat_ptr(compat);
44091 }
44092 #endif
44093
44094 if (get_user(native, argv.ptr.native + nr))
44095 - return ERR_PTR(-EFAULT);
44096 + return (const char __force_user *)ERR_PTR(-EFAULT);
44097
44098 return native;
44099 }
44100 @@ -445,7 +463,7 @@ static int count(struct user_arg_ptr argv, int max)
44101 if (!p)
44102 break;
44103
44104 - if (IS_ERR(p))
44105 + if (IS_ERR((const char __force_kernel *)p))
44106 return -EFAULT;
44107
44108 if (i++ >= max)
44109 @@ -479,7 +497,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44110
44111 ret = -EFAULT;
44112 str = get_user_arg_ptr(argv, argc);
44113 - if (IS_ERR(str))
44114 + if (IS_ERR((const char __force_kernel *)str))
44115 goto out;
44116
44117 len = strnlen_user(str, MAX_ARG_STRLEN);
44118 @@ -561,7 +579,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44119 int r;
44120 mm_segment_t oldfs = get_fs();
44121 struct user_arg_ptr argv = {
44122 - .ptr.native = (const char __user *const __user *)__argv,
44123 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44124 };
44125
44126 set_fs(KERNEL_DS);
44127 @@ -596,7 +614,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44128 unsigned long new_end = old_end - shift;
44129 struct mmu_gather tlb;
44130
44131 - BUG_ON(new_start > new_end);
44132 + if (new_start >= new_end || new_start < mmap_min_addr)
44133 + return -ENOMEM;
44134
44135 /*
44136 * ensure there are no vmas between where we want to go
44137 @@ -605,6 +624,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44138 if (vma != find_vma(mm, new_start))
44139 return -EFAULT;
44140
44141 +#ifdef CONFIG_PAX_SEGMEXEC
44142 + BUG_ON(pax_find_mirror_vma(vma));
44143 +#endif
44144 +
44145 /*
44146 * cover the whole range: [new_start, old_end)
44147 */
44148 @@ -685,10 +708,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44149 stack_top = arch_align_stack(stack_top);
44150 stack_top = PAGE_ALIGN(stack_top);
44151
44152 - if (unlikely(stack_top < mmap_min_addr) ||
44153 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44154 - return -ENOMEM;
44155 -
44156 stack_shift = vma->vm_end - stack_top;
44157
44158 bprm->p -= stack_shift;
44159 @@ -700,8 +719,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44160 bprm->exec -= stack_shift;
44161
44162 down_write(&mm->mmap_sem);
44163 +
44164 + /* Move stack pages down in memory. */
44165 + if (stack_shift) {
44166 + ret = shift_arg_pages(vma, stack_shift);
44167 + if (ret)
44168 + goto out_unlock;
44169 + }
44170 +
44171 vm_flags = VM_STACK_FLAGS;
44172
44173 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44174 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44175 + vm_flags &= ~VM_EXEC;
44176 +
44177 +#ifdef CONFIG_PAX_MPROTECT
44178 + if (mm->pax_flags & MF_PAX_MPROTECT)
44179 + vm_flags &= ~VM_MAYEXEC;
44180 +#endif
44181 +
44182 + }
44183 +#endif
44184 +
44185 /*
44186 * Adjust stack execute permissions; explicitly enable for
44187 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
44188 @@ -720,13 +759,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44189 goto out_unlock;
44190 BUG_ON(prev != vma);
44191
44192 - /* Move stack pages down in memory. */
44193 - if (stack_shift) {
44194 - ret = shift_arg_pages(vma, stack_shift);
44195 - if (ret)
44196 - goto out_unlock;
44197 - }
44198 -
44199 /* mprotect_fixup is overkill to remove the temporary stack flags */
44200 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
44201
44202 @@ -807,7 +839,7 @@ int kernel_read(struct file *file, loff_t offset,
44203 old_fs = get_fs();
44204 set_fs(get_ds());
44205 /* The cast to a user pointer is valid due to the set_fs() */
44206 - result = vfs_read(file, (void __user *)addr, count, &pos);
44207 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
44208 set_fs(old_fs);
44209 return result;
44210 }
44211 @@ -1255,7 +1287,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
44212 }
44213 rcu_read_unlock();
44214
44215 - if (p->fs->users > n_fs) {
44216 + if (atomic_read(&p->fs->users) > n_fs) {
44217 bprm->unsafe |= LSM_UNSAFE_SHARE;
44218 } else {
44219 res = -EAGAIN;
44220 @@ -1450,6 +1482,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
44221
44222 EXPORT_SYMBOL(search_binary_handler);
44223
44224 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44225 +static DEFINE_PER_CPU(u64, exec_counter);
44226 +static int __init init_exec_counters(void)
44227 +{
44228 + unsigned int cpu;
44229 +
44230 + for_each_possible_cpu(cpu) {
44231 + per_cpu(exec_counter, cpu) = (u64)cpu;
44232 + }
44233 +
44234 + return 0;
44235 +}
44236 +early_initcall(init_exec_counters);
44237 +static inline void increment_exec_counter(void)
44238 +{
44239 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
44240 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
44241 +}
44242 +#else
44243 +static inline void increment_exec_counter(void) {}
44244 +#endif
44245 +
44246 /*
44247 * sys_execve() executes a new program.
44248 */
44249 @@ -1458,6 +1512,11 @@ static int do_execve_common(const char *filename,
44250 struct user_arg_ptr envp,
44251 struct pt_regs *regs)
44252 {
44253 +#ifdef CONFIG_GRKERNSEC
44254 + struct file *old_exec_file;
44255 + struct acl_subject_label *old_acl;
44256 + struct rlimit old_rlim[RLIM_NLIMITS];
44257 +#endif
44258 struct linux_binprm *bprm;
44259 struct file *file;
44260 struct files_struct *displaced;
44261 @@ -1465,6 +1524,8 @@ static int do_execve_common(const char *filename,
44262 int retval;
44263 const struct cred *cred = current_cred();
44264
44265 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
44266 +
44267 /*
44268 * We move the actual failure in case of RLIMIT_NPROC excess from
44269 * set*uid() to execve() because too many poorly written programs
44270 @@ -1505,12 +1566,27 @@ static int do_execve_common(const char *filename,
44271 if (IS_ERR(file))
44272 goto out_unmark;
44273
44274 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
44275 + retval = -EPERM;
44276 + goto out_file;
44277 + }
44278 +
44279 sched_exec();
44280
44281 bprm->file = file;
44282 bprm->filename = filename;
44283 bprm->interp = filename;
44284
44285 + if (gr_process_user_ban()) {
44286 + retval = -EPERM;
44287 + goto out_file;
44288 + }
44289 +
44290 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
44291 + retval = -EACCES;
44292 + goto out_file;
44293 + }
44294 +
44295 retval = bprm_mm_init(bprm);
44296 if (retval)
44297 goto out_file;
44298 @@ -1527,24 +1603,65 @@ static int do_execve_common(const char *filename,
44299 if (retval < 0)
44300 goto out;
44301
44302 +#ifdef CONFIG_GRKERNSEC
44303 + old_acl = current->acl;
44304 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
44305 + old_exec_file = current->exec_file;
44306 + get_file(file);
44307 + current->exec_file = file;
44308 +#endif
44309 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44310 + /* limit suid stack to 8MB
44311 + we saved the old limits above and will restore them if this exec fails
44312 + */
44313 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
44314 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
44315 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
44316 +#endif
44317 +
44318 + if (!gr_tpe_allow(file)) {
44319 + retval = -EACCES;
44320 + goto out_fail;
44321 + }
44322 +
44323 + if (gr_check_crash_exec(file)) {
44324 + retval = -EACCES;
44325 + goto out_fail;
44326 + }
44327 +
44328 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
44329 + bprm->unsafe);
44330 + if (retval < 0)
44331 + goto out_fail;
44332 +
44333 retval = copy_strings_kernel(1, &bprm->filename, bprm);
44334 if (retval < 0)
44335 - goto out;
44336 + goto out_fail;
44337
44338 bprm->exec = bprm->p;
44339 retval = copy_strings(bprm->envc, envp, bprm);
44340 if (retval < 0)
44341 - goto out;
44342 + goto out_fail;
44343
44344 retval = copy_strings(bprm->argc, argv, bprm);
44345 if (retval < 0)
44346 - goto out;
44347 + goto out_fail;
44348 +
44349 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
44350 +
44351 + gr_handle_exec_args(bprm, argv);
44352
44353 retval = search_binary_handler(bprm,regs);
44354 if (retval < 0)
44355 - goto out;
44356 + goto out_fail;
44357 +#ifdef CONFIG_GRKERNSEC
44358 + if (old_exec_file)
44359 + fput(old_exec_file);
44360 +#endif
44361
44362 /* execve succeeded */
44363 +
44364 + increment_exec_counter();
44365 current->fs->in_exec = 0;
44366 current->in_execve = 0;
44367 acct_update_integrals(current);
44368 @@ -1553,6 +1670,14 @@ static int do_execve_common(const char *filename,
44369 put_files_struct(displaced);
44370 return retval;
44371
44372 +out_fail:
44373 +#ifdef CONFIG_GRKERNSEC
44374 + current->acl = old_acl;
44375 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
44376 + fput(current->exec_file);
44377 + current->exec_file = old_exec_file;
44378 +#endif
44379 +
44380 out:
44381 if (bprm->mm) {
44382 acct_arg_size(bprm, 0);
44383 @@ -1626,7 +1751,7 @@ static int expand_corename(struct core_name *cn)
44384 {
44385 char *old_corename = cn->corename;
44386
44387 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
44388 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
44389 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
44390
44391 if (!cn->corename) {
44392 @@ -1723,7 +1848,7 @@ static int format_corename(struct core_name *cn, long signr)
44393 int pid_in_pattern = 0;
44394 int err = 0;
44395
44396 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
44397 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
44398 cn->corename = kmalloc(cn->size, GFP_KERNEL);
44399 cn->used = 0;
44400
44401 @@ -1820,6 +1945,228 @@ out:
44402 return ispipe;
44403 }
44404
44405 +int pax_check_flags(unsigned long *flags)
44406 +{
44407 + int retval = 0;
44408 +
44409 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
44410 + if (*flags & MF_PAX_SEGMEXEC)
44411 + {
44412 + *flags &= ~MF_PAX_SEGMEXEC;
44413 + retval = -EINVAL;
44414 + }
44415 +#endif
44416 +
44417 + if ((*flags & MF_PAX_PAGEEXEC)
44418 +
44419 +#ifdef CONFIG_PAX_PAGEEXEC
44420 + && (*flags & MF_PAX_SEGMEXEC)
44421 +#endif
44422 +
44423 + )
44424 + {
44425 + *flags &= ~MF_PAX_PAGEEXEC;
44426 + retval = -EINVAL;
44427 + }
44428 +
44429 + if ((*flags & MF_PAX_MPROTECT)
44430 +
44431 +#ifdef CONFIG_PAX_MPROTECT
44432 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44433 +#endif
44434 +
44435 + )
44436 + {
44437 + *flags &= ~MF_PAX_MPROTECT;
44438 + retval = -EINVAL;
44439 + }
44440 +
44441 + if ((*flags & MF_PAX_EMUTRAMP)
44442 +
44443 +#ifdef CONFIG_PAX_EMUTRAMP
44444 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
44445 +#endif
44446 +
44447 + )
44448 + {
44449 + *flags &= ~MF_PAX_EMUTRAMP;
44450 + retval = -EINVAL;
44451 + }
44452 +
44453 + return retval;
44454 +}
44455 +
44456 +EXPORT_SYMBOL(pax_check_flags);
44457 +
44458 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44459 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
44460 +{
44461 + struct task_struct *tsk = current;
44462 + struct mm_struct *mm = current->mm;
44463 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
44464 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
44465 + char *path_exec = NULL;
44466 + char *path_fault = NULL;
44467 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
44468 +
44469 + if (buffer_exec && buffer_fault) {
44470 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
44471 +
44472 + down_read(&mm->mmap_sem);
44473 + vma = mm->mmap;
44474 + while (vma && (!vma_exec || !vma_fault)) {
44475 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
44476 + vma_exec = vma;
44477 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
44478 + vma_fault = vma;
44479 + vma = vma->vm_next;
44480 + }
44481 + if (vma_exec) {
44482 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
44483 + if (IS_ERR(path_exec))
44484 + path_exec = "<path too long>";
44485 + else {
44486 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
44487 + if (path_exec) {
44488 + *path_exec = 0;
44489 + path_exec = buffer_exec;
44490 + } else
44491 + path_exec = "<path too long>";
44492 + }
44493 + }
44494 + if (vma_fault) {
44495 + start = vma_fault->vm_start;
44496 + end = vma_fault->vm_end;
44497 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
44498 + if (vma_fault->vm_file) {
44499 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
44500 + if (IS_ERR(path_fault))
44501 + path_fault = "<path too long>";
44502 + else {
44503 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
44504 + if (path_fault) {
44505 + *path_fault = 0;
44506 + path_fault = buffer_fault;
44507 + } else
44508 + path_fault = "<path too long>";
44509 + }
44510 + } else
44511 + path_fault = "<anonymous mapping>";
44512 + }
44513 + up_read(&mm->mmap_sem);
44514 + }
44515 + if (tsk->signal->curr_ip)
44516 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
44517 + else
44518 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
44519 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
44520 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
44521 + task_uid(tsk), task_euid(tsk), pc, sp);
44522 + free_page((unsigned long)buffer_exec);
44523 + free_page((unsigned long)buffer_fault);
44524 + pax_report_insns(regs, pc, sp);
44525 + do_coredump(SIGKILL, SIGKILL, regs);
44526 +}
44527 +#endif
44528 +
44529 +#ifdef CONFIG_PAX_REFCOUNT
44530 +void pax_report_refcount_overflow(struct pt_regs *regs)
44531 +{
44532 + if (current->signal->curr_ip)
44533 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44534 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
44535 + else
44536 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
44537 + current->comm, task_pid_nr(current), current_uid(), current_euid());
44538 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
44539 + show_regs(regs);
44540 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
44541 +}
44542 +#endif
44543 +
44544 +#ifdef CONFIG_PAX_USERCOPY
44545 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
44546 +int object_is_on_stack(const void *obj, unsigned long len)
44547 +{
44548 + const void * const stack = task_stack_page(current);
44549 + const void * const stackend = stack + THREAD_SIZE;
44550 +
44551 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44552 + const void *frame = NULL;
44553 + const void *oldframe;
44554 +#endif
44555 +
44556 + if (obj + len < obj)
44557 + return -1;
44558 +
44559 + if (obj + len <= stack || stackend <= obj)
44560 + return 0;
44561 +
44562 + if (obj < stack || stackend < obj + len)
44563 + return -1;
44564 +
44565 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
44566 + oldframe = __builtin_frame_address(1);
44567 + if (oldframe)
44568 + frame = __builtin_frame_address(2);
44569 + /*
44570 + low ----------------------------------------------> high
44571 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
44572 + ^----------------^
44573 + allow copies only within here
44574 + */
44575 + while (stack <= frame && frame < stackend) {
44576 + /* if obj + len extends past the last frame, this
44577 + check won't pass and the next frame will be 0,
44578 + causing us to bail out and correctly report
44579 + the copy as invalid
44580 + */
44581 + if (obj + len <= frame)
44582 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
44583 + oldframe = frame;
44584 + frame = *(const void * const *)frame;
44585 + }
44586 + return -1;
44587 +#else
44588 + return 1;
44589 +#endif
44590 +}
44591 +
44592 +__noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
44593 +{
44594 + if (current->signal->curr_ip)
44595 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44596 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44597 + else
44598 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
44599 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
44600 + dump_stack();
44601 + gr_handle_kernel_exploit();
44602 + do_group_exit(SIGKILL);
44603 +}
44604 +#endif
44605 +
44606 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
44607 +void pax_track_stack(void)
44608 +{
44609 + unsigned long sp = (unsigned long)&sp;
44610 + if (sp < current_thread_info()->lowest_stack &&
44611 + sp > (unsigned long)task_stack_page(current))
44612 + current_thread_info()->lowest_stack = sp;
44613 +}
44614 +EXPORT_SYMBOL(pax_track_stack);
44615 +#endif
44616 +
44617 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
44618 +void report_size_overflow(const char *file, unsigned int line, const char *func)
44619 +{
44620 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u\n", func, file, line);
44621 + dump_stack();
44622 + do_group_exit(SIGKILL);
44623 +}
44624 +EXPORT_SYMBOL(report_size_overflow);
44625 +#endif
44626 +
44627 static int zap_process(struct task_struct *start, int exit_code)
44628 {
44629 struct task_struct *t;
44630 @@ -2017,17 +2364,17 @@ static void wait_for_dump_helpers(struct file *file)
44631 pipe = file->f_path.dentry->d_inode->i_pipe;
44632
44633 pipe_lock(pipe);
44634 - pipe->readers++;
44635 - pipe->writers--;
44636 + atomic_inc(&pipe->readers);
44637 + atomic_dec(&pipe->writers);
44638
44639 - while ((pipe->readers > 1) && (!signal_pending(current))) {
44640 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
44641 wake_up_interruptible_sync(&pipe->wait);
44642 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
44643 pipe_wait(pipe);
44644 }
44645
44646 - pipe->readers--;
44647 - pipe->writers++;
44648 + atomic_dec(&pipe->readers);
44649 + atomic_inc(&pipe->writers);
44650 pipe_unlock(pipe);
44651
44652 }
44653 @@ -2088,7 +2435,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44654 int retval = 0;
44655 int flag = 0;
44656 int ispipe;
44657 - static atomic_t core_dump_count = ATOMIC_INIT(0);
44658 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
44659 struct coredump_params cprm = {
44660 .signr = signr,
44661 .regs = regs,
44662 @@ -2103,6 +2450,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44663
44664 audit_core_dumps(signr);
44665
44666 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
44667 + gr_handle_brute_attach(current, cprm.mm_flags);
44668 +
44669 binfmt = mm->binfmt;
44670 if (!binfmt || !binfmt->core_dump)
44671 goto fail;
44672 @@ -2170,7 +2520,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44673 }
44674 cprm.limit = RLIM_INFINITY;
44675
44676 - dump_count = atomic_inc_return(&core_dump_count);
44677 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
44678 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
44679 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
44680 task_tgid_vnr(current), current->comm);
44681 @@ -2197,6 +2547,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
44682 } else {
44683 struct inode *inode;
44684
44685 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
44686 +
44687 if (cprm.limit < binfmt->min_coredump)
44688 goto fail_unlock;
44689
44690 @@ -2240,7 +2592,7 @@ close_fail:
44691 filp_close(cprm.file, NULL);
44692 fail_dropcount:
44693 if (ispipe)
44694 - atomic_dec(&core_dump_count);
44695 + atomic_dec_unchecked(&core_dump_count);
44696 fail_unlock:
44697 kfree(cn.corename);
44698 fail_corename:
44699 @@ -2259,7 +2611,7 @@ fail:
44700 */
44701 int dump_write(struct file *file, const void *addr, int nr)
44702 {
44703 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
44704 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
44705 }
44706 EXPORT_SYMBOL(dump_write);
44707
44708 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
44709 index a8cbe1b..fed04cb 100644
44710 --- a/fs/ext2/balloc.c
44711 +++ b/fs/ext2/balloc.c
44712 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
44713
44714 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44715 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44716 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44717 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
44718 sbi->s_resuid != current_fsuid() &&
44719 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44720 return 0;
44721 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
44722 index a203892..4e64db5 100644
44723 --- a/fs/ext3/balloc.c
44724 +++ b/fs/ext3/balloc.c
44725 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
44726
44727 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
44728 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
44729 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
44730 + if (free_blocks < root_blocks + 1 &&
44731 !use_reservation && sbi->s_resuid != current_fsuid() &&
44732 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
44733 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
44734 + !capable_nolog(CAP_SYS_RESOURCE)) {
44735 return 0;
44736 }
44737 return 1;
44738 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
44739 index f9e2cd8..bfdc476 100644
44740 --- a/fs/ext4/balloc.c
44741 +++ b/fs/ext4/balloc.c
44742 @@ -438,8 +438,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
44743 /* Hm, nope. Are (enough) root reserved clusters available? */
44744 if (sbi->s_resuid == current_fsuid() ||
44745 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
44746 - capable(CAP_SYS_RESOURCE) ||
44747 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
44748 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
44749 + capable_nolog(CAP_SYS_RESOURCE)) {
44750
44751 if (free_clusters >= (nclusters + dirty_clusters))
44752 return 1;
44753 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
44754 index 9983ba8..2a5272c 100644
44755 --- a/fs/ext4/ext4.h
44756 +++ b/fs/ext4/ext4.h
44757 @@ -1217,19 +1217,19 @@ struct ext4_sb_info {
44758 unsigned long s_mb_last_start;
44759
44760 /* stats for buddy allocator */
44761 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
44762 - atomic_t s_bal_success; /* we found long enough chunks */
44763 - atomic_t s_bal_allocated; /* in blocks */
44764 - atomic_t s_bal_ex_scanned; /* total extents scanned */
44765 - atomic_t s_bal_goals; /* goal hits */
44766 - atomic_t s_bal_breaks; /* too long searches */
44767 - atomic_t s_bal_2orders; /* 2^order hits */
44768 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
44769 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
44770 + atomic_unchecked_t s_bal_allocated; /* in blocks */
44771 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
44772 + atomic_unchecked_t s_bal_goals; /* goal hits */
44773 + atomic_unchecked_t s_bal_breaks; /* too long searches */
44774 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
44775 spinlock_t s_bal_lock;
44776 unsigned long s_mb_buddies_generated;
44777 unsigned long long s_mb_generation_time;
44778 - atomic_t s_mb_lost_chunks;
44779 - atomic_t s_mb_preallocated;
44780 - atomic_t s_mb_discarded;
44781 + atomic_unchecked_t s_mb_lost_chunks;
44782 + atomic_unchecked_t s_mb_preallocated;
44783 + atomic_unchecked_t s_mb_discarded;
44784 atomic_t s_lock_busy;
44785
44786 /* locality groups */
44787 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
44788 index cb990b2..4820141 100644
44789 --- a/fs/ext4/mballoc.c
44790 +++ b/fs/ext4/mballoc.c
44791 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
44792 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
44793
44794 if (EXT4_SB(sb)->s_mb_stats)
44795 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
44796 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
44797
44798 break;
44799 }
44800 @@ -2088,7 +2088,7 @@ repeat:
44801 ac->ac_status = AC_STATUS_CONTINUE;
44802 ac->ac_flags |= EXT4_MB_HINT_FIRST;
44803 cr = 3;
44804 - atomic_inc(&sbi->s_mb_lost_chunks);
44805 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
44806 goto repeat;
44807 }
44808 }
44809 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
44810 if (sbi->s_mb_stats) {
44811 ext4_msg(sb, KERN_INFO,
44812 "mballoc: %u blocks %u reqs (%u success)",
44813 - atomic_read(&sbi->s_bal_allocated),
44814 - atomic_read(&sbi->s_bal_reqs),
44815 - atomic_read(&sbi->s_bal_success));
44816 + atomic_read_unchecked(&sbi->s_bal_allocated),
44817 + atomic_read_unchecked(&sbi->s_bal_reqs),
44818 + atomic_read_unchecked(&sbi->s_bal_success));
44819 ext4_msg(sb, KERN_INFO,
44820 "mballoc: %u extents scanned, %u goal hits, "
44821 "%u 2^N hits, %u breaks, %u lost",
44822 - atomic_read(&sbi->s_bal_ex_scanned),
44823 - atomic_read(&sbi->s_bal_goals),
44824 - atomic_read(&sbi->s_bal_2orders),
44825 - atomic_read(&sbi->s_bal_breaks),
44826 - atomic_read(&sbi->s_mb_lost_chunks));
44827 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
44828 + atomic_read_unchecked(&sbi->s_bal_goals),
44829 + atomic_read_unchecked(&sbi->s_bal_2orders),
44830 + atomic_read_unchecked(&sbi->s_bal_breaks),
44831 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
44832 ext4_msg(sb, KERN_INFO,
44833 "mballoc: %lu generated and it took %Lu",
44834 sbi->s_mb_buddies_generated,
44835 sbi->s_mb_generation_time);
44836 ext4_msg(sb, KERN_INFO,
44837 "mballoc: %u preallocated, %u discarded",
44838 - atomic_read(&sbi->s_mb_preallocated),
44839 - atomic_read(&sbi->s_mb_discarded));
44840 + atomic_read_unchecked(&sbi->s_mb_preallocated),
44841 + atomic_read_unchecked(&sbi->s_mb_discarded));
44842 }
44843
44844 free_percpu(sbi->s_locality_groups);
44845 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
44846 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
44847
44848 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
44849 - atomic_inc(&sbi->s_bal_reqs);
44850 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44851 + atomic_inc_unchecked(&sbi->s_bal_reqs);
44852 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
44853 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
44854 - atomic_inc(&sbi->s_bal_success);
44855 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
44856 + atomic_inc_unchecked(&sbi->s_bal_success);
44857 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
44858 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
44859 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
44860 - atomic_inc(&sbi->s_bal_goals);
44861 + atomic_inc_unchecked(&sbi->s_bal_goals);
44862 if (ac->ac_found > sbi->s_mb_max_to_scan)
44863 - atomic_inc(&sbi->s_bal_breaks);
44864 + atomic_inc_unchecked(&sbi->s_bal_breaks);
44865 }
44866
44867 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
44868 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
44869 trace_ext4_mb_new_inode_pa(ac, pa);
44870
44871 ext4_mb_use_inode_pa(ac, pa);
44872 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
44873 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
44874
44875 ei = EXT4_I(ac->ac_inode);
44876 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44877 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
44878 trace_ext4_mb_new_group_pa(ac, pa);
44879
44880 ext4_mb_use_group_pa(ac, pa);
44881 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44882 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
44883
44884 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
44885 lg = ac->ac_lg;
44886 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
44887 * from the bitmap and continue.
44888 */
44889 }
44890 - atomic_add(free, &sbi->s_mb_discarded);
44891 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
44892
44893 return err;
44894 }
44895 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
44896 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
44897 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
44898 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
44899 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44900 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
44901 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
44902
44903 return 0;
44904 diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
44905 index f9d948f..8601f4b 100644
44906 --- a/fs/ext4/resize.c
44907 +++ b/fs/ext4/resize.c
44908 @@ -161,6 +161,8 @@ static struct ext4_new_flex_group_data *alloc_flex_gd(unsigned long flexbg_size)
44909 if (flex_gd == NULL)
44910 goto out3;
44911
44912 + if (flexbg_size >= UINT_MAX / sizeof(struct ext4_new_flex_group_data))
44913 + goto out2;
44914 flex_gd->count = flexbg_size;
44915
44916 flex_gd->groups = kmalloc(sizeof(struct ext4_new_group_data) *
44917 diff --git a/fs/fcntl.c b/fs/fcntl.c
44918 index 22764c7..86372c9 100644
44919 --- a/fs/fcntl.c
44920 +++ b/fs/fcntl.c
44921 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
44922 if (err)
44923 return err;
44924
44925 + if (gr_handle_chroot_fowner(pid, type))
44926 + return -ENOENT;
44927 + if (gr_check_protected_task_fowner(pid, type))
44928 + return -EACCES;
44929 +
44930 f_modown(filp, pid, type, force);
44931 return 0;
44932 }
44933 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
44934
44935 static int f_setown_ex(struct file *filp, unsigned long arg)
44936 {
44937 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44938 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44939 struct f_owner_ex owner;
44940 struct pid *pid;
44941 int type;
44942 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
44943
44944 static int f_getown_ex(struct file *filp, unsigned long arg)
44945 {
44946 - struct f_owner_ex * __user owner_p = (void * __user)arg;
44947 + struct f_owner_ex __user *owner_p = (void __user *)arg;
44948 struct f_owner_ex owner;
44949 int ret = 0;
44950
44951 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
44952 switch (cmd) {
44953 case F_DUPFD:
44954 case F_DUPFD_CLOEXEC:
44955 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
44956 if (arg >= rlimit(RLIMIT_NOFILE))
44957 break;
44958 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
44959 diff --git a/fs/fifo.c b/fs/fifo.c
44960 index b1a524d..4ee270e 100644
44961 --- a/fs/fifo.c
44962 +++ b/fs/fifo.c
44963 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
44964 */
44965 filp->f_op = &read_pipefifo_fops;
44966 pipe->r_counter++;
44967 - if (pipe->readers++ == 0)
44968 + if (atomic_inc_return(&pipe->readers) == 1)
44969 wake_up_partner(inode);
44970
44971 - if (!pipe->writers) {
44972 + if (!atomic_read(&pipe->writers)) {
44973 if ((filp->f_flags & O_NONBLOCK)) {
44974 /* suppress POLLHUP until we have
44975 * seen a writer */
44976 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
44977 * errno=ENXIO when there is no process reading the FIFO.
44978 */
44979 ret = -ENXIO;
44980 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
44981 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
44982 goto err;
44983
44984 filp->f_op = &write_pipefifo_fops;
44985 pipe->w_counter++;
44986 - if (!pipe->writers++)
44987 + if (atomic_inc_return(&pipe->writers) == 1)
44988 wake_up_partner(inode);
44989
44990 - if (!pipe->readers) {
44991 + if (!atomic_read(&pipe->readers)) {
44992 wait_for_partner(inode, &pipe->r_counter);
44993 if (signal_pending(current))
44994 goto err_wr;
44995 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
44996 */
44997 filp->f_op = &rdwr_pipefifo_fops;
44998
44999 - pipe->readers++;
45000 - pipe->writers++;
45001 + atomic_inc(&pipe->readers);
45002 + atomic_inc(&pipe->writers);
45003 pipe->r_counter++;
45004 pipe->w_counter++;
45005 - if (pipe->readers == 1 || pipe->writers == 1)
45006 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45007 wake_up_partner(inode);
45008 break;
45009
45010 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45011 return 0;
45012
45013 err_rd:
45014 - if (!--pipe->readers)
45015 + if (atomic_dec_and_test(&pipe->readers))
45016 wake_up_interruptible(&pipe->wait);
45017 ret = -ERESTARTSYS;
45018 goto err;
45019
45020 err_wr:
45021 - if (!--pipe->writers)
45022 + if (atomic_dec_and_test(&pipe->writers))
45023 wake_up_interruptible(&pipe->wait);
45024 ret = -ERESTARTSYS;
45025 goto err;
45026
45027 err:
45028 - if (!pipe->readers && !pipe->writers)
45029 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45030 free_pipe_info(inode);
45031
45032 err_nocleanup:
45033 diff --git a/fs/file.c b/fs/file.c
45034 index 4c6992d..104cdea 100644
45035 --- a/fs/file.c
45036 +++ b/fs/file.c
45037 @@ -15,6 +15,7 @@
45038 #include <linux/slab.h>
45039 #include <linux/vmalloc.h>
45040 #include <linux/file.h>
45041 +#include <linux/security.h>
45042 #include <linux/fdtable.h>
45043 #include <linux/bitops.h>
45044 #include <linux/interrupt.h>
45045 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
45046 * N.B. For clone tasks sharing a files structure, this test
45047 * will limit the total number of files that can be opened.
45048 */
45049 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45050 if (nr >= rlimit(RLIMIT_NOFILE))
45051 return -EMFILE;
45052
45053 diff --git a/fs/filesystems.c b/fs/filesystems.c
45054 index 96f2428..f5eeb8e 100644
45055 --- a/fs/filesystems.c
45056 +++ b/fs/filesystems.c
45057 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45058 int len = dot ? dot - name : strlen(name);
45059
45060 fs = __get_fs_type(name, len);
45061 +
45062 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45063 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45064 +#else
45065 if (!fs && (request_module("%.*s", len, name) == 0))
45066 +#endif
45067 fs = __get_fs_type(name, len);
45068
45069 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45070 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45071 index 78b519c..a8b4979 100644
45072 --- a/fs/fs_struct.c
45073 +++ b/fs/fs_struct.c
45074 @@ -4,6 +4,7 @@
45075 #include <linux/path.h>
45076 #include <linux/slab.h>
45077 #include <linux/fs_struct.h>
45078 +#include <linux/grsecurity.h>
45079 #include "internal.h"
45080
45081 static inline void path_get_longterm(struct path *path)
45082 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45083 old_root = fs->root;
45084 fs->root = *path;
45085 path_get_longterm(path);
45086 + gr_set_chroot_entries(current, path);
45087 write_seqcount_end(&fs->seq);
45088 spin_unlock(&fs->lock);
45089 if (old_root.dentry)
45090 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45091 && fs->root.mnt == old_root->mnt) {
45092 path_get_longterm(new_root);
45093 fs->root = *new_root;
45094 + gr_set_chroot_entries(p, new_root);
45095 count++;
45096 }
45097 if (fs->pwd.dentry == old_root->dentry
45098 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
45099 spin_lock(&fs->lock);
45100 write_seqcount_begin(&fs->seq);
45101 tsk->fs = NULL;
45102 - kill = !--fs->users;
45103 + gr_clear_chroot_entries(tsk);
45104 + kill = !atomic_dec_return(&fs->users);
45105 write_seqcount_end(&fs->seq);
45106 spin_unlock(&fs->lock);
45107 task_unlock(tsk);
45108 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45109 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45110 /* We don't need to lock fs - think why ;-) */
45111 if (fs) {
45112 - fs->users = 1;
45113 + atomic_set(&fs->users, 1);
45114 fs->in_exec = 0;
45115 spin_lock_init(&fs->lock);
45116 seqcount_init(&fs->seq);
45117 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45118 spin_lock(&old->lock);
45119 fs->root = old->root;
45120 path_get_longterm(&fs->root);
45121 + /* instead of calling gr_set_chroot_entries here,
45122 + we call it from every caller of this function
45123 + */
45124 fs->pwd = old->pwd;
45125 path_get_longterm(&fs->pwd);
45126 spin_unlock(&old->lock);
45127 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
45128
45129 task_lock(current);
45130 spin_lock(&fs->lock);
45131 - kill = !--fs->users;
45132 + kill = !atomic_dec_return(&fs->users);
45133 current->fs = new_fs;
45134 + gr_set_chroot_entries(current, &new_fs->root);
45135 spin_unlock(&fs->lock);
45136 task_unlock(current);
45137
45138 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
45139
45140 int current_umask(void)
45141 {
45142 - return current->fs->umask;
45143 + return current->fs->umask | gr_acl_umask();
45144 }
45145 EXPORT_SYMBOL(current_umask);
45146
45147 /* to be mentioned only in INIT_TASK */
45148 struct fs_struct init_fs = {
45149 - .users = 1,
45150 + .users = ATOMIC_INIT(1),
45151 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
45152 .seq = SEQCNT_ZERO,
45153 .umask = 0022,
45154 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
45155 task_lock(current);
45156
45157 spin_lock(&init_fs.lock);
45158 - init_fs.users++;
45159 + atomic_inc(&init_fs.users);
45160 spin_unlock(&init_fs.lock);
45161
45162 spin_lock(&fs->lock);
45163 current->fs = &init_fs;
45164 - kill = !--fs->users;
45165 + gr_set_chroot_entries(current, &current->fs->root);
45166 + kill = !atomic_dec_return(&fs->users);
45167 spin_unlock(&fs->lock);
45168
45169 task_unlock(current);
45170 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
45171 index 9905350..02eaec4 100644
45172 --- a/fs/fscache/cookie.c
45173 +++ b/fs/fscache/cookie.c
45174 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
45175 parent ? (char *) parent->def->name : "<no-parent>",
45176 def->name, netfs_data);
45177
45178 - fscache_stat(&fscache_n_acquires);
45179 + fscache_stat_unchecked(&fscache_n_acquires);
45180
45181 /* if there's no parent cookie, then we don't create one here either */
45182 if (!parent) {
45183 - fscache_stat(&fscache_n_acquires_null);
45184 + fscache_stat_unchecked(&fscache_n_acquires_null);
45185 _leave(" [no parent]");
45186 return NULL;
45187 }
45188 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
45189 /* allocate and initialise a cookie */
45190 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
45191 if (!cookie) {
45192 - fscache_stat(&fscache_n_acquires_oom);
45193 + fscache_stat_unchecked(&fscache_n_acquires_oom);
45194 _leave(" [ENOMEM]");
45195 return NULL;
45196 }
45197 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45198
45199 switch (cookie->def->type) {
45200 case FSCACHE_COOKIE_TYPE_INDEX:
45201 - fscache_stat(&fscache_n_cookie_index);
45202 + fscache_stat_unchecked(&fscache_n_cookie_index);
45203 break;
45204 case FSCACHE_COOKIE_TYPE_DATAFILE:
45205 - fscache_stat(&fscache_n_cookie_data);
45206 + fscache_stat_unchecked(&fscache_n_cookie_data);
45207 break;
45208 default:
45209 - fscache_stat(&fscache_n_cookie_special);
45210 + fscache_stat_unchecked(&fscache_n_cookie_special);
45211 break;
45212 }
45213
45214 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
45215 if (fscache_acquire_non_index_cookie(cookie) < 0) {
45216 atomic_dec(&parent->n_children);
45217 __fscache_cookie_put(cookie);
45218 - fscache_stat(&fscache_n_acquires_nobufs);
45219 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
45220 _leave(" = NULL");
45221 return NULL;
45222 }
45223 }
45224
45225 - fscache_stat(&fscache_n_acquires_ok);
45226 + fscache_stat_unchecked(&fscache_n_acquires_ok);
45227 _leave(" = %p", cookie);
45228 return cookie;
45229 }
45230 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
45231 cache = fscache_select_cache_for_object(cookie->parent);
45232 if (!cache) {
45233 up_read(&fscache_addremove_sem);
45234 - fscache_stat(&fscache_n_acquires_no_cache);
45235 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
45236 _leave(" = -ENOMEDIUM [no cache]");
45237 return -ENOMEDIUM;
45238 }
45239 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
45240 object = cache->ops->alloc_object(cache, cookie);
45241 fscache_stat_d(&fscache_n_cop_alloc_object);
45242 if (IS_ERR(object)) {
45243 - fscache_stat(&fscache_n_object_no_alloc);
45244 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
45245 ret = PTR_ERR(object);
45246 goto error;
45247 }
45248
45249 - fscache_stat(&fscache_n_object_alloc);
45250 + fscache_stat_unchecked(&fscache_n_object_alloc);
45251
45252 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
45253
45254 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
45255 struct fscache_object *object;
45256 struct hlist_node *_p;
45257
45258 - fscache_stat(&fscache_n_updates);
45259 + fscache_stat_unchecked(&fscache_n_updates);
45260
45261 if (!cookie) {
45262 - fscache_stat(&fscache_n_updates_null);
45263 + fscache_stat_unchecked(&fscache_n_updates_null);
45264 _leave(" [no cookie]");
45265 return;
45266 }
45267 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45268 struct fscache_object *object;
45269 unsigned long event;
45270
45271 - fscache_stat(&fscache_n_relinquishes);
45272 + fscache_stat_unchecked(&fscache_n_relinquishes);
45273 if (retire)
45274 - fscache_stat(&fscache_n_relinquishes_retire);
45275 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
45276
45277 if (!cookie) {
45278 - fscache_stat(&fscache_n_relinquishes_null);
45279 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
45280 _leave(" [no cookie]");
45281 return;
45282 }
45283 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
45284
45285 /* wait for the cookie to finish being instantiated (or to fail) */
45286 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
45287 - fscache_stat(&fscache_n_relinquishes_waitcrt);
45288 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
45289 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
45290 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
45291 }
45292 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
45293 index f6aad48..88dcf26 100644
45294 --- a/fs/fscache/internal.h
45295 +++ b/fs/fscache/internal.h
45296 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
45297 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
45298 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
45299
45300 -extern atomic_t fscache_n_op_pend;
45301 -extern atomic_t fscache_n_op_run;
45302 -extern atomic_t fscache_n_op_enqueue;
45303 -extern atomic_t fscache_n_op_deferred_release;
45304 -extern atomic_t fscache_n_op_release;
45305 -extern atomic_t fscache_n_op_gc;
45306 -extern atomic_t fscache_n_op_cancelled;
45307 -extern atomic_t fscache_n_op_rejected;
45308 +extern atomic_unchecked_t fscache_n_op_pend;
45309 +extern atomic_unchecked_t fscache_n_op_run;
45310 +extern atomic_unchecked_t fscache_n_op_enqueue;
45311 +extern atomic_unchecked_t fscache_n_op_deferred_release;
45312 +extern atomic_unchecked_t fscache_n_op_release;
45313 +extern atomic_unchecked_t fscache_n_op_gc;
45314 +extern atomic_unchecked_t fscache_n_op_cancelled;
45315 +extern atomic_unchecked_t fscache_n_op_rejected;
45316
45317 -extern atomic_t fscache_n_attr_changed;
45318 -extern atomic_t fscache_n_attr_changed_ok;
45319 -extern atomic_t fscache_n_attr_changed_nobufs;
45320 -extern atomic_t fscache_n_attr_changed_nomem;
45321 -extern atomic_t fscache_n_attr_changed_calls;
45322 +extern atomic_unchecked_t fscache_n_attr_changed;
45323 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
45324 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
45325 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
45326 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
45327
45328 -extern atomic_t fscache_n_allocs;
45329 -extern atomic_t fscache_n_allocs_ok;
45330 -extern atomic_t fscache_n_allocs_wait;
45331 -extern atomic_t fscache_n_allocs_nobufs;
45332 -extern atomic_t fscache_n_allocs_intr;
45333 -extern atomic_t fscache_n_allocs_object_dead;
45334 -extern atomic_t fscache_n_alloc_ops;
45335 -extern atomic_t fscache_n_alloc_op_waits;
45336 +extern atomic_unchecked_t fscache_n_allocs;
45337 +extern atomic_unchecked_t fscache_n_allocs_ok;
45338 +extern atomic_unchecked_t fscache_n_allocs_wait;
45339 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
45340 +extern atomic_unchecked_t fscache_n_allocs_intr;
45341 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
45342 +extern atomic_unchecked_t fscache_n_alloc_ops;
45343 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
45344
45345 -extern atomic_t fscache_n_retrievals;
45346 -extern atomic_t fscache_n_retrievals_ok;
45347 -extern atomic_t fscache_n_retrievals_wait;
45348 -extern atomic_t fscache_n_retrievals_nodata;
45349 -extern atomic_t fscache_n_retrievals_nobufs;
45350 -extern atomic_t fscache_n_retrievals_intr;
45351 -extern atomic_t fscache_n_retrievals_nomem;
45352 -extern atomic_t fscache_n_retrievals_object_dead;
45353 -extern atomic_t fscache_n_retrieval_ops;
45354 -extern atomic_t fscache_n_retrieval_op_waits;
45355 +extern atomic_unchecked_t fscache_n_retrievals;
45356 +extern atomic_unchecked_t fscache_n_retrievals_ok;
45357 +extern atomic_unchecked_t fscache_n_retrievals_wait;
45358 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
45359 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
45360 +extern atomic_unchecked_t fscache_n_retrievals_intr;
45361 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
45362 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
45363 +extern atomic_unchecked_t fscache_n_retrieval_ops;
45364 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
45365
45366 -extern atomic_t fscache_n_stores;
45367 -extern atomic_t fscache_n_stores_ok;
45368 -extern atomic_t fscache_n_stores_again;
45369 -extern atomic_t fscache_n_stores_nobufs;
45370 -extern atomic_t fscache_n_stores_oom;
45371 -extern atomic_t fscache_n_store_ops;
45372 -extern atomic_t fscache_n_store_calls;
45373 -extern atomic_t fscache_n_store_pages;
45374 -extern atomic_t fscache_n_store_radix_deletes;
45375 -extern atomic_t fscache_n_store_pages_over_limit;
45376 +extern atomic_unchecked_t fscache_n_stores;
45377 +extern atomic_unchecked_t fscache_n_stores_ok;
45378 +extern atomic_unchecked_t fscache_n_stores_again;
45379 +extern atomic_unchecked_t fscache_n_stores_nobufs;
45380 +extern atomic_unchecked_t fscache_n_stores_oom;
45381 +extern atomic_unchecked_t fscache_n_store_ops;
45382 +extern atomic_unchecked_t fscache_n_store_calls;
45383 +extern atomic_unchecked_t fscache_n_store_pages;
45384 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
45385 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
45386
45387 -extern atomic_t fscache_n_store_vmscan_not_storing;
45388 -extern atomic_t fscache_n_store_vmscan_gone;
45389 -extern atomic_t fscache_n_store_vmscan_busy;
45390 -extern atomic_t fscache_n_store_vmscan_cancelled;
45391 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
45392 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
45393 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
45394 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
45395
45396 -extern atomic_t fscache_n_marks;
45397 -extern atomic_t fscache_n_uncaches;
45398 +extern atomic_unchecked_t fscache_n_marks;
45399 +extern atomic_unchecked_t fscache_n_uncaches;
45400
45401 -extern atomic_t fscache_n_acquires;
45402 -extern atomic_t fscache_n_acquires_null;
45403 -extern atomic_t fscache_n_acquires_no_cache;
45404 -extern atomic_t fscache_n_acquires_ok;
45405 -extern atomic_t fscache_n_acquires_nobufs;
45406 -extern atomic_t fscache_n_acquires_oom;
45407 +extern atomic_unchecked_t fscache_n_acquires;
45408 +extern atomic_unchecked_t fscache_n_acquires_null;
45409 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
45410 +extern atomic_unchecked_t fscache_n_acquires_ok;
45411 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
45412 +extern atomic_unchecked_t fscache_n_acquires_oom;
45413
45414 -extern atomic_t fscache_n_updates;
45415 -extern atomic_t fscache_n_updates_null;
45416 -extern atomic_t fscache_n_updates_run;
45417 +extern atomic_unchecked_t fscache_n_updates;
45418 +extern atomic_unchecked_t fscache_n_updates_null;
45419 +extern atomic_unchecked_t fscache_n_updates_run;
45420
45421 -extern atomic_t fscache_n_relinquishes;
45422 -extern atomic_t fscache_n_relinquishes_null;
45423 -extern atomic_t fscache_n_relinquishes_waitcrt;
45424 -extern atomic_t fscache_n_relinquishes_retire;
45425 +extern atomic_unchecked_t fscache_n_relinquishes;
45426 +extern atomic_unchecked_t fscache_n_relinquishes_null;
45427 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
45428 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
45429
45430 -extern atomic_t fscache_n_cookie_index;
45431 -extern atomic_t fscache_n_cookie_data;
45432 -extern atomic_t fscache_n_cookie_special;
45433 +extern atomic_unchecked_t fscache_n_cookie_index;
45434 +extern atomic_unchecked_t fscache_n_cookie_data;
45435 +extern atomic_unchecked_t fscache_n_cookie_special;
45436
45437 -extern atomic_t fscache_n_object_alloc;
45438 -extern atomic_t fscache_n_object_no_alloc;
45439 -extern atomic_t fscache_n_object_lookups;
45440 -extern atomic_t fscache_n_object_lookups_negative;
45441 -extern atomic_t fscache_n_object_lookups_positive;
45442 -extern atomic_t fscache_n_object_lookups_timed_out;
45443 -extern atomic_t fscache_n_object_created;
45444 -extern atomic_t fscache_n_object_avail;
45445 -extern atomic_t fscache_n_object_dead;
45446 +extern atomic_unchecked_t fscache_n_object_alloc;
45447 +extern atomic_unchecked_t fscache_n_object_no_alloc;
45448 +extern atomic_unchecked_t fscache_n_object_lookups;
45449 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
45450 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
45451 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
45452 +extern atomic_unchecked_t fscache_n_object_created;
45453 +extern atomic_unchecked_t fscache_n_object_avail;
45454 +extern atomic_unchecked_t fscache_n_object_dead;
45455
45456 -extern atomic_t fscache_n_checkaux_none;
45457 -extern atomic_t fscache_n_checkaux_okay;
45458 -extern atomic_t fscache_n_checkaux_update;
45459 -extern atomic_t fscache_n_checkaux_obsolete;
45460 +extern atomic_unchecked_t fscache_n_checkaux_none;
45461 +extern atomic_unchecked_t fscache_n_checkaux_okay;
45462 +extern atomic_unchecked_t fscache_n_checkaux_update;
45463 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
45464
45465 extern atomic_t fscache_n_cop_alloc_object;
45466 extern atomic_t fscache_n_cop_lookup_object;
45467 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
45468 atomic_inc(stat);
45469 }
45470
45471 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
45472 +{
45473 + atomic_inc_unchecked(stat);
45474 +}
45475 +
45476 static inline void fscache_stat_d(atomic_t *stat)
45477 {
45478 atomic_dec(stat);
45479 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
45480
45481 #define __fscache_stat(stat) (NULL)
45482 #define fscache_stat(stat) do {} while (0)
45483 +#define fscache_stat_unchecked(stat) do {} while (0)
45484 #define fscache_stat_d(stat) do {} while (0)
45485 #endif
45486
45487 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
45488 index b6b897c..0ffff9c 100644
45489 --- a/fs/fscache/object.c
45490 +++ b/fs/fscache/object.c
45491 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45492 /* update the object metadata on disk */
45493 case FSCACHE_OBJECT_UPDATING:
45494 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
45495 - fscache_stat(&fscache_n_updates_run);
45496 + fscache_stat_unchecked(&fscache_n_updates_run);
45497 fscache_stat(&fscache_n_cop_update_object);
45498 object->cache->ops->update_object(object);
45499 fscache_stat_d(&fscache_n_cop_update_object);
45500 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45501 spin_lock(&object->lock);
45502 object->state = FSCACHE_OBJECT_DEAD;
45503 spin_unlock(&object->lock);
45504 - fscache_stat(&fscache_n_object_dead);
45505 + fscache_stat_unchecked(&fscache_n_object_dead);
45506 goto terminal_transit;
45507
45508 /* handle the parent cache of this object being withdrawn from
45509 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
45510 spin_lock(&object->lock);
45511 object->state = FSCACHE_OBJECT_DEAD;
45512 spin_unlock(&object->lock);
45513 - fscache_stat(&fscache_n_object_dead);
45514 + fscache_stat_unchecked(&fscache_n_object_dead);
45515 goto terminal_transit;
45516
45517 /* complain about the object being woken up once it is
45518 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45519 parent->cookie->def->name, cookie->def->name,
45520 object->cache->tag->name);
45521
45522 - fscache_stat(&fscache_n_object_lookups);
45523 + fscache_stat_unchecked(&fscache_n_object_lookups);
45524 fscache_stat(&fscache_n_cop_lookup_object);
45525 ret = object->cache->ops->lookup_object(object);
45526 fscache_stat_d(&fscache_n_cop_lookup_object);
45527 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
45528 if (ret == -ETIMEDOUT) {
45529 /* probably stuck behind another object, so move this one to
45530 * the back of the queue */
45531 - fscache_stat(&fscache_n_object_lookups_timed_out);
45532 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
45533 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45534 }
45535
45536 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
45537
45538 spin_lock(&object->lock);
45539 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45540 - fscache_stat(&fscache_n_object_lookups_negative);
45541 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
45542
45543 /* transit here to allow write requests to begin stacking up
45544 * and read requests to begin returning ENODATA */
45545 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
45546 * result, in which case there may be data available */
45547 spin_lock(&object->lock);
45548 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
45549 - fscache_stat(&fscache_n_object_lookups_positive);
45550 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
45551
45552 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
45553
45554 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
45555 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
45556 } else {
45557 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
45558 - fscache_stat(&fscache_n_object_created);
45559 + fscache_stat_unchecked(&fscache_n_object_created);
45560
45561 object->state = FSCACHE_OBJECT_AVAILABLE;
45562 spin_unlock(&object->lock);
45563 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
45564 fscache_enqueue_dependents(object);
45565
45566 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
45567 - fscache_stat(&fscache_n_object_avail);
45568 + fscache_stat_unchecked(&fscache_n_object_avail);
45569
45570 _leave("");
45571 }
45572 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45573 enum fscache_checkaux result;
45574
45575 if (!object->cookie->def->check_aux) {
45576 - fscache_stat(&fscache_n_checkaux_none);
45577 + fscache_stat_unchecked(&fscache_n_checkaux_none);
45578 return FSCACHE_CHECKAUX_OKAY;
45579 }
45580
45581 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
45582 switch (result) {
45583 /* entry okay as is */
45584 case FSCACHE_CHECKAUX_OKAY:
45585 - fscache_stat(&fscache_n_checkaux_okay);
45586 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
45587 break;
45588
45589 /* entry requires update */
45590 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
45591 - fscache_stat(&fscache_n_checkaux_update);
45592 + fscache_stat_unchecked(&fscache_n_checkaux_update);
45593 break;
45594
45595 /* entry requires deletion */
45596 case FSCACHE_CHECKAUX_OBSOLETE:
45597 - fscache_stat(&fscache_n_checkaux_obsolete);
45598 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
45599 break;
45600
45601 default:
45602 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
45603 index 30afdfa..2256596 100644
45604 --- a/fs/fscache/operation.c
45605 +++ b/fs/fscache/operation.c
45606 @@ -17,7 +17,7 @@
45607 #include <linux/slab.h>
45608 #include "internal.h"
45609
45610 -atomic_t fscache_op_debug_id;
45611 +atomic_unchecked_t fscache_op_debug_id;
45612 EXPORT_SYMBOL(fscache_op_debug_id);
45613
45614 /**
45615 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
45616 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
45617 ASSERTCMP(atomic_read(&op->usage), >, 0);
45618
45619 - fscache_stat(&fscache_n_op_enqueue);
45620 + fscache_stat_unchecked(&fscache_n_op_enqueue);
45621 switch (op->flags & FSCACHE_OP_TYPE) {
45622 case FSCACHE_OP_ASYNC:
45623 _debug("queue async");
45624 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
45625 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
45626 if (op->processor)
45627 fscache_enqueue_operation(op);
45628 - fscache_stat(&fscache_n_op_run);
45629 + fscache_stat_unchecked(&fscache_n_op_run);
45630 }
45631
45632 /*
45633 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45634 if (object->n_ops > 1) {
45635 atomic_inc(&op->usage);
45636 list_add_tail(&op->pend_link, &object->pending_ops);
45637 - fscache_stat(&fscache_n_op_pend);
45638 + fscache_stat_unchecked(&fscache_n_op_pend);
45639 } else if (!list_empty(&object->pending_ops)) {
45640 atomic_inc(&op->usage);
45641 list_add_tail(&op->pend_link, &object->pending_ops);
45642 - fscache_stat(&fscache_n_op_pend);
45643 + fscache_stat_unchecked(&fscache_n_op_pend);
45644 fscache_start_operations(object);
45645 } else {
45646 ASSERTCMP(object->n_in_progress, ==, 0);
45647 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
45648 object->n_exclusive++; /* reads and writes must wait */
45649 atomic_inc(&op->usage);
45650 list_add_tail(&op->pend_link, &object->pending_ops);
45651 - fscache_stat(&fscache_n_op_pend);
45652 + fscache_stat_unchecked(&fscache_n_op_pend);
45653 ret = 0;
45654 } else {
45655 /* not allowed to submit ops in any other state */
45656 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
45657 if (object->n_exclusive > 0) {
45658 atomic_inc(&op->usage);
45659 list_add_tail(&op->pend_link, &object->pending_ops);
45660 - fscache_stat(&fscache_n_op_pend);
45661 + fscache_stat_unchecked(&fscache_n_op_pend);
45662 } else if (!list_empty(&object->pending_ops)) {
45663 atomic_inc(&op->usage);
45664 list_add_tail(&op->pend_link, &object->pending_ops);
45665 - fscache_stat(&fscache_n_op_pend);
45666 + fscache_stat_unchecked(&fscache_n_op_pend);
45667 fscache_start_operations(object);
45668 } else {
45669 ASSERTCMP(object->n_exclusive, ==, 0);
45670 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
45671 object->n_ops++;
45672 atomic_inc(&op->usage);
45673 list_add_tail(&op->pend_link, &object->pending_ops);
45674 - fscache_stat(&fscache_n_op_pend);
45675 + fscache_stat_unchecked(&fscache_n_op_pend);
45676 ret = 0;
45677 } else if (object->state == FSCACHE_OBJECT_DYING ||
45678 object->state == FSCACHE_OBJECT_LC_DYING ||
45679 object->state == FSCACHE_OBJECT_WITHDRAWING) {
45680 - fscache_stat(&fscache_n_op_rejected);
45681 + fscache_stat_unchecked(&fscache_n_op_rejected);
45682 ret = -ENOBUFS;
45683 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
45684 fscache_report_unexpected_submission(object, op, ostate);
45685 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
45686
45687 ret = -EBUSY;
45688 if (!list_empty(&op->pend_link)) {
45689 - fscache_stat(&fscache_n_op_cancelled);
45690 + fscache_stat_unchecked(&fscache_n_op_cancelled);
45691 list_del_init(&op->pend_link);
45692 object->n_ops--;
45693 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
45694 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
45695 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
45696 BUG();
45697
45698 - fscache_stat(&fscache_n_op_release);
45699 + fscache_stat_unchecked(&fscache_n_op_release);
45700
45701 if (op->release) {
45702 op->release(op);
45703 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
45704 * lock, and defer it otherwise */
45705 if (!spin_trylock(&object->lock)) {
45706 _debug("defer put");
45707 - fscache_stat(&fscache_n_op_deferred_release);
45708 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
45709
45710 cache = object->cache;
45711 spin_lock(&cache->op_gc_list_lock);
45712 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
45713
45714 _debug("GC DEFERRED REL OBJ%x OP%x",
45715 object->debug_id, op->debug_id);
45716 - fscache_stat(&fscache_n_op_gc);
45717 + fscache_stat_unchecked(&fscache_n_op_gc);
45718
45719 ASSERTCMP(atomic_read(&op->usage), ==, 0);
45720
45721 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
45722 index 3f7a59b..cf196cc 100644
45723 --- a/fs/fscache/page.c
45724 +++ b/fs/fscache/page.c
45725 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45726 val = radix_tree_lookup(&cookie->stores, page->index);
45727 if (!val) {
45728 rcu_read_unlock();
45729 - fscache_stat(&fscache_n_store_vmscan_not_storing);
45730 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
45731 __fscache_uncache_page(cookie, page);
45732 return true;
45733 }
45734 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
45735 spin_unlock(&cookie->stores_lock);
45736
45737 if (xpage) {
45738 - fscache_stat(&fscache_n_store_vmscan_cancelled);
45739 - fscache_stat(&fscache_n_store_radix_deletes);
45740 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
45741 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45742 ASSERTCMP(xpage, ==, page);
45743 } else {
45744 - fscache_stat(&fscache_n_store_vmscan_gone);
45745 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
45746 }
45747
45748 wake_up_bit(&cookie->flags, 0);
45749 @@ -107,7 +107,7 @@ page_busy:
45750 /* we might want to wait here, but that could deadlock the allocator as
45751 * the work threads writing to the cache may all end up sleeping
45752 * on memory allocation */
45753 - fscache_stat(&fscache_n_store_vmscan_busy);
45754 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
45755 return false;
45756 }
45757 EXPORT_SYMBOL(__fscache_maybe_release_page);
45758 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
45759 FSCACHE_COOKIE_STORING_TAG);
45760 if (!radix_tree_tag_get(&cookie->stores, page->index,
45761 FSCACHE_COOKIE_PENDING_TAG)) {
45762 - fscache_stat(&fscache_n_store_radix_deletes);
45763 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
45764 xpage = radix_tree_delete(&cookie->stores, page->index);
45765 }
45766 spin_unlock(&cookie->stores_lock);
45767 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
45768
45769 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
45770
45771 - fscache_stat(&fscache_n_attr_changed_calls);
45772 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
45773
45774 if (fscache_object_is_active(object)) {
45775 fscache_stat(&fscache_n_cop_attr_changed);
45776 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45777
45778 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
45779
45780 - fscache_stat(&fscache_n_attr_changed);
45781 + fscache_stat_unchecked(&fscache_n_attr_changed);
45782
45783 op = kzalloc(sizeof(*op), GFP_KERNEL);
45784 if (!op) {
45785 - fscache_stat(&fscache_n_attr_changed_nomem);
45786 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
45787 _leave(" = -ENOMEM");
45788 return -ENOMEM;
45789 }
45790 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45791 if (fscache_submit_exclusive_op(object, op) < 0)
45792 goto nobufs;
45793 spin_unlock(&cookie->lock);
45794 - fscache_stat(&fscache_n_attr_changed_ok);
45795 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
45796 fscache_put_operation(op);
45797 _leave(" = 0");
45798 return 0;
45799 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
45800 nobufs:
45801 spin_unlock(&cookie->lock);
45802 kfree(op);
45803 - fscache_stat(&fscache_n_attr_changed_nobufs);
45804 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
45805 _leave(" = %d", -ENOBUFS);
45806 return -ENOBUFS;
45807 }
45808 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
45809 /* allocate a retrieval operation and attempt to submit it */
45810 op = kzalloc(sizeof(*op), GFP_NOIO);
45811 if (!op) {
45812 - fscache_stat(&fscache_n_retrievals_nomem);
45813 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45814 return NULL;
45815 }
45816
45817 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45818 return 0;
45819 }
45820
45821 - fscache_stat(&fscache_n_retrievals_wait);
45822 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
45823
45824 jif = jiffies;
45825 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
45826 fscache_wait_bit_interruptible,
45827 TASK_INTERRUPTIBLE) != 0) {
45828 - fscache_stat(&fscache_n_retrievals_intr);
45829 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45830 _leave(" = -ERESTARTSYS");
45831 return -ERESTARTSYS;
45832 }
45833 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
45834 */
45835 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45836 struct fscache_retrieval *op,
45837 - atomic_t *stat_op_waits,
45838 - atomic_t *stat_object_dead)
45839 + atomic_unchecked_t *stat_op_waits,
45840 + atomic_unchecked_t *stat_object_dead)
45841 {
45842 int ret;
45843
45844 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45845 goto check_if_dead;
45846
45847 _debug(">>> WT");
45848 - fscache_stat(stat_op_waits);
45849 + fscache_stat_unchecked(stat_op_waits);
45850 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
45851 fscache_wait_bit_interruptible,
45852 TASK_INTERRUPTIBLE) < 0) {
45853 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
45854
45855 check_if_dead:
45856 if (unlikely(fscache_object_is_dead(object))) {
45857 - fscache_stat(stat_object_dead);
45858 + fscache_stat_unchecked(stat_object_dead);
45859 return -ENOBUFS;
45860 }
45861 return 0;
45862 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45863
45864 _enter("%p,%p,,,", cookie, page);
45865
45866 - fscache_stat(&fscache_n_retrievals);
45867 + fscache_stat_unchecked(&fscache_n_retrievals);
45868
45869 if (hlist_empty(&cookie->backing_objects))
45870 goto nobufs;
45871 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45872 goto nobufs_unlock;
45873 spin_unlock(&cookie->lock);
45874
45875 - fscache_stat(&fscache_n_retrieval_ops);
45876 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45877
45878 /* pin the netfs read context in case we need to do the actual netfs
45879 * read because we've encountered a cache read failure */
45880 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
45881
45882 error:
45883 if (ret == -ENOMEM)
45884 - fscache_stat(&fscache_n_retrievals_nomem);
45885 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45886 else if (ret == -ERESTARTSYS)
45887 - fscache_stat(&fscache_n_retrievals_intr);
45888 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45889 else if (ret == -ENODATA)
45890 - fscache_stat(&fscache_n_retrievals_nodata);
45891 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45892 else if (ret < 0)
45893 - fscache_stat(&fscache_n_retrievals_nobufs);
45894 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45895 else
45896 - fscache_stat(&fscache_n_retrievals_ok);
45897 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45898
45899 fscache_put_retrieval(op);
45900 _leave(" = %d", ret);
45901 @@ -429,7 +429,7 @@ nobufs_unlock:
45902 spin_unlock(&cookie->lock);
45903 kfree(op);
45904 nobufs:
45905 - fscache_stat(&fscache_n_retrievals_nobufs);
45906 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45907 _leave(" = -ENOBUFS");
45908 return -ENOBUFS;
45909 }
45910 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45911
45912 _enter("%p,,%d,,,", cookie, *nr_pages);
45913
45914 - fscache_stat(&fscache_n_retrievals);
45915 + fscache_stat_unchecked(&fscache_n_retrievals);
45916
45917 if (hlist_empty(&cookie->backing_objects))
45918 goto nobufs;
45919 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45920 goto nobufs_unlock;
45921 spin_unlock(&cookie->lock);
45922
45923 - fscache_stat(&fscache_n_retrieval_ops);
45924 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
45925
45926 /* pin the netfs read context in case we need to do the actual netfs
45927 * read because we've encountered a cache read failure */
45928 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
45929
45930 error:
45931 if (ret == -ENOMEM)
45932 - fscache_stat(&fscache_n_retrievals_nomem);
45933 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
45934 else if (ret == -ERESTARTSYS)
45935 - fscache_stat(&fscache_n_retrievals_intr);
45936 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
45937 else if (ret == -ENODATA)
45938 - fscache_stat(&fscache_n_retrievals_nodata);
45939 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
45940 else if (ret < 0)
45941 - fscache_stat(&fscache_n_retrievals_nobufs);
45942 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45943 else
45944 - fscache_stat(&fscache_n_retrievals_ok);
45945 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
45946
45947 fscache_put_retrieval(op);
45948 _leave(" = %d", ret);
45949 @@ -545,7 +545,7 @@ nobufs_unlock:
45950 spin_unlock(&cookie->lock);
45951 kfree(op);
45952 nobufs:
45953 - fscache_stat(&fscache_n_retrievals_nobufs);
45954 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
45955 _leave(" = -ENOBUFS");
45956 return -ENOBUFS;
45957 }
45958 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45959
45960 _enter("%p,%p,,,", cookie, page);
45961
45962 - fscache_stat(&fscache_n_allocs);
45963 + fscache_stat_unchecked(&fscache_n_allocs);
45964
45965 if (hlist_empty(&cookie->backing_objects))
45966 goto nobufs;
45967 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45968 goto nobufs_unlock;
45969 spin_unlock(&cookie->lock);
45970
45971 - fscache_stat(&fscache_n_alloc_ops);
45972 + fscache_stat_unchecked(&fscache_n_alloc_ops);
45973
45974 ret = fscache_wait_for_retrieval_activation(
45975 object, op,
45976 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
45977
45978 error:
45979 if (ret == -ERESTARTSYS)
45980 - fscache_stat(&fscache_n_allocs_intr);
45981 + fscache_stat_unchecked(&fscache_n_allocs_intr);
45982 else if (ret < 0)
45983 - fscache_stat(&fscache_n_allocs_nobufs);
45984 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45985 else
45986 - fscache_stat(&fscache_n_allocs_ok);
45987 + fscache_stat_unchecked(&fscache_n_allocs_ok);
45988
45989 fscache_put_retrieval(op);
45990 _leave(" = %d", ret);
45991 @@ -625,7 +625,7 @@ nobufs_unlock:
45992 spin_unlock(&cookie->lock);
45993 kfree(op);
45994 nobufs:
45995 - fscache_stat(&fscache_n_allocs_nobufs);
45996 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
45997 _leave(" = -ENOBUFS");
45998 return -ENOBUFS;
45999 }
46000 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46001
46002 spin_lock(&cookie->stores_lock);
46003
46004 - fscache_stat(&fscache_n_store_calls);
46005 + fscache_stat_unchecked(&fscache_n_store_calls);
46006
46007 /* find a page to store */
46008 page = NULL;
46009 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46010 page = results[0];
46011 _debug("gang %d [%lx]", n, page->index);
46012 if (page->index > op->store_limit) {
46013 - fscache_stat(&fscache_n_store_pages_over_limit);
46014 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46015 goto superseded;
46016 }
46017
46018 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46019 spin_unlock(&cookie->stores_lock);
46020 spin_unlock(&object->lock);
46021
46022 - fscache_stat(&fscache_n_store_pages);
46023 + fscache_stat_unchecked(&fscache_n_store_pages);
46024 fscache_stat(&fscache_n_cop_write_page);
46025 ret = object->cache->ops->write_page(op, page);
46026 fscache_stat_d(&fscache_n_cop_write_page);
46027 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46028 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46029 ASSERT(PageFsCache(page));
46030
46031 - fscache_stat(&fscache_n_stores);
46032 + fscache_stat_unchecked(&fscache_n_stores);
46033
46034 op = kzalloc(sizeof(*op), GFP_NOIO);
46035 if (!op)
46036 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46037 spin_unlock(&cookie->stores_lock);
46038 spin_unlock(&object->lock);
46039
46040 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46041 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46042 op->store_limit = object->store_limit;
46043
46044 if (fscache_submit_op(object, &op->op) < 0)
46045 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46046
46047 spin_unlock(&cookie->lock);
46048 radix_tree_preload_end();
46049 - fscache_stat(&fscache_n_store_ops);
46050 - fscache_stat(&fscache_n_stores_ok);
46051 + fscache_stat_unchecked(&fscache_n_store_ops);
46052 + fscache_stat_unchecked(&fscache_n_stores_ok);
46053
46054 /* the work queue now carries its own ref on the object */
46055 fscache_put_operation(&op->op);
46056 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46057 return 0;
46058
46059 already_queued:
46060 - fscache_stat(&fscache_n_stores_again);
46061 + fscache_stat_unchecked(&fscache_n_stores_again);
46062 already_pending:
46063 spin_unlock(&cookie->stores_lock);
46064 spin_unlock(&object->lock);
46065 spin_unlock(&cookie->lock);
46066 radix_tree_preload_end();
46067 kfree(op);
46068 - fscache_stat(&fscache_n_stores_ok);
46069 + fscache_stat_unchecked(&fscache_n_stores_ok);
46070 _leave(" = 0");
46071 return 0;
46072
46073 @@ -851,14 +851,14 @@ nobufs:
46074 spin_unlock(&cookie->lock);
46075 radix_tree_preload_end();
46076 kfree(op);
46077 - fscache_stat(&fscache_n_stores_nobufs);
46078 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46079 _leave(" = -ENOBUFS");
46080 return -ENOBUFS;
46081
46082 nomem_free:
46083 kfree(op);
46084 nomem:
46085 - fscache_stat(&fscache_n_stores_oom);
46086 + fscache_stat_unchecked(&fscache_n_stores_oom);
46087 _leave(" = -ENOMEM");
46088 return -ENOMEM;
46089 }
46090 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46091 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46092 ASSERTCMP(page, !=, NULL);
46093
46094 - fscache_stat(&fscache_n_uncaches);
46095 + fscache_stat_unchecked(&fscache_n_uncaches);
46096
46097 /* cache withdrawal may beat us to it */
46098 if (!PageFsCache(page))
46099 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46100 unsigned long loop;
46101
46102 #ifdef CONFIG_FSCACHE_STATS
46103 - atomic_add(pagevec->nr, &fscache_n_marks);
46104 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46105 #endif
46106
46107 for (loop = 0; loop < pagevec->nr; loop++) {
46108 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46109 index 4765190..2a067f2 100644
46110 --- a/fs/fscache/stats.c
46111 +++ b/fs/fscache/stats.c
46112 @@ -18,95 +18,95 @@
46113 /*
46114 * operation counters
46115 */
46116 -atomic_t fscache_n_op_pend;
46117 -atomic_t fscache_n_op_run;
46118 -atomic_t fscache_n_op_enqueue;
46119 -atomic_t fscache_n_op_requeue;
46120 -atomic_t fscache_n_op_deferred_release;
46121 -atomic_t fscache_n_op_release;
46122 -atomic_t fscache_n_op_gc;
46123 -atomic_t fscache_n_op_cancelled;
46124 -atomic_t fscache_n_op_rejected;
46125 +atomic_unchecked_t fscache_n_op_pend;
46126 +atomic_unchecked_t fscache_n_op_run;
46127 +atomic_unchecked_t fscache_n_op_enqueue;
46128 +atomic_unchecked_t fscache_n_op_requeue;
46129 +atomic_unchecked_t fscache_n_op_deferred_release;
46130 +atomic_unchecked_t fscache_n_op_release;
46131 +atomic_unchecked_t fscache_n_op_gc;
46132 +atomic_unchecked_t fscache_n_op_cancelled;
46133 +atomic_unchecked_t fscache_n_op_rejected;
46134
46135 -atomic_t fscache_n_attr_changed;
46136 -atomic_t fscache_n_attr_changed_ok;
46137 -atomic_t fscache_n_attr_changed_nobufs;
46138 -atomic_t fscache_n_attr_changed_nomem;
46139 -atomic_t fscache_n_attr_changed_calls;
46140 +atomic_unchecked_t fscache_n_attr_changed;
46141 +atomic_unchecked_t fscache_n_attr_changed_ok;
46142 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
46143 +atomic_unchecked_t fscache_n_attr_changed_nomem;
46144 +atomic_unchecked_t fscache_n_attr_changed_calls;
46145
46146 -atomic_t fscache_n_allocs;
46147 -atomic_t fscache_n_allocs_ok;
46148 -atomic_t fscache_n_allocs_wait;
46149 -atomic_t fscache_n_allocs_nobufs;
46150 -atomic_t fscache_n_allocs_intr;
46151 -atomic_t fscache_n_allocs_object_dead;
46152 -atomic_t fscache_n_alloc_ops;
46153 -atomic_t fscache_n_alloc_op_waits;
46154 +atomic_unchecked_t fscache_n_allocs;
46155 +atomic_unchecked_t fscache_n_allocs_ok;
46156 +atomic_unchecked_t fscache_n_allocs_wait;
46157 +atomic_unchecked_t fscache_n_allocs_nobufs;
46158 +atomic_unchecked_t fscache_n_allocs_intr;
46159 +atomic_unchecked_t fscache_n_allocs_object_dead;
46160 +atomic_unchecked_t fscache_n_alloc_ops;
46161 +atomic_unchecked_t fscache_n_alloc_op_waits;
46162
46163 -atomic_t fscache_n_retrievals;
46164 -atomic_t fscache_n_retrievals_ok;
46165 -atomic_t fscache_n_retrievals_wait;
46166 -atomic_t fscache_n_retrievals_nodata;
46167 -atomic_t fscache_n_retrievals_nobufs;
46168 -atomic_t fscache_n_retrievals_intr;
46169 -atomic_t fscache_n_retrievals_nomem;
46170 -atomic_t fscache_n_retrievals_object_dead;
46171 -atomic_t fscache_n_retrieval_ops;
46172 -atomic_t fscache_n_retrieval_op_waits;
46173 +atomic_unchecked_t fscache_n_retrievals;
46174 +atomic_unchecked_t fscache_n_retrievals_ok;
46175 +atomic_unchecked_t fscache_n_retrievals_wait;
46176 +atomic_unchecked_t fscache_n_retrievals_nodata;
46177 +atomic_unchecked_t fscache_n_retrievals_nobufs;
46178 +atomic_unchecked_t fscache_n_retrievals_intr;
46179 +atomic_unchecked_t fscache_n_retrievals_nomem;
46180 +atomic_unchecked_t fscache_n_retrievals_object_dead;
46181 +atomic_unchecked_t fscache_n_retrieval_ops;
46182 +atomic_unchecked_t fscache_n_retrieval_op_waits;
46183
46184 -atomic_t fscache_n_stores;
46185 -atomic_t fscache_n_stores_ok;
46186 -atomic_t fscache_n_stores_again;
46187 -atomic_t fscache_n_stores_nobufs;
46188 -atomic_t fscache_n_stores_oom;
46189 -atomic_t fscache_n_store_ops;
46190 -atomic_t fscache_n_store_calls;
46191 -atomic_t fscache_n_store_pages;
46192 -atomic_t fscache_n_store_radix_deletes;
46193 -atomic_t fscache_n_store_pages_over_limit;
46194 +atomic_unchecked_t fscache_n_stores;
46195 +atomic_unchecked_t fscache_n_stores_ok;
46196 +atomic_unchecked_t fscache_n_stores_again;
46197 +atomic_unchecked_t fscache_n_stores_nobufs;
46198 +atomic_unchecked_t fscache_n_stores_oom;
46199 +atomic_unchecked_t fscache_n_store_ops;
46200 +atomic_unchecked_t fscache_n_store_calls;
46201 +atomic_unchecked_t fscache_n_store_pages;
46202 +atomic_unchecked_t fscache_n_store_radix_deletes;
46203 +atomic_unchecked_t fscache_n_store_pages_over_limit;
46204
46205 -atomic_t fscache_n_store_vmscan_not_storing;
46206 -atomic_t fscache_n_store_vmscan_gone;
46207 -atomic_t fscache_n_store_vmscan_busy;
46208 -atomic_t fscache_n_store_vmscan_cancelled;
46209 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46210 +atomic_unchecked_t fscache_n_store_vmscan_gone;
46211 +atomic_unchecked_t fscache_n_store_vmscan_busy;
46212 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46213
46214 -atomic_t fscache_n_marks;
46215 -atomic_t fscache_n_uncaches;
46216 +atomic_unchecked_t fscache_n_marks;
46217 +atomic_unchecked_t fscache_n_uncaches;
46218
46219 -atomic_t fscache_n_acquires;
46220 -atomic_t fscache_n_acquires_null;
46221 -atomic_t fscache_n_acquires_no_cache;
46222 -atomic_t fscache_n_acquires_ok;
46223 -atomic_t fscache_n_acquires_nobufs;
46224 -atomic_t fscache_n_acquires_oom;
46225 +atomic_unchecked_t fscache_n_acquires;
46226 +atomic_unchecked_t fscache_n_acquires_null;
46227 +atomic_unchecked_t fscache_n_acquires_no_cache;
46228 +atomic_unchecked_t fscache_n_acquires_ok;
46229 +atomic_unchecked_t fscache_n_acquires_nobufs;
46230 +atomic_unchecked_t fscache_n_acquires_oom;
46231
46232 -atomic_t fscache_n_updates;
46233 -atomic_t fscache_n_updates_null;
46234 -atomic_t fscache_n_updates_run;
46235 +atomic_unchecked_t fscache_n_updates;
46236 +atomic_unchecked_t fscache_n_updates_null;
46237 +atomic_unchecked_t fscache_n_updates_run;
46238
46239 -atomic_t fscache_n_relinquishes;
46240 -atomic_t fscache_n_relinquishes_null;
46241 -atomic_t fscache_n_relinquishes_waitcrt;
46242 -atomic_t fscache_n_relinquishes_retire;
46243 +atomic_unchecked_t fscache_n_relinquishes;
46244 +atomic_unchecked_t fscache_n_relinquishes_null;
46245 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46246 +atomic_unchecked_t fscache_n_relinquishes_retire;
46247
46248 -atomic_t fscache_n_cookie_index;
46249 -atomic_t fscache_n_cookie_data;
46250 -atomic_t fscache_n_cookie_special;
46251 +atomic_unchecked_t fscache_n_cookie_index;
46252 +atomic_unchecked_t fscache_n_cookie_data;
46253 +atomic_unchecked_t fscache_n_cookie_special;
46254
46255 -atomic_t fscache_n_object_alloc;
46256 -atomic_t fscache_n_object_no_alloc;
46257 -atomic_t fscache_n_object_lookups;
46258 -atomic_t fscache_n_object_lookups_negative;
46259 -atomic_t fscache_n_object_lookups_positive;
46260 -atomic_t fscache_n_object_lookups_timed_out;
46261 -atomic_t fscache_n_object_created;
46262 -atomic_t fscache_n_object_avail;
46263 -atomic_t fscache_n_object_dead;
46264 +atomic_unchecked_t fscache_n_object_alloc;
46265 +atomic_unchecked_t fscache_n_object_no_alloc;
46266 +atomic_unchecked_t fscache_n_object_lookups;
46267 +atomic_unchecked_t fscache_n_object_lookups_negative;
46268 +atomic_unchecked_t fscache_n_object_lookups_positive;
46269 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
46270 +atomic_unchecked_t fscache_n_object_created;
46271 +atomic_unchecked_t fscache_n_object_avail;
46272 +atomic_unchecked_t fscache_n_object_dead;
46273
46274 -atomic_t fscache_n_checkaux_none;
46275 -atomic_t fscache_n_checkaux_okay;
46276 -atomic_t fscache_n_checkaux_update;
46277 -atomic_t fscache_n_checkaux_obsolete;
46278 +atomic_unchecked_t fscache_n_checkaux_none;
46279 +atomic_unchecked_t fscache_n_checkaux_okay;
46280 +atomic_unchecked_t fscache_n_checkaux_update;
46281 +atomic_unchecked_t fscache_n_checkaux_obsolete;
46282
46283 atomic_t fscache_n_cop_alloc_object;
46284 atomic_t fscache_n_cop_lookup_object;
46285 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
46286 seq_puts(m, "FS-Cache statistics\n");
46287
46288 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
46289 - atomic_read(&fscache_n_cookie_index),
46290 - atomic_read(&fscache_n_cookie_data),
46291 - atomic_read(&fscache_n_cookie_special));
46292 + atomic_read_unchecked(&fscache_n_cookie_index),
46293 + atomic_read_unchecked(&fscache_n_cookie_data),
46294 + atomic_read_unchecked(&fscache_n_cookie_special));
46295
46296 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
46297 - atomic_read(&fscache_n_object_alloc),
46298 - atomic_read(&fscache_n_object_no_alloc),
46299 - atomic_read(&fscache_n_object_avail),
46300 - atomic_read(&fscache_n_object_dead));
46301 + atomic_read_unchecked(&fscache_n_object_alloc),
46302 + atomic_read_unchecked(&fscache_n_object_no_alloc),
46303 + atomic_read_unchecked(&fscache_n_object_avail),
46304 + atomic_read_unchecked(&fscache_n_object_dead));
46305 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
46306 - atomic_read(&fscache_n_checkaux_none),
46307 - atomic_read(&fscache_n_checkaux_okay),
46308 - atomic_read(&fscache_n_checkaux_update),
46309 - atomic_read(&fscache_n_checkaux_obsolete));
46310 + atomic_read_unchecked(&fscache_n_checkaux_none),
46311 + atomic_read_unchecked(&fscache_n_checkaux_okay),
46312 + atomic_read_unchecked(&fscache_n_checkaux_update),
46313 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
46314
46315 seq_printf(m, "Pages : mrk=%u unc=%u\n",
46316 - atomic_read(&fscache_n_marks),
46317 - atomic_read(&fscache_n_uncaches));
46318 + atomic_read_unchecked(&fscache_n_marks),
46319 + atomic_read_unchecked(&fscache_n_uncaches));
46320
46321 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
46322 " oom=%u\n",
46323 - atomic_read(&fscache_n_acquires),
46324 - atomic_read(&fscache_n_acquires_null),
46325 - atomic_read(&fscache_n_acquires_no_cache),
46326 - atomic_read(&fscache_n_acquires_ok),
46327 - atomic_read(&fscache_n_acquires_nobufs),
46328 - atomic_read(&fscache_n_acquires_oom));
46329 + atomic_read_unchecked(&fscache_n_acquires),
46330 + atomic_read_unchecked(&fscache_n_acquires_null),
46331 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
46332 + atomic_read_unchecked(&fscache_n_acquires_ok),
46333 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
46334 + atomic_read_unchecked(&fscache_n_acquires_oom));
46335
46336 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
46337 - atomic_read(&fscache_n_object_lookups),
46338 - atomic_read(&fscache_n_object_lookups_negative),
46339 - atomic_read(&fscache_n_object_lookups_positive),
46340 - atomic_read(&fscache_n_object_created),
46341 - atomic_read(&fscache_n_object_lookups_timed_out));
46342 + atomic_read_unchecked(&fscache_n_object_lookups),
46343 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
46344 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
46345 + atomic_read_unchecked(&fscache_n_object_created),
46346 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
46347
46348 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
46349 - atomic_read(&fscache_n_updates),
46350 - atomic_read(&fscache_n_updates_null),
46351 - atomic_read(&fscache_n_updates_run));
46352 + atomic_read_unchecked(&fscache_n_updates),
46353 + atomic_read_unchecked(&fscache_n_updates_null),
46354 + atomic_read_unchecked(&fscache_n_updates_run));
46355
46356 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
46357 - atomic_read(&fscache_n_relinquishes),
46358 - atomic_read(&fscache_n_relinquishes_null),
46359 - atomic_read(&fscache_n_relinquishes_waitcrt),
46360 - atomic_read(&fscache_n_relinquishes_retire));
46361 + atomic_read_unchecked(&fscache_n_relinquishes),
46362 + atomic_read_unchecked(&fscache_n_relinquishes_null),
46363 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
46364 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
46365
46366 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
46367 - atomic_read(&fscache_n_attr_changed),
46368 - atomic_read(&fscache_n_attr_changed_ok),
46369 - atomic_read(&fscache_n_attr_changed_nobufs),
46370 - atomic_read(&fscache_n_attr_changed_nomem),
46371 - atomic_read(&fscache_n_attr_changed_calls));
46372 + atomic_read_unchecked(&fscache_n_attr_changed),
46373 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
46374 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
46375 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
46376 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
46377
46378 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
46379 - atomic_read(&fscache_n_allocs),
46380 - atomic_read(&fscache_n_allocs_ok),
46381 - atomic_read(&fscache_n_allocs_wait),
46382 - atomic_read(&fscache_n_allocs_nobufs),
46383 - atomic_read(&fscache_n_allocs_intr));
46384 + atomic_read_unchecked(&fscache_n_allocs),
46385 + atomic_read_unchecked(&fscache_n_allocs_ok),
46386 + atomic_read_unchecked(&fscache_n_allocs_wait),
46387 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
46388 + atomic_read_unchecked(&fscache_n_allocs_intr));
46389 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
46390 - atomic_read(&fscache_n_alloc_ops),
46391 - atomic_read(&fscache_n_alloc_op_waits),
46392 - atomic_read(&fscache_n_allocs_object_dead));
46393 + atomic_read_unchecked(&fscache_n_alloc_ops),
46394 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
46395 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
46396
46397 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
46398 " int=%u oom=%u\n",
46399 - atomic_read(&fscache_n_retrievals),
46400 - atomic_read(&fscache_n_retrievals_ok),
46401 - atomic_read(&fscache_n_retrievals_wait),
46402 - atomic_read(&fscache_n_retrievals_nodata),
46403 - atomic_read(&fscache_n_retrievals_nobufs),
46404 - atomic_read(&fscache_n_retrievals_intr),
46405 - atomic_read(&fscache_n_retrievals_nomem));
46406 + atomic_read_unchecked(&fscache_n_retrievals),
46407 + atomic_read_unchecked(&fscache_n_retrievals_ok),
46408 + atomic_read_unchecked(&fscache_n_retrievals_wait),
46409 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
46410 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
46411 + atomic_read_unchecked(&fscache_n_retrievals_intr),
46412 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
46413 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
46414 - atomic_read(&fscache_n_retrieval_ops),
46415 - atomic_read(&fscache_n_retrieval_op_waits),
46416 - atomic_read(&fscache_n_retrievals_object_dead));
46417 + atomic_read_unchecked(&fscache_n_retrieval_ops),
46418 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
46419 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
46420
46421 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
46422 - atomic_read(&fscache_n_stores),
46423 - atomic_read(&fscache_n_stores_ok),
46424 - atomic_read(&fscache_n_stores_again),
46425 - atomic_read(&fscache_n_stores_nobufs),
46426 - atomic_read(&fscache_n_stores_oom));
46427 + atomic_read_unchecked(&fscache_n_stores),
46428 + atomic_read_unchecked(&fscache_n_stores_ok),
46429 + atomic_read_unchecked(&fscache_n_stores_again),
46430 + atomic_read_unchecked(&fscache_n_stores_nobufs),
46431 + atomic_read_unchecked(&fscache_n_stores_oom));
46432 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
46433 - atomic_read(&fscache_n_store_ops),
46434 - atomic_read(&fscache_n_store_calls),
46435 - atomic_read(&fscache_n_store_pages),
46436 - atomic_read(&fscache_n_store_radix_deletes),
46437 - atomic_read(&fscache_n_store_pages_over_limit));
46438 + atomic_read_unchecked(&fscache_n_store_ops),
46439 + atomic_read_unchecked(&fscache_n_store_calls),
46440 + atomic_read_unchecked(&fscache_n_store_pages),
46441 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
46442 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
46443
46444 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
46445 - atomic_read(&fscache_n_store_vmscan_not_storing),
46446 - atomic_read(&fscache_n_store_vmscan_gone),
46447 - atomic_read(&fscache_n_store_vmscan_busy),
46448 - atomic_read(&fscache_n_store_vmscan_cancelled));
46449 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
46450 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
46451 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
46452 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
46453
46454 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
46455 - atomic_read(&fscache_n_op_pend),
46456 - atomic_read(&fscache_n_op_run),
46457 - atomic_read(&fscache_n_op_enqueue),
46458 - atomic_read(&fscache_n_op_cancelled),
46459 - atomic_read(&fscache_n_op_rejected));
46460 + atomic_read_unchecked(&fscache_n_op_pend),
46461 + atomic_read_unchecked(&fscache_n_op_run),
46462 + atomic_read_unchecked(&fscache_n_op_enqueue),
46463 + atomic_read_unchecked(&fscache_n_op_cancelled),
46464 + atomic_read_unchecked(&fscache_n_op_rejected));
46465 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
46466 - atomic_read(&fscache_n_op_deferred_release),
46467 - atomic_read(&fscache_n_op_release),
46468 - atomic_read(&fscache_n_op_gc));
46469 + atomic_read_unchecked(&fscache_n_op_deferred_release),
46470 + atomic_read_unchecked(&fscache_n_op_release),
46471 + atomic_read_unchecked(&fscache_n_op_gc));
46472
46473 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
46474 atomic_read(&fscache_n_cop_alloc_object),
46475 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
46476 index 3426521..3b75162 100644
46477 --- a/fs/fuse/cuse.c
46478 +++ b/fs/fuse/cuse.c
46479 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
46480 INIT_LIST_HEAD(&cuse_conntbl[i]);
46481
46482 /* inherit and extend fuse_dev_operations */
46483 - cuse_channel_fops = fuse_dev_operations;
46484 - cuse_channel_fops.owner = THIS_MODULE;
46485 - cuse_channel_fops.open = cuse_channel_open;
46486 - cuse_channel_fops.release = cuse_channel_release;
46487 + pax_open_kernel();
46488 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
46489 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
46490 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
46491 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
46492 + pax_close_kernel();
46493
46494 cuse_class = class_create(THIS_MODULE, "cuse");
46495 if (IS_ERR(cuse_class))
46496 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
46497 index 5f3368a..8306426 100644
46498 --- a/fs/fuse/dev.c
46499 +++ b/fs/fuse/dev.c
46500 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
46501 ret = 0;
46502 pipe_lock(pipe);
46503
46504 - if (!pipe->readers) {
46505 + if (!atomic_read(&pipe->readers)) {
46506 send_sig(SIGPIPE, current, 0);
46507 if (!ret)
46508 ret = -EPIPE;
46509 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
46510 index 2066328..f5add3b 100644
46511 --- a/fs/fuse/dir.c
46512 +++ b/fs/fuse/dir.c
46513 @@ -1175,7 +1175,7 @@ static char *read_link(struct dentry *dentry)
46514 return link;
46515 }
46516
46517 -static void free_link(char *link)
46518 +static void free_link(const char *link)
46519 {
46520 if (!IS_ERR(link))
46521 free_page((unsigned long) link);
46522 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
46523 index 5698746..6086012 100644
46524 --- a/fs/gfs2/inode.c
46525 +++ b/fs/gfs2/inode.c
46526 @@ -1487,7 +1487,7 @@ out:
46527
46528 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
46529 {
46530 - char *s = nd_get_link(nd);
46531 + const char *s = nd_get_link(nd);
46532 if (!IS_ERR(s))
46533 kfree(s);
46534 }
46535 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
46536 index c60267e..193d9e4 100644
46537 --- a/fs/hugetlbfs/inode.c
46538 +++ b/fs/hugetlbfs/inode.c
46539 @@ -902,7 +902,7 @@ static struct file_system_type hugetlbfs_fs_type = {
46540 .kill_sb = kill_litter_super,
46541 };
46542
46543 -static struct vfsmount *hugetlbfs_vfsmount;
46544 +struct vfsmount *hugetlbfs_vfsmount;
46545
46546 static int can_do_hugetlb_shm(void)
46547 {
46548 diff --git a/fs/inode.c b/fs/inode.c
46549 index 83ab215..8842101 100644
46550 --- a/fs/inode.c
46551 +++ b/fs/inode.c
46552 @@ -870,8 +870,8 @@ unsigned int get_next_ino(void)
46553
46554 #ifdef CONFIG_SMP
46555 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
46556 - static atomic_t shared_last_ino;
46557 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
46558 + static atomic_unchecked_t shared_last_ino;
46559 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
46560
46561 res = next - LAST_INO_BATCH;
46562 }
46563 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
46564 index eafb8d3..f423d37 100644
46565 --- a/fs/jffs2/erase.c
46566 +++ b/fs/jffs2/erase.c
46567 @@ -438,7 +438,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
46568 struct jffs2_unknown_node marker = {
46569 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
46570 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46571 - .totlen = cpu_to_je32(c->cleanmarker_size)
46572 + .totlen = cpu_to_je32(c->cleanmarker_size),
46573 + .hdr_crc = cpu_to_je32(0)
46574 };
46575
46576 jffs2_prealloc_raw_node_refs(c, jeb, 1);
46577 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
46578 index 30e8f47..21f600c 100644
46579 --- a/fs/jffs2/wbuf.c
46580 +++ b/fs/jffs2/wbuf.c
46581 @@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
46582 {
46583 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
46584 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
46585 - .totlen = constant_cpu_to_je32(8)
46586 + .totlen = constant_cpu_to_je32(8),
46587 + .hdr_crc = constant_cpu_to_je32(0)
46588 };
46589
46590 /*
46591 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
46592 index 682bca6..86b8e6e 100644
46593 --- a/fs/jfs/super.c
46594 +++ b/fs/jfs/super.c
46595 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
46596
46597 jfs_inode_cachep =
46598 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
46599 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
46600 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
46601 init_once);
46602 if (jfs_inode_cachep == NULL)
46603 return -ENOMEM;
46604 diff --git a/fs/libfs.c b/fs/libfs.c
46605 index 5b2dbb3..7442d54 100644
46606 --- a/fs/libfs.c
46607 +++ b/fs/libfs.c
46608 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46609
46610 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
46611 struct dentry *next;
46612 + char d_name[sizeof(next->d_iname)];
46613 + const unsigned char *name;
46614 +
46615 next = list_entry(p, struct dentry, d_u.d_child);
46616 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
46617 if (!simple_positive(next)) {
46618 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
46619
46620 spin_unlock(&next->d_lock);
46621 spin_unlock(&dentry->d_lock);
46622 - if (filldir(dirent, next->d_name.name,
46623 + name = next->d_name.name;
46624 + if (name == next->d_iname) {
46625 + memcpy(d_name, name, next->d_name.len);
46626 + name = d_name;
46627 + }
46628 + if (filldir(dirent, name,
46629 next->d_name.len, filp->f_pos,
46630 next->d_inode->i_ino,
46631 dt_type(next->d_inode)) < 0)
46632 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
46633 index 8392cb8..80d6193 100644
46634 --- a/fs/lockd/clntproc.c
46635 +++ b/fs/lockd/clntproc.c
46636 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
46637 /*
46638 * Cookie counter for NLM requests
46639 */
46640 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
46641 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
46642
46643 void nlmclnt_next_cookie(struct nlm_cookie *c)
46644 {
46645 - u32 cookie = atomic_inc_return(&nlm_cookie);
46646 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
46647
46648 memcpy(c->data, &cookie, 4);
46649 c->len=4;
46650 diff --git a/fs/locks.c b/fs/locks.c
46651 index 0d68f1f..f216b79 100644
46652 --- a/fs/locks.c
46653 +++ b/fs/locks.c
46654 @@ -2075,16 +2075,16 @@ void locks_remove_flock(struct file *filp)
46655 return;
46656
46657 if (filp->f_op && filp->f_op->flock) {
46658 - struct file_lock fl = {
46659 + struct file_lock flock = {
46660 .fl_pid = current->tgid,
46661 .fl_file = filp,
46662 .fl_flags = FL_FLOCK,
46663 .fl_type = F_UNLCK,
46664 .fl_end = OFFSET_MAX,
46665 };
46666 - filp->f_op->flock(filp, F_SETLKW, &fl);
46667 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
46668 - fl.fl_ops->fl_release_private(&fl);
46669 + filp->f_op->flock(filp, F_SETLKW, &flock);
46670 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
46671 + flock.fl_ops->fl_release_private(&flock);
46672 }
46673
46674 lock_flocks();
46675 diff --git a/fs/namei.c b/fs/namei.c
46676 index 46ea9cc..c7cf3a3 100644
46677 --- a/fs/namei.c
46678 +++ b/fs/namei.c
46679 @@ -278,16 +278,32 @@ int generic_permission(struct inode *inode, int mask)
46680 if (ret != -EACCES)
46681 return ret;
46682
46683 +#ifdef CONFIG_GRKERNSEC
46684 + /* we'll block if we have to log due to a denied capability use */
46685 + if (mask & MAY_NOT_BLOCK)
46686 + return -ECHILD;
46687 +#endif
46688 +
46689 if (S_ISDIR(inode->i_mode)) {
46690 /* DACs are overridable for directories */
46691 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46692 - return 0;
46693 if (!(mask & MAY_WRITE))
46694 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46695 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46696 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46697 return 0;
46698 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46699 + return 0;
46700 return -EACCES;
46701 }
46702 /*
46703 + * Searching includes executable on directories, else just read.
46704 + */
46705 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46706 + if (mask == MAY_READ)
46707 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
46708 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46709 + return 0;
46710 +
46711 + /*
46712 * Read/write DACs are always overridable.
46713 * Executable DACs are overridable when there is
46714 * at least one exec bit set.
46715 @@ -296,14 +312,6 @@ int generic_permission(struct inode *inode, int mask)
46716 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
46717 return 0;
46718
46719 - /*
46720 - * Searching includes executable on directories, else just read.
46721 - */
46722 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
46723 - if (mask == MAY_READ)
46724 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
46725 - return 0;
46726 -
46727 return -EACCES;
46728 }
46729
46730 @@ -652,11 +660,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
46731 return error;
46732 }
46733
46734 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
46735 + dentry->d_inode, dentry, nd->path.mnt)) {
46736 + error = -EACCES;
46737 + *p = ERR_PTR(error); /* no ->put_link(), please */
46738 + path_put(&nd->path);
46739 + return error;
46740 + }
46741 +
46742 nd->last_type = LAST_BIND;
46743 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
46744 error = PTR_ERR(*p);
46745 if (!IS_ERR(*p)) {
46746 - char *s = nd_get_link(nd);
46747 + const char *s = nd_get_link(nd);
46748 error = 0;
46749 if (s)
46750 error = __vfs_follow_link(nd, s);
46751 @@ -1650,6 +1666,21 @@ static int path_lookupat(int dfd, const char *name,
46752 if (!err)
46753 err = complete_walk(nd);
46754
46755 + if (!(nd->flags & LOOKUP_PARENT)) {
46756 +#ifdef CONFIG_GRKERNSEC
46757 + if (flags & LOOKUP_RCU) {
46758 + if (!err)
46759 + path_put(&nd->path);
46760 + err = -ECHILD;
46761 + } else
46762 +#endif
46763 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46764 + if (!err)
46765 + path_put(&nd->path);
46766 + err = -ENOENT;
46767 + }
46768 + }
46769 +
46770 if (!err && nd->flags & LOOKUP_DIRECTORY) {
46771 if (!nd->inode->i_op->lookup) {
46772 path_put(&nd->path);
46773 @@ -1677,6 +1708,15 @@ static int do_path_lookup(int dfd, const char *name,
46774 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
46775
46776 if (likely(!retval)) {
46777 + if (*name != '/' && nd->path.dentry && nd->inode) {
46778 +#ifdef CONFIG_GRKERNSEC
46779 + if (flags & LOOKUP_RCU)
46780 + return -ECHILD;
46781 +#endif
46782 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
46783 + return -ENOENT;
46784 + }
46785 +
46786 if (unlikely(!audit_dummy_context())) {
46787 if (nd->path.dentry && nd->inode)
46788 audit_inode(name, nd->path.dentry);
46789 @@ -2071,6 +2111,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
46790 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
46791 return -EPERM;
46792
46793 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
46794 + return -EPERM;
46795 + if (gr_handle_rawio(inode))
46796 + return -EPERM;
46797 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
46798 + return -EACCES;
46799 +
46800 return 0;
46801 }
46802
46803 @@ -2132,6 +2179,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46804 error = complete_walk(nd);
46805 if (error)
46806 return ERR_PTR(error);
46807 +#ifdef CONFIG_GRKERNSEC
46808 + if (nd->flags & LOOKUP_RCU) {
46809 + error = -ECHILD;
46810 + goto exit;
46811 + }
46812 +#endif
46813 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46814 + error = -ENOENT;
46815 + goto exit;
46816 + }
46817 audit_inode(pathname, nd->path.dentry);
46818 if (open_flag & O_CREAT) {
46819 error = -EISDIR;
46820 @@ -2142,6 +2199,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46821 error = complete_walk(nd);
46822 if (error)
46823 return ERR_PTR(error);
46824 +#ifdef CONFIG_GRKERNSEC
46825 + if (nd->flags & LOOKUP_RCU) {
46826 + error = -ECHILD;
46827 + goto exit;
46828 + }
46829 +#endif
46830 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
46831 + error = -ENOENT;
46832 + goto exit;
46833 + }
46834 audit_inode(pathname, dir);
46835 goto ok;
46836 }
46837 @@ -2163,6 +2230,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46838 error = complete_walk(nd);
46839 if (error)
46840 return ERR_PTR(error);
46841 +#ifdef CONFIG_GRKERNSEC
46842 + if (nd->flags & LOOKUP_RCU) {
46843 + error = -ECHILD;
46844 + goto exit;
46845 + }
46846 +#endif
46847 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
46848 + error = -ENOENT;
46849 + goto exit;
46850 + }
46851
46852 error = -ENOTDIR;
46853 if (nd->flags & LOOKUP_DIRECTORY) {
46854 @@ -2203,6 +2280,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46855 /* Negative dentry, just create the file */
46856 if (!dentry->d_inode) {
46857 umode_t mode = op->mode;
46858 +
46859 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
46860 + error = -EACCES;
46861 + goto exit_mutex_unlock;
46862 + }
46863 +
46864 if (!IS_POSIXACL(dir->d_inode))
46865 mode &= ~current_umask();
46866 /*
46867 @@ -2226,6 +2309,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46868 error = vfs_create(dir->d_inode, dentry, mode, nd);
46869 if (error)
46870 goto exit_mutex_unlock;
46871 + else
46872 + gr_handle_create(path->dentry, path->mnt);
46873 mutex_unlock(&dir->d_inode->i_mutex);
46874 dput(nd->path.dentry);
46875 nd->path.dentry = dentry;
46876 @@ -2235,6 +2320,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
46877 /*
46878 * It already exists.
46879 */
46880 +
46881 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
46882 + error = -ENOENT;
46883 + goto exit_mutex_unlock;
46884 + }
46885 +
46886 + /* only check if O_CREAT is specified, all other checks need to go
46887 + into may_open */
46888 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
46889 + error = -EACCES;
46890 + goto exit_mutex_unlock;
46891 + }
46892 +
46893 mutex_unlock(&dir->d_inode->i_mutex);
46894 audit_inode(pathname, path->dentry);
46895
46896 @@ -2447,6 +2545,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
46897 *path = nd.path;
46898 return dentry;
46899 eexist:
46900 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
46901 + dput(dentry);
46902 + dentry = ERR_PTR(-ENOENT);
46903 + goto fail;
46904 + }
46905 dput(dentry);
46906 dentry = ERR_PTR(-EEXIST);
46907 fail:
46908 @@ -2469,6 +2572,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
46909 }
46910 EXPORT_SYMBOL(user_path_create);
46911
46912 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
46913 +{
46914 + char *tmp = getname(pathname);
46915 + struct dentry *res;
46916 + if (IS_ERR(tmp))
46917 + return ERR_CAST(tmp);
46918 + res = kern_path_create(dfd, tmp, path, is_dir);
46919 + if (IS_ERR(res))
46920 + putname(tmp);
46921 + else
46922 + *to = tmp;
46923 + return res;
46924 +}
46925 +
46926 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
46927 {
46928 int error = may_create(dir, dentry);
46929 @@ -2536,6 +2653,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46930 error = mnt_want_write(path.mnt);
46931 if (error)
46932 goto out_dput;
46933 +
46934 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
46935 + error = -EPERM;
46936 + goto out_drop_write;
46937 + }
46938 +
46939 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
46940 + error = -EACCES;
46941 + goto out_drop_write;
46942 + }
46943 +
46944 error = security_path_mknod(&path, dentry, mode, dev);
46945 if (error)
46946 goto out_drop_write;
46947 @@ -2553,6 +2681,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
46948 }
46949 out_drop_write:
46950 mnt_drop_write(path.mnt);
46951 +
46952 + if (!error)
46953 + gr_handle_create(dentry, path.mnt);
46954 out_dput:
46955 dput(dentry);
46956 mutex_unlock(&path.dentry->d_inode->i_mutex);
46957 @@ -2602,12 +2733,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
46958 error = mnt_want_write(path.mnt);
46959 if (error)
46960 goto out_dput;
46961 +
46962 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
46963 + error = -EACCES;
46964 + goto out_drop_write;
46965 + }
46966 +
46967 error = security_path_mkdir(&path, dentry, mode);
46968 if (error)
46969 goto out_drop_write;
46970 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
46971 out_drop_write:
46972 mnt_drop_write(path.mnt);
46973 +
46974 + if (!error)
46975 + gr_handle_create(dentry, path.mnt);
46976 out_dput:
46977 dput(dentry);
46978 mutex_unlock(&path.dentry->d_inode->i_mutex);
46979 @@ -2687,6 +2827,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
46980 char * name;
46981 struct dentry *dentry;
46982 struct nameidata nd;
46983 + ino_t saved_ino = 0;
46984 + dev_t saved_dev = 0;
46985
46986 error = user_path_parent(dfd, pathname, &nd, &name);
46987 if (error)
46988 @@ -2715,6 +2857,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
46989 error = -ENOENT;
46990 goto exit3;
46991 }
46992 +
46993 + saved_ino = dentry->d_inode->i_ino;
46994 + saved_dev = gr_get_dev_from_dentry(dentry);
46995 +
46996 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
46997 + error = -EACCES;
46998 + goto exit3;
46999 + }
47000 +
47001 error = mnt_want_write(nd.path.mnt);
47002 if (error)
47003 goto exit3;
47004 @@ -2722,6 +2873,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47005 if (error)
47006 goto exit4;
47007 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47008 + if (!error && (saved_dev || saved_ino))
47009 + gr_handle_delete(saved_ino, saved_dev);
47010 exit4:
47011 mnt_drop_write(nd.path.mnt);
47012 exit3:
47013 @@ -2784,6 +2937,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47014 struct dentry *dentry;
47015 struct nameidata nd;
47016 struct inode *inode = NULL;
47017 + ino_t saved_ino = 0;
47018 + dev_t saved_dev = 0;
47019
47020 error = user_path_parent(dfd, pathname, &nd, &name);
47021 if (error)
47022 @@ -2806,6 +2961,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47023 if (!inode)
47024 goto slashes;
47025 ihold(inode);
47026 +
47027 + if (inode->i_nlink <= 1) {
47028 + saved_ino = inode->i_ino;
47029 + saved_dev = gr_get_dev_from_dentry(dentry);
47030 + }
47031 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
47032 + error = -EACCES;
47033 + goto exit2;
47034 + }
47035 +
47036 error = mnt_want_write(nd.path.mnt);
47037 if (error)
47038 goto exit2;
47039 @@ -2813,6 +2978,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47040 if (error)
47041 goto exit3;
47042 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
47043 + if (!error && (saved_ino || saved_dev))
47044 + gr_handle_delete(saved_ino, saved_dev);
47045 exit3:
47046 mnt_drop_write(nd.path.mnt);
47047 exit2:
47048 @@ -2888,10 +3055,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
47049 error = mnt_want_write(path.mnt);
47050 if (error)
47051 goto out_dput;
47052 +
47053 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
47054 + error = -EACCES;
47055 + goto out_drop_write;
47056 + }
47057 +
47058 error = security_path_symlink(&path, dentry, from);
47059 if (error)
47060 goto out_drop_write;
47061 error = vfs_symlink(path.dentry->d_inode, dentry, from);
47062 + if (!error)
47063 + gr_handle_create(dentry, path.mnt);
47064 out_drop_write:
47065 mnt_drop_write(path.mnt);
47066 out_dput:
47067 @@ -2963,6 +3138,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47068 {
47069 struct dentry *new_dentry;
47070 struct path old_path, new_path;
47071 + char *to = NULL;
47072 int how = 0;
47073 int error;
47074
47075 @@ -2986,7 +3162,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47076 if (error)
47077 return error;
47078
47079 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
47080 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
47081 error = PTR_ERR(new_dentry);
47082 if (IS_ERR(new_dentry))
47083 goto out;
47084 @@ -2997,13 +3173,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
47085 error = mnt_want_write(new_path.mnt);
47086 if (error)
47087 goto out_dput;
47088 +
47089 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
47090 + old_path.dentry->d_inode,
47091 + old_path.dentry->d_inode->i_mode, to)) {
47092 + error = -EACCES;
47093 + goto out_drop_write;
47094 + }
47095 +
47096 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
47097 + old_path.dentry, old_path.mnt, to)) {
47098 + error = -EACCES;
47099 + goto out_drop_write;
47100 + }
47101 +
47102 error = security_path_link(old_path.dentry, &new_path, new_dentry);
47103 if (error)
47104 goto out_drop_write;
47105 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
47106 + if (!error)
47107 + gr_handle_create(new_dentry, new_path.mnt);
47108 out_drop_write:
47109 mnt_drop_write(new_path.mnt);
47110 out_dput:
47111 + putname(to);
47112 dput(new_dentry);
47113 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
47114 path_put(&new_path);
47115 @@ -3231,6 +3424,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47116 if (new_dentry == trap)
47117 goto exit5;
47118
47119 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
47120 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
47121 + to);
47122 + if (error)
47123 + goto exit5;
47124 +
47125 error = mnt_want_write(oldnd.path.mnt);
47126 if (error)
47127 goto exit5;
47128 @@ -3240,6 +3439,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
47129 goto exit6;
47130 error = vfs_rename(old_dir->d_inode, old_dentry,
47131 new_dir->d_inode, new_dentry);
47132 + if (!error)
47133 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
47134 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
47135 exit6:
47136 mnt_drop_write(oldnd.path.mnt);
47137 exit5:
47138 @@ -3265,6 +3467,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
47139
47140 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
47141 {
47142 + char tmpbuf[64];
47143 + const char *newlink;
47144 int len;
47145
47146 len = PTR_ERR(link);
47147 @@ -3274,7 +3478,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
47148 len = strlen(link);
47149 if (len > (unsigned) buflen)
47150 len = buflen;
47151 - if (copy_to_user(buffer, link, len))
47152 +
47153 + if (len < sizeof(tmpbuf)) {
47154 + memcpy(tmpbuf, link, len);
47155 + newlink = tmpbuf;
47156 + } else
47157 + newlink = link;
47158 +
47159 + if (copy_to_user(buffer, newlink, len))
47160 len = -EFAULT;
47161 out:
47162 return len;
47163 diff --git a/fs/namespace.c b/fs/namespace.c
47164 index e608199..9609cb9 100644
47165 --- a/fs/namespace.c
47166 +++ b/fs/namespace.c
47167 @@ -1155,6 +1155,9 @@ static int do_umount(struct mount *mnt, int flags)
47168 if (!(sb->s_flags & MS_RDONLY))
47169 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
47170 up_write(&sb->s_umount);
47171 +
47172 + gr_log_remount(mnt->mnt_devname, retval);
47173 +
47174 return retval;
47175 }
47176
47177 @@ -1174,6 +1177,9 @@ static int do_umount(struct mount *mnt, int flags)
47178 br_write_unlock(vfsmount_lock);
47179 up_write(&namespace_sem);
47180 release_mounts(&umount_list);
47181 +
47182 + gr_log_unmount(mnt->mnt_devname, retval);
47183 +
47184 return retval;
47185 }
47186
47187 @@ -2175,6 +2181,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47188 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
47189 MS_STRICTATIME);
47190
47191 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
47192 + retval = -EPERM;
47193 + goto dput_out;
47194 + }
47195 +
47196 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
47197 + retval = -EPERM;
47198 + goto dput_out;
47199 + }
47200 +
47201 if (flags & MS_REMOUNT)
47202 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
47203 data_page);
47204 @@ -2189,6 +2205,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
47205 dev_name, data_page);
47206 dput_out:
47207 path_put(&path);
47208 +
47209 + gr_log_mount(dev_name, dir_name, retval);
47210 +
47211 return retval;
47212 }
47213
47214 @@ -2470,6 +2489,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
47215 if (error)
47216 goto out2;
47217
47218 + if (gr_handle_chroot_pivot()) {
47219 + error = -EPERM;
47220 + goto out2;
47221 + }
47222 +
47223 get_fs_root(current->fs, &root);
47224 error = lock_mount(&old);
47225 if (error)
47226 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
47227 index f649fba..236bf92 100644
47228 --- a/fs/nfs/inode.c
47229 +++ b/fs/nfs/inode.c
47230 @@ -151,7 +151,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
47231 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
47232 nfsi->attrtimeo_timestamp = jiffies;
47233
47234 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
47235 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
47236 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
47237 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
47238 else
47239 @@ -1003,16 +1003,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
47240 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
47241 }
47242
47243 -static atomic_long_t nfs_attr_generation_counter;
47244 +static atomic_long_unchecked_t nfs_attr_generation_counter;
47245
47246 static unsigned long nfs_read_attr_generation_counter(void)
47247 {
47248 - return atomic_long_read(&nfs_attr_generation_counter);
47249 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
47250 }
47251
47252 unsigned long nfs_inc_attr_generation_counter(void)
47253 {
47254 - return atomic_long_inc_return(&nfs_attr_generation_counter);
47255 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
47256 }
47257
47258 void nfs_fattr_init(struct nfs_fattr *fattr)
47259 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
47260 index b96fe94..a4dbece 100644
47261 --- a/fs/nfsd/vfs.c
47262 +++ b/fs/nfsd/vfs.c
47263 @@ -925,7 +925,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47264 } else {
47265 oldfs = get_fs();
47266 set_fs(KERNEL_DS);
47267 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
47268 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
47269 set_fs(oldfs);
47270 }
47271
47272 @@ -1029,7 +1029,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
47273
47274 /* Write the data. */
47275 oldfs = get_fs(); set_fs(KERNEL_DS);
47276 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
47277 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
47278 set_fs(oldfs);
47279 if (host_err < 0)
47280 goto out_nfserr;
47281 @@ -1564,7 +1564,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
47282 */
47283
47284 oldfs = get_fs(); set_fs(KERNEL_DS);
47285 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
47286 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
47287 set_fs(oldfs);
47288
47289 if (host_err < 0)
47290 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
47291 index 3568c8a..e0240d8 100644
47292 --- a/fs/notify/fanotify/fanotify_user.c
47293 +++ b/fs/notify/fanotify/fanotify_user.c
47294 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
47295 goto out_close_fd;
47296
47297 ret = -EFAULT;
47298 - if (copy_to_user(buf, &fanotify_event_metadata,
47299 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
47300 + copy_to_user(buf, &fanotify_event_metadata,
47301 fanotify_event_metadata.event_len))
47302 goto out_kill_access_response;
47303
47304 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
47305 index ee18815..7aa5d01 100644
47306 --- a/fs/notify/notification.c
47307 +++ b/fs/notify/notification.c
47308 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
47309 * get set to 0 so it will never get 'freed'
47310 */
47311 static struct fsnotify_event *q_overflow_event;
47312 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47313 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47314
47315 /**
47316 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
47317 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
47318 */
47319 u32 fsnotify_get_cookie(void)
47320 {
47321 - return atomic_inc_return(&fsnotify_sync_cookie);
47322 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
47323 }
47324 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
47325
47326 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
47327 index 99e3610..02c1068 100644
47328 --- a/fs/ntfs/dir.c
47329 +++ b/fs/ntfs/dir.c
47330 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
47331 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
47332 ~(s64)(ndir->itype.index.block_size - 1)));
47333 /* Bounds checks. */
47334 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47335 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
47336 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
47337 "inode 0x%lx or driver bug.", vdir->i_ino);
47338 goto err_out;
47339 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
47340 index c587e2d..3641eaa 100644
47341 --- a/fs/ntfs/file.c
47342 +++ b/fs/ntfs/file.c
47343 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
47344 #endif /* NTFS_RW */
47345 };
47346
47347 -const struct file_operations ntfs_empty_file_ops = {};
47348 +const struct file_operations ntfs_empty_file_ops __read_only;
47349
47350 -const struct inode_operations ntfs_empty_inode_ops = {};
47351 +const struct inode_operations ntfs_empty_inode_ops __read_only;
47352 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
47353 index 210c352..a174f83 100644
47354 --- a/fs/ocfs2/localalloc.c
47355 +++ b/fs/ocfs2/localalloc.c
47356 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
47357 goto bail;
47358 }
47359
47360 - atomic_inc(&osb->alloc_stats.moves);
47361 + atomic_inc_unchecked(&osb->alloc_stats.moves);
47362
47363 bail:
47364 if (handle)
47365 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
47366 index d355e6e..578d905 100644
47367 --- a/fs/ocfs2/ocfs2.h
47368 +++ b/fs/ocfs2/ocfs2.h
47369 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
47370
47371 struct ocfs2_alloc_stats
47372 {
47373 - atomic_t moves;
47374 - atomic_t local_data;
47375 - atomic_t bitmap_data;
47376 - atomic_t bg_allocs;
47377 - atomic_t bg_extends;
47378 + atomic_unchecked_t moves;
47379 + atomic_unchecked_t local_data;
47380 + atomic_unchecked_t bitmap_data;
47381 + atomic_unchecked_t bg_allocs;
47382 + atomic_unchecked_t bg_extends;
47383 };
47384
47385 enum ocfs2_local_alloc_state
47386 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
47387 index f169da4..9112253 100644
47388 --- a/fs/ocfs2/suballoc.c
47389 +++ b/fs/ocfs2/suballoc.c
47390 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
47391 mlog_errno(status);
47392 goto bail;
47393 }
47394 - atomic_inc(&osb->alloc_stats.bg_extends);
47395 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
47396
47397 /* You should never ask for this much metadata */
47398 BUG_ON(bits_wanted >
47399 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
47400 mlog_errno(status);
47401 goto bail;
47402 }
47403 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47404 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47405
47406 *suballoc_loc = res.sr_bg_blkno;
47407 *suballoc_bit_start = res.sr_bit_offset;
47408 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
47409 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
47410 res->sr_bits);
47411
47412 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47413 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47414
47415 BUG_ON(res->sr_bits != 1);
47416
47417 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
47418 mlog_errno(status);
47419 goto bail;
47420 }
47421 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47422 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
47423
47424 BUG_ON(res.sr_bits != 1);
47425
47426 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47427 cluster_start,
47428 num_clusters);
47429 if (!status)
47430 - atomic_inc(&osb->alloc_stats.local_data);
47431 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
47432 } else {
47433 if (min_clusters > (osb->bitmap_cpg - 1)) {
47434 /* The only paths asking for contiguousness
47435 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
47436 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
47437 res.sr_bg_blkno,
47438 res.sr_bit_offset);
47439 - atomic_inc(&osb->alloc_stats.bitmap_data);
47440 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
47441 *num_clusters = res.sr_bits;
47442 }
47443 }
47444 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
47445 index 604e12c..8426483 100644
47446 --- a/fs/ocfs2/super.c
47447 +++ b/fs/ocfs2/super.c
47448 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
47449 "%10s => GlobalAllocs: %d LocalAllocs: %d "
47450 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
47451 "Stats",
47452 - atomic_read(&osb->alloc_stats.bitmap_data),
47453 - atomic_read(&osb->alloc_stats.local_data),
47454 - atomic_read(&osb->alloc_stats.bg_allocs),
47455 - atomic_read(&osb->alloc_stats.moves),
47456 - atomic_read(&osb->alloc_stats.bg_extends));
47457 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
47458 + atomic_read_unchecked(&osb->alloc_stats.local_data),
47459 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
47460 + atomic_read_unchecked(&osb->alloc_stats.moves),
47461 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
47462
47463 out += snprintf(buf + out, len - out,
47464 "%10s => State: %u Descriptor: %llu Size: %u bits "
47465 @@ -2117,11 +2117,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
47466 spin_lock_init(&osb->osb_xattr_lock);
47467 ocfs2_init_steal_slots(osb);
47468
47469 - atomic_set(&osb->alloc_stats.moves, 0);
47470 - atomic_set(&osb->alloc_stats.local_data, 0);
47471 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
47472 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
47473 - atomic_set(&osb->alloc_stats.bg_extends, 0);
47474 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
47475 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
47476 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
47477 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
47478 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
47479
47480 /* Copy the blockcheck stats from the superblock probe */
47481 osb->osb_ecc_stats = *stats;
47482 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
47483 index 5d22872..523db20 100644
47484 --- a/fs/ocfs2/symlink.c
47485 +++ b/fs/ocfs2/symlink.c
47486 @@ -142,7 +142,7 @@ bail:
47487
47488 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47489 {
47490 - char *link = nd_get_link(nd);
47491 + const char *link = nd_get_link(nd);
47492 if (!IS_ERR(link))
47493 kfree(link);
47494 }
47495 diff --git a/fs/open.c b/fs/open.c
47496 index 77becc0..aad7bd9 100644
47497 --- a/fs/open.c
47498 +++ b/fs/open.c
47499 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
47500 error = locks_verify_truncate(inode, NULL, length);
47501 if (!error)
47502 error = security_path_truncate(&path);
47503 +
47504 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
47505 + error = -EACCES;
47506 +
47507 if (!error)
47508 error = do_truncate(path.dentry, length, 0, NULL);
47509
47510 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
47511 if (__mnt_is_readonly(path.mnt))
47512 res = -EROFS;
47513
47514 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
47515 + res = -EACCES;
47516 +
47517 out_path_release:
47518 path_put(&path);
47519 out:
47520 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
47521 if (error)
47522 goto dput_and_out;
47523
47524 + gr_log_chdir(path.dentry, path.mnt);
47525 +
47526 set_fs_pwd(current->fs, &path);
47527
47528 dput_and_out:
47529 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
47530 goto out_putf;
47531
47532 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
47533 +
47534 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
47535 + error = -EPERM;
47536 +
47537 + if (!error)
47538 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
47539 +
47540 if (!error)
47541 set_fs_pwd(current->fs, &file->f_path);
47542 out_putf:
47543 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
47544 if (error)
47545 goto dput_and_out;
47546
47547 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
47548 + goto dput_and_out;
47549 +
47550 set_fs_root(current->fs, &path);
47551 +
47552 + gr_handle_chroot_chdir(&path);
47553 +
47554 error = 0;
47555 dput_and_out:
47556 path_put(&path);
47557 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
47558 if (error)
47559 return error;
47560 mutex_lock(&inode->i_mutex);
47561 +
47562 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
47563 + error = -EACCES;
47564 + goto out_unlock;
47565 + }
47566 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
47567 + error = -EACCES;
47568 + goto out_unlock;
47569 + }
47570 +
47571 error = security_path_chmod(path, mode);
47572 if (error)
47573 goto out_unlock;
47574 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
47575 int error;
47576 struct iattr newattrs;
47577
47578 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
47579 + return -EACCES;
47580 +
47581 newattrs.ia_valid = ATTR_CTIME;
47582 if (user != (uid_t) -1) {
47583 newattrs.ia_valid |= ATTR_UID;
47584 diff --git a/fs/pipe.c b/fs/pipe.c
47585 index 82e651b..8a68573 100644
47586 --- a/fs/pipe.c
47587 +++ b/fs/pipe.c
47588 @@ -437,9 +437,9 @@ redo:
47589 }
47590 if (bufs) /* More to do? */
47591 continue;
47592 - if (!pipe->writers)
47593 + if (!atomic_read(&pipe->writers))
47594 break;
47595 - if (!pipe->waiting_writers) {
47596 + if (!atomic_read(&pipe->waiting_writers)) {
47597 /* syscall merging: Usually we must not sleep
47598 * if O_NONBLOCK is set, or if we got some data.
47599 * But if a writer sleeps in kernel space, then
47600 @@ -503,7 +503,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
47601 mutex_lock(&inode->i_mutex);
47602 pipe = inode->i_pipe;
47603
47604 - if (!pipe->readers) {
47605 + if (!atomic_read(&pipe->readers)) {
47606 send_sig(SIGPIPE, current, 0);
47607 ret = -EPIPE;
47608 goto out;
47609 @@ -552,7 +552,7 @@ redo1:
47610 for (;;) {
47611 int bufs;
47612
47613 - if (!pipe->readers) {
47614 + if (!atomic_read(&pipe->readers)) {
47615 send_sig(SIGPIPE, current, 0);
47616 if (!ret)
47617 ret = -EPIPE;
47618 @@ -643,9 +643,9 @@ redo2:
47619 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47620 do_wakeup = 0;
47621 }
47622 - pipe->waiting_writers++;
47623 + atomic_inc(&pipe->waiting_writers);
47624 pipe_wait(pipe);
47625 - pipe->waiting_writers--;
47626 + atomic_dec(&pipe->waiting_writers);
47627 }
47628 out:
47629 mutex_unlock(&inode->i_mutex);
47630 @@ -712,7 +712,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47631 mask = 0;
47632 if (filp->f_mode & FMODE_READ) {
47633 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
47634 - if (!pipe->writers && filp->f_version != pipe->w_counter)
47635 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
47636 mask |= POLLHUP;
47637 }
47638
47639 @@ -722,7 +722,7 @@ pipe_poll(struct file *filp, poll_table *wait)
47640 * Most Unices do not set POLLERR for FIFOs but on Linux they
47641 * behave exactly like pipes for poll().
47642 */
47643 - if (!pipe->readers)
47644 + if (!atomic_read(&pipe->readers))
47645 mask |= POLLERR;
47646 }
47647
47648 @@ -736,10 +736,10 @@ pipe_release(struct inode *inode, int decr, int decw)
47649
47650 mutex_lock(&inode->i_mutex);
47651 pipe = inode->i_pipe;
47652 - pipe->readers -= decr;
47653 - pipe->writers -= decw;
47654 + atomic_sub(decr, &pipe->readers);
47655 + atomic_sub(decw, &pipe->writers);
47656
47657 - if (!pipe->readers && !pipe->writers) {
47658 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
47659 free_pipe_info(inode);
47660 } else {
47661 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
47662 @@ -829,7 +829,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
47663
47664 if (inode->i_pipe) {
47665 ret = 0;
47666 - inode->i_pipe->readers++;
47667 + atomic_inc(&inode->i_pipe->readers);
47668 }
47669
47670 mutex_unlock(&inode->i_mutex);
47671 @@ -846,7 +846,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
47672
47673 if (inode->i_pipe) {
47674 ret = 0;
47675 - inode->i_pipe->writers++;
47676 + atomic_inc(&inode->i_pipe->writers);
47677 }
47678
47679 mutex_unlock(&inode->i_mutex);
47680 @@ -864,9 +864,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
47681 if (inode->i_pipe) {
47682 ret = 0;
47683 if (filp->f_mode & FMODE_READ)
47684 - inode->i_pipe->readers++;
47685 + atomic_inc(&inode->i_pipe->readers);
47686 if (filp->f_mode & FMODE_WRITE)
47687 - inode->i_pipe->writers++;
47688 + atomic_inc(&inode->i_pipe->writers);
47689 }
47690
47691 mutex_unlock(&inode->i_mutex);
47692 @@ -958,7 +958,7 @@ void free_pipe_info(struct inode *inode)
47693 inode->i_pipe = NULL;
47694 }
47695
47696 -static struct vfsmount *pipe_mnt __read_mostly;
47697 +struct vfsmount *pipe_mnt __read_mostly;
47698
47699 /*
47700 * pipefs_dname() is called from d_path().
47701 @@ -988,7 +988,8 @@ static struct inode * get_pipe_inode(void)
47702 goto fail_iput;
47703 inode->i_pipe = pipe;
47704
47705 - pipe->readers = pipe->writers = 1;
47706 + atomic_set(&pipe->readers, 1);
47707 + atomic_set(&pipe->writers, 1);
47708 inode->i_fop = &rdwr_pipefifo_fops;
47709
47710 /*
47711 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
47712 index 15af622..0e9f4467 100644
47713 --- a/fs/proc/Kconfig
47714 +++ b/fs/proc/Kconfig
47715 @@ -30,12 +30,12 @@ config PROC_FS
47716
47717 config PROC_KCORE
47718 bool "/proc/kcore support" if !ARM
47719 - depends on PROC_FS && MMU
47720 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
47721
47722 config PROC_VMCORE
47723 bool "/proc/vmcore support"
47724 - depends on PROC_FS && CRASH_DUMP
47725 - default y
47726 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
47727 + default n
47728 help
47729 Exports the dump image of crashed kernel in ELF format.
47730
47731 @@ -59,8 +59,8 @@ config PROC_SYSCTL
47732 limited in memory.
47733
47734 config PROC_PAGE_MONITOR
47735 - default y
47736 - depends on PROC_FS && MMU
47737 + default n
47738 + depends on PROC_FS && MMU && !GRKERNSEC
47739 bool "Enable /proc page monitoring" if EXPERT
47740 help
47741 Various /proc files exist to monitor process memory utilization:
47742 diff --git a/fs/proc/array.c b/fs/proc/array.c
47743 index c602b8d..a7de642 100644
47744 --- a/fs/proc/array.c
47745 +++ b/fs/proc/array.c
47746 @@ -60,6 +60,7 @@
47747 #include <linux/tty.h>
47748 #include <linux/string.h>
47749 #include <linux/mman.h>
47750 +#include <linux/grsecurity.h>
47751 #include <linux/proc_fs.h>
47752 #include <linux/ioport.h>
47753 #include <linux/uaccess.h>
47754 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
47755 seq_putc(m, '\n');
47756 }
47757
47758 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47759 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
47760 +{
47761 + if (p->mm)
47762 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
47763 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
47764 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
47765 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
47766 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
47767 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
47768 + else
47769 + seq_printf(m, "PaX:\t-----\n");
47770 +}
47771 +#endif
47772 +
47773 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47774 struct pid *pid, struct task_struct *task)
47775 {
47776 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
47777 task_cpus_allowed(m, task);
47778 cpuset_task_status_allowed(m, task);
47779 task_context_switch_counts(m, task);
47780 +
47781 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47782 + task_pax(m, task);
47783 +#endif
47784 +
47785 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
47786 + task_grsec_rbac(m, task);
47787 +#endif
47788 +
47789 return 0;
47790 }
47791
47792 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47793 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47794 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47795 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47796 +#endif
47797 +
47798 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47799 struct pid *pid, struct task_struct *task, int whole)
47800 {
47801 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47802 char tcomm[sizeof(task->comm)];
47803 unsigned long flags;
47804
47805 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47806 + if (current->exec_id != m->exec_id) {
47807 + gr_log_badprocpid("stat");
47808 + return 0;
47809 + }
47810 +#endif
47811 +
47812 state = *get_task_state(task);
47813 vsize = eip = esp = 0;
47814 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47815 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47816 gtime = task->gtime;
47817 }
47818
47819 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47820 + if (PAX_RAND_FLAGS(mm)) {
47821 + eip = 0;
47822 + esp = 0;
47823 + wchan = 0;
47824 + }
47825 +#endif
47826 +#ifdef CONFIG_GRKERNSEC_HIDESYM
47827 + wchan = 0;
47828 + eip =0;
47829 + esp =0;
47830 +#endif
47831 +
47832 /* scale priority and nice values from timeslices to -20..20 */
47833 /* to make it look like a "normal" Unix priority/nice value */
47834 priority = task_prio(task);
47835 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
47836 vsize,
47837 mm ? get_mm_rss(mm) : 0,
47838 rsslim,
47839 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47840 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
47841 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
47842 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
47843 +#else
47844 mm ? (permitted ? mm->start_code : 1) : 0,
47845 mm ? (permitted ? mm->end_code : 1) : 0,
47846 (permitted && mm) ? mm->start_stack : 0,
47847 +#endif
47848 esp,
47849 eip,
47850 /* The signal information here is obsolete.
47851 @@ -536,8 +593,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47852 struct pid *pid, struct task_struct *task)
47853 {
47854 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
47855 - struct mm_struct *mm = get_task_mm(task);
47856 + struct mm_struct *mm;
47857
47858 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47859 + if (current->exec_id != m->exec_id) {
47860 + gr_log_badprocpid("statm");
47861 + return 0;
47862 + }
47863 +#endif
47864 + mm = get_task_mm(task);
47865 if (mm) {
47866 size = task_statm(mm, &shared, &text, &data, &resident);
47867 mmput(mm);
47868 @@ -547,3 +611,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
47869
47870 return 0;
47871 }
47872 +
47873 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
47874 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
47875 +{
47876 + u32 curr_ip = 0;
47877 + unsigned long flags;
47878 +
47879 + if (lock_task_sighand(task, &flags)) {
47880 + curr_ip = task->signal->curr_ip;
47881 + unlock_task_sighand(task, &flags);
47882 + }
47883 +
47884 + return sprintf(buffer, "%pI4\n", &curr_ip);
47885 +}
47886 +#endif
47887 diff --git a/fs/proc/base.c b/fs/proc/base.c
47888 index d4548dd..d101f84 100644
47889 --- a/fs/proc/base.c
47890 +++ b/fs/proc/base.c
47891 @@ -109,6 +109,14 @@ struct pid_entry {
47892 union proc_op op;
47893 };
47894
47895 +struct getdents_callback {
47896 + struct linux_dirent __user * current_dir;
47897 + struct linux_dirent __user * previous;
47898 + struct file * file;
47899 + int count;
47900 + int error;
47901 +};
47902 +
47903 #define NOD(NAME, MODE, IOP, FOP, OP) { \
47904 .name = (NAME), \
47905 .len = sizeof(NAME) - 1, \
47906 @@ -213,6 +221,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
47907 if (!mm->arg_end)
47908 goto out_mm; /* Shh! No looking before we're done */
47909
47910 + if (gr_acl_handle_procpidmem(task))
47911 + goto out_mm;
47912 +
47913 len = mm->arg_end - mm->arg_start;
47914
47915 if (len > PAGE_SIZE)
47916 @@ -240,12 +251,28 @@ out:
47917 return res;
47918 }
47919
47920 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47921 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
47922 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
47923 + _mm->pax_flags & MF_PAX_SEGMEXEC))
47924 +#endif
47925 +
47926 static int proc_pid_auxv(struct task_struct *task, char *buffer)
47927 {
47928 struct mm_struct *mm = mm_for_maps(task);
47929 int res = PTR_ERR(mm);
47930 if (mm && !IS_ERR(mm)) {
47931 unsigned int nwords = 0;
47932 +
47933 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47934 + /* allow if we're currently ptracing this task */
47935 + if (PAX_RAND_FLAGS(mm) &&
47936 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
47937 + mmput(mm);
47938 + return 0;
47939 + }
47940 +#endif
47941 +
47942 do {
47943 nwords += 2;
47944 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
47945 @@ -259,7 +286,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
47946 }
47947
47948
47949 -#ifdef CONFIG_KALLSYMS
47950 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47951 /*
47952 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
47953 * Returns the resolved symbol. If that fails, simply return the address.
47954 @@ -298,7 +325,7 @@ static void unlock_trace(struct task_struct *task)
47955 mutex_unlock(&task->signal->cred_guard_mutex);
47956 }
47957
47958 -#ifdef CONFIG_STACKTRACE
47959 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
47960
47961 #define MAX_STACK_TRACE_DEPTH 64
47962
47963 @@ -489,7 +516,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
47964 return count;
47965 }
47966
47967 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
47968 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
47969 static int proc_pid_syscall(struct task_struct *task, char *buffer)
47970 {
47971 long nr;
47972 @@ -518,7 +545,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
47973 /************************************************************************/
47974
47975 /* permission checks */
47976 -static int proc_fd_access_allowed(struct inode *inode)
47977 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
47978 {
47979 struct task_struct *task;
47980 int allowed = 0;
47981 @@ -528,7 +555,10 @@ static int proc_fd_access_allowed(struct inode *inode)
47982 */
47983 task = get_proc_task(inode);
47984 if (task) {
47985 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47986 + if (log)
47987 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
47988 + else
47989 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
47990 put_task_struct(task);
47991 }
47992 return allowed;
47993 @@ -566,10 +596,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
47994 struct task_struct *task,
47995 int hide_pid_min)
47996 {
47997 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
47998 + return false;
47999 +
48000 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48001 + rcu_read_lock();
48002 + {
48003 + const struct cred *tmpcred = current_cred();
48004 + const struct cred *cred = __task_cred(task);
48005 +
48006 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48007 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48008 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
48009 +#endif
48010 + ) {
48011 + rcu_read_unlock();
48012 + return true;
48013 + }
48014 + }
48015 + rcu_read_unlock();
48016 +
48017 + if (!pid->hide_pid)
48018 + return false;
48019 +#endif
48020 +
48021 if (pid->hide_pid < hide_pid_min)
48022 return true;
48023 if (in_group_p(pid->pid_gid))
48024 return true;
48025 +
48026 return ptrace_may_access(task, PTRACE_MODE_READ);
48027 }
48028
48029 @@ -587,7 +642,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
48030 put_task_struct(task);
48031
48032 if (!has_perms) {
48033 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48034 + {
48035 +#else
48036 if (pid->hide_pid == 2) {
48037 +#endif
48038 /*
48039 * Let's make getdents(), stat(), and open()
48040 * consistent with each other. If a process
48041 @@ -702,6 +761,10 @@ static int mem_open(struct inode* inode, struct file* file)
48042 file->f_mode |= FMODE_UNSIGNED_OFFSET;
48043 file->private_data = mm;
48044
48045 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48046 + file->f_version = current->exec_id;
48047 +#endif
48048 +
48049 return 0;
48050 }
48051
48052 @@ -713,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
48053 ssize_t copied;
48054 char *page;
48055
48056 +#ifdef CONFIG_GRKERNSEC
48057 + if (write)
48058 + return -EPERM;
48059 +#endif
48060 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48061 + if (file->f_version != current->exec_id) {
48062 + gr_log_badprocpid("mem");
48063 + return 0;
48064 + }
48065 +#endif
48066 +
48067 if (!mm)
48068 return 0;
48069
48070 @@ -813,6 +887,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
48071 if (!task)
48072 goto out_no_task;
48073
48074 + if (gr_acl_handle_procpidmem(task))
48075 + goto out;
48076 +
48077 ret = -ENOMEM;
48078 page = (char *)__get_free_page(GFP_TEMPORARY);
48079 if (!page)
48080 @@ -1434,7 +1511,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
48081 path_put(&nd->path);
48082
48083 /* Are we allowed to snoop on the tasks file descriptors? */
48084 - if (!proc_fd_access_allowed(inode))
48085 + if (!proc_fd_access_allowed(inode, 0))
48086 goto out;
48087
48088 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
48089 @@ -1473,8 +1550,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
48090 struct path path;
48091
48092 /* Are we allowed to snoop on the tasks file descriptors? */
48093 - if (!proc_fd_access_allowed(inode))
48094 - goto out;
48095 + /* logging this is needed for learning on chromium to work properly,
48096 + but we don't want to flood the logs from 'ps' which does a readlink
48097 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
48098 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
48099 + */
48100 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
48101 + if (!proc_fd_access_allowed(inode,0))
48102 + goto out;
48103 + } else {
48104 + if (!proc_fd_access_allowed(inode,1))
48105 + goto out;
48106 + }
48107
48108 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
48109 if (error)
48110 @@ -1539,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
48111 rcu_read_lock();
48112 cred = __task_cred(task);
48113 inode->i_uid = cred->euid;
48114 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48115 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48116 +#else
48117 inode->i_gid = cred->egid;
48118 +#endif
48119 rcu_read_unlock();
48120 }
48121 security_task_to_inode(task, inode);
48122 @@ -1575,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
48123 return -ENOENT;
48124 }
48125 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48126 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48127 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48128 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48129 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48130 +#endif
48131 task_dumpable(task)) {
48132 cred = __task_cred(task);
48133 stat->uid = cred->euid;
48134 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48135 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
48136 +#else
48137 stat->gid = cred->egid;
48138 +#endif
48139 }
48140 }
48141 rcu_read_unlock();
48142 @@ -1616,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
48143
48144 if (task) {
48145 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
48146 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48147 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
48148 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48149 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
48150 +#endif
48151 task_dumpable(task)) {
48152 rcu_read_lock();
48153 cred = __task_cred(task);
48154 inode->i_uid = cred->euid;
48155 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48156 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48157 +#else
48158 inode->i_gid = cred->egid;
48159 +#endif
48160 rcu_read_unlock();
48161 } else {
48162 inode->i_uid = 0;
48163 @@ -1738,7 +1847,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
48164 int fd = proc_fd(inode);
48165
48166 if (task) {
48167 - files = get_files_struct(task);
48168 + if (!gr_acl_handle_procpidmem(task))
48169 + files = get_files_struct(task);
48170 put_task_struct(task);
48171 }
48172 if (files) {
48173 @@ -2355,11 +2465,21 @@ static const struct file_operations proc_map_files_operations = {
48174 */
48175 static int proc_fd_permission(struct inode *inode, int mask)
48176 {
48177 + struct task_struct *task;
48178 int rv = generic_permission(inode, mask);
48179 - if (rv == 0)
48180 - return 0;
48181 +
48182 if (task_pid(current) == proc_pid(inode))
48183 rv = 0;
48184 +
48185 + task = get_proc_task(inode);
48186 + if (task == NULL)
48187 + return rv;
48188 +
48189 + if (gr_acl_handle_procpidmem(task))
48190 + rv = -EACCES;
48191 +
48192 + put_task_struct(task);
48193 +
48194 return rv;
48195 }
48196
48197 @@ -2469,6 +2589,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
48198 if (!task)
48199 goto out_no_task;
48200
48201 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48202 + goto out;
48203 +
48204 /*
48205 * Yes, it does not scale. And it should not. Don't add
48206 * new entries into /proc/<tgid>/ without very good reasons.
48207 @@ -2513,6 +2636,9 @@ static int proc_pident_readdir(struct file *filp,
48208 if (!task)
48209 goto out_no_task;
48210
48211 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48212 + goto out;
48213 +
48214 ret = 0;
48215 i = filp->f_pos;
48216 switch (i) {
48217 @@ -2783,7 +2909,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
48218 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
48219 void *cookie)
48220 {
48221 - char *s = nd_get_link(nd);
48222 + const char *s = nd_get_link(nd);
48223 if (!IS_ERR(s))
48224 __putname(s);
48225 }
48226 @@ -2984,7 +3110,7 @@ static const struct pid_entry tgid_base_stuff[] = {
48227 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
48228 #endif
48229 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48230 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48231 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48232 INF("syscall", S_IRUGO, proc_pid_syscall),
48233 #endif
48234 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48235 @@ -3009,10 +3135,10 @@ static const struct pid_entry tgid_base_stuff[] = {
48236 #ifdef CONFIG_SECURITY
48237 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48238 #endif
48239 -#ifdef CONFIG_KALLSYMS
48240 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48241 INF("wchan", S_IRUGO, proc_pid_wchan),
48242 #endif
48243 -#ifdef CONFIG_STACKTRACE
48244 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48245 ONE("stack", S_IRUGO, proc_pid_stack),
48246 #endif
48247 #ifdef CONFIG_SCHEDSTATS
48248 @@ -3046,6 +3172,9 @@ static const struct pid_entry tgid_base_stuff[] = {
48249 #ifdef CONFIG_HARDWALL
48250 INF("hardwall", S_IRUGO, proc_pid_hardwall),
48251 #endif
48252 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48253 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
48254 +#endif
48255 };
48256
48257 static int proc_tgid_base_readdir(struct file * filp,
48258 @@ -3172,7 +3301,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
48259 if (!inode)
48260 goto out;
48261
48262 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48263 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
48264 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48265 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48266 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
48267 +#else
48268 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
48269 +#endif
48270 inode->i_op = &proc_tgid_base_inode_operations;
48271 inode->i_fop = &proc_tgid_base_operations;
48272 inode->i_flags|=S_IMMUTABLE;
48273 @@ -3214,7 +3350,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
48274 if (!task)
48275 goto out;
48276
48277 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48278 + goto out_put_task;
48279 +
48280 result = proc_pid_instantiate(dir, dentry, task, NULL);
48281 +out_put_task:
48282 put_task_struct(task);
48283 out:
48284 return result;
48285 @@ -3277,6 +3417,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
48286 static int fake_filldir(void *buf, const char *name, int namelen,
48287 loff_t offset, u64 ino, unsigned d_type)
48288 {
48289 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
48290 + __buf->error = -EINVAL;
48291 return 0;
48292 }
48293
48294 @@ -3343,7 +3485,7 @@ static const struct pid_entry tid_base_stuff[] = {
48295 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
48296 #endif
48297 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
48298 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48299 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48300 INF("syscall", S_IRUGO, proc_pid_syscall),
48301 #endif
48302 INF("cmdline", S_IRUGO, proc_pid_cmdline),
48303 @@ -3367,10 +3509,10 @@ static const struct pid_entry tid_base_stuff[] = {
48304 #ifdef CONFIG_SECURITY
48305 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
48306 #endif
48307 -#ifdef CONFIG_KALLSYMS
48308 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48309 INF("wchan", S_IRUGO, proc_pid_wchan),
48310 #endif
48311 -#ifdef CONFIG_STACKTRACE
48312 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48313 ONE("stack", S_IRUGO, proc_pid_stack),
48314 #endif
48315 #ifdef CONFIG_SCHEDSTATS
48316 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
48317 index 82676e3..5f8518a 100644
48318 --- a/fs/proc/cmdline.c
48319 +++ b/fs/proc/cmdline.c
48320 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
48321
48322 static int __init proc_cmdline_init(void)
48323 {
48324 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48325 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
48326 +#else
48327 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
48328 +#endif
48329 return 0;
48330 }
48331 module_init(proc_cmdline_init);
48332 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
48333 index b143471..bb105e5 100644
48334 --- a/fs/proc/devices.c
48335 +++ b/fs/proc/devices.c
48336 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
48337
48338 static int __init proc_devices_init(void)
48339 {
48340 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48341 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
48342 +#else
48343 proc_create("devices", 0, NULL, &proc_devinfo_operations);
48344 +#endif
48345 return 0;
48346 }
48347 module_init(proc_devices_init);
48348 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
48349 index 84fd323..f698a32 100644
48350 --- a/fs/proc/inode.c
48351 +++ b/fs/proc/inode.c
48352 @@ -21,12 +21,18 @@
48353 #include <linux/seq_file.h>
48354 #include <linux/slab.h>
48355 #include <linux/mount.h>
48356 +#include <linux/grsecurity.h>
48357
48358 #include <asm/system.h>
48359 #include <asm/uaccess.h>
48360
48361 #include "internal.h"
48362
48363 +#ifdef CONFIG_PROC_SYSCTL
48364 +extern const struct inode_operations proc_sys_inode_operations;
48365 +extern const struct inode_operations proc_sys_dir_operations;
48366 +#endif
48367 +
48368 static void proc_evict_inode(struct inode *inode)
48369 {
48370 struct proc_dir_entry *de;
48371 @@ -52,6 +58,13 @@ static void proc_evict_inode(struct inode *inode)
48372 ns_ops = PROC_I(inode)->ns_ops;
48373 if (ns_ops && ns_ops->put)
48374 ns_ops->put(PROC_I(inode)->ns);
48375 +
48376 +#ifdef CONFIG_PROC_SYSCTL
48377 + if (inode->i_op == &proc_sys_inode_operations ||
48378 + inode->i_op == &proc_sys_dir_operations)
48379 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
48380 +#endif
48381 +
48382 }
48383
48384 static struct kmem_cache * proc_inode_cachep;
48385 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
48386 if (de->mode) {
48387 inode->i_mode = de->mode;
48388 inode->i_uid = de->uid;
48389 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48390 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
48391 +#else
48392 inode->i_gid = de->gid;
48393 +#endif
48394 }
48395 if (de->size)
48396 inode->i_size = de->size;
48397 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
48398 index 2925775..4f08fae 100644
48399 --- a/fs/proc/internal.h
48400 +++ b/fs/proc/internal.h
48401 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48402 struct pid *pid, struct task_struct *task);
48403 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48404 struct pid *pid, struct task_struct *task);
48405 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48406 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
48407 +#endif
48408 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
48409
48410 extern const struct file_operations proc_maps_operations;
48411 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
48412 index d245cb2..f4e8498 100644
48413 --- a/fs/proc/kcore.c
48414 +++ b/fs/proc/kcore.c
48415 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48416 * the addresses in the elf_phdr on our list.
48417 */
48418 start = kc_offset_to_vaddr(*fpos - elf_buflen);
48419 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
48420 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
48421 + if (tsz > buflen)
48422 tsz = buflen;
48423 -
48424 +
48425 while (buflen) {
48426 struct kcore_list *m;
48427
48428 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48429 kfree(elf_buf);
48430 } else {
48431 if (kern_addr_valid(start)) {
48432 - unsigned long n;
48433 + char *elf_buf;
48434 + mm_segment_t oldfs;
48435
48436 - n = copy_to_user(buffer, (char *)start, tsz);
48437 - /*
48438 - * We cannot distingush between fault on source
48439 - * and fault on destination. When this happens
48440 - * we clear too and hope it will trigger the
48441 - * EFAULT again.
48442 - */
48443 - if (n) {
48444 - if (clear_user(buffer + tsz - n,
48445 - n))
48446 + elf_buf = kmalloc(tsz, GFP_KERNEL);
48447 + if (!elf_buf)
48448 + return -ENOMEM;
48449 + oldfs = get_fs();
48450 + set_fs(KERNEL_DS);
48451 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
48452 + set_fs(oldfs);
48453 + if (copy_to_user(buffer, elf_buf, tsz)) {
48454 + kfree(elf_buf);
48455 return -EFAULT;
48456 + }
48457 }
48458 + set_fs(oldfs);
48459 + kfree(elf_buf);
48460 } else {
48461 if (clear_user(buffer, tsz))
48462 return -EFAULT;
48463 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
48464
48465 static int open_kcore(struct inode *inode, struct file *filp)
48466 {
48467 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
48468 + return -EPERM;
48469 +#endif
48470 if (!capable(CAP_SYS_RAWIO))
48471 return -EPERM;
48472 if (kcore_need_update)
48473 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
48474 index 80e4645..53e5fcf 100644
48475 --- a/fs/proc/meminfo.c
48476 +++ b/fs/proc/meminfo.c
48477 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
48478 vmi.used >> 10,
48479 vmi.largest_chunk >> 10
48480 #ifdef CONFIG_MEMORY_FAILURE
48481 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
48482 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
48483 #endif
48484 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
48485 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
48486 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
48487 index b1822dd..df622cb 100644
48488 --- a/fs/proc/nommu.c
48489 +++ b/fs/proc/nommu.c
48490 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
48491 if (len < 1)
48492 len = 1;
48493 seq_printf(m, "%*c", len, ' ');
48494 - seq_path(m, &file->f_path, "");
48495 + seq_path(m, &file->f_path, "\n\\");
48496 }
48497
48498 seq_putc(m, '\n');
48499 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
48500 index 06e1cc1..177cd98 100644
48501 --- a/fs/proc/proc_net.c
48502 +++ b/fs/proc/proc_net.c
48503 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
48504 struct task_struct *task;
48505 struct nsproxy *ns;
48506 struct net *net = NULL;
48507 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48508 + const struct cred *cred = current_cred();
48509 +#endif
48510 +
48511 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48512 + if (cred->fsuid)
48513 + return net;
48514 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48515 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
48516 + return net;
48517 +#endif
48518
48519 rcu_read_lock();
48520 task = pid_task(proc_pid(dir), PIDTYPE_PID);
48521 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
48522 index 53c3bce..10ad159 100644
48523 --- a/fs/proc/proc_sysctl.c
48524 +++ b/fs/proc/proc_sysctl.c
48525 @@ -9,11 +9,13 @@
48526 #include <linux/namei.h>
48527 #include "internal.h"
48528
48529 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
48530 +
48531 static const struct dentry_operations proc_sys_dentry_operations;
48532 static const struct file_operations proc_sys_file_operations;
48533 -static const struct inode_operations proc_sys_inode_operations;
48534 +const struct inode_operations proc_sys_inode_operations;
48535 static const struct file_operations proc_sys_dir_file_operations;
48536 -static const struct inode_operations proc_sys_dir_operations;
48537 +const struct inode_operations proc_sys_dir_operations;
48538
48539 void proc_sys_poll_notify(struct ctl_table_poll *poll)
48540 {
48541 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
48542
48543 err = NULL;
48544 d_set_d_op(dentry, &proc_sys_dentry_operations);
48545 +
48546 + gr_handle_proc_create(dentry, inode);
48547 +
48548 d_add(dentry, inode);
48549
48550 + if (gr_handle_sysctl(p, MAY_EXEC))
48551 + err = ERR_PTR(-ENOENT);
48552 +
48553 out:
48554 sysctl_head_finish(head);
48555 return err;
48556 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
48557 if (!table->proc_handler)
48558 goto out;
48559
48560 +#ifdef CONFIG_GRKERNSEC
48561 + error = -EPERM;
48562 + if (write && !capable(CAP_SYS_ADMIN))
48563 + goto out;
48564 +#endif
48565 +
48566 /* careful: calling conventions are nasty here */
48567 res = count;
48568 error = table->proc_handler(table, write, buf, &res, ppos);
48569 @@ -260,6 +274,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
48570 return -ENOMEM;
48571 } else {
48572 d_set_d_op(child, &proc_sys_dentry_operations);
48573 +
48574 + gr_handle_proc_create(child, inode);
48575 +
48576 d_add(child, inode);
48577 }
48578 } else {
48579 @@ -288,6 +305,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
48580 if (*pos < file->f_pos)
48581 continue;
48582
48583 + if (gr_handle_sysctl(table, 0))
48584 + continue;
48585 +
48586 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
48587 if (res)
48588 return res;
48589 @@ -413,6 +433,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
48590 if (IS_ERR(head))
48591 return PTR_ERR(head);
48592
48593 + if (table && gr_handle_sysctl(table, MAY_EXEC))
48594 + return -ENOENT;
48595 +
48596 generic_fillattr(inode, stat);
48597 if (table)
48598 stat->mode = (stat->mode & S_IFMT) | table->mode;
48599 @@ -435,13 +458,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
48600 .llseek = generic_file_llseek,
48601 };
48602
48603 -static const struct inode_operations proc_sys_inode_operations = {
48604 +const struct inode_operations proc_sys_inode_operations = {
48605 .permission = proc_sys_permission,
48606 .setattr = proc_sys_setattr,
48607 .getattr = proc_sys_getattr,
48608 };
48609
48610 -static const struct inode_operations proc_sys_dir_operations = {
48611 +const struct inode_operations proc_sys_dir_operations = {
48612 .lookup = proc_sys_lookup,
48613 .permission = proc_sys_permission,
48614 .setattr = proc_sys_setattr,
48615 diff --git a/fs/proc/root.c b/fs/proc/root.c
48616 index 46a15d8..335631a 100644
48617 --- a/fs/proc/root.c
48618 +++ b/fs/proc/root.c
48619 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
48620 #ifdef CONFIG_PROC_DEVICETREE
48621 proc_device_tree_init();
48622 #endif
48623 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
48624 +#ifdef CONFIG_GRKERNSEC_PROC_USER
48625 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
48626 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48627 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
48628 +#endif
48629 +#else
48630 proc_mkdir("bus", NULL);
48631 +#endif
48632 proc_sys_init();
48633 }
48634
48635 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
48636 index 3efa725..23c925b 100644
48637 --- a/fs/proc/task_mmu.c
48638 +++ b/fs/proc/task_mmu.c
48639 @@ -11,6 +11,7 @@
48640 #include <linux/rmap.h>
48641 #include <linux/swap.h>
48642 #include <linux/swapops.h>
48643 +#include <linux/grsecurity.h>
48644
48645 #include <asm/elf.h>
48646 #include <asm/uaccess.h>
48647 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48648 "VmExe:\t%8lu kB\n"
48649 "VmLib:\t%8lu kB\n"
48650 "VmPTE:\t%8lu kB\n"
48651 - "VmSwap:\t%8lu kB\n",
48652 - hiwater_vm << (PAGE_SHIFT-10),
48653 + "VmSwap:\t%8lu kB\n"
48654 +
48655 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48656 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
48657 +#endif
48658 +
48659 + ,hiwater_vm << (PAGE_SHIFT-10),
48660 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
48661 mm->locked_vm << (PAGE_SHIFT-10),
48662 mm->pinned_vm << (PAGE_SHIFT-10),
48663 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48664 data << (PAGE_SHIFT-10),
48665 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
48666 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
48667 - swap << (PAGE_SHIFT-10));
48668 + swap << (PAGE_SHIFT-10)
48669 +
48670 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
48671 + , mm->context.user_cs_base, mm->context.user_cs_limit
48672 +#endif
48673 +
48674 + );
48675 }
48676
48677 unsigned long task_vsize(struct mm_struct *mm)
48678 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
48679 return ret;
48680 }
48681
48682 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48683 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48684 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48685 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48686 +#endif
48687 +
48688 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48689 {
48690 struct mm_struct *mm = vma->vm_mm;
48691 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48692 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
48693 }
48694
48695 - /* We don't show the stack guard page in /proc/maps */
48696 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48697 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
48698 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
48699 +#else
48700 start = vma->vm_start;
48701 - if (stack_guard_page_start(vma, start))
48702 - start += PAGE_SIZE;
48703 end = vma->vm_end;
48704 - if (stack_guard_page_end(vma, end))
48705 - end -= PAGE_SIZE;
48706 +#endif
48707
48708 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
48709 start,
48710 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48711 flags & VM_WRITE ? 'w' : '-',
48712 flags & VM_EXEC ? 'x' : '-',
48713 flags & VM_MAYSHARE ? 's' : 'p',
48714 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48715 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
48716 +#else
48717 pgoff,
48718 +#endif
48719 MAJOR(dev), MINOR(dev), ino, &len);
48720
48721 /*
48722 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48723 */
48724 if (file) {
48725 pad_len_spaces(m, len);
48726 - seq_path(m, &file->f_path, "\n");
48727 + seq_path(m, &file->f_path, "\n\\");
48728 } else {
48729 const char *name = arch_vma_name(vma);
48730 if (!name) {
48731 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
48732 if (vma->vm_start <= mm->brk &&
48733 vma->vm_end >= mm->start_brk) {
48734 name = "[heap]";
48735 - } else if (vma->vm_start <= mm->start_stack &&
48736 - vma->vm_end >= mm->start_stack) {
48737 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
48738 + (vma->vm_start <= mm->start_stack &&
48739 + vma->vm_end >= mm->start_stack)) {
48740 name = "[stack]";
48741 }
48742 } else {
48743 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
48744 struct proc_maps_private *priv = m->private;
48745 struct task_struct *task = priv->task;
48746
48747 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48748 + if (current->exec_id != m->exec_id) {
48749 + gr_log_badprocpid("maps");
48750 + return 0;
48751 + }
48752 +#endif
48753 +
48754 show_map_vma(m, vma);
48755
48756 if (m->count < m->size) /* vma is copied successfully */
48757 @@ -437,12 +467,23 @@ static int show_smap(struct seq_file *m, void *v)
48758 .private = &mss,
48759 };
48760
48761 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48762 + if (current->exec_id != m->exec_id) {
48763 + gr_log_badprocpid("smaps");
48764 + return 0;
48765 + }
48766 +#endif
48767 memset(&mss, 0, sizeof mss);
48768 - mss.vma = vma;
48769 - /* mmap_sem is held in m_start */
48770 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48771 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48772 -
48773 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48774 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
48775 +#endif
48776 + mss.vma = vma;
48777 + /* mmap_sem is held in m_start */
48778 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
48779 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
48780 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48781 + }
48782 +#endif
48783 show_map_vma(m, vma);
48784
48785 seq_printf(m,
48786 @@ -460,7 +501,11 @@ static int show_smap(struct seq_file *m, void *v)
48787 "KernelPageSize: %8lu kB\n"
48788 "MMUPageSize: %8lu kB\n"
48789 "Locked: %8lu kB\n",
48790 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48791 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
48792 +#else
48793 (vma->vm_end - vma->vm_start) >> 10,
48794 +#endif
48795 mss.resident >> 10,
48796 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
48797 mss.shared_clean >> 10,
48798 @@ -1024,6 +1069,13 @@ static int show_numa_map(struct seq_file *m, void *v)
48799 int n;
48800 char buffer[50];
48801
48802 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48803 + if (current->exec_id != m->exec_id) {
48804 + gr_log_badprocpid("numa_maps");
48805 + return 0;
48806 + }
48807 +#endif
48808 +
48809 if (!mm)
48810 return 0;
48811
48812 @@ -1041,11 +1093,15 @@ static int show_numa_map(struct seq_file *m, void *v)
48813 mpol_to_str(buffer, sizeof(buffer), pol, 0);
48814 mpol_cond_put(pol);
48815
48816 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48817 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
48818 +#else
48819 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
48820 +#endif
48821
48822 if (file) {
48823 seq_printf(m, " file=");
48824 - seq_path(m, &file->f_path, "\n\t= ");
48825 + seq_path(m, &file->f_path, "\n\t\\= ");
48826 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
48827 seq_printf(m, " heap");
48828 } else if (vma->vm_start <= mm->start_stack &&
48829 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
48830 index 980de54..2a4db5f 100644
48831 --- a/fs/proc/task_nommu.c
48832 +++ b/fs/proc/task_nommu.c
48833 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
48834 else
48835 bytes += kobjsize(mm);
48836
48837 - if (current->fs && current->fs->users > 1)
48838 + if (current->fs && atomic_read(&current->fs->users) > 1)
48839 sbytes += kobjsize(current->fs);
48840 else
48841 bytes += kobjsize(current->fs);
48842 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
48843
48844 if (file) {
48845 pad_len_spaces(m, len);
48846 - seq_path(m, &file->f_path, "");
48847 + seq_path(m, &file->f_path, "\n\\");
48848 } else if (mm) {
48849 if (vma->vm_start <= mm->start_stack &&
48850 vma->vm_end >= mm->start_stack) {
48851 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
48852 index d67908b..d13f6a6 100644
48853 --- a/fs/quota/netlink.c
48854 +++ b/fs/quota/netlink.c
48855 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
48856 void quota_send_warning(short type, unsigned int id, dev_t dev,
48857 const char warntype)
48858 {
48859 - static atomic_t seq;
48860 + static atomic_unchecked_t seq;
48861 struct sk_buff *skb;
48862 void *msg_head;
48863 int ret;
48864 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
48865 "VFS: Not enough memory to send quota warning.\n");
48866 return;
48867 }
48868 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
48869 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
48870 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
48871 if (!msg_head) {
48872 printk(KERN_ERR
48873 diff --git a/fs/readdir.c b/fs/readdir.c
48874 index 356f715..c918d38 100644
48875 --- a/fs/readdir.c
48876 +++ b/fs/readdir.c
48877 @@ -17,6 +17,7 @@
48878 #include <linux/security.h>
48879 #include <linux/syscalls.h>
48880 #include <linux/unistd.h>
48881 +#include <linux/namei.h>
48882
48883 #include <asm/uaccess.h>
48884
48885 @@ -67,6 +68,7 @@ struct old_linux_dirent {
48886
48887 struct readdir_callback {
48888 struct old_linux_dirent __user * dirent;
48889 + struct file * file;
48890 int result;
48891 };
48892
48893 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
48894 buf->result = -EOVERFLOW;
48895 return -EOVERFLOW;
48896 }
48897 +
48898 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48899 + return 0;
48900 +
48901 buf->result++;
48902 dirent = buf->dirent;
48903 if (!access_ok(VERIFY_WRITE, dirent,
48904 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
48905
48906 buf.result = 0;
48907 buf.dirent = dirent;
48908 + buf.file = file;
48909
48910 error = vfs_readdir(file, fillonedir, &buf);
48911 if (buf.result)
48912 @@ -142,6 +149,7 @@ struct linux_dirent {
48913 struct getdents_callback {
48914 struct linux_dirent __user * current_dir;
48915 struct linux_dirent __user * previous;
48916 + struct file * file;
48917 int count;
48918 int error;
48919 };
48920 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
48921 buf->error = -EOVERFLOW;
48922 return -EOVERFLOW;
48923 }
48924 +
48925 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48926 + return 0;
48927 +
48928 dirent = buf->previous;
48929 if (dirent) {
48930 if (__put_user(offset, &dirent->d_off))
48931 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
48932 buf.previous = NULL;
48933 buf.count = count;
48934 buf.error = 0;
48935 + buf.file = file;
48936
48937 error = vfs_readdir(file, filldir, &buf);
48938 if (error >= 0)
48939 @@ -229,6 +242,7 @@ out:
48940 struct getdents_callback64 {
48941 struct linux_dirent64 __user * current_dir;
48942 struct linux_dirent64 __user * previous;
48943 + struct file *file;
48944 int count;
48945 int error;
48946 };
48947 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
48948 buf->error = -EINVAL; /* only used if we fail.. */
48949 if (reclen > buf->count)
48950 return -EINVAL;
48951 +
48952 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
48953 + return 0;
48954 +
48955 dirent = buf->previous;
48956 if (dirent) {
48957 if (__put_user(offset, &dirent->d_off))
48958 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48959
48960 buf.current_dir = dirent;
48961 buf.previous = NULL;
48962 + buf.file = file;
48963 buf.count = count;
48964 buf.error = 0;
48965
48966 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
48967 error = buf.error;
48968 lastdirent = buf.previous;
48969 if (lastdirent) {
48970 - typeof(lastdirent->d_off) d_off = file->f_pos;
48971 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
48972 if (__put_user(d_off, &lastdirent->d_off))
48973 error = -EFAULT;
48974 else
48975 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
48976 index 60c0804..d814f98 100644
48977 --- a/fs/reiserfs/do_balan.c
48978 +++ b/fs/reiserfs/do_balan.c
48979 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
48980 return;
48981 }
48982
48983 - atomic_inc(&(fs_generation(tb->tb_sb)));
48984 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
48985 do_balance_starts(tb);
48986
48987 /* balance leaf returns 0 except if combining L R and S into
48988 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
48989 index 7a99811..a7c96c4 100644
48990 --- a/fs/reiserfs/procfs.c
48991 +++ b/fs/reiserfs/procfs.c
48992 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
48993 "SMALL_TAILS " : "NO_TAILS ",
48994 replay_only(sb) ? "REPLAY_ONLY " : "",
48995 convert_reiserfs(sb) ? "CONV " : "",
48996 - atomic_read(&r->s_generation_counter),
48997 + atomic_read_unchecked(&r->s_generation_counter),
48998 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
48999 SF(s_do_balance), SF(s_unneeded_left_neighbor),
49000 SF(s_good_search_by_key_reada), SF(s_bmaps),
49001 diff --git a/fs/select.c b/fs/select.c
49002 index e782258..3b4b44c 100644
49003 --- a/fs/select.c
49004 +++ b/fs/select.c
49005 @@ -20,6 +20,7 @@
49006 #include <linux/module.h>
49007 #include <linux/slab.h>
49008 #include <linux/poll.h>
49009 +#include <linux/security.h>
49010 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
49011 #include <linux/file.h>
49012 #include <linux/fdtable.h>
49013 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
49014 struct poll_list *walk = head;
49015 unsigned long todo = nfds;
49016
49017 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
49018 if (nfds > rlimit(RLIMIT_NOFILE))
49019 return -EINVAL;
49020
49021 diff --git a/fs/seq_file.c b/fs/seq_file.c
49022 index 4023d6b..ab46c6a 100644
49023 --- a/fs/seq_file.c
49024 +++ b/fs/seq_file.c
49025 @@ -9,6 +9,7 @@
49026 #include <linux/module.h>
49027 #include <linux/seq_file.h>
49028 #include <linux/slab.h>
49029 +#include <linux/sched.h>
49030
49031 #include <asm/uaccess.h>
49032 #include <asm/page.h>
49033 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
49034 memset(p, 0, sizeof(*p));
49035 mutex_init(&p->lock);
49036 p->op = op;
49037 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49038 + p->exec_id = current->exec_id;
49039 +#endif
49040
49041 /*
49042 * Wrappers around seq_open(e.g. swaps_open) need to be
49043 @@ -549,7 +553,7 @@ static void single_stop(struct seq_file *p, void *v)
49044 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
49045 void *data)
49046 {
49047 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
49048 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
49049 int res = -ENOMEM;
49050
49051 if (op) {
49052 diff --git a/fs/splice.c b/fs/splice.c
49053 index 96d7b28..fd465ac 100644
49054 --- a/fs/splice.c
49055 +++ b/fs/splice.c
49056 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49057 pipe_lock(pipe);
49058
49059 for (;;) {
49060 - if (!pipe->readers) {
49061 + if (!atomic_read(&pipe->readers)) {
49062 send_sig(SIGPIPE, current, 0);
49063 if (!ret)
49064 ret = -EPIPE;
49065 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
49066 do_wakeup = 0;
49067 }
49068
49069 - pipe->waiting_writers++;
49070 + atomic_inc(&pipe->waiting_writers);
49071 pipe_wait(pipe);
49072 - pipe->waiting_writers--;
49073 + atomic_dec(&pipe->waiting_writers);
49074 }
49075
49076 pipe_unlock(pipe);
49077 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
49078 old_fs = get_fs();
49079 set_fs(get_ds());
49080 /* The cast to a user pointer is valid due to the set_fs() */
49081 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
49082 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
49083 set_fs(old_fs);
49084
49085 return res;
49086 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
49087 old_fs = get_fs();
49088 set_fs(get_ds());
49089 /* The cast to a user pointer is valid due to the set_fs() */
49090 - res = vfs_write(file, (const char __user *)buf, count, &pos);
49091 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
49092 set_fs(old_fs);
49093
49094 return res;
49095 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
49096 goto err;
49097
49098 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
49099 - vec[i].iov_base = (void __user *) page_address(page);
49100 + vec[i].iov_base = (void __force_user *) page_address(page);
49101 vec[i].iov_len = this_len;
49102 spd.pages[i] = page;
49103 spd.nr_pages++;
49104 @@ -848,10 +848,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
49105 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
49106 {
49107 while (!pipe->nrbufs) {
49108 - if (!pipe->writers)
49109 + if (!atomic_read(&pipe->writers))
49110 return 0;
49111
49112 - if (!pipe->waiting_writers && sd->num_spliced)
49113 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
49114 return 0;
49115
49116 if (sd->flags & SPLICE_F_NONBLOCK)
49117 @@ -1184,7 +1184,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
49118 * out of the pipe right after the splice_to_pipe(). So set
49119 * PIPE_READERS appropriately.
49120 */
49121 - pipe->readers = 1;
49122 + atomic_set(&pipe->readers, 1);
49123
49124 current->splice_pipe = pipe;
49125 }
49126 @@ -1736,9 +1736,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49127 ret = -ERESTARTSYS;
49128 break;
49129 }
49130 - if (!pipe->writers)
49131 + if (!atomic_read(&pipe->writers))
49132 break;
49133 - if (!pipe->waiting_writers) {
49134 + if (!atomic_read(&pipe->waiting_writers)) {
49135 if (flags & SPLICE_F_NONBLOCK) {
49136 ret = -EAGAIN;
49137 break;
49138 @@ -1770,7 +1770,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49139 pipe_lock(pipe);
49140
49141 while (pipe->nrbufs >= pipe->buffers) {
49142 - if (!pipe->readers) {
49143 + if (!atomic_read(&pipe->readers)) {
49144 send_sig(SIGPIPE, current, 0);
49145 ret = -EPIPE;
49146 break;
49147 @@ -1783,9 +1783,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
49148 ret = -ERESTARTSYS;
49149 break;
49150 }
49151 - pipe->waiting_writers++;
49152 + atomic_inc(&pipe->waiting_writers);
49153 pipe_wait(pipe);
49154 - pipe->waiting_writers--;
49155 + atomic_dec(&pipe->waiting_writers);
49156 }
49157
49158 pipe_unlock(pipe);
49159 @@ -1821,14 +1821,14 @@ retry:
49160 pipe_double_lock(ipipe, opipe);
49161
49162 do {
49163 - if (!opipe->readers) {
49164 + if (!atomic_read(&opipe->readers)) {
49165 send_sig(SIGPIPE, current, 0);
49166 if (!ret)
49167 ret = -EPIPE;
49168 break;
49169 }
49170
49171 - if (!ipipe->nrbufs && !ipipe->writers)
49172 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
49173 break;
49174
49175 /*
49176 @@ -1925,7 +1925,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49177 pipe_double_lock(ipipe, opipe);
49178
49179 do {
49180 - if (!opipe->readers) {
49181 + if (!atomic_read(&opipe->readers)) {
49182 send_sig(SIGPIPE, current, 0);
49183 if (!ret)
49184 ret = -EPIPE;
49185 @@ -1970,7 +1970,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
49186 * return EAGAIN if we have the potential of some data in the
49187 * future, otherwise just return 0
49188 */
49189 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
49190 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
49191 ret = -EAGAIN;
49192
49193 pipe_unlock(ipipe);
49194 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
49195 index 7fdf6a7..e6cd8ad 100644
49196 --- a/fs/sysfs/dir.c
49197 +++ b/fs/sysfs/dir.c
49198 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
49199 struct sysfs_dirent *sd;
49200 int rc;
49201
49202 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49203 + const char *parent_name = parent_sd->s_name;
49204 +
49205 + mode = S_IFDIR | S_IRWXU;
49206 +
49207 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
49208 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
49209 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
49210 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
49211 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
49212 +#endif
49213 +
49214 /* allocate */
49215 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
49216 if (!sd)
49217 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
49218 index 00012e3..8392349 100644
49219 --- a/fs/sysfs/file.c
49220 +++ b/fs/sysfs/file.c
49221 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
49222
49223 struct sysfs_open_dirent {
49224 atomic_t refcnt;
49225 - atomic_t event;
49226 + atomic_unchecked_t event;
49227 wait_queue_head_t poll;
49228 struct list_head buffers; /* goes through sysfs_buffer.list */
49229 };
49230 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
49231 if (!sysfs_get_active(attr_sd))
49232 return -ENODEV;
49233
49234 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
49235 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
49236 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
49237
49238 sysfs_put_active(attr_sd);
49239 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
49240 return -ENOMEM;
49241
49242 atomic_set(&new_od->refcnt, 0);
49243 - atomic_set(&new_od->event, 1);
49244 + atomic_set_unchecked(&new_od->event, 1);
49245 init_waitqueue_head(&new_od->poll);
49246 INIT_LIST_HEAD(&new_od->buffers);
49247 goto retry;
49248 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
49249
49250 sysfs_put_active(attr_sd);
49251
49252 - if (buffer->event != atomic_read(&od->event))
49253 + if (buffer->event != atomic_read_unchecked(&od->event))
49254 goto trigger;
49255
49256 return DEFAULT_POLLMASK;
49257 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
49258
49259 od = sd->s_attr.open;
49260 if (od) {
49261 - atomic_inc(&od->event);
49262 + atomic_inc_unchecked(&od->event);
49263 wake_up_interruptible(&od->poll);
49264 }
49265
49266 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
49267 index a7ac78f..02158e1 100644
49268 --- a/fs/sysfs/symlink.c
49269 +++ b/fs/sysfs/symlink.c
49270 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
49271
49272 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
49273 {
49274 - char *page = nd_get_link(nd);
49275 + const char *page = nd_get_link(nd);
49276 if (!IS_ERR(page))
49277 free_page((unsigned long)page);
49278 }
49279 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
49280 index c175b4d..8f36a16 100644
49281 --- a/fs/udf/misc.c
49282 +++ b/fs/udf/misc.c
49283 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
49284
49285 u8 udf_tag_checksum(const struct tag *t)
49286 {
49287 - u8 *data = (u8 *)t;
49288 + const u8 *data = (const u8 *)t;
49289 u8 checksum = 0;
49290 int i;
49291 for (i = 0; i < sizeof(struct tag); ++i)
49292 diff --git a/fs/utimes.c b/fs/utimes.c
49293 index ba653f3..06ea4b1 100644
49294 --- a/fs/utimes.c
49295 +++ b/fs/utimes.c
49296 @@ -1,6 +1,7 @@
49297 #include <linux/compiler.h>
49298 #include <linux/file.h>
49299 #include <linux/fs.h>
49300 +#include <linux/security.h>
49301 #include <linux/linkage.h>
49302 #include <linux/mount.h>
49303 #include <linux/namei.h>
49304 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
49305 goto mnt_drop_write_and_out;
49306 }
49307 }
49308 +
49309 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
49310 + error = -EACCES;
49311 + goto mnt_drop_write_and_out;
49312 + }
49313 +
49314 mutex_lock(&inode->i_mutex);
49315 error = notify_change(path->dentry, &newattrs);
49316 mutex_unlock(&inode->i_mutex);
49317 diff --git a/fs/xattr.c b/fs/xattr.c
49318 index 82f4337..236473c 100644
49319 --- a/fs/xattr.c
49320 +++ b/fs/xattr.c
49321 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
49322 * Extended attribute SET operations
49323 */
49324 static long
49325 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
49326 +setxattr(struct path *path, const char __user *name, const void __user *value,
49327 size_t size, int flags)
49328 {
49329 int error;
49330 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
49331 return PTR_ERR(kvalue);
49332 }
49333
49334 - error = vfs_setxattr(d, kname, kvalue, size, flags);
49335 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
49336 + error = -EACCES;
49337 + goto out;
49338 + }
49339 +
49340 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
49341 +out:
49342 kfree(kvalue);
49343 return error;
49344 }
49345 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
49346 return error;
49347 error = mnt_want_write(path.mnt);
49348 if (!error) {
49349 - error = setxattr(path.dentry, name, value, size, flags);
49350 + error = setxattr(&path, name, value, size, flags);
49351 mnt_drop_write(path.mnt);
49352 }
49353 path_put(&path);
49354 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
49355 return error;
49356 error = mnt_want_write(path.mnt);
49357 if (!error) {
49358 - error = setxattr(path.dentry, name, value, size, flags);
49359 + error = setxattr(&path, name, value, size, flags);
49360 mnt_drop_write(path.mnt);
49361 }
49362 path_put(&path);
49363 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
49364 const void __user *,value, size_t, size, int, flags)
49365 {
49366 struct file *f;
49367 - struct dentry *dentry;
49368 int error = -EBADF;
49369
49370 f = fget(fd);
49371 if (!f)
49372 return error;
49373 - dentry = f->f_path.dentry;
49374 - audit_inode(NULL, dentry);
49375 + audit_inode(NULL, f->f_path.dentry);
49376 error = mnt_want_write_file(f);
49377 if (!error) {
49378 - error = setxattr(dentry, name, value, size, flags);
49379 + error = setxattr(&f->f_path, name, value, size, flags);
49380 mnt_drop_write_file(f);
49381 }
49382 fput(f);
49383 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
49384 index 8d5a506..7f62712 100644
49385 --- a/fs/xattr_acl.c
49386 +++ b/fs/xattr_acl.c
49387 @@ -17,8 +17,8 @@
49388 struct posix_acl *
49389 posix_acl_from_xattr(const void *value, size_t size)
49390 {
49391 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
49392 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
49393 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
49394 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
49395 int count;
49396 struct posix_acl *acl;
49397 struct posix_acl_entry *acl_e;
49398 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
49399 index 188ef2f..adcf864 100644
49400 --- a/fs/xfs/xfs_bmap.c
49401 +++ b/fs/xfs/xfs_bmap.c
49402 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
49403 int nmap,
49404 int ret_nmap);
49405 #else
49406 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
49407 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
49408 #endif /* DEBUG */
49409
49410 STATIC int
49411 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
49412 index 79d05e8..e3e5861 100644
49413 --- a/fs/xfs/xfs_dir2_sf.c
49414 +++ b/fs/xfs/xfs_dir2_sf.c
49415 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
49416 }
49417
49418 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
49419 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49420 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
49421 + char name[sfep->namelen];
49422 + memcpy(name, sfep->name, sfep->namelen);
49423 + if (filldir(dirent, name, sfep->namelen,
49424 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
49425 + *offset = off & 0x7fffffff;
49426 + return 0;
49427 + }
49428 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
49429 off & 0x7fffffff, ino, DT_UNKNOWN)) {
49430 *offset = off & 0x7fffffff;
49431 return 0;
49432 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
49433 index 76f3ca5..f57f712 100644
49434 --- a/fs/xfs/xfs_ioctl.c
49435 +++ b/fs/xfs/xfs_ioctl.c
49436 @@ -128,7 +128,7 @@ xfs_find_handle(
49437 }
49438
49439 error = -EFAULT;
49440 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
49441 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
49442 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
49443 goto out_put;
49444
49445 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
49446 index ab30253..4d86958 100644
49447 --- a/fs/xfs/xfs_iops.c
49448 +++ b/fs/xfs/xfs_iops.c
49449 @@ -447,7 +447,7 @@ xfs_vn_put_link(
49450 struct nameidata *nd,
49451 void *p)
49452 {
49453 - char *s = nd_get_link(nd);
49454 + const char *s = nd_get_link(nd);
49455
49456 if (!IS_ERR(s))
49457 kfree(s);
49458 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
49459 new file mode 100644
49460 index 0000000..2645296
49461 --- /dev/null
49462 +++ b/grsecurity/Kconfig
49463 @@ -0,0 +1,1079 @@
49464 +#
49465 +# grecurity configuration
49466 +#
49467 +
49468 +menu "Grsecurity"
49469 +
49470 +config GRKERNSEC
49471 + bool "Grsecurity"
49472 + select CRYPTO
49473 + select CRYPTO_SHA256
49474 + help
49475 + If you say Y here, you will be able to configure many features
49476 + that will enhance the security of your system. It is highly
49477 + recommended that you say Y here and read through the help
49478 + for each option so that you fully understand the features and
49479 + can evaluate their usefulness for your machine.
49480 +
49481 +choice
49482 + prompt "Security Level"
49483 + depends on GRKERNSEC
49484 + default GRKERNSEC_CUSTOM
49485 +
49486 +config GRKERNSEC_LOW
49487 + bool "Low"
49488 + select GRKERNSEC_LINK
49489 + select GRKERNSEC_FIFO
49490 + select GRKERNSEC_RANDNET
49491 + select GRKERNSEC_DMESG
49492 + select GRKERNSEC_CHROOT
49493 + select GRKERNSEC_CHROOT_CHDIR
49494 +
49495 + help
49496 + If you choose this option, several of the grsecurity options will
49497 + be enabled that will give you greater protection against a number
49498 + of attacks, while assuring that none of your software will have any
49499 + conflicts with the additional security measures. If you run a lot
49500 + of unusual software, or you are having problems with the higher
49501 + security levels, you should say Y here. With this option, the
49502 + following features are enabled:
49503 +
49504 + - Linking restrictions
49505 + - FIFO restrictions
49506 + - Restricted dmesg
49507 + - Enforced chdir("/") on chroot
49508 + - Runtime module disabling
49509 +
49510 +config GRKERNSEC_MEDIUM
49511 + bool "Medium"
49512 + select PAX
49513 + select PAX_EI_PAX
49514 + select PAX_PT_PAX_FLAGS
49515 + select PAX_HAVE_ACL_FLAGS
49516 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49517 + select GRKERNSEC_CHROOT
49518 + select GRKERNSEC_CHROOT_SYSCTL
49519 + select GRKERNSEC_LINK
49520 + select GRKERNSEC_FIFO
49521 + select GRKERNSEC_DMESG
49522 + select GRKERNSEC_RANDNET
49523 + select GRKERNSEC_FORKFAIL
49524 + select GRKERNSEC_TIME
49525 + select GRKERNSEC_SIGNAL
49526 + select GRKERNSEC_CHROOT
49527 + select GRKERNSEC_CHROOT_UNIX
49528 + select GRKERNSEC_CHROOT_MOUNT
49529 + select GRKERNSEC_CHROOT_PIVOT
49530 + select GRKERNSEC_CHROOT_DOUBLE
49531 + select GRKERNSEC_CHROOT_CHDIR
49532 + select GRKERNSEC_CHROOT_MKNOD
49533 + select GRKERNSEC_PROC
49534 + select GRKERNSEC_PROC_USERGROUP
49535 + select PAX_RANDUSTACK
49536 + select PAX_ASLR
49537 + select PAX_RANDMMAP
49538 + select PAX_REFCOUNT if (X86 || SPARC64)
49539 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
49540 +
49541 + help
49542 + If you say Y here, several features in addition to those included
49543 + in the low additional security level will be enabled. These
49544 + features provide even more security to your system, though in rare
49545 + cases they may be incompatible with very old or poorly written
49546 + software. If you enable this option, make sure that your auth
49547 + service (identd) is running as gid 1001. With this option,
49548 + the following features (in addition to those provided in the
49549 + low additional security level) will be enabled:
49550 +
49551 + - Failed fork logging
49552 + - Time change logging
49553 + - Signal logging
49554 + - Deny mounts in chroot
49555 + - Deny double chrooting
49556 + - Deny sysctl writes in chroot
49557 + - Deny mknod in chroot
49558 + - Deny access to abstract AF_UNIX sockets out of chroot
49559 + - Deny pivot_root in chroot
49560 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
49561 + - /proc restrictions with special GID set to 10 (usually wheel)
49562 + - Address Space Layout Randomization (ASLR)
49563 + - Prevent exploitation of most refcount overflows
49564 + - Bounds checking of copying between the kernel and userland
49565 +
49566 +config GRKERNSEC_HIGH
49567 + bool "High"
49568 + select GRKERNSEC_LINK
49569 + select GRKERNSEC_FIFO
49570 + select GRKERNSEC_DMESG
49571 + select GRKERNSEC_FORKFAIL
49572 + select GRKERNSEC_TIME
49573 + select GRKERNSEC_SIGNAL
49574 + select GRKERNSEC_CHROOT
49575 + select GRKERNSEC_CHROOT_SHMAT
49576 + select GRKERNSEC_CHROOT_UNIX
49577 + select GRKERNSEC_CHROOT_MOUNT
49578 + select GRKERNSEC_CHROOT_FCHDIR
49579 + select GRKERNSEC_CHROOT_PIVOT
49580 + select GRKERNSEC_CHROOT_DOUBLE
49581 + select GRKERNSEC_CHROOT_CHDIR
49582 + select GRKERNSEC_CHROOT_MKNOD
49583 + select GRKERNSEC_CHROOT_CAPS
49584 + select GRKERNSEC_CHROOT_SYSCTL
49585 + select GRKERNSEC_CHROOT_FINDTASK
49586 + select GRKERNSEC_SYSFS_RESTRICT
49587 + select GRKERNSEC_PROC
49588 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
49589 + select GRKERNSEC_HIDESYM
49590 + select GRKERNSEC_BRUTE
49591 + select GRKERNSEC_PROC_USERGROUP
49592 + select GRKERNSEC_KMEM
49593 + select GRKERNSEC_RESLOG
49594 + select GRKERNSEC_RANDNET
49595 + select GRKERNSEC_PROC_ADD
49596 + select GRKERNSEC_CHROOT_CHMOD
49597 + select GRKERNSEC_CHROOT_NICE
49598 + select GRKERNSEC_SETXID if (X86 || SPARC64 || PPC || ARM || MIPS)
49599 + select GRKERNSEC_AUDIT_MOUNT
49600 + select GRKERNSEC_MODHARDEN if (MODULES)
49601 + select GRKERNSEC_HARDEN_PTRACE
49602 + select GRKERNSEC_PTRACE_READEXEC
49603 + select GRKERNSEC_VM86 if (X86_32)
49604 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
49605 + select PAX
49606 + select PAX_RANDUSTACK
49607 + select PAX_ASLR
49608 + select PAX_RANDMMAP
49609 + select PAX_NOEXEC
49610 + select PAX_MPROTECT
49611 + select PAX_EI_PAX
49612 + select PAX_PT_PAX_FLAGS
49613 + select PAX_HAVE_ACL_FLAGS
49614 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
49615 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
49616 + select PAX_RANDKSTACK if (X86_TSC && X86)
49617 + select PAX_SEGMEXEC if (X86_32)
49618 + select PAX_PAGEEXEC
49619 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
49620 + select PAX_EMUTRAMP if (PARISC)
49621 + select PAX_EMUSIGRT if (PARISC)
49622 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
49623 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
49624 + select PAX_REFCOUNT if (X86 || SPARC64)
49625 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
49626 + help
49627 + If you say Y here, many of the features of grsecurity will be
49628 + enabled, which will protect you against many kinds of attacks
49629 + against your system. The heightened security comes at a cost
49630 + of an increased chance of incompatibilities with rare software
49631 + on your machine. Since this security level enables PaX, you should
49632 + view <http://pax.grsecurity.net> and read about the PaX
49633 + project. While you are there, download chpax and run it on
49634 + binaries that cause problems with PaX. Also remember that
49635 + since the /proc restrictions are enabled, you must run your
49636 + identd as gid 1001. This security level enables the following
49637 + features in addition to those listed in the low and medium
49638 + security levels:
49639 +
49640 + - Additional /proc restrictions
49641 + - Chmod restrictions in chroot
49642 + - No signals, ptrace, or viewing of processes outside of chroot
49643 + - Capability restrictions in chroot
49644 + - Deny fchdir out of chroot
49645 + - Priority restrictions in chroot
49646 + - Segmentation-based implementation of PaX
49647 + - Mprotect restrictions
49648 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
49649 + - Kernel stack randomization
49650 + - Mount/unmount/remount logging
49651 + - Kernel symbol hiding
49652 + - Hardening of module auto-loading
49653 + - Ptrace restrictions
49654 + - Restricted vm86 mode
49655 + - Restricted sysfs/debugfs
49656 + - Active kernel exploit response
49657 +
49658 +config GRKERNSEC_CUSTOM
49659 + bool "Custom"
49660 + help
49661 + If you say Y here, you will be able to configure every grsecurity
49662 + option, which allows you to enable many more features that aren't
49663 + covered in the basic security levels. These additional features
49664 + include TPE, socket restrictions, and the sysctl system for
49665 + grsecurity. It is advised that you read through the help for
49666 + each option to determine its usefulness in your situation.
49667 +
49668 +endchoice
49669 +
49670 +menu "Memory Protections"
49671 +depends on GRKERNSEC
49672 +
49673 +config GRKERNSEC_KMEM
49674 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
49675 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
49676 + help
49677 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
49678 + be written to or read from to modify or leak the contents of the running
49679 + kernel. /dev/port will also not be allowed to be opened. If you have module
49680 + support disabled, enabling this will close up four ways that are
49681 + currently used to insert malicious code into the running kernel.
49682 + Even with all these features enabled, we still highly recommend that
49683 + you use the RBAC system, as it is still possible for an attacker to
49684 + modify the running kernel through privileged I/O granted by ioperm/iopl.
49685 + If you are not using XFree86, you may be able to stop this additional
49686 + case by enabling the 'Disable privileged I/O' option. Though nothing
49687 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
49688 + but only to video memory, which is the only writing we allow in this
49689 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
49690 + not be allowed to mprotect it with PROT_WRITE later.
49691 + It is highly recommended that you say Y here if you meet all the
49692 + conditions above.
49693 +
49694 +config GRKERNSEC_VM86
49695 + bool "Restrict VM86 mode"
49696 + depends on X86_32
49697 +
49698 + help
49699 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
49700 + make use of a special execution mode on 32bit x86 processors called
49701 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
49702 + video cards and will still work with this option enabled. The purpose
49703 + of the option is to prevent exploitation of emulation errors in
49704 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
49705 + Nearly all users should be able to enable this option.
49706 +
49707 +config GRKERNSEC_IO
49708 + bool "Disable privileged I/O"
49709 + depends on X86
49710 + select RTC_CLASS
49711 + select RTC_INTF_DEV
49712 + select RTC_DRV_CMOS
49713 +
49714 + help
49715 + If you say Y here, all ioperm and iopl calls will return an error.
49716 + Ioperm and iopl can be used to modify the running kernel.
49717 + Unfortunately, some programs need this access to operate properly,
49718 + the most notable of which are XFree86 and hwclock. hwclock can be
49719 + remedied by having RTC support in the kernel, so real-time
49720 + clock support is enabled if this option is enabled, to ensure
49721 + that hwclock operates correctly. XFree86 still will not
49722 + operate correctly with this option enabled, so DO NOT CHOOSE Y
49723 + IF YOU USE XFree86. If you use XFree86 and you still want to
49724 + protect your kernel against modification, use the RBAC system.
49725 +
49726 +config GRKERNSEC_PROC_MEMMAP
49727 + bool "Harden ASLR against information leaks and entropy reduction"
49728 + default y if (PAX_NOEXEC || PAX_ASLR)
49729 + depends on PAX_NOEXEC || PAX_ASLR
49730 + help
49731 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
49732 + give no information about the addresses of its mappings if
49733 + PaX features that rely on random addresses are enabled on the task.
49734 + In addition to sanitizing this information and disabling other
49735 + dangerous sources of information, this option causes reads of sensitive
49736 + /proc/<pid> entries where the file descriptor was opened in a different
49737 + task than the one performing the read. Such attempts are logged.
49738 + This option also limits argv/env strings for suid/sgid binaries
49739 + to 512KB to prevent a complete exhaustion of the stack entropy provided
49740 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
49741 + binaries to prevent alternative mmap layouts from being abused.
49742 +
49743 + If you use PaX it is essential that you say Y here as it closes up
49744 + several holes that make full ASLR useless locally.
49745 +
49746 +config GRKERNSEC_BRUTE
49747 + bool "Deter exploit bruteforcing"
49748 + help
49749 + If you say Y here, attempts to bruteforce exploits against forking
49750 + daemons such as apache or sshd, as well as against suid/sgid binaries
49751 + will be deterred. When a child of a forking daemon is killed by PaX
49752 + or crashes due to an illegal instruction or other suspicious signal,
49753 + the parent process will be delayed 30 seconds upon every subsequent
49754 + fork until the administrator is able to assess the situation and
49755 + restart the daemon.
49756 + In the suid/sgid case, the attempt is logged, the user has all their
49757 + processes terminated, and they are prevented from executing any further
49758 + processes for 15 minutes.
49759 + It is recommended that you also enable signal logging in the auditing
49760 + section so that logs are generated when a process triggers a suspicious
49761 + signal.
49762 + If the sysctl option is enabled, a sysctl option with name
49763 + "deter_bruteforce" is created.
49764 +
49765 +
49766 +config GRKERNSEC_MODHARDEN
49767 + bool "Harden module auto-loading"
49768 + depends on MODULES
49769 + help
49770 + If you say Y here, module auto-loading in response to use of some
49771 + feature implemented by an unloaded module will be restricted to
49772 + root users. Enabling this option helps defend against attacks
49773 + by unprivileged users who abuse the auto-loading behavior to
49774 + cause a vulnerable module to load that is then exploited.
49775 +
49776 + If this option prevents a legitimate use of auto-loading for a
49777 + non-root user, the administrator can execute modprobe manually
49778 + with the exact name of the module mentioned in the alert log.
49779 + Alternatively, the administrator can add the module to the list
49780 + of modules loaded at boot by modifying init scripts.
49781 +
49782 + Modification of init scripts will most likely be needed on
49783 + Ubuntu servers with encrypted home directory support enabled,
49784 + as the first non-root user logging in will cause the ecb(aes),
49785 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
49786 +
49787 +config GRKERNSEC_HIDESYM
49788 + bool "Hide kernel symbols"
49789 + help
49790 + If you say Y here, getting information on loaded modules, and
49791 + displaying all kernel symbols through a syscall will be restricted
49792 + to users with CAP_SYS_MODULE. For software compatibility reasons,
49793 + /proc/kallsyms will be restricted to the root user. The RBAC
49794 + system can hide that entry even from root.
49795 +
49796 + This option also prevents leaking of kernel addresses through
49797 + several /proc entries.
49798 +
49799 + Note that this option is only effective provided the following
49800 + conditions are met:
49801 + 1) The kernel using grsecurity is not precompiled by some distribution
49802 + 2) You have also enabled GRKERNSEC_DMESG
49803 + 3) You are using the RBAC system and hiding other files such as your
49804 + kernel image and System.map. Alternatively, enabling this option
49805 + causes the permissions on /boot, /lib/modules, and the kernel
49806 + source directory to change at compile time to prevent
49807 + reading by non-root users.
49808 + If the above conditions are met, this option will aid in providing a
49809 + useful protection against local kernel exploitation of overflows
49810 + and arbitrary read/write vulnerabilities.
49811 +
49812 +config GRKERNSEC_KERN_LOCKOUT
49813 + bool "Active kernel exploit response"
49814 + depends on X86 || ARM || PPC || SPARC
49815 + help
49816 + If you say Y here, when a PaX alert is triggered due to suspicious
49817 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
49818 + or an OOPs occurs due to bad memory accesses, instead of just
49819 + terminating the offending process (and potentially allowing
49820 + a subsequent exploit from the same user), we will take one of two
49821 + actions:
49822 + If the user was root, we will panic the system
49823 + If the user was non-root, we will log the attempt, terminate
49824 + all processes owned by the user, then prevent them from creating
49825 + any new processes until the system is restarted
49826 + This deters repeated kernel exploitation/bruteforcing attempts
49827 + and is useful for later forensics.
49828 +
49829 +endmenu
49830 +menu "Role Based Access Control Options"
49831 +depends on GRKERNSEC
49832 +
49833 +config GRKERNSEC_RBAC_DEBUG
49834 + bool
49835 +
49836 +config GRKERNSEC_NO_RBAC
49837 + bool "Disable RBAC system"
49838 + help
49839 + If you say Y here, the /dev/grsec device will be removed from the kernel,
49840 + preventing the RBAC system from being enabled. You should only say Y
49841 + here if you have no intention of using the RBAC system, so as to prevent
49842 + an attacker with root access from misusing the RBAC system to hide files
49843 + and processes when loadable module support and /dev/[k]mem have been
49844 + locked down.
49845 +
49846 +config GRKERNSEC_ACL_HIDEKERN
49847 + bool "Hide kernel processes"
49848 + help
49849 + If you say Y here, all kernel threads will be hidden to all
49850 + processes but those whose subject has the "view hidden processes"
49851 + flag.
49852 +
49853 +config GRKERNSEC_ACL_MAXTRIES
49854 + int "Maximum tries before password lockout"
49855 + default 3
49856 + help
49857 + This option enforces the maximum number of times a user can attempt
49858 + to authorize themselves with the grsecurity RBAC system before being
49859 + denied the ability to attempt authorization again for a specified time.
49860 + The lower the number, the harder it will be to brute-force a password.
49861 +
49862 +config GRKERNSEC_ACL_TIMEOUT
49863 + int "Time to wait after max password tries, in seconds"
49864 + default 30
49865 + help
49866 + This option specifies the time the user must wait after attempting to
49867 + authorize to the RBAC system with the maximum number of invalid
49868 + passwords. The higher the number, the harder it will be to brute-force
49869 + a password.
49870 +
49871 +endmenu
49872 +menu "Filesystem Protections"
49873 +depends on GRKERNSEC
49874 +
49875 +config GRKERNSEC_PROC
49876 + bool "Proc restrictions"
49877 + help
49878 + If you say Y here, the permissions of the /proc filesystem
49879 + will be altered to enhance system security and privacy. You MUST
49880 + choose either a user only restriction or a user and group restriction.
49881 + Depending upon the option you choose, you can either restrict users to
49882 + see only the processes they themselves run, or choose a group that can
49883 + view all processes and files normally restricted to root if you choose
49884 + the "restrict to user only" option. NOTE: If you're running identd or
49885 + ntpd as a non-root user, you will have to run it as the group you
49886 + specify here.
49887 +
49888 +config GRKERNSEC_PROC_USER
49889 + bool "Restrict /proc to user only"
49890 + depends on GRKERNSEC_PROC
49891 + help
49892 + If you say Y here, non-root users will only be able to view their own
49893 + processes, and restricts them from viewing network-related information,
49894 + and viewing kernel symbol and module information.
49895 +
49896 +config GRKERNSEC_PROC_USERGROUP
49897 + bool "Allow special group"
49898 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
49899 + help
49900 + If you say Y here, you will be able to select a group that will be
49901 + able to view all processes and network-related information. If you've
49902 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
49903 + remain hidden. This option is useful if you want to run identd as
49904 + a non-root user.
49905 +
49906 +config GRKERNSEC_PROC_GID
49907 + int "GID for special group"
49908 + depends on GRKERNSEC_PROC_USERGROUP
49909 + default 1001
49910 +
49911 +config GRKERNSEC_PROC_ADD
49912 + bool "Additional restrictions"
49913 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
49914 + help
49915 + If you say Y here, additional restrictions will be placed on
49916 + /proc that keep normal users from viewing device information and
49917 + slabinfo information that could be useful for exploits.
49918 +
49919 +config GRKERNSEC_LINK
49920 + bool "Linking restrictions"
49921 + help
49922 + If you say Y here, /tmp race exploits will be prevented, since users
49923 + will no longer be able to follow symlinks owned by other users in
49924 + world-writable +t directories (e.g. /tmp), unless the owner of the
49925 + symlink is the owner of the directory. users will also not be
49926 + able to hardlink to files they do not own. If the sysctl option is
49927 + enabled, a sysctl option with name "linking_restrictions" is created.
49928 +
49929 +config GRKERNSEC_FIFO
49930 + bool "FIFO restrictions"
49931 + help
49932 + If you say Y here, users will not be able to write to FIFOs they don't
49933 + own in world-writable +t directories (e.g. /tmp), unless the owner of
49934 + the FIFO is the same owner of the directory it's held in. If the sysctl
49935 + option is enabled, a sysctl option with name "fifo_restrictions" is
49936 + created.
49937 +
49938 +config GRKERNSEC_SYSFS_RESTRICT
49939 + bool "Sysfs/debugfs restriction"
49940 + depends on SYSFS
49941 + help
49942 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
49943 + any filesystem normally mounted under it (e.g. debugfs) will be
49944 + mostly accessible only by root. These filesystems generally provide access
49945 + to hardware and debug information that isn't appropriate for unprivileged
49946 + users of the system. Sysfs and debugfs have also become a large source
49947 + of new vulnerabilities, ranging from infoleaks to local compromise.
49948 + There has been very little oversight with an eye toward security involved
49949 + in adding new exporters of information to these filesystems, so their
49950 + use is discouraged.
49951 + For reasons of compatibility, a few directories have been whitelisted
49952 + for access by non-root users:
49953 + /sys/fs/selinux
49954 + /sys/fs/fuse
49955 + /sys/devices/system/cpu
49956 +
49957 +config GRKERNSEC_ROFS
49958 + bool "Runtime read-only mount protection"
49959 + help
49960 + If you say Y here, a sysctl option with name "romount_protect" will
49961 + be created. By setting this option to 1 at runtime, filesystems
49962 + will be protected in the following ways:
49963 + * No new writable mounts will be allowed
49964 + * Existing read-only mounts won't be able to be remounted read/write
49965 + * Write operations will be denied on all block devices
49966 + This option acts independently of grsec_lock: once it is set to 1,
49967 + it cannot be turned off. Therefore, please be mindful of the resulting
49968 + behavior if this option is enabled in an init script on a read-only
49969 + filesystem. This feature is mainly intended for secure embedded systems.
49970 +
49971 +config GRKERNSEC_CHROOT
49972 + bool "Chroot jail restrictions"
49973 + help
49974 + If you say Y here, you will be able to choose several options that will
49975 + make breaking out of a chrooted jail much more difficult. If you
49976 + encounter no software incompatibilities with the following options, it
49977 + is recommended that you enable each one.
49978 +
49979 +config GRKERNSEC_CHROOT_MOUNT
49980 + bool "Deny mounts"
49981 + depends on GRKERNSEC_CHROOT
49982 + help
49983 + If you say Y here, processes inside a chroot will not be able to
49984 + mount or remount filesystems. If the sysctl option is enabled, a
49985 + sysctl option with name "chroot_deny_mount" is created.
49986 +
49987 +config GRKERNSEC_CHROOT_DOUBLE
49988 + bool "Deny double-chroots"
49989 + depends on GRKERNSEC_CHROOT
49990 + help
49991 + If you say Y here, processes inside a chroot will not be able to chroot
49992 + again outside the chroot. This is a widely used method of breaking
49993 + out of a chroot jail and should not be allowed. If the sysctl
49994 + option is enabled, a sysctl option with name
49995 + "chroot_deny_chroot" is created.
49996 +
49997 +config GRKERNSEC_CHROOT_PIVOT
49998 + bool "Deny pivot_root in chroot"
49999 + depends on GRKERNSEC_CHROOT
50000 + help
50001 + If you say Y here, processes inside a chroot will not be able to use
50002 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50003 + works similar to chroot in that it changes the root filesystem. This
50004 + function could be misused in a chrooted process to attempt to break out
50005 + of the chroot, and therefore should not be allowed. If the sysctl
50006 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50007 + created.
50008 +
50009 +config GRKERNSEC_CHROOT_CHDIR
50010 + bool "Enforce chdir(\"/\") on all chroots"
50011 + depends on GRKERNSEC_CHROOT
50012 + help
50013 + If you say Y here, the current working directory of all newly-chrooted
50014 + applications will be set to the the root directory of the chroot.
50015 + The man page on chroot(2) states:
50016 + Note that this call does not change the current working
50017 + directory, so that `.' can be outside the tree rooted at
50018 + `/'. In particular, the super-user can escape from a
50019 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50020 +
50021 + It is recommended that you say Y here, since it's not known to break
50022 + any software. If the sysctl option is enabled, a sysctl option with
50023 + name "chroot_enforce_chdir" is created.
50024 +
50025 +config GRKERNSEC_CHROOT_CHMOD
50026 + bool "Deny (f)chmod +s"
50027 + depends on GRKERNSEC_CHROOT
50028 + help
50029 + If you say Y here, processes inside a chroot will not be able to chmod
50030 + or fchmod files to make them have suid or sgid bits. This protects
50031 + against another published method of breaking a chroot. If the sysctl
50032 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50033 + created.
50034 +
50035 +config GRKERNSEC_CHROOT_FCHDIR
50036 + bool "Deny fchdir out of chroot"
50037 + depends on GRKERNSEC_CHROOT
50038 + help
50039 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50040 + to a file descriptor of the chrooting process that points to a directory
50041 + outside the filesystem will be stopped. If the sysctl option
50042 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50043 +
50044 +config GRKERNSEC_CHROOT_MKNOD
50045 + bool "Deny mknod"
50046 + depends on GRKERNSEC_CHROOT
50047 + help
50048 + If you say Y here, processes inside a chroot will not be allowed to
50049 + mknod. The problem with using mknod inside a chroot is that it
50050 + would allow an attacker to create a device entry that is the same
50051 + as one on the physical root of your system, which could range from
50052 + anything from the console device to a device for your harddrive (which
50053 + they could then use to wipe the drive or steal data). It is recommended
50054 + that you say Y here, unless you run into software incompatibilities.
50055 + If the sysctl option is enabled, a sysctl option with name
50056 + "chroot_deny_mknod" is created.
50057 +
50058 +config GRKERNSEC_CHROOT_SHMAT
50059 + bool "Deny shmat() out of chroot"
50060 + depends on GRKERNSEC_CHROOT
50061 + help
50062 + If you say Y here, processes inside a chroot will not be able to attach
50063 + to shared memory segments that were created outside of the chroot jail.
50064 + It is recommended that you say Y here. If the sysctl option is enabled,
50065 + a sysctl option with name "chroot_deny_shmat" is created.
50066 +
50067 +config GRKERNSEC_CHROOT_UNIX
50068 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
50069 + depends on GRKERNSEC_CHROOT
50070 + help
50071 + If you say Y here, processes inside a chroot will not be able to
50072 + connect to abstract (meaning not belonging to a filesystem) Unix
50073 + domain sockets that were bound outside of a chroot. It is recommended
50074 + that you say Y here. If the sysctl option is enabled, a sysctl option
50075 + with name "chroot_deny_unix" is created.
50076 +
50077 +config GRKERNSEC_CHROOT_FINDTASK
50078 + bool "Protect outside processes"
50079 + depends on GRKERNSEC_CHROOT
50080 + help
50081 + If you say Y here, processes inside a chroot will not be able to
50082 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
50083 + getsid, or view any process outside of the chroot. If the sysctl
50084 + option is enabled, a sysctl option with name "chroot_findtask" is
50085 + created.
50086 +
50087 +config GRKERNSEC_CHROOT_NICE
50088 + bool "Restrict priority changes"
50089 + depends on GRKERNSEC_CHROOT
50090 + help
50091 + If you say Y here, processes inside a chroot will not be able to raise
50092 + the priority of processes in the chroot, or alter the priority of
50093 + processes outside the chroot. This provides more security than simply
50094 + removing CAP_SYS_NICE from the process' capability set. If the
50095 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
50096 + is created.
50097 +
50098 +config GRKERNSEC_CHROOT_SYSCTL
50099 + bool "Deny sysctl writes"
50100 + depends on GRKERNSEC_CHROOT
50101 + help
50102 + If you say Y here, an attacker in a chroot will not be able to
50103 + write to sysctl entries, either by sysctl(2) or through a /proc
50104 + interface. It is strongly recommended that you say Y here. If the
50105 + sysctl option is enabled, a sysctl option with name
50106 + "chroot_deny_sysctl" is created.
50107 +
50108 +config GRKERNSEC_CHROOT_CAPS
50109 + bool "Capability restrictions"
50110 + depends on GRKERNSEC_CHROOT
50111 + help
50112 + If you say Y here, the capabilities on all processes within a
50113 + chroot jail will be lowered to stop module insertion, raw i/o,
50114 + system and net admin tasks, rebooting the system, modifying immutable
50115 + files, modifying IPC owned by another, and changing the system time.
50116 + This is left an option because it can break some apps. Disable this
50117 + if your chrooted apps are having problems performing those kinds of
50118 + tasks. If the sysctl option is enabled, a sysctl option with
50119 + name "chroot_caps" is created.
50120 +
50121 +endmenu
50122 +menu "Kernel Auditing"
50123 +depends on GRKERNSEC
50124 +
50125 +config GRKERNSEC_AUDIT_GROUP
50126 + bool "Single group for auditing"
50127 + help
50128 + If you say Y here, the exec, chdir, and (un)mount logging features
50129 + will only operate on a group you specify. This option is recommended
50130 + if you only want to watch certain users instead of having a large
50131 + amount of logs from the entire system. If the sysctl option is enabled,
50132 + a sysctl option with name "audit_group" is created.
50133 +
50134 +config GRKERNSEC_AUDIT_GID
50135 + int "GID for auditing"
50136 + depends on GRKERNSEC_AUDIT_GROUP
50137 + default 1007
50138 +
50139 +config GRKERNSEC_EXECLOG
50140 + bool "Exec logging"
50141 + help
50142 + If you say Y here, all execve() calls will be logged (since the
50143 + other exec*() calls are frontends to execve(), all execution
50144 + will be logged). Useful for shell-servers that like to keep track
50145 + of their users. If the sysctl option is enabled, a sysctl option with
50146 + name "exec_logging" is created.
50147 + WARNING: This option when enabled will produce a LOT of logs, especially
50148 + on an active system.
50149 +
50150 +config GRKERNSEC_RESLOG
50151 + bool "Resource logging"
50152 + help
50153 + If you say Y here, all attempts to overstep resource limits will
50154 + be logged with the resource name, the requested size, and the current
50155 + limit. It is highly recommended that you say Y here. If the sysctl
50156 + option is enabled, a sysctl option with name "resource_logging" is
50157 + created. If the RBAC system is enabled, the sysctl value is ignored.
50158 +
50159 +config GRKERNSEC_CHROOT_EXECLOG
50160 + bool "Log execs within chroot"
50161 + help
50162 + If you say Y here, all executions inside a chroot jail will be logged
50163 + to syslog. This can cause a large amount of logs if certain
50164 + applications (eg. djb's daemontools) are installed on the system, and
50165 + is therefore left as an option. If the sysctl option is enabled, a
50166 + sysctl option with name "chroot_execlog" is created.
50167 +
50168 +config GRKERNSEC_AUDIT_PTRACE
50169 + bool "Ptrace logging"
50170 + help
50171 + If you say Y here, all attempts to attach to a process via ptrace
50172 + will be logged. If the sysctl option is enabled, a sysctl option
50173 + with name "audit_ptrace" is created.
50174 +
50175 +config GRKERNSEC_AUDIT_CHDIR
50176 + bool "Chdir logging"
50177 + help
50178 + If you say Y here, all chdir() calls will be logged. If the sysctl
50179 + option is enabled, a sysctl option with name "audit_chdir" is created.
50180 +
50181 +config GRKERNSEC_AUDIT_MOUNT
50182 + bool "(Un)Mount logging"
50183 + help
50184 + If you say Y here, all mounts and unmounts will be logged. If the
50185 + sysctl option is enabled, a sysctl option with name "audit_mount" is
50186 + created.
50187 +
50188 +config GRKERNSEC_SIGNAL
50189 + bool "Signal logging"
50190 + help
50191 + If you say Y here, certain important signals will be logged, such as
50192 + SIGSEGV, which will as a result inform you of when a error in a program
50193 + occurred, which in some cases could mean a possible exploit attempt.
50194 + If the sysctl option is enabled, a sysctl option with name
50195 + "signal_logging" is created.
50196 +
50197 +config GRKERNSEC_FORKFAIL
50198 + bool "Fork failure logging"
50199 + help
50200 + If you say Y here, all failed fork() attempts will be logged.
50201 + This could suggest a fork bomb, or someone attempting to overstep
50202 + their process limit. If the sysctl option is enabled, a sysctl option
50203 + with name "forkfail_logging" is created.
50204 +
50205 +config GRKERNSEC_TIME
50206 + bool "Time change logging"
50207 + help
50208 + If you say Y here, any changes of the system clock will be logged.
50209 + If the sysctl option is enabled, a sysctl option with name
50210 + "timechange_logging" is created.
50211 +
50212 +config GRKERNSEC_PROC_IPADDR
50213 + bool "/proc/<pid>/ipaddr support"
50214 + help
50215 + If you say Y here, a new entry will be added to each /proc/<pid>
50216 + directory that contains the IP address of the person using the task.
50217 + The IP is carried across local TCP and AF_UNIX stream sockets.
50218 + This information can be useful for IDS/IPSes to perform remote response
50219 + to a local attack. The entry is readable by only the owner of the
50220 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
50221 + the RBAC system), and thus does not create privacy concerns.
50222 +
50223 +config GRKERNSEC_RWXMAP_LOG
50224 + bool 'Denied RWX mmap/mprotect logging'
50225 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
50226 + help
50227 + If you say Y here, calls to mmap() and mprotect() with explicit
50228 + usage of PROT_WRITE and PROT_EXEC together will be logged when
50229 + denied by the PAX_MPROTECT feature. If the sysctl option is
50230 + enabled, a sysctl option with name "rwxmap_logging" is created.
50231 +
50232 +config GRKERNSEC_AUDIT_TEXTREL
50233 + bool 'ELF text relocations logging (READ HELP)'
50234 + depends on PAX_MPROTECT
50235 + help
50236 + If you say Y here, text relocations will be logged with the filename
50237 + of the offending library or binary. The purpose of the feature is
50238 + to help Linux distribution developers get rid of libraries and
50239 + binaries that need text relocations which hinder the future progress
50240 + of PaX. Only Linux distribution developers should say Y here, and
50241 + never on a production machine, as this option creates an information
50242 + leak that could aid an attacker in defeating the randomization of
50243 + a single memory region. If the sysctl option is enabled, a sysctl
50244 + option with name "audit_textrel" is created.
50245 +
50246 +endmenu
50247 +
50248 +menu "Executable Protections"
50249 +depends on GRKERNSEC
50250 +
50251 +config GRKERNSEC_DMESG
50252 + bool "Dmesg(8) restriction"
50253 + help
50254 + If you say Y here, non-root users will not be able to use dmesg(8)
50255 + to view up to the last 4kb of messages in the kernel's log buffer.
50256 + The kernel's log buffer often contains kernel addresses and other
50257 + identifying information useful to an attacker in fingerprinting a
50258 + system for a targeted exploit.
50259 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
50260 + created.
50261 +
50262 +config GRKERNSEC_HARDEN_PTRACE
50263 + bool "Deter ptrace-based process snooping"
50264 + help
50265 + If you say Y here, TTY sniffers and other malicious monitoring
50266 + programs implemented through ptrace will be defeated. If you
50267 + have been using the RBAC system, this option has already been
50268 + enabled for several years for all users, with the ability to make
50269 + fine-grained exceptions.
50270 +
50271 + This option only affects the ability of non-root users to ptrace
50272 + processes that are not a descendent of the ptracing process.
50273 + This means that strace ./binary and gdb ./binary will still work,
50274 + but attaching to arbitrary processes will not. If the sysctl
50275 + option is enabled, a sysctl option with name "harden_ptrace" is
50276 + created.
50277 +
50278 +config GRKERNSEC_PTRACE_READEXEC
50279 + bool "Require read access to ptrace sensitive binaries"
50280 + help
50281 + If you say Y here, unprivileged users will not be able to ptrace unreadable
50282 + binaries. This option is useful in environments that
50283 + remove the read bits (e.g. file mode 4711) from suid binaries to
50284 + prevent infoleaking of their contents. This option adds
50285 + consistency to the use of that file mode, as the binary could normally
50286 + be read out when run without privileges while ptracing.
50287 +
50288 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
50289 + is created.
50290 +
50291 +config GRKERNSEC_SETXID
50292 + bool "Enforce consistent multithreaded privileges"
50293 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
50294 + help
50295 + If you say Y here, a change from a root uid to a non-root uid
50296 + in a multithreaded application will cause the resulting uids,
50297 + gids, supplementary groups, and capabilities in that thread
50298 + to be propagated to the other threads of the process. In most
50299 + cases this is unnecessary, as glibc will emulate this behavior
50300 + on behalf of the application. Other libcs do not act in the
50301 + same way, allowing the other threads of the process to continue
50302 + running with root privileges. If the sysctl option is enabled,
50303 + a sysctl option with name "consistent_setxid" is created.
50304 +
50305 +config GRKERNSEC_TPE
50306 + bool "Trusted Path Execution (TPE)"
50307 + help
50308 + If you say Y here, you will be able to choose a gid to add to the
50309 + supplementary groups of users you want to mark as "untrusted."
50310 + These users will not be able to execute any files that are not in
50311 + root-owned directories writable only by root. If the sysctl option
50312 + is enabled, a sysctl option with name "tpe" is created.
50313 +
50314 +config GRKERNSEC_TPE_ALL
50315 + bool "Partially restrict all non-root users"
50316 + depends on GRKERNSEC_TPE
50317 + help
50318 + If you say Y here, all non-root users will be covered under
50319 + a weaker TPE restriction. This is separate from, and in addition to,
50320 + the main TPE options that you have selected elsewhere. Thus, if a
50321 + "trusted" GID is chosen, this restriction applies to even that GID.
50322 + Under this restriction, all non-root users will only be allowed to
50323 + execute files in directories they own that are not group or
50324 + world-writable, or in directories owned by root and writable only by
50325 + root. If the sysctl option is enabled, a sysctl option with name
50326 + "tpe_restrict_all" is created.
50327 +
50328 +config GRKERNSEC_TPE_INVERT
50329 + bool "Invert GID option"
50330 + depends on GRKERNSEC_TPE
50331 + help
50332 + If you say Y here, the group you specify in the TPE configuration will
50333 + decide what group TPE restrictions will be *disabled* for. This
50334 + option is useful if you want TPE restrictions to be applied to most
50335 + users on the system. If the sysctl option is enabled, a sysctl option
50336 + with name "tpe_invert" is created. Unlike other sysctl options, this
50337 + entry will default to on for backward-compatibility.
50338 +
50339 +config GRKERNSEC_TPE_GID
50340 + int "GID for untrusted users"
50341 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
50342 + default 1005
50343 + help
50344 + Setting this GID determines what group TPE restrictions will be
50345 + *enabled* for. If the sysctl option is enabled, a sysctl option
50346 + with name "tpe_gid" is created.
50347 +
50348 +config GRKERNSEC_TPE_GID
50349 + int "GID for trusted users"
50350 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
50351 + default 1005
50352 + help
50353 + Setting this GID determines what group TPE restrictions will be
50354 + *disabled* for. If the sysctl option is enabled, a sysctl option
50355 + with name "tpe_gid" is created.
50356 +
50357 +endmenu
50358 +menu "Network Protections"
50359 +depends on GRKERNSEC
50360 +
50361 +config GRKERNSEC_RANDNET
50362 + bool "Larger entropy pools"
50363 + help
50364 + If you say Y here, the entropy pools used for many features of Linux
50365 + and grsecurity will be doubled in size. Since several grsecurity
50366 + features use additional randomness, it is recommended that you say Y
50367 + here. Saying Y here has a similar effect as modifying
50368 + /proc/sys/kernel/random/poolsize.
50369 +
50370 +config GRKERNSEC_BLACKHOLE
50371 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
50372 + depends on NET
50373 + help
50374 + If you say Y here, neither TCP resets nor ICMP
50375 + destination-unreachable packets will be sent in response to packets
50376 + sent to ports for which no associated listening process exists.
50377 + This feature supports both IPV4 and IPV6 and exempts the
50378 + loopback interface from blackholing. Enabling this feature
50379 + makes a host more resilient to DoS attacks and reduces network
50380 + visibility against scanners.
50381 +
50382 + The blackhole feature as-implemented is equivalent to the FreeBSD
50383 + blackhole feature, as it prevents RST responses to all packets, not
50384 + just SYNs. Under most application behavior this causes no
50385 + problems, but applications (like haproxy) may not close certain
50386 + connections in a way that cleanly terminates them on the remote
50387 + end, leaving the remote host in LAST_ACK state. Because of this
50388 + side-effect and to prevent intentional LAST_ACK DoSes, this
50389 + feature also adds automatic mitigation against such attacks.
50390 + The mitigation drastically reduces the amount of time a socket
50391 + can spend in LAST_ACK state. If you're using haproxy and not
50392 + all servers it connects to have this option enabled, consider
50393 + disabling this feature on the haproxy host.
50394 +
50395 + If the sysctl option is enabled, two sysctl options with names
50396 + "ip_blackhole" and "lastack_retries" will be created.
50397 + While "ip_blackhole" takes the standard zero/non-zero on/off
50398 + toggle, "lastack_retries" uses the same kinds of values as
50399 + "tcp_retries1" and "tcp_retries2". The default value of 4
50400 + prevents a socket from lasting more than 45 seconds in LAST_ACK
50401 + state.
50402 +
50403 +config GRKERNSEC_SOCKET
50404 + bool "Socket restrictions"
50405 + depends on NET
50406 + help
50407 + If you say Y here, you will be able to choose from several options.
50408 + If you assign a GID on your system and add it to the supplementary
50409 + groups of users you want to restrict socket access to, this patch
50410 + will perform up to three things, based on the option(s) you choose.
50411 +
50412 +config GRKERNSEC_SOCKET_ALL
50413 + bool "Deny any sockets to group"
50414 + depends on GRKERNSEC_SOCKET
50415 + help
50416 + If you say Y here, you will be able to choose a GID of whose users will
50417 + be unable to connect to other hosts from your machine or run server
50418 + applications from your machine. If the sysctl option is enabled, a
50419 + sysctl option with name "socket_all" is created.
50420 +
50421 +config GRKERNSEC_SOCKET_ALL_GID
50422 + int "GID to deny all sockets for"
50423 + depends on GRKERNSEC_SOCKET_ALL
50424 + default 1004
50425 + help
50426 + Here you can choose the GID to disable socket access for. Remember to
50427 + add the users you want socket access disabled for to the GID
50428 + specified here. If the sysctl option is enabled, a sysctl option
50429 + with name "socket_all_gid" is created.
50430 +
50431 +config GRKERNSEC_SOCKET_CLIENT
50432 + bool "Deny client sockets to group"
50433 + depends on GRKERNSEC_SOCKET
50434 + help
50435 + If you say Y here, you will be able to choose a GID of whose users will
50436 + be unable to connect to other hosts from your machine, but will be
50437 + able to run servers. If this option is enabled, all users in the group
50438 + you specify will have to use passive mode when initiating ftp transfers
50439 + from the shell on your machine. If the sysctl option is enabled, a
50440 + sysctl option with name "socket_client" is created.
50441 +
50442 +config GRKERNSEC_SOCKET_CLIENT_GID
50443 + int "GID to deny client sockets for"
50444 + depends on GRKERNSEC_SOCKET_CLIENT
50445 + default 1003
50446 + help
50447 + Here you can choose the GID to disable client socket access for.
50448 + Remember to add the users you want client socket access disabled for to
50449 + the GID specified here. If the sysctl option is enabled, a sysctl
50450 + option with name "socket_client_gid" is created.
50451 +
50452 +config GRKERNSEC_SOCKET_SERVER
50453 + bool "Deny server sockets to group"
50454 + depends on GRKERNSEC_SOCKET
50455 + help
50456 + If you say Y here, you will be able to choose a GID of whose users will
50457 + be unable to run server applications from your machine. If the sysctl
50458 + option is enabled, a sysctl option with name "socket_server" is created.
50459 +
50460 +config GRKERNSEC_SOCKET_SERVER_GID
50461 + int "GID to deny server sockets for"
50462 + depends on GRKERNSEC_SOCKET_SERVER
50463 + default 1002
50464 + help
50465 + Here you can choose the GID to disable server socket access for.
50466 + Remember to add the users you want server socket access disabled for to
50467 + the GID specified here. If the sysctl option is enabled, a sysctl
50468 + option with name "socket_server_gid" is created.
50469 +
50470 +endmenu
50471 +menu "Sysctl support"
50472 +depends on GRKERNSEC && SYSCTL
50473 +
50474 +config GRKERNSEC_SYSCTL
50475 + bool "Sysctl support"
50476 + help
50477 + If you say Y here, you will be able to change the options that
50478 + grsecurity runs with at bootup, without having to recompile your
50479 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
50480 + to enable (1) or disable (0) various features. All the sysctl entries
50481 + are mutable until the "grsec_lock" entry is set to a non-zero value.
50482 + All features enabled in the kernel configuration are disabled at boot
50483 + if you do not say Y to the "Turn on features by default" option.
50484 + All options should be set at startup, and the grsec_lock entry should
50485 + be set to a non-zero value after all the options are set.
50486 + *THIS IS EXTREMELY IMPORTANT*
50487 +
50488 +config GRKERNSEC_SYSCTL_DISTRO
50489 + bool "Extra sysctl support for distro makers (READ HELP)"
50490 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
50491 + help
50492 + If you say Y here, additional sysctl options will be created
50493 + for features that affect processes running as root. Therefore,
50494 + it is critical when using this option that the grsec_lock entry be
50495 + enabled after boot. Only distros with prebuilt kernel packages
50496 + with this option enabled that can ensure grsec_lock is enabled
50497 + after boot should use this option.
50498 + *Failure to set grsec_lock after boot makes all grsec features
50499 + this option covers useless*
50500 +
50501 + Currently this option creates the following sysctl entries:
50502 + "Disable Privileged I/O": "disable_priv_io"
50503 +
50504 +config GRKERNSEC_SYSCTL_ON
50505 + bool "Turn on features by default"
50506 + depends on GRKERNSEC_SYSCTL
50507 + help
50508 + If you say Y here, instead of having all features enabled in the
50509 + kernel configuration disabled at boot time, the features will be
50510 + enabled at boot time. It is recommended you say Y here unless
50511 + there is some reason you would want all sysctl-tunable features to
50512 + be disabled by default. As mentioned elsewhere, it is important
50513 + to enable the grsec_lock entry once you have finished modifying
50514 + the sysctl entries.
50515 +
50516 +endmenu
50517 +menu "Logging Options"
50518 +depends on GRKERNSEC
50519 +
50520 +config GRKERNSEC_FLOODTIME
50521 + int "Seconds in between log messages (minimum)"
50522 + default 10
50523 + help
50524 + This option allows you to enforce the number of seconds between
50525 + grsecurity log messages. The default should be suitable for most
50526 + people, however, if you choose to change it, choose a value small enough
50527 + to allow informative logs to be produced, but large enough to
50528 + prevent flooding.
50529 +
50530 +config GRKERNSEC_FLOODBURST
50531 + int "Number of messages in a burst (maximum)"
50532 + default 6
50533 + help
50534 + This option allows you to choose the maximum number of messages allowed
50535 + within the flood time interval you chose in a separate option. The
50536 + default should be suitable for most people, however if you find that
50537 + many of your logs are being interpreted as flooding, you may want to
50538 + raise this value.
50539 +
50540 +endmenu
50541 +
50542 +endmenu
50543 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
50544 new file mode 100644
50545 index 0000000..1b9afa9
50546 --- /dev/null
50547 +++ b/grsecurity/Makefile
50548 @@ -0,0 +1,38 @@
50549 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
50550 +# during 2001-2009 it has been completely redesigned by Brad Spengler
50551 +# into an RBAC system
50552 +#
50553 +# All code in this directory and various hooks inserted throughout the kernel
50554 +# are copyright Brad Spengler - Open Source Security, Inc., and released
50555 +# under the GPL v2 or higher
50556 +
50557 +KBUILD_CFLAGS += -Werror
50558 +
50559 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
50560 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
50561 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
50562 +
50563 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
50564 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
50565 + gracl_learn.o grsec_log.o
50566 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
50567 +
50568 +ifdef CONFIG_NET
50569 +obj-y += grsec_sock.o
50570 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
50571 +endif
50572 +
50573 +ifndef CONFIG_GRKERNSEC
50574 +obj-y += grsec_disabled.o
50575 +endif
50576 +
50577 +ifdef CONFIG_GRKERNSEC_HIDESYM
50578 +extra-y := grsec_hidesym.o
50579 +$(obj)/grsec_hidesym.o:
50580 + @-chmod -f 500 /boot
50581 + @-chmod -f 500 /lib/modules
50582 + @-chmod -f 500 /lib64/modules
50583 + @-chmod -f 500 /lib32/modules
50584 + @-chmod -f 700 .
50585 + @echo ' grsec: protected kernel image paths'
50586 +endif
50587 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
50588 new file mode 100644
50589 index 0000000..a6d83f0
50590 --- /dev/null
50591 +++ b/grsecurity/gracl.c
50592 @@ -0,0 +1,4193 @@
50593 +#include <linux/kernel.h>
50594 +#include <linux/module.h>
50595 +#include <linux/sched.h>
50596 +#include <linux/mm.h>
50597 +#include <linux/file.h>
50598 +#include <linux/fs.h>
50599 +#include <linux/namei.h>
50600 +#include <linux/mount.h>
50601 +#include <linux/tty.h>
50602 +#include <linux/proc_fs.h>
50603 +#include <linux/lglock.h>
50604 +#include <linux/slab.h>
50605 +#include <linux/vmalloc.h>
50606 +#include <linux/types.h>
50607 +#include <linux/sysctl.h>
50608 +#include <linux/netdevice.h>
50609 +#include <linux/ptrace.h>
50610 +#include <linux/gracl.h>
50611 +#include <linux/gralloc.h>
50612 +#include <linux/security.h>
50613 +#include <linux/grinternal.h>
50614 +#include <linux/pid_namespace.h>
50615 +#include <linux/fdtable.h>
50616 +#include <linux/percpu.h>
50617 +#include "../fs/mount.h"
50618 +
50619 +#include <asm/uaccess.h>
50620 +#include <asm/errno.h>
50621 +#include <asm/mman.h>
50622 +
50623 +static struct acl_role_db acl_role_set;
50624 +static struct name_db name_set;
50625 +static struct inodev_db inodev_set;
50626 +
50627 +/* for keeping track of userspace pointers used for subjects, so we
50628 + can share references in the kernel as well
50629 +*/
50630 +
50631 +static struct path real_root;
50632 +
50633 +static struct acl_subj_map_db subj_map_set;
50634 +
50635 +static struct acl_role_label *default_role;
50636 +
50637 +static struct acl_role_label *role_list;
50638 +
50639 +static u16 acl_sp_role_value;
50640 +
50641 +extern char *gr_shared_page[4];
50642 +static DEFINE_MUTEX(gr_dev_mutex);
50643 +DEFINE_RWLOCK(gr_inode_lock);
50644 +
50645 +struct gr_arg *gr_usermode;
50646 +
50647 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
50648 +
50649 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
50650 +extern void gr_clear_learn_entries(void);
50651 +
50652 +#ifdef CONFIG_GRKERNSEC_RESLOG
50653 +extern void gr_log_resource(const struct task_struct *task,
50654 + const int res, const unsigned long wanted, const int gt);
50655 +#endif
50656 +
50657 +unsigned char *gr_system_salt;
50658 +unsigned char *gr_system_sum;
50659 +
50660 +static struct sprole_pw **acl_special_roles = NULL;
50661 +static __u16 num_sprole_pws = 0;
50662 +
50663 +static struct acl_role_label *kernel_role = NULL;
50664 +
50665 +static unsigned int gr_auth_attempts = 0;
50666 +static unsigned long gr_auth_expires = 0UL;
50667 +
50668 +#ifdef CONFIG_NET
50669 +extern struct vfsmount *sock_mnt;
50670 +#endif
50671 +
50672 +extern struct vfsmount *pipe_mnt;
50673 +extern struct vfsmount *shm_mnt;
50674 +#ifdef CONFIG_HUGETLBFS
50675 +extern struct vfsmount *hugetlbfs_vfsmount;
50676 +#endif
50677 +
50678 +static struct acl_object_label *fakefs_obj_rw;
50679 +static struct acl_object_label *fakefs_obj_rwx;
50680 +
50681 +extern int gr_init_uidset(void);
50682 +extern void gr_free_uidset(void);
50683 +extern void gr_remove_uid(uid_t uid);
50684 +extern int gr_find_uid(uid_t uid);
50685 +
50686 +DECLARE_BRLOCK(vfsmount_lock);
50687 +
50688 +__inline__ int
50689 +gr_acl_is_enabled(void)
50690 +{
50691 + return (gr_status & GR_READY);
50692 +}
50693 +
50694 +#ifdef CONFIG_BTRFS_FS
50695 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
50696 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
50697 +#endif
50698 +
50699 +static inline dev_t __get_dev(const struct dentry *dentry)
50700 +{
50701 +#ifdef CONFIG_BTRFS_FS
50702 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
50703 + return get_btrfs_dev_from_inode(dentry->d_inode);
50704 + else
50705 +#endif
50706 + return dentry->d_inode->i_sb->s_dev;
50707 +}
50708 +
50709 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
50710 +{
50711 + return __get_dev(dentry);
50712 +}
50713 +
50714 +static char gr_task_roletype_to_char(struct task_struct *task)
50715 +{
50716 + switch (task->role->roletype &
50717 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
50718 + GR_ROLE_SPECIAL)) {
50719 + case GR_ROLE_DEFAULT:
50720 + return 'D';
50721 + case GR_ROLE_USER:
50722 + return 'U';
50723 + case GR_ROLE_GROUP:
50724 + return 'G';
50725 + case GR_ROLE_SPECIAL:
50726 + return 'S';
50727 + }
50728 +
50729 + return 'X';
50730 +}
50731 +
50732 +char gr_roletype_to_char(void)
50733 +{
50734 + return gr_task_roletype_to_char(current);
50735 +}
50736 +
50737 +__inline__ int
50738 +gr_acl_tpe_check(void)
50739 +{
50740 + if (unlikely(!(gr_status & GR_READY)))
50741 + return 0;
50742 + if (current->role->roletype & GR_ROLE_TPE)
50743 + return 1;
50744 + else
50745 + return 0;
50746 +}
50747 +
50748 +int
50749 +gr_handle_rawio(const struct inode *inode)
50750 +{
50751 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
50752 + if (inode && S_ISBLK(inode->i_mode) &&
50753 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
50754 + !capable(CAP_SYS_RAWIO))
50755 + return 1;
50756 +#endif
50757 + return 0;
50758 +}
50759 +
50760 +static int
50761 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
50762 +{
50763 + if (likely(lena != lenb))
50764 + return 0;
50765 +
50766 + return !memcmp(a, b, lena);
50767 +}
50768 +
50769 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
50770 +{
50771 + *buflen -= namelen;
50772 + if (*buflen < 0)
50773 + return -ENAMETOOLONG;
50774 + *buffer -= namelen;
50775 + memcpy(*buffer, str, namelen);
50776 + return 0;
50777 +}
50778 +
50779 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
50780 +{
50781 + return prepend(buffer, buflen, name->name, name->len);
50782 +}
50783 +
50784 +static int prepend_path(const struct path *path, struct path *root,
50785 + char **buffer, int *buflen)
50786 +{
50787 + struct dentry *dentry = path->dentry;
50788 + struct vfsmount *vfsmnt = path->mnt;
50789 + struct mount *mnt = real_mount(vfsmnt);
50790 + bool slash = false;
50791 + int error = 0;
50792 +
50793 + while (dentry != root->dentry || vfsmnt != root->mnt) {
50794 + struct dentry * parent;
50795 +
50796 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
50797 + /* Global root? */
50798 + if (!mnt_has_parent(mnt)) {
50799 + goto out;
50800 + }
50801 + dentry = mnt->mnt_mountpoint;
50802 + mnt = mnt->mnt_parent;
50803 + vfsmnt = &mnt->mnt;
50804 + continue;
50805 + }
50806 + parent = dentry->d_parent;
50807 + prefetch(parent);
50808 + spin_lock(&dentry->d_lock);
50809 + error = prepend_name(buffer, buflen, &dentry->d_name);
50810 + spin_unlock(&dentry->d_lock);
50811 + if (!error)
50812 + error = prepend(buffer, buflen, "/", 1);
50813 + if (error)
50814 + break;
50815 +
50816 + slash = true;
50817 + dentry = parent;
50818 + }
50819 +
50820 +out:
50821 + if (!error && !slash)
50822 + error = prepend(buffer, buflen, "/", 1);
50823 +
50824 + return error;
50825 +}
50826 +
50827 +/* this must be called with vfsmount_lock and rename_lock held */
50828 +
50829 +static char *__our_d_path(const struct path *path, struct path *root,
50830 + char *buf, int buflen)
50831 +{
50832 + char *res = buf + buflen;
50833 + int error;
50834 +
50835 + prepend(&res, &buflen, "\0", 1);
50836 + error = prepend_path(path, root, &res, &buflen);
50837 + if (error)
50838 + return ERR_PTR(error);
50839 +
50840 + return res;
50841 +}
50842 +
50843 +static char *
50844 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
50845 +{
50846 + char *retval;
50847 +
50848 + retval = __our_d_path(path, root, buf, buflen);
50849 + if (unlikely(IS_ERR(retval)))
50850 + retval = strcpy(buf, "<path too long>");
50851 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
50852 + retval[1] = '\0';
50853 +
50854 + return retval;
50855 +}
50856 +
50857 +static char *
50858 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50859 + char *buf, int buflen)
50860 +{
50861 + struct path path;
50862 + char *res;
50863 +
50864 + path.dentry = (struct dentry *)dentry;
50865 + path.mnt = (struct vfsmount *)vfsmnt;
50866 +
50867 + /* we can use real_root.dentry, real_root.mnt, because this is only called
50868 + by the RBAC system */
50869 + res = gen_full_path(&path, &real_root, buf, buflen);
50870 +
50871 + return res;
50872 +}
50873 +
50874 +static char *
50875 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
50876 + char *buf, int buflen)
50877 +{
50878 + char *res;
50879 + struct path path;
50880 + struct path root;
50881 + struct task_struct *reaper = &init_task;
50882 +
50883 + path.dentry = (struct dentry *)dentry;
50884 + path.mnt = (struct vfsmount *)vfsmnt;
50885 +
50886 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
50887 + get_fs_root(reaper->fs, &root);
50888 +
50889 + write_seqlock(&rename_lock);
50890 + br_read_lock(vfsmount_lock);
50891 + res = gen_full_path(&path, &root, buf, buflen);
50892 + br_read_unlock(vfsmount_lock);
50893 + write_sequnlock(&rename_lock);
50894 +
50895 + path_put(&root);
50896 + return res;
50897 +}
50898 +
50899 +static char *
50900 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50901 +{
50902 + char *ret;
50903 + write_seqlock(&rename_lock);
50904 + br_read_lock(vfsmount_lock);
50905 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50906 + PAGE_SIZE);
50907 + br_read_unlock(vfsmount_lock);
50908 + write_sequnlock(&rename_lock);
50909 + return ret;
50910 +}
50911 +
50912 +static char *
50913 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
50914 +{
50915 + char *ret;
50916 + char *buf;
50917 + int buflen;
50918 +
50919 + write_seqlock(&rename_lock);
50920 + br_read_lock(vfsmount_lock);
50921 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
50922 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
50923 + buflen = (int)(ret - buf);
50924 + if (buflen >= 5)
50925 + prepend(&ret, &buflen, "/proc", 5);
50926 + else
50927 + ret = strcpy(buf, "<path too long>");
50928 + br_read_unlock(vfsmount_lock);
50929 + write_sequnlock(&rename_lock);
50930 + return ret;
50931 +}
50932 +
50933 +char *
50934 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
50935 +{
50936 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
50937 + PAGE_SIZE);
50938 +}
50939 +
50940 +char *
50941 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
50942 +{
50943 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
50944 + PAGE_SIZE);
50945 +}
50946 +
50947 +char *
50948 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
50949 +{
50950 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
50951 + PAGE_SIZE);
50952 +}
50953 +
50954 +char *
50955 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
50956 +{
50957 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
50958 + PAGE_SIZE);
50959 +}
50960 +
50961 +char *
50962 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
50963 +{
50964 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
50965 + PAGE_SIZE);
50966 +}
50967 +
50968 +__inline__ __u32
50969 +to_gr_audit(const __u32 reqmode)
50970 +{
50971 + /* masks off auditable permission flags, then shifts them to create
50972 + auditing flags, and adds the special case of append auditing if
50973 + we're requesting write */
50974 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
50975 +}
50976 +
50977 +struct acl_subject_label *
50978 +lookup_subject_map(const struct acl_subject_label *userp)
50979 +{
50980 + unsigned int index = shash(userp, subj_map_set.s_size);
50981 + struct subject_map *match;
50982 +
50983 + match = subj_map_set.s_hash[index];
50984 +
50985 + while (match && match->user != userp)
50986 + match = match->next;
50987 +
50988 + if (match != NULL)
50989 + return match->kernel;
50990 + else
50991 + return NULL;
50992 +}
50993 +
50994 +static void
50995 +insert_subj_map_entry(struct subject_map *subjmap)
50996 +{
50997 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
50998 + struct subject_map **curr;
50999 +
51000 + subjmap->prev = NULL;
51001 +
51002 + curr = &subj_map_set.s_hash[index];
51003 + if (*curr != NULL)
51004 + (*curr)->prev = subjmap;
51005 +
51006 + subjmap->next = *curr;
51007 + *curr = subjmap;
51008 +
51009 + return;
51010 +}
51011 +
51012 +static struct acl_role_label *
51013 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51014 + const gid_t gid)
51015 +{
51016 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51017 + struct acl_role_label *match;
51018 + struct role_allowed_ip *ipp;
51019 + unsigned int x;
51020 + u32 curr_ip = task->signal->curr_ip;
51021 +
51022 + task->signal->saved_ip = curr_ip;
51023 +
51024 + match = acl_role_set.r_hash[index];
51025 +
51026 + while (match) {
51027 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51028 + for (x = 0; x < match->domain_child_num; x++) {
51029 + if (match->domain_children[x] == uid)
51030 + goto found;
51031 + }
51032 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51033 + break;
51034 + match = match->next;
51035 + }
51036 +found:
51037 + if (match == NULL) {
51038 + try_group:
51039 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
51040 + match = acl_role_set.r_hash[index];
51041 +
51042 + while (match) {
51043 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
51044 + for (x = 0; x < match->domain_child_num; x++) {
51045 + if (match->domain_children[x] == gid)
51046 + goto found2;
51047 + }
51048 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
51049 + break;
51050 + match = match->next;
51051 + }
51052 +found2:
51053 + if (match == NULL)
51054 + match = default_role;
51055 + if (match->allowed_ips == NULL)
51056 + return match;
51057 + else {
51058 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51059 + if (likely
51060 + ((ntohl(curr_ip) & ipp->netmask) ==
51061 + (ntohl(ipp->addr) & ipp->netmask)))
51062 + return match;
51063 + }
51064 + match = default_role;
51065 + }
51066 + } else if (match->allowed_ips == NULL) {
51067 + return match;
51068 + } else {
51069 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
51070 + if (likely
51071 + ((ntohl(curr_ip) & ipp->netmask) ==
51072 + (ntohl(ipp->addr) & ipp->netmask)))
51073 + return match;
51074 + }
51075 + goto try_group;
51076 + }
51077 +
51078 + return match;
51079 +}
51080 +
51081 +struct acl_subject_label *
51082 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
51083 + const struct acl_role_label *role)
51084 +{
51085 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51086 + struct acl_subject_label *match;
51087 +
51088 + match = role->subj_hash[index];
51089 +
51090 + while (match && (match->inode != ino || match->device != dev ||
51091 + (match->mode & GR_DELETED))) {
51092 + match = match->next;
51093 + }
51094 +
51095 + if (match && !(match->mode & GR_DELETED))
51096 + return match;
51097 + else
51098 + return NULL;
51099 +}
51100 +
51101 +struct acl_subject_label *
51102 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
51103 + const struct acl_role_label *role)
51104 +{
51105 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
51106 + struct acl_subject_label *match;
51107 +
51108 + match = role->subj_hash[index];
51109 +
51110 + while (match && (match->inode != ino || match->device != dev ||
51111 + !(match->mode & GR_DELETED))) {
51112 + match = match->next;
51113 + }
51114 +
51115 + if (match && (match->mode & GR_DELETED))
51116 + return match;
51117 + else
51118 + return NULL;
51119 +}
51120 +
51121 +static struct acl_object_label *
51122 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
51123 + const struct acl_subject_label *subj)
51124 +{
51125 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51126 + struct acl_object_label *match;
51127 +
51128 + match = subj->obj_hash[index];
51129 +
51130 + while (match && (match->inode != ino || match->device != dev ||
51131 + (match->mode & GR_DELETED))) {
51132 + match = match->next;
51133 + }
51134 +
51135 + if (match && !(match->mode & GR_DELETED))
51136 + return match;
51137 + else
51138 + return NULL;
51139 +}
51140 +
51141 +static struct acl_object_label *
51142 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
51143 + const struct acl_subject_label *subj)
51144 +{
51145 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
51146 + struct acl_object_label *match;
51147 +
51148 + match = subj->obj_hash[index];
51149 +
51150 + while (match && (match->inode != ino || match->device != dev ||
51151 + !(match->mode & GR_DELETED))) {
51152 + match = match->next;
51153 + }
51154 +
51155 + if (match && (match->mode & GR_DELETED))
51156 + return match;
51157 +
51158 + match = subj->obj_hash[index];
51159 +
51160 + while (match && (match->inode != ino || match->device != dev ||
51161 + (match->mode & GR_DELETED))) {
51162 + match = match->next;
51163 + }
51164 +
51165 + if (match && !(match->mode & GR_DELETED))
51166 + return match;
51167 + else
51168 + return NULL;
51169 +}
51170 +
51171 +static struct name_entry *
51172 +lookup_name_entry(const char *name)
51173 +{
51174 + unsigned int len = strlen(name);
51175 + unsigned int key = full_name_hash(name, len);
51176 + unsigned int index = key % name_set.n_size;
51177 + struct name_entry *match;
51178 +
51179 + match = name_set.n_hash[index];
51180 +
51181 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
51182 + match = match->next;
51183 +
51184 + return match;
51185 +}
51186 +
51187 +static struct name_entry *
51188 +lookup_name_entry_create(const char *name)
51189 +{
51190 + unsigned int len = strlen(name);
51191 + unsigned int key = full_name_hash(name, len);
51192 + unsigned int index = key % name_set.n_size;
51193 + struct name_entry *match;
51194 +
51195 + match = name_set.n_hash[index];
51196 +
51197 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51198 + !match->deleted))
51199 + match = match->next;
51200 +
51201 + if (match && match->deleted)
51202 + return match;
51203 +
51204 + match = name_set.n_hash[index];
51205 +
51206 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
51207 + match->deleted))
51208 + match = match->next;
51209 +
51210 + if (match && !match->deleted)
51211 + return match;
51212 + else
51213 + return NULL;
51214 +}
51215 +
51216 +static struct inodev_entry *
51217 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
51218 +{
51219 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
51220 + struct inodev_entry *match;
51221 +
51222 + match = inodev_set.i_hash[index];
51223 +
51224 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
51225 + match = match->next;
51226 +
51227 + return match;
51228 +}
51229 +
51230 +static void
51231 +insert_inodev_entry(struct inodev_entry *entry)
51232 +{
51233 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
51234 + inodev_set.i_size);
51235 + struct inodev_entry **curr;
51236 +
51237 + entry->prev = NULL;
51238 +
51239 + curr = &inodev_set.i_hash[index];
51240 + if (*curr != NULL)
51241 + (*curr)->prev = entry;
51242 +
51243 + entry->next = *curr;
51244 + *curr = entry;
51245 +
51246 + return;
51247 +}
51248 +
51249 +static void
51250 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
51251 +{
51252 + unsigned int index =
51253 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
51254 + struct acl_role_label **curr;
51255 + struct acl_role_label *tmp, *tmp2;
51256 +
51257 + curr = &acl_role_set.r_hash[index];
51258 +
51259 + /* simple case, slot is empty, just set it to our role */
51260 + if (*curr == NULL) {
51261 + *curr = role;
51262 + } else {
51263 + /* example:
51264 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
51265 + 2 -> 3
51266 + */
51267 + /* first check to see if we can already be reached via this slot */
51268 + tmp = *curr;
51269 + while (tmp && tmp != role)
51270 + tmp = tmp->next;
51271 + if (tmp == role) {
51272 + /* we don't need to add ourselves to this slot's chain */
51273 + return;
51274 + }
51275 + /* we need to add ourselves to this chain, two cases */
51276 + if (role->next == NULL) {
51277 + /* simple case, append the current chain to our role */
51278 + role->next = *curr;
51279 + *curr = role;
51280 + } else {
51281 + /* 1 -> 2 -> 3 -> 4
51282 + 2 -> 3 -> 4
51283 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
51284 + */
51285 + /* trickier case: walk our role's chain until we find
51286 + the role for the start of the current slot's chain */
51287 + tmp = role;
51288 + tmp2 = *curr;
51289 + while (tmp->next && tmp->next != tmp2)
51290 + tmp = tmp->next;
51291 + if (tmp->next == tmp2) {
51292 + /* from example above, we found 3, so just
51293 + replace this slot's chain with ours */
51294 + *curr = role;
51295 + } else {
51296 + /* we didn't find a subset of our role's chain
51297 + in the current slot's chain, so append their
51298 + chain to ours, and set us as the first role in
51299 + the slot's chain
51300 +
51301 + we could fold this case with the case above,
51302 + but making it explicit for clarity
51303 + */
51304 + tmp->next = tmp2;
51305 + *curr = role;
51306 + }
51307 + }
51308 + }
51309 +
51310 + return;
51311 +}
51312 +
51313 +static void
51314 +insert_acl_role_label(struct acl_role_label *role)
51315 +{
51316 + int i;
51317 +
51318 + if (role_list == NULL) {
51319 + role_list = role;
51320 + role->prev = NULL;
51321 + } else {
51322 + role->prev = role_list;
51323 + role_list = role;
51324 + }
51325 +
51326 + /* used for hash chains */
51327 + role->next = NULL;
51328 +
51329 + if (role->roletype & GR_ROLE_DOMAIN) {
51330 + for (i = 0; i < role->domain_child_num; i++)
51331 + __insert_acl_role_label(role, role->domain_children[i]);
51332 + } else
51333 + __insert_acl_role_label(role, role->uidgid);
51334 +}
51335 +
51336 +static int
51337 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
51338 +{
51339 + struct name_entry **curr, *nentry;
51340 + struct inodev_entry *ientry;
51341 + unsigned int len = strlen(name);
51342 + unsigned int key = full_name_hash(name, len);
51343 + unsigned int index = key % name_set.n_size;
51344 +
51345 + curr = &name_set.n_hash[index];
51346 +
51347 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
51348 + curr = &((*curr)->next);
51349 +
51350 + if (*curr != NULL)
51351 + return 1;
51352 +
51353 + nentry = acl_alloc(sizeof (struct name_entry));
51354 + if (nentry == NULL)
51355 + return 0;
51356 + ientry = acl_alloc(sizeof (struct inodev_entry));
51357 + if (ientry == NULL)
51358 + return 0;
51359 + ientry->nentry = nentry;
51360 +
51361 + nentry->key = key;
51362 + nentry->name = name;
51363 + nentry->inode = inode;
51364 + nentry->device = device;
51365 + nentry->len = len;
51366 + nentry->deleted = deleted;
51367 +
51368 + nentry->prev = NULL;
51369 + curr = &name_set.n_hash[index];
51370 + if (*curr != NULL)
51371 + (*curr)->prev = nentry;
51372 + nentry->next = *curr;
51373 + *curr = nentry;
51374 +
51375 + /* insert us into the table searchable by inode/dev */
51376 + insert_inodev_entry(ientry);
51377 +
51378 + return 1;
51379 +}
51380 +
51381 +static void
51382 +insert_acl_obj_label(struct acl_object_label *obj,
51383 + struct acl_subject_label *subj)
51384 +{
51385 + unsigned int index =
51386 + fhash(obj->inode, obj->device, subj->obj_hash_size);
51387 + struct acl_object_label **curr;
51388 +
51389 +
51390 + obj->prev = NULL;
51391 +
51392 + curr = &subj->obj_hash[index];
51393 + if (*curr != NULL)
51394 + (*curr)->prev = obj;
51395 +
51396 + obj->next = *curr;
51397 + *curr = obj;
51398 +
51399 + return;
51400 +}
51401 +
51402 +static void
51403 +insert_acl_subj_label(struct acl_subject_label *obj,
51404 + struct acl_role_label *role)
51405 +{
51406 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
51407 + struct acl_subject_label **curr;
51408 +
51409 + obj->prev = NULL;
51410 +
51411 + curr = &role->subj_hash[index];
51412 + if (*curr != NULL)
51413 + (*curr)->prev = obj;
51414 +
51415 + obj->next = *curr;
51416 + *curr = obj;
51417 +
51418 + return;
51419 +}
51420 +
51421 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
51422 +
51423 +static void *
51424 +create_table(__u32 * len, int elementsize)
51425 +{
51426 + unsigned int table_sizes[] = {
51427 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
51428 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
51429 + 4194301, 8388593, 16777213, 33554393, 67108859
51430 + };
51431 + void *newtable = NULL;
51432 + unsigned int pwr = 0;
51433 +
51434 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
51435 + table_sizes[pwr] <= *len)
51436 + pwr++;
51437 +
51438 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
51439 + return newtable;
51440 +
51441 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
51442 + newtable =
51443 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
51444 + else
51445 + newtable = vmalloc(table_sizes[pwr] * elementsize);
51446 +
51447 + *len = table_sizes[pwr];
51448 +
51449 + return newtable;
51450 +}
51451 +
51452 +static int
51453 +init_variables(const struct gr_arg *arg)
51454 +{
51455 + struct task_struct *reaper = &init_task;
51456 + unsigned int stacksize;
51457 +
51458 + subj_map_set.s_size = arg->role_db.num_subjects;
51459 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
51460 + name_set.n_size = arg->role_db.num_objects;
51461 + inodev_set.i_size = arg->role_db.num_objects;
51462 +
51463 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
51464 + !name_set.n_size || !inodev_set.i_size)
51465 + return 1;
51466 +
51467 + if (!gr_init_uidset())
51468 + return 1;
51469 +
51470 + /* set up the stack that holds allocation info */
51471 +
51472 + stacksize = arg->role_db.num_pointers + 5;
51473 +
51474 + if (!acl_alloc_stack_init(stacksize))
51475 + return 1;
51476 +
51477 + /* grab reference for the real root dentry and vfsmount */
51478 + get_fs_root(reaper->fs, &real_root);
51479 +
51480 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51481 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
51482 +#endif
51483 +
51484 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
51485 + if (fakefs_obj_rw == NULL)
51486 + return 1;
51487 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
51488 +
51489 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
51490 + if (fakefs_obj_rwx == NULL)
51491 + return 1;
51492 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
51493 +
51494 + subj_map_set.s_hash =
51495 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
51496 + acl_role_set.r_hash =
51497 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
51498 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
51499 + inodev_set.i_hash =
51500 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
51501 +
51502 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
51503 + !name_set.n_hash || !inodev_set.i_hash)
51504 + return 1;
51505 +
51506 + memset(subj_map_set.s_hash, 0,
51507 + sizeof(struct subject_map *) * subj_map_set.s_size);
51508 + memset(acl_role_set.r_hash, 0,
51509 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
51510 + memset(name_set.n_hash, 0,
51511 + sizeof (struct name_entry *) * name_set.n_size);
51512 + memset(inodev_set.i_hash, 0,
51513 + sizeof (struct inodev_entry *) * inodev_set.i_size);
51514 +
51515 + return 0;
51516 +}
51517 +
51518 +/* free information not needed after startup
51519 + currently contains user->kernel pointer mappings for subjects
51520 +*/
51521 +
51522 +static void
51523 +free_init_variables(void)
51524 +{
51525 + __u32 i;
51526 +
51527 + if (subj_map_set.s_hash) {
51528 + for (i = 0; i < subj_map_set.s_size; i++) {
51529 + if (subj_map_set.s_hash[i]) {
51530 + kfree(subj_map_set.s_hash[i]);
51531 + subj_map_set.s_hash[i] = NULL;
51532 + }
51533 + }
51534 +
51535 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
51536 + PAGE_SIZE)
51537 + kfree(subj_map_set.s_hash);
51538 + else
51539 + vfree(subj_map_set.s_hash);
51540 + }
51541 +
51542 + return;
51543 +}
51544 +
51545 +static void
51546 +free_variables(void)
51547 +{
51548 + struct acl_subject_label *s;
51549 + struct acl_role_label *r;
51550 + struct task_struct *task, *task2;
51551 + unsigned int x;
51552 +
51553 + gr_clear_learn_entries();
51554 +
51555 + read_lock(&tasklist_lock);
51556 + do_each_thread(task2, task) {
51557 + task->acl_sp_role = 0;
51558 + task->acl_role_id = 0;
51559 + task->acl = NULL;
51560 + task->role = NULL;
51561 + } while_each_thread(task2, task);
51562 + read_unlock(&tasklist_lock);
51563 +
51564 + /* release the reference to the real root dentry and vfsmount */
51565 + path_put(&real_root);
51566 + memset(&real_root, 0, sizeof(real_root));
51567 +
51568 + /* free all object hash tables */
51569 +
51570 + FOR_EACH_ROLE_START(r)
51571 + if (r->subj_hash == NULL)
51572 + goto next_role;
51573 + FOR_EACH_SUBJECT_START(r, s, x)
51574 + if (s->obj_hash == NULL)
51575 + break;
51576 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51577 + kfree(s->obj_hash);
51578 + else
51579 + vfree(s->obj_hash);
51580 + FOR_EACH_SUBJECT_END(s, x)
51581 + FOR_EACH_NESTED_SUBJECT_START(r, s)
51582 + if (s->obj_hash == NULL)
51583 + break;
51584 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
51585 + kfree(s->obj_hash);
51586 + else
51587 + vfree(s->obj_hash);
51588 + FOR_EACH_NESTED_SUBJECT_END(s)
51589 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
51590 + kfree(r->subj_hash);
51591 + else
51592 + vfree(r->subj_hash);
51593 + r->subj_hash = NULL;
51594 +next_role:
51595 + FOR_EACH_ROLE_END(r)
51596 +
51597 + acl_free_all();
51598 +
51599 + if (acl_role_set.r_hash) {
51600 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
51601 + PAGE_SIZE)
51602 + kfree(acl_role_set.r_hash);
51603 + else
51604 + vfree(acl_role_set.r_hash);
51605 + }
51606 + if (name_set.n_hash) {
51607 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
51608 + PAGE_SIZE)
51609 + kfree(name_set.n_hash);
51610 + else
51611 + vfree(name_set.n_hash);
51612 + }
51613 +
51614 + if (inodev_set.i_hash) {
51615 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
51616 + PAGE_SIZE)
51617 + kfree(inodev_set.i_hash);
51618 + else
51619 + vfree(inodev_set.i_hash);
51620 + }
51621 +
51622 + gr_free_uidset();
51623 +
51624 + memset(&name_set, 0, sizeof (struct name_db));
51625 + memset(&inodev_set, 0, sizeof (struct inodev_db));
51626 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
51627 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
51628 +
51629 + default_role = NULL;
51630 + kernel_role = NULL;
51631 + role_list = NULL;
51632 +
51633 + return;
51634 +}
51635 +
51636 +static __u32
51637 +count_user_objs(struct acl_object_label *userp)
51638 +{
51639 + struct acl_object_label o_tmp;
51640 + __u32 num = 0;
51641 +
51642 + while (userp) {
51643 + if (copy_from_user(&o_tmp, userp,
51644 + sizeof (struct acl_object_label)))
51645 + break;
51646 +
51647 + userp = o_tmp.prev;
51648 + num++;
51649 + }
51650 +
51651 + return num;
51652 +}
51653 +
51654 +static struct acl_subject_label *
51655 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
51656 +
51657 +static int
51658 +copy_user_glob(struct acl_object_label *obj)
51659 +{
51660 + struct acl_object_label *g_tmp, **guser;
51661 + unsigned int len;
51662 + char *tmp;
51663 +
51664 + if (obj->globbed == NULL)
51665 + return 0;
51666 +
51667 + guser = &obj->globbed;
51668 + while (*guser) {
51669 + g_tmp = (struct acl_object_label *)
51670 + acl_alloc(sizeof (struct acl_object_label));
51671 + if (g_tmp == NULL)
51672 + return -ENOMEM;
51673 +
51674 + if (copy_from_user(g_tmp, *guser,
51675 + sizeof (struct acl_object_label)))
51676 + return -EFAULT;
51677 +
51678 + len = strnlen_user(g_tmp->filename, PATH_MAX);
51679 +
51680 + if (!len || len >= PATH_MAX)
51681 + return -EINVAL;
51682 +
51683 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51684 + return -ENOMEM;
51685 +
51686 + if (copy_from_user(tmp, g_tmp->filename, len))
51687 + return -EFAULT;
51688 + tmp[len-1] = '\0';
51689 + g_tmp->filename = tmp;
51690 +
51691 + *guser = g_tmp;
51692 + guser = &(g_tmp->next);
51693 + }
51694 +
51695 + return 0;
51696 +}
51697 +
51698 +static int
51699 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
51700 + struct acl_role_label *role)
51701 +{
51702 + struct acl_object_label *o_tmp;
51703 + unsigned int len;
51704 + int ret;
51705 + char *tmp;
51706 +
51707 + while (userp) {
51708 + if ((o_tmp = (struct acl_object_label *)
51709 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
51710 + return -ENOMEM;
51711 +
51712 + if (copy_from_user(o_tmp, userp,
51713 + sizeof (struct acl_object_label)))
51714 + return -EFAULT;
51715 +
51716 + userp = o_tmp->prev;
51717 +
51718 + len = strnlen_user(o_tmp->filename, PATH_MAX);
51719 +
51720 + if (!len || len >= PATH_MAX)
51721 + return -EINVAL;
51722 +
51723 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51724 + return -ENOMEM;
51725 +
51726 + if (copy_from_user(tmp, o_tmp->filename, len))
51727 + return -EFAULT;
51728 + tmp[len-1] = '\0';
51729 + o_tmp->filename = tmp;
51730 +
51731 + insert_acl_obj_label(o_tmp, subj);
51732 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
51733 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
51734 + return -ENOMEM;
51735 +
51736 + ret = copy_user_glob(o_tmp);
51737 + if (ret)
51738 + return ret;
51739 +
51740 + if (o_tmp->nested) {
51741 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
51742 + if (IS_ERR(o_tmp->nested))
51743 + return PTR_ERR(o_tmp->nested);
51744 +
51745 + /* insert into nested subject list */
51746 + o_tmp->nested->next = role->hash->first;
51747 + role->hash->first = o_tmp->nested;
51748 + }
51749 + }
51750 +
51751 + return 0;
51752 +}
51753 +
51754 +static __u32
51755 +count_user_subjs(struct acl_subject_label *userp)
51756 +{
51757 + struct acl_subject_label s_tmp;
51758 + __u32 num = 0;
51759 +
51760 + while (userp) {
51761 + if (copy_from_user(&s_tmp, userp,
51762 + sizeof (struct acl_subject_label)))
51763 + break;
51764 +
51765 + userp = s_tmp.prev;
51766 + /* do not count nested subjects against this count, since
51767 + they are not included in the hash table, but are
51768 + attached to objects. We have already counted
51769 + the subjects in userspace for the allocation
51770 + stack
51771 + */
51772 + if (!(s_tmp.mode & GR_NESTED))
51773 + num++;
51774 + }
51775 +
51776 + return num;
51777 +}
51778 +
51779 +static int
51780 +copy_user_allowedips(struct acl_role_label *rolep)
51781 +{
51782 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
51783 +
51784 + ruserip = rolep->allowed_ips;
51785 +
51786 + while (ruserip) {
51787 + rlast = rtmp;
51788 +
51789 + if ((rtmp = (struct role_allowed_ip *)
51790 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
51791 + return -ENOMEM;
51792 +
51793 + if (copy_from_user(rtmp, ruserip,
51794 + sizeof (struct role_allowed_ip)))
51795 + return -EFAULT;
51796 +
51797 + ruserip = rtmp->prev;
51798 +
51799 + if (!rlast) {
51800 + rtmp->prev = NULL;
51801 + rolep->allowed_ips = rtmp;
51802 + } else {
51803 + rlast->next = rtmp;
51804 + rtmp->prev = rlast;
51805 + }
51806 +
51807 + if (!ruserip)
51808 + rtmp->next = NULL;
51809 + }
51810 +
51811 + return 0;
51812 +}
51813 +
51814 +static int
51815 +copy_user_transitions(struct acl_role_label *rolep)
51816 +{
51817 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
51818 +
51819 + unsigned int len;
51820 + char *tmp;
51821 +
51822 + rusertp = rolep->transitions;
51823 +
51824 + while (rusertp) {
51825 + rlast = rtmp;
51826 +
51827 + if ((rtmp = (struct role_transition *)
51828 + acl_alloc(sizeof (struct role_transition))) == NULL)
51829 + return -ENOMEM;
51830 +
51831 + if (copy_from_user(rtmp, rusertp,
51832 + sizeof (struct role_transition)))
51833 + return -EFAULT;
51834 +
51835 + rusertp = rtmp->prev;
51836 +
51837 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
51838 +
51839 + if (!len || len >= GR_SPROLE_LEN)
51840 + return -EINVAL;
51841 +
51842 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51843 + return -ENOMEM;
51844 +
51845 + if (copy_from_user(tmp, rtmp->rolename, len))
51846 + return -EFAULT;
51847 + tmp[len-1] = '\0';
51848 + rtmp->rolename = tmp;
51849 +
51850 + if (!rlast) {
51851 + rtmp->prev = NULL;
51852 + rolep->transitions = rtmp;
51853 + } else {
51854 + rlast->next = rtmp;
51855 + rtmp->prev = rlast;
51856 + }
51857 +
51858 + if (!rusertp)
51859 + rtmp->next = NULL;
51860 + }
51861 +
51862 + return 0;
51863 +}
51864 +
51865 +static struct acl_subject_label *
51866 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
51867 +{
51868 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
51869 + unsigned int len;
51870 + char *tmp;
51871 + __u32 num_objs;
51872 + struct acl_ip_label **i_tmp, *i_utmp2;
51873 + struct gr_hash_struct ghash;
51874 + struct subject_map *subjmap;
51875 + unsigned int i_num;
51876 + int err;
51877 +
51878 + s_tmp = lookup_subject_map(userp);
51879 +
51880 + /* we've already copied this subject into the kernel, just return
51881 + the reference to it, and don't copy it over again
51882 + */
51883 + if (s_tmp)
51884 + return(s_tmp);
51885 +
51886 + if ((s_tmp = (struct acl_subject_label *)
51887 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
51888 + return ERR_PTR(-ENOMEM);
51889 +
51890 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
51891 + if (subjmap == NULL)
51892 + return ERR_PTR(-ENOMEM);
51893 +
51894 + subjmap->user = userp;
51895 + subjmap->kernel = s_tmp;
51896 + insert_subj_map_entry(subjmap);
51897 +
51898 + if (copy_from_user(s_tmp, userp,
51899 + sizeof (struct acl_subject_label)))
51900 + return ERR_PTR(-EFAULT);
51901 +
51902 + len = strnlen_user(s_tmp->filename, PATH_MAX);
51903 +
51904 + if (!len || len >= PATH_MAX)
51905 + return ERR_PTR(-EINVAL);
51906 +
51907 + if ((tmp = (char *) acl_alloc(len)) == NULL)
51908 + return ERR_PTR(-ENOMEM);
51909 +
51910 + if (copy_from_user(tmp, s_tmp->filename, len))
51911 + return ERR_PTR(-EFAULT);
51912 + tmp[len-1] = '\0';
51913 + s_tmp->filename = tmp;
51914 +
51915 + if (!strcmp(s_tmp->filename, "/"))
51916 + role->root_label = s_tmp;
51917 +
51918 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
51919 + return ERR_PTR(-EFAULT);
51920 +
51921 + /* copy user and group transition tables */
51922 +
51923 + if (s_tmp->user_trans_num) {
51924 + uid_t *uidlist;
51925 +
51926 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
51927 + if (uidlist == NULL)
51928 + return ERR_PTR(-ENOMEM);
51929 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
51930 + return ERR_PTR(-EFAULT);
51931 +
51932 + s_tmp->user_transitions = uidlist;
51933 + }
51934 +
51935 + if (s_tmp->group_trans_num) {
51936 + gid_t *gidlist;
51937 +
51938 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
51939 + if (gidlist == NULL)
51940 + return ERR_PTR(-ENOMEM);
51941 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
51942 + return ERR_PTR(-EFAULT);
51943 +
51944 + s_tmp->group_transitions = gidlist;
51945 + }
51946 +
51947 + /* set up object hash table */
51948 + num_objs = count_user_objs(ghash.first);
51949 +
51950 + s_tmp->obj_hash_size = num_objs;
51951 + s_tmp->obj_hash =
51952 + (struct acl_object_label **)
51953 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
51954 +
51955 + if (!s_tmp->obj_hash)
51956 + return ERR_PTR(-ENOMEM);
51957 +
51958 + memset(s_tmp->obj_hash, 0,
51959 + s_tmp->obj_hash_size *
51960 + sizeof (struct acl_object_label *));
51961 +
51962 + /* add in objects */
51963 + err = copy_user_objs(ghash.first, s_tmp, role);
51964 +
51965 + if (err)
51966 + return ERR_PTR(err);
51967 +
51968 + /* set pointer for parent subject */
51969 + if (s_tmp->parent_subject) {
51970 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
51971 +
51972 + if (IS_ERR(s_tmp2))
51973 + return s_tmp2;
51974 +
51975 + s_tmp->parent_subject = s_tmp2;
51976 + }
51977 +
51978 + /* add in ip acls */
51979 +
51980 + if (!s_tmp->ip_num) {
51981 + s_tmp->ips = NULL;
51982 + goto insert;
51983 + }
51984 +
51985 + i_tmp =
51986 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
51987 + sizeof (struct acl_ip_label *));
51988 +
51989 + if (!i_tmp)
51990 + return ERR_PTR(-ENOMEM);
51991 +
51992 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
51993 + *(i_tmp + i_num) =
51994 + (struct acl_ip_label *)
51995 + acl_alloc(sizeof (struct acl_ip_label));
51996 + if (!*(i_tmp + i_num))
51997 + return ERR_PTR(-ENOMEM);
51998 +
51999 + if (copy_from_user
52000 + (&i_utmp2, s_tmp->ips + i_num,
52001 + sizeof (struct acl_ip_label *)))
52002 + return ERR_PTR(-EFAULT);
52003 +
52004 + if (copy_from_user
52005 + (*(i_tmp + i_num), i_utmp2,
52006 + sizeof (struct acl_ip_label)))
52007 + return ERR_PTR(-EFAULT);
52008 +
52009 + if ((*(i_tmp + i_num))->iface == NULL)
52010 + continue;
52011 +
52012 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52013 + if (!len || len >= IFNAMSIZ)
52014 + return ERR_PTR(-EINVAL);
52015 + tmp = acl_alloc(len);
52016 + if (tmp == NULL)
52017 + return ERR_PTR(-ENOMEM);
52018 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52019 + return ERR_PTR(-EFAULT);
52020 + (*(i_tmp + i_num))->iface = tmp;
52021 + }
52022 +
52023 + s_tmp->ips = i_tmp;
52024 +
52025 +insert:
52026 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52027 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52028 + return ERR_PTR(-ENOMEM);
52029 +
52030 + return s_tmp;
52031 +}
52032 +
52033 +static int
52034 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52035 +{
52036 + struct acl_subject_label s_pre;
52037 + struct acl_subject_label * ret;
52038 + int err;
52039 +
52040 + while (userp) {
52041 + if (copy_from_user(&s_pre, userp,
52042 + sizeof (struct acl_subject_label)))
52043 + return -EFAULT;
52044 +
52045 + /* do not add nested subjects here, add
52046 + while parsing objects
52047 + */
52048 +
52049 + if (s_pre.mode & GR_NESTED) {
52050 + userp = s_pre.prev;
52051 + continue;
52052 + }
52053 +
52054 + ret = do_copy_user_subj(userp, role);
52055 +
52056 + err = PTR_ERR(ret);
52057 + if (IS_ERR(ret))
52058 + return err;
52059 +
52060 + insert_acl_subj_label(ret, role);
52061 +
52062 + userp = s_pre.prev;
52063 + }
52064 +
52065 + return 0;
52066 +}
52067 +
52068 +static int
52069 +copy_user_acl(struct gr_arg *arg)
52070 +{
52071 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
52072 + struct sprole_pw *sptmp;
52073 + struct gr_hash_struct *ghash;
52074 + uid_t *domainlist;
52075 + unsigned int r_num;
52076 + unsigned int len;
52077 + char *tmp;
52078 + int err = 0;
52079 + __u16 i;
52080 + __u32 num_subjs;
52081 +
52082 + /* we need a default and kernel role */
52083 + if (arg->role_db.num_roles < 2)
52084 + return -EINVAL;
52085 +
52086 + /* copy special role authentication info from userspace */
52087 +
52088 + num_sprole_pws = arg->num_sprole_pws;
52089 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
52090 +
52091 + if (!acl_special_roles && num_sprole_pws)
52092 + return -ENOMEM;
52093 +
52094 + for (i = 0; i < num_sprole_pws; i++) {
52095 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
52096 + if (!sptmp)
52097 + return -ENOMEM;
52098 + if (copy_from_user(sptmp, arg->sprole_pws + i,
52099 + sizeof (struct sprole_pw)))
52100 + return -EFAULT;
52101 +
52102 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
52103 +
52104 + if (!len || len >= GR_SPROLE_LEN)
52105 + return -EINVAL;
52106 +
52107 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52108 + return -ENOMEM;
52109 +
52110 + if (copy_from_user(tmp, sptmp->rolename, len))
52111 + return -EFAULT;
52112 +
52113 + tmp[len-1] = '\0';
52114 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52115 + printk(KERN_ALERT "Copying special role %s\n", tmp);
52116 +#endif
52117 + sptmp->rolename = tmp;
52118 + acl_special_roles[i] = sptmp;
52119 + }
52120 +
52121 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
52122 +
52123 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
52124 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
52125 +
52126 + if (!r_tmp)
52127 + return -ENOMEM;
52128 +
52129 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
52130 + sizeof (struct acl_role_label *)))
52131 + return -EFAULT;
52132 +
52133 + if (copy_from_user(r_tmp, r_utmp2,
52134 + sizeof (struct acl_role_label)))
52135 + return -EFAULT;
52136 +
52137 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
52138 +
52139 + if (!len || len >= PATH_MAX)
52140 + return -EINVAL;
52141 +
52142 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52143 + return -ENOMEM;
52144 +
52145 + if (copy_from_user(tmp, r_tmp->rolename, len))
52146 + return -EFAULT;
52147 +
52148 + tmp[len-1] = '\0';
52149 + r_tmp->rolename = tmp;
52150 +
52151 + if (!strcmp(r_tmp->rolename, "default")
52152 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
52153 + default_role = r_tmp;
52154 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
52155 + kernel_role = r_tmp;
52156 + }
52157 +
52158 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
52159 + return -ENOMEM;
52160 +
52161 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
52162 + return -EFAULT;
52163 +
52164 + r_tmp->hash = ghash;
52165 +
52166 + num_subjs = count_user_subjs(r_tmp->hash->first);
52167 +
52168 + r_tmp->subj_hash_size = num_subjs;
52169 + r_tmp->subj_hash =
52170 + (struct acl_subject_label **)
52171 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
52172 +
52173 + if (!r_tmp->subj_hash)
52174 + return -ENOMEM;
52175 +
52176 + err = copy_user_allowedips(r_tmp);
52177 + if (err)
52178 + return err;
52179 +
52180 + /* copy domain info */
52181 + if (r_tmp->domain_children != NULL) {
52182 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
52183 + if (domainlist == NULL)
52184 + return -ENOMEM;
52185 +
52186 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
52187 + return -EFAULT;
52188 +
52189 + r_tmp->domain_children = domainlist;
52190 + }
52191 +
52192 + err = copy_user_transitions(r_tmp);
52193 + if (err)
52194 + return err;
52195 +
52196 + memset(r_tmp->subj_hash, 0,
52197 + r_tmp->subj_hash_size *
52198 + sizeof (struct acl_subject_label *));
52199 +
52200 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
52201 +
52202 + if (err)
52203 + return err;
52204 +
52205 + /* set nested subject list to null */
52206 + r_tmp->hash->first = NULL;
52207 +
52208 + insert_acl_role_label(r_tmp);
52209 + }
52210 +
52211 + if (default_role == NULL || kernel_role == NULL)
52212 + return -EINVAL;
52213 +
52214 + return err;
52215 +}
52216 +
52217 +static int
52218 +gracl_init(struct gr_arg *args)
52219 +{
52220 + int error = 0;
52221 +
52222 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
52223 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
52224 +
52225 + if (init_variables(args)) {
52226 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
52227 + error = -ENOMEM;
52228 + free_variables();
52229 + goto out;
52230 + }
52231 +
52232 + error = copy_user_acl(args);
52233 + free_init_variables();
52234 + if (error) {
52235 + free_variables();
52236 + goto out;
52237 + }
52238 +
52239 + if ((error = gr_set_acls(0))) {
52240 + free_variables();
52241 + goto out;
52242 + }
52243 +
52244 + pax_open_kernel();
52245 + gr_status |= GR_READY;
52246 + pax_close_kernel();
52247 +
52248 + out:
52249 + return error;
52250 +}
52251 +
52252 +/* derived from glibc fnmatch() 0: match, 1: no match*/
52253 +
52254 +static int
52255 +glob_match(const char *p, const char *n)
52256 +{
52257 + char c;
52258 +
52259 + while ((c = *p++) != '\0') {
52260 + switch (c) {
52261 + case '?':
52262 + if (*n == '\0')
52263 + return 1;
52264 + else if (*n == '/')
52265 + return 1;
52266 + break;
52267 + case '\\':
52268 + if (*n != c)
52269 + return 1;
52270 + break;
52271 + case '*':
52272 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
52273 + if (*n == '/')
52274 + return 1;
52275 + else if (c == '?') {
52276 + if (*n == '\0')
52277 + return 1;
52278 + else
52279 + ++n;
52280 + }
52281 + }
52282 + if (c == '\0') {
52283 + return 0;
52284 + } else {
52285 + const char *endp;
52286 +
52287 + if ((endp = strchr(n, '/')) == NULL)
52288 + endp = n + strlen(n);
52289 +
52290 + if (c == '[') {
52291 + for (--p; n < endp; ++n)
52292 + if (!glob_match(p, n))
52293 + return 0;
52294 + } else if (c == '/') {
52295 + while (*n != '\0' && *n != '/')
52296 + ++n;
52297 + if (*n == '/' && !glob_match(p, n + 1))
52298 + return 0;
52299 + } else {
52300 + for (--p; n < endp; ++n)
52301 + if (*n == c && !glob_match(p, n))
52302 + return 0;
52303 + }
52304 +
52305 + return 1;
52306 + }
52307 + case '[':
52308 + {
52309 + int not;
52310 + char cold;
52311 +
52312 + if (*n == '\0' || *n == '/')
52313 + return 1;
52314 +
52315 + not = (*p == '!' || *p == '^');
52316 + if (not)
52317 + ++p;
52318 +
52319 + c = *p++;
52320 + for (;;) {
52321 + unsigned char fn = (unsigned char)*n;
52322 +
52323 + if (c == '\0')
52324 + return 1;
52325 + else {
52326 + if (c == fn)
52327 + goto matched;
52328 + cold = c;
52329 + c = *p++;
52330 +
52331 + if (c == '-' && *p != ']') {
52332 + unsigned char cend = *p++;
52333 +
52334 + if (cend == '\0')
52335 + return 1;
52336 +
52337 + if (cold <= fn && fn <= cend)
52338 + goto matched;
52339 +
52340 + c = *p++;
52341 + }
52342 + }
52343 +
52344 + if (c == ']')
52345 + break;
52346 + }
52347 + if (!not)
52348 + return 1;
52349 + break;
52350 + matched:
52351 + while (c != ']') {
52352 + if (c == '\0')
52353 + return 1;
52354 +
52355 + c = *p++;
52356 + }
52357 + if (not)
52358 + return 1;
52359 + }
52360 + break;
52361 + default:
52362 + if (c != *n)
52363 + return 1;
52364 + }
52365 +
52366 + ++n;
52367 + }
52368 +
52369 + if (*n == '\0')
52370 + return 0;
52371 +
52372 + if (*n == '/')
52373 + return 0;
52374 +
52375 + return 1;
52376 +}
52377 +
52378 +static struct acl_object_label *
52379 +chk_glob_label(struct acl_object_label *globbed,
52380 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
52381 +{
52382 + struct acl_object_label *tmp;
52383 +
52384 + if (*path == NULL)
52385 + *path = gr_to_filename_nolock(dentry, mnt);
52386 +
52387 + tmp = globbed;
52388 +
52389 + while (tmp) {
52390 + if (!glob_match(tmp->filename, *path))
52391 + return tmp;
52392 + tmp = tmp->next;
52393 + }
52394 +
52395 + return NULL;
52396 +}
52397 +
52398 +static struct acl_object_label *
52399 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52400 + const ino_t curr_ino, const dev_t curr_dev,
52401 + const struct acl_subject_label *subj, char **path, const int checkglob)
52402 +{
52403 + struct acl_subject_label *tmpsubj;
52404 + struct acl_object_label *retval;
52405 + struct acl_object_label *retval2;
52406 +
52407 + tmpsubj = (struct acl_subject_label *) subj;
52408 + read_lock(&gr_inode_lock);
52409 + do {
52410 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
52411 + if (retval) {
52412 + if (checkglob && retval->globbed) {
52413 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
52414 + if (retval2)
52415 + retval = retval2;
52416 + }
52417 + break;
52418 + }
52419 + } while ((tmpsubj = tmpsubj->parent_subject));
52420 + read_unlock(&gr_inode_lock);
52421 +
52422 + return retval;
52423 +}
52424 +
52425 +static __inline__ struct acl_object_label *
52426 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
52427 + struct dentry *curr_dentry,
52428 + const struct acl_subject_label *subj, char **path, const int checkglob)
52429 +{
52430 + int newglob = checkglob;
52431 + ino_t inode;
52432 + dev_t device;
52433 +
52434 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
52435 + as we don't want a / * rule to match instead of the / object
52436 + don't do this for create lookups that call this function though, since they're looking up
52437 + on the parent and thus need globbing checks on all paths
52438 + */
52439 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
52440 + newglob = GR_NO_GLOB;
52441 +
52442 + spin_lock(&curr_dentry->d_lock);
52443 + inode = curr_dentry->d_inode->i_ino;
52444 + device = __get_dev(curr_dentry);
52445 + spin_unlock(&curr_dentry->d_lock);
52446 +
52447 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
52448 +}
52449 +
52450 +static struct acl_object_label *
52451 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52452 + const struct acl_subject_label *subj, char *path, const int checkglob)
52453 +{
52454 + struct dentry *dentry = (struct dentry *) l_dentry;
52455 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52456 + struct mount *real_mnt = real_mount(mnt);
52457 + struct acl_object_label *retval;
52458 + struct dentry *parent;
52459 +
52460 + write_seqlock(&rename_lock);
52461 + br_read_lock(vfsmount_lock);
52462 +
52463 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
52464 +#ifdef CONFIG_NET
52465 + mnt == sock_mnt ||
52466 +#endif
52467 +#ifdef CONFIG_HUGETLBFS
52468 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
52469 +#endif
52470 + /* ignore Eric Biederman */
52471 + IS_PRIVATE(l_dentry->d_inode))) {
52472 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
52473 + goto out;
52474 + }
52475 +
52476 + for (;;) {
52477 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52478 + break;
52479 +
52480 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52481 + if (!mnt_has_parent(real_mnt))
52482 + break;
52483 +
52484 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52485 + if (retval != NULL)
52486 + goto out;
52487 +
52488 + dentry = real_mnt->mnt_mountpoint;
52489 + real_mnt = real_mnt->mnt_parent;
52490 + mnt = &real_mnt->mnt;
52491 + continue;
52492 + }
52493 +
52494 + parent = dentry->d_parent;
52495 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52496 + if (retval != NULL)
52497 + goto out;
52498 +
52499 + dentry = parent;
52500 + }
52501 +
52502 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
52503 +
52504 + /* real_root is pinned so we don't have to hold a reference */
52505 + if (retval == NULL)
52506 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
52507 +out:
52508 + br_read_unlock(vfsmount_lock);
52509 + write_sequnlock(&rename_lock);
52510 +
52511 + BUG_ON(retval == NULL);
52512 +
52513 + return retval;
52514 +}
52515 +
52516 +static __inline__ struct acl_object_label *
52517 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52518 + const struct acl_subject_label *subj)
52519 +{
52520 + char *path = NULL;
52521 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
52522 +}
52523 +
52524 +static __inline__ struct acl_object_label *
52525 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52526 + const struct acl_subject_label *subj)
52527 +{
52528 + char *path = NULL;
52529 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
52530 +}
52531 +
52532 +static __inline__ struct acl_object_label *
52533 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52534 + const struct acl_subject_label *subj, char *path)
52535 +{
52536 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
52537 +}
52538 +
52539 +static struct acl_subject_label *
52540 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
52541 + const struct acl_role_label *role)
52542 +{
52543 + struct dentry *dentry = (struct dentry *) l_dentry;
52544 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
52545 + struct mount *real_mnt = real_mount(mnt);
52546 + struct acl_subject_label *retval;
52547 + struct dentry *parent;
52548 +
52549 + write_seqlock(&rename_lock);
52550 + br_read_lock(vfsmount_lock);
52551 +
52552 + for (;;) {
52553 + if (dentry == real_root.dentry && mnt == real_root.mnt)
52554 + break;
52555 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
52556 + if (!mnt_has_parent(real_mnt))
52557 + break;
52558 +
52559 + spin_lock(&dentry->d_lock);
52560 + read_lock(&gr_inode_lock);
52561 + retval =
52562 + lookup_acl_subj_label(dentry->d_inode->i_ino,
52563 + __get_dev(dentry), role);
52564 + read_unlock(&gr_inode_lock);
52565 + spin_unlock(&dentry->d_lock);
52566 + if (retval != NULL)
52567 + goto out;
52568 +
52569 + dentry = real_mnt->mnt_mountpoint;
52570 + real_mnt = real_mnt->mnt_parent;
52571 + mnt = &real_mnt->mnt;
52572 + continue;
52573 + }
52574 +
52575 + spin_lock(&dentry->d_lock);
52576 + read_lock(&gr_inode_lock);
52577 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52578 + __get_dev(dentry), role);
52579 + read_unlock(&gr_inode_lock);
52580 + parent = dentry->d_parent;
52581 + spin_unlock(&dentry->d_lock);
52582 +
52583 + if (retval != NULL)
52584 + goto out;
52585 +
52586 + dentry = parent;
52587 + }
52588 +
52589 + spin_lock(&dentry->d_lock);
52590 + read_lock(&gr_inode_lock);
52591 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
52592 + __get_dev(dentry), role);
52593 + read_unlock(&gr_inode_lock);
52594 + spin_unlock(&dentry->d_lock);
52595 +
52596 + if (unlikely(retval == NULL)) {
52597 + /* real_root is pinned, we don't need to hold a reference */
52598 + read_lock(&gr_inode_lock);
52599 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
52600 + __get_dev(real_root.dentry), role);
52601 + read_unlock(&gr_inode_lock);
52602 + }
52603 +out:
52604 + br_read_unlock(vfsmount_lock);
52605 + write_sequnlock(&rename_lock);
52606 +
52607 + BUG_ON(retval == NULL);
52608 +
52609 + return retval;
52610 +}
52611 +
52612 +static void
52613 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
52614 +{
52615 + struct task_struct *task = current;
52616 + const struct cred *cred = current_cred();
52617 +
52618 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52619 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52620 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52621 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
52622 +
52623 + return;
52624 +}
52625 +
52626 +static void
52627 +gr_log_learn_sysctl(const char *path, const __u32 mode)
52628 +{
52629 + struct task_struct *task = current;
52630 + const struct cred *cred = current_cred();
52631 +
52632 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
52633 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52634 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52635 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
52636 +
52637 + return;
52638 +}
52639 +
52640 +static void
52641 +gr_log_learn_id_change(const char type, const unsigned int real,
52642 + const unsigned int effective, const unsigned int fs)
52643 +{
52644 + struct task_struct *task = current;
52645 + const struct cred *cred = current_cred();
52646 +
52647 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
52648 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
52649 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
52650 + type, real, effective, fs, &task->signal->saved_ip);
52651 +
52652 + return;
52653 +}
52654 +
52655 +__u32
52656 +gr_search_file(const struct dentry * dentry, const __u32 mode,
52657 + const struct vfsmount * mnt)
52658 +{
52659 + __u32 retval = mode;
52660 + struct acl_subject_label *curracl;
52661 + struct acl_object_label *currobj;
52662 +
52663 + if (unlikely(!(gr_status & GR_READY)))
52664 + return (mode & ~GR_AUDITS);
52665 +
52666 + curracl = current->acl;
52667 +
52668 + currobj = chk_obj_label(dentry, mnt, curracl);
52669 + retval = currobj->mode & mode;
52670 +
52671 + /* if we're opening a specified transfer file for writing
52672 + (e.g. /dev/initctl), then transfer our role to init
52673 + */
52674 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
52675 + current->role->roletype & GR_ROLE_PERSIST)) {
52676 + struct task_struct *task = init_pid_ns.child_reaper;
52677 +
52678 + if (task->role != current->role) {
52679 + task->acl_sp_role = 0;
52680 + task->acl_role_id = current->acl_role_id;
52681 + task->role = current->role;
52682 + rcu_read_lock();
52683 + read_lock(&grsec_exec_file_lock);
52684 + gr_apply_subject_to_task(task);
52685 + read_unlock(&grsec_exec_file_lock);
52686 + rcu_read_unlock();
52687 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
52688 + }
52689 + }
52690 +
52691 + if (unlikely
52692 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
52693 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
52694 + __u32 new_mode = mode;
52695 +
52696 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52697 +
52698 + retval = new_mode;
52699 +
52700 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
52701 + new_mode |= GR_INHERIT;
52702 +
52703 + if (!(mode & GR_NOLEARN))
52704 + gr_log_learn(dentry, mnt, new_mode);
52705 + }
52706 +
52707 + return retval;
52708 +}
52709 +
52710 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
52711 + const struct dentry *parent,
52712 + const struct vfsmount *mnt)
52713 +{
52714 + struct name_entry *match;
52715 + struct acl_object_label *matchpo;
52716 + struct acl_subject_label *curracl;
52717 + char *path;
52718 +
52719 + if (unlikely(!(gr_status & GR_READY)))
52720 + return NULL;
52721 +
52722 + preempt_disable();
52723 + path = gr_to_filename_rbac(new_dentry, mnt);
52724 + match = lookup_name_entry_create(path);
52725 +
52726 + curracl = current->acl;
52727 +
52728 + if (match) {
52729 + read_lock(&gr_inode_lock);
52730 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
52731 + read_unlock(&gr_inode_lock);
52732 +
52733 + if (matchpo) {
52734 + preempt_enable();
52735 + return matchpo;
52736 + }
52737 + }
52738 +
52739 + // lookup parent
52740 +
52741 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
52742 +
52743 + preempt_enable();
52744 + return matchpo;
52745 +}
52746 +
52747 +__u32
52748 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
52749 + const struct vfsmount * mnt, const __u32 mode)
52750 +{
52751 + struct acl_object_label *matchpo;
52752 + __u32 retval;
52753 +
52754 + if (unlikely(!(gr_status & GR_READY)))
52755 + return (mode & ~GR_AUDITS);
52756 +
52757 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
52758 +
52759 + retval = matchpo->mode & mode;
52760 +
52761 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
52762 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
52763 + __u32 new_mode = mode;
52764 +
52765 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52766 +
52767 + gr_log_learn(new_dentry, mnt, new_mode);
52768 + return new_mode;
52769 + }
52770 +
52771 + return retval;
52772 +}
52773 +
52774 +__u32
52775 +gr_check_link(const struct dentry * new_dentry,
52776 + const struct dentry * parent_dentry,
52777 + const struct vfsmount * parent_mnt,
52778 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
52779 +{
52780 + struct acl_object_label *obj;
52781 + __u32 oldmode, newmode;
52782 + __u32 needmode;
52783 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
52784 + GR_DELETE | GR_INHERIT;
52785 +
52786 + if (unlikely(!(gr_status & GR_READY)))
52787 + return (GR_CREATE | GR_LINK);
52788 +
52789 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
52790 + oldmode = obj->mode;
52791 +
52792 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
52793 + newmode = obj->mode;
52794 +
52795 + needmode = newmode & checkmodes;
52796 +
52797 + // old name for hardlink must have at least the permissions of the new name
52798 + if ((oldmode & needmode) != needmode)
52799 + goto bad;
52800 +
52801 + // if old name had restrictions/auditing, make sure the new name does as well
52802 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
52803 +
52804 + // don't allow hardlinking of suid/sgid files without permission
52805 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52806 + needmode |= GR_SETID;
52807 +
52808 + if ((newmode & needmode) != needmode)
52809 + goto bad;
52810 +
52811 + // enforce minimum permissions
52812 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
52813 + return newmode;
52814 +bad:
52815 + needmode = oldmode;
52816 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
52817 + needmode |= GR_SETID;
52818 +
52819 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
52820 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
52821 + return (GR_CREATE | GR_LINK);
52822 + } else if (newmode & GR_SUPPRESS)
52823 + return GR_SUPPRESS;
52824 + else
52825 + return 0;
52826 +}
52827 +
52828 +int
52829 +gr_check_hidden_task(const struct task_struct *task)
52830 +{
52831 + if (unlikely(!(gr_status & GR_READY)))
52832 + return 0;
52833 +
52834 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
52835 + return 1;
52836 +
52837 + return 0;
52838 +}
52839 +
52840 +int
52841 +gr_check_protected_task(const struct task_struct *task)
52842 +{
52843 + if (unlikely(!(gr_status & GR_READY) || !task))
52844 + return 0;
52845 +
52846 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52847 + task->acl != current->acl)
52848 + return 1;
52849 +
52850 + return 0;
52851 +}
52852 +
52853 +int
52854 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
52855 +{
52856 + struct task_struct *p;
52857 + int ret = 0;
52858 +
52859 + if (unlikely(!(gr_status & GR_READY) || !pid))
52860 + return ret;
52861 +
52862 + read_lock(&tasklist_lock);
52863 + do_each_pid_task(pid, type, p) {
52864 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
52865 + p->acl != current->acl) {
52866 + ret = 1;
52867 + goto out;
52868 + }
52869 + } while_each_pid_task(pid, type, p);
52870 +out:
52871 + read_unlock(&tasklist_lock);
52872 +
52873 + return ret;
52874 +}
52875 +
52876 +void
52877 +gr_copy_label(struct task_struct *tsk)
52878 +{
52879 + /* plain copying of fields is already done by dup_task_struct */
52880 + tsk->signal->used_accept = 0;
52881 + tsk->acl_sp_role = 0;
52882 + //tsk->acl_role_id = current->acl_role_id;
52883 + //tsk->acl = current->acl;
52884 + //tsk->role = current->role;
52885 + tsk->signal->curr_ip = current->signal->curr_ip;
52886 + tsk->signal->saved_ip = current->signal->saved_ip;
52887 + if (current->exec_file)
52888 + get_file(current->exec_file);
52889 + //tsk->exec_file = current->exec_file;
52890 + //tsk->is_writable = current->is_writable;
52891 + if (unlikely(current->signal->used_accept)) {
52892 + current->signal->curr_ip = 0;
52893 + current->signal->saved_ip = 0;
52894 + }
52895 +
52896 + return;
52897 +}
52898 +
52899 +static void
52900 +gr_set_proc_res(struct task_struct *task)
52901 +{
52902 + struct acl_subject_label *proc;
52903 + unsigned short i;
52904 +
52905 + proc = task->acl;
52906 +
52907 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
52908 + return;
52909 +
52910 + for (i = 0; i < RLIM_NLIMITS; i++) {
52911 + if (!(proc->resmask & (1 << i)))
52912 + continue;
52913 +
52914 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
52915 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
52916 + }
52917 +
52918 + return;
52919 +}
52920 +
52921 +extern int __gr_process_user_ban(struct user_struct *user);
52922 +
52923 +int
52924 +gr_check_user_change(int real, int effective, int fs)
52925 +{
52926 + unsigned int i;
52927 + __u16 num;
52928 + uid_t *uidlist;
52929 + int curuid;
52930 + int realok = 0;
52931 + int effectiveok = 0;
52932 + int fsok = 0;
52933 +
52934 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
52935 + struct user_struct *user;
52936 +
52937 + if (real == -1)
52938 + goto skipit;
52939 +
52940 + user = find_user(real);
52941 + if (user == NULL)
52942 + goto skipit;
52943 +
52944 + if (__gr_process_user_ban(user)) {
52945 + /* for find_user */
52946 + free_uid(user);
52947 + return 1;
52948 + }
52949 +
52950 + /* for find_user */
52951 + free_uid(user);
52952 +
52953 +skipit:
52954 +#endif
52955 +
52956 + if (unlikely(!(gr_status & GR_READY)))
52957 + return 0;
52958 +
52959 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52960 + gr_log_learn_id_change('u', real, effective, fs);
52961 +
52962 + num = current->acl->user_trans_num;
52963 + uidlist = current->acl->user_transitions;
52964 +
52965 + if (uidlist == NULL)
52966 + return 0;
52967 +
52968 + if (real == -1)
52969 + realok = 1;
52970 + if (effective == -1)
52971 + effectiveok = 1;
52972 + if (fs == -1)
52973 + fsok = 1;
52974 +
52975 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
52976 + for (i = 0; i < num; i++) {
52977 + curuid = (int)uidlist[i];
52978 + if (real == curuid)
52979 + realok = 1;
52980 + if (effective == curuid)
52981 + effectiveok = 1;
52982 + if (fs == curuid)
52983 + fsok = 1;
52984 + }
52985 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
52986 + for (i = 0; i < num; i++) {
52987 + curuid = (int)uidlist[i];
52988 + if (real == curuid)
52989 + break;
52990 + if (effective == curuid)
52991 + break;
52992 + if (fs == curuid)
52993 + break;
52994 + }
52995 + /* not in deny list */
52996 + if (i == num) {
52997 + realok = 1;
52998 + effectiveok = 1;
52999 + fsok = 1;
53000 + }
53001 + }
53002 +
53003 + if (realok && effectiveok && fsok)
53004 + return 0;
53005 + else {
53006 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53007 + return 1;
53008 + }
53009 +}
53010 +
53011 +int
53012 +gr_check_group_change(int real, int effective, int fs)
53013 +{
53014 + unsigned int i;
53015 + __u16 num;
53016 + gid_t *gidlist;
53017 + int curgid;
53018 + int realok = 0;
53019 + int effectiveok = 0;
53020 + int fsok = 0;
53021 +
53022 + if (unlikely(!(gr_status & GR_READY)))
53023 + return 0;
53024 +
53025 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53026 + gr_log_learn_id_change('g', real, effective, fs);
53027 +
53028 + num = current->acl->group_trans_num;
53029 + gidlist = current->acl->group_transitions;
53030 +
53031 + if (gidlist == NULL)
53032 + return 0;
53033 +
53034 + if (real == -1)
53035 + realok = 1;
53036 + if (effective == -1)
53037 + effectiveok = 1;
53038 + if (fs == -1)
53039 + fsok = 1;
53040 +
53041 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53042 + for (i = 0; i < num; i++) {
53043 + curgid = (int)gidlist[i];
53044 + if (real == curgid)
53045 + realok = 1;
53046 + if (effective == curgid)
53047 + effectiveok = 1;
53048 + if (fs == curgid)
53049 + fsok = 1;
53050 + }
53051 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
53052 + for (i = 0; i < num; i++) {
53053 + curgid = (int)gidlist[i];
53054 + if (real == curgid)
53055 + break;
53056 + if (effective == curgid)
53057 + break;
53058 + if (fs == curgid)
53059 + break;
53060 + }
53061 + /* not in deny list */
53062 + if (i == num) {
53063 + realok = 1;
53064 + effectiveok = 1;
53065 + fsok = 1;
53066 + }
53067 + }
53068 +
53069 + if (realok && effectiveok && fsok)
53070 + return 0;
53071 + else {
53072 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53073 + return 1;
53074 + }
53075 +}
53076 +
53077 +extern int gr_acl_is_capable(const int cap);
53078 +
53079 +void
53080 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
53081 +{
53082 + struct acl_role_label *role = task->role;
53083 + struct acl_subject_label *subj = NULL;
53084 + struct acl_object_label *obj;
53085 + struct file *filp;
53086 +
53087 + if (unlikely(!(gr_status & GR_READY)))
53088 + return;
53089 +
53090 + filp = task->exec_file;
53091 +
53092 + /* kernel process, we'll give them the kernel role */
53093 + if (unlikely(!filp)) {
53094 + task->role = kernel_role;
53095 + task->acl = kernel_role->root_label;
53096 + return;
53097 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
53098 + role = lookup_acl_role_label(task, uid, gid);
53099 +
53100 + /* don't change the role if we're not a privileged process */
53101 + if (role && task->role != role &&
53102 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
53103 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
53104 + return;
53105 +
53106 + /* perform subject lookup in possibly new role
53107 + we can use this result below in the case where role == task->role
53108 + */
53109 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
53110 +
53111 + /* if we changed uid/gid, but result in the same role
53112 + and are using inheritance, don't lose the inherited subject
53113 + if current subject is other than what normal lookup
53114 + would result in, we arrived via inheritance, don't
53115 + lose subject
53116 + */
53117 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
53118 + (subj == task->acl)))
53119 + task->acl = subj;
53120 +
53121 + task->role = role;
53122 +
53123 + task->is_writable = 0;
53124 +
53125 + /* ignore additional mmap checks for processes that are writable
53126 + by the default ACL */
53127 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53128 + if (unlikely(obj->mode & GR_WRITE))
53129 + task->is_writable = 1;
53130 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53131 + if (unlikely(obj->mode & GR_WRITE))
53132 + task->is_writable = 1;
53133 +
53134 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53135 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53136 +#endif
53137 +
53138 + gr_set_proc_res(task);
53139 +
53140 + return;
53141 +}
53142 +
53143 +int
53144 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
53145 + const int unsafe_flags)
53146 +{
53147 + struct task_struct *task = current;
53148 + struct acl_subject_label *newacl;
53149 + struct acl_object_label *obj;
53150 + __u32 retmode;
53151 +
53152 + if (unlikely(!(gr_status & GR_READY)))
53153 + return 0;
53154 +
53155 + newacl = chk_subj_label(dentry, mnt, task->role);
53156 +
53157 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
53158 + did an exec
53159 + */
53160 + rcu_read_lock();
53161 + read_lock(&tasklist_lock);
53162 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
53163 + (task->parent->acl->mode & GR_POVERRIDE))) {
53164 + read_unlock(&tasklist_lock);
53165 + rcu_read_unlock();
53166 + goto skip_check;
53167 + }
53168 + read_unlock(&tasklist_lock);
53169 + rcu_read_unlock();
53170 +
53171 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
53172 + !(task->role->roletype & GR_ROLE_GOD) &&
53173 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
53174 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53175 + if (unsafe_flags & LSM_UNSAFE_SHARE)
53176 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
53177 + else
53178 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
53179 + return -EACCES;
53180 + }
53181 +
53182 +skip_check:
53183 +
53184 + obj = chk_obj_label(dentry, mnt, task->acl);
53185 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
53186 +
53187 + if (!(task->acl->mode & GR_INHERITLEARN) &&
53188 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
53189 + if (obj->nested)
53190 + task->acl = obj->nested;
53191 + else
53192 + task->acl = newacl;
53193 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
53194 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
53195 +
53196 + task->is_writable = 0;
53197 +
53198 + /* ignore additional mmap checks for processes that are writable
53199 + by the default ACL */
53200 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
53201 + if (unlikely(obj->mode & GR_WRITE))
53202 + task->is_writable = 1;
53203 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
53204 + if (unlikely(obj->mode & GR_WRITE))
53205 + task->is_writable = 1;
53206 +
53207 + gr_set_proc_res(task);
53208 +
53209 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53210 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
53211 +#endif
53212 + return 0;
53213 +}
53214 +
53215 +/* always called with valid inodev ptr */
53216 +static void
53217 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
53218 +{
53219 + struct acl_object_label *matchpo;
53220 + struct acl_subject_label *matchps;
53221 + struct acl_subject_label *subj;
53222 + struct acl_role_label *role;
53223 + unsigned int x;
53224 +
53225 + FOR_EACH_ROLE_START(role)
53226 + FOR_EACH_SUBJECT_START(role, subj, x)
53227 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
53228 + matchpo->mode |= GR_DELETED;
53229 + FOR_EACH_SUBJECT_END(subj,x)
53230 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53231 + if (subj->inode == ino && subj->device == dev)
53232 + subj->mode |= GR_DELETED;
53233 + FOR_EACH_NESTED_SUBJECT_END(subj)
53234 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
53235 + matchps->mode |= GR_DELETED;
53236 + FOR_EACH_ROLE_END(role)
53237 +
53238 + inodev->nentry->deleted = 1;
53239 +
53240 + return;
53241 +}
53242 +
53243 +void
53244 +gr_handle_delete(const ino_t ino, const dev_t dev)
53245 +{
53246 + struct inodev_entry *inodev;
53247 +
53248 + if (unlikely(!(gr_status & GR_READY)))
53249 + return;
53250 +
53251 + write_lock(&gr_inode_lock);
53252 + inodev = lookup_inodev_entry(ino, dev);
53253 + if (inodev != NULL)
53254 + do_handle_delete(inodev, ino, dev);
53255 + write_unlock(&gr_inode_lock);
53256 +
53257 + return;
53258 +}
53259 +
53260 +static void
53261 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
53262 + const ino_t newinode, const dev_t newdevice,
53263 + struct acl_subject_label *subj)
53264 +{
53265 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
53266 + struct acl_object_label *match;
53267 +
53268 + match = subj->obj_hash[index];
53269 +
53270 + while (match && (match->inode != oldinode ||
53271 + match->device != olddevice ||
53272 + !(match->mode & GR_DELETED)))
53273 + match = match->next;
53274 +
53275 + if (match && (match->inode == oldinode)
53276 + && (match->device == olddevice)
53277 + && (match->mode & GR_DELETED)) {
53278 + if (match->prev == NULL) {
53279 + subj->obj_hash[index] = match->next;
53280 + if (match->next != NULL)
53281 + match->next->prev = NULL;
53282 + } else {
53283 + match->prev->next = match->next;
53284 + if (match->next != NULL)
53285 + match->next->prev = match->prev;
53286 + }
53287 + match->prev = NULL;
53288 + match->next = NULL;
53289 + match->inode = newinode;
53290 + match->device = newdevice;
53291 + match->mode &= ~GR_DELETED;
53292 +
53293 + insert_acl_obj_label(match, subj);
53294 + }
53295 +
53296 + return;
53297 +}
53298 +
53299 +static void
53300 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
53301 + const ino_t newinode, const dev_t newdevice,
53302 + struct acl_role_label *role)
53303 +{
53304 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
53305 + struct acl_subject_label *match;
53306 +
53307 + match = role->subj_hash[index];
53308 +
53309 + while (match && (match->inode != oldinode ||
53310 + match->device != olddevice ||
53311 + !(match->mode & GR_DELETED)))
53312 + match = match->next;
53313 +
53314 + if (match && (match->inode == oldinode)
53315 + && (match->device == olddevice)
53316 + && (match->mode & GR_DELETED)) {
53317 + if (match->prev == NULL) {
53318 + role->subj_hash[index] = match->next;
53319 + if (match->next != NULL)
53320 + match->next->prev = NULL;
53321 + } else {
53322 + match->prev->next = match->next;
53323 + if (match->next != NULL)
53324 + match->next->prev = match->prev;
53325 + }
53326 + match->prev = NULL;
53327 + match->next = NULL;
53328 + match->inode = newinode;
53329 + match->device = newdevice;
53330 + match->mode &= ~GR_DELETED;
53331 +
53332 + insert_acl_subj_label(match, role);
53333 + }
53334 +
53335 + return;
53336 +}
53337 +
53338 +static void
53339 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
53340 + const ino_t newinode, const dev_t newdevice)
53341 +{
53342 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
53343 + struct inodev_entry *match;
53344 +
53345 + match = inodev_set.i_hash[index];
53346 +
53347 + while (match && (match->nentry->inode != oldinode ||
53348 + match->nentry->device != olddevice || !match->nentry->deleted))
53349 + match = match->next;
53350 +
53351 + if (match && (match->nentry->inode == oldinode)
53352 + && (match->nentry->device == olddevice) &&
53353 + match->nentry->deleted) {
53354 + if (match->prev == NULL) {
53355 + inodev_set.i_hash[index] = match->next;
53356 + if (match->next != NULL)
53357 + match->next->prev = NULL;
53358 + } else {
53359 + match->prev->next = match->next;
53360 + if (match->next != NULL)
53361 + match->next->prev = match->prev;
53362 + }
53363 + match->prev = NULL;
53364 + match->next = NULL;
53365 + match->nentry->inode = newinode;
53366 + match->nentry->device = newdevice;
53367 + match->nentry->deleted = 0;
53368 +
53369 + insert_inodev_entry(match);
53370 + }
53371 +
53372 + return;
53373 +}
53374 +
53375 +static void
53376 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
53377 +{
53378 + struct acl_subject_label *subj;
53379 + struct acl_role_label *role;
53380 + unsigned int x;
53381 +
53382 + FOR_EACH_ROLE_START(role)
53383 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
53384 +
53385 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
53386 + if ((subj->inode == ino) && (subj->device == dev)) {
53387 + subj->inode = ino;
53388 + subj->device = dev;
53389 + }
53390 + FOR_EACH_NESTED_SUBJECT_END(subj)
53391 + FOR_EACH_SUBJECT_START(role, subj, x)
53392 + update_acl_obj_label(matchn->inode, matchn->device,
53393 + ino, dev, subj);
53394 + FOR_EACH_SUBJECT_END(subj,x)
53395 + FOR_EACH_ROLE_END(role)
53396 +
53397 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
53398 +
53399 + return;
53400 +}
53401 +
53402 +static void
53403 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
53404 + const struct vfsmount *mnt)
53405 +{
53406 + ino_t ino = dentry->d_inode->i_ino;
53407 + dev_t dev = __get_dev(dentry);
53408 +
53409 + __do_handle_create(matchn, ino, dev);
53410 +
53411 + return;
53412 +}
53413 +
53414 +void
53415 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
53416 +{
53417 + struct name_entry *matchn;
53418 +
53419 + if (unlikely(!(gr_status & GR_READY)))
53420 + return;
53421 +
53422 + preempt_disable();
53423 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
53424 +
53425 + if (unlikely((unsigned long)matchn)) {
53426 + write_lock(&gr_inode_lock);
53427 + do_handle_create(matchn, dentry, mnt);
53428 + write_unlock(&gr_inode_lock);
53429 + }
53430 + preempt_enable();
53431 +
53432 + return;
53433 +}
53434 +
53435 +void
53436 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
53437 +{
53438 + struct name_entry *matchn;
53439 +
53440 + if (unlikely(!(gr_status & GR_READY)))
53441 + return;
53442 +
53443 + preempt_disable();
53444 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
53445 +
53446 + if (unlikely((unsigned long)matchn)) {
53447 + write_lock(&gr_inode_lock);
53448 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
53449 + write_unlock(&gr_inode_lock);
53450 + }
53451 + preempt_enable();
53452 +
53453 + return;
53454 +}
53455 +
53456 +void
53457 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
53458 + struct dentry *old_dentry,
53459 + struct dentry *new_dentry,
53460 + struct vfsmount *mnt, const __u8 replace)
53461 +{
53462 + struct name_entry *matchn;
53463 + struct inodev_entry *inodev;
53464 + struct inode *inode = new_dentry->d_inode;
53465 + ino_t old_ino = old_dentry->d_inode->i_ino;
53466 + dev_t old_dev = __get_dev(old_dentry);
53467 +
53468 + /* vfs_rename swaps the name and parent link for old_dentry and
53469 + new_dentry
53470 + at this point, old_dentry has the new name, parent link, and inode
53471 + for the renamed file
53472 + if a file is being replaced by a rename, new_dentry has the inode
53473 + and name for the replaced file
53474 + */
53475 +
53476 + if (unlikely(!(gr_status & GR_READY)))
53477 + return;
53478 +
53479 + preempt_disable();
53480 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
53481 +
53482 + /* we wouldn't have to check d_inode if it weren't for
53483 + NFS silly-renaming
53484 + */
53485 +
53486 + write_lock(&gr_inode_lock);
53487 + if (unlikely(replace && inode)) {
53488 + ino_t new_ino = inode->i_ino;
53489 + dev_t new_dev = __get_dev(new_dentry);
53490 +
53491 + inodev = lookup_inodev_entry(new_ino, new_dev);
53492 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
53493 + do_handle_delete(inodev, new_ino, new_dev);
53494 + }
53495 +
53496 + inodev = lookup_inodev_entry(old_ino, old_dev);
53497 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
53498 + do_handle_delete(inodev, old_ino, old_dev);
53499 +
53500 + if (unlikely((unsigned long)matchn))
53501 + do_handle_create(matchn, old_dentry, mnt);
53502 +
53503 + write_unlock(&gr_inode_lock);
53504 + preempt_enable();
53505 +
53506 + return;
53507 +}
53508 +
53509 +static int
53510 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
53511 + unsigned char **sum)
53512 +{
53513 + struct acl_role_label *r;
53514 + struct role_allowed_ip *ipp;
53515 + struct role_transition *trans;
53516 + unsigned int i;
53517 + int found = 0;
53518 + u32 curr_ip = current->signal->curr_ip;
53519 +
53520 + current->signal->saved_ip = curr_ip;
53521 +
53522 + /* check transition table */
53523 +
53524 + for (trans = current->role->transitions; trans; trans = trans->next) {
53525 + if (!strcmp(rolename, trans->rolename)) {
53526 + found = 1;
53527 + break;
53528 + }
53529 + }
53530 +
53531 + if (!found)
53532 + return 0;
53533 +
53534 + /* handle special roles that do not require authentication
53535 + and check ip */
53536 +
53537 + FOR_EACH_ROLE_START(r)
53538 + if (!strcmp(rolename, r->rolename) &&
53539 + (r->roletype & GR_ROLE_SPECIAL)) {
53540 + found = 0;
53541 + if (r->allowed_ips != NULL) {
53542 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
53543 + if ((ntohl(curr_ip) & ipp->netmask) ==
53544 + (ntohl(ipp->addr) & ipp->netmask))
53545 + found = 1;
53546 + }
53547 + } else
53548 + found = 2;
53549 + if (!found)
53550 + return 0;
53551 +
53552 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
53553 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
53554 + *salt = NULL;
53555 + *sum = NULL;
53556 + return 1;
53557 + }
53558 + }
53559 + FOR_EACH_ROLE_END(r)
53560 +
53561 + for (i = 0; i < num_sprole_pws; i++) {
53562 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
53563 + *salt = acl_special_roles[i]->salt;
53564 + *sum = acl_special_roles[i]->sum;
53565 + return 1;
53566 + }
53567 + }
53568 +
53569 + return 0;
53570 +}
53571 +
53572 +static void
53573 +assign_special_role(char *rolename)
53574 +{
53575 + struct acl_object_label *obj;
53576 + struct acl_role_label *r;
53577 + struct acl_role_label *assigned = NULL;
53578 + struct task_struct *tsk;
53579 + struct file *filp;
53580 +
53581 + FOR_EACH_ROLE_START(r)
53582 + if (!strcmp(rolename, r->rolename) &&
53583 + (r->roletype & GR_ROLE_SPECIAL)) {
53584 + assigned = r;
53585 + break;
53586 + }
53587 + FOR_EACH_ROLE_END(r)
53588 +
53589 + if (!assigned)
53590 + return;
53591 +
53592 + read_lock(&tasklist_lock);
53593 + read_lock(&grsec_exec_file_lock);
53594 +
53595 + tsk = current->real_parent;
53596 + if (tsk == NULL)
53597 + goto out_unlock;
53598 +
53599 + filp = tsk->exec_file;
53600 + if (filp == NULL)
53601 + goto out_unlock;
53602 +
53603 + tsk->is_writable = 0;
53604 +
53605 + tsk->acl_sp_role = 1;
53606 + tsk->acl_role_id = ++acl_sp_role_value;
53607 + tsk->role = assigned;
53608 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
53609 +
53610 + /* ignore additional mmap checks for processes that are writable
53611 + by the default ACL */
53612 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53613 + if (unlikely(obj->mode & GR_WRITE))
53614 + tsk->is_writable = 1;
53615 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
53616 + if (unlikely(obj->mode & GR_WRITE))
53617 + tsk->is_writable = 1;
53618 +
53619 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53620 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
53621 +#endif
53622 +
53623 +out_unlock:
53624 + read_unlock(&grsec_exec_file_lock);
53625 + read_unlock(&tasklist_lock);
53626 + return;
53627 +}
53628 +
53629 +int gr_check_secure_terminal(struct task_struct *task)
53630 +{
53631 + struct task_struct *p, *p2, *p3;
53632 + struct files_struct *files;
53633 + struct fdtable *fdt;
53634 + struct file *our_file = NULL, *file;
53635 + int i;
53636 +
53637 + if (task->signal->tty == NULL)
53638 + return 1;
53639 +
53640 + files = get_files_struct(task);
53641 + if (files != NULL) {
53642 + rcu_read_lock();
53643 + fdt = files_fdtable(files);
53644 + for (i=0; i < fdt->max_fds; i++) {
53645 + file = fcheck_files(files, i);
53646 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
53647 + get_file(file);
53648 + our_file = file;
53649 + }
53650 + }
53651 + rcu_read_unlock();
53652 + put_files_struct(files);
53653 + }
53654 +
53655 + if (our_file == NULL)
53656 + return 1;
53657 +
53658 + read_lock(&tasklist_lock);
53659 + do_each_thread(p2, p) {
53660 + files = get_files_struct(p);
53661 + if (files == NULL ||
53662 + (p->signal && p->signal->tty == task->signal->tty)) {
53663 + if (files != NULL)
53664 + put_files_struct(files);
53665 + continue;
53666 + }
53667 + rcu_read_lock();
53668 + fdt = files_fdtable(files);
53669 + for (i=0; i < fdt->max_fds; i++) {
53670 + file = fcheck_files(files, i);
53671 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
53672 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
53673 + p3 = task;
53674 + while (p3->pid > 0) {
53675 + if (p3 == p)
53676 + break;
53677 + p3 = p3->real_parent;
53678 + }
53679 + if (p3 == p)
53680 + break;
53681 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
53682 + gr_handle_alertkill(p);
53683 + rcu_read_unlock();
53684 + put_files_struct(files);
53685 + read_unlock(&tasklist_lock);
53686 + fput(our_file);
53687 + return 0;
53688 + }
53689 + }
53690 + rcu_read_unlock();
53691 + put_files_struct(files);
53692 + } while_each_thread(p2, p);
53693 + read_unlock(&tasklist_lock);
53694 +
53695 + fput(our_file);
53696 + return 1;
53697 +}
53698 +
53699 +ssize_t
53700 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
53701 +{
53702 + struct gr_arg_wrapper uwrap;
53703 + unsigned char *sprole_salt = NULL;
53704 + unsigned char *sprole_sum = NULL;
53705 + int error = sizeof (struct gr_arg_wrapper);
53706 + int error2 = 0;
53707 +
53708 + mutex_lock(&gr_dev_mutex);
53709 +
53710 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
53711 + error = -EPERM;
53712 + goto out;
53713 + }
53714 +
53715 + if (count != sizeof (struct gr_arg_wrapper)) {
53716 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
53717 + error = -EINVAL;
53718 + goto out;
53719 + }
53720 +
53721 +
53722 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
53723 + gr_auth_expires = 0;
53724 + gr_auth_attempts = 0;
53725 + }
53726 +
53727 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
53728 + error = -EFAULT;
53729 + goto out;
53730 + }
53731 +
53732 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
53733 + error = -EINVAL;
53734 + goto out;
53735 + }
53736 +
53737 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
53738 + error = -EFAULT;
53739 + goto out;
53740 + }
53741 +
53742 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53743 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53744 + time_after(gr_auth_expires, get_seconds())) {
53745 + error = -EBUSY;
53746 + goto out;
53747 + }
53748 +
53749 + /* if non-root trying to do anything other than use a special role,
53750 + do not attempt authentication, do not count towards authentication
53751 + locking
53752 + */
53753 +
53754 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
53755 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
53756 + current_uid()) {
53757 + error = -EPERM;
53758 + goto out;
53759 + }
53760 +
53761 + /* ensure pw and special role name are null terminated */
53762 +
53763 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
53764 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
53765 +
53766 + /* Okay.
53767 + * We have our enough of the argument structure..(we have yet
53768 + * to copy_from_user the tables themselves) . Copy the tables
53769 + * only if we need them, i.e. for loading operations. */
53770 +
53771 + switch (gr_usermode->mode) {
53772 + case GR_STATUS:
53773 + if (gr_status & GR_READY) {
53774 + error = 1;
53775 + if (!gr_check_secure_terminal(current))
53776 + error = 3;
53777 + } else
53778 + error = 2;
53779 + goto out;
53780 + case GR_SHUTDOWN:
53781 + if ((gr_status & GR_READY)
53782 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53783 + pax_open_kernel();
53784 + gr_status &= ~GR_READY;
53785 + pax_close_kernel();
53786 +
53787 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
53788 + free_variables();
53789 + memset(gr_usermode, 0, sizeof (struct gr_arg));
53790 + memset(gr_system_salt, 0, GR_SALT_LEN);
53791 + memset(gr_system_sum, 0, GR_SHA_LEN);
53792 + } else if (gr_status & GR_READY) {
53793 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
53794 + error = -EPERM;
53795 + } else {
53796 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
53797 + error = -EAGAIN;
53798 + }
53799 + break;
53800 + case GR_ENABLE:
53801 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
53802 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
53803 + else {
53804 + if (gr_status & GR_READY)
53805 + error = -EAGAIN;
53806 + else
53807 + error = error2;
53808 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
53809 + }
53810 + break;
53811 + case GR_RELOAD:
53812 + if (!(gr_status & GR_READY)) {
53813 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
53814 + error = -EAGAIN;
53815 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53816 + preempt_disable();
53817 +
53818 + pax_open_kernel();
53819 + gr_status &= ~GR_READY;
53820 + pax_close_kernel();
53821 +
53822 + free_variables();
53823 + if (!(error2 = gracl_init(gr_usermode))) {
53824 + preempt_enable();
53825 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
53826 + } else {
53827 + preempt_enable();
53828 + error = error2;
53829 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53830 + }
53831 + } else {
53832 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
53833 + error = -EPERM;
53834 + }
53835 + break;
53836 + case GR_SEGVMOD:
53837 + if (unlikely(!(gr_status & GR_READY))) {
53838 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
53839 + error = -EAGAIN;
53840 + break;
53841 + }
53842 +
53843 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
53844 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
53845 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
53846 + struct acl_subject_label *segvacl;
53847 + segvacl =
53848 + lookup_acl_subj_label(gr_usermode->segv_inode,
53849 + gr_usermode->segv_device,
53850 + current->role);
53851 + if (segvacl) {
53852 + segvacl->crashes = 0;
53853 + segvacl->expires = 0;
53854 + }
53855 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
53856 + gr_remove_uid(gr_usermode->segv_uid);
53857 + }
53858 + } else {
53859 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
53860 + error = -EPERM;
53861 + }
53862 + break;
53863 + case GR_SPROLE:
53864 + case GR_SPROLEPAM:
53865 + if (unlikely(!(gr_status & GR_READY))) {
53866 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
53867 + error = -EAGAIN;
53868 + break;
53869 + }
53870 +
53871 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
53872 + current->role->expires = 0;
53873 + current->role->auth_attempts = 0;
53874 + }
53875 +
53876 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
53877 + time_after(current->role->expires, get_seconds())) {
53878 + error = -EBUSY;
53879 + goto out;
53880 + }
53881 +
53882 + if (lookup_special_role_auth
53883 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
53884 + && ((!sprole_salt && !sprole_sum)
53885 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
53886 + char *p = "";
53887 + assign_special_role(gr_usermode->sp_role);
53888 + read_lock(&tasklist_lock);
53889 + if (current->real_parent)
53890 + p = current->real_parent->role->rolename;
53891 + read_unlock(&tasklist_lock);
53892 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
53893 + p, acl_sp_role_value);
53894 + } else {
53895 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
53896 + error = -EPERM;
53897 + if(!(current->role->auth_attempts++))
53898 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53899 +
53900 + goto out;
53901 + }
53902 + break;
53903 + case GR_UNSPROLE:
53904 + if (unlikely(!(gr_status & GR_READY))) {
53905 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
53906 + error = -EAGAIN;
53907 + break;
53908 + }
53909 +
53910 + if (current->role->roletype & GR_ROLE_SPECIAL) {
53911 + char *p = "";
53912 + int i = 0;
53913 +
53914 + read_lock(&tasklist_lock);
53915 + if (current->real_parent) {
53916 + p = current->real_parent->role->rolename;
53917 + i = current->real_parent->acl_role_id;
53918 + }
53919 + read_unlock(&tasklist_lock);
53920 +
53921 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
53922 + gr_set_acls(1);
53923 + } else {
53924 + error = -EPERM;
53925 + goto out;
53926 + }
53927 + break;
53928 + default:
53929 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
53930 + error = -EINVAL;
53931 + break;
53932 + }
53933 +
53934 + if (error != -EPERM)
53935 + goto out;
53936 +
53937 + if(!(gr_auth_attempts++))
53938 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
53939 +
53940 + out:
53941 + mutex_unlock(&gr_dev_mutex);
53942 + return error;
53943 +}
53944 +
53945 +/* must be called with
53946 + rcu_read_lock();
53947 + read_lock(&tasklist_lock);
53948 + read_lock(&grsec_exec_file_lock);
53949 +*/
53950 +int gr_apply_subject_to_task(struct task_struct *task)
53951 +{
53952 + struct acl_object_label *obj;
53953 + char *tmpname;
53954 + struct acl_subject_label *tmpsubj;
53955 + struct file *filp;
53956 + struct name_entry *nmatch;
53957 +
53958 + filp = task->exec_file;
53959 + if (filp == NULL)
53960 + return 0;
53961 +
53962 + /* the following is to apply the correct subject
53963 + on binaries running when the RBAC system
53964 + is enabled, when the binaries have been
53965 + replaced or deleted since their execution
53966 + -----
53967 + when the RBAC system starts, the inode/dev
53968 + from exec_file will be one the RBAC system
53969 + is unaware of. It only knows the inode/dev
53970 + of the present file on disk, or the absence
53971 + of it.
53972 + */
53973 + preempt_disable();
53974 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
53975 +
53976 + nmatch = lookup_name_entry(tmpname);
53977 + preempt_enable();
53978 + tmpsubj = NULL;
53979 + if (nmatch) {
53980 + if (nmatch->deleted)
53981 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
53982 + else
53983 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
53984 + if (tmpsubj != NULL)
53985 + task->acl = tmpsubj;
53986 + }
53987 + if (tmpsubj == NULL)
53988 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
53989 + task->role);
53990 + if (task->acl) {
53991 + task->is_writable = 0;
53992 + /* ignore additional mmap checks for processes that are writable
53993 + by the default ACL */
53994 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
53995 + if (unlikely(obj->mode & GR_WRITE))
53996 + task->is_writable = 1;
53997 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
53998 + if (unlikely(obj->mode & GR_WRITE))
53999 + task->is_writable = 1;
54000 +
54001 + gr_set_proc_res(task);
54002 +
54003 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54004 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54005 +#endif
54006 + } else {
54007 + return 1;
54008 + }
54009 +
54010 + return 0;
54011 +}
54012 +
54013 +int
54014 +gr_set_acls(const int type)
54015 +{
54016 + struct task_struct *task, *task2;
54017 + struct acl_role_label *role = current->role;
54018 + __u16 acl_role_id = current->acl_role_id;
54019 + const struct cred *cred;
54020 + int ret;
54021 +
54022 + rcu_read_lock();
54023 + read_lock(&tasklist_lock);
54024 + read_lock(&grsec_exec_file_lock);
54025 + do_each_thread(task2, task) {
54026 + /* check to see if we're called from the exit handler,
54027 + if so, only replace ACLs that have inherited the admin
54028 + ACL */
54029 +
54030 + if (type && (task->role != role ||
54031 + task->acl_role_id != acl_role_id))
54032 + continue;
54033 +
54034 + task->acl_role_id = 0;
54035 + task->acl_sp_role = 0;
54036 +
54037 + if (task->exec_file) {
54038 + cred = __task_cred(task);
54039 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54040 + ret = gr_apply_subject_to_task(task);
54041 + if (ret) {
54042 + read_unlock(&grsec_exec_file_lock);
54043 + read_unlock(&tasklist_lock);
54044 + rcu_read_unlock();
54045 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54046 + return ret;
54047 + }
54048 + } else {
54049 + // it's a kernel process
54050 + task->role = kernel_role;
54051 + task->acl = kernel_role->root_label;
54052 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
54053 + task->acl->mode &= ~GR_PROCFIND;
54054 +#endif
54055 + }
54056 + } while_each_thread(task2, task);
54057 + read_unlock(&grsec_exec_file_lock);
54058 + read_unlock(&tasklist_lock);
54059 + rcu_read_unlock();
54060 +
54061 + return 0;
54062 +}
54063 +
54064 +void
54065 +gr_learn_resource(const struct task_struct *task,
54066 + const int res, const unsigned long wanted, const int gt)
54067 +{
54068 + struct acl_subject_label *acl;
54069 + const struct cred *cred;
54070 +
54071 + if (unlikely((gr_status & GR_READY) &&
54072 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
54073 + goto skip_reslog;
54074 +
54075 +#ifdef CONFIG_GRKERNSEC_RESLOG
54076 + gr_log_resource(task, res, wanted, gt);
54077 +#endif
54078 + skip_reslog:
54079 +
54080 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
54081 + return;
54082 +
54083 + acl = task->acl;
54084 +
54085 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
54086 + !(acl->resmask & (1 << (unsigned short) res))))
54087 + return;
54088 +
54089 + if (wanted >= acl->res[res].rlim_cur) {
54090 + unsigned long res_add;
54091 +
54092 + res_add = wanted;
54093 + switch (res) {
54094 + case RLIMIT_CPU:
54095 + res_add += GR_RLIM_CPU_BUMP;
54096 + break;
54097 + case RLIMIT_FSIZE:
54098 + res_add += GR_RLIM_FSIZE_BUMP;
54099 + break;
54100 + case RLIMIT_DATA:
54101 + res_add += GR_RLIM_DATA_BUMP;
54102 + break;
54103 + case RLIMIT_STACK:
54104 + res_add += GR_RLIM_STACK_BUMP;
54105 + break;
54106 + case RLIMIT_CORE:
54107 + res_add += GR_RLIM_CORE_BUMP;
54108 + break;
54109 + case RLIMIT_RSS:
54110 + res_add += GR_RLIM_RSS_BUMP;
54111 + break;
54112 + case RLIMIT_NPROC:
54113 + res_add += GR_RLIM_NPROC_BUMP;
54114 + break;
54115 + case RLIMIT_NOFILE:
54116 + res_add += GR_RLIM_NOFILE_BUMP;
54117 + break;
54118 + case RLIMIT_MEMLOCK:
54119 + res_add += GR_RLIM_MEMLOCK_BUMP;
54120 + break;
54121 + case RLIMIT_AS:
54122 + res_add += GR_RLIM_AS_BUMP;
54123 + break;
54124 + case RLIMIT_LOCKS:
54125 + res_add += GR_RLIM_LOCKS_BUMP;
54126 + break;
54127 + case RLIMIT_SIGPENDING:
54128 + res_add += GR_RLIM_SIGPENDING_BUMP;
54129 + break;
54130 + case RLIMIT_MSGQUEUE:
54131 + res_add += GR_RLIM_MSGQUEUE_BUMP;
54132 + break;
54133 + case RLIMIT_NICE:
54134 + res_add += GR_RLIM_NICE_BUMP;
54135 + break;
54136 + case RLIMIT_RTPRIO:
54137 + res_add += GR_RLIM_RTPRIO_BUMP;
54138 + break;
54139 + case RLIMIT_RTTIME:
54140 + res_add += GR_RLIM_RTTIME_BUMP;
54141 + break;
54142 + }
54143 +
54144 + acl->res[res].rlim_cur = res_add;
54145 +
54146 + if (wanted > acl->res[res].rlim_max)
54147 + acl->res[res].rlim_max = res_add;
54148 +
54149 + /* only log the subject filename, since resource logging is supported for
54150 + single-subject learning only */
54151 + rcu_read_lock();
54152 + cred = __task_cred(task);
54153 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54154 + task->role->roletype, cred->uid, cred->gid, acl->filename,
54155 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
54156 + "", (unsigned long) res, &task->signal->saved_ip);
54157 + rcu_read_unlock();
54158 + }
54159 +
54160 + return;
54161 +}
54162 +
54163 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
54164 +void
54165 +pax_set_initial_flags(struct linux_binprm *bprm)
54166 +{
54167 + struct task_struct *task = current;
54168 + struct acl_subject_label *proc;
54169 + unsigned long flags;
54170 +
54171 + if (unlikely(!(gr_status & GR_READY)))
54172 + return;
54173 +
54174 + flags = pax_get_flags(task);
54175 +
54176 + proc = task->acl;
54177 +
54178 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
54179 + flags &= ~MF_PAX_PAGEEXEC;
54180 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
54181 + flags &= ~MF_PAX_SEGMEXEC;
54182 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
54183 + flags &= ~MF_PAX_RANDMMAP;
54184 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
54185 + flags &= ~MF_PAX_EMUTRAMP;
54186 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
54187 + flags &= ~MF_PAX_MPROTECT;
54188 +
54189 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
54190 + flags |= MF_PAX_PAGEEXEC;
54191 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
54192 + flags |= MF_PAX_SEGMEXEC;
54193 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
54194 + flags |= MF_PAX_RANDMMAP;
54195 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
54196 + flags |= MF_PAX_EMUTRAMP;
54197 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
54198 + flags |= MF_PAX_MPROTECT;
54199 +
54200 + pax_set_flags(task, flags);
54201 +
54202 + return;
54203 +}
54204 +#endif
54205 +
54206 +#ifdef CONFIG_SYSCTL
54207 +/* Eric Biederman likes breaking userland ABI and every inode-based security
54208 + system to save 35kb of memory */
54209 +
54210 +/* we modify the passed in filename, but adjust it back before returning */
54211 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
54212 +{
54213 + struct name_entry *nmatch;
54214 + char *p, *lastp = NULL;
54215 + struct acl_object_label *obj = NULL, *tmp;
54216 + struct acl_subject_label *tmpsubj;
54217 + char c = '\0';
54218 +
54219 + read_lock(&gr_inode_lock);
54220 +
54221 + p = name + len - 1;
54222 + do {
54223 + nmatch = lookup_name_entry(name);
54224 + if (lastp != NULL)
54225 + *lastp = c;
54226 +
54227 + if (nmatch == NULL)
54228 + goto next_component;
54229 + tmpsubj = current->acl;
54230 + do {
54231 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
54232 + if (obj != NULL) {
54233 + tmp = obj->globbed;
54234 + while (tmp) {
54235 + if (!glob_match(tmp->filename, name)) {
54236 + obj = tmp;
54237 + goto found_obj;
54238 + }
54239 + tmp = tmp->next;
54240 + }
54241 + goto found_obj;
54242 + }
54243 + } while ((tmpsubj = tmpsubj->parent_subject));
54244 +next_component:
54245 + /* end case */
54246 + if (p == name)
54247 + break;
54248 +
54249 + while (*p != '/')
54250 + p--;
54251 + if (p == name)
54252 + lastp = p + 1;
54253 + else {
54254 + lastp = p;
54255 + p--;
54256 + }
54257 + c = *lastp;
54258 + *lastp = '\0';
54259 + } while (1);
54260 +found_obj:
54261 + read_unlock(&gr_inode_lock);
54262 + /* obj returned will always be non-null */
54263 + return obj;
54264 +}
54265 +
54266 +/* returns 0 when allowing, non-zero on error
54267 + op of 0 is used for readdir, so we don't log the names of hidden files
54268 +*/
54269 +__u32
54270 +gr_handle_sysctl(const struct ctl_table *table, const int op)
54271 +{
54272 + struct ctl_table *tmp;
54273 + const char *proc_sys = "/proc/sys";
54274 + char *path;
54275 + struct acl_object_label *obj;
54276 + unsigned short len = 0, pos = 0, depth = 0, i;
54277 + __u32 err = 0;
54278 + __u32 mode = 0;
54279 +
54280 + if (unlikely(!(gr_status & GR_READY)))
54281 + return 0;
54282 +
54283 + /* for now, ignore operations on non-sysctl entries if it's not a
54284 + readdir*/
54285 + if (table->child != NULL && op != 0)
54286 + return 0;
54287 +
54288 + mode |= GR_FIND;
54289 + /* it's only a read if it's an entry, read on dirs is for readdir */
54290 + if (op & MAY_READ)
54291 + mode |= GR_READ;
54292 + if (op & MAY_WRITE)
54293 + mode |= GR_WRITE;
54294 +
54295 + preempt_disable();
54296 +
54297 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54298 +
54299 + /* it's only a read/write if it's an actual entry, not a dir
54300 + (which are opened for readdir)
54301 + */
54302 +
54303 + /* convert the requested sysctl entry into a pathname */
54304 +
54305 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54306 + len += strlen(tmp->procname);
54307 + len++;
54308 + depth++;
54309 + }
54310 +
54311 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
54312 + /* deny */
54313 + goto out;
54314 + }
54315 +
54316 + memset(path, 0, PAGE_SIZE);
54317 +
54318 + memcpy(path, proc_sys, strlen(proc_sys));
54319 +
54320 + pos += strlen(proc_sys);
54321 +
54322 + for (; depth > 0; depth--) {
54323 + path[pos] = '/';
54324 + pos++;
54325 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
54326 + if (depth == i) {
54327 + memcpy(path + pos, tmp->procname,
54328 + strlen(tmp->procname));
54329 + pos += strlen(tmp->procname);
54330 + }
54331 + i++;
54332 + }
54333 + }
54334 +
54335 + obj = gr_lookup_by_name(path, pos);
54336 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
54337 +
54338 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
54339 + ((err & mode) != mode))) {
54340 + __u32 new_mode = mode;
54341 +
54342 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
54343 +
54344 + err = 0;
54345 + gr_log_learn_sysctl(path, new_mode);
54346 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
54347 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
54348 + err = -ENOENT;
54349 + } else if (!(err & GR_FIND)) {
54350 + err = -ENOENT;
54351 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
54352 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
54353 + path, (mode & GR_READ) ? " reading" : "",
54354 + (mode & GR_WRITE) ? " writing" : "");
54355 + err = -EACCES;
54356 + } else if ((err & mode) != mode) {
54357 + err = -EACCES;
54358 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
54359 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
54360 + path, (mode & GR_READ) ? " reading" : "",
54361 + (mode & GR_WRITE) ? " writing" : "");
54362 + err = 0;
54363 + } else
54364 + err = 0;
54365 +
54366 + out:
54367 + preempt_enable();
54368 +
54369 + return err;
54370 +}
54371 +#endif
54372 +
54373 +int
54374 +gr_handle_proc_ptrace(struct task_struct *task)
54375 +{
54376 + struct file *filp;
54377 + struct task_struct *tmp = task;
54378 + struct task_struct *curtemp = current;
54379 + __u32 retmode;
54380 +
54381 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54382 + if (unlikely(!(gr_status & GR_READY)))
54383 + return 0;
54384 +#endif
54385 +
54386 + read_lock(&tasklist_lock);
54387 + read_lock(&grsec_exec_file_lock);
54388 + filp = task->exec_file;
54389 +
54390 + while (tmp->pid > 0) {
54391 + if (tmp == curtemp)
54392 + break;
54393 + tmp = tmp->real_parent;
54394 + }
54395 +
54396 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54397 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
54398 + read_unlock(&grsec_exec_file_lock);
54399 + read_unlock(&tasklist_lock);
54400 + return 1;
54401 + }
54402 +
54403 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54404 + if (!(gr_status & GR_READY)) {
54405 + read_unlock(&grsec_exec_file_lock);
54406 + read_unlock(&tasklist_lock);
54407 + return 0;
54408 + }
54409 +#endif
54410 +
54411 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
54412 + read_unlock(&grsec_exec_file_lock);
54413 + read_unlock(&tasklist_lock);
54414 +
54415 + if (retmode & GR_NOPTRACE)
54416 + return 1;
54417 +
54418 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
54419 + && (current->acl != task->acl || (current->acl != current->role->root_label
54420 + && current->pid != task->pid)))
54421 + return 1;
54422 +
54423 + return 0;
54424 +}
54425 +
54426 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
54427 +{
54428 + if (unlikely(!(gr_status & GR_READY)))
54429 + return;
54430 +
54431 + if (!(current->role->roletype & GR_ROLE_GOD))
54432 + return;
54433 +
54434 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
54435 + p->role->rolename, gr_task_roletype_to_char(p),
54436 + p->acl->filename);
54437 +}
54438 +
54439 +int
54440 +gr_handle_ptrace(struct task_struct *task, const long request)
54441 +{
54442 + struct task_struct *tmp = task;
54443 + struct task_struct *curtemp = current;
54444 + __u32 retmode;
54445 +
54446 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
54447 + if (unlikely(!(gr_status & GR_READY)))
54448 + return 0;
54449 +#endif
54450 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
54451 + read_lock(&tasklist_lock);
54452 + while (tmp->pid > 0) {
54453 + if (tmp == curtemp)
54454 + break;
54455 + tmp = tmp->real_parent;
54456 + }
54457 +
54458 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
54459 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
54460 + read_unlock(&tasklist_lock);
54461 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54462 + return 1;
54463 + }
54464 + read_unlock(&tasklist_lock);
54465 + }
54466 +
54467 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
54468 + if (!(gr_status & GR_READY))
54469 + return 0;
54470 +#endif
54471 +
54472 + read_lock(&grsec_exec_file_lock);
54473 + if (unlikely(!task->exec_file)) {
54474 + read_unlock(&grsec_exec_file_lock);
54475 + return 0;
54476 + }
54477 +
54478 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
54479 + read_unlock(&grsec_exec_file_lock);
54480 +
54481 + if (retmode & GR_NOPTRACE) {
54482 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54483 + return 1;
54484 + }
54485 +
54486 + if (retmode & GR_PTRACERD) {
54487 + switch (request) {
54488 + case PTRACE_SEIZE:
54489 + case PTRACE_POKETEXT:
54490 + case PTRACE_POKEDATA:
54491 + case PTRACE_POKEUSR:
54492 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
54493 + case PTRACE_SETREGS:
54494 + case PTRACE_SETFPREGS:
54495 +#endif
54496 +#ifdef CONFIG_X86
54497 + case PTRACE_SETFPXREGS:
54498 +#endif
54499 +#ifdef CONFIG_ALTIVEC
54500 + case PTRACE_SETVRREGS:
54501 +#endif
54502 + return 1;
54503 + default:
54504 + return 0;
54505 + }
54506 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
54507 + !(current->role->roletype & GR_ROLE_GOD) &&
54508 + (current->acl != task->acl)) {
54509 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
54510 + return 1;
54511 + }
54512 +
54513 + return 0;
54514 +}
54515 +
54516 +static int is_writable_mmap(const struct file *filp)
54517 +{
54518 + struct task_struct *task = current;
54519 + struct acl_object_label *obj, *obj2;
54520 +
54521 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
54522 + !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))) {
54523 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54524 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
54525 + task->role->root_label);
54526 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
54527 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
54528 + return 1;
54529 + }
54530 + }
54531 + return 0;
54532 +}
54533 +
54534 +int
54535 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
54536 +{
54537 + __u32 mode;
54538 +
54539 + if (unlikely(!file || !(prot & PROT_EXEC)))
54540 + return 1;
54541 +
54542 + if (is_writable_mmap(file))
54543 + return 0;
54544 +
54545 + mode =
54546 + gr_search_file(file->f_path.dentry,
54547 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54548 + file->f_path.mnt);
54549 +
54550 + if (!gr_tpe_allow(file))
54551 + return 0;
54552 +
54553 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54554 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54555 + return 0;
54556 + } else if (unlikely(!(mode & GR_EXEC))) {
54557 + return 0;
54558 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54559 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54560 + return 1;
54561 + }
54562 +
54563 + return 1;
54564 +}
54565 +
54566 +int
54567 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
54568 +{
54569 + __u32 mode;
54570 +
54571 + if (unlikely(!file || !(prot & PROT_EXEC)))
54572 + return 1;
54573 +
54574 + if (is_writable_mmap(file))
54575 + return 0;
54576 +
54577 + mode =
54578 + gr_search_file(file->f_path.dentry,
54579 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
54580 + file->f_path.mnt);
54581 +
54582 + if (!gr_tpe_allow(file))
54583 + return 0;
54584 +
54585 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
54586 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54587 + return 0;
54588 + } else if (unlikely(!(mode & GR_EXEC))) {
54589 + return 0;
54590 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
54591 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
54592 + return 1;
54593 + }
54594 +
54595 + return 1;
54596 +}
54597 +
54598 +void
54599 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54600 +{
54601 + unsigned long runtime;
54602 + unsigned long cputime;
54603 + unsigned int wday, cday;
54604 + __u8 whr, chr;
54605 + __u8 wmin, cmin;
54606 + __u8 wsec, csec;
54607 + struct timespec timeval;
54608 +
54609 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
54610 + !(task->acl->mode & GR_PROCACCT)))
54611 + return;
54612 +
54613 + do_posix_clock_monotonic_gettime(&timeval);
54614 + runtime = timeval.tv_sec - task->start_time.tv_sec;
54615 + wday = runtime / (3600 * 24);
54616 + runtime -= wday * (3600 * 24);
54617 + whr = runtime / 3600;
54618 + runtime -= whr * 3600;
54619 + wmin = runtime / 60;
54620 + runtime -= wmin * 60;
54621 + wsec = runtime;
54622 +
54623 + cputime = (task->utime + task->stime) / HZ;
54624 + cday = cputime / (3600 * 24);
54625 + cputime -= cday * (3600 * 24);
54626 + chr = cputime / 3600;
54627 + cputime -= chr * 3600;
54628 + cmin = cputime / 60;
54629 + cputime -= cmin * 60;
54630 + csec = cputime;
54631 +
54632 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
54633 +
54634 + return;
54635 +}
54636 +
54637 +void gr_set_kernel_label(struct task_struct *task)
54638 +{
54639 + if (gr_status & GR_READY) {
54640 + task->role = kernel_role;
54641 + task->acl = kernel_role->root_label;
54642 + }
54643 + return;
54644 +}
54645 +
54646 +#ifdef CONFIG_TASKSTATS
54647 +int gr_is_taskstats_denied(int pid)
54648 +{
54649 + struct task_struct *task;
54650 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54651 + const struct cred *cred;
54652 +#endif
54653 + int ret = 0;
54654 +
54655 + /* restrict taskstats viewing to un-chrooted root users
54656 + who have the 'view' subject flag if the RBAC system is enabled
54657 + */
54658 +
54659 + rcu_read_lock();
54660 + read_lock(&tasklist_lock);
54661 + task = find_task_by_vpid(pid);
54662 + if (task) {
54663 +#ifdef CONFIG_GRKERNSEC_CHROOT
54664 + if (proc_is_chrooted(task))
54665 + ret = -EACCES;
54666 +#endif
54667 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54668 + cred = __task_cred(task);
54669 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54670 + if (cred->uid != 0)
54671 + ret = -EACCES;
54672 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54673 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
54674 + ret = -EACCES;
54675 +#endif
54676 +#endif
54677 + if (gr_status & GR_READY) {
54678 + if (!(task->acl->mode & GR_VIEW))
54679 + ret = -EACCES;
54680 + }
54681 + } else
54682 + ret = -ENOENT;
54683 +
54684 + read_unlock(&tasklist_lock);
54685 + rcu_read_unlock();
54686 +
54687 + return ret;
54688 +}
54689 +#endif
54690 +
54691 +/* AUXV entries are filled via a descendant of search_binary_handler
54692 + after we've already applied the subject for the target
54693 +*/
54694 +int gr_acl_enable_at_secure(void)
54695 +{
54696 + if (unlikely(!(gr_status & GR_READY)))
54697 + return 0;
54698 +
54699 + if (current->acl->mode & GR_ATSECURE)
54700 + return 1;
54701 +
54702 + return 0;
54703 +}
54704 +
54705 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
54706 +{
54707 + struct task_struct *task = current;
54708 + struct dentry *dentry = file->f_path.dentry;
54709 + struct vfsmount *mnt = file->f_path.mnt;
54710 + struct acl_object_label *obj, *tmp;
54711 + struct acl_subject_label *subj;
54712 + unsigned int bufsize;
54713 + int is_not_root;
54714 + char *path;
54715 + dev_t dev = __get_dev(dentry);
54716 +
54717 + if (unlikely(!(gr_status & GR_READY)))
54718 + return 1;
54719 +
54720 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54721 + return 1;
54722 +
54723 + /* ignore Eric Biederman */
54724 + if (IS_PRIVATE(dentry->d_inode))
54725 + return 1;
54726 +
54727 + subj = task->acl;
54728 + do {
54729 + obj = lookup_acl_obj_label(ino, dev, subj);
54730 + if (obj != NULL)
54731 + return (obj->mode & GR_FIND) ? 1 : 0;
54732 + } while ((subj = subj->parent_subject));
54733 +
54734 + /* this is purely an optimization since we're looking for an object
54735 + for the directory we're doing a readdir on
54736 + if it's possible for any globbed object to match the entry we're
54737 + filling into the directory, then the object we find here will be
54738 + an anchor point with attached globbed objects
54739 + */
54740 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
54741 + if (obj->globbed == NULL)
54742 + return (obj->mode & GR_FIND) ? 1 : 0;
54743 +
54744 + is_not_root = ((obj->filename[0] == '/') &&
54745 + (obj->filename[1] == '\0')) ? 0 : 1;
54746 + bufsize = PAGE_SIZE - namelen - is_not_root;
54747 +
54748 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
54749 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
54750 + return 1;
54751 +
54752 + preempt_disable();
54753 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54754 + bufsize);
54755 +
54756 + bufsize = strlen(path);
54757 +
54758 + /* if base is "/", don't append an additional slash */
54759 + if (is_not_root)
54760 + *(path + bufsize) = '/';
54761 + memcpy(path + bufsize + is_not_root, name, namelen);
54762 + *(path + bufsize + namelen + is_not_root) = '\0';
54763 +
54764 + tmp = obj->globbed;
54765 + while (tmp) {
54766 + if (!glob_match(tmp->filename, path)) {
54767 + preempt_enable();
54768 + return (tmp->mode & GR_FIND) ? 1 : 0;
54769 + }
54770 + tmp = tmp->next;
54771 + }
54772 + preempt_enable();
54773 + return (obj->mode & GR_FIND) ? 1 : 0;
54774 +}
54775 +
54776 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
54777 +EXPORT_SYMBOL(gr_acl_is_enabled);
54778 +#endif
54779 +EXPORT_SYMBOL(gr_learn_resource);
54780 +EXPORT_SYMBOL(gr_set_kernel_label);
54781 +#ifdef CONFIG_SECURITY
54782 +EXPORT_SYMBOL(gr_check_user_change);
54783 +EXPORT_SYMBOL(gr_check_group_change);
54784 +#endif
54785 +
54786 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
54787 new file mode 100644
54788 index 0000000..34fefda
54789 --- /dev/null
54790 +++ b/grsecurity/gracl_alloc.c
54791 @@ -0,0 +1,105 @@
54792 +#include <linux/kernel.h>
54793 +#include <linux/mm.h>
54794 +#include <linux/slab.h>
54795 +#include <linux/vmalloc.h>
54796 +#include <linux/gracl.h>
54797 +#include <linux/grsecurity.h>
54798 +
54799 +static unsigned long alloc_stack_next = 1;
54800 +static unsigned long alloc_stack_size = 1;
54801 +static void **alloc_stack;
54802 +
54803 +static __inline__ int
54804 +alloc_pop(void)
54805 +{
54806 + if (alloc_stack_next == 1)
54807 + return 0;
54808 +
54809 + kfree(alloc_stack[alloc_stack_next - 2]);
54810 +
54811 + alloc_stack_next--;
54812 +
54813 + return 1;
54814 +}
54815 +
54816 +static __inline__ int
54817 +alloc_push(void *buf)
54818 +{
54819 + if (alloc_stack_next >= alloc_stack_size)
54820 + return 1;
54821 +
54822 + alloc_stack[alloc_stack_next - 1] = buf;
54823 +
54824 + alloc_stack_next++;
54825 +
54826 + return 0;
54827 +}
54828 +
54829 +void *
54830 +acl_alloc(unsigned long len)
54831 +{
54832 + void *ret = NULL;
54833 +
54834 + if (!len || len > PAGE_SIZE)
54835 + goto out;
54836 +
54837 + ret = kmalloc(len, GFP_KERNEL);
54838 +
54839 + if (ret) {
54840 + if (alloc_push(ret)) {
54841 + kfree(ret);
54842 + ret = NULL;
54843 + }
54844 + }
54845 +
54846 +out:
54847 + return ret;
54848 +}
54849 +
54850 +void *
54851 +acl_alloc_num(unsigned long num, unsigned long len)
54852 +{
54853 + if (!len || (num > (PAGE_SIZE / len)))
54854 + return NULL;
54855 +
54856 + return acl_alloc(num * len);
54857 +}
54858 +
54859 +void
54860 +acl_free_all(void)
54861 +{
54862 + if (gr_acl_is_enabled() || !alloc_stack)
54863 + return;
54864 +
54865 + while (alloc_pop()) ;
54866 +
54867 + if (alloc_stack) {
54868 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
54869 + kfree(alloc_stack);
54870 + else
54871 + vfree(alloc_stack);
54872 + }
54873 +
54874 + alloc_stack = NULL;
54875 + alloc_stack_size = 1;
54876 + alloc_stack_next = 1;
54877 +
54878 + return;
54879 +}
54880 +
54881 +int
54882 +acl_alloc_stack_init(unsigned long size)
54883 +{
54884 + if ((size * sizeof (void *)) <= PAGE_SIZE)
54885 + alloc_stack =
54886 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
54887 + else
54888 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
54889 +
54890 + alloc_stack_size = size;
54891 +
54892 + if (!alloc_stack)
54893 + return 0;
54894 + else
54895 + return 1;
54896 +}
54897 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
54898 new file mode 100644
54899 index 0000000..6d21049
54900 --- /dev/null
54901 +++ b/grsecurity/gracl_cap.c
54902 @@ -0,0 +1,110 @@
54903 +#include <linux/kernel.h>
54904 +#include <linux/module.h>
54905 +#include <linux/sched.h>
54906 +#include <linux/gracl.h>
54907 +#include <linux/grsecurity.h>
54908 +#include <linux/grinternal.h>
54909 +
54910 +extern const char *captab_log[];
54911 +extern int captab_log_entries;
54912 +
54913 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
54914 +{
54915 + struct acl_subject_label *curracl;
54916 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54917 + kernel_cap_t cap_audit = __cap_empty_set;
54918 +
54919 + if (!gr_acl_is_enabled())
54920 + return 1;
54921 +
54922 + curracl = task->acl;
54923 +
54924 + cap_drop = curracl->cap_lower;
54925 + cap_mask = curracl->cap_mask;
54926 + cap_audit = curracl->cap_invert_audit;
54927 +
54928 + while ((curracl = curracl->parent_subject)) {
54929 + /* if the cap isn't specified in the current computed mask but is specified in the
54930 + current level subject, and is lowered in the current level subject, then add
54931 + it to the set of dropped capabilities
54932 + otherwise, add the current level subject's mask to the current computed mask
54933 + */
54934 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54935 + cap_raise(cap_mask, cap);
54936 + if (cap_raised(curracl->cap_lower, cap))
54937 + cap_raise(cap_drop, cap);
54938 + if (cap_raised(curracl->cap_invert_audit, cap))
54939 + cap_raise(cap_audit, cap);
54940 + }
54941 + }
54942 +
54943 + if (!cap_raised(cap_drop, cap)) {
54944 + if (cap_raised(cap_audit, cap))
54945 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
54946 + return 1;
54947 + }
54948 +
54949 + curracl = task->acl;
54950 +
54951 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
54952 + && cap_raised(cred->cap_effective, cap)) {
54953 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
54954 + task->role->roletype, cred->uid,
54955 + cred->gid, task->exec_file ?
54956 + gr_to_filename(task->exec_file->f_path.dentry,
54957 + task->exec_file->f_path.mnt) : curracl->filename,
54958 + curracl->filename, 0UL,
54959 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
54960 + return 1;
54961 + }
54962 +
54963 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
54964 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
54965 +
54966 + return 0;
54967 +}
54968 +
54969 +int
54970 +gr_acl_is_capable(const int cap)
54971 +{
54972 + return gr_task_acl_is_capable(current, current_cred(), cap);
54973 +}
54974 +
54975 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
54976 +{
54977 + struct acl_subject_label *curracl;
54978 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
54979 +
54980 + if (!gr_acl_is_enabled())
54981 + return 1;
54982 +
54983 + curracl = task->acl;
54984 +
54985 + cap_drop = curracl->cap_lower;
54986 + cap_mask = curracl->cap_mask;
54987 +
54988 + while ((curracl = curracl->parent_subject)) {
54989 + /* if the cap isn't specified in the current computed mask but is specified in the
54990 + current level subject, and is lowered in the current level subject, then add
54991 + it to the set of dropped capabilities
54992 + otherwise, add the current level subject's mask to the current computed mask
54993 + */
54994 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
54995 + cap_raise(cap_mask, cap);
54996 + if (cap_raised(curracl->cap_lower, cap))
54997 + cap_raise(cap_drop, cap);
54998 + }
54999 + }
55000 +
55001 + if (!cap_raised(cap_drop, cap))
55002 + return 1;
55003 +
55004 + return 0;
55005 +}
55006 +
55007 +int
55008 +gr_acl_is_capable_nolog(const int cap)
55009 +{
55010 + return gr_task_acl_is_capable_nolog(current, cap);
55011 +}
55012 +
55013 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55014 new file mode 100644
55015 index 0000000..88d0e87
55016 --- /dev/null
55017 +++ b/grsecurity/gracl_fs.c
55018 @@ -0,0 +1,435 @@
55019 +#include <linux/kernel.h>
55020 +#include <linux/sched.h>
55021 +#include <linux/types.h>
55022 +#include <linux/fs.h>
55023 +#include <linux/file.h>
55024 +#include <linux/stat.h>
55025 +#include <linux/grsecurity.h>
55026 +#include <linux/grinternal.h>
55027 +#include <linux/gracl.h>
55028 +
55029 +umode_t
55030 +gr_acl_umask(void)
55031 +{
55032 + if (unlikely(!gr_acl_is_enabled()))
55033 + return 0;
55034 +
55035 + return current->role->umask;
55036 +}
55037 +
55038 +__u32
55039 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55040 + const struct vfsmount * mnt)
55041 +{
55042 + __u32 mode;
55043 +
55044 + if (unlikely(!dentry->d_inode))
55045 + return GR_FIND;
55046 +
55047 + mode =
55048 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55049 +
55050 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55051 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55052 + return mode;
55053 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55054 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55055 + return 0;
55056 + } else if (unlikely(!(mode & GR_FIND)))
55057 + return 0;
55058 +
55059 + return GR_FIND;
55060 +}
55061 +
55062 +__u32
55063 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55064 + int acc_mode)
55065 +{
55066 + __u32 reqmode = GR_FIND;
55067 + __u32 mode;
55068 +
55069 + if (unlikely(!dentry->d_inode))
55070 + return reqmode;
55071 +
55072 + if (acc_mode & MAY_APPEND)
55073 + reqmode |= GR_APPEND;
55074 + else if (acc_mode & MAY_WRITE)
55075 + reqmode |= GR_WRITE;
55076 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55077 + reqmode |= GR_READ;
55078 +
55079 + mode =
55080 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55081 + mnt);
55082 +
55083 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55084 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55085 + reqmode & GR_READ ? " reading" : "",
55086 + reqmode & GR_WRITE ? " writing" : reqmode &
55087 + GR_APPEND ? " appending" : "");
55088 + return reqmode;
55089 + } else
55090 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55091 + {
55092 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55093 + reqmode & GR_READ ? " reading" : "",
55094 + reqmode & GR_WRITE ? " writing" : reqmode &
55095 + GR_APPEND ? " appending" : "");
55096 + return 0;
55097 + } else if (unlikely((mode & reqmode) != reqmode))
55098 + return 0;
55099 +
55100 + return reqmode;
55101 +}
55102 +
55103 +__u32
55104 +gr_acl_handle_creat(const struct dentry * dentry,
55105 + const struct dentry * p_dentry,
55106 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55107 + const int imode)
55108 +{
55109 + __u32 reqmode = GR_WRITE | GR_CREATE;
55110 + __u32 mode;
55111 +
55112 + if (acc_mode & MAY_APPEND)
55113 + reqmode |= GR_APPEND;
55114 + // if a directory was required or the directory already exists, then
55115 + // don't count this open as a read
55116 + if ((acc_mode & MAY_READ) &&
55117 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55118 + reqmode |= GR_READ;
55119 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
55120 + reqmode |= GR_SETID;
55121 +
55122 + mode =
55123 + gr_check_create(dentry, p_dentry, p_mnt,
55124 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55125 +
55126 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55127 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55128 + reqmode & GR_READ ? " reading" : "",
55129 + reqmode & GR_WRITE ? " writing" : reqmode &
55130 + GR_APPEND ? " appending" : "");
55131 + return reqmode;
55132 + } else
55133 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55134 + {
55135 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55136 + reqmode & GR_READ ? " reading" : "",
55137 + reqmode & GR_WRITE ? " writing" : reqmode &
55138 + GR_APPEND ? " appending" : "");
55139 + return 0;
55140 + } else if (unlikely((mode & reqmode) != reqmode))
55141 + return 0;
55142 +
55143 + return reqmode;
55144 +}
55145 +
55146 +__u32
55147 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55148 + const int fmode)
55149 +{
55150 + __u32 mode, reqmode = GR_FIND;
55151 +
55152 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55153 + reqmode |= GR_EXEC;
55154 + if (fmode & S_IWOTH)
55155 + reqmode |= GR_WRITE;
55156 + if (fmode & S_IROTH)
55157 + reqmode |= GR_READ;
55158 +
55159 + mode =
55160 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55161 + mnt);
55162 +
55163 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55164 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55165 + reqmode & GR_READ ? " reading" : "",
55166 + reqmode & GR_WRITE ? " writing" : "",
55167 + reqmode & GR_EXEC ? " executing" : "");
55168 + return reqmode;
55169 + } else
55170 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55171 + {
55172 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55173 + reqmode & GR_READ ? " reading" : "",
55174 + reqmode & GR_WRITE ? " writing" : "",
55175 + reqmode & GR_EXEC ? " executing" : "");
55176 + return 0;
55177 + } else if (unlikely((mode & reqmode) != reqmode))
55178 + return 0;
55179 +
55180 + return reqmode;
55181 +}
55182 +
55183 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55184 +{
55185 + __u32 mode;
55186 +
55187 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55188 +
55189 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55190 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55191 + return mode;
55192 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55193 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55194 + return 0;
55195 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55196 + return 0;
55197 +
55198 + return (reqmode);
55199 +}
55200 +
55201 +__u32
55202 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55203 +{
55204 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55205 +}
55206 +
55207 +__u32
55208 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55209 +{
55210 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
55211 +}
55212 +
55213 +__u32
55214 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
55215 +{
55216 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
55217 +}
55218 +
55219 +__u32
55220 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
55221 +{
55222 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
55223 +}
55224 +
55225 +__u32
55226 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
55227 + umode_t *modeptr)
55228 +{
55229 + umode_t mode;
55230 +
55231 + *modeptr &= ~gr_acl_umask();
55232 + mode = *modeptr;
55233 +
55234 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
55235 + return 1;
55236 +
55237 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
55238 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
55239 + GR_CHMOD_ACL_MSG);
55240 + } else {
55241 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
55242 + }
55243 +}
55244 +
55245 +__u32
55246 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
55247 +{
55248 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
55249 +}
55250 +
55251 +__u32
55252 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
55253 +{
55254 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
55255 +}
55256 +
55257 +__u32
55258 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
55259 +{
55260 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
55261 +}
55262 +
55263 +__u32
55264 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
55265 +{
55266 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
55267 + GR_UNIXCONNECT_ACL_MSG);
55268 +}
55269 +
55270 +/* hardlinks require at minimum create and link permission,
55271 + any additional privilege required is based on the
55272 + privilege of the file being linked to
55273 +*/
55274 +__u32
55275 +gr_acl_handle_link(const struct dentry * new_dentry,
55276 + const struct dentry * parent_dentry,
55277 + const struct vfsmount * parent_mnt,
55278 + const struct dentry * old_dentry,
55279 + const struct vfsmount * old_mnt, const char *to)
55280 +{
55281 + __u32 mode;
55282 + __u32 needmode = GR_CREATE | GR_LINK;
55283 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
55284 +
55285 + mode =
55286 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
55287 + old_mnt);
55288 +
55289 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
55290 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55291 + return mode;
55292 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55293 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
55294 + return 0;
55295 + } else if (unlikely((mode & needmode) != needmode))
55296 + return 0;
55297 +
55298 + return 1;
55299 +}
55300 +
55301 +__u32
55302 +gr_acl_handle_symlink(const struct dentry * new_dentry,
55303 + const struct dentry * parent_dentry,
55304 + const struct vfsmount * parent_mnt, const char *from)
55305 +{
55306 + __u32 needmode = GR_WRITE | GR_CREATE;
55307 + __u32 mode;
55308 +
55309 + mode =
55310 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
55311 + GR_CREATE | GR_AUDIT_CREATE |
55312 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
55313 +
55314 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
55315 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55316 + return mode;
55317 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
55318 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
55319 + return 0;
55320 + } else if (unlikely((mode & needmode) != needmode))
55321 + return 0;
55322 +
55323 + return (GR_WRITE | GR_CREATE);
55324 +}
55325 +
55326 +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)
55327 +{
55328 + __u32 mode;
55329 +
55330 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55331 +
55332 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55333 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
55334 + return mode;
55335 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55336 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
55337 + return 0;
55338 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55339 + return 0;
55340 +
55341 + return (reqmode);
55342 +}
55343 +
55344 +__u32
55345 +gr_acl_handle_mknod(const struct dentry * new_dentry,
55346 + const struct dentry * parent_dentry,
55347 + const struct vfsmount * parent_mnt,
55348 + const int mode)
55349 +{
55350 + __u32 reqmode = GR_WRITE | GR_CREATE;
55351 + if (unlikely(mode & (S_ISUID | S_ISGID)))
55352 + reqmode |= GR_SETID;
55353 +
55354 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55355 + reqmode, GR_MKNOD_ACL_MSG);
55356 +}
55357 +
55358 +__u32
55359 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
55360 + const struct dentry *parent_dentry,
55361 + const struct vfsmount *parent_mnt)
55362 +{
55363 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
55364 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
55365 +}
55366 +
55367 +#define RENAME_CHECK_SUCCESS(old, new) \
55368 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
55369 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
55370 +
55371 +int
55372 +gr_acl_handle_rename(struct dentry *new_dentry,
55373 + struct dentry *parent_dentry,
55374 + const struct vfsmount *parent_mnt,
55375 + struct dentry *old_dentry,
55376 + struct inode *old_parent_inode,
55377 + struct vfsmount *old_mnt, const char *newname)
55378 +{
55379 + __u32 comp1, comp2;
55380 + int error = 0;
55381 +
55382 + if (unlikely(!gr_acl_is_enabled()))
55383 + return 0;
55384 +
55385 + if (!new_dentry->d_inode) {
55386 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
55387 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
55388 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
55389 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
55390 + GR_DELETE | GR_AUDIT_DELETE |
55391 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55392 + GR_SUPPRESS, old_mnt);
55393 + } else {
55394 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
55395 + GR_CREATE | GR_DELETE |
55396 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
55397 + GR_AUDIT_READ | GR_AUDIT_WRITE |
55398 + GR_SUPPRESS, parent_mnt);
55399 + comp2 =
55400 + gr_search_file(old_dentry,
55401 + GR_READ | GR_WRITE | GR_AUDIT_READ |
55402 + GR_DELETE | GR_AUDIT_DELETE |
55403 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
55404 + }
55405 +
55406 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
55407 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
55408 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55409 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
55410 + && !(comp2 & GR_SUPPRESS)) {
55411 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
55412 + error = -EACCES;
55413 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
55414 + error = -EACCES;
55415 +
55416 + return error;
55417 +}
55418 +
55419 +void
55420 +gr_acl_handle_exit(void)
55421 +{
55422 + u16 id;
55423 + char *rolename;
55424 + struct file *exec_file;
55425 +
55426 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
55427 + !(current->role->roletype & GR_ROLE_PERSIST))) {
55428 + id = current->acl_role_id;
55429 + rolename = current->role->rolename;
55430 + gr_set_acls(1);
55431 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
55432 + }
55433 +
55434 + write_lock(&grsec_exec_file_lock);
55435 + exec_file = current->exec_file;
55436 + current->exec_file = NULL;
55437 + write_unlock(&grsec_exec_file_lock);
55438 +
55439 + if (exec_file)
55440 + fput(exec_file);
55441 +}
55442 +
55443 +int
55444 +gr_acl_handle_procpidmem(const struct task_struct *task)
55445 +{
55446 + if (unlikely(!gr_acl_is_enabled()))
55447 + return 0;
55448 +
55449 + if (task != current && task->acl->mode & GR_PROTPROCFD)
55450 + return -EACCES;
55451 +
55452 + return 0;
55453 +}
55454 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
55455 new file mode 100644
55456 index 0000000..58800a7
55457 --- /dev/null
55458 +++ b/grsecurity/gracl_ip.c
55459 @@ -0,0 +1,384 @@
55460 +#include <linux/kernel.h>
55461 +#include <asm/uaccess.h>
55462 +#include <asm/errno.h>
55463 +#include <net/sock.h>
55464 +#include <linux/file.h>
55465 +#include <linux/fs.h>
55466 +#include <linux/net.h>
55467 +#include <linux/in.h>
55468 +#include <linux/skbuff.h>
55469 +#include <linux/ip.h>
55470 +#include <linux/udp.h>
55471 +#include <linux/types.h>
55472 +#include <linux/sched.h>
55473 +#include <linux/netdevice.h>
55474 +#include <linux/inetdevice.h>
55475 +#include <linux/gracl.h>
55476 +#include <linux/grsecurity.h>
55477 +#include <linux/grinternal.h>
55478 +
55479 +#define GR_BIND 0x01
55480 +#define GR_CONNECT 0x02
55481 +#define GR_INVERT 0x04
55482 +#define GR_BINDOVERRIDE 0x08
55483 +#define GR_CONNECTOVERRIDE 0x10
55484 +#define GR_SOCK_FAMILY 0x20
55485 +
55486 +static const char * gr_protocols[IPPROTO_MAX] = {
55487 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
55488 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
55489 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
55490 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
55491 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
55492 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
55493 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
55494 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
55495 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
55496 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
55497 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
55498 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
55499 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
55500 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
55501 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
55502 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
55503 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
55504 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
55505 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
55506 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
55507 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
55508 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
55509 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
55510 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
55511 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
55512 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
55513 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
55514 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
55515 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
55516 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
55517 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
55518 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
55519 + };
55520 +
55521 +static const char * gr_socktypes[SOCK_MAX] = {
55522 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
55523 + "unknown:7", "unknown:8", "unknown:9", "packet"
55524 + };
55525 +
55526 +static const char * gr_sockfamilies[AF_MAX+1] = {
55527 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
55528 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
55529 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
55530 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
55531 + };
55532 +
55533 +const char *
55534 +gr_proto_to_name(unsigned char proto)
55535 +{
55536 + return gr_protocols[proto];
55537 +}
55538 +
55539 +const char *
55540 +gr_socktype_to_name(unsigned char type)
55541 +{
55542 + return gr_socktypes[type];
55543 +}
55544 +
55545 +const char *
55546 +gr_sockfamily_to_name(unsigned char family)
55547 +{
55548 + return gr_sockfamilies[family];
55549 +}
55550 +
55551 +int
55552 +gr_search_socket(const int domain, const int type, const int protocol)
55553 +{
55554 + struct acl_subject_label *curr;
55555 + const struct cred *cred = current_cred();
55556 +
55557 + if (unlikely(!gr_acl_is_enabled()))
55558 + goto exit;
55559 +
55560 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
55561 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
55562 + goto exit; // let the kernel handle it
55563 +
55564 + curr = current->acl;
55565 +
55566 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
55567 + /* the family is allowed, if this is PF_INET allow it only if
55568 + the extra sock type/protocol checks pass */
55569 + if (domain == PF_INET)
55570 + goto inet_check;
55571 + goto exit;
55572 + } else {
55573 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55574 + __u32 fakeip = 0;
55575 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55576 + current->role->roletype, cred->uid,
55577 + cred->gid, current->exec_file ?
55578 + gr_to_filename(current->exec_file->f_path.dentry,
55579 + current->exec_file->f_path.mnt) :
55580 + curr->filename, curr->filename,
55581 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
55582 + &current->signal->saved_ip);
55583 + goto exit;
55584 + }
55585 + goto exit_fail;
55586 + }
55587 +
55588 +inet_check:
55589 + /* the rest of this checking is for IPv4 only */
55590 + if (!curr->ips)
55591 + goto exit;
55592 +
55593 + if ((curr->ip_type & (1 << type)) &&
55594 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
55595 + goto exit;
55596 +
55597 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55598 + /* we don't place acls on raw sockets , and sometimes
55599 + dgram/ip sockets are opened for ioctl and not
55600 + bind/connect, so we'll fake a bind learn log */
55601 + if (type == SOCK_RAW || type == SOCK_PACKET) {
55602 + __u32 fakeip = 0;
55603 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55604 + current->role->roletype, cred->uid,
55605 + cred->gid, current->exec_file ?
55606 + gr_to_filename(current->exec_file->f_path.dentry,
55607 + current->exec_file->f_path.mnt) :
55608 + curr->filename, curr->filename,
55609 + &fakeip, 0, type,
55610 + protocol, GR_CONNECT, &current->signal->saved_ip);
55611 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
55612 + __u32 fakeip = 0;
55613 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55614 + current->role->roletype, cred->uid,
55615 + cred->gid, current->exec_file ?
55616 + gr_to_filename(current->exec_file->f_path.dentry,
55617 + current->exec_file->f_path.mnt) :
55618 + curr->filename, curr->filename,
55619 + &fakeip, 0, type,
55620 + protocol, GR_BIND, &current->signal->saved_ip);
55621 + }
55622 + /* we'll log when they use connect or bind */
55623 + goto exit;
55624 + }
55625 +
55626 +exit_fail:
55627 + if (domain == PF_INET)
55628 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
55629 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
55630 + else
55631 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
55632 + gr_socktype_to_name(type), protocol);
55633 +
55634 + return 0;
55635 +exit:
55636 + return 1;
55637 +}
55638 +
55639 +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)
55640 +{
55641 + if ((ip->mode & mode) &&
55642 + (ip_port >= ip->low) &&
55643 + (ip_port <= ip->high) &&
55644 + ((ntohl(ip_addr) & our_netmask) ==
55645 + (ntohl(our_addr) & our_netmask))
55646 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
55647 + && (ip->type & (1 << type))) {
55648 + if (ip->mode & GR_INVERT)
55649 + return 2; // specifically denied
55650 + else
55651 + return 1; // allowed
55652 + }
55653 +
55654 + return 0; // not specifically allowed, may continue parsing
55655 +}
55656 +
55657 +static int
55658 +gr_search_connectbind(const int full_mode, struct sock *sk,
55659 + struct sockaddr_in *addr, const int type)
55660 +{
55661 + char iface[IFNAMSIZ] = {0};
55662 + struct acl_subject_label *curr;
55663 + struct acl_ip_label *ip;
55664 + struct inet_sock *isk;
55665 + struct net_device *dev;
55666 + struct in_device *idev;
55667 + unsigned long i;
55668 + int ret;
55669 + int mode = full_mode & (GR_BIND | GR_CONNECT);
55670 + __u32 ip_addr = 0;
55671 + __u32 our_addr;
55672 + __u32 our_netmask;
55673 + char *p;
55674 + __u16 ip_port = 0;
55675 + const struct cred *cred = current_cred();
55676 +
55677 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
55678 + return 0;
55679 +
55680 + curr = current->acl;
55681 + isk = inet_sk(sk);
55682 +
55683 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
55684 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
55685 + addr->sin_addr.s_addr = curr->inaddr_any_override;
55686 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
55687 + struct sockaddr_in saddr;
55688 + int err;
55689 +
55690 + saddr.sin_family = AF_INET;
55691 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
55692 + saddr.sin_port = isk->inet_sport;
55693 +
55694 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55695 + if (err)
55696 + return err;
55697 +
55698 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
55699 + if (err)
55700 + return err;
55701 + }
55702 +
55703 + if (!curr->ips)
55704 + return 0;
55705 +
55706 + ip_addr = addr->sin_addr.s_addr;
55707 + ip_port = ntohs(addr->sin_port);
55708 +
55709 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
55710 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
55711 + current->role->roletype, cred->uid,
55712 + cred->gid, current->exec_file ?
55713 + gr_to_filename(current->exec_file->f_path.dentry,
55714 + current->exec_file->f_path.mnt) :
55715 + curr->filename, curr->filename,
55716 + &ip_addr, ip_port, type,
55717 + sk->sk_protocol, mode, &current->signal->saved_ip);
55718 + return 0;
55719 + }
55720 +
55721 + for (i = 0; i < curr->ip_num; i++) {
55722 + ip = *(curr->ips + i);
55723 + if (ip->iface != NULL) {
55724 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
55725 + p = strchr(iface, ':');
55726 + if (p != NULL)
55727 + *p = '\0';
55728 + dev = dev_get_by_name(sock_net(sk), iface);
55729 + if (dev == NULL)
55730 + continue;
55731 + idev = in_dev_get(dev);
55732 + if (idev == NULL) {
55733 + dev_put(dev);
55734 + continue;
55735 + }
55736 + rcu_read_lock();
55737 + for_ifa(idev) {
55738 + if (!strcmp(ip->iface, ifa->ifa_label)) {
55739 + our_addr = ifa->ifa_address;
55740 + our_netmask = 0xffffffff;
55741 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55742 + if (ret == 1) {
55743 + rcu_read_unlock();
55744 + in_dev_put(idev);
55745 + dev_put(dev);
55746 + return 0;
55747 + } else if (ret == 2) {
55748 + rcu_read_unlock();
55749 + in_dev_put(idev);
55750 + dev_put(dev);
55751 + goto denied;
55752 + }
55753 + }
55754 + } endfor_ifa(idev);
55755 + rcu_read_unlock();
55756 + in_dev_put(idev);
55757 + dev_put(dev);
55758 + } else {
55759 + our_addr = ip->addr;
55760 + our_netmask = ip->netmask;
55761 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
55762 + if (ret == 1)
55763 + return 0;
55764 + else if (ret == 2)
55765 + goto denied;
55766 + }
55767 + }
55768 +
55769 +denied:
55770 + if (mode == GR_BIND)
55771 + 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));
55772 + else if (mode == GR_CONNECT)
55773 + 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));
55774 +
55775 + return -EACCES;
55776 +}
55777 +
55778 +int
55779 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
55780 +{
55781 + /* always allow disconnection of dgram sockets with connect */
55782 + if (addr->sin_family == AF_UNSPEC)
55783 + return 0;
55784 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
55785 +}
55786 +
55787 +int
55788 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
55789 +{
55790 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
55791 +}
55792 +
55793 +int gr_search_listen(struct socket *sock)
55794 +{
55795 + struct sock *sk = sock->sk;
55796 + struct sockaddr_in addr;
55797 +
55798 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55799 + addr.sin_port = inet_sk(sk)->inet_sport;
55800 +
55801 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55802 +}
55803 +
55804 +int gr_search_accept(struct socket *sock)
55805 +{
55806 + struct sock *sk = sock->sk;
55807 + struct sockaddr_in addr;
55808 +
55809 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
55810 + addr.sin_port = inet_sk(sk)->inet_sport;
55811 +
55812 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
55813 +}
55814 +
55815 +int
55816 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
55817 +{
55818 + if (addr)
55819 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
55820 + else {
55821 + struct sockaddr_in sin;
55822 + const struct inet_sock *inet = inet_sk(sk);
55823 +
55824 + sin.sin_addr.s_addr = inet->inet_daddr;
55825 + sin.sin_port = inet->inet_dport;
55826 +
55827 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55828 + }
55829 +}
55830 +
55831 +int
55832 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
55833 +{
55834 + struct sockaddr_in sin;
55835 +
55836 + if (unlikely(skb->len < sizeof (struct udphdr)))
55837 + return 0; // skip this packet
55838 +
55839 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
55840 + sin.sin_port = udp_hdr(skb)->source;
55841 +
55842 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
55843 +}
55844 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
55845 new file mode 100644
55846 index 0000000..25f54ef
55847 --- /dev/null
55848 +++ b/grsecurity/gracl_learn.c
55849 @@ -0,0 +1,207 @@
55850 +#include <linux/kernel.h>
55851 +#include <linux/mm.h>
55852 +#include <linux/sched.h>
55853 +#include <linux/poll.h>
55854 +#include <linux/string.h>
55855 +#include <linux/file.h>
55856 +#include <linux/types.h>
55857 +#include <linux/vmalloc.h>
55858 +#include <linux/grinternal.h>
55859 +
55860 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
55861 + size_t count, loff_t *ppos);
55862 +extern int gr_acl_is_enabled(void);
55863 +
55864 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
55865 +static int gr_learn_attached;
55866 +
55867 +/* use a 512k buffer */
55868 +#define LEARN_BUFFER_SIZE (512 * 1024)
55869 +
55870 +static DEFINE_SPINLOCK(gr_learn_lock);
55871 +static DEFINE_MUTEX(gr_learn_user_mutex);
55872 +
55873 +/* we need to maintain two buffers, so that the kernel context of grlearn
55874 + uses a semaphore around the userspace copying, and the other kernel contexts
55875 + use a spinlock when copying into the buffer, since they cannot sleep
55876 +*/
55877 +static char *learn_buffer;
55878 +static char *learn_buffer_user;
55879 +static int learn_buffer_len;
55880 +static int learn_buffer_user_len;
55881 +
55882 +static ssize_t
55883 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
55884 +{
55885 + DECLARE_WAITQUEUE(wait, current);
55886 + ssize_t retval = 0;
55887 +
55888 + add_wait_queue(&learn_wait, &wait);
55889 + set_current_state(TASK_INTERRUPTIBLE);
55890 + do {
55891 + mutex_lock(&gr_learn_user_mutex);
55892 + spin_lock(&gr_learn_lock);
55893 + if (learn_buffer_len)
55894 + break;
55895 + spin_unlock(&gr_learn_lock);
55896 + mutex_unlock(&gr_learn_user_mutex);
55897 + if (file->f_flags & O_NONBLOCK) {
55898 + retval = -EAGAIN;
55899 + goto out;
55900 + }
55901 + if (signal_pending(current)) {
55902 + retval = -ERESTARTSYS;
55903 + goto out;
55904 + }
55905 +
55906 + schedule();
55907 + } while (1);
55908 +
55909 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
55910 + learn_buffer_user_len = learn_buffer_len;
55911 + retval = learn_buffer_len;
55912 + learn_buffer_len = 0;
55913 +
55914 + spin_unlock(&gr_learn_lock);
55915 +
55916 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
55917 + retval = -EFAULT;
55918 +
55919 + mutex_unlock(&gr_learn_user_mutex);
55920 +out:
55921 + set_current_state(TASK_RUNNING);
55922 + remove_wait_queue(&learn_wait, &wait);
55923 + return retval;
55924 +}
55925 +
55926 +static unsigned int
55927 +poll_learn(struct file * file, poll_table * wait)
55928 +{
55929 + poll_wait(file, &learn_wait, wait);
55930 +
55931 + if (learn_buffer_len)
55932 + return (POLLIN | POLLRDNORM);
55933 +
55934 + return 0;
55935 +}
55936 +
55937 +void
55938 +gr_clear_learn_entries(void)
55939 +{
55940 + char *tmp;
55941 +
55942 + mutex_lock(&gr_learn_user_mutex);
55943 + spin_lock(&gr_learn_lock);
55944 + tmp = learn_buffer;
55945 + learn_buffer = NULL;
55946 + spin_unlock(&gr_learn_lock);
55947 + if (tmp)
55948 + vfree(tmp);
55949 + if (learn_buffer_user != NULL) {
55950 + vfree(learn_buffer_user);
55951 + learn_buffer_user = NULL;
55952 + }
55953 + learn_buffer_len = 0;
55954 + mutex_unlock(&gr_learn_user_mutex);
55955 +
55956 + return;
55957 +}
55958 +
55959 +void
55960 +gr_add_learn_entry(const char *fmt, ...)
55961 +{
55962 + va_list args;
55963 + unsigned int len;
55964 +
55965 + if (!gr_learn_attached)
55966 + return;
55967 +
55968 + spin_lock(&gr_learn_lock);
55969 +
55970 + /* leave a gap at the end so we know when it's "full" but don't have to
55971 + compute the exact length of the string we're trying to append
55972 + */
55973 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
55974 + spin_unlock(&gr_learn_lock);
55975 + wake_up_interruptible(&learn_wait);
55976 + return;
55977 + }
55978 + if (learn_buffer == NULL) {
55979 + spin_unlock(&gr_learn_lock);
55980 + return;
55981 + }
55982 +
55983 + va_start(args, fmt);
55984 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
55985 + va_end(args);
55986 +
55987 + learn_buffer_len += len + 1;
55988 +
55989 + spin_unlock(&gr_learn_lock);
55990 + wake_up_interruptible(&learn_wait);
55991 +
55992 + return;
55993 +}
55994 +
55995 +static int
55996 +open_learn(struct inode *inode, struct file *file)
55997 +{
55998 + if (file->f_mode & FMODE_READ && gr_learn_attached)
55999 + return -EBUSY;
56000 + if (file->f_mode & FMODE_READ) {
56001 + int retval = 0;
56002 + mutex_lock(&gr_learn_user_mutex);
56003 + if (learn_buffer == NULL)
56004 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56005 + if (learn_buffer_user == NULL)
56006 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56007 + if (learn_buffer == NULL) {
56008 + retval = -ENOMEM;
56009 + goto out_error;
56010 + }
56011 + if (learn_buffer_user == NULL) {
56012 + retval = -ENOMEM;
56013 + goto out_error;
56014 + }
56015 + learn_buffer_len = 0;
56016 + learn_buffer_user_len = 0;
56017 + gr_learn_attached = 1;
56018 +out_error:
56019 + mutex_unlock(&gr_learn_user_mutex);
56020 + return retval;
56021 + }
56022 + return 0;
56023 +}
56024 +
56025 +static int
56026 +close_learn(struct inode *inode, struct file *file)
56027 +{
56028 + if (file->f_mode & FMODE_READ) {
56029 + char *tmp = NULL;
56030 + mutex_lock(&gr_learn_user_mutex);
56031 + spin_lock(&gr_learn_lock);
56032 + tmp = learn_buffer;
56033 + learn_buffer = NULL;
56034 + spin_unlock(&gr_learn_lock);
56035 + if (tmp)
56036 + vfree(tmp);
56037 + if (learn_buffer_user != NULL) {
56038 + vfree(learn_buffer_user);
56039 + learn_buffer_user = NULL;
56040 + }
56041 + learn_buffer_len = 0;
56042 + learn_buffer_user_len = 0;
56043 + gr_learn_attached = 0;
56044 + mutex_unlock(&gr_learn_user_mutex);
56045 + }
56046 +
56047 + return 0;
56048 +}
56049 +
56050 +const struct file_operations grsec_fops = {
56051 + .read = read_learn,
56052 + .write = write_grsec_handler,
56053 + .open = open_learn,
56054 + .release = close_learn,
56055 + .poll = poll_learn,
56056 +};
56057 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56058 new file mode 100644
56059 index 0000000..39645c9
56060 --- /dev/null
56061 +++ b/grsecurity/gracl_res.c
56062 @@ -0,0 +1,68 @@
56063 +#include <linux/kernel.h>
56064 +#include <linux/sched.h>
56065 +#include <linux/gracl.h>
56066 +#include <linux/grinternal.h>
56067 +
56068 +static const char *restab_log[] = {
56069 + [RLIMIT_CPU] = "RLIMIT_CPU",
56070 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56071 + [RLIMIT_DATA] = "RLIMIT_DATA",
56072 + [RLIMIT_STACK] = "RLIMIT_STACK",
56073 + [RLIMIT_CORE] = "RLIMIT_CORE",
56074 + [RLIMIT_RSS] = "RLIMIT_RSS",
56075 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56076 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56077 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56078 + [RLIMIT_AS] = "RLIMIT_AS",
56079 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56080 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56081 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56082 + [RLIMIT_NICE] = "RLIMIT_NICE",
56083 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56084 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56085 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56086 +};
56087 +
56088 +void
56089 +gr_log_resource(const struct task_struct *task,
56090 + const int res, const unsigned long wanted, const int gt)
56091 +{
56092 + const struct cred *cred;
56093 + unsigned long rlim;
56094 +
56095 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56096 + return;
56097 +
56098 + // not yet supported resource
56099 + if (unlikely(!restab_log[res]))
56100 + return;
56101 +
56102 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56103 + rlim = task_rlimit_max(task, res);
56104 + else
56105 + rlim = task_rlimit(task, res);
56106 +
56107 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56108 + return;
56109 +
56110 + rcu_read_lock();
56111 + cred = __task_cred(task);
56112 +
56113 + if (res == RLIMIT_NPROC &&
56114 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56115 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56116 + goto out_rcu_unlock;
56117 + else if (res == RLIMIT_MEMLOCK &&
56118 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56119 + goto out_rcu_unlock;
56120 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56121 + goto out_rcu_unlock;
56122 + rcu_read_unlock();
56123 +
56124 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56125 +
56126 + return;
56127 +out_rcu_unlock:
56128 + rcu_read_unlock();
56129 + return;
56130 +}
56131 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56132 new file mode 100644
56133 index 0000000..5556be3
56134 --- /dev/null
56135 +++ b/grsecurity/gracl_segv.c
56136 @@ -0,0 +1,299 @@
56137 +#include <linux/kernel.h>
56138 +#include <linux/mm.h>
56139 +#include <asm/uaccess.h>
56140 +#include <asm/errno.h>
56141 +#include <asm/mman.h>
56142 +#include <net/sock.h>
56143 +#include <linux/file.h>
56144 +#include <linux/fs.h>
56145 +#include <linux/net.h>
56146 +#include <linux/in.h>
56147 +#include <linux/slab.h>
56148 +#include <linux/types.h>
56149 +#include <linux/sched.h>
56150 +#include <linux/timer.h>
56151 +#include <linux/gracl.h>
56152 +#include <linux/grsecurity.h>
56153 +#include <linux/grinternal.h>
56154 +
56155 +static struct crash_uid *uid_set;
56156 +static unsigned short uid_used;
56157 +static DEFINE_SPINLOCK(gr_uid_lock);
56158 +extern rwlock_t gr_inode_lock;
56159 +extern struct acl_subject_label *
56160 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56161 + struct acl_role_label *role);
56162 +
56163 +#ifdef CONFIG_BTRFS_FS
56164 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56165 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56166 +#endif
56167 +
56168 +static inline dev_t __get_dev(const struct dentry *dentry)
56169 +{
56170 +#ifdef CONFIG_BTRFS_FS
56171 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56172 + return get_btrfs_dev_from_inode(dentry->d_inode);
56173 + else
56174 +#endif
56175 + return dentry->d_inode->i_sb->s_dev;
56176 +}
56177 +
56178 +int
56179 +gr_init_uidset(void)
56180 +{
56181 + uid_set =
56182 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56183 + uid_used = 0;
56184 +
56185 + return uid_set ? 1 : 0;
56186 +}
56187 +
56188 +void
56189 +gr_free_uidset(void)
56190 +{
56191 + if (uid_set)
56192 + kfree(uid_set);
56193 +
56194 + return;
56195 +}
56196 +
56197 +int
56198 +gr_find_uid(const uid_t uid)
56199 +{
56200 + struct crash_uid *tmp = uid_set;
56201 + uid_t buid;
56202 + int low = 0, high = uid_used - 1, mid;
56203 +
56204 + while (high >= low) {
56205 + mid = (low + high) >> 1;
56206 + buid = tmp[mid].uid;
56207 + if (buid == uid)
56208 + return mid;
56209 + if (buid > uid)
56210 + high = mid - 1;
56211 + if (buid < uid)
56212 + low = mid + 1;
56213 + }
56214 +
56215 + return -1;
56216 +}
56217 +
56218 +static __inline__ void
56219 +gr_insertsort(void)
56220 +{
56221 + unsigned short i, j;
56222 + struct crash_uid index;
56223 +
56224 + for (i = 1; i < uid_used; i++) {
56225 + index = uid_set[i];
56226 + j = i;
56227 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
56228 + uid_set[j] = uid_set[j - 1];
56229 + j--;
56230 + }
56231 + uid_set[j] = index;
56232 + }
56233 +
56234 + return;
56235 +}
56236 +
56237 +static __inline__ void
56238 +gr_insert_uid(const uid_t uid, const unsigned long expires)
56239 +{
56240 + int loc;
56241 +
56242 + if (uid_used == GR_UIDTABLE_MAX)
56243 + return;
56244 +
56245 + loc = gr_find_uid(uid);
56246 +
56247 + if (loc >= 0) {
56248 + uid_set[loc].expires = expires;
56249 + return;
56250 + }
56251 +
56252 + uid_set[uid_used].uid = uid;
56253 + uid_set[uid_used].expires = expires;
56254 + uid_used++;
56255 +
56256 + gr_insertsort();
56257 +
56258 + return;
56259 +}
56260 +
56261 +void
56262 +gr_remove_uid(const unsigned short loc)
56263 +{
56264 + unsigned short i;
56265 +
56266 + for (i = loc + 1; i < uid_used; i++)
56267 + uid_set[i - 1] = uid_set[i];
56268 +
56269 + uid_used--;
56270 +
56271 + return;
56272 +}
56273 +
56274 +int
56275 +gr_check_crash_uid(const uid_t uid)
56276 +{
56277 + int loc;
56278 + int ret = 0;
56279 +
56280 + if (unlikely(!gr_acl_is_enabled()))
56281 + return 0;
56282 +
56283 + spin_lock(&gr_uid_lock);
56284 + loc = gr_find_uid(uid);
56285 +
56286 + if (loc < 0)
56287 + goto out_unlock;
56288 +
56289 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
56290 + gr_remove_uid(loc);
56291 + else
56292 + ret = 1;
56293 +
56294 +out_unlock:
56295 + spin_unlock(&gr_uid_lock);
56296 + return ret;
56297 +}
56298 +
56299 +static __inline__ int
56300 +proc_is_setxid(const struct cred *cred)
56301 +{
56302 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
56303 + cred->uid != cred->fsuid)
56304 + return 1;
56305 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
56306 + cred->gid != cred->fsgid)
56307 + return 1;
56308 +
56309 + return 0;
56310 +}
56311 +
56312 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
56313 +
56314 +void
56315 +gr_handle_crash(struct task_struct *task, const int sig)
56316 +{
56317 + struct acl_subject_label *curr;
56318 + struct task_struct *tsk, *tsk2;
56319 + const struct cred *cred;
56320 + const struct cred *cred2;
56321 +
56322 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
56323 + return;
56324 +
56325 + if (unlikely(!gr_acl_is_enabled()))
56326 + return;
56327 +
56328 + curr = task->acl;
56329 +
56330 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
56331 + return;
56332 +
56333 + if (time_before_eq(curr->expires, get_seconds())) {
56334 + curr->expires = 0;
56335 + curr->crashes = 0;
56336 + }
56337 +
56338 + curr->crashes++;
56339 +
56340 + if (!curr->expires)
56341 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
56342 +
56343 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56344 + time_after(curr->expires, get_seconds())) {
56345 + rcu_read_lock();
56346 + cred = __task_cred(task);
56347 + if (cred->uid && proc_is_setxid(cred)) {
56348 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56349 + spin_lock(&gr_uid_lock);
56350 + gr_insert_uid(cred->uid, curr->expires);
56351 + spin_unlock(&gr_uid_lock);
56352 + curr->expires = 0;
56353 + curr->crashes = 0;
56354 + read_lock(&tasklist_lock);
56355 + do_each_thread(tsk2, tsk) {
56356 + cred2 = __task_cred(tsk);
56357 + if (tsk != task && cred2->uid == cred->uid)
56358 + gr_fake_force_sig(SIGKILL, tsk);
56359 + } while_each_thread(tsk2, tsk);
56360 + read_unlock(&tasklist_lock);
56361 + } else {
56362 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
56363 + read_lock(&tasklist_lock);
56364 + read_lock(&grsec_exec_file_lock);
56365 + do_each_thread(tsk2, tsk) {
56366 + if (likely(tsk != task)) {
56367 + // if this thread has the same subject as the one that triggered
56368 + // RES_CRASH and it's the same binary, kill it
56369 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
56370 + gr_fake_force_sig(SIGKILL, tsk);
56371 + }
56372 + } while_each_thread(tsk2, tsk);
56373 + read_unlock(&grsec_exec_file_lock);
56374 + read_unlock(&tasklist_lock);
56375 + }
56376 + rcu_read_unlock();
56377 + }
56378 +
56379 + return;
56380 +}
56381 +
56382 +int
56383 +gr_check_crash_exec(const struct file *filp)
56384 +{
56385 + struct acl_subject_label *curr;
56386 +
56387 + if (unlikely(!gr_acl_is_enabled()))
56388 + return 0;
56389 +
56390 + read_lock(&gr_inode_lock);
56391 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
56392 + __get_dev(filp->f_path.dentry),
56393 + current->role);
56394 + read_unlock(&gr_inode_lock);
56395 +
56396 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
56397 + (!curr->crashes && !curr->expires))
56398 + return 0;
56399 +
56400 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
56401 + time_after(curr->expires, get_seconds()))
56402 + return 1;
56403 + else if (time_before_eq(curr->expires, get_seconds())) {
56404 + curr->crashes = 0;
56405 + curr->expires = 0;
56406 + }
56407 +
56408 + return 0;
56409 +}
56410 +
56411 +void
56412 +gr_handle_alertkill(struct task_struct *task)
56413 +{
56414 + struct acl_subject_label *curracl;
56415 + __u32 curr_ip;
56416 + struct task_struct *p, *p2;
56417 +
56418 + if (unlikely(!gr_acl_is_enabled()))
56419 + return;
56420 +
56421 + curracl = task->acl;
56422 + curr_ip = task->signal->curr_ip;
56423 +
56424 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
56425 + read_lock(&tasklist_lock);
56426 + do_each_thread(p2, p) {
56427 + if (p->signal->curr_ip == curr_ip)
56428 + gr_fake_force_sig(SIGKILL, p);
56429 + } while_each_thread(p2, p);
56430 + read_unlock(&tasklist_lock);
56431 + } else if (curracl->mode & GR_KILLPROC)
56432 + gr_fake_force_sig(SIGKILL, task);
56433 +
56434 + return;
56435 +}
56436 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
56437 new file mode 100644
56438 index 0000000..9d83a69
56439 --- /dev/null
56440 +++ b/grsecurity/gracl_shm.c
56441 @@ -0,0 +1,40 @@
56442 +#include <linux/kernel.h>
56443 +#include <linux/mm.h>
56444 +#include <linux/sched.h>
56445 +#include <linux/file.h>
56446 +#include <linux/ipc.h>
56447 +#include <linux/gracl.h>
56448 +#include <linux/grsecurity.h>
56449 +#include <linux/grinternal.h>
56450 +
56451 +int
56452 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56453 + const time_t shm_createtime, const uid_t cuid, const int shmid)
56454 +{
56455 + struct task_struct *task;
56456 +
56457 + if (!gr_acl_is_enabled())
56458 + return 1;
56459 +
56460 + rcu_read_lock();
56461 + read_lock(&tasklist_lock);
56462 +
56463 + task = find_task_by_vpid(shm_cprid);
56464 +
56465 + if (unlikely(!task))
56466 + task = find_task_by_vpid(shm_lapid);
56467 +
56468 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
56469 + (task->pid == shm_lapid)) &&
56470 + (task->acl->mode & GR_PROTSHM) &&
56471 + (task->acl != current->acl))) {
56472 + read_unlock(&tasklist_lock);
56473 + rcu_read_unlock();
56474 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
56475 + return 0;
56476 + }
56477 + read_unlock(&tasklist_lock);
56478 + rcu_read_unlock();
56479 +
56480 + return 1;
56481 +}
56482 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
56483 new file mode 100644
56484 index 0000000..bc0be01
56485 --- /dev/null
56486 +++ b/grsecurity/grsec_chdir.c
56487 @@ -0,0 +1,19 @@
56488 +#include <linux/kernel.h>
56489 +#include <linux/sched.h>
56490 +#include <linux/fs.h>
56491 +#include <linux/file.h>
56492 +#include <linux/grsecurity.h>
56493 +#include <linux/grinternal.h>
56494 +
56495 +void
56496 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
56497 +{
56498 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56499 + if ((grsec_enable_chdir && grsec_enable_group &&
56500 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
56501 + !grsec_enable_group)) {
56502 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
56503 + }
56504 +#endif
56505 + return;
56506 +}
56507 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
56508 new file mode 100644
56509 index 0000000..9807ee2
56510 --- /dev/null
56511 +++ b/grsecurity/grsec_chroot.c
56512 @@ -0,0 +1,368 @@
56513 +#include <linux/kernel.h>
56514 +#include <linux/module.h>
56515 +#include <linux/sched.h>
56516 +#include <linux/file.h>
56517 +#include <linux/fs.h>
56518 +#include <linux/mount.h>
56519 +#include <linux/types.h>
56520 +#include "../fs/mount.h"
56521 +#include <linux/grsecurity.h>
56522 +#include <linux/grinternal.h>
56523 +
56524 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
56525 +{
56526 +#ifdef CONFIG_GRKERNSEC
56527 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
56528 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
56529 + task->gr_is_chrooted = 1;
56530 + else
56531 + task->gr_is_chrooted = 0;
56532 +
56533 + task->gr_chroot_dentry = path->dentry;
56534 +#endif
56535 + return;
56536 +}
56537 +
56538 +void gr_clear_chroot_entries(struct task_struct *task)
56539 +{
56540 +#ifdef CONFIG_GRKERNSEC
56541 + task->gr_is_chrooted = 0;
56542 + task->gr_chroot_dentry = NULL;
56543 +#endif
56544 + return;
56545 +}
56546 +
56547 +int
56548 +gr_handle_chroot_unix(const pid_t pid)
56549 +{
56550 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56551 + struct task_struct *p;
56552 +
56553 + if (unlikely(!grsec_enable_chroot_unix))
56554 + return 1;
56555 +
56556 + if (likely(!proc_is_chrooted(current)))
56557 + return 1;
56558 +
56559 + rcu_read_lock();
56560 + read_lock(&tasklist_lock);
56561 + p = find_task_by_vpid_unrestricted(pid);
56562 + if (unlikely(p && !have_same_root(current, p))) {
56563 + read_unlock(&tasklist_lock);
56564 + rcu_read_unlock();
56565 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
56566 + return 0;
56567 + }
56568 + read_unlock(&tasklist_lock);
56569 + rcu_read_unlock();
56570 +#endif
56571 + return 1;
56572 +}
56573 +
56574 +int
56575 +gr_handle_chroot_nice(void)
56576 +{
56577 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56578 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
56579 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
56580 + return -EPERM;
56581 + }
56582 +#endif
56583 + return 0;
56584 +}
56585 +
56586 +int
56587 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
56588 +{
56589 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56590 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
56591 + && proc_is_chrooted(current)) {
56592 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
56593 + return -EACCES;
56594 + }
56595 +#endif
56596 + return 0;
56597 +}
56598 +
56599 +int
56600 +gr_handle_chroot_rawio(const struct inode *inode)
56601 +{
56602 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56603 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56604 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
56605 + return 1;
56606 +#endif
56607 + return 0;
56608 +}
56609 +
56610 +int
56611 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
56612 +{
56613 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56614 + struct task_struct *p;
56615 + int ret = 0;
56616 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
56617 + return ret;
56618 +
56619 + read_lock(&tasklist_lock);
56620 + do_each_pid_task(pid, type, p) {
56621 + if (!have_same_root(current, p)) {
56622 + ret = 1;
56623 + goto out;
56624 + }
56625 + } while_each_pid_task(pid, type, p);
56626 +out:
56627 + read_unlock(&tasklist_lock);
56628 + return ret;
56629 +#endif
56630 + return 0;
56631 +}
56632 +
56633 +int
56634 +gr_pid_is_chrooted(struct task_struct *p)
56635 +{
56636 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
56637 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
56638 + return 0;
56639 +
56640 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
56641 + !have_same_root(current, p)) {
56642 + return 1;
56643 + }
56644 +#endif
56645 + return 0;
56646 +}
56647 +
56648 +EXPORT_SYMBOL(gr_pid_is_chrooted);
56649 +
56650 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
56651 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
56652 +{
56653 + struct path path, currentroot;
56654 + int ret = 0;
56655 +
56656 + path.dentry = (struct dentry *)u_dentry;
56657 + path.mnt = (struct vfsmount *)u_mnt;
56658 + get_fs_root(current->fs, &currentroot);
56659 + if (path_is_under(&path, &currentroot))
56660 + ret = 1;
56661 + path_put(&currentroot);
56662 +
56663 + return ret;
56664 +}
56665 +#endif
56666 +
56667 +int
56668 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
56669 +{
56670 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56671 + if (!grsec_enable_chroot_fchdir)
56672 + return 1;
56673 +
56674 + if (!proc_is_chrooted(current))
56675 + return 1;
56676 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
56677 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
56678 + return 0;
56679 + }
56680 +#endif
56681 + return 1;
56682 +}
56683 +
56684 +int
56685 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
56686 + const time_t shm_createtime)
56687 +{
56688 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56689 + struct task_struct *p;
56690 + time_t starttime;
56691 +
56692 + if (unlikely(!grsec_enable_chroot_shmat))
56693 + return 1;
56694 +
56695 + if (likely(!proc_is_chrooted(current)))
56696 + return 1;
56697 +
56698 + rcu_read_lock();
56699 + read_lock(&tasklist_lock);
56700 +
56701 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
56702 + starttime = p->start_time.tv_sec;
56703 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
56704 + if (have_same_root(current, p)) {
56705 + goto allow;
56706 + } else {
56707 + read_unlock(&tasklist_lock);
56708 + rcu_read_unlock();
56709 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56710 + return 0;
56711 + }
56712 + }
56713 + /* creator exited, pid reuse, fall through to next check */
56714 + }
56715 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
56716 + if (unlikely(!have_same_root(current, p))) {
56717 + read_unlock(&tasklist_lock);
56718 + rcu_read_unlock();
56719 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
56720 + return 0;
56721 + }
56722 + }
56723 +
56724 +allow:
56725 + read_unlock(&tasklist_lock);
56726 + rcu_read_unlock();
56727 +#endif
56728 + return 1;
56729 +}
56730 +
56731 +void
56732 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
56733 +{
56734 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56735 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
56736 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
56737 +#endif
56738 + return;
56739 +}
56740 +
56741 +int
56742 +gr_handle_chroot_mknod(const struct dentry *dentry,
56743 + const struct vfsmount *mnt, const int mode)
56744 +{
56745 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56746 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
56747 + proc_is_chrooted(current)) {
56748 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
56749 + return -EPERM;
56750 + }
56751 +#endif
56752 + return 0;
56753 +}
56754 +
56755 +int
56756 +gr_handle_chroot_mount(const struct dentry *dentry,
56757 + const struct vfsmount *mnt, const char *dev_name)
56758 +{
56759 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56760 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
56761 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
56762 + return -EPERM;
56763 + }
56764 +#endif
56765 + return 0;
56766 +}
56767 +
56768 +int
56769 +gr_handle_chroot_pivot(void)
56770 +{
56771 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56772 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
56773 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
56774 + return -EPERM;
56775 + }
56776 +#endif
56777 + return 0;
56778 +}
56779 +
56780 +int
56781 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
56782 +{
56783 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56784 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
56785 + !gr_is_outside_chroot(dentry, mnt)) {
56786 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
56787 + return -EPERM;
56788 + }
56789 +#endif
56790 + return 0;
56791 +}
56792 +
56793 +extern const char *captab_log[];
56794 +extern int captab_log_entries;
56795 +
56796 +int
56797 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
56798 +{
56799 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56800 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56801 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56802 + if (cap_raised(chroot_caps, cap)) {
56803 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
56804 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
56805 + }
56806 + return 0;
56807 + }
56808 + }
56809 +#endif
56810 + return 1;
56811 +}
56812 +
56813 +int
56814 +gr_chroot_is_capable(const int cap)
56815 +{
56816 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56817 + return gr_task_chroot_is_capable(current, current_cred(), cap);
56818 +#endif
56819 + return 1;
56820 +}
56821 +
56822 +int
56823 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
56824 +{
56825 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56826 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
56827 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
56828 + if (cap_raised(chroot_caps, cap)) {
56829 + return 0;
56830 + }
56831 + }
56832 +#endif
56833 + return 1;
56834 +}
56835 +
56836 +int
56837 +gr_chroot_is_capable_nolog(const int cap)
56838 +{
56839 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56840 + return gr_task_chroot_is_capable_nolog(current, cap);
56841 +#endif
56842 + return 1;
56843 +}
56844 +
56845 +int
56846 +gr_handle_chroot_sysctl(const int op)
56847 +{
56848 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56849 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
56850 + proc_is_chrooted(current))
56851 + return -EACCES;
56852 +#endif
56853 + return 0;
56854 +}
56855 +
56856 +void
56857 +gr_handle_chroot_chdir(struct path *path)
56858 +{
56859 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56860 + if (grsec_enable_chroot_chdir)
56861 + set_fs_pwd(current->fs, path);
56862 +#endif
56863 + return;
56864 +}
56865 +
56866 +int
56867 +gr_handle_chroot_chmod(const struct dentry *dentry,
56868 + const struct vfsmount *mnt, const int mode)
56869 +{
56870 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56871 + /* allow chmod +s on directories, but not files */
56872 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
56873 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
56874 + proc_is_chrooted(current)) {
56875 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
56876 + return -EPERM;
56877 + }
56878 +#endif
56879 + return 0;
56880 +}
56881 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
56882 new file mode 100644
56883 index 0000000..213ad8b
56884 --- /dev/null
56885 +++ b/grsecurity/grsec_disabled.c
56886 @@ -0,0 +1,437 @@
56887 +#include <linux/kernel.h>
56888 +#include <linux/module.h>
56889 +#include <linux/sched.h>
56890 +#include <linux/file.h>
56891 +#include <linux/fs.h>
56892 +#include <linux/kdev_t.h>
56893 +#include <linux/net.h>
56894 +#include <linux/in.h>
56895 +#include <linux/ip.h>
56896 +#include <linux/skbuff.h>
56897 +#include <linux/sysctl.h>
56898 +
56899 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56900 +void
56901 +pax_set_initial_flags(struct linux_binprm *bprm)
56902 +{
56903 + return;
56904 +}
56905 +#endif
56906 +
56907 +#ifdef CONFIG_SYSCTL
56908 +__u32
56909 +gr_handle_sysctl(const struct ctl_table * table, const int op)
56910 +{
56911 + return 0;
56912 +}
56913 +#endif
56914 +
56915 +#ifdef CONFIG_TASKSTATS
56916 +int gr_is_taskstats_denied(int pid)
56917 +{
56918 + return 0;
56919 +}
56920 +#endif
56921 +
56922 +int
56923 +gr_acl_is_enabled(void)
56924 +{
56925 + return 0;
56926 +}
56927 +
56928 +void
56929 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56930 +{
56931 + return;
56932 +}
56933 +
56934 +int
56935 +gr_handle_rawio(const struct inode *inode)
56936 +{
56937 + return 0;
56938 +}
56939 +
56940 +void
56941 +gr_acl_handle_psacct(struct task_struct *task, const long code)
56942 +{
56943 + return;
56944 +}
56945 +
56946 +int
56947 +gr_handle_ptrace(struct task_struct *task, const long request)
56948 +{
56949 + return 0;
56950 +}
56951 +
56952 +int
56953 +gr_handle_proc_ptrace(struct task_struct *task)
56954 +{
56955 + return 0;
56956 +}
56957 +
56958 +void
56959 +gr_learn_resource(const struct task_struct *task,
56960 + const int res, const unsigned long wanted, const int gt)
56961 +{
56962 + return;
56963 +}
56964 +
56965 +int
56966 +gr_set_acls(const int type)
56967 +{
56968 + return 0;
56969 +}
56970 +
56971 +int
56972 +gr_check_hidden_task(const struct task_struct *tsk)
56973 +{
56974 + return 0;
56975 +}
56976 +
56977 +int
56978 +gr_check_protected_task(const struct task_struct *task)
56979 +{
56980 + return 0;
56981 +}
56982 +
56983 +int
56984 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56985 +{
56986 + return 0;
56987 +}
56988 +
56989 +void
56990 +gr_copy_label(struct task_struct *tsk)
56991 +{
56992 + return;
56993 +}
56994 +
56995 +void
56996 +gr_set_pax_flags(struct task_struct *task)
56997 +{
56998 + return;
56999 +}
57000 +
57001 +int
57002 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57003 + const int unsafe_share)
57004 +{
57005 + return 0;
57006 +}
57007 +
57008 +void
57009 +gr_handle_delete(const ino_t ino, const dev_t dev)
57010 +{
57011 + return;
57012 +}
57013 +
57014 +void
57015 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57016 +{
57017 + return;
57018 +}
57019 +
57020 +void
57021 +gr_handle_crash(struct task_struct *task, const int sig)
57022 +{
57023 + return;
57024 +}
57025 +
57026 +int
57027 +gr_check_crash_exec(const struct file *filp)
57028 +{
57029 + return 0;
57030 +}
57031 +
57032 +int
57033 +gr_check_crash_uid(const uid_t uid)
57034 +{
57035 + return 0;
57036 +}
57037 +
57038 +void
57039 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57040 + struct dentry *old_dentry,
57041 + struct dentry *new_dentry,
57042 + struct vfsmount *mnt, const __u8 replace)
57043 +{
57044 + return;
57045 +}
57046 +
57047 +int
57048 +gr_search_socket(const int family, const int type, const int protocol)
57049 +{
57050 + return 1;
57051 +}
57052 +
57053 +int
57054 +gr_search_connectbind(const int mode, const struct socket *sock,
57055 + const struct sockaddr_in *addr)
57056 +{
57057 + return 0;
57058 +}
57059 +
57060 +void
57061 +gr_handle_alertkill(struct task_struct *task)
57062 +{
57063 + return;
57064 +}
57065 +
57066 +__u32
57067 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57068 +{
57069 + return 1;
57070 +}
57071 +
57072 +__u32
57073 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57074 + const struct vfsmount * mnt)
57075 +{
57076 + return 1;
57077 +}
57078 +
57079 +__u32
57080 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57081 + int acc_mode)
57082 +{
57083 + return 1;
57084 +}
57085 +
57086 +__u32
57087 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57088 +{
57089 + return 1;
57090 +}
57091 +
57092 +__u32
57093 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57094 +{
57095 + return 1;
57096 +}
57097 +
57098 +int
57099 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57100 + unsigned int *vm_flags)
57101 +{
57102 + return 1;
57103 +}
57104 +
57105 +__u32
57106 +gr_acl_handle_truncate(const struct dentry * dentry,
57107 + const struct vfsmount * mnt)
57108 +{
57109 + return 1;
57110 +}
57111 +
57112 +__u32
57113 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57114 +{
57115 + return 1;
57116 +}
57117 +
57118 +__u32
57119 +gr_acl_handle_access(const struct dentry * dentry,
57120 + const struct vfsmount * mnt, const int fmode)
57121 +{
57122 + return 1;
57123 +}
57124 +
57125 +__u32
57126 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57127 + umode_t *mode)
57128 +{
57129 + return 1;
57130 +}
57131 +
57132 +__u32
57133 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57134 +{
57135 + return 1;
57136 +}
57137 +
57138 +__u32
57139 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57140 +{
57141 + return 1;
57142 +}
57143 +
57144 +void
57145 +grsecurity_init(void)
57146 +{
57147 + return;
57148 +}
57149 +
57150 +umode_t gr_acl_umask(void)
57151 +{
57152 + return 0;
57153 +}
57154 +
57155 +__u32
57156 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57157 + const struct dentry * parent_dentry,
57158 + const struct vfsmount * parent_mnt,
57159 + const int mode)
57160 +{
57161 + return 1;
57162 +}
57163 +
57164 +__u32
57165 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57166 + const struct dentry * parent_dentry,
57167 + const struct vfsmount * parent_mnt)
57168 +{
57169 + return 1;
57170 +}
57171 +
57172 +__u32
57173 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57174 + const struct dentry * parent_dentry,
57175 + const struct vfsmount * parent_mnt, const char *from)
57176 +{
57177 + return 1;
57178 +}
57179 +
57180 +__u32
57181 +gr_acl_handle_link(const struct dentry * new_dentry,
57182 + const struct dentry * parent_dentry,
57183 + const struct vfsmount * parent_mnt,
57184 + const struct dentry * old_dentry,
57185 + const struct vfsmount * old_mnt, const char *to)
57186 +{
57187 + return 1;
57188 +}
57189 +
57190 +int
57191 +gr_acl_handle_rename(const struct dentry *new_dentry,
57192 + const struct dentry *parent_dentry,
57193 + const struct vfsmount *parent_mnt,
57194 + const struct dentry *old_dentry,
57195 + const struct inode *old_parent_inode,
57196 + const struct vfsmount *old_mnt, const char *newname)
57197 +{
57198 + return 0;
57199 +}
57200 +
57201 +int
57202 +gr_acl_handle_filldir(const struct file *file, const char *name,
57203 + const int namelen, const ino_t ino)
57204 +{
57205 + return 1;
57206 +}
57207 +
57208 +int
57209 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57210 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57211 +{
57212 + return 1;
57213 +}
57214 +
57215 +int
57216 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
57217 +{
57218 + return 0;
57219 +}
57220 +
57221 +int
57222 +gr_search_accept(const struct socket *sock)
57223 +{
57224 + return 0;
57225 +}
57226 +
57227 +int
57228 +gr_search_listen(const struct socket *sock)
57229 +{
57230 + return 0;
57231 +}
57232 +
57233 +int
57234 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
57235 +{
57236 + return 0;
57237 +}
57238 +
57239 +__u32
57240 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
57241 +{
57242 + return 1;
57243 +}
57244 +
57245 +__u32
57246 +gr_acl_handle_creat(const struct dentry * dentry,
57247 + const struct dentry * p_dentry,
57248 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57249 + const int imode)
57250 +{
57251 + return 1;
57252 +}
57253 +
57254 +void
57255 +gr_acl_handle_exit(void)
57256 +{
57257 + return;
57258 +}
57259 +
57260 +int
57261 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57262 +{
57263 + return 1;
57264 +}
57265 +
57266 +void
57267 +gr_set_role_label(const uid_t uid, const gid_t gid)
57268 +{
57269 + return;
57270 +}
57271 +
57272 +int
57273 +gr_acl_handle_procpidmem(const struct task_struct *task)
57274 +{
57275 + return 0;
57276 +}
57277 +
57278 +int
57279 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
57280 +{
57281 + return 0;
57282 +}
57283 +
57284 +int
57285 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
57286 +{
57287 + return 0;
57288 +}
57289 +
57290 +void
57291 +gr_set_kernel_label(struct task_struct *task)
57292 +{
57293 + return;
57294 +}
57295 +
57296 +int
57297 +gr_check_user_change(int real, int effective, int fs)
57298 +{
57299 + return 0;
57300 +}
57301 +
57302 +int
57303 +gr_check_group_change(int real, int effective, int fs)
57304 +{
57305 + return 0;
57306 +}
57307 +
57308 +int gr_acl_enable_at_secure(void)
57309 +{
57310 + return 0;
57311 +}
57312 +
57313 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
57314 +{
57315 + return dentry->d_inode->i_sb->s_dev;
57316 +}
57317 +
57318 +EXPORT_SYMBOL(gr_learn_resource);
57319 +EXPORT_SYMBOL(gr_set_kernel_label);
57320 +#ifdef CONFIG_SECURITY
57321 +EXPORT_SYMBOL(gr_check_user_change);
57322 +EXPORT_SYMBOL(gr_check_group_change);
57323 +#endif
57324 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
57325 new file mode 100644
57326 index 0000000..abfa971
57327 --- /dev/null
57328 +++ b/grsecurity/grsec_exec.c
57329 @@ -0,0 +1,174 @@
57330 +#include <linux/kernel.h>
57331 +#include <linux/sched.h>
57332 +#include <linux/file.h>
57333 +#include <linux/binfmts.h>
57334 +#include <linux/fs.h>
57335 +#include <linux/types.h>
57336 +#include <linux/grdefs.h>
57337 +#include <linux/grsecurity.h>
57338 +#include <linux/grinternal.h>
57339 +#include <linux/capability.h>
57340 +#include <linux/module.h>
57341 +
57342 +#include <asm/uaccess.h>
57343 +
57344 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57345 +static char gr_exec_arg_buf[132];
57346 +static DEFINE_MUTEX(gr_exec_arg_mutex);
57347 +#endif
57348 +
57349 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
57350 +
57351 +void
57352 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
57353 +{
57354 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57355 + char *grarg = gr_exec_arg_buf;
57356 + unsigned int i, x, execlen = 0;
57357 + char c;
57358 +
57359 + if (!((grsec_enable_execlog && grsec_enable_group &&
57360 + in_group_p(grsec_audit_gid))
57361 + || (grsec_enable_execlog && !grsec_enable_group)))
57362 + return;
57363 +
57364 + mutex_lock(&gr_exec_arg_mutex);
57365 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
57366 +
57367 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
57368 + const char __user *p;
57369 + unsigned int len;
57370 +
57371 + p = get_user_arg_ptr(argv, i);
57372 + if (IS_ERR(p))
57373 + goto log;
57374 +
57375 + len = strnlen_user(p, 128 - execlen);
57376 + if (len > 128 - execlen)
57377 + len = 128 - execlen;
57378 + else if (len > 0)
57379 + len--;
57380 + if (copy_from_user(grarg + execlen, p, len))
57381 + goto log;
57382 +
57383 + /* rewrite unprintable characters */
57384 + for (x = 0; x < len; x++) {
57385 + c = *(grarg + execlen + x);
57386 + if (c < 32 || c > 126)
57387 + *(grarg + execlen + x) = ' ';
57388 + }
57389 +
57390 + execlen += len;
57391 + *(grarg + execlen) = ' ';
57392 + *(grarg + execlen + 1) = '\0';
57393 + execlen++;
57394 + }
57395 +
57396 + log:
57397 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
57398 + bprm->file->f_path.mnt, grarg);
57399 + mutex_unlock(&gr_exec_arg_mutex);
57400 +#endif
57401 + return;
57402 +}
57403 +
57404 +#ifdef CONFIG_GRKERNSEC
57405 +extern int gr_acl_is_capable(const int cap);
57406 +extern int gr_acl_is_capable_nolog(const int cap);
57407 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57408 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
57409 +extern int gr_chroot_is_capable(const int cap);
57410 +extern int gr_chroot_is_capable_nolog(const int cap);
57411 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
57412 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
57413 +#endif
57414 +
57415 +const char *captab_log[] = {
57416 + "CAP_CHOWN",
57417 + "CAP_DAC_OVERRIDE",
57418 + "CAP_DAC_READ_SEARCH",
57419 + "CAP_FOWNER",
57420 + "CAP_FSETID",
57421 + "CAP_KILL",
57422 + "CAP_SETGID",
57423 + "CAP_SETUID",
57424 + "CAP_SETPCAP",
57425 + "CAP_LINUX_IMMUTABLE",
57426 + "CAP_NET_BIND_SERVICE",
57427 + "CAP_NET_BROADCAST",
57428 + "CAP_NET_ADMIN",
57429 + "CAP_NET_RAW",
57430 + "CAP_IPC_LOCK",
57431 + "CAP_IPC_OWNER",
57432 + "CAP_SYS_MODULE",
57433 + "CAP_SYS_RAWIO",
57434 + "CAP_SYS_CHROOT",
57435 + "CAP_SYS_PTRACE",
57436 + "CAP_SYS_PACCT",
57437 + "CAP_SYS_ADMIN",
57438 + "CAP_SYS_BOOT",
57439 + "CAP_SYS_NICE",
57440 + "CAP_SYS_RESOURCE",
57441 + "CAP_SYS_TIME",
57442 + "CAP_SYS_TTY_CONFIG",
57443 + "CAP_MKNOD",
57444 + "CAP_LEASE",
57445 + "CAP_AUDIT_WRITE",
57446 + "CAP_AUDIT_CONTROL",
57447 + "CAP_SETFCAP",
57448 + "CAP_MAC_OVERRIDE",
57449 + "CAP_MAC_ADMIN",
57450 + "CAP_SYSLOG",
57451 + "CAP_WAKE_ALARM"
57452 +};
57453 +
57454 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
57455 +
57456 +int gr_is_capable(const int cap)
57457 +{
57458 +#ifdef CONFIG_GRKERNSEC
57459 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
57460 + return 1;
57461 + return 0;
57462 +#else
57463 + return 1;
57464 +#endif
57465 +}
57466 +
57467 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57468 +{
57469 +#ifdef CONFIG_GRKERNSEC
57470 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
57471 + return 1;
57472 + return 0;
57473 +#else
57474 + return 1;
57475 +#endif
57476 +}
57477 +
57478 +int gr_is_capable_nolog(const int cap)
57479 +{
57480 +#ifdef CONFIG_GRKERNSEC
57481 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
57482 + return 1;
57483 + return 0;
57484 +#else
57485 + return 1;
57486 +#endif
57487 +}
57488 +
57489 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
57490 +{
57491 +#ifdef CONFIG_GRKERNSEC
57492 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
57493 + return 1;
57494 + return 0;
57495 +#else
57496 + return 1;
57497 +#endif
57498 +}
57499 +
57500 +EXPORT_SYMBOL(gr_is_capable);
57501 +EXPORT_SYMBOL(gr_is_capable_nolog);
57502 +EXPORT_SYMBOL(gr_task_is_capable);
57503 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
57504 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
57505 new file mode 100644
57506 index 0000000..d3ee748
57507 --- /dev/null
57508 +++ b/grsecurity/grsec_fifo.c
57509 @@ -0,0 +1,24 @@
57510 +#include <linux/kernel.h>
57511 +#include <linux/sched.h>
57512 +#include <linux/fs.h>
57513 +#include <linux/file.h>
57514 +#include <linux/grinternal.h>
57515 +
57516 +int
57517 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
57518 + const struct dentry *dir, const int flag, const int acc_mode)
57519 +{
57520 +#ifdef CONFIG_GRKERNSEC_FIFO
57521 + const struct cred *cred = current_cred();
57522 +
57523 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
57524 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
57525 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
57526 + (cred->fsuid != dentry->d_inode->i_uid)) {
57527 + if (!inode_permission(dentry->d_inode, acc_mode))
57528 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
57529 + return -EACCES;
57530 + }
57531 +#endif
57532 + return 0;
57533 +}
57534 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
57535 new file mode 100644
57536 index 0000000..8ca18bf
57537 --- /dev/null
57538 +++ b/grsecurity/grsec_fork.c
57539 @@ -0,0 +1,23 @@
57540 +#include <linux/kernel.h>
57541 +#include <linux/sched.h>
57542 +#include <linux/grsecurity.h>
57543 +#include <linux/grinternal.h>
57544 +#include <linux/errno.h>
57545 +
57546 +void
57547 +gr_log_forkfail(const int retval)
57548 +{
57549 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57550 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
57551 + switch (retval) {
57552 + case -EAGAIN:
57553 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
57554 + break;
57555 + case -ENOMEM:
57556 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
57557 + break;
57558 + }
57559 + }
57560 +#endif
57561 + return;
57562 +}
57563 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
57564 new file mode 100644
57565 index 0000000..01ddde4
57566 --- /dev/null
57567 +++ b/grsecurity/grsec_init.c
57568 @@ -0,0 +1,277 @@
57569 +#include <linux/kernel.h>
57570 +#include <linux/sched.h>
57571 +#include <linux/mm.h>
57572 +#include <linux/gracl.h>
57573 +#include <linux/slab.h>
57574 +#include <linux/vmalloc.h>
57575 +#include <linux/percpu.h>
57576 +#include <linux/module.h>
57577 +
57578 +int grsec_enable_ptrace_readexec;
57579 +int grsec_enable_setxid;
57580 +int grsec_enable_brute;
57581 +int grsec_enable_link;
57582 +int grsec_enable_dmesg;
57583 +int grsec_enable_harden_ptrace;
57584 +int grsec_enable_fifo;
57585 +int grsec_enable_execlog;
57586 +int grsec_enable_signal;
57587 +int grsec_enable_forkfail;
57588 +int grsec_enable_audit_ptrace;
57589 +int grsec_enable_time;
57590 +int grsec_enable_audit_textrel;
57591 +int grsec_enable_group;
57592 +int grsec_audit_gid;
57593 +int grsec_enable_chdir;
57594 +int grsec_enable_mount;
57595 +int grsec_enable_rofs;
57596 +int grsec_enable_chroot_findtask;
57597 +int grsec_enable_chroot_mount;
57598 +int grsec_enable_chroot_shmat;
57599 +int grsec_enable_chroot_fchdir;
57600 +int grsec_enable_chroot_double;
57601 +int grsec_enable_chroot_pivot;
57602 +int grsec_enable_chroot_chdir;
57603 +int grsec_enable_chroot_chmod;
57604 +int grsec_enable_chroot_mknod;
57605 +int grsec_enable_chroot_nice;
57606 +int grsec_enable_chroot_execlog;
57607 +int grsec_enable_chroot_caps;
57608 +int grsec_enable_chroot_sysctl;
57609 +int grsec_enable_chroot_unix;
57610 +int grsec_enable_tpe;
57611 +int grsec_tpe_gid;
57612 +int grsec_enable_blackhole;
57613 +#ifdef CONFIG_IPV6_MODULE
57614 +EXPORT_SYMBOL(grsec_enable_blackhole);
57615 +#endif
57616 +int grsec_lastack_retries;
57617 +int grsec_enable_tpe_all;
57618 +int grsec_enable_tpe_invert;
57619 +int grsec_enable_socket_all;
57620 +int grsec_socket_all_gid;
57621 +int grsec_enable_socket_client;
57622 +int grsec_socket_client_gid;
57623 +int grsec_enable_socket_server;
57624 +int grsec_socket_server_gid;
57625 +int grsec_resource_logging;
57626 +int grsec_disable_privio;
57627 +int grsec_enable_log_rwxmaps;
57628 +int grsec_lock;
57629 +
57630 +DEFINE_SPINLOCK(grsec_alert_lock);
57631 +unsigned long grsec_alert_wtime = 0;
57632 +unsigned long grsec_alert_fyet = 0;
57633 +
57634 +DEFINE_SPINLOCK(grsec_audit_lock);
57635 +
57636 +DEFINE_RWLOCK(grsec_exec_file_lock);
57637 +
57638 +char *gr_shared_page[4];
57639 +
57640 +char *gr_alert_log_fmt;
57641 +char *gr_audit_log_fmt;
57642 +char *gr_alert_log_buf;
57643 +char *gr_audit_log_buf;
57644 +
57645 +extern struct gr_arg *gr_usermode;
57646 +extern unsigned char *gr_system_salt;
57647 +extern unsigned char *gr_system_sum;
57648 +
57649 +void __init
57650 +grsecurity_init(void)
57651 +{
57652 + int j;
57653 + /* create the per-cpu shared pages */
57654 +
57655 +#ifdef CONFIG_X86
57656 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
57657 +#endif
57658 +
57659 + for (j = 0; j < 4; j++) {
57660 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
57661 + if (gr_shared_page[j] == NULL) {
57662 + panic("Unable to allocate grsecurity shared page");
57663 + return;
57664 + }
57665 + }
57666 +
57667 + /* allocate log buffers */
57668 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
57669 + if (!gr_alert_log_fmt) {
57670 + panic("Unable to allocate grsecurity alert log format buffer");
57671 + return;
57672 + }
57673 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
57674 + if (!gr_audit_log_fmt) {
57675 + panic("Unable to allocate grsecurity audit log format buffer");
57676 + return;
57677 + }
57678 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57679 + if (!gr_alert_log_buf) {
57680 + panic("Unable to allocate grsecurity alert log buffer");
57681 + return;
57682 + }
57683 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
57684 + if (!gr_audit_log_buf) {
57685 + panic("Unable to allocate grsecurity audit log buffer");
57686 + return;
57687 + }
57688 +
57689 + /* allocate memory for authentication structure */
57690 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
57691 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
57692 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
57693 +
57694 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
57695 + panic("Unable to allocate grsecurity authentication structure");
57696 + return;
57697 + }
57698 +
57699 +
57700 +#ifdef CONFIG_GRKERNSEC_IO
57701 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
57702 + grsec_disable_privio = 1;
57703 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57704 + grsec_disable_privio = 1;
57705 +#else
57706 + grsec_disable_privio = 0;
57707 +#endif
57708 +#endif
57709 +
57710 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57711 + /* for backward compatibility, tpe_invert always defaults to on if
57712 + enabled in the kernel
57713 + */
57714 + grsec_enable_tpe_invert = 1;
57715 +#endif
57716 +
57717 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
57718 +#ifndef CONFIG_GRKERNSEC_SYSCTL
57719 + grsec_lock = 1;
57720 +#endif
57721 +
57722 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
57723 + grsec_enable_audit_textrel = 1;
57724 +#endif
57725 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57726 + grsec_enable_log_rwxmaps = 1;
57727 +#endif
57728 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
57729 + grsec_enable_group = 1;
57730 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
57731 +#endif
57732 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
57733 + grsec_enable_ptrace_readexec = 1;
57734 +#endif
57735 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57736 + grsec_enable_chdir = 1;
57737 +#endif
57738 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57739 + grsec_enable_harden_ptrace = 1;
57740 +#endif
57741 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
57742 + grsec_enable_mount = 1;
57743 +#endif
57744 +#ifdef CONFIG_GRKERNSEC_LINK
57745 + grsec_enable_link = 1;
57746 +#endif
57747 +#ifdef CONFIG_GRKERNSEC_BRUTE
57748 + grsec_enable_brute = 1;
57749 +#endif
57750 +#ifdef CONFIG_GRKERNSEC_DMESG
57751 + grsec_enable_dmesg = 1;
57752 +#endif
57753 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
57754 + grsec_enable_blackhole = 1;
57755 + grsec_lastack_retries = 4;
57756 +#endif
57757 +#ifdef CONFIG_GRKERNSEC_FIFO
57758 + grsec_enable_fifo = 1;
57759 +#endif
57760 +#ifdef CONFIG_GRKERNSEC_EXECLOG
57761 + grsec_enable_execlog = 1;
57762 +#endif
57763 +#ifdef CONFIG_GRKERNSEC_SETXID
57764 + grsec_enable_setxid = 1;
57765 +#endif
57766 +#ifdef CONFIG_GRKERNSEC_SIGNAL
57767 + grsec_enable_signal = 1;
57768 +#endif
57769 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
57770 + grsec_enable_forkfail = 1;
57771 +#endif
57772 +#ifdef CONFIG_GRKERNSEC_TIME
57773 + grsec_enable_time = 1;
57774 +#endif
57775 +#ifdef CONFIG_GRKERNSEC_RESLOG
57776 + grsec_resource_logging = 1;
57777 +#endif
57778 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57779 + grsec_enable_chroot_findtask = 1;
57780 +#endif
57781 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57782 + grsec_enable_chroot_unix = 1;
57783 +#endif
57784 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57785 + grsec_enable_chroot_mount = 1;
57786 +#endif
57787 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57788 + grsec_enable_chroot_fchdir = 1;
57789 +#endif
57790 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57791 + grsec_enable_chroot_shmat = 1;
57792 +#endif
57793 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57794 + grsec_enable_audit_ptrace = 1;
57795 +#endif
57796 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57797 + grsec_enable_chroot_double = 1;
57798 +#endif
57799 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57800 + grsec_enable_chroot_pivot = 1;
57801 +#endif
57802 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57803 + grsec_enable_chroot_chdir = 1;
57804 +#endif
57805 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57806 + grsec_enable_chroot_chmod = 1;
57807 +#endif
57808 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57809 + grsec_enable_chroot_mknod = 1;
57810 +#endif
57811 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57812 + grsec_enable_chroot_nice = 1;
57813 +#endif
57814 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57815 + grsec_enable_chroot_execlog = 1;
57816 +#endif
57817 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57818 + grsec_enable_chroot_caps = 1;
57819 +#endif
57820 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57821 + grsec_enable_chroot_sysctl = 1;
57822 +#endif
57823 +#ifdef CONFIG_GRKERNSEC_TPE
57824 + grsec_enable_tpe = 1;
57825 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
57826 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57827 + grsec_enable_tpe_all = 1;
57828 +#endif
57829 +#endif
57830 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
57831 + grsec_enable_socket_all = 1;
57832 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
57833 +#endif
57834 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
57835 + grsec_enable_socket_client = 1;
57836 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
57837 +#endif
57838 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
57839 + grsec_enable_socket_server = 1;
57840 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
57841 +#endif
57842 +#endif
57843 +
57844 + return;
57845 +}
57846 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
57847 new file mode 100644
57848 index 0000000..3efe141
57849 --- /dev/null
57850 +++ b/grsecurity/grsec_link.c
57851 @@ -0,0 +1,43 @@
57852 +#include <linux/kernel.h>
57853 +#include <linux/sched.h>
57854 +#include <linux/fs.h>
57855 +#include <linux/file.h>
57856 +#include <linux/grinternal.h>
57857 +
57858 +int
57859 +gr_handle_follow_link(const struct inode *parent,
57860 + const struct inode *inode,
57861 + const struct dentry *dentry, const struct vfsmount *mnt)
57862 +{
57863 +#ifdef CONFIG_GRKERNSEC_LINK
57864 + const struct cred *cred = current_cred();
57865 +
57866 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
57867 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
57868 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
57869 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
57870 + return -EACCES;
57871 + }
57872 +#endif
57873 + return 0;
57874 +}
57875 +
57876 +int
57877 +gr_handle_hardlink(const struct dentry *dentry,
57878 + const struct vfsmount *mnt,
57879 + struct inode *inode, const int mode, const char *to)
57880 +{
57881 +#ifdef CONFIG_GRKERNSEC_LINK
57882 + const struct cred *cred = current_cred();
57883 +
57884 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
57885 + (!S_ISREG(mode) || (mode & S_ISUID) ||
57886 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
57887 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
57888 + !capable(CAP_FOWNER) && cred->uid) {
57889 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
57890 + return -EPERM;
57891 + }
57892 +#endif
57893 + return 0;
57894 +}
57895 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
57896 new file mode 100644
57897 index 0000000..a45d2e9
57898 --- /dev/null
57899 +++ b/grsecurity/grsec_log.c
57900 @@ -0,0 +1,322 @@
57901 +#include <linux/kernel.h>
57902 +#include <linux/sched.h>
57903 +#include <linux/file.h>
57904 +#include <linux/tty.h>
57905 +#include <linux/fs.h>
57906 +#include <linux/grinternal.h>
57907 +
57908 +#ifdef CONFIG_TREE_PREEMPT_RCU
57909 +#define DISABLE_PREEMPT() preempt_disable()
57910 +#define ENABLE_PREEMPT() preempt_enable()
57911 +#else
57912 +#define DISABLE_PREEMPT()
57913 +#define ENABLE_PREEMPT()
57914 +#endif
57915 +
57916 +#define BEGIN_LOCKS(x) \
57917 + DISABLE_PREEMPT(); \
57918 + rcu_read_lock(); \
57919 + read_lock(&tasklist_lock); \
57920 + read_lock(&grsec_exec_file_lock); \
57921 + if (x != GR_DO_AUDIT) \
57922 + spin_lock(&grsec_alert_lock); \
57923 + else \
57924 + spin_lock(&grsec_audit_lock)
57925 +
57926 +#define END_LOCKS(x) \
57927 + if (x != GR_DO_AUDIT) \
57928 + spin_unlock(&grsec_alert_lock); \
57929 + else \
57930 + spin_unlock(&grsec_audit_lock); \
57931 + read_unlock(&grsec_exec_file_lock); \
57932 + read_unlock(&tasklist_lock); \
57933 + rcu_read_unlock(); \
57934 + ENABLE_PREEMPT(); \
57935 + if (x == GR_DONT_AUDIT) \
57936 + gr_handle_alertkill(current)
57937 +
57938 +enum {
57939 + FLOODING,
57940 + NO_FLOODING
57941 +};
57942 +
57943 +extern char *gr_alert_log_fmt;
57944 +extern char *gr_audit_log_fmt;
57945 +extern char *gr_alert_log_buf;
57946 +extern char *gr_audit_log_buf;
57947 +
57948 +static int gr_log_start(int audit)
57949 +{
57950 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
57951 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
57952 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57953 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
57954 + unsigned long curr_secs = get_seconds();
57955 +
57956 + if (audit == GR_DO_AUDIT)
57957 + goto set_fmt;
57958 +
57959 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
57960 + grsec_alert_wtime = curr_secs;
57961 + grsec_alert_fyet = 0;
57962 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
57963 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
57964 + grsec_alert_fyet++;
57965 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
57966 + grsec_alert_wtime = curr_secs;
57967 + grsec_alert_fyet++;
57968 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
57969 + return FLOODING;
57970 + }
57971 + else return FLOODING;
57972 +
57973 +set_fmt:
57974 +#endif
57975 + memset(buf, 0, PAGE_SIZE);
57976 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
57977 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
57978 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57979 + } else if (current->signal->curr_ip) {
57980 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
57981 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
57982 + } else if (gr_acl_is_enabled()) {
57983 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
57984 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
57985 + } else {
57986 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
57987 + strcpy(buf, fmt);
57988 + }
57989 +
57990 + return NO_FLOODING;
57991 +}
57992 +
57993 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57994 + __attribute__ ((format (printf, 2, 0)));
57995 +
57996 +static void gr_log_middle(int audit, const char *msg, va_list ap)
57997 +{
57998 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
57999 + unsigned int len = strlen(buf);
58000 +
58001 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58002 +
58003 + return;
58004 +}
58005 +
58006 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58007 + __attribute__ ((format (printf, 2, 3)));
58008 +
58009 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58010 +{
58011 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58012 + unsigned int len = strlen(buf);
58013 + va_list ap;
58014 +
58015 + va_start(ap, msg);
58016 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58017 + va_end(ap);
58018 +
58019 + return;
58020 +}
58021 +
58022 +static void gr_log_end(int audit, int append_default)
58023 +{
58024 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58025 +
58026 + if (append_default) {
58027 + unsigned int len = strlen(buf);
58028 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58029 + }
58030 +
58031 + printk("%s\n", buf);
58032 +
58033 + return;
58034 +}
58035 +
58036 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58037 +{
58038 + int logtype;
58039 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58040 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58041 + void *voidptr = NULL;
58042 + int num1 = 0, num2 = 0;
58043 + unsigned long ulong1 = 0, ulong2 = 0;
58044 + struct dentry *dentry = NULL;
58045 + struct vfsmount *mnt = NULL;
58046 + struct file *file = NULL;
58047 + struct task_struct *task = NULL;
58048 + const struct cred *cred, *pcred;
58049 + va_list ap;
58050 +
58051 + BEGIN_LOCKS(audit);
58052 + logtype = gr_log_start(audit);
58053 + if (logtype == FLOODING) {
58054 + END_LOCKS(audit);
58055 + return;
58056 + }
58057 + va_start(ap, argtypes);
58058 + switch (argtypes) {
58059 + case GR_TTYSNIFF:
58060 + task = va_arg(ap, struct task_struct *);
58061 + 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);
58062 + break;
58063 + case GR_SYSCTL_HIDDEN:
58064 + str1 = va_arg(ap, char *);
58065 + gr_log_middle_varargs(audit, msg, result, str1);
58066 + break;
58067 + case GR_RBAC:
58068 + dentry = va_arg(ap, struct dentry *);
58069 + mnt = va_arg(ap, struct vfsmount *);
58070 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58071 + break;
58072 + case GR_RBAC_STR:
58073 + dentry = va_arg(ap, struct dentry *);
58074 + mnt = va_arg(ap, struct vfsmount *);
58075 + str1 = va_arg(ap, char *);
58076 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58077 + break;
58078 + case GR_STR_RBAC:
58079 + str1 = va_arg(ap, char *);
58080 + dentry = va_arg(ap, struct dentry *);
58081 + mnt = va_arg(ap, struct vfsmount *);
58082 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58083 + break;
58084 + case GR_RBAC_MODE2:
58085 + dentry = va_arg(ap, struct dentry *);
58086 + mnt = va_arg(ap, struct vfsmount *);
58087 + str1 = va_arg(ap, char *);
58088 + str2 = va_arg(ap, char *);
58089 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58090 + break;
58091 + case GR_RBAC_MODE3:
58092 + dentry = va_arg(ap, struct dentry *);
58093 + mnt = va_arg(ap, struct vfsmount *);
58094 + str1 = va_arg(ap, char *);
58095 + str2 = va_arg(ap, char *);
58096 + str3 = va_arg(ap, char *);
58097 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58098 + break;
58099 + case GR_FILENAME:
58100 + dentry = va_arg(ap, struct dentry *);
58101 + mnt = va_arg(ap, struct vfsmount *);
58102 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58103 + break;
58104 + case GR_STR_FILENAME:
58105 + str1 = va_arg(ap, char *);
58106 + dentry = va_arg(ap, struct dentry *);
58107 + mnt = va_arg(ap, struct vfsmount *);
58108 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58109 + break;
58110 + case GR_FILENAME_STR:
58111 + dentry = va_arg(ap, struct dentry *);
58112 + mnt = va_arg(ap, struct vfsmount *);
58113 + str1 = va_arg(ap, char *);
58114 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58115 + break;
58116 + case GR_FILENAME_TWO_INT:
58117 + dentry = va_arg(ap, struct dentry *);
58118 + mnt = va_arg(ap, struct vfsmount *);
58119 + num1 = va_arg(ap, int);
58120 + num2 = va_arg(ap, int);
58121 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58122 + break;
58123 + case GR_FILENAME_TWO_INT_STR:
58124 + dentry = va_arg(ap, struct dentry *);
58125 + mnt = va_arg(ap, struct vfsmount *);
58126 + num1 = va_arg(ap, int);
58127 + num2 = va_arg(ap, int);
58128 + str1 = va_arg(ap, char *);
58129 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58130 + break;
58131 + case GR_TEXTREL:
58132 + file = va_arg(ap, struct file *);
58133 + ulong1 = va_arg(ap, unsigned long);
58134 + ulong2 = va_arg(ap, unsigned long);
58135 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58136 + break;
58137 + case GR_PTRACE:
58138 + task = va_arg(ap, struct task_struct *);
58139 + 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);
58140 + break;
58141 + case GR_RESOURCE:
58142 + task = va_arg(ap, struct task_struct *);
58143 + cred = __task_cred(task);
58144 + pcred = __task_cred(task->real_parent);
58145 + ulong1 = va_arg(ap, unsigned long);
58146 + str1 = va_arg(ap, char *);
58147 + ulong2 = va_arg(ap, unsigned long);
58148 + 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);
58149 + break;
58150 + case GR_CAP:
58151 + task = va_arg(ap, struct task_struct *);
58152 + cred = __task_cred(task);
58153 + pcred = __task_cred(task->real_parent);
58154 + str1 = va_arg(ap, char *);
58155 + 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);
58156 + break;
58157 + case GR_SIG:
58158 + str1 = va_arg(ap, char *);
58159 + voidptr = va_arg(ap, void *);
58160 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58161 + break;
58162 + case GR_SIG2:
58163 + task = va_arg(ap, struct task_struct *);
58164 + cred = __task_cred(task);
58165 + pcred = __task_cred(task->real_parent);
58166 + num1 = va_arg(ap, int);
58167 + 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);
58168 + break;
58169 + case GR_CRASH1:
58170 + task = va_arg(ap, struct task_struct *);
58171 + cred = __task_cred(task);
58172 + pcred = __task_cred(task->real_parent);
58173 + ulong1 = va_arg(ap, unsigned long);
58174 + 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);
58175 + break;
58176 + case GR_CRASH2:
58177 + task = va_arg(ap, struct task_struct *);
58178 + cred = __task_cred(task);
58179 + pcred = __task_cred(task->real_parent);
58180 + ulong1 = va_arg(ap, unsigned long);
58181 + 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);
58182 + break;
58183 + case GR_RWXMAP:
58184 + file = va_arg(ap, struct file *);
58185 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58186 + break;
58187 + case GR_PSACCT:
58188 + {
58189 + unsigned int wday, cday;
58190 + __u8 whr, chr;
58191 + __u8 wmin, cmin;
58192 + __u8 wsec, csec;
58193 + char cur_tty[64] = { 0 };
58194 + char parent_tty[64] = { 0 };
58195 +
58196 + task = va_arg(ap, struct task_struct *);
58197 + wday = va_arg(ap, unsigned int);
58198 + cday = va_arg(ap, unsigned int);
58199 + whr = va_arg(ap, int);
58200 + chr = va_arg(ap, int);
58201 + wmin = va_arg(ap, int);
58202 + cmin = va_arg(ap, int);
58203 + wsec = va_arg(ap, int);
58204 + csec = va_arg(ap, int);
58205 + ulong1 = va_arg(ap, unsigned long);
58206 + cred = __task_cred(task);
58207 + pcred = __task_cred(task->real_parent);
58208 +
58209 + 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);
58210 + }
58211 + break;
58212 + default:
58213 + gr_log_middle(audit, msg, ap);
58214 + }
58215 + va_end(ap);
58216 + // these don't need DEFAULTSECARGS printed on the end
58217 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
58218 + gr_log_end(audit, 0);
58219 + else
58220 + gr_log_end(audit, 1);
58221 + END_LOCKS(audit);
58222 +}
58223 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
58224 new file mode 100644
58225 index 0000000..f536303
58226 --- /dev/null
58227 +++ b/grsecurity/grsec_mem.c
58228 @@ -0,0 +1,40 @@
58229 +#include <linux/kernel.h>
58230 +#include <linux/sched.h>
58231 +#include <linux/mm.h>
58232 +#include <linux/mman.h>
58233 +#include <linux/grinternal.h>
58234 +
58235 +void
58236 +gr_handle_ioperm(void)
58237 +{
58238 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
58239 + return;
58240 +}
58241 +
58242 +void
58243 +gr_handle_iopl(void)
58244 +{
58245 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
58246 + return;
58247 +}
58248 +
58249 +void
58250 +gr_handle_mem_readwrite(u64 from, u64 to)
58251 +{
58252 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
58253 + return;
58254 +}
58255 +
58256 +void
58257 +gr_handle_vm86(void)
58258 +{
58259 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
58260 + return;
58261 +}
58262 +
58263 +void
58264 +gr_log_badprocpid(const char *entry)
58265 +{
58266 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
58267 + return;
58268 +}
58269 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
58270 new file mode 100644
58271 index 0000000..2131422
58272 --- /dev/null
58273 +++ b/grsecurity/grsec_mount.c
58274 @@ -0,0 +1,62 @@
58275 +#include <linux/kernel.h>
58276 +#include <linux/sched.h>
58277 +#include <linux/mount.h>
58278 +#include <linux/grsecurity.h>
58279 +#include <linux/grinternal.h>
58280 +
58281 +void
58282 +gr_log_remount(const char *devname, const int retval)
58283 +{
58284 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58285 + if (grsec_enable_mount && (retval >= 0))
58286 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
58287 +#endif
58288 + return;
58289 +}
58290 +
58291 +void
58292 +gr_log_unmount(const char *devname, const int retval)
58293 +{
58294 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58295 + if (grsec_enable_mount && (retval >= 0))
58296 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
58297 +#endif
58298 + return;
58299 +}
58300 +
58301 +void
58302 +gr_log_mount(const char *from, const char *to, const int retval)
58303 +{
58304 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58305 + if (grsec_enable_mount && (retval >= 0))
58306 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
58307 +#endif
58308 + return;
58309 +}
58310 +
58311 +int
58312 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
58313 +{
58314 +#ifdef CONFIG_GRKERNSEC_ROFS
58315 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
58316 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
58317 + return -EPERM;
58318 + } else
58319 + return 0;
58320 +#endif
58321 + return 0;
58322 +}
58323 +
58324 +int
58325 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
58326 +{
58327 +#ifdef CONFIG_GRKERNSEC_ROFS
58328 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
58329 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
58330 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
58331 + return -EPERM;
58332 + } else
58333 + return 0;
58334 +#endif
58335 + return 0;
58336 +}
58337 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
58338 new file mode 100644
58339 index 0000000..a3b12a0
58340 --- /dev/null
58341 +++ b/grsecurity/grsec_pax.c
58342 @@ -0,0 +1,36 @@
58343 +#include <linux/kernel.h>
58344 +#include <linux/sched.h>
58345 +#include <linux/mm.h>
58346 +#include <linux/file.h>
58347 +#include <linux/grinternal.h>
58348 +#include <linux/grsecurity.h>
58349 +
58350 +void
58351 +gr_log_textrel(struct vm_area_struct * vma)
58352 +{
58353 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58354 + if (grsec_enable_audit_textrel)
58355 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
58356 +#endif
58357 + return;
58358 +}
58359 +
58360 +void
58361 +gr_log_rwxmmap(struct file *file)
58362 +{
58363 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58364 + if (grsec_enable_log_rwxmaps)
58365 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
58366 +#endif
58367 + return;
58368 +}
58369 +
58370 +void
58371 +gr_log_rwxmprotect(struct file *file)
58372 +{
58373 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58374 + if (grsec_enable_log_rwxmaps)
58375 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
58376 +#endif
58377 + return;
58378 +}
58379 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
58380 new file mode 100644
58381 index 0000000..f7f29aa
58382 --- /dev/null
58383 +++ b/grsecurity/grsec_ptrace.c
58384 @@ -0,0 +1,30 @@
58385 +#include <linux/kernel.h>
58386 +#include <linux/sched.h>
58387 +#include <linux/grinternal.h>
58388 +#include <linux/security.h>
58389 +
58390 +void
58391 +gr_audit_ptrace(struct task_struct *task)
58392 +{
58393 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58394 + if (grsec_enable_audit_ptrace)
58395 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
58396 +#endif
58397 + return;
58398 +}
58399 +
58400 +int
58401 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
58402 +{
58403 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58404 + const struct dentry *dentry = file->f_path.dentry;
58405 + const struct vfsmount *mnt = file->f_path.mnt;
58406 +
58407 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
58408 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
58409 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
58410 + return -EACCES;
58411 + }
58412 +#endif
58413 + return 0;
58414 +}
58415 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
58416 new file mode 100644
58417 index 0000000..7a5b2de
58418 --- /dev/null
58419 +++ b/grsecurity/grsec_sig.c
58420 @@ -0,0 +1,207 @@
58421 +#include <linux/kernel.h>
58422 +#include <linux/sched.h>
58423 +#include <linux/delay.h>
58424 +#include <linux/grsecurity.h>
58425 +#include <linux/grinternal.h>
58426 +#include <linux/hardirq.h>
58427 +
58428 +char *signames[] = {
58429 + [SIGSEGV] = "Segmentation fault",
58430 + [SIGILL] = "Illegal instruction",
58431 + [SIGABRT] = "Abort",
58432 + [SIGBUS] = "Invalid alignment/Bus error"
58433 +};
58434 +
58435 +void
58436 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
58437 +{
58438 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58439 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
58440 + (sig == SIGABRT) || (sig == SIGBUS))) {
58441 + if (t->pid == current->pid) {
58442 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
58443 + } else {
58444 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
58445 + }
58446 + }
58447 +#endif
58448 + return;
58449 +}
58450 +
58451 +int
58452 +gr_handle_signal(const struct task_struct *p, const int sig)
58453 +{
58454 +#ifdef CONFIG_GRKERNSEC
58455 + /* ignore the 0 signal for protected task checks */
58456 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
58457 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
58458 + return -EPERM;
58459 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
58460 + return -EPERM;
58461 + }
58462 +#endif
58463 + return 0;
58464 +}
58465 +
58466 +#ifdef CONFIG_GRKERNSEC
58467 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
58468 +
58469 +int gr_fake_force_sig(int sig, struct task_struct *t)
58470 +{
58471 + unsigned long int flags;
58472 + int ret, blocked, ignored;
58473 + struct k_sigaction *action;
58474 +
58475 + spin_lock_irqsave(&t->sighand->siglock, flags);
58476 + action = &t->sighand->action[sig-1];
58477 + ignored = action->sa.sa_handler == SIG_IGN;
58478 + blocked = sigismember(&t->blocked, sig);
58479 + if (blocked || ignored) {
58480 + action->sa.sa_handler = SIG_DFL;
58481 + if (blocked) {
58482 + sigdelset(&t->blocked, sig);
58483 + recalc_sigpending_and_wake(t);
58484 + }
58485 + }
58486 + if (action->sa.sa_handler == SIG_DFL)
58487 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
58488 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
58489 +
58490 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
58491 +
58492 + return ret;
58493 +}
58494 +#endif
58495 +
58496 +#ifdef CONFIG_GRKERNSEC_BRUTE
58497 +#define GR_USER_BAN_TIME (15 * 60)
58498 +
58499 +static int __get_dumpable(unsigned long mm_flags)
58500 +{
58501 + int ret;
58502 +
58503 + ret = mm_flags & MMF_DUMPABLE_MASK;
58504 + return (ret >= 2) ? 2 : ret;
58505 +}
58506 +#endif
58507 +
58508 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
58509 +{
58510 +#ifdef CONFIG_GRKERNSEC_BRUTE
58511 + uid_t uid = 0;
58512 +
58513 + if (!grsec_enable_brute)
58514 + return;
58515 +
58516 + rcu_read_lock();
58517 + read_lock(&tasklist_lock);
58518 + read_lock(&grsec_exec_file_lock);
58519 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
58520 + p->real_parent->brute = 1;
58521 + else {
58522 + const struct cred *cred = __task_cred(p), *cred2;
58523 + struct task_struct *tsk, *tsk2;
58524 +
58525 + if (!__get_dumpable(mm_flags) && cred->uid) {
58526 + struct user_struct *user;
58527 +
58528 + uid = cred->uid;
58529 +
58530 + /* this is put upon execution past expiration */
58531 + user = find_user(uid);
58532 + if (user == NULL)
58533 + goto unlock;
58534 + user->banned = 1;
58535 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
58536 + if (user->ban_expires == ~0UL)
58537 + user->ban_expires--;
58538 +
58539 + do_each_thread(tsk2, tsk) {
58540 + cred2 = __task_cred(tsk);
58541 + if (tsk != p && cred2->uid == uid)
58542 + gr_fake_force_sig(SIGKILL, tsk);
58543 + } while_each_thread(tsk2, tsk);
58544 + }
58545 + }
58546 +unlock:
58547 + read_unlock(&grsec_exec_file_lock);
58548 + read_unlock(&tasklist_lock);
58549 + rcu_read_unlock();
58550 +
58551 + if (uid)
58552 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
58553 +
58554 +#endif
58555 + return;
58556 +}
58557 +
58558 +void gr_handle_brute_check(void)
58559 +{
58560 +#ifdef CONFIG_GRKERNSEC_BRUTE
58561 + if (current->brute)
58562 + msleep(30 * 1000);
58563 +#endif
58564 + return;
58565 +}
58566 +
58567 +void gr_handle_kernel_exploit(void)
58568 +{
58569 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
58570 + const struct cred *cred;
58571 + struct task_struct *tsk, *tsk2;
58572 + struct user_struct *user;
58573 + uid_t uid;
58574 +
58575 + if (in_irq() || in_serving_softirq() || in_nmi())
58576 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
58577 +
58578 + uid = current_uid();
58579 +
58580 + if (uid == 0)
58581 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
58582 + else {
58583 + /* kill all the processes of this user, hold a reference
58584 + to their creds struct, and prevent them from creating
58585 + another process until system reset
58586 + */
58587 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
58588 + /* we intentionally leak this ref */
58589 + user = get_uid(current->cred->user);
58590 + if (user) {
58591 + user->banned = 1;
58592 + user->ban_expires = ~0UL;
58593 + }
58594 +
58595 + read_lock(&tasklist_lock);
58596 + do_each_thread(tsk2, tsk) {
58597 + cred = __task_cred(tsk);
58598 + if (cred->uid == uid)
58599 + gr_fake_force_sig(SIGKILL, tsk);
58600 + } while_each_thread(tsk2, tsk);
58601 + read_unlock(&tasklist_lock);
58602 + }
58603 +#endif
58604 +}
58605 +
58606 +int __gr_process_user_ban(struct user_struct *user)
58607 +{
58608 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58609 + if (unlikely(user->banned)) {
58610 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
58611 + user->banned = 0;
58612 + user->ban_expires = 0;
58613 + free_uid(user);
58614 + } else
58615 + return -EPERM;
58616 + }
58617 +#endif
58618 + return 0;
58619 +}
58620 +
58621 +int gr_process_user_ban(void)
58622 +{
58623 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
58624 + return __gr_process_user_ban(current->cred->user);
58625 +#endif
58626 + return 0;
58627 +}
58628 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
58629 new file mode 100644
58630 index 0000000..4030d57
58631 --- /dev/null
58632 +++ b/grsecurity/grsec_sock.c
58633 @@ -0,0 +1,244 @@
58634 +#include <linux/kernel.h>
58635 +#include <linux/module.h>
58636 +#include <linux/sched.h>
58637 +#include <linux/file.h>
58638 +#include <linux/net.h>
58639 +#include <linux/in.h>
58640 +#include <linux/ip.h>
58641 +#include <net/sock.h>
58642 +#include <net/inet_sock.h>
58643 +#include <linux/grsecurity.h>
58644 +#include <linux/grinternal.h>
58645 +#include <linux/gracl.h>
58646 +
58647 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
58648 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
58649 +
58650 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
58651 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
58652 +
58653 +#ifdef CONFIG_UNIX_MODULE
58654 +EXPORT_SYMBOL(gr_acl_handle_unix);
58655 +EXPORT_SYMBOL(gr_acl_handle_mknod);
58656 +EXPORT_SYMBOL(gr_handle_chroot_unix);
58657 +EXPORT_SYMBOL(gr_handle_create);
58658 +#endif
58659 +
58660 +#ifdef CONFIG_GRKERNSEC
58661 +#define gr_conn_table_size 32749
58662 +struct conn_table_entry {
58663 + struct conn_table_entry *next;
58664 + struct signal_struct *sig;
58665 +};
58666 +
58667 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
58668 +DEFINE_SPINLOCK(gr_conn_table_lock);
58669 +
58670 +extern const char * gr_socktype_to_name(unsigned char type);
58671 +extern const char * gr_proto_to_name(unsigned char proto);
58672 +extern const char * gr_sockfamily_to_name(unsigned char family);
58673 +
58674 +static __inline__ int
58675 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
58676 +{
58677 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
58678 +}
58679 +
58680 +static __inline__ int
58681 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
58682 + __u16 sport, __u16 dport)
58683 +{
58684 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
58685 + sig->gr_sport == sport && sig->gr_dport == dport))
58686 + return 1;
58687 + else
58688 + return 0;
58689 +}
58690 +
58691 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
58692 +{
58693 + struct conn_table_entry **match;
58694 + unsigned int index;
58695 +
58696 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58697 + sig->gr_sport, sig->gr_dport,
58698 + gr_conn_table_size);
58699 +
58700 + newent->sig = sig;
58701 +
58702 + match = &gr_conn_table[index];
58703 + newent->next = *match;
58704 + *match = newent;
58705 +
58706 + return;
58707 +}
58708 +
58709 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
58710 +{
58711 + struct conn_table_entry *match, *last = NULL;
58712 + unsigned int index;
58713 +
58714 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
58715 + sig->gr_sport, sig->gr_dport,
58716 + gr_conn_table_size);
58717 +
58718 + match = gr_conn_table[index];
58719 + while (match && !conn_match(match->sig,
58720 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
58721 + sig->gr_dport)) {
58722 + last = match;
58723 + match = match->next;
58724 + }
58725 +
58726 + if (match) {
58727 + if (last)
58728 + last->next = match->next;
58729 + else
58730 + gr_conn_table[index] = NULL;
58731 + kfree(match);
58732 + }
58733 +
58734 + return;
58735 +}
58736 +
58737 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
58738 + __u16 sport, __u16 dport)
58739 +{
58740 + struct conn_table_entry *match;
58741 + unsigned int index;
58742 +
58743 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
58744 +
58745 + match = gr_conn_table[index];
58746 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
58747 + match = match->next;
58748 +
58749 + if (match)
58750 + return match->sig;
58751 + else
58752 + return NULL;
58753 +}
58754 +
58755 +#endif
58756 +
58757 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
58758 +{
58759 +#ifdef CONFIG_GRKERNSEC
58760 + struct signal_struct *sig = task->signal;
58761 + struct conn_table_entry *newent;
58762 +
58763 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
58764 + if (newent == NULL)
58765 + return;
58766 + /* no bh lock needed since we are called with bh disabled */
58767 + spin_lock(&gr_conn_table_lock);
58768 + gr_del_task_from_ip_table_nolock(sig);
58769 + sig->gr_saddr = inet->inet_rcv_saddr;
58770 + sig->gr_daddr = inet->inet_daddr;
58771 + sig->gr_sport = inet->inet_sport;
58772 + sig->gr_dport = inet->inet_dport;
58773 + gr_add_to_task_ip_table_nolock(sig, newent);
58774 + spin_unlock(&gr_conn_table_lock);
58775 +#endif
58776 + return;
58777 +}
58778 +
58779 +void gr_del_task_from_ip_table(struct task_struct *task)
58780 +{
58781 +#ifdef CONFIG_GRKERNSEC
58782 + spin_lock_bh(&gr_conn_table_lock);
58783 + gr_del_task_from_ip_table_nolock(task->signal);
58784 + spin_unlock_bh(&gr_conn_table_lock);
58785 +#endif
58786 + return;
58787 +}
58788 +
58789 +void
58790 +gr_attach_curr_ip(const struct sock *sk)
58791 +{
58792 +#ifdef CONFIG_GRKERNSEC
58793 + struct signal_struct *p, *set;
58794 + const struct inet_sock *inet = inet_sk(sk);
58795 +
58796 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
58797 + return;
58798 +
58799 + set = current->signal;
58800 +
58801 + spin_lock_bh(&gr_conn_table_lock);
58802 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
58803 + inet->inet_dport, inet->inet_sport);
58804 + if (unlikely(p != NULL)) {
58805 + set->curr_ip = p->curr_ip;
58806 + set->used_accept = 1;
58807 + gr_del_task_from_ip_table_nolock(p);
58808 + spin_unlock_bh(&gr_conn_table_lock);
58809 + return;
58810 + }
58811 + spin_unlock_bh(&gr_conn_table_lock);
58812 +
58813 + set->curr_ip = inet->inet_daddr;
58814 + set->used_accept = 1;
58815 +#endif
58816 + return;
58817 +}
58818 +
58819 +int
58820 +gr_handle_sock_all(const int family, const int type, const int protocol)
58821 +{
58822 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58823 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
58824 + (family != AF_UNIX)) {
58825 + if (family == AF_INET)
58826 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
58827 + else
58828 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
58829 + return -EACCES;
58830 + }
58831 +#endif
58832 + return 0;
58833 +}
58834 +
58835 +int
58836 +gr_handle_sock_server(const struct sockaddr *sck)
58837 +{
58838 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58839 + if (grsec_enable_socket_server &&
58840 + in_group_p(grsec_socket_server_gid) &&
58841 + sck && (sck->sa_family != AF_UNIX) &&
58842 + (sck->sa_family != AF_LOCAL)) {
58843 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58844 + return -EACCES;
58845 + }
58846 +#endif
58847 + return 0;
58848 +}
58849 +
58850 +int
58851 +gr_handle_sock_server_other(const struct sock *sck)
58852 +{
58853 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58854 + if (grsec_enable_socket_server &&
58855 + in_group_p(grsec_socket_server_gid) &&
58856 + sck && (sck->sk_family != AF_UNIX) &&
58857 + (sck->sk_family != AF_LOCAL)) {
58858 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
58859 + return -EACCES;
58860 + }
58861 +#endif
58862 + return 0;
58863 +}
58864 +
58865 +int
58866 +gr_handle_sock_client(const struct sockaddr *sck)
58867 +{
58868 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58869 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
58870 + sck && (sck->sa_family != AF_UNIX) &&
58871 + (sck->sa_family != AF_LOCAL)) {
58872 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
58873 + return -EACCES;
58874 + }
58875 +#endif
58876 + return 0;
58877 +}
58878 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
58879 new file mode 100644
58880 index 0000000..a1aedd7
58881 --- /dev/null
58882 +++ b/grsecurity/grsec_sysctl.c
58883 @@ -0,0 +1,451 @@
58884 +#include <linux/kernel.h>
58885 +#include <linux/sched.h>
58886 +#include <linux/sysctl.h>
58887 +#include <linux/grsecurity.h>
58888 +#include <linux/grinternal.h>
58889 +
58890 +int
58891 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
58892 +{
58893 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58894 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
58895 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
58896 + return -EACCES;
58897 + }
58898 +#endif
58899 + return 0;
58900 +}
58901 +
58902 +#ifdef CONFIG_GRKERNSEC_ROFS
58903 +static int __maybe_unused one = 1;
58904 +#endif
58905 +
58906 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
58907 +struct ctl_table grsecurity_table[] = {
58908 +#ifdef CONFIG_GRKERNSEC_SYSCTL
58909 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
58910 +#ifdef CONFIG_GRKERNSEC_IO
58911 + {
58912 + .procname = "disable_priv_io",
58913 + .data = &grsec_disable_privio,
58914 + .maxlen = sizeof(int),
58915 + .mode = 0600,
58916 + .proc_handler = &proc_dointvec,
58917 + },
58918 +#endif
58919 +#endif
58920 +#ifdef CONFIG_GRKERNSEC_LINK
58921 + {
58922 + .procname = "linking_restrictions",
58923 + .data = &grsec_enable_link,
58924 + .maxlen = sizeof(int),
58925 + .mode = 0600,
58926 + .proc_handler = &proc_dointvec,
58927 + },
58928 +#endif
58929 +#ifdef CONFIG_GRKERNSEC_BRUTE
58930 + {
58931 + .procname = "deter_bruteforce",
58932 + .data = &grsec_enable_brute,
58933 + .maxlen = sizeof(int),
58934 + .mode = 0600,
58935 + .proc_handler = &proc_dointvec,
58936 + },
58937 +#endif
58938 +#ifdef CONFIG_GRKERNSEC_FIFO
58939 + {
58940 + .procname = "fifo_restrictions",
58941 + .data = &grsec_enable_fifo,
58942 + .maxlen = sizeof(int),
58943 + .mode = 0600,
58944 + .proc_handler = &proc_dointvec,
58945 + },
58946 +#endif
58947 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58948 + {
58949 + .procname = "ptrace_readexec",
58950 + .data = &grsec_enable_ptrace_readexec,
58951 + .maxlen = sizeof(int),
58952 + .mode = 0600,
58953 + .proc_handler = &proc_dointvec,
58954 + },
58955 +#endif
58956 +#ifdef CONFIG_GRKERNSEC_SETXID
58957 + {
58958 + .procname = "consistent_setxid",
58959 + .data = &grsec_enable_setxid,
58960 + .maxlen = sizeof(int),
58961 + .mode = 0600,
58962 + .proc_handler = &proc_dointvec,
58963 + },
58964 +#endif
58965 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58966 + {
58967 + .procname = "ip_blackhole",
58968 + .data = &grsec_enable_blackhole,
58969 + .maxlen = sizeof(int),
58970 + .mode = 0600,
58971 + .proc_handler = &proc_dointvec,
58972 + },
58973 + {
58974 + .procname = "lastack_retries",
58975 + .data = &grsec_lastack_retries,
58976 + .maxlen = sizeof(int),
58977 + .mode = 0600,
58978 + .proc_handler = &proc_dointvec,
58979 + },
58980 +#endif
58981 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58982 + {
58983 + .procname = "exec_logging",
58984 + .data = &grsec_enable_execlog,
58985 + .maxlen = sizeof(int),
58986 + .mode = 0600,
58987 + .proc_handler = &proc_dointvec,
58988 + },
58989 +#endif
58990 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58991 + {
58992 + .procname = "rwxmap_logging",
58993 + .data = &grsec_enable_log_rwxmaps,
58994 + .maxlen = sizeof(int),
58995 + .mode = 0600,
58996 + .proc_handler = &proc_dointvec,
58997 + },
58998 +#endif
58999 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59000 + {
59001 + .procname = "signal_logging",
59002 + .data = &grsec_enable_signal,
59003 + .maxlen = sizeof(int),
59004 + .mode = 0600,
59005 + .proc_handler = &proc_dointvec,
59006 + },
59007 +#endif
59008 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59009 + {
59010 + .procname = "forkfail_logging",
59011 + .data = &grsec_enable_forkfail,
59012 + .maxlen = sizeof(int),
59013 + .mode = 0600,
59014 + .proc_handler = &proc_dointvec,
59015 + },
59016 +#endif
59017 +#ifdef CONFIG_GRKERNSEC_TIME
59018 + {
59019 + .procname = "timechange_logging",
59020 + .data = &grsec_enable_time,
59021 + .maxlen = sizeof(int),
59022 + .mode = 0600,
59023 + .proc_handler = &proc_dointvec,
59024 + },
59025 +#endif
59026 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59027 + {
59028 + .procname = "chroot_deny_shmat",
59029 + .data = &grsec_enable_chroot_shmat,
59030 + .maxlen = sizeof(int),
59031 + .mode = 0600,
59032 + .proc_handler = &proc_dointvec,
59033 + },
59034 +#endif
59035 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59036 + {
59037 + .procname = "chroot_deny_unix",
59038 + .data = &grsec_enable_chroot_unix,
59039 + .maxlen = sizeof(int),
59040 + .mode = 0600,
59041 + .proc_handler = &proc_dointvec,
59042 + },
59043 +#endif
59044 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59045 + {
59046 + .procname = "chroot_deny_mount",
59047 + .data = &grsec_enable_chroot_mount,
59048 + .maxlen = sizeof(int),
59049 + .mode = 0600,
59050 + .proc_handler = &proc_dointvec,
59051 + },
59052 +#endif
59053 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59054 + {
59055 + .procname = "chroot_deny_fchdir",
59056 + .data = &grsec_enable_chroot_fchdir,
59057 + .maxlen = sizeof(int),
59058 + .mode = 0600,
59059 + .proc_handler = &proc_dointvec,
59060 + },
59061 +#endif
59062 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59063 + {
59064 + .procname = "chroot_deny_chroot",
59065 + .data = &grsec_enable_chroot_double,
59066 + .maxlen = sizeof(int),
59067 + .mode = 0600,
59068 + .proc_handler = &proc_dointvec,
59069 + },
59070 +#endif
59071 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59072 + {
59073 + .procname = "chroot_deny_pivot",
59074 + .data = &grsec_enable_chroot_pivot,
59075 + .maxlen = sizeof(int),
59076 + .mode = 0600,
59077 + .proc_handler = &proc_dointvec,
59078 + },
59079 +#endif
59080 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59081 + {
59082 + .procname = "chroot_enforce_chdir",
59083 + .data = &grsec_enable_chroot_chdir,
59084 + .maxlen = sizeof(int),
59085 + .mode = 0600,
59086 + .proc_handler = &proc_dointvec,
59087 + },
59088 +#endif
59089 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59090 + {
59091 + .procname = "chroot_deny_chmod",
59092 + .data = &grsec_enable_chroot_chmod,
59093 + .maxlen = sizeof(int),
59094 + .mode = 0600,
59095 + .proc_handler = &proc_dointvec,
59096 + },
59097 +#endif
59098 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59099 + {
59100 + .procname = "chroot_deny_mknod",
59101 + .data = &grsec_enable_chroot_mknod,
59102 + .maxlen = sizeof(int),
59103 + .mode = 0600,
59104 + .proc_handler = &proc_dointvec,
59105 + },
59106 +#endif
59107 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59108 + {
59109 + .procname = "chroot_restrict_nice",
59110 + .data = &grsec_enable_chroot_nice,
59111 + .maxlen = sizeof(int),
59112 + .mode = 0600,
59113 + .proc_handler = &proc_dointvec,
59114 + },
59115 +#endif
59116 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59117 + {
59118 + .procname = "chroot_execlog",
59119 + .data = &grsec_enable_chroot_execlog,
59120 + .maxlen = sizeof(int),
59121 + .mode = 0600,
59122 + .proc_handler = &proc_dointvec,
59123 + },
59124 +#endif
59125 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59126 + {
59127 + .procname = "chroot_caps",
59128 + .data = &grsec_enable_chroot_caps,
59129 + .maxlen = sizeof(int),
59130 + .mode = 0600,
59131 + .proc_handler = &proc_dointvec,
59132 + },
59133 +#endif
59134 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59135 + {
59136 + .procname = "chroot_deny_sysctl",
59137 + .data = &grsec_enable_chroot_sysctl,
59138 + .maxlen = sizeof(int),
59139 + .mode = 0600,
59140 + .proc_handler = &proc_dointvec,
59141 + },
59142 +#endif
59143 +#ifdef CONFIG_GRKERNSEC_TPE
59144 + {
59145 + .procname = "tpe",
59146 + .data = &grsec_enable_tpe,
59147 + .maxlen = sizeof(int),
59148 + .mode = 0600,
59149 + .proc_handler = &proc_dointvec,
59150 + },
59151 + {
59152 + .procname = "tpe_gid",
59153 + .data = &grsec_tpe_gid,
59154 + .maxlen = sizeof(int),
59155 + .mode = 0600,
59156 + .proc_handler = &proc_dointvec,
59157 + },
59158 +#endif
59159 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59160 + {
59161 + .procname = "tpe_invert",
59162 + .data = &grsec_enable_tpe_invert,
59163 + .maxlen = sizeof(int),
59164 + .mode = 0600,
59165 + .proc_handler = &proc_dointvec,
59166 + },
59167 +#endif
59168 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59169 + {
59170 + .procname = "tpe_restrict_all",
59171 + .data = &grsec_enable_tpe_all,
59172 + .maxlen = sizeof(int),
59173 + .mode = 0600,
59174 + .proc_handler = &proc_dointvec,
59175 + },
59176 +#endif
59177 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59178 + {
59179 + .procname = "socket_all",
59180 + .data = &grsec_enable_socket_all,
59181 + .maxlen = sizeof(int),
59182 + .mode = 0600,
59183 + .proc_handler = &proc_dointvec,
59184 + },
59185 + {
59186 + .procname = "socket_all_gid",
59187 + .data = &grsec_socket_all_gid,
59188 + .maxlen = sizeof(int),
59189 + .mode = 0600,
59190 + .proc_handler = &proc_dointvec,
59191 + },
59192 +#endif
59193 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59194 + {
59195 + .procname = "socket_client",
59196 + .data = &grsec_enable_socket_client,
59197 + .maxlen = sizeof(int),
59198 + .mode = 0600,
59199 + .proc_handler = &proc_dointvec,
59200 + },
59201 + {
59202 + .procname = "socket_client_gid",
59203 + .data = &grsec_socket_client_gid,
59204 + .maxlen = sizeof(int),
59205 + .mode = 0600,
59206 + .proc_handler = &proc_dointvec,
59207 + },
59208 +#endif
59209 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59210 + {
59211 + .procname = "socket_server",
59212 + .data = &grsec_enable_socket_server,
59213 + .maxlen = sizeof(int),
59214 + .mode = 0600,
59215 + .proc_handler = &proc_dointvec,
59216 + },
59217 + {
59218 + .procname = "socket_server_gid",
59219 + .data = &grsec_socket_server_gid,
59220 + .maxlen = sizeof(int),
59221 + .mode = 0600,
59222 + .proc_handler = &proc_dointvec,
59223 + },
59224 +#endif
59225 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
59226 + {
59227 + .procname = "audit_group",
59228 + .data = &grsec_enable_group,
59229 + .maxlen = sizeof(int),
59230 + .mode = 0600,
59231 + .proc_handler = &proc_dointvec,
59232 + },
59233 + {
59234 + .procname = "audit_gid",
59235 + .data = &grsec_audit_gid,
59236 + .maxlen = sizeof(int),
59237 + .mode = 0600,
59238 + .proc_handler = &proc_dointvec,
59239 + },
59240 +#endif
59241 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59242 + {
59243 + .procname = "audit_chdir",
59244 + .data = &grsec_enable_chdir,
59245 + .maxlen = sizeof(int),
59246 + .mode = 0600,
59247 + .proc_handler = &proc_dointvec,
59248 + },
59249 +#endif
59250 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59251 + {
59252 + .procname = "audit_mount",
59253 + .data = &grsec_enable_mount,
59254 + .maxlen = sizeof(int),
59255 + .mode = 0600,
59256 + .proc_handler = &proc_dointvec,
59257 + },
59258 +#endif
59259 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59260 + {
59261 + .procname = "audit_textrel",
59262 + .data = &grsec_enable_audit_textrel,
59263 + .maxlen = sizeof(int),
59264 + .mode = 0600,
59265 + .proc_handler = &proc_dointvec,
59266 + },
59267 +#endif
59268 +#ifdef CONFIG_GRKERNSEC_DMESG
59269 + {
59270 + .procname = "dmesg",
59271 + .data = &grsec_enable_dmesg,
59272 + .maxlen = sizeof(int),
59273 + .mode = 0600,
59274 + .proc_handler = &proc_dointvec,
59275 + },
59276 +#endif
59277 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59278 + {
59279 + .procname = "chroot_findtask",
59280 + .data = &grsec_enable_chroot_findtask,
59281 + .maxlen = sizeof(int),
59282 + .mode = 0600,
59283 + .proc_handler = &proc_dointvec,
59284 + },
59285 +#endif
59286 +#ifdef CONFIG_GRKERNSEC_RESLOG
59287 + {
59288 + .procname = "resource_logging",
59289 + .data = &grsec_resource_logging,
59290 + .maxlen = sizeof(int),
59291 + .mode = 0600,
59292 + .proc_handler = &proc_dointvec,
59293 + },
59294 +#endif
59295 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59296 + {
59297 + .procname = "audit_ptrace",
59298 + .data = &grsec_enable_audit_ptrace,
59299 + .maxlen = sizeof(int),
59300 + .mode = 0600,
59301 + .proc_handler = &proc_dointvec,
59302 + },
59303 +#endif
59304 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
59305 + {
59306 + .procname = "harden_ptrace",
59307 + .data = &grsec_enable_harden_ptrace,
59308 + .maxlen = sizeof(int),
59309 + .mode = 0600,
59310 + .proc_handler = &proc_dointvec,
59311 + },
59312 +#endif
59313 + {
59314 + .procname = "grsec_lock",
59315 + .data = &grsec_lock,
59316 + .maxlen = sizeof(int),
59317 + .mode = 0600,
59318 + .proc_handler = &proc_dointvec,
59319 + },
59320 +#endif
59321 +#ifdef CONFIG_GRKERNSEC_ROFS
59322 + {
59323 + .procname = "romount_protect",
59324 + .data = &grsec_enable_rofs,
59325 + .maxlen = sizeof(int),
59326 + .mode = 0600,
59327 + .proc_handler = &proc_dointvec_minmax,
59328 + .extra1 = &one,
59329 + .extra2 = &one,
59330 + },
59331 +#endif
59332 + { }
59333 +};
59334 +#endif
59335 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
59336 new file mode 100644
59337 index 0000000..0dc13c3
59338 --- /dev/null
59339 +++ b/grsecurity/grsec_time.c
59340 @@ -0,0 +1,16 @@
59341 +#include <linux/kernel.h>
59342 +#include <linux/sched.h>
59343 +#include <linux/grinternal.h>
59344 +#include <linux/module.h>
59345 +
59346 +void
59347 +gr_log_timechange(void)
59348 +{
59349 +#ifdef CONFIG_GRKERNSEC_TIME
59350 + if (grsec_enable_time)
59351 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
59352 +#endif
59353 + return;
59354 +}
59355 +
59356 +EXPORT_SYMBOL(gr_log_timechange);
59357 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
59358 new file mode 100644
59359 index 0000000..07e0dc0
59360 --- /dev/null
59361 +++ b/grsecurity/grsec_tpe.c
59362 @@ -0,0 +1,73 @@
59363 +#include <linux/kernel.h>
59364 +#include <linux/sched.h>
59365 +#include <linux/file.h>
59366 +#include <linux/fs.h>
59367 +#include <linux/grinternal.h>
59368 +
59369 +extern int gr_acl_tpe_check(void);
59370 +
59371 +int
59372 +gr_tpe_allow(const struct file *file)
59373 +{
59374 +#ifdef CONFIG_GRKERNSEC
59375 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
59376 + const struct cred *cred = current_cred();
59377 + char *msg = NULL;
59378 + char *msg2 = NULL;
59379 +
59380 + // never restrict root
59381 + if (!cred->uid)
59382 + return 1;
59383 +
59384 + if (grsec_enable_tpe) {
59385 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59386 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
59387 + msg = "not being in trusted group";
59388 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
59389 + msg = "being in untrusted group";
59390 +#else
59391 + if (in_group_p(grsec_tpe_gid))
59392 + msg = "being in untrusted group";
59393 +#endif
59394 + }
59395 + if (!msg && gr_acl_tpe_check())
59396 + msg = "being in untrusted role";
59397 +
59398 + // not in any affected group/role
59399 + if (!msg)
59400 + goto next_check;
59401 +
59402 + if (inode->i_uid)
59403 + msg2 = "file in non-root-owned directory";
59404 + else if (inode->i_mode & S_IWOTH)
59405 + msg2 = "file in world-writable directory";
59406 + else if (inode->i_mode & S_IWGRP)
59407 + msg2 = "file in group-writable directory";
59408 +
59409 + if (msg && msg2) {
59410 + char fullmsg[70] = {0};
59411 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
59412 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
59413 + return 0;
59414 + }
59415 + msg = NULL;
59416 +next_check:
59417 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
59418 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
59419 + return 1;
59420 +
59421 + if (inode->i_uid && (inode->i_uid != cred->uid))
59422 + msg = "directory not owned by user";
59423 + else if (inode->i_mode & S_IWOTH)
59424 + msg = "file in world-writable directory";
59425 + else if (inode->i_mode & S_IWGRP)
59426 + msg = "file in group-writable directory";
59427 +
59428 + if (msg) {
59429 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
59430 + return 0;
59431 + }
59432 +#endif
59433 +#endif
59434 + return 1;
59435 +}
59436 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
59437 new file mode 100644
59438 index 0000000..9f7b1ac
59439 --- /dev/null
59440 +++ b/grsecurity/grsum.c
59441 @@ -0,0 +1,61 @@
59442 +#include <linux/err.h>
59443 +#include <linux/kernel.h>
59444 +#include <linux/sched.h>
59445 +#include <linux/mm.h>
59446 +#include <linux/scatterlist.h>
59447 +#include <linux/crypto.h>
59448 +#include <linux/gracl.h>
59449 +
59450 +
59451 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
59452 +#error "crypto and sha256 must be built into the kernel"
59453 +#endif
59454 +
59455 +int
59456 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
59457 +{
59458 + char *p;
59459 + struct crypto_hash *tfm;
59460 + struct hash_desc desc;
59461 + struct scatterlist sg;
59462 + unsigned char temp_sum[GR_SHA_LEN];
59463 + volatile int retval = 0;
59464 + volatile int dummy = 0;
59465 + unsigned int i;
59466 +
59467 + sg_init_table(&sg, 1);
59468 +
59469 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
59470 + if (IS_ERR(tfm)) {
59471 + /* should never happen, since sha256 should be built in */
59472 + return 1;
59473 + }
59474 +
59475 + desc.tfm = tfm;
59476 + desc.flags = 0;
59477 +
59478 + crypto_hash_init(&desc);
59479 +
59480 + p = salt;
59481 + sg_set_buf(&sg, p, GR_SALT_LEN);
59482 + crypto_hash_update(&desc, &sg, sg.length);
59483 +
59484 + p = entry->pw;
59485 + sg_set_buf(&sg, p, strlen(p));
59486 +
59487 + crypto_hash_update(&desc, &sg, sg.length);
59488 +
59489 + crypto_hash_final(&desc, temp_sum);
59490 +
59491 + memset(entry->pw, 0, GR_PW_LEN);
59492 +
59493 + for (i = 0; i < GR_SHA_LEN; i++)
59494 + if (sum[i] != temp_sum[i])
59495 + retval = 1;
59496 + else
59497 + dummy = 1; // waste a cycle
59498 +
59499 + crypto_free_hash(tfm);
59500 +
59501 + return retval;
59502 +}
59503 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
59504 index 6cd5b64..f620d2d 100644
59505 --- a/include/acpi/acpi_bus.h
59506 +++ b/include/acpi/acpi_bus.h
59507 @@ -107,7 +107,7 @@ struct acpi_device_ops {
59508 acpi_op_bind bind;
59509 acpi_op_unbind unbind;
59510 acpi_op_notify notify;
59511 -};
59512 +} __no_const;
59513
59514 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
59515
59516 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
59517 index b7babf0..71e4e74 100644
59518 --- a/include/asm-generic/atomic-long.h
59519 +++ b/include/asm-generic/atomic-long.h
59520 @@ -22,6 +22,12 @@
59521
59522 typedef atomic64_t atomic_long_t;
59523
59524 +#ifdef CONFIG_PAX_REFCOUNT
59525 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
59526 +#else
59527 +typedef atomic64_t atomic_long_unchecked_t;
59528 +#endif
59529 +
59530 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
59531
59532 static inline long atomic_long_read(atomic_long_t *l)
59533 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59534 return (long)atomic64_read(v);
59535 }
59536
59537 +#ifdef CONFIG_PAX_REFCOUNT
59538 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59539 +{
59540 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59541 +
59542 + return (long)atomic64_read_unchecked(v);
59543 +}
59544 +#endif
59545 +
59546 static inline void atomic_long_set(atomic_long_t *l, long i)
59547 {
59548 atomic64_t *v = (atomic64_t *)l;
59549 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59550 atomic64_set(v, i);
59551 }
59552
59553 +#ifdef CONFIG_PAX_REFCOUNT
59554 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59555 +{
59556 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59557 +
59558 + atomic64_set_unchecked(v, i);
59559 +}
59560 +#endif
59561 +
59562 static inline void atomic_long_inc(atomic_long_t *l)
59563 {
59564 atomic64_t *v = (atomic64_t *)l;
59565 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59566 atomic64_inc(v);
59567 }
59568
59569 +#ifdef CONFIG_PAX_REFCOUNT
59570 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59571 +{
59572 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59573 +
59574 + atomic64_inc_unchecked(v);
59575 +}
59576 +#endif
59577 +
59578 static inline void atomic_long_dec(atomic_long_t *l)
59579 {
59580 atomic64_t *v = (atomic64_t *)l;
59581 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59582 atomic64_dec(v);
59583 }
59584
59585 +#ifdef CONFIG_PAX_REFCOUNT
59586 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59587 +{
59588 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59589 +
59590 + atomic64_dec_unchecked(v);
59591 +}
59592 +#endif
59593 +
59594 static inline void atomic_long_add(long i, atomic_long_t *l)
59595 {
59596 atomic64_t *v = (atomic64_t *)l;
59597 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59598 atomic64_add(i, v);
59599 }
59600
59601 +#ifdef CONFIG_PAX_REFCOUNT
59602 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59603 +{
59604 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59605 +
59606 + atomic64_add_unchecked(i, v);
59607 +}
59608 +#endif
59609 +
59610 static inline void atomic_long_sub(long i, atomic_long_t *l)
59611 {
59612 atomic64_t *v = (atomic64_t *)l;
59613 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59614 atomic64_sub(i, v);
59615 }
59616
59617 +#ifdef CONFIG_PAX_REFCOUNT
59618 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59619 +{
59620 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59621 +
59622 + atomic64_sub_unchecked(i, v);
59623 +}
59624 +#endif
59625 +
59626 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59627 {
59628 atomic64_t *v = (atomic64_t *)l;
59629 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59630 return (long)atomic64_inc_return(v);
59631 }
59632
59633 +#ifdef CONFIG_PAX_REFCOUNT
59634 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59635 +{
59636 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
59637 +
59638 + return (long)atomic64_inc_return_unchecked(v);
59639 +}
59640 +#endif
59641 +
59642 static inline long atomic_long_dec_return(atomic_long_t *l)
59643 {
59644 atomic64_t *v = (atomic64_t *)l;
59645 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59646
59647 typedef atomic_t atomic_long_t;
59648
59649 +#ifdef CONFIG_PAX_REFCOUNT
59650 +typedef atomic_unchecked_t atomic_long_unchecked_t;
59651 +#else
59652 +typedef atomic_t atomic_long_unchecked_t;
59653 +#endif
59654 +
59655 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
59656 static inline long atomic_long_read(atomic_long_t *l)
59657 {
59658 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
59659 return (long)atomic_read(v);
59660 }
59661
59662 +#ifdef CONFIG_PAX_REFCOUNT
59663 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
59664 +{
59665 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59666 +
59667 + return (long)atomic_read_unchecked(v);
59668 +}
59669 +#endif
59670 +
59671 static inline void atomic_long_set(atomic_long_t *l, long i)
59672 {
59673 atomic_t *v = (atomic_t *)l;
59674 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
59675 atomic_set(v, i);
59676 }
59677
59678 +#ifdef CONFIG_PAX_REFCOUNT
59679 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
59680 +{
59681 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59682 +
59683 + atomic_set_unchecked(v, i);
59684 +}
59685 +#endif
59686 +
59687 static inline void atomic_long_inc(atomic_long_t *l)
59688 {
59689 atomic_t *v = (atomic_t *)l;
59690 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
59691 atomic_inc(v);
59692 }
59693
59694 +#ifdef CONFIG_PAX_REFCOUNT
59695 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
59696 +{
59697 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59698 +
59699 + atomic_inc_unchecked(v);
59700 +}
59701 +#endif
59702 +
59703 static inline void atomic_long_dec(atomic_long_t *l)
59704 {
59705 atomic_t *v = (atomic_t *)l;
59706 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
59707 atomic_dec(v);
59708 }
59709
59710 +#ifdef CONFIG_PAX_REFCOUNT
59711 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
59712 +{
59713 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59714 +
59715 + atomic_dec_unchecked(v);
59716 +}
59717 +#endif
59718 +
59719 static inline void atomic_long_add(long i, atomic_long_t *l)
59720 {
59721 atomic_t *v = (atomic_t *)l;
59722 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
59723 atomic_add(i, v);
59724 }
59725
59726 +#ifdef CONFIG_PAX_REFCOUNT
59727 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
59728 +{
59729 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59730 +
59731 + atomic_add_unchecked(i, v);
59732 +}
59733 +#endif
59734 +
59735 static inline void atomic_long_sub(long i, atomic_long_t *l)
59736 {
59737 atomic_t *v = (atomic_t *)l;
59738 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
59739 atomic_sub(i, v);
59740 }
59741
59742 +#ifdef CONFIG_PAX_REFCOUNT
59743 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
59744 +{
59745 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59746 +
59747 + atomic_sub_unchecked(i, v);
59748 +}
59749 +#endif
59750 +
59751 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
59752 {
59753 atomic_t *v = (atomic_t *)l;
59754 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
59755 return (long)atomic_inc_return(v);
59756 }
59757
59758 +#ifdef CONFIG_PAX_REFCOUNT
59759 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
59760 +{
59761 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
59762 +
59763 + return (long)atomic_inc_return_unchecked(v);
59764 +}
59765 +#endif
59766 +
59767 static inline long atomic_long_dec_return(atomic_long_t *l)
59768 {
59769 atomic_t *v = (atomic_t *)l;
59770 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
59771
59772 #endif /* BITS_PER_LONG == 64 */
59773
59774 +#ifdef CONFIG_PAX_REFCOUNT
59775 +static inline void pax_refcount_needs_these_functions(void)
59776 +{
59777 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
59778 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
59779 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
59780 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
59781 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
59782 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
59783 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
59784 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
59785 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
59786 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
59787 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
59788 +
59789 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
59790 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
59791 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
59792 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
59793 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
59794 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
59795 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
59796 +}
59797 +#else
59798 +#define atomic_read_unchecked(v) atomic_read(v)
59799 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
59800 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
59801 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
59802 +#define atomic_inc_unchecked(v) atomic_inc(v)
59803 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
59804 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
59805 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
59806 +#define atomic_dec_unchecked(v) atomic_dec(v)
59807 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
59808 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
59809 +
59810 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
59811 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
59812 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
59813 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
59814 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
59815 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
59816 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
59817 +#endif
59818 +
59819 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
59820 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
59821 index b18ce4f..2ee2843 100644
59822 --- a/include/asm-generic/atomic64.h
59823 +++ b/include/asm-generic/atomic64.h
59824 @@ -16,6 +16,8 @@ typedef struct {
59825 long long counter;
59826 } atomic64_t;
59827
59828 +typedef atomic64_t atomic64_unchecked_t;
59829 +
59830 #define ATOMIC64_INIT(i) { (i) }
59831
59832 extern long long atomic64_read(const atomic64_t *v);
59833 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
59834 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
59835 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
59836
59837 +#define atomic64_read_unchecked(v) atomic64_read(v)
59838 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
59839 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
59840 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
59841 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
59842 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
59843 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
59844 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
59845 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
59846 +
59847 #endif /* _ASM_GENERIC_ATOMIC64_H */
59848 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
59849 index 1bfcfe5..e04c5c9 100644
59850 --- a/include/asm-generic/cache.h
59851 +++ b/include/asm-generic/cache.h
59852 @@ -6,7 +6,7 @@
59853 * cache lines need to provide their own cache.h.
59854 */
59855
59856 -#define L1_CACHE_SHIFT 5
59857 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
59858 +#define L1_CACHE_SHIFT 5UL
59859 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
59860
59861 #endif /* __ASM_GENERIC_CACHE_H */
59862 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
59863 index 0d68a1e..b74a761 100644
59864 --- a/include/asm-generic/emergency-restart.h
59865 +++ b/include/asm-generic/emergency-restart.h
59866 @@ -1,7 +1,7 @@
59867 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
59868 #define _ASM_GENERIC_EMERGENCY_RESTART_H
59869
59870 -static inline void machine_emergency_restart(void)
59871 +static inline __noreturn void machine_emergency_restart(void)
59872 {
59873 machine_restart(NULL);
59874 }
59875 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
59876 index 0232ccb..13d9165 100644
59877 --- a/include/asm-generic/kmap_types.h
59878 +++ b/include/asm-generic/kmap_types.h
59879 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
59880 KMAP_D(17) KM_NMI,
59881 KMAP_D(18) KM_NMI_PTE,
59882 KMAP_D(19) KM_KDB,
59883 +KMAP_D(20) KM_CLEARPAGE,
59884 /*
59885 * Remember to update debug_kmap_atomic() when adding new kmap types!
59886 */
59887 -KMAP_D(20) KM_TYPE_NR
59888 +KMAP_D(21) KM_TYPE_NR
59889 };
59890
59891 #undef KMAP_D
59892 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
59893 index 9ceb03b..2efbcbd 100644
59894 --- a/include/asm-generic/local.h
59895 +++ b/include/asm-generic/local.h
59896 @@ -39,6 +39,7 @@ typedef struct
59897 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
59898 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
59899 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
59900 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
59901
59902 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
59903 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
59904 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
59905 index 725612b..9cc513a 100644
59906 --- a/include/asm-generic/pgtable-nopmd.h
59907 +++ b/include/asm-generic/pgtable-nopmd.h
59908 @@ -1,14 +1,19 @@
59909 #ifndef _PGTABLE_NOPMD_H
59910 #define _PGTABLE_NOPMD_H
59911
59912 -#ifndef __ASSEMBLY__
59913 -
59914 #include <asm-generic/pgtable-nopud.h>
59915
59916 -struct mm_struct;
59917 -
59918 #define __PAGETABLE_PMD_FOLDED
59919
59920 +#define PMD_SHIFT PUD_SHIFT
59921 +#define PTRS_PER_PMD 1
59922 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
59923 +#define PMD_MASK (~(PMD_SIZE-1))
59924 +
59925 +#ifndef __ASSEMBLY__
59926 +
59927 +struct mm_struct;
59928 +
59929 /*
59930 * Having the pmd type consist of a pud gets the size right, and allows
59931 * us to conceptually access the pud entry that this pmd is folded into
59932 @@ -16,11 +21,6 @@ struct mm_struct;
59933 */
59934 typedef struct { pud_t pud; } pmd_t;
59935
59936 -#define PMD_SHIFT PUD_SHIFT
59937 -#define PTRS_PER_PMD 1
59938 -#define PMD_SIZE (1UL << PMD_SHIFT)
59939 -#define PMD_MASK (~(PMD_SIZE-1))
59940 -
59941 /*
59942 * The "pud_xxx()" functions here are trivial for a folded two-level
59943 * setup: the pmd is never bad, and a pmd always exists (as it's folded
59944 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
59945 index 810431d..0ec4804f 100644
59946 --- a/include/asm-generic/pgtable-nopud.h
59947 +++ b/include/asm-generic/pgtable-nopud.h
59948 @@ -1,10 +1,15 @@
59949 #ifndef _PGTABLE_NOPUD_H
59950 #define _PGTABLE_NOPUD_H
59951
59952 -#ifndef __ASSEMBLY__
59953 -
59954 #define __PAGETABLE_PUD_FOLDED
59955
59956 +#define PUD_SHIFT PGDIR_SHIFT
59957 +#define PTRS_PER_PUD 1
59958 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
59959 +#define PUD_MASK (~(PUD_SIZE-1))
59960 +
59961 +#ifndef __ASSEMBLY__
59962 +
59963 /*
59964 * Having the pud type consist of a pgd gets the size right, and allows
59965 * us to conceptually access the pgd entry that this pud is folded into
59966 @@ -12,11 +17,6 @@
59967 */
59968 typedef struct { pgd_t pgd; } pud_t;
59969
59970 -#define PUD_SHIFT PGDIR_SHIFT
59971 -#define PTRS_PER_PUD 1
59972 -#define PUD_SIZE (1UL << PUD_SHIFT)
59973 -#define PUD_MASK (~(PUD_SIZE-1))
59974 -
59975 /*
59976 * The "pgd_xxx()" functions here are trivial for a folded two-level
59977 * setup: the pud is never bad, and a pud always exists (as it's folded
59978 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
59979 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
59980
59981 #define pgd_populate(mm, pgd, pud) do { } while (0)
59982 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
59983 /*
59984 * (puds are folded into pgds so this doesn't get actually called,
59985 * but the define is needed for a generic inline function.)
59986 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
59987 index a03c098..19751cf 100644
59988 --- a/include/asm-generic/pgtable.h
59989 +++ b/include/asm-generic/pgtable.h
59990 @@ -445,6 +445,18 @@ static inline int pmd_write(pmd_t pmd)
59991 #endif /* __HAVE_ARCH_PMD_WRITE */
59992 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
59993
59994 +#ifndef __HAVE_ARCH_READ_PMD_ATOMIC
59995 +static inline pmd_t read_pmd_atomic(pmd_t *pmdp)
59996 +{
59997 + /*
59998 + * Depend on compiler for an atomic pmd read. NOTE: this is
59999 + * only going to work, if the pmdval_t isn't larger than
60000 + * an unsigned long.
60001 + */
60002 + return *pmdp;
60003 +}
60004 +#endif /* __HAVE_ARCH_READ_PMD_ATOMIC */
60005 +
60006 /*
60007 * This function is meant to be used by sites walking pagetables with
60008 * the mmap_sem hold in read mode to protect against MADV_DONTNEED and
60009 @@ -458,11 +470,17 @@ static inline int pmd_write(pmd_t pmd)
60010 * undefined so behaving like if the pmd was none is safe (because it
60011 * can return none anyway). The compiler level barrier() is critically
60012 * important to compute the two checks atomically on the same pmdval.
60013 + *
60014 + * For 32bit kernels with a 64bit large pmd_t this automatically takes
60015 + * care of reading the pmd atomically to avoid SMP race conditions
60016 + * against pmd_populate() when the mmap_sem is hold for reading by the
60017 + * caller (a special atomic read not done by "gcc" as in the generic
60018 + * version above, is also needed when THP is disabled because the page
60019 + * fault can populate the pmd from under us).
60020 */
60021 static inline int pmd_none_or_trans_huge_or_clear_bad(pmd_t *pmd)
60022 {
60023 - /* depend on compiler for an atomic pmd read */
60024 - pmd_t pmdval = *pmd;
60025 + pmd_t pmdval = read_pmd_atomic(pmd);
60026 /*
60027 * The barrier will stabilize the pmdval in a register or on
60028 * the stack so that it will stop changing under the code.
60029 @@ -502,6 +520,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60030 #endif
60031 }
60032
60033 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60034 +static inline unsigned long pax_open_kernel(void) { return 0; }
60035 +#endif
60036 +
60037 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60038 +static inline unsigned long pax_close_kernel(void) { return 0; }
60039 +#endif
60040 +
60041 #endif /* CONFIG_MMU */
60042
60043 #endif /* !__ASSEMBLY__ */
60044 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60045 index b5e2e4c..6a5373e 100644
60046 --- a/include/asm-generic/vmlinux.lds.h
60047 +++ b/include/asm-generic/vmlinux.lds.h
60048 @@ -217,6 +217,7 @@
60049 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60050 VMLINUX_SYMBOL(__start_rodata) = .; \
60051 *(.rodata) *(.rodata.*) \
60052 + *(.data..read_only) \
60053 *(__vermagic) /* Kernel version magic */ \
60054 . = ALIGN(8); \
60055 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60056 @@ -722,17 +723,18 @@
60057 * section in the linker script will go there too. @phdr should have
60058 * a leading colon.
60059 *
60060 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60061 + * Note that this macros defines per_cpu_load as an absolute symbol.
60062 * If there is no need to put the percpu section at a predetermined
60063 * address, use PERCPU_SECTION.
60064 */
60065 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60066 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60067 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60068 + per_cpu_load = .; \
60069 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60070 - LOAD_OFFSET) { \
60071 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60072 PERCPU_INPUT(cacheline) \
60073 } phdr \
60074 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60075 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60076
60077 /**
60078 * PERCPU_SECTION - define output section for percpu area, simple version
60079 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60080 index 92f0981..d44a37c 100644
60081 --- a/include/drm/drmP.h
60082 +++ b/include/drm/drmP.h
60083 @@ -72,6 +72,7 @@
60084 #include <linux/workqueue.h>
60085 #include <linux/poll.h>
60086 #include <asm/pgalloc.h>
60087 +#include <asm/local.h>
60088 #include "drm.h"
60089
60090 #include <linux/idr.h>
60091 @@ -1038,7 +1039,7 @@ struct drm_device {
60092
60093 /** \name Usage Counters */
60094 /*@{ */
60095 - int open_count; /**< Outstanding files open */
60096 + local_t open_count; /**< Outstanding files open */
60097 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60098 atomic_t vma_count; /**< Outstanding vma areas open */
60099 int buf_use; /**< Buffers in use -- cannot alloc */
60100 @@ -1049,7 +1050,7 @@ struct drm_device {
60101 /*@{ */
60102 unsigned long counters;
60103 enum drm_stat_type types[15];
60104 - atomic_t counts[15];
60105 + atomic_unchecked_t counts[15];
60106 /*@} */
60107
60108 struct list_head filelist;
60109 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60110 index 37515d1..34fa8b0 100644
60111 --- a/include/drm/drm_crtc_helper.h
60112 +++ b/include/drm/drm_crtc_helper.h
60113 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
60114
60115 /* disable crtc when not in use - more explicit than dpms off */
60116 void (*disable)(struct drm_crtc *crtc);
60117 -};
60118 +} __no_const;
60119
60120 struct drm_encoder_helper_funcs {
60121 void (*dpms)(struct drm_encoder *encoder, int mode);
60122 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
60123 struct drm_connector *connector);
60124 /* disable encoder when not in use - more explicit than dpms off */
60125 void (*disable)(struct drm_encoder *encoder);
60126 -};
60127 +} __no_const;
60128
60129 struct drm_connector_helper_funcs {
60130 int (*get_modes)(struct drm_connector *connector);
60131 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60132 index 26c1f78..6722682 100644
60133 --- a/include/drm/ttm/ttm_memory.h
60134 +++ b/include/drm/ttm/ttm_memory.h
60135 @@ -47,7 +47,7 @@
60136
60137 struct ttm_mem_shrink {
60138 int (*do_shrink) (struct ttm_mem_shrink *);
60139 -};
60140 +} __no_const;
60141
60142 /**
60143 * struct ttm_mem_global - Global memory accounting structure.
60144 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60145 index e86dfca..40cc55f 100644
60146 --- a/include/linux/a.out.h
60147 +++ b/include/linux/a.out.h
60148 @@ -39,6 +39,14 @@ enum machine_type {
60149 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60150 };
60151
60152 +/* Constants for the N_FLAGS field */
60153 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60154 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60155 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60156 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60157 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60158 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60159 +
60160 #if !defined (N_MAGIC)
60161 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60162 #endif
60163 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60164 index f4ff882..84b53a6 100644
60165 --- a/include/linux/atmdev.h
60166 +++ b/include/linux/atmdev.h
60167 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60168 #endif
60169
60170 struct k_atm_aal_stats {
60171 -#define __HANDLE_ITEM(i) atomic_t i
60172 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60173 __AAL_STAT_ITEMS
60174 #undef __HANDLE_ITEM
60175 };
60176 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
60177 index 0092102..8a801b4 100644
60178 --- a/include/linux/binfmts.h
60179 +++ b/include/linux/binfmts.h
60180 @@ -89,6 +89,7 @@ struct linux_binfmt {
60181 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
60182 int (*load_shlib)(struct file *);
60183 int (*core_dump)(struct coredump_params *cprm);
60184 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
60185 unsigned long min_coredump; /* minimal dump size */
60186 };
60187
60188 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
60189 index 606cf33..b72c577 100644
60190 --- a/include/linux/blkdev.h
60191 +++ b/include/linux/blkdev.h
60192 @@ -1379,7 +1379,7 @@ struct block_device_operations {
60193 /* this callback is with swap_lock and sometimes page table lock held */
60194 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
60195 struct module *owner;
60196 -};
60197 +} __do_const;
60198
60199 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
60200 unsigned long);
60201 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
60202 index 4d1a074..88f929a 100644
60203 --- a/include/linux/blktrace_api.h
60204 +++ b/include/linux/blktrace_api.h
60205 @@ -162,7 +162,7 @@ struct blk_trace {
60206 struct dentry *dir;
60207 struct dentry *dropped_file;
60208 struct dentry *msg_file;
60209 - atomic_t dropped;
60210 + atomic_unchecked_t dropped;
60211 };
60212
60213 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
60214 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
60215 index 83195fb..0b0f77d 100644
60216 --- a/include/linux/byteorder/little_endian.h
60217 +++ b/include/linux/byteorder/little_endian.h
60218 @@ -42,51 +42,51 @@
60219
60220 static inline __le64 __cpu_to_le64p(const __u64 *p)
60221 {
60222 - return (__force __le64)*p;
60223 + return (__force const __le64)*p;
60224 }
60225 static inline __u64 __le64_to_cpup(const __le64 *p)
60226 {
60227 - return (__force __u64)*p;
60228 + return (__force const __u64)*p;
60229 }
60230 static inline __le32 __cpu_to_le32p(const __u32 *p)
60231 {
60232 - return (__force __le32)*p;
60233 + return (__force const __le32)*p;
60234 }
60235 static inline __u32 __le32_to_cpup(const __le32 *p)
60236 {
60237 - return (__force __u32)*p;
60238 + return (__force const __u32)*p;
60239 }
60240 static inline __le16 __cpu_to_le16p(const __u16 *p)
60241 {
60242 - return (__force __le16)*p;
60243 + return (__force const __le16)*p;
60244 }
60245 static inline __u16 __le16_to_cpup(const __le16 *p)
60246 {
60247 - return (__force __u16)*p;
60248 + return (__force const __u16)*p;
60249 }
60250 static inline __be64 __cpu_to_be64p(const __u64 *p)
60251 {
60252 - return (__force __be64)__swab64p(p);
60253 + return (__force const __be64)__swab64p(p);
60254 }
60255 static inline __u64 __be64_to_cpup(const __be64 *p)
60256 {
60257 - return __swab64p((__u64 *)p);
60258 + return __swab64p((const __u64 *)p);
60259 }
60260 static inline __be32 __cpu_to_be32p(const __u32 *p)
60261 {
60262 - return (__force __be32)__swab32p(p);
60263 + return (__force const __be32)__swab32p(p);
60264 }
60265 static inline __u32 __be32_to_cpup(const __be32 *p)
60266 {
60267 - return __swab32p((__u32 *)p);
60268 + return __swab32p((const __u32 *)p);
60269 }
60270 static inline __be16 __cpu_to_be16p(const __u16 *p)
60271 {
60272 - return (__force __be16)__swab16p(p);
60273 + return (__force const __be16)__swab16p(p);
60274 }
60275 static inline __u16 __be16_to_cpup(const __be16 *p)
60276 {
60277 - return __swab16p((__u16 *)p);
60278 + return __swab16p((const __u16 *)p);
60279 }
60280 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
60281 #define __le64_to_cpus(x) do { (void)(x); } while (0)
60282 diff --git a/include/linux/cache.h b/include/linux/cache.h
60283 index 4c57065..4307975 100644
60284 --- a/include/linux/cache.h
60285 +++ b/include/linux/cache.h
60286 @@ -16,6 +16,10 @@
60287 #define __read_mostly
60288 #endif
60289
60290 +#ifndef __read_only
60291 +#define __read_only __read_mostly
60292 +#endif
60293 +
60294 #ifndef ____cacheline_aligned
60295 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
60296 #endif
60297 diff --git a/include/linux/capability.h b/include/linux/capability.h
60298 index 12d52de..b5f7fa7 100644
60299 --- a/include/linux/capability.h
60300 +++ b/include/linux/capability.h
60301 @@ -548,6 +548,8 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
60302 extern bool capable(int cap);
60303 extern bool ns_capable(struct user_namespace *ns, int cap);
60304 extern bool nsown_capable(int cap);
60305 +extern bool capable_nolog(int cap);
60306 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
60307
60308 /* audit system wants to get cap info from files as well */
60309 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
60310 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
60311 index 04ffb2e..6799180 100644
60312 --- a/include/linux/cleancache.h
60313 +++ b/include/linux/cleancache.h
60314 @@ -31,7 +31,7 @@ struct cleancache_ops {
60315 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
60316 void (*flush_inode)(int, struct cleancache_filekey);
60317 void (*flush_fs)(int);
60318 -};
60319 +} __no_const;
60320
60321 extern struct cleancache_ops
60322 cleancache_register_ops(struct cleancache_ops *ops);
60323 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
60324 index 2f40791..a62d196 100644
60325 --- a/include/linux/compiler-gcc4.h
60326 +++ b/include/linux/compiler-gcc4.h
60327 @@ -32,6 +32,16 @@
60328 #define __linktime_error(message) __attribute__((__error__(message)))
60329
60330 #if __GNUC_MINOR__ >= 5
60331 +
60332 +#ifdef CONSTIFY_PLUGIN
60333 +#define __no_const __attribute__((no_const))
60334 +#define __do_const __attribute__((do_const))
60335 +#endif
60336 +
60337 +#ifdef SIZE_OVERFLOW_PLUGIN
60338 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
60339 +#endif
60340 +
60341 /*
60342 * Mark a position in code as unreachable. This can be used to
60343 * suppress control flow warnings after asm blocks that transfer
60344 @@ -47,6 +57,11 @@
60345 #define __noclone __attribute__((__noclone__))
60346
60347 #endif
60348 +
60349 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
60350 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
60351 +#define __bos0(ptr) __bos((ptr), 0)
60352 +#define __bos1(ptr) __bos((ptr), 1)
60353 #endif
60354
60355 #if __GNUC_MINOR__ > 0
60356 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
60357 index 4a24354..7149ac2 100644
60358 --- a/include/linux/compiler.h
60359 +++ b/include/linux/compiler.h
60360 @@ -5,31 +5,62 @@
60361
60362 #ifdef __CHECKER__
60363 # define __user __attribute__((noderef, address_space(1)))
60364 +# define __force_user __force __user
60365 # define __kernel __attribute__((address_space(0)))
60366 +# define __force_kernel __force __kernel
60367 # define __safe __attribute__((safe))
60368 # define __force __attribute__((force))
60369 # define __nocast __attribute__((nocast))
60370 # define __iomem __attribute__((noderef, address_space(2)))
60371 +# define __force_iomem __force __iomem
60372 # define __acquires(x) __attribute__((context(x,0,1)))
60373 # define __releases(x) __attribute__((context(x,1,0)))
60374 # define __acquire(x) __context__(x,1)
60375 # define __release(x) __context__(x,-1)
60376 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
60377 # define __percpu __attribute__((noderef, address_space(3)))
60378 +# define __force_percpu __force __percpu
60379 #ifdef CONFIG_SPARSE_RCU_POINTER
60380 # define __rcu __attribute__((noderef, address_space(4)))
60381 +# define __force_rcu __force __rcu
60382 #else
60383 # define __rcu
60384 +# define __force_rcu
60385 #endif
60386 extern void __chk_user_ptr(const volatile void __user *);
60387 extern void __chk_io_ptr(const volatile void __iomem *);
60388 +#elif defined(CHECKER_PLUGIN)
60389 +//# define __user
60390 +//# define __force_user
60391 +//# define __kernel
60392 +//# define __force_kernel
60393 +# define __safe
60394 +# define __force
60395 +# define __nocast
60396 +# define __iomem
60397 +# define __force_iomem
60398 +# define __chk_user_ptr(x) (void)0
60399 +# define __chk_io_ptr(x) (void)0
60400 +# define __builtin_warning(x, y...) (1)
60401 +# define __acquires(x)
60402 +# define __releases(x)
60403 +# define __acquire(x) (void)0
60404 +# define __release(x) (void)0
60405 +# define __cond_lock(x,c) (c)
60406 +# define __percpu
60407 +# define __force_percpu
60408 +# define __rcu
60409 +# define __force_rcu
60410 #else
60411 # define __user
60412 +# define __force_user
60413 # define __kernel
60414 +# define __force_kernel
60415 # define __safe
60416 # define __force
60417 # define __nocast
60418 # define __iomem
60419 +# define __force_iomem
60420 # define __chk_user_ptr(x) (void)0
60421 # define __chk_io_ptr(x) (void)0
60422 # define __builtin_warning(x, y...) (1)
60423 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
60424 # define __release(x) (void)0
60425 # define __cond_lock(x,c) (c)
60426 # define __percpu
60427 +# define __force_percpu
60428 # define __rcu
60429 +# define __force_rcu
60430 #endif
60431
60432 #ifdef __KERNEL__
60433 @@ -264,6 +297,18 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60434 # define __attribute_const__ /* unimplemented */
60435 #endif
60436
60437 +#ifndef __no_const
60438 +# define __no_const
60439 +#endif
60440 +
60441 +#ifndef __do_const
60442 +# define __do_const
60443 +#endif
60444 +
60445 +#ifndef __size_overflow
60446 +# define __size_overflow(...)
60447 +#endif
60448 +
60449 /*
60450 * Tell gcc if a function is cold. The compiler will assume any path
60451 * directly leading to the call is unlikely.
60452 @@ -273,6 +318,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60453 #define __cold
60454 #endif
60455
60456 +#ifndef __alloc_size
60457 +#define __alloc_size(...)
60458 +#endif
60459 +
60460 +#ifndef __bos
60461 +#define __bos(ptr, arg)
60462 +#endif
60463 +
60464 +#ifndef __bos0
60465 +#define __bos0(ptr)
60466 +#endif
60467 +
60468 +#ifndef __bos1
60469 +#define __bos1(ptr)
60470 +#endif
60471 +
60472 /* Simple shorthand for a section definition */
60473 #ifndef __section
60474 # define __section(S) __attribute__ ((__section__(#S)))
60475 @@ -308,6 +369,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
60476 * use is to mediate communication between process-level code and irq/NMI
60477 * handlers, all running on the same CPU.
60478 */
60479 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
60480 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
60481 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
60482
60483 #endif /* __LINUX_COMPILER_H */
60484 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
60485 index e9eaec5..bfeb9bb 100644
60486 --- a/include/linux/cpuset.h
60487 +++ b/include/linux/cpuset.h
60488 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
60489 * nodemask.
60490 */
60491 smp_mb();
60492 - --ACCESS_ONCE(current->mems_allowed_change_disable);
60493 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
60494 }
60495
60496 static inline void set_mems_allowed(nodemask_t nodemask)
60497 diff --git a/include/linux/cred.h b/include/linux/cred.h
60498 index adadf71..6af5560 100644
60499 --- a/include/linux/cred.h
60500 +++ b/include/linux/cred.h
60501 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
60502 static inline void validate_process_creds(void)
60503 {
60504 }
60505 +static inline void validate_task_creds(struct task_struct *task)
60506 +{
60507 +}
60508 #endif
60509
60510 /**
60511 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
60512 index 8a94217..15d49e3 100644
60513 --- a/include/linux/crypto.h
60514 +++ b/include/linux/crypto.h
60515 @@ -365,7 +365,7 @@ struct cipher_tfm {
60516 const u8 *key, unsigned int keylen);
60517 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60518 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
60519 -};
60520 +} __no_const;
60521
60522 struct hash_tfm {
60523 int (*init)(struct hash_desc *desc);
60524 @@ -386,13 +386,13 @@ struct compress_tfm {
60525 int (*cot_decompress)(struct crypto_tfm *tfm,
60526 const u8 *src, unsigned int slen,
60527 u8 *dst, unsigned int *dlen);
60528 -};
60529 +} __no_const;
60530
60531 struct rng_tfm {
60532 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
60533 unsigned int dlen);
60534 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
60535 -};
60536 +} __no_const;
60537
60538 #define crt_ablkcipher crt_u.ablkcipher
60539 #define crt_aead crt_u.aead
60540 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
60541 index 7925bf0..d5143d2 100644
60542 --- a/include/linux/decompress/mm.h
60543 +++ b/include/linux/decompress/mm.h
60544 @@ -77,7 +77,7 @@ static void free(void *where)
60545 * warnings when not needed (indeed large_malloc / large_free are not
60546 * needed by inflate */
60547
60548 -#define malloc(a) kmalloc(a, GFP_KERNEL)
60549 +#define malloc(a) kmalloc((a), GFP_KERNEL)
60550 #define free(a) kfree(a)
60551
60552 #define large_malloc(a) vmalloc(a)
60553 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
60554 index e13117c..e9fc938 100644
60555 --- a/include/linux/dma-mapping.h
60556 +++ b/include/linux/dma-mapping.h
60557 @@ -46,7 +46,7 @@ struct dma_map_ops {
60558 u64 (*get_required_mask)(struct device *dev);
60559 #endif
60560 int is_phys;
60561 -};
60562 +} __do_const;
60563
60564 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
60565
60566 diff --git a/include/linux/efi.h b/include/linux/efi.h
60567 index 7cce0ea..c2085e4 100644
60568 --- a/include/linux/efi.h
60569 +++ b/include/linux/efi.h
60570 @@ -591,7 +591,7 @@ struct efivar_operations {
60571 efi_get_variable_t *get_variable;
60572 efi_get_next_variable_t *get_next_variable;
60573 efi_set_variable_t *set_variable;
60574 -};
60575 +} __no_const;
60576
60577 struct efivars {
60578 /*
60579 diff --git a/include/linux/elf.h b/include/linux/elf.h
60580 index 999b4f5..57753b4 100644
60581 --- a/include/linux/elf.h
60582 +++ b/include/linux/elf.h
60583 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
60584 #define PT_GNU_EH_FRAME 0x6474e550
60585
60586 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
60587 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
60588 +
60589 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
60590 +
60591 +/* Constants for the e_flags field */
60592 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60593 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
60594 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
60595 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
60596 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60597 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60598
60599 /*
60600 * Extended Numbering
60601 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
60602 #define DT_DEBUG 21
60603 #define DT_TEXTREL 22
60604 #define DT_JMPREL 23
60605 +#define DT_FLAGS 30
60606 + #define DF_TEXTREL 0x00000004
60607 #define DT_ENCODING 32
60608 #define OLD_DT_LOOS 0x60000000
60609 #define DT_LOOS 0x6000000d
60610 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
60611 #define PF_W 0x2
60612 #define PF_X 0x1
60613
60614 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
60615 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
60616 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
60617 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
60618 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
60619 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
60620 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
60621 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
60622 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
60623 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
60624 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
60625 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
60626 +
60627 typedef struct elf32_phdr{
60628 Elf32_Word p_type;
60629 Elf32_Off p_offset;
60630 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
60631 #define EI_OSABI 7
60632 #define EI_PAD 8
60633
60634 +#define EI_PAX 14
60635 +
60636 #define ELFMAG0 0x7f /* EI_MAG */
60637 #define ELFMAG1 'E'
60638 #define ELFMAG2 'L'
60639 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
60640 #define elf_note elf32_note
60641 #define elf_addr_t Elf32_Off
60642 #define Elf_Half Elf32_Half
60643 +#define elf_dyn Elf32_Dyn
60644
60645 #else
60646
60647 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
60648 #define elf_note elf64_note
60649 #define elf_addr_t Elf64_Off
60650 #define Elf_Half Elf64_Half
60651 +#define elf_dyn Elf64_Dyn
60652
60653 #endif
60654
60655 diff --git a/include/linux/filter.h b/include/linux/filter.h
60656 index 8eeb205..d59bfa2 100644
60657 --- a/include/linux/filter.h
60658 +++ b/include/linux/filter.h
60659 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
60660
60661 struct sk_buff;
60662 struct sock;
60663 +struct bpf_jit_work;
60664
60665 struct sk_filter
60666 {
60667 @@ -141,6 +142,9 @@ struct sk_filter
60668 unsigned int len; /* Number of filter blocks */
60669 unsigned int (*bpf_func)(const struct sk_buff *skb,
60670 const struct sock_filter *filter);
60671 +#ifdef CONFIG_BPF_JIT
60672 + struct bpf_jit_work *work;
60673 +#endif
60674 struct rcu_head rcu;
60675 struct sock_filter insns[0];
60676 };
60677 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
60678 index 84ccf8e..2e9b14c 100644
60679 --- a/include/linux/firewire.h
60680 +++ b/include/linux/firewire.h
60681 @@ -428,7 +428,7 @@ struct fw_iso_context {
60682 union {
60683 fw_iso_callback_t sc;
60684 fw_iso_mc_callback_t mc;
60685 - } callback;
60686 + } __no_const callback;
60687 void *callback_data;
60688 };
60689
60690 diff --git a/include/linux/fs.h b/include/linux/fs.h
60691 index fd65e0d..7232c62 100644
60692 --- a/include/linux/fs.h
60693 +++ b/include/linux/fs.h
60694 @@ -1628,7 +1628,8 @@ struct file_operations {
60695 int (*setlease)(struct file *, long, struct file_lock **);
60696 long (*fallocate)(struct file *file, int mode, loff_t offset,
60697 loff_t len);
60698 -};
60699 +} __do_const;
60700 +typedef struct file_operations __no_const file_operations_no_const;
60701
60702 struct inode_operations {
60703 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
60704 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
60705 index 003dc0f..3c4ea97 100644
60706 --- a/include/linux/fs_struct.h
60707 +++ b/include/linux/fs_struct.h
60708 @@ -6,7 +6,7 @@
60709 #include <linux/seqlock.h>
60710
60711 struct fs_struct {
60712 - int users;
60713 + atomic_t users;
60714 spinlock_t lock;
60715 seqcount_t seq;
60716 int umask;
60717 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
60718 index ce31408..b1ad003 100644
60719 --- a/include/linux/fscache-cache.h
60720 +++ b/include/linux/fscache-cache.h
60721 @@ -102,7 +102,7 @@ struct fscache_operation {
60722 fscache_operation_release_t release;
60723 };
60724
60725 -extern atomic_t fscache_op_debug_id;
60726 +extern atomic_unchecked_t fscache_op_debug_id;
60727 extern void fscache_op_work_func(struct work_struct *work);
60728
60729 extern void fscache_enqueue_operation(struct fscache_operation *);
60730 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
60731 {
60732 INIT_WORK(&op->work, fscache_op_work_func);
60733 atomic_set(&op->usage, 1);
60734 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60735 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60736 op->processor = processor;
60737 op->release = release;
60738 INIT_LIST_HEAD(&op->pend_link);
60739 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
60740 index 2a53f10..0187fdf 100644
60741 --- a/include/linux/fsnotify.h
60742 +++ b/include/linux/fsnotify.h
60743 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
60744 */
60745 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
60746 {
60747 - return kstrdup(name, GFP_KERNEL);
60748 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
60749 }
60750
60751 /*
60752 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
60753 index 91d0e0a3..035666b 100644
60754 --- a/include/linux/fsnotify_backend.h
60755 +++ b/include/linux/fsnotify_backend.h
60756 @@ -105,6 +105,7 @@ struct fsnotify_ops {
60757 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
60758 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
60759 };
60760 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
60761
60762 /*
60763 * A group is a "thing" that wants to receive notification about filesystem
60764 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
60765 index c3da42d..c70e0df 100644
60766 --- a/include/linux/ftrace_event.h
60767 +++ b/include/linux/ftrace_event.h
60768 @@ -97,7 +97,7 @@ struct trace_event_functions {
60769 trace_print_func raw;
60770 trace_print_func hex;
60771 trace_print_func binary;
60772 -};
60773 +} __no_const;
60774
60775 struct trace_event {
60776 struct hlist_node node;
60777 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
60778 extern int trace_add_event_call(struct ftrace_event_call *call);
60779 extern void trace_remove_event_call(struct ftrace_event_call *call);
60780
60781 -#define is_signed_type(type) (((type)(-1)) < 0)
60782 +#define is_signed_type(type) (((type)(-1)) < (type)1)
60783
60784 int trace_set_clr_event(const char *system, const char *event, int set);
60785
60786 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
60787 index 017a7fb..33a8507 100644
60788 --- a/include/linux/genhd.h
60789 +++ b/include/linux/genhd.h
60790 @@ -185,7 +185,7 @@ struct gendisk {
60791 struct kobject *slave_dir;
60792
60793 struct timer_rand_state *random;
60794 - atomic_t sync_io; /* RAID */
60795 + atomic_unchecked_t sync_io; /* RAID */
60796 struct disk_events *ev;
60797 #ifdef CONFIG_BLK_DEV_INTEGRITY
60798 struct blk_integrity *integrity;
60799 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
60800 new file mode 100644
60801 index 0000000..8a130b6
60802 --- /dev/null
60803 +++ b/include/linux/gracl.h
60804 @@ -0,0 +1,319 @@
60805 +#ifndef GR_ACL_H
60806 +#define GR_ACL_H
60807 +
60808 +#include <linux/grdefs.h>
60809 +#include <linux/resource.h>
60810 +#include <linux/capability.h>
60811 +#include <linux/dcache.h>
60812 +#include <asm/resource.h>
60813 +
60814 +/* Major status information */
60815 +
60816 +#define GR_VERSION "grsecurity 2.9"
60817 +#define GRSECURITY_VERSION 0x2900
60818 +
60819 +enum {
60820 + GR_SHUTDOWN = 0,
60821 + GR_ENABLE = 1,
60822 + GR_SPROLE = 2,
60823 + GR_RELOAD = 3,
60824 + GR_SEGVMOD = 4,
60825 + GR_STATUS = 5,
60826 + GR_UNSPROLE = 6,
60827 + GR_PASSSET = 7,
60828 + GR_SPROLEPAM = 8,
60829 +};
60830 +
60831 +/* Password setup definitions
60832 + * kernel/grhash.c */
60833 +enum {
60834 + GR_PW_LEN = 128,
60835 + GR_SALT_LEN = 16,
60836 + GR_SHA_LEN = 32,
60837 +};
60838 +
60839 +enum {
60840 + GR_SPROLE_LEN = 64,
60841 +};
60842 +
60843 +enum {
60844 + GR_NO_GLOB = 0,
60845 + GR_REG_GLOB,
60846 + GR_CREATE_GLOB
60847 +};
60848 +
60849 +#define GR_NLIMITS 32
60850 +
60851 +/* Begin Data Structures */
60852 +
60853 +struct sprole_pw {
60854 + unsigned char *rolename;
60855 + unsigned char salt[GR_SALT_LEN];
60856 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
60857 +};
60858 +
60859 +struct name_entry {
60860 + __u32 key;
60861 + ino_t inode;
60862 + dev_t device;
60863 + char *name;
60864 + __u16 len;
60865 + __u8 deleted;
60866 + struct name_entry *prev;
60867 + struct name_entry *next;
60868 +};
60869 +
60870 +struct inodev_entry {
60871 + struct name_entry *nentry;
60872 + struct inodev_entry *prev;
60873 + struct inodev_entry *next;
60874 +};
60875 +
60876 +struct acl_role_db {
60877 + struct acl_role_label **r_hash;
60878 + __u32 r_size;
60879 +};
60880 +
60881 +struct inodev_db {
60882 + struct inodev_entry **i_hash;
60883 + __u32 i_size;
60884 +};
60885 +
60886 +struct name_db {
60887 + struct name_entry **n_hash;
60888 + __u32 n_size;
60889 +};
60890 +
60891 +struct crash_uid {
60892 + uid_t uid;
60893 + unsigned long expires;
60894 +};
60895 +
60896 +struct gr_hash_struct {
60897 + void **table;
60898 + void **nametable;
60899 + void *first;
60900 + __u32 table_size;
60901 + __u32 used_size;
60902 + int type;
60903 +};
60904 +
60905 +/* Userspace Grsecurity ACL data structures */
60906 +
60907 +struct acl_subject_label {
60908 + char *filename;
60909 + ino_t inode;
60910 + dev_t device;
60911 + __u32 mode;
60912 + kernel_cap_t cap_mask;
60913 + kernel_cap_t cap_lower;
60914 + kernel_cap_t cap_invert_audit;
60915 +
60916 + struct rlimit res[GR_NLIMITS];
60917 + __u32 resmask;
60918 +
60919 + __u8 user_trans_type;
60920 + __u8 group_trans_type;
60921 + uid_t *user_transitions;
60922 + gid_t *group_transitions;
60923 + __u16 user_trans_num;
60924 + __u16 group_trans_num;
60925 +
60926 + __u32 sock_families[2];
60927 + __u32 ip_proto[8];
60928 + __u32 ip_type;
60929 + struct acl_ip_label **ips;
60930 + __u32 ip_num;
60931 + __u32 inaddr_any_override;
60932 +
60933 + __u32 crashes;
60934 + unsigned long expires;
60935 +
60936 + struct acl_subject_label *parent_subject;
60937 + struct gr_hash_struct *hash;
60938 + struct acl_subject_label *prev;
60939 + struct acl_subject_label *next;
60940 +
60941 + struct acl_object_label **obj_hash;
60942 + __u32 obj_hash_size;
60943 + __u16 pax_flags;
60944 +};
60945 +
60946 +struct role_allowed_ip {
60947 + __u32 addr;
60948 + __u32 netmask;
60949 +
60950 + struct role_allowed_ip *prev;
60951 + struct role_allowed_ip *next;
60952 +};
60953 +
60954 +struct role_transition {
60955 + char *rolename;
60956 +
60957 + struct role_transition *prev;
60958 + struct role_transition *next;
60959 +};
60960 +
60961 +struct acl_role_label {
60962 + char *rolename;
60963 + uid_t uidgid;
60964 + __u16 roletype;
60965 +
60966 + __u16 auth_attempts;
60967 + unsigned long expires;
60968 +
60969 + struct acl_subject_label *root_label;
60970 + struct gr_hash_struct *hash;
60971 +
60972 + struct acl_role_label *prev;
60973 + struct acl_role_label *next;
60974 +
60975 + struct role_transition *transitions;
60976 + struct role_allowed_ip *allowed_ips;
60977 + uid_t *domain_children;
60978 + __u16 domain_child_num;
60979 +
60980 + umode_t umask;
60981 +
60982 + struct acl_subject_label **subj_hash;
60983 + __u32 subj_hash_size;
60984 +};
60985 +
60986 +struct user_acl_role_db {
60987 + struct acl_role_label **r_table;
60988 + __u32 num_pointers; /* Number of allocations to track */
60989 + __u32 num_roles; /* Number of roles */
60990 + __u32 num_domain_children; /* Number of domain children */
60991 + __u32 num_subjects; /* Number of subjects */
60992 + __u32 num_objects; /* Number of objects */
60993 +};
60994 +
60995 +struct acl_object_label {
60996 + char *filename;
60997 + ino_t inode;
60998 + dev_t device;
60999 + __u32 mode;
61000 +
61001 + struct acl_subject_label *nested;
61002 + struct acl_object_label *globbed;
61003 +
61004 + /* next two structures not used */
61005 +
61006 + struct acl_object_label *prev;
61007 + struct acl_object_label *next;
61008 +};
61009 +
61010 +struct acl_ip_label {
61011 + char *iface;
61012 + __u32 addr;
61013 + __u32 netmask;
61014 + __u16 low, high;
61015 + __u8 mode;
61016 + __u32 type;
61017 + __u32 proto[8];
61018 +
61019 + /* next two structures not used */
61020 +
61021 + struct acl_ip_label *prev;
61022 + struct acl_ip_label *next;
61023 +};
61024 +
61025 +struct gr_arg {
61026 + struct user_acl_role_db role_db;
61027 + unsigned char pw[GR_PW_LEN];
61028 + unsigned char salt[GR_SALT_LEN];
61029 + unsigned char sum[GR_SHA_LEN];
61030 + unsigned char sp_role[GR_SPROLE_LEN];
61031 + struct sprole_pw *sprole_pws;
61032 + dev_t segv_device;
61033 + ino_t segv_inode;
61034 + uid_t segv_uid;
61035 + __u16 num_sprole_pws;
61036 + __u16 mode;
61037 +};
61038 +
61039 +struct gr_arg_wrapper {
61040 + struct gr_arg *arg;
61041 + __u32 version;
61042 + __u32 size;
61043 +};
61044 +
61045 +struct subject_map {
61046 + struct acl_subject_label *user;
61047 + struct acl_subject_label *kernel;
61048 + struct subject_map *prev;
61049 + struct subject_map *next;
61050 +};
61051 +
61052 +struct acl_subj_map_db {
61053 + struct subject_map **s_hash;
61054 + __u32 s_size;
61055 +};
61056 +
61057 +/* End Data Structures Section */
61058 +
61059 +/* Hash functions generated by empirical testing by Brad Spengler
61060 + Makes good use of the low bits of the inode. Generally 0-1 times
61061 + in loop for successful match. 0-3 for unsuccessful match.
61062 + Shift/add algorithm with modulus of table size and an XOR*/
61063 +
61064 +static __inline__ unsigned int
61065 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61066 +{
61067 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61068 +}
61069 +
61070 + static __inline__ unsigned int
61071 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61072 +{
61073 + return ((const unsigned long)userp % sz);
61074 +}
61075 +
61076 +static __inline__ unsigned int
61077 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61078 +{
61079 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61080 +}
61081 +
61082 +static __inline__ unsigned int
61083 +nhash(const char *name, const __u16 len, const unsigned int sz)
61084 +{
61085 + return full_name_hash((const unsigned char *)name, len) % sz;
61086 +}
61087 +
61088 +#define FOR_EACH_ROLE_START(role) \
61089 + role = role_list; \
61090 + while (role) {
61091 +
61092 +#define FOR_EACH_ROLE_END(role) \
61093 + role = role->prev; \
61094 + }
61095 +
61096 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
61097 + subj = NULL; \
61098 + iter = 0; \
61099 + while (iter < role->subj_hash_size) { \
61100 + if (subj == NULL) \
61101 + subj = role->subj_hash[iter]; \
61102 + if (subj == NULL) { \
61103 + iter++; \
61104 + continue; \
61105 + }
61106 +
61107 +#define FOR_EACH_SUBJECT_END(subj,iter) \
61108 + subj = subj->next; \
61109 + if (subj == NULL) \
61110 + iter++; \
61111 + }
61112 +
61113 +
61114 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
61115 + subj = role->hash->first; \
61116 + while (subj != NULL) {
61117 +
61118 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
61119 + subj = subj->next; \
61120 + }
61121 +
61122 +#endif
61123 +
61124 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
61125 new file mode 100644
61126 index 0000000..323ecf2
61127 --- /dev/null
61128 +++ b/include/linux/gralloc.h
61129 @@ -0,0 +1,9 @@
61130 +#ifndef __GRALLOC_H
61131 +#define __GRALLOC_H
61132 +
61133 +void acl_free_all(void);
61134 +int acl_alloc_stack_init(unsigned long size);
61135 +void *acl_alloc(unsigned long len);
61136 +void *acl_alloc_num(unsigned long num, unsigned long len);
61137 +
61138 +#endif
61139 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
61140 new file mode 100644
61141 index 0000000..b30e9bc
61142 --- /dev/null
61143 +++ b/include/linux/grdefs.h
61144 @@ -0,0 +1,140 @@
61145 +#ifndef GRDEFS_H
61146 +#define GRDEFS_H
61147 +
61148 +/* Begin grsecurity status declarations */
61149 +
61150 +enum {
61151 + GR_READY = 0x01,
61152 + GR_STATUS_INIT = 0x00 // disabled state
61153 +};
61154 +
61155 +/* Begin ACL declarations */
61156 +
61157 +/* Role flags */
61158 +
61159 +enum {
61160 + GR_ROLE_USER = 0x0001,
61161 + GR_ROLE_GROUP = 0x0002,
61162 + GR_ROLE_DEFAULT = 0x0004,
61163 + GR_ROLE_SPECIAL = 0x0008,
61164 + GR_ROLE_AUTH = 0x0010,
61165 + GR_ROLE_NOPW = 0x0020,
61166 + GR_ROLE_GOD = 0x0040,
61167 + GR_ROLE_LEARN = 0x0080,
61168 + GR_ROLE_TPE = 0x0100,
61169 + GR_ROLE_DOMAIN = 0x0200,
61170 + GR_ROLE_PAM = 0x0400,
61171 + GR_ROLE_PERSIST = 0x0800
61172 +};
61173 +
61174 +/* ACL Subject and Object mode flags */
61175 +enum {
61176 + GR_DELETED = 0x80000000
61177 +};
61178 +
61179 +/* ACL Object-only mode flags */
61180 +enum {
61181 + GR_READ = 0x00000001,
61182 + GR_APPEND = 0x00000002,
61183 + GR_WRITE = 0x00000004,
61184 + GR_EXEC = 0x00000008,
61185 + GR_FIND = 0x00000010,
61186 + GR_INHERIT = 0x00000020,
61187 + GR_SETID = 0x00000040,
61188 + GR_CREATE = 0x00000080,
61189 + GR_DELETE = 0x00000100,
61190 + GR_LINK = 0x00000200,
61191 + GR_AUDIT_READ = 0x00000400,
61192 + GR_AUDIT_APPEND = 0x00000800,
61193 + GR_AUDIT_WRITE = 0x00001000,
61194 + GR_AUDIT_EXEC = 0x00002000,
61195 + GR_AUDIT_FIND = 0x00004000,
61196 + GR_AUDIT_INHERIT= 0x00008000,
61197 + GR_AUDIT_SETID = 0x00010000,
61198 + GR_AUDIT_CREATE = 0x00020000,
61199 + GR_AUDIT_DELETE = 0x00040000,
61200 + GR_AUDIT_LINK = 0x00080000,
61201 + GR_PTRACERD = 0x00100000,
61202 + GR_NOPTRACE = 0x00200000,
61203 + GR_SUPPRESS = 0x00400000,
61204 + GR_NOLEARN = 0x00800000,
61205 + GR_INIT_TRANSFER= 0x01000000
61206 +};
61207 +
61208 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
61209 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
61210 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
61211 +
61212 +/* ACL subject-only mode flags */
61213 +enum {
61214 + GR_KILL = 0x00000001,
61215 + GR_VIEW = 0x00000002,
61216 + GR_PROTECTED = 0x00000004,
61217 + GR_LEARN = 0x00000008,
61218 + GR_OVERRIDE = 0x00000010,
61219 + /* just a placeholder, this mode is only used in userspace */
61220 + GR_DUMMY = 0x00000020,
61221 + GR_PROTSHM = 0x00000040,
61222 + GR_KILLPROC = 0x00000080,
61223 + GR_KILLIPPROC = 0x00000100,
61224 + /* just a placeholder, this mode is only used in userspace */
61225 + GR_NOTROJAN = 0x00000200,
61226 + GR_PROTPROCFD = 0x00000400,
61227 + GR_PROCACCT = 0x00000800,
61228 + GR_RELAXPTRACE = 0x00001000,
61229 + GR_NESTED = 0x00002000,
61230 + GR_INHERITLEARN = 0x00004000,
61231 + GR_PROCFIND = 0x00008000,
61232 + GR_POVERRIDE = 0x00010000,
61233 + GR_KERNELAUTH = 0x00020000,
61234 + GR_ATSECURE = 0x00040000,
61235 + GR_SHMEXEC = 0x00080000
61236 +};
61237 +
61238 +enum {
61239 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
61240 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
61241 + GR_PAX_ENABLE_MPROTECT = 0x0004,
61242 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
61243 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
61244 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
61245 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
61246 + GR_PAX_DISABLE_MPROTECT = 0x0400,
61247 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
61248 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
61249 +};
61250 +
61251 +enum {
61252 + GR_ID_USER = 0x01,
61253 + GR_ID_GROUP = 0x02,
61254 +};
61255 +
61256 +enum {
61257 + GR_ID_ALLOW = 0x01,
61258 + GR_ID_DENY = 0x02,
61259 +};
61260 +
61261 +#define GR_CRASH_RES 31
61262 +#define GR_UIDTABLE_MAX 500
61263 +
61264 +/* begin resource learning section */
61265 +enum {
61266 + GR_RLIM_CPU_BUMP = 60,
61267 + GR_RLIM_FSIZE_BUMP = 50000,
61268 + GR_RLIM_DATA_BUMP = 10000,
61269 + GR_RLIM_STACK_BUMP = 1000,
61270 + GR_RLIM_CORE_BUMP = 10000,
61271 + GR_RLIM_RSS_BUMP = 500000,
61272 + GR_RLIM_NPROC_BUMP = 1,
61273 + GR_RLIM_NOFILE_BUMP = 5,
61274 + GR_RLIM_MEMLOCK_BUMP = 50000,
61275 + GR_RLIM_AS_BUMP = 500000,
61276 + GR_RLIM_LOCKS_BUMP = 2,
61277 + GR_RLIM_SIGPENDING_BUMP = 5,
61278 + GR_RLIM_MSGQUEUE_BUMP = 10000,
61279 + GR_RLIM_NICE_BUMP = 1,
61280 + GR_RLIM_RTPRIO_BUMP = 1,
61281 + GR_RLIM_RTTIME_BUMP = 1000000
61282 +};
61283 +
61284 +#endif
61285 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
61286 new file mode 100644
61287 index 0000000..da390f1
61288 --- /dev/null
61289 +++ b/include/linux/grinternal.h
61290 @@ -0,0 +1,221 @@
61291 +#ifndef __GRINTERNAL_H
61292 +#define __GRINTERNAL_H
61293 +
61294 +#ifdef CONFIG_GRKERNSEC
61295 +
61296 +#include <linux/fs.h>
61297 +#include <linux/mnt_namespace.h>
61298 +#include <linux/nsproxy.h>
61299 +#include <linux/gracl.h>
61300 +#include <linux/grdefs.h>
61301 +#include <linux/grmsg.h>
61302 +
61303 +void gr_add_learn_entry(const char *fmt, ...)
61304 + __attribute__ ((format (printf, 1, 2)));
61305 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
61306 + const struct vfsmount *mnt);
61307 +__u32 gr_check_create(const struct dentry *new_dentry,
61308 + const struct dentry *parent,
61309 + const struct vfsmount *mnt, const __u32 mode);
61310 +int gr_check_protected_task(const struct task_struct *task);
61311 +__u32 to_gr_audit(const __u32 reqmode);
61312 +int gr_set_acls(const int type);
61313 +int gr_apply_subject_to_task(struct task_struct *task);
61314 +int gr_acl_is_enabled(void);
61315 +char gr_roletype_to_char(void);
61316 +
61317 +void gr_handle_alertkill(struct task_struct *task);
61318 +char *gr_to_filename(const struct dentry *dentry,
61319 + const struct vfsmount *mnt);
61320 +char *gr_to_filename1(const struct dentry *dentry,
61321 + const struct vfsmount *mnt);
61322 +char *gr_to_filename2(const struct dentry *dentry,
61323 + const struct vfsmount *mnt);
61324 +char *gr_to_filename3(const struct dentry *dentry,
61325 + const struct vfsmount *mnt);
61326 +
61327 +extern int grsec_enable_ptrace_readexec;
61328 +extern int grsec_enable_harden_ptrace;
61329 +extern int grsec_enable_link;
61330 +extern int grsec_enable_fifo;
61331 +extern int grsec_enable_execve;
61332 +extern int grsec_enable_shm;
61333 +extern int grsec_enable_execlog;
61334 +extern int grsec_enable_signal;
61335 +extern int grsec_enable_audit_ptrace;
61336 +extern int grsec_enable_forkfail;
61337 +extern int grsec_enable_time;
61338 +extern int grsec_enable_rofs;
61339 +extern int grsec_enable_chroot_shmat;
61340 +extern int grsec_enable_chroot_mount;
61341 +extern int grsec_enable_chroot_double;
61342 +extern int grsec_enable_chroot_pivot;
61343 +extern int grsec_enable_chroot_chdir;
61344 +extern int grsec_enable_chroot_chmod;
61345 +extern int grsec_enable_chroot_mknod;
61346 +extern int grsec_enable_chroot_fchdir;
61347 +extern int grsec_enable_chroot_nice;
61348 +extern int grsec_enable_chroot_execlog;
61349 +extern int grsec_enable_chroot_caps;
61350 +extern int grsec_enable_chroot_sysctl;
61351 +extern int grsec_enable_chroot_unix;
61352 +extern int grsec_enable_tpe;
61353 +extern int grsec_tpe_gid;
61354 +extern int grsec_enable_tpe_all;
61355 +extern int grsec_enable_tpe_invert;
61356 +extern int grsec_enable_socket_all;
61357 +extern int grsec_socket_all_gid;
61358 +extern int grsec_enable_socket_client;
61359 +extern int grsec_socket_client_gid;
61360 +extern int grsec_enable_socket_server;
61361 +extern int grsec_socket_server_gid;
61362 +extern int grsec_audit_gid;
61363 +extern int grsec_enable_group;
61364 +extern int grsec_enable_audit_textrel;
61365 +extern int grsec_enable_log_rwxmaps;
61366 +extern int grsec_enable_mount;
61367 +extern int grsec_enable_chdir;
61368 +extern int grsec_resource_logging;
61369 +extern int grsec_enable_blackhole;
61370 +extern int grsec_lastack_retries;
61371 +extern int grsec_enable_brute;
61372 +extern int grsec_lock;
61373 +
61374 +extern spinlock_t grsec_alert_lock;
61375 +extern unsigned long grsec_alert_wtime;
61376 +extern unsigned long grsec_alert_fyet;
61377 +
61378 +extern spinlock_t grsec_audit_lock;
61379 +
61380 +extern rwlock_t grsec_exec_file_lock;
61381 +
61382 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
61383 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
61384 + (tsk)->exec_file->f_vfsmnt) : "/")
61385 +
61386 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
61387 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
61388 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61389 +
61390 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
61391 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
61392 + (tsk)->exec_file->f_vfsmnt) : "/")
61393 +
61394 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
61395 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
61396 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
61397 +
61398 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
61399 +
61400 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
61401 +
61402 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
61403 + (task)->pid, (cred)->uid, \
61404 + (cred)->euid, (cred)->gid, (cred)->egid, \
61405 + gr_parent_task_fullpath(task), \
61406 + (task)->real_parent->comm, (task)->real_parent->pid, \
61407 + (pcred)->uid, (pcred)->euid, \
61408 + (pcred)->gid, (pcred)->egid
61409 +
61410 +#define GR_CHROOT_CAPS {{ \
61411 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
61412 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
61413 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
61414 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
61415 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
61416 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
61417 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
61418 +
61419 +#define security_learn(normal_msg,args...) \
61420 +({ \
61421 + read_lock(&grsec_exec_file_lock); \
61422 + gr_add_learn_entry(normal_msg "\n", ## args); \
61423 + read_unlock(&grsec_exec_file_lock); \
61424 +})
61425 +
61426 +enum {
61427 + GR_DO_AUDIT,
61428 + GR_DONT_AUDIT,
61429 + /* used for non-audit messages that we shouldn't kill the task on */
61430 + GR_DONT_AUDIT_GOOD
61431 +};
61432 +
61433 +enum {
61434 + GR_TTYSNIFF,
61435 + GR_RBAC,
61436 + GR_RBAC_STR,
61437 + GR_STR_RBAC,
61438 + GR_RBAC_MODE2,
61439 + GR_RBAC_MODE3,
61440 + GR_FILENAME,
61441 + GR_SYSCTL_HIDDEN,
61442 + GR_NOARGS,
61443 + GR_ONE_INT,
61444 + GR_ONE_INT_TWO_STR,
61445 + GR_ONE_STR,
61446 + GR_STR_INT,
61447 + GR_TWO_STR_INT,
61448 + GR_TWO_INT,
61449 + GR_TWO_U64,
61450 + GR_THREE_INT,
61451 + GR_FIVE_INT_TWO_STR,
61452 + GR_TWO_STR,
61453 + GR_THREE_STR,
61454 + GR_FOUR_STR,
61455 + GR_STR_FILENAME,
61456 + GR_FILENAME_STR,
61457 + GR_FILENAME_TWO_INT,
61458 + GR_FILENAME_TWO_INT_STR,
61459 + GR_TEXTREL,
61460 + GR_PTRACE,
61461 + GR_RESOURCE,
61462 + GR_CAP,
61463 + GR_SIG,
61464 + GR_SIG2,
61465 + GR_CRASH1,
61466 + GR_CRASH2,
61467 + GR_PSACCT,
61468 + GR_RWXMAP
61469 +};
61470 +
61471 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
61472 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
61473 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
61474 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
61475 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
61476 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
61477 +#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)
61478 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
61479 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
61480 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
61481 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
61482 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
61483 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
61484 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
61485 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
61486 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
61487 +#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)
61488 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
61489 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
61490 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
61491 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
61492 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
61493 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
61494 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
61495 +#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)
61496 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
61497 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
61498 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
61499 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
61500 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
61501 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
61502 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
61503 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
61504 +#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)
61505 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
61506 +
61507 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
61508 +
61509 +#endif
61510 +
61511 +#endif
61512 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
61513 new file mode 100644
61514 index 0000000..ae576a1
61515 --- /dev/null
61516 +++ b/include/linux/grmsg.h
61517 @@ -0,0 +1,109 @@
61518 +#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"
61519 +#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"
61520 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
61521 +#define GR_STOPMOD_MSG "denied modification of module state by "
61522 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
61523 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
61524 +#define GR_IOPERM_MSG "denied use of ioperm() by "
61525 +#define GR_IOPL_MSG "denied use of iopl() by "
61526 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
61527 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
61528 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
61529 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
61530 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
61531 +#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"
61532 +#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"
61533 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
61534 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
61535 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
61536 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
61537 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
61538 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
61539 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
61540 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
61541 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
61542 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
61543 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
61544 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
61545 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
61546 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
61547 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
61548 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
61549 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
61550 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
61551 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
61552 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
61553 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
61554 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
61555 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
61556 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
61557 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
61558 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
61559 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
61560 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
61561 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
61562 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
61563 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
61564 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
61565 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
61566 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
61567 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
61568 +#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"
61569 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
61570 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
61571 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
61572 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
61573 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
61574 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
61575 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
61576 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
61577 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
61578 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
61579 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
61580 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
61581 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
61582 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
61583 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
61584 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
61585 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
61586 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
61587 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
61588 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
61589 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
61590 +#define GR_NICE_CHROOT_MSG "denied priority change by "
61591 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
61592 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
61593 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
61594 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
61595 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
61596 +#define GR_TIME_MSG "time set by "
61597 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
61598 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
61599 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
61600 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
61601 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
61602 +#define GR_BIND_MSG "denied bind() by "
61603 +#define GR_CONNECT_MSG "denied connect() by "
61604 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
61605 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
61606 +#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"
61607 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
61608 +#define GR_CAP_ACL_MSG "use of %s denied for "
61609 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
61610 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
61611 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
61612 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
61613 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
61614 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
61615 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
61616 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
61617 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
61618 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
61619 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
61620 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
61621 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
61622 +#define GR_VM86_MSG "denied use of vm86 by "
61623 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
61624 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
61625 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
61626 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
61627 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
61628 new file mode 100644
61629 index 0000000..acd05db
61630 --- /dev/null
61631 +++ b/include/linux/grsecurity.h
61632 @@ -0,0 +1,232 @@
61633 +#ifndef GR_SECURITY_H
61634 +#define GR_SECURITY_H
61635 +#include <linux/fs.h>
61636 +#include <linux/fs_struct.h>
61637 +#include <linux/binfmts.h>
61638 +#include <linux/gracl.h>
61639 +
61640 +/* notify of brain-dead configs */
61641 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
61642 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
61643 +#endif
61644 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
61645 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
61646 +#endif
61647 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
61648 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
61649 +#endif
61650 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
61651 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
61652 +#endif
61653 +
61654 +#include <linux/compat.h>
61655 +
61656 +struct user_arg_ptr {
61657 +#ifdef CONFIG_COMPAT
61658 + bool is_compat;
61659 +#endif
61660 + union {
61661 + const char __user *const __user *native;
61662 +#ifdef CONFIG_COMPAT
61663 + compat_uptr_t __user *compat;
61664 +#endif
61665 + } ptr;
61666 +};
61667 +
61668 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
61669 +void gr_handle_brute_check(void);
61670 +void gr_handle_kernel_exploit(void);
61671 +int gr_process_user_ban(void);
61672 +
61673 +char gr_roletype_to_char(void);
61674 +
61675 +int gr_acl_enable_at_secure(void);
61676 +
61677 +int gr_check_user_change(int real, int effective, int fs);
61678 +int gr_check_group_change(int real, int effective, int fs);
61679 +
61680 +void gr_del_task_from_ip_table(struct task_struct *p);
61681 +
61682 +int gr_pid_is_chrooted(struct task_struct *p);
61683 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
61684 +int gr_handle_chroot_nice(void);
61685 +int gr_handle_chroot_sysctl(const int op);
61686 +int gr_handle_chroot_setpriority(struct task_struct *p,
61687 + const int niceval);
61688 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
61689 +int gr_handle_chroot_chroot(const struct dentry *dentry,
61690 + const struct vfsmount *mnt);
61691 +void gr_handle_chroot_chdir(struct path *path);
61692 +int gr_handle_chroot_chmod(const struct dentry *dentry,
61693 + const struct vfsmount *mnt, const int mode);
61694 +int gr_handle_chroot_mknod(const struct dentry *dentry,
61695 + const struct vfsmount *mnt, const int mode);
61696 +int gr_handle_chroot_mount(const struct dentry *dentry,
61697 + const struct vfsmount *mnt,
61698 + const char *dev_name);
61699 +int gr_handle_chroot_pivot(void);
61700 +int gr_handle_chroot_unix(const pid_t pid);
61701 +
61702 +int gr_handle_rawio(const struct inode *inode);
61703 +
61704 +void gr_handle_ioperm(void);
61705 +void gr_handle_iopl(void);
61706 +
61707 +umode_t gr_acl_umask(void);
61708 +
61709 +int gr_tpe_allow(const struct file *file);
61710 +
61711 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
61712 +void gr_clear_chroot_entries(struct task_struct *task);
61713 +
61714 +void gr_log_forkfail(const int retval);
61715 +void gr_log_timechange(void);
61716 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
61717 +void gr_log_chdir(const struct dentry *dentry,
61718 + const struct vfsmount *mnt);
61719 +void gr_log_chroot_exec(const struct dentry *dentry,
61720 + const struct vfsmount *mnt);
61721 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
61722 +void gr_log_remount(const char *devname, const int retval);
61723 +void gr_log_unmount(const char *devname, const int retval);
61724 +void gr_log_mount(const char *from, const char *to, const int retval);
61725 +void gr_log_textrel(struct vm_area_struct *vma);
61726 +void gr_log_rwxmmap(struct file *file);
61727 +void gr_log_rwxmprotect(struct file *file);
61728 +
61729 +int gr_handle_follow_link(const struct inode *parent,
61730 + const struct inode *inode,
61731 + const struct dentry *dentry,
61732 + const struct vfsmount *mnt);
61733 +int gr_handle_fifo(const struct dentry *dentry,
61734 + const struct vfsmount *mnt,
61735 + const struct dentry *dir, const int flag,
61736 + const int acc_mode);
61737 +int gr_handle_hardlink(const struct dentry *dentry,
61738 + const struct vfsmount *mnt,
61739 + struct inode *inode,
61740 + const int mode, const char *to);
61741 +
61742 +int gr_is_capable(const int cap);
61743 +int gr_is_capable_nolog(const int cap);
61744 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61745 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
61746 +
61747 +void gr_learn_resource(const struct task_struct *task, const int limit,
61748 + const unsigned long wanted, const int gt);
61749 +void gr_copy_label(struct task_struct *tsk);
61750 +void gr_handle_crash(struct task_struct *task, const int sig);
61751 +int gr_handle_signal(const struct task_struct *p, const int sig);
61752 +int gr_check_crash_uid(const uid_t uid);
61753 +int gr_check_protected_task(const struct task_struct *task);
61754 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
61755 +int gr_acl_handle_mmap(const struct file *file,
61756 + const unsigned long prot);
61757 +int gr_acl_handle_mprotect(const struct file *file,
61758 + const unsigned long prot);
61759 +int gr_check_hidden_task(const struct task_struct *tsk);
61760 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
61761 + const struct vfsmount *mnt);
61762 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
61763 + const struct vfsmount *mnt);
61764 +__u32 gr_acl_handle_access(const struct dentry *dentry,
61765 + const struct vfsmount *mnt, const int fmode);
61766 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
61767 + const struct vfsmount *mnt, umode_t *mode);
61768 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
61769 + const struct vfsmount *mnt);
61770 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
61771 + const struct vfsmount *mnt);
61772 +int gr_handle_ptrace(struct task_struct *task, const long request);
61773 +int gr_handle_proc_ptrace(struct task_struct *task);
61774 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
61775 + const struct vfsmount *mnt);
61776 +int gr_check_crash_exec(const struct file *filp);
61777 +int gr_acl_is_enabled(void);
61778 +void gr_set_kernel_label(struct task_struct *task);
61779 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
61780 + const gid_t gid);
61781 +int gr_set_proc_label(const struct dentry *dentry,
61782 + const struct vfsmount *mnt,
61783 + const int unsafe_flags);
61784 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
61785 + const struct vfsmount *mnt);
61786 +__u32 gr_acl_handle_open(const struct dentry *dentry,
61787 + const struct vfsmount *mnt, int acc_mode);
61788 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
61789 + const struct dentry *p_dentry,
61790 + const struct vfsmount *p_mnt,
61791 + int open_flags, int acc_mode, const int imode);
61792 +void gr_handle_create(const struct dentry *dentry,
61793 + const struct vfsmount *mnt);
61794 +void gr_handle_proc_create(const struct dentry *dentry,
61795 + const struct inode *inode);
61796 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
61797 + const struct dentry *parent_dentry,
61798 + const struct vfsmount *parent_mnt,
61799 + const int mode);
61800 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
61801 + const struct dentry *parent_dentry,
61802 + const struct vfsmount *parent_mnt);
61803 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
61804 + const struct vfsmount *mnt);
61805 +void gr_handle_delete(const ino_t ino, const dev_t dev);
61806 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
61807 + const struct vfsmount *mnt);
61808 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
61809 + const struct dentry *parent_dentry,
61810 + const struct vfsmount *parent_mnt,
61811 + const char *from);
61812 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
61813 + const struct dentry *parent_dentry,
61814 + const struct vfsmount *parent_mnt,
61815 + const struct dentry *old_dentry,
61816 + const struct vfsmount *old_mnt, const char *to);
61817 +int gr_acl_handle_rename(struct dentry *new_dentry,
61818 + struct dentry *parent_dentry,
61819 + const struct vfsmount *parent_mnt,
61820 + struct dentry *old_dentry,
61821 + struct inode *old_parent_inode,
61822 + struct vfsmount *old_mnt, const char *newname);
61823 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61824 + struct dentry *old_dentry,
61825 + struct dentry *new_dentry,
61826 + struct vfsmount *mnt, const __u8 replace);
61827 +__u32 gr_check_link(const struct dentry *new_dentry,
61828 + const struct dentry *parent_dentry,
61829 + const struct vfsmount *parent_mnt,
61830 + const struct dentry *old_dentry,
61831 + const struct vfsmount *old_mnt);
61832 +int gr_acl_handle_filldir(const struct file *file, const char *name,
61833 + const unsigned int namelen, const ino_t ino);
61834 +
61835 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
61836 + const struct vfsmount *mnt);
61837 +void gr_acl_handle_exit(void);
61838 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
61839 +int gr_acl_handle_procpidmem(const struct task_struct *task);
61840 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
61841 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
61842 +void gr_audit_ptrace(struct task_struct *task);
61843 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
61844 +
61845 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
61846 +
61847 +#ifdef CONFIG_GRKERNSEC
61848 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
61849 +void gr_handle_vm86(void);
61850 +void gr_handle_mem_readwrite(u64 from, u64 to);
61851 +
61852 +void gr_log_badprocpid(const char *entry);
61853 +
61854 +extern int grsec_enable_dmesg;
61855 +extern int grsec_disable_privio;
61856 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61857 +extern int grsec_enable_chroot_findtask;
61858 +#endif
61859 +#ifdef CONFIG_GRKERNSEC_SETXID
61860 +extern int grsec_enable_setxid;
61861 +#endif
61862 +#endif
61863 +
61864 +#endif
61865 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
61866 new file mode 100644
61867 index 0000000..e7ffaaf
61868 --- /dev/null
61869 +++ b/include/linux/grsock.h
61870 @@ -0,0 +1,19 @@
61871 +#ifndef __GRSOCK_H
61872 +#define __GRSOCK_H
61873 +
61874 +extern void gr_attach_curr_ip(const struct sock *sk);
61875 +extern int gr_handle_sock_all(const int family, const int type,
61876 + const int protocol);
61877 +extern int gr_handle_sock_server(const struct sockaddr *sck);
61878 +extern int gr_handle_sock_server_other(const struct sock *sck);
61879 +extern int gr_handle_sock_client(const struct sockaddr *sck);
61880 +extern int gr_search_connect(struct socket * sock,
61881 + struct sockaddr_in * addr);
61882 +extern int gr_search_bind(struct socket * sock,
61883 + struct sockaddr_in * addr);
61884 +extern int gr_search_listen(struct socket * sock);
61885 +extern int gr_search_accept(struct socket * sock);
61886 +extern int gr_search_socket(const int domain, const int type,
61887 + const int protocol);
61888 +
61889 +#endif
61890 diff --git a/include/linux/hid.h b/include/linux/hid.h
61891 index 3a95da6..51986f1 100644
61892 --- a/include/linux/hid.h
61893 +++ b/include/linux/hid.h
61894 @@ -696,7 +696,7 @@ struct hid_ll_driver {
61895 unsigned int code, int value);
61896
61897 int (*parse)(struct hid_device *hdev);
61898 -};
61899 +} __no_const;
61900
61901 #define PM_HINT_FULLON 1<<5
61902 #define PM_HINT_NORMAL 1<<1
61903 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
61904 index 3a93f73..b19d0b3 100644
61905 --- a/include/linux/highmem.h
61906 +++ b/include/linux/highmem.h
61907 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
61908 kunmap_atomic(kaddr, KM_USER0);
61909 }
61910
61911 +static inline void sanitize_highpage(struct page *page)
61912 +{
61913 + void *kaddr;
61914 + unsigned long flags;
61915 +
61916 + local_irq_save(flags);
61917 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
61918 + clear_page(kaddr);
61919 + kunmap_atomic(kaddr, KM_CLEARPAGE);
61920 + local_irq_restore(flags);
61921 +}
61922 +
61923 static inline void zero_user_segments(struct page *page,
61924 unsigned start1, unsigned end1,
61925 unsigned start2, unsigned end2)
61926 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
61927 index 8e25a91..551b161 100644
61928 --- a/include/linux/i2c.h
61929 +++ b/include/linux/i2c.h
61930 @@ -364,6 +364,7 @@ struct i2c_algorithm {
61931 /* To determine what the adapter supports */
61932 u32 (*functionality) (struct i2c_adapter *);
61933 };
61934 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
61935
61936 /*
61937 * i2c_adapter is the structure used to identify a physical i2c bus along
61938 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
61939 index a6deef4..c56a7f2 100644
61940 --- a/include/linux/i2o.h
61941 +++ b/include/linux/i2o.h
61942 @@ -564,7 +564,7 @@ struct i2o_controller {
61943 struct i2o_device *exec; /* Executive */
61944 #if BITS_PER_LONG == 64
61945 spinlock_t context_list_lock; /* lock for context_list */
61946 - atomic_t context_list_counter; /* needed for unique contexts */
61947 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
61948 struct list_head context_list; /* list of context id's
61949 and pointers */
61950 #endif
61951 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
61952 index 58404b0..439ed95 100644
61953 --- a/include/linux/if_team.h
61954 +++ b/include/linux/if_team.h
61955 @@ -64,6 +64,7 @@ struct team_mode_ops {
61956 void (*port_leave)(struct team *team, struct team_port *port);
61957 void (*port_change_mac)(struct team *team, struct team_port *port);
61958 };
61959 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
61960
61961 enum team_option_type {
61962 TEAM_OPTION_TYPE_U32,
61963 @@ -112,7 +113,7 @@ struct team {
61964 struct list_head option_list;
61965
61966 const struct team_mode *mode;
61967 - struct team_mode_ops ops;
61968 + team_mode_ops_no_const ops;
61969 long mode_priv[TEAM_MODE_PRIV_LONGS];
61970 };
61971
61972 diff --git a/include/linux/init.h b/include/linux/init.h
61973 index 6b95109..4aca62c 100644
61974 --- a/include/linux/init.h
61975 +++ b/include/linux/init.h
61976 @@ -294,13 +294,13 @@ void __init parse_early_options(char *cmdline);
61977
61978 /* Each module must use one module_init(). */
61979 #define module_init(initfn) \
61980 - static inline initcall_t __inittest(void) \
61981 + static inline __used initcall_t __inittest(void) \
61982 { return initfn; } \
61983 int init_module(void) __attribute__((alias(#initfn)));
61984
61985 /* This is only required if you want to be unloadable. */
61986 #define module_exit(exitfn) \
61987 - static inline exitcall_t __exittest(void) \
61988 + static inline __used exitcall_t __exittest(void) \
61989 { return exitfn; } \
61990 void cleanup_module(void) __attribute__((alias(#exitfn)));
61991
61992 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
61993 index 9c66b1a..a3fdded 100644
61994 --- a/include/linux/init_task.h
61995 +++ b/include/linux/init_task.h
61996 @@ -127,6 +127,12 @@ extern struct cred init_cred;
61997
61998 #define INIT_TASK_COMM "swapper"
61999
62000 +#ifdef CONFIG_X86
62001 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62002 +#else
62003 +#define INIT_TASK_THREAD_INFO
62004 +#endif
62005 +
62006 /*
62007 * INIT_TASK is used to set up the first task table, touch at
62008 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62009 @@ -165,6 +171,7 @@ extern struct cred init_cred;
62010 RCU_INIT_POINTER(.cred, &init_cred), \
62011 .comm = INIT_TASK_COMM, \
62012 .thread = INIT_THREAD, \
62013 + INIT_TASK_THREAD_INFO \
62014 .fs = &init_fs, \
62015 .files = &init_files, \
62016 .signal = &init_signals, \
62017 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62018 index e6ca56d..8583707 100644
62019 --- a/include/linux/intel-iommu.h
62020 +++ b/include/linux/intel-iommu.h
62021 @@ -296,7 +296,7 @@ struct iommu_flush {
62022 u8 fm, u64 type);
62023 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62024 unsigned int size_order, u64 type);
62025 -};
62026 +} __no_const;
62027
62028 enum {
62029 SR_DMAR_FECTL_REG,
62030 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62031 index a64b00e..464d8bc 100644
62032 --- a/include/linux/interrupt.h
62033 +++ b/include/linux/interrupt.h
62034 @@ -441,7 +441,7 @@ enum
62035 /* map softirq index to softirq name. update 'softirq_to_name' in
62036 * kernel/softirq.c when adding a new softirq.
62037 */
62038 -extern char *softirq_to_name[NR_SOFTIRQS];
62039 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62040
62041 /* softirq mask and active fields moved to irq_cpustat_t in
62042 * asm/hardirq.h to get better cache usage. KAO
62043 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62044
62045 struct softirq_action
62046 {
62047 - void (*action)(struct softirq_action *);
62048 + void (*action)(void);
62049 };
62050
62051 asmlinkage void do_softirq(void);
62052 asmlinkage void __do_softirq(void);
62053 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
62054 +extern void open_softirq(int nr, void (*action)(void));
62055 extern void softirq_init(void);
62056 static inline void __raise_softirq_irqoff(unsigned int nr)
62057 {
62058 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
62059 index 3875719..4cd454c 100644
62060 --- a/include/linux/kallsyms.h
62061 +++ b/include/linux/kallsyms.h
62062 @@ -15,7 +15,8 @@
62063
62064 struct module;
62065
62066 -#ifdef CONFIG_KALLSYMS
62067 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
62068 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62069 /* Lookup the address for a symbol. Returns 0 if not found. */
62070 unsigned long kallsyms_lookup_name(const char *name);
62071
62072 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
62073 /* Stupid that this does nothing, but I didn't create this mess. */
62074 #define __print_symbol(fmt, addr)
62075 #endif /*CONFIG_KALLSYMS*/
62076 +#else /* when included by kallsyms.c, vsnprintf.c, or
62077 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
62078 +extern void __print_symbol(const char *fmt, unsigned long address);
62079 +extern int sprint_backtrace(char *buffer, unsigned long address);
62080 +extern int sprint_symbol(char *buffer, unsigned long address);
62081 +const char *kallsyms_lookup(unsigned long addr,
62082 + unsigned long *symbolsize,
62083 + unsigned long *offset,
62084 + char **modname, char *namebuf);
62085 +#endif
62086
62087 /* This macro allows us to keep printk typechecking */
62088 static __printf(1, 2)
62089 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
62090 index c4d2fc1..5df9c19 100644
62091 --- a/include/linux/kgdb.h
62092 +++ b/include/linux/kgdb.h
62093 @@ -53,7 +53,7 @@ extern int kgdb_connected;
62094 extern int kgdb_io_module_registered;
62095
62096 extern atomic_t kgdb_setting_breakpoint;
62097 -extern atomic_t kgdb_cpu_doing_single_step;
62098 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
62099
62100 extern struct task_struct *kgdb_usethread;
62101 extern struct task_struct *kgdb_contthread;
62102 @@ -252,7 +252,7 @@ struct kgdb_arch {
62103 void (*disable_hw_break)(struct pt_regs *regs);
62104 void (*remove_all_hw_break)(void);
62105 void (*correct_hw_break)(void);
62106 -};
62107 +} __do_const;
62108
62109 /**
62110 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
62111 @@ -277,7 +277,7 @@ struct kgdb_io {
62112 void (*pre_exception) (void);
62113 void (*post_exception) (void);
62114 int is_console;
62115 -};
62116 +} __do_const;
62117
62118 extern struct kgdb_arch arch_kgdb_ops;
62119
62120 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
62121 index 0fb48ef..1b680b2 100644
62122 --- a/include/linux/kmod.h
62123 +++ b/include/linux/kmod.h
62124 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
62125 * usually useless though. */
62126 extern __printf(2, 3)
62127 int __request_module(bool wait, const char *name, ...);
62128 +extern __printf(3, 4)
62129 +int ___request_module(bool wait, char *param_name, const char *name, ...);
62130 #define request_module(mod...) __request_module(true, mod)
62131 #define request_module_nowait(mod...) __request_module(false, mod)
62132 #define try_then_request_module(x, mod...) \
62133 diff --git a/include/linux/kref.h b/include/linux/kref.h
62134 index 9c07dce..a92fa71 100644
62135 --- a/include/linux/kref.h
62136 +++ b/include/linux/kref.h
62137 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
62138 static inline int kref_sub(struct kref *kref, unsigned int count,
62139 void (*release)(struct kref *kref))
62140 {
62141 - WARN_ON(release == NULL);
62142 + BUG_ON(release == NULL);
62143
62144 if (atomic_sub_and_test((int) count, &kref->refcount)) {
62145 release(kref);
62146 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
62147 index 4c4e83d..695674f 100644
62148 --- a/include/linux/kvm_host.h
62149 +++ b/include/linux/kvm_host.h
62150 @@ -326,7 +326,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
62151 void vcpu_load(struct kvm_vcpu *vcpu);
62152 void vcpu_put(struct kvm_vcpu *vcpu);
62153
62154 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62155 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
62156 struct module *module);
62157 void kvm_exit(void);
62158
62159 @@ -485,7 +485,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
62160 struct kvm_guest_debug *dbg);
62161 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
62162
62163 -int kvm_arch_init(void *opaque);
62164 +int kvm_arch_init(const void *opaque);
62165 void kvm_arch_exit(void);
62166
62167 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
62168 diff --git a/include/linux/libata.h b/include/linux/libata.h
62169 index cafc09a..d7e7829 100644
62170 --- a/include/linux/libata.h
62171 +++ b/include/linux/libata.h
62172 @@ -909,7 +909,7 @@ struct ata_port_operations {
62173 * fields must be pointers.
62174 */
62175 const struct ata_port_operations *inherits;
62176 -};
62177 +} __do_const;
62178
62179 struct ata_port_info {
62180 unsigned long flags;
62181 diff --git a/include/linux/mca.h b/include/linux/mca.h
62182 index 3797270..7765ede 100644
62183 --- a/include/linux/mca.h
62184 +++ b/include/linux/mca.h
62185 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
62186 int region);
62187 void * (*mca_transform_memory)(struct mca_device *,
62188 void *memory);
62189 -};
62190 +} __no_const;
62191
62192 struct mca_bus {
62193 u64 default_dma_mask;
62194 diff --git a/include/linux/memory.h b/include/linux/memory.h
62195 index 1ac7f6e..a5794d0 100644
62196 --- a/include/linux/memory.h
62197 +++ b/include/linux/memory.h
62198 @@ -143,7 +143,7 @@ struct memory_accessor {
62199 size_t count);
62200 ssize_t (*write)(struct memory_accessor *, const char *buf,
62201 off_t offset, size_t count);
62202 -};
62203 +} __no_const;
62204
62205 /*
62206 * Kernel text modification mutex, used for code patching. Users of this lock
62207 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
62208 index 9970337..9444122 100644
62209 --- a/include/linux/mfd/abx500.h
62210 +++ b/include/linux/mfd/abx500.h
62211 @@ -188,6 +188,7 @@ struct abx500_ops {
62212 int (*event_registers_startup_state_get) (struct device *, u8 *);
62213 int (*startup_irq_enabled) (struct device *, unsigned int);
62214 };
62215 +typedef struct abx500_ops __no_const abx500_ops_no_const;
62216
62217 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
62218 void abx500_remove_ops(struct device *dev);
62219 diff --git a/include/linux/mm.h b/include/linux/mm.h
62220 index 17b27cd..baea141 100644
62221 --- a/include/linux/mm.h
62222 +++ b/include/linux/mm.h
62223 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
62224
62225 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
62226 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
62227 +
62228 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
62229 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
62230 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
62231 +#else
62232 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
62233 +#endif
62234 +
62235 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
62236 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
62237
62238 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
62239 int set_page_dirty_lock(struct page *page);
62240 int clear_page_dirty_for_io(struct page *page);
62241
62242 -/* Is the vma a continuation of the stack vma above it? */
62243 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
62244 -{
62245 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
62246 -}
62247 -
62248 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
62249 - unsigned long addr)
62250 -{
62251 - return (vma->vm_flags & VM_GROWSDOWN) &&
62252 - (vma->vm_start == addr) &&
62253 - !vma_growsdown(vma->vm_prev, addr);
62254 -}
62255 -
62256 -/* Is the vma a continuation of the stack vma below it? */
62257 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
62258 -{
62259 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
62260 -}
62261 -
62262 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
62263 - unsigned long addr)
62264 -{
62265 - return (vma->vm_flags & VM_GROWSUP) &&
62266 - (vma->vm_end == addr) &&
62267 - !vma_growsup(vma->vm_next, addr);
62268 -}
62269 -
62270 extern unsigned long move_page_tables(struct vm_area_struct *vma,
62271 unsigned long old_addr, struct vm_area_struct *new_vma,
62272 unsigned long new_addr, unsigned long len);
62273 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
62274 }
62275 #endif
62276
62277 +#ifdef CONFIG_MMU
62278 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
62279 +#else
62280 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
62281 +{
62282 + return __pgprot(0);
62283 +}
62284 +#endif
62285 +
62286 int vma_wants_writenotify(struct vm_area_struct *vma);
62287
62288 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
62289 @@ -1152,8 +1140,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
62290 {
62291 return 0;
62292 }
62293 +
62294 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
62295 + unsigned long address)
62296 +{
62297 + return 0;
62298 +}
62299 #else
62300 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62301 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
62302 #endif
62303
62304 #ifdef __PAGETABLE_PMD_FOLDED
62305 @@ -1162,8 +1157,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
62306 {
62307 return 0;
62308 }
62309 +
62310 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
62311 + unsigned long address)
62312 +{
62313 + return 0;
62314 +}
62315 #else
62316 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
62317 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
62318 #endif
62319
62320 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
62321 @@ -1181,11 +1183,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
62322 NULL: pud_offset(pgd, address);
62323 }
62324
62325 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
62326 +{
62327 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
62328 + NULL: pud_offset(pgd, address);
62329 +}
62330 +
62331 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
62332 {
62333 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
62334 NULL: pmd_offset(pud, address);
62335 }
62336 +
62337 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
62338 +{
62339 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
62340 + NULL: pmd_offset(pud, address);
62341 +}
62342 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
62343
62344 #if USE_SPLIT_PTLOCKS
62345 @@ -1409,6 +1423,7 @@ out:
62346 }
62347
62348 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
62349 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
62350
62351 extern unsigned long do_brk(unsigned long, unsigned long);
62352
62353 @@ -1466,6 +1481,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
62354 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
62355 struct vm_area_struct **pprev);
62356
62357 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
62358 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
62359 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
62360 +
62361 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
62362 NULL if none. Assume start_addr < end_addr. */
62363 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
62364 @@ -1494,15 +1513,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
62365 return vma;
62366 }
62367
62368 -#ifdef CONFIG_MMU
62369 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
62370 -#else
62371 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
62372 -{
62373 - return __pgprot(0);
62374 -}
62375 -#endif
62376 -
62377 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
62378 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
62379 unsigned long pfn, unsigned long size, pgprot_t);
62380 @@ -1606,7 +1616,7 @@ extern int unpoison_memory(unsigned long pfn);
62381 extern int sysctl_memory_failure_early_kill;
62382 extern int sysctl_memory_failure_recovery;
62383 extern void shake_page(struct page *p, int access);
62384 -extern atomic_long_t mce_bad_pages;
62385 +extern atomic_long_unchecked_t mce_bad_pages;
62386 extern int soft_offline_page(struct page *page, int flags);
62387
62388 extern void dump_page(struct page *page);
62389 @@ -1637,5 +1647,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
62390 static inline bool page_is_guard(struct page *page) { return false; }
62391 #endif /* CONFIG_DEBUG_PAGEALLOC */
62392
62393 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
62394 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
62395 +#else
62396 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
62397 +#endif
62398 +
62399 #endif /* __KERNEL__ */
62400 #endif /* _LINUX_MM_H */
62401 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
62402 index 3cc3062..efeaeb7 100644
62403 --- a/include/linux/mm_types.h
62404 +++ b/include/linux/mm_types.h
62405 @@ -252,6 +252,8 @@ struct vm_area_struct {
62406 #ifdef CONFIG_NUMA
62407 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
62408 #endif
62409 +
62410 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
62411 };
62412
62413 struct core_thread {
62414 @@ -326,7 +328,7 @@ struct mm_struct {
62415 unsigned long def_flags;
62416 unsigned long nr_ptes; /* Page table pages */
62417 unsigned long start_code, end_code, start_data, end_data;
62418 - unsigned long start_brk, brk, start_stack;
62419 + unsigned long brk_gap, start_brk, brk, start_stack;
62420 unsigned long arg_start, arg_end, env_start, env_end;
62421
62422 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
62423 @@ -388,6 +390,24 @@ struct mm_struct {
62424 #ifdef CONFIG_CPUMASK_OFFSTACK
62425 struct cpumask cpumask_allocation;
62426 #endif
62427 +
62428 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS) || defined(CONFIG_PAX_HAVE_ACL_FLAGS) || defined(CONFIG_PAX_HOOK_ACL_FLAGS)
62429 + unsigned long pax_flags;
62430 +#endif
62431 +
62432 +#ifdef CONFIG_PAX_DLRESOLVE
62433 + unsigned long call_dl_resolve;
62434 +#endif
62435 +
62436 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
62437 + unsigned long call_syscall;
62438 +#endif
62439 +
62440 +#ifdef CONFIG_PAX_ASLR
62441 + unsigned long delta_mmap; /* randomized offset */
62442 + unsigned long delta_stack; /* randomized offset */
62443 +#endif
62444 +
62445 };
62446
62447 static inline void mm_init_cpumask(struct mm_struct *mm)
62448 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
62449 index 1d1b1e1..2a13c78 100644
62450 --- a/include/linux/mmu_notifier.h
62451 +++ b/include/linux/mmu_notifier.h
62452 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
62453 */
62454 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
62455 ({ \
62456 - pte_t __pte; \
62457 + pte_t ___pte; \
62458 struct vm_area_struct *___vma = __vma; \
62459 unsigned long ___address = __address; \
62460 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
62461 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
62462 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
62463 - __pte; \
62464 + ___pte; \
62465 })
62466
62467 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
62468 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
62469 index 650ba2f..af0a58c 100644
62470 --- a/include/linux/mmzone.h
62471 +++ b/include/linux/mmzone.h
62472 @@ -379,7 +379,7 @@ struct zone {
62473 unsigned long flags; /* zone flags, see below */
62474
62475 /* Zone statistics */
62476 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62477 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
62478
62479 /*
62480 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
62481 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
62482 index 83ac071..2656e0e 100644
62483 --- a/include/linux/mod_devicetable.h
62484 +++ b/include/linux/mod_devicetable.h
62485 @@ -12,7 +12,7 @@
62486 typedef unsigned long kernel_ulong_t;
62487 #endif
62488
62489 -#define PCI_ANY_ID (~0)
62490 +#define PCI_ANY_ID ((__u16)~0)
62491
62492 struct pci_device_id {
62493 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
62494 @@ -131,7 +131,7 @@ struct usb_device_id {
62495 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
62496 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
62497
62498 -#define HID_ANY_ID (~0)
62499 +#define HID_ANY_ID (~0U)
62500
62501 struct hid_device_id {
62502 __u16 bus;
62503 diff --git a/include/linux/module.h b/include/linux/module.h
62504 index 4598bf0..e069d7f 100644
62505 --- a/include/linux/module.h
62506 +++ b/include/linux/module.h
62507 @@ -17,6 +17,7 @@
62508 #include <linux/moduleparam.h>
62509 #include <linux/tracepoint.h>
62510 #include <linux/export.h>
62511 +#include <linux/fs.h>
62512
62513 #include <linux/percpu.h>
62514 #include <asm/module.h>
62515 @@ -275,19 +276,16 @@ struct module
62516 int (*init)(void);
62517
62518 /* If this is non-NULL, vfree after init() returns */
62519 - void *module_init;
62520 + void *module_init_rx, *module_init_rw;
62521
62522 /* Here is the actual code + data, vfree'd on unload. */
62523 - void *module_core;
62524 + void *module_core_rx, *module_core_rw;
62525
62526 /* Here are the sizes of the init and core sections */
62527 - unsigned int init_size, core_size;
62528 + unsigned int init_size_rw, core_size_rw;
62529
62530 /* The size of the executable code in each section. */
62531 - unsigned int init_text_size, core_text_size;
62532 -
62533 - /* Size of RO sections of the module (text+rodata) */
62534 - unsigned int init_ro_size, core_ro_size;
62535 + unsigned int init_size_rx, core_size_rx;
62536
62537 /* Arch-specific module values */
62538 struct mod_arch_specific arch;
62539 @@ -343,6 +341,10 @@ struct module
62540 #ifdef CONFIG_EVENT_TRACING
62541 struct ftrace_event_call **trace_events;
62542 unsigned int num_trace_events;
62543 + struct file_operations trace_id;
62544 + struct file_operations trace_enable;
62545 + struct file_operations trace_format;
62546 + struct file_operations trace_filter;
62547 #endif
62548 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
62549 unsigned int num_ftrace_callsites;
62550 @@ -390,16 +392,46 @@ bool is_module_address(unsigned long addr);
62551 bool is_module_percpu_address(unsigned long addr);
62552 bool is_module_text_address(unsigned long addr);
62553
62554 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
62555 +{
62556 +
62557 +#ifdef CONFIG_PAX_KERNEXEC
62558 + if (ktla_ktva(addr) >= (unsigned long)start &&
62559 + ktla_ktva(addr) < (unsigned long)start + size)
62560 + return 1;
62561 +#endif
62562 +
62563 + return ((void *)addr >= start && (void *)addr < start + size);
62564 +}
62565 +
62566 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
62567 +{
62568 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
62569 +}
62570 +
62571 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
62572 +{
62573 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
62574 +}
62575 +
62576 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
62577 +{
62578 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
62579 +}
62580 +
62581 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
62582 +{
62583 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
62584 +}
62585 +
62586 static inline int within_module_core(unsigned long addr, struct module *mod)
62587 {
62588 - return (unsigned long)mod->module_core <= addr &&
62589 - addr < (unsigned long)mod->module_core + mod->core_size;
62590 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
62591 }
62592
62593 static inline int within_module_init(unsigned long addr, struct module *mod)
62594 {
62595 - return (unsigned long)mod->module_init <= addr &&
62596 - addr < (unsigned long)mod->module_init + mod->init_size;
62597 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
62598 }
62599
62600 /* Search for module by name: must hold module_mutex. */
62601 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
62602 index b2be02e..0a61daa 100644
62603 --- a/include/linux/moduleloader.h
62604 +++ b/include/linux/moduleloader.h
62605 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
62606 sections. Returns NULL on failure. */
62607 void *module_alloc(unsigned long size);
62608
62609 +#ifdef CONFIG_PAX_KERNEXEC
62610 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
62611 +#else
62612 +#define module_alloc_exec(x) module_alloc(x)
62613 +#endif
62614 +
62615 /* Free memory returned from module_alloc. */
62616 void module_free(struct module *mod, void *module_region);
62617
62618 +#ifdef CONFIG_PAX_KERNEXEC
62619 +void module_free_exec(struct module *mod, void *module_region);
62620 +#else
62621 +#define module_free_exec(x, y) module_free((x), (y))
62622 +#endif
62623 +
62624 /* Apply the given relocation to the (simplified) ELF. Return -error
62625 or 0. */
62626 int apply_relocate(Elf_Shdr *sechdrs,
62627 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
62628 index c47f4d6..23f9bdb 100644
62629 --- a/include/linux/moduleparam.h
62630 +++ b/include/linux/moduleparam.h
62631 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
62632 * @len is usually just sizeof(string).
62633 */
62634 #define module_param_string(name, string, len, perm) \
62635 - static const struct kparam_string __param_string_##name \
62636 + static const struct kparam_string __param_string_##name __used \
62637 = { len, string }; \
62638 __module_param_call(MODULE_PARAM_PREFIX, name, \
62639 &param_ops_string, \
62640 @@ -396,7 +396,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
62641 */
62642 #define module_param_array_named(name, array, type, nump, perm) \
62643 param_check_##type(name, &(array)[0]); \
62644 - static const struct kparam_array __param_arr_##name \
62645 + static const struct kparam_array __param_arr_##name __used \
62646 = { .max = ARRAY_SIZE(array), .num = nump, \
62647 .ops = &param_ops_##type, \
62648 .elemsize = sizeof(array[0]), .elem = array }; \
62649 diff --git a/include/linux/namei.h b/include/linux/namei.h
62650 index ffc0213..2c1f2cb 100644
62651 --- a/include/linux/namei.h
62652 +++ b/include/linux/namei.h
62653 @@ -24,7 +24,7 @@ struct nameidata {
62654 unsigned seq;
62655 int last_type;
62656 unsigned depth;
62657 - char *saved_names[MAX_NESTED_LINKS + 1];
62658 + const char *saved_names[MAX_NESTED_LINKS + 1];
62659
62660 /* Intent data */
62661 union {
62662 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
62663 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
62664 extern void unlock_rename(struct dentry *, struct dentry *);
62665
62666 -static inline void nd_set_link(struct nameidata *nd, char *path)
62667 +static inline void nd_set_link(struct nameidata *nd, const char *path)
62668 {
62669 nd->saved_names[nd->depth] = path;
62670 }
62671
62672 -static inline char *nd_get_link(struct nameidata *nd)
62673 +static inline const char *nd_get_link(const struct nameidata *nd)
62674 {
62675 return nd->saved_names[nd->depth];
62676 }
62677 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
62678 index 7e472b7..212d381 100644
62679 --- a/include/linux/netdevice.h
62680 +++ b/include/linux/netdevice.h
62681 @@ -1002,6 +1002,7 @@ struct net_device_ops {
62682 int (*ndo_neigh_construct)(struct neighbour *n);
62683 void (*ndo_neigh_destroy)(struct neighbour *n);
62684 };
62685 +typedef struct net_device_ops __no_const net_device_ops_no_const;
62686
62687 /*
62688 * The DEVICE structure.
62689 @@ -1063,7 +1064,7 @@ struct net_device {
62690 int iflink;
62691
62692 struct net_device_stats stats;
62693 - atomic_long_t rx_dropped; /* dropped packets by core network
62694 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
62695 * Do not use this in drivers.
62696 */
62697
62698 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
62699 new file mode 100644
62700 index 0000000..33f4af8
62701 --- /dev/null
62702 +++ b/include/linux/netfilter/xt_gradm.h
62703 @@ -0,0 +1,9 @@
62704 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
62705 +#define _LINUX_NETFILTER_XT_GRADM_H 1
62706 +
62707 +struct xt_gradm_mtinfo {
62708 + __u16 flags;
62709 + __u16 invflags;
62710 +};
62711 +
62712 +#endif
62713 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
62714 index c65a18a..0c05f3a 100644
62715 --- a/include/linux/of_pdt.h
62716 +++ b/include/linux/of_pdt.h
62717 @@ -32,7 +32,7 @@ struct of_pdt_ops {
62718
62719 /* return 0 on success; fill in 'len' with number of bytes in path */
62720 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
62721 -};
62722 +} __no_const;
62723
62724 extern void *prom_early_alloc(unsigned long size);
62725
62726 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
62727 index a4c5624..79d6d88 100644
62728 --- a/include/linux/oprofile.h
62729 +++ b/include/linux/oprofile.h
62730 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
62731 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
62732 char const * name, ulong * val);
62733
62734 -/** Create a file for read-only access to an atomic_t. */
62735 +/** Create a file for read-only access to an atomic_unchecked_t. */
62736 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
62737 - char const * name, atomic_t * val);
62738 + char const * name, atomic_unchecked_t * val);
62739
62740 /** create a directory */
62741 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
62742 diff --git a/include/linux/padata.h b/include/linux/padata.h
62743 index 4633b2f..988bc08 100644
62744 --- a/include/linux/padata.h
62745 +++ b/include/linux/padata.h
62746 @@ -129,7 +129,7 @@ struct parallel_data {
62747 struct padata_instance *pinst;
62748 struct padata_parallel_queue __percpu *pqueue;
62749 struct padata_serial_queue __percpu *squeue;
62750 - atomic_t seq_nr;
62751 + atomic_unchecked_t seq_nr;
62752 atomic_t reorder_objects;
62753 atomic_t refcnt;
62754 unsigned int max_seq_nr;
62755 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
62756 index abb2776..d8b8e15 100644
62757 --- a/include/linux/perf_event.h
62758 +++ b/include/linux/perf_event.h
62759 @@ -750,8 +750,8 @@ struct perf_event {
62760
62761 enum perf_event_active_state state;
62762 unsigned int attach_state;
62763 - local64_t count;
62764 - atomic64_t child_count;
62765 + local64_t count; /* PaX: fix it one day */
62766 + atomic64_unchecked_t child_count;
62767
62768 /*
62769 * These are the total time in nanoseconds that the event
62770 @@ -802,8 +802,8 @@ struct perf_event {
62771 * These accumulate total time (in nanoseconds) that children
62772 * events have been enabled and running, respectively.
62773 */
62774 - atomic64_t child_total_time_enabled;
62775 - atomic64_t child_total_time_running;
62776 + atomic64_unchecked_t child_total_time_enabled;
62777 + atomic64_unchecked_t child_total_time_running;
62778
62779 /*
62780 * Protect attach/detach and child_list:
62781 diff --git a/include/linux/personality.h b/include/linux/personality.h
62782 index 8fc7dd1a..c19d89e 100644
62783 --- a/include/linux/personality.h
62784 +++ b/include/linux/personality.h
62785 @@ -44,6 +44,7 @@ enum {
62786 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
62787 ADDR_NO_RANDOMIZE | \
62788 ADDR_COMPAT_LAYOUT | \
62789 + ADDR_LIMIT_3GB | \
62790 MMAP_PAGE_ZERO)
62791
62792 /*
62793 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
62794 index 0072a53..c5dcca5 100644
62795 --- a/include/linux/pipe_fs_i.h
62796 +++ b/include/linux/pipe_fs_i.h
62797 @@ -47,9 +47,9 @@ struct pipe_buffer {
62798 struct pipe_inode_info {
62799 wait_queue_head_t wait;
62800 unsigned int nrbufs, curbuf, buffers;
62801 - unsigned int readers;
62802 - unsigned int writers;
62803 - unsigned int waiting_writers;
62804 + atomic_t readers;
62805 + atomic_t writers;
62806 + atomic_t waiting_writers;
62807 unsigned int r_counter;
62808 unsigned int w_counter;
62809 struct page *tmp_page;
62810 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
62811 index 609daae..5392427 100644
62812 --- a/include/linux/pm_runtime.h
62813 +++ b/include/linux/pm_runtime.h
62814 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
62815
62816 static inline void pm_runtime_mark_last_busy(struct device *dev)
62817 {
62818 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
62819 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
62820 }
62821
62822 #else /* !CONFIG_PM_RUNTIME */
62823 diff --git a/include/linux/poison.h b/include/linux/poison.h
62824 index 2110a81..13a11bb 100644
62825 --- a/include/linux/poison.h
62826 +++ b/include/linux/poison.h
62827 @@ -19,8 +19,8 @@
62828 * under normal circumstances, used to verify that nobody uses
62829 * non-initialized list entries.
62830 */
62831 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
62832 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
62833 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
62834 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
62835
62836 /********** include/linux/timer.h **********/
62837 /*
62838 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
62839 index 58969b2..ead129b 100644
62840 --- a/include/linux/preempt.h
62841 +++ b/include/linux/preempt.h
62842 @@ -123,7 +123,7 @@ struct preempt_ops {
62843 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
62844 void (*sched_out)(struct preempt_notifier *notifier,
62845 struct task_struct *next);
62846 -};
62847 +} __no_const;
62848
62849 /**
62850 * preempt_notifier - key for installing preemption notifiers
62851 diff --git a/include/linux/printk.h b/include/linux/printk.h
62852 index f0e22f7..82dd544 100644
62853 --- a/include/linux/printk.h
62854 +++ b/include/linux/printk.h
62855 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
62856 extern int printk_needs_cpu(int cpu);
62857 extern void printk_tick(void);
62858
62859 +extern int kptr_restrict;
62860 +
62861 #ifdef CONFIG_PRINTK
62862 asmlinkage __printf(1, 0)
62863 int vprintk(const char *fmt, va_list args);
62864 @@ -112,7 +114,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
62865
62866 extern int printk_delay_msec;
62867 extern int dmesg_restrict;
62868 -extern int kptr_restrict;
62869
62870 void log_buf_kexec_setup(void);
62871 void __init setup_log_buf(int early);
62872 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
62873 index 85c5073..51fac8b 100644
62874 --- a/include/linux/proc_fs.h
62875 +++ b/include/linux/proc_fs.h
62876 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
62877 return proc_create_data(name, mode, parent, proc_fops, NULL);
62878 }
62879
62880 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
62881 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
62882 +{
62883 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62884 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
62885 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62886 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
62887 +#else
62888 + return proc_create_data(name, mode, parent, proc_fops, NULL);
62889 +#endif
62890 +}
62891 +
62892 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
62893 umode_t mode, struct proc_dir_entry *base,
62894 read_proc_t *read_proc, void * data)
62895 @@ -258,7 +270,7 @@ union proc_op {
62896 int (*proc_show)(struct seq_file *m,
62897 struct pid_namespace *ns, struct pid *pid,
62898 struct task_struct *task);
62899 -};
62900 +} __no_const;
62901
62902 struct ctl_table_header;
62903 struct ctl_table;
62904 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
62905 index c2f1f6a..6fdb196 100644
62906 --- a/include/linux/ptrace.h
62907 +++ b/include/linux/ptrace.h
62908 @@ -199,9 +199,10 @@ static inline void ptrace_event(int event, unsigned long message)
62909 if (unlikely(ptrace_event_enabled(current, event))) {
62910 current->ptrace_message = message;
62911 ptrace_notify((event << 8) | SIGTRAP);
62912 - } else if (event == PTRACE_EVENT_EXEC && unlikely(current->ptrace)) {
62913 + } else if (event == PTRACE_EVENT_EXEC) {
62914 /* legacy EXEC report via SIGTRAP */
62915 - send_sig(SIGTRAP, current, 0);
62916 + if ((current->ptrace & (PT_PTRACED|PT_SEIZED)) == PT_PTRACED)
62917 + send_sig(SIGTRAP, current, 0);
62918 }
62919 }
62920
62921 diff --git a/include/linux/random.h b/include/linux/random.h
62922 index 8f74538..02a1012 100644
62923 --- a/include/linux/random.h
62924 +++ b/include/linux/random.h
62925 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
62926
62927 u32 prandom32(struct rnd_state *);
62928
62929 +static inline unsigned long pax_get_random_long(void)
62930 +{
62931 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
62932 +}
62933 +
62934 /*
62935 * Handle minimum values for seeds
62936 */
62937 static inline u32 __seed(u32 x, u32 m)
62938 {
62939 - return (x < m) ? x + m : x;
62940 + return (x <= m) ? x + m + 1 : x;
62941 }
62942
62943 /**
62944 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
62945 index e0879a7..a12f962 100644
62946 --- a/include/linux/reboot.h
62947 +++ b/include/linux/reboot.h
62948 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
62949 * Architecture-specific implementations of sys_reboot commands.
62950 */
62951
62952 -extern void machine_restart(char *cmd);
62953 -extern void machine_halt(void);
62954 -extern void machine_power_off(void);
62955 +extern void machine_restart(char *cmd) __noreturn;
62956 +extern void machine_halt(void) __noreturn;
62957 +extern void machine_power_off(void) __noreturn;
62958
62959 extern void machine_shutdown(void);
62960 struct pt_regs;
62961 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
62962 */
62963
62964 extern void kernel_restart_prepare(char *cmd);
62965 -extern void kernel_restart(char *cmd);
62966 -extern void kernel_halt(void);
62967 -extern void kernel_power_off(void);
62968 +extern void kernel_restart(char *cmd) __noreturn;
62969 +extern void kernel_halt(void) __noreturn;
62970 +extern void kernel_power_off(void) __noreturn;
62971
62972 extern int C_A_D; /* for sysctl */
62973 void ctrl_alt_del(void);
62974 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
62975 * Emergency restart, callable from an interrupt handler.
62976 */
62977
62978 -extern void emergency_restart(void);
62979 +extern void emergency_restart(void) __noreturn;
62980 #include <asm/emergency-restart.h>
62981
62982 #endif
62983 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
62984 index 2213ddc..650212a 100644
62985 --- a/include/linux/reiserfs_fs.h
62986 +++ b/include/linux/reiserfs_fs.h
62987 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
62988 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
62989
62990 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
62991 -#define get_generation(s) atomic_read (&fs_generation(s))
62992 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
62993 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
62994 #define __fs_changed(gen,s) (gen != get_generation (s))
62995 #define fs_changed(gen,s) \
62996 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
62997 index 8c9e85c..1698e9a 100644
62998 --- a/include/linux/reiserfs_fs_sb.h
62999 +++ b/include/linux/reiserfs_fs_sb.h
63000 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
63001 /* Comment? -Hans */
63002 wait_queue_head_t s_wait;
63003 /* To be obsoleted soon by per buffer seals.. -Hans */
63004 - atomic_t s_generation_counter; // increased by one every time the
63005 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63006 // tree gets re-balanced
63007 unsigned long s_properties; /* File system properties. Currently holds
63008 on-disk FS format */
63009 diff --git a/include/linux/relay.h b/include/linux/relay.h
63010 index a822fd7..62b70f6 100644
63011 --- a/include/linux/relay.h
63012 +++ b/include/linux/relay.h
63013 @@ -159,7 +159,7 @@ struct rchan_callbacks
63014 * The callback should return 0 if successful, negative if not.
63015 */
63016 int (*remove_buf_file)(struct dentry *dentry);
63017 -};
63018 +} __no_const;
63019
63020 /*
63021 * CONFIG_RELAY kernel API, kernel/relay.c
63022 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63023 index c6c6084..5bf1212 100644
63024 --- a/include/linux/rfkill.h
63025 +++ b/include/linux/rfkill.h
63026 @@ -147,6 +147,7 @@ struct rfkill_ops {
63027 void (*query)(struct rfkill *rfkill, void *data);
63028 int (*set_block)(void *data, bool blocked);
63029 };
63030 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63031
63032 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63033 /**
63034 diff --git a/include/linux/rio.h b/include/linux/rio.h
63035 index 4d50611..c6858a2 100644
63036 --- a/include/linux/rio.h
63037 +++ b/include/linux/rio.h
63038 @@ -315,7 +315,7 @@ struct rio_ops {
63039 int mbox, void *buffer, size_t len);
63040 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63041 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63042 -};
63043 +} __no_const;
63044
63045 #define RIO_RESOURCE_MEM 0x00000100
63046 #define RIO_RESOURCE_DOORBELL 0x00000200
63047 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63048 index 1cdd62a..e399f0d 100644
63049 --- a/include/linux/rmap.h
63050 +++ b/include/linux/rmap.h
63051 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63052 void anon_vma_init(void); /* create anon_vma_cachep */
63053 int anon_vma_prepare(struct vm_area_struct *);
63054 void unlink_anon_vmas(struct vm_area_struct *);
63055 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63056 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63057 void anon_vma_moveto_tail(struct vm_area_struct *);
63058 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63059 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63060 void __anon_vma_link(struct vm_area_struct *);
63061
63062 static inline void anon_vma_merge(struct vm_area_struct *vma,
63063 diff --git a/include/linux/sched.h b/include/linux/sched.h
63064 index 0657368..765f70f 100644
63065 --- a/include/linux/sched.h
63066 +++ b/include/linux/sched.h
63067 @@ -101,6 +101,7 @@ struct bio_list;
63068 struct fs_struct;
63069 struct perf_event_context;
63070 struct blk_plug;
63071 +struct linux_binprm;
63072
63073 /*
63074 * List of flags we want to share for kernel threads,
63075 @@ -382,10 +383,13 @@ struct user_namespace;
63076 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63077
63078 extern int sysctl_max_map_count;
63079 +extern unsigned long sysctl_heap_stack_gap;
63080
63081 #include <linux/aio.h>
63082
63083 #ifdef CONFIG_MMU
63084 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63085 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63086 extern void arch_pick_mmap_layout(struct mm_struct *mm);
63087 extern unsigned long
63088 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
63089 @@ -631,6 +635,17 @@ struct signal_struct {
63090 #ifdef CONFIG_TASKSTATS
63091 struct taskstats *stats;
63092 #endif
63093 +
63094 +#ifdef CONFIG_GRKERNSEC
63095 + u32 curr_ip;
63096 + u32 saved_ip;
63097 + u32 gr_saddr;
63098 + u32 gr_daddr;
63099 + u16 gr_sport;
63100 + u16 gr_dport;
63101 + u8 used_accept:1;
63102 +#endif
63103 +
63104 #ifdef CONFIG_AUDIT
63105 unsigned audit_tty;
63106 struct tty_audit_buf *tty_audit_buf;
63107 @@ -714,6 +729,11 @@ struct user_struct {
63108 struct key *session_keyring; /* UID's default session keyring */
63109 #endif
63110
63111 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
63112 + unsigned int banned;
63113 + unsigned long ban_expires;
63114 +#endif
63115 +
63116 /* Hash table maintenance information */
63117 struct hlist_node uidhash_node;
63118 uid_t uid;
63119 @@ -1354,8 +1374,8 @@ struct task_struct {
63120 struct list_head thread_group;
63121
63122 struct completion *vfork_done; /* for vfork() */
63123 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
63124 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63125 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
63126 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
63127
63128 cputime_t utime, stime, utimescaled, stimescaled;
63129 cputime_t gtime;
63130 @@ -1371,13 +1391,6 @@ struct task_struct {
63131 struct task_cputime cputime_expires;
63132 struct list_head cpu_timers[3];
63133
63134 -/* process credentials */
63135 - const struct cred __rcu *real_cred; /* objective and real subjective task
63136 - * credentials (COW) */
63137 - const struct cred __rcu *cred; /* effective (overridable) subjective task
63138 - * credentials (COW) */
63139 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63140 -
63141 char comm[TASK_COMM_LEN]; /* executable name excluding path
63142 - access with [gs]et_task_comm (which lock
63143 it with task_lock())
63144 @@ -1394,8 +1407,16 @@ struct task_struct {
63145 #endif
63146 /* CPU-specific state of this task */
63147 struct thread_struct thread;
63148 +/* thread_info moved to task_struct */
63149 +#ifdef CONFIG_X86
63150 + struct thread_info tinfo;
63151 +#endif
63152 /* filesystem information */
63153 struct fs_struct *fs;
63154 +
63155 + const struct cred __rcu *cred; /* effective (overridable) subjective task
63156 + * credentials (COW) */
63157 +
63158 /* open file information */
63159 struct files_struct *files;
63160 /* namespaces */
63161 @@ -1442,6 +1463,11 @@ struct task_struct {
63162 struct rt_mutex_waiter *pi_blocked_on;
63163 #endif
63164
63165 +/* process credentials */
63166 + const struct cred __rcu *real_cred; /* objective and real subjective task
63167 + * credentials (COW) */
63168 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
63169 +
63170 #ifdef CONFIG_DEBUG_MUTEXES
63171 /* mutex deadlock detection */
63172 struct mutex_waiter *blocked_on;
63173 @@ -1558,6 +1584,27 @@ struct task_struct {
63174 unsigned long default_timer_slack_ns;
63175
63176 struct list_head *scm_work_list;
63177 +
63178 +#ifdef CONFIG_GRKERNSEC
63179 + /* grsecurity */
63180 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63181 + u64 exec_id;
63182 +#endif
63183 +#ifdef CONFIG_GRKERNSEC_SETXID
63184 + const struct cred *delayed_cred;
63185 +#endif
63186 + struct dentry *gr_chroot_dentry;
63187 + struct acl_subject_label *acl;
63188 + struct acl_role_label *role;
63189 + struct file *exec_file;
63190 + u16 acl_role_id;
63191 + /* is this the task that authenticated to the special role */
63192 + u8 acl_sp_role;
63193 + u8 is_writable;
63194 + u8 brute;
63195 + u8 gr_is_chrooted;
63196 +#endif
63197 +
63198 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
63199 /* Index of current stored address in ret_stack */
63200 int curr_ret_stack;
63201 @@ -1592,6 +1639,51 @@ struct task_struct {
63202 #endif
63203 };
63204
63205 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
63206 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
63207 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
63208 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
63209 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
63210 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
63211 +
63212 +#ifdef CONFIG_PAX_SOFTMODE
63213 +extern int pax_softmode;
63214 +#endif
63215 +
63216 +extern int pax_check_flags(unsigned long *);
63217 +
63218 +/* if tsk != current then task_lock must be held on it */
63219 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63220 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
63221 +{
63222 + if (likely(tsk->mm))
63223 + return tsk->mm->pax_flags;
63224 + else
63225 + return 0UL;
63226 +}
63227 +
63228 +/* if tsk != current then task_lock must be held on it */
63229 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
63230 +{
63231 + if (likely(tsk->mm)) {
63232 + tsk->mm->pax_flags = flags;
63233 + return 0;
63234 + }
63235 + return -EINVAL;
63236 +}
63237 +#endif
63238 +
63239 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
63240 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
63241 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
63242 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
63243 +#endif
63244 +
63245 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
63246 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
63247 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
63248 +extern __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type);
63249 +
63250 /* Future-safe accessor for struct task_struct's cpus_allowed. */
63251 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
63252
63253 @@ -2104,7 +2196,9 @@ void yield(void);
63254 extern struct exec_domain default_exec_domain;
63255
63256 union thread_union {
63257 +#ifndef CONFIG_X86
63258 struct thread_info thread_info;
63259 +#endif
63260 unsigned long stack[THREAD_SIZE/sizeof(long)];
63261 };
63262
63263 @@ -2137,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
63264 */
63265
63266 extern struct task_struct *find_task_by_vpid(pid_t nr);
63267 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
63268 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
63269 struct pid_namespace *ns);
63270
63271 @@ -2280,7 +2375,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
63272 extern void exit_itimers(struct signal_struct *);
63273 extern void flush_itimer_signals(void);
63274
63275 -extern void do_group_exit(int);
63276 +extern __noreturn void do_group_exit(int);
63277
63278 extern void daemonize(const char *, ...);
63279 extern int allow_signal(int);
63280 @@ -2478,13 +2573,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
63281
63282 #endif
63283
63284 -static inline int object_is_on_stack(void *obj)
63285 +static inline int object_starts_on_stack(void *obj)
63286 {
63287 - void *stack = task_stack_page(current);
63288 + const void *stack = task_stack_page(current);
63289
63290 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
63291 }
63292
63293 +#ifdef CONFIG_PAX_USERCOPY
63294 +extern int object_is_on_stack(const void *obj, unsigned long len);
63295 +#endif
63296 +
63297 extern void thread_info_cache_init(void);
63298
63299 #ifdef CONFIG_DEBUG_STACK_USAGE
63300 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
63301 index 899fbb4..1cb4138 100644
63302 --- a/include/linux/screen_info.h
63303 +++ b/include/linux/screen_info.h
63304 @@ -43,7 +43,8 @@ struct screen_info {
63305 __u16 pages; /* 0x32 */
63306 __u16 vesa_attributes; /* 0x34 */
63307 __u32 capabilities; /* 0x36 */
63308 - __u8 _reserved[6]; /* 0x3a */
63309 + __u16 vesapm_size; /* 0x3a */
63310 + __u8 _reserved[4]; /* 0x3c */
63311 } __attribute__((packed));
63312
63313 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
63314 diff --git a/include/linux/security.h b/include/linux/security.h
63315 index 83c18e8..2d98860 100644
63316 --- a/include/linux/security.h
63317 +++ b/include/linux/security.h
63318 @@ -37,6 +37,7 @@
63319 #include <linux/xfrm.h>
63320 #include <linux/slab.h>
63321 #include <linux/xattr.h>
63322 +#include <linux/grsecurity.h>
63323 #include <net/flow.h>
63324
63325 /* Maximum number of letters for an LSM name string */
63326 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
63327 index 44f1514..2bbf6c1 100644
63328 --- a/include/linux/seq_file.h
63329 +++ b/include/linux/seq_file.h
63330 @@ -24,6 +24,9 @@ struct seq_file {
63331 struct mutex lock;
63332 const struct seq_operations *op;
63333 int poll_event;
63334 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63335 + u64 exec_id;
63336 +#endif
63337 void *private;
63338 };
63339
63340 @@ -33,6 +36,7 @@ struct seq_operations {
63341 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
63342 int (*show) (struct seq_file *m, void *v);
63343 };
63344 +typedef struct seq_operations __no_const seq_operations_no_const;
63345
63346 #define SEQ_SKIP 1
63347
63348 diff --git a/include/linux/shm.h b/include/linux/shm.h
63349 index 92808b8..c28cac4 100644
63350 --- a/include/linux/shm.h
63351 +++ b/include/linux/shm.h
63352 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
63353
63354 /* The task created the shm object. NULL if the task is dead. */
63355 struct task_struct *shm_creator;
63356 +#ifdef CONFIG_GRKERNSEC
63357 + time_t shm_createtime;
63358 + pid_t shm_lapid;
63359 +#endif
63360 };
63361
63362 /* shm_mode upper byte flags */
63363 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
63364 index 42854ce..3b7d3c8 100644
63365 --- a/include/linux/skbuff.h
63366 +++ b/include/linux/skbuff.h
63367 @@ -655,7 +655,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
63368 */
63369 static inline int skb_queue_empty(const struct sk_buff_head *list)
63370 {
63371 - return list->next == (struct sk_buff *)list;
63372 + return list->next == (const struct sk_buff *)list;
63373 }
63374
63375 /**
63376 @@ -668,7 +668,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
63377 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63378 const struct sk_buff *skb)
63379 {
63380 - return skb->next == (struct sk_buff *)list;
63381 + return skb->next == (const struct sk_buff *)list;
63382 }
63383
63384 /**
63385 @@ -681,7 +681,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
63386 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
63387 const struct sk_buff *skb)
63388 {
63389 - return skb->prev == (struct sk_buff *)list;
63390 + return skb->prev == (const struct sk_buff *)list;
63391 }
63392
63393 /**
63394 @@ -1558,7 +1558,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
63395 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
63396 */
63397 #ifndef NET_SKB_PAD
63398 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
63399 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
63400 #endif
63401
63402 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
63403 diff --git a/include/linux/slab.h b/include/linux/slab.h
63404 index 573c809..eaaf6ea 100644
63405 --- a/include/linux/slab.h
63406 +++ b/include/linux/slab.h
63407 @@ -11,12 +11,20 @@
63408
63409 #include <linux/gfp.h>
63410 #include <linux/types.h>
63411 +#include <linux/err.h>
63412
63413 /*
63414 * Flags to pass to kmem_cache_create().
63415 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
63416 */
63417 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
63418 +
63419 +#ifdef CONFIG_PAX_USERCOPY
63420 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
63421 +#else
63422 +#define SLAB_USERCOPY 0x00000000UL
63423 +#endif
63424 +
63425 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
63426 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
63427 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
63428 @@ -87,10 +95,13 @@
63429 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
63430 * Both make kfree a no-op.
63431 */
63432 -#define ZERO_SIZE_PTR ((void *)16)
63433 +#define ZERO_SIZE_PTR \
63434 +({ \
63435 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
63436 + (void *)(-MAX_ERRNO-1L); \
63437 +})
63438
63439 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
63440 - (unsigned long)ZERO_SIZE_PTR)
63441 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
63442
63443 /*
63444 * struct kmem_cache related prototypes
63445 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
63446 void kfree(const void *);
63447 void kzfree(const void *);
63448 size_t ksize(const void *);
63449 +void check_object_size(const void *ptr, unsigned long n, bool to);
63450
63451 /*
63452 * Allocator specific definitions. These are mainly used to establish optimized
63453 @@ -287,7 +299,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
63454 */
63455 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63456 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63457 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63458 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
63459 #define kmalloc_track_caller(size, flags) \
63460 __kmalloc_track_caller(size, flags, _RET_IP_)
63461 #else
63462 @@ -306,7 +318,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
63463 */
63464 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
63465 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
63466 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
63467 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
63468 #define kmalloc_node_track_caller(size, flags, node) \
63469 __kmalloc_node_track_caller(size, flags, node, \
63470 _RET_IP_)
63471 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
63472 index fbd1117..d4d8ef8 100644
63473 --- a/include/linux/slab_def.h
63474 +++ b/include/linux/slab_def.h
63475 @@ -66,10 +66,10 @@ struct kmem_cache {
63476 unsigned long node_allocs;
63477 unsigned long node_frees;
63478 unsigned long node_overflow;
63479 - atomic_t allochit;
63480 - atomic_t allocmiss;
63481 - atomic_t freehit;
63482 - atomic_t freemiss;
63483 + atomic_unchecked_t allochit;
63484 + atomic_unchecked_t allocmiss;
63485 + atomic_unchecked_t freehit;
63486 + atomic_unchecked_t freemiss;
63487
63488 /*
63489 * If debugging is enabled, then the allocator can add additional
63490 @@ -107,7 +107,7 @@ struct cache_sizes {
63491 extern struct cache_sizes malloc_sizes[];
63492
63493 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63494 -void *__kmalloc(size_t size, gfp_t flags);
63495 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63496
63497 #ifdef CONFIG_TRACING
63498 extern void *kmem_cache_alloc_trace(size_t size,
63499 @@ -160,7 +160,7 @@ found:
63500 }
63501
63502 #ifdef CONFIG_NUMA
63503 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
63504 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63505 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63506
63507 #ifdef CONFIG_TRACING
63508 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
63509 index 0ec00b3..39cb7fc 100644
63510 --- a/include/linux/slob_def.h
63511 +++ b/include/linux/slob_def.h
63512 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
63513 return kmem_cache_alloc_node(cachep, flags, -1);
63514 }
63515
63516 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63517 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63518
63519 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
63520 {
63521 @@ -29,6 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63522 return __kmalloc_node(size, flags, -1);
63523 }
63524
63525 +static __always_inline void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
63526 static __always_inline void *__kmalloc(size_t size, gfp_t flags)
63527 {
63528 return kmalloc(size, flags);
63529 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
63530 index a32bcfd..a80ed70 100644
63531 --- a/include/linux/slub_def.h
63532 +++ b/include/linux/slub_def.h
63533 @@ -89,7 +89,7 @@ struct kmem_cache {
63534 struct kmem_cache_order_objects max;
63535 struct kmem_cache_order_objects min;
63536 gfp_t allocflags; /* gfp flags to use on each alloc */
63537 - int refcount; /* Refcount for slab cache destroy */
63538 + atomic_t refcount; /* Refcount for slab cache destroy */
63539 void (*ctor)(void *);
63540 int inuse; /* Offset to metadata */
63541 int align; /* Alignment */
63542 @@ -150,6 +150,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
63543 * Sorry that the following has to be that ugly but some versions of GCC
63544 * have trouble with constant propagation and loops.
63545 */
63546 +static __always_inline int kmalloc_index(size_t size) __size_overflow(1);
63547 static __always_inline int kmalloc_index(size_t size)
63548 {
63549 if (!size)
63550 @@ -215,7 +216,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
63551 }
63552
63553 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
63554 -void *__kmalloc(size_t size, gfp_t flags);
63555 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
63556
63557 static __always_inline void *
63558 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
63559 @@ -256,6 +257,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
63560 }
63561 #endif
63562
63563 +static __always_inline void *kmalloc_large(size_t size, gfp_t flags) __size_overflow(1);
63564 static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
63565 {
63566 unsigned int order = get_order(size);
63567 @@ -281,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
63568 }
63569
63570 #ifdef CONFIG_NUMA
63571 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
63572 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
63573 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
63574
63575 #ifdef CONFIG_TRACING
63576 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
63577 index de8832d..0147b46 100644
63578 --- a/include/linux/sonet.h
63579 +++ b/include/linux/sonet.h
63580 @@ -61,7 +61,7 @@ struct sonet_stats {
63581 #include <linux/atomic.h>
63582
63583 struct k_sonet_stats {
63584 -#define __HANDLE_ITEM(i) atomic_t i
63585 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63586 __SONET_ITEMS
63587 #undef __HANDLE_ITEM
63588 };
63589 diff --git a/include/linux/stddef.h b/include/linux/stddef.h
63590 index 6a40c76..1747b67 100644
63591 --- a/include/linux/stddef.h
63592 +++ b/include/linux/stddef.h
63593 @@ -3,14 +3,10 @@
63594
63595 #include <linux/compiler.h>
63596
63597 +#ifdef __KERNEL__
63598 +
63599 #undef NULL
63600 -#if defined(__cplusplus)
63601 -#define NULL 0
63602 -#else
63603 #define NULL ((void *)0)
63604 -#endif
63605 -
63606 -#ifdef __KERNEL__
63607
63608 enum {
63609 false = 0,
63610 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
63611 index 2c5993a..b0e79f0 100644
63612 --- a/include/linux/sunrpc/clnt.h
63613 +++ b/include/linux/sunrpc/clnt.h
63614 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
63615 {
63616 switch (sap->sa_family) {
63617 case AF_INET:
63618 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
63619 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
63620 case AF_INET6:
63621 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
63622 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
63623 }
63624 return 0;
63625 }
63626 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
63627 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
63628 const struct sockaddr *src)
63629 {
63630 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
63631 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
63632 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
63633
63634 dsin->sin_family = ssin->sin_family;
63635 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
63636 if (sa->sa_family != AF_INET6)
63637 return 0;
63638
63639 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
63640 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
63641 }
63642
63643 #endif /* __KERNEL__ */
63644 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
63645 index e775689..9e206d9 100644
63646 --- a/include/linux/sunrpc/sched.h
63647 +++ b/include/linux/sunrpc/sched.h
63648 @@ -105,6 +105,7 @@ struct rpc_call_ops {
63649 void (*rpc_call_done)(struct rpc_task *, void *);
63650 void (*rpc_release)(void *);
63651 };
63652 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
63653
63654 struct rpc_task_setup {
63655 struct rpc_task *task;
63656 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
63657 index c14fe86..393245e 100644
63658 --- a/include/linux/sunrpc/svc_rdma.h
63659 +++ b/include/linux/sunrpc/svc_rdma.h
63660 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
63661 extern unsigned int svcrdma_max_requests;
63662 extern unsigned int svcrdma_max_req_size;
63663
63664 -extern atomic_t rdma_stat_recv;
63665 -extern atomic_t rdma_stat_read;
63666 -extern atomic_t rdma_stat_write;
63667 -extern atomic_t rdma_stat_sq_starve;
63668 -extern atomic_t rdma_stat_rq_starve;
63669 -extern atomic_t rdma_stat_rq_poll;
63670 -extern atomic_t rdma_stat_rq_prod;
63671 -extern atomic_t rdma_stat_sq_poll;
63672 -extern atomic_t rdma_stat_sq_prod;
63673 +extern atomic_unchecked_t rdma_stat_recv;
63674 +extern atomic_unchecked_t rdma_stat_read;
63675 +extern atomic_unchecked_t rdma_stat_write;
63676 +extern atomic_unchecked_t rdma_stat_sq_starve;
63677 +extern atomic_unchecked_t rdma_stat_rq_starve;
63678 +extern atomic_unchecked_t rdma_stat_rq_poll;
63679 +extern atomic_unchecked_t rdma_stat_rq_prod;
63680 +extern atomic_unchecked_t rdma_stat_sq_poll;
63681 +extern atomic_unchecked_t rdma_stat_sq_prod;
63682
63683 #define RPCRDMA_VERSION 1
63684
63685 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
63686 index bb9127d..34ab358 100644
63687 --- a/include/linux/sysctl.h
63688 +++ b/include/linux/sysctl.h
63689 @@ -155,7 +155,11 @@ enum
63690 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
63691 };
63692
63693 -
63694 +#ifdef CONFIG_PAX_SOFTMODE
63695 +enum {
63696 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
63697 +};
63698 +#endif
63699
63700 /* CTL_VM names: */
63701 enum
63702 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
63703
63704 extern int proc_dostring(struct ctl_table *, int,
63705 void __user *, size_t *, loff_t *);
63706 +extern int proc_dostring_modpriv(struct ctl_table *, int,
63707 + void __user *, size_t *, loff_t *);
63708 extern int proc_dointvec(struct ctl_table *, int,
63709 void __user *, size_t *, loff_t *);
63710 extern int proc_dointvec_minmax(struct ctl_table *, int,
63711 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
63712 index a71a292..51bd91d 100644
63713 --- a/include/linux/tracehook.h
63714 +++ b/include/linux/tracehook.h
63715 @@ -54,12 +54,12 @@ struct linux_binprm;
63716 /*
63717 * ptrace report for syscall entry and exit looks identical.
63718 */
63719 -static inline void ptrace_report_syscall(struct pt_regs *regs)
63720 +static inline int ptrace_report_syscall(struct pt_regs *regs)
63721 {
63722 int ptrace = current->ptrace;
63723
63724 if (!(ptrace & PT_PTRACED))
63725 - return;
63726 + return 0;
63727
63728 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
63729
63730 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63731 send_sig(current->exit_code, current, 1);
63732 current->exit_code = 0;
63733 }
63734 +
63735 + return fatal_signal_pending(current);
63736 }
63737
63738 /**
63739 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
63740 static inline __must_check int tracehook_report_syscall_entry(
63741 struct pt_regs *regs)
63742 {
63743 - ptrace_report_syscall(regs);
63744 - return 0;
63745 + return ptrace_report_syscall(regs);
63746 }
63747
63748 /**
63749 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
63750 index ff7dc08..893e1bd 100644
63751 --- a/include/linux/tty_ldisc.h
63752 +++ b/include/linux/tty_ldisc.h
63753 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
63754
63755 struct module *owner;
63756
63757 - int refcount;
63758 + atomic_t refcount;
63759 };
63760
63761 struct tty_ldisc {
63762 diff --git a/include/linux/types.h b/include/linux/types.h
63763 index e5fa503..df6e8a4 100644
63764 --- a/include/linux/types.h
63765 +++ b/include/linux/types.h
63766 @@ -214,10 +214,26 @@ typedef struct {
63767 int counter;
63768 } atomic_t;
63769
63770 +#ifdef CONFIG_PAX_REFCOUNT
63771 +typedef struct {
63772 + int counter;
63773 +} atomic_unchecked_t;
63774 +#else
63775 +typedef atomic_t atomic_unchecked_t;
63776 +#endif
63777 +
63778 #ifdef CONFIG_64BIT
63779 typedef struct {
63780 long counter;
63781 } atomic64_t;
63782 +
63783 +#ifdef CONFIG_PAX_REFCOUNT
63784 +typedef struct {
63785 + long counter;
63786 +} atomic64_unchecked_t;
63787 +#else
63788 +typedef atomic64_t atomic64_unchecked_t;
63789 +#endif
63790 #endif
63791
63792 struct list_head {
63793 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
63794 index 5ca0951..ab496a5 100644
63795 --- a/include/linux/uaccess.h
63796 +++ b/include/linux/uaccess.h
63797 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
63798 long ret; \
63799 mm_segment_t old_fs = get_fs(); \
63800 \
63801 - set_fs(KERNEL_DS); \
63802 pagefault_disable(); \
63803 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
63804 - pagefault_enable(); \
63805 + set_fs(KERNEL_DS); \
63806 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
63807 set_fs(old_fs); \
63808 + pagefault_enable(); \
63809 ret; \
63810 })
63811
63812 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
63813 index 99c1b4d..bb94261 100644
63814 --- a/include/linux/unaligned/access_ok.h
63815 +++ b/include/linux/unaligned/access_ok.h
63816 @@ -6,32 +6,32 @@
63817
63818 static inline u16 get_unaligned_le16(const void *p)
63819 {
63820 - return le16_to_cpup((__le16 *)p);
63821 + return le16_to_cpup((const __le16 *)p);
63822 }
63823
63824 static inline u32 get_unaligned_le32(const void *p)
63825 {
63826 - return le32_to_cpup((__le32 *)p);
63827 + return le32_to_cpup((const __le32 *)p);
63828 }
63829
63830 static inline u64 get_unaligned_le64(const void *p)
63831 {
63832 - return le64_to_cpup((__le64 *)p);
63833 + return le64_to_cpup((const __le64 *)p);
63834 }
63835
63836 static inline u16 get_unaligned_be16(const void *p)
63837 {
63838 - return be16_to_cpup((__be16 *)p);
63839 + return be16_to_cpup((const __be16 *)p);
63840 }
63841
63842 static inline u32 get_unaligned_be32(const void *p)
63843 {
63844 - return be32_to_cpup((__be32 *)p);
63845 + return be32_to_cpup((const __be32 *)p);
63846 }
63847
63848 static inline u64 get_unaligned_be64(const void *p)
63849 {
63850 - return be64_to_cpup((__be64 *)p);
63851 + return be64_to_cpup((const __be64 *)p);
63852 }
63853
63854 static inline void put_unaligned_le16(u16 val, void *p)
63855 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
63856 index 0d3f988..000f101 100644
63857 --- a/include/linux/usb/renesas_usbhs.h
63858 +++ b/include/linux/usb/renesas_usbhs.h
63859 @@ -39,7 +39,7 @@ enum {
63860 */
63861 struct renesas_usbhs_driver_callback {
63862 int (*notify_hotplug)(struct platform_device *pdev);
63863 -};
63864 +} __no_const;
63865
63866 /*
63867 * callback functions for platform
63868 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
63869 * VBUS control is needed for Host
63870 */
63871 int (*set_vbus)(struct platform_device *pdev, int enable);
63872 -};
63873 +} __no_const;
63874
63875 /*
63876 * parameters for renesas usbhs
63877 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
63878 index 6f8fbcf..8259001 100644
63879 --- a/include/linux/vermagic.h
63880 +++ b/include/linux/vermagic.h
63881 @@ -25,9 +25,35 @@
63882 #define MODULE_ARCH_VERMAGIC ""
63883 #endif
63884
63885 +#ifdef CONFIG_PAX_REFCOUNT
63886 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
63887 +#else
63888 +#define MODULE_PAX_REFCOUNT ""
63889 +#endif
63890 +
63891 +#ifdef CONSTIFY_PLUGIN
63892 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
63893 +#else
63894 +#define MODULE_CONSTIFY_PLUGIN ""
63895 +#endif
63896 +
63897 +#ifdef STACKLEAK_PLUGIN
63898 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
63899 +#else
63900 +#define MODULE_STACKLEAK_PLUGIN ""
63901 +#endif
63902 +
63903 +#ifdef CONFIG_GRKERNSEC
63904 +#define MODULE_GRSEC "GRSEC "
63905 +#else
63906 +#define MODULE_GRSEC ""
63907 +#endif
63908 +
63909 #define VERMAGIC_STRING \
63910 UTS_RELEASE " " \
63911 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
63912 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
63913 - MODULE_ARCH_VERMAGIC
63914 + MODULE_ARCH_VERMAGIC \
63915 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
63916 + MODULE_GRSEC
63917
63918 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
63919 index dcdfc2b..ec79ab5 100644
63920 --- a/include/linux/vmalloc.h
63921 +++ b/include/linux/vmalloc.h
63922 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
63923 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
63924 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
63925 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
63926 +
63927 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
63928 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
63929 +#endif
63930 +
63931 /* bits [20..32] reserved for arch specific ioremap internals */
63932
63933 /*
63934 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
63935 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
63936 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
63937 unsigned long start, unsigned long end, gfp_t gfp_mask,
63938 - pgprot_t prot, int node, void *caller);
63939 + pgprot_t prot, int node, void *caller) __size_overflow(1);
63940 extern void vfree(const void *addr);
63941
63942 extern void *vmap(struct page **pages, unsigned int count,
63943 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
63944 extern void free_vm_area(struct vm_struct *area);
63945
63946 /* for /dev/kmem */
63947 -extern long vread(char *buf, char *addr, unsigned long count);
63948 -extern long vwrite(char *buf, char *addr, unsigned long count);
63949 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
63950 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
63951
63952 /*
63953 * Internals. Dont't use..
63954 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
63955 index 65efb92..137adbb 100644
63956 --- a/include/linux/vmstat.h
63957 +++ b/include/linux/vmstat.h
63958 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
63959 /*
63960 * Zone based page accounting with per cpu differentials.
63961 */
63962 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63963 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63964
63965 static inline void zone_page_state_add(long x, struct zone *zone,
63966 enum zone_stat_item item)
63967 {
63968 - atomic_long_add(x, &zone->vm_stat[item]);
63969 - atomic_long_add(x, &vm_stat[item]);
63970 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
63971 + atomic_long_add_unchecked(x, &vm_stat[item]);
63972 }
63973
63974 static inline unsigned long global_page_state(enum zone_stat_item item)
63975 {
63976 - long x = atomic_long_read(&vm_stat[item]);
63977 + long x = atomic_long_read_unchecked(&vm_stat[item]);
63978 #ifdef CONFIG_SMP
63979 if (x < 0)
63980 x = 0;
63981 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
63982 static inline unsigned long zone_page_state(struct zone *zone,
63983 enum zone_stat_item item)
63984 {
63985 - long x = atomic_long_read(&zone->vm_stat[item]);
63986 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63987 #ifdef CONFIG_SMP
63988 if (x < 0)
63989 x = 0;
63990 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
63991 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
63992 enum zone_stat_item item)
63993 {
63994 - long x = atomic_long_read(&zone->vm_stat[item]);
63995 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
63996
63997 #ifdef CONFIG_SMP
63998 int cpu;
63999 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64000
64001 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64002 {
64003 - atomic_long_inc(&zone->vm_stat[item]);
64004 - atomic_long_inc(&vm_stat[item]);
64005 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64006 + atomic_long_inc_unchecked(&vm_stat[item]);
64007 }
64008
64009 static inline void __inc_zone_page_state(struct page *page,
64010 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
64011
64012 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64013 {
64014 - atomic_long_dec(&zone->vm_stat[item]);
64015 - atomic_long_dec(&vm_stat[item]);
64016 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64017 + atomic_long_dec_unchecked(&vm_stat[item]);
64018 }
64019
64020 static inline void __dec_zone_page_state(struct page *page,
64021 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64022 index e5d1220..ef6e406 100644
64023 --- a/include/linux/xattr.h
64024 +++ b/include/linux/xattr.h
64025 @@ -57,6 +57,11 @@
64026 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64027 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64028
64029 +/* User namespace */
64030 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64031 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64032 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64033 +
64034 #ifdef __KERNEL__
64035
64036 #include <linux/types.h>
64037 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64038 index 4aeff96..b378cdc 100644
64039 --- a/include/media/saa7146_vv.h
64040 +++ b/include/media/saa7146_vv.h
64041 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
64042 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64043
64044 /* the extension can override this */
64045 - struct v4l2_ioctl_ops ops;
64046 + v4l2_ioctl_ops_no_const ops;
64047 /* pointer to the saa7146 core ops */
64048 const struct v4l2_ioctl_ops *core_ops;
64049
64050 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64051 index c7c40f1..4f01585 100644
64052 --- a/include/media/v4l2-dev.h
64053 +++ b/include/media/v4l2-dev.h
64054 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
64055
64056
64057 struct v4l2_file_operations {
64058 - struct module *owner;
64059 + struct module * const owner;
64060 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
64061 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
64062 unsigned int (*poll) (struct file *, struct poll_table_struct *);
64063 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
64064 int (*open) (struct file *);
64065 int (*release) (struct file *);
64066 };
64067 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64068
64069 /*
64070 * Newer version of video_device, handled by videodev2.c
64071 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64072 index 3f5d60f..44210ed 100644
64073 --- a/include/media/v4l2-ioctl.h
64074 +++ b/include/media/v4l2-ioctl.h
64075 @@ -278,7 +278,7 @@ struct v4l2_ioctl_ops {
64076 long (*vidioc_default) (struct file *file, void *fh,
64077 bool valid_prio, int cmd, void *arg);
64078 };
64079 -
64080 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
64081
64082 /* v4l debugging and diagnostics */
64083
64084 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
64085 index 8d55251..dfe5b0a 100644
64086 --- a/include/net/caif/caif_hsi.h
64087 +++ b/include/net/caif/caif_hsi.h
64088 @@ -98,7 +98,7 @@ struct cfhsi_drv {
64089 void (*rx_done_cb) (struct cfhsi_drv *drv);
64090 void (*wake_up_cb) (struct cfhsi_drv *drv);
64091 void (*wake_down_cb) (struct cfhsi_drv *drv);
64092 -};
64093 +} __no_const;
64094
64095 /* Structure implemented by HSI device. */
64096 struct cfhsi_dev {
64097 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
64098 index 9e5425b..8136ffc 100644
64099 --- a/include/net/caif/cfctrl.h
64100 +++ b/include/net/caif/cfctrl.h
64101 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
64102 void (*radioset_rsp)(void);
64103 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
64104 struct cflayer *client_layer);
64105 -};
64106 +} __no_const;
64107
64108 /* Link Setup Parameters for CAIF-Links. */
64109 struct cfctrl_link_param {
64110 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
64111 struct cfctrl {
64112 struct cfsrvl serv;
64113 struct cfctrl_rsp res;
64114 - atomic_t req_seq_no;
64115 - atomic_t rsp_seq_no;
64116 + atomic_unchecked_t req_seq_no;
64117 + atomic_unchecked_t rsp_seq_no;
64118 struct list_head list;
64119 /* Protects from simultaneous access to first_req list */
64120 spinlock_t info_list_lock;
64121 diff --git a/include/net/flow.h b/include/net/flow.h
64122 index 6c469db..7743b8e 100644
64123 --- a/include/net/flow.h
64124 +++ b/include/net/flow.h
64125 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
64126
64127 extern void flow_cache_flush(void);
64128 extern void flow_cache_flush_deferred(void);
64129 -extern atomic_t flow_cache_genid;
64130 +extern atomic_unchecked_t flow_cache_genid;
64131
64132 #endif
64133 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
64134 index b94765e..053f68b 100644
64135 --- a/include/net/inetpeer.h
64136 +++ b/include/net/inetpeer.h
64137 @@ -48,8 +48,8 @@ struct inet_peer {
64138 */
64139 union {
64140 struct {
64141 - atomic_t rid; /* Frag reception counter */
64142 - atomic_t ip_id_count; /* IP ID for the next packet */
64143 + atomic_unchecked_t rid; /* Frag reception counter */
64144 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
64145 __u32 tcp_ts;
64146 __u32 tcp_ts_stamp;
64147 };
64148 @@ -115,11 +115,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
64149 more++;
64150 inet_peer_refcheck(p);
64151 do {
64152 - old = atomic_read(&p->ip_id_count);
64153 + old = atomic_read_unchecked(&p->ip_id_count);
64154 new = old + more;
64155 if (!new)
64156 new = 1;
64157 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
64158 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
64159 return new;
64160 }
64161
64162 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
64163 index 10422ef..662570f 100644
64164 --- a/include/net/ip_fib.h
64165 +++ b/include/net/ip_fib.h
64166 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
64167
64168 #define FIB_RES_SADDR(net, res) \
64169 ((FIB_RES_NH(res).nh_saddr_genid == \
64170 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
64171 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
64172 FIB_RES_NH(res).nh_saddr : \
64173 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
64174 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
64175 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
64176 index ebe517f..1bd286b 100644
64177 --- a/include/net/ip_vs.h
64178 +++ b/include/net/ip_vs.h
64179 @@ -509,7 +509,7 @@ struct ip_vs_conn {
64180 struct ip_vs_conn *control; /* Master control connection */
64181 atomic_t n_control; /* Number of controlled ones */
64182 struct ip_vs_dest *dest; /* real server */
64183 - atomic_t in_pkts; /* incoming packet counter */
64184 + atomic_unchecked_t in_pkts; /* incoming packet counter */
64185
64186 /* packet transmitter for different forwarding methods. If it
64187 mangles the packet, it must return NF_DROP or better NF_STOLEN,
64188 @@ -647,7 +647,7 @@ struct ip_vs_dest {
64189 __be16 port; /* port number of the server */
64190 union nf_inet_addr addr; /* IP address of the server */
64191 volatile unsigned flags; /* dest status flags */
64192 - atomic_t conn_flags; /* flags to copy to conn */
64193 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
64194 atomic_t weight; /* server weight */
64195
64196 atomic_t refcnt; /* reference counter */
64197 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
64198 index 69b610a..fe3962c 100644
64199 --- a/include/net/irda/ircomm_core.h
64200 +++ b/include/net/irda/ircomm_core.h
64201 @@ -51,7 +51,7 @@ typedef struct {
64202 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
64203 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
64204 struct ircomm_info *);
64205 -} call_t;
64206 +} __no_const call_t;
64207
64208 struct ircomm_cb {
64209 irda_queue_t queue;
64210 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
64211 index 59ba38bc..d515662 100644
64212 --- a/include/net/irda/ircomm_tty.h
64213 +++ b/include/net/irda/ircomm_tty.h
64214 @@ -35,6 +35,7 @@
64215 #include <linux/termios.h>
64216 #include <linux/timer.h>
64217 #include <linux/tty.h> /* struct tty_struct */
64218 +#include <asm/local.h>
64219
64220 #include <net/irda/irias_object.h>
64221 #include <net/irda/ircomm_core.h>
64222 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
64223 unsigned short close_delay;
64224 unsigned short closing_wait; /* time to wait before closing */
64225
64226 - int open_count;
64227 - int blocked_open; /* # of blocked opens */
64228 + local_t open_count;
64229 + local_t blocked_open; /* # of blocked opens */
64230
64231 /* Protect concurent access to :
64232 * o self->open_count
64233 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
64234 index 0954ec9..7413562 100644
64235 --- a/include/net/iucv/af_iucv.h
64236 +++ b/include/net/iucv/af_iucv.h
64237 @@ -138,7 +138,7 @@ struct iucv_sock {
64238 struct iucv_sock_list {
64239 struct hlist_head head;
64240 rwlock_t lock;
64241 - atomic_t autobind_name;
64242 + atomic_unchecked_t autobind_name;
64243 };
64244
64245 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
64246 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
64247 index 34c996f..bb3b4d4 100644
64248 --- a/include/net/neighbour.h
64249 +++ b/include/net/neighbour.h
64250 @@ -123,7 +123,7 @@ struct neigh_ops {
64251 void (*error_report)(struct neighbour *, struct sk_buff *);
64252 int (*output)(struct neighbour *, struct sk_buff *);
64253 int (*connected_output)(struct neighbour *, struct sk_buff *);
64254 -};
64255 +} __do_const;
64256
64257 struct pneigh_entry {
64258 struct pneigh_entry *next;
64259 diff --git a/include/net/netlink.h b/include/net/netlink.h
64260 index cb1f350..3279d2c 100644
64261 --- a/include/net/netlink.h
64262 +++ b/include/net/netlink.h
64263 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
64264 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
64265 {
64266 if (mark)
64267 - skb_trim(skb, (unsigned char *) mark - skb->data);
64268 + skb_trim(skb, (const unsigned char *) mark - skb->data);
64269 }
64270
64271 /**
64272 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
64273 index bbd023a..97c6d0d 100644
64274 --- a/include/net/netns/ipv4.h
64275 +++ b/include/net/netns/ipv4.h
64276 @@ -57,8 +57,8 @@ struct netns_ipv4 {
64277 unsigned int sysctl_ping_group_range[2];
64278 long sysctl_tcp_mem[3];
64279
64280 - atomic_t rt_genid;
64281 - atomic_t dev_addr_genid;
64282 + atomic_unchecked_t rt_genid;
64283 + atomic_unchecked_t dev_addr_genid;
64284
64285 #ifdef CONFIG_IP_MROUTE
64286 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
64287 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
64288 index d368561..96aaa17 100644
64289 --- a/include/net/sctp/sctp.h
64290 +++ b/include/net/sctp/sctp.h
64291 @@ -318,9 +318,9 @@ do { \
64292
64293 #else /* SCTP_DEBUG */
64294
64295 -#define SCTP_DEBUG_PRINTK(whatever...)
64296 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
64297 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
64298 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
64299 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
64300 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
64301 #define SCTP_ENABLE_DEBUG
64302 #define SCTP_DISABLE_DEBUG
64303 #define SCTP_ASSERT(expr, str, func)
64304 diff --git a/include/net/sock.h b/include/net/sock.h
64305 index 91c1c8b..15ae923 100644
64306 --- a/include/net/sock.h
64307 +++ b/include/net/sock.h
64308 @@ -299,7 +299,7 @@ struct sock {
64309 #ifdef CONFIG_RPS
64310 __u32 sk_rxhash;
64311 #endif
64312 - atomic_t sk_drops;
64313 + atomic_unchecked_t sk_drops;
64314 int sk_rcvbuf;
64315
64316 struct sk_filter __rcu *sk_filter;
64317 @@ -1660,7 +1660,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
64318 }
64319
64320 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
64321 - char __user *from, char *to,
64322 + char __user *from, unsigned char *to,
64323 int copy, int offset)
64324 {
64325 if (skb->ip_summed == CHECKSUM_NONE) {
64326 diff --git a/include/net/tcp.h b/include/net/tcp.h
64327 index 2d80c29..aa07caf 100644
64328 --- a/include/net/tcp.h
64329 +++ b/include/net/tcp.h
64330 @@ -1426,7 +1426,7 @@ struct tcp_seq_afinfo {
64331 char *name;
64332 sa_family_t family;
64333 const struct file_operations *seq_fops;
64334 - struct seq_operations seq_ops;
64335 + seq_operations_no_const seq_ops;
64336 };
64337
64338 struct tcp_iter_state {
64339 diff --git a/include/net/udp.h b/include/net/udp.h
64340 index e39592f..fef9680 100644
64341 --- a/include/net/udp.h
64342 +++ b/include/net/udp.h
64343 @@ -243,7 +243,7 @@ struct udp_seq_afinfo {
64344 sa_family_t family;
64345 struct udp_table *udp_table;
64346 const struct file_operations *seq_fops;
64347 - struct seq_operations seq_ops;
64348 + seq_operations_no_const seq_ops;
64349 };
64350
64351 struct udp_iter_state {
64352 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
64353 index 89174e2..1f82598 100644
64354 --- a/include/net/xfrm.h
64355 +++ b/include/net/xfrm.h
64356 @@ -505,7 +505,7 @@ struct xfrm_policy {
64357 struct timer_list timer;
64358
64359 struct flow_cache_object flo;
64360 - atomic_t genid;
64361 + atomic_unchecked_t genid;
64362 u32 priority;
64363 u32 index;
64364 struct xfrm_mark mark;
64365 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
64366 index 1a046b1..ee0bef0 100644
64367 --- a/include/rdma/iw_cm.h
64368 +++ b/include/rdma/iw_cm.h
64369 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
64370 int backlog);
64371
64372 int (*destroy_listen)(struct iw_cm_id *cm_id);
64373 -};
64374 +} __no_const;
64375
64376 /**
64377 * iw_create_cm_id - Create an IW CM identifier.
64378 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
64379 index 6a3922f..0b73022 100644
64380 --- a/include/scsi/libfc.h
64381 +++ b/include/scsi/libfc.h
64382 @@ -748,6 +748,7 @@ struct libfc_function_template {
64383 */
64384 void (*disc_stop_final) (struct fc_lport *);
64385 };
64386 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
64387
64388 /**
64389 * struct fc_disc - Discovery context
64390 @@ -851,7 +852,7 @@ struct fc_lport {
64391 struct fc_vport *vport;
64392
64393 /* Operational Information */
64394 - struct libfc_function_template tt;
64395 + libfc_function_template_no_const tt;
64396 u8 link_up;
64397 u8 qfull;
64398 enum fc_lport_state state;
64399 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
64400 index 77273f2..dd4031f 100644
64401 --- a/include/scsi/scsi_device.h
64402 +++ b/include/scsi/scsi_device.h
64403 @@ -161,9 +161,9 @@ struct scsi_device {
64404 unsigned int max_device_blocked; /* what device_blocked counts down from */
64405 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
64406
64407 - atomic_t iorequest_cnt;
64408 - atomic_t iodone_cnt;
64409 - atomic_t ioerr_cnt;
64410 + atomic_unchecked_t iorequest_cnt;
64411 + atomic_unchecked_t iodone_cnt;
64412 + atomic_unchecked_t ioerr_cnt;
64413
64414 struct device sdev_gendev,
64415 sdev_dev;
64416 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
64417 index 2a65167..91e01f8 100644
64418 --- a/include/scsi/scsi_transport_fc.h
64419 +++ b/include/scsi/scsi_transport_fc.h
64420 @@ -711,7 +711,7 @@ struct fc_function_template {
64421 unsigned long show_host_system_hostname:1;
64422
64423 unsigned long disable_target_scan:1;
64424 -};
64425 +} __do_const;
64426
64427
64428 /**
64429 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
64430 index 030b87c..98a6954 100644
64431 --- a/include/sound/ak4xxx-adda.h
64432 +++ b/include/sound/ak4xxx-adda.h
64433 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
64434 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
64435 unsigned char val);
64436 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
64437 -};
64438 +} __no_const;
64439
64440 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
64441
64442 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
64443 index 8c05e47..2b5df97 100644
64444 --- a/include/sound/hwdep.h
64445 +++ b/include/sound/hwdep.h
64446 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
64447 struct snd_hwdep_dsp_status *status);
64448 int (*dsp_load)(struct snd_hwdep *hw,
64449 struct snd_hwdep_dsp_image *image);
64450 -};
64451 +} __no_const;
64452
64453 struct snd_hwdep {
64454 struct snd_card *card;
64455 diff --git a/include/sound/info.h b/include/sound/info.h
64456 index 9ca1a49..aba1728 100644
64457 --- a/include/sound/info.h
64458 +++ b/include/sound/info.h
64459 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
64460 struct snd_info_buffer *buffer);
64461 void (*write)(struct snd_info_entry *entry,
64462 struct snd_info_buffer *buffer);
64463 -};
64464 +} __no_const;
64465
64466 struct snd_info_entry_ops {
64467 int (*open)(struct snd_info_entry *entry,
64468 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
64469 index 0cf91b2..b70cae4 100644
64470 --- a/include/sound/pcm.h
64471 +++ b/include/sound/pcm.h
64472 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
64473 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
64474 int (*ack)(struct snd_pcm_substream *substream);
64475 };
64476 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
64477
64478 /*
64479 *
64480 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
64481 index af1b49e..a5d55a5 100644
64482 --- a/include/sound/sb16_csp.h
64483 +++ b/include/sound/sb16_csp.h
64484 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
64485 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
64486 int (*csp_stop) (struct snd_sb_csp * p);
64487 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
64488 -};
64489 +} __no_const;
64490
64491 /*
64492 * CSP private data
64493 diff --git a/include/sound/soc.h b/include/sound/soc.h
64494 index 0992dff..bb366fe 100644
64495 --- a/include/sound/soc.h
64496 +++ b/include/sound/soc.h
64497 @@ -682,7 +682,7 @@ struct snd_soc_platform_driver {
64498 /* platform IO - used for platform DAPM */
64499 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
64500 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
64501 -};
64502 +} __do_const;
64503
64504 struct snd_soc_platform {
64505 const char *name;
64506 @@ -852,7 +852,7 @@ struct snd_soc_pcm_runtime {
64507 struct snd_soc_dai_link *dai_link;
64508 struct mutex pcm_mutex;
64509 enum snd_soc_pcm_subclass pcm_subclass;
64510 - struct snd_pcm_ops ops;
64511 + snd_pcm_ops_no_const ops;
64512
64513 unsigned int complete:1;
64514 unsigned int dev_registered:1;
64515 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
64516 index 444cd6b..3327cc5 100644
64517 --- a/include/sound/ymfpci.h
64518 +++ b/include/sound/ymfpci.h
64519 @@ -358,7 +358,7 @@ struct snd_ymfpci {
64520 spinlock_t reg_lock;
64521 spinlock_t voice_lock;
64522 wait_queue_head_t interrupt_sleep;
64523 - atomic_t interrupt_sleep_count;
64524 + atomic_unchecked_t interrupt_sleep_count;
64525 struct snd_info_entry *proc_entry;
64526 const struct firmware *dsp_microcode;
64527 const struct firmware *controller_microcode;
64528 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
64529 index fe73eb8..56388b1 100644
64530 --- a/include/target/target_core_base.h
64531 +++ b/include/target/target_core_base.h
64532 @@ -443,7 +443,7 @@ struct t10_reservation_ops {
64533 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
64534 int (*t10_pr_register)(struct se_cmd *);
64535 int (*t10_pr_clear)(struct se_cmd *);
64536 -};
64537 +} __no_const;
64538
64539 struct t10_reservation {
64540 /* Reservation effects all target ports */
64541 @@ -561,8 +561,8 @@ struct se_cmd {
64542 atomic_t t_se_count;
64543 atomic_t t_task_cdbs_left;
64544 atomic_t t_task_cdbs_ex_left;
64545 - atomic_t t_task_cdbs_sent;
64546 - atomic_t t_transport_aborted;
64547 + atomic_unchecked_t t_task_cdbs_sent;
64548 + atomic_unchecked_t t_transport_aborted;
64549 atomic_t t_transport_active;
64550 atomic_t t_transport_complete;
64551 atomic_t t_transport_queue_active;
64552 @@ -799,7 +799,7 @@ struct se_device {
64553 spinlock_t stats_lock;
64554 /* Active commands on this virtual SE device */
64555 atomic_t simple_cmds;
64556 - atomic_t dev_ordered_id;
64557 + atomic_unchecked_t dev_ordered_id;
64558 atomic_t execute_tasks;
64559 atomic_t dev_ordered_sync;
64560 atomic_t dev_qf_count;
64561 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
64562 index 1c09820..7f5ec79 100644
64563 --- a/include/trace/events/irq.h
64564 +++ b/include/trace/events/irq.h
64565 @@ -36,7 +36,7 @@ struct softirq_action;
64566 */
64567 TRACE_EVENT(irq_handler_entry,
64568
64569 - TP_PROTO(int irq, struct irqaction *action),
64570 + TP_PROTO(int irq, const struct irqaction *action),
64571
64572 TP_ARGS(irq, action),
64573
64574 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
64575 */
64576 TRACE_EVENT(irq_handler_exit,
64577
64578 - TP_PROTO(int irq, struct irqaction *action, int ret),
64579 + TP_PROTO(int irq, const struct irqaction *action, int ret),
64580
64581 TP_ARGS(irq, action, ret),
64582
64583 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
64584 index f9466fa..f4e2b81 100644
64585 --- a/include/video/udlfb.h
64586 +++ b/include/video/udlfb.h
64587 @@ -53,10 +53,10 @@ struct dlfb_data {
64588 u32 pseudo_palette[256];
64589 int blank_mode; /*one of FB_BLANK_ */
64590 /* blit-only rendering path metrics, exposed through sysfs */
64591 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64592 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
64593 - atomic_t bytes_sent; /* to usb, after compression including overhead */
64594 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
64595 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
64596 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
64597 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
64598 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
64599 };
64600
64601 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
64602 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
64603 index 0993a22..32ba2fe 100644
64604 --- a/include/video/uvesafb.h
64605 +++ b/include/video/uvesafb.h
64606 @@ -177,6 +177,7 @@ struct uvesafb_par {
64607 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
64608 u8 pmi_setpal; /* PMI for palette changes */
64609 u16 *pmi_base; /* protected mode interface location */
64610 + u8 *pmi_code; /* protected mode code location */
64611 void *pmi_start;
64612 void *pmi_pal;
64613 u8 *vbe_state_orig; /*
64614 diff --git a/init/Kconfig b/init/Kconfig
64615 index 3f42cd6..613f41d 100644
64616 --- a/init/Kconfig
64617 +++ b/init/Kconfig
64618 @@ -799,6 +799,7 @@ endif # CGROUPS
64619
64620 config CHECKPOINT_RESTORE
64621 bool "Checkpoint/restore support" if EXPERT
64622 + depends on !GRKERNSEC
64623 default n
64624 help
64625 Enables additional kernel features in a sake of checkpoint/restore.
64626 @@ -1249,7 +1250,7 @@ config SLUB_DEBUG
64627
64628 config COMPAT_BRK
64629 bool "Disable heap randomization"
64630 - default y
64631 + default n
64632 help
64633 Randomizing heap placement makes heap exploits harder, but it
64634 also breaks ancient binaries (including anything libc5 based).
64635 diff --git a/init/do_mounts.c b/init/do_mounts.c
64636 index bf6edbf..4e5809c 100644
64637 --- a/init/do_mounts.c
64638 +++ b/init/do_mounts.c
64639 @@ -326,11 +326,11 @@ static void __init get_fs_names(char *page)
64640 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
64641 {
64642 struct super_block *s;
64643 - int err = sys_mount(name, "/root", fs, flags, data);
64644 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
64645 if (err)
64646 return err;
64647
64648 - sys_chdir((const char __user __force *)"/root");
64649 + sys_chdir((const char __force_user *)"/root");
64650 s = current->fs->pwd.dentry->d_sb;
64651 ROOT_DEV = s->s_dev;
64652 printk(KERN_INFO
64653 @@ -450,18 +450,18 @@ void __init change_floppy(char *fmt, ...)
64654 va_start(args, fmt);
64655 vsprintf(buf, fmt, args);
64656 va_end(args);
64657 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
64658 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
64659 if (fd >= 0) {
64660 sys_ioctl(fd, FDEJECT, 0);
64661 sys_close(fd);
64662 }
64663 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
64664 - fd = sys_open("/dev/console", O_RDWR, 0);
64665 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
64666 if (fd >= 0) {
64667 sys_ioctl(fd, TCGETS, (long)&termios);
64668 termios.c_lflag &= ~ICANON;
64669 sys_ioctl(fd, TCSETSF, (long)&termios);
64670 - sys_read(fd, &c, 1);
64671 + sys_read(fd, (char __user *)&c, 1);
64672 termios.c_lflag |= ICANON;
64673 sys_ioctl(fd, TCSETSF, (long)&termios);
64674 sys_close(fd);
64675 @@ -555,6 +555,6 @@ void __init prepare_namespace(void)
64676 mount_root();
64677 out:
64678 devtmpfs_mount("dev");
64679 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64680 - sys_chroot((const char __user __force *)".");
64681 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64682 + sys_chroot((const char __force_user *)".");
64683 }
64684 diff --git a/init/do_mounts.h b/init/do_mounts.h
64685 index f5b978a..69dbfe8 100644
64686 --- a/init/do_mounts.h
64687 +++ b/init/do_mounts.h
64688 @@ -15,15 +15,15 @@ extern int root_mountflags;
64689
64690 static inline int create_dev(char *name, dev_t dev)
64691 {
64692 - sys_unlink(name);
64693 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
64694 + sys_unlink((char __force_user *)name);
64695 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
64696 }
64697
64698 #if BITS_PER_LONG == 32
64699 static inline u32 bstat(char *name)
64700 {
64701 struct stat64 stat;
64702 - if (sys_stat64(name, &stat) != 0)
64703 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
64704 return 0;
64705 if (!S_ISBLK(stat.st_mode))
64706 return 0;
64707 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
64708 static inline u32 bstat(char *name)
64709 {
64710 struct stat stat;
64711 - if (sys_newstat(name, &stat) != 0)
64712 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
64713 return 0;
64714 if (!S_ISBLK(stat.st_mode))
64715 return 0;
64716 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
64717 index 3098a38..253064e 100644
64718 --- a/init/do_mounts_initrd.c
64719 +++ b/init/do_mounts_initrd.c
64720 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
64721 create_dev("/dev/root.old", Root_RAM0);
64722 /* mount initrd on rootfs' /root */
64723 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
64724 - sys_mkdir("/old", 0700);
64725 - root_fd = sys_open("/", 0, 0);
64726 - old_fd = sys_open("/old", 0, 0);
64727 + sys_mkdir((const char __force_user *)"/old", 0700);
64728 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
64729 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
64730 /* move initrd over / and chdir/chroot in initrd root */
64731 - sys_chdir("/root");
64732 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
64733 - sys_chroot(".");
64734 + sys_chdir((const char __force_user *)"/root");
64735 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
64736 + sys_chroot((const char __force_user *)".");
64737
64738 /*
64739 * In case that a resume from disk is carried out by linuxrc or one of
64740 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
64741
64742 /* move initrd to rootfs' /old */
64743 sys_fchdir(old_fd);
64744 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
64745 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
64746 /* switch root and cwd back to / of rootfs */
64747 sys_fchdir(root_fd);
64748 - sys_chroot(".");
64749 + sys_chroot((const char __force_user *)".");
64750 sys_close(old_fd);
64751 sys_close(root_fd);
64752
64753 if (new_decode_dev(real_root_dev) == Root_RAM0) {
64754 - sys_chdir("/old");
64755 + sys_chdir((const char __force_user *)"/old");
64756 return;
64757 }
64758
64759 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
64760 mount_root();
64761
64762 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
64763 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
64764 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
64765 if (!error)
64766 printk("okay\n");
64767 else {
64768 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
64769 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
64770 if (error == -ENOENT)
64771 printk("/initrd does not exist. Ignored.\n");
64772 else
64773 printk("failed\n");
64774 printk(KERN_NOTICE "Unmounting old root\n");
64775 - sys_umount("/old", MNT_DETACH);
64776 + sys_umount((char __force_user *)"/old", MNT_DETACH);
64777 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
64778 if (fd < 0) {
64779 error = fd;
64780 @@ -116,11 +116,11 @@ int __init initrd_load(void)
64781 * mounted in the normal path.
64782 */
64783 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
64784 - sys_unlink("/initrd.image");
64785 + sys_unlink((const char __force_user *)"/initrd.image");
64786 handle_initrd();
64787 return 1;
64788 }
64789 }
64790 - sys_unlink("/initrd.image");
64791 + sys_unlink((const char __force_user *)"/initrd.image");
64792 return 0;
64793 }
64794 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
64795 index 32c4799..c27ee74 100644
64796 --- a/init/do_mounts_md.c
64797 +++ b/init/do_mounts_md.c
64798 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
64799 partitioned ? "_d" : "", minor,
64800 md_setup_args[ent].device_names);
64801
64802 - fd = sys_open(name, 0, 0);
64803 + fd = sys_open((char __force_user *)name, 0, 0);
64804 if (fd < 0) {
64805 printk(KERN_ERR "md: open failed - cannot start "
64806 "array %s\n", name);
64807 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
64808 * array without it
64809 */
64810 sys_close(fd);
64811 - fd = sys_open(name, 0, 0);
64812 + fd = sys_open((char __force_user *)name, 0, 0);
64813 sys_ioctl(fd, BLKRRPART, 0);
64814 }
64815 sys_close(fd);
64816 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
64817
64818 wait_for_device_probe();
64819
64820 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
64821 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
64822 if (fd >= 0) {
64823 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
64824 sys_close(fd);
64825 diff --git a/init/initramfs.c b/init/initramfs.c
64826 index 8216c30..25e8e32 100644
64827 --- a/init/initramfs.c
64828 +++ b/init/initramfs.c
64829 @@ -74,7 +74,7 @@ static void __init free_hash(void)
64830 }
64831 }
64832
64833 -static long __init do_utime(char __user *filename, time_t mtime)
64834 +static long __init do_utime(__force char __user *filename, time_t mtime)
64835 {
64836 struct timespec t[2];
64837
64838 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
64839 struct dir_entry *de, *tmp;
64840 list_for_each_entry_safe(de, tmp, &dir_list, list) {
64841 list_del(&de->list);
64842 - do_utime(de->name, de->mtime);
64843 + do_utime((char __force_user *)de->name, de->mtime);
64844 kfree(de->name);
64845 kfree(de);
64846 }
64847 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
64848 if (nlink >= 2) {
64849 char *old = find_link(major, minor, ino, mode, collected);
64850 if (old)
64851 - return (sys_link(old, collected) < 0) ? -1 : 1;
64852 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
64853 }
64854 return 0;
64855 }
64856 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, umode_t mode)
64857 {
64858 struct stat st;
64859
64860 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
64861 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
64862 if (S_ISDIR(st.st_mode))
64863 - sys_rmdir(path);
64864 + sys_rmdir((char __force_user *)path);
64865 else
64866 - sys_unlink(path);
64867 + sys_unlink((char __force_user *)path);
64868 }
64869 }
64870
64871 @@ -305,7 +305,7 @@ static int __init do_name(void)
64872 int openflags = O_WRONLY|O_CREAT;
64873 if (ml != 1)
64874 openflags |= O_TRUNC;
64875 - wfd = sys_open(collected, openflags, mode);
64876 + wfd = sys_open((char __force_user *)collected, openflags, mode);
64877
64878 if (wfd >= 0) {
64879 sys_fchown(wfd, uid, gid);
64880 @@ -317,17 +317,17 @@ static int __init do_name(void)
64881 }
64882 }
64883 } else if (S_ISDIR(mode)) {
64884 - sys_mkdir(collected, mode);
64885 - sys_chown(collected, uid, gid);
64886 - sys_chmod(collected, mode);
64887 + sys_mkdir((char __force_user *)collected, mode);
64888 + sys_chown((char __force_user *)collected, uid, gid);
64889 + sys_chmod((char __force_user *)collected, mode);
64890 dir_add(collected, mtime);
64891 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
64892 S_ISFIFO(mode) || S_ISSOCK(mode)) {
64893 if (maybe_link() == 0) {
64894 - sys_mknod(collected, mode, rdev);
64895 - sys_chown(collected, uid, gid);
64896 - sys_chmod(collected, mode);
64897 - do_utime(collected, mtime);
64898 + sys_mknod((char __force_user *)collected, mode, rdev);
64899 + sys_chown((char __force_user *)collected, uid, gid);
64900 + sys_chmod((char __force_user *)collected, mode);
64901 + do_utime((char __force_user *)collected, mtime);
64902 }
64903 }
64904 return 0;
64905 @@ -336,15 +336,15 @@ static int __init do_name(void)
64906 static int __init do_copy(void)
64907 {
64908 if (count >= body_len) {
64909 - sys_write(wfd, victim, body_len);
64910 + sys_write(wfd, (char __force_user *)victim, body_len);
64911 sys_close(wfd);
64912 - do_utime(vcollected, mtime);
64913 + do_utime((char __force_user *)vcollected, mtime);
64914 kfree(vcollected);
64915 eat(body_len);
64916 state = SkipIt;
64917 return 0;
64918 } else {
64919 - sys_write(wfd, victim, count);
64920 + sys_write(wfd, (char __force_user *)victim, count);
64921 body_len -= count;
64922 eat(count);
64923 return 1;
64924 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
64925 {
64926 collected[N_ALIGN(name_len) + body_len] = '\0';
64927 clean_path(collected, 0);
64928 - sys_symlink(collected + N_ALIGN(name_len), collected);
64929 - sys_lchown(collected, uid, gid);
64930 - do_utime(collected, mtime);
64931 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
64932 + sys_lchown((char __force_user *)collected, uid, gid);
64933 + do_utime((char __force_user *)collected, mtime);
64934 state = SkipIt;
64935 next_state = Reset;
64936 return 0;
64937 diff --git a/init/main.c b/init/main.c
64938 index 45a7bf5..7ba1b61 100644
64939 --- a/init/main.c
64940 +++ b/init/main.c
64941 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
64942 extern void tc_init(void);
64943 #endif
64944
64945 +extern void grsecurity_init(void);
64946 +
64947 /*
64948 * Debug helper: via this flag we know that we are in 'early bootup code'
64949 * where only the boot processor is running with IRQ disabled. This means
64950 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
64951
64952 __setup("reset_devices", set_reset_devices);
64953
64954 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
64955 +extern char pax_enter_kernel_user[];
64956 +extern char pax_exit_kernel_user[];
64957 +extern pgdval_t clone_pgd_mask;
64958 +#endif
64959 +
64960 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
64961 +static int __init setup_pax_nouderef(char *str)
64962 +{
64963 +#ifdef CONFIG_X86_32
64964 + unsigned int cpu;
64965 + struct desc_struct *gdt;
64966 +
64967 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
64968 + gdt = get_cpu_gdt_table(cpu);
64969 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
64970 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
64971 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
64972 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
64973 + }
64974 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
64975 +#else
64976 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
64977 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
64978 + clone_pgd_mask = ~(pgdval_t)0UL;
64979 +#endif
64980 +
64981 + return 0;
64982 +}
64983 +early_param("pax_nouderef", setup_pax_nouderef);
64984 +#endif
64985 +
64986 +#ifdef CONFIG_PAX_SOFTMODE
64987 +int pax_softmode;
64988 +
64989 +static int __init setup_pax_softmode(char *str)
64990 +{
64991 + get_option(&str, &pax_softmode);
64992 + return 1;
64993 +}
64994 +__setup("pax_softmode=", setup_pax_softmode);
64995 +#endif
64996 +
64997 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
64998 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
64999 static const char *panic_later, *panic_param;
65000 @@ -672,6 +717,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
65001 {
65002 int count = preempt_count();
65003 int ret;
65004 + const char *msg1 = "", *msg2 = "";
65005
65006 if (initcall_debug)
65007 ret = do_one_initcall_debug(fn);
65008 @@ -684,15 +730,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
65009 sprintf(msgbuf, "error code %d ", ret);
65010
65011 if (preempt_count() != count) {
65012 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
65013 + msg1 = " preemption imbalance";
65014 preempt_count() = count;
65015 }
65016 if (irqs_disabled()) {
65017 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
65018 + msg2 = " disabled interrupts";
65019 local_irq_enable();
65020 }
65021 - if (msgbuf[0]) {
65022 - printk("initcall %pF returned with %s\n", fn, msgbuf);
65023 + if (msgbuf[0] || *msg1 || *msg2) {
65024 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
65025 }
65026
65027 return ret;
65028 @@ -815,7 +861,7 @@ static int __init kernel_init(void * unused)
65029 do_basic_setup();
65030
65031 /* Open the /dev/console on the rootfs, this should never fail */
65032 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
65033 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
65034 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
65035
65036 (void) sys_dup(0);
65037 @@ -828,11 +874,13 @@ static int __init kernel_init(void * unused)
65038 if (!ramdisk_execute_command)
65039 ramdisk_execute_command = "/init";
65040
65041 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
65042 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
65043 ramdisk_execute_command = NULL;
65044 prepare_namespace();
65045 }
65046
65047 + grsecurity_init();
65048 +
65049 /*
65050 * Ok, we have completed the initial bootup, and
65051 * we're essentially up and running. Get rid of the
65052 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
65053 index 86ee272..773d937 100644
65054 --- a/ipc/mqueue.c
65055 +++ b/ipc/mqueue.c
65056 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
65057 mq_bytes = (mq_msg_tblsz +
65058 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
65059
65060 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
65061 spin_lock(&mq_lock);
65062 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
65063 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
65064 diff --git a/ipc/msg.c b/ipc/msg.c
65065 index 7385de2..a8180e08 100644
65066 --- a/ipc/msg.c
65067 +++ b/ipc/msg.c
65068 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
65069 return security_msg_queue_associate(msq, msgflg);
65070 }
65071
65072 +static struct ipc_ops msg_ops = {
65073 + .getnew = newque,
65074 + .associate = msg_security,
65075 + .more_checks = NULL
65076 +};
65077 +
65078 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
65079 {
65080 struct ipc_namespace *ns;
65081 - struct ipc_ops msg_ops;
65082 struct ipc_params msg_params;
65083
65084 ns = current->nsproxy->ipc_ns;
65085
65086 - msg_ops.getnew = newque;
65087 - msg_ops.associate = msg_security;
65088 - msg_ops.more_checks = NULL;
65089 -
65090 msg_params.key = key;
65091 msg_params.flg = msgflg;
65092
65093 diff --git a/ipc/sem.c b/ipc/sem.c
65094 index 5215a81..cfc0cac 100644
65095 --- a/ipc/sem.c
65096 +++ b/ipc/sem.c
65097 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
65098 return 0;
65099 }
65100
65101 +static struct ipc_ops sem_ops = {
65102 + .getnew = newary,
65103 + .associate = sem_security,
65104 + .more_checks = sem_more_checks
65105 +};
65106 +
65107 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65108 {
65109 struct ipc_namespace *ns;
65110 - struct ipc_ops sem_ops;
65111 struct ipc_params sem_params;
65112
65113 ns = current->nsproxy->ipc_ns;
65114 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
65115 if (nsems < 0 || nsems > ns->sc_semmsl)
65116 return -EINVAL;
65117
65118 - sem_ops.getnew = newary;
65119 - sem_ops.associate = sem_security;
65120 - sem_ops.more_checks = sem_more_checks;
65121 -
65122 sem_params.key = key;
65123 sem_params.flg = semflg;
65124 sem_params.u.nsems = nsems;
65125 diff --git a/ipc/shm.c b/ipc/shm.c
65126 index b76be5b..859e750 100644
65127 --- a/ipc/shm.c
65128 +++ b/ipc/shm.c
65129 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
65130 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
65131 #endif
65132
65133 +#ifdef CONFIG_GRKERNSEC
65134 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65135 + const time_t shm_createtime, const uid_t cuid,
65136 + const int shmid);
65137 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65138 + const time_t shm_createtime);
65139 +#endif
65140 +
65141 void shm_init_ns(struct ipc_namespace *ns)
65142 {
65143 ns->shm_ctlmax = SHMMAX;
65144 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
65145 shp->shm_lprid = 0;
65146 shp->shm_atim = shp->shm_dtim = 0;
65147 shp->shm_ctim = get_seconds();
65148 +#ifdef CONFIG_GRKERNSEC
65149 + {
65150 + struct timespec timeval;
65151 + do_posix_clock_monotonic_gettime(&timeval);
65152 +
65153 + shp->shm_createtime = timeval.tv_sec;
65154 + }
65155 +#endif
65156 shp->shm_segsz = size;
65157 shp->shm_nattch = 0;
65158 shp->shm_file = file;
65159 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
65160 return 0;
65161 }
65162
65163 +static struct ipc_ops shm_ops = {
65164 + .getnew = newseg,
65165 + .associate = shm_security,
65166 + .more_checks = shm_more_checks
65167 +};
65168 +
65169 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
65170 {
65171 struct ipc_namespace *ns;
65172 - struct ipc_ops shm_ops;
65173 struct ipc_params shm_params;
65174
65175 ns = current->nsproxy->ipc_ns;
65176
65177 - shm_ops.getnew = newseg;
65178 - shm_ops.associate = shm_security;
65179 - shm_ops.more_checks = shm_more_checks;
65180 -
65181 shm_params.key = key;
65182 shm_params.flg = shmflg;
65183 shm_params.u.size = size;
65184 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65185 f_mode = FMODE_READ | FMODE_WRITE;
65186 }
65187 if (shmflg & SHM_EXEC) {
65188 +
65189 +#ifdef CONFIG_PAX_MPROTECT
65190 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
65191 + goto out;
65192 +#endif
65193 +
65194 prot |= PROT_EXEC;
65195 acc_mode |= S_IXUGO;
65196 }
65197 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
65198 if (err)
65199 goto out_unlock;
65200
65201 +#ifdef CONFIG_GRKERNSEC
65202 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
65203 + shp->shm_perm.cuid, shmid) ||
65204 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
65205 + err = -EACCES;
65206 + goto out_unlock;
65207 + }
65208 +#endif
65209 +
65210 path = shp->shm_file->f_path;
65211 path_get(&path);
65212 shp->shm_nattch++;
65213 +#ifdef CONFIG_GRKERNSEC
65214 + shp->shm_lapid = current->pid;
65215 +#endif
65216 size = i_size_read(path.dentry->d_inode);
65217 shm_unlock(shp);
65218
65219 diff --git a/kernel/acct.c b/kernel/acct.c
65220 index 02e6167..54824f7 100644
65221 --- a/kernel/acct.c
65222 +++ b/kernel/acct.c
65223 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
65224 */
65225 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
65226 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
65227 - file->f_op->write(file, (char *)&ac,
65228 + file->f_op->write(file, (char __force_user *)&ac,
65229 sizeof(acct_t), &file->f_pos);
65230 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
65231 set_fs(fs);
65232 diff --git a/kernel/audit.c b/kernel/audit.c
65233 index bb0eb5b..cf2a03a 100644
65234 --- a/kernel/audit.c
65235 +++ b/kernel/audit.c
65236 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
65237 3) suppressed due to audit_rate_limit
65238 4) suppressed due to audit_backlog_limit
65239 */
65240 -static atomic_t audit_lost = ATOMIC_INIT(0);
65241 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
65242
65243 /* The netlink socket. */
65244 static struct sock *audit_sock;
65245 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
65246 unsigned long now;
65247 int print;
65248
65249 - atomic_inc(&audit_lost);
65250 + atomic_inc_unchecked(&audit_lost);
65251
65252 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
65253
65254 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
65255 printk(KERN_WARNING
65256 "audit: audit_lost=%d audit_rate_limit=%d "
65257 "audit_backlog_limit=%d\n",
65258 - atomic_read(&audit_lost),
65259 + atomic_read_unchecked(&audit_lost),
65260 audit_rate_limit,
65261 audit_backlog_limit);
65262 audit_panic(message);
65263 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
65264 status_set.pid = audit_pid;
65265 status_set.rate_limit = audit_rate_limit;
65266 status_set.backlog_limit = audit_backlog_limit;
65267 - status_set.lost = atomic_read(&audit_lost);
65268 + status_set.lost = atomic_read_unchecked(&audit_lost);
65269 status_set.backlog = skb_queue_len(&audit_skb_queue);
65270 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
65271 &status_set, sizeof(status_set));
65272 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
65273 index af1de0f..06dfe57 100644
65274 --- a/kernel/auditsc.c
65275 +++ b/kernel/auditsc.c
65276 @@ -2288,7 +2288,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
65277 }
65278
65279 /* global counter which is incremented every time something logs in */
65280 -static atomic_t session_id = ATOMIC_INIT(0);
65281 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
65282
65283 /**
65284 * audit_set_loginuid - set current task's audit_context loginuid
65285 @@ -2312,7 +2312,7 @@ int audit_set_loginuid(uid_t loginuid)
65286 return -EPERM;
65287 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
65288
65289 - sessionid = atomic_inc_return(&session_id);
65290 + sessionid = atomic_inc_return_unchecked(&session_id);
65291 if (context && context->in_syscall) {
65292 struct audit_buffer *ab;
65293
65294 diff --git a/kernel/capability.c b/kernel/capability.c
65295 index 3f1adb6..c564db0 100644
65296 --- a/kernel/capability.c
65297 +++ b/kernel/capability.c
65298 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
65299 * before modification is attempted and the application
65300 * fails.
65301 */
65302 + if (tocopy > ARRAY_SIZE(kdata))
65303 + return -EFAULT;
65304 +
65305 if (copy_to_user(dataptr, kdata, tocopy
65306 * sizeof(struct __user_cap_data_struct))) {
65307 return -EFAULT;
65308 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
65309 int ret;
65310
65311 rcu_read_lock();
65312 - ret = security_capable(__task_cred(t), ns, cap);
65313 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
65314 + gr_task_is_capable(t, __task_cred(t), cap);
65315 rcu_read_unlock();
65316
65317 - return (ret == 0);
65318 + return ret;
65319 }
65320
65321 /**
65322 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
65323 int ret;
65324
65325 rcu_read_lock();
65326 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
65327 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
65328 rcu_read_unlock();
65329
65330 - return (ret == 0);
65331 + return ret;
65332 }
65333
65334 /**
65335 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
65336 BUG();
65337 }
65338
65339 - if (security_capable(current_cred(), ns, cap) == 0) {
65340 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
65341 current->flags |= PF_SUPERPRIV;
65342 return true;
65343 }
65344 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
65345 }
65346 EXPORT_SYMBOL(ns_capable);
65347
65348 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
65349 +{
65350 + if (unlikely(!cap_valid(cap))) {
65351 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
65352 + BUG();
65353 + }
65354 +
65355 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
65356 + current->flags |= PF_SUPERPRIV;
65357 + return true;
65358 + }
65359 + return false;
65360 +}
65361 +EXPORT_SYMBOL(ns_capable_nolog);
65362 +
65363 /**
65364 * capable - Determine if the current task has a superior capability in effect
65365 * @cap: The capability to be tested for
65366 @@ -408,6 +427,12 @@ bool capable(int cap)
65367 }
65368 EXPORT_SYMBOL(capable);
65369
65370 +bool capable_nolog(int cap)
65371 +{
65372 + return ns_capable_nolog(&init_user_ns, cap);
65373 +}
65374 +EXPORT_SYMBOL(capable_nolog);
65375 +
65376 /**
65377 * nsown_capable - Check superior capability to one's own user_ns
65378 * @cap: The capability in question
65379 diff --git a/kernel/compat.c b/kernel/compat.c
65380 index a6d0649..f44fb27 100644
65381 --- a/kernel/compat.c
65382 +++ b/kernel/compat.c
65383 @@ -13,6 +13,7 @@
65384
65385 #include <linux/linkage.h>
65386 #include <linux/compat.h>
65387 +#include <linux/module.h>
65388 #include <linux/errno.h>
65389 #include <linux/time.h>
65390 #include <linux/signal.h>
65391 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
65392 mm_segment_t oldfs;
65393 long ret;
65394
65395 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
65396 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
65397 oldfs = get_fs();
65398 set_fs(KERNEL_DS);
65399 ret = hrtimer_nanosleep_restart(restart);
65400 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
65401 oldfs = get_fs();
65402 set_fs(KERNEL_DS);
65403 ret = hrtimer_nanosleep(&tu,
65404 - rmtp ? (struct timespec __user *)&rmt : NULL,
65405 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
65406 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
65407 set_fs(oldfs);
65408
65409 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
65410 mm_segment_t old_fs = get_fs();
65411
65412 set_fs(KERNEL_DS);
65413 - ret = sys_sigpending((old_sigset_t __user *) &s);
65414 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
65415 set_fs(old_fs);
65416 if (ret == 0)
65417 ret = put_user(s, set);
65418 @@ -399,7 +400,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
65419 mm_segment_t old_fs = get_fs();
65420
65421 set_fs(KERNEL_DS);
65422 - ret = sys_old_getrlimit(resource, &r);
65423 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
65424 set_fs(old_fs);
65425
65426 if (!ret) {
65427 @@ -471,7 +472,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
65428 mm_segment_t old_fs = get_fs();
65429
65430 set_fs(KERNEL_DS);
65431 - ret = sys_getrusage(who, (struct rusage __user *) &r);
65432 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
65433 set_fs(old_fs);
65434
65435 if (ret)
65436 @@ -498,8 +499,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
65437 set_fs (KERNEL_DS);
65438 ret = sys_wait4(pid,
65439 (stat_addr ?
65440 - (unsigned int __user *) &status : NULL),
65441 - options, (struct rusage __user *) &r);
65442 + (unsigned int __force_user *) &status : NULL),
65443 + options, (struct rusage __force_user *) &r);
65444 set_fs (old_fs);
65445
65446 if (ret > 0) {
65447 @@ -524,8 +525,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
65448 memset(&info, 0, sizeof(info));
65449
65450 set_fs(KERNEL_DS);
65451 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
65452 - uru ? (struct rusage __user *)&ru : NULL);
65453 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
65454 + uru ? (struct rusage __force_user *)&ru : NULL);
65455 set_fs(old_fs);
65456
65457 if ((ret < 0) || (info.si_signo == 0))
65458 @@ -655,8 +656,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
65459 oldfs = get_fs();
65460 set_fs(KERNEL_DS);
65461 err = sys_timer_settime(timer_id, flags,
65462 - (struct itimerspec __user *) &newts,
65463 - (struct itimerspec __user *) &oldts);
65464 + (struct itimerspec __force_user *) &newts,
65465 + (struct itimerspec __force_user *) &oldts);
65466 set_fs(oldfs);
65467 if (!err && old && put_compat_itimerspec(old, &oldts))
65468 return -EFAULT;
65469 @@ -673,7 +674,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
65470 oldfs = get_fs();
65471 set_fs(KERNEL_DS);
65472 err = sys_timer_gettime(timer_id,
65473 - (struct itimerspec __user *) &ts);
65474 + (struct itimerspec __force_user *) &ts);
65475 set_fs(oldfs);
65476 if (!err && put_compat_itimerspec(setting, &ts))
65477 return -EFAULT;
65478 @@ -692,7 +693,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
65479 oldfs = get_fs();
65480 set_fs(KERNEL_DS);
65481 err = sys_clock_settime(which_clock,
65482 - (struct timespec __user *) &ts);
65483 + (struct timespec __force_user *) &ts);
65484 set_fs(oldfs);
65485 return err;
65486 }
65487 @@ -707,7 +708,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
65488 oldfs = get_fs();
65489 set_fs(KERNEL_DS);
65490 err = sys_clock_gettime(which_clock,
65491 - (struct timespec __user *) &ts);
65492 + (struct timespec __force_user *) &ts);
65493 set_fs(oldfs);
65494 if (!err && put_compat_timespec(&ts, tp))
65495 return -EFAULT;
65496 @@ -727,7 +728,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
65497
65498 oldfs = get_fs();
65499 set_fs(KERNEL_DS);
65500 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
65501 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
65502 set_fs(oldfs);
65503
65504 err = compat_put_timex(utp, &txc);
65505 @@ -747,7 +748,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
65506 oldfs = get_fs();
65507 set_fs(KERNEL_DS);
65508 err = sys_clock_getres(which_clock,
65509 - (struct timespec __user *) &ts);
65510 + (struct timespec __force_user *) &ts);
65511 set_fs(oldfs);
65512 if (!err && tp && put_compat_timespec(&ts, tp))
65513 return -EFAULT;
65514 @@ -759,9 +760,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
65515 long err;
65516 mm_segment_t oldfs;
65517 struct timespec tu;
65518 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
65519 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
65520
65521 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
65522 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
65523 oldfs = get_fs();
65524 set_fs(KERNEL_DS);
65525 err = clock_nanosleep_restart(restart);
65526 @@ -793,8 +794,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
65527 oldfs = get_fs();
65528 set_fs(KERNEL_DS);
65529 err = sys_clock_nanosleep(which_clock, flags,
65530 - (struct timespec __user *) &in,
65531 - (struct timespec __user *) &out);
65532 + (struct timespec __force_user *) &in,
65533 + (struct timespec __force_user *) &out);
65534 set_fs(oldfs);
65535
65536 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
65537 diff --git a/kernel/configs.c b/kernel/configs.c
65538 index 42e8fa0..9e7406b 100644
65539 --- a/kernel/configs.c
65540 +++ b/kernel/configs.c
65541 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
65542 struct proc_dir_entry *entry;
65543
65544 /* create the current config file */
65545 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
65546 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
65547 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
65548 + &ikconfig_file_ops);
65549 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65550 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
65551 + &ikconfig_file_ops);
65552 +#endif
65553 +#else
65554 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
65555 &ikconfig_file_ops);
65556 +#endif
65557 +
65558 if (!entry)
65559 return -ENOMEM;
65560
65561 diff --git a/kernel/cred.c b/kernel/cred.c
65562 index 48c6fd3..8398912 100644
65563 --- a/kernel/cred.c
65564 +++ b/kernel/cred.c
65565 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
65566 validate_creds(cred);
65567 put_cred(cred);
65568 }
65569 +
65570 +#ifdef CONFIG_GRKERNSEC_SETXID
65571 + cred = (struct cred *) tsk->delayed_cred;
65572 + if (cred) {
65573 + tsk->delayed_cred = NULL;
65574 + validate_creds(cred);
65575 + put_cred(cred);
65576 + }
65577 +#endif
65578 }
65579
65580 /**
65581 @@ -472,7 +481,7 @@ error_put:
65582 * Always returns 0 thus allowing this function to be tail-called at the end
65583 * of, say, sys_setgid().
65584 */
65585 -int commit_creds(struct cred *new)
65586 +static int __commit_creds(struct cred *new)
65587 {
65588 struct task_struct *task = current;
65589 const struct cred *old = task->real_cred;
65590 @@ -491,6 +500,8 @@ int commit_creds(struct cred *new)
65591
65592 get_cred(new); /* we will require a ref for the subj creds too */
65593
65594 + gr_set_role_label(task, new->uid, new->gid);
65595 +
65596 /* dumpability changes */
65597 if (old->euid != new->euid ||
65598 old->egid != new->egid ||
65599 @@ -540,6 +551,101 @@ int commit_creds(struct cred *new)
65600 put_cred(old);
65601 return 0;
65602 }
65603 +#ifdef CONFIG_GRKERNSEC_SETXID
65604 +extern int set_user(struct cred *new);
65605 +
65606 +void gr_delayed_cred_worker(void)
65607 +{
65608 + const struct cred *new = current->delayed_cred;
65609 + struct cred *ncred;
65610 +
65611 + current->delayed_cred = NULL;
65612 +
65613 + if (current_uid() && new != NULL) {
65614 + // from doing get_cred on it when queueing this
65615 + put_cred(new);
65616 + return;
65617 + } else if (new == NULL)
65618 + return;
65619 +
65620 + ncred = prepare_creds();
65621 + if (!ncred)
65622 + goto die;
65623 + // uids
65624 + ncred->uid = new->uid;
65625 + ncred->euid = new->euid;
65626 + ncred->suid = new->suid;
65627 + ncred->fsuid = new->fsuid;
65628 + // gids
65629 + ncred->gid = new->gid;
65630 + ncred->egid = new->egid;
65631 + ncred->sgid = new->sgid;
65632 + ncred->fsgid = new->fsgid;
65633 + // groups
65634 + if (set_groups(ncred, new->group_info) < 0) {
65635 + abort_creds(ncred);
65636 + goto die;
65637 + }
65638 + // caps
65639 + ncred->securebits = new->securebits;
65640 + ncred->cap_inheritable = new->cap_inheritable;
65641 + ncred->cap_permitted = new->cap_permitted;
65642 + ncred->cap_effective = new->cap_effective;
65643 + ncred->cap_bset = new->cap_bset;
65644 +
65645 + if (set_user(ncred)) {
65646 + abort_creds(ncred);
65647 + goto die;
65648 + }
65649 +
65650 + // from doing get_cred on it when queueing this
65651 + put_cred(new);
65652 +
65653 + __commit_creds(ncred);
65654 + return;
65655 +die:
65656 + // from doing get_cred on it when queueing this
65657 + put_cred(new);
65658 + do_group_exit(SIGKILL);
65659 +}
65660 +#endif
65661 +
65662 +int commit_creds(struct cred *new)
65663 +{
65664 +#ifdef CONFIG_GRKERNSEC_SETXID
65665 + int ret;
65666 + int schedule_it = 0;
65667 + struct task_struct *t;
65668 +
65669 + /* we won't get called with tasklist_lock held for writing
65670 + and interrupts disabled as the cred struct in that case is
65671 + init_cred
65672 + */
65673 + if (grsec_enable_setxid && !current_is_single_threaded() &&
65674 + !current_uid() && new->uid) {
65675 + schedule_it = 1;
65676 + }
65677 + ret = __commit_creds(new);
65678 + if (schedule_it) {
65679 + rcu_read_lock();
65680 + read_lock(&tasklist_lock);
65681 + for (t = next_thread(current); t != current;
65682 + t = next_thread(t)) {
65683 + if (t->delayed_cred == NULL) {
65684 + t->delayed_cred = get_cred(new);
65685 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
65686 + set_tsk_need_resched(t);
65687 + }
65688 + }
65689 + read_unlock(&tasklist_lock);
65690 + rcu_read_unlock();
65691 + }
65692 + return ret;
65693 +#else
65694 + return __commit_creds(new);
65695 +#endif
65696 +}
65697 +
65698 EXPORT_SYMBOL(commit_creds);
65699
65700 /**
65701 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
65702 index 7fda904..59f620c 100644
65703 --- a/kernel/debug/debug_core.c
65704 +++ b/kernel/debug/debug_core.c
65705 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
65706 */
65707 static atomic_t masters_in_kgdb;
65708 static atomic_t slaves_in_kgdb;
65709 -static atomic_t kgdb_break_tasklet_var;
65710 +static atomic_unchecked_t kgdb_break_tasklet_var;
65711 atomic_t kgdb_setting_breakpoint;
65712
65713 struct task_struct *kgdb_usethread;
65714 @@ -129,7 +129,7 @@ int kgdb_single_step;
65715 static pid_t kgdb_sstep_pid;
65716
65717 /* to keep track of the CPU which is doing the single stepping*/
65718 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65719 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
65720
65721 /*
65722 * If you are debugging a problem where roundup (the collection of
65723 @@ -537,7 +537,7 @@ return_normal:
65724 * kernel will only try for the value of sstep_tries before
65725 * giving up and continuing on.
65726 */
65727 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
65728 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
65729 (kgdb_info[cpu].task &&
65730 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
65731 atomic_set(&kgdb_active, -1);
65732 @@ -631,8 +631,8 @@ cpu_master_loop:
65733 }
65734
65735 kgdb_restore:
65736 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
65737 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
65738 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
65739 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
65740 if (kgdb_info[sstep_cpu].task)
65741 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
65742 else
65743 @@ -829,18 +829,18 @@ static void kgdb_unregister_callbacks(void)
65744 static void kgdb_tasklet_bpt(unsigned long ing)
65745 {
65746 kgdb_breakpoint();
65747 - atomic_set(&kgdb_break_tasklet_var, 0);
65748 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
65749 }
65750
65751 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
65752
65753 void kgdb_schedule_breakpoint(void)
65754 {
65755 - if (atomic_read(&kgdb_break_tasklet_var) ||
65756 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
65757 atomic_read(&kgdb_active) != -1 ||
65758 atomic_read(&kgdb_setting_breakpoint))
65759 return;
65760 - atomic_inc(&kgdb_break_tasklet_var);
65761 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
65762 tasklet_schedule(&kgdb_tasklet_breakpoint);
65763 }
65764 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
65765 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
65766 index e2ae734..08a4c5c 100644
65767 --- a/kernel/debug/kdb/kdb_main.c
65768 +++ b/kernel/debug/kdb/kdb_main.c
65769 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
65770 list_for_each_entry(mod, kdb_modules, list) {
65771
65772 kdb_printf("%-20s%8u 0x%p ", mod->name,
65773 - mod->core_size, (void *)mod);
65774 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
65775 #ifdef CONFIG_MODULE_UNLOAD
65776 kdb_printf("%4ld ", module_refcount(mod));
65777 #endif
65778 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
65779 kdb_printf(" (Loading)");
65780 else
65781 kdb_printf(" (Live)");
65782 - kdb_printf(" 0x%p", mod->module_core);
65783 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
65784
65785 #ifdef CONFIG_MODULE_UNLOAD
65786 {
65787 diff --git a/kernel/events/core.c b/kernel/events/core.c
65788 index 1b5c081..c375f83 100644
65789 --- a/kernel/events/core.c
65790 +++ b/kernel/events/core.c
65791 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
65792 return 0;
65793 }
65794
65795 -static atomic64_t perf_event_id;
65796 +static atomic64_unchecked_t perf_event_id;
65797
65798 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
65799 enum event_type_t event_type);
65800 @@ -2581,7 +2581,7 @@ static void __perf_event_read(void *info)
65801
65802 static inline u64 perf_event_count(struct perf_event *event)
65803 {
65804 - return local64_read(&event->count) + atomic64_read(&event->child_count);
65805 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
65806 }
65807
65808 static u64 perf_event_read(struct perf_event *event)
65809 @@ -2897,9 +2897,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
65810 mutex_lock(&event->child_mutex);
65811 total += perf_event_read(event);
65812 *enabled += event->total_time_enabled +
65813 - atomic64_read(&event->child_total_time_enabled);
65814 + atomic64_read_unchecked(&event->child_total_time_enabled);
65815 *running += event->total_time_running +
65816 - atomic64_read(&event->child_total_time_running);
65817 + atomic64_read_unchecked(&event->child_total_time_running);
65818
65819 list_for_each_entry(child, &event->child_list, child_list) {
65820 total += perf_event_read(child);
65821 @@ -3306,10 +3306,10 @@ void perf_event_update_userpage(struct perf_event *event)
65822 userpg->offset -= local64_read(&event->hw.prev_count);
65823
65824 userpg->time_enabled = enabled +
65825 - atomic64_read(&event->child_total_time_enabled);
65826 + atomic64_read_unchecked(&event->child_total_time_enabled);
65827
65828 userpg->time_running = running +
65829 - atomic64_read(&event->child_total_time_running);
65830 + atomic64_read_unchecked(&event->child_total_time_running);
65831
65832 barrier();
65833 ++userpg->lock;
65834 @@ -3738,11 +3738,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
65835 values[n++] = perf_event_count(event);
65836 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
65837 values[n++] = enabled +
65838 - atomic64_read(&event->child_total_time_enabled);
65839 + atomic64_read_unchecked(&event->child_total_time_enabled);
65840 }
65841 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
65842 values[n++] = running +
65843 - atomic64_read(&event->child_total_time_running);
65844 + atomic64_read_unchecked(&event->child_total_time_running);
65845 }
65846 if (read_format & PERF_FORMAT_ID)
65847 values[n++] = primary_event_id(event);
65848 @@ -4393,12 +4393,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
65849 * need to add enough zero bytes after the string to handle
65850 * the 64bit alignment we do later.
65851 */
65852 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
65853 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
65854 if (!buf) {
65855 name = strncpy(tmp, "//enomem", sizeof(tmp));
65856 goto got_name;
65857 }
65858 - name = d_path(&file->f_path, buf, PATH_MAX);
65859 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
65860 if (IS_ERR(name)) {
65861 name = strncpy(tmp, "//toolong", sizeof(tmp));
65862 goto got_name;
65863 @@ -5765,7 +5765,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
65864 event->parent = parent_event;
65865
65866 event->ns = get_pid_ns(current->nsproxy->pid_ns);
65867 - event->id = atomic64_inc_return(&perf_event_id);
65868 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
65869
65870 event->state = PERF_EVENT_STATE_INACTIVE;
65871
65872 @@ -6287,10 +6287,10 @@ static void sync_child_event(struct perf_event *child_event,
65873 /*
65874 * Add back the child's count to the parent's count:
65875 */
65876 - atomic64_add(child_val, &parent_event->child_count);
65877 - atomic64_add(child_event->total_time_enabled,
65878 + atomic64_add_unchecked(child_val, &parent_event->child_count);
65879 + atomic64_add_unchecked(child_event->total_time_enabled,
65880 &parent_event->child_total_time_enabled);
65881 - atomic64_add(child_event->total_time_running,
65882 + atomic64_add_unchecked(child_event->total_time_running,
65883 &parent_event->child_total_time_running);
65884
65885 /*
65886 diff --git a/kernel/exit.c b/kernel/exit.c
65887 index 46c8b14..d868958 100644
65888 --- a/kernel/exit.c
65889 +++ b/kernel/exit.c
65890 @@ -58,6 +58,10 @@
65891 #include <asm/pgtable.h>
65892 #include <asm/mmu_context.h>
65893
65894 +#ifdef CONFIG_GRKERNSEC
65895 +extern rwlock_t grsec_exec_file_lock;
65896 +#endif
65897 +
65898 static void exit_mm(struct task_struct * tsk);
65899
65900 static void __unhash_process(struct task_struct *p, bool group_dead)
65901 @@ -169,6 +173,10 @@ void release_task(struct task_struct * p)
65902 struct task_struct *leader;
65903 int zap_leader;
65904 repeat:
65905 +#ifdef CONFIG_NET
65906 + gr_del_task_from_ip_table(p);
65907 +#endif
65908 +
65909 /* don't need to get the RCU readlock here - the process is dead and
65910 * can't be modifying its own credentials. But shut RCU-lockdep up */
65911 rcu_read_lock();
65912 @@ -381,7 +389,7 @@ int allow_signal(int sig)
65913 * know it'll be handled, so that they don't get converted to
65914 * SIGKILL or just silently dropped.
65915 */
65916 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
65917 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
65918 recalc_sigpending();
65919 spin_unlock_irq(&current->sighand->siglock);
65920 return 0;
65921 @@ -417,6 +425,17 @@ void daemonize(const char *name, ...)
65922 vsnprintf(current->comm, sizeof(current->comm), name, args);
65923 va_end(args);
65924
65925 +#ifdef CONFIG_GRKERNSEC
65926 + write_lock(&grsec_exec_file_lock);
65927 + if (current->exec_file) {
65928 + fput(current->exec_file);
65929 + current->exec_file = NULL;
65930 + }
65931 + write_unlock(&grsec_exec_file_lock);
65932 +#endif
65933 +
65934 + gr_set_kernel_label(current);
65935 +
65936 /*
65937 * If we were started as result of loading a module, close all of the
65938 * user space pages. We don't need them, and if we didn't close them
65939 @@ -873,6 +892,8 @@ void do_exit(long code)
65940 struct task_struct *tsk = current;
65941 int group_dead;
65942
65943 + set_fs(USER_DS);
65944 +
65945 profile_task_exit(tsk);
65946
65947 WARN_ON(blk_needs_flush_plug(tsk));
65948 @@ -889,7 +910,6 @@ void do_exit(long code)
65949 * mm_release()->clear_child_tid() from writing to a user-controlled
65950 * kernel address.
65951 */
65952 - set_fs(USER_DS);
65953
65954 ptrace_event(PTRACE_EVENT_EXIT, code);
65955
65956 @@ -950,6 +970,9 @@ void do_exit(long code)
65957 tsk->exit_code = code;
65958 taskstats_exit(tsk, group_dead);
65959
65960 + gr_acl_handle_psacct(tsk, code);
65961 + gr_acl_handle_exit();
65962 +
65963 exit_mm(tsk);
65964
65965 if (group_dead)
65966 @@ -1066,7 +1089,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
65967 * Take down every thread in the group. This is called by fatal signals
65968 * as well as by sys_exit_group (below).
65969 */
65970 -void
65971 +__noreturn void
65972 do_group_exit(int exit_code)
65973 {
65974 struct signal_struct *sig = current->signal;
65975 diff --git a/kernel/fork.c b/kernel/fork.c
65976 index 423d5a4..881923e 100644
65977 --- a/kernel/fork.c
65978 +++ b/kernel/fork.c
65979 @@ -285,7 +285,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
65980 *stackend = STACK_END_MAGIC; /* for overflow detection */
65981
65982 #ifdef CONFIG_CC_STACKPROTECTOR
65983 - tsk->stack_canary = get_random_int();
65984 + tsk->stack_canary = pax_get_random_long();
65985 #endif
65986
65987 /*
65988 @@ -309,13 +309,77 @@ out:
65989 }
65990
65991 #ifdef CONFIG_MMU
65992 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
65993 +{
65994 + struct vm_area_struct *tmp;
65995 + unsigned long charge;
65996 + struct mempolicy *pol;
65997 + struct file *file;
65998 +
65999 + charge = 0;
66000 + if (mpnt->vm_flags & VM_ACCOUNT) {
66001 + unsigned long len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66002 + if (security_vm_enough_memory(len))
66003 + goto fail_nomem;
66004 + charge = len;
66005 + }
66006 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66007 + if (!tmp)
66008 + goto fail_nomem;
66009 + *tmp = *mpnt;
66010 + tmp->vm_mm = mm;
66011 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
66012 + pol = mpol_dup(vma_policy(mpnt));
66013 + if (IS_ERR(pol))
66014 + goto fail_nomem_policy;
66015 + vma_set_policy(tmp, pol);
66016 + if (anon_vma_fork(tmp, mpnt))
66017 + goto fail_nomem_anon_vma_fork;
66018 + tmp->vm_flags &= ~VM_LOCKED;
66019 + tmp->vm_next = tmp->vm_prev = NULL;
66020 + tmp->vm_mirror = NULL;
66021 + file = tmp->vm_file;
66022 + if (file) {
66023 + struct inode *inode = file->f_path.dentry->d_inode;
66024 + struct address_space *mapping = file->f_mapping;
66025 +
66026 + get_file(file);
66027 + if (tmp->vm_flags & VM_DENYWRITE)
66028 + atomic_dec(&inode->i_writecount);
66029 + mutex_lock(&mapping->i_mmap_mutex);
66030 + if (tmp->vm_flags & VM_SHARED)
66031 + mapping->i_mmap_writable++;
66032 + flush_dcache_mmap_lock(mapping);
66033 + /* insert tmp into the share list, just after mpnt */
66034 + vma_prio_tree_add(tmp, mpnt);
66035 + flush_dcache_mmap_unlock(mapping);
66036 + mutex_unlock(&mapping->i_mmap_mutex);
66037 + }
66038 +
66039 + /*
66040 + * Clear hugetlb-related page reserves for children. This only
66041 + * affects MAP_PRIVATE mappings. Faults generated by the child
66042 + * are not guaranteed to succeed, even if read-only
66043 + */
66044 + if (is_vm_hugetlb_page(tmp))
66045 + reset_vma_resv_huge_pages(tmp);
66046 +
66047 + return tmp;
66048 +
66049 +fail_nomem_anon_vma_fork:
66050 + mpol_put(pol);
66051 +fail_nomem_policy:
66052 + kmem_cache_free(vm_area_cachep, tmp);
66053 +fail_nomem:
66054 + vm_unacct_memory(charge);
66055 + return NULL;
66056 +}
66057 +
66058 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66059 {
66060 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
66061 struct rb_node **rb_link, *rb_parent;
66062 int retval;
66063 - unsigned long charge;
66064 - struct mempolicy *pol;
66065
66066 down_write(&oldmm->mmap_sem);
66067 flush_cache_dup_mm(oldmm);
66068 @@ -327,8 +391,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66069 mm->locked_vm = 0;
66070 mm->mmap = NULL;
66071 mm->mmap_cache = NULL;
66072 - mm->free_area_cache = oldmm->mmap_base;
66073 - mm->cached_hole_size = ~0UL;
66074 + mm->free_area_cache = oldmm->free_area_cache;
66075 + mm->cached_hole_size = oldmm->cached_hole_size;
66076 mm->map_count = 0;
66077 cpumask_clear(mm_cpumask(mm));
66078 mm->mm_rb = RB_ROOT;
66079 @@ -344,8 +408,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66080
66081 prev = NULL;
66082 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
66083 - struct file *file;
66084 -
66085 if (mpnt->vm_flags & VM_DONTCOPY) {
66086 long pages = vma_pages(mpnt);
66087 mm->total_vm -= pages;
66088 @@ -353,53 +415,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66089 -pages);
66090 continue;
66091 }
66092 - charge = 0;
66093 - if (mpnt->vm_flags & VM_ACCOUNT) {
66094 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
66095 - if (security_vm_enough_memory(len))
66096 - goto fail_nomem;
66097 - charge = len;
66098 + tmp = dup_vma(mm, mpnt);
66099 + if (!tmp) {
66100 + retval = -ENOMEM;
66101 + goto out;
66102 }
66103 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
66104 - if (!tmp)
66105 - goto fail_nomem;
66106 - *tmp = *mpnt;
66107 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
66108 - pol = mpol_dup(vma_policy(mpnt));
66109 - retval = PTR_ERR(pol);
66110 - if (IS_ERR(pol))
66111 - goto fail_nomem_policy;
66112 - vma_set_policy(tmp, pol);
66113 - tmp->vm_mm = mm;
66114 - if (anon_vma_fork(tmp, mpnt))
66115 - goto fail_nomem_anon_vma_fork;
66116 - tmp->vm_flags &= ~VM_LOCKED;
66117 - tmp->vm_next = tmp->vm_prev = NULL;
66118 - file = tmp->vm_file;
66119 - if (file) {
66120 - struct inode *inode = file->f_path.dentry->d_inode;
66121 - struct address_space *mapping = file->f_mapping;
66122 -
66123 - get_file(file);
66124 - if (tmp->vm_flags & VM_DENYWRITE)
66125 - atomic_dec(&inode->i_writecount);
66126 - mutex_lock(&mapping->i_mmap_mutex);
66127 - if (tmp->vm_flags & VM_SHARED)
66128 - mapping->i_mmap_writable++;
66129 - flush_dcache_mmap_lock(mapping);
66130 - /* insert tmp into the share list, just after mpnt */
66131 - vma_prio_tree_add(tmp, mpnt);
66132 - flush_dcache_mmap_unlock(mapping);
66133 - mutex_unlock(&mapping->i_mmap_mutex);
66134 - }
66135 -
66136 - /*
66137 - * Clear hugetlb-related page reserves for children. This only
66138 - * affects MAP_PRIVATE mappings. Faults generated by the child
66139 - * are not guaranteed to succeed, even if read-only
66140 - */
66141 - if (is_vm_hugetlb_page(tmp))
66142 - reset_vma_resv_huge_pages(tmp);
66143
66144 /*
66145 * Link in the new vma and copy the page table entries.
66146 @@ -422,6 +442,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
66147 if (retval)
66148 goto out;
66149 }
66150 +
66151 +#ifdef CONFIG_PAX_SEGMEXEC
66152 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
66153 + struct vm_area_struct *mpnt_m;
66154 +
66155 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
66156 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
66157 +
66158 + if (!mpnt->vm_mirror)
66159 + continue;
66160 +
66161 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
66162 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
66163 + mpnt->vm_mirror = mpnt_m;
66164 + } else {
66165 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
66166 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
66167 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
66168 + mpnt->vm_mirror->vm_mirror = mpnt;
66169 + }
66170 + }
66171 + BUG_ON(mpnt_m);
66172 + }
66173 +#endif
66174 +
66175 /* a new mm has just been created */
66176 arch_dup_mmap(oldmm, mm);
66177 retval = 0;
66178 @@ -430,14 +475,6 @@ out:
66179 flush_tlb_mm(oldmm);
66180 up_write(&oldmm->mmap_sem);
66181 return retval;
66182 -fail_nomem_anon_vma_fork:
66183 - mpol_put(pol);
66184 -fail_nomem_policy:
66185 - kmem_cache_free(vm_area_cachep, tmp);
66186 -fail_nomem:
66187 - retval = -ENOMEM;
66188 - vm_unacct_memory(charge);
66189 - goto out;
66190 }
66191
66192 static inline int mm_alloc_pgd(struct mm_struct *mm)
66193 @@ -659,8 +696,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
66194 return ERR_PTR(err);
66195
66196 mm = get_task_mm(task);
66197 - if (mm && mm != current->mm &&
66198 - !ptrace_may_access(task, mode)) {
66199 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
66200 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
66201 mmput(mm);
66202 mm = ERR_PTR(-EACCES);
66203 }
66204 @@ -882,13 +919,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
66205 spin_unlock(&fs->lock);
66206 return -EAGAIN;
66207 }
66208 - fs->users++;
66209 + atomic_inc(&fs->users);
66210 spin_unlock(&fs->lock);
66211 return 0;
66212 }
66213 tsk->fs = copy_fs_struct(fs);
66214 if (!tsk->fs)
66215 return -ENOMEM;
66216 + gr_set_chroot_entries(tsk, &tsk->fs->root);
66217 return 0;
66218 }
66219
66220 @@ -1152,6 +1190,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66221 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
66222 #endif
66223 retval = -EAGAIN;
66224 +
66225 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
66226 +
66227 if (atomic_read(&p->real_cred->user->processes) >=
66228 task_rlimit(p, RLIMIT_NPROC)) {
66229 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
66230 @@ -1307,6 +1348,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
66231 if (clone_flags & CLONE_THREAD)
66232 p->tgid = current->tgid;
66233
66234 + gr_copy_label(p);
66235 +
66236 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
66237 /*
66238 * Clear TID on mm_release()?
66239 @@ -1475,6 +1518,8 @@ bad_fork_cleanup_count:
66240 bad_fork_free:
66241 free_task(p);
66242 fork_out:
66243 + gr_log_forkfail(retval);
66244 +
66245 return ERR_PTR(retval);
66246 }
66247
66248 @@ -1575,6 +1620,8 @@ long do_fork(unsigned long clone_flags,
66249 if (clone_flags & CLONE_PARENT_SETTID)
66250 put_user(nr, parent_tidptr);
66251
66252 + gr_handle_brute_check();
66253 +
66254 if (clone_flags & CLONE_VFORK) {
66255 p->vfork_done = &vfork;
66256 init_completion(&vfork);
66257 @@ -1673,7 +1720,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
66258 return 0;
66259
66260 /* don't need lock here; in the worst case we'll do useless copy */
66261 - if (fs->users == 1)
66262 + if (atomic_read(&fs->users) == 1)
66263 return 0;
66264
66265 *new_fsp = copy_fs_struct(fs);
66266 @@ -1762,7 +1809,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
66267 fs = current->fs;
66268 spin_lock(&fs->lock);
66269 current->fs = new_fs;
66270 - if (--fs->users)
66271 + gr_set_chroot_entries(current, &current->fs->root);
66272 + if (atomic_dec_return(&fs->users))
66273 new_fs = NULL;
66274 else
66275 new_fs = fs;
66276 diff --git a/kernel/futex.c b/kernel/futex.c
66277 index 866c9d5..5c5f828 100644
66278 --- a/kernel/futex.c
66279 +++ b/kernel/futex.c
66280 @@ -54,6 +54,7 @@
66281 #include <linux/mount.h>
66282 #include <linux/pagemap.h>
66283 #include <linux/syscalls.h>
66284 +#include <linux/ptrace.h>
66285 #include <linux/signal.h>
66286 #include <linux/export.h>
66287 #include <linux/magic.h>
66288 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
66289 struct page *page, *page_head;
66290 int err, ro = 0;
66291
66292 +#ifdef CONFIG_PAX_SEGMEXEC
66293 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
66294 + return -EFAULT;
66295 +#endif
66296 +
66297 /*
66298 * The futex address must be "naturally" aligned.
66299 */
66300 @@ -2721,6 +2727,7 @@ static int __init futex_init(void)
66301 {
66302 u32 curval;
66303 int i;
66304 + mm_segment_t oldfs;
66305
66306 /*
66307 * This will fail and we want it. Some arch implementations do
66308 @@ -2732,8 +2739,11 @@ static int __init futex_init(void)
66309 * implementation, the non-functional ones will return
66310 * -ENOSYS.
66311 */
66312 + oldfs = get_fs();
66313 + set_fs(USER_DS);
66314 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
66315 futex_cmpxchg_enabled = 1;
66316 + set_fs(oldfs);
66317
66318 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
66319 plist_head_init(&futex_queues[i].chain);
66320 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
66321 index 9b22d03..6295b62 100644
66322 --- a/kernel/gcov/base.c
66323 +++ b/kernel/gcov/base.c
66324 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
66325 }
66326
66327 #ifdef CONFIG_MODULES
66328 -static inline int within(void *addr, void *start, unsigned long size)
66329 -{
66330 - return ((addr >= start) && (addr < start + size));
66331 -}
66332 -
66333 /* Update list and generate events when modules are unloaded. */
66334 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66335 void *data)
66336 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
66337 prev = NULL;
66338 /* Remove entries located in module from linked list. */
66339 for (info = gcov_info_head; info; info = info->next) {
66340 - if (within(info, mod->module_core, mod->core_size)) {
66341 + if (within_module_core_rw((unsigned long)info, mod)) {
66342 if (prev)
66343 prev->next = info->next;
66344 else
66345 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
66346 index ae34bf5..4e2f3d0 100644
66347 --- a/kernel/hrtimer.c
66348 +++ b/kernel/hrtimer.c
66349 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
66350 local_irq_restore(flags);
66351 }
66352
66353 -static void run_hrtimer_softirq(struct softirq_action *h)
66354 +static void run_hrtimer_softirq(void)
66355 {
66356 hrtimer_peek_ahead_timers();
66357 }
66358 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
66359 index 01d3b70..9e4d098 100644
66360 --- a/kernel/jump_label.c
66361 +++ b/kernel/jump_label.c
66362 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
66363
66364 size = (((unsigned long)stop - (unsigned long)start)
66365 / sizeof(struct jump_entry));
66366 + pax_open_kernel();
66367 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
66368 + pax_close_kernel();
66369 }
66370
66371 static void jump_label_update(struct jump_label_key *key, int enable);
66372 @@ -340,10 +342,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
66373 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
66374 struct jump_entry *iter;
66375
66376 + pax_open_kernel();
66377 for (iter = iter_start; iter < iter_stop; iter++) {
66378 if (within_module_init(iter->code, mod))
66379 iter->code = 0;
66380 }
66381 + pax_close_kernel();
66382 }
66383
66384 static int
66385 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
66386 index 079f1d3..a407562 100644
66387 --- a/kernel/kallsyms.c
66388 +++ b/kernel/kallsyms.c
66389 @@ -11,6 +11,9 @@
66390 * Changed the compression method from stem compression to "table lookup"
66391 * compression (see scripts/kallsyms.c for a more complete description)
66392 */
66393 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66394 +#define __INCLUDED_BY_HIDESYM 1
66395 +#endif
66396 #include <linux/kallsyms.h>
66397 #include <linux/module.h>
66398 #include <linux/init.h>
66399 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
66400
66401 static inline int is_kernel_inittext(unsigned long addr)
66402 {
66403 + if (system_state != SYSTEM_BOOTING)
66404 + return 0;
66405 +
66406 if (addr >= (unsigned long)_sinittext
66407 && addr <= (unsigned long)_einittext)
66408 return 1;
66409 return 0;
66410 }
66411
66412 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66413 +#ifdef CONFIG_MODULES
66414 +static inline int is_module_text(unsigned long addr)
66415 +{
66416 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
66417 + return 1;
66418 +
66419 + addr = ktla_ktva(addr);
66420 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
66421 +}
66422 +#else
66423 +static inline int is_module_text(unsigned long addr)
66424 +{
66425 + return 0;
66426 +}
66427 +#endif
66428 +#endif
66429 +
66430 static inline int is_kernel_text(unsigned long addr)
66431 {
66432 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
66433 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
66434
66435 static inline int is_kernel(unsigned long addr)
66436 {
66437 +
66438 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66439 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
66440 + return 1;
66441 +
66442 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
66443 +#else
66444 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
66445 +#endif
66446 +
66447 return 1;
66448 return in_gate_area_no_mm(addr);
66449 }
66450
66451 static int is_ksym_addr(unsigned long addr)
66452 {
66453 +
66454 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
66455 + if (is_module_text(addr))
66456 + return 0;
66457 +#endif
66458 +
66459 if (all_var)
66460 return is_kernel(addr);
66461
66462 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
66463
66464 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
66465 {
66466 - iter->name[0] = '\0';
66467 iter->nameoff = get_symbol_offset(new_pos);
66468 iter->pos = new_pos;
66469 }
66470 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
66471 {
66472 struct kallsym_iter *iter = m->private;
66473
66474 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66475 + if (current_uid())
66476 + return 0;
66477 +#endif
66478 +
66479 /* Some debugging symbols have no name. Ignore them. */
66480 if (!iter->name[0])
66481 return 0;
66482 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
66483 struct kallsym_iter *iter;
66484 int ret;
66485
66486 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
66487 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
66488 if (!iter)
66489 return -ENOMEM;
66490 reset_iter(iter, 0);
66491 diff --git a/kernel/kexec.c b/kernel/kexec.c
66492 index 7b08867..3bac516 100644
66493 --- a/kernel/kexec.c
66494 +++ b/kernel/kexec.c
66495 @@ -1047,7 +1047,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
66496 unsigned long flags)
66497 {
66498 struct compat_kexec_segment in;
66499 - struct kexec_segment out, __user *ksegments;
66500 + struct kexec_segment out;
66501 + struct kexec_segment __user *ksegments;
66502 unsigned long i, result;
66503
66504 /* Don't allow clients that don't understand the native
66505 diff --git a/kernel/kmod.c b/kernel/kmod.c
66506 index a3a46cb..f2e42f8 100644
66507 --- a/kernel/kmod.c
66508 +++ b/kernel/kmod.c
66509 @@ -75,13 +75,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
66510 * If module auto-loading support is disabled then this function
66511 * becomes a no-operation.
66512 */
66513 -int __request_module(bool wait, const char *fmt, ...)
66514 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
66515 {
66516 - va_list args;
66517 char module_name[MODULE_NAME_LEN];
66518 unsigned int max_modprobes;
66519 int ret;
66520 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
66521 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
66522 static char *envp[] = { "HOME=/",
66523 "TERM=linux",
66524 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
66525 @@ -90,9 +89,7 @@ int __request_module(bool wait, const char *fmt, ...)
66526 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
66527 static int kmod_loop_msg;
66528
66529 - va_start(args, fmt);
66530 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
66531 - va_end(args);
66532 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
66533 if (ret >= MODULE_NAME_LEN)
66534 return -ENAMETOOLONG;
66535
66536 @@ -100,6 +97,20 @@ int __request_module(bool wait, const char *fmt, ...)
66537 if (ret)
66538 return ret;
66539
66540 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66541 + if (!current_uid()) {
66542 + /* hack to workaround consolekit/udisks stupidity */
66543 + read_lock(&tasklist_lock);
66544 + if (!strcmp(current->comm, "mount") &&
66545 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
66546 + read_unlock(&tasklist_lock);
66547 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
66548 + return -EPERM;
66549 + }
66550 + read_unlock(&tasklist_lock);
66551 + }
66552 +#endif
66553 +
66554 /* If modprobe needs a service that is in a module, we get a recursive
66555 * loop. Limit the number of running kmod threads to max_threads/2 or
66556 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
66557 @@ -135,6 +146,47 @@ int __request_module(bool wait, const char *fmt, ...)
66558 atomic_dec(&kmod_concurrent);
66559 return ret;
66560 }
66561 +
66562 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
66563 +{
66564 + va_list args;
66565 + int ret;
66566 +
66567 + va_start(args, fmt);
66568 + ret = ____request_module(wait, module_param, fmt, args);
66569 + va_end(args);
66570 +
66571 + return ret;
66572 +}
66573 +
66574 +int __request_module(bool wait, const char *fmt, ...)
66575 +{
66576 + va_list args;
66577 + int ret;
66578 +
66579 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66580 + if (current_uid()) {
66581 + char module_param[MODULE_NAME_LEN];
66582 +
66583 + memset(module_param, 0, sizeof(module_param));
66584 +
66585 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
66586 +
66587 + va_start(args, fmt);
66588 + ret = ____request_module(wait, module_param, fmt, args);
66589 + va_end(args);
66590 +
66591 + return ret;
66592 + }
66593 +#endif
66594 +
66595 + va_start(args, fmt);
66596 + ret = ____request_module(wait, NULL, fmt, args);
66597 + va_end(args);
66598 +
66599 + return ret;
66600 +}
66601 +
66602 EXPORT_SYMBOL(__request_module);
66603 #endif /* CONFIG_MODULES */
66604
66605 @@ -224,7 +276,7 @@ static int wait_for_helper(void *data)
66606 *
66607 * Thus the __user pointer cast is valid here.
66608 */
66609 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
66610 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
66611
66612 /*
66613 * If ret is 0, either ____call_usermodehelper failed and the
66614 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
66615 index c62b854..cb67968 100644
66616 --- a/kernel/kprobes.c
66617 +++ b/kernel/kprobes.c
66618 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
66619 * kernel image and loaded module images reside. This is required
66620 * so x86_64 can correctly handle the %rip-relative fixups.
66621 */
66622 - kip->insns = module_alloc(PAGE_SIZE);
66623 + kip->insns = module_alloc_exec(PAGE_SIZE);
66624 if (!kip->insns) {
66625 kfree(kip);
66626 return NULL;
66627 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
66628 */
66629 if (!list_is_singular(&kip->list)) {
66630 list_del(&kip->list);
66631 - module_free(NULL, kip->insns);
66632 + module_free_exec(NULL, kip->insns);
66633 kfree(kip);
66634 }
66635 return 1;
66636 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
66637 {
66638 int i, err = 0;
66639 unsigned long offset = 0, size = 0;
66640 - char *modname, namebuf[128];
66641 + char *modname, namebuf[KSYM_NAME_LEN];
66642 const char *symbol_name;
66643 void *addr;
66644 struct kprobe_blackpoint *kb;
66645 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
66646 const char *sym = NULL;
66647 unsigned int i = *(loff_t *) v;
66648 unsigned long offset = 0;
66649 - char *modname, namebuf[128];
66650 + char *modname, namebuf[KSYM_NAME_LEN];
66651
66652 head = &kprobe_table[i];
66653 preempt_disable();
66654 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
66655 index 4e316e1..5501eef 100644
66656 --- a/kernel/ksysfs.c
66657 +++ b/kernel/ksysfs.c
66658 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
66659 {
66660 if (count+1 > UEVENT_HELPER_PATH_LEN)
66661 return -ENOENT;
66662 + if (!capable(CAP_SYS_ADMIN))
66663 + return -EPERM;
66664 memcpy(uevent_helper, buf, count);
66665 uevent_helper[count] = '\0';
66666 if (count && uevent_helper[count-1] == '\n')
66667 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
66668 index 8889f7d..95319b7 100644
66669 --- a/kernel/lockdep.c
66670 +++ b/kernel/lockdep.c
66671 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
66672 end = (unsigned long) &_end,
66673 addr = (unsigned long) obj;
66674
66675 +#ifdef CONFIG_PAX_KERNEXEC
66676 + start = ktla_ktva(start);
66677 +#endif
66678 +
66679 /*
66680 * static variable?
66681 */
66682 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
66683 if (!static_obj(lock->key)) {
66684 debug_locks_off();
66685 printk("INFO: trying to register non-static key.\n");
66686 + printk("lock:%pS key:%pS.\n", lock, lock->key);
66687 printk("the code is fine but needs lockdep annotation.\n");
66688 printk("turning off the locking correctness validator.\n");
66689 dump_stack();
66690 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
66691 if (!class)
66692 return 0;
66693 }
66694 - atomic_inc((atomic_t *)&class->ops);
66695 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
66696 if (very_verbose(class)) {
66697 printk("\nacquire class [%p] %s", class->key, class->name);
66698 if (class->name_version > 1)
66699 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
66700 index 91c32a0..b2c71c5 100644
66701 --- a/kernel/lockdep_proc.c
66702 +++ b/kernel/lockdep_proc.c
66703 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
66704
66705 static void print_name(struct seq_file *m, struct lock_class *class)
66706 {
66707 - char str[128];
66708 + char str[KSYM_NAME_LEN];
66709 const char *name = class->name;
66710
66711 if (!name) {
66712 diff --git a/kernel/module.c b/kernel/module.c
66713 index 3d56b6f..2a22bd0 100644
66714 --- a/kernel/module.c
66715 +++ b/kernel/module.c
66716 @@ -58,6 +58,7 @@
66717 #include <linux/jump_label.h>
66718 #include <linux/pfn.h>
66719 #include <linux/bsearch.h>
66720 +#include <linux/grsecurity.h>
66721
66722 #define CREATE_TRACE_POINTS
66723 #include <trace/events/module.h>
66724 @@ -113,7 +114,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
66725
66726 /* Bounds of module allocation, for speeding __module_address.
66727 * Protected by module_mutex. */
66728 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
66729 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
66730 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
66731
66732 int register_module_notifier(struct notifier_block * nb)
66733 {
66734 @@ -277,7 +279,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66735 return true;
66736
66737 list_for_each_entry_rcu(mod, &modules, list) {
66738 - struct symsearch arr[] = {
66739 + struct symsearch modarr[] = {
66740 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
66741 NOT_GPL_ONLY, false },
66742 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
66743 @@ -299,7 +301,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
66744 #endif
66745 };
66746
66747 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
66748 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
66749 return true;
66750 }
66751 return false;
66752 @@ -431,7 +433,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
66753 static int percpu_modalloc(struct module *mod,
66754 unsigned long size, unsigned long align)
66755 {
66756 - if (align > PAGE_SIZE) {
66757 + if (align-1 >= PAGE_SIZE) {
66758 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
66759 mod->name, align, PAGE_SIZE);
66760 align = PAGE_SIZE;
66761 @@ -1001,7 +1003,7 @@ struct module_attribute module_uevent =
66762 static ssize_t show_coresize(struct module_attribute *mattr,
66763 struct module_kobject *mk, char *buffer)
66764 {
66765 - return sprintf(buffer, "%u\n", mk->mod->core_size);
66766 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
66767 }
66768
66769 static struct module_attribute modinfo_coresize =
66770 @@ -1010,7 +1012,7 @@ static struct module_attribute modinfo_coresize =
66771 static ssize_t show_initsize(struct module_attribute *mattr,
66772 struct module_kobject *mk, char *buffer)
66773 {
66774 - return sprintf(buffer, "%u\n", mk->mod->init_size);
66775 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
66776 }
66777
66778 static struct module_attribute modinfo_initsize =
66779 @@ -1224,7 +1226,7 @@ resolve_symbol_wait(struct module *mod,
66780 */
66781 #ifdef CONFIG_SYSFS
66782
66783 -#ifdef CONFIG_KALLSYMS
66784 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66785 static inline bool sect_empty(const Elf_Shdr *sect)
66786 {
66787 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
66788 @@ -1690,21 +1692,21 @@ static void set_section_ro_nx(void *base,
66789
66790 static void unset_module_core_ro_nx(struct module *mod)
66791 {
66792 - set_page_attributes(mod->module_core + mod->core_text_size,
66793 - mod->module_core + mod->core_size,
66794 + set_page_attributes(mod->module_core_rw,
66795 + mod->module_core_rw + mod->core_size_rw,
66796 set_memory_x);
66797 - set_page_attributes(mod->module_core,
66798 - mod->module_core + mod->core_ro_size,
66799 + set_page_attributes(mod->module_core_rx,
66800 + mod->module_core_rx + mod->core_size_rx,
66801 set_memory_rw);
66802 }
66803
66804 static void unset_module_init_ro_nx(struct module *mod)
66805 {
66806 - set_page_attributes(mod->module_init + mod->init_text_size,
66807 - mod->module_init + mod->init_size,
66808 + set_page_attributes(mod->module_init_rw,
66809 + mod->module_init_rw + mod->init_size_rw,
66810 set_memory_x);
66811 - set_page_attributes(mod->module_init,
66812 - mod->module_init + mod->init_ro_size,
66813 + set_page_attributes(mod->module_init_rx,
66814 + mod->module_init_rx + mod->init_size_rx,
66815 set_memory_rw);
66816 }
66817
66818 @@ -1715,14 +1717,14 @@ void set_all_modules_text_rw(void)
66819
66820 mutex_lock(&module_mutex);
66821 list_for_each_entry_rcu(mod, &modules, list) {
66822 - if ((mod->module_core) && (mod->core_text_size)) {
66823 - set_page_attributes(mod->module_core,
66824 - mod->module_core + mod->core_text_size,
66825 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66826 + set_page_attributes(mod->module_core_rx,
66827 + mod->module_core_rx + mod->core_size_rx,
66828 set_memory_rw);
66829 }
66830 - if ((mod->module_init) && (mod->init_text_size)) {
66831 - set_page_attributes(mod->module_init,
66832 - mod->module_init + mod->init_text_size,
66833 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66834 + set_page_attributes(mod->module_init_rx,
66835 + mod->module_init_rx + mod->init_size_rx,
66836 set_memory_rw);
66837 }
66838 }
66839 @@ -1736,14 +1738,14 @@ void set_all_modules_text_ro(void)
66840
66841 mutex_lock(&module_mutex);
66842 list_for_each_entry_rcu(mod, &modules, list) {
66843 - if ((mod->module_core) && (mod->core_text_size)) {
66844 - set_page_attributes(mod->module_core,
66845 - mod->module_core + mod->core_text_size,
66846 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
66847 + set_page_attributes(mod->module_core_rx,
66848 + mod->module_core_rx + mod->core_size_rx,
66849 set_memory_ro);
66850 }
66851 - if ((mod->module_init) && (mod->init_text_size)) {
66852 - set_page_attributes(mod->module_init,
66853 - mod->module_init + mod->init_text_size,
66854 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
66855 + set_page_attributes(mod->module_init_rx,
66856 + mod->module_init_rx + mod->init_size_rx,
66857 set_memory_ro);
66858 }
66859 }
66860 @@ -1789,16 +1791,19 @@ static void free_module(struct module *mod)
66861
66862 /* This may be NULL, but that's OK */
66863 unset_module_init_ro_nx(mod);
66864 - module_free(mod, mod->module_init);
66865 + module_free(mod, mod->module_init_rw);
66866 + module_free_exec(mod, mod->module_init_rx);
66867 kfree(mod->args);
66868 percpu_modfree(mod);
66869
66870 /* Free lock-classes: */
66871 - lockdep_free_key_range(mod->module_core, mod->core_size);
66872 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
66873 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
66874
66875 /* Finally, free the core (containing the module structure) */
66876 unset_module_core_ro_nx(mod);
66877 - module_free(mod, mod->module_core);
66878 + module_free_exec(mod, mod->module_core_rx);
66879 + module_free(mod, mod->module_core_rw);
66880
66881 #ifdef CONFIG_MPU
66882 update_protections(current->mm);
66883 @@ -1867,10 +1872,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66884 unsigned int i;
66885 int ret = 0;
66886 const struct kernel_symbol *ksym;
66887 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66888 + int is_fs_load = 0;
66889 + int register_filesystem_found = 0;
66890 + char *p;
66891 +
66892 + p = strstr(mod->args, "grsec_modharden_fs");
66893 + if (p) {
66894 + char *endptr = p + strlen("grsec_modharden_fs");
66895 + /* copy \0 as well */
66896 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
66897 + is_fs_load = 1;
66898 + }
66899 +#endif
66900
66901 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
66902 const char *name = info->strtab + sym[i].st_name;
66903
66904 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66905 + /* it's a real shame this will never get ripped and copied
66906 + upstream! ;(
66907 + */
66908 + if (is_fs_load && !strcmp(name, "register_filesystem"))
66909 + register_filesystem_found = 1;
66910 +#endif
66911 +
66912 switch (sym[i].st_shndx) {
66913 case SHN_COMMON:
66914 /* We compiled with -fno-common. These are not
66915 @@ -1891,7 +1917,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66916 ksym = resolve_symbol_wait(mod, info, name);
66917 /* Ok if resolved. */
66918 if (ksym && !IS_ERR(ksym)) {
66919 + pax_open_kernel();
66920 sym[i].st_value = ksym->value;
66921 + pax_close_kernel();
66922 break;
66923 }
66924
66925 @@ -1910,11 +1938,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
66926 secbase = (unsigned long)mod_percpu(mod);
66927 else
66928 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
66929 + pax_open_kernel();
66930 sym[i].st_value += secbase;
66931 + pax_close_kernel();
66932 break;
66933 }
66934 }
66935
66936 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
66937 + if (is_fs_load && !register_filesystem_found) {
66938 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
66939 + ret = -EPERM;
66940 + }
66941 +#endif
66942 +
66943 return ret;
66944 }
66945
66946 @@ -2018,22 +2055,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
66947 || s->sh_entsize != ~0UL
66948 || strstarts(sname, ".init"))
66949 continue;
66950 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
66951 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66952 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
66953 + else
66954 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
66955 pr_debug("\t%s\n", sname);
66956 }
66957 - switch (m) {
66958 - case 0: /* executable */
66959 - mod->core_size = debug_align(mod->core_size);
66960 - mod->core_text_size = mod->core_size;
66961 - break;
66962 - case 1: /* RO: text and ro-data */
66963 - mod->core_size = debug_align(mod->core_size);
66964 - mod->core_ro_size = mod->core_size;
66965 - break;
66966 - case 3: /* whole core */
66967 - mod->core_size = debug_align(mod->core_size);
66968 - break;
66969 - }
66970 }
66971
66972 pr_debug("Init section allocation order:\n");
66973 @@ -2047,23 +2074,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
66974 || s->sh_entsize != ~0UL
66975 || !strstarts(sname, ".init"))
66976 continue;
66977 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
66978 - | INIT_OFFSET_MASK);
66979 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
66980 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
66981 + else
66982 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
66983 + s->sh_entsize |= INIT_OFFSET_MASK;
66984 pr_debug("\t%s\n", sname);
66985 }
66986 - switch (m) {
66987 - case 0: /* executable */
66988 - mod->init_size = debug_align(mod->init_size);
66989 - mod->init_text_size = mod->init_size;
66990 - break;
66991 - case 1: /* RO: text and ro-data */
66992 - mod->init_size = debug_align(mod->init_size);
66993 - mod->init_ro_size = mod->init_size;
66994 - break;
66995 - case 3: /* whole init */
66996 - mod->init_size = debug_align(mod->init_size);
66997 - break;
66998 - }
66999 }
67000 }
67001
67002 @@ -2235,7 +2252,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67003
67004 /* Put symbol section at end of init part of module. */
67005 symsect->sh_flags |= SHF_ALLOC;
67006 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
67007 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
67008 info->index.sym) | INIT_OFFSET_MASK;
67009 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
67010
67011 @@ -2250,13 +2267,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
67012 }
67013
67014 /* Append room for core symbols at end of core part. */
67015 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
67016 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
67017 - mod->core_size += strtab_size;
67018 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
67019 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
67020 + mod->core_size_rx += strtab_size;
67021
67022 /* Put string table section at end of init part of module. */
67023 strsect->sh_flags |= SHF_ALLOC;
67024 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
67025 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
67026 info->index.str) | INIT_OFFSET_MASK;
67027 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
67028 }
67029 @@ -2274,12 +2291,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67030 /* Make sure we get permanent strtab: don't use info->strtab. */
67031 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
67032
67033 + pax_open_kernel();
67034 +
67035 /* Set types up while we still have access to sections. */
67036 for (i = 0; i < mod->num_symtab; i++)
67037 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
67038
67039 - mod->core_symtab = dst = mod->module_core + info->symoffs;
67040 - mod->core_strtab = s = mod->module_core + info->stroffs;
67041 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
67042 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
67043 src = mod->symtab;
67044 *dst = *src;
67045 *s++ = 0;
67046 @@ -2292,6 +2311,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
67047 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
67048 }
67049 mod->core_num_syms = ndst;
67050 +
67051 + pax_close_kernel();
67052 }
67053 #else
67054 static inline void layout_symtab(struct module *mod, struct load_info *info)
67055 @@ -2325,17 +2346,33 @@ void * __weak module_alloc(unsigned long size)
67056 return size == 0 ? NULL : vmalloc_exec(size);
67057 }
67058
67059 -static void *module_alloc_update_bounds(unsigned long size)
67060 +static void *module_alloc_update_bounds_rw(unsigned long size)
67061 {
67062 void *ret = module_alloc(size);
67063
67064 if (ret) {
67065 mutex_lock(&module_mutex);
67066 /* Update module bounds. */
67067 - if ((unsigned long)ret < module_addr_min)
67068 - module_addr_min = (unsigned long)ret;
67069 - if ((unsigned long)ret + size > module_addr_max)
67070 - module_addr_max = (unsigned long)ret + size;
67071 + if ((unsigned long)ret < module_addr_min_rw)
67072 + module_addr_min_rw = (unsigned long)ret;
67073 + if ((unsigned long)ret + size > module_addr_max_rw)
67074 + module_addr_max_rw = (unsigned long)ret + size;
67075 + mutex_unlock(&module_mutex);
67076 + }
67077 + return ret;
67078 +}
67079 +
67080 +static void *module_alloc_update_bounds_rx(unsigned long size)
67081 +{
67082 + void *ret = module_alloc_exec(size);
67083 +
67084 + if (ret) {
67085 + mutex_lock(&module_mutex);
67086 + /* Update module bounds. */
67087 + if ((unsigned long)ret < module_addr_min_rx)
67088 + module_addr_min_rx = (unsigned long)ret;
67089 + if ((unsigned long)ret + size > module_addr_max_rx)
67090 + module_addr_max_rx = (unsigned long)ret + size;
67091 mutex_unlock(&module_mutex);
67092 }
67093 return ret;
67094 @@ -2512,8 +2549,14 @@ static struct module *setup_load_info(struct load_info *info)
67095 static int check_modinfo(struct module *mod, struct load_info *info)
67096 {
67097 const char *modmagic = get_modinfo(info, "vermagic");
67098 + const char *license = get_modinfo(info, "license");
67099 int err;
67100
67101 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
67102 + if (!license || !license_is_gpl_compatible(license))
67103 + return -ENOEXEC;
67104 +#endif
67105 +
67106 /* This is allowed: modprobe --force will invalidate it. */
67107 if (!modmagic) {
67108 err = try_to_force_load(mod, "bad vermagic");
67109 @@ -2536,7 +2579,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
67110 }
67111
67112 /* Set up license info based on the info section */
67113 - set_license(mod, get_modinfo(info, "license"));
67114 + set_license(mod, license);
67115
67116 return 0;
67117 }
67118 @@ -2630,7 +2673,7 @@ static int move_module(struct module *mod, struct load_info *info)
67119 void *ptr;
67120
67121 /* Do the allocs. */
67122 - ptr = module_alloc_update_bounds(mod->core_size);
67123 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
67124 /*
67125 * The pointer to this block is stored in the module structure
67126 * which is inside the block. Just mark it as not being a
67127 @@ -2640,23 +2683,50 @@ static int move_module(struct module *mod, struct load_info *info)
67128 if (!ptr)
67129 return -ENOMEM;
67130
67131 - memset(ptr, 0, mod->core_size);
67132 - mod->module_core = ptr;
67133 + memset(ptr, 0, mod->core_size_rw);
67134 + mod->module_core_rw = ptr;
67135
67136 - ptr = module_alloc_update_bounds(mod->init_size);
67137 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
67138 /*
67139 * The pointer to this block is stored in the module structure
67140 * which is inside the block. This block doesn't need to be
67141 * scanned as it contains data and code that will be freed
67142 * after the module is initialized.
67143 */
67144 - kmemleak_ignore(ptr);
67145 - if (!ptr && mod->init_size) {
67146 - module_free(mod, mod->module_core);
67147 + kmemleak_not_leak(ptr);
67148 + if (!ptr && mod->init_size_rw) {
67149 + module_free(mod, mod->module_core_rw);
67150 return -ENOMEM;
67151 }
67152 - memset(ptr, 0, mod->init_size);
67153 - mod->module_init = ptr;
67154 + memset(ptr, 0, mod->init_size_rw);
67155 + mod->module_init_rw = ptr;
67156 +
67157 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
67158 + kmemleak_not_leak(ptr);
67159 + if (!ptr) {
67160 + module_free(mod, mod->module_init_rw);
67161 + module_free(mod, mod->module_core_rw);
67162 + return -ENOMEM;
67163 + }
67164 +
67165 + pax_open_kernel();
67166 + memset(ptr, 0, mod->core_size_rx);
67167 + pax_close_kernel();
67168 + mod->module_core_rx = ptr;
67169 +
67170 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
67171 + kmemleak_not_leak(ptr);
67172 + if (!ptr && mod->init_size_rx) {
67173 + module_free_exec(mod, mod->module_core_rx);
67174 + module_free(mod, mod->module_init_rw);
67175 + module_free(mod, mod->module_core_rw);
67176 + return -ENOMEM;
67177 + }
67178 +
67179 + pax_open_kernel();
67180 + memset(ptr, 0, mod->init_size_rx);
67181 + pax_close_kernel();
67182 + mod->module_init_rx = ptr;
67183
67184 /* Transfer each section which specifies SHF_ALLOC */
67185 pr_debug("final section addresses:\n");
67186 @@ -2667,16 +2737,45 @@ static int move_module(struct module *mod, struct load_info *info)
67187 if (!(shdr->sh_flags & SHF_ALLOC))
67188 continue;
67189
67190 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
67191 - dest = mod->module_init
67192 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67193 - else
67194 - dest = mod->module_core + shdr->sh_entsize;
67195 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
67196 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67197 + dest = mod->module_init_rw
67198 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67199 + else
67200 + dest = mod->module_init_rx
67201 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
67202 + } else {
67203 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
67204 + dest = mod->module_core_rw + shdr->sh_entsize;
67205 + else
67206 + dest = mod->module_core_rx + shdr->sh_entsize;
67207 + }
67208 +
67209 + if (shdr->sh_type != SHT_NOBITS) {
67210 +
67211 +#ifdef CONFIG_PAX_KERNEXEC
67212 +#ifdef CONFIG_X86_64
67213 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
67214 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
67215 +#endif
67216 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
67217 + pax_open_kernel();
67218 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67219 + pax_close_kernel();
67220 + } else
67221 +#endif
67222
67223 - if (shdr->sh_type != SHT_NOBITS)
67224 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
67225 + }
67226 /* Update sh_addr to point to copy in image. */
67227 - shdr->sh_addr = (unsigned long)dest;
67228 +
67229 +#ifdef CONFIG_PAX_KERNEXEC
67230 + if (shdr->sh_flags & SHF_EXECINSTR)
67231 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
67232 + else
67233 +#endif
67234 +
67235 + shdr->sh_addr = (unsigned long)dest;
67236 pr_debug("\t0x%lx %s\n",
67237 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
67238 }
67239 @@ -2727,12 +2826,12 @@ static void flush_module_icache(const struct module *mod)
67240 * Do it before processing of module parameters, so the module
67241 * can provide parameter accessor functions of its own.
67242 */
67243 - if (mod->module_init)
67244 - flush_icache_range((unsigned long)mod->module_init,
67245 - (unsigned long)mod->module_init
67246 - + mod->init_size);
67247 - flush_icache_range((unsigned long)mod->module_core,
67248 - (unsigned long)mod->module_core + mod->core_size);
67249 + if (mod->module_init_rx)
67250 + flush_icache_range((unsigned long)mod->module_init_rx,
67251 + (unsigned long)mod->module_init_rx
67252 + + mod->init_size_rx);
67253 + flush_icache_range((unsigned long)mod->module_core_rx,
67254 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
67255
67256 set_fs(old_fs);
67257 }
67258 @@ -2802,8 +2901,10 @@ out:
67259 static void module_deallocate(struct module *mod, struct load_info *info)
67260 {
67261 percpu_modfree(mod);
67262 - module_free(mod, mod->module_init);
67263 - module_free(mod, mod->module_core);
67264 + module_free_exec(mod, mod->module_init_rx);
67265 + module_free_exec(mod, mod->module_core_rx);
67266 + module_free(mod, mod->module_init_rw);
67267 + module_free(mod, mod->module_core_rw);
67268 }
67269
67270 int __weak module_finalize(const Elf_Ehdr *hdr,
67271 @@ -2867,9 +2968,38 @@ static struct module *load_module(void __user *umod,
67272 if (err)
67273 goto free_unload;
67274
67275 + /* Now copy in args */
67276 + mod->args = strndup_user(uargs, ~0UL >> 1);
67277 + if (IS_ERR(mod->args)) {
67278 + err = PTR_ERR(mod->args);
67279 + goto free_unload;
67280 + }
67281 +
67282 /* Set up MODINFO_ATTR fields */
67283 setup_modinfo(mod, &info);
67284
67285 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67286 + {
67287 + char *p, *p2;
67288 +
67289 + if (strstr(mod->args, "grsec_modharden_netdev")) {
67290 + 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);
67291 + err = -EPERM;
67292 + goto free_modinfo;
67293 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
67294 + p += strlen("grsec_modharden_normal");
67295 + p2 = strstr(p, "_");
67296 + if (p2) {
67297 + *p2 = '\0';
67298 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
67299 + *p2 = '_';
67300 + }
67301 + err = -EPERM;
67302 + goto free_modinfo;
67303 + }
67304 + }
67305 +#endif
67306 +
67307 /* Fix up syms, so that st_value is a pointer to location. */
67308 err = simplify_symbols(mod, &info);
67309 if (err < 0)
67310 @@ -2885,13 +3015,6 @@ static struct module *load_module(void __user *umod,
67311
67312 flush_module_icache(mod);
67313
67314 - /* Now copy in args */
67315 - mod->args = strndup_user(uargs, ~0UL >> 1);
67316 - if (IS_ERR(mod->args)) {
67317 - err = PTR_ERR(mod->args);
67318 - goto free_arch_cleanup;
67319 - }
67320 -
67321 /* Mark state as coming so strong_try_module_get() ignores us. */
67322 mod->state = MODULE_STATE_COMING;
67323
67324 @@ -2948,11 +3071,10 @@ static struct module *load_module(void __user *umod,
67325 unlock:
67326 mutex_unlock(&module_mutex);
67327 synchronize_sched();
67328 - kfree(mod->args);
67329 - free_arch_cleanup:
67330 module_arch_cleanup(mod);
67331 free_modinfo:
67332 free_modinfo(mod);
67333 + kfree(mod->args);
67334 free_unload:
67335 module_unload_free(mod);
67336 free_module:
67337 @@ -2993,16 +3115,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67338 MODULE_STATE_COMING, mod);
67339
67340 /* Set RO and NX regions for core */
67341 - set_section_ro_nx(mod->module_core,
67342 - mod->core_text_size,
67343 - mod->core_ro_size,
67344 - mod->core_size);
67345 + set_section_ro_nx(mod->module_core_rx,
67346 + mod->core_size_rx,
67347 + mod->core_size_rx,
67348 + mod->core_size_rx);
67349
67350 /* Set RO and NX regions for init */
67351 - set_section_ro_nx(mod->module_init,
67352 - mod->init_text_size,
67353 - mod->init_ro_size,
67354 - mod->init_size);
67355 + set_section_ro_nx(mod->module_init_rx,
67356 + mod->init_size_rx,
67357 + mod->init_size_rx,
67358 + mod->init_size_rx);
67359
67360 do_mod_ctors(mod);
67361 /* Start the module */
67362 @@ -3048,11 +3170,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
67363 mod->strtab = mod->core_strtab;
67364 #endif
67365 unset_module_init_ro_nx(mod);
67366 - module_free(mod, mod->module_init);
67367 - mod->module_init = NULL;
67368 - mod->init_size = 0;
67369 - mod->init_ro_size = 0;
67370 - mod->init_text_size = 0;
67371 + module_free(mod, mod->module_init_rw);
67372 + module_free_exec(mod, mod->module_init_rx);
67373 + mod->module_init_rw = NULL;
67374 + mod->module_init_rx = NULL;
67375 + mod->init_size_rw = 0;
67376 + mod->init_size_rx = 0;
67377 mutex_unlock(&module_mutex);
67378
67379 return 0;
67380 @@ -3083,10 +3206,16 @@ static const char *get_ksymbol(struct module *mod,
67381 unsigned long nextval;
67382
67383 /* At worse, next value is at end of module */
67384 - if (within_module_init(addr, mod))
67385 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
67386 + if (within_module_init_rx(addr, mod))
67387 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
67388 + else if (within_module_init_rw(addr, mod))
67389 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
67390 + else if (within_module_core_rx(addr, mod))
67391 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
67392 + else if (within_module_core_rw(addr, mod))
67393 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
67394 else
67395 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
67396 + return NULL;
67397
67398 /* Scan for closest preceding symbol, and next symbol. (ELF
67399 starts real symbols at 1). */
67400 @@ -3321,7 +3450,7 @@ static int m_show(struct seq_file *m, void *p)
67401 char buf[8];
67402
67403 seq_printf(m, "%s %u",
67404 - mod->name, mod->init_size + mod->core_size);
67405 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
67406 print_unload_info(m, mod);
67407
67408 /* Informative for users. */
67409 @@ -3330,7 +3459,7 @@ static int m_show(struct seq_file *m, void *p)
67410 mod->state == MODULE_STATE_COMING ? "Loading":
67411 "Live");
67412 /* Used by oprofile and other similar tools. */
67413 - seq_printf(m, " 0x%pK", mod->module_core);
67414 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
67415
67416 /* Taints info */
67417 if (mod->taints)
67418 @@ -3366,7 +3495,17 @@ static const struct file_operations proc_modules_operations = {
67419
67420 static int __init proc_modules_init(void)
67421 {
67422 +#ifndef CONFIG_GRKERNSEC_HIDESYM
67423 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67424 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67425 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67426 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
67427 +#else
67428 proc_create("modules", 0, NULL, &proc_modules_operations);
67429 +#endif
67430 +#else
67431 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
67432 +#endif
67433 return 0;
67434 }
67435 module_init(proc_modules_init);
67436 @@ -3425,12 +3564,12 @@ struct module *__module_address(unsigned long addr)
67437 {
67438 struct module *mod;
67439
67440 - if (addr < module_addr_min || addr > module_addr_max)
67441 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
67442 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
67443 return NULL;
67444
67445 list_for_each_entry_rcu(mod, &modules, list)
67446 - if (within_module_core(addr, mod)
67447 - || within_module_init(addr, mod))
67448 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
67449 return mod;
67450 return NULL;
67451 }
67452 @@ -3464,11 +3603,20 @@ bool is_module_text_address(unsigned long addr)
67453 */
67454 struct module *__module_text_address(unsigned long addr)
67455 {
67456 - struct module *mod = __module_address(addr);
67457 + struct module *mod;
67458 +
67459 +#ifdef CONFIG_X86_32
67460 + addr = ktla_ktva(addr);
67461 +#endif
67462 +
67463 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
67464 + return NULL;
67465 +
67466 + mod = __module_address(addr);
67467 +
67468 if (mod) {
67469 /* Make sure it's within the text section. */
67470 - if (!within(addr, mod->module_init, mod->init_text_size)
67471 - && !within(addr, mod->module_core, mod->core_text_size))
67472 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
67473 mod = NULL;
67474 }
67475 return mod;
67476 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
67477 index 7e3443f..b2a1e6b 100644
67478 --- a/kernel/mutex-debug.c
67479 +++ b/kernel/mutex-debug.c
67480 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
67481 }
67482
67483 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67484 - struct thread_info *ti)
67485 + struct task_struct *task)
67486 {
67487 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
67488
67489 /* Mark the current thread as blocked on the lock: */
67490 - ti->task->blocked_on = waiter;
67491 + task->blocked_on = waiter;
67492 }
67493
67494 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67495 - struct thread_info *ti)
67496 + struct task_struct *task)
67497 {
67498 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
67499 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
67500 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
67501 - ti->task->blocked_on = NULL;
67502 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
67503 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
67504 + task->blocked_on = NULL;
67505
67506 list_del_init(&waiter->list);
67507 waiter->task = NULL;
67508 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
67509 index 0799fd3..d06ae3b 100644
67510 --- a/kernel/mutex-debug.h
67511 +++ b/kernel/mutex-debug.h
67512 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
67513 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
67514 extern void debug_mutex_add_waiter(struct mutex *lock,
67515 struct mutex_waiter *waiter,
67516 - struct thread_info *ti);
67517 + struct task_struct *task);
67518 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
67519 - struct thread_info *ti);
67520 + struct task_struct *task);
67521 extern void debug_mutex_unlock(struct mutex *lock);
67522 extern void debug_mutex_init(struct mutex *lock, const char *name,
67523 struct lock_class_key *key);
67524 diff --git a/kernel/mutex.c b/kernel/mutex.c
67525 index 89096dd..f91ebc5 100644
67526 --- a/kernel/mutex.c
67527 +++ b/kernel/mutex.c
67528 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67529 spin_lock_mutex(&lock->wait_lock, flags);
67530
67531 debug_mutex_lock_common(lock, &waiter);
67532 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
67533 + debug_mutex_add_waiter(lock, &waiter, task);
67534
67535 /* add waiting tasks to the end of the waitqueue (FIFO): */
67536 list_add_tail(&waiter.list, &lock->wait_list);
67537 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67538 * TASK_UNINTERRUPTIBLE case.)
67539 */
67540 if (unlikely(signal_pending_state(state, task))) {
67541 - mutex_remove_waiter(lock, &waiter,
67542 - task_thread_info(task));
67543 + mutex_remove_waiter(lock, &waiter, task);
67544 mutex_release(&lock->dep_map, 1, ip);
67545 spin_unlock_mutex(&lock->wait_lock, flags);
67546
67547 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
67548 done:
67549 lock_acquired(&lock->dep_map, ip);
67550 /* got the lock - rejoice! */
67551 - mutex_remove_waiter(lock, &waiter, current_thread_info());
67552 + mutex_remove_waiter(lock, &waiter, task);
67553 mutex_set_owner(lock);
67554
67555 /* set it to 0 if there are no waiters left: */
67556 diff --git a/kernel/padata.c b/kernel/padata.c
67557 index b452599..5d68f4e 100644
67558 --- a/kernel/padata.c
67559 +++ b/kernel/padata.c
67560 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
67561 padata->pd = pd;
67562 padata->cb_cpu = cb_cpu;
67563
67564 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
67565 - atomic_set(&pd->seq_nr, -1);
67566 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
67567 + atomic_set_unchecked(&pd->seq_nr, -1);
67568
67569 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
67570 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
67571
67572 target_cpu = padata_cpu_hash(padata);
67573 queue = per_cpu_ptr(pd->pqueue, target_cpu);
67574 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
67575 padata_init_pqueues(pd);
67576 padata_init_squeues(pd);
67577 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
67578 - atomic_set(&pd->seq_nr, -1);
67579 + atomic_set_unchecked(&pd->seq_nr, -1);
67580 atomic_set(&pd->reorder_objects, 0);
67581 atomic_set(&pd->refcnt, 0);
67582 pd->pinst = pinst;
67583 diff --git a/kernel/panic.c b/kernel/panic.c
67584 index 8ed89a1..e83856a 100644
67585 --- a/kernel/panic.c
67586 +++ b/kernel/panic.c
67587 @@ -402,7 +402,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
67588 const char *board;
67589
67590 printk(KERN_WARNING "------------[ cut here ]------------\n");
67591 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
67592 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
67593 board = dmi_get_system_info(DMI_PRODUCT_NAME);
67594 if (board)
67595 printk(KERN_WARNING "Hardware name: %s\n", board);
67596 @@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
67597 */
67598 void __stack_chk_fail(void)
67599 {
67600 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
67601 + dump_stack();
67602 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
67603 __builtin_return_address(0));
67604 }
67605 EXPORT_SYMBOL(__stack_chk_fail);
67606 diff --git a/kernel/pid.c b/kernel/pid.c
67607 index 9f08dfa..6765c40 100644
67608 --- a/kernel/pid.c
67609 +++ b/kernel/pid.c
67610 @@ -33,6 +33,7 @@
67611 #include <linux/rculist.h>
67612 #include <linux/bootmem.h>
67613 #include <linux/hash.h>
67614 +#include <linux/security.h>
67615 #include <linux/pid_namespace.h>
67616 #include <linux/init_task.h>
67617 #include <linux/syscalls.h>
67618 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
67619
67620 int pid_max = PID_MAX_DEFAULT;
67621
67622 -#define RESERVED_PIDS 300
67623 +#define RESERVED_PIDS 500
67624
67625 int pid_max_min = RESERVED_PIDS + 1;
67626 int pid_max_max = PID_MAX_LIMIT;
67627 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
67628 */
67629 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
67630 {
67631 + struct task_struct *task;
67632 +
67633 rcu_lockdep_assert(rcu_read_lock_held(),
67634 "find_task_by_pid_ns() needs rcu_read_lock()"
67635 " protection");
67636 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67637 +
67638 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
67639 +
67640 + if (gr_pid_is_chrooted(task))
67641 + return NULL;
67642 +
67643 + return task;
67644 }
67645
67646 struct task_struct *find_task_by_vpid(pid_t vnr)
67647 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
67648 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
67649 }
67650
67651 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
67652 +{
67653 + rcu_lockdep_assert(rcu_read_lock_held(),
67654 + "find_task_by_pid_ns() needs rcu_read_lock()"
67655 + " protection");
67656 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
67657 +}
67658 +
67659 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
67660 {
67661 struct pid *pid;
67662 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
67663 index 125cb67..a4d1c30 100644
67664 --- a/kernel/posix-cpu-timers.c
67665 +++ b/kernel/posix-cpu-timers.c
67666 @@ -6,6 +6,7 @@
67667 #include <linux/posix-timers.h>
67668 #include <linux/errno.h>
67669 #include <linux/math64.h>
67670 +#include <linux/security.h>
67671 #include <asm/uaccess.h>
67672 #include <linux/kernel_stat.h>
67673 #include <trace/events/timer.h>
67674 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
67675
67676 static __init int init_posix_cpu_timers(void)
67677 {
67678 - struct k_clock process = {
67679 + static struct k_clock process = {
67680 .clock_getres = process_cpu_clock_getres,
67681 .clock_get = process_cpu_clock_get,
67682 .timer_create = process_cpu_timer_create,
67683 .nsleep = process_cpu_nsleep,
67684 .nsleep_restart = process_cpu_nsleep_restart,
67685 };
67686 - struct k_clock thread = {
67687 + static struct k_clock thread = {
67688 .clock_getres = thread_cpu_clock_getres,
67689 .clock_get = thread_cpu_clock_get,
67690 .timer_create = thread_cpu_timer_create,
67691 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
67692 index 69185ae..cc2847a 100644
67693 --- a/kernel/posix-timers.c
67694 +++ b/kernel/posix-timers.c
67695 @@ -43,6 +43,7 @@
67696 #include <linux/idr.h>
67697 #include <linux/posix-clock.h>
67698 #include <linux/posix-timers.h>
67699 +#include <linux/grsecurity.h>
67700 #include <linux/syscalls.h>
67701 #include <linux/wait.h>
67702 #include <linux/workqueue.h>
67703 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
67704 * which we beg off on and pass to do_sys_settimeofday().
67705 */
67706
67707 -static struct k_clock posix_clocks[MAX_CLOCKS];
67708 +static struct k_clock *posix_clocks[MAX_CLOCKS];
67709
67710 /*
67711 * These ones are defined below.
67712 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
67713 */
67714 static __init int init_posix_timers(void)
67715 {
67716 - struct k_clock clock_realtime = {
67717 + static struct k_clock clock_realtime = {
67718 .clock_getres = hrtimer_get_res,
67719 .clock_get = posix_clock_realtime_get,
67720 .clock_set = posix_clock_realtime_set,
67721 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
67722 .timer_get = common_timer_get,
67723 .timer_del = common_timer_del,
67724 };
67725 - struct k_clock clock_monotonic = {
67726 + static struct k_clock clock_monotonic = {
67727 .clock_getres = hrtimer_get_res,
67728 .clock_get = posix_ktime_get_ts,
67729 .nsleep = common_nsleep,
67730 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
67731 .timer_get = common_timer_get,
67732 .timer_del = common_timer_del,
67733 };
67734 - struct k_clock clock_monotonic_raw = {
67735 + static struct k_clock clock_monotonic_raw = {
67736 .clock_getres = hrtimer_get_res,
67737 .clock_get = posix_get_monotonic_raw,
67738 };
67739 - struct k_clock clock_realtime_coarse = {
67740 + static struct k_clock clock_realtime_coarse = {
67741 .clock_getres = posix_get_coarse_res,
67742 .clock_get = posix_get_realtime_coarse,
67743 };
67744 - struct k_clock clock_monotonic_coarse = {
67745 + static struct k_clock clock_monotonic_coarse = {
67746 .clock_getres = posix_get_coarse_res,
67747 .clock_get = posix_get_monotonic_coarse,
67748 };
67749 - struct k_clock clock_boottime = {
67750 + static struct k_clock clock_boottime = {
67751 .clock_getres = hrtimer_get_res,
67752 .clock_get = posix_get_boottime,
67753 .nsleep = common_nsleep,
67754 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
67755 return;
67756 }
67757
67758 - posix_clocks[clock_id] = *new_clock;
67759 + posix_clocks[clock_id] = new_clock;
67760 }
67761 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
67762
67763 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
67764 return (id & CLOCKFD_MASK) == CLOCKFD ?
67765 &clock_posix_dynamic : &clock_posix_cpu;
67766
67767 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
67768 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
67769 return NULL;
67770 - return &posix_clocks[id];
67771 + return posix_clocks[id];
67772 }
67773
67774 static int common_timer_create(struct k_itimer *new_timer)
67775 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
67776 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
67777 return -EFAULT;
67778
67779 + /* only the CLOCK_REALTIME clock can be set, all other clocks
67780 + have their clock_set fptr set to a nosettime dummy function
67781 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
67782 + call common_clock_set, which calls do_sys_settimeofday, which
67783 + we hook
67784 + */
67785 +
67786 return kc->clock_set(which_clock, &new_tp);
67787 }
67788
67789 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
67790 index d523593..68197a4 100644
67791 --- a/kernel/power/poweroff.c
67792 +++ b/kernel/power/poweroff.c
67793 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
67794 .enable_mask = SYSRQ_ENABLE_BOOT,
67795 };
67796
67797 -static int pm_sysrq_init(void)
67798 +static int __init pm_sysrq_init(void)
67799 {
67800 register_sysrq_key('o', &sysrq_poweroff_op);
67801 return 0;
67802 diff --git a/kernel/power/process.c b/kernel/power/process.c
67803 index 7aac07a..2d3c6dc 100644
67804 --- a/kernel/power/process.c
67805 +++ b/kernel/power/process.c
67806 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
67807 u64 elapsed_csecs64;
67808 unsigned int elapsed_csecs;
67809 bool wakeup = false;
67810 + bool timedout = false;
67811
67812 do_gettimeofday(&start);
67813
67814 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
67815
67816 while (true) {
67817 todo = 0;
67818 + if (time_after(jiffies, end_time))
67819 + timedout = true;
67820 read_lock(&tasklist_lock);
67821 do_each_thread(g, p) {
67822 if (p == current || !freeze_task(p))
67823 @@ -60,9 +63,13 @@ static int try_to_freeze_tasks(bool user_only)
67824 * try_to_stop() after schedule() in ptrace/signal
67825 * stop sees TIF_FREEZE.
67826 */
67827 - if (!task_is_stopped_or_traced(p) &&
67828 - !freezer_should_skip(p))
67829 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
67830 todo++;
67831 + if (timedout) {
67832 + printk(KERN_ERR "Task refusing to freeze:\n");
67833 + sched_show_task(p);
67834 + }
67835 + }
67836 } while_each_thread(g, p);
67837 read_unlock(&tasklist_lock);
67838
67839 @@ -71,7 +78,7 @@ static int try_to_freeze_tasks(bool user_only)
67840 todo += wq_busy;
67841 }
67842
67843 - if (!todo || time_after(jiffies, end_time))
67844 + if (!todo || timedout)
67845 break;
67846
67847 if (pm_wakeup_pending()) {
67848 diff --git a/kernel/printk.c b/kernel/printk.c
67849 index 32690a0..cd7c798 100644
67850 --- a/kernel/printk.c
67851 +++ b/kernel/printk.c
67852 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
67853 if (from_file && type != SYSLOG_ACTION_OPEN)
67854 return 0;
67855
67856 +#ifdef CONFIG_GRKERNSEC_DMESG
67857 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
67858 + return -EPERM;
67859 +#endif
67860 +
67861 if (syslog_action_restricted(type)) {
67862 if (capable(CAP_SYSLOG))
67863 return 0;
67864 diff --git a/kernel/profile.c b/kernel/profile.c
67865 index 76b8e77..a2930e8 100644
67866 --- a/kernel/profile.c
67867 +++ b/kernel/profile.c
67868 @@ -39,7 +39,7 @@ struct profile_hit {
67869 /* Oprofile timer tick hook */
67870 static int (*timer_hook)(struct pt_regs *) __read_mostly;
67871
67872 -static atomic_t *prof_buffer;
67873 +static atomic_unchecked_t *prof_buffer;
67874 static unsigned long prof_len, prof_shift;
67875
67876 int prof_on __read_mostly;
67877 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
67878 hits[i].pc = 0;
67879 continue;
67880 }
67881 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67882 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67883 hits[i].hits = hits[i].pc = 0;
67884 }
67885 }
67886 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67887 * Add the current hit(s) and flush the write-queue out
67888 * to the global buffer:
67889 */
67890 - atomic_add(nr_hits, &prof_buffer[pc]);
67891 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
67892 for (i = 0; i < NR_PROFILE_HIT; ++i) {
67893 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
67894 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
67895 hits[i].pc = hits[i].hits = 0;
67896 }
67897 out:
67898 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
67899 {
67900 unsigned long pc;
67901 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
67902 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67903 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
67904 }
67905 #endif /* !CONFIG_SMP */
67906
67907 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
67908 return -EFAULT;
67909 buf++; p++; count--; read++;
67910 }
67911 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
67912 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
67913 if (copy_to_user(buf, (void *)pnt, count))
67914 return -EFAULT;
67915 read += count;
67916 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
67917 }
67918 #endif
67919 profile_discard_flip_buffers();
67920 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
67921 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
67922 return count;
67923 }
67924
67925 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
67926 index 00ab2ca..d237f61 100644
67927 --- a/kernel/ptrace.c
67928 +++ b/kernel/ptrace.c
67929 @@ -285,7 +285,7 @@ static int ptrace_attach(struct task_struct *task, long request,
67930 task->ptrace = PT_PTRACED;
67931 if (seize)
67932 task->ptrace |= PT_SEIZED;
67933 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
67934 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
67935 task->ptrace |= PT_PTRACE_CAP;
67936
67937 __ptrace_link(task, current);
67938 @@ -491,7 +491,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
67939 break;
67940 return -EIO;
67941 }
67942 - if (copy_to_user(dst, buf, retval))
67943 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
67944 return -EFAULT;
67945 copied += retval;
67946 src += retval;
67947 @@ -688,7 +688,7 @@ int ptrace_request(struct task_struct *child, long request,
67948 bool seized = child->ptrace & PT_SEIZED;
67949 int ret = -EIO;
67950 siginfo_t siginfo, *si;
67951 - void __user *datavp = (void __user *) data;
67952 + void __user *datavp = (__force void __user *) data;
67953 unsigned long __user *datalp = datavp;
67954 unsigned long flags;
67955
67956 @@ -890,14 +890,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
67957 goto out;
67958 }
67959
67960 + if (gr_handle_ptrace(child, request)) {
67961 + ret = -EPERM;
67962 + goto out_put_task_struct;
67963 + }
67964 +
67965 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67966 ret = ptrace_attach(child, request, data);
67967 /*
67968 * Some architectures need to do book-keeping after
67969 * a ptrace attach.
67970 */
67971 - if (!ret)
67972 + if (!ret) {
67973 arch_ptrace_attach(child);
67974 + gr_audit_ptrace(child);
67975 + }
67976 goto out_put_task_struct;
67977 }
67978
67979 @@ -923,7 +930,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
67980 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
67981 if (copied != sizeof(tmp))
67982 return -EIO;
67983 - return put_user(tmp, (unsigned long __user *)data);
67984 + return put_user(tmp, (__force unsigned long __user *)data);
67985 }
67986
67987 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
67988 @@ -1033,14 +1040,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67989 goto out;
67990 }
67991
67992 + if (gr_handle_ptrace(child, request)) {
67993 + ret = -EPERM;
67994 + goto out_put_task_struct;
67995 + }
67996 +
67997 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67998 ret = ptrace_attach(child, request, data);
67999 /*
68000 * Some architectures need to do book-keeping after
68001 * a ptrace attach.
68002 */
68003 - if (!ret)
68004 + if (!ret) {
68005 arch_ptrace_attach(child);
68006 + gr_audit_ptrace(child);
68007 + }
68008 goto out_put_task_struct;
68009 }
68010
68011 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
68012 index 977296d..c4744dc 100644
68013 --- a/kernel/rcutiny.c
68014 +++ b/kernel/rcutiny.c
68015 @@ -46,7 +46,7 @@
68016 struct rcu_ctrlblk;
68017 static void invoke_rcu_callbacks(void);
68018 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
68019 -static void rcu_process_callbacks(struct softirq_action *unused);
68020 +static void rcu_process_callbacks(void);
68021 static void __call_rcu(struct rcu_head *head,
68022 void (*func)(struct rcu_head *rcu),
68023 struct rcu_ctrlblk *rcp);
68024 @@ -297,7 +297,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
68025 rcu_is_callbacks_kthread()));
68026 }
68027
68028 -static void rcu_process_callbacks(struct softirq_action *unused)
68029 +static void rcu_process_callbacks(void)
68030 {
68031 __rcu_process_callbacks(&rcu_sched_ctrlblk);
68032 __rcu_process_callbacks(&rcu_bh_ctrlblk);
68033 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
68034 index 9cb1ae4..aac7d3e 100644
68035 --- a/kernel/rcutiny_plugin.h
68036 +++ b/kernel/rcutiny_plugin.h
68037 @@ -920,7 +920,7 @@ static int rcu_kthread(void *arg)
68038 have_rcu_kthread_work = morework;
68039 local_irq_restore(flags);
68040 if (work)
68041 - rcu_process_callbacks(NULL);
68042 + rcu_process_callbacks();
68043 schedule_timeout_interruptible(1); /* Leave CPU for others. */
68044 }
68045
68046 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
68047 index a58ac28..196a3d8 100644
68048 --- a/kernel/rcutorture.c
68049 +++ b/kernel/rcutorture.c
68050 @@ -148,12 +148,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
68051 { 0 };
68052 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
68053 { 0 };
68054 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68055 -static atomic_t n_rcu_torture_alloc;
68056 -static atomic_t n_rcu_torture_alloc_fail;
68057 -static atomic_t n_rcu_torture_free;
68058 -static atomic_t n_rcu_torture_mberror;
68059 -static atomic_t n_rcu_torture_error;
68060 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
68061 +static atomic_unchecked_t n_rcu_torture_alloc;
68062 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
68063 +static atomic_unchecked_t n_rcu_torture_free;
68064 +static atomic_unchecked_t n_rcu_torture_mberror;
68065 +static atomic_unchecked_t n_rcu_torture_error;
68066 static long n_rcu_torture_boost_ktrerror;
68067 static long n_rcu_torture_boost_rterror;
68068 static long n_rcu_torture_boost_failure;
68069 @@ -243,11 +243,11 @@ rcu_torture_alloc(void)
68070
68071 spin_lock_bh(&rcu_torture_lock);
68072 if (list_empty(&rcu_torture_freelist)) {
68073 - atomic_inc(&n_rcu_torture_alloc_fail);
68074 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
68075 spin_unlock_bh(&rcu_torture_lock);
68076 return NULL;
68077 }
68078 - atomic_inc(&n_rcu_torture_alloc);
68079 + atomic_inc_unchecked(&n_rcu_torture_alloc);
68080 p = rcu_torture_freelist.next;
68081 list_del_init(p);
68082 spin_unlock_bh(&rcu_torture_lock);
68083 @@ -260,7 +260,7 @@ rcu_torture_alloc(void)
68084 static void
68085 rcu_torture_free(struct rcu_torture *p)
68086 {
68087 - atomic_inc(&n_rcu_torture_free);
68088 + atomic_inc_unchecked(&n_rcu_torture_free);
68089 spin_lock_bh(&rcu_torture_lock);
68090 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
68091 spin_unlock_bh(&rcu_torture_lock);
68092 @@ -380,7 +380,7 @@ rcu_torture_cb(struct rcu_head *p)
68093 i = rp->rtort_pipe_count;
68094 if (i > RCU_TORTURE_PIPE_LEN)
68095 i = RCU_TORTURE_PIPE_LEN;
68096 - atomic_inc(&rcu_torture_wcount[i]);
68097 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68098 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68099 rp->rtort_mbtest = 0;
68100 rcu_torture_free(rp);
68101 @@ -427,7 +427,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
68102 i = rp->rtort_pipe_count;
68103 if (i > RCU_TORTURE_PIPE_LEN)
68104 i = RCU_TORTURE_PIPE_LEN;
68105 - atomic_inc(&rcu_torture_wcount[i]);
68106 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68107 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
68108 rp->rtort_mbtest = 0;
68109 list_del(&rp->rtort_free);
68110 @@ -916,7 +916,7 @@ rcu_torture_writer(void *arg)
68111 i = old_rp->rtort_pipe_count;
68112 if (i > RCU_TORTURE_PIPE_LEN)
68113 i = RCU_TORTURE_PIPE_LEN;
68114 - atomic_inc(&rcu_torture_wcount[i]);
68115 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
68116 old_rp->rtort_pipe_count++;
68117 cur_ops->deferred_free(old_rp);
68118 }
68119 @@ -997,7 +997,7 @@ static void rcu_torture_timer(unsigned long unused)
68120 return;
68121 }
68122 if (p->rtort_mbtest == 0)
68123 - atomic_inc(&n_rcu_torture_mberror);
68124 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68125 spin_lock(&rand_lock);
68126 cur_ops->read_delay(&rand);
68127 n_rcu_torture_timers++;
68128 @@ -1061,7 +1061,7 @@ rcu_torture_reader(void *arg)
68129 continue;
68130 }
68131 if (p->rtort_mbtest == 0)
68132 - atomic_inc(&n_rcu_torture_mberror);
68133 + atomic_inc_unchecked(&n_rcu_torture_mberror);
68134 cur_ops->read_delay(&rand);
68135 preempt_disable();
68136 pipe_count = p->rtort_pipe_count;
68137 @@ -1123,10 +1123,10 @@ rcu_torture_printk(char *page)
68138 rcu_torture_current,
68139 rcu_torture_current_version,
68140 list_empty(&rcu_torture_freelist),
68141 - atomic_read(&n_rcu_torture_alloc),
68142 - atomic_read(&n_rcu_torture_alloc_fail),
68143 - atomic_read(&n_rcu_torture_free),
68144 - atomic_read(&n_rcu_torture_mberror),
68145 + atomic_read_unchecked(&n_rcu_torture_alloc),
68146 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
68147 + atomic_read_unchecked(&n_rcu_torture_free),
68148 + atomic_read_unchecked(&n_rcu_torture_mberror),
68149 n_rcu_torture_boost_ktrerror,
68150 n_rcu_torture_boost_rterror,
68151 n_rcu_torture_boost_failure,
68152 @@ -1136,7 +1136,7 @@ rcu_torture_printk(char *page)
68153 n_online_attempts,
68154 n_offline_successes,
68155 n_offline_attempts);
68156 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
68157 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
68158 n_rcu_torture_boost_ktrerror != 0 ||
68159 n_rcu_torture_boost_rterror != 0 ||
68160 n_rcu_torture_boost_failure != 0)
68161 @@ -1144,7 +1144,7 @@ rcu_torture_printk(char *page)
68162 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
68163 if (i > 1) {
68164 cnt += sprintf(&page[cnt], "!!! ");
68165 - atomic_inc(&n_rcu_torture_error);
68166 + atomic_inc_unchecked(&n_rcu_torture_error);
68167 WARN_ON_ONCE(1);
68168 }
68169 cnt += sprintf(&page[cnt], "Reader Pipe: ");
68170 @@ -1158,7 +1158,7 @@ rcu_torture_printk(char *page)
68171 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
68172 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68173 cnt += sprintf(&page[cnt], " %d",
68174 - atomic_read(&rcu_torture_wcount[i]));
68175 + atomic_read_unchecked(&rcu_torture_wcount[i]));
68176 }
68177 cnt += sprintf(&page[cnt], "\n");
68178 if (cur_ops->stats)
68179 @@ -1600,7 +1600,7 @@ rcu_torture_cleanup(void)
68180
68181 if (cur_ops->cleanup)
68182 cur_ops->cleanup();
68183 - if (atomic_read(&n_rcu_torture_error))
68184 + if (atomic_read_unchecked(&n_rcu_torture_error))
68185 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
68186 else
68187 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
68188 @@ -1664,17 +1664,17 @@ rcu_torture_init(void)
68189
68190 rcu_torture_current = NULL;
68191 rcu_torture_current_version = 0;
68192 - atomic_set(&n_rcu_torture_alloc, 0);
68193 - atomic_set(&n_rcu_torture_alloc_fail, 0);
68194 - atomic_set(&n_rcu_torture_free, 0);
68195 - atomic_set(&n_rcu_torture_mberror, 0);
68196 - atomic_set(&n_rcu_torture_error, 0);
68197 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
68198 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
68199 + atomic_set_unchecked(&n_rcu_torture_free, 0);
68200 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
68201 + atomic_set_unchecked(&n_rcu_torture_error, 0);
68202 n_rcu_torture_boost_ktrerror = 0;
68203 n_rcu_torture_boost_rterror = 0;
68204 n_rcu_torture_boost_failure = 0;
68205 n_rcu_torture_boosts = 0;
68206 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
68207 - atomic_set(&rcu_torture_wcount[i], 0);
68208 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
68209 for_each_possible_cpu(cpu) {
68210 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
68211 per_cpu(rcu_torture_count, cpu)[i] = 0;
68212 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
68213 index 6c4a672..70f3202 100644
68214 --- a/kernel/rcutree.c
68215 +++ b/kernel/rcutree.c
68216 @@ -363,9 +363,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
68217 rcu_prepare_for_idle(smp_processor_id());
68218 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68219 smp_mb__before_atomic_inc(); /* See above. */
68220 - atomic_inc(&rdtp->dynticks);
68221 + atomic_inc_unchecked(&rdtp->dynticks);
68222 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
68223 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68224 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68225 }
68226
68227 /**
68228 @@ -438,10 +438,10 @@ void rcu_irq_exit(void)
68229 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
68230 {
68231 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
68232 - atomic_inc(&rdtp->dynticks);
68233 + atomic_inc_unchecked(&rdtp->dynticks);
68234 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68235 smp_mb__after_atomic_inc(); /* See above. */
68236 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68237 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68238 rcu_cleanup_after_idle(smp_processor_id());
68239 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
68240 if (!is_idle_task(current)) {
68241 @@ -531,14 +531,14 @@ void rcu_nmi_enter(void)
68242 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
68243
68244 if (rdtp->dynticks_nmi_nesting == 0 &&
68245 - (atomic_read(&rdtp->dynticks) & 0x1))
68246 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
68247 return;
68248 rdtp->dynticks_nmi_nesting++;
68249 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
68250 - atomic_inc(&rdtp->dynticks);
68251 + atomic_inc_unchecked(&rdtp->dynticks);
68252 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
68253 smp_mb__after_atomic_inc(); /* See above. */
68254 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
68255 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
68256 }
68257
68258 /**
68259 @@ -557,9 +557,9 @@ void rcu_nmi_exit(void)
68260 return;
68261 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
68262 smp_mb__before_atomic_inc(); /* See above. */
68263 - atomic_inc(&rdtp->dynticks);
68264 + atomic_inc_unchecked(&rdtp->dynticks);
68265 smp_mb__after_atomic_inc(); /* Force delay to next write. */
68266 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
68267 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
68268 }
68269
68270 #ifdef CONFIG_PROVE_RCU
68271 @@ -575,7 +575,7 @@ int rcu_is_cpu_idle(void)
68272 int ret;
68273
68274 preempt_disable();
68275 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68276 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
68277 preempt_enable();
68278 return ret;
68279 }
68280 @@ -604,7 +604,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
68281 */
68282 static int dyntick_save_progress_counter(struct rcu_data *rdp)
68283 {
68284 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
68285 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68286 return (rdp->dynticks_snap & 0x1) == 0;
68287 }
68288
68289 @@ -619,7 +619,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
68290 unsigned int curr;
68291 unsigned int snap;
68292
68293 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
68294 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
68295 snap = (unsigned int)rdp->dynticks_snap;
68296
68297 /*
68298 @@ -1667,7 +1667,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
68299 /*
68300 * Do RCU core processing for the current CPU.
68301 */
68302 -static void rcu_process_callbacks(struct softirq_action *unused)
68303 +static void rcu_process_callbacks(void)
68304 {
68305 trace_rcu_utilization("Start RCU core");
68306 __rcu_process_callbacks(&rcu_sched_state,
68307 @@ -2030,7 +2030,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
68308 rdp->qlen = 0;
68309 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
68310 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_NESTING);
68311 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
68312 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
68313 rdp->cpu = cpu;
68314 rdp->rsp = rsp;
68315 raw_spin_unlock_irqrestore(&rnp->lock, flags);
68316 @@ -2058,8 +2058,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
68317 rdp->n_force_qs_snap = rsp->n_force_qs;
68318 rdp->blimit = blimit;
68319 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_NESTING;
68320 - atomic_set(&rdp->dynticks->dynticks,
68321 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
68322 + atomic_set_unchecked(&rdp->dynticks->dynticks,
68323 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
68324 rcu_prepare_for_idle_init(cpu);
68325 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
68326
68327 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
68328 index fddff92..2c08359 100644
68329 --- a/kernel/rcutree.h
68330 +++ b/kernel/rcutree.h
68331 @@ -87,7 +87,7 @@ struct rcu_dynticks {
68332 long long dynticks_nesting; /* Track irq/process nesting level. */
68333 /* Process level is worth LLONG_MAX/2. */
68334 int dynticks_nmi_nesting; /* Track NMI nesting level. */
68335 - atomic_t dynticks; /* Even value for idle, else odd. */
68336 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
68337 };
68338
68339 /* RCU's kthread states for tracing. */
68340 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
68341 index 8bb35d7..6ea0a463 100644
68342 --- a/kernel/rcutree_plugin.h
68343 +++ b/kernel/rcutree_plugin.h
68344 @@ -850,7 +850,7 @@ void synchronize_rcu_expedited(void)
68345
68346 /* Clean up and exit. */
68347 smp_mb(); /* ensure expedited GP seen before counter increment. */
68348 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
68349 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
68350 unlock_mb_ret:
68351 mutex_unlock(&sync_rcu_preempt_exp_mutex);
68352 mb_ret:
68353 @@ -1833,8 +1833,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
68354
68355 #else /* #ifndef CONFIG_SMP */
68356
68357 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
68358 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
68359 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
68360 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
68361
68362 static int synchronize_sched_expedited_cpu_stop(void *data)
68363 {
68364 @@ -1889,7 +1889,7 @@ void synchronize_sched_expedited(void)
68365 int firstsnap, s, snap, trycount = 0;
68366
68367 /* Note that atomic_inc_return() implies full memory barrier. */
68368 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
68369 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
68370 get_online_cpus();
68371
68372 /*
68373 @@ -1910,7 +1910,7 @@ void synchronize_sched_expedited(void)
68374 }
68375
68376 /* Check to see if someone else did our work for us. */
68377 - s = atomic_read(&sync_sched_expedited_done);
68378 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68379 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
68380 smp_mb(); /* ensure test happens before caller kfree */
68381 return;
68382 @@ -1925,7 +1925,7 @@ void synchronize_sched_expedited(void)
68383 * grace period works for us.
68384 */
68385 get_online_cpus();
68386 - snap = atomic_read(&sync_sched_expedited_started);
68387 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
68388 smp_mb(); /* ensure read is before try_stop_cpus(). */
68389 }
68390
68391 @@ -1936,12 +1936,12 @@ void synchronize_sched_expedited(void)
68392 * than we did beat us to the punch.
68393 */
68394 do {
68395 - s = atomic_read(&sync_sched_expedited_done);
68396 + s = atomic_read_unchecked(&sync_sched_expedited_done);
68397 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
68398 smp_mb(); /* ensure test happens before caller kfree */
68399 break;
68400 }
68401 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
68402 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
68403
68404 put_online_cpus();
68405 }
68406 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
68407 index 654cfe6..c0b28e2 100644
68408 --- a/kernel/rcutree_trace.c
68409 +++ b/kernel/rcutree_trace.c
68410 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
68411 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68412 rdp->qs_pending);
68413 seq_printf(m, " dt=%d/%llx/%d df=%lu",
68414 - atomic_read(&rdp->dynticks->dynticks),
68415 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68416 rdp->dynticks->dynticks_nesting,
68417 rdp->dynticks->dynticks_nmi_nesting,
68418 rdp->dynticks_fqs);
68419 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
68420 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
68421 rdp->qs_pending);
68422 seq_printf(m, ",%d,%llx,%d,%lu",
68423 - atomic_read(&rdp->dynticks->dynticks),
68424 + atomic_read_unchecked(&rdp->dynticks->dynticks),
68425 rdp->dynticks->dynticks_nesting,
68426 rdp->dynticks->dynticks_nmi_nesting,
68427 rdp->dynticks_fqs);
68428 diff --git a/kernel/resource.c b/kernel/resource.c
68429 index 7640b3a..5879283 100644
68430 --- a/kernel/resource.c
68431 +++ b/kernel/resource.c
68432 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
68433
68434 static int __init ioresources_init(void)
68435 {
68436 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
68437 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68438 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
68439 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
68440 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68441 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
68442 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
68443 +#endif
68444 +#else
68445 proc_create("ioports", 0, NULL, &proc_ioports_operations);
68446 proc_create("iomem", 0, NULL, &proc_iomem_operations);
68447 +#endif
68448 return 0;
68449 }
68450 __initcall(ioresources_init);
68451 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
68452 index 98ec494..4241d6d 100644
68453 --- a/kernel/rtmutex-tester.c
68454 +++ b/kernel/rtmutex-tester.c
68455 @@ -20,7 +20,7 @@
68456 #define MAX_RT_TEST_MUTEXES 8
68457
68458 static spinlock_t rttest_lock;
68459 -static atomic_t rttest_event;
68460 +static atomic_unchecked_t rttest_event;
68461
68462 struct test_thread_data {
68463 int opcode;
68464 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68465
68466 case RTTEST_LOCKCONT:
68467 td->mutexes[td->opdata] = 1;
68468 - td->event = atomic_add_return(1, &rttest_event);
68469 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68470 return 0;
68471
68472 case RTTEST_RESET:
68473 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68474 return 0;
68475
68476 case RTTEST_RESETEVENT:
68477 - atomic_set(&rttest_event, 0);
68478 + atomic_set_unchecked(&rttest_event, 0);
68479 return 0;
68480
68481 default:
68482 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68483 return ret;
68484
68485 td->mutexes[id] = 1;
68486 - td->event = atomic_add_return(1, &rttest_event);
68487 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68488 rt_mutex_lock(&mutexes[id]);
68489 - td->event = atomic_add_return(1, &rttest_event);
68490 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68491 td->mutexes[id] = 4;
68492 return 0;
68493
68494 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68495 return ret;
68496
68497 td->mutexes[id] = 1;
68498 - td->event = atomic_add_return(1, &rttest_event);
68499 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68500 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
68501 - td->event = atomic_add_return(1, &rttest_event);
68502 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68503 td->mutexes[id] = ret ? 0 : 4;
68504 return ret ? -EINTR : 0;
68505
68506 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
68507 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
68508 return ret;
68509
68510 - td->event = atomic_add_return(1, &rttest_event);
68511 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68512 rt_mutex_unlock(&mutexes[id]);
68513 - td->event = atomic_add_return(1, &rttest_event);
68514 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68515 td->mutexes[id] = 0;
68516 return 0;
68517
68518 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68519 break;
68520
68521 td->mutexes[dat] = 2;
68522 - td->event = atomic_add_return(1, &rttest_event);
68523 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68524 break;
68525
68526 default:
68527 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68528 return;
68529
68530 td->mutexes[dat] = 3;
68531 - td->event = atomic_add_return(1, &rttest_event);
68532 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68533 break;
68534
68535 case RTTEST_LOCKNOWAIT:
68536 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
68537 return;
68538
68539 td->mutexes[dat] = 1;
68540 - td->event = atomic_add_return(1, &rttest_event);
68541 + td->event = atomic_add_return_unchecked(1, &rttest_event);
68542 return;
68543
68544 default:
68545 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
68546 index e8a1f83..363d17d 100644
68547 --- a/kernel/sched/auto_group.c
68548 +++ b/kernel/sched/auto_group.c
68549 @@ -11,7 +11,7 @@
68550
68551 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
68552 static struct autogroup autogroup_default;
68553 -static atomic_t autogroup_seq_nr;
68554 +static atomic_unchecked_t autogroup_seq_nr;
68555
68556 void __init autogroup_init(struct task_struct *init_task)
68557 {
68558 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
68559
68560 kref_init(&ag->kref);
68561 init_rwsem(&ag->lock);
68562 - ag->id = atomic_inc_return(&autogroup_seq_nr);
68563 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
68564 ag->tg = tg;
68565 #ifdef CONFIG_RT_GROUP_SCHED
68566 /*
68567 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
68568 index 478a04c..e16339a 100644
68569 --- a/kernel/sched/core.c
68570 +++ b/kernel/sched/core.c
68571 @@ -3851,6 +3851,8 @@ int can_nice(const struct task_struct *p, const int nice)
68572 /* convert nice value [19,-20] to rlimit style value [1,40] */
68573 int nice_rlim = 20 - nice;
68574
68575 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
68576 +
68577 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
68578 capable(CAP_SYS_NICE));
68579 }
68580 @@ -3884,7 +3886,8 @@ SYSCALL_DEFINE1(nice, int, increment)
68581 if (nice > 19)
68582 nice = 19;
68583
68584 - if (increment < 0 && !can_nice(current, nice))
68585 + if (increment < 0 && (!can_nice(current, nice) ||
68586 + gr_handle_chroot_nice()))
68587 return -EPERM;
68588
68589 retval = security_task_setnice(current, nice);
68590 @@ -4041,6 +4044,7 @@ recheck:
68591 unsigned long rlim_rtprio =
68592 task_rlimit(p, RLIMIT_RTPRIO);
68593
68594 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
68595 /* can't set/change the rt policy */
68596 if (policy != p->policy && !rlim_rtprio)
68597 return -EPERM;
68598 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
68599 index aca16b8..8e3acc4 100644
68600 --- a/kernel/sched/fair.c
68601 +++ b/kernel/sched/fair.c
68602 @@ -5147,7 +5147,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
68603 * run_rebalance_domains is triggered when needed from the scheduler tick.
68604 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
68605 */
68606 -static void run_rebalance_domains(struct softirq_action *h)
68607 +static void run_rebalance_domains(void)
68608 {
68609 int this_cpu = smp_processor_id();
68610 struct rq *this_rq = cpu_rq(this_cpu);
68611 diff --git a/kernel/signal.c b/kernel/signal.c
68612 index b09cf3b..b291c66 100644
68613 --- a/kernel/signal.c
68614 +++ b/kernel/signal.c
68615 @@ -46,12 +46,12 @@ static struct kmem_cache *sigqueue_cachep;
68616
68617 int print_fatal_signals __read_mostly;
68618
68619 -static void __user *sig_handler(struct task_struct *t, int sig)
68620 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
68621 {
68622 return t->sighand->action[sig - 1].sa.sa_handler;
68623 }
68624
68625 -static int sig_handler_ignored(void __user *handler, int sig)
68626 +static int sig_handler_ignored(__sighandler_t handler, int sig)
68627 {
68628 /* Is it explicitly or implicitly ignored? */
68629 return handler == SIG_IGN ||
68630 @@ -61,7 +61,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
68631 static int sig_task_ignored(struct task_struct *t, int sig,
68632 int from_ancestor_ns)
68633 {
68634 - void __user *handler;
68635 + __sighandler_t handler;
68636
68637 handler = sig_handler(t, sig);
68638
68639 @@ -365,6 +365,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
68640 atomic_inc(&user->sigpending);
68641 rcu_read_unlock();
68642
68643 + if (!override_rlimit)
68644 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
68645 +
68646 if (override_rlimit ||
68647 atomic_read(&user->sigpending) <=
68648 task_rlimit(t, RLIMIT_SIGPENDING)) {
68649 @@ -489,7 +492,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
68650
68651 int unhandled_signal(struct task_struct *tsk, int sig)
68652 {
68653 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
68654 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
68655 if (is_global_init(tsk))
68656 return 1;
68657 if (handler != SIG_IGN && handler != SIG_DFL)
68658 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
68659 }
68660 }
68661
68662 + /* allow glibc communication via tgkill to other threads in our
68663 + thread group */
68664 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
68665 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
68666 + && gr_handle_signal(t, sig))
68667 + return -EPERM;
68668 +
68669 return security_task_kill(t, info, sig, 0);
68670 }
68671
68672 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68673 return send_signal(sig, info, p, 1);
68674 }
68675
68676 -static int
68677 +int
68678 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68679 {
68680 return send_signal(sig, info, t, 0);
68681 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68682 unsigned long int flags;
68683 int ret, blocked, ignored;
68684 struct k_sigaction *action;
68685 + int is_unhandled = 0;
68686
68687 spin_lock_irqsave(&t->sighand->siglock, flags);
68688 action = &t->sighand->action[sig-1];
68689 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
68690 }
68691 if (action->sa.sa_handler == SIG_DFL)
68692 t->signal->flags &= ~SIGNAL_UNKILLABLE;
68693 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
68694 + is_unhandled = 1;
68695 ret = specific_send_sig_info(sig, info, t);
68696 spin_unlock_irqrestore(&t->sighand->siglock, flags);
68697
68698 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
68699 + normal operation */
68700 + if (is_unhandled) {
68701 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
68702 + gr_handle_crash(t, sig);
68703 + }
68704 +
68705 return ret;
68706 }
68707
68708 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
68709 ret = check_kill_permission(sig, info, p);
68710 rcu_read_unlock();
68711
68712 - if (!ret && sig)
68713 + if (!ret && sig) {
68714 ret = do_send_sig_info(sig, info, p, true);
68715 + if (!ret)
68716 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
68717 + }
68718
68719 return ret;
68720 }
68721 @@ -2829,7 +2852,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
68722 int error = -ESRCH;
68723
68724 rcu_read_lock();
68725 - p = find_task_by_vpid(pid);
68726 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68727 + /* allow glibc communication via tgkill to other threads in our
68728 + thread group */
68729 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
68730 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
68731 + p = find_task_by_vpid_unrestricted(pid);
68732 + else
68733 +#endif
68734 + p = find_task_by_vpid(pid);
68735 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
68736 error = check_kill_permission(sig, info, p);
68737 /*
68738 diff --git a/kernel/smp.c b/kernel/smp.c
68739 index db197d6..17aef0b 100644
68740 --- a/kernel/smp.c
68741 +++ b/kernel/smp.c
68742 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
68743 }
68744 EXPORT_SYMBOL(smp_call_function);
68745
68746 -void ipi_call_lock(void)
68747 +void ipi_call_lock(void) __acquires(call_function.lock)
68748 {
68749 raw_spin_lock(&call_function.lock);
68750 }
68751
68752 -void ipi_call_unlock(void)
68753 +void ipi_call_unlock(void) __releases(call_function.lock)
68754 {
68755 raw_spin_unlock(&call_function.lock);
68756 }
68757
68758 -void ipi_call_lock_irq(void)
68759 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
68760 {
68761 raw_spin_lock_irq(&call_function.lock);
68762 }
68763
68764 -void ipi_call_unlock_irq(void)
68765 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
68766 {
68767 raw_spin_unlock_irq(&call_function.lock);
68768 }
68769 diff --git a/kernel/softirq.c b/kernel/softirq.c
68770 index 4eb3a0f..6f1fa81 100644
68771 --- a/kernel/softirq.c
68772 +++ b/kernel/softirq.c
68773 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
68774
68775 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
68776
68777 -char *softirq_to_name[NR_SOFTIRQS] = {
68778 +const char * const softirq_to_name[NR_SOFTIRQS] = {
68779 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
68780 "TASKLET", "SCHED", "HRTIMER", "RCU"
68781 };
68782 @@ -235,7 +235,7 @@ restart:
68783 kstat_incr_softirqs_this_cpu(vec_nr);
68784
68785 trace_softirq_entry(vec_nr);
68786 - h->action(h);
68787 + h->action();
68788 trace_softirq_exit(vec_nr);
68789 if (unlikely(prev_count != preempt_count())) {
68790 printk(KERN_ERR "huh, entered softirq %u %s %p"
68791 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
68792 local_irq_restore(flags);
68793 }
68794
68795 -void open_softirq(int nr, void (*action)(struct softirq_action *))
68796 +void open_softirq(int nr, void (*action)(void))
68797 {
68798 - softirq_vec[nr].action = action;
68799 + pax_open_kernel();
68800 + *(void **)&softirq_vec[nr].action = action;
68801 + pax_close_kernel();
68802 }
68803
68804 /*
68805 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
68806
68807 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
68808
68809 -static void tasklet_action(struct softirq_action *a)
68810 +static void tasklet_action(void)
68811 {
68812 struct tasklet_struct *list;
68813
68814 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
68815 }
68816 }
68817
68818 -static void tasklet_hi_action(struct softirq_action *a)
68819 +static void tasklet_hi_action(void)
68820 {
68821 struct tasklet_struct *list;
68822
68823 diff --git a/kernel/sys.c b/kernel/sys.c
68824 index 888d227..f04b318 100644
68825 --- a/kernel/sys.c
68826 +++ b/kernel/sys.c
68827 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
68828 error = -EACCES;
68829 goto out;
68830 }
68831 +
68832 + if (gr_handle_chroot_setpriority(p, niceval)) {
68833 + error = -EACCES;
68834 + goto out;
68835 + }
68836 +
68837 no_nice = security_task_setnice(p, niceval);
68838 if (no_nice) {
68839 error = no_nice;
68840 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
68841 goto error;
68842 }
68843
68844 + if (gr_check_group_change(new->gid, new->egid, -1))
68845 + goto error;
68846 +
68847 if (rgid != (gid_t) -1 ||
68848 (egid != (gid_t) -1 && egid != old->gid))
68849 new->sgid = new->egid;
68850 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
68851 old = current_cred();
68852
68853 retval = -EPERM;
68854 +
68855 + if (gr_check_group_change(gid, gid, gid))
68856 + goto error;
68857 +
68858 if (nsown_capable(CAP_SETGID))
68859 new->gid = new->egid = new->sgid = new->fsgid = gid;
68860 else if (gid == old->gid || gid == old->sgid)
68861 @@ -618,7 +631,7 @@ error:
68862 /*
68863 * change the user struct in a credentials set to match the new UID
68864 */
68865 -static int set_user(struct cred *new)
68866 +int set_user(struct cred *new)
68867 {
68868 struct user_struct *new_user;
68869
68870 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
68871 goto error;
68872 }
68873
68874 + if (gr_check_user_change(new->uid, new->euid, -1))
68875 + goto error;
68876 +
68877 if (new->uid != old->uid) {
68878 retval = set_user(new);
68879 if (retval < 0)
68880 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
68881 old = current_cred();
68882
68883 retval = -EPERM;
68884 +
68885 + if (gr_check_crash_uid(uid))
68886 + goto error;
68887 + if (gr_check_user_change(uid, uid, uid))
68888 + goto error;
68889 +
68890 if (nsown_capable(CAP_SETUID)) {
68891 new->suid = new->uid = uid;
68892 if (uid != old->uid) {
68893 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
68894 goto error;
68895 }
68896
68897 + if (gr_check_user_change(ruid, euid, -1))
68898 + goto error;
68899 +
68900 if (ruid != (uid_t) -1) {
68901 new->uid = ruid;
68902 if (ruid != old->uid) {
68903 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
68904 goto error;
68905 }
68906
68907 + if (gr_check_group_change(rgid, egid, -1))
68908 + goto error;
68909 +
68910 if (rgid != (gid_t) -1)
68911 new->gid = rgid;
68912 if (egid != (gid_t) -1)
68913 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68914 old = current_cred();
68915 old_fsuid = old->fsuid;
68916
68917 + if (gr_check_user_change(-1, -1, uid))
68918 + goto error;
68919 +
68920 if (uid == old->uid || uid == old->euid ||
68921 uid == old->suid || uid == old->fsuid ||
68922 nsown_capable(CAP_SETUID)) {
68923 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
68924 }
68925 }
68926
68927 +error:
68928 abort_creds(new);
68929 return old_fsuid;
68930
68931 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
68932 if (gid == old->gid || gid == old->egid ||
68933 gid == old->sgid || gid == old->fsgid ||
68934 nsown_capable(CAP_SETGID)) {
68935 + if (gr_check_group_change(-1, -1, gid))
68936 + goto error;
68937 +
68938 if (gid != old_fsgid) {
68939 new->fsgid = gid;
68940 goto change_okay;
68941 }
68942 }
68943
68944 +error:
68945 abort_creds(new);
68946 return old_fsgid;
68947
68948 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
68949 }
68950 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
68951 snprintf(buf, len, "2.6.%u%s", v, rest);
68952 - ret = copy_to_user(release, buf, len);
68953 + if (len > sizeof(buf))
68954 + ret = -EFAULT;
68955 + else
68956 + ret = copy_to_user(release, buf, len);
68957 }
68958 return ret;
68959 }
68960 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
68961 return -EFAULT;
68962
68963 down_read(&uts_sem);
68964 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
68965 + error = __copy_to_user(name->sysname, &utsname()->sysname,
68966 __OLD_UTS_LEN);
68967 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
68968 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
68969 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
68970 __OLD_UTS_LEN);
68971 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
68972 - error |= __copy_to_user(&name->release, &utsname()->release,
68973 + error |= __copy_to_user(name->release, &utsname()->release,
68974 __OLD_UTS_LEN);
68975 error |= __put_user(0, name->release + __OLD_UTS_LEN);
68976 - error |= __copy_to_user(&name->version, &utsname()->version,
68977 + error |= __copy_to_user(name->version, &utsname()->version,
68978 __OLD_UTS_LEN);
68979 error |= __put_user(0, name->version + __OLD_UTS_LEN);
68980 - error |= __copy_to_user(&name->machine, &utsname()->machine,
68981 + error |= __copy_to_user(name->machine, &utsname()->machine,
68982 __OLD_UTS_LEN);
68983 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
68984 up_read(&uts_sem);
68985 @@ -1838,7 +1877,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
68986 error = get_dumpable(me->mm);
68987 break;
68988 case PR_SET_DUMPABLE:
68989 - if (arg2 < 0 || arg2 > 1) {
68990 + if (arg2 > 1) {
68991 error = -EINVAL;
68992 break;
68993 }
68994 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
68995 index f03a6ef..735d95c 100644
68996 --- a/kernel/sysctl.c
68997 +++ b/kernel/sysctl.c
68998 @@ -86,6 +86,13 @@
68999
69000
69001 #if defined(CONFIG_SYSCTL)
69002 +#include <linux/grsecurity.h>
69003 +#include <linux/grinternal.h>
69004 +
69005 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
69006 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
69007 + const int op);
69008 +extern int gr_handle_chroot_sysctl(const int op);
69009
69010 /* External variables not in a header file. */
69011 extern int sysctl_overcommit_memory;
69012 @@ -165,10 +172,8 @@ static int proc_taint(struct ctl_table *table, int write,
69013 void __user *buffer, size_t *lenp, loff_t *ppos);
69014 #endif
69015
69016 -#ifdef CONFIG_PRINTK
69017 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69018 void __user *buffer, size_t *lenp, loff_t *ppos);
69019 -#endif
69020
69021 #ifdef CONFIG_MAGIC_SYSRQ
69022 /* Note: sysrq code uses it's own private copy */
69023 @@ -191,6 +196,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
69024 }
69025
69026 #endif
69027 +extern struct ctl_table grsecurity_table[];
69028
69029 static struct ctl_table root_table[];
69030 static struct ctl_table_root sysctl_table_root;
69031 @@ -220,6 +226,20 @@ extern struct ctl_table epoll_table[];
69032 int sysctl_legacy_va_layout;
69033 #endif
69034
69035 +#ifdef CONFIG_PAX_SOFTMODE
69036 +static ctl_table pax_table[] = {
69037 + {
69038 + .procname = "softmode",
69039 + .data = &pax_softmode,
69040 + .maxlen = sizeof(unsigned int),
69041 + .mode = 0600,
69042 + .proc_handler = &proc_dointvec,
69043 + },
69044 +
69045 + { }
69046 +};
69047 +#endif
69048 +
69049 /* The default sysctl tables: */
69050
69051 static struct ctl_table root_table[] = {
69052 @@ -266,6 +286,22 @@ static int max_extfrag_threshold = 1000;
69053 #endif
69054
69055 static struct ctl_table kern_table[] = {
69056 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
69057 + {
69058 + .procname = "grsecurity",
69059 + .mode = 0500,
69060 + .child = grsecurity_table,
69061 + },
69062 +#endif
69063 +
69064 +#ifdef CONFIG_PAX_SOFTMODE
69065 + {
69066 + .procname = "pax",
69067 + .mode = 0500,
69068 + .child = pax_table,
69069 + },
69070 +#endif
69071 +
69072 {
69073 .procname = "sched_child_runs_first",
69074 .data = &sysctl_sched_child_runs_first,
69075 @@ -550,7 +586,7 @@ static struct ctl_table kern_table[] = {
69076 .data = &modprobe_path,
69077 .maxlen = KMOD_PATH_LEN,
69078 .mode = 0644,
69079 - .proc_handler = proc_dostring,
69080 + .proc_handler = proc_dostring_modpriv,
69081 },
69082 {
69083 .procname = "modules_disabled",
69084 @@ -717,16 +753,20 @@ static struct ctl_table kern_table[] = {
69085 .extra1 = &zero,
69086 .extra2 = &one,
69087 },
69088 +#endif
69089 {
69090 .procname = "kptr_restrict",
69091 .data = &kptr_restrict,
69092 .maxlen = sizeof(int),
69093 .mode = 0644,
69094 .proc_handler = proc_dointvec_minmax_sysadmin,
69095 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69096 + .extra1 = &two,
69097 +#else
69098 .extra1 = &zero,
69099 +#endif
69100 .extra2 = &two,
69101 },
69102 -#endif
69103 {
69104 .procname = "ngroups_max",
69105 .data = &ngroups_max,
69106 @@ -1225,6 +1265,13 @@ static struct ctl_table vm_table[] = {
69107 .proc_handler = proc_dointvec_minmax,
69108 .extra1 = &zero,
69109 },
69110 + {
69111 + .procname = "heap_stack_gap",
69112 + .data = &sysctl_heap_stack_gap,
69113 + .maxlen = sizeof(sysctl_heap_stack_gap),
69114 + .mode = 0644,
69115 + .proc_handler = proc_doulongvec_minmax,
69116 + },
69117 #else
69118 {
69119 .procname = "nr_trim_pages",
69120 @@ -1729,6 +1776,17 @@ static int test_perm(int mode, int op)
69121 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
69122 {
69123 int mode;
69124 + int error;
69125 +
69126 + if (table->parent != NULL && table->parent->procname != NULL &&
69127 + table->procname != NULL &&
69128 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
69129 + return -EACCES;
69130 + if (gr_handle_chroot_sysctl(op))
69131 + return -EACCES;
69132 + error = gr_handle_sysctl(table, op);
69133 + if (error)
69134 + return error;
69135
69136 if (root->permissions)
69137 mode = root->permissions(root, current->nsproxy, table);
69138 @@ -2133,6 +2191,16 @@ int proc_dostring(struct ctl_table *table, int write,
69139 buffer, lenp, ppos);
69140 }
69141
69142 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69143 + void __user *buffer, size_t *lenp, loff_t *ppos)
69144 +{
69145 + if (write && !capable(CAP_SYS_MODULE))
69146 + return -EPERM;
69147 +
69148 + return _proc_do_string(table->data, table->maxlen, write,
69149 + buffer, lenp, ppos);
69150 +}
69151 +
69152 static size_t proc_skip_spaces(char **buf)
69153 {
69154 size_t ret;
69155 @@ -2238,6 +2306,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
69156 len = strlen(tmp);
69157 if (len > *size)
69158 len = *size;
69159 + if (len > sizeof(tmp))
69160 + len = sizeof(tmp);
69161 if (copy_to_user(*buf, tmp, len))
69162 return -EFAULT;
69163 *size -= len;
69164 @@ -2430,7 +2500,6 @@ static int proc_taint(struct ctl_table *table, int write,
69165 return err;
69166 }
69167
69168 -#ifdef CONFIG_PRINTK
69169 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69170 void __user *buffer, size_t *lenp, loff_t *ppos)
69171 {
69172 @@ -2439,7 +2508,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
69173
69174 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
69175 }
69176 -#endif
69177
69178 struct do_proc_dointvec_minmax_conv_param {
69179 int *min;
69180 @@ -2554,8 +2622,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
69181 *i = val;
69182 } else {
69183 val = convdiv * (*i) / convmul;
69184 - if (!first)
69185 + if (!first) {
69186 err = proc_put_char(&buffer, &left, '\t');
69187 + if (err)
69188 + break;
69189 + }
69190 err = proc_put_long(&buffer, &left, val, false);
69191 if (err)
69192 break;
69193 @@ -2950,6 +3021,12 @@ int proc_dostring(struct ctl_table *table, int write,
69194 return -ENOSYS;
69195 }
69196
69197 +int proc_dostring_modpriv(struct ctl_table *table, int write,
69198 + void __user *buffer, size_t *lenp, loff_t *ppos)
69199 +{
69200 + return -ENOSYS;
69201 +}
69202 +
69203 int proc_dointvec(struct ctl_table *table, int write,
69204 void __user *buffer, size_t *lenp, loff_t *ppos)
69205 {
69206 @@ -3006,6 +3083,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
69207 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
69208 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
69209 EXPORT_SYMBOL(proc_dostring);
69210 +EXPORT_SYMBOL(proc_dostring_modpriv);
69211 EXPORT_SYMBOL(proc_doulongvec_minmax);
69212 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
69213 EXPORT_SYMBOL(register_sysctl_table);
69214 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
69215 index a650694..aaeeb20 100644
69216 --- a/kernel/sysctl_binary.c
69217 +++ b/kernel/sysctl_binary.c
69218 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
69219 int i;
69220
69221 set_fs(KERNEL_DS);
69222 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69223 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69224 set_fs(old_fs);
69225 if (result < 0)
69226 goto out_kfree;
69227 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
69228 }
69229
69230 set_fs(KERNEL_DS);
69231 - result = vfs_write(file, buffer, str - buffer, &pos);
69232 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69233 set_fs(old_fs);
69234 if (result < 0)
69235 goto out_kfree;
69236 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
69237 int i;
69238
69239 set_fs(KERNEL_DS);
69240 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
69241 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
69242 set_fs(old_fs);
69243 if (result < 0)
69244 goto out_kfree;
69245 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
69246 }
69247
69248 set_fs(KERNEL_DS);
69249 - result = vfs_write(file, buffer, str - buffer, &pos);
69250 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
69251 set_fs(old_fs);
69252 if (result < 0)
69253 goto out_kfree;
69254 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
69255 int i;
69256
69257 set_fs(KERNEL_DS);
69258 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69259 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69260 set_fs(old_fs);
69261 if (result < 0)
69262 goto out;
69263 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69264 __le16 dnaddr;
69265
69266 set_fs(KERNEL_DS);
69267 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
69268 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
69269 set_fs(old_fs);
69270 if (result < 0)
69271 goto out;
69272 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
69273 le16_to_cpu(dnaddr) & 0x3ff);
69274
69275 set_fs(KERNEL_DS);
69276 - result = vfs_write(file, buf, len, &pos);
69277 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
69278 set_fs(old_fs);
69279 if (result < 0)
69280 goto out;
69281 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
69282 index 362da65..ab8ef8c 100644
69283 --- a/kernel/sysctl_check.c
69284 +++ b/kernel/sysctl_check.c
69285 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
69286 set_fail(&fail, table, "Directory with extra2");
69287 } else {
69288 if ((table->proc_handler == proc_dostring) ||
69289 + (table->proc_handler == proc_dostring_modpriv) ||
69290 (table->proc_handler == proc_dointvec) ||
69291 (table->proc_handler == proc_dointvec_minmax) ||
69292 (table->proc_handler == proc_dointvec_jiffies) ||
69293 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
69294 index e660464..c8b9e67 100644
69295 --- a/kernel/taskstats.c
69296 +++ b/kernel/taskstats.c
69297 @@ -27,9 +27,12 @@
69298 #include <linux/cgroup.h>
69299 #include <linux/fs.h>
69300 #include <linux/file.h>
69301 +#include <linux/grsecurity.h>
69302 #include <net/genetlink.h>
69303 #include <linux/atomic.h>
69304
69305 +extern int gr_is_taskstats_denied(int pid);
69306 +
69307 /*
69308 * Maximum length of a cpumask that can be specified in
69309 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
69310 @@ -556,6 +559,9 @@ err:
69311
69312 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
69313 {
69314 + if (gr_is_taskstats_denied(current->pid))
69315 + return -EACCES;
69316 +
69317 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
69318 return cmd_attr_register_cpumask(info);
69319 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
69320 diff --git a/kernel/time.c b/kernel/time.c
69321 index 73e416d..cfc6f69 100644
69322 --- a/kernel/time.c
69323 +++ b/kernel/time.c
69324 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
69325 return error;
69326
69327 if (tz) {
69328 + /* we log in do_settimeofday called below, so don't log twice
69329 + */
69330 + if (!tv)
69331 + gr_log_timechange();
69332 +
69333 /* SMP safe, global irq locking makes it work. */
69334 sys_tz = *tz;
69335 update_vsyscall_tz();
69336 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
69337 index 8a46f5d..bbe6f9c 100644
69338 --- a/kernel/time/alarmtimer.c
69339 +++ b/kernel/time/alarmtimer.c
69340 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
69341 struct platform_device *pdev;
69342 int error = 0;
69343 int i;
69344 - struct k_clock alarm_clock = {
69345 + static struct k_clock alarm_clock = {
69346 .clock_getres = alarm_clock_getres,
69347 .clock_get = alarm_clock_get,
69348 .timer_create = alarm_timer_create,
69349 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
69350 index fd4a7b1..fae5c2a 100644
69351 --- a/kernel/time/tick-broadcast.c
69352 +++ b/kernel/time/tick-broadcast.c
69353 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
69354 * then clear the broadcast bit.
69355 */
69356 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
69357 - int cpu = smp_processor_id();
69358 + cpu = smp_processor_id();
69359
69360 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
69361 tick_broadcast_clear_oneshot(cpu);
69362 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
69363 index 0c63581..e25dcb6 100644
69364 --- a/kernel/time/timekeeping.c
69365 +++ b/kernel/time/timekeeping.c
69366 @@ -14,6 +14,7 @@
69367 #include <linux/init.h>
69368 #include <linux/mm.h>
69369 #include <linux/sched.h>
69370 +#include <linux/grsecurity.h>
69371 #include <linux/syscore_ops.h>
69372 #include <linux/clocksource.h>
69373 #include <linux/jiffies.h>
69374 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
69375 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
69376 return -EINVAL;
69377
69378 + gr_log_timechange();
69379 +
69380 write_seqlock_irqsave(&xtime_lock, flags);
69381
69382 timekeeping_forward_now();
69383 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
69384 index 3258455..f35227d 100644
69385 --- a/kernel/time/timer_list.c
69386 +++ b/kernel/time/timer_list.c
69387 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
69388
69389 static void print_name_offset(struct seq_file *m, void *sym)
69390 {
69391 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69392 + SEQ_printf(m, "<%p>", NULL);
69393 +#else
69394 char symname[KSYM_NAME_LEN];
69395
69396 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
69397 SEQ_printf(m, "<%pK>", sym);
69398 else
69399 SEQ_printf(m, "%s", symname);
69400 +#endif
69401 }
69402
69403 static void
69404 @@ -112,7 +116,11 @@ next_one:
69405 static void
69406 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
69407 {
69408 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69409 + SEQ_printf(m, " .base: %p\n", NULL);
69410 +#else
69411 SEQ_printf(m, " .base: %pK\n", base);
69412 +#endif
69413 SEQ_printf(m, " .index: %d\n",
69414 base->index);
69415 SEQ_printf(m, " .resolution: %Lu nsecs\n",
69416 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
69417 {
69418 struct proc_dir_entry *pe;
69419
69420 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69421 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
69422 +#else
69423 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
69424 +#endif
69425 if (!pe)
69426 return -ENOMEM;
69427 return 0;
69428 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
69429 index 0b537f2..9e71eca 100644
69430 --- a/kernel/time/timer_stats.c
69431 +++ b/kernel/time/timer_stats.c
69432 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
69433 static unsigned long nr_entries;
69434 static struct entry entries[MAX_ENTRIES];
69435
69436 -static atomic_t overflow_count;
69437 +static atomic_unchecked_t overflow_count;
69438
69439 /*
69440 * The entries are in a hash-table, for fast lookup:
69441 @@ -140,7 +140,7 @@ static void reset_entries(void)
69442 nr_entries = 0;
69443 memset(entries, 0, sizeof(entries));
69444 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
69445 - atomic_set(&overflow_count, 0);
69446 + atomic_set_unchecked(&overflow_count, 0);
69447 }
69448
69449 static struct entry *alloc_entry(void)
69450 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69451 if (likely(entry))
69452 entry->count++;
69453 else
69454 - atomic_inc(&overflow_count);
69455 + atomic_inc_unchecked(&overflow_count);
69456
69457 out_unlock:
69458 raw_spin_unlock_irqrestore(lock, flags);
69459 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
69460
69461 static void print_name_offset(struct seq_file *m, unsigned long addr)
69462 {
69463 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69464 + seq_printf(m, "<%p>", NULL);
69465 +#else
69466 char symname[KSYM_NAME_LEN];
69467
69468 if (lookup_symbol_name(addr, symname) < 0)
69469 seq_printf(m, "<%p>", (void *)addr);
69470 else
69471 seq_printf(m, "%s", symname);
69472 +#endif
69473 }
69474
69475 static int tstats_show(struct seq_file *m, void *v)
69476 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
69477
69478 seq_puts(m, "Timer Stats Version: v0.2\n");
69479 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
69480 - if (atomic_read(&overflow_count))
69481 + if (atomic_read_unchecked(&overflow_count))
69482 seq_printf(m, "Overflow: %d entries\n",
69483 - atomic_read(&overflow_count));
69484 + atomic_read_unchecked(&overflow_count));
69485
69486 for (i = 0; i < nr_entries; i++) {
69487 entry = entries + i;
69488 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
69489 {
69490 struct proc_dir_entry *pe;
69491
69492 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69493 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
69494 +#else
69495 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
69496 +#endif
69497 if (!pe)
69498 return -ENOMEM;
69499 return 0;
69500 diff --git a/kernel/timer.c b/kernel/timer.c
69501 index a297ffc..5e16b0b 100644
69502 --- a/kernel/timer.c
69503 +++ b/kernel/timer.c
69504 @@ -1354,7 +1354,7 @@ void update_process_times(int user_tick)
69505 /*
69506 * This function runs timers and the timer-tq in bottom half context.
69507 */
69508 -static void run_timer_softirq(struct softirq_action *h)
69509 +static void run_timer_softirq(void)
69510 {
69511 struct tvec_base *base = __this_cpu_read(tvec_bases);
69512
69513 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
69514 index cdea7b5..9b820d4 100644
69515 --- a/kernel/trace/blktrace.c
69516 +++ b/kernel/trace/blktrace.c
69517 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
69518 struct blk_trace *bt = filp->private_data;
69519 char buf[16];
69520
69521 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
69522 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
69523
69524 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
69525 }
69526 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
69527 return 1;
69528
69529 bt = buf->chan->private_data;
69530 - atomic_inc(&bt->dropped);
69531 + atomic_inc_unchecked(&bt->dropped);
69532 return 0;
69533 }
69534
69535 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
69536
69537 bt->dir = dir;
69538 bt->dev = dev;
69539 - atomic_set(&bt->dropped, 0);
69540 + atomic_set_unchecked(&bt->dropped, 0);
69541
69542 ret = -EIO;
69543 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
69544 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
69545 index 683d559..d70d914 100644
69546 --- a/kernel/trace/ftrace.c
69547 +++ b/kernel/trace/ftrace.c
69548 @@ -1726,12 +1726,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
69549 if (unlikely(ftrace_disabled))
69550 return 0;
69551
69552 + ret = ftrace_arch_code_modify_prepare();
69553 + FTRACE_WARN_ON(ret);
69554 + if (ret)
69555 + return 0;
69556 +
69557 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
69558 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
69559 if (ret) {
69560 ftrace_bug(ret, ip);
69561 - return 0;
69562 }
69563 - return 1;
69564 + return ret ? 0 : 1;
69565 }
69566
69567 /*
69568 @@ -2843,7 +2848,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
69569
69570 int
69571 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
69572 - void *data)
69573 + void *data)
69574 {
69575 struct ftrace_func_probe *entry;
69576 struct ftrace_page *pg;
69577 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
69578 index c4579f1..6a439da 100644
69579 --- a/kernel/trace/trace.c
69580 +++ b/kernel/trace/trace.c
69581 @@ -4258,10 +4258,9 @@ static const struct file_operations tracing_dyn_info_fops = {
69582 };
69583 #endif
69584
69585 -static struct dentry *d_tracer;
69586 -
69587 struct dentry *tracing_init_dentry(void)
69588 {
69589 + static struct dentry *d_tracer;
69590 static int once;
69591
69592 if (d_tracer)
69593 @@ -4281,10 +4280,9 @@ struct dentry *tracing_init_dentry(void)
69594 return d_tracer;
69595 }
69596
69597 -static struct dentry *d_percpu;
69598 -
69599 struct dentry *tracing_dentry_percpu(void)
69600 {
69601 + static struct dentry *d_percpu;
69602 static int once;
69603 struct dentry *d_tracer;
69604
69605 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
69606 index c212a7f..7b02394 100644
69607 --- a/kernel/trace/trace_events.c
69608 +++ b/kernel/trace/trace_events.c
69609 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
69610 struct ftrace_module_file_ops {
69611 struct list_head list;
69612 struct module *mod;
69613 - struct file_operations id;
69614 - struct file_operations enable;
69615 - struct file_operations format;
69616 - struct file_operations filter;
69617 };
69618
69619 static struct ftrace_module_file_ops *
69620 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
69621
69622 file_ops->mod = mod;
69623
69624 - file_ops->id = ftrace_event_id_fops;
69625 - file_ops->id.owner = mod;
69626 -
69627 - file_ops->enable = ftrace_enable_fops;
69628 - file_ops->enable.owner = mod;
69629 -
69630 - file_ops->filter = ftrace_event_filter_fops;
69631 - file_ops->filter.owner = mod;
69632 -
69633 - file_ops->format = ftrace_event_format_fops;
69634 - file_ops->format.owner = mod;
69635 + pax_open_kernel();
69636 + *(void **)&mod->trace_id.owner = mod;
69637 + *(void **)&mod->trace_enable.owner = mod;
69638 + *(void **)&mod->trace_filter.owner = mod;
69639 + *(void **)&mod->trace_format.owner = mod;
69640 + pax_close_kernel();
69641
69642 list_add(&file_ops->list, &ftrace_module_file_list);
69643
69644 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
69645
69646 for_each_event(call, start, end) {
69647 __trace_add_event_call(*call, mod,
69648 - &file_ops->id, &file_ops->enable,
69649 - &file_ops->filter, &file_ops->format);
69650 + &mod->trace_id, &mod->trace_enable,
69651 + &mod->trace_filter, &mod->trace_format);
69652 }
69653 }
69654
69655 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
69656 index 00d527c..7c5b1a3 100644
69657 --- a/kernel/trace/trace_kprobe.c
69658 +++ b/kernel/trace/trace_kprobe.c
69659 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69660 long ret;
69661 int maxlen = get_rloc_len(*(u32 *)dest);
69662 u8 *dst = get_rloc_data(dest);
69663 - u8 *src = addr;
69664 + const u8 __user *src = (const u8 __force_user *)addr;
69665 mm_segment_t old_fs = get_fs();
69666 if (!maxlen)
69667 return;
69668 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69669 pagefault_disable();
69670 do
69671 ret = __copy_from_user_inatomic(dst++, src++, 1);
69672 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
69673 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
69674 dst[-1] = '\0';
69675 pagefault_enable();
69676 set_fs(old_fs);
69677 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
69678 ((u8 *)get_rloc_data(dest))[0] = '\0';
69679 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
69680 } else
69681 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
69682 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
69683 get_rloc_offs(*(u32 *)dest));
69684 }
69685 /* Return the length of string -- including null terminal byte */
69686 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
69687 set_fs(KERNEL_DS);
69688 pagefault_disable();
69689 do {
69690 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
69691 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
69692 len++;
69693 } while (c && ret == 0 && len < MAX_STRING_SIZE);
69694 pagefault_enable();
69695 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
69696 index fd3c8aa..5f324a6 100644
69697 --- a/kernel/trace/trace_mmiotrace.c
69698 +++ b/kernel/trace/trace_mmiotrace.c
69699 @@ -24,7 +24,7 @@ struct header_iter {
69700 static struct trace_array *mmio_trace_array;
69701 static bool overrun_detected;
69702 static unsigned long prev_overruns;
69703 -static atomic_t dropped_count;
69704 +static atomic_unchecked_t dropped_count;
69705
69706 static void mmio_reset_data(struct trace_array *tr)
69707 {
69708 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
69709
69710 static unsigned long count_overruns(struct trace_iterator *iter)
69711 {
69712 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
69713 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
69714 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
69715
69716 if (over > prev_overruns)
69717 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
69718 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
69719 sizeof(*entry), 0, pc);
69720 if (!event) {
69721 - atomic_inc(&dropped_count);
69722 + atomic_inc_unchecked(&dropped_count);
69723 return;
69724 }
69725 entry = ring_buffer_event_data(event);
69726 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
69727 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
69728 sizeof(*entry), 0, pc);
69729 if (!event) {
69730 - atomic_inc(&dropped_count);
69731 + atomic_inc_unchecked(&dropped_count);
69732 return;
69733 }
69734 entry = ring_buffer_event_data(event);
69735 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
69736 index d9c07f0..c1eeceb 100644
69737 --- a/kernel/trace/trace_output.c
69738 +++ b/kernel/trace/trace_output.c
69739 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
69740
69741 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
69742 if (!IS_ERR(p)) {
69743 - p = mangle_path(s->buffer + s->len, p, "\n");
69744 + p = mangle_path(s->buffer + s->len, p, "\n\\");
69745 if (p) {
69746 s->len = p - s->buffer;
69747 return 1;
69748 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
69749 index d4545f4..a9010a1 100644
69750 --- a/kernel/trace/trace_stack.c
69751 +++ b/kernel/trace/trace_stack.c
69752 @@ -53,7 +53,7 @@ static inline void check_stack(void)
69753 return;
69754
69755 /* we do not handle interrupt stacks yet */
69756 - if (!object_is_on_stack(&this_size))
69757 + if (!object_starts_on_stack(&this_size))
69758 return;
69759
69760 local_irq_save(flags);
69761 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
69762 index 209b379..7f76423 100644
69763 --- a/kernel/trace/trace_workqueue.c
69764 +++ b/kernel/trace/trace_workqueue.c
69765 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
69766 int cpu;
69767 pid_t pid;
69768 /* Can be inserted from interrupt or user context, need to be atomic */
69769 - atomic_t inserted;
69770 + atomic_unchecked_t inserted;
69771 /*
69772 * Don't need to be atomic, works are serialized in a single workqueue thread
69773 * on a single CPU.
69774 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
69775 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
69776 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
69777 if (node->pid == wq_thread->pid) {
69778 - atomic_inc(&node->inserted);
69779 + atomic_inc_unchecked(&node->inserted);
69780 goto found;
69781 }
69782 }
69783 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
69784 tsk = get_pid_task(pid, PIDTYPE_PID);
69785 if (tsk) {
69786 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
69787 - atomic_read(&cws->inserted), cws->executed,
69788 + atomic_read_unchecked(&cws->inserted), cws->executed,
69789 tsk->comm);
69790 put_task_struct(tsk);
69791 }
69792 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
69793 index 8745ac7..d144e37 100644
69794 --- a/lib/Kconfig.debug
69795 +++ b/lib/Kconfig.debug
69796 @@ -1103,6 +1103,7 @@ config LATENCYTOP
69797 depends on DEBUG_KERNEL
69798 depends on STACKTRACE_SUPPORT
69799 depends on PROC_FS
69800 + depends on !GRKERNSEC_HIDESYM
69801 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
69802 select KALLSYMS
69803 select KALLSYMS_ALL
69804 diff --git a/lib/bitmap.c b/lib/bitmap.c
69805 index 0d4a127..33a06c7 100644
69806 --- a/lib/bitmap.c
69807 +++ b/lib/bitmap.c
69808 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
69809 {
69810 int c, old_c, totaldigits, ndigits, nchunks, nbits;
69811 u32 chunk;
69812 - const char __user __force *ubuf = (const char __user __force *)buf;
69813 + const char __user *ubuf = (const char __force_user *)buf;
69814
69815 bitmap_zero(maskp, nmaskbits);
69816
69817 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
69818 {
69819 if (!access_ok(VERIFY_READ, ubuf, ulen))
69820 return -EFAULT;
69821 - return __bitmap_parse((const char __force *)ubuf,
69822 + return __bitmap_parse((const char __force_kernel *)ubuf,
69823 ulen, 1, maskp, nmaskbits);
69824
69825 }
69826 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
69827 {
69828 unsigned a, b;
69829 int c, old_c, totaldigits;
69830 - const char __user __force *ubuf = (const char __user __force *)buf;
69831 + const char __user *ubuf = (const char __force_user *)buf;
69832 int exp_digit, in_range;
69833
69834 totaldigits = c = 0;
69835 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
69836 {
69837 if (!access_ok(VERIFY_READ, ubuf, ulen))
69838 return -EFAULT;
69839 - return __bitmap_parselist((const char __force *)ubuf,
69840 + return __bitmap_parselist((const char __force_kernel *)ubuf,
69841 ulen, 1, maskp, nmaskbits);
69842 }
69843 EXPORT_SYMBOL(bitmap_parselist_user);
69844 diff --git a/lib/bug.c b/lib/bug.c
69845 index a28c141..2bd3d95 100644
69846 --- a/lib/bug.c
69847 +++ b/lib/bug.c
69848 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
69849 return BUG_TRAP_TYPE_NONE;
69850
69851 bug = find_bug(bugaddr);
69852 + if (!bug)
69853 + return BUG_TRAP_TYPE_NONE;
69854
69855 file = NULL;
69856 line = 0;
69857 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
69858 index 0ab9ae8..f01ceca 100644
69859 --- a/lib/debugobjects.c
69860 +++ b/lib/debugobjects.c
69861 @@ -288,7 +288,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
69862 if (limit > 4)
69863 return;
69864
69865 - is_on_stack = object_is_on_stack(addr);
69866 + is_on_stack = object_starts_on_stack(addr);
69867 if (is_on_stack == onstack)
69868 return;
69869
69870 diff --git a/lib/devres.c b/lib/devres.c
69871 index 9676617..5149e15 100644
69872 --- a/lib/devres.c
69873 +++ b/lib/devres.c
69874 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
69875 void devm_iounmap(struct device *dev, void __iomem *addr)
69876 {
69877 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
69878 - (void *)addr));
69879 + (void __force *)addr));
69880 iounmap(addr);
69881 }
69882 EXPORT_SYMBOL(devm_iounmap);
69883 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
69884 {
69885 ioport_unmap(addr);
69886 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
69887 - devm_ioport_map_match, (void *)addr));
69888 + devm_ioport_map_match, (void __force *)addr));
69889 }
69890 EXPORT_SYMBOL(devm_ioport_unmap);
69891
69892 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
69893 index fea790a..ebb0e82 100644
69894 --- a/lib/dma-debug.c
69895 +++ b/lib/dma-debug.c
69896 @@ -925,7 +925,7 @@ out:
69897
69898 static void check_for_stack(struct device *dev, void *addr)
69899 {
69900 - if (object_is_on_stack(addr))
69901 + if (object_starts_on_stack(addr))
69902 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
69903 "stack [addr=%p]\n", addr);
69904 }
69905 diff --git a/lib/extable.c b/lib/extable.c
69906 index 4cac81e..63e9b8f 100644
69907 --- a/lib/extable.c
69908 +++ b/lib/extable.c
69909 @@ -13,6 +13,7 @@
69910 #include <linux/init.h>
69911 #include <linux/sort.h>
69912 #include <asm/uaccess.h>
69913 +#include <asm/pgtable.h>
69914
69915 #ifndef ARCH_HAS_SORT_EXTABLE
69916 /*
69917 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
69918 void sort_extable(struct exception_table_entry *start,
69919 struct exception_table_entry *finish)
69920 {
69921 + pax_open_kernel();
69922 sort(start, finish - start, sizeof(struct exception_table_entry),
69923 cmp_ex, NULL);
69924 + pax_close_kernel();
69925 }
69926
69927 #ifdef CONFIG_MODULES
69928 diff --git a/lib/inflate.c b/lib/inflate.c
69929 index 013a761..c28f3fc 100644
69930 --- a/lib/inflate.c
69931 +++ b/lib/inflate.c
69932 @@ -269,7 +269,7 @@ static void free(void *where)
69933 malloc_ptr = free_mem_ptr;
69934 }
69935 #else
69936 -#define malloc(a) kmalloc(a, GFP_KERNEL)
69937 +#define malloc(a) kmalloc((a), GFP_KERNEL)
69938 #define free(a) kfree(a)
69939 #endif
69940
69941 diff --git a/lib/ioremap.c b/lib/ioremap.c
69942 index da4e2ad..6373b5f 100644
69943 --- a/lib/ioremap.c
69944 +++ b/lib/ioremap.c
69945 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
69946 unsigned long next;
69947
69948 phys_addr -= addr;
69949 - pmd = pmd_alloc(&init_mm, pud, addr);
69950 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
69951 if (!pmd)
69952 return -ENOMEM;
69953 do {
69954 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
69955 unsigned long next;
69956
69957 phys_addr -= addr;
69958 - pud = pud_alloc(&init_mm, pgd, addr);
69959 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
69960 if (!pud)
69961 return -ENOMEM;
69962 do {
69963 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
69964 index bd2bea9..6b3c95e 100644
69965 --- a/lib/is_single_threaded.c
69966 +++ b/lib/is_single_threaded.c
69967 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
69968 struct task_struct *p, *t;
69969 bool ret;
69970
69971 + if (!mm)
69972 + return true;
69973 +
69974 if (atomic_read(&task->signal->live) != 1)
69975 return false;
69976
69977 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
69978 index dc63d08..95ae14a 100644
69979 --- a/lib/radix-tree.c
69980 +++ b/lib/radix-tree.c
69981 @@ -78,7 +78,7 @@ struct radix_tree_preload {
69982 int nr;
69983 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
69984 };
69985 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
69986 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
69987
69988 static inline void *ptr_to_indirect(void *ptr)
69989 {
69990 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
69991 index 38e612e..4fb99a8 100644
69992 --- a/lib/vsprintf.c
69993 +++ b/lib/vsprintf.c
69994 @@ -16,6 +16,9 @@
69995 * - scnprintf and vscnprintf
69996 */
69997
69998 +#ifdef CONFIG_GRKERNSEC_HIDESYM
69999 +#define __INCLUDED_BY_HIDESYM 1
70000 +#endif
70001 #include <stdarg.h>
70002 #include <linux/module.h>
70003 #include <linux/types.h>
70004 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
70005 char sym[KSYM_SYMBOL_LEN];
70006 if (ext == 'B')
70007 sprint_backtrace(sym, value);
70008 - else if (ext != 'f' && ext != 's')
70009 + else if (ext != 'f' && ext != 's' && ext != 'a')
70010 sprint_symbol(sym, value);
70011 else
70012 kallsyms_lookup(value, NULL, NULL, NULL, sym);
70013 @@ -789,7 +792,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
70014 return number(buf, end, *(const netdev_features_t *)addr, spec);
70015 }
70016
70017 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70018 +int kptr_restrict __read_mostly = 2;
70019 +#else
70020 int kptr_restrict __read_mostly;
70021 +#endif
70022
70023 /*
70024 * Show a '%p' thing. A kernel extension is that the '%p' is followed
70025 @@ -803,6 +810,8 @@ int kptr_restrict __read_mostly;
70026 * - 'S' For symbolic direct pointers with offset
70027 * - 's' For symbolic direct pointers without offset
70028 * - 'B' For backtraced symbolic direct pointers with offset
70029 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
70030 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
70031 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
70032 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
70033 * - 'M' For a 6-byte MAC address, it prints the address in the
70034 @@ -848,12 +857,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70035 {
70036 if (!ptr && *fmt != 'K') {
70037 /*
70038 - * Print (null) with the same width as a pointer so it makes
70039 + * Print (nil) with the same width as a pointer so it makes
70040 * tabular output look nice.
70041 */
70042 if (spec.field_width == -1)
70043 spec.field_width = 2 * sizeof(void *);
70044 - return string(buf, end, "(null)", spec);
70045 + return string(buf, end, "(nil)", spec);
70046 }
70047
70048 switch (*fmt) {
70049 @@ -863,6 +872,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
70050 /* Fallthrough */
70051 case 'S':
70052 case 's':
70053 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70054 + break;
70055 +#else
70056 + return symbol_string(buf, end, ptr, spec, *fmt);
70057 +#endif
70058 + case 'A':
70059 + case 'a':
70060 case 'B':
70061 return symbol_string(buf, end, ptr, spec, *fmt);
70062 case 'R':
70063 @@ -1633,11 +1649,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70064 typeof(type) value; \
70065 if (sizeof(type) == 8) { \
70066 args = PTR_ALIGN(args, sizeof(u32)); \
70067 - *(u32 *)&value = *(u32 *)args; \
70068 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
70069 + *(u32 *)&value = *(const u32 *)args; \
70070 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
70071 } else { \
70072 args = PTR_ALIGN(args, sizeof(type)); \
70073 - value = *(typeof(type) *)args; \
70074 + value = *(const typeof(type) *)args; \
70075 } \
70076 args += sizeof(type); \
70077 value; \
70078 @@ -1700,7 +1716,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
70079 case FORMAT_TYPE_STR: {
70080 const char *str_arg = args;
70081 args += strlen(str_arg) + 1;
70082 - str = string(str, end, (char *)str_arg, spec);
70083 + str = string(str, end, str_arg, spec);
70084 break;
70085 }
70086
70087 diff --git a/localversion-grsec b/localversion-grsec
70088 new file mode 100644
70089 index 0000000..7cd6065
70090 --- /dev/null
70091 +++ b/localversion-grsec
70092 @@ -0,0 +1 @@
70093 +-grsec
70094 diff --git a/mm/Kconfig b/mm/Kconfig
70095 index e338407..4210331 100644
70096 --- a/mm/Kconfig
70097 +++ b/mm/Kconfig
70098 @@ -247,10 +247,10 @@ config KSM
70099 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
70100
70101 config DEFAULT_MMAP_MIN_ADDR
70102 - int "Low address space to protect from user allocation"
70103 + int "Low address space to protect from user allocation"
70104 depends on MMU
70105 - default 4096
70106 - help
70107 + default 65536
70108 + help
70109 This is the portion of low virtual memory which should be protected
70110 from userspace allocation. Keeping a user from writing to low pages
70111 can help reduce the impact of kernel NULL pointer bugs.
70112 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
70113
70114 config HWPOISON_INJECT
70115 tristate "HWPoison pages injector"
70116 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
70117 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
70118 select PROC_PAGE_MONITOR
70119
70120 config NOMMU_INITIAL_TRIM_EXCESS
70121 diff --git a/mm/filemap.c b/mm/filemap.c
70122 index b662757..3081ddd 100644
70123 --- a/mm/filemap.c
70124 +++ b/mm/filemap.c
70125 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
70126 struct address_space *mapping = file->f_mapping;
70127
70128 if (!mapping->a_ops->readpage)
70129 - return -ENOEXEC;
70130 + return -ENODEV;
70131 file_accessed(file);
70132 vma->vm_ops = &generic_file_vm_ops;
70133 vma->vm_flags |= VM_CAN_NONLINEAR;
70134 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
70135 *pos = i_size_read(inode);
70136
70137 if (limit != RLIM_INFINITY) {
70138 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
70139 if (*pos >= limit) {
70140 send_sig(SIGXFSZ, current, 0);
70141 return -EFBIG;
70142 diff --git a/mm/fremap.c b/mm/fremap.c
70143 index 9ed4fd4..c42648d 100644
70144 --- a/mm/fremap.c
70145 +++ b/mm/fremap.c
70146 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
70147 retry:
70148 vma = find_vma(mm, start);
70149
70150 +#ifdef CONFIG_PAX_SEGMEXEC
70151 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
70152 + goto out;
70153 +#endif
70154 +
70155 /*
70156 * Make sure the vma is shared, that it supports prefaulting,
70157 * and that the remapped range is valid and fully within
70158 diff --git a/mm/highmem.c b/mm/highmem.c
70159 index 57d82c6..e9e0552 100644
70160 --- a/mm/highmem.c
70161 +++ b/mm/highmem.c
70162 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
70163 * So no dangers, even with speculative execution.
70164 */
70165 page = pte_page(pkmap_page_table[i]);
70166 + pax_open_kernel();
70167 pte_clear(&init_mm, (unsigned long)page_address(page),
70168 &pkmap_page_table[i]);
70169 -
70170 + pax_close_kernel();
70171 set_page_address(page, NULL);
70172 need_flush = 1;
70173 }
70174 @@ -186,9 +187,11 @@ start:
70175 }
70176 }
70177 vaddr = PKMAP_ADDR(last_pkmap_nr);
70178 +
70179 + pax_open_kernel();
70180 set_pte_at(&init_mm, vaddr,
70181 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
70182 -
70183 + pax_close_kernel();
70184 pkmap_count[last_pkmap_nr] = 1;
70185 set_page_address(page, (void *)vaddr);
70186
70187 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
70188 index 8f7fc39..69bf1e9 100644
70189 --- a/mm/huge_memory.c
70190 +++ b/mm/huge_memory.c
70191 @@ -733,7 +733,7 @@ out:
70192 * run pte_offset_map on the pmd, if an huge pmd could
70193 * materialize from under us from a different thread.
70194 */
70195 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
70196 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
70197 return VM_FAULT_OOM;
70198 /* if an huge pmd materialized from under us just retry later */
70199 if (unlikely(pmd_trans_huge(*pmd)))
70200 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
70201 index fece520..e10da7f 100644
70202 --- a/mm/hugetlb.c
70203 +++ b/mm/hugetlb.c
70204 @@ -2146,6 +2146,15 @@ static void hugetlb_vm_op_open(struct vm_area_struct *vma)
70205 kref_get(&reservations->refs);
70206 }
70207
70208 +static void resv_map_put(struct vm_area_struct *vma)
70209 +{
70210 + struct resv_map *reservations = vma_resv_map(vma);
70211 +
70212 + if (!reservations)
70213 + return;
70214 + kref_put(&reservations->refs, resv_map_release);
70215 +}
70216 +
70217 static void hugetlb_vm_op_close(struct vm_area_struct *vma)
70218 {
70219 struct hstate *h = hstate_vma(vma);
70220 @@ -2162,7 +2171,7 @@ static void hugetlb_vm_op_close(struct vm_area_struct *vma)
70221 reserve = (end - start) -
70222 region_count(&reservations->regions, start, end);
70223
70224 - kref_put(&reservations->refs, resv_map_release);
70225 + resv_map_put(vma);
70226
70227 if (reserve) {
70228 hugetlb_acct_memory(h, -reserve);
70229 @@ -2425,6 +2434,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
70230 return 1;
70231 }
70232
70233 +#ifdef CONFIG_PAX_SEGMEXEC
70234 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
70235 +{
70236 + struct mm_struct *mm = vma->vm_mm;
70237 + struct vm_area_struct *vma_m;
70238 + unsigned long address_m;
70239 + pte_t *ptep_m;
70240 +
70241 + vma_m = pax_find_mirror_vma(vma);
70242 + if (!vma_m)
70243 + return;
70244 +
70245 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70246 + address_m = address + SEGMEXEC_TASK_SIZE;
70247 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
70248 + get_page(page_m);
70249 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
70250 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
70251 +}
70252 +#endif
70253 +
70254 /*
70255 * Hugetlb_cow() should be called with page lock of the original hugepage held.
70256 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
70257 @@ -2537,6 +2567,11 @@ retry_avoidcopy:
70258 make_huge_pte(vma, new_page, 1));
70259 page_remove_rmap(old_page);
70260 hugepage_add_new_anon_rmap(new_page, vma, address);
70261 +
70262 +#ifdef CONFIG_PAX_SEGMEXEC
70263 + pax_mirror_huge_pte(vma, address, new_page);
70264 +#endif
70265 +
70266 /* Make the old page be freed below */
70267 new_page = old_page;
70268 mmu_notifier_invalidate_range_end(mm,
70269 @@ -2691,6 +2726,10 @@ retry:
70270 && (vma->vm_flags & VM_SHARED)));
70271 set_huge_pte_at(mm, address, ptep, new_pte);
70272
70273 +#ifdef CONFIG_PAX_SEGMEXEC
70274 + pax_mirror_huge_pte(vma, address, page);
70275 +#endif
70276 +
70277 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
70278 /* Optimization, do the COW without a second fault */
70279 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
70280 @@ -2720,6 +2759,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70281 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
70282 struct hstate *h = hstate_vma(vma);
70283
70284 +#ifdef CONFIG_PAX_SEGMEXEC
70285 + struct vm_area_struct *vma_m;
70286 +#endif
70287 +
70288 address &= huge_page_mask(h);
70289
70290 ptep = huge_pte_offset(mm, address);
70291 @@ -2733,6 +2776,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
70292 VM_FAULT_SET_HINDEX(h - hstates);
70293 }
70294
70295 +#ifdef CONFIG_PAX_SEGMEXEC
70296 + vma_m = pax_find_mirror_vma(vma);
70297 + if (vma_m) {
70298 + unsigned long address_m;
70299 +
70300 + if (vma->vm_start > vma_m->vm_start) {
70301 + address_m = address;
70302 + address -= SEGMEXEC_TASK_SIZE;
70303 + vma = vma_m;
70304 + h = hstate_vma(vma);
70305 + } else
70306 + address_m = address + SEGMEXEC_TASK_SIZE;
70307 +
70308 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
70309 + return VM_FAULT_OOM;
70310 + address_m &= HPAGE_MASK;
70311 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
70312 + }
70313 +#endif
70314 +
70315 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
70316 if (!ptep)
70317 return VM_FAULT_OOM;
70318 @@ -2978,12 +3041,16 @@ int hugetlb_reserve_pages(struct inode *inode,
70319 set_vma_resv_flags(vma, HPAGE_RESV_OWNER);
70320 }
70321
70322 - if (chg < 0)
70323 - return chg;
70324 + if (chg < 0) {
70325 + ret = chg;
70326 + goto out_err;
70327 + }
70328
70329 /* There must be enough pages in the subpool for the mapping */
70330 - if (hugepage_subpool_get_pages(spool, chg))
70331 - return -ENOSPC;
70332 + if (hugepage_subpool_get_pages(spool, chg)) {
70333 + ret = -ENOSPC;
70334 + goto out_err;
70335 + }
70336
70337 /*
70338 * Check enough hugepages are available for the reservation.
70339 @@ -2992,7 +3059,7 @@ int hugetlb_reserve_pages(struct inode *inode,
70340 ret = hugetlb_acct_memory(h, chg);
70341 if (ret < 0) {
70342 hugepage_subpool_put_pages(spool, chg);
70343 - return ret;
70344 + goto out_err;
70345 }
70346
70347 /*
70348 @@ -3009,6 +3076,10 @@ int hugetlb_reserve_pages(struct inode *inode,
70349 if (!vma || vma->vm_flags & VM_MAYSHARE)
70350 region_add(&inode->i_mapping->private_list, from, to);
70351 return 0;
70352 +out_err:
70353 + if (vma)
70354 + resv_map_put(vma);
70355 + return ret;
70356 }
70357
70358 void hugetlb_unreserve_pages(struct inode *inode, long offset, long freed)
70359 diff --git a/mm/internal.h b/mm/internal.h
70360 index 2189af4..f2ca332 100644
70361 --- a/mm/internal.h
70362 +++ b/mm/internal.h
70363 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
70364 * in mm/page_alloc.c
70365 */
70366 extern void __free_pages_bootmem(struct page *page, unsigned int order);
70367 +extern void free_compound_page(struct page *page);
70368 extern void prep_compound_page(struct page *page, unsigned long order);
70369 #ifdef CONFIG_MEMORY_FAILURE
70370 extern bool is_free_buddy_page(struct page *page);
70371 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
70372 index 45eb621..6ccd8ea 100644
70373 --- a/mm/kmemleak.c
70374 +++ b/mm/kmemleak.c
70375 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
70376
70377 for (i = 0; i < object->trace_len; i++) {
70378 void *ptr = (void *)object->trace[i];
70379 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
70380 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
70381 }
70382 }
70383
70384 diff --git a/mm/maccess.c b/mm/maccess.c
70385 index d53adf9..03a24bf 100644
70386 --- a/mm/maccess.c
70387 +++ b/mm/maccess.c
70388 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
70389 set_fs(KERNEL_DS);
70390 pagefault_disable();
70391 ret = __copy_from_user_inatomic(dst,
70392 - (__force const void __user *)src, size);
70393 + (const void __force_user *)src, size);
70394 pagefault_enable();
70395 set_fs(old_fs);
70396
70397 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
70398
70399 set_fs(KERNEL_DS);
70400 pagefault_disable();
70401 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
70402 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
70403 pagefault_enable();
70404 set_fs(old_fs);
70405
70406 diff --git a/mm/madvise.c b/mm/madvise.c
70407 index 74bf193..feb6fd3 100644
70408 --- a/mm/madvise.c
70409 +++ b/mm/madvise.c
70410 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
70411 pgoff_t pgoff;
70412 unsigned long new_flags = vma->vm_flags;
70413
70414 +#ifdef CONFIG_PAX_SEGMEXEC
70415 + struct vm_area_struct *vma_m;
70416 +#endif
70417 +
70418 switch (behavior) {
70419 case MADV_NORMAL:
70420 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
70421 @@ -110,6 +114,13 @@ success:
70422 /*
70423 * vm_flags is protected by the mmap_sem held in write mode.
70424 */
70425 +
70426 +#ifdef CONFIG_PAX_SEGMEXEC
70427 + vma_m = pax_find_mirror_vma(vma);
70428 + if (vma_m)
70429 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
70430 +#endif
70431 +
70432 vma->vm_flags = new_flags;
70433
70434 out:
70435 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70436 struct vm_area_struct ** prev,
70437 unsigned long start, unsigned long end)
70438 {
70439 +
70440 +#ifdef CONFIG_PAX_SEGMEXEC
70441 + struct vm_area_struct *vma_m;
70442 +#endif
70443 +
70444 *prev = vma;
70445 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
70446 return -EINVAL;
70447 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
70448 zap_page_range(vma, start, end - start, &details);
70449 } else
70450 zap_page_range(vma, start, end - start, NULL);
70451 +
70452 +#ifdef CONFIG_PAX_SEGMEXEC
70453 + vma_m = pax_find_mirror_vma(vma);
70454 + if (vma_m) {
70455 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
70456 + struct zap_details details = {
70457 + .nonlinear_vma = vma_m,
70458 + .last_index = ULONG_MAX,
70459 + };
70460 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
70461 + } else
70462 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
70463 + }
70464 +#endif
70465 +
70466 return 0;
70467 }
70468
70469 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
70470 if (end < start)
70471 goto out;
70472
70473 +#ifdef CONFIG_PAX_SEGMEXEC
70474 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70475 + if (end > SEGMEXEC_TASK_SIZE)
70476 + goto out;
70477 + } else
70478 +#endif
70479 +
70480 + if (end > TASK_SIZE)
70481 + goto out;
70482 +
70483 error = 0;
70484 if (end == start)
70485 goto out;
70486 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
70487 index 56080ea..115071e 100644
70488 --- a/mm/memory-failure.c
70489 +++ b/mm/memory-failure.c
70490 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
70491
70492 int sysctl_memory_failure_recovery __read_mostly = 1;
70493
70494 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70495 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
70496
70497 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
70498
70499 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
70500 si.si_signo = SIGBUS;
70501 si.si_errno = 0;
70502 si.si_code = BUS_MCEERR_AO;
70503 - si.si_addr = (void *)addr;
70504 + si.si_addr = (void __user *)addr;
70505 #ifdef __ARCH_SI_TRAPNO
70506 si.si_trapno = trapno;
70507 #endif
70508 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70509 }
70510
70511 nr_pages = 1 << compound_trans_order(hpage);
70512 - atomic_long_add(nr_pages, &mce_bad_pages);
70513 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
70514
70515 /*
70516 * We need/can do nothing about count=0 pages.
70517 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70518 if (!PageHWPoison(hpage)
70519 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
70520 || (p != hpage && TestSetPageHWPoison(hpage))) {
70521 - atomic_long_sub(nr_pages, &mce_bad_pages);
70522 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70523 return 0;
70524 }
70525 set_page_hwpoison_huge_page(hpage);
70526 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
70527 }
70528 if (hwpoison_filter(p)) {
70529 if (TestClearPageHWPoison(p))
70530 - atomic_long_sub(nr_pages, &mce_bad_pages);
70531 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70532 unlock_page(hpage);
70533 put_page(hpage);
70534 return 0;
70535 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
70536 return 0;
70537 }
70538 if (TestClearPageHWPoison(p))
70539 - atomic_long_sub(nr_pages, &mce_bad_pages);
70540 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70541 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
70542 return 0;
70543 }
70544 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
70545 */
70546 if (TestClearPageHWPoison(page)) {
70547 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
70548 - atomic_long_sub(nr_pages, &mce_bad_pages);
70549 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
70550 freeit = 1;
70551 if (PageHuge(page))
70552 clear_page_hwpoison_huge_page(page);
70553 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
70554 }
70555 done:
70556 if (!PageHWPoison(hpage))
70557 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
70558 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
70559 set_page_hwpoison_huge_page(hpage);
70560 dequeue_hwpoisoned_huge_page(hpage);
70561 /* keep elevated page count for bad page */
70562 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
70563 return ret;
70564
70565 done:
70566 - atomic_long_add(1, &mce_bad_pages);
70567 + atomic_long_add_unchecked(1, &mce_bad_pages);
70568 SetPageHWPoison(page);
70569 /* keep elevated page count for bad page */
70570 return ret;
70571 diff --git a/mm/memory.c b/mm/memory.c
70572 index 10b4dda..06857f3 100644
70573 --- a/mm/memory.c
70574 +++ b/mm/memory.c
70575 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
70576 return;
70577
70578 pmd = pmd_offset(pud, start);
70579 +
70580 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
70581 pud_clear(pud);
70582 pmd_free_tlb(tlb, pmd, start);
70583 +#endif
70584 +
70585 }
70586
70587 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70588 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
70589 if (end - 1 > ceiling - 1)
70590 return;
70591
70592 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
70593 pud = pud_offset(pgd, start);
70594 pgd_clear(pgd);
70595 pud_free_tlb(tlb, pud, start);
70596 +#endif
70597 +
70598 }
70599
70600 /*
70601 @@ -1593,12 +1600,6 @@ no_page_table:
70602 return page;
70603 }
70604
70605 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
70606 -{
70607 - return stack_guard_page_start(vma, addr) ||
70608 - stack_guard_page_end(vma, addr+PAGE_SIZE);
70609 -}
70610 -
70611 /**
70612 * __get_user_pages() - pin user pages in memory
70613 * @tsk: task_struct of target task
70614 @@ -1671,10 +1672,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70615 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
70616 i = 0;
70617
70618 - do {
70619 + while (nr_pages) {
70620 struct vm_area_struct *vma;
70621
70622 - vma = find_extend_vma(mm, start);
70623 + vma = find_vma(mm, start);
70624 if (!vma && in_gate_area(mm, start)) {
70625 unsigned long pg = start & PAGE_MASK;
70626 pgd_t *pgd;
70627 @@ -1722,7 +1723,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70628 goto next_page;
70629 }
70630
70631 - if (!vma ||
70632 + if (!vma || start < vma->vm_start ||
70633 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
70634 !(vm_flags & vma->vm_flags))
70635 return i ? : -EFAULT;
70636 @@ -1749,11 +1750,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70637 int ret;
70638 unsigned int fault_flags = 0;
70639
70640 - /* For mlock, just skip the stack guard page. */
70641 - if (foll_flags & FOLL_MLOCK) {
70642 - if (stack_guard_page(vma, start))
70643 - goto next_page;
70644 - }
70645 if (foll_flags & FOLL_WRITE)
70646 fault_flags |= FAULT_FLAG_WRITE;
70647 if (nonblocking)
70648 @@ -1827,7 +1823,7 @@ next_page:
70649 start += PAGE_SIZE;
70650 nr_pages--;
70651 } while (nr_pages && start < vma->vm_end);
70652 - } while (nr_pages);
70653 + }
70654 return i;
70655 }
70656 EXPORT_SYMBOL(__get_user_pages);
70657 @@ -2034,6 +2030,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
70658 page_add_file_rmap(page);
70659 set_pte_at(mm, addr, pte, mk_pte(page, prot));
70660
70661 +#ifdef CONFIG_PAX_SEGMEXEC
70662 + pax_mirror_file_pte(vma, addr, page, ptl);
70663 +#endif
70664 +
70665 retval = 0;
70666 pte_unmap_unlock(pte, ptl);
70667 return retval;
70668 @@ -2068,10 +2068,22 @@ out:
70669 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
70670 struct page *page)
70671 {
70672 +
70673 +#ifdef CONFIG_PAX_SEGMEXEC
70674 + struct vm_area_struct *vma_m;
70675 +#endif
70676 +
70677 if (addr < vma->vm_start || addr >= vma->vm_end)
70678 return -EFAULT;
70679 if (!page_count(page))
70680 return -EINVAL;
70681 +
70682 +#ifdef CONFIG_PAX_SEGMEXEC
70683 + vma_m = pax_find_mirror_vma(vma);
70684 + if (vma_m)
70685 + vma_m->vm_flags |= VM_INSERTPAGE;
70686 +#endif
70687 +
70688 vma->vm_flags |= VM_INSERTPAGE;
70689 return insert_page(vma, addr, page, vma->vm_page_prot);
70690 }
70691 @@ -2157,6 +2169,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
70692 unsigned long pfn)
70693 {
70694 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
70695 + BUG_ON(vma->vm_mirror);
70696
70697 if (addr < vma->vm_start || addr >= vma->vm_end)
70698 return -EFAULT;
70699 @@ -2364,7 +2377,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
70700
70701 BUG_ON(pud_huge(*pud));
70702
70703 - pmd = pmd_alloc(mm, pud, addr);
70704 + pmd = (mm == &init_mm) ?
70705 + pmd_alloc_kernel(mm, pud, addr) :
70706 + pmd_alloc(mm, pud, addr);
70707 if (!pmd)
70708 return -ENOMEM;
70709 do {
70710 @@ -2384,7 +2399,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
70711 unsigned long next;
70712 int err;
70713
70714 - pud = pud_alloc(mm, pgd, addr);
70715 + pud = (mm == &init_mm) ?
70716 + pud_alloc_kernel(mm, pgd, addr) :
70717 + pud_alloc(mm, pgd, addr);
70718 if (!pud)
70719 return -ENOMEM;
70720 do {
70721 @@ -2472,6 +2489,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
70722 copy_user_highpage(dst, src, va, vma);
70723 }
70724
70725 +#ifdef CONFIG_PAX_SEGMEXEC
70726 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
70727 +{
70728 + struct mm_struct *mm = vma->vm_mm;
70729 + spinlock_t *ptl;
70730 + pte_t *pte, entry;
70731 +
70732 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
70733 + entry = *pte;
70734 + if (!pte_present(entry)) {
70735 + if (!pte_none(entry)) {
70736 + BUG_ON(pte_file(entry));
70737 + free_swap_and_cache(pte_to_swp_entry(entry));
70738 + pte_clear_not_present_full(mm, address, pte, 0);
70739 + }
70740 + } else {
70741 + struct page *page;
70742 +
70743 + flush_cache_page(vma, address, pte_pfn(entry));
70744 + entry = ptep_clear_flush(vma, address, pte);
70745 + BUG_ON(pte_dirty(entry));
70746 + page = vm_normal_page(vma, address, entry);
70747 + if (page) {
70748 + update_hiwater_rss(mm);
70749 + if (PageAnon(page))
70750 + dec_mm_counter_fast(mm, MM_ANONPAGES);
70751 + else
70752 + dec_mm_counter_fast(mm, MM_FILEPAGES);
70753 + page_remove_rmap(page);
70754 + page_cache_release(page);
70755 + }
70756 + }
70757 + pte_unmap_unlock(pte, ptl);
70758 +}
70759 +
70760 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
70761 + *
70762 + * the ptl of the lower mapped page is held on entry and is not released on exit
70763 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
70764 + */
70765 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70766 +{
70767 + struct mm_struct *mm = vma->vm_mm;
70768 + unsigned long address_m;
70769 + spinlock_t *ptl_m;
70770 + struct vm_area_struct *vma_m;
70771 + pmd_t *pmd_m;
70772 + pte_t *pte_m, entry_m;
70773 +
70774 + BUG_ON(!page_m || !PageAnon(page_m));
70775 +
70776 + vma_m = pax_find_mirror_vma(vma);
70777 + if (!vma_m)
70778 + return;
70779 +
70780 + BUG_ON(!PageLocked(page_m));
70781 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70782 + address_m = address + SEGMEXEC_TASK_SIZE;
70783 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70784 + pte_m = pte_offset_map(pmd_m, address_m);
70785 + ptl_m = pte_lockptr(mm, pmd_m);
70786 + if (ptl != ptl_m) {
70787 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70788 + if (!pte_none(*pte_m))
70789 + goto out;
70790 + }
70791 +
70792 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70793 + page_cache_get(page_m);
70794 + page_add_anon_rmap(page_m, vma_m, address_m);
70795 + inc_mm_counter_fast(mm, MM_ANONPAGES);
70796 + set_pte_at(mm, address_m, pte_m, entry_m);
70797 + update_mmu_cache(vma_m, address_m, entry_m);
70798 +out:
70799 + if (ptl != ptl_m)
70800 + spin_unlock(ptl_m);
70801 + pte_unmap(pte_m);
70802 + unlock_page(page_m);
70803 +}
70804 +
70805 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
70806 +{
70807 + struct mm_struct *mm = vma->vm_mm;
70808 + unsigned long address_m;
70809 + spinlock_t *ptl_m;
70810 + struct vm_area_struct *vma_m;
70811 + pmd_t *pmd_m;
70812 + pte_t *pte_m, entry_m;
70813 +
70814 + BUG_ON(!page_m || PageAnon(page_m));
70815 +
70816 + vma_m = pax_find_mirror_vma(vma);
70817 + if (!vma_m)
70818 + return;
70819 +
70820 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70821 + address_m = address + SEGMEXEC_TASK_SIZE;
70822 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70823 + pte_m = pte_offset_map(pmd_m, address_m);
70824 + ptl_m = pte_lockptr(mm, pmd_m);
70825 + if (ptl != ptl_m) {
70826 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70827 + if (!pte_none(*pte_m))
70828 + goto out;
70829 + }
70830 +
70831 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
70832 + page_cache_get(page_m);
70833 + page_add_file_rmap(page_m);
70834 + inc_mm_counter_fast(mm, MM_FILEPAGES);
70835 + set_pte_at(mm, address_m, pte_m, entry_m);
70836 + update_mmu_cache(vma_m, address_m, entry_m);
70837 +out:
70838 + if (ptl != ptl_m)
70839 + spin_unlock(ptl_m);
70840 + pte_unmap(pte_m);
70841 +}
70842 +
70843 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
70844 +{
70845 + struct mm_struct *mm = vma->vm_mm;
70846 + unsigned long address_m;
70847 + spinlock_t *ptl_m;
70848 + struct vm_area_struct *vma_m;
70849 + pmd_t *pmd_m;
70850 + pte_t *pte_m, entry_m;
70851 +
70852 + vma_m = pax_find_mirror_vma(vma);
70853 + if (!vma_m)
70854 + return;
70855 +
70856 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
70857 + address_m = address + SEGMEXEC_TASK_SIZE;
70858 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
70859 + pte_m = pte_offset_map(pmd_m, address_m);
70860 + ptl_m = pte_lockptr(mm, pmd_m);
70861 + if (ptl != ptl_m) {
70862 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
70863 + if (!pte_none(*pte_m))
70864 + goto out;
70865 + }
70866 +
70867 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
70868 + set_pte_at(mm, address_m, pte_m, entry_m);
70869 +out:
70870 + if (ptl != ptl_m)
70871 + spin_unlock(ptl_m);
70872 + pte_unmap(pte_m);
70873 +}
70874 +
70875 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
70876 +{
70877 + struct page *page_m;
70878 + pte_t entry;
70879 +
70880 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
70881 + goto out;
70882 +
70883 + entry = *pte;
70884 + page_m = vm_normal_page(vma, address, entry);
70885 + if (!page_m)
70886 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
70887 + else if (PageAnon(page_m)) {
70888 + if (pax_find_mirror_vma(vma)) {
70889 + pte_unmap_unlock(pte, ptl);
70890 + lock_page(page_m);
70891 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
70892 + if (pte_same(entry, *pte))
70893 + pax_mirror_anon_pte(vma, address, page_m, ptl);
70894 + else
70895 + unlock_page(page_m);
70896 + }
70897 + } else
70898 + pax_mirror_file_pte(vma, address, page_m, ptl);
70899 +
70900 +out:
70901 + pte_unmap_unlock(pte, ptl);
70902 +}
70903 +#endif
70904 +
70905 /*
70906 * This routine handles present pages, when users try to write
70907 * to a shared page. It is done by copying the page to a new address
70908 @@ -2683,6 +2880,12 @@ gotten:
70909 */
70910 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
70911 if (likely(pte_same(*page_table, orig_pte))) {
70912 +
70913 +#ifdef CONFIG_PAX_SEGMEXEC
70914 + if (pax_find_mirror_vma(vma))
70915 + BUG_ON(!trylock_page(new_page));
70916 +#endif
70917 +
70918 if (old_page) {
70919 if (!PageAnon(old_page)) {
70920 dec_mm_counter_fast(mm, MM_FILEPAGES);
70921 @@ -2734,6 +2937,10 @@ gotten:
70922 page_remove_rmap(old_page);
70923 }
70924
70925 +#ifdef CONFIG_PAX_SEGMEXEC
70926 + pax_mirror_anon_pte(vma, address, new_page, ptl);
70927 +#endif
70928 +
70929 /* Free the old page.. */
70930 new_page = old_page;
70931 ret |= VM_FAULT_WRITE;
70932 @@ -3013,6 +3220,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70933 swap_free(entry);
70934 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
70935 try_to_free_swap(page);
70936 +
70937 +#ifdef CONFIG_PAX_SEGMEXEC
70938 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
70939 +#endif
70940 +
70941 unlock_page(page);
70942 if (swapcache) {
70943 /*
70944 @@ -3036,6 +3248,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
70945
70946 /* No need to invalidate - it was non-present before */
70947 update_mmu_cache(vma, address, page_table);
70948 +
70949 +#ifdef CONFIG_PAX_SEGMEXEC
70950 + pax_mirror_anon_pte(vma, address, page, ptl);
70951 +#endif
70952 +
70953 unlock:
70954 pte_unmap_unlock(page_table, ptl);
70955 out:
70956 @@ -3055,40 +3272,6 @@ out_release:
70957 }
70958
70959 /*
70960 - * This is like a special single-page "expand_{down|up}wards()",
70961 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
70962 - * doesn't hit another vma.
70963 - */
70964 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
70965 -{
70966 - address &= PAGE_MASK;
70967 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
70968 - struct vm_area_struct *prev = vma->vm_prev;
70969 -
70970 - /*
70971 - * Is there a mapping abutting this one below?
70972 - *
70973 - * That's only ok if it's the same stack mapping
70974 - * that has gotten split..
70975 - */
70976 - if (prev && prev->vm_end == address)
70977 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
70978 -
70979 - expand_downwards(vma, address - PAGE_SIZE);
70980 - }
70981 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
70982 - struct vm_area_struct *next = vma->vm_next;
70983 -
70984 - /* As VM_GROWSDOWN but s/below/above/ */
70985 - if (next && next->vm_start == address + PAGE_SIZE)
70986 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
70987 -
70988 - expand_upwards(vma, address + PAGE_SIZE);
70989 - }
70990 - return 0;
70991 -}
70992 -
70993 -/*
70994 * We enter with non-exclusive mmap_sem (to exclude vma changes,
70995 * but allow concurrent faults), and pte mapped but not yet locked.
70996 * We return with mmap_sem still held, but pte unmapped and unlocked.
70997 @@ -3097,27 +3280,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
70998 unsigned long address, pte_t *page_table, pmd_t *pmd,
70999 unsigned int flags)
71000 {
71001 - struct page *page;
71002 + struct page *page = NULL;
71003 spinlock_t *ptl;
71004 pte_t entry;
71005
71006 - pte_unmap(page_table);
71007 -
71008 - /* Check if we need to add a guard page to the stack */
71009 - if (check_stack_guard_page(vma, address) < 0)
71010 - return VM_FAULT_SIGBUS;
71011 -
71012 - /* Use the zero-page for reads */
71013 if (!(flags & FAULT_FLAG_WRITE)) {
71014 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
71015 vma->vm_page_prot));
71016 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
71017 + ptl = pte_lockptr(mm, pmd);
71018 + spin_lock(ptl);
71019 if (!pte_none(*page_table))
71020 goto unlock;
71021 goto setpte;
71022 }
71023
71024 /* Allocate our own private page. */
71025 + pte_unmap(page_table);
71026 +
71027 if (unlikely(anon_vma_prepare(vma)))
71028 goto oom;
71029 page = alloc_zeroed_user_highpage_movable(vma, address);
71030 @@ -3136,6 +3315,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
71031 if (!pte_none(*page_table))
71032 goto release;
71033
71034 +#ifdef CONFIG_PAX_SEGMEXEC
71035 + if (pax_find_mirror_vma(vma))
71036 + BUG_ON(!trylock_page(page));
71037 +#endif
71038 +
71039 inc_mm_counter_fast(mm, MM_ANONPAGES);
71040 page_add_new_anon_rmap(page, vma, address);
71041 setpte:
71042 @@ -3143,6 +3327,12 @@ setpte:
71043
71044 /* No need to invalidate - it was non-present before */
71045 update_mmu_cache(vma, address, page_table);
71046 +
71047 +#ifdef CONFIG_PAX_SEGMEXEC
71048 + if (page)
71049 + pax_mirror_anon_pte(vma, address, page, ptl);
71050 +#endif
71051 +
71052 unlock:
71053 pte_unmap_unlock(page_table, ptl);
71054 return 0;
71055 @@ -3286,6 +3476,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71056 */
71057 /* Only go through if we didn't race with anybody else... */
71058 if (likely(pte_same(*page_table, orig_pte))) {
71059 +
71060 +#ifdef CONFIG_PAX_SEGMEXEC
71061 + if (anon && pax_find_mirror_vma(vma))
71062 + BUG_ON(!trylock_page(page));
71063 +#endif
71064 +
71065 flush_icache_page(vma, page);
71066 entry = mk_pte(page, vma->vm_page_prot);
71067 if (flags & FAULT_FLAG_WRITE)
71068 @@ -3305,6 +3501,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71069
71070 /* no need to invalidate: a not-present page won't be cached */
71071 update_mmu_cache(vma, address, page_table);
71072 +
71073 +#ifdef CONFIG_PAX_SEGMEXEC
71074 + if (anon)
71075 + pax_mirror_anon_pte(vma, address, page, ptl);
71076 + else
71077 + pax_mirror_file_pte(vma, address, page, ptl);
71078 +#endif
71079 +
71080 } else {
71081 if (cow_page)
71082 mem_cgroup_uncharge_page(cow_page);
71083 @@ -3458,6 +3662,12 @@ int handle_pte_fault(struct mm_struct *mm,
71084 if (flags & FAULT_FLAG_WRITE)
71085 flush_tlb_fix_spurious_fault(vma, address);
71086 }
71087 +
71088 +#ifdef CONFIG_PAX_SEGMEXEC
71089 + pax_mirror_pte(vma, address, pte, pmd, ptl);
71090 + return 0;
71091 +#endif
71092 +
71093 unlock:
71094 pte_unmap_unlock(pte, ptl);
71095 return 0;
71096 @@ -3474,6 +3684,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71097 pmd_t *pmd;
71098 pte_t *pte;
71099
71100 +#ifdef CONFIG_PAX_SEGMEXEC
71101 + struct vm_area_struct *vma_m;
71102 +#endif
71103 +
71104 __set_current_state(TASK_RUNNING);
71105
71106 count_vm_event(PGFAULT);
71107 @@ -3485,6 +3699,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71108 if (unlikely(is_vm_hugetlb_page(vma)))
71109 return hugetlb_fault(mm, vma, address, flags);
71110
71111 +#ifdef CONFIG_PAX_SEGMEXEC
71112 + vma_m = pax_find_mirror_vma(vma);
71113 + if (vma_m) {
71114 + unsigned long address_m;
71115 + pgd_t *pgd_m;
71116 + pud_t *pud_m;
71117 + pmd_t *pmd_m;
71118 +
71119 + if (vma->vm_start > vma_m->vm_start) {
71120 + address_m = address;
71121 + address -= SEGMEXEC_TASK_SIZE;
71122 + vma = vma_m;
71123 + } else
71124 + address_m = address + SEGMEXEC_TASK_SIZE;
71125 +
71126 + pgd_m = pgd_offset(mm, address_m);
71127 + pud_m = pud_alloc(mm, pgd_m, address_m);
71128 + if (!pud_m)
71129 + return VM_FAULT_OOM;
71130 + pmd_m = pmd_alloc(mm, pud_m, address_m);
71131 + if (!pmd_m)
71132 + return VM_FAULT_OOM;
71133 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
71134 + return VM_FAULT_OOM;
71135 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
71136 + }
71137 +#endif
71138 +
71139 pgd = pgd_offset(mm, address);
71140 pud = pud_alloc(mm, pgd, address);
71141 if (!pud)
71142 @@ -3514,7 +3756,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71143 * run pte_offset_map on the pmd, if an huge pmd could
71144 * materialize from under us from a different thread.
71145 */
71146 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
71147 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71148 return VM_FAULT_OOM;
71149 /* if an huge pmd materialized from under us just retry later */
71150 if (unlikely(pmd_trans_huge(*pmd)))
71151 @@ -3551,6 +3793,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71152 spin_unlock(&mm->page_table_lock);
71153 return 0;
71154 }
71155 +
71156 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71157 +{
71158 + pud_t *new = pud_alloc_one(mm, address);
71159 + if (!new)
71160 + return -ENOMEM;
71161 +
71162 + smp_wmb(); /* See comment in __pte_alloc */
71163 +
71164 + spin_lock(&mm->page_table_lock);
71165 + if (pgd_present(*pgd)) /* Another has populated it */
71166 + pud_free(mm, new);
71167 + else
71168 + pgd_populate_kernel(mm, pgd, new);
71169 + spin_unlock(&mm->page_table_lock);
71170 + return 0;
71171 +}
71172 #endif /* __PAGETABLE_PUD_FOLDED */
71173
71174 #ifndef __PAGETABLE_PMD_FOLDED
71175 @@ -3581,6 +3840,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71176 spin_unlock(&mm->page_table_lock);
71177 return 0;
71178 }
71179 +
71180 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71181 +{
71182 + pmd_t *new = pmd_alloc_one(mm, address);
71183 + if (!new)
71184 + return -ENOMEM;
71185 +
71186 + smp_wmb(); /* See comment in __pte_alloc */
71187 +
71188 + spin_lock(&mm->page_table_lock);
71189 +#ifndef __ARCH_HAS_4LEVEL_HACK
71190 + if (pud_present(*pud)) /* Another has populated it */
71191 + pmd_free(mm, new);
71192 + else
71193 + pud_populate_kernel(mm, pud, new);
71194 +#else
71195 + if (pgd_present(*pud)) /* Another has populated it */
71196 + pmd_free(mm, new);
71197 + else
71198 + pgd_populate_kernel(mm, pud, new);
71199 +#endif /* __ARCH_HAS_4LEVEL_HACK */
71200 + spin_unlock(&mm->page_table_lock);
71201 + return 0;
71202 +}
71203 #endif /* __PAGETABLE_PMD_FOLDED */
71204
71205 int make_pages_present(unsigned long addr, unsigned long end)
71206 @@ -3618,7 +3901,7 @@ static int __init gate_vma_init(void)
71207 gate_vma.vm_start = FIXADDR_USER_START;
71208 gate_vma.vm_end = FIXADDR_USER_END;
71209 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
71210 - gate_vma.vm_page_prot = __P101;
71211 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
71212 /*
71213 * Make sure the vDSO gets into every core dump.
71214 * Dumping its contents makes post-mortem fully interpretable later
71215 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
71216 index a8f97d5..e2ed444 100644
71217 --- a/mm/mempolicy.c
71218 +++ b/mm/mempolicy.c
71219 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71220 unsigned long vmstart;
71221 unsigned long vmend;
71222
71223 +#ifdef CONFIG_PAX_SEGMEXEC
71224 + struct vm_area_struct *vma_m;
71225 +#endif
71226 +
71227 vma = find_vma(mm, start);
71228 if (!vma || vma->vm_start > start)
71229 return -EFAULT;
71230 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
71231 if (err)
71232 goto out;
71233 }
71234 +
71235 +#ifdef CONFIG_PAX_SEGMEXEC
71236 + vma_m = pax_find_mirror_vma(vma);
71237 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
71238 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
71239 + if (err)
71240 + goto out;
71241 + }
71242 +#endif
71243 +
71244 }
71245
71246 out:
71247 @@ -1105,6 +1119,17 @@ static long do_mbind(unsigned long start, unsigned long len,
71248
71249 if (end < start)
71250 return -EINVAL;
71251 +
71252 +#ifdef CONFIG_PAX_SEGMEXEC
71253 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
71254 + if (end > SEGMEXEC_TASK_SIZE)
71255 + return -EINVAL;
71256 + } else
71257 +#endif
71258 +
71259 + if (end > TASK_SIZE)
71260 + return -EINVAL;
71261 +
71262 if (end == start)
71263 return 0;
71264
71265 @@ -1323,6 +1348,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71266 if (!mm)
71267 goto out;
71268
71269 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71270 + if (mm != current->mm &&
71271 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71272 + err = -EPERM;
71273 + goto out;
71274 + }
71275 +#endif
71276 +
71277 /*
71278 * Check if this process has the right to modify the specified
71279 * process. The right exists if the process has administrative
71280 @@ -1332,8 +1365,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
71281 rcu_read_lock();
71282 tcred = __task_cred(task);
71283 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71284 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71285 - !capable(CAP_SYS_NICE)) {
71286 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71287 rcu_read_unlock();
71288 err = -EPERM;
71289 goto out;
71290 diff --git a/mm/migrate.c b/mm/migrate.c
71291 index 1503b6b..156c672 100644
71292 --- a/mm/migrate.c
71293 +++ b/mm/migrate.c
71294 @@ -1370,6 +1370,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71295 if (!mm)
71296 return -EINVAL;
71297
71298 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71299 + if (mm != current->mm &&
71300 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
71301 + err = -EPERM;
71302 + goto out;
71303 + }
71304 +#endif
71305 +
71306 /*
71307 * Check if this process has the right to modify the specified
71308 * process. The right exists if the process has administrative
71309 @@ -1379,8 +1387,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
71310 rcu_read_lock();
71311 tcred = __task_cred(task);
71312 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
71313 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
71314 - !capable(CAP_SYS_NICE)) {
71315 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
71316 rcu_read_unlock();
71317 err = -EPERM;
71318 goto out;
71319 diff --git a/mm/mlock.c b/mm/mlock.c
71320 index ef726e8..13e0901 100644
71321 --- a/mm/mlock.c
71322 +++ b/mm/mlock.c
71323 @@ -13,6 +13,7 @@
71324 #include <linux/pagemap.h>
71325 #include <linux/mempolicy.h>
71326 #include <linux/syscalls.h>
71327 +#include <linux/security.h>
71328 #include <linux/sched.h>
71329 #include <linux/export.h>
71330 #include <linux/rmap.h>
71331 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
71332 return -EINVAL;
71333 if (end == start)
71334 return 0;
71335 + if (end > TASK_SIZE)
71336 + return -EINVAL;
71337 +
71338 vma = find_vma(current->mm, start);
71339 if (!vma || vma->vm_start > start)
71340 return -ENOMEM;
71341 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
71342 for (nstart = start ; ; ) {
71343 vm_flags_t newflags;
71344
71345 +#ifdef CONFIG_PAX_SEGMEXEC
71346 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71347 + break;
71348 +#endif
71349 +
71350 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
71351
71352 newflags = vma->vm_flags | VM_LOCKED;
71353 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
71354 lock_limit >>= PAGE_SHIFT;
71355
71356 /* check against resource limits */
71357 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
71358 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
71359 error = do_mlock(start, len, 1);
71360 up_write(&current->mm->mmap_sem);
71361 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
71362 static int do_mlockall(int flags)
71363 {
71364 struct vm_area_struct * vma, * prev = NULL;
71365 - unsigned int def_flags = 0;
71366
71367 if (flags & MCL_FUTURE)
71368 - def_flags = VM_LOCKED;
71369 - current->mm->def_flags = def_flags;
71370 + current->mm->def_flags |= VM_LOCKED;
71371 + else
71372 + current->mm->def_flags &= ~VM_LOCKED;
71373 if (flags == MCL_FUTURE)
71374 goto out;
71375
71376 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
71377 vm_flags_t newflags;
71378
71379 +#ifdef CONFIG_PAX_SEGMEXEC
71380 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
71381 + break;
71382 +#endif
71383 +
71384 + BUG_ON(vma->vm_end > TASK_SIZE);
71385 newflags = vma->vm_flags | VM_LOCKED;
71386 if (!(flags & MCL_CURRENT))
71387 newflags &= ~VM_LOCKED;
71388 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
71389 lock_limit >>= PAGE_SHIFT;
71390
71391 ret = -ENOMEM;
71392 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
71393 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
71394 capable(CAP_IPC_LOCK))
71395 ret = do_mlockall(flags);
71396 diff --git a/mm/mmap.c b/mm/mmap.c
71397 index da15a79..314aef3 100644
71398 --- a/mm/mmap.c
71399 +++ b/mm/mmap.c
71400 @@ -46,6 +46,16 @@
71401 #define arch_rebalance_pgtables(addr, len) (addr)
71402 #endif
71403
71404 +static inline void verify_mm_writelocked(struct mm_struct *mm)
71405 +{
71406 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
71407 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
71408 + up_read(&mm->mmap_sem);
71409 + BUG();
71410 + }
71411 +#endif
71412 +}
71413 +
71414 static void unmap_region(struct mm_struct *mm,
71415 struct vm_area_struct *vma, struct vm_area_struct *prev,
71416 unsigned long start, unsigned long end);
71417 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
71418 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
71419 *
71420 */
71421 -pgprot_t protection_map[16] = {
71422 +pgprot_t protection_map[16] __read_only = {
71423 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
71424 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
71425 };
71426
71427 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
71428 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71429 {
71430 - return __pgprot(pgprot_val(protection_map[vm_flags &
71431 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
71432 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
71433 pgprot_val(arch_vm_get_page_prot(vm_flags)));
71434 +
71435 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71436 + if (!(__supported_pte_mask & _PAGE_NX) &&
71437 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
71438 + (vm_flags & (VM_READ | VM_WRITE)))
71439 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
71440 +#endif
71441 +
71442 + return prot;
71443 }
71444 EXPORT_SYMBOL(vm_get_page_prot);
71445
71446 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
71447 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
71448 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
71449 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
71450 /*
71451 * Make sure vm_committed_as in one cacheline and not cacheline shared with
71452 * other variables. It can be updated by several CPUs frequently.
71453 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
71454 struct vm_area_struct *next = vma->vm_next;
71455
71456 might_sleep();
71457 + BUG_ON(vma->vm_mirror);
71458 if (vma->vm_ops && vma->vm_ops->close)
71459 vma->vm_ops->close(vma);
71460 if (vma->vm_file) {
71461 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
71462 * not page aligned -Ram Gupta
71463 */
71464 rlim = rlimit(RLIMIT_DATA);
71465 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
71466 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
71467 (mm->end_data - mm->start_data) > rlim)
71468 goto out;
71469 @@ -689,6 +711,12 @@ static int
71470 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
71471 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71472 {
71473 +
71474 +#ifdef CONFIG_PAX_SEGMEXEC
71475 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
71476 + return 0;
71477 +#endif
71478 +
71479 if (is_mergeable_vma(vma, file, vm_flags) &&
71480 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71481 if (vma->vm_pgoff == vm_pgoff)
71482 @@ -708,6 +736,12 @@ static int
71483 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71484 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
71485 {
71486 +
71487 +#ifdef CONFIG_PAX_SEGMEXEC
71488 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
71489 + return 0;
71490 +#endif
71491 +
71492 if (is_mergeable_vma(vma, file, vm_flags) &&
71493 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
71494 pgoff_t vm_pglen;
71495 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
71496 struct vm_area_struct *vma_merge(struct mm_struct *mm,
71497 struct vm_area_struct *prev, unsigned long addr,
71498 unsigned long end, unsigned long vm_flags,
71499 - struct anon_vma *anon_vma, struct file *file,
71500 + struct anon_vma *anon_vma, struct file *file,
71501 pgoff_t pgoff, struct mempolicy *policy)
71502 {
71503 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
71504 struct vm_area_struct *area, *next;
71505 int err;
71506
71507 +#ifdef CONFIG_PAX_SEGMEXEC
71508 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
71509 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
71510 +
71511 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
71512 +#endif
71513 +
71514 /*
71515 * We later require that vma->vm_flags == vm_flags,
71516 * so this tests vma->vm_flags & VM_SPECIAL, too.
71517 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71518 if (next && next->vm_end == end) /* cases 6, 7, 8 */
71519 next = next->vm_next;
71520
71521 +#ifdef CONFIG_PAX_SEGMEXEC
71522 + if (prev)
71523 + prev_m = pax_find_mirror_vma(prev);
71524 + if (area)
71525 + area_m = pax_find_mirror_vma(area);
71526 + if (next)
71527 + next_m = pax_find_mirror_vma(next);
71528 +#endif
71529 +
71530 /*
71531 * Can it merge with the predecessor?
71532 */
71533 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71534 /* cases 1, 6 */
71535 err = vma_adjust(prev, prev->vm_start,
71536 next->vm_end, prev->vm_pgoff, NULL);
71537 - } else /* cases 2, 5, 7 */
71538 +
71539 +#ifdef CONFIG_PAX_SEGMEXEC
71540 + if (!err && prev_m)
71541 + err = vma_adjust(prev_m, prev_m->vm_start,
71542 + next_m->vm_end, prev_m->vm_pgoff, NULL);
71543 +#endif
71544 +
71545 + } else { /* cases 2, 5, 7 */
71546 err = vma_adjust(prev, prev->vm_start,
71547 end, prev->vm_pgoff, NULL);
71548 +
71549 +#ifdef CONFIG_PAX_SEGMEXEC
71550 + if (!err && prev_m)
71551 + err = vma_adjust(prev_m, prev_m->vm_start,
71552 + end_m, prev_m->vm_pgoff, NULL);
71553 +#endif
71554 +
71555 + }
71556 if (err)
71557 return NULL;
71558 khugepaged_enter_vma_merge(prev);
71559 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
71560 mpol_equal(policy, vma_policy(next)) &&
71561 can_vma_merge_before(next, vm_flags,
71562 anon_vma, file, pgoff+pglen)) {
71563 - if (prev && addr < prev->vm_end) /* case 4 */
71564 + if (prev && addr < prev->vm_end) { /* case 4 */
71565 err = vma_adjust(prev, prev->vm_start,
71566 addr, prev->vm_pgoff, NULL);
71567 - else /* cases 3, 8 */
71568 +
71569 +#ifdef CONFIG_PAX_SEGMEXEC
71570 + if (!err && prev_m)
71571 + err = vma_adjust(prev_m, prev_m->vm_start,
71572 + addr_m, prev_m->vm_pgoff, NULL);
71573 +#endif
71574 +
71575 + } else { /* cases 3, 8 */
71576 err = vma_adjust(area, addr, next->vm_end,
71577 next->vm_pgoff - pglen, NULL);
71578 +
71579 +#ifdef CONFIG_PAX_SEGMEXEC
71580 + if (!err && area_m)
71581 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
71582 + next_m->vm_pgoff - pglen, NULL);
71583 +#endif
71584 +
71585 + }
71586 if (err)
71587 return NULL;
71588 khugepaged_enter_vma_merge(area);
71589 @@ -921,14 +1001,11 @@ none:
71590 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
71591 struct file *file, long pages)
71592 {
71593 - const unsigned long stack_flags
71594 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
71595 -
71596 if (file) {
71597 mm->shared_vm += pages;
71598 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
71599 mm->exec_vm += pages;
71600 - } else if (flags & stack_flags)
71601 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
71602 mm->stack_vm += pages;
71603 if (flags & (VM_RESERVED|VM_IO))
71604 mm->reserved_vm += pages;
71605 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71606 * (the exception is when the underlying filesystem is noexec
71607 * mounted, in which case we dont add PROT_EXEC.)
71608 */
71609 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
71610 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
71611 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
71612 prot |= PROT_EXEC;
71613
71614 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71615 /* Obtain the address to map to. we verify (or select) it and ensure
71616 * that it represents a valid section of the address space.
71617 */
71618 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
71619 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
71620 if (addr & ~PAGE_MASK)
71621 return addr;
71622
71623 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71624 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
71625 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
71626
71627 +#ifdef CONFIG_PAX_MPROTECT
71628 + if (mm->pax_flags & MF_PAX_MPROTECT) {
71629 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
71630 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
71631 + gr_log_rwxmmap(file);
71632 +
71633 +#ifdef CONFIG_PAX_EMUPLT
71634 + vm_flags &= ~VM_EXEC;
71635 +#else
71636 + return -EPERM;
71637 +#endif
71638 +
71639 + }
71640 +
71641 + if (!(vm_flags & VM_EXEC))
71642 + vm_flags &= ~VM_MAYEXEC;
71643 +#else
71644 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
71645 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
71646 +#endif
71647 + else
71648 + vm_flags &= ~VM_MAYWRITE;
71649 + }
71650 +#endif
71651 +
71652 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71653 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
71654 + vm_flags &= ~VM_PAGEEXEC;
71655 +#endif
71656 +
71657 if (flags & MAP_LOCKED)
71658 if (!can_do_mlock())
71659 return -EPERM;
71660 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71661 locked += mm->locked_vm;
71662 lock_limit = rlimit(RLIMIT_MEMLOCK);
71663 lock_limit >>= PAGE_SHIFT;
71664 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
71665 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
71666 return -EAGAIN;
71667 }
71668 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71669 if (error)
71670 return error;
71671
71672 + if (!gr_acl_handle_mmap(file, prot))
71673 + return -EACCES;
71674 +
71675 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
71676 }
71677 EXPORT_SYMBOL(do_mmap_pgoff);
71678 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
71679 vm_flags_t vm_flags = vma->vm_flags;
71680
71681 /* If it was private or non-writable, the write bit is already clear */
71682 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
71683 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
71684 return 0;
71685
71686 /* The backer wishes to know when pages are first written to? */
71687 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
71688 unsigned long charged = 0;
71689 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
71690
71691 +#ifdef CONFIG_PAX_SEGMEXEC
71692 + struct vm_area_struct *vma_m = NULL;
71693 +#endif
71694 +
71695 + /*
71696 + * mm->mmap_sem is required to protect against another thread
71697 + * changing the mappings in case we sleep.
71698 + */
71699 + verify_mm_writelocked(mm);
71700 +
71701 /* Clear old maps */
71702 error = -ENOMEM;
71703 -munmap_back:
71704 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71705 if (vma && vma->vm_start < addr + len) {
71706 if (do_munmap(mm, addr, len))
71707 return -ENOMEM;
71708 - goto munmap_back;
71709 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
71710 + BUG_ON(vma && vma->vm_start < addr + len);
71711 }
71712
71713 /* Check against address space limit. */
71714 @@ -1258,6 +1379,16 @@ munmap_back:
71715 goto unacct_error;
71716 }
71717
71718 +#ifdef CONFIG_PAX_SEGMEXEC
71719 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
71720 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
71721 + if (!vma_m) {
71722 + error = -ENOMEM;
71723 + goto free_vma;
71724 + }
71725 + }
71726 +#endif
71727 +
71728 vma->vm_mm = mm;
71729 vma->vm_start = addr;
71730 vma->vm_end = addr + len;
71731 @@ -1282,6 +1413,19 @@ munmap_back:
71732 error = file->f_op->mmap(file, vma);
71733 if (error)
71734 goto unmap_and_free_vma;
71735 +
71736 +#ifdef CONFIG_PAX_SEGMEXEC
71737 + if (vma_m && (vm_flags & VM_EXECUTABLE))
71738 + added_exe_file_vma(mm);
71739 +#endif
71740 +
71741 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71742 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
71743 + vma->vm_flags |= VM_PAGEEXEC;
71744 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
71745 + }
71746 +#endif
71747 +
71748 if (vm_flags & VM_EXECUTABLE)
71749 added_exe_file_vma(mm);
71750
71751 @@ -1319,6 +1463,11 @@ munmap_back:
71752 vma_link(mm, vma, prev, rb_link, rb_parent);
71753 file = vma->vm_file;
71754
71755 +#ifdef CONFIG_PAX_SEGMEXEC
71756 + if (vma_m)
71757 + BUG_ON(pax_mirror_vma(vma_m, vma));
71758 +#endif
71759 +
71760 /* Once vma denies write, undo our temporary denial count */
71761 if (correct_wcount)
71762 atomic_inc(&inode->i_writecount);
71763 @@ -1327,6 +1476,7 @@ out:
71764
71765 mm->total_vm += len >> PAGE_SHIFT;
71766 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
71767 + track_exec_limit(mm, addr, addr + len, vm_flags);
71768 if (vm_flags & VM_LOCKED) {
71769 if (!mlock_vma_pages_range(vma, addr, addr + len))
71770 mm->locked_vm += (len >> PAGE_SHIFT);
71771 @@ -1344,6 +1494,12 @@ unmap_and_free_vma:
71772 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
71773 charged = 0;
71774 free_vma:
71775 +
71776 +#ifdef CONFIG_PAX_SEGMEXEC
71777 + if (vma_m)
71778 + kmem_cache_free(vm_area_cachep, vma_m);
71779 +#endif
71780 +
71781 kmem_cache_free(vm_area_cachep, vma);
71782 unacct_error:
71783 if (charged)
71784 @@ -1351,6 +1507,44 @@ unacct_error:
71785 return error;
71786 }
71787
71788 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
71789 +{
71790 + if (!vma) {
71791 +#ifdef CONFIG_STACK_GROWSUP
71792 + if (addr > sysctl_heap_stack_gap)
71793 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
71794 + else
71795 + vma = find_vma(current->mm, 0);
71796 + if (vma && (vma->vm_flags & VM_GROWSUP))
71797 + return false;
71798 +#endif
71799 + return true;
71800 + }
71801 +
71802 + if (addr + len > vma->vm_start)
71803 + return false;
71804 +
71805 + if (vma->vm_flags & VM_GROWSDOWN)
71806 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
71807 +#ifdef CONFIG_STACK_GROWSUP
71808 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
71809 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
71810 +#endif
71811 +
71812 + return true;
71813 +}
71814 +
71815 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
71816 +{
71817 + if (vma->vm_start < len)
71818 + return -ENOMEM;
71819 + if (!(vma->vm_flags & VM_GROWSDOWN))
71820 + return vma->vm_start - len;
71821 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
71822 + return vma->vm_start - len - sysctl_heap_stack_gap;
71823 + return -ENOMEM;
71824 +}
71825 +
71826 /* Get an address range which is currently unmapped.
71827 * For shmat() with addr=0.
71828 *
71829 @@ -1377,18 +1571,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
71830 if (flags & MAP_FIXED)
71831 return addr;
71832
71833 +#ifdef CONFIG_PAX_RANDMMAP
71834 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71835 +#endif
71836 +
71837 if (addr) {
71838 addr = PAGE_ALIGN(addr);
71839 - vma = find_vma(mm, addr);
71840 - if (TASK_SIZE - len >= addr &&
71841 - (!vma || addr + len <= vma->vm_start))
71842 - return addr;
71843 + if (TASK_SIZE - len >= addr) {
71844 + vma = find_vma(mm, addr);
71845 + if (check_heap_stack_gap(vma, addr, len))
71846 + return addr;
71847 + }
71848 }
71849 if (len > mm->cached_hole_size) {
71850 - start_addr = addr = mm->free_area_cache;
71851 + start_addr = addr = mm->free_area_cache;
71852 } else {
71853 - start_addr = addr = TASK_UNMAPPED_BASE;
71854 - mm->cached_hole_size = 0;
71855 + start_addr = addr = mm->mmap_base;
71856 + mm->cached_hole_size = 0;
71857 }
71858
71859 full_search:
71860 @@ -1399,34 +1598,40 @@ full_search:
71861 * Start a new search - just in case we missed
71862 * some holes.
71863 */
71864 - if (start_addr != TASK_UNMAPPED_BASE) {
71865 - addr = TASK_UNMAPPED_BASE;
71866 - start_addr = addr;
71867 + if (start_addr != mm->mmap_base) {
71868 + start_addr = addr = mm->mmap_base;
71869 mm->cached_hole_size = 0;
71870 goto full_search;
71871 }
71872 return -ENOMEM;
71873 }
71874 - if (!vma || addr + len <= vma->vm_start) {
71875 - /*
71876 - * Remember the place where we stopped the search:
71877 - */
71878 - mm->free_area_cache = addr + len;
71879 - return addr;
71880 - }
71881 + if (check_heap_stack_gap(vma, addr, len))
71882 + break;
71883 if (addr + mm->cached_hole_size < vma->vm_start)
71884 mm->cached_hole_size = vma->vm_start - addr;
71885 addr = vma->vm_end;
71886 }
71887 +
71888 + /*
71889 + * Remember the place where we stopped the search:
71890 + */
71891 + mm->free_area_cache = addr + len;
71892 + return addr;
71893 }
71894 #endif
71895
71896 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
71897 {
71898 +
71899 +#ifdef CONFIG_PAX_SEGMEXEC
71900 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
71901 + return;
71902 +#endif
71903 +
71904 /*
71905 * Is this a new hole at the lowest possible address?
71906 */
71907 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
71908 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
71909 mm->free_area_cache = addr;
71910 mm->cached_hole_size = ~0UL;
71911 }
71912 @@ -1444,7 +1649,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71913 {
71914 struct vm_area_struct *vma;
71915 struct mm_struct *mm = current->mm;
71916 - unsigned long addr = addr0;
71917 + unsigned long base = mm->mmap_base, addr = addr0;
71918
71919 /* requested length too big for entire address space */
71920 if (len > TASK_SIZE)
71921 @@ -1453,13 +1658,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71922 if (flags & MAP_FIXED)
71923 return addr;
71924
71925 +#ifdef CONFIG_PAX_RANDMMAP
71926 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
71927 +#endif
71928 +
71929 /* requesting a specific address */
71930 if (addr) {
71931 addr = PAGE_ALIGN(addr);
71932 - vma = find_vma(mm, addr);
71933 - if (TASK_SIZE - len >= addr &&
71934 - (!vma || addr + len <= vma->vm_start))
71935 - return addr;
71936 + if (TASK_SIZE - len >= addr) {
71937 + vma = find_vma(mm, addr);
71938 + if (check_heap_stack_gap(vma, addr, len))
71939 + return addr;
71940 + }
71941 }
71942
71943 /* check if free_area_cache is useful for us */
71944 @@ -1474,7 +1684,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71945 /* make sure it can fit in the remaining address space */
71946 if (addr > len) {
71947 vma = find_vma(mm, addr-len);
71948 - if (!vma || addr <= vma->vm_start)
71949 + if (check_heap_stack_gap(vma, addr - len, len))
71950 /* remember the address as a hint for next time */
71951 return (mm->free_area_cache = addr-len);
71952 }
71953 @@ -1491,7 +1701,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71954 * return with success:
71955 */
71956 vma = find_vma(mm, addr);
71957 - if (!vma || addr+len <= vma->vm_start)
71958 + if (check_heap_stack_gap(vma, addr, len))
71959 /* remember the address as a hint for next time */
71960 return (mm->free_area_cache = addr);
71961
71962 @@ -1500,8 +1710,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
71963 mm->cached_hole_size = vma->vm_start - addr;
71964
71965 /* try just below the current vma->vm_start */
71966 - addr = vma->vm_start-len;
71967 - } while (len < vma->vm_start);
71968 + addr = skip_heap_stack_gap(vma, len);
71969 + } while (!IS_ERR_VALUE(addr));
71970
71971 bottomup:
71972 /*
71973 @@ -1510,13 +1720,21 @@ bottomup:
71974 * can happen with large stack limits and large mmap()
71975 * allocations.
71976 */
71977 + mm->mmap_base = TASK_UNMAPPED_BASE;
71978 +
71979 +#ifdef CONFIG_PAX_RANDMMAP
71980 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71981 + mm->mmap_base += mm->delta_mmap;
71982 +#endif
71983 +
71984 + mm->free_area_cache = mm->mmap_base;
71985 mm->cached_hole_size = ~0UL;
71986 - mm->free_area_cache = TASK_UNMAPPED_BASE;
71987 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
71988 /*
71989 * Restore the topdown base:
71990 */
71991 - mm->free_area_cache = mm->mmap_base;
71992 + mm->mmap_base = base;
71993 + mm->free_area_cache = base;
71994 mm->cached_hole_size = ~0UL;
71995
71996 return addr;
71997 @@ -1525,6 +1743,12 @@ bottomup:
71998
71999 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72000 {
72001 +
72002 +#ifdef CONFIG_PAX_SEGMEXEC
72003 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
72004 + return;
72005 +#endif
72006 +
72007 /*
72008 * Is this a new hole at the highest possible address?
72009 */
72010 @@ -1532,8 +1756,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
72011 mm->free_area_cache = addr;
72012
72013 /* dont allow allocations above current base */
72014 - if (mm->free_area_cache > mm->mmap_base)
72015 + if (mm->free_area_cache > mm->mmap_base) {
72016 mm->free_area_cache = mm->mmap_base;
72017 + mm->cached_hole_size = ~0UL;
72018 + }
72019 }
72020
72021 unsigned long
72022 @@ -1629,6 +1855,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
72023 return vma;
72024 }
72025
72026 +#ifdef CONFIG_PAX_SEGMEXEC
72027 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
72028 +{
72029 + struct vm_area_struct *vma_m;
72030 +
72031 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
72032 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
72033 + BUG_ON(vma->vm_mirror);
72034 + return NULL;
72035 + }
72036 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
72037 + vma_m = vma->vm_mirror;
72038 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
72039 + BUG_ON(vma->vm_file != vma_m->vm_file);
72040 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
72041 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
72042 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
72043 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
72044 + return vma_m;
72045 +}
72046 +#endif
72047 +
72048 /*
72049 * Verify that the stack growth is acceptable and
72050 * update accounting. This is shared with both the
72051 @@ -1645,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72052 return -ENOMEM;
72053
72054 /* Stack limit test */
72055 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
72056 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
72057 return -ENOMEM;
72058
72059 @@ -1655,6 +1904,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72060 locked = mm->locked_vm + grow;
72061 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
72062 limit >>= PAGE_SHIFT;
72063 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72064 if (locked > limit && !capable(CAP_IPC_LOCK))
72065 return -ENOMEM;
72066 }
72067 @@ -1685,37 +1935,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
72068 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
72069 * vma is the last one with address > vma->vm_end. Have to extend vma.
72070 */
72071 +#ifndef CONFIG_IA64
72072 +static
72073 +#endif
72074 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72075 {
72076 int error;
72077 + bool locknext;
72078
72079 if (!(vma->vm_flags & VM_GROWSUP))
72080 return -EFAULT;
72081
72082 + /* Also guard against wrapping around to address 0. */
72083 + if (address < PAGE_ALIGN(address+1))
72084 + address = PAGE_ALIGN(address+1);
72085 + else
72086 + return -ENOMEM;
72087 +
72088 /*
72089 * We must make sure the anon_vma is allocated
72090 * so that the anon_vma locking is not a noop.
72091 */
72092 if (unlikely(anon_vma_prepare(vma)))
72093 return -ENOMEM;
72094 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
72095 + if (locknext && anon_vma_prepare(vma->vm_next))
72096 + return -ENOMEM;
72097 vma_lock_anon_vma(vma);
72098 + if (locknext)
72099 + vma_lock_anon_vma(vma->vm_next);
72100
72101 /*
72102 * vma->vm_start/vm_end cannot change under us because the caller
72103 * is required to hold the mmap_sem in read mode. We need the
72104 - * anon_vma lock to serialize against concurrent expand_stacks.
72105 - * Also guard against wrapping around to address 0.
72106 + * anon_vma locks to serialize against concurrent expand_stacks
72107 + * and expand_upwards.
72108 */
72109 - if (address < PAGE_ALIGN(address+4))
72110 - address = PAGE_ALIGN(address+4);
72111 - else {
72112 - vma_unlock_anon_vma(vma);
72113 - return -ENOMEM;
72114 - }
72115 error = 0;
72116
72117 /* Somebody else might have raced and expanded it already */
72118 - if (address > vma->vm_end) {
72119 + 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)
72120 + error = -ENOMEM;
72121 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
72122 unsigned long size, grow;
72123
72124 size = address - vma->vm_start;
72125 @@ -1730,6 +1991,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
72126 }
72127 }
72128 }
72129 + if (locknext)
72130 + vma_unlock_anon_vma(vma->vm_next);
72131 vma_unlock_anon_vma(vma);
72132 khugepaged_enter_vma_merge(vma);
72133 return error;
72134 @@ -1743,6 +2006,8 @@ int expand_downwards(struct vm_area_struct *vma,
72135 unsigned long address)
72136 {
72137 int error;
72138 + bool lockprev = false;
72139 + struct vm_area_struct *prev;
72140
72141 /*
72142 * We must make sure the anon_vma is allocated
72143 @@ -1756,6 +2021,15 @@ int expand_downwards(struct vm_area_struct *vma,
72144 if (error)
72145 return error;
72146
72147 + prev = vma->vm_prev;
72148 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
72149 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
72150 +#endif
72151 + if (lockprev && anon_vma_prepare(prev))
72152 + return -ENOMEM;
72153 + if (lockprev)
72154 + vma_lock_anon_vma(prev);
72155 +
72156 vma_lock_anon_vma(vma);
72157
72158 /*
72159 @@ -1765,9 +2039,17 @@ int expand_downwards(struct vm_area_struct *vma,
72160 */
72161
72162 /* Somebody else might have raced and expanded it already */
72163 - if (address < vma->vm_start) {
72164 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
72165 + error = -ENOMEM;
72166 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
72167 unsigned long size, grow;
72168
72169 +#ifdef CONFIG_PAX_SEGMEXEC
72170 + struct vm_area_struct *vma_m;
72171 +
72172 + vma_m = pax_find_mirror_vma(vma);
72173 +#endif
72174 +
72175 size = vma->vm_end - address;
72176 grow = (vma->vm_start - address) >> PAGE_SHIFT;
72177
72178 @@ -1777,11 +2059,22 @@ int expand_downwards(struct vm_area_struct *vma,
72179 if (!error) {
72180 vma->vm_start = address;
72181 vma->vm_pgoff -= grow;
72182 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
72183 +
72184 +#ifdef CONFIG_PAX_SEGMEXEC
72185 + if (vma_m) {
72186 + vma_m->vm_start -= grow << PAGE_SHIFT;
72187 + vma_m->vm_pgoff -= grow;
72188 + }
72189 +#endif
72190 +
72191 perf_event_mmap(vma);
72192 }
72193 }
72194 }
72195 vma_unlock_anon_vma(vma);
72196 + if (lockprev)
72197 + vma_unlock_anon_vma(prev);
72198 khugepaged_enter_vma_merge(vma);
72199 return error;
72200 }
72201 @@ -1851,6 +2144,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
72202 do {
72203 long nrpages = vma_pages(vma);
72204
72205 +#ifdef CONFIG_PAX_SEGMEXEC
72206 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
72207 + vma = remove_vma(vma);
72208 + continue;
72209 + }
72210 +#endif
72211 +
72212 mm->total_vm -= nrpages;
72213 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
72214 vma = remove_vma(vma);
72215 @@ -1896,6 +2196,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
72216 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
72217 vma->vm_prev = NULL;
72218 do {
72219 +
72220 +#ifdef CONFIG_PAX_SEGMEXEC
72221 + if (vma->vm_mirror) {
72222 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
72223 + vma->vm_mirror->vm_mirror = NULL;
72224 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
72225 + vma->vm_mirror = NULL;
72226 + }
72227 +#endif
72228 +
72229 rb_erase(&vma->vm_rb, &mm->mm_rb);
72230 mm->map_count--;
72231 tail_vma = vma;
72232 @@ -1924,14 +2234,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72233 struct vm_area_struct *new;
72234 int err = -ENOMEM;
72235
72236 +#ifdef CONFIG_PAX_SEGMEXEC
72237 + struct vm_area_struct *vma_m, *new_m = NULL;
72238 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
72239 +#endif
72240 +
72241 if (is_vm_hugetlb_page(vma) && (addr &
72242 ~(huge_page_mask(hstate_vma(vma)))))
72243 return -EINVAL;
72244
72245 +#ifdef CONFIG_PAX_SEGMEXEC
72246 + vma_m = pax_find_mirror_vma(vma);
72247 +#endif
72248 +
72249 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72250 if (!new)
72251 goto out_err;
72252
72253 +#ifdef CONFIG_PAX_SEGMEXEC
72254 + if (vma_m) {
72255 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
72256 + if (!new_m) {
72257 + kmem_cache_free(vm_area_cachep, new);
72258 + goto out_err;
72259 + }
72260 + }
72261 +#endif
72262 +
72263 /* most fields are the same, copy all, and then fixup */
72264 *new = *vma;
72265
72266 @@ -1944,6 +2273,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72267 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
72268 }
72269
72270 +#ifdef CONFIG_PAX_SEGMEXEC
72271 + if (vma_m) {
72272 + *new_m = *vma_m;
72273 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
72274 + new_m->vm_mirror = new;
72275 + new->vm_mirror = new_m;
72276 +
72277 + if (new_below)
72278 + new_m->vm_end = addr_m;
72279 + else {
72280 + new_m->vm_start = addr_m;
72281 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
72282 + }
72283 + }
72284 +#endif
72285 +
72286 pol = mpol_dup(vma_policy(vma));
72287 if (IS_ERR(pol)) {
72288 err = PTR_ERR(pol);
72289 @@ -1969,6 +2314,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72290 else
72291 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
72292
72293 +#ifdef CONFIG_PAX_SEGMEXEC
72294 + if (!err && vma_m) {
72295 + if (anon_vma_clone(new_m, vma_m))
72296 + goto out_free_mpol;
72297 +
72298 + mpol_get(pol);
72299 + vma_set_policy(new_m, pol);
72300 +
72301 + if (new_m->vm_file) {
72302 + get_file(new_m->vm_file);
72303 + if (vma_m->vm_flags & VM_EXECUTABLE)
72304 + added_exe_file_vma(mm);
72305 + }
72306 +
72307 + if (new_m->vm_ops && new_m->vm_ops->open)
72308 + new_m->vm_ops->open(new_m);
72309 +
72310 + if (new_below)
72311 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
72312 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
72313 + else
72314 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
72315 +
72316 + if (err) {
72317 + if (new_m->vm_ops && new_m->vm_ops->close)
72318 + new_m->vm_ops->close(new_m);
72319 + if (new_m->vm_file) {
72320 + if (vma_m->vm_flags & VM_EXECUTABLE)
72321 + removed_exe_file_vma(mm);
72322 + fput(new_m->vm_file);
72323 + }
72324 + mpol_put(pol);
72325 + }
72326 + }
72327 +#endif
72328 +
72329 /* Success. */
72330 if (!err)
72331 return 0;
72332 @@ -1981,10 +2362,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72333 removed_exe_file_vma(mm);
72334 fput(new->vm_file);
72335 }
72336 - unlink_anon_vmas(new);
72337 out_free_mpol:
72338 mpol_put(pol);
72339 out_free_vma:
72340 +
72341 +#ifdef CONFIG_PAX_SEGMEXEC
72342 + if (new_m) {
72343 + unlink_anon_vmas(new_m);
72344 + kmem_cache_free(vm_area_cachep, new_m);
72345 + }
72346 +#endif
72347 +
72348 + unlink_anon_vmas(new);
72349 kmem_cache_free(vm_area_cachep, new);
72350 out_err:
72351 return err;
72352 @@ -1997,6 +2386,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
72353 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72354 unsigned long addr, int new_below)
72355 {
72356 +
72357 +#ifdef CONFIG_PAX_SEGMEXEC
72358 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72359 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
72360 + if (mm->map_count >= sysctl_max_map_count-1)
72361 + return -ENOMEM;
72362 + } else
72363 +#endif
72364 +
72365 if (mm->map_count >= sysctl_max_map_count)
72366 return -ENOMEM;
72367
72368 @@ -2008,11 +2406,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
72369 * work. This now handles partial unmappings.
72370 * Jeremy Fitzhardinge <jeremy@goop.org>
72371 */
72372 +#ifdef CONFIG_PAX_SEGMEXEC
72373 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72374 {
72375 + int ret = __do_munmap(mm, start, len);
72376 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
72377 + return ret;
72378 +
72379 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
72380 +}
72381 +
72382 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72383 +#else
72384 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72385 +#endif
72386 +{
72387 unsigned long end;
72388 struct vm_area_struct *vma, *prev, *last;
72389
72390 + /*
72391 + * mm->mmap_sem is required to protect against another thread
72392 + * changing the mappings in case we sleep.
72393 + */
72394 + verify_mm_writelocked(mm);
72395 +
72396 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
72397 return -EINVAL;
72398
72399 @@ -2087,6 +2504,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
72400 /* Fix up all other VM information */
72401 remove_vma_list(mm, vma);
72402
72403 + track_exec_limit(mm, start, end, 0UL);
72404 +
72405 return 0;
72406 }
72407
72408 @@ -2099,22 +2518,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
72409
72410 profile_munmap(addr);
72411
72412 +#ifdef CONFIG_PAX_SEGMEXEC
72413 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
72414 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
72415 + return -EINVAL;
72416 +#endif
72417 +
72418 down_write(&mm->mmap_sem);
72419 ret = do_munmap(mm, addr, len);
72420 up_write(&mm->mmap_sem);
72421 return ret;
72422 }
72423
72424 -static inline void verify_mm_writelocked(struct mm_struct *mm)
72425 -{
72426 -#ifdef CONFIG_DEBUG_VM
72427 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72428 - WARN_ON(1);
72429 - up_read(&mm->mmap_sem);
72430 - }
72431 -#endif
72432 -}
72433 -
72434 /*
72435 * this is really a simplified "do_mmap". it only handles
72436 * anonymous maps. eventually we may be able to do some
72437 @@ -2128,6 +2543,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72438 struct rb_node ** rb_link, * rb_parent;
72439 pgoff_t pgoff = addr >> PAGE_SHIFT;
72440 int error;
72441 + unsigned long charged;
72442
72443 len = PAGE_ALIGN(len);
72444 if (!len)
72445 @@ -2139,16 +2555,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72446
72447 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
72448
72449 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
72450 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
72451 + flags &= ~VM_EXEC;
72452 +
72453 +#ifdef CONFIG_PAX_MPROTECT
72454 + if (mm->pax_flags & MF_PAX_MPROTECT)
72455 + flags &= ~VM_MAYEXEC;
72456 +#endif
72457 +
72458 + }
72459 +#endif
72460 +
72461 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
72462 if (error & ~PAGE_MASK)
72463 return error;
72464
72465 + charged = len >> PAGE_SHIFT;
72466 +
72467 /*
72468 * mlock MCL_FUTURE?
72469 */
72470 if (mm->def_flags & VM_LOCKED) {
72471 unsigned long locked, lock_limit;
72472 - locked = len >> PAGE_SHIFT;
72473 + locked = charged;
72474 locked += mm->locked_vm;
72475 lock_limit = rlimit(RLIMIT_MEMLOCK);
72476 lock_limit >>= PAGE_SHIFT;
72477 @@ -2165,22 +2595,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72478 /*
72479 * Clear old maps. this also does some error checking for us
72480 */
72481 - munmap_back:
72482 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72483 if (vma && vma->vm_start < addr + len) {
72484 if (do_munmap(mm, addr, len))
72485 return -ENOMEM;
72486 - goto munmap_back;
72487 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72488 + BUG_ON(vma && vma->vm_start < addr + len);
72489 }
72490
72491 /* Check against address space limits *after* clearing old maps... */
72492 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
72493 + if (!may_expand_vm(mm, charged))
72494 return -ENOMEM;
72495
72496 if (mm->map_count > sysctl_max_map_count)
72497 return -ENOMEM;
72498
72499 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
72500 + if (security_vm_enough_memory(charged))
72501 return -ENOMEM;
72502
72503 /* Can we just expand an old private anonymous mapping? */
72504 @@ -2194,7 +2624,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72505 */
72506 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72507 if (!vma) {
72508 - vm_unacct_memory(len >> PAGE_SHIFT);
72509 + vm_unacct_memory(charged);
72510 return -ENOMEM;
72511 }
72512
72513 @@ -2208,11 +2638,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
72514 vma_link(mm, vma, prev, rb_link, rb_parent);
72515 out:
72516 perf_event_mmap(vma);
72517 - mm->total_vm += len >> PAGE_SHIFT;
72518 + mm->total_vm += charged;
72519 if (flags & VM_LOCKED) {
72520 if (!mlock_vma_pages_range(vma, addr, addr + len))
72521 - mm->locked_vm += (len >> PAGE_SHIFT);
72522 + mm->locked_vm += charged;
72523 }
72524 + track_exec_limit(mm, addr, addr + len, flags);
72525 return addr;
72526 }
72527
72528 @@ -2259,8 +2690,10 @@ void exit_mmap(struct mm_struct *mm)
72529 * Walk the list again, actually closing and freeing it,
72530 * with preemption enabled, without holding any MM locks.
72531 */
72532 - while (vma)
72533 + while (vma) {
72534 + vma->vm_mirror = NULL;
72535 vma = remove_vma(vma);
72536 + }
72537
72538 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
72539 }
72540 @@ -2274,6 +2707,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72541 struct vm_area_struct * __vma, * prev;
72542 struct rb_node ** rb_link, * rb_parent;
72543
72544 +#ifdef CONFIG_PAX_SEGMEXEC
72545 + struct vm_area_struct *vma_m = NULL;
72546 +#endif
72547 +
72548 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
72549 + return -EPERM;
72550 +
72551 /*
72552 * The vm_pgoff of a purely anonymous vma should be irrelevant
72553 * until its first write fault, when page's anon_vma and index
72554 @@ -2296,7 +2736,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
72555 if ((vma->vm_flags & VM_ACCOUNT) &&
72556 security_vm_enough_memory_mm(mm, vma_pages(vma)))
72557 return -ENOMEM;
72558 +
72559 +#ifdef CONFIG_PAX_SEGMEXEC
72560 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
72561 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72562 + if (!vma_m)
72563 + return -ENOMEM;
72564 + }
72565 +#endif
72566 +
72567 vma_link(mm, vma, prev, rb_link, rb_parent);
72568 +
72569 +#ifdef CONFIG_PAX_SEGMEXEC
72570 + if (vma_m)
72571 + BUG_ON(pax_mirror_vma(vma_m, vma));
72572 +#endif
72573 +
72574 return 0;
72575 }
72576
72577 @@ -2315,6 +2770,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72578 struct mempolicy *pol;
72579 bool faulted_in_anon_vma = true;
72580
72581 + BUG_ON(vma->vm_mirror);
72582 +
72583 /*
72584 * If anonymous vma has not yet been faulted, update new pgoff
72585 * to match new location, to increase its chance of merging.
72586 @@ -2382,6 +2839,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
72587 return NULL;
72588 }
72589
72590 +#ifdef CONFIG_PAX_SEGMEXEC
72591 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
72592 +{
72593 + struct vm_area_struct *prev_m;
72594 + struct rb_node **rb_link_m, *rb_parent_m;
72595 + struct mempolicy *pol_m;
72596 +
72597 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
72598 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
72599 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
72600 + *vma_m = *vma;
72601 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
72602 + if (anon_vma_clone(vma_m, vma))
72603 + return -ENOMEM;
72604 + pol_m = vma_policy(vma_m);
72605 + mpol_get(pol_m);
72606 + vma_set_policy(vma_m, pol_m);
72607 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
72608 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
72609 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
72610 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
72611 + if (vma_m->vm_file)
72612 + get_file(vma_m->vm_file);
72613 + if (vma_m->vm_ops && vma_m->vm_ops->open)
72614 + vma_m->vm_ops->open(vma_m);
72615 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
72616 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
72617 + vma_m->vm_mirror = vma;
72618 + vma->vm_mirror = vma_m;
72619 + return 0;
72620 +}
72621 +#endif
72622 +
72623 /*
72624 * Return true if the calling process may expand its vm space by the passed
72625 * number of pages
72626 @@ -2393,6 +2883,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
72627
72628 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
72629
72630 +#ifdef CONFIG_PAX_RANDMMAP
72631 + if (mm->pax_flags & MF_PAX_RANDMMAP)
72632 + cur -= mm->brk_gap;
72633 +#endif
72634 +
72635 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
72636 if (cur + npages > lim)
72637 return 0;
72638 return 1;
72639 @@ -2463,6 +2959,22 @@ int install_special_mapping(struct mm_struct *mm,
72640 vma->vm_start = addr;
72641 vma->vm_end = addr + len;
72642
72643 +#ifdef CONFIG_PAX_MPROTECT
72644 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72645 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72646 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
72647 + return -EPERM;
72648 + if (!(vm_flags & VM_EXEC))
72649 + vm_flags &= ~VM_MAYEXEC;
72650 +#else
72651 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72652 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72653 +#endif
72654 + else
72655 + vm_flags &= ~VM_MAYWRITE;
72656 + }
72657 +#endif
72658 +
72659 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
72660 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72661
72662 diff --git a/mm/mprotect.c b/mm/mprotect.c
72663 index f437d05..e3763f6 100644
72664 --- a/mm/mprotect.c
72665 +++ b/mm/mprotect.c
72666 @@ -23,10 +23,16 @@
72667 #include <linux/mmu_notifier.h>
72668 #include <linux/migrate.h>
72669 #include <linux/perf_event.h>
72670 +
72671 +#ifdef CONFIG_PAX_MPROTECT
72672 +#include <linux/elf.h>
72673 +#endif
72674 +
72675 #include <asm/uaccess.h>
72676 #include <asm/pgtable.h>
72677 #include <asm/cacheflush.h>
72678 #include <asm/tlbflush.h>
72679 +#include <asm/mmu_context.h>
72680
72681 #ifndef pgprot_modify
72682 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
72683 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
72684 flush_tlb_range(vma, start, end);
72685 }
72686
72687 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72688 +/* called while holding the mmap semaphor for writing except stack expansion */
72689 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
72690 +{
72691 + unsigned long oldlimit, newlimit = 0UL;
72692 +
72693 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
72694 + return;
72695 +
72696 + spin_lock(&mm->page_table_lock);
72697 + oldlimit = mm->context.user_cs_limit;
72698 + if ((prot & VM_EXEC) && oldlimit < end)
72699 + /* USER_CS limit moved up */
72700 + newlimit = end;
72701 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
72702 + /* USER_CS limit moved down */
72703 + newlimit = start;
72704 +
72705 + if (newlimit) {
72706 + mm->context.user_cs_limit = newlimit;
72707 +
72708 +#ifdef CONFIG_SMP
72709 + wmb();
72710 + cpus_clear(mm->context.cpu_user_cs_mask);
72711 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
72712 +#endif
72713 +
72714 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
72715 + }
72716 + spin_unlock(&mm->page_table_lock);
72717 + if (newlimit == end) {
72718 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
72719 +
72720 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
72721 + if (is_vm_hugetlb_page(vma))
72722 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
72723 + else
72724 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
72725 + }
72726 +}
72727 +#endif
72728 +
72729 int
72730 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72731 unsigned long start, unsigned long end, unsigned long newflags)
72732 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72733 int error;
72734 int dirty_accountable = 0;
72735
72736 +#ifdef CONFIG_PAX_SEGMEXEC
72737 + struct vm_area_struct *vma_m = NULL;
72738 + unsigned long start_m, end_m;
72739 +
72740 + start_m = start + SEGMEXEC_TASK_SIZE;
72741 + end_m = end + SEGMEXEC_TASK_SIZE;
72742 +#endif
72743 +
72744 if (newflags == oldflags) {
72745 *pprev = vma;
72746 return 0;
72747 }
72748
72749 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
72750 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
72751 +
72752 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
72753 + return -ENOMEM;
72754 +
72755 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
72756 + return -ENOMEM;
72757 + }
72758 +
72759 /*
72760 * If we make a private mapping writable we increase our commit;
72761 * but (without finer accounting) cannot reduce our commit if we
72762 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
72763 }
72764 }
72765
72766 +#ifdef CONFIG_PAX_SEGMEXEC
72767 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
72768 + if (start != vma->vm_start) {
72769 + error = split_vma(mm, vma, start, 1);
72770 + if (error)
72771 + goto fail;
72772 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
72773 + *pprev = (*pprev)->vm_next;
72774 + }
72775 +
72776 + if (end != vma->vm_end) {
72777 + error = split_vma(mm, vma, end, 0);
72778 + if (error)
72779 + goto fail;
72780 + }
72781 +
72782 + if (pax_find_mirror_vma(vma)) {
72783 + error = __do_munmap(mm, start_m, end_m - start_m);
72784 + if (error)
72785 + goto fail;
72786 + } else {
72787 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72788 + if (!vma_m) {
72789 + error = -ENOMEM;
72790 + goto fail;
72791 + }
72792 + vma->vm_flags = newflags;
72793 + error = pax_mirror_vma(vma_m, vma);
72794 + if (error) {
72795 + vma->vm_flags = oldflags;
72796 + goto fail;
72797 + }
72798 + }
72799 + }
72800 +#endif
72801 +
72802 /*
72803 * First try to merge with previous and/or next vma.
72804 */
72805 @@ -204,9 +306,21 @@ success:
72806 * vm_flags and vm_page_prot are protected by the mmap_sem
72807 * held in write mode.
72808 */
72809 +
72810 +#ifdef CONFIG_PAX_SEGMEXEC
72811 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
72812 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
72813 +#endif
72814 +
72815 vma->vm_flags = newflags;
72816 +
72817 +#ifdef CONFIG_PAX_MPROTECT
72818 + if (mm->binfmt && mm->binfmt->handle_mprotect)
72819 + mm->binfmt->handle_mprotect(vma, newflags);
72820 +#endif
72821 +
72822 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
72823 - vm_get_page_prot(newflags));
72824 + vm_get_page_prot(vma->vm_flags));
72825
72826 if (vma_wants_writenotify(vma)) {
72827 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
72828 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72829 end = start + len;
72830 if (end <= start)
72831 return -ENOMEM;
72832 +
72833 +#ifdef CONFIG_PAX_SEGMEXEC
72834 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
72835 + if (end > SEGMEXEC_TASK_SIZE)
72836 + return -EINVAL;
72837 + } else
72838 +#endif
72839 +
72840 + if (end > TASK_SIZE)
72841 + return -EINVAL;
72842 +
72843 if (!arch_validate_prot(prot))
72844 return -EINVAL;
72845
72846 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72847 /*
72848 * Does the application expect PROT_READ to imply PROT_EXEC:
72849 */
72850 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72851 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72852 prot |= PROT_EXEC;
72853
72854 vm_flags = calc_vm_prot_bits(prot);
72855 @@ -288,6 +413,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72856 if (start > vma->vm_start)
72857 prev = vma;
72858
72859 +#ifdef CONFIG_PAX_MPROTECT
72860 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
72861 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
72862 +#endif
72863 +
72864 for (nstart = start ; ; ) {
72865 unsigned long newflags;
72866
72867 @@ -297,6 +427,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72868
72869 /* newflags >> 4 shift VM_MAY% in place of VM_% */
72870 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
72871 + if (prot & (PROT_WRITE | PROT_EXEC))
72872 + gr_log_rwxmprotect(vma->vm_file);
72873 +
72874 + error = -EACCES;
72875 + goto out;
72876 + }
72877 +
72878 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
72879 error = -EACCES;
72880 goto out;
72881 }
72882 @@ -311,6 +449,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
72883 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
72884 if (error)
72885 goto out;
72886 +
72887 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
72888 +
72889 nstart = tmp;
72890
72891 if (nstart < prev->vm_end)
72892 diff --git a/mm/mremap.c b/mm/mremap.c
72893 index 87bb839..c3bfadb 100644
72894 --- a/mm/mremap.c
72895 +++ b/mm/mremap.c
72896 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
72897 continue;
72898 pte = ptep_get_and_clear(mm, old_addr, old_pte);
72899 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
72900 +
72901 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
72902 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
72903 + pte = pte_exprotect(pte);
72904 +#endif
72905 +
72906 set_pte_at(mm, new_addr, new_pte, pte);
72907 }
72908
72909 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
72910 if (is_vm_hugetlb_page(vma))
72911 goto Einval;
72912
72913 +#ifdef CONFIG_PAX_SEGMEXEC
72914 + if (pax_find_mirror_vma(vma))
72915 + goto Einval;
72916 +#endif
72917 +
72918 /* We can't remap across vm area boundaries */
72919 if (old_len > vma->vm_end - addr)
72920 goto Efault;
72921 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
72922 unsigned long ret = -EINVAL;
72923 unsigned long charged = 0;
72924 unsigned long map_flags;
72925 + unsigned long pax_task_size = TASK_SIZE;
72926
72927 if (new_addr & ~PAGE_MASK)
72928 goto out;
72929
72930 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
72931 +#ifdef CONFIG_PAX_SEGMEXEC
72932 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72933 + pax_task_size = SEGMEXEC_TASK_SIZE;
72934 +#endif
72935 +
72936 + pax_task_size -= PAGE_SIZE;
72937 +
72938 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
72939 goto out;
72940
72941 /* Check if the location we're moving into overlaps the
72942 * old location at all, and fail if it does.
72943 */
72944 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
72945 - goto out;
72946 -
72947 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
72948 + if (addr + old_len > new_addr && new_addr + new_len > addr)
72949 goto out;
72950
72951 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72952 @@ -440,6 +456,7 @@ unsigned long do_mremap(unsigned long addr,
72953 struct vm_area_struct *vma;
72954 unsigned long ret = -EINVAL;
72955 unsigned long charged = 0;
72956 + unsigned long pax_task_size = TASK_SIZE;
72957
72958 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
72959 goto out;
72960 @@ -458,6 +475,17 @@ unsigned long do_mremap(unsigned long addr,
72961 if (!new_len)
72962 goto out;
72963
72964 +#ifdef CONFIG_PAX_SEGMEXEC
72965 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
72966 + pax_task_size = SEGMEXEC_TASK_SIZE;
72967 +#endif
72968 +
72969 + pax_task_size -= PAGE_SIZE;
72970 +
72971 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
72972 + old_len > pax_task_size || addr > pax_task_size-old_len)
72973 + goto out;
72974 +
72975 if (flags & MREMAP_FIXED) {
72976 if (flags & MREMAP_MAYMOVE)
72977 ret = mremap_to(addr, old_len, new_addr, new_len);
72978 @@ -507,6 +535,7 @@ unsigned long do_mremap(unsigned long addr,
72979 addr + new_len);
72980 }
72981 ret = addr;
72982 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
72983 goto out;
72984 }
72985 }
72986 @@ -533,7 +562,13 @@ unsigned long do_mremap(unsigned long addr,
72987 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
72988 if (ret)
72989 goto out;
72990 +
72991 + map_flags = vma->vm_flags;
72992 ret = move_vma(vma, addr, old_len, new_len, new_addr);
72993 + if (!(ret & ~PAGE_MASK)) {
72994 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
72995 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
72996 + }
72997 }
72998 out:
72999 if (ret & ~PAGE_MASK)
73000 diff --git a/mm/nommu.c b/mm/nommu.c
73001 index f59e170..34e2a2b 100644
73002 --- a/mm/nommu.c
73003 +++ b/mm/nommu.c
73004 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
73005 int sysctl_overcommit_ratio = 50; /* default is 50% */
73006 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
73007 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
73008 -int heap_stack_gap = 0;
73009
73010 atomic_long_t mmap_pages_allocated;
73011
73012 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
73013 EXPORT_SYMBOL(find_vma);
73014
73015 /*
73016 - * find a VMA
73017 - * - we don't extend stack VMAs under NOMMU conditions
73018 - */
73019 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
73020 -{
73021 - return find_vma(mm, addr);
73022 -}
73023 -
73024 -/*
73025 * expand a stack to a given address
73026 * - not supported under NOMMU conditions
73027 */
73028 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73029
73030 /* most fields are the same, copy all, and then fixup */
73031 *new = *vma;
73032 + INIT_LIST_HEAD(&new->anon_vma_chain);
73033 *region = *vma->vm_region;
73034 new->vm_region = region;
73035
73036 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
73037 index a13ded1..b949d15 100644
73038 --- a/mm/page_alloc.c
73039 +++ b/mm/page_alloc.c
73040 @@ -335,7 +335,7 @@ out:
73041 * This usage means that zero-order pages may not be compound.
73042 */
73043
73044 -static void free_compound_page(struct page *page)
73045 +void free_compound_page(struct page *page)
73046 {
73047 __free_pages_ok(page, compound_order(page));
73048 }
73049 @@ -692,6 +692,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73050 int i;
73051 int bad = 0;
73052
73053 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73054 + unsigned long index = 1UL << order;
73055 +#endif
73056 +
73057 trace_mm_page_free(page, order);
73058 kmemcheck_free_shadow(page, order);
73059
73060 @@ -707,6 +711,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
73061 debug_check_no_obj_freed(page_address(page),
73062 PAGE_SIZE << order);
73063 }
73064 +
73065 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
73066 + for (; index; --index)
73067 + sanitize_highpage(page + index - 1);
73068 +#endif
73069 +
73070 arch_free_page(page, order);
73071 kernel_map_pages(page, 1 << order, 0);
73072
73073 @@ -830,8 +840,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
73074 arch_alloc_page(page, order);
73075 kernel_map_pages(page, 1 << order, 1);
73076
73077 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
73078 if (gfp_flags & __GFP_ZERO)
73079 prep_zero_page(page, order, gfp_flags);
73080 +#endif
73081
73082 if (order && (gfp_flags & __GFP_COMP))
73083 prep_compound_page(page, order);
73084 @@ -3468,7 +3480,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
73085 unsigned long pfn;
73086
73087 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
73088 +#ifdef CONFIG_X86_32
73089 + /* boot failures in VMware 8 on 32bit vanilla since
73090 + this change */
73091 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
73092 +#else
73093 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
73094 +#endif
73095 return 1;
73096 }
73097 return 0;
73098 diff --git a/mm/percpu.c b/mm/percpu.c
73099 index 317de23..1ba7776 100644
73100 --- a/mm/percpu.c
73101 +++ b/mm/percpu.c
73102 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
73103 static unsigned int pcpu_high_unit_cpu __read_mostly;
73104
73105 /* the address of the first chunk which starts with the kernel static area */
73106 -void *pcpu_base_addr __read_mostly;
73107 +void *pcpu_base_addr __read_only;
73108 EXPORT_SYMBOL_GPL(pcpu_base_addr);
73109
73110 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
73111 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
73112 index c20ff48..137702a 100644
73113 --- a/mm/process_vm_access.c
73114 +++ b/mm/process_vm_access.c
73115 @@ -13,6 +13,7 @@
73116 #include <linux/uio.h>
73117 #include <linux/sched.h>
73118 #include <linux/highmem.h>
73119 +#include <linux/security.h>
73120 #include <linux/ptrace.h>
73121 #include <linux/slab.h>
73122 #include <linux/syscalls.h>
73123 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73124 size_t iov_l_curr_offset = 0;
73125 ssize_t iov_len;
73126
73127 + return -ENOSYS; // PaX: until properly audited
73128 +
73129 /*
73130 * Work out how many pages of struct pages we're going to need
73131 * when eventually calling get_user_pages
73132 */
73133 for (i = 0; i < riovcnt; i++) {
73134 iov_len = rvec[i].iov_len;
73135 - if (iov_len > 0) {
73136 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
73137 - + iov_len)
73138 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
73139 - / PAGE_SIZE + 1;
73140 - nr_pages = max(nr_pages, nr_pages_iov);
73141 - }
73142 + if (iov_len <= 0)
73143 + continue;
73144 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
73145 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
73146 + nr_pages = max(nr_pages, nr_pages_iov);
73147 }
73148
73149 if (nr_pages == 0)
73150 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
73151 goto free_proc_pages;
73152 }
73153
73154 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
73155 + rc = -EPERM;
73156 + goto put_task_struct;
73157 + }
73158 +
73159 mm = mm_access(task, PTRACE_MODE_ATTACH);
73160 if (!mm || IS_ERR(mm)) {
73161 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
73162 diff --git a/mm/rmap.c b/mm/rmap.c
73163 index c8454e0..b04f3a2 100644
73164 --- a/mm/rmap.c
73165 +++ b/mm/rmap.c
73166 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73167 struct anon_vma *anon_vma = vma->anon_vma;
73168 struct anon_vma_chain *avc;
73169
73170 +#ifdef CONFIG_PAX_SEGMEXEC
73171 + struct anon_vma_chain *avc_m = NULL;
73172 +#endif
73173 +
73174 might_sleep();
73175 if (unlikely(!anon_vma)) {
73176 struct mm_struct *mm = vma->vm_mm;
73177 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73178 if (!avc)
73179 goto out_enomem;
73180
73181 +#ifdef CONFIG_PAX_SEGMEXEC
73182 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
73183 + if (!avc_m)
73184 + goto out_enomem_free_avc;
73185 +#endif
73186 +
73187 anon_vma = find_mergeable_anon_vma(vma);
73188 allocated = NULL;
73189 if (!anon_vma) {
73190 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73191 /* page_table_lock to protect against threads */
73192 spin_lock(&mm->page_table_lock);
73193 if (likely(!vma->anon_vma)) {
73194 +
73195 +#ifdef CONFIG_PAX_SEGMEXEC
73196 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
73197 +
73198 + if (vma_m) {
73199 + BUG_ON(vma_m->anon_vma);
73200 + vma_m->anon_vma = anon_vma;
73201 + avc_m->anon_vma = anon_vma;
73202 + avc_m->vma = vma;
73203 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
73204 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
73205 + avc_m = NULL;
73206 + }
73207 +#endif
73208 +
73209 vma->anon_vma = anon_vma;
73210 avc->anon_vma = anon_vma;
73211 avc->vma = vma;
73212 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
73213
73214 if (unlikely(allocated))
73215 put_anon_vma(allocated);
73216 +
73217 +#ifdef CONFIG_PAX_SEGMEXEC
73218 + if (unlikely(avc_m))
73219 + anon_vma_chain_free(avc_m);
73220 +#endif
73221 +
73222 if (unlikely(avc))
73223 anon_vma_chain_free(avc);
73224 }
73225 return 0;
73226
73227 out_enomem_free_avc:
73228 +
73229 +#ifdef CONFIG_PAX_SEGMEXEC
73230 + if (avc_m)
73231 + anon_vma_chain_free(avc_m);
73232 +#endif
73233 +
73234 anon_vma_chain_free(avc);
73235 out_enomem:
73236 return -ENOMEM;
73237 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
73238 * Attach the anon_vmas from src to dst.
73239 * Returns 0 on success, -ENOMEM on failure.
73240 */
73241 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
73242 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
73243 {
73244 struct anon_vma_chain *avc, *pavc;
73245 struct anon_vma *root = NULL;
73246 @@ -321,7 +358,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
73247 * the corresponding VMA in the parent process is attached to.
73248 * Returns 0 on success, non-zero on failure.
73249 */
73250 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
73251 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
73252 {
73253 struct anon_vma_chain *avc;
73254 struct anon_vma *anon_vma;
73255 diff --git a/mm/shmem.c b/mm/shmem.c
73256 index 269d049..a9d2b50 100644
73257 --- a/mm/shmem.c
73258 +++ b/mm/shmem.c
73259 @@ -31,7 +31,7 @@
73260 #include <linux/export.h>
73261 #include <linux/swap.h>
73262
73263 -static struct vfsmount *shm_mnt;
73264 +struct vfsmount *shm_mnt;
73265
73266 #ifdef CONFIG_SHMEM
73267 /*
73268 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
73269 #define BOGO_DIRENT_SIZE 20
73270
73271 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
73272 -#define SHORT_SYMLINK_LEN 128
73273 +#define SHORT_SYMLINK_LEN 64
73274
73275 struct shmem_xattr {
73276 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
73277 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
73278 int err = -ENOMEM;
73279
73280 /* Round up to L1_CACHE_BYTES to resist false sharing */
73281 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
73282 - L1_CACHE_BYTES), GFP_KERNEL);
73283 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
73284 if (!sbinfo)
73285 return -ENOMEM;
73286
73287 diff --git a/mm/slab.c b/mm/slab.c
73288 index f0bd785..348b96a 100644
73289 --- a/mm/slab.c
73290 +++ b/mm/slab.c
73291 @@ -153,7 +153,7 @@
73292
73293 /* Legal flag mask for kmem_cache_create(). */
73294 #if DEBUG
73295 -# define CREATE_MASK (SLAB_RED_ZONE | \
73296 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
73297 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
73298 SLAB_CACHE_DMA | \
73299 SLAB_STORE_USER | \
73300 @@ -161,7 +161,7 @@
73301 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73302 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
73303 #else
73304 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
73305 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
73306 SLAB_CACHE_DMA | \
73307 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
73308 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
73309 @@ -290,7 +290,7 @@ struct kmem_list3 {
73310 * Need this for bootstrapping a per node allocator.
73311 */
73312 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
73313 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
73314 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
73315 #define CACHE_CACHE 0
73316 #define SIZE_AC MAX_NUMNODES
73317 #define SIZE_L3 (2 * MAX_NUMNODES)
73318 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
73319 if ((x)->max_freeable < i) \
73320 (x)->max_freeable = i; \
73321 } while (0)
73322 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
73323 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
73324 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
73325 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
73326 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
73327 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
73328 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
73329 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
73330 #else
73331 #define STATS_INC_ACTIVE(x) do { } while (0)
73332 #define STATS_DEC_ACTIVE(x) do { } while (0)
73333 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
73334 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
73335 */
73336 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
73337 - const struct slab *slab, void *obj)
73338 + const struct slab *slab, const void *obj)
73339 {
73340 u32 offset = (obj - slab->s_mem);
73341 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
73342 @@ -568,7 +568,7 @@ struct cache_names {
73343 static struct cache_names __initdata cache_names[] = {
73344 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
73345 #include <linux/kmalloc_sizes.h>
73346 - {NULL,}
73347 + {NULL}
73348 #undef CACHE
73349 };
73350
73351 @@ -1588,7 +1588,7 @@ void __init kmem_cache_init(void)
73352 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
73353 sizes[INDEX_AC].cs_size,
73354 ARCH_KMALLOC_MINALIGN,
73355 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73356 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73357 NULL);
73358
73359 if (INDEX_AC != INDEX_L3) {
73360 @@ -1596,7 +1596,7 @@ void __init kmem_cache_init(void)
73361 kmem_cache_create(names[INDEX_L3].name,
73362 sizes[INDEX_L3].cs_size,
73363 ARCH_KMALLOC_MINALIGN,
73364 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73365 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73366 NULL);
73367 }
73368
73369 @@ -1614,7 +1614,7 @@ void __init kmem_cache_init(void)
73370 sizes->cs_cachep = kmem_cache_create(names->name,
73371 sizes->cs_size,
73372 ARCH_KMALLOC_MINALIGN,
73373 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
73374 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
73375 NULL);
73376 }
73377 #ifdef CONFIG_ZONE_DMA
73378 @@ -4339,10 +4339,10 @@ static int s_show(struct seq_file *m, void *p)
73379 }
73380 /* cpu stats */
73381 {
73382 - unsigned long allochit = atomic_read(&cachep->allochit);
73383 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
73384 - unsigned long freehit = atomic_read(&cachep->freehit);
73385 - unsigned long freemiss = atomic_read(&cachep->freemiss);
73386 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
73387 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
73388 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
73389 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
73390
73391 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
73392 allochit, allocmiss, freehit, freemiss);
73393 @@ -4601,13 +4601,62 @@ static int __init slab_proc_init(void)
73394 {
73395 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
73396 #ifdef CONFIG_DEBUG_SLAB_LEAK
73397 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
73398 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
73399 #endif
73400 return 0;
73401 }
73402 module_init(slab_proc_init);
73403 #endif
73404
73405 +void check_object_size(const void *ptr, unsigned long n, bool to)
73406 +{
73407 +
73408 +#ifdef CONFIG_PAX_USERCOPY
73409 + struct page *page;
73410 + struct kmem_cache *cachep = NULL;
73411 + struct slab *slabp;
73412 + unsigned int objnr;
73413 + unsigned long offset;
73414 + const char *type;
73415 +
73416 + if (!n)
73417 + return;
73418 +
73419 + type = "<null>";
73420 + if (ZERO_OR_NULL_PTR(ptr))
73421 + goto report;
73422 +
73423 + if (!virt_addr_valid(ptr))
73424 + return;
73425 +
73426 + page = virt_to_head_page(ptr);
73427 +
73428 + type = "<process stack>";
73429 + if (!PageSlab(page)) {
73430 + if (object_is_on_stack(ptr, n) == -1)
73431 + goto report;
73432 + return;
73433 + }
73434 +
73435 + cachep = page_get_cache(page);
73436 + type = cachep->name;
73437 + if (!(cachep->flags & SLAB_USERCOPY))
73438 + goto report;
73439 +
73440 + slabp = page_get_slab(page);
73441 + objnr = obj_to_index(cachep, slabp, ptr);
73442 + BUG_ON(objnr >= cachep->num);
73443 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
73444 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
73445 + return;
73446 +
73447 +report:
73448 + pax_report_usercopy(ptr, n, to, type);
73449 +#endif
73450 +
73451 +}
73452 +EXPORT_SYMBOL(check_object_size);
73453 +
73454 /**
73455 * ksize - get the actual amount of memory allocated for a given object
73456 * @objp: Pointer to the object
73457 diff --git a/mm/slob.c b/mm/slob.c
73458 index 8105be4..e045f96 100644
73459 --- a/mm/slob.c
73460 +++ b/mm/slob.c
73461 @@ -29,7 +29,7 @@
73462 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
73463 * alloc_pages() directly, allocating compound pages so the page order
73464 * does not have to be separately tracked, and also stores the exact
73465 - * allocation size in page->private so that it can be used to accurately
73466 + * allocation size in slob_page->size so that it can be used to accurately
73467 * provide ksize(). These objects are detected in kfree() because slob_page()
73468 * is false for them.
73469 *
73470 @@ -58,6 +58,7 @@
73471 */
73472
73473 #include <linux/kernel.h>
73474 +#include <linux/sched.h>
73475 #include <linux/slab.h>
73476 #include <linux/mm.h>
73477 #include <linux/swap.h> /* struct reclaim_state */
73478 @@ -102,7 +103,8 @@ struct slob_page {
73479 unsigned long flags; /* mandatory */
73480 atomic_t _count; /* mandatory */
73481 slobidx_t units; /* free units left in page */
73482 - unsigned long pad[2];
73483 + unsigned long pad[1];
73484 + unsigned long size; /* size when >=PAGE_SIZE */
73485 slob_t *free; /* first free slob_t in page */
73486 struct list_head list; /* linked list of free pages */
73487 };
73488 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
73489 */
73490 static inline int is_slob_page(struct slob_page *sp)
73491 {
73492 - return PageSlab((struct page *)sp);
73493 + return PageSlab((struct page *)sp) && !sp->size;
73494 }
73495
73496 static inline void set_slob_page(struct slob_page *sp)
73497 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
73498
73499 static inline struct slob_page *slob_page(const void *addr)
73500 {
73501 - return (struct slob_page *)virt_to_page(addr);
73502 + return (struct slob_page *)virt_to_head_page(addr);
73503 }
73504
73505 /*
73506 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
73507 /*
73508 * Return the size of a slob block.
73509 */
73510 -static slobidx_t slob_units(slob_t *s)
73511 +static slobidx_t slob_units(const slob_t *s)
73512 {
73513 if (s->units > 0)
73514 return s->units;
73515 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
73516 /*
73517 * Return the next free slob block pointer after this one.
73518 */
73519 -static slob_t *slob_next(slob_t *s)
73520 +static slob_t *slob_next(const slob_t *s)
73521 {
73522 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
73523 slobidx_t next;
73524 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
73525 /*
73526 * Returns true if s is the last free block in its page.
73527 */
73528 -static int slob_last(slob_t *s)
73529 +static int slob_last(const slob_t *s)
73530 {
73531 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
73532 }
73533 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
73534 if (!page)
73535 return NULL;
73536
73537 + set_slob_page(page);
73538 return page_address(page);
73539 }
73540
73541 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
73542 if (!b)
73543 return NULL;
73544 sp = slob_page(b);
73545 - set_slob_page(sp);
73546
73547 spin_lock_irqsave(&slob_lock, flags);
73548 sp->units = SLOB_UNITS(PAGE_SIZE);
73549 sp->free = b;
73550 + sp->size = 0;
73551 INIT_LIST_HEAD(&sp->list);
73552 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
73553 set_slob_page_free(sp, slob_list);
73554 @@ -476,10 +479,9 @@ out:
73555 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
73556 */
73557
73558 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73559 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
73560 {
73561 - unsigned int *m;
73562 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73563 + slob_t *m;
73564 void *ret;
73565
73566 gfp &= gfp_allowed_mask;
73567 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73568
73569 if (!m)
73570 return NULL;
73571 - *m = size;
73572 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
73573 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
73574 + m[0].units = size;
73575 + m[1].units = align;
73576 ret = (void *)m + align;
73577
73578 trace_kmalloc_node(_RET_IP_, ret,
73579 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73580 gfp |= __GFP_COMP;
73581 ret = slob_new_pages(gfp, order, node);
73582 if (ret) {
73583 - struct page *page;
73584 - page = virt_to_page(ret);
73585 - page->private = size;
73586 + struct slob_page *sp;
73587 + sp = slob_page(ret);
73588 + sp->size = size;
73589 }
73590
73591 trace_kmalloc_node(_RET_IP_, ret,
73592 size, PAGE_SIZE << order, gfp, node);
73593 }
73594
73595 - kmemleak_alloc(ret, size, 1, gfp);
73596 + return ret;
73597 +}
73598 +
73599 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
73600 +{
73601 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73602 + void *ret = __kmalloc_node_align(size, gfp, node, align);
73603 +
73604 + if (!ZERO_OR_NULL_PTR(ret))
73605 + kmemleak_alloc(ret, size, 1, gfp);
73606 return ret;
73607 }
73608 EXPORT_SYMBOL(__kmalloc_node);
73609 @@ -533,13 +547,92 @@ void kfree(const void *block)
73610 sp = slob_page(block);
73611 if (is_slob_page(sp)) {
73612 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73613 - unsigned int *m = (unsigned int *)(block - align);
73614 - slob_free(m, *m + align);
73615 - } else
73616 + slob_t *m = (slob_t *)(block - align);
73617 + slob_free(m, m[0].units + align);
73618 + } else {
73619 + clear_slob_page(sp);
73620 + free_slob_page(sp);
73621 + sp->size = 0;
73622 put_page(&sp->page);
73623 + }
73624 }
73625 EXPORT_SYMBOL(kfree);
73626
73627 +void check_object_size(const void *ptr, unsigned long n, bool to)
73628 +{
73629 +
73630 +#ifdef CONFIG_PAX_USERCOPY
73631 + struct slob_page *sp;
73632 + const slob_t *free;
73633 + const void *base;
73634 + unsigned long flags;
73635 + const char *type;
73636 +
73637 + if (!n)
73638 + return;
73639 +
73640 + type = "<null>";
73641 + if (ZERO_OR_NULL_PTR(ptr))
73642 + goto report;
73643 +
73644 + if (!virt_addr_valid(ptr))
73645 + return;
73646 +
73647 + type = "<process stack>";
73648 + sp = slob_page(ptr);
73649 + if (!PageSlab((struct page *)sp)) {
73650 + if (object_is_on_stack(ptr, n) == -1)
73651 + goto report;
73652 + return;
73653 + }
73654 +
73655 + type = "<slob>";
73656 + if (sp->size) {
73657 + base = page_address(&sp->page);
73658 + if (base <= ptr && n <= sp->size - (ptr - base))
73659 + return;
73660 + goto report;
73661 + }
73662 +
73663 + /* some tricky double walking to find the chunk */
73664 + spin_lock_irqsave(&slob_lock, flags);
73665 + base = (void *)((unsigned long)ptr & PAGE_MASK);
73666 + free = sp->free;
73667 +
73668 + while (!slob_last(free) && (void *)free <= ptr) {
73669 + base = free + slob_units(free);
73670 + free = slob_next(free);
73671 + }
73672 +
73673 + while (base < (void *)free) {
73674 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
73675 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
73676 + int offset;
73677 +
73678 + if (ptr < base + align)
73679 + break;
73680 +
73681 + offset = ptr - base - align;
73682 + if (offset >= m) {
73683 + base += size;
73684 + continue;
73685 + }
73686 +
73687 + if (n > m - offset)
73688 + break;
73689 +
73690 + spin_unlock_irqrestore(&slob_lock, flags);
73691 + return;
73692 + }
73693 +
73694 + spin_unlock_irqrestore(&slob_lock, flags);
73695 +report:
73696 + pax_report_usercopy(ptr, n, to, type);
73697 +#endif
73698 +
73699 +}
73700 +EXPORT_SYMBOL(check_object_size);
73701 +
73702 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
73703 size_t ksize(const void *block)
73704 {
73705 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
73706 sp = slob_page(block);
73707 if (is_slob_page(sp)) {
73708 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
73709 - unsigned int *m = (unsigned int *)(block - align);
73710 - return SLOB_UNITS(*m) * SLOB_UNIT;
73711 + slob_t *m = (slob_t *)(block - align);
73712 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
73713 } else
73714 - return sp->page.private;
73715 + return sp->size;
73716 }
73717 EXPORT_SYMBOL(ksize);
73718
73719 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73720 {
73721 struct kmem_cache *c;
73722
73723 +#ifdef CONFIG_PAX_USERCOPY
73724 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
73725 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
73726 +#else
73727 c = slob_alloc(sizeof(struct kmem_cache),
73728 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
73729 +#endif
73730
73731 if (c) {
73732 c->name = name;
73733 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
73734
73735 lockdep_trace_alloc(flags);
73736
73737 +#ifdef CONFIG_PAX_USERCOPY
73738 + b = __kmalloc_node_align(c->size, flags, node, c->align);
73739 +#else
73740 if (c->size < PAGE_SIZE) {
73741 b = slob_alloc(c->size, flags, c->align, node);
73742 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73743 SLOB_UNITS(c->size) * SLOB_UNIT,
73744 flags, node);
73745 } else {
73746 + struct slob_page *sp;
73747 +
73748 b = slob_new_pages(flags, get_order(c->size), node);
73749 + sp = slob_page(b);
73750 + sp->size = c->size;
73751 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
73752 PAGE_SIZE << get_order(c->size),
73753 flags, node);
73754 }
73755 +#endif
73756
73757 if (c->ctor)
73758 c->ctor(b);
73759 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
73760
73761 static void __kmem_cache_free(void *b, int size)
73762 {
73763 - if (size < PAGE_SIZE)
73764 + struct slob_page *sp = slob_page(b);
73765 +
73766 + if (is_slob_page(sp))
73767 slob_free(b, size);
73768 - else
73769 + else {
73770 + clear_slob_page(sp);
73771 + free_slob_page(sp);
73772 + sp->size = 0;
73773 slob_free_pages(b, get_order(size));
73774 + }
73775 }
73776
73777 static void kmem_rcu_free(struct rcu_head *head)
73778 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
73779
73780 void kmem_cache_free(struct kmem_cache *c, void *b)
73781 {
73782 + int size = c->size;
73783 +
73784 +#ifdef CONFIG_PAX_USERCOPY
73785 + if (size + c->align < PAGE_SIZE) {
73786 + size += c->align;
73787 + b -= c->align;
73788 + }
73789 +#endif
73790 +
73791 kmemleak_free_recursive(b, c->flags);
73792 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
73793 struct slob_rcu *slob_rcu;
73794 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
73795 - slob_rcu->size = c->size;
73796 + slob_rcu = b + (size - sizeof(struct slob_rcu));
73797 + slob_rcu->size = size;
73798 call_rcu(&slob_rcu->head, kmem_rcu_free);
73799 } else {
73800 - __kmem_cache_free(b, c->size);
73801 + __kmem_cache_free(b, size);
73802 }
73803
73804 +#ifdef CONFIG_PAX_USERCOPY
73805 + trace_kfree(_RET_IP_, b);
73806 +#else
73807 trace_kmem_cache_free(_RET_IP_, b);
73808 +#endif
73809 +
73810 }
73811 EXPORT_SYMBOL(kmem_cache_free);
73812
73813 diff --git a/mm/slub.c b/mm/slub.c
73814 index 0342a5d..8180ae9 100644
73815 --- a/mm/slub.c
73816 +++ b/mm/slub.c
73817 @@ -208,7 +208,7 @@ struct track {
73818
73819 enum track_item { TRACK_ALLOC, TRACK_FREE };
73820
73821 -#ifdef CONFIG_SYSFS
73822 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73823 static int sysfs_slab_add(struct kmem_cache *);
73824 static int sysfs_slab_alias(struct kmem_cache *, const char *);
73825 static void sysfs_slab_remove(struct kmem_cache *);
73826 @@ -532,7 +532,7 @@ static void print_track(const char *s, struct track *t)
73827 if (!t->addr)
73828 return;
73829
73830 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
73831 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
73832 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
73833 #ifdef CONFIG_STACKTRACE
73834 {
73835 @@ -2571,6 +2571,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
73836
73837 page = virt_to_head_page(x);
73838
73839 + BUG_ON(!PageSlab(page));
73840 +
73841 slab_free(s, page, x, _RET_IP_);
73842
73843 trace_kmem_cache_free(_RET_IP_, x);
73844 @@ -2604,7 +2606,7 @@ static int slub_min_objects;
73845 * Merge control. If this is set then no merging of slab caches will occur.
73846 * (Could be removed. This was introduced to pacify the merge skeptics.)
73847 */
73848 -static int slub_nomerge;
73849 +static int slub_nomerge = 1;
73850
73851 /*
73852 * Calculate the order of allocation given an slab object size.
73853 @@ -3057,7 +3059,7 @@ static int kmem_cache_open(struct kmem_cache *s,
73854 else
73855 s->cpu_partial = 30;
73856
73857 - s->refcount = 1;
73858 + atomic_set(&s->refcount, 1);
73859 #ifdef CONFIG_NUMA
73860 s->remote_node_defrag_ratio = 1000;
73861 #endif
73862 @@ -3161,8 +3163,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
73863 void kmem_cache_destroy(struct kmem_cache *s)
73864 {
73865 down_write(&slub_lock);
73866 - s->refcount--;
73867 - if (!s->refcount) {
73868 + if (atomic_dec_and_test(&s->refcount)) {
73869 list_del(&s->list);
73870 up_write(&slub_lock);
73871 if (kmem_cache_close(s)) {
73872 @@ -3373,6 +3374,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
73873 EXPORT_SYMBOL(__kmalloc_node);
73874 #endif
73875
73876 +void check_object_size(const void *ptr, unsigned long n, bool to)
73877 +{
73878 +
73879 +#ifdef CONFIG_PAX_USERCOPY
73880 + struct page *page;
73881 + struct kmem_cache *s = NULL;
73882 + unsigned long offset;
73883 + const char *type;
73884 +
73885 + if (!n)
73886 + return;
73887 +
73888 + type = "<null>";
73889 + if (ZERO_OR_NULL_PTR(ptr))
73890 + goto report;
73891 +
73892 + if (!virt_addr_valid(ptr))
73893 + return;
73894 +
73895 + page = virt_to_head_page(ptr);
73896 +
73897 + type = "<process stack>";
73898 + if (!PageSlab(page)) {
73899 + if (object_is_on_stack(ptr, n) == -1)
73900 + goto report;
73901 + return;
73902 + }
73903 +
73904 + s = page->slab;
73905 + type = s->name;
73906 + if (!(s->flags & SLAB_USERCOPY))
73907 + goto report;
73908 +
73909 + offset = (ptr - page_address(page)) % s->size;
73910 + if (offset <= s->objsize && n <= s->objsize - offset)
73911 + return;
73912 +
73913 +report:
73914 + pax_report_usercopy(ptr, n, to, type);
73915 +#endif
73916 +
73917 +}
73918 +EXPORT_SYMBOL(check_object_size);
73919 +
73920 size_t ksize(const void *object)
73921 {
73922 struct page *page;
73923 @@ -3647,7 +3692,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
73924 int node;
73925
73926 list_add(&s->list, &slab_caches);
73927 - s->refcount = -1;
73928 + atomic_set(&s->refcount, -1);
73929
73930 for_each_node_state(node, N_NORMAL_MEMORY) {
73931 struct kmem_cache_node *n = get_node(s, node);
73932 @@ -3767,17 +3812,17 @@ void __init kmem_cache_init(void)
73933
73934 /* Caches that are not of the two-to-the-power-of size */
73935 if (KMALLOC_MIN_SIZE <= 32) {
73936 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
73937 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
73938 caches++;
73939 }
73940
73941 if (KMALLOC_MIN_SIZE <= 64) {
73942 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
73943 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
73944 caches++;
73945 }
73946
73947 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
73948 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
73949 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
73950 caches++;
73951 }
73952
73953 @@ -3845,7 +3890,7 @@ static int slab_unmergeable(struct kmem_cache *s)
73954 /*
73955 * We may have set a slab to be unmergeable during bootstrap.
73956 */
73957 - if (s->refcount < 0)
73958 + if (atomic_read(&s->refcount) < 0)
73959 return 1;
73960
73961 return 0;
73962 @@ -3904,7 +3949,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73963 down_write(&slub_lock);
73964 s = find_mergeable(size, align, flags, name, ctor);
73965 if (s) {
73966 - s->refcount++;
73967 + atomic_inc(&s->refcount);
73968 /*
73969 * Adjust the object sizes so that we clear
73970 * the complete object on kzalloc.
73971 @@ -3913,7 +3958,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
73972 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
73973
73974 if (sysfs_slab_alias(s, name)) {
73975 - s->refcount--;
73976 + atomic_dec(&s->refcount);
73977 goto err;
73978 }
73979 up_write(&slub_lock);
73980 @@ -4042,7 +4087,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
73981 }
73982 #endif
73983
73984 -#ifdef CONFIG_SYSFS
73985 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73986 static int count_inuse(struct page *page)
73987 {
73988 return page->inuse;
73989 @@ -4429,12 +4474,12 @@ static void resiliency_test(void)
73990 validate_slab_cache(kmalloc_caches[9]);
73991 }
73992 #else
73993 -#ifdef CONFIG_SYSFS
73994 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
73995 static void resiliency_test(void) {};
73996 #endif
73997 #endif
73998
73999 -#ifdef CONFIG_SYSFS
74000 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74001 enum slab_stat_type {
74002 SL_ALL, /* All slabs */
74003 SL_PARTIAL, /* Only partially allocated slabs */
74004 @@ -4677,7 +4722,7 @@ SLAB_ATTR_RO(ctor);
74005
74006 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
74007 {
74008 - return sprintf(buf, "%d\n", s->refcount - 1);
74009 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
74010 }
74011 SLAB_ATTR_RO(aliases);
74012
74013 @@ -5244,6 +5289,7 @@ static char *create_unique_id(struct kmem_cache *s)
74014 return name;
74015 }
74016
74017 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74018 static int sysfs_slab_add(struct kmem_cache *s)
74019 {
74020 int err;
74021 @@ -5306,6 +5352,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
74022 kobject_del(&s->kobj);
74023 kobject_put(&s->kobj);
74024 }
74025 +#endif
74026
74027 /*
74028 * Need to buffer aliases during bootup until sysfs becomes
74029 @@ -5319,6 +5366,7 @@ struct saved_alias {
74030
74031 static struct saved_alias *alias_list;
74032
74033 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
74034 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74035 {
74036 struct saved_alias *al;
74037 @@ -5341,6 +5389,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
74038 alias_list = al;
74039 return 0;
74040 }
74041 +#endif
74042
74043 static int __init slab_sysfs_init(void)
74044 {
74045 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
74046 index 1b7e22a..3fcd4f3 100644
74047 --- a/mm/sparse-vmemmap.c
74048 +++ b/mm/sparse-vmemmap.c
74049 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
74050 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74051 if (!p)
74052 return NULL;
74053 - pud_populate(&init_mm, pud, p);
74054 + pud_populate_kernel(&init_mm, pud, p);
74055 }
74056 return pud;
74057 }
74058 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
74059 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
74060 if (!p)
74061 return NULL;
74062 - pgd_populate(&init_mm, pgd, p);
74063 + pgd_populate_kernel(&init_mm, pgd, p);
74064 }
74065 return pgd;
74066 }
74067 diff --git a/mm/swap.c b/mm/swap.c
74068 index 14380e9..e244704 100644
74069 --- a/mm/swap.c
74070 +++ b/mm/swap.c
74071 @@ -30,6 +30,7 @@
74072 #include <linux/backing-dev.h>
74073 #include <linux/memcontrol.h>
74074 #include <linux/gfp.h>
74075 +#include <linux/hugetlb.h>
74076
74077 #include "internal.h"
74078
74079 @@ -70,6 +71,8 @@ static void __put_compound_page(struct page *page)
74080
74081 __page_cache_release(page);
74082 dtor = get_compound_page_dtor(page);
74083 + if (!PageHuge(page))
74084 + BUG_ON(dtor != free_compound_page);
74085 (*dtor)(page);
74086 }
74087
74088 diff --git a/mm/swapfile.c b/mm/swapfile.c
74089 index 099c209..7db7b6f 100644
74090 --- a/mm/swapfile.c
74091 +++ b/mm/swapfile.c
74092 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
74093
74094 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
74095 /* Activity counter to indicate that a swapon or swapoff has occurred */
74096 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
74097 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
74098
74099 static inline unsigned char swap_count(unsigned char ent)
74100 {
74101 @@ -1669,7 +1669,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
74102 }
74103 filp_close(swap_file, NULL);
74104 err = 0;
74105 - atomic_inc(&proc_poll_event);
74106 + atomic_inc_unchecked(&proc_poll_event);
74107 wake_up_interruptible(&proc_poll_wait);
74108
74109 out_dput:
74110 @@ -1685,8 +1685,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
74111
74112 poll_wait(file, &proc_poll_wait, wait);
74113
74114 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
74115 - seq->poll_event = atomic_read(&proc_poll_event);
74116 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
74117 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74118 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
74119 }
74120
74121 @@ -1784,7 +1784,7 @@ static int swaps_open(struct inode *inode, struct file *file)
74122 return ret;
74123
74124 seq = file->private_data;
74125 - seq->poll_event = atomic_read(&proc_poll_event);
74126 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
74127 return 0;
74128 }
74129
74130 @@ -2122,7 +2122,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
74131 (p->flags & SWP_DISCARDABLE) ? "D" : "");
74132
74133 mutex_unlock(&swapon_mutex);
74134 - atomic_inc(&proc_poll_event);
74135 + atomic_inc_unchecked(&proc_poll_event);
74136 wake_up_interruptible(&proc_poll_wait);
74137
74138 if (S_ISREG(inode->i_mode))
74139 diff --git a/mm/util.c b/mm/util.c
74140 index 136ac4f..f917fa9 100644
74141 --- a/mm/util.c
74142 +++ b/mm/util.c
74143 @@ -243,6 +243,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
74144 void arch_pick_mmap_layout(struct mm_struct *mm)
74145 {
74146 mm->mmap_base = TASK_UNMAPPED_BASE;
74147 +
74148 +#ifdef CONFIG_PAX_RANDMMAP
74149 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74150 + mm->mmap_base += mm->delta_mmap;
74151 +#endif
74152 +
74153 mm->get_unmapped_area = arch_get_unmapped_area;
74154 mm->unmap_area = arch_unmap_area;
74155 }
74156 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
74157 index 86ce9a5..550d03c 100644
74158 --- a/mm/vmalloc.c
74159 +++ b/mm/vmalloc.c
74160 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
74161
74162 pte = pte_offset_kernel(pmd, addr);
74163 do {
74164 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74165 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74166 +
74167 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74168 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
74169 + BUG_ON(!pte_exec(*pte));
74170 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
74171 + continue;
74172 + }
74173 +#endif
74174 +
74175 + {
74176 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
74177 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
74178 + }
74179 } while (pte++, addr += PAGE_SIZE, addr != end);
74180 }
74181
74182 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74183 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
74184 {
74185 pte_t *pte;
74186 + int ret = -ENOMEM;
74187
74188 /*
74189 * nr is a running index into the array which helps higher level
74190 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
74191 pte = pte_alloc_kernel(pmd, addr);
74192 if (!pte)
74193 return -ENOMEM;
74194 +
74195 + pax_open_kernel();
74196 do {
74197 struct page *page = pages[*nr];
74198
74199 - if (WARN_ON(!pte_none(*pte)))
74200 - return -EBUSY;
74201 - if (WARN_ON(!page))
74202 - return -ENOMEM;
74203 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74204 + if (pgprot_val(prot) & _PAGE_NX)
74205 +#endif
74206 +
74207 + if (WARN_ON(!pte_none(*pte))) {
74208 + ret = -EBUSY;
74209 + goto out;
74210 + }
74211 + if (WARN_ON(!page)) {
74212 + ret = -ENOMEM;
74213 + goto out;
74214 + }
74215 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
74216 (*nr)++;
74217 } while (pte++, addr += PAGE_SIZE, addr != end);
74218 - return 0;
74219 + ret = 0;
74220 +out:
74221 + pax_close_kernel();
74222 + return ret;
74223 }
74224
74225 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74226 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
74227 pmd_t *pmd;
74228 unsigned long next;
74229
74230 - pmd = pmd_alloc(&init_mm, pud, addr);
74231 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74232 if (!pmd)
74233 return -ENOMEM;
74234 do {
74235 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
74236 pud_t *pud;
74237 unsigned long next;
74238
74239 - pud = pud_alloc(&init_mm, pgd, addr);
74240 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
74241 if (!pud)
74242 return -ENOMEM;
74243 do {
74244 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
74245 * and fall back on vmalloc() if that fails. Others
74246 * just put it in the vmalloc space.
74247 */
74248 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
74249 +#ifdef CONFIG_MODULES
74250 +#ifdef MODULES_VADDR
74251 unsigned long addr = (unsigned long)x;
74252 if (addr >= MODULES_VADDR && addr < MODULES_END)
74253 return 1;
74254 #endif
74255 +
74256 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74257 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
74258 + return 1;
74259 +#endif
74260 +
74261 +#endif
74262 +
74263 return is_vmalloc_addr(x);
74264 }
74265
74266 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
74267
74268 if (!pgd_none(*pgd)) {
74269 pud_t *pud = pud_offset(pgd, addr);
74270 +#ifdef CONFIG_X86
74271 + if (!pud_large(*pud))
74272 +#endif
74273 if (!pud_none(*pud)) {
74274 pmd_t *pmd = pmd_offset(pud, addr);
74275 +#ifdef CONFIG_X86
74276 + if (!pmd_large(*pmd))
74277 +#endif
74278 if (!pmd_none(*pmd)) {
74279 pte_t *ptep, pte;
74280
74281 @@ -332,6 +372,10 @@ static void purge_vmap_area_lazy(void);
74282 static struct vmap_area *alloc_vmap_area(unsigned long size,
74283 unsigned long align,
74284 unsigned long vstart, unsigned long vend,
74285 + int node, gfp_t gfp_mask) __size_overflow(1);
74286 +static struct vmap_area *alloc_vmap_area(unsigned long size,
74287 + unsigned long align,
74288 + unsigned long vstart, unsigned long vend,
74289 int node, gfp_t gfp_mask)
74290 {
74291 struct vmap_area *va;
74292 @@ -1319,6 +1363,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
74293 struct vm_struct *area;
74294
74295 BUG_ON(in_interrupt());
74296 +
74297 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74298 + if (flags & VM_KERNEXEC) {
74299 + if (start != VMALLOC_START || end != VMALLOC_END)
74300 + return NULL;
74301 + start = (unsigned long)MODULES_EXEC_VADDR;
74302 + end = (unsigned long)MODULES_EXEC_END;
74303 + }
74304 +#endif
74305 +
74306 if (flags & VM_IOREMAP) {
74307 int bit = fls(size);
74308
74309 @@ -1551,6 +1605,11 @@ void *vmap(struct page **pages, unsigned int count,
74310 if (count > totalram_pages)
74311 return NULL;
74312
74313 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74314 + if (!(pgprot_val(prot) & _PAGE_NX))
74315 + flags |= VM_KERNEXEC;
74316 +#endif
74317 +
74318 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
74319 __builtin_return_address(0));
74320 if (!area)
74321 @@ -1652,6 +1711,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
74322 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
74323 goto fail;
74324
74325 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
74326 + if (!(pgprot_val(prot) & _PAGE_NX))
74327 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
74328 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
74329 + else
74330 +#endif
74331 +
74332 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
74333 start, end, node, gfp_mask, caller);
74334 if (!area)
74335 @@ -1825,10 +1891,9 @@ EXPORT_SYMBOL(vzalloc_node);
74336 * For tight control over page level allocator and protection flags
74337 * use __vmalloc() instead.
74338 */
74339 -
74340 void *vmalloc_exec(unsigned long size)
74341 {
74342 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
74343 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
74344 -1, __builtin_return_address(0));
74345 }
74346
74347 @@ -2123,6 +2188,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
74348 unsigned long uaddr = vma->vm_start;
74349 unsigned long usize = vma->vm_end - vma->vm_start;
74350
74351 + BUG_ON(vma->vm_mirror);
74352 +
74353 if ((PAGE_SIZE-1) & (unsigned long)addr)
74354 return -EINVAL;
74355
74356 @@ -2375,8 +2442,8 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets,
74357 return NULL;
74358 }
74359
74360 - vms = kzalloc(sizeof(vms[0]) * nr_vms, GFP_KERNEL);
74361 - vas = kzalloc(sizeof(vas[0]) * nr_vms, GFP_KERNEL);
74362 + vms = kcalloc(nr_vms, sizeof(vms[0]), GFP_KERNEL);
74363 + vas = kcalloc(nr_vms, sizeof(vas[0]), GFP_KERNEL);
74364 if (!vas || !vms)
74365 goto err_free2;
74366
74367 diff --git a/mm/vmstat.c b/mm/vmstat.c
74368 index f600557..1459fc8 100644
74369 --- a/mm/vmstat.c
74370 +++ b/mm/vmstat.c
74371 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
74372 *
74373 * vm_stat contains the global counters
74374 */
74375 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74376 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
74377 EXPORT_SYMBOL(vm_stat);
74378
74379 #ifdef CONFIG_SMP
74380 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
74381 v = p->vm_stat_diff[i];
74382 p->vm_stat_diff[i] = 0;
74383 local_irq_restore(flags);
74384 - atomic_long_add(v, &zone->vm_stat[i]);
74385 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
74386 global_diff[i] += v;
74387 #ifdef CONFIG_NUMA
74388 /* 3 seconds idle till flush */
74389 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
74390
74391 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
74392 if (global_diff[i])
74393 - atomic_long_add(global_diff[i], &vm_stat[i]);
74394 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
74395 }
74396
74397 #endif
74398 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
74399 start_cpu_timer(cpu);
74400 #endif
74401 #ifdef CONFIG_PROC_FS
74402 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
74403 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
74404 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
74405 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
74406 + {
74407 + mode_t gr_mode = S_IRUGO;
74408 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74409 + gr_mode = S_IRUSR;
74410 +#endif
74411 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
74412 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
74413 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74414 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
74415 +#else
74416 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
74417 +#endif
74418 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
74419 + }
74420 #endif
74421 return 0;
74422 }
74423 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
74424 index efea35b..9c8dd0b 100644
74425 --- a/net/8021q/vlan.c
74426 +++ b/net/8021q/vlan.c
74427 @@ -554,8 +554,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
74428 err = -EPERM;
74429 if (!capable(CAP_NET_ADMIN))
74430 break;
74431 - if ((args.u.name_type >= 0) &&
74432 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
74433 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
74434 struct vlan_net *vn;
74435
74436 vn = net_generic(net, vlan_net_id);
74437 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
74438 index fccae26..e7ece2f 100644
74439 --- a/net/9p/trans_fd.c
74440 +++ b/net/9p/trans_fd.c
74441 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
74442 oldfs = get_fs();
74443 set_fs(get_ds());
74444 /* The cast to a user pointer is valid due to the set_fs() */
74445 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
74446 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
74447 set_fs(oldfs);
74448
74449 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
74450 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
74451 index 876fbe8..8bbea9f 100644
74452 --- a/net/atm/atm_misc.c
74453 +++ b/net/atm/atm_misc.c
74454 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
74455 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
74456 return 1;
74457 atm_return(vcc, truesize);
74458 - atomic_inc(&vcc->stats->rx_drop);
74459 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74460 return 0;
74461 }
74462 EXPORT_SYMBOL(atm_charge);
74463 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
74464 }
74465 }
74466 atm_return(vcc, guess);
74467 - atomic_inc(&vcc->stats->rx_drop);
74468 + atomic_inc_unchecked(&vcc->stats->rx_drop);
74469 return NULL;
74470 }
74471 EXPORT_SYMBOL(atm_alloc_charge);
74472 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
74473
74474 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74475 {
74476 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74477 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74478 __SONET_ITEMS
74479 #undef __HANDLE_ITEM
74480 }
74481 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
74482
74483 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
74484 {
74485 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74486 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
74487 __SONET_ITEMS
74488 #undef __HANDLE_ITEM
74489 }
74490 diff --git a/net/atm/lec.h b/net/atm/lec.h
74491 index dfc0719..47c5322 100644
74492 --- a/net/atm/lec.h
74493 +++ b/net/atm/lec.h
74494 @@ -48,7 +48,7 @@ struct lane2_ops {
74495 const u8 *tlvs, u32 sizeoftlvs);
74496 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
74497 const u8 *tlvs, u32 sizeoftlvs);
74498 -};
74499 +} __no_const;
74500
74501 /*
74502 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
74503 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
74504 index 0919a88..a23d54e 100644
74505 --- a/net/atm/mpc.h
74506 +++ b/net/atm/mpc.h
74507 @@ -33,7 +33,7 @@ struct mpoa_client {
74508 struct mpc_parameters parameters; /* parameters for this client */
74509
74510 const struct net_device_ops *old_ops;
74511 - struct net_device_ops new_ops;
74512 + net_device_ops_no_const new_ops;
74513 };
74514
74515
74516 diff --git a/net/atm/proc.c b/net/atm/proc.c
74517 index 0d020de..011c7bb 100644
74518 --- a/net/atm/proc.c
74519 +++ b/net/atm/proc.c
74520 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
74521 const struct k_atm_aal_stats *stats)
74522 {
74523 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
74524 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
74525 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
74526 - atomic_read(&stats->rx_drop));
74527 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
74528 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
74529 + atomic_read_unchecked(&stats->rx_drop));
74530 }
74531
74532 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
74533 diff --git a/net/atm/resources.c b/net/atm/resources.c
74534 index 23f45ce..c748f1a 100644
74535 --- a/net/atm/resources.c
74536 +++ b/net/atm/resources.c
74537 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
74538 static void copy_aal_stats(struct k_atm_aal_stats *from,
74539 struct atm_aal_stats *to)
74540 {
74541 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
74542 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
74543 __AAL_STAT_ITEMS
74544 #undef __HANDLE_ITEM
74545 }
74546 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
74547 static void subtract_aal_stats(struct k_atm_aal_stats *from,
74548 struct atm_aal_stats *to)
74549 {
74550 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
74551 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
74552 __AAL_STAT_ITEMS
74553 #undef __HANDLE_ITEM
74554 }
74555 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
74556 index 3512e25..2b33401 100644
74557 --- a/net/batman-adv/bat_iv_ogm.c
74558 +++ b/net/batman-adv/bat_iv_ogm.c
74559 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74560
74561 /* change sequence number to network order */
74562 batman_ogm_packet->seqno =
74563 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
74564 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
74565
74566 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
74567 batman_ogm_packet->tt_crc = htons((uint16_t)
74568 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
74569 else
74570 batman_ogm_packet->gw_flags = NO_FLAGS;
74571
74572 - atomic_inc(&hard_iface->seqno);
74573 + atomic_inc_unchecked(&hard_iface->seqno);
74574
74575 slide_own_bcast_window(hard_iface);
74576 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
74577 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
74578 return;
74579
74580 /* could be changed by schedule_own_packet() */
74581 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
74582 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
74583
74584 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
74585
74586 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
74587 index 7704df4..beb4e16 100644
74588 --- a/net/batman-adv/hard-interface.c
74589 +++ b/net/batman-adv/hard-interface.c
74590 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
74591 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
74592 dev_add_pack(&hard_iface->batman_adv_ptype);
74593
74594 - atomic_set(&hard_iface->seqno, 1);
74595 - atomic_set(&hard_iface->frag_seqno, 1);
74596 + atomic_set_unchecked(&hard_iface->seqno, 1);
74597 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
74598 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
74599 hard_iface->net_dev->name);
74600
74601 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
74602 index 987c75a..20d6f36 100644
74603 --- a/net/batman-adv/soft-interface.c
74604 +++ b/net/batman-adv/soft-interface.c
74605 @@ -645,7 +645,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
74606
74607 /* set broadcast sequence number */
74608 bcast_packet->seqno =
74609 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
74610 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
74611
74612 add_bcast_packet_to_list(bat_priv, skb, 1);
74613
74614 @@ -843,7 +843,7 @@ struct net_device *softif_create(const char *name)
74615 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
74616
74617 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
74618 - atomic_set(&bat_priv->bcast_seqno, 1);
74619 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
74620 atomic_set(&bat_priv->ttvn, 0);
74621 atomic_set(&bat_priv->tt_local_changes, 0);
74622 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
74623 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
74624 index e9eb043..d174eeb 100644
74625 --- a/net/batman-adv/types.h
74626 +++ b/net/batman-adv/types.h
74627 @@ -38,8 +38,8 @@ struct hard_iface {
74628 int16_t if_num;
74629 char if_status;
74630 struct net_device *net_dev;
74631 - atomic_t seqno;
74632 - atomic_t frag_seqno;
74633 + atomic_unchecked_t seqno;
74634 + atomic_unchecked_t frag_seqno;
74635 unsigned char *packet_buff;
74636 int packet_len;
74637 struct kobject *hardif_obj;
74638 @@ -154,7 +154,7 @@ struct bat_priv {
74639 atomic_t orig_interval; /* uint */
74640 atomic_t hop_penalty; /* uint */
74641 atomic_t log_level; /* uint */
74642 - atomic_t bcast_seqno;
74643 + atomic_unchecked_t bcast_seqno;
74644 atomic_t bcast_queue_left;
74645 atomic_t batman_queue_left;
74646 atomic_t ttvn; /* translation table version number */
74647 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
74648 index 07d1c1d..7e9bea9 100644
74649 --- a/net/batman-adv/unicast.c
74650 +++ b/net/batman-adv/unicast.c
74651 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
74652 frag1->flags = UNI_FRAG_HEAD | large_tail;
74653 frag2->flags = large_tail;
74654
74655 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
74656 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
74657 frag1->seqno = htons(seqno - 1);
74658 frag2->seqno = htons(seqno);
74659
74660 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
74661 index 280953b..cd219bb 100644
74662 --- a/net/bluetooth/hci_conn.c
74663 +++ b/net/bluetooth/hci_conn.c
74664 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
74665 memset(&cp, 0, sizeof(cp));
74666
74667 cp.handle = cpu_to_le16(conn->handle);
74668 - memcpy(cp.ltk, ltk, sizeof(ltk));
74669 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
74670
74671 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
74672 }
74673 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
74674 index 32d338c..d24bcdb 100644
74675 --- a/net/bluetooth/l2cap_core.c
74676 +++ b/net/bluetooth/l2cap_core.c
74677 @@ -2418,8 +2418,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
74678 break;
74679
74680 case L2CAP_CONF_RFC:
74681 - if (olen == sizeof(rfc))
74682 - memcpy(&rfc, (void *)val, olen);
74683 + if (olen != sizeof(rfc))
74684 + break;
74685 +
74686 + memcpy(&rfc, (void *)val, olen);
74687
74688 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
74689 rfc.mode != chan->mode)
74690 @@ -2537,8 +2539,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
74691
74692 switch (type) {
74693 case L2CAP_CONF_RFC:
74694 - if (olen == sizeof(rfc))
74695 - memcpy(&rfc, (void *)val, olen);
74696 + if (olen != sizeof(rfc))
74697 + break;
74698 +
74699 + memcpy(&rfc, (void *)val, olen);
74700 goto done;
74701 }
74702 }
74703 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
74704 index 5fe2ff3..10968b5 100644
74705 --- a/net/bridge/netfilter/ebtables.c
74706 +++ b/net/bridge/netfilter/ebtables.c
74707 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
74708 tmp.valid_hooks = t->table->valid_hooks;
74709 }
74710 mutex_unlock(&ebt_mutex);
74711 - if (copy_to_user(user, &tmp, *len) != 0){
74712 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
74713 BUGPRINT("c2u Didn't work\n");
74714 ret = -EFAULT;
74715 break;
74716 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
74717 index a97d97a..6f679ed 100644
74718 --- a/net/caif/caif_socket.c
74719 +++ b/net/caif/caif_socket.c
74720 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
74721 #ifdef CONFIG_DEBUG_FS
74722 struct debug_fs_counter {
74723 atomic_t caif_nr_socks;
74724 - atomic_t caif_sock_create;
74725 - atomic_t num_connect_req;
74726 - atomic_t num_connect_resp;
74727 - atomic_t num_connect_fail_resp;
74728 - atomic_t num_disconnect;
74729 - atomic_t num_remote_shutdown_ind;
74730 - atomic_t num_tx_flow_off_ind;
74731 - atomic_t num_tx_flow_on_ind;
74732 - atomic_t num_rx_flow_off;
74733 - atomic_t num_rx_flow_on;
74734 + atomic_unchecked_t caif_sock_create;
74735 + atomic_unchecked_t num_connect_req;
74736 + atomic_unchecked_t num_connect_resp;
74737 + atomic_unchecked_t num_connect_fail_resp;
74738 + atomic_unchecked_t num_disconnect;
74739 + atomic_unchecked_t num_remote_shutdown_ind;
74740 + atomic_unchecked_t num_tx_flow_off_ind;
74741 + atomic_unchecked_t num_tx_flow_on_ind;
74742 + atomic_unchecked_t num_rx_flow_off;
74743 + atomic_unchecked_t num_rx_flow_on;
74744 };
74745 static struct debug_fs_counter cnt;
74746 #define dbfs_atomic_inc(v) atomic_inc_return(v)
74747 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
74748 #define dbfs_atomic_dec(v) atomic_dec_return(v)
74749 #else
74750 #define dbfs_atomic_inc(v) 0
74751 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74752 atomic_read(&cf_sk->sk.sk_rmem_alloc),
74753 sk_rcvbuf_lowwater(cf_sk));
74754 set_rx_flow_off(cf_sk);
74755 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74756 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74757 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74758 }
74759
74760 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
74761 set_rx_flow_off(cf_sk);
74762 if (net_ratelimit())
74763 pr_debug("sending flow OFF due to rmem_schedule\n");
74764 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
74765 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
74766 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
74767 }
74768 skb->dev = NULL;
74769 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
74770 switch (flow) {
74771 case CAIF_CTRLCMD_FLOW_ON_IND:
74772 /* OK from modem to start sending again */
74773 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
74774 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
74775 set_tx_flow_on(cf_sk);
74776 cf_sk->sk.sk_state_change(&cf_sk->sk);
74777 break;
74778
74779 case CAIF_CTRLCMD_FLOW_OFF_IND:
74780 /* Modem asks us to shut up */
74781 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
74782 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
74783 set_tx_flow_off(cf_sk);
74784 cf_sk->sk.sk_state_change(&cf_sk->sk);
74785 break;
74786 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74787 /* We're now connected */
74788 caif_client_register_refcnt(&cf_sk->layer,
74789 cfsk_hold, cfsk_put);
74790 - dbfs_atomic_inc(&cnt.num_connect_resp);
74791 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
74792 cf_sk->sk.sk_state = CAIF_CONNECTED;
74793 set_tx_flow_on(cf_sk);
74794 cf_sk->sk.sk_state_change(&cf_sk->sk);
74795 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74796
74797 case CAIF_CTRLCMD_INIT_FAIL_RSP:
74798 /* Connect request failed */
74799 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
74800 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
74801 cf_sk->sk.sk_err = ECONNREFUSED;
74802 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
74803 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74804 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
74805
74806 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
74807 /* Modem has closed this connection, or device is down. */
74808 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
74809 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
74810 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
74811 cf_sk->sk.sk_err = ECONNRESET;
74812 set_rx_flow_on(cf_sk);
74813 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
74814 return;
74815
74816 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
74817 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
74818 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
74819 set_rx_flow_on(cf_sk);
74820 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
74821 }
74822 @@ -856,7 +857,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
74823 /*ifindex = id of the interface.*/
74824 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
74825
74826 - dbfs_atomic_inc(&cnt.num_connect_req);
74827 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
74828 cf_sk->layer.receive = caif_sktrecv_cb;
74829
74830 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
74831 @@ -945,7 +946,7 @@ static int caif_release(struct socket *sock)
74832 spin_unlock_bh(&sk->sk_receive_queue.lock);
74833 sock->sk = NULL;
74834
74835 - dbfs_atomic_inc(&cnt.num_disconnect);
74836 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
74837
74838 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
74839 if (cf_sk->debugfs_socket_dir != NULL)
74840 @@ -1124,7 +1125,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
74841 cf_sk->conn_req.protocol = protocol;
74842 /* Increase the number of sockets created. */
74843 dbfs_atomic_inc(&cnt.caif_nr_socks);
74844 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
74845 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
74846 #ifdef CONFIG_DEBUG_FS
74847 if (!IS_ERR(debugfsdir)) {
74848
74849 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
74850 index 5cf5222..6f704ad 100644
74851 --- a/net/caif/cfctrl.c
74852 +++ b/net/caif/cfctrl.c
74853 @@ -9,6 +9,7 @@
74854 #include <linux/stddef.h>
74855 #include <linux/spinlock.h>
74856 #include <linux/slab.h>
74857 +#include <linux/sched.h>
74858 #include <net/caif/caif_layer.h>
74859 #include <net/caif/cfpkt.h>
74860 #include <net/caif/cfctrl.h>
74861 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
74862 memset(&dev_info, 0, sizeof(dev_info));
74863 dev_info.id = 0xff;
74864 cfsrvl_init(&this->serv, 0, &dev_info, false);
74865 - atomic_set(&this->req_seq_no, 1);
74866 - atomic_set(&this->rsp_seq_no, 1);
74867 + atomic_set_unchecked(&this->req_seq_no, 1);
74868 + atomic_set_unchecked(&this->rsp_seq_no, 1);
74869 this->serv.layer.receive = cfctrl_recv;
74870 sprintf(this->serv.layer.name, "ctrl");
74871 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
74872 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
74873 struct cfctrl_request_info *req)
74874 {
74875 spin_lock_bh(&ctrl->info_list_lock);
74876 - atomic_inc(&ctrl->req_seq_no);
74877 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
74878 + atomic_inc_unchecked(&ctrl->req_seq_no);
74879 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
74880 list_add_tail(&req->list, &ctrl->list);
74881 spin_unlock_bh(&ctrl->info_list_lock);
74882 }
74883 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
74884 if (p != first)
74885 pr_warn("Requests are not received in order\n");
74886
74887 - atomic_set(&ctrl->rsp_seq_no,
74888 + atomic_set_unchecked(&ctrl->rsp_seq_no,
74889 p->sequence_no);
74890 list_del(&p->list);
74891 goto out;
74892 diff --git a/net/can/gw.c b/net/can/gw.c
74893 index 3d79b12..8de85fa 100644
74894 --- a/net/can/gw.c
74895 +++ b/net/can/gw.c
74896 @@ -96,7 +96,7 @@ struct cf_mod {
74897 struct {
74898 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
74899 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
74900 - } csumfunc;
74901 + } __no_const csumfunc;
74902 };
74903
74904
74905 diff --git a/net/compat.c b/net/compat.c
74906 index 6def90e..c6992fa 100644
74907 --- a/net/compat.c
74908 +++ b/net/compat.c
74909 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
74910 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
74911 __get_user(kmsg->msg_flags, &umsg->msg_flags))
74912 return -EFAULT;
74913 - kmsg->msg_name = compat_ptr(tmp1);
74914 - kmsg->msg_iov = compat_ptr(tmp2);
74915 - kmsg->msg_control = compat_ptr(tmp3);
74916 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
74917 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
74918 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
74919 return 0;
74920 }
74921
74922 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74923
74924 if (kern_msg->msg_namelen) {
74925 if (mode == VERIFY_READ) {
74926 - int err = move_addr_to_kernel(kern_msg->msg_name,
74927 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
74928 kern_msg->msg_namelen,
74929 kern_address);
74930 if (err < 0)
74931 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74932 kern_msg->msg_name = NULL;
74933
74934 tot_len = iov_from_user_compat_to_kern(kern_iov,
74935 - (struct compat_iovec __user *)kern_msg->msg_iov,
74936 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
74937 kern_msg->msg_iovlen);
74938 if (tot_len >= 0)
74939 kern_msg->msg_iov = kern_iov;
74940 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
74941
74942 #define CMSG_COMPAT_FIRSTHDR(msg) \
74943 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
74944 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
74945 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
74946 (struct compat_cmsghdr __user *)NULL)
74947
74948 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
74949 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
74950 (ucmlen) <= (unsigned long) \
74951 ((mhdr)->msg_controllen - \
74952 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
74953 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
74954
74955 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
74956 struct compat_cmsghdr __user *cmsg, int cmsg_len)
74957 {
74958 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
74959 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
74960 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
74961 msg->msg_controllen)
74962 return NULL;
74963 return (struct compat_cmsghdr __user *)ptr;
74964 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74965 {
74966 struct compat_timeval ctv;
74967 struct compat_timespec cts[3];
74968 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74969 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74970 struct compat_cmsghdr cmhdr;
74971 int cmlen;
74972
74973 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
74974
74975 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
74976 {
74977 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
74978 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
74979 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
74980 int fdnum = scm->fp->count;
74981 struct file **fp = scm->fp->fp;
74982 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
74983 return -EFAULT;
74984 old_fs = get_fs();
74985 set_fs(KERNEL_DS);
74986 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
74987 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
74988 set_fs(old_fs);
74989
74990 return err;
74991 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
74992 len = sizeof(ktime);
74993 old_fs = get_fs();
74994 set_fs(KERNEL_DS);
74995 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
74996 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
74997 set_fs(old_fs);
74998
74999 if (!err) {
75000 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75001 case MCAST_JOIN_GROUP:
75002 case MCAST_LEAVE_GROUP:
75003 {
75004 - struct compat_group_req __user *gr32 = (void *)optval;
75005 + struct compat_group_req __user *gr32 = (void __user *)optval;
75006 struct group_req __user *kgr =
75007 compat_alloc_user_space(sizeof(struct group_req));
75008 u32 interface;
75009 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75010 case MCAST_BLOCK_SOURCE:
75011 case MCAST_UNBLOCK_SOURCE:
75012 {
75013 - struct compat_group_source_req __user *gsr32 = (void *)optval;
75014 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
75015 struct group_source_req __user *kgsr = compat_alloc_user_space(
75016 sizeof(struct group_source_req));
75017 u32 interface;
75018 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
75019 }
75020 case MCAST_MSFILTER:
75021 {
75022 - struct compat_group_filter __user *gf32 = (void *)optval;
75023 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75024 struct group_filter __user *kgf;
75025 u32 interface, fmode, numsrc;
75026
75027 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
75028 char __user *optval, int __user *optlen,
75029 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
75030 {
75031 - struct compat_group_filter __user *gf32 = (void *)optval;
75032 + struct compat_group_filter __user *gf32 = (void __user *)optval;
75033 struct group_filter __user *kgf;
75034 int __user *koptlen;
75035 u32 interface, fmode, numsrc;
75036 diff --git a/net/core/datagram.c b/net/core/datagram.c
75037 index 68bbf9f..5ef0d12 100644
75038 --- a/net/core/datagram.c
75039 +++ b/net/core/datagram.c
75040 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
75041 }
75042
75043 kfree_skb(skb);
75044 - atomic_inc(&sk->sk_drops);
75045 + atomic_inc_unchecked(&sk->sk_drops);
75046 sk_mem_reclaim_partial(sk);
75047
75048 return err;
75049 diff --git a/net/core/dev.c b/net/core/dev.c
75050 index 0336374..659088a 100644
75051 --- a/net/core/dev.c
75052 +++ b/net/core/dev.c
75053 @@ -1138,10 +1138,14 @@ void dev_load(struct net *net, const char *name)
75054 if (no_module && capable(CAP_NET_ADMIN))
75055 no_module = request_module("netdev-%s", name);
75056 if (no_module && capable(CAP_SYS_MODULE)) {
75057 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75058 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
75059 +#else
75060 if (!request_module("%s", name))
75061 pr_err("Loading kernel module for a network device "
75062 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
75063 "instead\n", name);
75064 +#endif
75065 }
75066 }
75067 EXPORT_SYMBOL(dev_load);
75068 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75069 {
75070 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
75071 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
75072 - atomic_long_inc(&dev->rx_dropped);
75073 + atomic_long_inc_unchecked(&dev->rx_dropped);
75074 kfree_skb(skb);
75075 return NET_RX_DROP;
75076 }
75077 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
75078 nf_reset(skb);
75079
75080 if (unlikely(!is_skb_forwardable(dev, skb))) {
75081 - atomic_long_inc(&dev->rx_dropped);
75082 + atomic_long_inc_unchecked(&dev->rx_dropped);
75083 kfree_skb(skb);
75084 return NET_RX_DROP;
75085 }
75086 @@ -2077,7 +2081,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
75087
75088 struct dev_gso_cb {
75089 void (*destructor)(struct sk_buff *skb);
75090 -};
75091 +} __no_const;
75092
75093 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
75094
75095 @@ -2933,7 +2937,7 @@ enqueue:
75096
75097 local_irq_restore(flags);
75098
75099 - atomic_long_inc(&skb->dev->rx_dropped);
75100 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75101 kfree_skb(skb);
75102 return NET_RX_DROP;
75103 }
75104 @@ -3005,7 +3009,7 @@ int netif_rx_ni(struct sk_buff *skb)
75105 }
75106 EXPORT_SYMBOL(netif_rx_ni);
75107
75108 -static void net_tx_action(struct softirq_action *h)
75109 +static void net_tx_action(void)
75110 {
75111 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75112
75113 @@ -3293,7 +3297,7 @@ ncls:
75114 if (pt_prev) {
75115 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
75116 } else {
75117 - atomic_long_inc(&skb->dev->rx_dropped);
75118 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
75119 kfree_skb(skb);
75120 /* Jamal, now you will not able to escape explaining
75121 * me how you were going to use this. :-)
75122 @@ -3853,7 +3857,7 @@ void netif_napi_del(struct napi_struct *napi)
75123 }
75124 EXPORT_SYMBOL(netif_napi_del);
75125
75126 -static void net_rx_action(struct softirq_action *h)
75127 +static void net_rx_action(void)
75128 {
75129 struct softnet_data *sd = &__get_cpu_var(softnet_data);
75130 unsigned long time_limit = jiffies + 2;
75131 @@ -5878,7 +5882,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
75132 } else {
75133 netdev_stats_to_stats64(storage, &dev->stats);
75134 }
75135 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
75136 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
75137 return storage;
75138 }
75139 EXPORT_SYMBOL(dev_get_stats);
75140 diff --git a/net/core/flow.c b/net/core/flow.c
75141 index e318c7e..168b1d0 100644
75142 --- a/net/core/flow.c
75143 +++ b/net/core/flow.c
75144 @@ -61,7 +61,7 @@ struct flow_cache {
75145 struct timer_list rnd_timer;
75146 };
75147
75148 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
75149 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
75150 EXPORT_SYMBOL(flow_cache_genid);
75151 static struct flow_cache flow_cache_global;
75152 static struct kmem_cache *flow_cachep __read_mostly;
75153 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
75154
75155 static int flow_entry_valid(struct flow_cache_entry *fle)
75156 {
75157 - if (atomic_read(&flow_cache_genid) != fle->genid)
75158 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
75159 return 0;
75160 if (fle->object && !fle->object->ops->check(fle->object))
75161 return 0;
75162 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
75163 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
75164 fcp->hash_count++;
75165 }
75166 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
75167 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
75168 flo = fle->object;
75169 if (!flo)
75170 goto ret_object;
75171 @@ -280,7 +280,7 @@ nocache:
75172 }
75173 flo = resolver(net, key, family, dir, flo, ctx);
75174 if (fle) {
75175 - fle->genid = atomic_read(&flow_cache_genid);
75176 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
75177 if (!IS_ERR(flo))
75178 fle->object = flo;
75179 else
75180 diff --git a/net/core/iovec.c b/net/core/iovec.c
75181 index c40f27e..7f49254 100644
75182 --- a/net/core/iovec.c
75183 +++ b/net/core/iovec.c
75184 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75185 if (m->msg_namelen) {
75186 if (mode == VERIFY_READ) {
75187 void __user *namep;
75188 - namep = (void __user __force *) m->msg_name;
75189 + namep = (void __force_user *) m->msg_name;
75190 err = move_addr_to_kernel(namep, m->msg_namelen,
75191 address);
75192 if (err < 0)
75193 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
75194 }
75195
75196 size = m->msg_iovlen * sizeof(struct iovec);
75197 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
75198 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
75199 return -EFAULT;
75200
75201 m->msg_iov = iov;
75202 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
75203 index 5c30296..ebe7b61 100644
75204 --- a/net/core/rtnetlink.c
75205 +++ b/net/core/rtnetlink.c
75206 @@ -57,7 +57,7 @@ struct rtnl_link {
75207 rtnl_doit_func doit;
75208 rtnl_dumpit_func dumpit;
75209 rtnl_calcit_func calcit;
75210 -};
75211 +} __no_const;
75212
75213 static DEFINE_MUTEX(rtnl_mutex);
75214
75215 diff --git a/net/core/scm.c b/net/core/scm.c
75216 index ff52ad0..aff1c0f 100644
75217 --- a/net/core/scm.c
75218 +++ b/net/core/scm.c
75219 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
75220 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75221 {
75222 struct cmsghdr __user *cm
75223 - = (__force struct cmsghdr __user *)msg->msg_control;
75224 + = (struct cmsghdr __force_user *)msg->msg_control;
75225 struct cmsghdr cmhdr;
75226 int cmlen = CMSG_LEN(len);
75227 int err;
75228 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
75229 err = -EFAULT;
75230 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
75231 goto out;
75232 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
75233 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
75234 goto out;
75235 cmlen = CMSG_SPACE(len);
75236 if (msg->msg_controllen < cmlen)
75237 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
75238 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75239 {
75240 struct cmsghdr __user *cm
75241 - = (__force struct cmsghdr __user*)msg->msg_control;
75242 + = (struct cmsghdr __force_user *)msg->msg_control;
75243
75244 int fdmax = 0;
75245 int fdnum = scm->fp->count;
75246 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
75247 if (fdnum < fdmax)
75248 fdmax = fdnum;
75249
75250 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
75251 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
75252 i++, cmfptr++)
75253 {
75254 int new_fd;
75255 diff --git a/net/core/sock.c b/net/core/sock.c
75256 index 02f8dfe..86dfd4a 100644
75257 --- a/net/core/sock.c
75258 +++ b/net/core/sock.c
75259 @@ -341,7 +341,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75260 struct sk_buff_head *list = &sk->sk_receive_queue;
75261
75262 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
75263 - atomic_inc(&sk->sk_drops);
75264 + atomic_inc_unchecked(&sk->sk_drops);
75265 trace_sock_rcvqueue_full(sk, skb);
75266 return -ENOMEM;
75267 }
75268 @@ -351,7 +351,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75269 return err;
75270
75271 if (!sk_rmem_schedule(sk, skb->truesize)) {
75272 - atomic_inc(&sk->sk_drops);
75273 + atomic_inc_unchecked(&sk->sk_drops);
75274 return -ENOBUFS;
75275 }
75276
75277 @@ -371,7 +371,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75278 skb_dst_force(skb);
75279
75280 spin_lock_irqsave(&list->lock, flags);
75281 - skb->dropcount = atomic_read(&sk->sk_drops);
75282 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
75283 __skb_queue_tail(list, skb);
75284 spin_unlock_irqrestore(&list->lock, flags);
75285
75286 @@ -391,7 +391,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75287 skb->dev = NULL;
75288
75289 if (sk_rcvqueues_full(sk, skb)) {
75290 - atomic_inc(&sk->sk_drops);
75291 + atomic_inc_unchecked(&sk->sk_drops);
75292 goto discard_and_relse;
75293 }
75294 if (nested)
75295 @@ -409,7 +409,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
75296 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
75297 } else if (sk_add_backlog(sk, skb)) {
75298 bh_unlock_sock(sk);
75299 - atomic_inc(&sk->sk_drops);
75300 + atomic_inc_unchecked(&sk->sk_drops);
75301 goto discard_and_relse;
75302 }
75303
75304 @@ -974,7 +974,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75305 if (len > sizeof(peercred))
75306 len = sizeof(peercred);
75307 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
75308 - if (copy_to_user(optval, &peercred, len))
75309 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
75310 return -EFAULT;
75311 goto lenout;
75312 }
75313 @@ -987,7 +987,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75314 return -ENOTCONN;
75315 if (lv < len)
75316 return -EINVAL;
75317 - if (copy_to_user(optval, address, len))
75318 + if (len > sizeof(address) || copy_to_user(optval, address, len))
75319 return -EFAULT;
75320 goto lenout;
75321 }
75322 @@ -1024,7 +1024,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
75323
75324 if (len > lv)
75325 len = lv;
75326 - if (copy_to_user(optval, &v, len))
75327 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
75328 return -EFAULT;
75329 lenout:
75330 if (put_user(len, optlen))
75331 @@ -2108,7 +2108,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
75332 */
75333 smp_wmb();
75334 atomic_set(&sk->sk_refcnt, 1);
75335 - atomic_set(&sk->sk_drops, 0);
75336 + atomic_set_unchecked(&sk->sk_drops, 0);
75337 }
75338 EXPORT_SYMBOL(sock_init_data);
75339
75340 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
75341 index b9868e1..849f809 100644
75342 --- a/net/core/sock_diag.c
75343 +++ b/net/core/sock_diag.c
75344 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
75345
75346 int sock_diag_check_cookie(void *sk, __u32 *cookie)
75347 {
75348 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75349 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
75350 cookie[1] != INET_DIAG_NOCOOKIE) &&
75351 ((u32)(unsigned long)sk != cookie[0] ||
75352 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
75353 return -ESTALE;
75354 else
75355 +#endif
75356 return 0;
75357 }
75358 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
75359
75360 void sock_diag_save_cookie(void *sk, __u32 *cookie)
75361 {
75362 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75363 + cookie[0] = 0;
75364 + cookie[1] = 0;
75365 +#else
75366 cookie[0] = (u32)(unsigned long)sk;
75367 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
75368 +#endif
75369 }
75370 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
75371
75372 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
75373 index 02e75d1..9a57a7c 100644
75374 --- a/net/decnet/sysctl_net_decnet.c
75375 +++ b/net/decnet/sysctl_net_decnet.c
75376 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
75377
75378 if (len > *lenp) len = *lenp;
75379
75380 - if (copy_to_user(buffer, addr, len))
75381 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
75382 return -EFAULT;
75383
75384 *lenp = len;
75385 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
75386
75387 if (len > *lenp) len = *lenp;
75388
75389 - if (copy_to_user(buffer, devname, len))
75390 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
75391 return -EFAULT;
75392
75393 *lenp = len;
75394 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
75395 index 39a2d29..f39c0fe 100644
75396 --- a/net/econet/Kconfig
75397 +++ b/net/econet/Kconfig
75398 @@ -4,7 +4,7 @@
75399
75400 config ECONET
75401 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
75402 - depends on EXPERIMENTAL && INET
75403 + depends on EXPERIMENTAL && INET && BROKEN
75404 ---help---
75405 Econet is a fairly old and slow networking protocol mainly used by
75406 Acorn computers to access file and print servers. It uses native
75407 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
75408 index 92fc5f6..b790d91 100644
75409 --- a/net/ipv4/fib_frontend.c
75410 +++ b/net/ipv4/fib_frontend.c
75411 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
75412 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75413 fib_sync_up(dev);
75414 #endif
75415 - atomic_inc(&net->ipv4.dev_addr_genid);
75416 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75417 rt_cache_flush(dev_net(dev), -1);
75418 break;
75419 case NETDEV_DOWN:
75420 fib_del_ifaddr(ifa, NULL);
75421 - atomic_inc(&net->ipv4.dev_addr_genid);
75422 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75423 if (ifa->ifa_dev->ifa_list == NULL) {
75424 /* Last address was deleted from this interface.
75425 * Disable IP.
75426 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
75427 #ifdef CONFIG_IP_ROUTE_MULTIPATH
75428 fib_sync_up(dev);
75429 #endif
75430 - atomic_inc(&net->ipv4.dev_addr_genid);
75431 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
75432 rt_cache_flush(dev_net(dev), -1);
75433 break;
75434 case NETDEV_DOWN:
75435 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
75436 index 80106d8..232e898 100644
75437 --- a/net/ipv4/fib_semantics.c
75438 +++ b/net/ipv4/fib_semantics.c
75439 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
75440 nh->nh_saddr = inet_select_addr(nh->nh_dev,
75441 nh->nh_gw,
75442 nh->nh_parent->fib_scope);
75443 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
75444 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
75445
75446 return nh->nh_saddr;
75447 }
75448 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
75449 index 984ec65..97ac518 100644
75450 --- a/net/ipv4/inet_hashtables.c
75451 +++ b/net/ipv4/inet_hashtables.c
75452 @@ -18,12 +18,15 @@
75453 #include <linux/sched.h>
75454 #include <linux/slab.h>
75455 #include <linux/wait.h>
75456 +#include <linux/security.h>
75457
75458 #include <net/inet_connection_sock.h>
75459 #include <net/inet_hashtables.h>
75460 #include <net/secure_seq.h>
75461 #include <net/ip.h>
75462
75463 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
75464 +
75465 /*
75466 * Allocate and initialize a new local port bind bucket.
75467 * The bindhash mutex for snum's hash chain must be held here.
75468 @@ -530,6 +533,8 @@ ok:
75469 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
75470 spin_unlock(&head->lock);
75471
75472 + gr_update_task_in_ip_table(current, inet_sk(sk));
75473 +
75474 if (tw) {
75475 inet_twsk_deschedule(tw, death_row);
75476 while (twrefcnt) {
75477 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
75478 index d4d61b6..b81aec8 100644
75479 --- a/net/ipv4/inetpeer.c
75480 +++ b/net/ipv4/inetpeer.c
75481 @@ -487,8 +487,8 @@ relookup:
75482 if (p) {
75483 p->daddr = *daddr;
75484 atomic_set(&p->refcnt, 1);
75485 - atomic_set(&p->rid, 0);
75486 - atomic_set(&p->ip_id_count,
75487 + atomic_set_unchecked(&p->rid, 0);
75488 + atomic_set_unchecked(&p->ip_id_count,
75489 (daddr->family == AF_INET) ?
75490 secure_ip_id(daddr->addr.a4) :
75491 secure_ipv6_id(daddr->addr.a6));
75492 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
75493 index 1f23a57..7180dfe 100644
75494 --- a/net/ipv4/ip_fragment.c
75495 +++ b/net/ipv4/ip_fragment.c
75496 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
75497 return 0;
75498
75499 start = qp->rid;
75500 - end = atomic_inc_return(&peer->rid);
75501 + end = atomic_inc_return_unchecked(&peer->rid);
75502 qp->rid = end;
75503
75504 rc = qp->q.fragments && (end - start) > max;
75505 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
75506 index 8aa87c1..35c3248 100644
75507 --- a/net/ipv4/ip_sockglue.c
75508 +++ b/net/ipv4/ip_sockglue.c
75509 @@ -1112,7 +1112,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75510 len = min_t(unsigned int, len, opt->optlen);
75511 if (put_user(len, optlen))
75512 return -EFAULT;
75513 - if (copy_to_user(optval, opt->__data, len))
75514 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
75515 + copy_to_user(optval, opt->__data, len))
75516 return -EFAULT;
75517 return 0;
75518 }
75519 @@ -1240,7 +1241,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
75520 if (sk->sk_type != SOCK_STREAM)
75521 return -ENOPROTOOPT;
75522
75523 - msg.msg_control = optval;
75524 + msg.msg_control = (void __force_kernel *)optval;
75525 msg.msg_controllen = len;
75526 msg.msg_flags = flags;
75527
75528 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
75529 index 6e412a6..6640538 100644
75530 --- a/net/ipv4/ipconfig.c
75531 +++ b/net/ipv4/ipconfig.c
75532 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
75533
75534 mm_segment_t oldfs = get_fs();
75535 set_fs(get_ds());
75536 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75537 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75538 set_fs(oldfs);
75539 return res;
75540 }
75541 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
75542
75543 mm_segment_t oldfs = get_fs();
75544 set_fs(get_ds());
75545 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
75546 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
75547 set_fs(oldfs);
75548 return res;
75549 }
75550 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
75551
75552 mm_segment_t oldfs = get_fs();
75553 set_fs(get_ds());
75554 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
75555 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
75556 set_fs(oldfs);
75557 return res;
75558 }
75559 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
75560 index b072386..abdebcf 100644
75561 --- a/net/ipv4/ping.c
75562 +++ b/net/ipv4/ping.c
75563 @@ -838,7 +838,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
75564 sk_rmem_alloc_get(sp),
75565 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75566 atomic_read(&sp->sk_refcnt), sp,
75567 - atomic_read(&sp->sk_drops), len);
75568 + atomic_read_unchecked(&sp->sk_drops), len);
75569 }
75570
75571 static int ping_seq_show(struct seq_file *seq, void *v)
75572 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
75573 index 3ccda5a..3c1e61d 100644
75574 --- a/net/ipv4/raw.c
75575 +++ b/net/ipv4/raw.c
75576 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
75577 int raw_rcv(struct sock *sk, struct sk_buff *skb)
75578 {
75579 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
75580 - atomic_inc(&sk->sk_drops);
75581 + atomic_inc_unchecked(&sk->sk_drops);
75582 kfree_skb(skb);
75583 return NET_RX_DROP;
75584 }
75585 @@ -742,16 +742,20 @@ static int raw_init(struct sock *sk)
75586
75587 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
75588 {
75589 + struct icmp_filter filter;
75590 +
75591 if (optlen > sizeof(struct icmp_filter))
75592 optlen = sizeof(struct icmp_filter);
75593 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
75594 + if (copy_from_user(&filter, optval, optlen))
75595 return -EFAULT;
75596 + raw_sk(sk)->filter = filter;
75597 return 0;
75598 }
75599
75600 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
75601 {
75602 int len, ret = -EFAULT;
75603 + struct icmp_filter filter;
75604
75605 if (get_user(len, optlen))
75606 goto out;
75607 @@ -761,8 +765,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
75608 if (len > sizeof(struct icmp_filter))
75609 len = sizeof(struct icmp_filter);
75610 ret = -EFAULT;
75611 - if (put_user(len, optlen) ||
75612 - copy_to_user(optval, &raw_sk(sk)->filter, len))
75613 + filter = raw_sk(sk)->filter;
75614 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
75615 goto out;
75616 ret = 0;
75617 out: return ret;
75618 @@ -990,7 +994,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
75619 sk_wmem_alloc_get(sp),
75620 sk_rmem_alloc_get(sp),
75621 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75622 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
75623 + atomic_read(&sp->sk_refcnt),
75624 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75625 + NULL,
75626 +#else
75627 + sp,
75628 +#endif
75629 + atomic_read_unchecked(&sp->sk_drops));
75630 }
75631
75632 static int raw_seq_show(struct seq_file *seq, void *v)
75633 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
75634 index 0197747..7adb0dc 100644
75635 --- a/net/ipv4/route.c
75636 +++ b/net/ipv4/route.c
75637 @@ -311,7 +311,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
75638
75639 static inline int rt_genid(struct net *net)
75640 {
75641 - return atomic_read(&net->ipv4.rt_genid);
75642 + return atomic_read_unchecked(&net->ipv4.rt_genid);
75643 }
75644
75645 #ifdef CONFIG_PROC_FS
75646 @@ -935,7 +935,7 @@ static void rt_cache_invalidate(struct net *net)
75647 unsigned char shuffle;
75648
75649 get_random_bytes(&shuffle, sizeof(shuffle));
75650 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
75651 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
75652 inetpeer_invalidate_tree(AF_INET);
75653 }
75654
75655 @@ -3010,7 +3010,7 @@ static int rt_fill_info(struct net *net,
75656 error = rt->dst.error;
75657 if (peer) {
75658 inet_peer_refcheck(rt->peer);
75659 - id = atomic_read(&peer->ip_id_count) & 0xffff;
75660 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
75661 if (peer->tcp_ts_stamp) {
75662 ts = peer->tcp_ts;
75663 tsage = get_seconds() - peer->tcp_ts_stamp;
75664 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
75665 index fd54c5f..96d6407 100644
75666 --- a/net/ipv4/tcp_ipv4.c
75667 +++ b/net/ipv4/tcp_ipv4.c
75668 @@ -88,6 +88,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
75669 int sysctl_tcp_low_latency __read_mostly;
75670 EXPORT_SYMBOL(sysctl_tcp_low_latency);
75671
75672 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75673 +extern int grsec_enable_blackhole;
75674 +#endif
75675
75676 #ifdef CONFIG_TCP_MD5SIG
75677 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
75678 @@ -1638,6 +1641,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
75679 return 0;
75680
75681 reset:
75682 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75683 + if (!grsec_enable_blackhole)
75684 +#endif
75685 tcp_v4_send_reset(rsk, skb);
75686 discard:
75687 kfree_skb(skb);
75688 @@ -1700,12 +1706,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
75689 TCP_SKB_CB(skb)->sacked = 0;
75690
75691 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
75692 - if (!sk)
75693 + if (!sk) {
75694 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75695 + ret = 1;
75696 +#endif
75697 goto no_tcp_socket;
75698 -
75699 + }
75700 process:
75701 - if (sk->sk_state == TCP_TIME_WAIT)
75702 + if (sk->sk_state == TCP_TIME_WAIT) {
75703 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75704 + ret = 2;
75705 +#endif
75706 goto do_time_wait;
75707 + }
75708
75709 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
75710 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
75711 @@ -1755,6 +1768,10 @@ no_tcp_socket:
75712 bad_packet:
75713 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
75714 } else {
75715 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75716 + if (!grsec_enable_blackhole || (ret == 1 &&
75717 + (skb->dev->flags & IFF_LOOPBACK)))
75718 +#endif
75719 tcp_v4_send_reset(NULL, skb);
75720 }
75721
75722 @@ -2417,7 +2434,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
75723 0, /* non standard timer */
75724 0, /* open_requests have no inode */
75725 atomic_read(&sk->sk_refcnt),
75726 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75727 + NULL,
75728 +#else
75729 req,
75730 +#endif
75731 len);
75732 }
75733
75734 @@ -2467,7 +2488,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
75735 sock_i_uid(sk),
75736 icsk->icsk_probes_out,
75737 sock_i_ino(sk),
75738 - atomic_read(&sk->sk_refcnt), sk,
75739 + atomic_read(&sk->sk_refcnt),
75740 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75741 + NULL,
75742 +#else
75743 + sk,
75744 +#endif
75745 jiffies_to_clock_t(icsk->icsk_rto),
75746 jiffies_to_clock_t(icsk->icsk_ack.ato),
75747 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
75748 @@ -2495,7 +2521,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
75749 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
75750 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
75751 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
75752 - atomic_read(&tw->tw_refcnt), tw, len);
75753 + atomic_read(&tw->tw_refcnt),
75754 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75755 + NULL,
75756 +#else
75757 + tw,
75758 +#endif
75759 + len);
75760 }
75761
75762 #define TMPSZ 150
75763 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
75764 index 550e755..25721b3 100644
75765 --- a/net/ipv4/tcp_minisocks.c
75766 +++ b/net/ipv4/tcp_minisocks.c
75767 @@ -27,6 +27,10 @@
75768 #include <net/inet_common.h>
75769 #include <net/xfrm.h>
75770
75771 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75772 +extern int grsec_enable_blackhole;
75773 +#endif
75774 +
75775 int sysctl_tcp_syncookies __read_mostly = 1;
75776 EXPORT_SYMBOL(sysctl_tcp_syncookies);
75777
75778 @@ -753,6 +757,10 @@ listen_overflow:
75779
75780 embryonic_reset:
75781 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
75782 +
75783 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75784 + if (!grsec_enable_blackhole)
75785 +#endif
75786 if (!(flg & TCP_FLAG_RST))
75787 req->rsk_ops->send_reset(sk, skb);
75788
75789 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
75790 index 85ee7eb..53277ab 100644
75791 --- a/net/ipv4/tcp_probe.c
75792 +++ b/net/ipv4/tcp_probe.c
75793 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
75794 if (cnt + width >= len)
75795 break;
75796
75797 - if (copy_to_user(buf + cnt, tbuf, width))
75798 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
75799 return -EFAULT;
75800 cnt += width;
75801 }
75802 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
75803 index cd2e072..1fffee2 100644
75804 --- a/net/ipv4/tcp_timer.c
75805 +++ b/net/ipv4/tcp_timer.c
75806 @@ -22,6 +22,10 @@
75807 #include <linux/gfp.h>
75808 #include <net/tcp.h>
75809
75810 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75811 +extern int grsec_lastack_retries;
75812 +#endif
75813 +
75814 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
75815 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
75816 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
75817 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
75818 }
75819 }
75820
75821 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75822 + if ((sk->sk_state == TCP_LAST_ACK) &&
75823 + (grsec_lastack_retries > 0) &&
75824 + (grsec_lastack_retries < retry_until))
75825 + retry_until = grsec_lastack_retries;
75826 +#endif
75827 +
75828 if (retransmits_timed_out(sk, retry_until,
75829 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
75830 /* Has it gone just too far? */
75831 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
75832 index 5d075b5..d907d5f 100644
75833 --- a/net/ipv4/udp.c
75834 +++ b/net/ipv4/udp.c
75835 @@ -86,6 +86,7 @@
75836 #include <linux/types.h>
75837 #include <linux/fcntl.h>
75838 #include <linux/module.h>
75839 +#include <linux/security.h>
75840 #include <linux/socket.h>
75841 #include <linux/sockios.h>
75842 #include <linux/igmp.h>
75843 @@ -108,6 +109,10 @@
75844 #include <trace/events/udp.h>
75845 #include "udp_impl.h"
75846
75847 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75848 +extern int grsec_enable_blackhole;
75849 +#endif
75850 +
75851 struct udp_table udp_table __read_mostly;
75852 EXPORT_SYMBOL(udp_table);
75853
75854 @@ -566,6 +571,9 @@ found:
75855 return s;
75856 }
75857
75858 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
75859 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
75860 +
75861 /*
75862 * This routine is called by the ICMP module when it gets some
75863 * sort of error condition. If err < 0 then the socket should
75864 @@ -857,9 +865,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
75865 dport = usin->sin_port;
75866 if (dport == 0)
75867 return -EINVAL;
75868 +
75869 + err = gr_search_udp_sendmsg(sk, usin);
75870 + if (err)
75871 + return err;
75872 } else {
75873 if (sk->sk_state != TCP_ESTABLISHED)
75874 return -EDESTADDRREQ;
75875 +
75876 + err = gr_search_udp_sendmsg(sk, NULL);
75877 + if (err)
75878 + return err;
75879 +
75880 daddr = inet->inet_daddr;
75881 dport = inet->inet_dport;
75882 /* Open fast path for connected socket.
75883 @@ -1100,7 +1117,7 @@ static unsigned int first_packet_length(struct sock *sk)
75884 udp_lib_checksum_complete(skb)) {
75885 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75886 IS_UDPLITE(sk));
75887 - atomic_inc(&sk->sk_drops);
75888 + atomic_inc_unchecked(&sk->sk_drops);
75889 __skb_unlink(skb, rcvq);
75890 __skb_queue_tail(&list_kill, skb);
75891 }
75892 @@ -1186,6 +1203,10 @@ try_again:
75893 if (!skb)
75894 goto out;
75895
75896 + err = gr_search_udp_recvmsg(sk, skb);
75897 + if (err)
75898 + goto out_free;
75899 +
75900 ulen = skb->len - sizeof(struct udphdr);
75901 copied = len;
75902 if (copied > ulen)
75903 @@ -1489,7 +1510,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
75904
75905 drop:
75906 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
75907 - atomic_inc(&sk->sk_drops);
75908 + atomic_inc_unchecked(&sk->sk_drops);
75909 kfree_skb(skb);
75910 return -1;
75911 }
75912 @@ -1508,7 +1529,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
75913 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
75914
75915 if (!skb1) {
75916 - atomic_inc(&sk->sk_drops);
75917 + atomic_inc_unchecked(&sk->sk_drops);
75918 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
75919 IS_UDPLITE(sk));
75920 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
75921 @@ -1677,6 +1698,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
75922 goto csum_error;
75923
75924 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
75925 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75926 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
75927 +#endif
75928 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
75929
75930 /*
75931 @@ -2100,8 +2124,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
75932 sk_wmem_alloc_get(sp),
75933 sk_rmem_alloc_get(sp),
75934 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
75935 - atomic_read(&sp->sk_refcnt), sp,
75936 - atomic_read(&sp->sk_drops), len);
75937 + atomic_read(&sp->sk_refcnt),
75938 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75939 + NULL,
75940 +#else
75941 + sp,
75942 +#endif
75943 + atomic_read_unchecked(&sp->sk_drops), len);
75944 }
75945
75946 int udp4_seq_show(struct seq_file *seq, void *v)
75947 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
75948 index 6b8ebc5..1d624f4 100644
75949 --- a/net/ipv6/addrconf.c
75950 +++ b/net/ipv6/addrconf.c
75951 @@ -2145,7 +2145,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
75952 p.iph.ihl = 5;
75953 p.iph.protocol = IPPROTO_IPV6;
75954 p.iph.ttl = 64;
75955 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
75956 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
75957
75958 if (ops->ndo_do_ioctl) {
75959 mm_segment_t oldfs = get_fs();
75960 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
75961 index 02dd203..e03fcc9 100644
75962 --- a/net/ipv6/inet6_connection_sock.c
75963 +++ b/net/ipv6/inet6_connection_sock.c
75964 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
75965 #ifdef CONFIG_XFRM
75966 {
75967 struct rt6_info *rt = (struct rt6_info *)dst;
75968 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
75969 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
75970 }
75971 #endif
75972 }
75973 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
75974 #ifdef CONFIG_XFRM
75975 if (dst) {
75976 struct rt6_info *rt = (struct rt6_info *)dst;
75977 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
75978 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
75979 __sk_dst_reset(sk);
75980 dst = NULL;
75981 }
75982 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
75983 index 18a2719..779f36a 100644
75984 --- a/net/ipv6/ipv6_sockglue.c
75985 +++ b/net/ipv6/ipv6_sockglue.c
75986 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
75987 if (sk->sk_type != SOCK_STREAM)
75988 return -ENOPROTOOPT;
75989
75990 - msg.msg_control = optval;
75991 + msg.msg_control = (void __force_kernel *)optval;
75992 msg.msg_controllen = len;
75993 msg.msg_flags = flags;
75994
75995 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
75996 index d02f7e4..2d2a0f1 100644
75997 --- a/net/ipv6/raw.c
75998 +++ b/net/ipv6/raw.c
75999 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
76000 {
76001 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
76002 skb_checksum_complete(skb)) {
76003 - atomic_inc(&sk->sk_drops);
76004 + atomic_inc_unchecked(&sk->sk_drops);
76005 kfree_skb(skb);
76006 return NET_RX_DROP;
76007 }
76008 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76009 struct raw6_sock *rp = raw6_sk(sk);
76010
76011 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
76012 - atomic_inc(&sk->sk_drops);
76013 + atomic_inc_unchecked(&sk->sk_drops);
76014 kfree_skb(skb);
76015 return NET_RX_DROP;
76016 }
76017 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
76018
76019 if (inet->hdrincl) {
76020 if (skb_checksum_complete(skb)) {
76021 - atomic_inc(&sk->sk_drops);
76022 + atomic_inc_unchecked(&sk->sk_drops);
76023 kfree_skb(skb);
76024 return NET_RX_DROP;
76025 }
76026 @@ -602,7 +602,7 @@ out:
76027 return err;
76028 }
76029
76030 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
76031 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
76032 struct flowi6 *fl6, struct dst_entry **dstp,
76033 unsigned int flags)
76034 {
76035 @@ -912,12 +912,15 @@ do_confirm:
76036 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
76037 char __user *optval, int optlen)
76038 {
76039 + struct icmp6_filter filter;
76040 +
76041 switch (optname) {
76042 case ICMPV6_FILTER:
76043 if (optlen > sizeof(struct icmp6_filter))
76044 optlen = sizeof(struct icmp6_filter);
76045 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
76046 + if (copy_from_user(&filter, optval, optlen))
76047 return -EFAULT;
76048 + raw6_sk(sk)->filter = filter;
76049 return 0;
76050 default:
76051 return -ENOPROTOOPT;
76052 @@ -930,6 +933,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76053 char __user *optval, int __user *optlen)
76054 {
76055 int len;
76056 + struct icmp6_filter filter;
76057
76058 switch (optname) {
76059 case ICMPV6_FILTER:
76060 @@ -941,7 +945,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
76061 len = sizeof(struct icmp6_filter);
76062 if (put_user(len, optlen))
76063 return -EFAULT;
76064 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
76065 + filter = raw6_sk(sk)->filter;
76066 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
76067 return -EFAULT;
76068 return 0;
76069 default:
76070 @@ -1248,7 +1253,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
76071 0, 0L, 0,
76072 sock_i_uid(sp), 0,
76073 sock_i_ino(sp),
76074 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
76075 + atomic_read(&sp->sk_refcnt),
76076 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76077 + NULL,
76078 +#else
76079 + sp,
76080 +#endif
76081 + atomic_read_unchecked(&sp->sk_drops));
76082 }
76083
76084 static int raw6_seq_show(struct seq_file *seq, void *v)
76085 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
76086 index a89ca8d..12e66b0 100644
76087 --- a/net/ipv6/tcp_ipv6.c
76088 +++ b/net/ipv6/tcp_ipv6.c
76089 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
76090 }
76091 #endif
76092
76093 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76094 +extern int grsec_enable_blackhole;
76095 +#endif
76096 +
76097 static void tcp_v6_hash(struct sock *sk)
76098 {
76099 if (sk->sk_state != TCP_CLOSE) {
76100 @@ -1654,6 +1658,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
76101 return 0;
76102
76103 reset:
76104 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76105 + if (!grsec_enable_blackhole)
76106 +#endif
76107 tcp_v6_send_reset(sk, skb);
76108 discard:
76109 if (opt_skb)
76110 @@ -1733,12 +1740,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
76111 TCP_SKB_CB(skb)->sacked = 0;
76112
76113 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
76114 - if (!sk)
76115 + if (!sk) {
76116 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76117 + ret = 1;
76118 +#endif
76119 goto no_tcp_socket;
76120 + }
76121
76122 process:
76123 - if (sk->sk_state == TCP_TIME_WAIT)
76124 + if (sk->sk_state == TCP_TIME_WAIT) {
76125 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76126 + ret = 2;
76127 +#endif
76128 goto do_time_wait;
76129 + }
76130
76131 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
76132 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
76133 @@ -1786,6 +1801,10 @@ no_tcp_socket:
76134 bad_packet:
76135 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
76136 } else {
76137 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76138 + if (!grsec_enable_blackhole || (ret == 1 &&
76139 + (skb->dev->flags & IFF_LOOPBACK)))
76140 +#endif
76141 tcp_v6_send_reset(NULL, skb);
76142 }
76143
76144 @@ -2047,7 +2066,13 @@ static void get_openreq6(struct seq_file *seq,
76145 uid,
76146 0, /* non standard timer */
76147 0, /* open_requests have no inode */
76148 - 0, req);
76149 + 0,
76150 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76151 + NULL
76152 +#else
76153 + req
76154 +#endif
76155 + );
76156 }
76157
76158 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76159 @@ -2097,7 +2122,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
76160 sock_i_uid(sp),
76161 icsk->icsk_probes_out,
76162 sock_i_ino(sp),
76163 - atomic_read(&sp->sk_refcnt), sp,
76164 + atomic_read(&sp->sk_refcnt),
76165 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76166 + NULL,
76167 +#else
76168 + sp,
76169 +#endif
76170 jiffies_to_clock_t(icsk->icsk_rto),
76171 jiffies_to_clock_t(icsk->icsk_ack.ato),
76172 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
76173 @@ -2132,7 +2162,13 @@ static void get_timewait6_sock(struct seq_file *seq,
76174 dest->s6_addr32[2], dest->s6_addr32[3], destp,
76175 tw->tw_substate, 0, 0,
76176 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
76177 - atomic_read(&tw->tw_refcnt), tw);
76178 + atomic_read(&tw->tw_refcnt),
76179 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76180 + NULL
76181 +#else
76182 + tw
76183 +#endif
76184 + );
76185 }
76186
76187 static int tcp6_seq_show(struct seq_file *seq, void *v)
76188 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
76189 index 4f96b5c..75543d7 100644
76190 --- a/net/ipv6/udp.c
76191 +++ b/net/ipv6/udp.c
76192 @@ -50,6 +50,10 @@
76193 #include <linux/seq_file.h>
76194 #include "udp_impl.h"
76195
76196 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76197 +extern int grsec_enable_blackhole;
76198 +#endif
76199 +
76200 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
76201 {
76202 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
76203 @@ -551,7 +555,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
76204
76205 return 0;
76206 drop:
76207 - atomic_inc(&sk->sk_drops);
76208 + atomic_inc_unchecked(&sk->sk_drops);
76209 drop_no_sk_drops_inc:
76210 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
76211 kfree_skb(skb);
76212 @@ -627,7 +631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
76213 continue;
76214 }
76215 drop:
76216 - atomic_inc(&sk->sk_drops);
76217 + atomic_inc_unchecked(&sk->sk_drops);
76218 UDP6_INC_STATS_BH(sock_net(sk),
76219 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
76220 UDP6_INC_STATS_BH(sock_net(sk),
76221 @@ -782,6 +786,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76222 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
76223 proto == IPPROTO_UDPLITE);
76224
76225 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76226 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
76227 +#endif
76228 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
76229
76230 kfree_skb(skb);
76231 @@ -798,7 +805,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
76232 if (!sock_owned_by_user(sk))
76233 udpv6_queue_rcv_skb(sk, skb);
76234 else if (sk_add_backlog(sk, skb)) {
76235 - atomic_inc(&sk->sk_drops);
76236 + atomic_inc_unchecked(&sk->sk_drops);
76237 bh_unlock_sock(sk);
76238 sock_put(sk);
76239 goto discard;
76240 @@ -1410,8 +1417,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
76241 0, 0L, 0,
76242 sock_i_uid(sp), 0,
76243 sock_i_ino(sp),
76244 - atomic_read(&sp->sk_refcnt), sp,
76245 - atomic_read(&sp->sk_drops));
76246 + atomic_read(&sp->sk_refcnt),
76247 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76248 + NULL,
76249 +#else
76250 + sp,
76251 +#endif
76252 + atomic_read_unchecked(&sp->sk_drops));
76253 }
76254
76255 int udp6_seq_show(struct seq_file *seq, void *v)
76256 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
76257 index 253695d..9481ce8 100644
76258 --- a/net/irda/ircomm/ircomm_tty.c
76259 +++ b/net/irda/ircomm/ircomm_tty.c
76260 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76261 add_wait_queue(&self->open_wait, &wait);
76262
76263 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
76264 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76265 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76266
76267 /* As far as I can see, we protect open_count - Jean II */
76268 spin_lock_irqsave(&self->spinlock, flags);
76269 if (!tty_hung_up_p(filp)) {
76270 extra_count = 1;
76271 - self->open_count--;
76272 + local_dec(&self->open_count);
76273 }
76274 spin_unlock_irqrestore(&self->spinlock, flags);
76275 - self->blocked_open++;
76276 + local_inc(&self->blocked_open);
76277
76278 while (1) {
76279 if (tty->termios->c_cflag & CBAUD) {
76280 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76281 }
76282
76283 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
76284 - __FILE__,__LINE__, tty->driver->name, self->open_count );
76285 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
76286
76287 schedule();
76288 }
76289 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
76290 if (extra_count) {
76291 /* ++ is not atomic, so this should be protected - Jean II */
76292 spin_lock_irqsave(&self->spinlock, flags);
76293 - self->open_count++;
76294 + local_inc(&self->open_count);
76295 spin_unlock_irqrestore(&self->spinlock, flags);
76296 }
76297 - self->blocked_open--;
76298 + local_dec(&self->blocked_open);
76299
76300 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
76301 - __FILE__,__LINE__, tty->driver->name, self->open_count);
76302 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
76303
76304 if (!retval)
76305 self->flags |= ASYNC_NORMAL_ACTIVE;
76306 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
76307 }
76308 /* ++ is not atomic, so this should be protected - Jean II */
76309 spin_lock_irqsave(&self->spinlock, flags);
76310 - self->open_count++;
76311 + local_inc(&self->open_count);
76312
76313 tty->driver_data = self;
76314 self->tty = tty;
76315 spin_unlock_irqrestore(&self->spinlock, flags);
76316
76317 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
76318 - self->line, self->open_count);
76319 + self->line, local_read(&self->open_count));
76320
76321 /* Not really used by us, but lets do it anyway */
76322 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
76323 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76324 return;
76325 }
76326
76327 - if ((tty->count == 1) && (self->open_count != 1)) {
76328 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
76329 /*
76330 * Uh, oh. tty->count is 1, which means that the tty
76331 * structure will be freed. state->count should always
76332 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76333 */
76334 IRDA_DEBUG(0, "%s(), bad serial port count; "
76335 "tty->count is 1, state->count is %d\n", __func__ ,
76336 - self->open_count);
76337 - self->open_count = 1;
76338 + local_read(&self->open_count));
76339 + local_set(&self->open_count, 1);
76340 }
76341
76342 - if (--self->open_count < 0) {
76343 + if (local_dec_return(&self->open_count) < 0) {
76344 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
76345 - __func__, self->line, self->open_count);
76346 - self->open_count = 0;
76347 + __func__, self->line, local_read(&self->open_count));
76348 + local_set(&self->open_count, 0);
76349 }
76350 - if (self->open_count) {
76351 + if (local_read(&self->open_count)) {
76352 spin_unlock_irqrestore(&self->spinlock, flags);
76353
76354 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
76355 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
76356 tty->closing = 0;
76357 self->tty = NULL;
76358
76359 - if (self->blocked_open) {
76360 + if (local_read(&self->blocked_open)) {
76361 if (self->close_delay)
76362 schedule_timeout_interruptible(self->close_delay);
76363 wake_up_interruptible(&self->open_wait);
76364 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
76365 spin_lock_irqsave(&self->spinlock, flags);
76366 self->flags &= ~ASYNC_NORMAL_ACTIVE;
76367 self->tty = NULL;
76368 - self->open_count = 0;
76369 + local_set(&self->open_count, 0);
76370 spin_unlock_irqrestore(&self->spinlock, flags);
76371
76372 wake_up_interruptible(&self->open_wait);
76373 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
76374 seq_putc(m, '\n');
76375
76376 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
76377 - seq_printf(m, "Open count: %d\n", self->open_count);
76378 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
76379 seq_printf(m, "Max data size: %d\n", self->max_data_size);
76380 seq_printf(m, "Max header size: %d\n", self->max_header_size);
76381
76382 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
76383 index d5c5b8f..33beff0 100644
76384 --- a/net/iucv/af_iucv.c
76385 +++ b/net/iucv/af_iucv.c
76386 @@ -764,10 +764,10 @@ static int iucv_sock_autobind(struct sock *sk)
76387
76388 write_lock_bh(&iucv_sk_list.lock);
76389
76390 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
76391 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76392 while (__iucv_get_sock_by_name(name)) {
76393 sprintf(name, "%08x",
76394 - atomic_inc_return(&iucv_sk_list.autobind_name));
76395 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
76396 }
76397
76398 write_unlock_bh(&iucv_sk_list.lock);
76399 diff --git a/net/key/af_key.c b/net/key/af_key.c
76400 index 11dbb22..c20f667 100644
76401 --- a/net/key/af_key.c
76402 +++ b/net/key/af_key.c
76403 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
76404 static u32 get_acqseq(void)
76405 {
76406 u32 res;
76407 - static atomic_t acqseq;
76408 + static atomic_unchecked_t acqseq;
76409
76410 do {
76411 - res = atomic_inc_return(&acqseq);
76412 + res = atomic_inc_return_unchecked(&acqseq);
76413 } while (!res);
76414 return res;
76415 }
76416 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
76417 index 2f0642d..e5c6fba 100644
76418 --- a/net/mac80211/ieee80211_i.h
76419 +++ b/net/mac80211/ieee80211_i.h
76420 @@ -28,6 +28,7 @@
76421 #include <net/ieee80211_radiotap.h>
76422 #include <net/cfg80211.h>
76423 #include <net/mac80211.h>
76424 +#include <asm/local.h>
76425 #include "key.h"
76426 #include "sta_info.h"
76427
76428 @@ -781,7 +782,7 @@ struct ieee80211_local {
76429 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
76430 spinlock_t queue_stop_reason_lock;
76431
76432 - int open_count;
76433 + local_t open_count;
76434 int monitors, cooked_mntrs;
76435 /* number of interfaces with corresponding FIF_ flags */
76436 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
76437 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
76438 index 8e2137b..2974283 100644
76439 --- a/net/mac80211/iface.c
76440 +++ b/net/mac80211/iface.c
76441 @@ -222,7 +222,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76442 break;
76443 }
76444
76445 - if (local->open_count == 0) {
76446 + if (local_read(&local->open_count) == 0) {
76447 res = drv_start(local);
76448 if (res)
76449 goto err_del_bss;
76450 @@ -246,7 +246,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76451 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
76452
76453 if (!is_valid_ether_addr(dev->dev_addr)) {
76454 - if (!local->open_count)
76455 + if (!local_read(&local->open_count))
76456 drv_stop(local);
76457 return -EADDRNOTAVAIL;
76458 }
76459 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76460 mutex_unlock(&local->mtx);
76461
76462 if (coming_up)
76463 - local->open_count++;
76464 + local_inc(&local->open_count);
76465
76466 if (hw_reconf_flags)
76467 ieee80211_hw_config(local, hw_reconf_flags);
76468 @@ -360,7 +360,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
76469 err_del_interface:
76470 drv_remove_interface(local, sdata);
76471 err_stop:
76472 - if (!local->open_count)
76473 + if (!local_read(&local->open_count))
76474 drv_stop(local);
76475 err_del_bss:
76476 sdata->bss = NULL;
76477 @@ -489,7 +489,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76478 }
76479
76480 if (going_down)
76481 - local->open_count--;
76482 + local_dec(&local->open_count);
76483
76484 switch (sdata->vif.type) {
76485 case NL80211_IFTYPE_AP_VLAN:
76486 @@ -548,7 +548,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
76487
76488 ieee80211_recalc_ps(local, -1);
76489
76490 - if (local->open_count == 0) {
76491 + if (local_read(&local->open_count) == 0) {
76492 if (local->ops->napi_poll)
76493 napi_disable(&local->napi);
76494 ieee80211_clear_tx_pending(local);
76495 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
76496 index b142bd4..a651749 100644
76497 --- a/net/mac80211/main.c
76498 +++ b/net/mac80211/main.c
76499 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
76500 local->hw.conf.power_level = power;
76501 }
76502
76503 - if (changed && local->open_count) {
76504 + if (changed && local_read(&local->open_count)) {
76505 ret = drv_config(local, changed);
76506 /*
76507 * Goal:
76508 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
76509 index 596efaf..8f1911f 100644
76510 --- a/net/mac80211/pm.c
76511 +++ b/net/mac80211/pm.c
76512 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76513 struct ieee80211_sub_if_data *sdata;
76514 struct sta_info *sta;
76515
76516 - if (!local->open_count)
76517 + if (!local_read(&local->open_count))
76518 goto suspend;
76519
76520 ieee80211_scan_cancel(local);
76521 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76522 cancel_work_sync(&local->dynamic_ps_enable_work);
76523 del_timer_sync(&local->dynamic_ps_timer);
76524
76525 - local->wowlan = wowlan && local->open_count;
76526 + local->wowlan = wowlan && local_read(&local->open_count);
76527 if (local->wowlan) {
76528 int err = drv_suspend(local, wowlan);
76529 if (err < 0) {
76530 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
76531 }
76532
76533 /* stop hardware - this must stop RX */
76534 - if (local->open_count)
76535 + if (local_read(&local->open_count))
76536 ieee80211_stop_device(local);
76537
76538 suspend:
76539 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
76540 index f9b8e81..bb89b46 100644
76541 --- a/net/mac80211/rate.c
76542 +++ b/net/mac80211/rate.c
76543 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
76544
76545 ASSERT_RTNL();
76546
76547 - if (local->open_count)
76548 + if (local_read(&local->open_count))
76549 return -EBUSY;
76550
76551 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
76552 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
76553 index c97a065..ff61928 100644
76554 --- a/net/mac80211/rc80211_pid_debugfs.c
76555 +++ b/net/mac80211/rc80211_pid_debugfs.c
76556 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
76557
76558 spin_unlock_irqrestore(&events->lock, status);
76559
76560 - if (copy_to_user(buf, pb, p))
76561 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
76562 return -EFAULT;
76563
76564 return p;
76565 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
76566 index 9919892..8c49803 100644
76567 --- a/net/mac80211/util.c
76568 +++ b/net/mac80211/util.c
76569 @@ -1143,7 +1143,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
76570 }
76571 #endif
76572 /* everything else happens only if HW was up & running */
76573 - if (!local->open_count)
76574 + if (!local_read(&local->open_count))
76575 goto wake_up;
76576
76577 /*
76578 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
76579 index f8ac4ef..b02560b 100644
76580 --- a/net/netfilter/Kconfig
76581 +++ b/net/netfilter/Kconfig
76582 @@ -806,6 +806,16 @@ config NETFILTER_XT_MATCH_ESP
76583
76584 To compile it as a module, choose M here. If unsure, say N.
76585
76586 +config NETFILTER_XT_MATCH_GRADM
76587 + tristate '"gradm" match support'
76588 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
76589 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
76590 + ---help---
76591 + The gradm match allows to match on grsecurity RBAC being enabled.
76592 + It is useful when iptables rules are applied early on bootup to
76593 + prevent connections to the machine (except from a trusted host)
76594 + while the RBAC system is disabled.
76595 +
76596 config NETFILTER_XT_MATCH_HASHLIMIT
76597 tristate '"hashlimit" match support'
76598 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
76599 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
76600 index 40f4c3d..0d5dd6b 100644
76601 --- a/net/netfilter/Makefile
76602 +++ b/net/netfilter/Makefile
76603 @@ -83,6 +83,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
76604 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
76605 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
76606 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
76607 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
76608 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
76609 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
76610 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
76611 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
76612 index 29fa5ba..8debc79 100644
76613 --- a/net/netfilter/ipvs/ip_vs_conn.c
76614 +++ b/net/netfilter/ipvs/ip_vs_conn.c
76615 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
76616 /* Increase the refcnt counter of the dest */
76617 atomic_inc(&dest->refcnt);
76618
76619 - conn_flags = atomic_read(&dest->conn_flags);
76620 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
76621 if (cp->protocol != IPPROTO_UDP)
76622 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
76623 /* Bind with the destination and its corresponding transmitter */
76624 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
76625 atomic_set(&cp->refcnt, 1);
76626
76627 atomic_set(&cp->n_control, 0);
76628 - atomic_set(&cp->in_pkts, 0);
76629 + atomic_set_unchecked(&cp->in_pkts, 0);
76630
76631 atomic_inc(&ipvs->conn_count);
76632 if (flags & IP_VS_CONN_F_NO_CPORT)
76633 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
76634
76635 /* Don't drop the entry if its number of incoming packets is not
76636 located in [0, 8] */
76637 - i = atomic_read(&cp->in_pkts);
76638 + i = atomic_read_unchecked(&cp->in_pkts);
76639 if (i > 8 || i < 0) return 0;
76640
76641 if (!todrop_rate[i]) return 0;
76642 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
76643 index 2555816..31492d9 100644
76644 --- a/net/netfilter/ipvs/ip_vs_core.c
76645 +++ b/net/netfilter/ipvs/ip_vs_core.c
76646 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
76647 ret = cp->packet_xmit(skb, cp, pd->pp);
76648 /* do not touch skb anymore */
76649
76650 - atomic_inc(&cp->in_pkts);
76651 + atomic_inc_unchecked(&cp->in_pkts);
76652 ip_vs_conn_put(cp);
76653 return ret;
76654 }
76655 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
76656 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
76657 pkts = sysctl_sync_threshold(ipvs);
76658 else
76659 - pkts = atomic_add_return(1, &cp->in_pkts);
76660 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76661
76662 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
76663 cp->protocol == IPPROTO_SCTP) {
76664 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
76665 index b3afe18..08ec940 100644
76666 --- a/net/netfilter/ipvs/ip_vs_ctl.c
76667 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
76668 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
76669 ip_vs_rs_hash(ipvs, dest);
76670 write_unlock_bh(&ipvs->rs_lock);
76671 }
76672 - atomic_set(&dest->conn_flags, conn_flags);
76673 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
76674
76675 /* bind the service */
76676 if (!dest->svc) {
76677 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76678 " %-7s %-6d %-10d %-10d\n",
76679 &dest->addr.in6,
76680 ntohs(dest->port),
76681 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76682 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76683 atomic_read(&dest->weight),
76684 atomic_read(&dest->activeconns),
76685 atomic_read(&dest->inactconns));
76686 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
76687 "%-7s %-6d %-10d %-10d\n",
76688 ntohl(dest->addr.ip),
76689 ntohs(dest->port),
76690 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
76691 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
76692 atomic_read(&dest->weight),
76693 atomic_read(&dest->activeconns),
76694 atomic_read(&dest->inactconns));
76695 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
76696
76697 entry.addr = dest->addr.ip;
76698 entry.port = dest->port;
76699 - entry.conn_flags = atomic_read(&dest->conn_flags);
76700 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
76701 entry.weight = atomic_read(&dest->weight);
76702 entry.u_threshold = dest->u_threshold;
76703 entry.l_threshold = dest->l_threshold;
76704 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
76705 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
76706
76707 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
76708 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76709 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
76710 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
76711 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
76712 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
76713 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
76714 index 8a0d6d6..90ec197 100644
76715 --- a/net/netfilter/ipvs/ip_vs_sync.c
76716 +++ b/net/netfilter/ipvs/ip_vs_sync.c
76717 @@ -649,7 +649,7 @@ control:
76718 * i.e only increment in_pkts for Templates.
76719 */
76720 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
76721 - int pkts = atomic_add_return(1, &cp->in_pkts);
76722 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
76723
76724 if (pkts % sysctl_sync_period(ipvs) != 1)
76725 return;
76726 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
76727
76728 if (opt)
76729 memcpy(&cp->in_seq, opt, sizeof(*opt));
76730 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76731 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
76732 cp->state = state;
76733 cp->old_state = cp->state;
76734 /*
76735 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
76736 index 7fd66de..e6fb361 100644
76737 --- a/net/netfilter/ipvs/ip_vs_xmit.c
76738 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
76739 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
76740 else
76741 rc = NF_ACCEPT;
76742 /* do not touch skb anymore */
76743 - atomic_inc(&cp->in_pkts);
76744 + atomic_inc_unchecked(&cp->in_pkts);
76745 goto out;
76746 }
76747
76748 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
76749 else
76750 rc = NF_ACCEPT;
76751 /* do not touch skb anymore */
76752 - atomic_inc(&cp->in_pkts);
76753 + atomic_inc_unchecked(&cp->in_pkts);
76754 goto out;
76755 }
76756
76757 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
76758 index 66b2c54..c7884e3 100644
76759 --- a/net/netfilter/nfnetlink_log.c
76760 +++ b/net/netfilter/nfnetlink_log.c
76761 @@ -70,7 +70,7 @@ struct nfulnl_instance {
76762 };
76763
76764 static DEFINE_SPINLOCK(instances_lock);
76765 -static atomic_t global_seq;
76766 +static atomic_unchecked_t global_seq;
76767
76768 #define INSTANCE_BUCKETS 16
76769 static struct hlist_head instance_table[INSTANCE_BUCKETS];
76770 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
76771 /* global sequence number */
76772 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
76773 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
76774 - htonl(atomic_inc_return(&global_seq)));
76775 + htonl(atomic_inc_return_unchecked(&global_seq)));
76776
76777 if (data_len) {
76778 struct nlattr *nla;
76779 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
76780 new file mode 100644
76781 index 0000000..6905327
76782 --- /dev/null
76783 +++ b/net/netfilter/xt_gradm.c
76784 @@ -0,0 +1,51 @@
76785 +/*
76786 + * gradm match for netfilter
76787 + * Copyright © Zbigniew Krzystolik, 2010
76788 + *
76789 + * This program is free software; you can redistribute it and/or modify
76790 + * it under the terms of the GNU General Public License; either version
76791 + * 2 or 3 as published by the Free Software Foundation.
76792 + */
76793 +#include <linux/module.h>
76794 +#include <linux/moduleparam.h>
76795 +#include <linux/skbuff.h>
76796 +#include <linux/netfilter/x_tables.h>
76797 +#include <linux/grsecurity.h>
76798 +#include <linux/netfilter/xt_gradm.h>
76799 +
76800 +static bool
76801 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
76802 +{
76803 + const struct xt_gradm_mtinfo *info = par->matchinfo;
76804 + bool retval = false;
76805 + if (gr_acl_is_enabled())
76806 + retval = true;
76807 + return retval ^ info->invflags;
76808 +}
76809 +
76810 +static struct xt_match gradm_mt_reg __read_mostly = {
76811 + .name = "gradm",
76812 + .revision = 0,
76813 + .family = NFPROTO_UNSPEC,
76814 + .match = gradm_mt,
76815 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
76816 + .me = THIS_MODULE,
76817 +};
76818 +
76819 +static int __init gradm_mt_init(void)
76820 +{
76821 + return xt_register_match(&gradm_mt_reg);
76822 +}
76823 +
76824 +static void __exit gradm_mt_exit(void)
76825 +{
76826 + xt_unregister_match(&gradm_mt_reg);
76827 +}
76828 +
76829 +module_init(gradm_mt_init);
76830 +module_exit(gradm_mt_exit);
76831 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
76832 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
76833 +MODULE_LICENSE("GPL");
76834 +MODULE_ALIAS("ipt_gradm");
76835 +MODULE_ALIAS("ip6t_gradm");
76836 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
76837 index 4fe4fb4..87a89e5 100644
76838 --- a/net/netfilter/xt_statistic.c
76839 +++ b/net/netfilter/xt_statistic.c
76840 @@ -19,7 +19,7 @@
76841 #include <linux/module.h>
76842
76843 struct xt_statistic_priv {
76844 - atomic_t count;
76845 + atomic_unchecked_t count;
76846 } ____cacheline_aligned_in_smp;
76847
76848 MODULE_LICENSE("GPL");
76849 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
76850 break;
76851 case XT_STATISTIC_MODE_NTH:
76852 do {
76853 - oval = atomic_read(&info->master->count);
76854 + oval = atomic_read_unchecked(&info->master->count);
76855 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
76856 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
76857 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
76858 if (nval == 0)
76859 ret = !ret;
76860 break;
76861 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
76862 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
76863 if (info->master == NULL)
76864 return -ENOMEM;
76865 - atomic_set(&info->master->count, info->u.nth.count);
76866 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
76867
76868 return 0;
76869 }
76870 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
76871 index 467af9c..8f415cc 100644
76872 --- a/net/netlink/af_netlink.c
76873 +++ b/net/netlink/af_netlink.c
76874 @@ -741,7 +741,7 @@ static void netlink_overrun(struct sock *sk)
76875 sk->sk_error_report(sk);
76876 }
76877 }
76878 - atomic_inc(&sk->sk_drops);
76879 + atomic_inc_unchecked(&sk->sk_drops);
76880 }
76881
76882 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
76883 @@ -1997,7 +1997,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
76884 sk_wmem_alloc_get(s),
76885 nlk->cb,
76886 atomic_read(&s->sk_refcnt),
76887 - atomic_read(&s->sk_drops),
76888 + atomic_read_unchecked(&s->sk_drops),
76889 sock_i_ino(s)
76890 );
76891
76892 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
76893 index 7dab229..212156f 100644
76894 --- a/net/netrom/af_netrom.c
76895 +++ b/net/netrom/af_netrom.c
76896 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76897 struct sock *sk = sock->sk;
76898 struct nr_sock *nr = nr_sk(sk);
76899
76900 + memset(sax, 0, sizeof(*sax));
76901 lock_sock(sk);
76902 if (peer != 0) {
76903 if (sk->sk_state != TCP_ESTABLISHED) {
76904 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
76905 *uaddr_len = sizeof(struct full_sockaddr_ax25);
76906 } else {
76907 sax->fsa_ax25.sax25_family = AF_NETROM;
76908 - sax->fsa_ax25.sax25_ndigis = 0;
76909 sax->fsa_ax25.sax25_call = nr->source_addr;
76910 *uaddr_len = sizeof(struct sockaddr_ax25);
76911 }
76912 diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
76913 index 2c03050..5cf68c1 100644
76914 --- a/net/openvswitch/datapath.c
76915 +++ b/net/openvswitch/datapath.c
76916 @@ -322,7 +322,7 @@ static int queue_userspace_packet(int dp_ifindex, struct sk_buff *skb,
76917 return -ENOMEM;
76918
76919 nskb = __vlan_put_tag(nskb, vlan_tx_tag_get(nskb));
76920 - if (!skb)
76921 + if (!nskb)
76922 return -ENOMEM;
76923
76924 nskb->vlan_tci = 0;
76925 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
76926 index 2dbb32b..a1b4722 100644
76927 --- a/net/packet/af_packet.c
76928 +++ b/net/packet/af_packet.c
76929 @@ -1676,7 +1676,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76930
76931 spin_lock(&sk->sk_receive_queue.lock);
76932 po->stats.tp_packets++;
76933 - skb->dropcount = atomic_read(&sk->sk_drops);
76934 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76935 __skb_queue_tail(&sk->sk_receive_queue, skb);
76936 spin_unlock(&sk->sk_receive_queue.lock);
76937 sk->sk_data_ready(sk, skb->len);
76938 @@ -1685,7 +1685,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
76939 drop_n_acct:
76940 spin_lock(&sk->sk_receive_queue.lock);
76941 po->stats.tp_drops++;
76942 - atomic_inc(&sk->sk_drops);
76943 + atomic_inc_unchecked(&sk->sk_drops);
76944 spin_unlock(&sk->sk_receive_queue.lock);
76945
76946 drop_n_restore:
76947 @@ -3271,7 +3271,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76948 case PACKET_HDRLEN:
76949 if (len > sizeof(int))
76950 len = sizeof(int);
76951 - if (copy_from_user(&val, optval, len))
76952 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
76953 return -EFAULT;
76954 switch (val) {
76955 case TPACKET_V1:
76956 @@ -3321,7 +3321,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
76957
76958 if (put_user(len, optlen))
76959 return -EFAULT;
76960 - if (copy_to_user(optval, data, len))
76961 + if (len > sizeof(st) || copy_to_user(optval, data, len))
76962 return -EFAULT;
76963 return 0;
76964 }
76965 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
76966 index d65f699..05aa6ce 100644
76967 --- a/net/phonet/af_phonet.c
76968 +++ b/net/phonet/af_phonet.c
76969 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
76970 {
76971 struct phonet_protocol *pp;
76972
76973 - if (protocol >= PHONET_NPROTO)
76974 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76975 return NULL;
76976
76977 rcu_read_lock();
76978 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
76979 {
76980 int err = 0;
76981
76982 - if (protocol >= PHONET_NPROTO)
76983 + if (protocol < 0 || protocol >= PHONET_NPROTO)
76984 return -EINVAL;
76985
76986 err = proto_register(pp->prot, 1);
76987 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
76988 index 9726fe6..fc4e3a4 100644
76989 --- a/net/phonet/pep.c
76990 +++ b/net/phonet/pep.c
76991 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
76992
76993 case PNS_PEP_CTRL_REQ:
76994 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
76995 - atomic_inc(&sk->sk_drops);
76996 + atomic_inc_unchecked(&sk->sk_drops);
76997 break;
76998 }
76999 __skb_pull(skb, 4);
77000 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
77001 }
77002
77003 if (pn->rx_credits == 0) {
77004 - atomic_inc(&sk->sk_drops);
77005 + atomic_inc_unchecked(&sk->sk_drops);
77006 err = -ENOBUFS;
77007 break;
77008 }
77009 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
77010 }
77011
77012 if (pn->rx_credits == 0) {
77013 - atomic_inc(&sk->sk_drops);
77014 + atomic_inc_unchecked(&sk->sk_drops);
77015 err = NET_RX_DROP;
77016 break;
77017 }
77018 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
77019 index 4c7eff3..59c727f 100644
77020 --- a/net/phonet/socket.c
77021 +++ b/net/phonet/socket.c
77022 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
77023 pn->resource, sk->sk_state,
77024 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
77025 sock_i_uid(sk), sock_i_ino(sk),
77026 - atomic_read(&sk->sk_refcnt), sk,
77027 - atomic_read(&sk->sk_drops), &len);
77028 + atomic_read(&sk->sk_refcnt),
77029 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77030 + NULL,
77031 +#else
77032 + sk,
77033 +#endif
77034 + atomic_read_unchecked(&sk->sk_drops), &len);
77035 }
77036 seq_printf(seq, "%*s\n", 127 - len, "");
77037 return 0;
77038 diff --git a/net/rds/cong.c b/net/rds/cong.c
77039 index e5b65ac..f3b6fb7 100644
77040 --- a/net/rds/cong.c
77041 +++ b/net/rds/cong.c
77042 @@ -78,7 +78,7 @@
77043 * finds that the saved generation number is smaller than the global generation
77044 * number, it wakes up the process.
77045 */
77046 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
77047 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
77048
77049 /*
77050 * Congestion monitoring
77051 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
77052 rdsdebug("waking map %p for %pI4\n",
77053 map, &map->m_addr);
77054 rds_stats_inc(s_cong_update_received);
77055 - atomic_inc(&rds_cong_generation);
77056 + atomic_inc_unchecked(&rds_cong_generation);
77057 if (waitqueue_active(&map->m_waitq))
77058 wake_up(&map->m_waitq);
77059 if (waitqueue_active(&rds_poll_waitq))
77060 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
77061
77062 int rds_cong_updated_since(unsigned long *recent)
77063 {
77064 - unsigned long gen = atomic_read(&rds_cong_generation);
77065 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
77066
77067 if (likely(*recent == gen))
77068 return 0;
77069 diff --git a/net/rds/ib.h b/net/rds/ib.h
77070 index edfaaaf..8c89879 100644
77071 --- a/net/rds/ib.h
77072 +++ b/net/rds/ib.h
77073 @@ -128,7 +128,7 @@ struct rds_ib_connection {
77074 /* sending acks */
77075 unsigned long i_ack_flags;
77076 #ifdef KERNEL_HAS_ATOMIC64
77077 - atomic64_t i_ack_next; /* next ACK to send */
77078 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77079 #else
77080 spinlock_t i_ack_lock; /* protect i_ack_next */
77081 u64 i_ack_next; /* next ACK to send */
77082 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
77083 index 51c8689..36c555f 100644
77084 --- a/net/rds/ib_cm.c
77085 +++ b/net/rds/ib_cm.c
77086 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
77087 /* Clear the ACK state */
77088 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77089 #ifdef KERNEL_HAS_ATOMIC64
77090 - atomic64_set(&ic->i_ack_next, 0);
77091 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77092 #else
77093 ic->i_ack_next = 0;
77094 #endif
77095 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
77096 index e29e0ca..fa3a6a3 100644
77097 --- a/net/rds/ib_recv.c
77098 +++ b/net/rds/ib_recv.c
77099 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77100 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
77101 int ack_required)
77102 {
77103 - atomic64_set(&ic->i_ack_next, seq);
77104 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77105 if (ack_required) {
77106 smp_mb__before_clear_bit();
77107 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77108 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
77109 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77110 smp_mb__after_clear_bit();
77111
77112 - return atomic64_read(&ic->i_ack_next);
77113 + return atomic64_read_unchecked(&ic->i_ack_next);
77114 }
77115 #endif
77116
77117 diff --git a/net/rds/iw.h b/net/rds/iw.h
77118 index 04ce3b1..48119a6 100644
77119 --- a/net/rds/iw.h
77120 +++ b/net/rds/iw.h
77121 @@ -134,7 +134,7 @@ struct rds_iw_connection {
77122 /* sending acks */
77123 unsigned long i_ack_flags;
77124 #ifdef KERNEL_HAS_ATOMIC64
77125 - atomic64_t i_ack_next; /* next ACK to send */
77126 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
77127 #else
77128 spinlock_t i_ack_lock; /* protect i_ack_next */
77129 u64 i_ack_next; /* next ACK to send */
77130 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
77131 index 9556d28..f046d0e 100644
77132 --- a/net/rds/iw_cm.c
77133 +++ b/net/rds/iw_cm.c
77134 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
77135 /* Clear the ACK state */
77136 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
77137 #ifdef KERNEL_HAS_ATOMIC64
77138 - atomic64_set(&ic->i_ack_next, 0);
77139 + atomic64_set_unchecked(&ic->i_ack_next, 0);
77140 #else
77141 ic->i_ack_next = 0;
77142 #endif
77143 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
77144 index 5e57347..3916042 100644
77145 --- a/net/rds/iw_recv.c
77146 +++ b/net/rds/iw_recv.c
77147 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77148 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
77149 int ack_required)
77150 {
77151 - atomic64_set(&ic->i_ack_next, seq);
77152 + atomic64_set_unchecked(&ic->i_ack_next, seq);
77153 if (ack_required) {
77154 smp_mb__before_clear_bit();
77155 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77156 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
77157 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
77158 smp_mb__after_clear_bit();
77159
77160 - return atomic64_read(&ic->i_ack_next);
77161 + return atomic64_read_unchecked(&ic->i_ack_next);
77162 }
77163 #endif
77164
77165 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
77166 index edac9ef..16bcb98 100644
77167 --- a/net/rds/tcp.c
77168 +++ b/net/rds/tcp.c
77169 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
77170 int val = 1;
77171
77172 set_fs(KERNEL_DS);
77173 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
77174 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
77175 sizeof(val));
77176 set_fs(oldfs);
77177 }
77178 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
77179 index 1b4fd68..2234175 100644
77180 --- a/net/rds/tcp_send.c
77181 +++ b/net/rds/tcp_send.c
77182 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
77183
77184 oldfs = get_fs();
77185 set_fs(KERNEL_DS);
77186 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
77187 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
77188 sizeof(val));
77189 set_fs(oldfs);
77190 }
77191 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
77192 index 74c064c..fdec26f 100644
77193 --- a/net/rxrpc/af_rxrpc.c
77194 +++ b/net/rxrpc/af_rxrpc.c
77195 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
77196 __be32 rxrpc_epoch;
77197
77198 /* current debugging ID */
77199 -atomic_t rxrpc_debug_id;
77200 +atomic_unchecked_t rxrpc_debug_id;
77201
77202 /* count of skbs currently in use */
77203 atomic_t rxrpc_n_skbs;
77204 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
77205 index c3126e8..21facc7 100644
77206 --- a/net/rxrpc/ar-ack.c
77207 +++ b/net/rxrpc/ar-ack.c
77208 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77209
77210 _enter("{%d,%d,%d,%d},",
77211 call->acks_hard, call->acks_unacked,
77212 - atomic_read(&call->sequence),
77213 + atomic_read_unchecked(&call->sequence),
77214 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
77215
77216 stop = 0;
77217 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
77218
77219 /* each Tx packet has a new serial number */
77220 sp->hdr.serial =
77221 - htonl(atomic_inc_return(&call->conn->serial));
77222 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
77223
77224 hdr = (struct rxrpc_header *) txb->head;
77225 hdr->serial = sp->hdr.serial;
77226 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
77227 */
77228 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
77229 {
77230 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
77231 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
77232 }
77233
77234 /*
77235 @@ -629,7 +629,7 @@ process_further:
77236
77237 latest = ntohl(sp->hdr.serial);
77238 hard = ntohl(ack.firstPacket);
77239 - tx = atomic_read(&call->sequence);
77240 + tx = atomic_read_unchecked(&call->sequence);
77241
77242 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77243 latest,
77244 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
77245 goto maybe_reschedule;
77246
77247 send_ACK_with_skew:
77248 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
77249 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
77250 ntohl(ack.serial));
77251 send_ACK:
77252 mtu = call->conn->trans->peer->if_mtu;
77253 @@ -1173,7 +1173,7 @@ send_ACK:
77254 ackinfo.rxMTU = htonl(5692);
77255 ackinfo.jumbo_max = htonl(4);
77256
77257 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77258 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77259 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
77260 ntohl(hdr.serial),
77261 ntohs(ack.maxSkew),
77262 @@ -1191,7 +1191,7 @@ send_ACK:
77263 send_message:
77264 _debug("send message");
77265
77266 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
77267 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
77268 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
77269 send_message_2:
77270
77271 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
77272 index bf656c2..48f9d27 100644
77273 --- a/net/rxrpc/ar-call.c
77274 +++ b/net/rxrpc/ar-call.c
77275 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
77276 spin_lock_init(&call->lock);
77277 rwlock_init(&call->state_lock);
77278 atomic_set(&call->usage, 1);
77279 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
77280 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77281 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
77282
77283 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
77284 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
77285 index 4106ca9..a338d7a 100644
77286 --- a/net/rxrpc/ar-connection.c
77287 +++ b/net/rxrpc/ar-connection.c
77288 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
77289 rwlock_init(&conn->lock);
77290 spin_lock_init(&conn->state_lock);
77291 atomic_set(&conn->usage, 1);
77292 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
77293 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77294 conn->avail_calls = RXRPC_MAXCALLS;
77295 conn->size_align = 4;
77296 conn->header_size = sizeof(struct rxrpc_header);
77297 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
77298 index e7ed43a..6afa140 100644
77299 --- a/net/rxrpc/ar-connevent.c
77300 +++ b/net/rxrpc/ar-connevent.c
77301 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
77302
77303 len = iov[0].iov_len + iov[1].iov_len;
77304
77305 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77306 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77307 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
77308
77309 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77310 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
77311 index 1a2b0633..e8d1382 100644
77312 --- a/net/rxrpc/ar-input.c
77313 +++ b/net/rxrpc/ar-input.c
77314 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
77315 /* track the latest serial number on this connection for ACK packet
77316 * information */
77317 serial = ntohl(sp->hdr.serial);
77318 - hi_serial = atomic_read(&call->conn->hi_serial);
77319 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
77320 while (serial > hi_serial)
77321 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
77322 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
77323 serial);
77324
77325 /* request ACK generation for any ACK or DATA packet that requests
77326 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
77327 index 8e22bd3..f66d1c0 100644
77328 --- a/net/rxrpc/ar-internal.h
77329 +++ b/net/rxrpc/ar-internal.h
77330 @@ -272,8 +272,8 @@ struct rxrpc_connection {
77331 int error; /* error code for local abort */
77332 int debug_id; /* debug ID for printks */
77333 unsigned call_counter; /* call ID counter */
77334 - atomic_t serial; /* packet serial number counter */
77335 - atomic_t hi_serial; /* highest serial number received */
77336 + atomic_unchecked_t serial; /* packet serial number counter */
77337 + atomic_unchecked_t hi_serial; /* highest serial number received */
77338 u8 avail_calls; /* number of calls available */
77339 u8 size_align; /* data size alignment (for security) */
77340 u8 header_size; /* rxrpc + security header size */
77341 @@ -346,7 +346,7 @@ struct rxrpc_call {
77342 spinlock_t lock;
77343 rwlock_t state_lock; /* lock for state transition */
77344 atomic_t usage;
77345 - atomic_t sequence; /* Tx data packet sequence counter */
77346 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
77347 u32 abort_code; /* local/remote abort code */
77348 enum { /* current state of call */
77349 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
77350 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
77351 */
77352 extern atomic_t rxrpc_n_skbs;
77353 extern __be32 rxrpc_epoch;
77354 -extern atomic_t rxrpc_debug_id;
77355 +extern atomic_unchecked_t rxrpc_debug_id;
77356 extern struct workqueue_struct *rxrpc_workqueue;
77357
77358 /*
77359 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
77360 index 87f7135..74d3703 100644
77361 --- a/net/rxrpc/ar-local.c
77362 +++ b/net/rxrpc/ar-local.c
77363 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
77364 spin_lock_init(&local->lock);
77365 rwlock_init(&local->services_lock);
77366 atomic_set(&local->usage, 1);
77367 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
77368 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77369 memcpy(&local->srx, srx, sizeof(*srx));
77370 }
77371
77372 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
77373 index 16ae887..d24f12b 100644
77374 --- a/net/rxrpc/ar-output.c
77375 +++ b/net/rxrpc/ar-output.c
77376 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
77377 sp->hdr.cid = call->cid;
77378 sp->hdr.callNumber = call->call_id;
77379 sp->hdr.seq =
77380 - htonl(atomic_inc_return(&call->sequence));
77381 + htonl(atomic_inc_return_unchecked(&call->sequence));
77382 sp->hdr.serial =
77383 - htonl(atomic_inc_return(&conn->serial));
77384 + htonl(atomic_inc_return_unchecked(&conn->serial));
77385 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
77386 sp->hdr.userStatus = 0;
77387 sp->hdr.securityIndex = conn->security_ix;
77388 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
77389 index 2754f09..b20e38f 100644
77390 --- a/net/rxrpc/ar-peer.c
77391 +++ b/net/rxrpc/ar-peer.c
77392 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
77393 INIT_LIST_HEAD(&peer->error_targets);
77394 spin_lock_init(&peer->lock);
77395 atomic_set(&peer->usage, 1);
77396 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
77397 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77398 memcpy(&peer->srx, srx, sizeof(*srx));
77399
77400 rxrpc_assess_MTU_size(peer);
77401 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
77402 index 38047f7..9f48511 100644
77403 --- a/net/rxrpc/ar-proc.c
77404 +++ b/net/rxrpc/ar-proc.c
77405 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
77406 atomic_read(&conn->usage),
77407 rxrpc_conn_states[conn->state],
77408 key_serial(conn->key),
77409 - atomic_read(&conn->serial),
77410 - atomic_read(&conn->hi_serial));
77411 + atomic_read_unchecked(&conn->serial),
77412 + atomic_read_unchecked(&conn->hi_serial));
77413
77414 return 0;
77415 }
77416 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
77417 index 92df566..87ec1bf 100644
77418 --- a/net/rxrpc/ar-transport.c
77419 +++ b/net/rxrpc/ar-transport.c
77420 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
77421 spin_lock_init(&trans->client_lock);
77422 rwlock_init(&trans->conn_lock);
77423 atomic_set(&trans->usage, 1);
77424 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
77425 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
77426
77427 if (peer->srx.transport.family == AF_INET) {
77428 switch (peer->srx.transport_type) {
77429 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
77430 index 7635107..4670276 100644
77431 --- a/net/rxrpc/rxkad.c
77432 +++ b/net/rxrpc/rxkad.c
77433 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
77434
77435 len = iov[0].iov_len + iov[1].iov_len;
77436
77437 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
77438 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77439 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
77440
77441 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
77442 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
77443
77444 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
77445
77446 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
77447 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
77448 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
77449
77450 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
77451 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
77452 index 1e2eee8..ce3967e 100644
77453 --- a/net/sctp/proc.c
77454 +++ b/net/sctp/proc.c
77455 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
77456 seq_printf(seq,
77457 "%8pK %8pK %-3d %-3d %-2d %-4d "
77458 "%4d %8d %8d %7d %5lu %-5d %5d ",
77459 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
77460 + assoc, sk,
77461 + sctp_sk(sk)->type, sk->sk_state,
77462 assoc->state, hash,
77463 assoc->assoc_id,
77464 assoc->sndbuf_used,
77465 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
77466 index d043722..6903416 100644
77467 --- a/net/sctp/socket.c
77468 +++ b/net/sctp/socket.c
77469 @@ -4575,7 +4575,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
77470 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
77471 if (space_left < addrlen)
77472 return -ENOMEM;
77473 - if (copy_to_user(to, &temp, addrlen))
77474 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
77475 return -EFAULT;
77476 to += addrlen;
77477 cnt++;
77478 diff --git a/net/socket.c b/net/socket.c
77479 index 0de4131..7e7ddab 100644
77480 --- a/net/socket.c
77481 +++ b/net/socket.c
77482 @@ -88,6 +88,7 @@
77483 #include <linux/nsproxy.h>
77484 #include <linux/magic.h>
77485 #include <linux/slab.h>
77486 +#include <linux/in.h>
77487
77488 #include <asm/uaccess.h>
77489 #include <asm/unistd.h>
77490 @@ -105,6 +106,8 @@
77491 #include <linux/sockios.h>
77492 #include <linux/atalk.h>
77493
77494 +#include <linux/grsock.h>
77495 +
77496 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
77497 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
77498 unsigned long nr_segs, loff_t pos);
77499 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
77500 &sockfs_dentry_operations, SOCKFS_MAGIC);
77501 }
77502
77503 -static struct vfsmount *sock_mnt __read_mostly;
77504 +struct vfsmount *sock_mnt __read_mostly;
77505
77506 static struct file_system_type sock_fs_type = {
77507 .name = "sockfs",
77508 @@ -1207,6 +1210,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
77509 return -EAFNOSUPPORT;
77510 if (type < 0 || type >= SOCK_MAX)
77511 return -EINVAL;
77512 + if (protocol < 0)
77513 + return -EINVAL;
77514
77515 /* Compatibility.
77516
77517 @@ -1339,6 +1344,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
77518 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
77519 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
77520
77521 + if(!gr_search_socket(family, type, protocol)) {
77522 + retval = -EACCES;
77523 + goto out;
77524 + }
77525 +
77526 + if (gr_handle_sock_all(family, type, protocol)) {
77527 + retval = -EACCES;
77528 + goto out;
77529 + }
77530 +
77531 retval = sock_create(family, type, protocol, &sock);
77532 if (retval < 0)
77533 goto out;
77534 @@ -1451,6 +1466,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77535 if (sock) {
77536 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
77537 if (err >= 0) {
77538 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
77539 + err = -EACCES;
77540 + goto error;
77541 + }
77542 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
77543 + if (err)
77544 + goto error;
77545 +
77546 err = security_socket_bind(sock,
77547 (struct sockaddr *)&address,
77548 addrlen);
77549 @@ -1459,6 +1482,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
77550 (struct sockaddr *)
77551 &address, addrlen);
77552 }
77553 +error:
77554 fput_light(sock->file, fput_needed);
77555 }
77556 return err;
77557 @@ -1482,10 +1506,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
77558 if ((unsigned)backlog > somaxconn)
77559 backlog = somaxconn;
77560
77561 + if (gr_handle_sock_server_other(sock->sk)) {
77562 + err = -EPERM;
77563 + goto error;
77564 + }
77565 +
77566 + err = gr_search_listen(sock);
77567 + if (err)
77568 + goto error;
77569 +
77570 err = security_socket_listen(sock, backlog);
77571 if (!err)
77572 err = sock->ops->listen(sock, backlog);
77573
77574 +error:
77575 fput_light(sock->file, fput_needed);
77576 }
77577 return err;
77578 @@ -1529,6 +1563,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77579 newsock->type = sock->type;
77580 newsock->ops = sock->ops;
77581
77582 + if (gr_handle_sock_server_other(sock->sk)) {
77583 + err = -EPERM;
77584 + sock_release(newsock);
77585 + goto out_put;
77586 + }
77587 +
77588 + err = gr_search_accept(sock);
77589 + if (err) {
77590 + sock_release(newsock);
77591 + goto out_put;
77592 + }
77593 +
77594 /*
77595 * We don't need try_module_get here, as the listening socket (sock)
77596 * has the protocol module (sock->ops->owner) held.
77597 @@ -1567,6 +1613,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
77598 fd_install(newfd, newfile);
77599 err = newfd;
77600
77601 + gr_attach_curr_ip(newsock->sk);
77602 +
77603 out_put:
77604 fput_light(sock->file, fput_needed);
77605 out:
77606 @@ -1599,6 +1647,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77607 int, addrlen)
77608 {
77609 struct socket *sock;
77610 + struct sockaddr *sck;
77611 struct sockaddr_storage address;
77612 int err, fput_needed;
77613
77614 @@ -1609,6 +1658,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
77615 if (err < 0)
77616 goto out_put;
77617
77618 + sck = (struct sockaddr *)&address;
77619 +
77620 + if (gr_handle_sock_client(sck)) {
77621 + err = -EACCES;
77622 + goto out_put;
77623 + }
77624 +
77625 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
77626 + if (err)
77627 + goto out_put;
77628 +
77629 err =
77630 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
77631 if (err)
77632 @@ -1970,7 +2030,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
77633 * checking falls down on this.
77634 */
77635 if (copy_from_user(ctl_buf,
77636 - (void __user __force *)msg_sys->msg_control,
77637 + (void __force_user *)msg_sys->msg_control,
77638 ctl_len))
77639 goto out_freectl;
77640 msg_sys->msg_control = ctl_buf;
77641 @@ -2140,7 +2200,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
77642 * kernel msghdr to use the kernel address space)
77643 */
77644
77645 - uaddr = (__force void __user *)msg_sys->msg_name;
77646 + uaddr = (void __force_user *)msg_sys->msg_name;
77647 uaddr_len = COMPAT_NAMELEN(msg);
77648 if (MSG_CMSG_COMPAT & flags) {
77649 err = verify_compat_iovec(msg_sys, iov,
77650 @@ -2768,7 +2828,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77651 }
77652
77653 ifr = compat_alloc_user_space(buf_size);
77654 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
77655 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
77656
77657 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
77658 return -EFAULT;
77659 @@ -2792,12 +2852,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77660 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
77661
77662 if (copy_in_user(rxnfc, compat_rxnfc,
77663 - (void *)(&rxnfc->fs.m_ext + 1) -
77664 - (void *)rxnfc) ||
77665 + (void __user *)(&rxnfc->fs.m_ext + 1) -
77666 + (void __user *)rxnfc) ||
77667 copy_in_user(&rxnfc->fs.ring_cookie,
77668 &compat_rxnfc->fs.ring_cookie,
77669 - (void *)(&rxnfc->fs.location + 1) -
77670 - (void *)&rxnfc->fs.ring_cookie) ||
77671 + (void __user *)(&rxnfc->fs.location + 1) -
77672 + (void __user *)&rxnfc->fs.ring_cookie) ||
77673 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
77674 sizeof(rxnfc->rule_cnt)))
77675 return -EFAULT;
77676 @@ -2809,12 +2869,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
77677
77678 if (convert_out) {
77679 if (copy_in_user(compat_rxnfc, rxnfc,
77680 - (const void *)(&rxnfc->fs.m_ext + 1) -
77681 - (const void *)rxnfc) ||
77682 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
77683 + (const void __user *)rxnfc) ||
77684 copy_in_user(&compat_rxnfc->fs.ring_cookie,
77685 &rxnfc->fs.ring_cookie,
77686 - (const void *)(&rxnfc->fs.location + 1) -
77687 - (const void *)&rxnfc->fs.ring_cookie) ||
77688 + (const void __user *)(&rxnfc->fs.location + 1) -
77689 + (const void __user *)&rxnfc->fs.ring_cookie) ||
77690 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
77691 sizeof(rxnfc->rule_cnt)))
77692 return -EFAULT;
77693 @@ -2884,7 +2944,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
77694 old_fs = get_fs();
77695 set_fs(KERNEL_DS);
77696 err = dev_ioctl(net, cmd,
77697 - (struct ifreq __user __force *) &kifr);
77698 + (struct ifreq __force_user *) &kifr);
77699 set_fs(old_fs);
77700
77701 return err;
77702 @@ -2993,7 +3053,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
77703
77704 old_fs = get_fs();
77705 set_fs(KERNEL_DS);
77706 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
77707 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
77708 set_fs(old_fs);
77709
77710 if (cmd == SIOCGIFMAP && !err) {
77711 @@ -3098,7 +3158,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
77712 ret |= __get_user(rtdev, &(ur4->rt_dev));
77713 if (rtdev) {
77714 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
77715 - r4.rt_dev = (char __user __force *)devname;
77716 + r4.rt_dev = (char __force_user *)devname;
77717 devname[15] = 0;
77718 } else
77719 r4.rt_dev = NULL;
77720 @@ -3324,8 +3384,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
77721 int __user *uoptlen;
77722 int err;
77723
77724 - uoptval = (char __user __force *) optval;
77725 - uoptlen = (int __user __force *) optlen;
77726 + uoptval = (char __force_user *) optval;
77727 + uoptlen = (int __force_user *) optlen;
77728
77729 set_fs(KERNEL_DS);
77730 if (level == SOL_SOCKET)
77731 @@ -3345,7 +3405,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
77732 char __user *uoptval;
77733 int err;
77734
77735 - uoptval = (char __user __force *) optval;
77736 + uoptval = (char __force_user *) optval;
77737
77738 set_fs(KERNEL_DS);
77739 if (level == SOL_SOCKET)
77740 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
77741 index 8efd96c..b492ab2 100644
77742 --- a/net/sunrpc/sched.c
77743 +++ b/net/sunrpc/sched.c
77744 @@ -239,9 +239,9 @@ static int rpc_wait_bit_killable(void *word)
77745 #ifdef RPC_DEBUG
77746 static void rpc_task_set_debuginfo(struct rpc_task *task)
77747 {
77748 - static atomic_t rpc_pid;
77749 + static atomic_unchecked_t rpc_pid;
77750
77751 - task->tk_pid = atomic_inc_return(&rpc_pid);
77752 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
77753 }
77754 #else
77755 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
77756 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
77757 index 4645709..d41d668 100644
77758 --- a/net/sunrpc/svcsock.c
77759 +++ b/net/sunrpc/svcsock.c
77760 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
77761 int buflen, unsigned int base)
77762 {
77763 size_t save_iovlen;
77764 - void __user *save_iovbase;
77765 + void *save_iovbase;
77766 unsigned int i;
77767 int ret;
77768
77769 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
77770 index 09af4fa..77110a9 100644
77771 --- a/net/sunrpc/xprtrdma/svc_rdma.c
77772 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
77773 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
77774 static unsigned int min_max_inline = 4096;
77775 static unsigned int max_max_inline = 65536;
77776
77777 -atomic_t rdma_stat_recv;
77778 -atomic_t rdma_stat_read;
77779 -atomic_t rdma_stat_write;
77780 -atomic_t rdma_stat_sq_starve;
77781 -atomic_t rdma_stat_rq_starve;
77782 -atomic_t rdma_stat_rq_poll;
77783 -atomic_t rdma_stat_rq_prod;
77784 -atomic_t rdma_stat_sq_poll;
77785 -atomic_t rdma_stat_sq_prod;
77786 +atomic_unchecked_t rdma_stat_recv;
77787 +atomic_unchecked_t rdma_stat_read;
77788 +atomic_unchecked_t rdma_stat_write;
77789 +atomic_unchecked_t rdma_stat_sq_starve;
77790 +atomic_unchecked_t rdma_stat_rq_starve;
77791 +atomic_unchecked_t rdma_stat_rq_poll;
77792 +atomic_unchecked_t rdma_stat_rq_prod;
77793 +atomic_unchecked_t rdma_stat_sq_poll;
77794 +atomic_unchecked_t rdma_stat_sq_prod;
77795
77796 /* Temporary NFS request map and context caches */
77797 struct kmem_cache *svc_rdma_map_cachep;
77798 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
77799 len -= *ppos;
77800 if (len > *lenp)
77801 len = *lenp;
77802 - if (len && copy_to_user(buffer, str_buf, len))
77803 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
77804 return -EFAULT;
77805 *lenp = len;
77806 *ppos += len;
77807 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
77808 {
77809 .procname = "rdma_stat_read",
77810 .data = &rdma_stat_read,
77811 - .maxlen = sizeof(atomic_t),
77812 + .maxlen = sizeof(atomic_unchecked_t),
77813 .mode = 0644,
77814 .proc_handler = read_reset_stat,
77815 },
77816 {
77817 .procname = "rdma_stat_recv",
77818 .data = &rdma_stat_recv,
77819 - .maxlen = sizeof(atomic_t),
77820 + .maxlen = sizeof(atomic_unchecked_t),
77821 .mode = 0644,
77822 .proc_handler = read_reset_stat,
77823 },
77824 {
77825 .procname = "rdma_stat_write",
77826 .data = &rdma_stat_write,
77827 - .maxlen = sizeof(atomic_t),
77828 + .maxlen = sizeof(atomic_unchecked_t),
77829 .mode = 0644,
77830 .proc_handler = read_reset_stat,
77831 },
77832 {
77833 .procname = "rdma_stat_sq_starve",
77834 .data = &rdma_stat_sq_starve,
77835 - .maxlen = sizeof(atomic_t),
77836 + .maxlen = sizeof(atomic_unchecked_t),
77837 .mode = 0644,
77838 .proc_handler = read_reset_stat,
77839 },
77840 {
77841 .procname = "rdma_stat_rq_starve",
77842 .data = &rdma_stat_rq_starve,
77843 - .maxlen = sizeof(atomic_t),
77844 + .maxlen = sizeof(atomic_unchecked_t),
77845 .mode = 0644,
77846 .proc_handler = read_reset_stat,
77847 },
77848 {
77849 .procname = "rdma_stat_rq_poll",
77850 .data = &rdma_stat_rq_poll,
77851 - .maxlen = sizeof(atomic_t),
77852 + .maxlen = sizeof(atomic_unchecked_t),
77853 .mode = 0644,
77854 .proc_handler = read_reset_stat,
77855 },
77856 {
77857 .procname = "rdma_stat_rq_prod",
77858 .data = &rdma_stat_rq_prod,
77859 - .maxlen = sizeof(atomic_t),
77860 + .maxlen = sizeof(atomic_unchecked_t),
77861 .mode = 0644,
77862 .proc_handler = read_reset_stat,
77863 },
77864 {
77865 .procname = "rdma_stat_sq_poll",
77866 .data = &rdma_stat_sq_poll,
77867 - .maxlen = sizeof(atomic_t),
77868 + .maxlen = sizeof(atomic_unchecked_t),
77869 .mode = 0644,
77870 .proc_handler = read_reset_stat,
77871 },
77872 {
77873 .procname = "rdma_stat_sq_prod",
77874 .data = &rdma_stat_sq_prod,
77875 - .maxlen = sizeof(atomic_t),
77876 + .maxlen = sizeof(atomic_unchecked_t),
77877 .mode = 0644,
77878 .proc_handler = read_reset_stat,
77879 },
77880 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77881 index df67211..c354b13 100644
77882 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77883 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
77884 @@ -499,7 +499,7 @@ next_sge:
77885 svc_rdma_put_context(ctxt, 0);
77886 goto out;
77887 }
77888 - atomic_inc(&rdma_stat_read);
77889 + atomic_inc_unchecked(&rdma_stat_read);
77890
77891 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
77892 chl_map->ch[ch_no].count -= read_wr.num_sge;
77893 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77894 dto_q);
77895 list_del_init(&ctxt->dto_q);
77896 } else {
77897 - atomic_inc(&rdma_stat_rq_starve);
77898 + atomic_inc_unchecked(&rdma_stat_rq_starve);
77899 clear_bit(XPT_DATA, &xprt->xpt_flags);
77900 ctxt = NULL;
77901 }
77902 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
77903 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
77904 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
77905 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
77906 - atomic_inc(&rdma_stat_recv);
77907 + atomic_inc_unchecked(&rdma_stat_recv);
77908
77909 /* Build up the XDR from the receive buffers. */
77910 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
77911 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77912 index 249a835..fb2794b 100644
77913 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77914 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
77915 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
77916 write_wr.wr.rdma.remote_addr = to;
77917
77918 /* Post It */
77919 - atomic_inc(&rdma_stat_write);
77920 + atomic_inc_unchecked(&rdma_stat_write);
77921 if (svc_rdma_send(xprt, &write_wr))
77922 goto err;
77923 return 0;
77924 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77925 index 894cb42..cf5bafb 100644
77926 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
77927 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
77928 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77929 return;
77930
77931 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
77932 - atomic_inc(&rdma_stat_rq_poll);
77933 + atomic_inc_unchecked(&rdma_stat_rq_poll);
77934
77935 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
77936 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
77937 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
77938 }
77939
77940 if (ctxt)
77941 - atomic_inc(&rdma_stat_rq_prod);
77942 + atomic_inc_unchecked(&rdma_stat_rq_prod);
77943
77944 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
77945 /*
77946 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77947 return;
77948
77949 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
77950 - atomic_inc(&rdma_stat_sq_poll);
77951 + atomic_inc_unchecked(&rdma_stat_sq_poll);
77952 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
77953 if (wc.status != IB_WC_SUCCESS)
77954 /* Close the transport */
77955 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
77956 }
77957
77958 if (ctxt)
77959 - atomic_inc(&rdma_stat_sq_prod);
77960 + atomic_inc_unchecked(&rdma_stat_sq_prod);
77961 }
77962
77963 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
77964 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
77965 spin_lock_bh(&xprt->sc_lock);
77966 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
77967 spin_unlock_bh(&xprt->sc_lock);
77968 - atomic_inc(&rdma_stat_sq_starve);
77969 + atomic_inc_unchecked(&rdma_stat_sq_starve);
77970
77971 /* See if we can opportunistically reap SQ WR to make room */
77972 sq_cq_reap(xprt);
77973 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
77974 index e758139..d29ea47 100644
77975 --- a/net/sysctl_net.c
77976 +++ b/net/sysctl_net.c
77977 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
77978 struct ctl_table *table)
77979 {
77980 /* Allow network administrator to have same access as root. */
77981 - if (capable(CAP_NET_ADMIN)) {
77982 + if (capable_nolog(CAP_NET_ADMIN)) {
77983 int mode = (table->mode >> 6) & 7;
77984 return (mode << 6) | (mode << 3) | mode;
77985 }
77986 diff --git a/net/tipc/link.c b/net/tipc/link.c
77987 index ac1832a..533ed97 100644
77988 --- a/net/tipc/link.c
77989 +++ b/net/tipc/link.c
77990 @@ -1205,7 +1205,7 @@ static int link_send_sections_long(struct tipc_port *sender,
77991 struct tipc_msg fragm_hdr;
77992 struct sk_buff *buf, *buf_chain, *prev;
77993 u32 fragm_crs, fragm_rest, hsz, sect_rest;
77994 - const unchar *sect_crs;
77995 + const unchar __user *sect_crs;
77996 int curr_sect;
77997 u32 fragm_no;
77998
77999 @@ -1249,7 +1249,7 @@ again:
78000
78001 if (!sect_rest) {
78002 sect_rest = msg_sect[++curr_sect].iov_len;
78003 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
78004 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
78005 }
78006
78007 if (sect_rest < fragm_rest)
78008 @@ -1268,7 +1268,7 @@ error:
78009 }
78010 } else
78011 skb_copy_to_linear_data_offset(buf, fragm_crs,
78012 - sect_crs, sz);
78013 + (const void __force_kernel *)sect_crs, sz);
78014 sect_crs += sz;
78015 sect_rest -= sz;
78016 fragm_crs += sz;
78017 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
78018 index 3e4d3e2..27b55dc 100644
78019 --- a/net/tipc/msg.c
78020 +++ b/net/tipc/msg.c
78021 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
78022 msg_sect[cnt].iov_len);
78023 else
78024 skb_copy_to_linear_data_offset(*buf, pos,
78025 - msg_sect[cnt].iov_base,
78026 + (const void __force_kernel *)msg_sect[cnt].iov_base,
78027 msg_sect[cnt].iov_len);
78028 pos += msg_sect[cnt].iov_len;
78029 }
78030 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
78031 index 8c49566..14510cb 100644
78032 --- a/net/tipc/subscr.c
78033 +++ b/net/tipc/subscr.c
78034 @@ -101,7 +101,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
78035 {
78036 struct iovec msg_sect;
78037
78038 - msg_sect.iov_base = (void *)&sub->evt;
78039 + msg_sect.iov_base = (void __force_user *)&sub->evt;
78040 msg_sect.iov_len = sizeof(struct tipc_event);
78041
78042 sub->evt.event = htohl(event, sub->swap);
78043 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
78044 index 85d3bb7..79f4487 100644
78045 --- a/net/unix/af_unix.c
78046 +++ b/net/unix/af_unix.c
78047 @@ -770,6 +770,12 @@ static struct sock *unix_find_other(struct net *net,
78048 err = -ECONNREFUSED;
78049 if (!S_ISSOCK(inode->i_mode))
78050 goto put_fail;
78051 +
78052 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
78053 + err = -EACCES;
78054 + goto put_fail;
78055 + }
78056 +
78057 u = unix_find_socket_byinode(inode);
78058 if (!u)
78059 goto put_fail;
78060 @@ -790,6 +796,13 @@ static struct sock *unix_find_other(struct net *net,
78061 if (u) {
78062 struct dentry *dentry;
78063 dentry = unix_sk(u)->dentry;
78064 +
78065 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
78066 + err = -EPERM;
78067 + sock_put(u);
78068 + goto fail;
78069 + }
78070 +
78071 if (dentry)
78072 touch_atime(unix_sk(u)->mnt, dentry);
78073 } else
78074 @@ -872,11 +885,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
78075 err = security_path_mknod(&path, dentry, mode, 0);
78076 if (err)
78077 goto out_mknod_drop_write;
78078 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
78079 + err = -EACCES;
78080 + goto out_mknod_drop_write;
78081 + }
78082 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
78083 out_mknod_drop_write:
78084 mnt_drop_write(path.mnt);
78085 if (err)
78086 goto out_mknod_dput;
78087 +
78088 + gr_handle_create(dentry, path.mnt);
78089 +
78090 mutex_unlock(&path.dentry->d_inode->i_mutex);
78091 dput(path.dentry);
78092 path.dentry = dentry;
78093 diff --git a/net/wireless/core.h b/net/wireless/core.h
78094 index 43ad9c8..ab5127c 100644
78095 --- a/net/wireless/core.h
78096 +++ b/net/wireless/core.h
78097 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
78098 struct mutex mtx;
78099
78100 /* rfkill support */
78101 - struct rfkill_ops rfkill_ops;
78102 + rfkill_ops_no_const rfkill_ops;
78103 struct rfkill *rfkill;
78104 struct work_struct rfkill_sync;
78105
78106 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
78107 index 0af7f54..c916d2f 100644
78108 --- a/net/wireless/wext-core.c
78109 +++ b/net/wireless/wext-core.c
78110 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78111 */
78112
78113 /* Support for very large requests */
78114 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
78115 - (user_length > descr->max_tokens)) {
78116 + if (user_length > descr->max_tokens) {
78117 /* Allow userspace to GET more than max so
78118 * we can support any size GET requests.
78119 * There is still a limit : -ENOMEM.
78120 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
78121 }
78122 }
78123
78124 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
78125 - /*
78126 - * If this is a GET, but not NOMAX, it means that the extra
78127 - * data is not bounded by userspace, but by max_tokens. Thus
78128 - * set the length to max_tokens. This matches the extra data
78129 - * allocation.
78130 - * The driver should fill it with the number of tokens it
78131 - * provided, and it may check iwp->length rather than having
78132 - * knowledge of max_tokens. If the driver doesn't change the
78133 - * iwp->length, this ioctl just copies back max_token tokens
78134 - * filled with zeroes. Hopefully the driver isn't claiming
78135 - * them to be valid data.
78136 - */
78137 - iwp->length = descr->max_tokens;
78138 - }
78139 -
78140 err = handler(dev, info, (union iwreq_data *) iwp, extra);
78141
78142 iwp->length += essid_compat;
78143 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
78144 index 7661576..80f7627 100644
78145 --- a/net/xfrm/xfrm_policy.c
78146 +++ b/net/xfrm/xfrm_policy.c
78147 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
78148 {
78149 policy->walk.dead = 1;
78150
78151 - atomic_inc(&policy->genid);
78152 + atomic_inc_unchecked(&policy->genid);
78153
78154 if (del_timer(&policy->timer))
78155 xfrm_pol_put(policy);
78156 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
78157 hlist_add_head(&policy->bydst, chain);
78158 xfrm_pol_hold(policy);
78159 net->xfrm.policy_count[dir]++;
78160 - atomic_inc(&flow_cache_genid);
78161 + atomic_inc_unchecked(&flow_cache_genid);
78162 if (delpol)
78163 __xfrm_policy_unlink(delpol, dir);
78164 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
78165 @@ -1530,7 +1530,7 @@ free_dst:
78166 goto out;
78167 }
78168
78169 -static int inline
78170 +static inline int
78171 xfrm_dst_alloc_copy(void **target, const void *src, int size)
78172 {
78173 if (!*target) {
78174 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
78175 return 0;
78176 }
78177
78178 -static int inline
78179 +static inline int
78180 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78181 {
78182 #ifdef CONFIG_XFRM_SUB_POLICY
78183 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
78184 #endif
78185 }
78186
78187 -static int inline
78188 +static inline int
78189 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
78190 {
78191 #ifdef CONFIG_XFRM_SUB_POLICY
78192 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
78193
78194 xdst->num_pols = num_pols;
78195 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
78196 - xdst->policy_genid = atomic_read(&pols[0]->genid);
78197 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
78198
78199 return xdst;
78200 }
78201 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
78202 if (xdst->xfrm_genid != dst->xfrm->genid)
78203 return 0;
78204 if (xdst->num_pols > 0 &&
78205 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
78206 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
78207 return 0;
78208
78209 mtu = dst_mtu(dst->child);
78210 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
78211 sizeof(pol->xfrm_vec[i].saddr));
78212 pol->xfrm_vec[i].encap_family = mp->new_family;
78213 /* flush bundles */
78214 - atomic_inc(&pol->genid);
78215 + atomic_inc_unchecked(&pol->genid);
78216 }
78217 }
78218
78219 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
78220 index d2b366c..51ff91ebc 100644
78221 --- a/scripts/Makefile.build
78222 +++ b/scripts/Makefile.build
78223 @@ -109,7 +109,7 @@ endif
78224 endif
78225
78226 # Do not include host rules unless needed
78227 -ifneq ($(hostprogs-y)$(hostprogs-m),)
78228 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
78229 include scripts/Makefile.host
78230 endif
78231
78232 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
78233 index 686cb0d..9d653bf 100644
78234 --- a/scripts/Makefile.clean
78235 +++ b/scripts/Makefile.clean
78236 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
78237 __clean-files := $(extra-y) $(always) \
78238 $(targets) $(clean-files) \
78239 $(host-progs) \
78240 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
78241 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
78242 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
78243
78244 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
78245
78246 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
78247 index 1ac414f..a1c1451 100644
78248 --- a/scripts/Makefile.host
78249 +++ b/scripts/Makefile.host
78250 @@ -31,6 +31,7 @@
78251 # Note: Shared libraries consisting of C++ files are not supported
78252
78253 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
78254 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
78255
78256 # C code
78257 # Executables compiled from a single .c file
78258 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
78259 # Shared libaries (only .c supported)
78260 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
78261 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
78262 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
78263 # Remove .so files from "xxx-objs"
78264 host-cobjs := $(filter-out %.so,$(host-cobjs))
78265
78266 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
78267 index cb1f50c..cef2a7c 100644
78268 --- a/scripts/basic/fixdep.c
78269 +++ b/scripts/basic/fixdep.c
78270 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
78271 /*
78272 * Lookup a value in the configuration string.
78273 */
78274 -static int is_defined_config(const char *name, int len, unsigned int hash)
78275 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
78276 {
78277 struct item *aux;
78278
78279 @@ -211,10 +211,10 @@ static void clear_config(void)
78280 /*
78281 * Record the use of a CONFIG_* word.
78282 */
78283 -static void use_config(const char *m, int slen)
78284 +static void use_config(const char *m, unsigned int slen)
78285 {
78286 unsigned int hash = strhash(m, slen);
78287 - int c, i;
78288 + unsigned int c, i;
78289
78290 if (is_defined_config(m, slen, hash))
78291 return;
78292 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
78293
78294 static void parse_config_file(const char *map, size_t len)
78295 {
78296 - const int *end = (const int *) (map + len);
78297 + const unsigned int *end = (const unsigned int *) (map + len);
78298 /* start at +1, so that p can never be < map */
78299 - const int *m = (const int *) map + 1;
78300 + const unsigned int *m = (const unsigned int *) map + 1;
78301 const char *p, *q;
78302
78303 for (; m < end; m++) {
78304 @@ -406,7 +406,7 @@ static void print_deps(void)
78305 static void traps(void)
78306 {
78307 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
78308 - int *p = (int *)test;
78309 + unsigned int *p = (unsigned int *)test;
78310
78311 if (*p != INT_CONF) {
78312 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
78313 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
78314 new file mode 100644
78315 index 0000000..8729101
78316 --- /dev/null
78317 +++ b/scripts/gcc-plugin.sh
78318 @@ -0,0 +1,2 @@
78319 +#!/bin/sh
78320 +echo -e "#include \"gcc-plugin.h\"\n#include \"tree.h\"\n#include \"tm.h\"\n#include \"rtl.h\"" | $1 -x c -shared - -o /dev/null -I`$2 -print-file-name=plugin`/include >/dev/null 2>&1 && echo "y"
78321 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
78322 index e047e17..ea646ec 100644
78323 --- a/scripts/mod/file2alias.c
78324 +++ b/scripts/mod/file2alias.c
78325 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
78326 unsigned long size, unsigned long id_size,
78327 void *symval)
78328 {
78329 - int i;
78330 + unsigned int i;
78331
78332 if (size % id_size || size < id_size) {
78333 if (cross_build != 0)
78334 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
78335 /* USB is special because the bcdDevice can be matched against a numeric range */
78336 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
78337 static void do_usb_entry(struct usb_device_id *id,
78338 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
78339 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
78340 unsigned char range_lo, unsigned char range_hi,
78341 unsigned char max, struct module *mod)
78342 {
78343 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
78344 {
78345 unsigned int devlo, devhi;
78346 unsigned char chi, clo, max;
78347 - int ndigits;
78348 + unsigned int ndigits;
78349
78350 id->match_flags = TO_NATIVE(id->match_flags);
78351 id->idVendor = TO_NATIVE(id->idVendor);
78352 @@ -501,7 +501,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
78353 for (i = 0; i < count; i++) {
78354 const char *id = (char *)devs[i].id;
78355 char acpi_id[sizeof(devs[0].id)];
78356 - int j;
78357 + unsigned int j;
78358
78359 buf_printf(&mod->dev_table_buf,
78360 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78361 @@ -531,7 +531,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78362
78363 for (j = 0; j < PNP_MAX_DEVICES; j++) {
78364 const char *id = (char *)card->devs[j].id;
78365 - int i2, j2;
78366 + unsigned int i2, j2;
78367 int dup = 0;
78368
78369 if (!id[0])
78370 @@ -557,7 +557,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
78371 /* add an individual alias for every device entry */
78372 if (!dup) {
78373 char acpi_id[sizeof(card->devs[0].id)];
78374 - int k;
78375 + unsigned int k;
78376
78377 buf_printf(&mod->dev_table_buf,
78378 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
78379 @@ -882,7 +882,7 @@ static void dmi_ascii_filter(char *d, const char *s)
78380 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
78381 char *alias)
78382 {
78383 - int i, j;
78384 + unsigned int i, j;
78385
78386 sprintf(alias, "dmi*");
78387
78388 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
78389 index c4e7d15..4241aef 100644
78390 --- a/scripts/mod/modpost.c
78391 +++ b/scripts/mod/modpost.c
78392 @@ -922,6 +922,7 @@ enum mismatch {
78393 ANY_INIT_TO_ANY_EXIT,
78394 ANY_EXIT_TO_ANY_INIT,
78395 EXPORT_TO_INIT_EXIT,
78396 + DATA_TO_TEXT
78397 };
78398
78399 struct sectioncheck {
78400 @@ -1030,6 +1031,12 @@ const struct sectioncheck sectioncheck[] = {
78401 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
78402 .mismatch = EXPORT_TO_INIT_EXIT,
78403 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
78404 +},
78405 +/* Do not reference code from writable data */
78406 +{
78407 + .fromsec = { DATA_SECTIONS, NULL },
78408 + .tosec = { TEXT_SECTIONS, NULL },
78409 + .mismatch = DATA_TO_TEXT
78410 }
78411 };
78412
78413 @@ -1152,10 +1159,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
78414 continue;
78415 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
78416 continue;
78417 - if (sym->st_value == addr)
78418 - return sym;
78419 /* Find a symbol nearby - addr are maybe negative */
78420 d = sym->st_value - addr;
78421 + if (d == 0)
78422 + return sym;
78423 if (d < 0)
78424 d = addr - sym->st_value;
78425 if (d < distance) {
78426 @@ -1434,6 +1441,14 @@ static void report_sec_mismatch(const char *modname,
78427 tosym, prl_to, prl_to, tosym);
78428 free(prl_to);
78429 break;
78430 + case DATA_TO_TEXT:
78431 +/*
78432 + fprintf(stderr,
78433 + "The variable %s references\n"
78434 + "the %s %s%s%s\n",
78435 + fromsym, to, sec2annotation(tosec), tosym, to_p);
78436 +*/
78437 + break;
78438 }
78439 fprintf(stderr, "\n");
78440 }
78441 @@ -1668,7 +1683,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
78442 static void check_sec_ref(struct module *mod, const char *modname,
78443 struct elf_info *elf)
78444 {
78445 - int i;
78446 + unsigned int i;
78447 Elf_Shdr *sechdrs = elf->sechdrs;
78448
78449 /* Walk through all sections */
78450 @@ -1766,7 +1781,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
78451 va_end(ap);
78452 }
78453
78454 -void buf_write(struct buffer *buf, const char *s, int len)
78455 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
78456 {
78457 if (buf->size - buf->pos < len) {
78458 buf->size += len + SZ;
78459 @@ -1984,7 +1999,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
78460 if (fstat(fileno(file), &st) < 0)
78461 goto close_write;
78462
78463 - if (st.st_size != b->pos)
78464 + if (st.st_size != (off_t)b->pos)
78465 goto close_write;
78466
78467 tmp = NOFAIL(malloc(b->pos));
78468 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
78469 index 51207e4..f7d603d 100644
78470 --- a/scripts/mod/modpost.h
78471 +++ b/scripts/mod/modpost.h
78472 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
78473
78474 struct buffer {
78475 char *p;
78476 - int pos;
78477 - int size;
78478 + unsigned int pos;
78479 + unsigned int size;
78480 };
78481
78482 void __attribute__((format(printf, 2, 3)))
78483 buf_printf(struct buffer *buf, const char *fmt, ...);
78484
78485 void
78486 -buf_write(struct buffer *buf, const char *s, int len);
78487 +buf_write(struct buffer *buf, const char *s, unsigned int len);
78488
78489 struct module {
78490 struct module *next;
78491 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
78492 index 9dfcd6d..099068e 100644
78493 --- a/scripts/mod/sumversion.c
78494 +++ b/scripts/mod/sumversion.c
78495 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
78496 goto out;
78497 }
78498
78499 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
78500 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
78501 warn("writing sum in %s failed: %s\n",
78502 filename, strerror(errno));
78503 goto out;
78504 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
78505 index 5c11312..72742b5 100644
78506 --- a/scripts/pnmtologo.c
78507 +++ b/scripts/pnmtologo.c
78508 @@ -237,14 +237,14 @@ static void write_header(void)
78509 fprintf(out, " * Linux logo %s\n", logoname);
78510 fputs(" */\n\n", out);
78511 fputs("#include <linux/linux_logo.h>\n\n", out);
78512 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
78513 + fprintf(out, "static unsigned char %s_data[] = {\n",
78514 logoname);
78515 }
78516
78517 static void write_footer(void)
78518 {
78519 fputs("\n};\n\n", out);
78520 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
78521 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
78522 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
78523 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
78524 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
78525 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
78526 fputs("\n};\n\n", out);
78527
78528 /* write logo clut */
78529 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
78530 + fprintf(out, "static unsigned char %s_clut[] = {\n",
78531 logoname);
78532 write_hex_cnt = 0;
78533 for (i = 0; i < logo_clutsize; i++) {
78534 diff --git a/scripts/tags.sh b/scripts/tags.sh
78535 index 833813a..0bc8588 100755
78536 --- a/scripts/tags.sh
78537 +++ b/scripts/tags.sh
78538 @@ -116,7 +116,7 @@ docscope()
78539
78540 dogtags()
78541 {
78542 - all_sources | gtags -f -
78543 + all_sources | gtags -i -f -
78544 }
78545
78546 exuberant()
78547 diff --git a/security/Kconfig b/security/Kconfig
78548 index 51bd5a0..c37f5e6 100644
78549 --- a/security/Kconfig
78550 +++ b/security/Kconfig
78551 @@ -4,6 +4,640 @@
78552
78553 menu "Security options"
78554
78555 +source grsecurity/Kconfig
78556 +
78557 +menu "PaX"
78558 +
78559 + config ARCH_TRACK_EXEC_LIMIT
78560 + bool
78561 +
78562 + config PAX_KERNEXEC_PLUGIN
78563 + bool
78564 +
78565 + config PAX_PER_CPU_PGD
78566 + bool
78567 +
78568 + config TASK_SIZE_MAX_SHIFT
78569 + int
78570 + depends on X86_64
78571 + default 47 if !PAX_PER_CPU_PGD
78572 + default 42 if PAX_PER_CPU_PGD
78573 +
78574 + config PAX_ENABLE_PAE
78575 + bool
78576 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
78577 +
78578 +config PAX
78579 + bool "Enable various PaX features"
78580 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
78581 + help
78582 + This allows you to enable various PaX features. PaX adds
78583 + intrusion prevention mechanisms to the kernel that reduce
78584 + the risks posed by exploitable memory corruption bugs.
78585 +
78586 +menu "PaX Control"
78587 + depends on PAX
78588 +
78589 +config PAX_SOFTMODE
78590 + bool 'Support soft mode'
78591 + help
78592 + Enabling this option will allow you to run PaX in soft mode, that
78593 + is, PaX features will not be enforced by default, only on executables
78594 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
78595 + support as they are the only way to mark executables for soft mode use.
78596 +
78597 + Soft mode can be activated by using the "pax_softmode=1" kernel command
78598 + line option on boot. Furthermore you can control various PaX features
78599 + at runtime via the entries in /proc/sys/kernel/pax.
78600 +
78601 +config PAX_EI_PAX
78602 + bool 'Use legacy ELF header marking'
78603 + help
78604 + Enabling this option will allow you to control PaX features on
78605 + a per executable basis via the 'chpax' utility available at
78606 + http://pax.grsecurity.net/. The control flags will be read from
78607 + an otherwise reserved part of the ELF header. This marking has
78608 + numerous drawbacks (no support for soft-mode, toolchain does not
78609 + know about the non-standard use of the ELF header) therefore it
78610 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
78611 + support.
78612 +
78613 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78614 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
78615 + option otherwise they will not get any protection.
78616 +
78617 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
78618 + support as well, they will override the legacy EI_PAX marks.
78619 +
78620 +config PAX_PT_PAX_FLAGS
78621 + bool 'Use ELF program header marking'
78622 + help
78623 + Enabling this option will allow you to control PaX features on
78624 + a per executable basis via the 'paxctl' utility available at
78625 + http://pax.grsecurity.net/. The control flags will be read from
78626 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
78627 + has the benefits of supporting both soft mode and being fully
78628 + integrated into the toolchain (the binutils patch is available
78629 + from http://pax.grsecurity.net).
78630 +
78631 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78632 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78633 + support otherwise they will not get any protection.
78634 +
78635 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78636 + must make sure that the marks are the same if a binary has both marks.
78637 +
78638 + Note that if you enable the legacy EI_PAX marking support as well,
78639 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
78640 +
78641 +config PAX_XATTR_PAX_FLAGS
78642 + bool 'Use filesystem extended attributes marking'
78643 + select CIFS_XATTR if CIFS
78644 + select EXT2_FS_XATTR if EXT2_FS
78645 + select EXT3_FS_XATTR if EXT3_FS
78646 + select EXT4_FS_XATTR if EXT4_FS
78647 + select JFFS2_FS_XATTR if JFFS2_FS
78648 + select REISERFS_FS_XATTR if REISERFS_FS
78649 + select SQUASHFS_XATTR if SQUASHFS
78650 + select TMPFS_XATTR if TMPFS
78651 + select UBIFS_FS_XATTR if UBIFS_FS
78652 + help
78653 + Enabling this option will allow you to control PaX features on
78654 + a per executable basis via the 'setfattr' utility. The control
78655 + flags will be read from the user.pax.flags extended attribute of
78656 + the file. This marking has the benefit of supporting binary-only
78657 + applications that self-check themselves (e.g., skype) and would
78658 + not tolerate chpax/paxctl changes. The main drawback is that
78659 + extended attributes are not supported by some filesystems (e.g.,
78660 + isofs, udf, vfat) so copying files through such filesystems will
78661 + lose the extended attributes and these PaX markings.
78662 +
78663 + If you have applications not marked by the PT_PAX_FLAGS ELF program
78664 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
78665 + support otherwise they will not get any protection.
78666 +
78667 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
78668 + must make sure that the marks are the same if a binary has both marks.
78669 +
78670 + Note that if you enable the legacy EI_PAX marking support as well,
78671 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
78672 +
78673 +choice
78674 + prompt 'MAC system integration'
78675 + default PAX_HAVE_ACL_FLAGS
78676 + help
78677 + Mandatory Access Control systems have the option of controlling
78678 + PaX flags on a per executable basis, choose the method supported
78679 + by your particular system.
78680 +
78681 + - "none": if your MAC system does not interact with PaX,
78682 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
78683 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
78684 +
78685 + NOTE: this option is for developers/integrators only.
78686 +
78687 + config PAX_NO_ACL_FLAGS
78688 + bool 'none'
78689 +
78690 + config PAX_HAVE_ACL_FLAGS
78691 + bool 'direct'
78692 +
78693 + config PAX_HOOK_ACL_FLAGS
78694 + bool 'hook'
78695 +endchoice
78696 +
78697 +endmenu
78698 +
78699 +menu "Non-executable pages"
78700 + depends on PAX
78701 +
78702 +config PAX_NOEXEC
78703 + bool "Enforce non-executable pages"
78704 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
78705 + help
78706 + By design some architectures do not allow for protecting memory
78707 + pages against execution or even if they do, Linux does not make
78708 + use of this feature. In practice this means that if a page is
78709 + readable (such as the stack or heap) it is also executable.
78710 +
78711 + There is a well known exploit technique that makes use of this
78712 + fact and a common programming mistake where an attacker can
78713 + introduce code of his choice somewhere in the attacked program's
78714 + memory (typically the stack or the heap) and then execute it.
78715 +
78716 + If the attacked program was running with different (typically
78717 + higher) privileges than that of the attacker, then he can elevate
78718 + his own privilege level (e.g. get a root shell, write to files for
78719 + which he does not have write access to, etc).
78720 +
78721 + Enabling this option will let you choose from various features
78722 + that prevent the injection and execution of 'foreign' code in
78723 + a program.
78724 +
78725 + This will also break programs that rely on the old behaviour and
78726 + expect that dynamically allocated memory via the malloc() family
78727 + of functions is executable (which it is not). Notable examples
78728 + are the XFree86 4.x server, the java runtime and wine.
78729 +
78730 +config PAX_PAGEEXEC
78731 + bool "Paging based non-executable pages"
78732 + 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)
78733 + select S390_SWITCH_AMODE if S390
78734 + select S390_EXEC_PROTECT if S390
78735 + select ARCH_TRACK_EXEC_LIMIT if X86_32
78736 + help
78737 + This implementation is based on the paging feature of the CPU.
78738 + On i386 without hardware non-executable bit support there is a
78739 + variable but usually low performance impact, however on Intel's
78740 + P4 core based CPUs it is very high so you should not enable this
78741 + for kernels meant to be used on such CPUs.
78742 +
78743 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
78744 + with hardware non-executable bit support there is no performance
78745 + impact, on ppc the impact is negligible.
78746 +
78747 + Note that several architectures require various emulations due to
78748 + badly designed userland ABIs, this will cause a performance impact
78749 + but will disappear as soon as userland is fixed. For example, ppc
78750 + userland MUST have been built with secure-plt by a recent toolchain.
78751 +
78752 +config PAX_SEGMEXEC
78753 + bool "Segmentation based non-executable pages"
78754 + depends on PAX_NOEXEC && X86_32
78755 + help
78756 + This implementation is based on the segmentation feature of the
78757 + CPU and has a very small performance impact, however applications
78758 + will be limited to a 1.5 GB address space instead of the normal
78759 + 3 GB.
78760 +
78761 +config PAX_EMUTRAMP
78762 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
78763 + default y if PARISC
78764 + help
78765 + There are some programs and libraries that for one reason or
78766 + another attempt to execute special small code snippets from
78767 + non-executable memory pages. Most notable examples are the
78768 + signal handler return code generated by the kernel itself and
78769 + the GCC trampolines.
78770 +
78771 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
78772 + such programs will no longer work under your kernel.
78773 +
78774 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
78775 + utilities to enable trampoline emulation for the affected programs
78776 + yet still have the protection provided by the non-executable pages.
78777 +
78778 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
78779 + your system will not even boot.
78780 +
78781 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
78782 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
78783 + for the affected files.
78784 +
78785 + NOTE: enabling this feature *may* open up a loophole in the
78786 + protection provided by non-executable pages that an attacker
78787 + could abuse. Therefore the best solution is to not have any
78788 + files on your system that would require this option. This can
78789 + be achieved by not using libc5 (which relies on the kernel
78790 + signal handler return code) and not using or rewriting programs
78791 + that make use of the nested function implementation of GCC.
78792 + Skilled users can just fix GCC itself so that it implements
78793 + nested function calls in a way that does not interfere with PaX.
78794 +
78795 +config PAX_EMUSIGRT
78796 + bool "Automatically emulate sigreturn trampolines"
78797 + depends on PAX_EMUTRAMP && PARISC
78798 + default y
78799 + help
78800 + Enabling this option will have the kernel automatically detect
78801 + and emulate signal return trampolines executing on the stack
78802 + that would otherwise lead to task termination.
78803 +
78804 + This solution is intended as a temporary one for users with
78805 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
78806 + Modula-3 runtime, etc) or executables linked to such, basically
78807 + everything that does not specify its own SA_RESTORER function in
78808 + normal executable memory like glibc 2.1+ does.
78809 +
78810 + On parisc you MUST enable this option, otherwise your system will
78811 + not even boot.
78812 +
78813 + NOTE: this feature cannot be disabled on a per executable basis
78814 + and since it *does* open up a loophole in the protection provided
78815 + by non-executable pages, the best solution is to not have any
78816 + files on your system that would require this option.
78817 +
78818 +config PAX_MPROTECT
78819 + bool "Restrict mprotect()"
78820 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
78821 + help
78822 + Enabling this option will prevent programs from
78823 + - changing the executable status of memory pages that were
78824 + not originally created as executable,
78825 + - making read-only executable pages writable again,
78826 + - creating executable pages from anonymous memory,
78827 + - making read-only-after-relocations (RELRO) data pages writable again.
78828 +
78829 + You should say Y here to complete the protection provided by
78830 + the enforcement of non-executable pages.
78831 +
78832 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
78833 + this feature on a per file basis.
78834 +
78835 +config PAX_MPROTECT_COMPAT
78836 + bool "Use legacy/compat protection demoting (read help)"
78837 + depends on PAX_MPROTECT
78838 + default n
78839 + help
78840 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
78841 + by sending the proper error code to the application. For some broken
78842 + userland, this can cause problems with Python or other applications. The
78843 + current implementation however allows for applications like clamav to
78844 + detect if JIT compilation/execution is allowed and to fall back gracefully
78845 + to an interpreter-based mode if it does not. While we encourage everyone
78846 + to use the current implementation as-is and push upstream to fix broken
78847 + userland (note that the RWX logging option can assist with this), in some
78848 + environments this may not be possible. Having to disable MPROTECT
78849 + completely on certain binaries reduces the security benefit of PaX,
78850 + so this option is provided for those environments to revert to the old
78851 + behavior.
78852 +
78853 +config PAX_ELFRELOCS
78854 + bool "Allow ELF text relocations (read help)"
78855 + depends on PAX_MPROTECT
78856 + default n
78857 + help
78858 + Non-executable pages and mprotect() restrictions are effective
78859 + in preventing the introduction of new executable code into an
78860 + attacked task's address space. There remain only two venues
78861 + for this kind of attack: if the attacker can execute already
78862 + existing code in the attacked task then he can either have it
78863 + create and mmap() a file containing his code or have it mmap()
78864 + an already existing ELF library that does not have position
78865 + independent code in it and use mprotect() on it to make it
78866 + writable and copy his code there. While protecting against
78867 + the former approach is beyond PaX, the latter can be prevented
78868 + by having only PIC ELF libraries on one's system (which do not
78869 + need to relocate their code). If you are sure this is your case,
78870 + as is the case with all modern Linux distributions, then leave
78871 + this option disabled. You should say 'n' here.
78872 +
78873 +config PAX_ETEXECRELOCS
78874 + bool "Allow ELF ET_EXEC text relocations"
78875 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
78876 + select PAX_ELFRELOCS
78877 + default y
78878 + help
78879 + On some architectures there are incorrectly created applications
78880 + that require text relocations and would not work without enabling
78881 + this option. If you are an alpha, ia64 or parisc user, you should
78882 + enable this option and disable it once you have made sure that
78883 + none of your applications need it.
78884 +
78885 +config PAX_EMUPLT
78886 + bool "Automatically emulate ELF PLT"
78887 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
78888 + default y
78889 + help
78890 + Enabling this option will have the kernel automatically detect
78891 + and emulate the Procedure Linkage Table entries in ELF files.
78892 + On some architectures such entries are in writable memory, and
78893 + become non-executable leading to task termination. Therefore
78894 + it is mandatory that you enable this option on alpha, parisc,
78895 + sparc and sparc64, otherwise your system would not even boot.
78896 +
78897 + NOTE: this feature *does* open up a loophole in the protection
78898 + provided by the non-executable pages, therefore the proper
78899 + solution is to modify the toolchain to produce a PLT that does
78900 + not need to be writable.
78901 +
78902 +config PAX_DLRESOLVE
78903 + bool 'Emulate old glibc resolver stub'
78904 + depends on PAX_EMUPLT && SPARC
78905 + default n
78906 + help
78907 + This option is needed if userland has an old glibc (before 2.4)
78908 + that puts a 'save' instruction into the runtime generated resolver
78909 + stub that needs special emulation.
78910 +
78911 +config PAX_KERNEXEC
78912 + bool "Enforce non-executable kernel pages"
78913 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
78914 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
78915 + select PAX_KERNEXEC_PLUGIN if X86_64
78916 + help
78917 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
78918 + that is, enabling this option will make it harder to inject
78919 + and execute 'foreign' code in kernel memory itself.
78920 +
78921 + Note that on x86_64 kernels there is a known regression when
78922 + this feature and KVM/VMX are both enabled in the host kernel.
78923 +
78924 +choice
78925 + prompt "Return Address Instrumentation Method"
78926 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
78927 + depends on PAX_KERNEXEC_PLUGIN
78928 + help
78929 + Select the method used to instrument function pointer dereferences.
78930 + Note that binary modules cannot be instrumented by this approach.
78931 +
78932 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
78933 + bool "bts"
78934 + help
78935 + This method is compatible with binary only modules but has
78936 + a higher runtime overhead.
78937 +
78938 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
78939 + bool "or"
78940 + depends on !PARAVIRT
78941 + help
78942 + This method is incompatible with binary only modules but has
78943 + a lower runtime overhead.
78944 +endchoice
78945 +
78946 +config PAX_KERNEXEC_PLUGIN_METHOD
78947 + string
78948 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
78949 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
78950 + default ""
78951 +
78952 +config PAX_KERNEXEC_MODULE_TEXT
78953 + int "Minimum amount of memory reserved for module code"
78954 + default "4"
78955 + depends on PAX_KERNEXEC && X86_32 && MODULES
78956 + help
78957 + Due to implementation details the kernel must reserve a fixed
78958 + amount of memory for module code at compile time that cannot be
78959 + changed at runtime. Here you can specify the minimum amount
78960 + in MB that will be reserved. Due to the same implementation
78961 + details this size will always be rounded up to the next 2/4 MB
78962 + boundary (depends on PAE) so the actually available memory for
78963 + module code will usually be more than this minimum.
78964 +
78965 + The default 4 MB should be enough for most users but if you have
78966 + an excessive number of modules (e.g., most distribution configs
78967 + compile many drivers as modules) or use huge modules such as
78968 + nvidia's kernel driver, you will need to adjust this amount.
78969 + A good rule of thumb is to look at your currently loaded kernel
78970 + modules and add up their sizes.
78971 +
78972 +endmenu
78973 +
78974 +menu "Address Space Layout Randomization"
78975 + depends on PAX
78976 +
78977 +config PAX_ASLR
78978 + bool "Address Space Layout Randomization"
78979 + help
78980 + Many if not most exploit techniques rely on the knowledge of
78981 + certain addresses in the attacked program. The following options
78982 + will allow the kernel to apply a certain amount of randomization
78983 + to specific parts of the program thereby forcing an attacker to
78984 + guess them in most cases. Any failed guess will most likely crash
78985 + the attacked program which allows the kernel to detect such attempts
78986 + and react on them. PaX itself provides no reaction mechanisms,
78987 + instead it is strongly encouraged that you make use of Nergal's
78988 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
78989 + (http://www.grsecurity.net/) built-in crash detection features or
78990 + develop one yourself.
78991 +
78992 + By saying Y here you can choose to randomize the following areas:
78993 + - top of the task's kernel stack
78994 + - top of the task's userland stack
78995 + - base address for mmap() requests that do not specify one
78996 + (this includes all libraries)
78997 + - base address of the main executable
78998 +
78999 + It is strongly recommended to say Y here as address space layout
79000 + randomization has negligible impact on performance yet it provides
79001 + a very effective protection.
79002 +
79003 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
79004 + this feature on a per file basis.
79005 +
79006 +config PAX_RANDKSTACK
79007 + bool "Randomize kernel stack base"
79008 + depends on X86_TSC && X86
79009 + help
79010 + By saying Y here the kernel will randomize every task's kernel
79011 + stack on every system call. This will not only force an attacker
79012 + to guess it but also prevent him from making use of possible
79013 + leaked information about it.
79014 +
79015 + Since the kernel stack is a rather scarce resource, randomization
79016 + may cause unexpected stack overflows, therefore you should very
79017 + carefully test your system. Note that once enabled in the kernel
79018 + configuration, this feature cannot be disabled on a per file basis.
79019 +
79020 +config PAX_RANDUSTACK
79021 + bool "Randomize user stack base"
79022 + depends on PAX_ASLR
79023 + help
79024 + By saying Y here the kernel will randomize every task's userland
79025 + stack. The randomization is done in two steps where the second
79026 + one may apply a big amount of shift to the top of the stack and
79027 + cause problems for programs that want to use lots of memory (more
79028 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
79029 + For this reason the second step can be controlled by 'chpax' or
79030 + 'paxctl' on a per file basis.
79031 +
79032 +config PAX_RANDMMAP
79033 + bool "Randomize mmap() base"
79034 + depends on PAX_ASLR
79035 + help
79036 + By saying Y here the kernel will use a randomized base address for
79037 + mmap() requests that do not specify one themselves. As a result
79038 + all dynamically loaded libraries will appear at random addresses
79039 + and therefore be harder to exploit by a technique where an attacker
79040 + attempts to execute library code for his purposes (e.g. spawn a
79041 + shell from an exploited program that is running at an elevated
79042 + privilege level).
79043 +
79044 + Furthermore, if a program is relinked as a dynamic ELF file, its
79045 + base address will be randomized as well, completing the full
79046 + randomization of the address space layout. Attacking such programs
79047 + becomes a guess game. You can find an example of doing this at
79048 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
79049 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
79050 +
79051 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
79052 + feature on a per file basis.
79053 +
79054 +endmenu
79055 +
79056 +menu "Miscellaneous hardening features"
79057 +
79058 +config PAX_MEMORY_SANITIZE
79059 + bool "Sanitize all freed memory"
79060 + depends on !HIBERNATION
79061 + help
79062 + By saying Y here the kernel will erase memory pages as soon as they
79063 + are freed. This in turn reduces the lifetime of data stored in the
79064 + pages, making it less likely that sensitive information such as
79065 + passwords, cryptographic secrets, etc stay in memory for too long.
79066 +
79067 + This is especially useful for programs whose runtime is short, long
79068 + lived processes and the kernel itself benefit from this as long as
79069 + they operate on whole memory pages and ensure timely freeing of pages
79070 + that may hold sensitive information.
79071 +
79072 + The tradeoff is performance impact, on a single CPU system kernel
79073 + compilation sees a 3% slowdown, other systems and workloads may vary
79074 + and you are advised to test this feature on your expected workload
79075 + before deploying it.
79076 +
79077 + Note that this feature does not protect data stored in live pages,
79078 + e.g., process memory swapped to disk may stay there for a long time.
79079 +
79080 +config PAX_MEMORY_STACKLEAK
79081 + bool "Sanitize kernel stack"
79082 + depends on X86
79083 + help
79084 + By saying Y here the kernel will erase the kernel stack before it
79085 + returns from a system call. This in turn reduces the information
79086 + that a kernel stack leak bug can reveal.
79087 +
79088 + Note that such a bug can still leak information that was put on
79089 + the stack by the current system call (the one eventually triggering
79090 + the bug) but traces of earlier system calls on the kernel stack
79091 + cannot leak anymore.
79092 +
79093 + The tradeoff is performance impact: on a single CPU system kernel
79094 + compilation sees a 1% slowdown, other systems and workloads may vary
79095 + and you are advised to test this feature on your expected workload
79096 + before deploying it.
79097 +
79098 + Note: full support for this feature requires gcc with plugin support
79099 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
79100 + versions means that functions with large enough stack frames may
79101 + leave uninitialized memory behind that may be exposed to a later
79102 + syscall leaking the stack.
79103 +
79104 +config PAX_MEMORY_UDEREF
79105 + bool "Prevent invalid userland pointer dereference"
79106 + depends on X86 && !UML_X86 && !XEN
79107 + select PAX_PER_CPU_PGD if X86_64
79108 + help
79109 + By saying Y here the kernel will be prevented from dereferencing
79110 + userland pointers in contexts where the kernel expects only kernel
79111 + pointers. This is both a useful runtime debugging feature and a
79112 + security measure that prevents exploiting a class of kernel bugs.
79113 +
79114 + The tradeoff is that some virtualization solutions may experience
79115 + a huge slowdown and therefore you should not enable this feature
79116 + for kernels meant to run in such environments. Whether a given VM
79117 + solution is affected or not is best determined by simply trying it
79118 + out, the performance impact will be obvious right on boot as this
79119 + mechanism engages from very early on. A good rule of thumb is that
79120 + VMs running on CPUs without hardware virtualization support (i.e.,
79121 + the majority of IA-32 CPUs) will likely experience the slowdown.
79122 +
79123 +config PAX_REFCOUNT
79124 + bool "Prevent various kernel object reference counter overflows"
79125 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
79126 + help
79127 + By saying Y here the kernel will detect and prevent overflowing
79128 + various (but not all) kinds of object reference counters. Such
79129 + overflows can normally occur due to bugs only and are often, if
79130 + not always, exploitable.
79131 +
79132 + The tradeoff is that data structures protected by an overflowed
79133 + refcount will never be freed and therefore will leak memory. Note
79134 + that this leak also happens even without this protection but in
79135 + that case the overflow can eventually trigger the freeing of the
79136 + data structure while it is still being used elsewhere, resulting
79137 + in the exploitable situation that this feature prevents.
79138 +
79139 + Since this has a negligible performance impact, you should enable
79140 + this feature.
79141 +
79142 +config PAX_USERCOPY
79143 + bool "Harden heap object copies between kernel and userland"
79144 + depends on X86 || PPC || SPARC || ARM
79145 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
79146 + help
79147 + By saying Y here the kernel will enforce the size of heap objects
79148 + when they are copied in either direction between the kernel and
79149 + userland, even if only a part of the heap object is copied.
79150 +
79151 + Specifically, this checking prevents information leaking from the
79152 + kernel heap during kernel to userland copies (if the kernel heap
79153 + object is otherwise fully initialized) and prevents kernel heap
79154 + overflows during userland to kernel copies.
79155 +
79156 + Note that the current implementation provides the strictest bounds
79157 + checks for the SLUB allocator.
79158 +
79159 + Enabling this option also enables per-slab cache protection against
79160 + data in a given cache being copied into/out of via userland
79161 + accessors. Though the whitelist of regions will be reduced over
79162 + time, it notably protects important data structures like task structs.
79163 +
79164 + If frame pointers are enabled on x86, this option will also restrict
79165 + copies into and out of the kernel stack to local variables within a
79166 + single frame.
79167 +
79168 + Since this has a negligible performance impact, you should enable
79169 + this feature.
79170 +
79171 +config PAX_SIZE_OVERFLOW
79172 + bool "Prevent various integer overflows in function size parameters"
79173 + depends on X86
79174 + help
79175 + By saying Y here the kernel recomputes expressions of function
79176 + arguments marked by a size_overflow attribute with double integer
79177 + precision (DImode/TImode for 32/64 bit integer types).
79178 +
79179 + The recomputed argument is checked against INT_MAX and an event
79180 + is logged on overflow and the triggering process is killed.
79181 +
79182 + Homepage:
79183 + http://www.grsecurity.net/~ephox/overflow_plugin/
79184 +
79185 +endmenu
79186 +
79187 +endmenu
79188 +
79189 config KEYS
79190 bool "Enable access key retention support"
79191 help
79192 @@ -169,7 +803,7 @@ config INTEL_TXT
79193 config LSM_MMAP_MIN_ADDR
79194 int "Low address space for LSM to protect from user allocation"
79195 depends on SECURITY && SECURITY_SELINUX
79196 - default 32768 if ARM
79197 + default 32768 if ALPHA || ARM || PARISC || SPARC32
79198 default 65536
79199 help
79200 This is the portion of low virtual memory which should be protected
79201 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
79202 index 97ce8fa..23dad96 100644
79203 --- a/security/apparmor/lsm.c
79204 +++ b/security/apparmor/lsm.c
79205 @@ -620,7 +620,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
79206 return error;
79207 }
79208
79209 -static struct security_operations apparmor_ops = {
79210 +static struct security_operations apparmor_ops __read_only = {
79211 .name = "apparmor",
79212
79213 .ptrace_access_check = apparmor_ptrace_access_check,
79214 diff --git a/security/commoncap.c b/security/commoncap.c
79215 index b8d2bb9..980069e 100644
79216 --- a/security/commoncap.c
79217 +++ b/security/commoncap.c
79218 @@ -29,6 +29,7 @@
79219 #include <linux/securebits.h>
79220 #include <linux/user_namespace.h>
79221 #include <linux/personality.h>
79222 +#include <net/sock.h>
79223
79224 /*
79225 * If a non-root user executes a setuid-root binary in
79226 @@ -575,6 +576,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
79227 {
79228 const struct cred *cred = current_cred();
79229
79230 + if (gr_acl_enable_at_secure())
79231 + return 1;
79232 +
79233 if (cred->uid != 0) {
79234 if (bprm->cap_effective)
79235 return 1;
79236 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
79237 index 3ccf7ac..d73ad64 100644
79238 --- a/security/integrity/ima/ima.h
79239 +++ b/security/integrity/ima/ima.h
79240 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79241 extern spinlock_t ima_queue_lock;
79242
79243 struct ima_h_table {
79244 - atomic_long_t len; /* number of stored measurements in the list */
79245 - atomic_long_t violations;
79246 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
79247 + atomic_long_unchecked_t violations;
79248 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
79249 };
79250 extern struct ima_h_table ima_htable;
79251 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
79252 index 88a2788..581ab92 100644
79253 --- a/security/integrity/ima/ima_api.c
79254 +++ b/security/integrity/ima/ima_api.c
79255 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
79256 int result;
79257
79258 /* can overflow, only indicator */
79259 - atomic_long_inc(&ima_htable.violations);
79260 + atomic_long_inc_unchecked(&ima_htable.violations);
79261
79262 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
79263 if (!entry) {
79264 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
79265 index e1aa2b4..52027bf 100644
79266 --- a/security/integrity/ima/ima_fs.c
79267 +++ b/security/integrity/ima/ima_fs.c
79268 @@ -28,12 +28,12 @@
79269 static int valid_policy = 1;
79270 #define TMPBUFLEN 12
79271 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
79272 - loff_t *ppos, atomic_long_t *val)
79273 + loff_t *ppos, atomic_long_unchecked_t *val)
79274 {
79275 char tmpbuf[TMPBUFLEN];
79276 ssize_t len;
79277
79278 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
79279 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
79280 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
79281 }
79282
79283 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
79284 index 55a6271..ad829c3 100644
79285 --- a/security/integrity/ima/ima_queue.c
79286 +++ b/security/integrity/ima/ima_queue.c
79287 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
79288 INIT_LIST_HEAD(&qe->later);
79289 list_add_tail_rcu(&qe->later, &ima_measurements);
79290
79291 - atomic_long_inc(&ima_htable.len);
79292 + atomic_long_inc_unchecked(&ima_htable.len);
79293 key = ima_hash_key(entry->digest);
79294 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
79295 return 0;
79296 diff --git a/security/keys/compat.c b/security/keys/compat.c
79297 index 4c48e13..7abdac9 100644
79298 --- a/security/keys/compat.c
79299 +++ b/security/keys/compat.c
79300 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
79301 if (ret == 0)
79302 goto no_payload_free;
79303
79304 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79305 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79306
79307 if (iov != iovstack)
79308 kfree(iov);
79309 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
79310 index 0b3f5d7..892c8a6 100644
79311 --- a/security/keys/keyctl.c
79312 +++ b/security/keys/keyctl.c
79313 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
79314 /*
79315 * Copy the iovec data from userspace
79316 */
79317 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79318 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
79319 unsigned ioc)
79320 {
79321 for (; ioc > 0; ioc--) {
79322 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
79323 * If successful, 0 will be returned.
79324 */
79325 long keyctl_instantiate_key_common(key_serial_t id,
79326 - const struct iovec *payload_iov,
79327 + const struct iovec __user *payload_iov,
79328 unsigned ioc,
79329 size_t plen,
79330 key_serial_t ringid)
79331 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
79332 [0].iov_len = plen
79333 };
79334
79335 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
79336 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
79337 }
79338
79339 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
79340 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
79341 if (ret == 0)
79342 goto no_payload_free;
79343
79344 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
79345 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
79346
79347 if (iov != iovstack)
79348 kfree(iov);
79349 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
79350 index d605f75..2bc6be9 100644
79351 --- a/security/keys/keyring.c
79352 +++ b/security/keys/keyring.c
79353 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
79354 ret = -EFAULT;
79355
79356 for (loop = 0; loop < klist->nkeys; loop++) {
79357 + key_serial_t serial;
79358 key = klist->keys[loop];
79359 + serial = key->serial;
79360
79361 tmp = sizeof(key_serial_t);
79362 if (tmp > buflen)
79363 tmp = buflen;
79364
79365 - if (copy_to_user(buffer,
79366 - &key->serial,
79367 - tmp) != 0)
79368 + if (copy_to_user(buffer, &serial, tmp))
79369 goto error;
79370
79371 buflen -= tmp;
79372 diff --git a/security/min_addr.c b/security/min_addr.c
79373 index f728728..6457a0c 100644
79374 --- a/security/min_addr.c
79375 +++ b/security/min_addr.c
79376 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
79377 */
79378 static void update_mmap_min_addr(void)
79379 {
79380 +#ifndef SPARC
79381 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
79382 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
79383 mmap_min_addr = dac_mmap_min_addr;
79384 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
79385 #else
79386 mmap_min_addr = dac_mmap_min_addr;
79387 #endif
79388 +#endif
79389 }
79390
79391 /*
79392 diff --git a/security/security.c b/security/security.c
79393 index d754249..8bf426e 100644
79394 --- a/security/security.c
79395 +++ b/security/security.c
79396 @@ -26,8 +26,8 @@
79397 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
79398 CONFIG_DEFAULT_SECURITY;
79399
79400 -static struct security_operations *security_ops;
79401 -static struct security_operations default_security_ops = {
79402 +static struct security_operations *security_ops __read_only;
79403 +static struct security_operations default_security_ops __read_only = {
79404 .name = "default",
79405 };
79406
79407 @@ -68,7 +68,9 @@ int __init security_init(void)
79408
79409 void reset_security_ops(void)
79410 {
79411 + pax_open_kernel();
79412 security_ops = &default_security_ops;
79413 + pax_close_kernel();
79414 }
79415
79416 /* Save user chosen LSM */
79417 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
79418 index 6a3683e..f52f4c0 100644
79419 --- a/security/selinux/hooks.c
79420 +++ b/security/selinux/hooks.c
79421 @@ -94,8 +94,6 @@
79422
79423 #define NUM_SEL_MNT_OPTS 5
79424
79425 -extern struct security_operations *security_ops;
79426 -
79427 /* SECMARK reference count */
79428 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
79429
79430 @@ -5429,7 +5427,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
79431
79432 #endif
79433
79434 -static struct security_operations selinux_ops = {
79435 +static struct security_operations selinux_ops __read_only = {
79436 .name = "selinux",
79437
79438 .ptrace_access_check = selinux_ptrace_access_check,
79439 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
79440 index b43813c..74be837 100644
79441 --- a/security/selinux/include/xfrm.h
79442 +++ b/security/selinux/include/xfrm.h
79443 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
79444
79445 static inline void selinux_xfrm_notify_policyload(void)
79446 {
79447 - atomic_inc(&flow_cache_genid);
79448 + atomic_inc_unchecked(&flow_cache_genid);
79449 }
79450 #else
79451 static inline int selinux_xfrm_enabled(void)
79452 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
79453 index e8af5b0b..78527ef 100644
79454 --- a/security/smack/smack_lsm.c
79455 +++ b/security/smack/smack_lsm.c
79456 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
79457 return 0;
79458 }
79459
79460 -struct security_operations smack_ops = {
79461 +struct security_operations smack_ops __read_only = {
79462 .name = "smack",
79463
79464 .ptrace_access_check = smack_ptrace_access_check,
79465 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
79466 index 620d37c..e2ad89b 100644
79467 --- a/security/tomoyo/tomoyo.c
79468 +++ b/security/tomoyo/tomoyo.c
79469 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
79470 * tomoyo_security_ops is a "struct security_operations" which is used for
79471 * registering TOMOYO.
79472 */
79473 -static struct security_operations tomoyo_security_ops = {
79474 +static struct security_operations tomoyo_security_ops __read_only = {
79475 .name = "tomoyo",
79476 .cred_alloc_blank = tomoyo_cred_alloc_blank,
79477 .cred_prepare = tomoyo_cred_prepare,
79478 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
79479 index 762af68..7103453 100644
79480 --- a/sound/aoa/codecs/onyx.c
79481 +++ b/sound/aoa/codecs/onyx.c
79482 @@ -54,7 +54,7 @@ struct onyx {
79483 spdif_locked:1,
79484 analog_locked:1,
79485 original_mute:2;
79486 - int open_count;
79487 + local_t open_count;
79488 struct codec_info *codec_info;
79489
79490 /* mutex serializes concurrent access to the device
79491 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
79492 struct onyx *onyx = cii->codec_data;
79493
79494 mutex_lock(&onyx->mutex);
79495 - onyx->open_count++;
79496 + local_inc(&onyx->open_count);
79497 mutex_unlock(&onyx->mutex);
79498
79499 return 0;
79500 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
79501 struct onyx *onyx = cii->codec_data;
79502
79503 mutex_lock(&onyx->mutex);
79504 - onyx->open_count--;
79505 - if (!onyx->open_count)
79506 + if (local_dec_and_test(&onyx->open_count))
79507 onyx->spdif_locked = onyx->analog_locked = 0;
79508 mutex_unlock(&onyx->mutex);
79509
79510 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
79511 index ffd2025..df062c9 100644
79512 --- a/sound/aoa/codecs/onyx.h
79513 +++ b/sound/aoa/codecs/onyx.h
79514 @@ -11,6 +11,7 @@
79515 #include <linux/i2c.h>
79516 #include <asm/pmac_low_i2c.h>
79517 #include <asm/prom.h>
79518 +#include <asm/local.h>
79519
79520 /* PCM3052 register definitions */
79521
79522 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
79523 index 08fde00..0bf641a 100644
79524 --- a/sound/core/oss/pcm_oss.c
79525 +++ b/sound/core/oss/pcm_oss.c
79526 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
79527 if (in_kernel) {
79528 mm_segment_t fs;
79529 fs = snd_enter_user();
79530 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79531 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79532 snd_leave_user(fs);
79533 } else {
79534 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
79535 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
79536 }
79537 if (ret != -EPIPE && ret != -ESTRPIPE)
79538 break;
79539 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
79540 if (in_kernel) {
79541 mm_segment_t fs;
79542 fs = snd_enter_user();
79543 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79544 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79545 snd_leave_user(fs);
79546 } else {
79547 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
79548 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
79549 }
79550 if (ret == -EPIPE) {
79551 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
79552 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
79553 struct snd_pcm_plugin_channel *channels;
79554 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
79555 if (!in_kernel) {
79556 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
79557 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
79558 return -EFAULT;
79559 buf = runtime->oss.buffer;
79560 }
79561 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
79562 }
79563 } else {
79564 tmp = snd_pcm_oss_write2(substream,
79565 - (const char __force *)buf,
79566 + (const char __force_kernel *)buf,
79567 runtime->oss.period_bytes, 0);
79568 if (tmp <= 0)
79569 goto err;
79570 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
79571 struct snd_pcm_runtime *runtime = substream->runtime;
79572 snd_pcm_sframes_t frames, frames1;
79573 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
79574 - char __user *final_dst = (char __force __user *)buf;
79575 + char __user *final_dst = (char __force_user *)buf;
79576 if (runtime->oss.plugin_first) {
79577 struct snd_pcm_plugin_channel *channels;
79578 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
79579 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
79580 xfer += tmp;
79581 runtime->oss.buffer_used -= tmp;
79582 } else {
79583 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
79584 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
79585 runtime->oss.period_bytes, 0);
79586 if (tmp <= 0)
79587 goto err;
79588 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
79589 size1);
79590 size1 /= runtime->channels; /* frames */
79591 fs = snd_enter_user();
79592 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
79593 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
79594 snd_leave_user(fs);
79595 }
79596 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
79597 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
79598 index 91cdf94..4085161 100644
79599 --- a/sound/core/pcm_compat.c
79600 +++ b/sound/core/pcm_compat.c
79601 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
79602 int err;
79603
79604 fs = snd_enter_user();
79605 - err = snd_pcm_delay(substream, &delay);
79606 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
79607 snd_leave_user(fs);
79608 if (err < 0)
79609 return err;
79610 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
79611 index 25ed9fe..24c46e9 100644
79612 --- a/sound/core/pcm_native.c
79613 +++ b/sound/core/pcm_native.c
79614 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
79615 switch (substream->stream) {
79616 case SNDRV_PCM_STREAM_PLAYBACK:
79617 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
79618 - (void __user *)arg);
79619 + (void __force_user *)arg);
79620 break;
79621 case SNDRV_PCM_STREAM_CAPTURE:
79622 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
79623 - (void __user *)arg);
79624 + (void __force_user *)arg);
79625 break;
79626 default:
79627 result = -EINVAL;
79628 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
79629 index 5cf8d65..912a79c 100644
79630 --- a/sound/core/seq/seq_device.c
79631 +++ b/sound/core/seq/seq_device.c
79632 @@ -64,7 +64,7 @@ struct ops_list {
79633 int argsize; /* argument size */
79634
79635 /* operators */
79636 - struct snd_seq_dev_ops ops;
79637 + struct snd_seq_dev_ops *ops;
79638
79639 /* registred devices */
79640 struct list_head dev_list; /* list of devices */
79641 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
79642
79643 mutex_lock(&ops->reg_mutex);
79644 /* copy driver operators */
79645 - ops->ops = *entry;
79646 + ops->ops = entry;
79647 ops->driver |= DRIVER_LOADED;
79648 ops->argsize = argsize;
79649
79650 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
79651 dev->name, ops->id, ops->argsize, dev->argsize);
79652 return -EINVAL;
79653 }
79654 - if (ops->ops.init_device(dev) >= 0) {
79655 + if (ops->ops->init_device(dev) >= 0) {
79656 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
79657 ops->num_init_devices++;
79658 } else {
79659 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
79660 dev->name, ops->id, ops->argsize, dev->argsize);
79661 return -EINVAL;
79662 }
79663 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
79664 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
79665 dev->status = SNDRV_SEQ_DEVICE_FREE;
79666 dev->driver_data = NULL;
79667 ops->num_init_devices--;
79668 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
79669 index 621e60e..f4543f5 100644
79670 --- a/sound/drivers/mts64.c
79671 +++ b/sound/drivers/mts64.c
79672 @@ -29,6 +29,7 @@
79673 #include <sound/initval.h>
79674 #include <sound/rawmidi.h>
79675 #include <sound/control.h>
79676 +#include <asm/local.h>
79677
79678 #define CARD_NAME "Miditerminal 4140"
79679 #define DRIVER_NAME "MTS64"
79680 @@ -67,7 +68,7 @@ struct mts64 {
79681 struct pardevice *pardev;
79682 int pardev_claimed;
79683
79684 - int open_count;
79685 + local_t open_count;
79686 int current_midi_output_port;
79687 int current_midi_input_port;
79688 u8 mode[MTS64_NUM_INPUT_PORTS];
79689 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79690 {
79691 struct mts64 *mts = substream->rmidi->private_data;
79692
79693 - if (mts->open_count == 0) {
79694 + if (local_read(&mts->open_count) == 0) {
79695 /* We don't need a spinlock here, because this is just called
79696 if the device has not been opened before.
79697 So there aren't any IRQs from the device */
79698 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
79699
79700 msleep(50);
79701 }
79702 - ++(mts->open_count);
79703 + local_inc(&mts->open_count);
79704
79705 return 0;
79706 }
79707 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79708 struct mts64 *mts = substream->rmidi->private_data;
79709 unsigned long flags;
79710
79711 - --(mts->open_count);
79712 - if (mts->open_count == 0) {
79713 + if (local_dec_return(&mts->open_count) == 0) {
79714 /* We need the spinlock_irqsave here because we can still
79715 have IRQs at this point */
79716 spin_lock_irqsave(&mts->lock, flags);
79717 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
79718
79719 msleep(500);
79720
79721 - } else if (mts->open_count < 0)
79722 - mts->open_count = 0;
79723 + } else if (local_read(&mts->open_count) < 0)
79724 + local_set(&mts->open_count, 0);
79725
79726 return 0;
79727 }
79728 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
79729 index b953fb4..1999c01 100644
79730 --- a/sound/drivers/opl4/opl4_lib.c
79731 +++ b/sound/drivers/opl4/opl4_lib.c
79732 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
79733 MODULE_DESCRIPTION("OPL4 driver");
79734 MODULE_LICENSE("GPL");
79735
79736 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
79737 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
79738 {
79739 int timeout = 10;
79740 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
79741 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
79742 index 3e32bd3..46fc152 100644
79743 --- a/sound/drivers/portman2x4.c
79744 +++ b/sound/drivers/portman2x4.c
79745 @@ -48,6 +48,7 @@
79746 #include <sound/initval.h>
79747 #include <sound/rawmidi.h>
79748 #include <sound/control.h>
79749 +#include <asm/local.h>
79750
79751 #define CARD_NAME "Portman 2x4"
79752 #define DRIVER_NAME "portman"
79753 @@ -85,7 +86,7 @@ struct portman {
79754 struct pardevice *pardev;
79755 int pardev_claimed;
79756
79757 - int open_count;
79758 + local_t open_count;
79759 int mode[PORTMAN_NUM_INPUT_PORTS];
79760 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
79761 };
79762 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
79763 index 87657dd..a8268d4 100644
79764 --- a/sound/firewire/amdtp.c
79765 +++ b/sound/firewire/amdtp.c
79766 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
79767 ptr = s->pcm_buffer_pointer + data_blocks;
79768 if (ptr >= pcm->runtime->buffer_size)
79769 ptr -= pcm->runtime->buffer_size;
79770 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
79771 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
79772
79773 s->pcm_period_pointer += data_blocks;
79774 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
79775 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
79776 */
79777 void amdtp_out_stream_update(struct amdtp_out_stream *s)
79778 {
79779 - ACCESS_ONCE(s->source_node_id_field) =
79780 + ACCESS_ONCE_RW(s->source_node_id_field) =
79781 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
79782 }
79783 EXPORT_SYMBOL(amdtp_out_stream_update);
79784 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
79785 index 537a9cb..8e8c8e9 100644
79786 --- a/sound/firewire/amdtp.h
79787 +++ b/sound/firewire/amdtp.h
79788 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
79789 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
79790 struct snd_pcm_substream *pcm)
79791 {
79792 - ACCESS_ONCE(s->pcm) = pcm;
79793 + ACCESS_ONCE_RW(s->pcm) = pcm;
79794 }
79795
79796 /**
79797 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
79798 index cd094ec..eca1277 100644
79799 --- a/sound/firewire/isight.c
79800 +++ b/sound/firewire/isight.c
79801 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
79802 ptr += count;
79803 if (ptr >= runtime->buffer_size)
79804 ptr -= runtime->buffer_size;
79805 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
79806 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
79807
79808 isight->period_counter += count;
79809 if (isight->period_counter >= runtime->period_size) {
79810 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
79811 if (err < 0)
79812 return err;
79813
79814 - ACCESS_ONCE(isight->pcm_active) = true;
79815 + ACCESS_ONCE_RW(isight->pcm_active) = true;
79816
79817 return 0;
79818 }
79819 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
79820 {
79821 struct isight *isight = substream->private_data;
79822
79823 - ACCESS_ONCE(isight->pcm_active) = false;
79824 + ACCESS_ONCE_RW(isight->pcm_active) = false;
79825
79826 mutex_lock(&isight->mutex);
79827 isight_stop_streaming(isight);
79828 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
79829
79830 switch (cmd) {
79831 case SNDRV_PCM_TRIGGER_START:
79832 - ACCESS_ONCE(isight->pcm_running) = true;
79833 + ACCESS_ONCE_RW(isight->pcm_running) = true;
79834 break;
79835 case SNDRV_PCM_TRIGGER_STOP:
79836 - ACCESS_ONCE(isight->pcm_running) = false;
79837 + ACCESS_ONCE_RW(isight->pcm_running) = false;
79838 break;
79839 default:
79840 return -EINVAL;
79841 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
79842 index 7bd5e33..1fcab12 100644
79843 --- a/sound/isa/cmi8330.c
79844 +++ b/sound/isa/cmi8330.c
79845 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
79846
79847 struct snd_pcm *pcm;
79848 struct snd_cmi8330_stream {
79849 - struct snd_pcm_ops ops;
79850 + snd_pcm_ops_no_const ops;
79851 snd_pcm_open_callback_t open;
79852 void *private_data; /* sb or wss */
79853 } streams[2];
79854 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
79855 index 733b014..56ce96f 100644
79856 --- a/sound/oss/sb_audio.c
79857 +++ b/sound/oss/sb_audio.c
79858 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
79859 buf16 = (signed short *)(localbuf + localoffs);
79860 while (c)
79861 {
79862 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79863 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
79864 if (copy_from_user(lbuf8,
79865 userbuf+useroffs + p,
79866 locallen))
79867 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
79868 index 09d4648..cf234c7 100644
79869 --- a/sound/oss/swarm_cs4297a.c
79870 +++ b/sound/oss/swarm_cs4297a.c
79871 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
79872 {
79873 struct cs4297a_state *s;
79874 u32 pwr, id;
79875 - mm_segment_t fs;
79876 int rval;
79877 #ifndef CONFIG_BCM_CS4297A_CSWARM
79878 u64 cfg;
79879 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
79880 if (!rval) {
79881 char *sb1250_duart_present;
79882
79883 +#if 0
79884 + mm_segment_t fs;
79885 fs = get_fs();
79886 set_fs(KERNEL_DS);
79887 -#if 0
79888 val = SOUND_MASK_LINE;
79889 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
79890 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
79891 val = initvol[i].vol;
79892 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
79893 }
79894 + set_fs(fs);
79895 // cs4297a_write_ac97(s, 0x18, 0x0808);
79896 #else
79897 // cs4297a_write_ac97(s, 0x5e, 0x180);
79898 cs4297a_write_ac97(s, 0x02, 0x0808);
79899 cs4297a_write_ac97(s, 0x18, 0x0808);
79900 #endif
79901 - set_fs(fs);
79902
79903 list_add(&s->list, &cs4297a_devs);
79904
79905 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
79906 index f0f1943..8e1f96c 100644
79907 --- a/sound/pci/hda/hda_codec.h
79908 +++ b/sound/pci/hda/hda_codec.h
79909 @@ -611,7 +611,7 @@ struct hda_bus_ops {
79910 /* notify power-up/down from codec to controller */
79911 void (*pm_notify)(struct hda_bus *bus);
79912 #endif
79913 -};
79914 +} __no_const;
79915
79916 /* template to pass to the bus constructor */
79917 struct hda_bus_template {
79918 @@ -713,6 +713,7 @@ struct hda_codec_ops {
79919 #endif
79920 void (*reboot_notify)(struct hda_codec *codec);
79921 };
79922 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
79923
79924 /* record for amp information cache */
79925 struct hda_cache_head {
79926 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
79927 struct snd_pcm_substream *substream);
79928 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
79929 struct snd_pcm_substream *substream);
79930 -};
79931 +} __no_const;
79932
79933 /* PCM information for each substream */
79934 struct hda_pcm_stream {
79935 @@ -801,7 +802,7 @@ struct hda_codec {
79936 const char *modelname; /* model name for preset */
79937
79938 /* set by patch */
79939 - struct hda_codec_ops patch_ops;
79940 + hda_codec_ops_no_const patch_ops;
79941
79942 /* PCM to create, set by patch_ops.build_pcms callback */
79943 unsigned int num_pcms;
79944 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
79945 index 0da778a..bc38b84 100644
79946 --- a/sound/pci/ice1712/ice1712.h
79947 +++ b/sound/pci/ice1712/ice1712.h
79948 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
79949 unsigned int mask_flags; /* total mask bits */
79950 struct snd_akm4xxx_ops {
79951 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
79952 - } ops;
79953 + } __no_const ops;
79954 };
79955
79956 struct snd_ice1712_spdif {
79957 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
79958 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79959 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79960 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
79961 - } ops;
79962 + } __no_const ops;
79963 };
79964
79965
79966 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
79967 index 12a9a2b..2b6138f 100644
79968 --- a/sound/pci/ymfpci/ymfpci_main.c
79969 +++ b/sound/pci/ymfpci/ymfpci_main.c
79970 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
79971 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
79972 break;
79973 }
79974 - if (atomic_read(&chip->interrupt_sleep_count)) {
79975 - atomic_set(&chip->interrupt_sleep_count, 0);
79976 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79977 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79978 wake_up(&chip->interrupt_sleep);
79979 }
79980 __end:
79981 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
79982 continue;
79983 init_waitqueue_entry(&wait, current);
79984 add_wait_queue(&chip->interrupt_sleep, &wait);
79985 - atomic_inc(&chip->interrupt_sleep_count);
79986 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
79987 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
79988 remove_wait_queue(&chip->interrupt_sleep, &wait);
79989 }
79990 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
79991 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
79992 spin_unlock(&chip->reg_lock);
79993
79994 - if (atomic_read(&chip->interrupt_sleep_count)) {
79995 - atomic_set(&chip->interrupt_sleep_count, 0);
79996 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
79997 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
79998 wake_up(&chip->interrupt_sleep);
79999 }
80000 }
80001 @@ -2389,7 +2389,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
80002 spin_lock_init(&chip->reg_lock);
80003 spin_lock_init(&chip->voice_lock);
80004 init_waitqueue_head(&chip->interrupt_sleep);
80005 - atomic_set(&chip->interrupt_sleep_count, 0);
80006 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
80007 chip->card = card;
80008 chip->pci = pci;
80009 chip->irq = -1;
80010 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
80011 index cdc860a..db34a93 100644
80012 --- a/sound/soc/soc-pcm.c
80013 +++ b/sound/soc/soc-pcm.c
80014 @@ -605,7 +605,7 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
80015 struct snd_soc_platform *platform = rtd->platform;
80016 struct snd_soc_dai *codec_dai = rtd->codec_dai;
80017 struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
80018 - struct snd_pcm_ops *soc_pcm_ops = &rtd->ops;
80019 + snd_pcm_ops_no_const *soc_pcm_ops = &rtd->ops;
80020 struct snd_pcm *pcm;
80021 char new_name[64];
80022 int ret = 0, playback = 0, capture = 0;
80023 diff --git a/sound/usb/card.h b/sound/usb/card.h
80024 index da5fa1a..113cd02 100644
80025 --- a/sound/usb/card.h
80026 +++ b/sound/usb/card.h
80027 @@ -45,6 +45,7 @@ struct snd_urb_ops {
80028 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80029 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
80030 };
80031 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
80032
80033 struct snd_usb_substream {
80034 struct snd_usb_stream *stream;
80035 @@ -94,7 +95,7 @@ struct snd_usb_substream {
80036 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
80037 spinlock_t lock;
80038
80039 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
80040 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
80041 int last_frame_number; /* stored frame number */
80042 int last_delay; /* stored delay */
80043 };
80044 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
80045 new file mode 100644
80046 index 0000000..ca64170
80047 --- /dev/null
80048 +++ b/tools/gcc/Makefile
80049 @@ -0,0 +1,26 @@
80050 +#CC := gcc
80051 +#PLUGIN_SOURCE_FILES := pax_plugin.c
80052 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
80053 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
80054 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
80055 +
80056 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
80057 +CFLAGS_size_overflow_plugin.o := -Wno-missing-initializer
80058 +
80059 +hostlibs-y := constify_plugin.so
80060 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
80061 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
80062 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
80063 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
80064 +hostlibs-y += colorize_plugin.so
80065 +hostlibs-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
80066 +
80067 +always := $(hostlibs-y)
80068 +
80069 +constify_plugin-objs := constify_plugin.o
80070 +stackleak_plugin-objs := stackleak_plugin.o
80071 +kallocstat_plugin-objs := kallocstat_plugin.o
80072 +kernexec_plugin-objs := kernexec_plugin.o
80073 +checker_plugin-objs := checker_plugin.o
80074 +colorize_plugin-objs := colorize_plugin.o
80075 +size_overflow_plugin-objs := size_overflow_plugin.o
80076 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
80077 new file mode 100644
80078 index 0000000..d41b5af
80079 --- /dev/null
80080 +++ b/tools/gcc/checker_plugin.c
80081 @@ -0,0 +1,171 @@
80082 +/*
80083 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80084 + * Licensed under the GPL v2
80085 + *
80086 + * Note: the choice of the license means that the compilation process is
80087 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80088 + * but for the kernel it doesn't matter since it doesn't link against
80089 + * any of the gcc libraries
80090 + *
80091 + * gcc plugin to implement various sparse (source code checker) features
80092 + *
80093 + * TODO:
80094 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
80095 + *
80096 + * BUGS:
80097 + * - none known
80098 + */
80099 +#include "gcc-plugin.h"
80100 +#include "config.h"
80101 +#include "system.h"
80102 +#include "coretypes.h"
80103 +#include "tree.h"
80104 +#include "tree-pass.h"
80105 +#include "flags.h"
80106 +#include "intl.h"
80107 +#include "toplev.h"
80108 +#include "plugin.h"
80109 +//#include "expr.h" where are you...
80110 +#include "diagnostic.h"
80111 +#include "plugin-version.h"
80112 +#include "tm.h"
80113 +#include "function.h"
80114 +#include "basic-block.h"
80115 +#include "gimple.h"
80116 +#include "rtl.h"
80117 +#include "emit-rtl.h"
80118 +#include "tree-flow.h"
80119 +#include "target.h"
80120 +
80121 +extern void c_register_addr_space (const char *str, addr_space_t as);
80122 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
80123 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
80124 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
80125 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
80126 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
80127 +
80128 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80129 +extern rtx emit_move_insn(rtx x, rtx y);
80130 +
80131 +int plugin_is_GPL_compatible;
80132 +
80133 +static struct plugin_info checker_plugin_info = {
80134 + .version = "201111150100",
80135 +};
80136 +
80137 +#define ADDR_SPACE_KERNEL 0
80138 +#define ADDR_SPACE_FORCE_KERNEL 1
80139 +#define ADDR_SPACE_USER 2
80140 +#define ADDR_SPACE_FORCE_USER 3
80141 +#define ADDR_SPACE_IOMEM 0
80142 +#define ADDR_SPACE_FORCE_IOMEM 0
80143 +#define ADDR_SPACE_PERCPU 0
80144 +#define ADDR_SPACE_FORCE_PERCPU 0
80145 +#define ADDR_SPACE_RCU 0
80146 +#define ADDR_SPACE_FORCE_RCU 0
80147 +
80148 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
80149 +{
80150 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
80151 +}
80152 +
80153 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
80154 +{
80155 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
80156 +}
80157 +
80158 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
80159 +{
80160 + return default_addr_space_valid_pointer_mode(mode, as);
80161 +}
80162 +
80163 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
80164 +{
80165 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
80166 +}
80167 +
80168 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
80169 +{
80170 + return default_addr_space_legitimize_address(x, oldx, mode, as);
80171 +}
80172 +
80173 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
80174 +{
80175 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
80176 + return true;
80177 +
80178 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
80179 + return true;
80180 +
80181 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
80182 + return true;
80183 +
80184 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
80185 + return true;
80186 +
80187 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
80188 + return true;
80189 +
80190 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
80191 + return true;
80192 +
80193 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
80194 + return true;
80195 +
80196 + return subset == superset;
80197 +}
80198 +
80199 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
80200 +{
80201 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
80202 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
80203 +
80204 + return op;
80205 +}
80206 +
80207 +static void register_checker_address_spaces(void *event_data, void *data)
80208 +{
80209 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
80210 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
80211 + c_register_addr_space("__user", ADDR_SPACE_USER);
80212 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
80213 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
80214 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
80215 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
80216 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
80217 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
80218 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
80219 +
80220 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
80221 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
80222 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
80223 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
80224 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
80225 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
80226 + targetm.addr_space.convert = checker_addr_space_convert;
80227 +}
80228 +
80229 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80230 +{
80231 + const char * const plugin_name = plugin_info->base_name;
80232 + const int argc = plugin_info->argc;
80233 + const struct plugin_argument * const argv = plugin_info->argv;
80234 + int i;
80235 +
80236 + if (!plugin_default_version_check(version, &gcc_version)) {
80237 + error(G_("incompatible gcc/plugin versions"));
80238 + return 1;
80239 + }
80240 +
80241 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
80242 +
80243 + for (i = 0; i < argc; ++i)
80244 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80245 +
80246 + if (TARGET_64BIT == 0)
80247 + return 0;
80248 +
80249 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
80250 +
80251 + return 0;
80252 +}
80253 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
80254 new file mode 100644
80255 index 0000000..ee950d0
80256 --- /dev/null
80257 +++ b/tools/gcc/colorize_plugin.c
80258 @@ -0,0 +1,147 @@
80259 +/*
80260 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
80261 + * Licensed under the GPL v2
80262 + *
80263 + * Note: the choice of the license means that the compilation process is
80264 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80265 + * but for the kernel it doesn't matter since it doesn't link against
80266 + * any of the gcc libraries
80267 + *
80268 + * gcc plugin to colorize diagnostic output
80269 + *
80270 + */
80271 +
80272 +#include "gcc-plugin.h"
80273 +#include "config.h"
80274 +#include "system.h"
80275 +#include "coretypes.h"
80276 +#include "tree.h"
80277 +#include "tree-pass.h"
80278 +#include "flags.h"
80279 +#include "intl.h"
80280 +#include "toplev.h"
80281 +#include "plugin.h"
80282 +#include "diagnostic.h"
80283 +#include "plugin-version.h"
80284 +#include "tm.h"
80285 +
80286 +int plugin_is_GPL_compatible;
80287 +
80288 +static struct plugin_info colorize_plugin_info = {
80289 + .version = "201203092200",
80290 +};
80291 +
80292 +#define GREEN "\033[32m\033[2m"
80293 +#define LIGHTGREEN "\033[32m\033[1m"
80294 +#define YELLOW "\033[33m\033[2m"
80295 +#define LIGHTYELLOW "\033[33m\033[1m"
80296 +#define RED "\033[31m\033[2m"
80297 +#define LIGHTRED "\033[31m\033[1m"
80298 +#define BLUE "\033[34m\033[2m"
80299 +#define LIGHTBLUE "\033[34m\033[1m"
80300 +#define BRIGHT "\033[m\033[1m"
80301 +#define NORMAL "\033[m"
80302 +
80303 +static diagnostic_starter_fn old_starter;
80304 +static diagnostic_finalizer_fn old_finalizer;
80305 +
80306 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80307 +{
80308 + const char *color;
80309 + char *newprefix;
80310 +
80311 + switch (diagnostic->kind) {
80312 + case DK_NOTE:
80313 + color = LIGHTBLUE;
80314 + break;
80315 +
80316 + case DK_PEDWARN:
80317 + case DK_WARNING:
80318 + color = LIGHTYELLOW;
80319 + break;
80320 +
80321 + case DK_ERROR:
80322 + case DK_FATAL:
80323 + case DK_ICE:
80324 + case DK_PERMERROR:
80325 + case DK_SORRY:
80326 + color = LIGHTRED;
80327 + break;
80328 +
80329 + default:
80330 + color = NORMAL;
80331 + }
80332 +
80333 + old_starter(context, diagnostic);
80334 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
80335 + return;
80336 + pp_destroy_prefix(context->printer);
80337 + pp_set_prefix(context->printer, newprefix);
80338 +}
80339 +
80340 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
80341 +{
80342 + old_finalizer(context, diagnostic);
80343 +}
80344 +
80345 +static void colorize_arm(void)
80346 +{
80347 + old_starter = diagnostic_starter(global_dc);
80348 + old_finalizer = diagnostic_finalizer(global_dc);
80349 +
80350 + diagnostic_starter(global_dc) = start_colorize;
80351 + diagnostic_finalizer(global_dc) = finalize_colorize;
80352 +}
80353 +
80354 +static unsigned int execute_colorize_rearm(void)
80355 +{
80356 + if (diagnostic_starter(global_dc) == start_colorize)
80357 + return 0;
80358 +
80359 + colorize_arm();
80360 + return 0;
80361 +}
80362 +
80363 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
80364 + .pass = {
80365 + .type = SIMPLE_IPA_PASS,
80366 + .name = "colorize_rearm",
80367 + .gate = NULL,
80368 + .execute = execute_colorize_rearm,
80369 + .sub = NULL,
80370 + .next = NULL,
80371 + .static_pass_number = 0,
80372 + .tv_id = TV_NONE,
80373 + .properties_required = 0,
80374 + .properties_provided = 0,
80375 + .properties_destroyed = 0,
80376 + .todo_flags_start = 0,
80377 + .todo_flags_finish = 0
80378 + }
80379 +};
80380 +
80381 +static void colorize_start_unit(void *gcc_data, void *user_data)
80382 +{
80383 + colorize_arm();
80384 +}
80385 +
80386 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80387 +{
80388 + const char * const plugin_name = plugin_info->base_name;
80389 + struct register_pass_info colorize_rearm_pass_info = {
80390 + .pass = &pass_ipa_colorize_rearm.pass,
80391 + .reference_pass_name = "*free_lang_data",
80392 + .ref_pass_instance_number = 0,
80393 + .pos_op = PASS_POS_INSERT_AFTER
80394 + };
80395 +
80396 + if (!plugin_default_version_check(version, &gcc_version)) {
80397 + error(G_("incompatible gcc/plugin versions"));
80398 + return 1;
80399 + }
80400 +
80401 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
80402 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
80403 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
80404 + return 0;
80405 +}
80406 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
80407 new file mode 100644
80408 index 0000000..89b7f56
80409 --- /dev/null
80410 +++ b/tools/gcc/constify_plugin.c
80411 @@ -0,0 +1,328 @@
80412 +/*
80413 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
80414 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
80415 + * Licensed under the GPL v2, or (at your option) v3
80416 + *
80417 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
80418 + *
80419 + * Homepage:
80420 + * http://www.grsecurity.net/~ephox/const_plugin/
80421 + *
80422 + * Usage:
80423 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
80424 + * $ gcc -fplugin=constify_plugin.so test.c -O2
80425 + */
80426 +
80427 +#include "gcc-plugin.h"
80428 +#include "config.h"
80429 +#include "system.h"
80430 +#include "coretypes.h"
80431 +#include "tree.h"
80432 +#include "tree-pass.h"
80433 +#include "flags.h"
80434 +#include "intl.h"
80435 +#include "toplev.h"
80436 +#include "plugin.h"
80437 +#include "diagnostic.h"
80438 +#include "plugin-version.h"
80439 +#include "tm.h"
80440 +#include "function.h"
80441 +#include "basic-block.h"
80442 +#include "gimple.h"
80443 +#include "rtl.h"
80444 +#include "emit-rtl.h"
80445 +#include "tree-flow.h"
80446 +
80447 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
80448 +
80449 +int plugin_is_GPL_compatible;
80450 +
80451 +static struct plugin_info const_plugin_info = {
80452 + .version = "201205300030",
80453 + .help = "no-constify\tturn off constification\n",
80454 +};
80455 +
80456 +static void deconstify_tree(tree node);
80457 +
80458 +static void deconstify_type(tree type)
80459 +{
80460 + tree field;
80461 +
80462 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
80463 + tree type = TREE_TYPE(field);
80464 +
80465 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80466 + continue;
80467 + if (!TYPE_READONLY(type))
80468 + continue;
80469 +
80470 + deconstify_tree(field);
80471 + }
80472 + TYPE_READONLY(type) = 0;
80473 + C_TYPE_FIELDS_READONLY(type) = 0;
80474 +}
80475 +
80476 +static void deconstify_tree(tree node)
80477 +{
80478 + tree old_type, new_type, field;
80479 +
80480 + old_type = TREE_TYPE(node);
80481 +
80482 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
80483 +
80484 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
80485 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
80486 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
80487 + DECL_FIELD_CONTEXT(field) = new_type;
80488 +
80489 + deconstify_type(new_type);
80490 +
80491 + TREE_READONLY(node) = 0;
80492 + TREE_TYPE(node) = new_type;
80493 +}
80494 +
80495 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80496 +{
80497 + tree type;
80498 +
80499 + *no_add_attrs = true;
80500 + if (TREE_CODE(*node) == FUNCTION_DECL) {
80501 + error("%qE attribute does not apply to functions", name);
80502 + return NULL_TREE;
80503 + }
80504 +
80505 + if (TREE_CODE(*node) == VAR_DECL) {
80506 + error("%qE attribute does not apply to variables", name);
80507 + return NULL_TREE;
80508 + }
80509 +
80510 + if (TYPE_P(*node)) {
80511 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
80512 + *no_add_attrs = false;
80513 + else
80514 + error("%qE attribute applies to struct and union types only", name);
80515 + return NULL_TREE;
80516 + }
80517 +
80518 + type = TREE_TYPE(*node);
80519 +
80520 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
80521 + error("%qE attribute applies to struct and union types only", name);
80522 + return NULL_TREE;
80523 + }
80524 +
80525 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
80526 + error("%qE attribute is already applied to the type", name);
80527 + return NULL_TREE;
80528 + }
80529 +
80530 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
80531 + error("%qE attribute used on type that is not constified", name);
80532 + return NULL_TREE;
80533 + }
80534 +
80535 + if (TREE_CODE(*node) == TYPE_DECL) {
80536 + deconstify_tree(*node);
80537 + return NULL_TREE;
80538 + }
80539 +
80540 + return NULL_TREE;
80541 +}
80542 +
80543 +static void constify_type(tree type)
80544 +{
80545 + TYPE_READONLY(type) = 1;
80546 + C_TYPE_FIELDS_READONLY(type) = 1;
80547 +}
80548 +
80549 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
80550 +{
80551 + *no_add_attrs = true;
80552 + if (!TYPE_P(*node)) {
80553 + error("%qE attribute applies to types only", name);
80554 + return NULL_TREE;
80555 + }
80556 +
80557 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
80558 + error("%qE attribute applies to struct and union types only", name);
80559 + return NULL_TREE;
80560 + }
80561 +
80562 + *no_add_attrs = false;
80563 + constify_type(*node);
80564 + return NULL_TREE;
80565 +}
80566 +
80567 +static struct attribute_spec no_const_attr = {
80568 + .name = "no_const",
80569 + .min_length = 0,
80570 + .max_length = 0,
80571 + .decl_required = false,
80572 + .type_required = false,
80573 + .function_type_required = false,
80574 + .handler = handle_no_const_attribute,
80575 +#if BUILDING_GCC_VERSION >= 4007
80576 + .affects_type_identity = true
80577 +#endif
80578 +};
80579 +
80580 +static struct attribute_spec do_const_attr = {
80581 + .name = "do_const",
80582 + .min_length = 0,
80583 + .max_length = 0,
80584 + .decl_required = false,
80585 + .type_required = false,
80586 + .function_type_required = false,
80587 + .handler = handle_do_const_attribute,
80588 +#if BUILDING_GCC_VERSION >= 4007
80589 + .affects_type_identity = true
80590 +#endif
80591 +};
80592 +
80593 +static void register_attributes(void *event_data, void *data)
80594 +{
80595 + register_attribute(&no_const_attr);
80596 + register_attribute(&do_const_attr);
80597 +}
80598 +
80599 +static bool is_fptr(tree field)
80600 +{
80601 + tree ptr = TREE_TYPE(field);
80602 +
80603 + if (TREE_CODE(ptr) != POINTER_TYPE)
80604 + return false;
80605 +
80606 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
80607 +}
80608 +
80609 +static bool walk_struct(tree node)
80610 +{
80611 + tree field;
80612 +
80613 + if (TYPE_FIELDS(node) == NULL_TREE)
80614 + return false;
80615 +
80616 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
80617 + gcc_assert(!TYPE_READONLY(node));
80618 + deconstify_type(node);
80619 + return false;
80620 + }
80621 +
80622 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
80623 + tree type = TREE_TYPE(field);
80624 + enum tree_code code = TREE_CODE(type);
80625 + if (code == RECORD_TYPE || code == UNION_TYPE) {
80626 + if (!(walk_struct(type)))
80627 + return false;
80628 + } else if (!is_fptr(field) && !TREE_READONLY(field))
80629 + return false;
80630 + }
80631 + return true;
80632 +}
80633 +
80634 +static void finish_type(void *event_data, void *data)
80635 +{
80636 + tree type = (tree)event_data;
80637 +
80638 + if (type == NULL_TREE)
80639 + return;
80640 +
80641 + if (TYPE_READONLY(type))
80642 + return;
80643 +
80644 + if (walk_struct(type))
80645 + constify_type(type);
80646 +}
80647 +
80648 +static unsigned int check_local_variables(void);
80649 +
80650 +struct gimple_opt_pass pass_local_variable = {
80651 + {
80652 + .type = GIMPLE_PASS,
80653 + .name = "check_local_variables",
80654 + .gate = NULL,
80655 + .execute = check_local_variables,
80656 + .sub = NULL,
80657 + .next = NULL,
80658 + .static_pass_number = 0,
80659 + .tv_id = TV_NONE,
80660 + .properties_required = 0,
80661 + .properties_provided = 0,
80662 + .properties_destroyed = 0,
80663 + .todo_flags_start = 0,
80664 + .todo_flags_finish = 0
80665 + }
80666 +};
80667 +
80668 +static unsigned int check_local_variables(void)
80669 +{
80670 + tree var;
80671 + referenced_var_iterator rvi;
80672 +
80673 +#if BUILDING_GCC_VERSION == 4005
80674 + FOR_EACH_REFERENCED_VAR(var, rvi) {
80675 +#else
80676 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
80677 +#endif
80678 + tree type = TREE_TYPE(var);
80679 +
80680 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
80681 + continue;
80682 +
80683 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
80684 + continue;
80685 +
80686 + if (!TYPE_READONLY(type))
80687 + continue;
80688 +
80689 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
80690 +// continue;
80691 +
80692 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
80693 +// continue;
80694 +
80695 + if (walk_struct(type)) {
80696 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
80697 + return 1;
80698 + }
80699 + }
80700 + return 0;
80701 +}
80702 +
80703 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80704 +{
80705 + const char * const plugin_name = plugin_info->base_name;
80706 + const int argc = plugin_info->argc;
80707 + const struct plugin_argument * const argv = plugin_info->argv;
80708 + int i;
80709 + bool constify = true;
80710 +
80711 + struct register_pass_info local_variable_pass_info = {
80712 + .pass = &pass_local_variable.pass,
80713 + .reference_pass_name = "*referenced_vars",
80714 + .ref_pass_instance_number = 0,
80715 + .pos_op = PASS_POS_INSERT_AFTER
80716 + };
80717 +
80718 + if (!plugin_default_version_check(version, &gcc_version)) {
80719 + error(G_("incompatible gcc/plugin versions"));
80720 + return 1;
80721 + }
80722 +
80723 + for (i = 0; i < argc; ++i) {
80724 + if (!(strcmp(argv[i].key, "no-constify"))) {
80725 + constify = false;
80726 + continue;
80727 + }
80728 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
80729 + }
80730 +
80731 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
80732 + if (constify) {
80733 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
80734 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
80735 + }
80736 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
80737 +
80738 + return 0;
80739 +}
80740 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
80741 new file mode 100644
80742 index 0000000..a5eabce
80743 --- /dev/null
80744 +++ b/tools/gcc/kallocstat_plugin.c
80745 @@ -0,0 +1,167 @@
80746 +/*
80747 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80748 + * Licensed under the GPL v2
80749 + *
80750 + * Note: the choice of the license means that the compilation process is
80751 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80752 + * but for the kernel it doesn't matter since it doesn't link against
80753 + * any of the gcc libraries
80754 + *
80755 + * gcc plugin to find the distribution of k*alloc sizes
80756 + *
80757 + * TODO:
80758 + *
80759 + * BUGS:
80760 + * - none known
80761 + */
80762 +#include "gcc-plugin.h"
80763 +#include "config.h"
80764 +#include "system.h"
80765 +#include "coretypes.h"
80766 +#include "tree.h"
80767 +#include "tree-pass.h"
80768 +#include "flags.h"
80769 +#include "intl.h"
80770 +#include "toplev.h"
80771 +#include "plugin.h"
80772 +//#include "expr.h" where are you...
80773 +#include "diagnostic.h"
80774 +#include "plugin-version.h"
80775 +#include "tm.h"
80776 +#include "function.h"
80777 +#include "basic-block.h"
80778 +#include "gimple.h"
80779 +#include "rtl.h"
80780 +#include "emit-rtl.h"
80781 +
80782 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80783 +
80784 +int plugin_is_GPL_compatible;
80785 +
80786 +static const char * const kalloc_functions[] = {
80787 + "__kmalloc",
80788 + "kmalloc",
80789 + "kmalloc_large",
80790 + "kmalloc_node",
80791 + "kmalloc_order",
80792 + "kmalloc_order_trace",
80793 + "kmalloc_slab",
80794 + "kzalloc",
80795 + "kzalloc_node",
80796 +};
80797 +
80798 +static struct plugin_info kallocstat_plugin_info = {
80799 + .version = "201111150100",
80800 +};
80801 +
80802 +static unsigned int execute_kallocstat(void);
80803 +
80804 +static struct gimple_opt_pass kallocstat_pass = {
80805 + .pass = {
80806 + .type = GIMPLE_PASS,
80807 + .name = "kallocstat",
80808 + .gate = NULL,
80809 + .execute = execute_kallocstat,
80810 + .sub = NULL,
80811 + .next = NULL,
80812 + .static_pass_number = 0,
80813 + .tv_id = TV_NONE,
80814 + .properties_required = 0,
80815 + .properties_provided = 0,
80816 + .properties_destroyed = 0,
80817 + .todo_flags_start = 0,
80818 + .todo_flags_finish = 0
80819 + }
80820 +};
80821 +
80822 +static bool is_kalloc(const char *fnname)
80823 +{
80824 + size_t i;
80825 +
80826 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
80827 + if (!strcmp(fnname, kalloc_functions[i]))
80828 + return true;
80829 + return false;
80830 +}
80831 +
80832 +static unsigned int execute_kallocstat(void)
80833 +{
80834 + basic_block bb;
80835 +
80836 + // 1. loop through BBs and GIMPLE statements
80837 + FOR_EACH_BB(bb) {
80838 + gimple_stmt_iterator gsi;
80839 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
80840 + // gimple match:
80841 + tree fndecl, size;
80842 + gimple call_stmt;
80843 + const char *fnname;
80844 +
80845 + // is it a call
80846 + call_stmt = gsi_stmt(gsi);
80847 + if (!is_gimple_call(call_stmt))
80848 + continue;
80849 + fndecl = gimple_call_fndecl(call_stmt);
80850 + if (fndecl == NULL_TREE)
80851 + continue;
80852 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
80853 + continue;
80854 +
80855 + // is it a call to k*alloc
80856 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
80857 + if (!is_kalloc(fnname))
80858 + continue;
80859 +
80860 + // is the size arg the result of a simple const assignment
80861 + size = gimple_call_arg(call_stmt, 0);
80862 + while (true) {
80863 + gimple def_stmt;
80864 + expanded_location xloc;
80865 + size_t size_val;
80866 +
80867 + if (TREE_CODE(size) != SSA_NAME)
80868 + break;
80869 + def_stmt = SSA_NAME_DEF_STMT(size);
80870 + if (!def_stmt || !is_gimple_assign(def_stmt))
80871 + break;
80872 + if (gimple_num_ops(def_stmt) != 2)
80873 + break;
80874 + size = gimple_assign_rhs1(def_stmt);
80875 + if (!TREE_CONSTANT(size))
80876 + continue;
80877 + xloc = expand_location(gimple_location(def_stmt));
80878 + if (!xloc.file)
80879 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
80880 + size_val = TREE_INT_CST_LOW(size);
80881 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
80882 + break;
80883 + }
80884 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
80885 +//debug_tree(gimple_call_fn(call_stmt));
80886 +//print_node(stderr, "pax", fndecl, 4);
80887 + }
80888 + }
80889 +
80890 + return 0;
80891 +}
80892 +
80893 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
80894 +{
80895 + const char * const plugin_name = plugin_info->base_name;
80896 + struct register_pass_info kallocstat_pass_info = {
80897 + .pass = &kallocstat_pass.pass,
80898 + .reference_pass_name = "ssa",
80899 + .ref_pass_instance_number = 0,
80900 + .pos_op = PASS_POS_INSERT_AFTER
80901 + };
80902 +
80903 + if (!plugin_default_version_check(version, &gcc_version)) {
80904 + error(G_("incompatible gcc/plugin versions"));
80905 + return 1;
80906 + }
80907 +
80908 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
80909 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
80910 +
80911 + return 0;
80912 +}
80913 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
80914 new file mode 100644
80915 index 0000000..d8a8da2
80916 --- /dev/null
80917 +++ b/tools/gcc/kernexec_plugin.c
80918 @@ -0,0 +1,427 @@
80919 +/*
80920 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
80921 + * Licensed under the GPL v2
80922 + *
80923 + * Note: the choice of the license means that the compilation process is
80924 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
80925 + * but for the kernel it doesn't matter since it doesn't link against
80926 + * any of the gcc libraries
80927 + *
80928 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
80929 + *
80930 + * TODO:
80931 + *
80932 + * BUGS:
80933 + * - none known
80934 + */
80935 +#include "gcc-plugin.h"
80936 +#include "config.h"
80937 +#include "system.h"
80938 +#include "coretypes.h"
80939 +#include "tree.h"
80940 +#include "tree-pass.h"
80941 +#include "flags.h"
80942 +#include "intl.h"
80943 +#include "toplev.h"
80944 +#include "plugin.h"
80945 +//#include "expr.h" where are you...
80946 +#include "diagnostic.h"
80947 +#include "plugin-version.h"
80948 +#include "tm.h"
80949 +#include "function.h"
80950 +#include "basic-block.h"
80951 +#include "gimple.h"
80952 +#include "rtl.h"
80953 +#include "emit-rtl.h"
80954 +#include "tree-flow.h"
80955 +
80956 +extern void print_gimple_stmt(FILE *, gimple, int, int);
80957 +extern rtx emit_move_insn(rtx x, rtx y);
80958 +
80959 +int plugin_is_GPL_compatible;
80960 +
80961 +static struct plugin_info kernexec_plugin_info = {
80962 + .version = "201111291120",
80963 + .help = "method=[bts|or]\tinstrumentation method\n"
80964 +};
80965 +
80966 +static unsigned int execute_kernexec_reload(void);
80967 +static unsigned int execute_kernexec_fptr(void);
80968 +static unsigned int execute_kernexec_retaddr(void);
80969 +static bool kernexec_cmodel_check(void);
80970 +
80971 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
80972 +static void (*kernexec_instrument_retaddr)(rtx);
80973 +
80974 +static struct gimple_opt_pass kernexec_reload_pass = {
80975 + .pass = {
80976 + .type = GIMPLE_PASS,
80977 + .name = "kernexec_reload",
80978 + .gate = kernexec_cmodel_check,
80979 + .execute = execute_kernexec_reload,
80980 + .sub = NULL,
80981 + .next = NULL,
80982 + .static_pass_number = 0,
80983 + .tv_id = TV_NONE,
80984 + .properties_required = 0,
80985 + .properties_provided = 0,
80986 + .properties_destroyed = 0,
80987 + .todo_flags_start = 0,
80988 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
80989 + }
80990 +};
80991 +
80992 +static struct gimple_opt_pass kernexec_fptr_pass = {
80993 + .pass = {
80994 + .type = GIMPLE_PASS,
80995 + .name = "kernexec_fptr",
80996 + .gate = kernexec_cmodel_check,
80997 + .execute = execute_kernexec_fptr,
80998 + .sub = NULL,
80999 + .next = NULL,
81000 + .static_pass_number = 0,
81001 + .tv_id = TV_NONE,
81002 + .properties_required = 0,
81003 + .properties_provided = 0,
81004 + .properties_destroyed = 0,
81005 + .todo_flags_start = 0,
81006 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
81007 + }
81008 +};
81009 +
81010 +static struct rtl_opt_pass kernexec_retaddr_pass = {
81011 + .pass = {
81012 + .type = RTL_PASS,
81013 + .name = "kernexec_retaddr",
81014 + .gate = kernexec_cmodel_check,
81015 + .execute = execute_kernexec_retaddr,
81016 + .sub = NULL,
81017 + .next = NULL,
81018 + .static_pass_number = 0,
81019 + .tv_id = TV_NONE,
81020 + .properties_required = 0,
81021 + .properties_provided = 0,
81022 + .properties_destroyed = 0,
81023 + .todo_flags_start = 0,
81024 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
81025 + }
81026 +};
81027 +
81028 +static bool kernexec_cmodel_check(void)
81029 +{
81030 + tree section;
81031 +
81032 + if (ix86_cmodel != CM_KERNEL)
81033 + return false;
81034 +
81035 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
81036 + if (!section || !TREE_VALUE(section))
81037 + return true;
81038 +
81039 + section = TREE_VALUE(TREE_VALUE(section));
81040 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
81041 + return true;
81042 +
81043 + return false;
81044 +}
81045 +
81046 +/*
81047 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
81048 + */
81049 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
81050 +{
81051 + gimple asm_movabs_stmt;
81052 +
81053 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
81054 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
81055 + gimple_asm_set_volatile(asm_movabs_stmt, true);
81056 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
81057 + update_stmt(asm_movabs_stmt);
81058 +}
81059 +
81060 +/*
81061 + * find all asm() stmts that clobber r10 and add a reload of r10
81062 + */
81063 +static unsigned int execute_kernexec_reload(void)
81064 +{
81065 + basic_block bb;
81066 +
81067 + // 1. loop through BBs and GIMPLE statements
81068 + FOR_EACH_BB(bb) {
81069 + gimple_stmt_iterator gsi;
81070 +
81071 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81072 + // gimple match: __asm__ ("" : : : "r10");
81073 + gimple asm_stmt;
81074 + size_t nclobbers;
81075 +
81076 + // is it an asm ...
81077 + asm_stmt = gsi_stmt(gsi);
81078 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
81079 + continue;
81080 +
81081 + // ... clobbering r10
81082 + nclobbers = gimple_asm_nclobbers(asm_stmt);
81083 + while (nclobbers--) {
81084 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
81085 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
81086 + continue;
81087 + kernexec_reload_fptr_mask(&gsi);
81088 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
81089 + break;
81090 + }
81091 + }
81092 + }
81093 +
81094 + return 0;
81095 +}
81096 +
81097 +/*
81098 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
81099 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
81100 + */
81101 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
81102 +{
81103 + gimple assign_intptr, assign_new_fptr, call_stmt;
81104 + tree intptr, old_fptr, new_fptr, kernexec_mask;
81105 +
81106 + call_stmt = gsi_stmt(*gsi);
81107 + old_fptr = gimple_call_fn(call_stmt);
81108 +
81109 + // create temporary unsigned long variable used for bitops and cast fptr to it
81110 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
81111 + add_referenced_var(intptr);
81112 + mark_sym_for_renaming(intptr);
81113 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
81114 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81115 + update_stmt(assign_intptr);
81116 +
81117 + // apply logical or to temporary unsigned long and bitmask
81118 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
81119 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
81120 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
81121 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
81122 + update_stmt(assign_intptr);
81123 +
81124 + // cast temporary unsigned long back to a temporary fptr variable
81125 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
81126 + add_referenced_var(new_fptr);
81127 + mark_sym_for_renaming(new_fptr);
81128 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
81129 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
81130 + update_stmt(assign_new_fptr);
81131 +
81132 + // replace call stmt fn with the new fptr
81133 + gimple_call_set_fn(call_stmt, new_fptr);
81134 + update_stmt(call_stmt);
81135 +}
81136 +
81137 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
81138 +{
81139 + gimple asm_or_stmt, call_stmt;
81140 + tree old_fptr, new_fptr, input, output;
81141 + VEC(tree, gc) *inputs = NULL;
81142 + VEC(tree, gc) *outputs = NULL;
81143 +
81144 + call_stmt = gsi_stmt(*gsi);
81145 + old_fptr = gimple_call_fn(call_stmt);
81146 +
81147 + // create temporary fptr variable
81148 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
81149 + add_referenced_var(new_fptr);
81150 + mark_sym_for_renaming(new_fptr);
81151 +
81152 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
81153 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
81154 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
81155 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
81156 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
81157 + VEC_safe_push(tree, gc, inputs, input);
81158 + VEC_safe_push(tree, gc, outputs, output);
81159 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
81160 + gimple_asm_set_volatile(asm_or_stmt, true);
81161 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
81162 + update_stmt(asm_or_stmt);
81163 +
81164 + // replace call stmt fn with the new fptr
81165 + gimple_call_set_fn(call_stmt, new_fptr);
81166 + update_stmt(call_stmt);
81167 +}
81168 +
81169 +/*
81170 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
81171 + */
81172 +static unsigned int execute_kernexec_fptr(void)
81173 +{
81174 + basic_block bb;
81175 +
81176 + // 1. loop through BBs and GIMPLE statements
81177 + FOR_EACH_BB(bb) {
81178 + gimple_stmt_iterator gsi;
81179 +
81180 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
81181 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
81182 + tree fn;
81183 + gimple call_stmt;
81184 +
81185 + // is it a call ...
81186 + call_stmt = gsi_stmt(gsi);
81187 + if (!is_gimple_call(call_stmt))
81188 + continue;
81189 + fn = gimple_call_fn(call_stmt);
81190 + if (TREE_CODE(fn) == ADDR_EXPR)
81191 + continue;
81192 + if (TREE_CODE(fn) != SSA_NAME)
81193 + gcc_unreachable();
81194 +
81195 + // ... through a function pointer
81196 + fn = SSA_NAME_VAR(fn);
81197 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
81198 + continue;
81199 + fn = TREE_TYPE(fn);
81200 + if (TREE_CODE(fn) != POINTER_TYPE)
81201 + continue;
81202 + fn = TREE_TYPE(fn);
81203 + if (TREE_CODE(fn) != FUNCTION_TYPE)
81204 + continue;
81205 +
81206 + kernexec_instrument_fptr(&gsi);
81207 +
81208 +//debug_tree(gimple_call_fn(call_stmt));
81209 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
81210 + }
81211 + }
81212 +
81213 + return 0;
81214 +}
81215 +
81216 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
81217 +static void kernexec_instrument_retaddr_bts(rtx insn)
81218 +{
81219 + rtx btsq;
81220 + rtvec argvec, constraintvec, labelvec;
81221 + int line;
81222 +
81223 + // create asm volatile("btsq $63,(%%rsp)":::)
81224 + argvec = rtvec_alloc(0);
81225 + constraintvec = rtvec_alloc(0);
81226 + labelvec = rtvec_alloc(0);
81227 + line = expand_location(RTL_LOCATION(insn)).line;
81228 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81229 + MEM_VOLATILE_P(btsq) = 1;
81230 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
81231 + emit_insn_before(btsq, insn);
81232 +}
81233 +
81234 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
81235 +static void kernexec_instrument_retaddr_or(rtx insn)
81236 +{
81237 + rtx orq;
81238 + rtvec argvec, constraintvec, labelvec;
81239 + int line;
81240 +
81241 + // create asm volatile("orq %%r10,(%%rsp)":::)
81242 + argvec = rtvec_alloc(0);
81243 + constraintvec = rtvec_alloc(0);
81244 + labelvec = rtvec_alloc(0);
81245 + line = expand_location(RTL_LOCATION(insn)).line;
81246 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
81247 + MEM_VOLATILE_P(orq) = 1;
81248 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
81249 + emit_insn_before(orq, insn);
81250 +}
81251 +
81252 +/*
81253 + * find all asm level function returns and forcibly set the highest bit of the return address
81254 + */
81255 +static unsigned int execute_kernexec_retaddr(void)
81256 +{
81257 + rtx insn;
81258 +
81259 + // 1. find function returns
81260 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
81261 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
81262 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
81263 + rtx body;
81264 +
81265 + // is it a retn
81266 + if (!JUMP_P(insn))
81267 + continue;
81268 + body = PATTERN(insn);
81269 + if (GET_CODE(body) == PARALLEL)
81270 + body = XVECEXP(body, 0, 0);
81271 + if (GET_CODE(body) != RETURN)
81272 + continue;
81273 + kernexec_instrument_retaddr(insn);
81274 + }
81275 +
81276 +// print_simple_rtl(stderr, get_insns());
81277 +// print_rtl(stderr, get_insns());
81278 +
81279 + return 0;
81280 +}
81281 +
81282 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
81283 +{
81284 + const char * const plugin_name = plugin_info->base_name;
81285 + const int argc = plugin_info->argc;
81286 + const struct plugin_argument * const argv = plugin_info->argv;
81287 + int i;
81288 + struct register_pass_info kernexec_reload_pass_info = {
81289 + .pass = &kernexec_reload_pass.pass,
81290 + .reference_pass_name = "ssa",
81291 + .ref_pass_instance_number = 0,
81292 + .pos_op = PASS_POS_INSERT_AFTER
81293 + };
81294 + struct register_pass_info kernexec_fptr_pass_info = {
81295 + .pass = &kernexec_fptr_pass.pass,
81296 + .reference_pass_name = "ssa",
81297 + .ref_pass_instance_number = 0,
81298 + .pos_op = PASS_POS_INSERT_AFTER
81299 + };
81300 + struct register_pass_info kernexec_retaddr_pass_info = {
81301 + .pass = &kernexec_retaddr_pass.pass,
81302 + .reference_pass_name = "pro_and_epilogue",
81303 + .ref_pass_instance_number = 0,
81304 + .pos_op = PASS_POS_INSERT_AFTER
81305 + };
81306 +
81307 + if (!plugin_default_version_check(version, &gcc_version)) {
81308 + error(G_("incompatible gcc/plugin versions"));
81309 + return 1;
81310 + }
81311 +
81312 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
81313 +
81314 + if (TARGET_64BIT == 0)
81315 + return 0;
81316 +
81317 + for (i = 0; i < argc; ++i) {
81318 + if (!strcmp(argv[i].key, "method")) {
81319 + if (!argv[i].value) {
81320 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81321 + continue;
81322 + }
81323 + if (!strcmp(argv[i].value, "bts")) {
81324 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
81325 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
81326 + } else if (!strcmp(argv[i].value, "or")) {
81327 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
81328 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
81329 + fix_register("r10", 1, 1);
81330 + } else
81331 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
81332 + continue;
81333 + }
81334 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
81335 + }
81336 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
81337 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
81338 +
81339 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
81340 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
81341 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
81342 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
81343 +
81344 + return 0;
81345 +}
81346 diff --git a/tools/gcc/size_overflow_hash.h b/tools/gcc/size_overflow_hash.h
81347 new file mode 100644
81348 index 0000000..ce7366b
81349 --- /dev/null
81350 +++ b/tools/gcc/size_overflow_hash.h
81351 @@ -0,0 +1,13933 @@
81352 +struct size_overflow_hash _000001_hash = {
81353 + .next = NULL,
81354 + .name = "alloc_dr",
81355 + .file = "drivers/base/devres.c",
81356 + .param2 = 1,
81357 +};
81358 +
81359 +struct size_overflow_hash _000002_hash = {
81360 + .next = NULL,
81361 + .name = "__copy_from_user",
81362 + .file = "arch/x86/include/asm/uaccess_32.h",
81363 + .param3 = 1,
81364 +};
81365 +
81366 +struct size_overflow_hash _000003_hash = {
81367 + .next = NULL,
81368 + .name = "copy_from_user",
81369 + .file = "arch/x86/include/asm/uaccess_32.h",
81370 + .param3 = 1,
81371 +};
81372 +
81373 +struct size_overflow_hash _000004_hash = {
81374 + .next = NULL,
81375 + .name = "__copy_from_user_inatomic",
81376 + .file = "arch/x86/include/asm/uaccess_32.h",
81377 + .param3 = 1,
81378 +};
81379 +
81380 +struct size_overflow_hash _000005_hash = {
81381 + .next = NULL,
81382 + .name = "__copy_from_user_nocache",
81383 + .file = "arch/x86/include/asm/uaccess_32.h",
81384 + .param3 = 1,
81385 +};
81386 +
81387 +struct size_overflow_hash _000006_hash = {
81388 + .next = NULL,
81389 + .name = "__copy_to_user_inatomic",
81390 + .file = "arch/x86/include/asm/uaccess_32.h",
81391 + .param3 = 1,
81392 +};
81393 +
81394 +struct size_overflow_hash _000007_hash = {
81395 + .next = NULL,
81396 + .name = "do_xip_mapping_read",
81397 + .file = "mm/filemap_xip.c",
81398 + .param5 = 1,
81399 +};
81400 +
81401 +struct size_overflow_hash _000008_hash = {
81402 + .next = NULL,
81403 + .name = "hugetlbfs_read",
81404 + .file = "fs/hugetlbfs/inode.c",
81405 + .param3 = 1,
81406 +};
81407 +
81408 +struct size_overflow_hash _000009_hash = {
81409 + .next = NULL,
81410 + .name = "kcalloc",
81411 + .file = "include/linux/slab.h",
81412 + .param1 = 1,
81413 + .param2 = 1,
81414 +};
81415 +
81416 +struct size_overflow_hash _000011_hash = {
81417 + .next = NULL,
81418 + .name = "kmalloc",
81419 + .file = "include/linux/slub_def.h",
81420 + .param1 = 1,
81421 +};
81422 +
81423 +struct size_overflow_hash _000012_hash = {
81424 + .next = NULL,
81425 + .name = "kmalloc_slab",
81426 + .file = "include/linux/slub_def.h",
81427 + .param1 = 1,
81428 +};
81429 +
81430 +struct size_overflow_hash _000013_hash = {
81431 + .next = NULL,
81432 + .name = "kmemdup",
81433 + .file = "include/linux/string.h",
81434 + .param2 = 1,
81435 +};
81436 +
81437 +struct size_overflow_hash _000014_hash = {
81438 + .next = NULL,
81439 + .name = "__krealloc",
81440 + .file = "include/linux/slab.h",
81441 + .param2 = 1,
81442 +};
81443 +
81444 +struct size_overflow_hash _000015_hash = {
81445 + .next = NULL,
81446 + .name = "memdup_user",
81447 + .file = "include/linux/string.h",
81448 + .param2 = 1,
81449 +};
81450 +
81451 +struct size_overflow_hash _000016_hash = {
81452 + .next = NULL,
81453 + .name = "module_alloc",
81454 + .file = "include/linux/moduleloader.h",
81455 + .param1 = 1,
81456 +};
81457 +
81458 +struct size_overflow_hash _000017_hash = {
81459 + .next = NULL,
81460 + .name = "read_default_ldt",
81461 + .file = "arch/x86/kernel/ldt.c",
81462 + .param2 = 1,
81463 +};
81464 +
81465 +struct size_overflow_hash _000018_hash = {
81466 + .next = NULL,
81467 + .name = "read_kcore",
81468 + .file = "fs/proc/kcore.c",
81469 + .param3 = 1,
81470 +};
81471 +
81472 +struct size_overflow_hash _000019_hash = {
81473 + .next = NULL,
81474 + .name = "read_ldt",
81475 + .file = "arch/x86/kernel/ldt.c",
81476 + .param2 = 1,
81477 +};
81478 +
81479 +struct size_overflow_hash _000020_hash = {
81480 + .next = NULL,
81481 + .name = "read_zero",
81482 + .file = "drivers/char/mem.c",
81483 + .param3 = 1,
81484 +};
81485 +
81486 +struct size_overflow_hash _000021_hash = {
81487 + .next = NULL,
81488 + .name = "__vmalloc_node",
81489 + .file = "mm/vmalloc.c",
81490 + .param1 = 1,
81491 +};
81492 +
81493 +struct size_overflow_hash _000022_hash = {
81494 + .next = NULL,
81495 + .name = "vm_map_ram",
81496 + .file = "include/linux/vmalloc.h",
81497 + .param2 = 1,
81498 +};
81499 +
81500 +struct size_overflow_hash _000023_hash = {
81501 + .next = NULL,
81502 + .name = "aa_simple_write_to_buffer",
81503 + .file = "security/apparmor/apparmorfs.c",
81504 + .param4 = 1,
81505 +};
81506 +
81507 +struct size_overflow_hash _000024_hash = {
81508 + .next = NULL,
81509 + .name = "ablkcipher_copy_iv",
81510 + .file = "crypto/ablkcipher.c",
81511 + .param3 = 1,
81512 +};
81513 +
81514 +struct size_overflow_hash _000025_hash = {
81515 + .next = NULL,
81516 + .name = "ablkcipher_next_slow",
81517 + .file = "crypto/ablkcipher.c",
81518 + .param4 = 1,
81519 +};
81520 +
81521 +struct size_overflow_hash _000026_hash = {
81522 + .next = NULL,
81523 + .name = "acpi_os_allocate",
81524 + .file = "include/acpi/platform/aclinux.h",
81525 + .param1 = 1,
81526 +};
81527 +
81528 +struct size_overflow_hash _000027_hash = {
81529 + .next = NULL,
81530 + .name = "acpi_system_write_wakeup_device",
81531 + .file = "drivers/acpi/proc.c",
81532 + .param3 = 1,
81533 +};
81534 +
81535 +struct size_overflow_hash _000028_hash = {
81536 + .next = NULL,
81537 + .name = "ahash_setkey_unaligned",
81538 + .file = "crypto/ahash.c",
81539 + .param3 = 1,
81540 +};
81541 +
81542 +struct size_overflow_hash _000029_hash = {
81543 + .next = NULL,
81544 + .name = "alloc_fdmem",
81545 + .file = "fs/file.c",
81546 + .param1 = 1,
81547 +};
81548 +
81549 +struct size_overflow_hash _000030_hash = {
81550 + .next = NULL,
81551 + .name = "audit_unpack_string",
81552 + .file = "kernel/auditfilter.c",
81553 + .param3 = 1,
81554 +};
81555 +
81556 +struct size_overflow_hash _000031_hash = {
81557 + .next = NULL,
81558 + .name = "bio_alloc_map_data",
81559 + .file = "fs/bio.c",
81560 + .param2 = 1,
81561 +};
81562 +
81563 +struct size_overflow_hash _000032_hash = {
81564 + .next = NULL,
81565 + .name = "bio_kmalloc",
81566 + .file = "include/linux/bio.h",
81567 + .param2 = 1,
81568 +};
81569 +
81570 +struct size_overflow_hash _000033_hash = {
81571 + .next = NULL,
81572 + .name = "blkcipher_copy_iv",
81573 + .file = "crypto/blkcipher.c",
81574 + .param3 = 1,
81575 +};
81576 +
81577 +struct size_overflow_hash _000034_hash = {
81578 + .next = NULL,
81579 + .name = "blkcipher_next_slow",
81580 + .file = "crypto/blkcipher.c",
81581 + .param4 = 1,
81582 +};
81583 +
81584 +struct size_overflow_hash _000035_hash = {
81585 + .next = NULL,
81586 + .name = "cgroup_write_string",
81587 + .file = "kernel/cgroup.c",
81588 + .param5 = 1,
81589 +};
81590 +
81591 +struct size_overflow_hash _000036_hash = {
81592 + .next = NULL,
81593 + .name = "cgroup_write_X64",
81594 + .file = "kernel/cgroup.c",
81595 + .param5 = 1,
81596 +};
81597 +
81598 +struct size_overflow_hash _000037_hash = {
81599 + .next = NULL,
81600 + .name = "clear_refs_write",
81601 + .file = "fs/proc/task_mmu.c",
81602 + .param3 = 1,
81603 +};
81604 +
81605 +struct size_overflow_hash _000038_hash = {
81606 + .next = NULL,
81607 + .name = "comm_write",
81608 + .file = "fs/proc/base.c",
81609 + .param3 = 1,
81610 +};
81611 +
81612 +struct size_overflow_hash _000039_hash = {
81613 + .next = NULL,
81614 + .name = "copy_and_check",
81615 + .file = "kernel/module.c",
81616 + .param3 = 1,
81617 +};
81618 +
81619 +struct size_overflow_hash _000040_hash = {
81620 + .next = NULL,
81621 + .name = "__copy_to_user",
81622 + .file = "arch/x86/include/asm/uaccess_32.h",
81623 + .param3 = 1,
81624 +};
81625 +
81626 +struct size_overflow_hash _000041_hash = {
81627 + .next = NULL,
81628 + .name = "copy_vm86_regs_from_user",
81629 + .file = "arch/x86/kernel/vm86_32.c",
81630 + .param3 = 1,
81631 +};
81632 +
81633 +struct size_overflow_hash _000042_hash = {
81634 + .next = NULL,
81635 + .name = "csum_partial_copy_fromiovecend",
81636 + .file = "include/linux/socket.h",
81637 + .param4 = 1,
81638 +};
81639 +
81640 +struct size_overflow_hash _000043_hash = {
81641 + .next = NULL,
81642 + .name = "ddebug_proc_write",
81643 + .file = "lib/dynamic_debug.c",
81644 + .param3 = 1,
81645 +};
81646 +
81647 +struct size_overflow_hash _000044_hash = {
81648 + .next = NULL,
81649 + .name = "devm_kzalloc",
81650 + .file = "include/linux/device.h",
81651 + .param2 = 1,
81652 +};
81653 +
81654 +struct size_overflow_hash _000045_hash = {
81655 + .next = NULL,
81656 + .name = "devres_alloc",
81657 + .file = "include/linux/device.h",
81658 + .param2 = 1,
81659 +};
81660 +
81661 +struct size_overflow_hash _000046_hash = {
81662 + .next = NULL,
81663 + .name = "do_ip_setsockopt",
81664 + .file = "net/ipv4/ip_sockglue.c",
81665 + .param5 = 1,
81666 +};
81667 +
81668 +struct size_overflow_hash _000047_hash = {
81669 + .next = NULL,
81670 + .name = "do_kimage_alloc",
81671 + .file = "kernel/kexec.c",
81672 + .param3 = 1,
81673 +};
81674 +
81675 +struct size_overflow_hash _000048_hash = {
81676 + .next = NULL,
81677 + .name = "do_tty_write",
81678 + .file = "drivers/tty/tty_io.c",
81679 + .param5 = 1,
81680 +};
81681 +
81682 +struct size_overflow_hash _000049_hash = {
81683 + .next = NULL,
81684 + .name = "fanotify_write",
81685 + .file = "fs/notify/fanotify/fanotify_user.c",
81686 + .param3 = 1,
81687 +};
81688 +
81689 +struct size_overflow_hash _000050_hash = {
81690 + .next = NULL,
81691 + .name = "file_read_actor",
81692 + .file = "include/linux/fs.h",
81693 + .param4 = 1,
81694 +};
81695 +
81696 +struct size_overflow_hash _000051_hash = {
81697 + .next = NULL,
81698 + .name = "fill_write_buffer",
81699 + .file = "fs/sysfs/file.c",
81700 + .param3 = 1,
81701 +};
81702 +
81703 +struct size_overflow_hash _000052_hash = {
81704 + .next = NULL,
81705 + .name = "get_user_cpu_mask",
81706 + .file = "kernel/sched/core.c",
81707 + .param2 = 1,
81708 +};
81709 +
81710 +struct size_overflow_hash _000053_hash = {
81711 + .next = NULL,
81712 + .name = "hashtab_create",
81713 + .file = "security/selinux/ss/hashtab.c",
81714 + .param3 = 1,
81715 +};
81716 +
81717 +struct size_overflow_hash _000054_hash = {
81718 + .next = NULL,
81719 + .name = "heap_init",
81720 + .file = "include/linux/prio_heap.h",
81721 + .param2 = 1,
81722 +};
81723 +
81724 +struct size_overflow_hash _000055_hash = {
81725 + .next = NULL,
81726 + .name = "hest_ghes_dev_register",
81727 + .file = "drivers/acpi/apei/hest.c",
81728 + .param1 = 1,
81729 +};
81730 +
81731 +struct size_overflow_hash _000056_hash = {
81732 + .next = NULL,
81733 + .name = "ima_write_policy",
81734 + .file = "security/integrity/ima/ima_fs.c",
81735 + .param3 = 1,
81736 +};
81737 +
81738 +struct size_overflow_hash _000057_hash = {
81739 + .next = NULL,
81740 + .name = "input_ff_create",
81741 + .file = "include/linux/input.h",
81742 + .param2 = 1,
81743 +};
81744 +
81745 +struct size_overflow_hash _000058_hash = {
81746 + .next = NULL,
81747 + .name = "input_mt_init_slots",
81748 + .file = "include/linux/input/mt.h",
81749 + .param2 = 1,
81750 +};
81751 +
81752 +struct size_overflow_hash _000059_hash = {
81753 + .next = NULL,
81754 + .name = "iov_iter_copy_from_user",
81755 + .file = "include/linux/fs.h",
81756 + .param4 = 1,
81757 +};
81758 +
81759 +struct size_overflow_hash _000060_hash = {
81760 + .next = NULL,
81761 + .name = "iov_iter_copy_from_user_atomic",
81762 + .file = "include/linux/fs.h",
81763 + .param4 = 1,
81764 +};
81765 +
81766 +struct size_overflow_hash _000061_hash = {
81767 + .next = NULL,
81768 + .name = "keyctl_instantiate_key_common",
81769 + .file = "security/keys/keyctl.c",
81770 + .param4 = 1,
81771 +};
81772 +
81773 +struct size_overflow_hash _000062_hash = {
81774 + .next = NULL,
81775 + .name = "keyctl_update_key",
81776 + .file = "security/keys/keyctl.c",
81777 + .param3 = 1,
81778 +};
81779 +
81780 +struct size_overflow_hash _000063_hash = {
81781 + .next = NULL,
81782 + .name = "__kfifo_alloc",
81783 + .file = "include/linux/kfifo.h",
81784 + .param2 = 1,
81785 + .param3 = 1,
81786 +};
81787 +
81788 +struct size_overflow_hash _000065_hash = {
81789 + .next = NULL,
81790 + .name = "kfifo_copy_from_user",
81791 + .file = "kernel/kfifo.c",
81792 + .param3 = 1,
81793 +};
81794 +
81795 +struct size_overflow_hash _000066_hash = {
81796 + .next = NULL,
81797 + .name = "kmalloc_node",
81798 + .file = "include/linux/slab.h",
81799 + .param1 = 1,
81800 +};
81801 +
81802 +struct size_overflow_hash _000067_hash = {
81803 + .next = NULL,
81804 + .name = "kmalloc_parameter",
81805 + .file = "kernel/params.c",
81806 + .param1 = 1,
81807 +};
81808 +
81809 +struct size_overflow_hash _000068_hash = {
81810 + .next = NULL,
81811 + .name = "kobj_map",
81812 + .file = "include/linux/kobj_map.h",
81813 + .param2 = 1,
81814 + .param3 = 1,
81815 +};
81816 +
81817 +struct size_overflow_hash _000070_hash = {
81818 + .next = NULL,
81819 + .name = "krealloc",
81820 + .file = "include/linux/slab.h",
81821 + .param2 = 1,
81822 +};
81823 +
81824 +struct size_overflow_hash _000071_hash = {
81825 + .next = NULL,
81826 + .name = "kvmalloc",
81827 + .file = "security/apparmor/lib.c",
81828 + .param1 = 1,
81829 +};
81830 +
81831 +struct size_overflow_hash _000072_hash = {
81832 + .next = NULL,
81833 + .name = "kzalloc",
81834 + .file = "include/linux/slab.h",
81835 + .param1 = 1,
81836 +};
81837 +
81838 +struct size_overflow_hash _000073_hash = {
81839 + .next = NULL,
81840 + .name = "listxattr",
81841 + .file = "fs/xattr.c",
81842 + .param3 = 1,
81843 +};
81844 +
81845 +struct size_overflow_hash _000074_hash = {
81846 + .next = NULL,
81847 + .name = "mempool_kmalloc",
81848 + .file = "include/linux/mempool.h",
81849 + .param2 = 1,
81850 +};
81851 +
81852 +struct size_overflow_hash _000075_hash = {
81853 + .next = NULL,
81854 + .name = "mem_rw",
81855 + .file = "fs/proc/base.c",
81856 + .param3 = 1,
81857 +};
81858 +
81859 +struct size_overflow_hash _000076_hash = {
81860 + .next = NULL,
81861 + .name = "module_alloc_update_bounds",
81862 + .file = "kernel/module.c",
81863 + .param1 = 1,
81864 +};
81865 +
81866 +struct size_overflow_hash _000077_hash = {
81867 + .next = NULL,
81868 + .name = "mpi_alloc_limb_space",
81869 + .file = "lib/mpi/mpiutil.c",
81870 + .param1 = 1,
81871 +};
81872 +
81873 +struct size_overflow_hash _000078_hash = {
81874 + .next = NULL,
81875 + .name = "mpi_resize",
81876 + .file = "include/linux/mpi.h",
81877 + .param2 = 1,
81878 +};
81879 +
81880 +struct size_overflow_hash _000079_hash = {
81881 + .next = NULL,
81882 + .name = "mtrr_write",
81883 + .file = "arch/x86/kernel/cpu/mtrr/if.c",
81884 + .param3 = 1,
81885 +};
81886 +
81887 +struct size_overflow_hash _000080_hash = {
81888 + .next = NULL,
81889 + .name = "oom_adjust_write",
81890 + .file = "fs/proc/base.c",
81891 + .param3 = 1,
81892 +};
81893 +
81894 +struct size_overflow_hash _000081_hash = {
81895 + .next = NULL,
81896 + .name = "oom_score_adj_write",
81897 + .file = "fs/proc/base.c",
81898 + .param3 = 1,
81899 +};
81900 +
81901 +struct size_overflow_hash _000082_hash = {
81902 + .next = NULL,
81903 + .name = "pipe_iov_copy_from_user",
81904 + .file = "fs/pipe.c",
81905 + .param3 = 1,
81906 +};
81907 +
81908 +struct size_overflow_hash _000083_hash = {
81909 + .next = NULL,
81910 + .name = "pipe_iov_copy_to_user",
81911 + .file = "fs/pipe.c",
81912 + .param3 = 1,
81913 +};
81914 +
81915 +struct size_overflow_hash _000084_hash = {
81916 + .next = NULL,
81917 + .name = "pipe_set_size",
81918 + .file = "fs/pipe.c",
81919 + .param2 = 1,
81920 +};
81921 +
81922 +struct size_overflow_hash _000085_hash = {
81923 + .next = NULL,
81924 + .name = "platform_device_add_data",
81925 + .file = "include/linux/platform_device.h",
81926 + .param3 = 1,
81927 +};
81928 +
81929 +struct size_overflow_hash _000086_hash = {
81930 + .next = NULL,
81931 + .name = "platform_device_add_resources",
81932 + .file = "include/linux/platform_device.h",
81933 + .param3 = 1,
81934 +};
81935 +
81936 +struct size_overflow_hash _000087_hash = {
81937 + .next = NULL,
81938 + .name = "pm_qos_power_write",
81939 + .file = "kernel/power/qos.c",
81940 + .param3 = 1,
81941 +};
81942 +
81943 +struct size_overflow_hash _000088_hash = {
81944 + .next = NULL,
81945 + .name = "pnpbios_proc_write",
81946 + .file = "drivers/pnp/pnpbios/proc.c",
81947 + .param3 = 1,
81948 +};
81949 +
81950 +struct size_overflow_hash _000089_hash = {
81951 + .next = NULL,
81952 + .name = "__probe_kernel_read",
81953 + .file = "include/linux/uaccess.h",
81954 + .param3 = 1,
81955 +};
81956 +
81957 +struct size_overflow_hash _000090_hash = {
81958 + .next = NULL,
81959 + .name = "__probe_kernel_write",
81960 + .file = "include/linux/uaccess.h",
81961 + .param3 = 1,
81962 +};
81963 +
81964 +struct size_overflow_hash _000091_hash = {
81965 + .next = NULL,
81966 + .name = "proc_coredump_filter_write",
81967 + .file = "fs/proc/base.c",
81968 + .param3 = 1,
81969 +};
81970 +
81971 +struct size_overflow_hash _000092_hash = {
81972 + .next = NULL,
81973 + .name = "process_vm_rw_pages",
81974 + .file = "mm/process_vm_access.c",
81975 + .param5 = 1,
81976 + .param6 = 1,
81977 +};
81978 +
81979 +struct size_overflow_hash _000094_hash = {
81980 + .next = NULL,
81981 + .name = "proc_loginuid_write",
81982 + .file = "fs/proc/base.c",
81983 + .param3 = 1,
81984 +};
81985 +
81986 +struct size_overflow_hash _000095_hash = {
81987 + .next = NULL,
81988 + .name = "proc_pid_attr_write",
81989 + .file = "fs/proc/base.c",
81990 + .param3 = 1,
81991 +};
81992 +
81993 +struct size_overflow_hash _000096_hash = {
81994 + .next = NULL,
81995 + .name = "pstore_mkfile",
81996 + .file = "fs/pstore/inode.c",
81997 + .param5 = 1,
81998 +};
81999 +
82000 +struct size_overflow_hash _000097_hash = {
82001 + .next = NULL,
82002 + .name = "qdisc_class_hash_alloc",
82003 + .file = "net/sched/sch_api.c",
82004 + .param1 = 1,
82005 +};
82006 +
82007 +struct size_overflow_hash _000098_hash = {
82008 + .next = NULL,
82009 + .name = "read",
82010 + .file = "fs/sysfs/bin.c",
82011 + .param3 = 1,
82012 +};
82013 +
82014 +struct size_overflow_hash _000099_hash = {
82015 + .next = NULL,
82016 + .name = "regmap_access_read_file",
82017 + .file = "drivers/base/regmap/regmap-debugfs.c",
82018 + .param3 = 1,
82019 +};
82020 +
82021 +struct size_overflow_hash _000100_hash = {
82022 + .next = NULL,
82023 + .name = "regmap_map_read_file",
82024 + .file = "drivers/base/regmap/regmap-debugfs.c",
82025 + .param3 = 1,
82026 +};
82027 +
82028 +struct size_overflow_hash _000101_hash = {
82029 + .next = NULL,
82030 + .name = "_regmap_raw_write",
82031 + .file = "drivers/base/regmap/regmap.c",
82032 + .param4 = 1,
82033 +};
82034 +
82035 +struct size_overflow_hash _000102_hash = {
82036 + .next = NULL,
82037 + .name = "regset_tls_set",
82038 + .file = "arch/x86/kernel/tls.c",
82039 + .param4 = 1,
82040 +};
82041 +
82042 +struct size_overflow_hash _000103_hash = {
82043 + .next = NULL,
82044 + .name = "request_key_auth_new",
82045 + .file = "security/keys/request_key_auth.c",
82046 + .param3 = 1,
82047 +};
82048 +
82049 +struct size_overflow_hash _000104_hash = {
82050 + .next = NULL,
82051 + .name = "restore_i387_fxsave",
82052 + .file = "arch/x86/kernel/i387.c",
82053 + .param2 = 1,
82054 +};
82055 +
82056 +struct size_overflow_hash _000105_hash = {
82057 + .next = NULL,
82058 + .name = "rngapi_reset",
82059 + .file = "crypto/rng.c",
82060 + .param3 = 1,
82061 +};
82062 +
82063 +struct size_overflow_hash _000106_hash = {
82064 + .next = NULL,
82065 + .name = "rw_copy_check_uvector",
82066 + .file = "include/linux/fs.h",
82067 + .param3 = 1,
82068 +};
82069 +
82070 +struct size_overflow_hash _000107_hash = {
82071 + .next = NULL,
82072 + .name = "sched_autogroup_write",
82073 + .file = "fs/proc/base.c",
82074 + .param3 = 1,
82075 +};
82076 +
82077 +struct size_overflow_hash _000108_hash = {
82078 + .next = NULL,
82079 + .name = "security_context_to_sid_core",
82080 + .file = "security/selinux/ss/services.c",
82081 + .param2 = 1,
82082 +};
82083 +
82084 +struct size_overflow_hash _000109_hash = {
82085 + .next = NULL,
82086 + .name = "sel_commit_bools_write",
82087 + .file = "security/selinux/selinuxfs.c",
82088 + .param3 = 1,
82089 +};
82090 +
82091 +struct size_overflow_hash _000110_hash = {
82092 + .next = NULL,
82093 + .name = "sel_write_avc_cache_threshold",
82094 + .file = "security/selinux/selinuxfs.c",
82095 + .param3 = 1,
82096 +};
82097 +
82098 +struct size_overflow_hash _000111_hash = {
82099 + .next = NULL,
82100 + .name = "sel_write_bool",
82101 + .file = "security/selinux/selinuxfs.c",
82102 + .param3 = 1,
82103 +};
82104 +
82105 +struct size_overflow_hash _000112_hash = {
82106 + .next = NULL,
82107 + .name = "sel_write_checkreqprot",
82108 + .file = "security/selinux/selinuxfs.c",
82109 + .param3 = 1,
82110 +};
82111 +
82112 +struct size_overflow_hash _000113_hash = {
82113 + .next = NULL,
82114 + .name = "sel_write_disable",
82115 + .file = "security/selinux/selinuxfs.c",
82116 + .param3 = 1,
82117 +};
82118 +
82119 +struct size_overflow_hash _000114_hash = {
82120 + .next = NULL,
82121 + .name = "sel_write_enforce",
82122 + .file = "security/selinux/selinuxfs.c",
82123 + .param3 = 1,
82124 +};
82125 +
82126 +struct size_overflow_hash _000115_hash = {
82127 + .next = NULL,
82128 + .name = "sel_write_load",
82129 + .file = "security/selinux/selinuxfs.c",
82130 + .param3 = 1,
82131 +};
82132 +
82133 +struct size_overflow_hash _000116_hash = {
82134 + .next = NULL,
82135 + .name = "setkey_unaligned",
82136 + .file = "crypto/ablkcipher.c",
82137 + .param3 = 1,
82138 +};
82139 +
82140 +struct size_overflow_hash _000117_hash = {
82141 + .next = NULL,
82142 + .name = "setkey_unaligned",
82143 + .file = "crypto/blkcipher.c",
82144 + .param3 = 1,
82145 +};
82146 +
82147 +struct size_overflow_hash _000118_hash = {
82148 + .next = NULL,
82149 + .name = "setkey_unaligned",
82150 + .file = "crypto/aead.c",
82151 + .param3 = 1,
82152 +};
82153 +
82154 +struct size_overflow_hash _000119_hash = {
82155 + .next = NULL,
82156 + .name = "setkey_unaligned",
82157 + .file = "crypto/cipher.c",
82158 + .param3 = 1,
82159 +};
82160 +
82161 +struct size_overflow_hash _000120_hash = {
82162 + .next = NULL,
82163 + .name = "setxattr",
82164 + .file = "fs/xattr.c",
82165 + .param4 = 1,
82166 +};
82167 +
82168 +struct size_overflow_hash _000121_hash = {
82169 + .next = NULL,
82170 + .name = "sg_kmalloc",
82171 + .file = "lib/scatterlist.c",
82172 + .param1 = 1,
82173 +};
82174 +
82175 +struct size_overflow_hash _000122_hash = {
82176 + .next = NULL,
82177 + .name = "shash_setkey_unaligned",
82178 + .file = "crypto/shash.c",
82179 + .param3 = 1,
82180 +};
82181 +
82182 +struct size_overflow_hash _000123_hash = {
82183 + .next = NULL,
82184 + .name = "shmem_xattr_set",
82185 + .file = "mm/shmem.c",
82186 + .param4 = 1,
82187 +};
82188 +
82189 +struct size_overflow_hash _000124_hash = {
82190 + .next = NULL,
82191 + .name = "simple_transaction_get",
82192 + .file = "include/linux/fs.h",
82193 + .param3 = 1,
82194 +};
82195 +
82196 +struct size_overflow_hash _000125_hash = {
82197 + .next = NULL,
82198 + .name = "simple_write_to_buffer",
82199 + .file = "include/linux/fs.h",
82200 + .param2 = 1,
82201 + .param5 = 1,
82202 +};
82203 +
82204 +struct size_overflow_hash _000127_hash = {
82205 + .next = NULL,
82206 + .name = "smk_write_ambient",
82207 + .file = "security/smack/smackfs.c",
82208 + .param3 = 1,
82209 +};
82210 +
82211 +struct size_overflow_hash _000128_hash = {
82212 + .next = NULL,
82213 + .name = "smk_write_cipso",
82214 + .file = "security/smack/smackfs.c",
82215 + .param3 = 1,
82216 +};
82217 +
82218 +struct size_overflow_hash _000129_hash = {
82219 + .next = NULL,
82220 + .name = "smk_write_direct",
82221 + .file = "security/smack/smackfs.c",
82222 + .param3 = 1,
82223 +};
82224 +
82225 +struct size_overflow_hash _000130_hash = {
82226 + .next = NULL,
82227 + .name = "smk_write_doi",
82228 + .file = "security/smack/smackfs.c",
82229 + .param3 = 1,
82230 +};
82231 +
82232 +struct size_overflow_hash _000131_hash = {
82233 + .next = NULL,
82234 + .name = "smk_write_load_list",
82235 + .file = "security/smack/smackfs.c",
82236 + .param3 = 1,
82237 +};
82238 +
82239 +struct size_overflow_hash _000132_hash = {
82240 + .next = &_000102_hash,
82241 + .name = "smk_write_logging",
82242 + .file = "security/smack/smackfs.c",
82243 + .param3 = 1,
82244 +};
82245 +
82246 +struct size_overflow_hash _000133_hash = {
82247 + .next = NULL,
82248 + .name = "smk_write_netlbladdr",
82249 + .file = "security/smack/smackfs.c",
82250 + .param3 = 1,
82251 +};
82252 +
82253 +struct size_overflow_hash _000134_hash = {
82254 + .next = NULL,
82255 + .name = "smk_write_onlycap",
82256 + .file = "security/smack/smackfs.c",
82257 + .param3 = 1,
82258 +};
82259 +
82260 +struct size_overflow_hash _000135_hash = {
82261 + .next = NULL,
82262 + .name = "sys_add_key",
82263 + .file = "include/linux/syscalls.h",
82264 + .param4 = 1,
82265 +};
82266 +
82267 +struct size_overflow_hash _000136_hash = {
82268 + .next = NULL,
82269 + .name = "sys_modify_ldt",
82270 + .file = "arch/x86/include/asm/syscalls.h",
82271 + .param3 = 1,
82272 +};
82273 +
82274 +struct size_overflow_hash _000137_hash = {
82275 + .next = NULL,
82276 + .name = "sys_semtimedop",
82277 + .file = "include/linux/syscalls.h",
82278 + .param3 = 1,
82279 +};
82280 +
82281 +struct size_overflow_hash _000138_hash = {
82282 + .next = NULL,
82283 + .name = "tomoyo_write_self",
82284 + .file = "security/tomoyo/securityfs_if.c",
82285 + .param3 = 1,
82286 +};
82287 +
82288 +struct size_overflow_hash _000139_hash = {
82289 + .next = NULL,
82290 + .name = "tpm_write",
82291 + .file = "drivers/char/tpm/tpm.c",
82292 + .param3 = 1,
82293 +};
82294 +
82295 +struct size_overflow_hash _000140_hash = {
82296 + .next = NULL,
82297 + .name = "tty_buffer_alloc",
82298 + .file = "drivers/tty/tty_buffer.c",
82299 + .param2 = 1,
82300 +};
82301 +
82302 +struct size_overflow_hash _000141_hash = {
82303 + .next = NULL,
82304 + .name = "user_instantiate",
82305 + .file = "include/keys/user-type.h",
82306 + .param3 = 1,
82307 +};
82308 +
82309 +struct size_overflow_hash _000142_hash = {
82310 + .next = NULL,
82311 + .name = "user_update",
82312 + .file = "include/keys/user-type.h",
82313 + .param3 = 1,
82314 +};
82315 +
82316 +struct size_overflow_hash _000143_hash = {
82317 + .next = NULL,
82318 + .name = "vc_do_resize",
82319 + .file = "drivers/tty/vt/vt.c",
82320 + .param3 = 1,
82321 + .param4 = 1,
82322 +};
82323 +
82324 +struct size_overflow_hash _000145_hash = {
82325 + .next = NULL,
82326 + .name = "vcs_write",
82327 + .file = "drivers/tty/vt/vc_screen.c",
82328 + .param3 = 1,
82329 +};
82330 +
82331 +struct size_overflow_hash _000146_hash = {
82332 + .next = NULL,
82333 + .name = "vga_arb_write",
82334 + .file = "drivers/gpu/vga/vgaarb.c",
82335 + .param3 = 1,
82336 +};
82337 +
82338 +struct size_overflow_hash _000147_hash = {
82339 + .next = NULL,
82340 + .name = "vga_switcheroo_debugfs_write",
82341 + .file = "drivers/gpu/vga/vga_switcheroo.c",
82342 + .param3 = 1,
82343 +};
82344 +
82345 +struct size_overflow_hash _000148_hash = {
82346 + .next = NULL,
82347 + .name = "__vmalloc",
82348 + .file = "include/linux/vmalloc.h",
82349 + .param1 = 1,
82350 +};
82351 +
82352 +struct size_overflow_hash _000149_hash = {
82353 + .next = NULL,
82354 + .name = "vmalloc_32",
82355 + .file = "include/linux/vmalloc.h",
82356 + .param1 = 1,
82357 +};
82358 +
82359 +struct size_overflow_hash _000150_hash = {
82360 + .next = NULL,
82361 + .name = "vmalloc_32_user",
82362 + .file = "include/linux/vmalloc.h",
82363 + .param1 = 1,
82364 +};
82365 +
82366 +struct size_overflow_hash _000151_hash = {
82367 + .next = NULL,
82368 + .name = "vmalloc_exec",
82369 + .file = "include/linux/vmalloc.h",
82370 + .param1 = 1,
82371 +};
82372 +
82373 +struct size_overflow_hash _000152_hash = {
82374 + .next = NULL,
82375 + .name = "vmalloc_node",
82376 + .file = "include/linux/vmalloc.h",
82377 + .param1 = 1,
82378 +};
82379 +
82380 +struct size_overflow_hash _000153_hash = {
82381 + .next = NULL,
82382 + .name = "__vmalloc_node_flags",
82383 + .file = "mm/vmalloc.c",
82384 + .param1 = 1,
82385 +};
82386 +
82387 +struct size_overflow_hash _000154_hash = {
82388 + .next = NULL,
82389 + .name = "vmalloc_user",
82390 + .file = "include/linux/vmalloc.h",
82391 + .param1 = 1,
82392 +};
82393 +
82394 +struct size_overflow_hash _000155_hash = {
82395 + .next = NULL,
82396 + .name = "write",
82397 + .file = "fs/sysfs/bin.c",
82398 + .param3 = 1,
82399 +};
82400 +
82401 +struct size_overflow_hash _000156_hash = {
82402 + .next = NULL,
82403 + .name = "__xip_file_write",
82404 + .file = "mm/filemap_xip.c",
82405 + .param3 = 1,
82406 +};
82407 +
82408 +struct size_overflow_hash _000157_hash = {
82409 + .next = NULL,
82410 + .name = "acpi_ex_allocate_name_string",
82411 + .file = "drivers/acpi/acpica/exnames.c",
82412 + .param2 = 1,
82413 +};
82414 +
82415 +struct size_overflow_hash _000158_hash = {
82416 + .next = NULL,
82417 + .name = "acpi_os_allocate_zeroed",
82418 + .file = "include/acpi/platform/aclinux.h",
82419 + .param1 = 1,
82420 +};
82421 +
82422 +struct size_overflow_hash _000159_hash = {
82423 + .next = NULL,
82424 + .name = "acpi_ut_initialize_buffer",
82425 + .file = "drivers/acpi/acpica/utalloc.c",
82426 + .param2 = 1,
82427 +};
82428 +
82429 +struct size_overflow_hash _000160_hash = {
82430 + .next = NULL,
82431 + .name = "add_numbered_child",
82432 + .file = "drivers/mfd/twl-core.c",
82433 + .param5 = 1,
82434 +};
82435 +
82436 +struct size_overflow_hash _000161_hash = {
82437 + .next = NULL,
82438 + .name = "___alloc_bootmem_nopanic",
82439 + .file = "mm/nobootmem.c",
82440 + .param1 = 1,
82441 +};
82442 +
82443 +struct size_overflow_hash _000162_hash = {
82444 + .next = NULL,
82445 + .name = "alloc_large_system_hash",
82446 + .file = "include/linux/bootmem.h",
82447 + .param2 = 1,
82448 +};
82449 +
82450 +struct size_overflow_hash _000163_hash = {
82451 + .next = NULL,
82452 + .name = "audit_init_entry",
82453 + .file = "kernel/auditfilter.c",
82454 + .param1 = 1,
82455 +};
82456 +
82457 +struct size_overflow_hash _000164_hash = {
82458 + .next = NULL,
82459 + .name = "__bio_map_kern",
82460 + .file = "fs/bio.c",
82461 + .param2 = 1,
82462 + .param3 = 1,
82463 +};
82464 +
82465 +struct size_overflow_hash _000166_hash = {
82466 + .next = NULL,
82467 + .name = "blk_register_region",
82468 + .file = "include/linux/genhd.h",
82469 + .param1 = 1,
82470 + .param2 = 1,
82471 +};
82472 +
82473 +struct size_overflow_hash _000168_hash = {
82474 + .next = NULL,
82475 + .name = "cdev_add",
82476 + .file = "include/linux/cdev.h",
82477 + .param2 = 1,
82478 + .param3 = 1,
82479 +};
82480 +
82481 +struct size_overflow_hash _000170_hash = {
82482 + .next = NULL,
82483 + .name = "copy_to_user",
82484 + .file = "arch/x86/include/asm/uaccess_32.h",
82485 + .param3 = 1,
82486 +};
82487 +
82488 +struct size_overflow_hash _000171_hash = {
82489 + .next = NULL,
82490 + .name = "crypto_ahash_setkey",
82491 + .file = "include/crypto/hash.h",
82492 + .param3 = 1,
82493 +};
82494 +
82495 +struct size_overflow_hash _000172_hash = {
82496 + .next = NULL,
82497 + .name = "crypto_alloc_instance2",
82498 + .file = "include/crypto/algapi.h",
82499 + .param3 = 1,
82500 +};
82501 +
82502 +struct size_overflow_hash _000173_hash = {
82503 + .next = NULL,
82504 + .name = "crypto_shash_setkey",
82505 + .file = "include/crypto/hash.h",
82506 + .param3 = 1,
82507 +};
82508 +
82509 +struct size_overflow_hash _000174_hash = {
82510 + .next = NULL,
82511 + .name = "dev_set_alias",
82512 + .file = "include/linux/netdevice.h",
82513 + .param3 = 1,
82514 +};
82515 +
82516 +struct size_overflow_hash _000175_hash = {
82517 + .next = NULL,
82518 + .name = "do_readv_writev",
82519 + .file = "fs/read_write.c",
82520 + .param4 = 1,
82521 +};
82522 +
82523 +struct size_overflow_hash _000176_hash = {
82524 + .next = NULL,
82525 + .name = "getxattr",
82526 + .file = "fs/xattr.c",
82527 + .param4 = 1,
82528 +};
82529 +
82530 +struct size_overflow_hash _000177_hash = {
82531 + .next = NULL,
82532 + .name = "hugetlbfs_read_actor",
82533 + .file = "fs/hugetlbfs/inode.c",
82534 + .param2 = 1,
82535 + .param5 = 1,
82536 + .param4 = 1,
82537 +};
82538 +
82539 +struct size_overflow_hash _000180_hash = {
82540 + .next = NULL,
82541 + .name = "keyctl_instantiate_key",
82542 + .file = "security/keys/keyctl.c",
82543 + .param3 = 1,
82544 +};
82545 +
82546 +struct size_overflow_hash _000181_hash = {
82547 + .next = NULL,
82548 + .name = "keyctl_instantiate_key_iov",
82549 + .file = "security/keys/keyctl.c",
82550 + .param3 = 1,
82551 +};
82552 +
82553 +struct size_overflow_hash _000182_hash = {
82554 + .next = NULL,
82555 + .name = "__kfifo_from_user",
82556 + .file = "include/linux/kfifo.h",
82557 + .param3 = 1,
82558 +};
82559 +
82560 +struct size_overflow_hash _000183_hash = {
82561 + .next = NULL,
82562 + .name = "kimage_crash_alloc",
82563 + .file = "kernel/kexec.c",
82564 + .param3 = 1,
82565 +};
82566 +
82567 +struct size_overflow_hash _000184_hash = {
82568 + .next = NULL,
82569 + .name = "kimage_normal_alloc",
82570 + .file = "kernel/kexec.c",
82571 + .param3 = 1,
82572 +};
82573 +
82574 +struct size_overflow_hash _000185_hash = {
82575 + .next = NULL,
82576 + .name = "mpi_alloc",
82577 + .file = "include/linux/mpi.h",
82578 + .param1 = 1,
82579 +};
82580 +
82581 +struct size_overflow_hash _000186_hash = {
82582 + .next = NULL,
82583 + .name = "mpi_set_bit",
82584 + .file = "include/linux/mpi.h",
82585 + .param2 = 1,
82586 +};
82587 +
82588 +struct size_overflow_hash _000187_hash = {
82589 + .next = NULL,
82590 + .name = "mpi_set_highbit",
82591 + .file = "include/linux/mpi.h",
82592 + .param2 = 1,
82593 +};
82594 +
82595 +struct size_overflow_hash _000188_hash = {
82596 + .next = NULL,
82597 + .name = "neigh_hash_alloc",
82598 + .file = "net/core/neighbour.c",
82599 + .param1 = 1,
82600 +};
82601 +
82602 +struct size_overflow_hash _000189_hash = {
82603 + .next = NULL,
82604 + .name = "nl_pid_hash_zalloc",
82605 + .file = "net/netlink/af_netlink.c",
82606 + .param1 = 1,
82607 +};
82608 +
82609 +struct size_overflow_hash _000190_hash = {
82610 + .next = NULL,
82611 + .name = "pci_add_cap_save_buffer",
82612 + .file = "drivers/pci/pci.c",
82613 + .param3 = 1,
82614 +};
82615 +
82616 +struct size_overflow_hash _000191_hash = {
82617 + .next = NULL,
82618 + .name = "pcpu_mem_zalloc",
82619 + .file = "mm/percpu.c",
82620 + .param1 = 1,
82621 +};
82622 +
82623 +struct size_overflow_hash _000192_hash = {
82624 + .next = NULL,
82625 + .name = "platform_create_bundle",
82626 + .file = "include/linux/platform_device.h",
82627 + .param4 = 1,
82628 + .param6 = 1,
82629 +};
82630 +
82631 +struct size_overflow_hash _000194_hash = {
82632 + .next = NULL,
82633 + .name = "process_vm_rw",
82634 + .file = "mm/process_vm_access.c",
82635 + .param3 = 1,
82636 + .param5 = 1,
82637 +};
82638 +
82639 +struct size_overflow_hash _000196_hash = {
82640 + .next = NULL,
82641 + .name = "process_vm_rw_single_vec",
82642 + .file = "mm/process_vm_access.c",
82643 + .param1 = 1,
82644 + .param2 = 1,
82645 +};
82646 +
82647 +struct size_overflow_hash _000198_hash = {
82648 + .next = NULL,
82649 + .name = "profile_load",
82650 + .file = "security/apparmor/apparmorfs.c",
82651 + .param3 = 1,
82652 +};
82653 +
82654 +struct size_overflow_hash _000199_hash = {
82655 + .next = NULL,
82656 + .name = "profile_remove",
82657 + .file = "security/apparmor/apparmorfs.c",
82658 + .param3 = 1,
82659 +};
82660 +
82661 +struct size_overflow_hash _000200_hash = {
82662 + .next = NULL,
82663 + .name = "profile_replace",
82664 + .file = "security/apparmor/apparmorfs.c",
82665 + .param3 = 1,
82666 +};
82667 +
82668 +struct size_overflow_hash _000201_hash = {
82669 + .next = NULL,
82670 + .name = "regcache_rbtree_insert_to_block",
82671 + .file = "drivers/base/regmap/regcache-rbtree.c",
82672 + .param5 = 1,
82673 +};
82674 +
82675 +struct size_overflow_hash _000202_hash = {
82676 + .next = NULL,
82677 + .name = "regmap_raw_write",
82678 + .file = "include/linux/regmap.h",
82679 + .param4 = 1,
82680 +};
82681 +
82682 +struct size_overflow_hash _000203_hash = {
82683 + .next = NULL,
82684 + .name = "relay_alloc_page_array",
82685 + .file = "kernel/relay.c",
82686 + .param1 = 1,
82687 +};
82688 +
82689 +struct size_overflow_hash _000204_hash = {
82690 + .next = NULL,
82691 + .name = "RESIZE_IF_NEEDED",
82692 + .file = "lib/mpi/mpi-internal.h",
82693 + .param2 = 1,
82694 +};
82695 +
82696 +struct size_overflow_hash _000205_hash = {
82697 + .next = NULL,
82698 + .name = "security_context_to_sid",
82699 + .file = "security/selinux/ss/services.c",
82700 + .param2 = 1,
82701 +};
82702 +
82703 +struct size_overflow_hash _000206_hash = {
82704 + .next = NULL,
82705 + .name = "security_context_to_sid_default",
82706 + .file = "security/selinux/ss/services.c",
82707 + .param2 = 1,
82708 +};
82709 +
82710 +struct size_overflow_hash _000207_hash = {
82711 + .next = NULL,
82712 + .name = "security_context_to_sid_force",
82713 + .file = "security/selinux/ss/services.c",
82714 + .param2 = 1,
82715 +};
82716 +
82717 +struct size_overflow_hash _000208_hash = {
82718 + .next = NULL,
82719 + .name = "selinux_transaction_write",
82720 + .file = "security/selinux/selinuxfs.c",
82721 + .param3 = 1,
82722 +};
82723 +
82724 +struct size_overflow_hash _000209_hash = {
82725 + .next = NULL,
82726 + .name = "sel_write_access",
82727 + .file = "security/selinux/selinuxfs.c",
82728 + .param3 = 1,
82729 +};
82730 +
82731 +struct size_overflow_hash _000210_hash = {
82732 + .next = NULL,
82733 + .name = "sel_write_create",
82734 + .file = "security/selinux/selinuxfs.c",
82735 + .param3 = 1,
82736 +};
82737 +
82738 +struct size_overflow_hash _000211_hash = {
82739 + .next = NULL,
82740 + .name = "sel_write_member",
82741 + .file = "security/selinux/selinuxfs.c",
82742 + .param3 = 1,
82743 +};
82744 +
82745 +struct size_overflow_hash _000212_hash = {
82746 + .next = NULL,
82747 + .name = "sel_write_relabel",
82748 + .file = "security/selinux/selinuxfs.c",
82749 + .param3 = 1,
82750 +};
82751 +
82752 +struct size_overflow_hash _000213_hash = {
82753 + .next = NULL,
82754 + .name = "sel_write_user",
82755 + .file = "security/selinux/selinuxfs.c",
82756 + .param3 = 1,
82757 +};
82758 +
82759 +struct size_overflow_hash _000214_hash = {
82760 + .next = NULL,
82761 + .name = "setkey",
82762 + .file = "crypto/cipher.c",
82763 + .param3 = 1,
82764 +};
82765 +
82766 +struct size_overflow_hash _000215_hash = {
82767 + .next = NULL,
82768 + .name = "setkey",
82769 + .file = "crypto/ablkcipher.c",
82770 + .param3 = 1,
82771 +};
82772 +
82773 +struct size_overflow_hash _000216_hash = {
82774 + .next = NULL,
82775 + .name = "setkey",
82776 + .file = "crypto/aead.c",
82777 + .param3 = 1,
82778 +};
82779 +
82780 +struct size_overflow_hash _000217_hash = {
82781 + .next = NULL,
82782 + .name = "setkey",
82783 + .file = "crypto/blkcipher.c",
82784 + .param3 = 1,
82785 +};
82786 +
82787 +struct size_overflow_hash _000218_hash = {
82788 + .next = NULL,
82789 + .name = "smk_write_access",
82790 + .file = "security/smack/smackfs.c",
82791 + .param3 = 1,
82792 +};
82793 +
82794 +struct size_overflow_hash _000219_hash = {
82795 + .next = NULL,
82796 + .name = "snapshot_write",
82797 + .file = "kernel/power/user.c",
82798 + .param3 = 1,
82799 +};
82800 +
82801 +struct size_overflow_hash _000220_hash = {
82802 + .next = NULL,
82803 + .name = "spi_alloc_master",
82804 + .file = "include/linux/spi/spi.h",
82805 + .param2 = 1,
82806 +};
82807 +
82808 +struct size_overflow_hash _000221_hash = {
82809 + .next = NULL,
82810 + .name = "spi_register_board_info",
82811 + .file = "include/linux/spi/spi.h",
82812 + .param2 = 1,
82813 +};
82814 +
82815 +struct size_overflow_hash _000222_hash = {
82816 + .next = NULL,
82817 + .name = "sys_flistxattr",
82818 + .file = "include/linux/syscalls.h",
82819 + .param3 = 1,
82820 +};
82821 +
82822 +struct size_overflow_hash _000223_hash = {
82823 + .next = NULL,
82824 + .name = "sys_fsetxattr",
82825 + .file = "include/linux/syscalls.h",
82826 + .param4 = 1,
82827 +};
82828 +
82829 +struct size_overflow_hash _000224_hash = {
82830 + .next = NULL,
82831 + .name = "sysfs_write_file",
82832 + .file = "fs/sysfs/file.c",
82833 + .param3 = 1,
82834 +};
82835 +
82836 +struct size_overflow_hash _000225_hash = {
82837 + .next = NULL,
82838 + .name = "sys_ipc",
82839 + .file = "include/linux/syscalls.h",
82840 + .param3 = 1,
82841 +};
82842 +
82843 +struct size_overflow_hash _000226_hash = {
82844 + .next = NULL,
82845 + .name = "sys_keyctl",
82846 + .file = "include/linux/syscalls.h",
82847 + .param4 = 1,
82848 +};
82849 +
82850 +struct size_overflow_hash _000227_hash = {
82851 + .next = NULL,
82852 + .name = "sys_listxattr",
82853 + .file = "include/linux/syscalls.h",
82854 + .param3 = 1,
82855 +};
82856 +
82857 +struct size_overflow_hash _000228_hash = {
82858 + .next = NULL,
82859 + .name = "sys_llistxattr",
82860 + .file = "include/linux/syscalls.h",
82861 + .param3 = 1,
82862 +};
82863 +
82864 +struct size_overflow_hash _000229_hash = {
82865 + .next = NULL,
82866 + .name = "sys_lsetxattr",
82867 + .file = "include/linux/syscalls.h",
82868 + .param4 = 1,
82869 +};
82870 +
82871 +struct size_overflow_hash _000230_hash = {
82872 + .next = NULL,
82873 + .name = "sys_sched_setaffinity",
82874 + .file = "include/linux/syscalls.h",
82875 + .param2 = 1,
82876 +};
82877 +
82878 +struct size_overflow_hash _000231_hash = {
82879 + .next = NULL,
82880 + .name = "sys_semop",
82881 + .file = "include/linux/syscalls.h",
82882 + .param3 = 1,
82883 +};
82884 +
82885 +struct size_overflow_hash _000232_hash = {
82886 + .next = NULL,
82887 + .name = "sys_setxattr",
82888 + .file = "include/linux/syscalls.h",
82889 + .param4 = 1,
82890 +};
82891 +
82892 +struct size_overflow_hash _000233_hash = {
82893 + .next = NULL,
82894 + .name = "tnode_alloc",
82895 + .file = "net/ipv4/fib_trie.c",
82896 + .param1 = 1,
82897 +};
82898 +
82899 +struct size_overflow_hash _000234_hash = {
82900 + .next = NULL,
82901 + .name = "tomoyo_commit_ok",
82902 + .file = "security/tomoyo/memory.c",
82903 + .param2 = 1,
82904 +};
82905 +
82906 +struct size_overflow_hash _000235_hash = {
82907 + .next = NULL,
82908 + .name = "tomoyo_scan_bprm",
82909 + .file = "security/tomoyo/condition.c",
82910 + .param2 = 1,
82911 + .param4 = 1,
82912 +};
82913 +
82914 +struct size_overflow_hash _000237_hash = {
82915 + .next = NULL,
82916 + .name = "tty_write",
82917 + .file = "drivers/tty/tty_io.c",
82918 + .param3 = 1,
82919 +};
82920 +
82921 +struct size_overflow_hash _000238_hash = {
82922 + .next = NULL,
82923 + .name = "vc_resize",
82924 + .file = "include/linux/vt_kern.h",
82925 + .param2 = 1,
82926 + .param3 = 1,
82927 +};
82928 +
82929 +struct size_overflow_hash _000240_hash = {
82930 + .next = NULL,
82931 + .name = "vmalloc",
82932 + .file = "include/linux/vmalloc.h",
82933 + .param1 = 1,
82934 +};
82935 +
82936 +struct size_overflow_hash _000241_hash = {
82937 + .next = NULL,
82938 + .name = "vzalloc",
82939 + .file = "include/linux/vmalloc.h",
82940 + .param1 = 1,
82941 +};
82942 +
82943 +struct size_overflow_hash _000242_hash = {
82944 + .next = NULL,
82945 + .name = "vzalloc_node",
82946 + .file = "include/linux/vmalloc.h",
82947 + .param1 = 1,
82948 +};
82949 +
82950 +struct size_overflow_hash _000243_hash = {
82951 + .next = NULL,
82952 + .name = "xfrm_hash_alloc",
82953 + .file = "net/xfrm/xfrm_hash.c",
82954 + .param1 = 1,
82955 +};
82956 +
82957 +struct size_overflow_hash _000244_hash = {
82958 + .next = NULL,
82959 + .name = "acpi_ds_build_internal_package_obj",
82960 + .file = "drivers/acpi/acpica/dsobject.c",
82961 + .param3 = 1,
82962 +};
82963 +
82964 +struct size_overflow_hash _000245_hash = {
82965 + .next = NULL,
82966 + .name = "acpi_system_read_event",
82967 + .file = "drivers/acpi/event.c",
82968 + .param3 = 1,
82969 +};
82970 +
82971 +struct size_overflow_hash _000246_hash = {
82972 + .next = NULL,
82973 + .name = "acpi_ut_create_buffer_object",
82974 + .file = "drivers/acpi/acpica/utobject.c",
82975 + .param1 = 1,
82976 +};
82977 +
82978 +struct size_overflow_hash _000247_hash = {
82979 + .next = NULL,
82980 + .name = "acpi_ut_create_package_object",
82981 + .file = "drivers/acpi/acpica/utobject.c",
82982 + .param1 = 1,
82983 +};
82984 +
82985 +struct size_overflow_hash _000248_hash = {
82986 + .next = NULL,
82987 + .name = "acpi_ut_create_string_object",
82988 + .file = "drivers/acpi/acpica/utobject.c",
82989 + .param1 = 1,
82990 +};
82991 +
82992 +struct size_overflow_hash _000249_hash = {
82993 + .next = NULL,
82994 + .name = "add_child",
82995 + .file = "drivers/mfd/twl-core.c",
82996 + .param4 = 1,
82997 +};
82998 +
82999 +struct size_overflow_hash _000250_hash = {
83000 + .next = NULL,
83001 + .name = "___alloc_bootmem",
83002 + .file = "mm/nobootmem.c",
83003 + .param1 = 1,
83004 +};
83005 +
83006 +struct size_overflow_hash _000251_hash = {
83007 + .next = NULL,
83008 + .name = "__alloc_bootmem_nopanic",
83009 + .file = "include/linux/bootmem.h",
83010 + .param1 = 1,
83011 +};
83012 +
83013 +struct size_overflow_hash _000252_hash = {
83014 + .next = NULL,
83015 + .name = "async_setkey",
83016 + .file = "crypto/blkcipher.c",
83017 + .param3 = 1,
83018 +};
83019 +
83020 +struct size_overflow_hash _000253_hash = {
83021 + .next = NULL,
83022 + .name = "bio_map_kern",
83023 + .file = "include/linux/bio.h",
83024 + .param3 = 1,
83025 +};
83026 +
83027 +struct size_overflow_hash _000254_hash = {
83028 + .next = NULL,
83029 + .name = "copy_oldmem_page",
83030 + .file = "include/linux/crash_dump.h",
83031 + .param3 = 1,
83032 +};
83033 +
83034 +struct size_overflow_hash _000255_hash = {
83035 + .next = NULL,
83036 + .name = "do_sigpending",
83037 + .file = "include/linux/signal.h",
83038 + .param2 = 1,
83039 +};
83040 +
83041 +struct size_overflow_hash _000257_hash = {
83042 + .next = NULL,
83043 + .name = "keyctl_describe_key",
83044 + .file = "security/keys/keyctl.c",
83045 + .param3 = 1,
83046 +};
83047 +
83048 +struct size_overflow_hash _000258_hash = {
83049 + .next = NULL,
83050 + .name = "keyctl_get_security",
83051 + .file = "security/keys/keyctl.c",
83052 + .param3 = 1,
83053 +};
83054 +
83055 +struct size_overflow_hash _000259_hash = {
83056 + .next = NULL,
83057 + .name = "keyring_read",
83058 + .file = "security/keys/keyring.c",
83059 + .param3 = 1,
83060 +};
83061 +
83062 +struct size_overflow_hash _000260_hash = {
83063 + .next = NULL,
83064 + .name = "kfifo_copy_to_user",
83065 + .file = "kernel/kfifo.c",
83066 + .param3 = 1,
83067 +};
83068 +
83069 +struct size_overflow_hash _000261_hash = {
83070 + .next = NULL,
83071 + .name = "mousedev_read",
83072 + .file = "drivers/input/mousedev.c",
83073 + .param3 = 1,
83074 +};
83075 +
83076 +struct size_overflow_hash _000262_hash = {
83077 + .next = NULL,
83078 + .name = "mpi_lshift_limbs",
83079 + .file = "lib/mpi/mpi-bit.c",
83080 + .param2 = 1,
83081 +};
83082 +
83083 +struct size_overflow_hash _000263_hash = {
83084 + .next = NULL,
83085 + .name = "neigh_hash_grow",
83086 + .file = "net/core/neighbour.c",
83087 + .param2 = 1,
83088 +};
83089 +
83090 +struct size_overflow_hash _000264_hash = {
83091 + .next = NULL,
83092 + .name = "posix_clock_register",
83093 + .file = "include/linux/posix-clock.h",
83094 + .param2 = 1,
83095 +};
83096 +
83097 +struct size_overflow_hash _000265_hash = {
83098 + .next = NULL,
83099 + .name = "__proc_file_read",
83100 + .file = "fs/proc/generic.c",
83101 + .param3 = 1,
83102 +};
83103 +
83104 +struct size_overflow_hash _000266_hash = {
83105 + .next = NULL,
83106 + .name = "read_profile",
83107 + .file = "kernel/profile.c",
83108 + .param3 = 1,
83109 +};
83110 +
83111 +struct size_overflow_hash _000267_hash = {
83112 + .next = NULL,
83113 + .name = "read_vmcore",
83114 + .file = "fs/proc/vmcore.c",
83115 + .param3 = 1,
83116 +};
83117 +
83118 +struct size_overflow_hash _000268_hash = {
83119 + .next = NULL,
83120 + .name = "redirected_tty_write",
83121 + .file = "drivers/tty/tty_io.c",
83122 + .param3 = 1,
83123 +};
83124 +
83125 +struct size_overflow_hash _000269_hash = {
83126 + .next = NULL,
83127 + .name = "__register_chrdev",
83128 + .file = "include/linux/fs.h",
83129 + .param2 = 1,
83130 + .param3 = 1,
83131 +};
83132 +
83133 +struct size_overflow_hash _000271_hash = {
83134 + .next = NULL,
83135 + .name = "request_key_auth_read",
83136 + .file = "security/keys/request_key_auth.c",
83137 + .param3 = 1,
83138 +};
83139 +
83140 +struct size_overflow_hash _000272_hash = {
83141 + .next = NULL,
83142 + .name = "shash_async_setkey",
83143 + .file = "crypto/shash.c",
83144 + .param3 = 1,
83145 +};
83146 +
83147 +struct size_overflow_hash _000273_hash = {
83148 + .next = NULL,
83149 + .name = "shash_compat_setkey",
83150 + .file = "crypto/shash.c",
83151 + .param3 = 1,
83152 +};
83153 +
83154 +struct size_overflow_hash _000274_hash = {
83155 + .next = NULL,
83156 + .name = "simple_read_from_buffer",
83157 + .file = "include/linux/fs.h",
83158 + .param2 = 1,
83159 + .param5 = 1,
83160 +};
83161 +
83162 +struct size_overflow_hash _000276_hash = {
83163 + .next = NULL,
83164 + .name = "store_ifalias",
83165 + .file = "net/core/net-sysfs.c",
83166 + .param4 = 1,
83167 +};
83168 +
83169 +struct size_overflow_hash _000277_hash = {
83170 + .next = NULL,
83171 + .name = "subbuf_read_actor",
83172 + .file = "kernel/relay.c",
83173 + .param3 = 1,
83174 +};
83175 +
83176 +struct size_overflow_hash _000278_hash = {
83177 + .next = NULL,
83178 + .name = "sys_fgetxattr",
83179 + .file = "include/linux/syscalls.h",
83180 + .param4 = 1,
83181 +};
83182 +
83183 +struct size_overflow_hash _000279_hash = {
83184 + .next = NULL,
83185 + .name = "sys_getxattr",
83186 + .file = "include/linux/syscalls.h",
83187 + .param4 = 1,
83188 +};
83189 +
83190 +struct size_overflow_hash _000280_hash = {
83191 + .next = NULL,
83192 + .name = "sys_kexec_load",
83193 + .file = "include/linux/syscalls.h",
83194 + .param2 = 1,
83195 +};
83196 +
83197 +struct size_overflow_hash _000281_hash = {
83198 + .next = NULL,
83199 + .name = "sys_lgetxattr",
83200 + .file = "include/linux/syscalls.h",
83201 + .param4 = 1,
83202 +};
83203 +
83204 +struct size_overflow_hash _000282_hash = {
83205 + .next = NULL,
83206 + .name = "sys_process_vm_readv",
83207 + .file = "include/linux/syscalls.h",
83208 + .param3 = 1,
83209 + .param5 = 1,
83210 +};
83211 +
83212 +struct size_overflow_hash _000284_hash = {
83213 + .next = NULL,
83214 + .name = "sys_process_vm_writev",
83215 + .file = "include/linux/syscalls.h",
83216 + .param3 = 1,
83217 + .param5 = 1,
83218 +};
83219 +
83220 +struct size_overflow_hash _000286_hash = {
83221 + .next = NULL,
83222 + .name = "sys_sched_getaffinity",
83223 + .file = "include/linux/syscalls.h",
83224 + .param2 = 1,
83225 +};
83226 +
83227 +struct size_overflow_hash _000287_hash = {
83228 + .next = NULL,
83229 + .name = "tomoyo_read_self",
83230 + .file = "security/tomoyo/securityfs_if.c",
83231 + .param3 = 1,
83232 +};
83233 +
83234 +struct size_overflow_hash _000288_hash = {
83235 + .next = NULL,
83236 + .name = "tpm_read",
83237 + .file = "drivers/char/tpm/tpm.c",
83238 + .param3 = 1,
83239 +};
83240 +
83241 +struct size_overflow_hash _000289_hash = {
83242 + .next = NULL,
83243 + .name = "user_read",
83244 + .file = "include/keys/user-type.h",
83245 + .param3 = 1,
83246 +};
83247 +
83248 +struct size_overflow_hash _000290_hash = {
83249 + .next = NULL,
83250 + .name = "vcs_read",
83251 + .file = "drivers/tty/vt/vc_screen.c",
83252 + .param3 = 1,
83253 +};
83254 +
83255 +struct size_overflow_hash _000291_hash = {
83256 + .next = NULL,
83257 + .name = "vfs_readv",
83258 + .file = "include/linux/fs.h",
83259 + .param3 = 1,
83260 +};
83261 +
83262 +struct size_overflow_hash _000292_hash = {
83263 + .next = NULL,
83264 + .name = "vfs_writev",
83265 + .file = "include/linux/fs.h",
83266 + .param3 = 1,
83267 +};
83268 +
83269 +struct size_overflow_hash _000293_hash = {
83270 + .next = NULL,
83271 + .name = "vga_arb_read",
83272 + .file = "drivers/gpu/vga/vgaarb.c",
83273 + .param3 = 1,
83274 +};
83275 +
83276 +struct size_overflow_hash _000294_hash = {
83277 + .next = NULL,
83278 + .name = "xz_dec_lzma2_create",
83279 + .file = "lib/xz/xz_dec_lzma2.c",
83280 + .param2 = 1,
83281 +};
83282 +
83283 +struct size_overflow_hash _000295_hash = {
83284 + .next = NULL,
83285 + .name = "aat2870_reg_read_file",
83286 + .file = "drivers/mfd/aat2870-core.c",
83287 + .param3 = 1,
83288 +};
83289 +
83290 +struct size_overflow_hash _000296_hash = {
83291 + .next = NULL,
83292 + .name = "__alloc_bootmem",
83293 + .file = "include/linux/bootmem.h",
83294 + .param1 = 1,
83295 +};
83296 +
83297 +struct size_overflow_hash _000297_hash = {
83298 + .next = NULL,
83299 + .name = "__alloc_bootmem_low",
83300 + .file = "include/linux/bootmem.h",
83301 + .param1 = 1,
83302 +};
83303 +
83304 +struct size_overflow_hash _000298_hash = {
83305 + .next = NULL,
83306 + .name = "__alloc_bootmem_node_nopanic",
83307 + .file = "include/linux/bootmem.h",
83308 + .param2 = 1,
83309 +};
83310 +
83311 +struct size_overflow_hash _000299_hash = {
83312 + .next = NULL,
83313 + .name = "blk_rq_map_kern",
83314 + .file = "include/linux/blkdev.h",
83315 + .param4 = 1,
83316 +};
83317 +
83318 +struct size_overflow_hash _000300_hash = {
83319 + .next = NULL,
83320 + .name = "cgroup_read_s64",
83321 + .file = "kernel/cgroup.c",
83322 + .param5 = 1,
83323 +};
83324 +
83325 +struct size_overflow_hash _000301_hash = {
83326 + .next = NULL,
83327 + .name = "cgroup_read_u64",
83328 + .file = "kernel/cgroup.c",
83329 + .param5 = 1,
83330 +};
83331 +
83332 +struct size_overflow_hash _000302_hash = {
83333 + .next = NULL,
83334 + .name = "cpuset_common_file_read",
83335 + .file = "kernel/cpuset.c",
83336 + .param5 = 1,
83337 +};
83338 +
83339 +struct size_overflow_hash _000303_hash = {
83340 + .next = NULL,
83341 + .name = "filter_read",
83342 + .file = "lib/dma-debug.c",
83343 + .param3 = 1,
83344 +};
83345 +
83346 +struct size_overflow_hash _000304_hash = {
83347 + .next = NULL,
83348 + .name = "ima_show_htable_value",
83349 + .file = "security/integrity/ima/ima_fs.c",
83350 + .param2 = 1,
83351 +};
83352 +
83353 +struct size_overflow_hash _000305_hash = {
83354 + .next = NULL,
83355 + .name = "kernel_readv",
83356 + .file = "fs/splice.c",
83357 + .param3 = 1,
83358 +};
83359 +
83360 +struct size_overflow_hash _000306_hash = {
83361 + .next = NULL,
83362 + .name = "__kfifo_to_user",
83363 + .file = "include/linux/kfifo.h",
83364 + .param3 = 1,
83365 +};
83366 +
83367 +struct size_overflow_hash _000307_hash = {
83368 + .next = NULL,
83369 + .name = "__kfifo_to_user_r",
83370 + .file = "include/linux/kfifo.h",
83371 + .param3 = 1,
83372 +};
83373 +
83374 +struct size_overflow_hash _000308_hash = {
83375 + .next = NULL,
83376 + .name = "mqueue_read_file",
83377 + .file = "ipc/mqueue.c",
83378 + .param3 = 1,
83379 +};
83380 +
83381 +struct size_overflow_hash _000309_hash = {
83382 + .next = NULL,
83383 + .name = "oom_adjust_read",
83384 + .file = "fs/proc/base.c",
83385 + .param3 = 1,
83386 +};
83387 +
83388 +struct size_overflow_hash _000310_hash = {
83389 + .next = NULL,
83390 + .name = "oom_score_adj_read",
83391 + .file = "fs/proc/base.c",
83392 + .param3 = 1,
83393 +};
83394 +
83395 +struct size_overflow_hash _000311_hash = {
83396 + .next = NULL,
83397 + .name = "pm_qos_power_read",
83398 + .file = "kernel/power/qos.c",
83399 + .param3 = 1,
83400 +};
83401 +
83402 +struct size_overflow_hash _000312_hash = {
83403 + .next = NULL,
83404 + .name = "proc_coredump_filter_read",
83405 + .file = "fs/proc/base.c",
83406 + .param3 = 1,
83407 +};
83408 +
83409 +struct size_overflow_hash _000313_hash = {
83410 + .next = NULL,
83411 + .name = "proc_fdinfo_read",
83412 + .file = "fs/proc/base.c",
83413 + .param3 = 1,
83414 +};
83415 +
83416 +struct size_overflow_hash _000314_hash = {
83417 + .next = NULL,
83418 + .name = "proc_info_read",
83419 + .file = "fs/proc/base.c",
83420 + .param3 = 1,
83421 +};
83422 +
83423 +struct size_overflow_hash _000315_hash = {
83424 + .next = NULL,
83425 + .name = "proc_loginuid_read",
83426 + .file = "fs/proc/base.c",
83427 + .param3 = 1,
83428 +};
83429 +
83430 +struct size_overflow_hash _000316_hash = {
83431 + .next = NULL,
83432 + .name = "proc_pid_attr_read",
83433 + .file = "fs/proc/base.c",
83434 + .param3 = 1,
83435 +};
83436 +
83437 +struct size_overflow_hash _000317_hash = {
83438 + .next = NULL,
83439 + .name = "proc_sessionid_read",
83440 + .file = "fs/proc/base.c",
83441 + .param3 = 1,
83442 +};
83443 +
83444 +struct size_overflow_hash _000318_hash = {
83445 + .next = NULL,
83446 + .name = "pstore_file_read",
83447 + .file = "fs/pstore/inode.c",
83448 + .param3 = 1,
83449 +};
83450 +
83451 +struct size_overflow_hash _000319_hash = {
83452 + .next = NULL,
83453 + .name = "read_enabled_file_bool",
83454 + .file = "kernel/kprobes.c",
83455 + .param3 = 1,
83456 +};
83457 +
83458 +struct size_overflow_hash _000320_hash = {
83459 + .next = NULL,
83460 + .name = "read_file_blob",
83461 + .file = "fs/debugfs/file.c",
83462 + .param3 = 1,
83463 +};
83464 +
83465 +struct size_overflow_hash _000321_hash = {
83466 + .next = NULL,
83467 + .name = "read_file_bool",
83468 + .file = "fs/debugfs/file.c",
83469 + .param3 = 1,
83470 +};
83471 +
83472 +struct size_overflow_hash _000322_hash = {
83473 + .next = NULL,
83474 + .name = "read_from_oldmem",
83475 + .file = "fs/proc/vmcore.c",
83476 + .param2 = 1,
83477 +};
83478 +
83479 +struct size_overflow_hash _000323_hash = {
83480 + .next = NULL,
83481 + .name = "read_oldmem",
83482 + .file = "drivers/char/mem.c",
83483 + .param3 = 1,
83484 +};
83485 +
83486 +struct size_overflow_hash _000324_hash = {
83487 + .next = NULL,
83488 + .name = "res_counter_read",
83489 + .file = "include/linux/res_counter.h",
83490 + .param4 = 1,
83491 +};
83492 +
83493 +struct size_overflow_hash _000325_hash = {
83494 + .next = NULL,
83495 + .name = "sel_read_avc_cache_threshold",
83496 + .file = "security/selinux/selinuxfs.c",
83497 + .param3 = 1,
83498 +};
83499 +
83500 +struct size_overflow_hash _000326_hash = {
83501 + .next = NULL,
83502 + .name = "sel_read_avc_hash_stats",
83503 + .file = "security/selinux/selinuxfs.c",
83504 + .param3 = 1,
83505 +};
83506 +
83507 +struct size_overflow_hash _000327_hash = {
83508 + .next = NULL,
83509 + .name = "sel_read_bool",
83510 + .file = "security/selinux/selinuxfs.c",
83511 + .param3 = 1,
83512 +};
83513 +
83514 +struct size_overflow_hash _000328_hash = {
83515 + .next = NULL,
83516 + .name = "sel_read_checkreqprot",
83517 + .file = "security/selinux/selinuxfs.c",
83518 + .param3 = 1,
83519 +};
83520 +
83521 +struct size_overflow_hash _000329_hash = {
83522 + .next = NULL,
83523 + .name = "sel_read_class",
83524 + .file = "security/selinux/selinuxfs.c",
83525 + .param3 = 1,
83526 +};
83527 +
83528 +struct size_overflow_hash _000330_hash = {
83529 + .next = NULL,
83530 + .name = "sel_read_enforce",
83531 + .file = "security/selinux/selinuxfs.c",
83532 + .param3 = 1,
83533 +};
83534 +
83535 +struct size_overflow_hash _000331_hash = {
83536 + .next = NULL,
83537 + .name = "sel_read_handle_status",
83538 + .file = "security/selinux/selinuxfs.c",
83539 + .param3 = 1,
83540 +};
83541 +
83542 +struct size_overflow_hash _000332_hash = {
83543 + .next = NULL,
83544 + .name = "sel_read_handle_unknown",
83545 + .file = "security/selinux/selinuxfs.c",
83546 + .param3 = 1,
83547 +};
83548 +
83549 +struct size_overflow_hash _000333_hash = {
83550 + .next = NULL,
83551 + .name = "sel_read_initcon",
83552 + .file = "security/selinux/selinuxfs.c",
83553 + .param3 = 1,
83554 +};
83555 +
83556 +struct size_overflow_hash _000334_hash = {
83557 + .next = NULL,
83558 + .name = "sel_read_mls",
83559 + .file = "security/selinux/selinuxfs.c",
83560 + .param3 = 1,
83561 +};
83562 +
83563 +struct size_overflow_hash _000335_hash = {
83564 + .next = NULL,
83565 + .name = "sel_read_perm",
83566 + .file = "security/selinux/selinuxfs.c",
83567 + .param3 = 1,
83568 +};
83569 +
83570 +struct size_overflow_hash _000336_hash = {
83571 + .next = NULL,
83572 + .name = "sel_read_policy",
83573 + .file = "security/selinux/selinuxfs.c",
83574 + .param3 = 1,
83575 +};
83576 +
83577 +struct size_overflow_hash _000337_hash = {
83578 + .next = NULL,
83579 + .name = "sel_read_policycap",
83580 + .file = "security/selinux/selinuxfs.c",
83581 + .param3 = 1,
83582 +};
83583 +
83584 +struct size_overflow_hash _000338_hash = {
83585 + .next = NULL,
83586 + .name = "sel_read_policyvers",
83587 + .file = "security/selinux/selinuxfs.c",
83588 + .param3 = 1,
83589 +};
83590 +
83591 +struct size_overflow_hash _000339_hash = {
83592 + .next = NULL,
83593 + .name = "simple_attr_read",
83594 + .file = "include/linux/fs.h",
83595 + .param3 = 1,
83596 +};
83597 +
83598 +struct size_overflow_hash _000340_hash = {
83599 + .next = NULL,
83600 + .name = "simple_transaction_read",
83601 + .file = "include/linux/fs.h",
83602 + .param3 = 1,
83603 +};
83604 +
83605 +struct size_overflow_hash _000341_hash = {
83606 + .next = NULL,
83607 + .name = "smk_read_ambient",
83608 + .file = "security/smack/smackfs.c",
83609 + .param3 = 1,
83610 +};
83611 +
83612 +struct size_overflow_hash _000342_hash = {
83613 + .next = NULL,
83614 + .name = "smk_read_direct",
83615 + .file = "security/smack/smackfs.c",
83616 + .param3 = 1,
83617 +};
83618 +
83619 +struct size_overflow_hash _000343_hash = {
83620 + .next = NULL,
83621 + .name = "smk_read_doi",
83622 + .file = "security/smack/smackfs.c",
83623 + .param3 = 1,
83624 +};
83625 +
83626 +struct size_overflow_hash _000344_hash = {
83627 + .next = NULL,
83628 + .name = "smk_read_logging",
83629 + .file = "security/smack/smackfs.c",
83630 + .param3 = 1,
83631 +};
83632 +
83633 +struct size_overflow_hash _000345_hash = {
83634 + .next = NULL,
83635 + .name = "smk_read_onlycap",
83636 + .file = "security/smack/smackfs.c",
83637 + .param3 = 1,
83638 +};
83639 +
83640 +struct size_overflow_hash _000346_hash = {
83641 + .next = NULL,
83642 + .name = "snapshot_read",
83643 + .file = "kernel/power/user.c",
83644 + .param3 = 1,
83645 +};
83646 +
83647 +struct size_overflow_hash _000347_hash = {
83648 + .next = NULL,
83649 + .name = "supply_map_read_file",
83650 + .file = "drivers/regulator/core.c",
83651 + .param3 = 1,
83652 +};
83653 +
83654 +struct size_overflow_hash _000348_hash = {
83655 + .next = NULL,
83656 + .name = "sysfs_read_file",
83657 + .file = "fs/sysfs/file.c",
83658 + .param3 = 1,
83659 +};
83660 +
83661 +struct size_overflow_hash _000349_hash = {
83662 + .next = NULL,
83663 + .name = "sys_preadv",
83664 + .file = "include/linux/syscalls.h",
83665 + .param3 = 1,
83666 +};
83667 +
83668 +struct size_overflow_hash _000350_hash = {
83669 + .next = NULL,
83670 + .name = "sys_pwritev",
83671 + .file = "include/linux/syscalls.h",
83672 + .param3 = 1,
83673 +};
83674 +
83675 +struct size_overflow_hash _000351_hash = {
83676 + .next = NULL,
83677 + .name = "sys_readv",
83678 + .file = "include/linux/syscalls.h",
83679 + .param3 = 1,
83680 +};
83681 +
83682 +struct size_overflow_hash _000352_hash = {
83683 + .next = NULL,
83684 + .name = "sys_rt_sigpending",
83685 + .file = "include/linux/syscalls.h",
83686 + .param2 = 1,
83687 +};
83688 +
83689 +struct size_overflow_hash _000353_hash = {
83690 + .next = NULL,
83691 + .name = "sys_writev",
83692 + .file = "include/linux/syscalls.h",
83693 + .param3 = 1,
83694 +};
83695 +
83696 +struct size_overflow_hash _000354_hash = {
83697 + .next = NULL,
83698 + .name = "ima_show_htable_violations",
83699 + .file = "security/integrity/ima/ima_fs.c",
83700 + .param3 = 1,
83701 +};
83702 +
83703 +struct size_overflow_hash _000355_hash = {
83704 + .next = NULL,
83705 + .name = "ima_show_measurements_count",
83706 + .file = "security/integrity/ima/ima_fs.c",
83707 + .param3 = 1,
83708 +};
83709 +
83710 +struct size_overflow_hash _000356_hash = {
83711 + .next = NULL,
83712 + .name = "alloc_cpu_rmap",
83713 + .file = "include/linux/cpu_rmap.h",
83714 + .param1 = 1,
83715 +};
83716 +
83717 +struct size_overflow_hash _000357_hash = {
83718 + .next = NULL,
83719 + .name = "alloc_page_cgroup",
83720 + .file = "mm/page_cgroup.c",
83721 + .param1 = 1,
83722 +};
83723 +
83724 +struct size_overflow_hash _000358_hash = {
83725 + .next = NULL,
83726 + .name = "alloc_sched_domains",
83727 + .file = "include/linux/sched.h",
83728 + .param1 = 1,
83729 +};
83730 +
83731 +struct size_overflow_hash _000359_hash = {
83732 + .next = NULL,
83733 + .name = "compat_rw_copy_check_uvector",
83734 + .file = "include/linux/compat.h",
83735 + .param3 = 1,
83736 +};
83737 +
83738 +struct size_overflow_hash _000360_hash = {
83739 + .next = NULL,
83740 + .name = "compat_sys_kexec_load",
83741 + .file = "include/linux/kexec.h",
83742 + .param2 = 1,
83743 +};
83744 +
83745 +struct size_overflow_hash _000361_hash = {
83746 + .next = NULL,
83747 + .name = "compat_sys_semtimedop",
83748 + .file = "include/linux/compat.h",
83749 + .param3 = 1,
83750 +};
83751 +
83752 +struct size_overflow_hash _000362_hash = {
83753 + .next = NULL,
83754 + .name = "copy_from_user",
83755 + .file = "arch/x86/include/asm/uaccess_64.h",
83756 + .param3 = 1,
83757 +};
83758 +
83759 +struct size_overflow_hash _000363_hash = {
83760 + .next = NULL,
83761 + .name = "__copy_from_user",
83762 + .file = "arch/x86/include/asm/uaccess_64.h",
83763 + .param3 = 1,
83764 +};
83765 +
83766 +struct size_overflow_hash _000364_hash = {
83767 + .next = NULL,
83768 + .name = "__copy_from_user_inatomic",
83769 + .file = "arch/x86/include/asm/uaccess_64.h",
83770 + .param3 = 1,
83771 +};
83772 +
83773 +struct size_overflow_hash _000365_hash = {
83774 + .next = NULL,
83775 + .name = "__copy_from_user_nocache",
83776 + .file = "arch/x86/include/asm/uaccess_64.h",
83777 + .param3 = 1,
83778 +};
83779 +
83780 +struct size_overflow_hash _000366_hash = {
83781 + .next = NULL,
83782 + .name = "__copy_in_user",
83783 + .file = "arch/x86/include/asm/uaccess_64.h",
83784 + .param3 = 1,
83785 +};
83786 +
83787 +struct size_overflow_hash _000367_hash = {
83788 + .next = NULL,
83789 + .name = "copy_in_user",
83790 + .file = "arch/x86/include/asm/uaccess_64.h",
83791 + .param3 = 1,
83792 +};
83793 +
83794 +struct size_overflow_hash _000368_hash = {
83795 + .next = NULL,
83796 + .name = "__copy_to_user",
83797 + .file = "arch/x86/include/asm/uaccess_64.h",
83798 + .param3 = 1,
83799 +};
83800 +
83801 +struct size_overflow_hash _000369_hash = {
83802 + .next = NULL,
83803 + .name = "copy_to_user",
83804 + .file = "arch/x86/include/asm/uaccess_64.h",
83805 + .param3 = 1,
83806 +};
83807 +
83808 +struct size_overflow_hash _000370_hash = {
83809 + .next = NULL,
83810 + .name = "__copy_to_user_inatomic",
83811 + .file = "arch/x86/include/asm/uaccess_64.h",
83812 + .param3 = 1,
83813 +};
83814 +
83815 +struct size_overflow_hash _000371_hash = {
83816 + .next = NULL,
83817 + .name = "kmalloc_node",
83818 + .file = "include/linux/slub_def.h",
83819 + .param1 = 1,
83820 +};
83821 +
83822 +struct size_overflow_hash _000372_hash = {
83823 + .next = NULL,
83824 + .name = "pcpu_alloc_bootmem",
83825 + .file = "arch/x86/kernel/setup_percpu.c",
83826 + .param2 = 1,
83827 +};
83828 +
83829 +struct size_overflow_hash _000373_hash = {
83830 + .next = NULL,
83831 + .name = "sys32_rt_sigpending",
83832 + .file = "arch/x86/include/asm/sys_ia32.h",
83833 + .param2 = 1,
83834 +};
83835 +
83836 +struct size_overflow_hash _000374_hash = {
83837 + .next = NULL,
83838 + .name = "tunables_read",
83839 + .file = "arch/x86/platform/uv/tlb_uv.c",
83840 + .param3 = 1,
83841 +};
83842 +
83843 +struct size_overflow_hash _000375_hash = {
83844 + .next = NULL,
83845 + .name = "compat_do_readv_writev",
83846 + .file = "fs/compat.c",
83847 + .param4 = 1,
83848 +};
83849 +
83850 +struct size_overflow_hash _000376_hash = {
83851 + .next = NULL,
83852 + .name = "compat_keyctl_instantiate_key_iov",
83853 + .file = "security/keys/compat.c",
83854 + .param3 = 1,
83855 +};
83856 +
83857 +struct size_overflow_hash _000377_hash = {
83858 + .next = NULL,
83859 + .name = "compat_process_vm_rw",
83860 + .file = "mm/process_vm_access.c",
83861 + .param3 = 1,
83862 + .param5 = 1,
83863 +};
83864 +
83865 +struct size_overflow_hash _000379_hash = {
83866 + .next = NULL,
83867 + .name = "do_pages_stat",
83868 + .file = "mm/migrate.c",
83869 + .param2 = 1,
83870 +};
83871 +
83872 +struct size_overflow_hash _000380_hash = {
83873 + .next = NULL,
83874 + .name = "kzalloc_node",
83875 + .file = "include/linux/slab.h",
83876 + .param1 = 1,
83877 +};
83878 +
83879 +struct size_overflow_hash _000381_hash = {
83880 + .next = NULL,
83881 + .name = "pcpu_fc_alloc",
83882 + .file = "arch/x86/kernel/setup_percpu.c",
83883 + .param2 = 1,
83884 +};
83885 +
83886 +struct size_overflow_hash _000382_hash = {
83887 + .next = NULL,
83888 + .name = "ptc_proc_write",
83889 + .file = "arch/x86/platform/uv/tlb_uv.c",
83890 + .param3 = 1,
83891 +};
83892 +
83893 +struct size_overflow_hash _000383_hash = {
83894 + .next = NULL,
83895 + .name = "tunables_write",
83896 + .file = "arch/x86/platform/uv/tlb_uv.c",
83897 + .param3 = 1,
83898 +};
83899 +
83900 +struct size_overflow_hash _000384_hash = {
83901 + .next = NULL,
83902 + .name = "__alloc_bootmem_low_node",
83903 + .file = "include/linux/bootmem.h",
83904 + .param2 = 1,
83905 +};
83906 +
83907 +struct size_overflow_hash _000385_hash = {
83908 + .next = NULL,
83909 + .name = "__alloc_bootmem_node",
83910 + .file = "include/linux/bootmem.h",
83911 + .param2 = 1,
83912 +};
83913 +
83914 +struct size_overflow_hash _000386_hash = {
83915 + .next = NULL,
83916 + .name = "compat_readv",
83917 + .file = "fs/compat.c",
83918 + .param3 = 1,
83919 +};
83920 +
83921 +struct size_overflow_hash _000387_hash = {
83922 + .next = NULL,
83923 + .name = "compat_sys_keyctl",
83924 + .file = "include/linux/compat.h",
83925 + .param4 = 1,
83926 +};
83927 +
83928 +struct size_overflow_hash _000388_hash = {
83929 + .next = NULL,
83930 + .name = "compat_sys_process_vm_readv",
83931 + .file = "include/linux/compat.h",
83932 + .param3 = 1,
83933 + .param5 = 1,
83934 +};
83935 +
83936 +struct size_overflow_hash _000390_hash = {
83937 + .next = NULL,
83938 + .name = "compat_sys_process_vm_writev",
83939 + .file = "include/linux/compat.h",
83940 + .param3 = 1,
83941 + .param5 = 1,
83942 +};
83943 +
83944 +struct size_overflow_hash _000392_hash = {
83945 + .next = NULL,
83946 + .name = "compat_writev",
83947 + .file = "fs/compat.c",
83948 + .param3 = 1,
83949 +};
83950 +
83951 +struct size_overflow_hash _000393_hash = {
83952 + .next = NULL,
83953 + .name = "sys_move_pages",
83954 + .file = "include/linux/syscalls.h",
83955 + .param2 = 1,
83956 +};
83957 +
83958 +struct size_overflow_hash _000394_hash = {
83959 + .next = NULL,
83960 + .name = "__alloc_bootmem_node_high",
83961 + .file = "include/linux/bootmem.h",
83962 + .param2 = 1,
83963 +};
83964 +
83965 +struct size_overflow_hash _000395_hash = {
83966 + .next = NULL,
83967 + .name = "compat_sys_move_pages",
83968 + .file = "include/linux/compat.h",
83969 + .param2 = 1,
83970 +};
83971 +
83972 +struct size_overflow_hash _000396_hash = {
83973 + .next = NULL,
83974 + .name = "compat_sys_preadv",
83975 + .file = "include/linux/compat.h",
83976 + .param3 = 1,
83977 +};
83978 +
83979 +struct size_overflow_hash _000397_hash = {
83980 + .next = NULL,
83981 + .name = "compat_sys_pwritev",
83982 + .file = "include/linux/compat.h",
83983 + .param3 = 1,
83984 +};
83985 +
83986 +struct size_overflow_hash _000398_hash = {
83987 + .next = NULL,
83988 + .name = "compat_sys_readv",
83989 + .file = "include/linux/compat.h",
83990 + .param3 = 1,
83991 +};
83992 +
83993 +struct size_overflow_hash _000399_hash = {
83994 + .next = NULL,
83995 + .name = "compat_sys_writev",
83996 + .file = "include/linux/compat.h",
83997 + .param3 = 1,
83998 +};
83999 +
84000 +struct size_overflow_hash _000400_hash = {
84001 + .next = NULL,
84002 + .name = "sparse_early_usemaps_alloc_node",
84003 + .file = "mm/sparse.c",
84004 + .param4 = 1,
84005 +};
84006 +
84007 +struct size_overflow_hash _000401_hash = {
84008 + .next = NULL,
84009 + .name = "__earlyonly_bootmem_alloc",
84010 + .file = "mm/sparse-vmemmap.c",
84011 + .param2 = 1,
84012 +};
84013 +
84014 +struct size_overflow_hash _000402_hash = {
84015 + .next = NULL,
84016 + .name = "sparse_mem_maps_populate_node",
84017 + .file = "include/linux/mm.h",
84018 + .param4 = 1,
84019 +};
84020 +
84021 +struct size_overflow_hash _000403_hash = {
84022 + .next = NULL,
84023 + .name = "vmemmap_alloc_block",
84024 + .file = "include/linux/mm.h",
84025 + .param1 = 1,
84026 +};
84027 +
84028 +struct size_overflow_hash _000404_hash = {
84029 + .next = NULL,
84030 + .name = "sparse_early_mem_maps_alloc_node",
84031 + .file = "mm/sparse.c",
84032 + .param4 = 1,
84033 +};
84034 +
84035 +struct size_overflow_hash _000405_hash = {
84036 + .next = NULL,
84037 + .name = "vmemmap_alloc_block_buf",
84038 + .file = "include/linux/mm.h",
84039 + .param1 = 1,
84040 +};
84041 +
84042 +struct size_overflow_hash _000406_hash = {
84043 + .next = NULL,
84044 + .name = "acpi_battery_write_alarm",
84045 + .file = "drivers/acpi/battery.c",
84046 + .param3 = 1,
84047 +};
84048 +
84049 +struct size_overflow_hash _000407_hash = {
84050 + .next = NULL,
84051 + .name = "acpi_battery_write_alarm",
84052 + .file = "drivers/acpi/sbs.c",
84053 + .param3 = 1,
84054 +};
84055 +
84056 +struct size_overflow_hash _000408_hash = {
84057 + .next = NULL,
84058 + .name = "ad7879_spi_xfer",
84059 + .file = "drivers/input/touchscreen/ad7879-spi.c",
84060 + .param3 = 1,
84061 +};
84062 +
84063 +struct size_overflow_hash _000409_hash = {
84064 + .next = NULL,
84065 + .name = "add_port",
84066 + .file = "drivers/char/virtio_console.c",
84067 + .param2 = 1,
84068 +};
84069 +
84070 +struct size_overflow_hash _000410_hash = {
84071 + .next = NULL,
84072 + .name = "addtgt",
84073 + .file = "drivers/block/aoe/aoecmd.c",
84074 + .param3 = 1,
84075 +};
84076 +
84077 +struct size_overflow_hash _000411_hash = {
84078 + .next = NULL,
84079 + .name = "adu_read",
84080 + .file = "drivers/usb/misc/adutux.c",
84081 + .param3 = 1,
84082 +};
84083 +
84084 +struct size_overflow_hash _000412_hash = {
84085 + .next = NULL,
84086 + .name = "adu_write",
84087 + .file = "drivers/usb/misc/adutux.c",
84088 + .param3 = 1,
84089 +};
84090 +
84091 +struct size_overflow_hash _000413_hash = {
84092 + .next = NULL,
84093 + .name = "aer_inject_write",
84094 + .file = "drivers/pci/pcie/aer/aer_inject.c",
84095 + .param3 = 1,
84096 +};
84097 +
84098 +struct size_overflow_hash _000414_hash = {
84099 + .next = NULL,
84100 + .name = "aes_decrypt_fail_read",
84101 + .file = "drivers/net/wireless/wl1251/debugfs.c",
84102 + .param3 = 1,
84103 +};
84104 +
84105 +struct size_overflow_hash _000415_hash = {
84106 + .next = NULL,
84107 + .name = "aes_decrypt_interrupt_read",
84108 + .file = "drivers/net/wireless/wl1251/debugfs.c",
84109 + .param3 = 1,
84110 +};
84111 +
84112 +struct size_overflow_hash _000416_hash = {
84113 + .next = NULL,
84114 + .name = "aes_decrypt_packets_read",
84115 + .file = "drivers/net/wireless/wl1251/debugfs.c",
84116 + .param3 = 1,
84117 +};
84118 +
84119 +struct size_overflow_hash _000417_hash = {
84120 + .next = NULL,
84121 + .name = "aes_encrypt_fail_read",
84122 + .file = "drivers/net/wireless/wl1251/debugfs.c",
84123 + .param3 = 1,
84124 +};
84125 +
84126 +struct size_overflow_hash _000418_hash = {
84127 + .next = NULL,
84128 + .name = "aes_encrypt_interrupt_read",
84129 + .file = "drivers/net/wireless/wl1251/debugfs.c",
84130 + .param3 = 1,
84131 +};
84132 +
84133 +struct size_overflow_hash _000419_hash = {
84134 + .next = NULL,
84135 + .name = "aes_encrypt_packets_read",
84136 + .file = "drivers/net/wireless/wl1251/debugfs.c",
84137 + .param3 = 1,
84138 +};
84139 +
84140 +struct size_overflow_hash _000420_hash = {
84141 + .next = NULL,
84142 + .name = "afs_alloc_flat_call",
84143 + .file = "fs/afs/rxrpc.c",
84144 + .param2 = 1,
84145 + .param3 = 1,
84146 +};
84147 +
84148 +struct size_overflow_hash _000422_hash = {
84149 + .next = NULL,
84150 + .name = "afs_cell_alloc",
84151 + .file = "fs/afs/cell.c",
84152 + .param2 = 1,
84153 +};
84154 +
84155 +struct size_overflow_hash _000423_hash = {
84156 + .next = NULL,
84157 + .name = "afs_proc_cells_write",
84158 + .file = "fs/afs/proc.c",
84159 + .param3 = 1,
84160 +};
84161 +
84162 +struct size_overflow_hash _000424_hash = {
84163 + .next = NULL,
84164 + .name = "afs_proc_rootcell_write",
84165 + .file = "fs/afs/proc.c",
84166 + .param3 = 1,
84167 +};
84168 +
84169 +struct size_overflow_hash _000425_hash = {
84170 + .next = NULL,
84171 + .name = "aggr_recv_addba_req_evt",
84172 + .file = "drivers/net/wireless/ath/ath6kl/txrx.c",
84173 + .param4 = 1,
84174 +};
84175 +
84176 +struct size_overflow_hash _000426_hash = {
84177 + .next = NULL,
84178 + .name = "agp_3_5_isochronous_node_enable",
84179 + .file = "drivers/char/agp/isoch.c",
84180 + .param3 = 1,
84181 +};
84182 +
84183 +struct size_overflow_hash _000427_hash = {
84184 + .next = NULL,
84185 + .name = "agp_alloc_page_array",
84186 + .file = "drivers/char/agp/generic.c",
84187 + .param1 = 1,
84188 +};
84189 +
84190 +struct size_overflow_hash _000428_hash = {
84191 + .next = NULL,
84192 + .name = "alg_setkey",
84193 + .file = "crypto/af_alg.c",
84194 + .param3 = 1,
84195 +};
84196 +
84197 +struct size_overflow_hash _000429_hash = {
84198 + .next = NULL,
84199 + .name = "alloc_buf",
84200 + .file = "drivers/char/virtio_console.c",
84201 + .param1 = 1,
84202 +};
84203 +
84204 +struct size_overflow_hash _000430_hash = {
84205 + .next = NULL,
84206 + .name = "alloc_context",
84207 + .file = "drivers/md/dm-raid1.c",
84208 + .param1 = 1,
84209 +};
84210 +
84211 +struct size_overflow_hash _000431_hash = {
84212 + .next = NULL,
84213 + .name = "alloc_context",
84214 + .file = "drivers/md/dm-stripe.c",
84215 + .param1 = 1,
84216 +};
84217 +
84218 +struct size_overflow_hash _000432_hash = {
84219 + .next = NULL,
84220 + .name = "__alloc_dev_table",
84221 + .file = "fs/exofs/super.c",
84222 + .param2 = 1,
84223 +};
84224 +
84225 +struct size_overflow_hash _000433_hash = {
84226 + .next = NULL,
84227 + .name = "alloc_ep_req",
84228 + .file = "drivers/usb/gadget/f_midi.c",
84229 + .param2 = 1,
84230 +};
84231 +
84232 +struct size_overflow_hash _000434_hash = {
84233 + .next = NULL,
84234 + .name = "alloc_flex_gd",
84235 + .file = "fs/ext4/resize.c",
84236 + .param1 = 1,
84237 +};
84238 +
84239 +struct size_overflow_hash _000435_hash = {
84240 + .next = NULL,
84241 + .name = "__alloc_objio_seg",
84242 + .file = "fs/nfs/objlayout/objio_osd.c",
84243 + .param1 = 1,
84244 +};
84245 +
84246 +struct size_overflow_hash _000436_hash = {
84247 + .next = NULL,
84248 + .name = "alloc_one_pg_vec_page",
84249 + .file = "net/packet/af_packet.c",
84250 + .param1 = 1,
84251 +};
84252 +
84253 +struct size_overflow_hash _000437_hash = {
84254 + .next = NULL,
84255 + .name = "alloc_ring",
84256 + .file = "drivers/net/ethernet/chelsio/cxgb3/sge.c",
84257 + .param2 = 1,
84258 + .param4 = 1,
84259 +};
84260 +
84261 +struct size_overflow_hash _000438_hash = {
84262 + .next = NULL,
84263 + .name = "alloc_ring",
84264 + .file = "drivers/net/ethernet/chelsio/cxgb4vf/sge.c",
84265 + .param2 = 1,
84266 + .param4 = 1,
84267 +};
84268 +
84269 +struct size_overflow_hash _000441_hash = {
84270 + .next = NULL,
84271 + .name = "alloc_ts_config",
84272 + .file = "include/linux/textsearch.h",
84273 + .param1 = 1,
84274 +};
84275 +
84276 +struct size_overflow_hash _000442_hash = {
84277 + .next = NULL,
84278 + .name = "altera_drscan",
84279 + .file = "drivers/misc/altera-stapl/altera-jtag.c",
84280 + .param2 = 1,
84281 +};
84282 +
84283 +struct size_overflow_hash _000443_hash = {
84284 + .next = NULL,
84285 + .name = "altera_irscan",
84286 + .file = "drivers/misc/altera-stapl/altera-jtag.c",
84287 + .param2 = 1,
84288 +};
84289 +
84290 +struct size_overflow_hash _000444_hash = {
84291 + .next = &_000066_hash,
84292 + .name = "altera_set_dr_post",
84293 + .file = "drivers/misc/altera-stapl/altera-jtag.c",
84294 + .param2 = 1,
84295 +};
84296 +
84297 +struct size_overflow_hash _000445_hash = {
84298 + .next = NULL,
84299 + .name = "altera_set_dr_pre",
84300 + .file = "drivers/misc/altera-stapl/altera-jtag.c",
84301 + .param2 = 1,
84302 +};
84303 +
84304 +struct size_overflow_hash _000446_hash = {
84305 + .next = NULL,
84306 + .name = "altera_set_ir_post",
84307 + .file = "drivers/misc/altera-stapl/altera-jtag.c",
84308 + .param2 = 1,
84309 +};
84310 +
84311 +struct size_overflow_hash _000447_hash = {
84312 + .next = NULL,
84313 + .name = "altera_set_ir_pre",
84314 + .file = "drivers/misc/altera-stapl/altera-jtag.c",
84315 + .param2 = 1,
84316 +};
84317 +
84318 +struct size_overflow_hash _000448_hash = {
84319 + .next = NULL,
84320 + .name = "altera_swap_dr",
84321 + .file = "drivers/misc/altera-stapl/altera-jtag.c",
84322 + .param2 = 1,
84323 +};
84324 +
84325 +struct size_overflow_hash _000449_hash = {
84326 + .next = NULL,
84327 + .name = "altera_swap_ir",
84328 + .file = "drivers/misc/altera-stapl/altera-jtag.c",
84329 + .param2 = 1,
84330 +};
84331 +
84332 +struct size_overflow_hash _000450_hash = {
84333 + .next = NULL,
84334 + .name = "aoedev_flush",
84335 + .file = "drivers/block/aoe/aoedev.c",
84336 + .param2 = 1,
84337 +};
84338 +
84339 +struct size_overflow_hash _000451_hash = {
84340 + .next = NULL,
84341 + .name = "asd_store_update_bios",
84342 + .file = "drivers/scsi/aic94xx/aic94xx_init.c",
84343 + .param4 = 1,
84344 +};
84345 +
84346 +struct size_overflow_hash _000452_hash = {
84347 + .next = NULL,
84348 + .name = "asix_read_cmd",
84349 + .file = "drivers/net/usb/asix.c",
84350 + .param5 = 1,
84351 +};
84352 +
84353 +struct size_overflow_hash _000453_hash = {
84354 + .next = NULL,
84355 + .name = "asix_write_cmd",
84356 + .file = "drivers/net/usb/asix.c",
84357 + .param5 = 1,
84358 +};
84359 +
84360 +struct size_overflow_hash _000454_hash = {
84361 + .next = NULL,
84362 + .name = "asn1_octets_decode",
84363 + .file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
84364 + .param2 = 1,
84365 +};
84366 +
84367 +struct size_overflow_hash _000455_hash = {
84368 + .next = NULL,
84369 + .name = "asn1_oid_decode",
84370 + .file = "net/ipv4/netfilter/nf_nat_snmp_basic.c",
84371 + .param2 = 1,
84372 +};
84373 +
84374 +struct size_overflow_hash _000456_hash = {
84375 + .next = NULL,
84376 + .name = "asn1_oid_decode",
84377 + .file = "fs/cifs/asn1.c",
84378 + .param2 = 1,
84379 +};
84380 +
84381 +struct size_overflow_hash _000457_hash = {
84382 + .next = NULL,
84383 + .name = "ath6kl_add_bss_if_needed",
84384 + .file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84385 + .param6 = 1,
84386 +};
84387 +
84388 +struct size_overflow_hash _000458_hash = {
84389 + .next = NULL,
84390 + .name = "ath6kl_debug_roam_tbl_event",
84391 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84392 + .param3 = 1,
84393 +};
84394 +
84395 +struct size_overflow_hash _000459_hash = {
84396 + .next = NULL,
84397 + .name = "ath6kl_disconnect_timeout_read",
84398 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84399 + .param3 = 1,
84400 +};
84401 +
84402 +struct size_overflow_hash _000460_hash = {
84403 + .next = NULL,
84404 + .name = "ath6kl_endpoint_stats_read",
84405 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84406 + .param3 = 1,
84407 +};
84408 +
84409 +struct size_overflow_hash _000461_hash = {
84410 + .next = NULL,
84411 + .name = "ath6kl_fwlog_mask_read",
84412 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84413 + .param3 = 1,
84414 +};
84415 +
84416 +struct size_overflow_hash _000462_hash = {
84417 + .next = NULL,
84418 + .name = "ath6kl_fwlog_read",
84419 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84420 + .param3 = 1,
84421 +};
84422 +
84423 +struct size_overflow_hash _000463_hash = {
84424 + .next = NULL,
84425 + .name = "ath6kl_keepalive_read",
84426 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84427 + .param3 = 1,
84428 +};
84429 +
84430 +struct size_overflow_hash _000464_hash = {
84431 + .next = NULL,
84432 + .name = "ath6kl_lrssi_roam_read",
84433 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84434 + .param3 = 1,
84435 +};
84436 +
84437 +struct size_overflow_hash _000465_hash = {
84438 + .next = NULL,
84439 + .name = "ath6kl_regdump_read",
84440 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84441 + .param3 = 1,
84442 +};
84443 +
84444 +struct size_overflow_hash _000466_hash = {
84445 + .next = NULL,
84446 + .name = "ath6kl_regread_read",
84447 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84448 + .param3 = 1,
84449 +};
84450 +
84451 +struct size_overflow_hash _000467_hash = {
84452 + .next = NULL,
84453 + .name = "ath6kl_regwrite_read",
84454 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84455 + .param3 = 1,
84456 +};
84457 +
84458 +struct size_overflow_hash _000468_hash = {
84459 + .next = NULL,
84460 + .name = "ath6kl_roam_table_read",
84461 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
84462 + .param3 = 1,
84463 +};
84464 +
84465 +struct size_overflow_hash _000469_hash = {
84466 + .next = NULL,
84467 + .name = "ath6kl_send_go_probe_resp",
84468 + .file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84469 + .param3 = 1,
84470 +};
84471 +
84472 +struct size_overflow_hash _000470_hash = {
84473 + .next = NULL,
84474 + .name = "ath6kl_set_ap_probe_resp_ies",
84475 + .file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84476 + .param3 = 1,
84477 +};
84478 +
84479 +struct size_overflow_hash _000471_hash = {
84480 + .next = NULL,
84481 + .name = "ath6kl_set_assoc_req_ies",
84482 + .file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
84483 + .param3 = 1,
84484 +};
84485 +
84486 +struct size_overflow_hash _000472_hash = {
84487 + .next = NULL,
84488 + .name = "ath6kl_tm_rx_report_event",
84489 + .file = "drivers/net/wireless/ath/ath6kl/testmode.c",
84490 + .param3 = 1,
84491 +};
84492 +
84493 +struct size_overflow_hash _000473_hash = {
84494 + .next = NULL,
84495 + .name = "ath6kl_wmi_send_action_cmd",
84496 + .file = "drivers/net/wireless/ath/ath6kl/wmi.c",
84497 + .param7 = 1,
84498 +};
84499 +
84500 +struct size_overflow_hash _000474_hash = {
84501 + .next = NULL,
84502 + .name = "ath6kl_wmi_send_mgmt_cmd",
84503 + .file = "drivers/net/wireless/ath/ath6kl/wmi.c",
84504 + .param7 = 1,
84505 +};
84506 +
84507 +struct size_overflow_hash _000475_hash = {
84508 + .next = NULL,
84509 + .name = "ath9k_debugfs_read_buf",
84510 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
84511 + .param3 = 1,
84512 +};
84513 +
84514 +struct size_overflow_hash _000476_hash = {
84515 + .next = NULL,
84516 + .name = "atk_debugfs_ggrp_read",
84517 + .file = "drivers/hwmon/asus_atk0110.c",
84518 + .param3 = 1,
84519 +};
84520 +
84521 +struct size_overflow_hash _000477_hash = {
84522 + .next = NULL,
84523 + .name = "atm_get_addr",
84524 + .file = "net/atm/addr.c",
84525 + .param3 = 1,
84526 +};
84527 +
84528 +struct size_overflow_hash _000478_hash = {
84529 + .next = NULL,
84530 + .name = "attach_hdlc_protocol",
84531 + .file = "include/linux/hdlc.h",
84532 + .param3 = 1,
84533 +};
84534 +
84535 +struct size_overflow_hash _000479_hash = {
84536 + .next = NULL,
84537 + .name = "av7110_vbi_write",
84538 + .file = "drivers/media/dvb/ttpci/av7110_v4l.c",
84539 + .param3 = 1,
84540 +};
84541 +
84542 +struct size_overflow_hash _000480_hash = {
84543 + .next = NULL,
84544 + .name = "ax25_setsockopt",
84545 + .file = "net/ax25/af_ax25.c",
84546 + .param5 = 1,
84547 +};
84548 +
84549 +struct size_overflow_hash _000481_hash = {
84550 + .next = NULL,
84551 + .name = "b43_debugfs_read",
84552 + .file = "drivers/net/wireless/b43/debugfs.c",
84553 + .param3 = 1,
84554 +};
84555 +
84556 +struct size_overflow_hash _000482_hash = {
84557 + .next = NULL,
84558 + .name = "b43_debugfs_write",
84559 + .file = "drivers/net/wireless/b43/debugfs.c",
84560 + .param3 = 1,
84561 +};
84562 +
84563 +struct size_overflow_hash _000483_hash = {
84564 + .next = NULL,
84565 + .name = "b43legacy_debugfs_read",
84566 + .file = "drivers/net/wireless/b43legacy/debugfs.c",
84567 + .param3 = 1,
84568 +};
84569 +
84570 +struct size_overflow_hash _000484_hash = {
84571 + .next = NULL,
84572 + .name = "b43legacy_debugfs_write",
84573 + .file = "drivers/net/wireless/b43legacy/debugfs.c",
84574 + .param3 = 1,
84575 +};
84576 +
84577 +struct size_overflow_hash _000485_hash = {
84578 + .next = NULL,
84579 + .name = "b43_nphy_load_samples",
84580 + .file = "drivers/net/wireless/b43/phy_n.c",
84581 + .param3 = 1,
84582 +};
84583 +
84584 +struct size_overflow_hash _000486_hash = {
84585 + .next = NULL,
84586 + .name = "bch_alloc",
84587 + .file = "lib/bch.c",
84588 + .param1 = 1,
84589 +};
84590 +
84591 +struct size_overflow_hash _000487_hash = {
84592 + .next = NULL,
84593 + .name = "bfad_debugfs_read",
84594 + .file = "drivers/scsi/bfa/bfad_debugfs.c",
84595 + .param3 = 1,
84596 +};
84597 +
84598 +struct size_overflow_hash _000488_hash = {
84599 + .next = NULL,
84600 + .name = "bfad_debugfs_read_regrd",
84601 + .file = "drivers/scsi/bfa/bfad_debugfs.c",
84602 + .param3 = 1,
84603 +};
84604 +
84605 +struct size_overflow_hash _000489_hash = {
84606 + .next = NULL,
84607 + .name = "bfad_debugfs_write_regrd",
84608 + .file = "drivers/scsi/bfa/bfad_debugfs.c",
84609 + .param3 = 1,
84610 +};
84611 +
84612 +struct size_overflow_hash _000490_hash = {
84613 + .next = NULL,
84614 + .name = "bfad_debugfs_write_regwr",
84615 + .file = "drivers/scsi/bfa/bfad_debugfs.c",
84616 + .param3 = 1,
84617 +};
84618 +
84619 +struct size_overflow_hash _000491_hash = {
84620 + .next = NULL,
84621 + .name = "bits_to_user",
84622 + .file = "drivers/input/evdev.c",
84623 + .param3 = 1,
84624 +};
84625 +
84626 +struct size_overflow_hash _000492_hash = {
84627 + .next = NULL,
84628 + .name = "bl_pipe_downcall",
84629 + .file = "fs/nfs/blocklayout/blocklayoutdev.c",
84630 + .param3 = 1,
84631 +};
84632 +
84633 +struct size_overflow_hash _000493_hash = {
84634 + .next = NULL,
84635 + .name = "bm_entry_read",
84636 + .file = "fs/binfmt_misc.c",
84637 + .param3 = 1,
84638 +};
84639 +
84640 +struct size_overflow_hash _000494_hash = {
84641 + .next = NULL,
84642 + .name = "bm_realloc_pages",
84643 + .file = "drivers/block/drbd/drbd_bitmap.c",
84644 + .param2 = 1,
84645 +};
84646 +
84647 +struct size_overflow_hash _000495_hash = {
84648 + .next = NULL,
84649 + .name = "bm_status_read",
84650 + .file = "fs/binfmt_misc.c",
84651 + .param3 = 1,
84652 +};
84653 +
84654 +struct size_overflow_hash _000496_hash = {
84655 + .next = NULL,
84656 + .name = "bnad_debugfs_read",
84657 + .file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
84658 + .param3 = 1,
84659 +};
84660 +
84661 +struct size_overflow_hash _000497_hash = {
84662 + .next = NULL,
84663 + .name = "bnad_debugfs_read_regrd",
84664 + .file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
84665 + .param3 = 1,
84666 +};
84667 +
84668 +struct size_overflow_hash _000498_hash = {
84669 + .next = NULL,
84670 + .name = "bnad_debugfs_write_regrd",
84671 + .file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
84672 + .param3 = 1,
84673 +};
84674 +
84675 +struct size_overflow_hash _000499_hash = {
84676 + .next = NULL,
84677 + .name = "bnad_debugfs_write_regwr",
84678 + .file = "drivers/net/ethernet/brocade/bna/bnad_debugfs.c",
84679 + .param3 = 1,
84680 +};
84681 +
84682 +struct size_overflow_hash _000500_hash = {
84683 + .next = NULL,
84684 + .name = "bnx2fc_cmd_mgr_alloc",
84685 + .file = "drivers/scsi/bnx2fc/bnx2fc_io.c",
84686 + .param2 = 1,
84687 + .param3 = 1,
84688 +};
84689 +
84690 +struct size_overflow_hash _000502_hash = {
84691 + .next = NULL,
84692 + .name = "btmrvl_curpsmode_read",
84693 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84694 + .param3 = 1,
84695 +};
84696 +
84697 +struct size_overflow_hash _000503_hash = {
84698 + .next = NULL,
84699 + .name = "btmrvl_gpiogap_read",
84700 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84701 + .param3 = 1,
84702 +};
84703 +
84704 +struct size_overflow_hash _000504_hash = {
84705 + .next = NULL,
84706 + .name = "btmrvl_gpiogap_write",
84707 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84708 + .param3 = 1,
84709 +};
84710 +
84711 +struct size_overflow_hash _000505_hash = {
84712 + .next = NULL,
84713 + .name = "btmrvl_hscfgcmd_read",
84714 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84715 + .param3 = 1,
84716 +};
84717 +
84718 +struct size_overflow_hash _000506_hash = {
84719 + .next = NULL,
84720 + .name = "btmrvl_hscfgcmd_write",
84721 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84722 + .param3 = 1,
84723 +};
84724 +
84725 +struct size_overflow_hash _000507_hash = {
84726 + .next = &_000006_hash,
84727 + .name = "btmrvl_hscmd_read",
84728 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84729 + .param3 = 1,
84730 +};
84731 +
84732 +struct size_overflow_hash _000508_hash = {
84733 + .next = NULL,
84734 + .name = "btmrvl_hscmd_write",
84735 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84736 + .param3 = 1,
84737 +};
84738 +
84739 +struct size_overflow_hash _000509_hash = {
84740 + .next = NULL,
84741 + .name = "btmrvl_hsmode_read",
84742 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84743 + .param3 = 1,
84744 +};
84745 +
84746 +struct size_overflow_hash _000510_hash = {
84747 + .next = NULL,
84748 + .name = "btmrvl_hsmode_write",
84749 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84750 + .param3 = 1,
84751 +};
84752 +
84753 +struct size_overflow_hash _000511_hash = {
84754 + .next = NULL,
84755 + .name = "btmrvl_hsstate_read",
84756 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84757 + .param3 = 1,
84758 +};
84759 +
84760 +struct size_overflow_hash _000512_hash = {
84761 + .next = NULL,
84762 + .name = "btmrvl_pscmd_read",
84763 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84764 + .param3 = 1,
84765 +};
84766 +
84767 +struct size_overflow_hash _000513_hash = {
84768 + .next = NULL,
84769 + .name = "btmrvl_pscmd_write",
84770 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84771 + .param3 = 1,
84772 +};
84773 +
84774 +struct size_overflow_hash _000514_hash = {
84775 + .next = NULL,
84776 + .name = "btmrvl_psmode_read",
84777 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84778 + .param3 = 1,
84779 +};
84780 +
84781 +struct size_overflow_hash _000515_hash = {
84782 + .next = NULL,
84783 + .name = "btmrvl_psmode_write",
84784 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84785 + .param3 = 1,
84786 +};
84787 +
84788 +struct size_overflow_hash _000516_hash = {
84789 + .next = NULL,
84790 + .name = "btmrvl_psstate_read",
84791 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84792 + .param3 = 1,
84793 +};
84794 +
84795 +struct size_overflow_hash _000517_hash = {
84796 + .next = NULL,
84797 + .name = "btmrvl_txdnldready_read",
84798 + .file = "drivers/bluetooth/btmrvl_debugfs.c",
84799 + .param3 = 1,
84800 +};
84801 +
84802 +struct size_overflow_hash _000518_hash = {
84803 + .next = NULL,
84804 + .name = "btrfs_alloc_delayed_item",
84805 + .file = "fs/btrfs/delayed-inode.c",
84806 + .param1 = 1,
84807 +};
84808 +
84809 +struct size_overflow_hash _000519_hash = {
84810 + .next = NULL,
84811 + .name = "btrfs_copy_from_user",
84812 + .file = "fs/btrfs/file.c",
84813 + .param3 = 1,
84814 +};
84815 +
84816 +struct size_overflow_hash _000520_hash = {
84817 + .next = NULL,
84818 + .name = "__btrfs_map_block",
84819 + .file = "fs/btrfs/volumes.c",
84820 + .param3 = 1,
84821 +};
84822 +
84823 +struct size_overflow_hash _000521_hash = {
84824 + .next = NULL,
84825 + .name = "__c4iw_init_resource_fifo",
84826 + .file = "drivers/infiniband/hw/cxgb4/resource.c",
84827 + .param3 = 1,
84828 +};
84829 +
84830 +struct size_overflow_hash _000522_hash = {
84831 + .next = NULL,
84832 + .name = "cache_do_downcall",
84833 + .file = "net/sunrpc/cache.c",
84834 + .param3 = 1,
84835 +};
84836 +
84837 +struct size_overflow_hash _000523_hash = {
84838 + .next = NULL,
84839 + .name = "cachefiles_daemon_write",
84840 + .file = "fs/cachefiles/daemon.c",
84841 + .param3 = 1,
84842 +};
84843 +
84844 +struct size_overflow_hash _000524_hash = {
84845 + .next = NULL,
84846 + .name = "cache_read",
84847 + .file = "net/sunrpc/cache.c",
84848 + .param3 = 1,
84849 +};
84850 +
84851 +struct size_overflow_hash _000525_hash = {
84852 + .next = NULL,
84853 + .name = "ca_extend",
84854 + .file = "drivers/md/persistent-data/dm-space-map-checker.c",
84855 + .param2 = 1,
84856 +};
84857 +
84858 +struct size_overflow_hash _000526_hash = {
84859 + .next = NULL,
84860 + .name = "calc_hmac",
84861 + .file = "security/keys/encrypted-keys/encrypted.c",
84862 + .param3 = 1,
84863 +};
84864 +
84865 +struct size_overflow_hash _000527_hash = {
84866 + .next = NULL,
84867 + .name = "capi_write",
84868 + .file = "drivers/isdn/capi/capi.c",
84869 + .param3 = 1,
84870 +};
84871 +
84872 +struct size_overflow_hash _000528_hash = {
84873 + .next = NULL,
84874 + .name = "carl9170_cmd_buf",
84875 + .file = "drivers/net/wireless/ath/carl9170/cmd.c",
84876 + .param3 = 1,
84877 +};
84878 +
84879 +struct size_overflow_hash _000529_hash = {
84880 + .next = NULL,
84881 + .name = "carl9170_debugfs_read",
84882 + .file = "drivers/net/wireless/ath/carl9170/debug.c",
84883 + .param3 = 1,
84884 +};
84885 +
84886 +struct size_overflow_hash _000530_hash = {
84887 + .next = NULL,
84888 + .name = "carl9170_debugfs_write",
84889 + .file = "drivers/net/wireless/ath/carl9170/debug.c",
84890 + .param3 = 1,
84891 +};
84892 +
84893 +struct size_overflow_hash _000531_hash = {
84894 + .next = NULL,
84895 + .name = "cciss_proc_write",
84896 + .file = "drivers/block/cciss.c",
84897 + .param3 = 1,
84898 +};
84899 +
84900 +struct size_overflow_hash _000532_hash = {
84901 + .next = NULL,
84902 + .name = "ceph_buffer_new",
84903 + .file = "include/linux/ceph/buffer.h",
84904 + .param1 = 1,
84905 +};
84906 +
84907 +struct size_overflow_hash _000533_hash = {
84908 + .next = NULL,
84909 + .name = "ceph_copy_page_vector_to_user",
84910 + .file = "include/linux/ceph/libceph.h",
84911 + .param4 = 1,
84912 +};
84913 +
84914 +struct size_overflow_hash _000534_hash = {
84915 + .next = NULL,
84916 + .name = "ceph_copy_user_to_page_vector",
84917 + .file = "include/linux/ceph/libceph.h",
84918 + .param4 = 1,
84919 +};
84920 +
84921 +struct size_overflow_hash _000535_hash = {
84922 + .next = NULL,
84923 + .name = "ceph_read_dir",
84924 + .file = "fs/ceph/dir.c",
84925 + .param3 = 1,
84926 +};
84927 +
84928 +struct size_overflow_hash _000536_hash = {
84929 + .next = NULL,
84930 + .name = "ceph_setxattr",
84931 + .file = "fs/ceph/xattr.c",
84932 + .param4 = 1,
84933 +};
84934 +
84935 +struct size_overflow_hash _000537_hash = {
84936 + .next = NULL,
84937 + .name = "cfg80211_connect_result",
84938 + .file = "include/net/cfg80211.h",
84939 + .param4 = 1,
84940 + .param6 = 1,
84941 +};
84942 +
84943 +struct size_overflow_hash _000539_hash = {
84944 + .next = NULL,
84945 + .name = "cfg80211_disconnected",
84946 + .file = "include/net/cfg80211.h",
84947 + .param4 = 1,
84948 +};
84949 +
84950 +struct size_overflow_hash _000540_hash = {
84951 + .next = NULL,
84952 + .name = "cfg80211_inform_bss",
84953 + .file = "include/net/cfg80211.h",
84954 + .param8 = 1,
84955 +};
84956 +
84957 +struct size_overflow_hash _000541_hash = {
84958 + .next = NULL,
84959 + .name = "cfg80211_inform_bss_frame",
84960 + .file = "include/net/cfg80211.h",
84961 + .param4 = 1,
84962 +};
84963 +
84964 +struct size_overflow_hash _000542_hash = {
84965 + .next = NULL,
84966 + .name = "cfg80211_roamed_bss",
84967 + .file = "include/net/cfg80211.h",
84968 + .param4 = 1,
84969 + .param6 = 1,
84970 +};
84971 +
84972 +struct size_overflow_hash _000544_hash = {
84973 + .next = NULL,
84974 + .name = "cfi_read_pri",
84975 + .file = "include/linux/mtd/cfi.h",
84976 + .param3 = 1,
84977 +};
84978 +
84979 +struct size_overflow_hash _000545_hash = {
84980 + .next = NULL,
84981 + .name = "channel_type_read",
84982 + .file = "net/mac80211/debugfs.c",
84983 + .param3 = 1,
84984 +};
84985 +
84986 +struct size_overflow_hash _000546_hash = {
84987 + .next = NULL,
84988 + .name = "cifs_idmap_key_instantiate",
84989 + .file = "fs/cifs/cifsacl.c",
84990 + .param3 = 1,
84991 +};
84992 +
84993 +struct size_overflow_hash _000547_hash = {
84994 + .next = NULL,
84995 + .name = "cifs_readdata_alloc",
84996 + .file = "fs/cifs/cifssmb.c",
84997 + .param1 = 1,
84998 +};
84999 +
85000 +struct size_overflow_hash _000548_hash = {
85001 + .next = NULL,
85002 + .name = "cifs_security_flags_proc_write",
85003 + .file = "fs/cifs/cifs_debug.c",
85004 + .param3 = 1,
85005 +};
85006 +
85007 +struct size_overflow_hash _000549_hash = {
85008 + .next = NULL,
85009 + .name = "cifs_setxattr",
85010 + .file = "fs/cifs/xattr.c",
85011 + .param4 = 1,
85012 +};
85013 +
85014 +struct size_overflow_hash _000550_hash = {
85015 + .next = NULL,
85016 + .name = "cifs_spnego_key_instantiate",
85017 + .file = "fs/cifs/cifs_spnego.c",
85018 + .param3 = 1,
85019 +};
85020 +
85021 +struct size_overflow_hash _000551_hash = {
85022 + .next = NULL,
85023 + .name = "cifs_writedata_alloc",
85024 + .file = "fs/cifs/cifssmb.c",
85025 + .param1 = 1,
85026 +};
85027 +
85028 +struct size_overflow_hash _000552_hash = {
85029 + .next = NULL,
85030 + .name = "ci_ll_write",
85031 + .file = "drivers/media/dvb/ttpci/av7110_ca.c",
85032 + .param4 = 1,
85033 +};
85034 +
85035 +struct size_overflow_hash _000553_hash = {
85036 + .next = NULL,
85037 + .name = "clusterip_proc_write",
85038 + .file = "net/ipv4/netfilter/ipt_CLUSTERIP.c",
85039 + .param3 = 1,
85040 +};
85041 +
85042 +struct size_overflow_hash _000554_hash = {
85043 + .next = &_000108_hash,
85044 + .name = "cm4040_write",
85045 + .file = "drivers/char/pcmcia/cm4040_cs.c",
85046 + .param3 = 1,
85047 +};
85048 +
85049 +struct size_overflow_hash _000555_hash = {
85050 + .next = NULL,
85051 + .name = "cm_copy_private_data",
85052 + .file = "drivers/infiniband/core/cm.c",
85053 + .param2 = 1,
85054 +};
85055 +
85056 +struct size_overflow_hash _000556_hash = {
85057 + .next = NULL,
85058 + .name = "cmm_write",
85059 + .file = "drivers/char/pcmcia/cm4000_cs.c",
85060 + .param3 = 1,
85061 +};
85062 +
85063 +struct size_overflow_hash _000557_hash = {
85064 + .next = NULL,
85065 + .name = "cm_write",
85066 + .file = "drivers/acpi/custom_method.c",
85067 + .param3 = 1,
85068 +};
85069 +
85070 +struct size_overflow_hash _000558_hash = {
85071 + .next = NULL,
85072 + .name = "coda_psdev_read",
85073 + .file = "fs/coda/psdev.c",
85074 + .param3 = 1,
85075 +};
85076 +
85077 +struct size_overflow_hash _000559_hash = {
85078 + .next = NULL,
85079 + .name = "coda_psdev_write",
85080 + .file = "fs/coda/psdev.c",
85081 + .param3 = 1,
85082 +};
85083 +
85084 +struct size_overflow_hash _000560_hash = {
85085 + .next = NULL,
85086 + .name = "codec_list_read_file",
85087 + .file = "sound/soc/soc-core.c",
85088 + .param3 = 1,
85089 +};
85090 +
85091 +struct size_overflow_hash _000561_hash = {
85092 + .next = NULL,
85093 + .name = "codec_reg_read_file",
85094 + .file = "sound/soc/soc-core.c",
85095 + .param3 = 1,
85096 +};
85097 +
85098 +struct size_overflow_hash _000562_hash = {
85099 + .next = NULL,
85100 + .name = "command_file_write",
85101 + .file = "drivers/misc/ibmasm/ibmasmfs.c",
85102 + .param3 = 1,
85103 +};
85104 +
85105 +struct size_overflow_hash _000563_hash = {
85106 + .next = NULL,
85107 + .name = "command_write",
85108 + .file = "drivers/uwb/uwb-debug.c",
85109 + .param3 = 1,
85110 +};
85111 +
85112 +struct size_overflow_hash _000564_hash = {
85113 + .next = NULL,
85114 + .name = "concat_writev",
85115 + .file = "drivers/mtd/mtdconcat.c",
85116 + .param3 = 1,
85117 +};
85118 +
85119 +struct size_overflow_hash _000565_hash = {
85120 + .next = NULL,
85121 + .name = "configfs_read_file",
85122 + .file = "fs/configfs/file.c",
85123 + .param3 = 1,
85124 +};
85125 +
85126 +struct size_overflow_hash _000566_hash = {
85127 + .next = NULL,
85128 + .name = "context_alloc",
85129 + .file = "drivers/md/dm-raid.c",
85130 + .param3 = 1,
85131 +};
85132 +
85133 +struct size_overflow_hash _000567_hash = {
85134 + .next = NULL,
85135 + .name = "copy_counters_to_user",
85136 + .file = "net/bridge/netfilter/ebtables.c",
85137 + .param5 = 1,
85138 +};
85139 +
85140 +struct size_overflow_hash _000568_hash = {
85141 + .next = NULL,
85142 + .name = "copy_entries_to_user",
85143 + .file = "net/ipv6/netfilter/ip6_tables.c",
85144 + .param1 = 1,
85145 +};
85146 +
85147 +struct size_overflow_hash _000569_hash = {
85148 + .next = NULL,
85149 + .name = "copy_entries_to_user",
85150 + .file = "net/ipv4/netfilter/arp_tables.c",
85151 + .param1 = 1,
85152 +};
85153 +
85154 +struct size_overflow_hash _000570_hash = {
85155 + .next = NULL,
85156 + .name = "copy_entries_to_user",
85157 + .file = "net/ipv4/netfilter/ip_tables.c",
85158 + .param1 = 1,
85159 +};
85160 +
85161 +struct size_overflow_hash _000571_hash = {
85162 + .next = NULL,
85163 + .name = "copy_from_user_toio",
85164 + .file = "include/sound/core.h",
85165 + .param3 = 1,
85166 +};
85167 +
85168 +struct size_overflow_hash _000572_hash = {
85169 + .next = NULL,
85170 + .name = "copy_macs",
85171 + .file = "net/atm/mpc.c",
85172 + .param4 = 1,
85173 +};
85174 +
85175 +struct size_overflow_hash _000573_hash = {
85176 + .next = NULL,
85177 + .name = "copy_to_user_fromio",
85178 + .file = "include/sound/core.h",
85179 + .param3 = 1,
85180 +};
85181 +
85182 +struct size_overflow_hash _000574_hash = {
85183 + .next = NULL,
85184 + .name = "cosa_write",
85185 + .file = "drivers/net/wan/cosa.c",
85186 + .param3 = 1,
85187 +};
85188 +
85189 +struct size_overflow_hash _000575_hash = {
85190 + .next = NULL,
85191 + .name = "create_attr_set",
85192 + .file = "drivers/platform/x86/thinkpad_acpi.c",
85193 + .param1 = 1,
85194 +};
85195 +
85196 +struct size_overflow_hash _000576_hash = {
85197 + .next = NULL,
85198 + .name = "create_entry",
85199 + .file = "fs/binfmt_misc.c",
85200 + .param2 = 1,
85201 +};
85202 +
85203 +struct size_overflow_hash _000577_hash = {
85204 + .next = NULL,
85205 + .name = "create_gpadl_header",
85206 + .file = "drivers/hv/channel.c",
85207 + .param2 = 1,
85208 +};
85209 +
85210 +struct size_overflow_hash _000578_hash = {
85211 + .next = NULL,
85212 + .name = "create_queues",
85213 + .file = "drivers/atm/ambassador.c",
85214 + .param2 = 1,
85215 + .param3 = 1,
85216 +};
85217 +
85218 +struct size_overflow_hash _000580_hash = {
85219 + .next = NULL,
85220 + .name = "_create_sg_bios",
85221 + .file = "drivers/scsi/osd/osd_initiator.c",
85222 + .param4 = 1,
85223 +};
85224 +
85225 +struct size_overflow_hash _000581_hash = {
85226 + .next = NULL,
85227 + .name = "cryptd_alloc_instance",
85228 + .file = "crypto/cryptd.c",
85229 + .param2 = 1,
85230 + .param3 = 1,
85231 +};
85232 +
85233 +struct size_overflow_hash _000583_hash = {
85234 + .next = NULL,
85235 + .name = "cryptd_hash_setkey",
85236 + .file = "crypto/cryptd.c",
85237 + .param3 = 1,
85238 +};
85239 +
85240 +struct size_overflow_hash _000584_hash = {
85241 + .next = NULL,
85242 + .name = "crypto_authenc_esn_setkey",
85243 + .file = "crypto/authencesn.c",
85244 + .param3 = 1,
85245 +};
85246 +
85247 +struct size_overflow_hash _000585_hash = {
85248 + .next = NULL,
85249 + .name = "crypto_authenc_setkey",
85250 + .file = "crypto/authenc.c",
85251 + .param3 = 1,
85252 +};
85253 +
85254 +struct size_overflow_hash _000586_hash = {
85255 + .next = NULL,
85256 + .name = "ctrl_out",
85257 + .file = "drivers/usb/misc/usbtest.c",
85258 + .param3 = 1,
85259 + .param5 = 1,
85260 +};
85261 +
85262 +struct size_overflow_hash _000588_hash = {
85263 + .next = NULL,
85264 + .name = "cx18_copy_buf_to_user",
85265 + .file = "drivers/media/video/cx18/cx18-fileops.c",
85266 + .param4 = 1,
85267 +};
85268 +
85269 +struct size_overflow_hash _000589_hash = {
85270 + .next = NULL,
85271 + .name = "cx24116_writeregN",
85272 + .file = "drivers/media/dvb/frontends/cx24116.c",
85273 + .param4 = 1,
85274 +};
85275 +
85276 +struct size_overflow_hash _000590_hash = {
85277 + .next = NULL,
85278 + .name = "cxgb_alloc_mem",
85279 + .file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
85280 + .param1 = 1,
85281 +};
85282 +
85283 +struct size_overflow_hash _000591_hash = {
85284 + .next = NULL,
85285 + .name = "cxgbi_alloc_big_mem",
85286 + .file = "drivers/scsi/cxgbi/libcxgbi.h",
85287 + .param1 = 1,
85288 +};
85289 +
85290 +struct size_overflow_hash _000592_hash = {
85291 + .next = NULL,
85292 + .name = "cxgbi_device_register",
85293 + .file = "drivers/scsi/cxgbi/libcxgbi.c",
85294 + .param1 = 1,
85295 + .param2 = 1,
85296 +};
85297 +
85298 +struct size_overflow_hash _000594_hash = {
85299 + .next = NULL,
85300 + .name = "__cxio_init_resource_fifo",
85301 + .file = "drivers/infiniband/hw/cxgb3/cxio_resource.c",
85302 + .param3 = 1,
85303 +};
85304 +
85305 +struct size_overflow_hash _000595_hash = {
85306 + .next = NULL,
85307 + .name = "dac960_user_command_proc_write",
85308 + .file = "drivers/block/DAC960.c",
85309 + .param3 = 1,
85310 +};
85311 +
85312 +struct size_overflow_hash _000596_hash = {
85313 + .next = NULL,
85314 + .name = "dai_list_read_file",
85315 + .file = "sound/soc/soc-core.c",
85316 + .param3 = 1,
85317 +};
85318 +
85319 +struct size_overflow_hash _000597_hash = {
85320 + .next = NULL,
85321 + .name = "dapm_bias_read_file",
85322 + .file = "sound/soc/soc-dapm.c",
85323 + .param3 = 1,
85324 +};
85325 +
85326 +struct size_overflow_hash _000598_hash = {
85327 + .next = NULL,
85328 + .name = "dapm_widget_power_read_file",
85329 + .file = "sound/soc/soc-dapm.c",
85330 + .param3 = 1,
85331 +};
85332 +
85333 +struct size_overflow_hash _000599_hash = {
85334 + .next = NULL,
85335 + .name = "datablob_format",
85336 + .file = "security/keys/encrypted-keys/encrypted.c",
85337 + .param2 = 1,
85338 +};
85339 +
85340 +struct size_overflow_hash _000600_hash = {
85341 + .next = NULL,
85342 + .name = "dbgfs_frame",
85343 + .file = "drivers/net/caif/caif_spi.c",
85344 + .param3 = 1,
85345 +};
85346 +
85347 +struct size_overflow_hash _000601_hash = {
85348 + .next = NULL,
85349 + .name = "dbgfs_state",
85350 + .file = "drivers/net/caif/caif_spi.c",
85351 + .param3 = 1,
85352 +};
85353 +
85354 +struct size_overflow_hash _000602_hash = {
85355 + .next = NULL,
85356 + .name = "dccp_feat_clone_sp_val",
85357 + .file = "net/dccp/feat.c",
85358 + .param3 = 1,
85359 +};
85360 +
85361 +struct size_overflow_hash _000603_hash = {
85362 + .next = NULL,
85363 + .name = "dccp_setsockopt_ccid",
85364 + .file = "net/dccp/proto.c",
85365 + .param4 = 1,
85366 +};
85367 +
85368 +struct size_overflow_hash _000604_hash = {
85369 + .next = NULL,
85370 + .name = "dccp_setsockopt_service",
85371 + .file = "net/dccp/proto.c",
85372 + .param4 = 1,
85373 +};
85374 +
85375 +struct size_overflow_hash _000605_hash = {
85376 + .next = NULL,
85377 + .name = "ddb_input_read",
85378 + .file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
85379 + .param3 = 1,
85380 +};
85381 +
85382 +struct size_overflow_hash _000606_hash = {
85383 + .next = NULL,
85384 + .name = "ddb_output_write",
85385 + .file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
85386 + .param3 = 1,
85387 +};
85388 +
85389 +struct size_overflow_hash _000607_hash = {
85390 + .next = NULL,
85391 + .name = "ddp_make_gl",
85392 + .file = "drivers/scsi/cxgbi/libcxgbi.c",
85393 + .param1 = 1,
85394 +};
85395 +
85396 +struct size_overflow_hash _000608_hash = {
85397 + .next = NULL,
85398 + .name = "debugfs_read",
85399 + .file = "drivers/infiniband/hw/cxgb4/device.c",
85400 + .param3 = 1,
85401 +};
85402 +
85403 +struct size_overflow_hash _000609_hash = {
85404 + .next = NULL,
85405 + .name = "debugfs_read",
85406 + .file = "drivers/char/virtio_console.c",
85407 + .param3 = 1,
85408 +};
85409 +
85410 +struct size_overflow_hash _000610_hash = {
85411 + .next = NULL,
85412 + .name = "debug_output",
85413 + .file = "drivers/usb/host/ohci-dbg.c",
85414 + .param3 = 1,
85415 +};
85416 +
85417 +struct size_overflow_hash _000611_hash = {
85418 + .next = NULL,
85419 + .name = "debug_output",
85420 + .file = "drivers/usb/host/ehci-dbg.c",
85421 + .param3 = 1,
85422 +};
85423 +
85424 +struct size_overflow_hash _000612_hash = {
85425 + .next = NULL,
85426 + .name = "debug_read",
85427 + .file = "fs/ocfs2/dlm/dlmdebug.c",
85428 + .param3 = 1,
85429 +};
85430 +
85431 +struct size_overflow_hash _000613_hash = {
85432 + .next = NULL,
85433 + .name = "dev_config",
85434 + .file = "drivers/usb/gadget/inode.c",
85435 + .param3 = 1,
85436 +};
85437 +
85438 +struct size_overflow_hash _000614_hash = {
85439 + .next = NULL,
85440 + .name = "device_write",
85441 + .file = "fs/dlm/user.c",
85442 + .param3 = 1,
85443 +};
85444 +
85445 +struct size_overflow_hash _000615_hash = {
85446 + .next = NULL,
85447 + .name = "dev_read",
85448 + .file = "drivers/media/video/gspca/gspca.c",
85449 + .param3 = 1,
85450 +};
85451 +
85452 +struct size_overflow_hash _000616_hash = {
85453 + .next = NULL,
85454 + .name = "dfs_file_read",
85455 + .file = "drivers/mtd/ubi/debug.c",
85456 + .param3 = 1,
85457 +};
85458 +
85459 +struct size_overflow_hash _000617_hash = {
85460 + .next = NULL,
85461 + .name = "dfs_file_write",
85462 + .file = "drivers/mtd/ubi/debug.c",
85463 + .param3 = 1,
85464 +};
85465 +
85466 +struct size_overflow_hash _000618_hash = {
85467 + .next = NULL,
85468 + .name = "direct_entry",
85469 + .file = "drivers/misc/lkdtm.c",
85470 + .param3 = 1,
85471 +};
85472 +
85473 +struct size_overflow_hash _000619_hash = {
85474 + .next = NULL,
85475 + .name = "dispatch_proc_write",
85476 + .file = "drivers/platform/x86/thinkpad_acpi.c",
85477 + .param3 = 1,
85478 +};
85479 +
85480 +struct size_overflow_hash _000620_hash = {
85481 + .next = NULL,
85482 + .name = "diva_os_malloc",
85483 + .file = "drivers/isdn/hardware/eicon/platform.h",
85484 + .param2 = 1,
85485 +};
85486 +
85487 +struct size_overflow_hash _000621_hash = {
85488 + .next = NULL,
85489 + .name = "dlmfs_file_read",
85490 + .file = "fs/ocfs2/dlmfs/dlmfs.c",
85491 + .param3 = 1,
85492 +};
85493 +
85494 +struct size_overflow_hash _000622_hash = {
85495 + .next = NULL,
85496 + .name = "dlmfs_file_write",
85497 + .file = "fs/ocfs2/dlmfs/dlmfs.c",
85498 + .param3 = 1,
85499 +};
85500 +
85501 +struct size_overflow_hash _000623_hash = {
85502 + .next = NULL,
85503 + .name = "dma_attach",
85504 + .file = "drivers/net/wireless/brcm80211/brcmsmac/dma.c",
85505 + .param6 = 1,
85506 + .param7 = 1,
85507 +};
85508 +
85509 +struct size_overflow_hash _000625_hash = {
85510 + .next = NULL,
85511 + .name = "dma_rx_errors_read",
85512 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85513 + .param3 = 1,
85514 +};
85515 +
85516 +struct size_overflow_hash _000626_hash = {
85517 + .next = NULL,
85518 + .name = "dma_rx_requested_read",
85519 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85520 + .param3 = 1,
85521 +};
85522 +
85523 +struct size_overflow_hash _000627_hash = {
85524 + .next = NULL,
85525 + .name = "dma_show_regs",
85526 + .file = "drivers/tty/serial/mfd.c",
85527 + .param3 = 1,
85528 +};
85529 +
85530 +struct size_overflow_hash _000628_hash = {
85531 + .next = NULL,
85532 + .name = "dma_tx_errors_read",
85533 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85534 + .param3 = 1,
85535 +};
85536 +
85537 +struct size_overflow_hash _000629_hash = {
85538 + .next = NULL,
85539 + .name = "dma_tx_requested_read",
85540 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85541 + .param3 = 1,
85542 +};
85543 +
85544 +struct size_overflow_hash _000630_hash = {
85545 + .next = NULL,
85546 + .name = "dm_read",
85547 + .file = "drivers/net/usb/dm9601.c",
85548 + .param3 = 1,
85549 +};
85550 +
85551 +struct size_overflow_hash _000631_hash = {
85552 + .next = NULL,
85553 + .name = "dm_vcalloc",
85554 + .file = "include/linux/device-mapper.h",
85555 + .param1 = 1,
85556 + .param2 = 1,
85557 +};
85558 +
85559 +struct size_overflow_hash _000633_hash = {
85560 + .next = NULL,
85561 + .name = "dm_write",
85562 + .file = "drivers/net/usb/dm9601.c",
85563 + .param3 = 1,
85564 +};
85565 +
85566 +struct size_overflow_hash _000634_hash = {
85567 + .next = NULL,
85568 + .name = "__dn_setsockopt",
85569 + .file = "net/decnet/af_decnet.c",
85570 + .param5 = 1,
85571 +};
85572 +
85573 +struct size_overflow_hash _000635_hash = {
85574 + .next = NULL,
85575 + .name = "dns_query",
85576 + .file = "include/linux/dns_resolver.h",
85577 + .param3 = 1,
85578 +};
85579 +
85580 +struct size_overflow_hash _000636_hash = {
85581 + .next = NULL,
85582 + .name = "dns_resolver_instantiate",
85583 + .file = "net/dns_resolver/dns_key.c",
85584 + .param3 = 1,
85585 +};
85586 +
85587 +struct size_overflow_hash _000637_hash = {
85588 + .next = NULL,
85589 + .name = "dns_resolver_read",
85590 + .file = "net/dns_resolver/dns_key.c",
85591 + .param3 = 1,
85592 +};
85593 +
85594 +struct size_overflow_hash _000638_hash = {
85595 + .next = NULL,
85596 + .name = "do_add_counters",
85597 + .file = "net/ipv6/netfilter/ip6_tables.c",
85598 + .param3 = 1,
85599 +};
85600 +
85601 +struct size_overflow_hash _000639_hash = {
85602 + .next = NULL,
85603 + .name = "do_add_counters",
85604 + .file = "net/ipv4/netfilter/ip_tables.c",
85605 + .param3 = 1,
85606 +};
85607 +
85608 +struct size_overflow_hash _000640_hash = {
85609 + .next = NULL,
85610 + .name = "do_add_counters",
85611 + .file = "net/ipv4/netfilter/arp_tables.c",
85612 + .param3 = 1,
85613 +};
85614 +
85615 +struct size_overflow_hash _000641_hash = {
85616 + .next = NULL,
85617 + .name = "__do_config_autodelink",
85618 + .file = "drivers/usb/storage/realtek_cr.c",
85619 + .param3 = 1,
85620 +};
85621 +
85622 +struct size_overflow_hash _000642_hash = {
85623 + .next = NULL,
85624 + .name = "do_ipv6_setsockopt",
85625 + .file = "net/ipv6/ipv6_sockglue.c",
85626 + .param5 = 1,
85627 +};
85628 +
85629 +struct size_overflow_hash _000643_hash = {
85630 + .next = NULL,
85631 + .name = "do_ip_vs_set_ctl",
85632 + .file = "net/netfilter/ipvs/ip_vs_ctl.c",
85633 + .param4 = 1,
85634 +};
85635 +
85636 +struct size_overflow_hash _000644_hash = {
85637 + .next = NULL,
85638 + .name = "do_register_entry",
85639 + .file = "drivers/misc/lkdtm.c",
85640 + .param4 = 1,
85641 +};
85642 +
85643 +struct size_overflow_hash _000645_hash = {
85644 + .next = NULL,
85645 + .name = "__do_replace",
85646 + .file = "net/ipv6/netfilter/ip6_tables.c",
85647 + .param5 = 1,
85648 +};
85649 +
85650 +struct size_overflow_hash _000646_hash = {
85651 + .next = NULL,
85652 + .name = "__do_replace",
85653 + .file = "net/ipv4/netfilter/ip_tables.c",
85654 + .param5 = 1,
85655 +};
85656 +
85657 +struct size_overflow_hash _000647_hash = {
85658 + .next = NULL,
85659 + .name = "__do_replace",
85660 + .file = "net/ipv4/netfilter/arp_tables.c",
85661 + .param5 = 1,
85662 +};
85663 +
85664 +struct size_overflow_hash _000648_hash = {
85665 + .next = NULL,
85666 + .name = "do_sync",
85667 + .file = "fs/gfs2/quota.c",
85668 + .param1 = 1,
85669 +};
85670 +
85671 +struct size_overflow_hash _000649_hash = {
85672 + .next = NULL,
85673 + .name = "do_update_counters",
85674 + .file = "net/bridge/netfilter/ebtables.c",
85675 + .param4 = 1,
85676 +};
85677 +
85678 +struct size_overflow_hash _000650_hash = {
85679 + .next = NULL,
85680 + .name = "driver_state_read",
85681 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
85682 + .param3 = 1,
85683 +};
85684 +
85685 +struct size_overflow_hash _000651_hash = {
85686 + .next = NULL,
85687 + .name = "dsp_write",
85688 + .file = "sound/oss/msnd_pinnacle.c",
85689 + .param2 = 1,
85690 +};
85691 +
85692 +struct size_overflow_hash _000652_hash = {
85693 + .next = NULL,
85694 + .name = "dvb_aplay",
85695 + .file = "drivers/media/dvb/ttpci/av7110_av.c",
85696 + .param3 = 1,
85697 +};
85698 +
85699 +struct size_overflow_hash _000653_hash = {
85700 + .next = NULL,
85701 + .name = "dvb_ca_en50221_io_write",
85702 + .file = "drivers/media/dvb/dvb-core/dvb_ca_en50221.c",
85703 + .param3 = 1,
85704 +};
85705 +
85706 +struct size_overflow_hash _000654_hash = {
85707 + .next = NULL,
85708 + .name = "dvb_dmxdev_set_buffer_size",
85709 + .file = "drivers/media/dvb/dvb-core/dmxdev.c",
85710 + .param2 = 1,
85711 +};
85712 +
85713 +struct size_overflow_hash _000655_hash = {
85714 + .next = NULL,
85715 + .name = "dvbdmx_write",
85716 + .file = "drivers/media/dvb/dvb-core/dvb_demux.c",
85717 + .param3 = 1,
85718 +};
85719 +
85720 +struct size_overflow_hash _000656_hash = {
85721 + .next = NULL,
85722 + .name = "dvb_dvr_set_buffer_size",
85723 + .file = "drivers/media/dvb/dvb-core/dmxdev.c",
85724 + .param2 = 1,
85725 +};
85726 +
85727 +struct size_overflow_hash _000657_hash = {
85728 + .next = NULL,
85729 + .name = "dvb_play",
85730 + .file = "drivers/media/dvb/ttpci/av7110_av.c",
85731 + .param3 = 1,
85732 +};
85733 +
85734 +struct size_overflow_hash _000658_hash = {
85735 + .next = NULL,
85736 + .name = "dvb_ringbuffer_pkt_read_user",
85737 + .file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
85738 + .param5 = 1,
85739 +};
85740 +
85741 +struct size_overflow_hash _000659_hash = {
85742 + .next = NULL,
85743 + .name = "dvb_ringbuffer_read_user",
85744 + .file = "drivers/media/dvb/dvb-core/dvb_ringbuffer.c",
85745 + .param3 = 1,
85746 +};
85747 +
85748 +struct size_overflow_hash _000660_hash = {
85749 + .next = NULL,
85750 + .name = "dw210x_op_rw",
85751 + .file = "drivers/media/dvb/dvb-usb/dw2102.c",
85752 + .param6 = 1,
85753 +};
85754 +
85755 +struct size_overflow_hash _000661_hash = {
85756 + .next = NULL,
85757 + .name = "dwc3_mode_write",
85758 + .file = "drivers/usb/dwc3/debugfs.c",
85759 + .param3 = 1,
85760 +};
85761 +
85762 +struct size_overflow_hash _000662_hash = {
85763 + .next = NULL,
85764 + .name = "econet_sendmsg",
85765 + .file = "net/econet/af_econet.c",
85766 + .param4 = 1,
85767 +};
85768 +
85769 +struct size_overflow_hash _000663_hash = {
85770 + .next = NULL,
85771 + .name = "ecryptfs_copy_filename",
85772 + .file = "fs/ecryptfs/crypto.c",
85773 + .param4 = 1,
85774 +};
85775 +
85776 +struct size_overflow_hash _000664_hash = {
85777 + .next = NULL,
85778 + .name = "ecryptfs_miscdev_write",
85779 + .file = "fs/ecryptfs/miscdev.c",
85780 + .param3 = 1,
85781 +};
85782 +
85783 +struct size_overflow_hash _000665_hash = {
85784 + .next = NULL,
85785 + .name = "ecryptfs_send_miscdev",
85786 + .file = "fs/ecryptfs/miscdev.c",
85787 + .param2 = 1,
85788 +};
85789 +
85790 +struct size_overflow_hash _000666_hash = {
85791 + .next = NULL,
85792 + .name = "edac_device_alloc_ctl_info",
85793 + .file = "drivers/edac/edac_device.c",
85794 + .param1 = 1,
85795 +};
85796 +
85797 +struct size_overflow_hash _000667_hash = {
85798 + .next = NULL,
85799 + .name = "edac_mc_alloc",
85800 + .file = "drivers/edac/edac_mc.c",
85801 + .param1 = 1,
85802 +};
85803 +
85804 +struct size_overflow_hash _000668_hash = {
85805 + .next = NULL,
85806 + .name = "edac_pci_alloc_ctl_info",
85807 + .file = "drivers/edac/edac_pci.c",
85808 + .param1 = 1,
85809 +};
85810 +
85811 +struct size_overflow_hash _000669_hash = {
85812 + .next = NULL,
85813 + .name = "efivar_create_sysfs_entry",
85814 + .file = "drivers/firmware/efivars.c",
85815 + .param2 = 1,
85816 +};
85817 +
85818 +struct size_overflow_hash _000670_hash = {
85819 + .next = NULL,
85820 + .name = "efx_tsoh_heap_alloc",
85821 + .file = "drivers/net/ethernet/sfc/tx.c",
85822 + .param2 = 1,
85823 +};
85824 +
85825 +struct size_overflow_hash _000671_hash = {
85826 + .next = NULL,
85827 + .name = "encrypted_instantiate",
85828 + .file = "security/keys/encrypted-keys/encrypted.c",
85829 + .param3 = 1,
85830 +};
85831 +
85832 +struct size_overflow_hash _000672_hash = {
85833 + .next = NULL,
85834 + .name = "encrypted_update",
85835 + .file = "security/keys/encrypted-keys/encrypted.c",
85836 + .param3 = 1,
85837 +};
85838 +
85839 +struct size_overflow_hash _000673_hash = {
85840 + .next = NULL,
85841 + .name = "ep0_write",
85842 + .file = "drivers/usb/gadget/inode.c",
85843 + .param3 = 1,
85844 +};
85845 +
85846 +struct size_overflow_hash _000674_hash = {
85847 + .next = NULL,
85848 + .name = "ep_read",
85849 + .file = "drivers/usb/gadget/inode.c",
85850 + .param3 = 1,
85851 +};
85852 +
85853 +struct size_overflow_hash _000675_hash = {
85854 + .next = NULL,
85855 + .name = "ep_write",
85856 + .file = "drivers/usb/gadget/inode.c",
85857 + .param3 = 1,
85858 +};
85859 +
85860 +struct size_overflow_hash _000676_hash = {
85861 + .next = NULL,
85862 + .name = "erst_dbg_write",
85863 + .file = "drivers/acpi/apei/erst-dbg.c",
85864 + .param3 = 1,
85865 +};
85866 +
85867 +struct size_overflow_hash _000677_hash = {
85868 + .next = NULL,
85869 + .name = "et61x251_read",
85870 + .file = "drivers/media/video/et61x251/et61x251_core.c",
85871 + .param3 = 1,
85872 +};
85873 +
85874 +struct size_overflow_hash _000678_hash = {
85875 + .next = NULL,
85876 + .name = "event_calibration_read",
85877 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85878 + .param3 = 1,
85879 +};
85880 +
85881 +struct size_overflow_hash _000679_hash = {
85882 + .next = NULL,
85883 + .name = "event_heart_beat_read",
85884 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85885 + .param3 = 1,
85886 +};
85887 +
85888 +struct size_overflow_hash _000680_hash = {
85889 + .next = NULL,
85890 + .name = "event_oom_late_read",
85891 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85892 + .param3 = 1,
85893 +};
85894 +
85895 +struct size_overflow_hash _000681_hash = {
85896 + .next = NULL,
85897 + .name = "event_phy_transmit_error_read",
85898 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85899 + .param3 = 1,
85900 +};
85901 +
85902 +struct size_overflow_hash _000682_hash = {
85903 + .next = NULL,
85904 + .name = "event_rx_mem_empty_read",
85905 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85906 + .param3 = 1,
85907 +};
85908 +
85909 +struct size_overflow_hash _000683_hash = {
85910 + .next = NULL,
85911 + .name = "event_rx_mismatch_read",
85912 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85913 + .param3 = 1,
85914 +};
85915 +
85916 +struct size_overflow_hash _000684_hash = {
85917 + .next = NULL,
85918 + .name = "event_rx_pool_read",
85919 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85920 + .param3 = 1,
85921 +};
85922 +
85923 +struct size_overflow_hash _000685_hash = {
85924 + .next = NULL,
85925 + .name = "event_tx_stuck_read",
85926 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85927 + .param3 = 1,
85928 +};
85929 +
85930 +struct size_overflow_hash _000686_hash = {
85931 + .next = NULL,
85932 + .name = "excessive_retries_read",
85933 + .file = "drivers/net/wireless/wl1251/debugfs.c",
85934 + .param3 = 1,
85935 +};
85936 +
85937 +struct size_overflow_hash _000687_hash = {
85938 + .next = NULL,
85939 + .name = "exofs_read_lookup_dev_table",
85940 + .file = "fs/exofs/super.c",
85941 + .param3 = 1,
85942 +};
85943 +
85944 +struct size_overflow_hash _000688_hash = {
85945 + .next = NULL,
85946 + .name = "ext4_kvmalloc",
85947 + .file = "fs/ext4/super.c",
85948 + .param1 = 1,
85949 +};
85950 +
85951 +struct size_overflow_hash _000689_hash = {
85952 + .next = NULL,
85953 + .name = "ext4_kvzalloc",
85954 + .file = "fs/ext4/super.c",
85955 + .param1 = 1,
85956 +};
85957 +
85958 +struct size_overflow_hash _000690_hash = {
85959 + .next = NULL,
85960 + .name = "extend_netdev_table",
85961 + .file = "net/core/netprio_cgroup.c",
85962 + .param2 = 1,
85963 +};
85964 +
85965 +struct size_overflow_hash _000691_hash = {
85966 + .next = NULL,
85967 + .name = "fd_copyin",
85968 + .file = "drivers/block/floppy.c",
85969 + .param3 = 1,
85970 +};
85971 +
85972 +struct size_overflow_hash _000692_hash = {
85973 + .next = NULL,
85974 + .name = "fd_copyout",
85975 + .file = "drivers/block/floppy.c",
85976 + .param3 = 1,
85977 +};
85978 +
85979 +struct size_overflow_hash _000693_hash = {
85980 + .next = NULL,
85981 + .name = "__ffs_ep0_read_events",
85982 + .file = "drivers/usb/gadget/f_fs.c",
85983 + .param3 = 1,
85984 +};
85985 +
85986 +struct size_overflow_hash _000694_hash = {
85987 + .next = NULL,
85988 + .name = "ffs_epfile_io",
85989 + .file = "drivers/usb/gadget/f_fs.c",
85990 + .param3 = 1,
85991 +};
85992 +
85993 +struct size_overflow_hash _000695_hash = {
85994 + .next = NULL,
85995 + .name = "ffs_prepare_buffer",
85996 + .file = "drivers/usb/gadget/f_fs.c",
85997 + .param2 = 1,
85998 +};
85999 +
86000 +struct size_overflow_hash _000696_hash = {
86001 + .next = NULL,
86002 + .name = "f_hidg_read",
86003 + .file = "drivers/usb/gadget/f_hid.c",
86004 + .param3 = 1,
86005 +};
86006 +
86007 +struct size_overflow_hash _000697_hash = {
86008 + .next = NULL,
86009 + .name = "f_hidg_write",
86010 + .file = "drivers/usb/gadget/f_hid.c",
86011 + .param3 = 1,
86012 +};
86013 +
86014 +struct size_overflow_hash _000698_hash = {
86015 + .next = NULL,
86016 + .name = "fill_write_buffer",
86017 + .file = "fs/configfs/file.c",
86018 + .param3 = 1,
86019 +};
86020 +
86021 +struct size_overflow_hash _000699_hash = {
86022 + .next = NULL,
86023 + .name = "flexcop_device_kmalloc",
86024 + .file = "drivers/media/dvb/b2c2/flexcop.c",
86025 + .param1 = 1,
86026 +};
86027 +
86028 +struct size_overflow_hash _000700_hash = {
86029 + .next = NULL,
86030 + .name = "fops_read",
86031 + .file = "drivers/media/video/saa7164/saa7164-encoder.c",
86032 + .param3 = 1,
86033 +};
86034 +
86035 +struct size_overflow_hash _000701_hash = {
86036 + .next = NULL,
86037 + .name = "fops_read",
86038 + .file = "drivers/media/video/saa7164/saa7164-vbi.c",
86039 + .param3 = 1,
86040 +};
86041 +
86042 +struct size_overflow_hash _000702_hash = {
86043 + .next = NULL,
86044 + .name = "format_devstat_counter",
86045 + .file = "net/mac80211/debugfs.c",
86046 + .param3 = 1,
86047 +};
86048 +
86049 +struct size_overflow_hash _000703_hash = {
86050 + .next = NULL,
86051 + .name = "fragmentation_threshold_read",
86052 + .file = "net/wireless/debugfs.c",
86053 + .param3 = 1,
86054 +};
86055 +
86056 +struct size_overflow_hash _000704_hash = {
86057 + .next = NULL,
86058 + .name = "frame_alloc",
86059 + .file = "drivers/media/video/gspca/gspca.c",
86060 + .param4 = 1,
86061 +};
86062 +
86063 +struct size_overflow_hash _000705_hash = {
86064 + .next = NULL,
86065 + .name = "ftdi_elan_write",
86066 + .file = "drivers/usb/misc/ftdi-elan.c",
86067 + .param3 = 1,
86068 +};
86069 +
86070 +struct size_overflow_hash _000706_hash = {
86071 + .next = NULL,
86072 + .name = "fuse_conn_limit_read",
86073 + .file = "fs/fuse/control.c",
86074 + .param3 = 1,
86075 +};
86076 +
86077 +struct size_overflow_hash _000707_hash = {
86078 + .next = NULL,
86079 + .name = "fuse_conn_limit_write",
86080 + .file = "fs/fuse/control.c",
86081 + .param3 = 1,
86082 +};
86083 +
86084 +struct size_overflow_hash _000708_hash = {
86085 + .next = &_000531_hash,
86086 + .name = "fuse_conn_waiting_read",
86087 + .file = "fs/fuse/control.c",
86088 + .param3 = 1,
86089 +};
86090 +
86091 +struct size_overflow_hash _000709_hash = {
86092 + .next = NULL,
86093 + .name = "garp_attr_create",
86094 + .file = "net/802/garp.c",
86095 + .param3 = 1,
86096 +};
86097 +
86098 +struct size_overflow_hash _000710_hash = {
86099 + .next = NULL,
86100 + .name = "get_alua_req",
86101 + .file = "drivers/scsi/device_handler/scsi_dh_alua.c",
86102 + .param3 = 1,
86103 +};
86104 +
86105 +struct size_overflow_hash _000711_hash = {
86106 + .next = NULL,
86107 + .name = "get_derived_key",
86108 + .file = "security/keys/encrypted-keys/encrypted.c",
86109 + .param4 = 1,
86110 +};
86111 +
86112 +struct size_overflow_hash _000712_hash = {
86113 + .next = NULL,
86114 + .name = "getdqbuf",
86115 + .file = "fs/quota/quota_tree.c",
86116 + .param1 = 1,
86117 +};
86118 +
86119 +struct size_overflow_hash _000713_hash = {
86120 + .next = NULL,
86121 + .name = "get_fdb_entries",
86122 + .file = "net/bridge/br_ioctl.c",
86123 + .param3 = 1,
86124 +};
86125 +
86126 +struct size_overflow_hash _000714_hash = {
86127 + .next = NULL,
86128 + .name = "get_rdac_req",
86129 + .file = "drivers/scsi/device_handler/scsi_dh_rdac.c",
86130 + .param3 = 1,
86131 +};
86132 +
86133 +struct size_overflow_hash _000715_hash = {
86134 + .next = NULL,
86135 + .name = "get_registers",
86136 + .file = "drivers/net/usb/pegasus.c",
86137 + .param3 = 1,
86138 +};
86139 +
86140 +struct size_overflow_hash _000716_hash = {
86141 + .next = NULL,
86142 + .name = "get_server_iovec",
86143 + .file = "fs/cifs/connect.c",
86144 + .param2 = 1,
86145 +};
86146 +
86147 +struct size_overflow_hash _000717_hash = {
86148 + .next = NULL,
86149 + .name = "get_ucode_user",
86150 + .file = "arch/x86/kernel/microcode_intel.c",
86151 + .param3 = 1,
86152 +};
86153 +
86154 +struct size_overflow_hash _000718_hash = {
86155 + .next = NULL,
86156 + .name = "gfs2_alloc_sort_buffer",
86157 + .file = "fs/gfs2/dir.c",
86158 + .param1 = 1,
86159 +};
86160 +
86161 +struct size_overflow_hash _000719_hash = {
86162 + .next = NULL,
86163 + .name = "gfs2_glock_nq_m",
86164 + .file = "fs/gfs2/glock.c",
86165 + .param1 = 1,
86166 +};
86167 +
86168 +struct size_overflow_hash _000720_hash = {
86169 + .next = NULL,
86170 + .name = "gigaset_initdriver",
86171 + .file = "drivers/isdn/gigaset/common.c",
86172 + .param2 = 1,
86173 +};
86174 +
86175 +struct size_overflow_hash _000721_hash = {
86176 + .next = NULL,
86177 + .name = "gpio_power_read",
86178 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
86179 + .param3 = 1,
86180 +};
86181 +
86182 +struct size_overflow_hash _000722_hash = {
86183 + .next = NULL,
86184 + .name = "gs_alloc_req",
86185 + .file = "drivers/usb/gadget/u_serial.c",
86186 + .param2 = 1,
86187 +};
86188 +
86189 +struct size_overflow_hash _000723_hash = {
86190 + .next = NULL,
86191 + .name = "gs_buf_alloc",
86192 + .file = "drivers/usb/gadget/u_serial.c",
86193 + .param2 = 1,
86194 +};
86195 +
86196 +struct size_overflow_hash _000724_hash = {
86197 + .next = NULL,
86198 + .name = "gss_pipe_downcall",
86199 + .file = "net/sunrpc/auth_gss/auth_gss.c",
86200 + .param3 = 1,
86201 +};
86202 +
86203 +struct size_overflow_hash _000725_hash = {
86204 + .next = NULL,
86205 + .name = "handle_request",
86206 + .file = "drivers/firewire/core-cdev.c",
86207 + .param9 = 1,
86208 +};
86209 +
86210 +struct size_overflow_hash _000726_hash = {
86211 + .next = NULL,
86212 + .name = "hash_new",
86213 + .file = "net/batman-adv/hash.c",
86214 + .param1 = 1,
86215 +};
86216 +
86217 +struct size_overflow_hash _000727_hash = {
86218 + .next = NULL,
86219 + .name = "hash_setkey",
86220 + .file = "crypto/algif_hash.c",
86221 + .param3 = 1,
86222 +};
86223 +
86224 +struct size_overflow_hash _000728_hash = {
86225 + .next = NULL,
86226 + .name = "hcd_buffer_alloc",
86227 + .file = "include/linux/usb/hcd.h",
86228 + .param2 = 1,
86229 +};
86230 +
86231 +struct size_overflow_hash _000729_hash = {
86232 + .next = NULL,
86233 + .name = "hci_sock_setsockopt",
86234 + .file = "net/bluetooth/hci_sock.c",
86235 + .param5 = 1,
86236 +};
86237 +
86238 +struct size_overflow_hash _000730_hash = {
86239 + .next = NULL,
86240 + .name = "hdpvr_read",
86241 + .file = "drivers/media/video/hdpvr/hdpvr-video.c",
86242 + .param3 = 1,
86243 +};
86244 +
86245 +struct size_overflow_hash _000731_hash = {
86246 + .next = NULL,
86247 + .name = "hidraw_get_report",
86248 + .file = "drivers/hid/hidraw.c",
86249 + .param3 = 1,
86250 +};
86251 +
86252 +struct size_overflow_hash _000732_hash = {
86253 + .next = NULL,
86254 + .name = "hidraw_read",
86255 + .file = "drivers/hid/hidraw.c",
86256 + .param3 = 1,
86257 +};
86258 +
86259 +struct size_overflow_hash _000733_hash = {
86260 + .next = NULL,
86261 + .name = "hidraw_send_report",
86262 + .file = "drivers/hid/hidraw.c",
86263 + .param3 = 1,
86264 +};
86265 +
86266 +struct size_overflow_hash _000734_hash = {
86267 + .next = NULL,
86268 + .name = "hid_register_field",
86269 + .file = "drivers/hid/hid-core.c",
86270 + .param2 = 1,
86271 + .param3 = 1,
86272 +};
86273 +
86274 +struct size_overflow_hash _000736_hash = {
86275 + .next = NULL,
86276 + .name = "hpfs_translate_name",
86277 + .file = "fs/hpfs/name.c",
86278 + .param3 = 1,
86279 +};
86280 +
86281 +struct size_overflow_hash _000737_hash = {
86282 + .next = NULL,
86283 + .name = "hpi_alloc_control_cache",
86284 + .file = "sound/pci/asihpi/hpicmn.c",
86285 + .param1 = 1,
86286 +};
86287 +
86288 +struct size_overflow_hash _000738_hash = {
86289 + .next = NULL,
86290 + .name = "ht40allow_map_read",
86291 + .file = "net/wireless/debugfs.c",
86292 + .param3 = 1,
86293 +};
86294 +
86295 +struct size_overflow_hash _000739_hash = {
86296 + .next = NULL,
86297 + .name = "__hwahc_dev_set_key",
86298 + .file = "drivers/usb/host/hwa-hc.c",
86299 + .param5 = 1,
86300 +};
86301 +
86302 +struct size_overflow_hash _000740_hash = {
86303 + .next = NULL,
86304 + .name = "hwflags_read",
86305 + .file = "net/mac80211/debugfs.c",
86306 + .param3 = 1,
86307 +};
86308 +
86309 +struct size_overflow_hash _000741_hash = {
86310 + .next = NULL,
86311 + .name = "hysdn_conf_read",
86312 + .file = "drivers/isdn/hysdn/hysdn_procconf.c",
86313 + .param3 = 1,
86314 +};
86315 +
86316 +struct size_overflow_hash _000742_hash = {
86317 + .next = NULL,
86318 + .name = "hysdn_conf_write",
86319 + .file = "drivers/isdn/hysdn/hysdn_procconf.c",
86320 + .param3 = 1,
86321 +};
86322 +
86323 +struct size_overflow_hash _000743_hash = {
86324 + .next = NULL,
86325 + .name = "hysdn_log_write",
86326 + .file = "drivers/isdn/hysdn/hysdn_proclog.c",
86327 + .param3 = 1,
86328 +};
86329 +
86330 +struct size_overflow_hash _000744_hash = {
86331 + .next = NULL,
86332 + .name = "i2400m_rx_stats_read",
86333 + .file = "drivers/net/wimax/i2400m/debugfs.c",
86334 + .param3 = 1,
86335 +};
86336 +
86337 +struct size_overflow_hash _000745_hash = {
86338 + .next = NULL,
86339 + .name = "i2400m_tx_stats_read",
86340 + .file = "drivers/net/wimax/i2400m/debugfs.c",
86341 + .param3 = 1,
86342 +};
86343 +
86344 +struct size_overflow_hash _000746_hash = {
86345 + .next = NULL,
86346 + .name = "__i2400mu_send_barker",
86347 + .file = "drivers/net/wimax/i2400m/usb.c",
86348 + .param3 = 1,
86349 +};
86350 +
86351 +struct size_overflow_hash _000747_hash = {
86352 + .next = NULL,
86353 + .name = "i2400m_zrealloc_2x",
86354 + .file = "drivers/net/wimax/i2400m/fw.c",
86355 + .param3 = 1,
86356 +};
86357 +
86358 +struct size_overflow_hash _000748_hash = {
86359 + .next = NULL,
86360 + .name = "i2cdev_read",
86361 + .file = "drivers/i2c/i2c-dev.c",
86362 + .param3 = 1,
86363 +};
86364 +
86365 +struct size_overflow_hash _000749_hash = {
86366 + .next = &_000459_hash,
86367 + .name = "i2cdev_write",
86368 + .file = "drivers/i2c/i2c-dev.c",
86369 + .param3 = 1,
86370 +};
86371 +
86372 +struct size_overflow_hash _000750_hash = {
86373 + .next = NULL,
86374 + .name = "ib_alloc_device",
86375 + .file = "include/rdma/ib_verbs.h",
86376 + .param1 = 1,
86377 +};
86378 +
86379 +struct size_overflow_hash _000751_hash = {
86380 + .next = NULL,
86381 + .name = "ib_copy_from_udata",
86382 + .file = "include/rdma/ib_verbs.h",
86383 + .param3 = 1,
86384 +};
86385 +
86386 +struct size_overflow_hash _000752_hash = {
86387 + .next = NULL,
86388 + .name = "ib_copy_to_udata",
86389 + .file = "include/rdma/ib_verbs.h",
86390 + .param3 = 1,
86391 +};
86392 +
86393 +struct size_overflow_hash _000753_hash = {
86394 + .next = NULL,
86395 + .name = "ibmasm_new_command",
86396 + .file = "drivers/misc/ibmasm/command.c",
86397 + .param2 = 1,
86398 +};
86399 +
86400 +struct size_overflow_hash _000754_hash = {
86401 + .next = NULL,
86402 + .name = "ib_ucm_alloc_data",
86403 + .file = "drivers/infiniband/core/ucm.c",
86404 + .param3 = 1,
86405 +};
86406 +
86407 +struct size_overflow_hash _000755_hash = {
86408 + .next = NULL,
86409 + .name = "ib_umad_write",
86410 + .file = "drivers/infiniband/core/user_mad.c",
86411 + .param3 = 1,
86412 +};
86413 +
86414 +struct size_overflow_hash _000756_hash = {
86415 + .next = NULL,
86416 + .name = "ib_uverbs_unmarshall_recv",
86417 + .file = "drivers/infiniband/core/uverbs_cmd.c",
86418 + .param5 = 1,
86419 +};
86420 +
86421 +struct size_overflow_hash _000757_hash = {
86422 + .next = NULL,
86423 + .name = "ide_driver_proc_write",
86424 + .file = "drivers/ide/ide-proc.c",
86425 + .param3 = 1,
86426 +};
86427 +
86428 +struct size_overflow_hash _000758_hash = {
86429 + .next = NULL,
86430 + .name = "ide_queue_pc_tail",
86431 + .file = "include/linux/ide.h",
86432 + .param5 = 1,
86433 +};
86434 +
86435 +struct size_overflow_hash _000759_hash = {
86436 + .next = NULL,
86437 + .name = "ide_raw_taskfile",
86438 + .file = "include/linux/ide.h",
86439 + .param4 = 1,
86440 +};
86441 +
86442 +struct size_overflow_hash _000760_hash = {
86443 + .next = NULL,
86444 + .name = "ide_settings_proc_write",
86445 + .file = "drivers/ide/ide-proc.c",
86446 + .param3 = 1,
86447 +};
86448 +
86449 +struct size_overflow_hash _000761_hash = {
86450 + .next = NULL,
86451 + .name = "idetape_chrdev_read",
86452 + .file = "drivers/ide/ide-tape.c",
86453 + .param3 = 1,
86454 +};
86455 +
86456 +struct size_overflow_hash _000762_hash = {
86457 + .next = NULL,
86458 + .name = "idetape_chrdev_write",
86459 + .file = "drivers/ide/ide-tape.c",
86460 + .param3 = 1,
86461 +};
86462 +
86463 +struct size_overflow_hash _000763_hash = {
86464 + .next = NULL,
86465 + .name = "idmouse_read",
86466 + .file = "drivers/usb/misc/idmouse.c",
86467 + .param3 = 1,
86468 +};
86469 +
86470 +struct size_overflow_hash _000764_hash = {
86471 + .next = NULL,
86472 + .name = "ieee80211_build_probe_req",
86473 + .file = "net/mac80211/util.c",
86474 + .param7 = 1,
86475 +};
86476 +
86477 +struct size_overflow_hash _000765_hash = {
86478 + .next = NULL,
86479 + .name = "ieee80211_if_read",
86480 + .file = "net/mac80211/debugfs_netdev.c",
86481 + .param3 = 1,
86482 +};
86483 +
86484 +struct size_overflow_hash _000766_hash = {
86485 + .next = NULL,
86486 + .name = "ieee80211_if_write",
86487 + .file = "net/mac80211/debugfs_netdev.c",
86488 + .param3 = 1,
86489 +};
86490 +
86491 +struct size_overflow_hash _000767_hash = {
86492 + .next = NULL,
86493 + .name = "ieee80211_key_alloc",
86494 + .file = "net/mac80211/key.c",
86495 + .param3 = 1,
86496 +};
86497 +
86498 +struct size_overflow_hash _000768_hash = {
86499 + .next = NULL,
86500 + .name = "ieee80211_mgmt_tx",
86501 + .file = "net/mac80211/cfg.c",
86502 + .param9 = 1,
86503 +};
86504 +
86505 +struct size_overflow_hash _000769_hash = {
86506 + .next = NULL,
86507 + .name = "ikconfig_read_current",
86508 + .file = "kernel/configs.c",
86509 + .param3 = 1,
86510 +};
86511 +
86512 +struct size_overflow_hash _000770_hash = {
86513 + .next = NULL,
86514 + .name = "il3945_sta_dbgfs_stats_table_read",
86515 + .file = "drivers/net/wireless/iwlegacy/3945-rs.c",
86516 + .param3 = 1,
86517 +};
86518 +
86519 +struct size_overflow_hash _000771_hash = {
86520 + .next = NULL,
86521 + .name = "il3945_ucode_general_stats_read",
86522 + .file = "drivers/net/wireless/iwlegacy/3945-debug.c",
86523 + .param3 = 1,
86524 +};
86525 +
86526 +struct size_overflow_hash _000772_hash = {
86527 + .next = NULL,
86528 + .name = "il3945_ucode_rx_stats_read",
86529 + .file = "drivers/net/wireless/iwlegacy/3945-debug.c",
86530 + .param3 = 1,
86531 +};
86532 +
86533 +struct size_overflow_hash _000773_hash = {
86534 + .next = NULL,
86535 + .name = "il3945_ucode_tx_stats_read",
86536 + .file = "drivers/net/wireless/iwlegacy/3945-debug.c",
86537 + .param3 = 1,
86538 +};
86539 +
86540 +struct size_overflow_hash _000774_hash = {
86541 + .next = NULL,
86542 + .name = "il4965_rs_sta_dbgfs_rate_scale_data_read",
86543 + .file = "drivers/net/wireless/iwlegacy/4965-rs.c",
86544 + .param3 = 1,
86545 +};
86546 +
86547 +struct size_overflow_hash _000775_hash = {
86548 + .next = NULL,
86549 + .name = "il4965_rs_sta_dbgfs_scale_table_read",
86550 + .file = "drivers/net/wireless/iwlegacy/4965-rs.c",
86551 + .param3 = 1,
86552 +};
86553 +
86554 +struct size_overflow_hash _000776_hash = {
86555 + .next = NULL,
86556 + .name = "il4965_rs_sta_dbgfs_stats_table_read",
86557 + .file = "drivers/net/wireless/iwlegacy/4965-rs.c",
86558 + .param3 = 1,
86559 +};
86560 +
86561 +struct size_overflow_hash _000777_hash = {
86562 + .next = NULL,
86563 + .name = "il4965_ucode_general_stats_read",
86564 + .file = "drivers/net/wireless/iwlegacy/4965-debug.c",
86565 + .param3 = 1,
86566 +};
86567 +
86568 +struct size_overflow_hash _000778_hash = {
86569 + .next = NULL,
86570 + .name = "il4965_ucode_rx_stats_read",
86571 + .file = "drivers/net/wireless/iwlegacy/4965-debug.c",
86572 + .param3 = 1,
86573 +};
86574 +
86575 +struct size_overflow_hash _000779_hash = {
86576 + .next = NULL,
86577 + .name = "il4965_ucode_tx_stats_read",
86578 + .file = "drivers/net/wireless/iwlegacy/4965-debug.c",
86579 + .param3 = 1,
86580 +};
86581 +
86582 +struct size_overflow_hash _000780_hash = {
86583 + .next = NULL,
86584 + .name = "il_dbgfs_chain_noise_read",
86585 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86586 + .param3 = 1,
86587 +};
86588 +
86589 +struct size_overflow_hash _000781_hash = {
86590 + .next = NULL,
86591 + .name = "il_dbgfs_channels_read",
86592 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86593 + .param3 = 1,
86594 +};
86595 +
86596 +struct size_overflow_hash _000782_hash = {
86597 + .next = NULL,
86598 + .name = "il_dbgfs_disable_ht40_read",
86599 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86600 + .param3 = 1,
86601 +};
86602 +
86603 +struct size_overflow_hash _000783_hash = {
86604 + .next = NULL,
86605 + .name = "il_dbgfs_fh_reg_read",
86606 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86607 + .param3 = 1,
86608 +};
86609 +
86610 +struct size_overflow_hash _000784_hash = {
86611 + .next = NULL,
86612 + .name = "il_dbgfs_force_reset_read",
86613 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86614 + .param3 = 1,
86615 +};
86616 +
86617 +struct size_overflow_hash _000785_hash = {
86618 + .next = NULL,
86619 + .name = "il_dbgfs_interrupt_read",
86620 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86621 + .param3 = 1,
86622 +};
86623 +
86624 +struct size_overflow_hash _000786_hash = {
86625 + .next = NULL,
86626 + .name = "il_dbgfs_missed_beacon_read",
86627 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86628 + .param3 = 1,
86629 +};
86630 +
86631 +struct size_overflow_hash _000787_hash = {
86632 + .next = NULL,
86633 + .name = "il_dbgfs_nvm_read",
86634 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86635 + .param3 = 1,
86636 +};
86637 +
86638 +struct size_overflow_hash _000788_hash = {
86639 + .next = NULL,
86640 + .name = "il_dbgfs_power_save_status_read",
86641 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86642 + .param3 = 1,
86643 +};
86644 +
86645 +struct size_overflow_hash _000789_hash = {
86646 + .next = NULL,
86647 + .name = "il_dbgfs_qos_read",
86648 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86649 + .param3 = 1,
86650 +};
86651 +
86652 +struct size_overflow_hash _000790_hash = {
86653 + .next = &_000221_hash,
86654 + .name = "il_dbgfs_rxon_filter_flags_read",
86655 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86656 + .param3 = 1,
86657 +};
86658 +
86659 +struct size_overflow_hash _000791_hash = {
86660 + .next = NULL,
86661 + .name = "il_dbgfs_rxon_flags_read",
86662 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86663 + .param3 = 1,
86664 +};
86665 +
86666 +struct size_overflow_hash _000792_hash = {
86667 + .next = NULL,
86668 + .name = "il_dbgfs_rx_queue_read",
86669 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86670 + .param3 = 1,
86671 +};
86672 +
86673 +struct size_overflow_hash _000793_hash = {
86674 + .next = NULL,
86675 + .name = "il_dbgfs_rx_stats_read",
86676 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86677 + .param3 = 1,
86678 +};
86679 +
86680 +struct size_overflow_hash _000794_hash = {
86681 + .next = NULL,
86682 + .name = "il_dbgfs_sensitivity_read",
86683 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86684 + .param3 = 1,
86685 +};
86686 +
86687 +struct size_overflow_hash _000795_hash = {
86688 + .next = NULL,
86689 + .name = "il_dbgfs_sram_read",
86690 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86691 + .param3 = 1,
86692 +};
86693 +
86694 +struct size_overflow_hash _000796_hash = {
86695 + .next = NULL,
86696 + .name = "il_dbgfs_stations_read",
86697 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86698 + .param3 = 1,
86699 +};
86700 +
86701 +struct size_overflow_hash _000797_hash = {
86702 + .next = NULL,
86703 + .name = "il_dbgfs_status_read",
86704 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86705 + .param3 = 1,
86706 +};
86707 +
86708 +struct size_overflow_hash _000798_hash = {
86709 + .next = NULL,
86710 + .name = "il_dbgfs_traffic_log_read",
86711 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86712 + .param3 = 1,
86713 +};
86714 +
86715 +struct size_overflow_hash _000799_hash = {
86716 + .next = NULL,
86717 + .name = "il_dbgfs_tx_queue_read",
86718 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86719 + .param3 = 1,
86720 +};
86721 +
86722 +struct size_overflow_hash _000800_hash = {
86723 + .next = NULL,
86724 + .name = "il_dbgfs_tx_stats_read",
86725 + .file = "drivers/net/wireless/iwlegacy/debug.c",
86726 + .param3 = 1,
86727 +};
86728 +
86729 +struct size_overflow_hash _000801_hash = {
86730 + .next = NULL,
86731 + .name = "ilo_read",
86732 + .file = "drivers/misc/hpilo.c",
86733 + .param3 = 1,
86734 +};
86735 +
86736 +struct size_overflow_hash _000802_hash = {
86737 + .next = NULL,
86738 + .name = "ilo_write",
86739 + .file = "drivers/misc/hpilo.c",
86740 + .param3 = 1,
86741 +};
86742 +
86743 +struct size_overflow_hash _000803_hash = {
86744 + .next = NULL,
86745 + .name = "init_data_container",
86746 + .file = "fs/btrfs/backref.c",
86747 + .param1 = 1,
86748 +};
86749 +
86750 +struct size_overflow_hash _000804_hash = {
86751 + .next = NULL,
86752 + .name = "init_list_set",
86753 + .file = "net/netfilter/ipset/ip_set_list_set.c",
86754 + .param2 = 1,
86755 + .param3 = 1,
86756 +};
86757 +
86758 +struct size_overflow_hash _000806_hash = {
86759 + .next = NULL,
86760 + .name = "interpret_user_input",
86761 + .file = "fs/ubifs/debug.c",
86762 + .param2 = 1,
86763 +};
86764 +
86765 +struct size_overflow_hash _000807_hash = {
86766 + .next = NULL,
86767 + .name = "int_proc_write",
86768 + .file = "drivers/net/wireless/ray_cs.c",
86769 + .param3 = 1,
86770 +};
86771 +
86772 +struct size_overflow_hash _000808_hash = {
86773 + .next = NULL,
86774 + .name = "iowarrior_read",
86775 + .file = "drivers/usb/misc/iowarrior.c",
86776 + .param3 = 1,
86777 +};
86778 +
86779 +struct size_overflow_hash _000809_hash = {
86780 + .next = NULL,
86781 + .name = "iowarrior_write",
86782 + .file = "drivers/usb/misc/iowarrior.c",
86783 + .param3 = 1,
86784 +};
86785 +
86786 +struct size_overflow_hash _000810_hash = {
86787 + .next = NULL,
86788 + .name = "ip_set_alloc",
86789 + .file = "include/linux/netfilter/ipset/ip_set.h",
86790 + .param1 = 1,
86791 +};
86792 +
86793 +struct size_overflow_hash _000811_hash = {
86794 + .next = NULL,
86795 + .name = "ip_vs_conn_fill_param_sync",
86796 + .file = "net/netfilter/ipvs/ip_vs_sync.c",
86797 + .param6 = 1,
86798 +};
86799 +
86800 +struct size_overflow_hash _000812_hash = {
86801 + .next = NULL,
86802 + .name = "irda_setsockopt",
86803 + .file = "net/irda/af_irda.c",
86804 + .param5 = 1,
86805 +};
86806 +
86807 +struct size_overflow_hash _000813_hash = {
86808 + .next = NULL,
86809 + .name = "ir_lirc_transmit_ir",
86810 + .file = "drivers/media/rc/ir-lirc-codec.c",
86811 + .param3 = 1,
86812 +};
86813 +
86814 +struct size_overflow_hash _000814_hash = {
86815 + .next = NULL,
86816 + .name = "irnet_ctrl_write",
86817 + .file = "net/irda/irnet/irnet_ppp.c",
86818 + .param3 = 1,
86819 +};
86820 +
86821 +struct size_overflow_hash _000815_hash = {
86822 + .next = NULL,
86823 + .name = "iscsi_decode_text_input",
86824 + .file = "drivers/target/iscsi/iscsi_target_parameters.c",
86825 + .param4 = 1,
86826 +};
86827 +
86828 +struct size_overflow_hash _000816_hash = {
86829 + .next = NULL,
86830 + .name = "iscsit_dump_data_payload",
86831 + .file = "drivers/target/iscsi/iscsi_target_erl1.c",
86832 + .param2 = 1,
86833 +};
86834 +
86835 +struct size_overflow_hash _000817_hash = {
86836 + .next = NULL,
86837 + .name = "isdn_read",
86838 + .file = "drivers/isdn/i4l/isdn_common.c",
86839 + .param3 = 1,
86840 +};
86841 +
86842 +struct size_overflow_hash _000818_hash = {
86843 + .next = NULL,
86844 + .name = "iso_callback",
86845 + .file = "drivers/firewire/core-cdev.c",
86846 + .param3 = 1,
86847 +};
86848 +
86849 +struct size_overflow_hash _000819_hash = {
86850 + .next = NULL,
86851 + .name = "iso_packets_buffer_init",
86852 + .file = "sound/firewire/packets-buffer.c",
86853 + .param3 = 1,
86854 +};
86855 +
86856 +struct size_overflow_hash _000820_hash = {
86857 + .next = NULL,
86858 + .name = "iso_sched_alloc",
86859 + .file = "drivers/usb/host/ehci-sched.c",
86860 + .param1 = 1,
86861 +};
86862 +
86863 +struct size_overflow_hash _000821_hash = {
86864 + .next = NULL,
86865 + .name = "isr_cmd_cmplt_read",
86866 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86867 + .param3 = 1,
86868 +};
86869 +
86870 +struct size_overflow_hash _000822_hash = {
86871 + .next = NULL,
86872 + .name = "isr_commands_read",
86873 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86874 + .param3 = 1,
86875 +};
86876 +
86877 +struct size_overflow_hash _000823_hash = {
86878 + .next = NULL,
86879 + .name = "isr_decrypt_done_read",
86880 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86881 + .param3 = 1,
86882 +};
86883 +
86884 +struct size_overflow_hash _000824_hash = {
86885 + .next = NULL,
86886 + .name = "isr_dma0_done_read",
86887 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86888 + .param3 = 1,
86889 +};
86890 +
86891 +struct size_overflow_hash _000825_hash = {
86892 + .next = NULL,
86893 + .name = "isr_dma1_done_read",
86894 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86895 + .param3 = 1,
86896 +};
86897 +
86898 +struct size_overflow_hash _000826_hash = {
86899 + .next = NULL,
86900 + .name = "isr_fiqs_read",
86901 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86902 + .param3 = 1,
86903 +};
86904 +
86905 +struct size_overflow_hash _000827_hash = {
86906 + .next = NULL,
86907 + .name = "isr_host_acknowledges_read",
86908 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86909 + .param3 = 1,
86910 +};
86911 +
86912 +struct size_overflow_hash _000828_hash = {
86913 + .next = &_000629_hash,
86914 + .name = "isr_hw_pm_mode_changes_read",
86915 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86916 + .param3 = 1,
86917 +};
86918 +
86919 +struct size_overflow_hash _000829_hash = {
86920 + .next = &_000329_hash,
86921 + .name = "isr_irqs_read",
86922 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86923 + .param3 = 1,
86924 +};
86925 +
86926 +struct size_overflow_hash _000830_hash = {
86927 + .next = NULL,
86928 + .name = "isr_low_rssi_read",
86929 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86930 + .param3 = 1,
86931 +};
86932 +
86933 +struct size_overflow_hash _000831_hash = {
86934 + .next = NULL,
86935 + .name = "isr_pci_pm_read",
86936 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86937 + .param3 = 1,
86938 +};
86939 +
86940 +struct size_overflow_hash _000832_hash = {
86941 + .next = NULL,
86942 + .name = "isr_rx_headers_read",
86943 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86944 + .param3 = 1,
86945 +};
86946 +
86947 +struct size_overflow_hash _000833_hash = {
86948 + .next = NULL,
86949 + .name = "isr_rx_mem_overflow_read",
86950 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86951 + .param3 = 1,
86952 +};
86953 +
86954 +struct size_overflow_hash _000834_hash = {
86955 + .next = NULL,
86956 + .name = "isr_rx_procs_read",
86957 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86958 + .param3 = 1,
86959 +};
86960 +
86961 +struct size_overflow_hash _000835_hash = {
86962 + .next = NULL,
86963 + .name = "isr_rx_rdys_read",
86964 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86965 + .param3 = 1,
86966 +};
86967 +
86968 +struct size_overflow_hash _000836_hash = {
86969 + .next = NULL,
86970 + .name = "isr_tx_exch_complete_read",
86971 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86972 + .param3 = 1,
86973 +};
86974 +
86975 +struct size_overflow_hash _000837_hash = {
86976 + .next = NULL,
86977 + .name = "isr_tx_procs_read",
86978 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86979 + .param3 = 1,
86980 +};
86981 +
86982 +struct size_overflow_hash _000838_hash = {
86983 + .next = NULL,
86984 + .name = "isr_wakeups_read",
86985 + .file = "drivers/net/wireless/wl1251/debugfs.c",
86986 + .param3 = 1,
86987 +};
86988 +
86989 +struct size_overflow_hash _000839_hash = {
86990 + .next = NULL,
86991 + .name = "ivtv_copy_buf_to_user",
86992 + .file = "drivers/media/video/ivtv/ivtv-fileops.c",
86993 + .param4 = 1,
86994 +};
86995 +
86996 +struct size_overflow_hash _000840_hash = {
86997 + .next = NULL,
86998 + .name = "iwl_dbgfs_bt_traffic_read",
86999 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87000 + .param3 = 1,
87001 +};
87002 +
87003 +struct size_overflow_hash _000841_hash = {
87004 + .next = NULL,
87005 + .name = "iwl_dbgfs_chain_noise_read",
87006 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87007 + .param3 = 1,
87008 +};
87009 +
87010 +struct size_overflow_hash _000842_hash = {
87011 + .next = NULL,
87012 + .name = "iwl_dbgfs_channels_read",
87013 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87014 + .param3 = 1,
87015 +};
87016 +
87017 +struct size_overflow_hash _000843_hash = {
87018 + .next = NULL,
87019 + .name = "iwl_dbgfs_current_sleep_command_read",
87020 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87021 + .param3 = 1,
87022 +};
87023 +
87024 +struct size_overflow_hash _000844_hash = {
87025 + .next = NULL,
87026 + .name = "iwl_dbgfs_debug_level_read",
87027 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87028 + .param3 = 1,
87029 +};
87030 +
87031 +struct size_overflow_hash _000845_hash = {
87032 + .next = NULL,
87033 + .name = "iwl_dbgfs_debug_level_write",
87034 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87035 + .param3 = 1,
87036 +};
87037 +
87038 +struct size_overflow_hash _000846_hash = {
87039 + .next = NULL,
87040 + .name = "iwl_dbgfs_disable_ht40_read",
87041 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87042 + .param3 = 1,
87043 +};
87044 +
87045 +struct size_overflow_hash _000847_hash = {
87046 + .next = NULL,
87047 + .name = "iwl_dbgfs_fh_reg_read",
87048 + .file = "drivers/net/wireless/iwlwifi/iwl-trans-pcie.c",
87049 + .param3 = 1,
87050 +};
87051 +
87052 +struct size_overflow_hash _000848_hash = {
87053 + .next = NULL,
87054 + .name = "iwl_dbgfs_force_reset_read",
87055 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87056 + .param3 = 1,
87057 +};
87058 +
87059 +struct size_overflow_hash _000849_hash = {
87060 + .next = NULL,
87061 + .name = "iwl_dbgfs_interrupt_read",
87062 + .file = "drivers/net/wireless/iwlwifi/iwl-trans-pcie.c",
87063 + .param3 = 1,
87064 +};
87065 +
87066 +struct size_overflow_hash _000850_hash = {
87067 + .next = NULL,
87068 + .name = "iwl_dbgfs_log_event_read",
87069 + .file = "drivers/net/wireless/iwlwifi/iwl-trans-pcie.c",
87070 + .param3 = 1,
87071 +};
87072 +
87073 +struct size_overflow_hash _000851_hash = {
87074 + .next = NULL,
87075 + .name = "iwl_dbgfs_missed_beacon_read",
87076 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87077 + .param3 = 1,
87078 +};
87079 +
87080 +struct size_overflow_hash _000852_hash = {
87081 + .next = NULL,
87082 + .name = "iwl_dbgfs_nvm_read",
87083 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87084 + .param3 = 1,
87085 +};
87086 +
87087 +struct size_overflow_hash _000853_hash = {
87088 + .next = NULL,
87089 + .name = "iwl_dbgfs_plcp_delta_read",
87090 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87091 + .param3 = 1,
87092 +};
87093 +
87094 +struct size_overflow_hash _000854_hash = {
87095 + .next = NULL,
87096 + .name = "iwl_dbgfs_power_save_status_read",
87097 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87098 + .param3 = 1,
87099 +};
87100 +
87101 +struct size_overflow_hash _000855_hash = {
87102 + .next = NULL,
87103 + .name = "iwl_dbgfs_protection_mode_read",
87104 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87105 + .param3 = 1,
87106 +};
87107 +
87108 +struct size_overflow_hash _000856_hash = {
87109 + .next = NULL,
87110 + .name = "iwl_dbgfs_qos_read",
87111 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87112 + .param3 = 1,
87113 +};
87114 +
87115 +struct size_overflow_hash _000857_hash = {
87116 + .next = NULL,
87117 + .name = "iwl_dbgfs_reply_tx_error_read",
87118 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87119 + .param3 = 1,
87120 +};
87121 +
87122 +struct size_overflow_hash _000858_hash = {
87123 + .next = NULL,
87124 + .name = "iwl_dbgfs_rx_handlers_read",
87125 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87126 + .param3 = 1,
87127 +};
87128 +
87129 +struct size_overflow_hash _000859_hash = {
87130 + .next = NULL,
87131 + .name = "iwl_dbgfs_rxon_filter_flags_read",
87132 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87133 + .param3 = 1,
87134 +};
87135 +
87136 +struct size_overflow_hash _000860_hash = {
87137 + .next = NULL,
87138 + .name = "iwl_dbgfs_rxon_flags_read",
87139 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87140 + .param3 = 1,
87141 +};
87142 +
87143 +struct size_overflow_hash _000861_hash = {
87144 + .next = NULL,
87145 + .name = "iwl_dbgfs_rx_queue_read",
87146 + .file = "drivers/net/wireless/iwlwifi/iwl-trans-pcie.c",
87147 + .param3 = 1,
87148 +};
87149 +
87150 +struct size_overflow_hash _000862_hash = {
87151 + .next = NULL,
87152 + .name = "iwl_dbgfs_rx_statistics_read",
87153 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87154 + .param3 = 1,
87155 +};
87156 +
87157 +struct size_overflow_hash _000863_hash = {
87158 + .next = NULL,
87159 + .name = "iwl_dbgfs_sensitivity_read",
87160 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87161 + .param3 = 1,
87162 +};
87163 +
87164 +struct size_overflow_hash _000864_hash = {
87165 + .next = NULL,
87166 + .name = "iwl_dbgfs_sleep_level_override_read",
87167 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87168 + .param3 = 1,
87169 +};
87170 +
87171 +struct size_overflow_hash _000865_hash = {
87172 + .next = NULL,
87173 + .name = "iwl_dbgfs_sram_read",
87174 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87175 + .param3 = 1,
87176 +};
87177 +
87178 +struct size_overflow_hash _000866_hash = {
87179 + .next = NULL,
87180 + .name = "iwl_dbgfs_stations_read",
87181 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87182 + .param3 = 1,
87183 +};
87184 +
87185 +struct size_overflow_hash _000867_hash = {
87186 + .next = NULL,
87187 + .name = "iwl_dbgfs_status_read",
87188 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87189 + .param3 = 1,
87190 +};
87191 +
87192 +struct size_overflow_hash _000868_hash = {
87193 + .next = NULL,
87194 + .name = "iwl_dbgfs_temperature_read",
87195 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87196 + .param3 = 1,
87197 +};
87198 +
87199 +struct size_overflow_hash _000869_hash = {
87200 + .next = NULL,
87201 + .name = "iwl_dbgfs_thermal_throttling_read",
87202 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87203 + .param3 = 1,
87204 +};
87205 +
87206 +struct size_overflow_hash _000870_hash = {
87207 + .next = NULL,
87208 + .name = "iwl_dbgfs_traffic_log_read",
87209 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87210 + .param3 = 1,
87211 +};
87212 +
87213 +struct size_overflow_hash _000871_hash = {
87214 + .next = NULL,
87215 + .name = "iwl_dbgfs_tx_queue_read",
87216 + .file = "drivers/net/wireless/iwlwifi/iwl-trans-pcie.c",
87217 + .param3 = 1,
87218 +};
87219 +
87220 +struct size_overflow_hash _000872_hash = {
87221 + .next = NULL,
87222 + .name = "iwl_dbgfs_tx_statistics_read",
87223 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87224 + .param3 = 1,
87225 +};
87226 +
87227 +struct size_overflow_hash _000873_hash = {
87228 + .next = NULL,
87229 + .name = "iwl_dbgfs_ucode_bt_stats_read",
87230 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87231 + .param3 = 1,
87232 +};
87233 +
87234 +struct size_overflow_hash _000874_hash = {
87235 + .next = NULL,
87236 + .name = "iwl_dbgfs_ucode_general_stats_read",
87237 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87238 + .param3 = 1,
87239 +};
87240 +
87241 +struct size_overflow_hash _000875_hash = {
87242 + .next = NULL,
87243 + .name = "iwl_dbgfs_ucode_rx_stats_read",
87244 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87245 + .param3 = 1,
87246 +};
87247 +
87248 +struct size_overflow_hash _000876_hash = {
87249 + .next = NULL,
87250 + .name = "iwl_dbgfs_ucode_tracing_read",
87251 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87252 + .param3 = 1,
87253 +};
87254 +
87255 +struct size_overflow_hash _000877_hash = {
87256 + .next = NULL,
87257 + .name = "iwl_dbgfs_ucode_tx_stats_read",
87258 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87259 + .param3 = 1,
87260 +};
87261 +
87262 +struct size_overflow_hash _000878_hash = {
87263 + .next = NULL,
87264 + .name = "iwl_dbgfs_wowlan_sram_read",
87265 + .file = "drivers/net/wireless/iwlwifi/iwl-debugfs.c",
87266 + .param3 = 1,
87267 +};
87268 +
87269 +struct size_overflow_hash _000879_hash = {
87270 + .next = NULL,
87271 + .name = "iwmct_fw_parser_init",
87272 + .file = "drivers/misc/iwmc3200top/fw-download.c",
87273 + .param4 = 1,
87274 +};
87275 +
87276 +struct size_overflow_hash _000880_hash = {
87277 + .next = NULL,
87278 + .name = "iwm_notif_send",
87279 + .file = "drivers/net/wireless/iwmc3200wifi/main.c",
87280 + .param6 = 1,
87281 +};
87282 +
87283 +struct size_overflow_hash _000881_hash = {
87284 + .next = NULL,
87285 + .name = "iwm_ntf_calib_res",
87286 + .file = "drivers/net/wireless/iwmc3200wifi/rx.c",
87287 + .param3 = 1,
87288 +};
87289 +
87290 +struct size_overflow_hash _000882_hash = {
87291 + .next = NULL,
87292 + .name = "iwm_umac_set_config_var",
87293 + .file = "drivers/net/wireless/iwmc3200wifi/commands.c",
87294 + .param4 = 1,
87295 +};
87296 +
87297 +struct size_overflow_hash _000883_hash = {
87298 + .next = NULL,
87299 + .name = "jbd2_alloc",
87300 + .file = "include/linux/jbd2.h",
87301 + .param1 = 1,
87302 +};
87303 +
87304 +struct size_overflow_hash _000884_hash = {
87305 + .next = NULL,
87306 + .name = "key_algorithm_read",
87307 + .file = "net/mac80211/debugfs_key.c",
87308 + .param3 = 1,
87309 +};
87310 +
87311 +struct size_overflow_hash _000885_hash = {
87312 + .next = NULL,
87313 + .name = "key_icverrors_read",
87314 + .file = "net/mac80211/debugfs_key.c",
87315 + .param3 = 1,
87316 +};
87317 +
87318 +struct size_overflow_hash _000886_hash = {
87319 + .next = NULL,
87320 + .name = "key_key_read",
87321 + .file = "net/mac80211/debugfs_key.c",
87322 + .param3 = 1,
87323 +};
87324 +
87325 +struct size_overflow_hash _000887_hash = {
87326 + .next = NULL,
87327 + .name = "key_replays_read",
87328 + .file = "net/mac80211/debugfs_key.c",
87329 + .param3 = 1,
87330 +};
87331 +
87332 +struct size_overflow_hash _000888_hash = {
87333 + .next = NULL,
87334 + .name = "key_rx_spec_read",
87335 + .file = "net/mac80211/debugfs_key.c",
87336 + .param3 = 1,
87337 +};
87338 +
87339 +struct size_overflow_hash _000889_hash = {
87340 + .next = NULL,
87341 + .name = "key_tx_spec_read",
87342 + .file = "net/mac80211/debugfs_key.c",
87343 + .param3 = 1,
87344 +};
87345 +
87346 +struct size_overflow_hash _000890_hash = {
87347 + .next = NULL,
87348 + .name = "kmem_alloc",
87349 + .file = "fs/xfs/kmem.c",
87350 + .param1 = 1,
87351 +};
87352 +
87353 +struct size_overflow_hash _000891_hash = {
87354 + .next = NULL,
87355 + .name = "kmem_zalloc_large",
87356 + .file = "fs/xfs/kmem.h",
87357 + .param1 = 1,
87358 +};
87359 +
87360 +struct size_overflow_hash _000892_hash = {
87361 + .next = NULL,
87362 + .name = "kone_receive",
87363 + .file = "drivers/hid/hid-roccat-kone.c",
87364 + .param4 = 1,
87365 +};
87366 +
87367 +struct size_overflow_hash _000893_hash = {
87368 + .next = NULL,
87369 + .name = "kone_send",
87370 + .file = "drivers/hid/hid-roccat-kone.c",
87371 + .param4 = 1,
87372 +};
87373 +
87374 +struct size_overflow_hash _000894_hash = {
87375 + .next = NULL,
87376 + .name = "kvm_read_guest_atomic",
87377 + .file = "include/linux/kvm_host.h",
87378 + .param4 = 1,
87379 +};
87380 +
87381 +struct size_overflow_hash _000895_hash = {
87382 + .next = NULL,
87383 + .name = "kvm_read_guest_cached",
87384 + .file = "include/linux/kvm_host.h",
87385 + .param4 = 1,
87386 +};
87387 +
87388 +struct size_overflow_hash _000896_hash = {
87389 + .next = NULL,
87390 + .name = "kvm_set_irq_routing",
87391 + .file = "include/linux/kvm_host.h",
87392 + .param3 = 1,
87393 +};
87394 +
87395 +struct size_overflow_hash _000897_hash = {
87396 + .next = NULL,
87397 + .name = "kvm_write_guest_cached",
87398 + .file = "include/linux/kvm_host.h",
87399 + .param4 = 1,
87400 +};
87401 +
87402 +struct size_overflow_hash _000898_hash = {
87403 + .next = NULL,
87404 + .name = "l2cap_sock_setsockopt",
87405 + .file = "net/bluetooth/l2cap_sock.c",
87406 + .param5 = 1,
87407 +};
87408 +
87409 +struct size_overflow_hash _000899_hash = {
87410 + .next = NULL,
87411 + .name = "l2cap_sock_setsockopt_old",
87412 + .file = "net/bluetooth/l2cap_sock.c",
87413 + .param4 = 1,
87414 +};
87415 +
87416 +struct size_overflow_hash _000900_hash = {
87417 + .next = NULL,
87418 + .name = "lane2_associate_req",
87419 + .file = "net/atm/lec.c",
87420 + .param4 = 1,
87421 +};
87422 +
87423 +struct size_overflow_hash _000901_hash = {
87424 + .next = NULL,
87425 + .name = "lbs_debugfs_read",
87426 + .file = "drivers/net/wireless/libertas/debugfs.c",
87427 + .param3 = 1,
87428 +};
87429 +
87430 +struct size_overflow_hash _000902_hash = {
87431 + .next = NULL,
87432 + .name = "lbs_debugfs_write",
87433 + .file = "drivers/net/wireless/libertas/debugfs.c",
87434 + .param3 = 1,
87435 +};
87436 +
87437 +struct size_overflow_hash _000903_hash = {
87438 + .next = NULL,
87439 + .name = "lbs_dev_info",
87440 + .file = "drivers/net/wireless/libertas/debugfs.c",
87441 + .param3 = 1,
87442 +};
87443 +
87444 +struct size_overflow_hash _000904_hash = {
87445 + .next = NULL,
87446 + .name = "lbs_host_sleep_read",
87447 + .file = "drivers/net/wireless/libertas/debugfs.c",
87448 + .param3 = 1,
87449 +};
87450 +
87451 +struct size_overflow_hash _000905_hash = {
87452 + .next = NULL,
87453 + .name = "lbs_rdbbp_read",
87454 + .file = "drivers/net/wireless/libertas/debugfs.c",
87455 + .param3 = 1,
87456 +};
87457 +
87458 +struct size_overflow_hash _000906_hash = {
87459 + .next = NULL,
87460 + .name = "lbs_rdmac_read",
87461 + .file = "drivers/net/wireless/libertas/debugfs.c",
87462 + .param3 = 1,
87463 +};
87464 +
87465 +struct size_overflow_hash _000907_hash = {
87466 + .next = NULL,
87467 + .name = "lbs_rdrf_read",
87468 + .file = "drivers/net/wireless/libertas/debugfs.c",
87469 + .param3 = 1,
87470 +};
87471 +
87472 +struct size_overflow_hash _000908_hash = {
87473 + .next = NULL,
87474 + .name = "lbs_sleepparams_read",
87475 + .file = "drivers/net/wireless/libertas/debugfs.c",
87476 + .param3 = 1,
87477 +};
87478 +
87479 +struct size_overflow_hash _000909_hash = {
87480 + .next = NULL,
87481 + .name = "lbs_threshold_read",
87482 + .file = "drivers/net/wireless/libertas/debugfs.c",
87483 + .param5 = 1,
87484 +};
87485 +
87486 +struct size_overflow_hash _000910_hash = {
87487 + .next = NULL,
87488 + .name = "lc_create",
87489 + .file = "include/linux/lru_cache.h",
87490 + .param3 = 1,
87491 +};
87492 +
87493 +struct size_overflow_hash _000911_hash = {
87494 + .next = NULL,
87495 + .name = "lcd_write",
87496 + .file = "drivers/usb/misc/usblcd.c",
87497 + .param3 = 1,
87498 +};
87499 +
87500 +struct size_overflow_hash _000912_hash = {
87501 + .next = NULL,
87502 + .name = "leaf_dealloc",
87503 + .file = "fs/gfs2/dir.c",
87504 + .param3 = 1,
87505 +};
87506 +
87507 +struct size_overflow_hash _000913_hash = {
87508 + .next = NULL,
87509 + .name = "__lgread",
87510 + .file = "drivers/lguest/core.c",
87511 + .param4 = 1,
87512 +};
87513 +
87514 +struct size_overflow_hash _000914_hash = {
87515 + .next = NULL,
87516 + .name = "__lgwrite",
87517 + .file = "drivers/lguest/core.c",
87518 + .param4 = 1,
87519 +};
87520 +
87521 +struct size_overflow_hash _000915_hash = {
87522 + .next = NULL,
87523 + .name = "link_send_sections_long",
87524 + .file = "net/tipc/link.c",
87525 + .param4 = 1,
87526 +};
87527 +
87528 +struct size_overflow_hash _000916_hash = {
87529 + .next = NULL,
87530 + .name = "lirc_buffer_init",
87531 + .file = "include/media/lirc_dev.h",
87532 + .param2 = 1,
87533 + .param3 = 1,
87534 +};
87535 +
87536 +struct size_overflow_hash _000918_hash = {
87537 + .next = NULL,
87538 + .name = "lkdtm_debugfs_read",
87539 + .file = "drivers/misc/lkdtm.c",
87540 + .param3 = 1,
87541 +};
87542 +
87543 +struct size_overflow_hash _000919_hash = {
87544 + .next = NULL,
87545 + .name = "LoadBitmap",
87546 + .file = "drivers/media/dvb/ttpci/av7110_hw.c",
87547 + .param2 = 1,
87548 +};
87549 +
87550 +struct size_overflow_hash _000920_hash = {
87551 + .next = NULL,
87552 + .name = "long_retry_limit_read",
87553 + .file = "net/wireless/debugfs.c",
87554 + .param3 = 1,
87555 +};
87556 +
87557 +struct size_overflow_hash _000921_hash = {
87558 + .next = NULL,
87559 + .name = "lpfc_debugfs_dif_err_read",
87560 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87561 + .param3 = 1,
87562 +};
87563 +
87564 +struct size_overflow_hash _000922_hash = {
87565 + .next = NULL,
87566 + .name = "lpfc_debugfs_dif_err_write",
87567 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87568 + .param3 = 1,
87569 +};
87570 +
87571 +struct size_overflow_hash _000923_hash = {
87572 + .next = NULL,
87573 + .name = "lpfc_debugfs_read",
87574 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87575 + .param3 = 1,
87576 +};
87577 +
87578 +struct size_overflow_hash _000924_hash = {
87579 + .next = NULL,
87580 + .name = "lpfc_idiag_baracc_read",
87581 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87582 + .param3 = 1,
87583 +};
87584 +
87585 +struct size_overflow_hash _000925_hash = {
87586 + .next = NULL,
87587 + .name = "lpfc_idiag_ctlacc_read",
87588 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87589 + .param3 = 1,
87590 +};
87591 +
87592 +struct size_overflow_hash _000926_hash = {
87593 + .next = NULL,
87594 + .name = "lpfc_idiag_drbacc_read",
87595 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87596 + .param3 = 1,
87597 +};
87598 +
87599 +struct size_overflow_hash _000927_hash = {
87600 + .next = NULL,
87601 + .name = "lpfc_idiag_extacc_read",
87602 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87603 + .param3 = 1,
87604 +};
87605 +
87606 +struct size_overflow_hash _000928_hash = {
87607 + .next = NULL,
87608 + .name = "lpfc_idiag_mbxacc_read",
87609 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87610 + .param3 = 1,
87611 +};
87612 +
87613 +struct size_overflow_hash _000929_hash = {
87614 + .next = NULL,
87615 + .name = "lpfc_idiag_pcicfg_read",
87616 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87617 + .param3 = 1,
87618 +};
87619 +
87620 +struct size_overflow_hash _000930_hash = {
87621 + .next = NULL,
87622 + .name = "lpfc_idiag_queacc_read",
87623 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87624 + .param3 = 1,
87625 +};
87626 +
87627 +struct size_overflow_hash _000931_hash = {
87628 + .next = NULL,
87629 + .name = "lpfc_idiag_queinfo_read",
87630 + .file = "drivers/scsi/lpfc/lpfc_debugfs.c",
87631 + .param3 = 1,
87632 +};
87633 +
87634 +struct size_overflow_hash _000932_hash = {
87635 + .next = NULL,
87636 + .name = "lpfc_sli4_queue_alloc",
87637 + .file = "drivers/scsi/lpfc/lpfc_sli.c",
87638 + .param3 = 1,
87639 +};
87640 +
87641 +struct size_overflow_hash _000933_hash = {
87642 + .next = NULL,
87643 + .name = "lp_write",
87644 + .file = "drivers/char/lp.c",
87645 + .param3 = 1,
87646 +};
87647 +
87648 +struct size_overflow_hash _000934_hash = {
87649 + .next = NULL,
87650 + .name = "mac80211_format_buffer",
87651 + .file = "net/mac80211/debugfs.c",
87652 + .param2 = 1,
87653 +};
87654 +
87655 +struct size_overflow_hash _000935_hash = {
87656 + .next = NULL,
87657 + .name = "mce_write",
87658 + .file = "arch/x86/kernel/cpu/mcheck/mce-inject.c",
87659 + .param3 = 1,
87660 +};
87661 +
87662 +struct size_overflow_hash _000936_hash = {
87663 + .next = NULL,
87664 + .name = "mcs7830_get_reg",
87665 + .file = "drivers/net/usb/mcs7830.c",
87666 + .param3 = 1,
87667 +};
87668 +
87669 +struct size_overflow_hash _000937_hash = {
87670 + .next = NULL,
87671 + .name = "mcs7830_set_reg",
87672 + .file = "drivers/net/usb/mcs7830.c",
87673 + .param3 = 1,
87674 +};
87675 +
87676 +struct size_overflow_hash _000938_hash = {
87677 + .next = NULL,
87678 + .name = "mdc800_device_read",
87679 + .file = "drivers/usb/image/mdc800.c",
87680 + .param3 = 1,
87681 +};
87682 +
87683 +struct size_overflow_hash _000939_hash = {
87684 + .next = NULL,
87685 + .name = "mdiobus_alloc_size",
87686 + .file = "include/linux/phy.h",
87687 + .param1 = 1,
87688 +};
87689 +
87690 +struct size_overflow_hash _000940_hash = {
87691 + .next = NULL,
87692 + .name = "media_entity_init",
87693 + .file = "include/media/media-entity.h",
87694 + .param2 = 1,
87695 + .param4 = 1,
87696 +};
87697 +
87698 +struct size_overflow_hash _000942_hash = {
87699 + .next = NULL,
87700 + .name = "memstick_alloc_host",
87701 + .file = "include/linux/memstick.h",
87702 + .param1 = 1,
87703 +};
87704 +
87705 +struct size_overflow_hash _000943_hash = {
87706 + .next = NULL,
87707 + .name = "mgmt_control",
87708 + .file = "include/net/bluetooth/hci_core.h",
87709 + .param3 = 1,
87710 +};
87711 +
87712 +struct size_overflow_hash _000944_hash = {
87713 + .next = NULL,
87714 + .name = "mgmt_pending_add",
87715 + .file = "net/bluetooth/mgmt.c",
87716 + .param5 = 1,
87717 +};
87718 +
87719 +struct size_overflow_hash _000945_hash = {
87720 + .next = &_000321_hash,
87721 + .name = "mic_calc_failure_read",
87722 + .file = "drivers/net/wireless/wl1251/debugfs.c",
87723 + .param3 = 1,
87724 +};
87725 +
87726 +struct size_overflow_hash _000946_hash = {
87727 + .next = NULL,
87728 + .name = "mic_rx_pkts_read",
87729 + .file = "drivers/net/wireless/wl1251/debugfs.c",
87730 + .param3 = 1,
87731 +};
87732 +
87733 +struct size_overflow_hash _000947_hash = {
87734 + .next = NULL,
87735 + .name = "minstrel_stats_read",
87736 + .file = "net/mac80211/rc80211_minstrel_debugfs.c",
87737 + .param3 = 1,
87738 +};
87739 +
87740 +struct size_overflow_hash _000948_hash = {
87741 + .next = NULL,
87742 + .name = "mlx4_en_create_rx_ring",
87743 + .file = "drivers/net/ethernet/mellanox/mlx4/en_rx.c",
87744 + .param3 = 1,
87745 +};
87746 +
87747 +struct size_overflow_hash _000949_hash = {
87748 + .next = NULL,
87749 + .name = "mlx4_en_create_tx_ring",
87750 + .file = "drivers/net/ethernet/mellanox/mlx4/en_tx.c",
87751 + .param4 = 1,
87752 +};
87753 +
87754 +struct size_overflow_hash _000950_hash = {
87755 + .next = NULL,
87756 + .name = "mmc_ext_csd_read",
87757 + .file = "drivers/mmc/core/debugfs.c",
87758 + .param3 = 1,
87759 +};
87760 +
87761 +struct size_overflow_hash _000951_hash = {
87762 + .next = NULL,
87763 + .name = "mmc_send_bus_test",
87764 + .file = "drivers/mmc/core/mmc_ops.c",
87765 + .param4 = 1,
87766 +};
87767 +
87768 +struct size_overflow_hash _000952_hash = {
87769 + .next = NULL,
87770 + .name = "mmc_send_cxd_data",
87771 + .file = "drivers/mmc/core/mmc_ops.c",
87772 + .param5 = 1,
87773 +};
87774 +
87775 +struct size_overflow_hash _000953_hash = {
87776 + .next = NULL,
87777 + .name = "mmc_test_alloc_mem",
87778 + .file = "drivers/mmc/card/mmc_test.c",
87779 + .param3 = 1,
87780 +};
87781 +
87782 +struct size_overflow_hash _000954_hash = {
87783 + .next = NULL,
87784 + .name = "mon_bin_get_event",
87785 + .file = "drivers/usb/mon/mon_bin.c",
87786 + .param4 = 1,
87787 +};
87788 +
87789 +struct size_overflow_hash _000955_hash = {
87790 + .next = NULL,
87791 + .name = "mon_stat_read",
87792 + .file = "drivers/usb/mon/mon_stat.c",
87793 + .param3 = 1,
87794 +};
87795 +
87796 +struct size_overflow_hash _000956_hash = {
87797 + .next = NULL,
87798 + .name = "mptctl_getiocinfo",
87799 + .file = "drivers/message/fusion/mptctl.c",
87800 + .param2 = 1,
87801 +};
87802 +
87803 +struct size_overflow_hash _000957_hash = {
87804 + .next = NULL,
87805 + .name = "msnd_fifo_alloc",
87806 + .file = "sound/oss/msnd.c",
87807 + .param2 = 1,
87808 +};
87809 +
87810 +struct size_overflow_hash _000958_hash = {
87811 + .next = NULL,
87812 + .name = "mtdchar_readoob",
87813 + .file = "drivers/mtd/mtdchar.c",
87814 + .param4 = 1,
87815 +};
87816 +
87817 +struct size_overflow_hash _000959_hash = {
87818 + .next = NULL,
87819 + .name = "mtdchar_write",
87820 + .file = "drivers/mtd/mtdchar.c",
87821 + .param3 = 1,
87822 +};
87823 +
87824 +struct size_overflow_hash _000960_hash = {
87825 + .next = NULL,
87826 + .name = "mtdchar_writeoob",
87827 + .file = "drivers/mtd/mtdchar.c",
87828 + .param4 = 1,
87829 +};
87830 +
87831 +struct size_overflow_hash _000961_hash = {
87832 + .next = NULL,
87833 + .name = "mtdswap_init",
87834 + .file = "drivers/mtd/mtdswap.c",
87835 + .param2 = 1,
87836 +};
87837 +
87838 +struct size_overflow_hash _000962_hash = {
87839 + .next = NULL,
87840 + .name = "mtf_test_write",
87841 + .file = "drivers/mmc/card/mmc_test.c",
87842 + .param3 = 1,
87843 +};
87844 +
87845 +struct size_overflow_hash _000963_hash = {
87846 + .next = NULL,
87847 + .name = "musb_test_mode_write",
87848 + .file = "drivers/usb/musb/musb_debugfs.c",
87849 + .param3 = 1,
87850 +};
87851 +
87852 +struct size_overflow_hash _000964_hash = {
87853 + .next = NULL,
87854 + .name = "mvumi_alloc_mem_resource",
87855 + .file = "drivers/scsi/mvumi.c",
87856 + .param3 = 1,
87857 +};
87858 +
87859 +struct size_overflow_hash _000965_hash = {
87860 + .next = NULL,
87861 + .name = "mwifiex_alloc_sdio_mpa_buffers",
87862 + .file = "drivers/net/wireless/mwifiex/sdio.c",
87863 + .param2 = 1,
87864 + .param3 = 1,
87865 +};
87866 +
87867 +struct size_overflow_hash _000967_hash = {
87868 + .next = NULL,
87869 + .name = "mwifiex_debug_read",
87870 + .file = "drivers/net/wireless/mwifiex/debugfs.c",
87871 + .param3 = 1,
87872 +};
87873 +
87874 +struct size_overflow_hash _000968_hash = {
87875 + .next = NULL,
87876 + .name = "mwifiex_get_common_rates",
87877 + .file = "drivers/net/wireless/mwifiex/join.c",
87878 + .param3 = 1,
87879 +};
87880 +
87881 +struct size_overflow_hash _000969_hash = {
87882 + .next = NULL,
87883 + .name = "mwifiex_getlog_read",
87884 + .file = "drivers/net/wireless/mwifiex/debugfs.c",
87885 + .param3 = 1,
87886 +};
87887 +
87888 +struct size_overflow_hash _000970_hash = {
87889 + .next = NULL,
87890 + .name = "mwifiex_info_read",
87891 + .file = "drivers/net/wireless/mwifiex/debugfs.c",
87892 + .param3 = 1,
87893 +};
87894 +
87895 +struct size_overflow_hash _000971_hash = {
87896 + .next = NULL,
87897 + .name = "mwifiex_rdeeprom_read",
87898 + .file = "drivers/net/wireless/mwifiex/debugfs.c",
87899 + .param3 = 1,
87900 +};
87901 +
87902 +struct size_overflow_hash _000972_hash = {
87903 + .next = NULL,
87904 + .name = "mwifiex_regrdwr_read",
87905 + .file = "drivers/net/wireless/mwifiex/debugfs.c",
87906 + .param3 = 1,
87907 +};
87908 +
87909 +struct size_overflow_hash _000973_hash = {
87910 + .next = NULL,
87911 + .name = "mwifiex_update_curr_bss_params",
87912 + .file = "drivers/net/wireless/mwifiex/scan.c",
87913 + .param5 = 1,
87914 +};
87915 +
87916 +struct size_overflow_hash _000974_hash = {
87917 + .next = NULL,
87918 + .name = "nand_bch_init",
87919 + .file = "include/linux/mtd/nand_bch.h",
87920 + .param2 = 1,
87921 + .param3 = 1,
87922 +};
87923 +
87924 +struct size_overflow_hash _000976_hash = {
87925 + .next = NULL,
87926 + .name = "ncp_file_write",
87927 + .file = "fs/ncpfs/file.c",
87928 + .param3 = 1,
87929 +};
87930 +
87931 +struct size_overflow_hash _000977_hash = {
87932 + .next = NULL,
87933 + .name = "ncp__vol2io",
87934 + .file = "fs/ncpfs/ncplib_kernel.c",
87935 + .param5 = 1,
87936 +};
87937 +
87938 +struct size_overflow_hash _000978_hash = {
87939 + .next = NULL,
87940 + .name = "new_bind_ctl",
87941 + .file = "sound/pci/hda/patch_realtek.c",
87942 + .param2 = 1,
87943 +};
87944 +
87945 +struct size_overflow_hash _000979_hash = {
87946 + .next = NULL,
87947 + .name = "nfc_llcp_build_tlv",
87948 + .file = "net/nfc/llcp/commands.c",
87949 + .param3 = 1,
87950 +};
87951 +
87952 +struct size_overflow_hash _000980_hash = {
87953 + .next = NULL,
87954 + .name = "nfs4_alloc_slots",
87955 + .file = "fs/nfs/nfs4proc.c",
87956 + .param1 = 1,
87957 +};
87958 +
87959 +struct size_overflow_hash _000981_hash = {
87960 + .next = NULL,
87961 + .name = "nfs4_write_cached_acl",
87962 + .file = "fs/nfs/nfs4proc.c",
87963 + .param3 = 1,
87964 +};
87965 +
87966 +struct size_overflow_hash _000982_hash = {
87967 + .next = NULL,
87968 + .name = "nfsctl_transaction_read",
87969 + .file = "fs/nfsd/nfsctl.c",
87970 + .param3 = 1,
87971 +};
87972 +
87973 +struct size_overflow_hash _000983_hash = {
87974 + .next = NULL,
87975 + .name = "nfsctl_transaction_write",
87976 + .file = "fs/nfsd/nfsctl.c",
87977 + .param3 = 1,
87978 +};
87979 +
87980 +struct size_overflow_hash _000984_hash = {
87981 + .next = NULL,
87982 + .name = "nfsd_cache_update",
87983 + .file = "fs/nfsd/nfscache.c",
87984 + .param3 = 1,
87985 +};
87986 +
87987 +struct size_overflow_hash _000985_hash = {
87988 + .next = NULL,
87989 + .name = "nfs_idmap_get_desc",
87990 + .file = "fs/nfs/idmap.c",
87991 + .param2 = 1,
87992 + .param4 = 1,
87993 +};
87994 +
87995 +struct size_overflow_hash _000987_hash = {
87996 + .next = NULL,
87997 + .name = "nfs_readdata_alloc",
87998 + .file = "include/linux/nfs_fs.h",
87999 + .param1 = 1,
88000 +};
88001 +
88002 +struct size_overflow_hash _000988_hash = {
88003 + .next = NULL,
88004 + .name = "nfs_readdir_make_qstr",
88005 + .file = "fs/nfs/dir.c",
88006 + .param3 = 1,
88007 +};
88008 +
88009 +struct size_overflow_hash _000989_hash = {
88010 + .next = NULL,
88011 + .name = "nfs_writedata_alloc",
88012 + .file = "include/linux/nfs_fs.h",
88013 + .param1 = 1,
88014 +};
88015 +
88016 +struct size_overflow_hash _000990_hash = {
88017 + .next = NULL,
88018 + .name = "nsm_create_handle",
88019 + .file = "fs/lockd/mon.c",
88020 + .param4 = 1,
88021 +};
88022 +
88023 +struct size_overflow_hash _000991_hash = {
88024 + .next = NULL,
88025 + .name = "ntfs_copy_from_user",
88026 + .file = "fs/ntfs/file.c",
88027 + .param3 = 1,
88028 + .param5 = 1,
88029 +};
88030 +
88031 +struct size_overflow_hash _000993_hash = {
88032 + .next = NULL,
88033 + .name = "__ntfs_copy_from_user_iovec_inatomic",
88034 + .file = "fs/ntfs/file.c",
88035 + .param3 = 1,
88036 + .param4 = 1,
88037 +};
88038 +
88039 +struct size_overflow_hash _000995_hash = {
88040 + .next = NULL,
88041 + .name = "__ntfs_malloc",
88042 + .file = "fs/ntfs/malloc.h",
88043 + .param1 = 1,
88044 +};
88045 +
88046 +struct size_overflow_hash _000996_hash = {
88047 + .next = NULL,
88048 + .name = "nvme_alloc_iod",
88049 + .file = "drivers/block/nvme.c",
88050 + .param1 = 1,
88051 +};
88052 +
88053 +struct size_overflow_hash _000997_hash = {
88054 + .next = NULL,
88055 + .name = "nvram_write",
88056 + .file = "drivers/char/nvram.c",
88057 + .param3 = 1,
88058 +};
88059 +
88060 +struct size_overflow_hash _000998_hash = {
88061 + .next = NULL,
88062 + .name = "o2hb_debug_read",
88063 + .file = "fs/ocfs2/cluster/heartbeat.c",
88064 + .param3 = 1,
88065 +};
88066 +
88067 +struct size_overflow_hash _000999_hash = {
88068 + .next = NULL,
88069 + .name = "o2net_debug_read",
88070 + .file = "fs/ocfs2/cluster/netdebug.c",
88071 + .param3 = 1,
88072 +};
88073 +
88074 +struct size_overflow_hash _001000_hash = {
88075 + .next = NULL,
88076 + .name = "o2net_send_message_vec",
88077 + .file = "fs/ocfs2/cluster/tcp.c",
88078 + .param4 = 1,
88079 +};
88080 +
88081 +struct size_overflow_hash _001001_hash = {
88082 + .next = NULL,
88083 + .name = "ocfs2_control_cfu",
88084 + .file = "fs/ocfs2/stack_user.c",
88085 + .param2 = 1,
88086 +};
88087 +
88088 +struct size_overflow_hash _001002_hash = {
88089 + .next = NULL,
88090 + .name = "ocfs2_control_read",
88091 + .file = "fs/ocfs2/stack_user.c",
88092 + .param3 = 1,
88093 +};
88094 +
88095 +struct size_overflow_hash _001003_hash = {
88096 + .next = NULL,
88097 + .name = "ocfs2_debug_read",
88098 + .file = "fs/ocfs2/super.c",
88099 + .param3 = 1,
88100 +};
88101 +
88102 +struct size_overflow_hash _001004_hash = {
88103 + .next = NULL,
88104 + .name = "opera1_xilinx_rw",
88105 + .file = "drivers/media/dvb/dvb-usb/opera1.c",
88106 + .param5 = 1,
88107 +};
88108 +
88109 +struct size_overflow_hash _001005_hash = {
88110 + .next = NULL,
88111 + .name = "oprofilefs_str_to_user",
88112 + .file = "include/linux/oprofile.h",
88113 + .param3 = 1,
88114 +};
88115 +
88116 +struct size_overflow_hash _001006_hash = {
88117 + .next = NULL,
88118 + .name = "oprofilefs_ulong_from_user",
88119 + .file = "include/linux/oprofile.h",
88120 + .param3 = 1,
88121 +};
88122 +
88123 +struct size_overflow_hash _001007_hash = {
88124 + .next = &_000626_hash,
88125 + .name = "oprofilefs_ulong_to_user",
88126 + .file = "include/linux/oprofile.h",
88127 + .param3 = 1,
88128 +};
88129 +
88130 +struct size_overflow_hash _001008_hash = {
88131 + .next = NULL,
88132 + .name = "_ore_get_io_state",
88133 + .file = "fs/exofs/ore.c",
88134 + .param3 = 1,
88135 +};
88136 +
88137 +struct size_overflow_hash _001009_hash = {
88138 + .next = NULL,
88139 + .name = "_osd_realloc_seg",
88140 + .file = "drivers/scsi/osd/osd_initiator.c",
88141 + .param3 = 1,
88142 +};
88143 +
88144 +struct size_overflow_hash _001010_hash = {
88145 + .next = NULL,
88146 + .name = "_osd_req_list_objects",
88147 + .file = "drivers/scsi/osd/osd_initiator.c",
88148 + .param6 = 1,
88149 +};
88150 +
88151 +struct size_overflow_hash _001011_hash = {
88152 + .next = NULL,
88153 + .name = "osd_req_read_kern",
88154 + .file = "include/scsi/osd_initiator.h",
88155 + .param5 = 1,
88156 +};
88157 +
88158 +struct size_overflow_hash _001012_hash = {
88159 + .next = NULL,
88160 + .name = "osd_req_write_kern",
88161 + .file = "include/scsi/osd_initiator.h",
88162 + .param5 = 1,
88163 +};
88164 +
88165 +struct size_overflow_hash _001013_hash = {
88166 + .next = NULL,
88167 + .name = "osst_execute",
88168 + .file = "drivers/scsi/osst.c",
88169 + .param6 = 1,
88170 +};
88171 +
88172 +struct size_overflow_hash _001014_hash = {
88173 + .next = NULL,
88174 + .name = "otp_read",
88175 + .file = "drivers/mtd/devices/mtd_dataflash.c",
88176 + .param2 = 1,
88177 + .param5 = 1,
88178 +};
88179 +
88180 +struct size_overflow_hash _001016_hash = {
88181 + .next = NULL,
88182 + .name = "packet_buffer_init",
88183 + .file = "drivers/firewire/nosy.c",
88184 + .param2 = 1,
88185 +};
88186 +
88187 +struct size_overflow_hash _001017_hash = {
88188 + .next = NULL,
88189 + .name = "packet_setsockopt",
88190 + .file = "net/packet/af_packet.c",
88191 + .param5 = 1,
88192 +};
88193 +
88194 +struct size_overflow_hash _001018_hash = {
88195 + .next = NULL,
88196 + .name = "parse_arg",
88197 + .file = "drivers/platform/x86/asus_acpi.c",
88198 + .param2 = 1,
88199 +};
88200 +
88201 +struct size_overflow_hash _001019_hash = {
88202 + .next = NULL,
88203 + .name = "parse_command",
88204 + .file = "fs/binfmt_misc.c",
88205 + .param2 = 1,
88206 +};
88207 +
88208 +struct size_overflow_hash _001020_hash = {
88209 + .next = NULL,
88210 + .name = "pcmcia_replace_cis",
88211 + .file = "drivers/pcmcia/cistpl.c",
88212 + .param3 = 1,
88213 +};
88214 +
88215 +struct size_overflow_hash _001021_hash = {
88216 + .next = NULL,
88217 + .name = "pcnet32_realloc_rx_ring",
88218 + .file = "drivers/net/ethernet/amd/pcnet32.c",
88219 + .param3 = 1,
88220 +};
88221 +
88222 +struct size_overflow_hash _001022_hash = {
88223 + .next = NULL,
88224 + .name = "pcnet32_realloc_tx_ring",
88225 + .file = "drivers/net/ethernet/amd/pcnet32.c",
88226 + .param3 = 1,
88227 +};
88228 +
88229 +struct size_overflow_hash _001023_hash = {
88230 + .next = NULL,
88231 + .name = "pgctrl_write",
88232 + .file = "net/core/pktgen.c",
88233 + .param3 = 1,
88234 +};
88235 +
88236 +struct size_overflow_hash _001024_hash = {
88237 + .next = NULL,
88238 + .name = "pg_read",
88239 + .file = "drivers/block/paride/pg.c",
88240 + .param3 = 1,
88241 +};
88242 +
88243 +struct size_overflow_hash _001025_hash = {
88244 + .next = NULL,
88245 + .name = "pg_write",
88246 + .file = "drivers/block/paride/pg.c",
88247 + .param3 = 1,
88248 +};
88249 +
88250 +struct size_overflow_hash _001026_hash = {
88251 + .next = NULL,
88252 + .name = "picolcd_debug_eeprom_read",
88253 + .file = "drivers/hid/hid-picolcd.c",
88254 + .param3 = 1,
88255 +};
88256 +
88257 +struct size_overflow_hash _001027_hash = {
88258 + .next = NULL,
88259 + .name = "pkt_add",
88260 + .file = "drivers/usb/serial/garmin_gps.c",
88261 + .param3 = 1,
88262 +};
88263 +
88264 +struct size_overflow_hash _001028_hash = {
88265 + .next = NULL,
88266 + .name = "pktgen_if_write",
88267 + .file = "net/core/pktgen.c",
88268 + .param3 = 1,
88269 +};
88270 +
88271 +struct size_overflow_hash _001029_hash = {
88272 + .next = NULL,
88273 + .name = "platform_list_read_file",
88274 + .file = "sound/soc/soc-core.c",
88275 + .param3 = 1,
88276 +};
88277 +
88278 +struct size_overflow_hash _001030_hash = {
88279 + .next = NULL,
88280 + .name = "pm8001_store_update_fw",
88281 + .file = "drivers/scsi/pm8001/pm8001_ctl.c",
88282 + .param4 = 1,
88283 +};
88284 +
88285 +struct size_overflow_hash _001031_hash = {
88286 + .next = NULL,
88287 + .name = "port_show_regs",
88288 + .file = "drivers/tty/serial/mfd.c",
88289 + .param3 = 1,
88290 +};
88291 +
88292 +struct size_overflow_hash _001032_hash = {
88293 + .next = NULL,
88294 + .name = "ppp_cp_parse_cr",
88295 + .file = "drivers/net/wan/hdlc_ppp.c",
88296 + .param4 = 1,
88297 +};
88298 +
88299 +struct size_overflow_hash _001033_hash = {
88300 + .next = NULL,
88301 + .name = "ppp_write",
88302 + .file = "drivers/net/ppp/ppp_generic.c",
88303 + .param3 = 1,
88304 +};
88305 +
88306 +struct size_overflow_hash _001034_hash = {
88307 + .next = NULL,
88308 + .name = "pp_read",
88309 + .file = "drivers/char/ppdev.c",
88310 + .param3 = 1,
88311 +};
88312 +
88313 +struct size_overflow_hash _001035_hash = {
88314 + .next = NULL,
88315 + .name = "pp_write",
88316 + .file = "drivers/char/ppdev.c",
88317 + .param3 = 1,
88318 +};
88319 +
88320 +struct size_overflow_hash _001036_hash = {
88321 + .next = NULL,
88322 + .name = "printer_read",
88323 + .file = "drivers/usb/gadget/printer.c",
88324 + .param3 = 1,
88325 +};
88326 +
88327 +struct size_overflow_hash _001037_hash = {
88328 + .next = NULL,
88329 + .name = "printer_req_alloc",
88330 + .file = "drivers/usb/gadget/printer.c",
88331 + .param2 = 1,
88332 +};
88333 +
88334 +struct size_overflow_hash _001038_hash = {
88335 + .next = NULL,
88336 + .name = "printer_write",
88337 + .file = "drivers/usb/gadget/printer.c",
88338 + .param3 = 1,
88339 +};
88340 +
88341 +struct size_overflow_hash _001039_hash = {
88342 + .next = NULL,
88343 + .name = "prism2_set_genericelement",
88344 + .file = "drivers/net/wireless/hostap/hostap_ioctl.c",
88345 + .param3 = 1,
88346 +};
88347 +
88348 +struct size_overflow_hash _001040_hash = {
88349 + .next = NULL,
88350 + .name = "proc_read",
88351 + .file = "drivers/net/wireless/airo.c",
88352 + .param3 = 1,
88353 +};
88354 +
88355 +struct size_overflow_hash _001041_hash = {
88356 + .next = NULL,
88357 + .name = "proc_scsi_devinfo_write",
88358 + .file = "drivers/scsi/scsi_devinfo.c",
88359 + .param3 = 1,
88360 +};
88361 +
88362 +struct size_overflow_hash _001042_hash = {
88363 + .next = NULL,
88364 + .name = "proc_scsi_write",
88365 + .file = "drivers/scsi/scsi_proc.c",
88366 + .param3 = 1,
88367 +};
88368 +
88369 +struct size_overflow_hash _001043_hash = {
88370 + .next = NULL,
88371 + .name = "proc_scsi_write_proc",
88372 + .file = "drivers/scsi/scsi_proc.c",
88373 + .param3 = 1,
88374 +};
88375 +
88376 +struct size_overflow_hash _001044_hash = {
88377 + .next = NULL,
88378 + .name = "proc_write",
88379 + .file = "drivers/net/wireless/airo.c",
88380 + .param3 = 1,
88381 +};
88382 +
88383 +struct size_overflow_hash _001045_hash = {
88384 + .next = NULL,
88385 + .name = "provide_user_output",
88386 + .file = "fs/ubifs/debug.c",
88387 + .param3 = 1,
88388 +};
88389 +
88390 +struct size_overflow_hash _001046_hash = {
88391 + .next = NULL,
88392 + .name = "ps_pspoll_max_apturn_read",
88393 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88394 + .param3 = 1,
88395 +};
88396 +
88397 +struct size_overflow_hash _001047_hash = {
88398 + .next = NULL,
88399 + .name = "ps_pspoll_timeouts_read",
88400 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88401 + .param3 = 1,
88402 +};
88403 +
88404 +struct size_overflow_hash _001048_hash = {
88405 + .next = NULL,
88406 + .name = "ps_pspoll_utilization_read",
88407 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88408 + .param3 = 1,
88409 +};
88410 +
88411 +struct size_overflow_hash _001049_hash = {
88412 + .next = NULL,
88413 + .name = "ps_upsd_max_apturn_read",
88414 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88415 + .param3 = 1,
88416 +};
88417 +
88418 +struct size_overflow_hash _001050_hash = {
88419 + .next = NULL,
88420 + .name = "ps_upsd_max_sptime_read",
88421 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88422 + .param3 = 1,
88423 +};
88424 +
88425 +struct size_overflow_hash _001051_hash = {
88426 + .next = NULL,
88427 + .name = "ps_upsd_timeouts_read",
88428 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88429 + .param3 = 1,
88430 +};
88431 +
88432 +struct size_overflow_hash _001052_hash = {
88433 + .next = NULL,
88434 + .name = "ps_upsd_utilization_read",
88435 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88436 + .param3 = 1,
88437 +};
88438 +
88439 +struct size_overflow_hash _001053_hash = {
88440 + .next = NULL,
88441 + .name = "pti_char_write",
88442 + .file = "drivers/misc/pti.c",
88443 + .param3 = 1,
88444 +};
88445 +
88446 +struct size_overflow_hash _001054_hash = {
88447 + .next = NULL,
88448 + .name = "pt_read",
88449 + .file = "drivers/block/paride/pt.c",
88450 + .param3 = 1,
88451 +};
88452 +
88453 +struct size_overflow_hash _001055_hash = {
88454 + .next = NULL,
88455 + .name = "pt_write",
88456 + .file = "drivers/block/paride/pt.c",
88457 + .param3 = 1,
88458 +};
88459 +
88460 +struct size_overflow_hash _001056_hash = {
88461 + .next = NULL,
88462 + .name = "pvr2_ioread_read",
88463 + .file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
88464 + .param3 = 1,
88465 +};
88466 +
88467 +struct size_overflow_hash _001057_hash = {
88468 + .next = NULL,
88469 + .name = "pvr2_ioread_set_sync_key",
88470 + .file = "drivers/media/video/pvrusb2/pvrusb2-ioread.c",
88471 + .param3 = 1,
88472 +};
88473 +
88474 +struct size_overflow_hash _001058_hash = {
88475 + .next = NULL,
88476 + .name = "pvr2_stream_buffer_count",
88477 + .file = "drivers/media/video/pvrusb2/pvrusb2-io.c",
88478 + .param2 = 1,
88479 +};
88480 +
88481 +struct size_overflow_hash _001059_hash = {
88482 + .next = NULL,
88483 + .name = "pwr_disable_ps_read",
88484 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88485 + .param3 = 1,
88486 +};
88487 +
88488 +struct size_overflow_hash _001060_hash = {
88489 + .next = NULL,
88490 + .name = "pwr_elp_enter_read",
88491 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88492 + .param3 = 1,
88493 +};
88494 +
88495 +struct size_overflow_hash _001061_hash = {
88496 + .next = NULL,
88497 + .name = "pwr_enable_ps_read",
88498 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88499 + .param3 = 1,
88500 +};
88501 +
88502 +struct size_overflow_hash _001062_hash = {
88503 + .next = NULL,
88504 + .name = "pwr_fix_tsf_ps_read",
88505 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88506 + .param3 = 1,
88507 +};
88508 +
88509 +struct size_overflow_hash _001063_hash = {
88510 + .next = NULL,
88511 + .name = "pwr_missing_bcns_read",
88512 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88513 + .param3 = 1,
88514 +};
88515 +
88516 +struct size_overflow_hash _001064_hash = {
88517 + .next = NULL,
88518 + .name = "pwr_power_save_off_read",
88519 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88520 + .param3 = 1,
88521 +};
88522 +
88523 +struct size_overflow_hash _001065_hash = {
88524 + .next = NULL,
88525 + .name = "pwr_ps_enter_read",
88526 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88527 + .param3 = 1,
88528 +};
88529 +
88530 +struct size_overflow_hash _001066_hash = {
88531 + .next = NULL,
88532 + .name = "pwr_rcvd_awake_beacons_read",
88533 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88534 + .param3 = 1,
88535 +};
88536 +
88537 +struct size_overflow_hash _001067_hash = {
88538 + .next = NULL,
88539 + .name = "pwr_rcvd_beacons_read",
88540 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88541 + .param3 = 1,
88542 +};
88543 +
88544 +struct size_overflow_hash _001068_hash = {
88545 + .next = NULL,
88546 + .name = "pwr_tx_without_ps_read",
88547 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88548 + .param3 = 1,
88549 +};
88550 +
88551 +struct size_overflow_hash _001069_hash = {
88552 + .next = NULL,
88553 + .name = "pwr_tx_with_ps_read",
88554 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88555 + .param3 = 1,
88556 +};
88557 +
88558 +struct size_overflow_hash _001070_hash = {
88559 + .next = NULL,
88560 + .name = "pwr_wake_on_host_read",
88561 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88562 + .param3 = 1,
88563 +};
88564 +
88565 +struct size_overflow_hash _001071_hash = {
88566 + .next = NULL,
88567 + .name = "pwr_wake_on_timer_exp_read",
88568 + .file = "drivers/net/wireless/wl1251/debugfs.c",
88569 + .param3 = 1,
88570 +};
88571 +
88572 +struct size_overflow_hash _001072_hash = {
88573 + .next = NULL,
88574 + .name = "qc_capture",
88575 + .file = "drivers/media/video/c-qcam.c",
88576 + .param3 = 1,
88577 +};
88578 +
88579 +struct size_overflow_hash _001073_hash = {
88580 + .next = NULL,
88581 + .name = "qla2x00_get_ctx_bsg_sp",
88582 + .file = "drivers/scsi/qla2xxx/qla_bsg.c",
88583 + .param3 = 1,
88584 +};
88585 +
88586 +struct size_overflow_hash _001074_hash = {
88587 + .next = NULL,
88588 + .name = "qla2x00_get_ctx_sp",
88589 + .file = "drivers/scsi/qla2xxx/qla_init.c",
88590 + .param3 = 1,
88591 +};
88592 +
88593 +struct size_overflow_hash _001075_hash = {
88594 + .next = NULL,
88595 + .name = "qlcnic_alloc_msix_entries",
88596 + .file = "drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c",
88597 + .param2 = 1,
88598 +};
88599 +
88600 +struct size_overflow_hash _001076_hash = {
88601 + .next = NULL,
88602 + .name = "queues_read",
88603 + .file = "net/mac80211/debugfs.c",
88604 + .param3 = 1,
88605 +};
88606 +
88607 +struct size_overflow_hash _001077_hash = {
88608 + .next = NULL,
88609 + .name = "r3964_write",
88610 + .file = "drivers/tty/n_r3964.c",
88611 + .param4 = 1,
88612 +};
88613 +
88614 +struct size_overflow_hash _001078_hash = {
88615 + .next = NULL,
88616 + .name = "raw_setsockopt",
88617 + .file = "net/can/raw.c",
88618 + .param5 = 1,
88619 +};
88620 +
88621 +struct size_overflow_hash _001079_hash = {
88622 + .next = NULL,
88623 + .name = "ray_cs_essid_proc_write",
88624 + .file = "drivers/net/wireless/ray_cs.c",
88625 + .param3 = 1,
88626 +};
88627 +
88628 +struct size_overflow_hash _001080_hash = {
88629 + .next = NULL,
88630 + .name = "rbd_snap_add",
88631 + .file = "drivers/block/rbd.c",
88632 + .param4 = 1,
88633 +};
88634 +
88635 +struct size_overflow_hash _001081_hash = {
88636 + .next = NULL,
88637 + .name = "rcname_read",
88638 + .file = "net/mac80211/rate.c",
88639 + .param3 = 1,
88640 +};
88641 +
88642 +struct size_overflow_hash _001082_hash = {
88643 + .next = NULL,
88644 + .name = "rds_message_alloc",
88645 + .file = "net/rds/message.c",
88646 + .param1 = 1,
88647 +};
88648 +
88649 +struct size_overflow_hash _001083_hash = {
88650 + .next = NULL,
88651 + .name = "rds_page_copy_user",
88652 + .file = "net/rds/page.c",
88653 + .param4 = 1,
88654 +};
88655 +
88656 +struct size_overflow_hash _001084_hash = {
88657 + .next = NULL,
88658 + .name = "read",
88659 + .file = "drivers/pci/hotplug/cpqphp_sysfs.c",
88660 + .param3 = 1,
88661 +};
88662 +
88663 +struct size_overflow_hash _001085_hash = {
88664 + .next = NULL,
88665 + .name = "read_4k_modal_eeprom",
88666 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88667 + .param3 = 1,
88668 +};
88669 +
88670 +struct size_overflow_hash _001086_hash = {
88671 + .next = NULL,
88672 + .name = "read_9287_modal_eeprom",
88673 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88674 + .param3 = 1,
88675 +};
88676 +
88677 +struct size_overflow_hash _001087_hash = {
88678 + .next = NULL,
88679 + .name = "read_buf",
88680 + .file = "fs/nfsd/nfs4xdr.c",
88681 + .param2 = 1,
88682 +};
88683 +
88684 +struct size_overflow_hash _001088_hash = {
88685 + .next = NULL,
88686 + .name = "read_cis_cache",
88687 + .file = "drivers/pcmcia/cistpl.c",
88688 + .param4 = 1,
88689 +};
88690 +
88691 +struct size_overflow_hash _001089_hash = {
88692 + .next = NULL,
88693 + .name = "read_def_modal_eeprom",
88694 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88695 + .param3 = 1,
88696 +};
88697 +
88698 +struct size_overflow_hash _001090_hash = {
88699 + .next = NULL,
88700 + .name = "read_file_ani",
88701 + .file = "drivers/net/wireless/ath/ath5k/debug.c",
88702 + .param3 = 1,
88703 +};
88704 +
88705 +struct size_overflow_hash _001091_hash = {
88706 + .next = NULL,
88707 + .name = "read_file_antenna",
88708 + .file = "drivers/net/wireless/ath/ath5k/debug.c",
88709 + .param3 = 1,
88710 +};
88711 +
88712 +struct size_overflow_hash _001092_hash = {
88713 + .next = NULL,
88714 + .name = "read_file_base_eeprom",
88715 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88716 + .param3 = 1,
88717 +};
88718 +
88719 +struct size_overflow_hash _001093_hash = {
88720 + .next = NULL,
88721 + .name = "read_file_base_eeprom",
88722 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88723 + .param3 = 1,
88724 +};
88725 +
88726 +struct size_overflow_hash _001094_hash = {
88727 + .next = NULL,
88728 + .name = "read_file_beacon",
88729 + .file = "drivers/net/wireless/ath/ath5k/debug.c",
88730 + .param3 = 1,
88731 +};
88732 +
88733 +struct size_overflow_hash _001095_hash = {
88734 + .next = NULL,
88735 + .name = "read_file_credit_dist_stats",
88736 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
88737 + .param3 = 1,
88738 +};
88739 +
88740 +struct size_overflow_hash _001096_hash = {
88741 + .next = NULL,
88742 + .name = "read_file_debug",
88743 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88744 + .param3 = 1,
88745 +};
88746 +
88747 +struct size_overflow_hash _001097_hash = {
88748 + .next = NULL,
88749 + .name = "read_file_debug",
88750 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88751 + .param3 = 1,
88752 +};
88753 +
88754 +struct size_overflow_hash _001098_hash = {
88755 + .next = NULL,
88756 + .name = "read_file_debug",
88757 + .file = "drivers/net/wireless/ath/ath5k/debug.c",
88758 + .param3 = 1,
88759 +};
88760 +
88761 +struct size_overflow_hash _001099_hash = {
88762 + .next = NULL,
88763 + .name = "read_file_disable_ani",
88764 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88765 + .param3 = 1,
88766 +};
88767 +
88768 +struct size_overflow_hash _001100_hash = {
88769 + .next = NULL,
88770 + .name = "read_file_dma",
88771 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88772 + .param3 = 1,
88773 +};
88774 +
88775 +struct size_overflow_hash _001101_hash = {
88776 + .next = NULL,
88777 + .name = "read_file_dump_nfcal",
88778 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88779 + .param3 = 1,
88780 +};
88781 +
88782 +struct size_overflow_hash _001102_hash = {
88783 + .next = NULL,
88784 + .name = "read_file_frameerrors",
88785 + .file = "drivers/net/wireless/ath/ath5k/debug.c",
88786 + .param3 = 1,
88787 +};
88788 +
88789 +struct size_overflow_hash _001103_hash = {
88790 + .next = NULL,
88791 + .name = "read_file_interrupt",
88792 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88793 + .param3 = 1,
88794 +};
88795 +
88796 +struct size_overflow_hash _001104_hash = {
88797 + .next = NULL,
88798 + .name = "read_file_misc",
88799 + .file = "drivers/net/wireless/ath/ath5k/debug.c",
88800 + .param3 = 1,
88801 +};
88802 +
88803 +struct size_overflow_hash _001105_hash = {
88804 + .next = NULL,
88805 + .name = "read_file_misc",
88806 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88807 + .param3 = 1,
88808 +};
88809 +
88810 +struct size_overflow_hash _001106_hash = {
88811 + .next = NULL,
88812 + .name = "read_file_modal_eeprom",
88813 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88814 + .param3 = 1,
88815 +};
88816 +
88817 +struct size_overflow_hash _001107_hash = {
88818 + .next = NULL,
88819 + .name = "read_file_queue",
88820 + .file = "drivers/net/wireless/ath/ath5k/debug.c",
88821 + .param3 = 1,
88822 +};
88823 +
88824 +struct size_overflow_hash _001108_hash = {
88825 + .next = NULL,
88826 + .name = "read_file_queue",
88827 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88828 + .param3 = 1,
88829 +};
88830 +
88831 +struct size_overflow_hash _001109_hash = {
88832 + .next = NULL,
88833 + .name = "read_file_rcstat",
88834 + .file = "drivers/net/wireless/ath/ath9k/rc.c",
88835 + .param3 = 1,
88836 +};
88837 +
88838 +struct size_overflow_hash _001110_hash = {
88839 + .next = NULL,
88840 + .name = "read_file_recv",
88841 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88842 + .param3 = 1,
88843 +};
88844 +
88845 +struct size_overflow_hash _001111_hash = {
88846 + .next = NULL,
88847 + .name = "read_file_recv",
88848 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88849 + .param3 = 1,
88850 +};
88851 +
88852 +struct size_overflow_hash _001112_hash = {
88853 + .next = NULL,
88854 + .name = "read_file_regidx",
88855 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88856 + .param3 = 1,
88857 +};
88858 +
88859 +struct size_overflow_hash _001113_hash = {
88860 + .next = &_001103_hash,
88861 + .name = "read_file_regval",
88862 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88863 + .param3 = 1,
88864 +};
88865 +
88866 +struct size_overflow_hash _001114_hash = {
88867 + .next = NULL,
88868 + .name = "read_file_rx_chainmask",
88869 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88870 + .param3 = 1,
88871 +};
88872 +
88873 +struct size_overflow_hash _001115_hash = {
88874 + .next = NULL,
88875 + .name = "read_file_slot",
88876 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88877 + .param3 = 1,
88878 +};
88879 +
88880 +struct size_overflow_hash _001116_hash = {
88881 + .next = NULL,
88882 + .name = "read_file_stations",
88883 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88884 + .param3 = 1,
88885 +};
88886 +
88887 +struct size_overflow_hash _001117_hash = {
88888 + .next = NULL,
88889 + .name = "read_file_tgt_int_stats",
88890 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88891 + .param3 = 1,
88892 +};
88893 +
88894 +struct size_overflow_hash _001118_hash = {
88895 + .next = NULL,
88896 + .name = "read_file_tgt_rx_stats",
88897 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88898 + .param3 = 1,
88899 +};
88900 +
88901 +struct size_overflow_hash _001119_hash = {
88902 + .next = NULL,
88903 + .name = "read_file_tgt_stats",
88904 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
88905 + .param3 = 1,
88906 +};
88907 +
88908 +struct size_overflow_hash _001120_hash = {
88909 + .next = NULL,
88910 + .name = "read_file_tgt_tx_stats",
88911 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88912 + .param3 = 1,
88913 +};
88914 +
88915 +struct size_overflow_hash _001121_hash = {
88916 + .next = NULL,
88917 + .name = "read_file_tx_chainmask",
88918 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88919 + .param3 = 1,
88920 +};
88921 +
88922 +struct size_overflow_hash _001122_hash = {
88923 + .next = NULL,
88924 + .name = "read_file_war_stats",
88925 + .file = "drivers/net/wireless/ath/ath6kl/debug.c",
88926 + .param3 = 1,
88927 +};
88928 +
88929 +struct size_overflow_hash _001123_hash = {
88930 + .next = NULL,
88931 + .name = "read_file_wiphy",
88932 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88933 + .param3 = 1,
88934 +};
88935 +
88936 +struct size_overflow_hash _001124_hash = {
88937 + .next = NULL,
88938 + .name = "read_file_xmit",
88939 + .file = "drivers/net/wireless/ath/ath9k/htc_drv_debug.c",
88940 + .param3 = 1,
88941 +};
88942 +
88943 +struct size_overflow_hash _001125_hash = {
88944 + .next = NULL,
88945 + .name = "read_file_xmit",
88946 + .file = "drivers/net/wireless/ath/ath9k/debug.c",
88947 + .param3 = 1,
88948 +};
88949 +
88950 +struct size_overflow_hash _001126_hash = {
88951 + .next = NULL,
88952 + .name = "read_flush",
88953 + .file = "net/sunrpc/cache.c",
88954 + .param3 = 1,
88955 +};
88956 +
88957 +struct size_overflow_hash _001127_hash = {
88958 + .next = NULL,
88959 + .name = "realloc_buffer",
88960 + .file = "drivers/scsi/device_handler/scsi_dh_alua.c",
88961 + .param2 = 1,
88962 +};
88963 +
88964 +struct size_overflow_hash _001128_hash = {
88965 + .next = NULL,
88966 + .name = "receive_DataRequest",
88967 + .file = "drivers/block/drbd/drbd_receiver.c",
88968 + .param3 = 1,
88969 +};
88970 +
88971 +struct size_overflow_hash _001129_hash = {
88972 + .next = NULL,
88973 + .name = "recent_mt_proc_write",
88974 + .file = "net/netfilter/xt_recent.c",
88975 + .param3 = 1,
88976 +};
88977 +
88978 +struct size_overflow_hash _001130_hash = {
88979 + .next = NULL,
88980 + .name = "redrat3_transmit_ir",
88981 + .file = "drivers/media/rc/redrat3.c",
88982 + .param3 = 1,
88983 +};
88984 +
88985 +struct size_overflow_hash _001131_hash = {
88986 + .next = NULL,
88987 + .name = "reg_w_buf",
88988 + .file = "drivers/media/video/gspca/t613.c",
88989 + .param3 = 1,
88990 +};
88991 +
88992 +struct size_overflow_hash _001132_hash = {
88993 + .next = NULL,
88994 + .name = "reg_w_ixbuf",
88995 + .file = "drivers/media/video/gspca/t613.c",
88996 + .param4 = 1,
88997 +};
88998 +
88999 +struct size_overflow_hash _001133_hash = {
89000 + .next = NULL,
89001 + .name = "reiserfs_allocate_list_bitmaps",
89002 + .file = "include/linux/reiserfs_fs.h",
89003 + .param3 = 1,
89004 +};
89005 +
89006 +struct size_overflow_hash _001134_hash = {
89007 + .next = NULL,
89008 + .name = "reiserfs_resize",
89009 + .file = "include/linux/reiserfs_fs_sb.h",
89010 + .param2 = 1,
89011 +};
89012 +
89013 +struct size_overflow_hash _001135_hash = {
89014 + .next = NULL,
89015 + .name = "remote_settings_file_write",
89016 + .file = "drivers/misc/ibmasm/ibmasmfs.c",
89017 + .param3 = 1,
89018 +};
89019 +
89020 +struct size_overflow_hash _001136_hash = {
89021 + .next = NULL,
89022 + .name = "_req_append_segment",
89023 + .file = "drivers/scsi/osd/osd_initiator.c",
89024 + .param2 = 1,
89025 +};
89026 +
89027 +struct size_overflow_hash _001137_hash = {
89028 + .next = NULL,
89029 + .name = "retry_count_read",
89030 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89031 + .param3 = 1,
89032 +};
89033 +
89034 +struct size_overflow_hash _001138_hash = {
89035 + .next = NULL,
89036 + .name = "revalidate",
89037 + .file = "drivers/block/aoe/aoechr.c",
89038 + .param2 = 1,
89039 +};
89040 +
89041 +struct size_overflow_hash _001139_hash = {
89042 + .next = NULL,
89043 + .name = "rfcomm_sock_setsockopt",
89044 + .file = "net/bluetooth/rfcomm/sock.c",
89045 + .param5 = 1,
89046 +};
89047 +
89048 +struct size_overflow_hash _001140_hash = {
89049 + .next = NULL,
89050 + .name = "rfkill_fop_read",
89051 + .file = "net/rfkill/core.c",
89052 + .param3 = 1,
89053 +};
89054 +
89055 +struct size_overflow_hash _001141_hash = {
89056 + .next = NULL,
89057 + .name = "rndis_add_response",
89058 + .file = "drivers/usb/gadget/rndis.c",
89059 + .param2 = 1,
89060 +};
89061 +
89062 +struct size_overflow_hash _001142_hash = {
89063 + .next = NULL,
89064 + .name = "rng_dev_read",
89065 + .file = "drivers/char/hw_random/core.c",
89066 + .param3 = 1,
89067 +};
89068 +
89069 +struct size_overflow_hash _001143_hash = {
89070 + .next = NULL,
89071 + .name = "roccat_common_receive",
89072 + .file = "drivers/hid/hid-roccat-common.c",
89073 + .param4 = 1,
89074 +};
89075 +
89076 +struct size_overflow_hash _001144_hash = {
89077 + .next = NULL,
89078 + .name = "roccat_common_send",
89079 + .file = "drivers/hid/hid-roccat-common.c",
89080 + .param4 = 1,
89081 +};
89082 +
89083 +struct size_overflow_hash _001145_hash = {
89084 + .next = NULL,
89085 + .name = "roccat_read",
89086 + .file = "drivers/hid/hid-roccat.c",
89087 + .param3 = 1,
89088 +};
89089 +
89090 +struct size_overflow_hash _001146_hash = {
89091 + .next = NULL,
89092 + .name = "rpc_malloc",
89093 + .file = "include/linux/sunrpc/sched.h",
89094 + .param2 = 1,
89095 +};
89096 +
89097 +struct size_overflow_hash _001147_hash = {
89098 + .next = NULL,
89099 + .name = "rs_sta_dbgfs_rate_scale_data_read",
89100 + .file = "drivers/net/wireless/iwlwifi/iwl-agn-rs.c",
89101 + .param3 = 1,
89102 +};
89103 +
89104 +struct size_overflow_hash _001148_hash = {
89105 + .next = NULL,
89106 + .name = "rs_sta_dbgfs_scale_table_read",
89107 + .file = "drivers/net/wireless/iwlwifi/iwl-agn-rs.c",
89108 + .param3 = 1,
89109 +};
89110 +
89111 +struct size_overflow_hash _001149_hash = {
89112 + .next = NULL,
89113 + .name = "rs_sta_dbgfs_stats_table_read",
89114 + .file = "drivers/net/wireless/iwlwifi/iwl-agn-rs.c",
89115 + .param3 = 1,
89116 +};
89117 +
89118 +struct size_overflow_hash _001150_hash = {
89119 + .next = NULL,
89120 + .name = "rt2x00debug_write_bbp",
89121 + .file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
89122 + .param3 = 1,
89123 +};
89124 +
89125 +struct size_overflow_hash _001151_hash = {
89126 + .next = NULL,
89127 + .name = "rt2x00debug_write_csr",
89128 + .file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
89129 + .param3 = 1,
89130 +};
89131 +
89132 +struct size_overflow_hash _001152_hash = {
89133 + .next = &_000808_hash,
89134 + .name = "rt2x00debug_write_eeprom",
89135 + .file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
89136 + .param3 = 1,
89137 +};
89138 +
89139 +struct size_overflow_hash _001153_hash = {
89140 + .next = NULL,
89141 + .name = "rt2x00debug_write_rf",
89142 + .file = "drivers/net/wireless/rt2x00/rt2x00debug.c",
89143 + .param3 = 1,
89144 +};
89145 +
89146 +struct size_overflow_hash _001154_hash = {
89147 + .next = NULL,
89148 + .name = "rts51x_read_mem",
89149 + .file = "drivers/usb/storage/realtek_cr.c",
89150 + .param4 = 1,
89151 +};
89152 +
89153 +struct size_overflow_hash _001155_hash = {
89154 + .next = NULL,
89155 + .name = "rts51x_write_mem",
89156 + .file = "drivers/usb/storage/realtek_cr.c",
89157 + .param4 = 1,
89158 +};
89159 +
89160 +struct size_overflow_hash _001156_hash = {
89161 + .next = NULL,
89162 + .name = "rts_threshold_read",
89163 + .file = "net/wireless/debugfs.c",
89164 + .param3 = 1,
89165 +};
89166 +
89167 +struct size_overflow_hash _001157_hash = {
89168 + .next = NULL,
89169 + .name = "rx_dropped_read",
89170 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89171 + .param3 = 1,
89172 +};
89173 +
89174 +struct size_overflow_hash _001158_hash = {
89175 + .next = NULL,
89176 + .name = "rx_fcs_err_read",
89177 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89178 + .param3 = 1,
89179 +};
89180 +
89181 +struct size_overflow_hash _001159_hash = {
89182 + .next = NULL,
89183 + .name = "rx_hdr_overflow_read",
89184 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89185 + .param3 = 1,
89186 +};
89187 +
89188 +struct size_overflow_hash _001160_hash = {
89189 + .next = NULL,
89190 + .name = "rx_hw_stuck_read",
89191 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89192 + .param3 = 1,
89193 +};
89194 +
89195 +struct size_overflow_hash _001161_hash = {
89196 + .next = NULL,
89197 + .name = "rx_out_of_mem_read",
89198 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89199 + .param3 = 1,
89200 +};
89201 +
89202 +struct size_overflow_hash _001162_hash = {
89203 + .next = NULL,
89204 + .name = "rx_path_reset_read",
89205 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89206 + .param3 = 1,
89207 +};
89208 +
89209 +struct size_overflow_hash _001163_hash = {
89210 + .next = NULL,
89211 + .name = "rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read",
89212 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89213 + .param3 = 1,
89214 +};
89215 +
89216 +struct size_overflow_hash _001164_hash = {
89217 + .next = NULL,
89218 + .name = "rxpipe_descr_host_int_trig_rx_data_read",
89219 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89220 + .param3 = 1,
89221 +};
89222 +
89223 +struct size_overflow_hash _001165_hash = {
89224 + .next = NULL,
89225 + .name = "rxpipe_missed_beacon_host_int_trig_rx_data_read",
89226 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89227 + .param3 = 1,
89228 +};
89229 +
89230 +struct size_overflow_hash _001166_hash = {
89231 + .next = NULL,
89232 + .name = "rxpipe_rx_prep_beacon_drop_read",
89233 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89234 + .param3 = 1,
89235 +};
89236 +
89237 +struct size_overflow_hash _001167_hash = {
89238 + .next = NULL,
89239 + .name = "rxpipe_tx_xfr_host_int_trig_rx_data_read",
89240 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89241 + .param3 = 1,
89242 +};
89243 +
89244 +struct size_overflow_hash _001168_hash = {
89245 + .next = NULL,
89246 + .name = "rx_reset_counter_read",
89247 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89248 + .param3 = 1,
89249 +};
89250 +
89251 +struct size_overflow_hash _001169_hash = {
89252 + .next = NULL,
89253 + .name = "rx_xfr_hint_trig_read",
89254 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89255 + .param3 = 1,
89256 +};
89257 +
89258 +struct size_overflow_hash _001170_hash = {
89259 + .next = NULL,
89260 + .name = "saa7164_buffer_alloc_user",
89261 + .file = "drivers/media/video/saa7164/saa7164-buffer.c",
89262 + .param2 = 1,
89263 +};
89264 +
89265 +struct size_overflow_hash _001171_hash = {
89266 + .next = NULL,
89267 + .name = "scsi_execute",
89268 + .file = "include/scsi/scsi_device.h",
89269 + .param5 = 1,
89270 +};
89271 +
89272 +struct size_overflow_hash _001172_hash = {
89273 + .next = NULL,
89274 + .name = "scsi_tgt_copy_sense",
89275 + .file = "drivers/scsi/scsi_tgt_lib.c",
89276 + .param3 = 1,
89277 +};
89278 +
89279 +struct size_overflow_hash _001173_hash = {
89280 + .next = NULL,
89281 + .name = "sctp_auth_create_key",
89282 + .file = "net/sctp/auth.c",
89283 + .param1 = 1,
89284 +};
89285 +
89286 +struct size_overflow_hash _001174_hash = {
89287 + .next = NULL,
89288 + .name = "sctp_make_abort_user",
89289 + .file = "include/net/sctp/sm.h",
89290 + .param3 = 1,
89291 +};
89292 +
89293 +struct size_overflow_hash _001175_hash = {
89294 + .next = NULL,
89295 + .name = "sctpprobe_read",
89296 + .file = "net/sctp/probe.c",
89297 + .param3 = 1,
89298 +};
89299 +
89300 +struct size_overflow_hash _001176_hash = {
89301 + .next = NULL,
89302 + .name = "sctp_setsockopt_active_key",
89303 + .file = "net/sctp/socket.c",
89304 + .param3 = 1,
89305 +};
89306 +
89307 +struct size_overflow_hash _001177_hash = {
89308 + .next = NULL,
89309 + .name = "sctp_setsockopt_adaptation_layer",
89310 + .file = "net/sctp/socket.c",
89311 + .param3 = 1,
89312 +};
89313 +
89314 +struct size_overflow_hash _001178_hash = {
89315 + .next = NULL,
89316 + .name = "sctp_setsockopt_associnfo",
89317 + .file = "net/sctp/socket.c",
89318 + .param3 = 1,
89319 +};
89320 +
89321 +struct size_overflow_hash _001179_hash = {
89322 + .next = NULL,
89323 + .name = "sctp_setsockopt_auth_chunk",
89324 + .file = "net/sctp/socket.c",
89325 + .param3 = 1,
89326 +};
89327 +
89328 +struct size_overflow_hash _001180_hash = {
89329 + .next = NULL,
89330 + .name = "sctp_setsockopt_auth_key",
89331 + .file = "net/sctp/socket.c",
89332 + .param3 = 1,
89333 +};
89334 +
89335 +struct size_overflow_hash _001181_hash = {
89336 + .next = NULL,
89337 + .name = "sctp_setsockopt_autoclose",
89338 + .file = "net/sctp/socket.c",
89339 + .param3 = 1,
89340 +};
89341 +
89342 +struct size_overflow_hash _001182_hash = {
89343 + .next = NULL,
89344 + .name = "sctp_setsockopt_context",
89345 + .file = "net/sctp/socket.c",
89346 + .param3 = 1,
89347 +};
89348 +
89349 +struct size_overflow_hash _001183_hash = {
89350 + .next = NULL,
89351 + .name = "sctp_setsockopt_default_send_param",
89352 + .file = "net/sctp/socket.c",
89353 + .param3 = 1,
89354 +};
89355 +
89356 +struct size_overflow_hash _001184_hash = {
89357 + .next = NULL,
89358 + .name = "sctp_setsockopt_delayed_ack",
89359 + .file = "net/sctp/socket.c",
89360 + .param3 = 1,
89361 +};
89362 +
89363 +struct size_overflow_hash _001185_hash = {
89364 + .next = NULL,
89365 + .name = "sctp_setsockopt_del_key",
89366 + .file = "net/sctp/socket.c",
89367 + .param3 = 1,
89368 +};
89369 +
89370 +struct size_overflow_hash _001186_hash = {
89371 + .next = NULL,
89372 + .name = "sctp_setsockopt_events",
89373 + .file = "net/sctp/socket.c",
89374 + .param3 = 1,
89375 +};
89376 +
89377 +struct size_overflow_hash _001187_hash = {
89378 + .next = NULL,
89379 + .name = "sctp_setsockopt_hmac_ident",
89380 + .file = "net/sctp/socket.c",
89381 + .param3 = 1,
89382 +};
89383 +
89384 +struct size_overflow_hash _001188_hash = {
89385 + .next = NULL,
89386 + .name = "sctp_setsockopt_initmsg",
89387 + .file = "net/sctp/socket.c",
89388 + .param3 = 1,
89389 +};
89390 +
89391 +struct size_overflow_hash _001189_hash = {
89392 + .next = NULL,
89393 + .name = "sctp_setsockopt_maxburst",
89394 + .file = "net/sctp/socket.c",
89395 + .param3 = 1,
89396 +};
89397 +
89398 +struct size_overflow_hash _001190_hash = {
89399 + .next = NULL,
89400 + .name = "sctp_setsockopt_maxseg",
89401 + .file = "net/sctp/socket.c",
89402 + .param3 = 1,
89403 +};
89404 +
89405 +struct size_overflow_hash _001191_hash = {
89406 + .next = NULL,
89407 + .name = "sctp_setsockopt_peer_addr_params",
89408 + .file = "net/sctp/socket.c",
89409 + .param3 = 1,
89410 +};
89411 +
89412 +struct size_overflow_hash _001192_hash = {
89413 + .next = NULL,
89414 + .name = "sctp_setsockopt_peer_primary_addr",
89415 + .file = "net/sctp/socket.c",
89416 + .param3 = 1,
89417 +};
89418 +
89419 +struct size_overflow_hash _001193_hash = {
89420 + .next = NULL,
89421 + .name = "sctp_setsockopt_rtoinfo",
89422 + .file = "net/sctp/socket.c",
89423 + .param3 = 1,
89424 +};
89425 +
89426 +struct size_overflow_hash _001194_hash = {
89427 + .next = NULL,
89428 + .name = "sctp_tsnmap_init",
89429 + .file = "include/net/sctp/tsnmap.h",
89430 + .param2 = 1,
89431 +};
89432 +
89433 +struct size_overflow_hash _001195_hash = {
89434 + .next = NULL,
89435 + .name = "send_control_msg",
89436 + .file = "drivers/media/video/zr364xx.c",
89437 + .param6 = 1,
89438 +};
89439 +
89440 +struct size_overflow_hash _001196_hash = {
89441 + .next = NULL,
89442 + .name = "set_aoe_iflist",
89443 + .file = "drivers/block/aoe/aoenet.c",
89444 + .param2 = 1,
89445 +};
89446 +
89447 +struct size_overflow_hash _001197_hash = {
89448 + .next = NULL,
89449 + .name = "set_registers",
89450 + .file = "drivers/net/usb/pegasus.c",
89451 + .param3 = 1,
89452 +};
89453 +
89454 +struct size_overflow_hash _001198_hash = {
89455 + .next = NULL,
89456 + .name = "setsockopt",
89457 + .file = "net/caif/caif_socket.c",
89458 + .param5 = 1,
89459 +};
89460 +
89461 +struct size_overflow_hash _001199_hash = {
89462 + .next = NULL,
89463 + .name = "setup_req",
89464 + .file = "drivers/usb/gadget/inode.c",
89465 + .param3 = 1,
89466 +};
89467 +
89468 +struct size_overflow_hash _001200_hash = {
89469 + .next = NULL,
89470 + .name = "sfq_alloc",
89471 + .file = "net/sched/sch_sfq.c",
89472 + .param1 = 1,
89473 +};
89474 +
89475 +struct size_overflow_hash _001201_hash = {
89476 + .next = NULL,
89477 + .name = "sgl_map_user_pages",
89478 + .file = "drivers/scsi/st.c",
89479 + .param2 = 1,
89480 +};
89481 +
89482 +struct size_overflow_hash _001202_hash = {
89483 + .next = NULL,
89484 + .name = "short_retry_limit_read",
89485 + .file = "net/wireless/debugfs.c",
89486 + .param3 = 1,
89487 +};
89488 +
89489 +struct size_overflow_hash _001203_hash = {
89490 + .next = NULL,
89491 + .name = "sm501_create_subdev",
89492 + .file = "drivers/mfd/sm501.c",
89493 + .param3 = 1,
89494 + .param4 = 1,
89495 +};
89496 +
89497 +struct size_overflow_hash _001205_hash = {
89498 + .next = NULL,
89499 + .name = "sn9c102_read",
89500 + .file = "drivers/media/video/sn9c102/sn9c102_core.c",
89501 + .param3 = 1,
89502 +};
89503 +
89504 +struct size_overflow_hash _001206_hash = {
89505 + .next = NULL,
89506 + .name = "snd_ac97_pcm_assign",
89507 + .file = "include/sound/ac97_codec.h",
89508 + .param2 = 1,
89509 +};
89510 +
89511 +struct size_overflow_hash _001207_hash = {
89512 + .next = NULL,
89513 + .name = "snd_ctl_elem_user_tlv",
89514 + .file = "sound/core/control.c",
89515 + .param3 = 1,
89516 +};
89517 +
89518 +struct size_overflow_hash _001208_hash = {
89519 + .next = NULL,
89520 + .name = "snd_emu10k1_fx8010_read",
89521 + .file = "sound/pci/emu10k1/emuproc.c",
89522 + .param5 = 1,
89523 +};
89524 +
89525 +struct size_overflow_hash _001209_hash = {
89526 + .next = NULL,
89527 + .name = "snd_es1938_capture_copy",
89528 + .file = "sound/pci/es1938.c",
89529 + .param5 = 1,
89530 +};
89531 +
89532 +struct size_overflow_hash _001210_hash = {
89533 + .next = NULL,
89534 + .name = "snd_gus_dram_peek",
89535 + .file = "sound/isa/gus/gus_dram.c",
89536 + .param4 = 1,
89537 +};
89538 +
89539 +struct size_overflow_hash _001211_hash = {
89540 + .next = NULL,
89541 + .name = "snd_gus_dram_poke",
89542 + .file = "sound/isa/gus/gus_dram.c",
89543 + .param4 = 1,
89544 +};
89545 +
89546 +struct size_overflow_hash _001212_hash = {
89547 + .next = NULL,
89548 + .name = "snd_hdsp_capture_copy",
89549 + .file = "sound/pci/rme9652/hdsp.c",
89550 + .param5 = 1,
89551 +};
89552 +
89553 +struct size_overflow_hash _001213_hash = {
89554 + .next = NULL,
89555 + .name = "snd_hdsp_playback_copy",
89556 + .file = "sound/pci/rme9652/hdsp.c",
89557 + .param5 = 1,
89558 +};
89559 +
89560 +struct size_overflow_hash _001214_hash = {
89561 + .next = NULL,
89562 + .name = "snd_info_entry_write",
89563 + .file = "sound/core/info.c",
89564 + .param3 = 1,
89565 +};
89566 +
89567 +struct size_overflow_hash _001215_hash = {
89568 + .next = NULL,
89569 + .name = "snd_opl4_mem_proc_read",
89570 + .file = "sound/drivers/opl4/opl4_proc.c",
89571 + .param5 = 1,
89572 +};
89573 +
89574 +struct size_overflow_hash _001216_hash = {
89575 + .next = NULL,
89576 + .name = "snd_opl4_mem_proc_write",
89577 + .file = "sound/drivers/opl4/opl4_proc.c",
89578 + .param5 = 1,
89579 +};
89580 +
89581 +struct size_overflow_hash _001217_hash = {
89582 + .next = NULL,
89583 + .name = "snd_pcm_aio_read",
89584 + .file = "sound/core/pcm_native.c",
89585 + .param3 = 1,
89586 +};
89587 +
89588 +struct size_overflow_hash _001218_hash = {
89589 + .next = NULL,
89590 + .name = "snd_pcm_aio_write",
89591 + .file = "sound/core/pcm_native.c",
89592 + .param3 = 1,
89593 +};
89594 +
89595 +struct size_overflow_hash _001219_hash = {
89596 + .next = NULL,
89597 + .name = "snd_pcm_alloc_vmalloc_buffer",
89598 + .file = "drivers/media/video/cx231xx/cx231xx-audio.c",
89599 + .param2 = 1,
89600 +};
89601 +
89602 +struct size_overflow_hash _001220_hash = {
89603 + .next = NULL,
89604 + .name = "snd_pcm_alloc_vmalloc_buffer",
89605 + .file = "drivers/media/video/cx18/cx18-alsa-pcm.c",
89606 + .param2 = 1,
89607 +};
89608 +
89609 +struct size_overflow_hash _001221_hash = {
89610 + .next = NULL,
89611 + .name = "snd_pcm_alloc_vmalloc_buffer",
89612 + .file = "drivers/media/video/em28xx/em28xx-audio.c",
89613 + .param2 = 1,
89614 +};
89615 +
89616 +struct size_overflow_hash _001222_hash = {
89617 + .next = NULL,
89618 + .name = "_snd_pcm_lib_alloc_vmalloc_buffer",
89619 + .file = "include/sound/pcm.h",
89620 + .param2 = 1,
89621 +};
89622 +
89623 +struct size_overflow_hash _001223_hash = {
89624 + .next = NULL,
89625 + .name = "snd_pcm_oss_read1",
89626 + .file = "sound/core/oss/pcm_oss.c",
89627 + .param3 = 1,
89628 +};
89629 +
89630 +struct size_overflow_hash _001224_hash = {
89631 + .next = NULL,
89632 + .name = "snd_pcm_oss_write1",
89633 + .file = "sound/core/oss/pcm_oss.c",
89634 + .param3 = 1,
89635 +};
89636 +
89637 +struct size_overflow_hash _001225_hash = {
89638 + .next = NULL,
89639 + .name = "snd_pcm_oss_write2",
89640 + .file = "sound/core/oss/pcm_oss.c",
89641 + .param3 = 1,
89642 +};
89643 +
89644 +struct size_overflow_hash _001226_hash = {
89645 + .next = NULL,
89646 + .name = "snd_pcm_plugin_build",
89647 + .file = "sound/core/oss/pcm_plugin.c",
89648 + .param5 = 1,
89649 +};
89650 +
89651 +struct size_overflow_hash _001227_hash = {
89652 + .next = NULL,
89653 + .name = "snd_rme9652_capture_copy",
89654 + .file = "sound/pci/rme9652/rme9652.c",
89655 + .param5 = 1,
89656 +};
89657 +
89658 +struct size_overflow_hash _001228_hash = {
89659 + .next = NULL,
89660 + .name = "snd_rme9652_playback_copy",
89661 + .file = "sound/pci/rme9652/rme9652.c",
89662 + .param5 = 1,
89663 +};
89664 +
89665 +struct size_overflow_hash _001229_hash = {
89666 + .next = NULL,
89667 + .name = "snd_soc_hw_bulk_write_raw",
89668 + .file = "sound/soc/soc-io.c",
89669 + .param4 = 1,
89670 +};
89671 +
89672 +struct size_overflow_hash _001230_hash = {
89673 + .next = NULL,
89674 + .name = "snd_usb_ctl_msg",
89675 + .file = "sound/usb/helper.c",
89676 + .param8 = 1,
89677 +};
89678 +
89679 +struct size_overflow_hash _001231_hash = {
89680 + .next = NULL,
89681 + .name = "_sp2d_alloc",
89682 + .file = "fs/exofs/ore_raid.c",
89683 + .param1 = 1,
89684 +};
89685 +
89686 +struct size_overflow_hash _001232_hash = {
89687 + .next = NULL,
89688 + .name = "spidev_message",
89689 + .file = "drivers/spi/spidev.c",
89690 + .param3 = 1,
89691 +};
89692 +
89693 +struct size_overflow_hash _001233_hash = {
89694 + .next = NULL,
89695 + .name = "spidev_write",
89696 + .file = "drivers/spi/spidev.c",
89697 + .param3 = 1,
89698 +};
89699 +
89700 +struct size_overflow_hash _001234_hash = {
89701 + .next = NULL,
89702 + .name = "spi_show_regs",
89703 + .file = "drivers/spi/spi-dw.c",
89704 + .param3 = 1,
89705 +};
89706 +
89707 +struct size_overflow_hash _001235_hash = {
89708 + .next = NULL,
89709 + .name = "srp_alloc_iu",
89710 + .file = "drivers/infiniband/ulp/srp/ib_srp.c",
89711 + .param2 = 1,
89712 +};
89713 +
89714 +struct size_overflow_hash _001236_hash = {
89715 + .next = NULL,
89716 + .name = "srp_iu_pool_alloc",
89717 + .file = "drivers/scsi/libsrp.c",
89718 + .param2 = 1,
89719 +};
89720 +
89721 +struct size_overflow_hash _001237_hash = {
89722 + .next = NULL,
89723 + .name = "srp_ring_alloc",
89724 + .file = "drivers/scsi/libsrp.c",
89725 + .param2 = 1,
89726 +};
89727 +
89728 +struct size_overflow_hash _001238_hash = {
89729 + .next = NULL,
89730 + .name = "sta_agg_status_read",
89731 + .file = "net/mac80211/debugfs_sta.c",
89732 + .param3 = 1,
89733 +};
89734 +
89735 +struct size_overflow_hash _001239_hash = {
89736 + .next = NULL,
89737 + .name = "sta_agg_status_write",
89738 + .file = "net/mac80211/debugfs_sta.c",
89739 + .param3 = 1,
89740 +};
89741 +
89742 +struct size_overflow_hash _001240_hash = {
89743 + .next = NULL,
89744 + .name = "sta_connected_time_read",
89745 + .file = "net/mac80211/debugfs_sta.c",
89746 + .param3 = 1,
89747 +};
89748 +
89749 +struct size_overflow_hash _001241_hash = {
89750 + .next = NULL,
89751 + .name = "sta_flags_read",
89752 + .file = "net/mac80211/debugfs_sta.c",
89753 + .param3 = 1,
89754 +};
89755 +
89756 +struct size_overflow_hash _001242_hash = {
89757 + .next = NULL,
89758 + .name = "sta_ht_capa_read",
89759 + .file = "net/mac80211/debugfs_sta.c",
89760 + .param3 = 1,
89761 +};
89762 +
89763 +struct size_overflow_hash _001243_hash = {
89764 + .next = NULL,
89765 + .name = "sta_last_seq_ctrl_read",
89766 + .file = "net/mac80211/debugfs_sta.c",
89767 + .param3 = 1,
89768 +};
89769 +
89770 +struct size_overflow_hash _001244_hash = {
89771 + .next = NULL,
89772 + .name = "sta_num_ps_buf_frames_read",
89773 + .file = "net/mac80211/debugfs_sta.c",
89774 + .param3 = 1,
89775 +};
89776 +
89777 +struct size_overflow_hash _001245_hash = {
89778 + .next = NULL,
89779 + .name = "stk_prepare_sio_buffers",
89780 + .file = "drivers/media/video/stk-webcam.c",
89781 + .param2 = 1,
89782 +};
89783 +
89784 +struct size_overflow_hash _001246_hash = {
89785 + .next = NULL,
89786 + .name = "store_iwmct_log_level",
89787 + .file = "drivers/misc/iwmc3200top/log.c",
89788 + .param4 = 1,
89789 +};
89790 +
89791 +struct size_overflow_hash _001247_hash = {
89792 + .next = NULL,
89793 + .name = "store_iwmct_log_level_fw",
89794 + .file = "drivers/misc/iwmc3200top/log.c",
89795 + .param4 = 1,
89796 +};
89797 +
89798 +struct size_overflow_hash _001248_hash = {
89799 + .next = NULL,
89800 + .name = "str_to_user",
89801 + .file = "drivers/input/evdev.c",
89802 + .param2 = 1,
89803 +};
89804 +
89805 +struct size_overflow_hash _001249_hash = {
89806 + .next = NULL,
89807 + .name = "svc_pool_map_alloc_arrays",
89808 + .file = "net/sunrpc/svc.c",
89809 + .param2 = 1,
89810 +};
89811 +
89812 +struct size_overflow_hash _001250_hash = {
89813 + .next = NULL,
89814 + .name = "svc_setsockopt",
89815 + .file = "net/atm/svc.c",
89816 + .param5 = 1,
89817 +};
89818 +
89819 +struct size_overflow_hash _001251_hash = {
89820 + .next = NULL,
89821 + .name = "t4_alloc_mem",
89822 + .file = "drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c",
89823 + .param1 = 1,
89824 +};
89825 +
89826 +struct size_overflow_hash _001252_hash = {
89827 + .next = NULL,
89828 + .name = "tda10048_writeregbulk",
89829 + .file = "drivers/media/dvb/frontends/tda10048.c",
89830 + .param4 = 1,
89831 +};
89832 +
89833 +struct size_overflow_hash _001253_hash = {
89834 + .next = NULL,
89835 + .name = "__team_options_register",
89836 + .file = "drivers/net/team/team.c",
89837 + .param3 = 1,
89838 +};
89839 +
89840 +struct size_overflow_hash _001254_hash = {
89841 + .next = NULL,
89842 + .name = "tifm_alloc_adapter",
89843 + .file = "include/linux/tifm.h",
89844 + .param1 = 1,
89845 +};
89846 +
89847 +struct size_overflow_hash _001255_hash = {
89848 + .next = NULL,
89849 + .name = "tipc_subseq_alloc",
89850 + .file = "net/tipc/name_table.c",
89851 + .param1 = 1,
89852 +};
89853 +
89854 +struct size_overflow_hash _001256_hash = {
89855 + .next = NULL,
89856 + .name = "tm6000_read_write_usb",
89857 + .file = "drivers/media/video/tm6000/tm6000-core.c",
89858 + .param7 = 1,
89859 +};
89860 +
89861 +struct size_overflow_hash _001257_hash = {
89862 + .next = NULL,
89863 + .name = "tower_write",
89864 + .file = "drivers/usb/misc/legousbtower.c",
89865 + .param3 = 1,
89866 +};
89867 +
89868 +struct size_overflow_hash _001258_hash = {
89869 + .next = NULL,
89870 + .name = "trusted_instantiate",
89871 + .file = "security/keys/trusted.c",
89872 + .param3 = 1,
89873 +};
89874 +
89875 +struct size_overflow_hash _001259_hash = {
89876 + .next = NULL,
89877 + .name = "trusted_update",
89878 + .file = "security/keys/trusted.c",
89879 + .param3 = 1,
89880 +};
89881 +
89882 +struct size_overflow_hash _001260_hash = {
89883 + .next = NULL,
89884 + .name = "TSS_rawhmac",
89885 + .file = "security/keys/trusted.c",
89886 + .param3 = 1,
89887 +};
89888 +
89889 +struct size_overflow_hash _001261_hash = {
89890 + .next = NULL,
89891 + .name = "tx_internal_desc_overflow_read",
89892 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89893 + .param3 = 1,
89894 +};
89895 +
89896 +struct size_overflow_hash _001262_hash = {
89897 + .next = NULL,
89898 + .name = "tx_queue_len_read",
89899 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89900 + .param3 = 1,
89901 +};
89902 +
89903 +struct size_overflow_hash _001263_hash = {
89904 + .next = NULL,
89905 + .name = "tx_queue_len_read",
89906 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
89907 + .param3 = 1,
89908 +};
89909 +
89910 +struct size_overflow_hash _001264_hash = {
89911 + .next = NULL,
89912 + .name = "tx_queue_status_read",
89913 + .file = "drivers/net/wireless/wl1251/debugfs.c",
89914 + .param3 = 1,
89915 +};
89916 +
89917 +struct size_overflow_hash _001265_hash = {
89918 + .next = NULL,
89919 + .name = "udf_alloc_i_data",
89920 + .file = "fs/udf/inode.c",
89921 + .param2 = 1,
89922 +};
89923 +
89924 +struct size_overflow_hash _001266_hash = {
89925 + .next = NULL,
89926 + .name = "udf_sb_alloc_partition_maps",
89927 + .file = "fs/udf/super.c",
89928 + .param2 = 1,
89929 +};
89930 +
89931 +struct size_overflow_hash _001267_hash = {
89932 + .next = NULL,
89933 + .name = "uea_idma_write",
89934 + .file = "drivers/usb/atm/ueagle-atm.c",
89935 + .param3 = 1,
89936 +};
89937 +
89938 +struct size_overflow_hash _001268_hash = {
89939 + .next = NULL,
89940 + .name = "uea_request",
89941 + .file = "drivers/usb/atm/ueagle-atm.c",
89942 + .param4 = 1,
89943 +};
89944 +
89945 +struct size_overflow_hash _001269_hash = {
89946 + .next = NULL,
89947 + .name = "uea_send_modem_cmd",
89948 + .file = "drivers/usb/atm/ueagle-atm.c",
89949 + .param3 = 1,
89950 +};
89951 +
89952 +struct size_overflow_hash _001270_hash = {
89953 + .next = NULL,
89954 + .name = "uhci_debug_read",
89955 + .file = "drivers/usb/host/uhci-debug.c",
89956 + .param3 = 1,
89957 +};
89958 +
89959 +struct size_overflow_hash _001271_hash = {
89960 + .next = NULL,
89961 + .name = "uio_read",
89962 + .file = "drivers/uio/uio.c",
89963 + .param3 = 1,
89964 +};
89965 +
89966 +struct size_overflow_hash _001272_hash = {
89967 + .next = NULL,
89968 + .name = "uio_write",
89969 + .file = "drivers/uio/uio.c",
89970 + .param3 = 1,
89971 +};
89972 +
89973 +struct size_overflow_hash _001273_hash = {
89974 + .next = NULL,
89975 + .name = "um_idi_write",
89976 + .file = "drivers/isdn/hardware/eicon/divasi.c",
89977 + .param3 = 1,
89978 +};
89979 +
89980 +struct size_overflow_hash _001274_hash = {
89981 + .next = NULL,
89982 + .name = "unlink_queued",
89983 + .file = "drivers/usb/misc/usbtest.c",
89984 + .param3 = 1,
89985 + .param4 = 1,
89986 +};
89987 +
89988 +struct size_overflow_hash _001275_hash = {
89989 + .next = NULL,
89990 + .name = "us122l_ctl_msg",
89991 + .file = "sound/usb/usx2y/us122l.c",
89992 + .param8 = 1,
89993 +};
89994 +
89995 +struct size_overflow_hash _001276_hash = {
89996 + .next = NULL,
89997 + .name = "usbdev_read",
89998 + .file = "drivers/usb/core/devio.c",
89999 + .param3 = 1,
90000 +};
90001 +
90002 +struct size_overflow_hash _001277_hash = {
90003 + .next = NULL,
90004 + .name = "usblp_read",
90005 + .file = "drivers/usb/class/usblp.c",
90006 + .param3 = 1,
90007 +};
90008 +
90009 +struct size_overflow_hash _001278_hash = {
90010 + .next = NULL,
90011 + .name = "usblp_write",
90012 + .file = "drivers/usb/class/usblp.c",
90013 + .param3 = 1,
90014 +};
90015 +
90016 +struct size_overflow_hash _001279_hash = {
90017 + .next = NULL,
90018 + .name = "usbtest_alloc_urb",
90019 + .file = "drivers/usb/misc/usbtest.c",
90020 + .param3 = 1,
90021 + .param5 = 1,
90022 +};
90023 +
90024 +struct size_overflow_hash _001281_hash = {
90025 + .next = NULL,
90026 + .name = "usbtmc_read",
90027 + .file = "drivers/usb/class/usbtmc.c",
90028 + .param3 = 1,
90029 +};
90030 +
90031 +struct size_overflow_hash _001282_hash = {
90032 + .next = NULL,
90033 + .name = "usbtmc_write",
90034 + .file = "drivers/usb/class/usbtmc.c",
90035 + .param3 = 1,
90036 +};
90037 +
90038 +struct size_overflow_hash _001283_hash = {
90039 + .next = NULL,
90040 + .name = "usbvision_v4l2_read",
90041 + .file = "drivers/media/video/usbvision/usbvision-video.c",
90042 + .param3 = 1,
90043 +};
90044 +
90045 +struct size_overflow_hash _001284_hash = {
90046 + .next = NULL,
90047 + .name = "uvc_alloc_buffers",
90048 + .file = "drivers/usb/gadget/uvc_queue.c",
90049 + .param2 = 1,
90050 +};
90051 +
90052 +struct size_overflow_hash _001285_hash = {
90053 + .next = NULL,
90054 + .name = "uvc_alloc_entity",
90055 + .file = "drivers/media/video/uvc/uvc_driver.c",
90056 + .param3 = 1,
90057 +};
90058 +
90059 +struct size_overflow_hash _001286_hash = {
90060 + .next = NULL,
90061 + .name = "uvc_debugfs_stats_read",
90062 + .file = "drivers/media/video/uvc/uvc_debugfs.c",
90063 + .param3 = 1,
90064 +};
90065 +
90066 +struct size_overflow_hash _001287_hash = {
90067 + .next = NULL,
90068 + .name = "uvc_simplify_fraction",
90069 + .file = "drivers/media/video/uvc/uvc_driver.c",
90070 + .param3 = 1,
90071 +};
90072 +
90073 +struct size_overflow_hash _001288_hash = {
90074 + .next = NULL,
90075 + .name = "uwb_rc_neh_grok_event",
90076 + .file = "drivers/uwb/neh.c",
90077 + .param3 = 1,
90078 +};
90079 +
90080 +struct size_overflow_hash _001289_hash = {
90081 + .next = NULL,
90082 + .name = "v4l2_event_subscribe",
90083 + .file = "include/media/v4l2-event.h",
90084 + .param3 = 1,
90085 +};
90086 +
90087 +struct size_overflow_hash _001290_hash = {
90088 + .next = NULL,
90089 + .name = "v4l_stk_read",
90090 + .file = "drivers/media/video/stk-webcam.c",
90091 + .param3 = 1,
90092 +};
90093 +
90094 +struct size_overflow_hash _001291_hash = {
90095 + .next = NULL,
90096 + .name = "__vb2_perform_fileio",
90097 + .file = "drivers/media/video/videobuf2-core.c",
90098 + .param3 = 1,
90099 +};
90100 +
90101 +struct size_overflow_hash _001292_hash = {
90102 + .next = NULL,
90103 + .name = "vdma_mem_alloc",
90104 + .file = "arch/x86/include/asm/floppy.h",
90105 + .param1 = 1,
90106 +};
90107 +
90108 +struct size_overflow_hash _001293_hash = {
90109 + .next = NULL,
90110 + .name = "vfd_write",
90111 + .file = "drivers/media/rc/imon.c",
90112 + .param3 = 1,
90113 +};
90114 +
90115 +struct size_overflow_hash _001294_hash = {
90116 + .next = NULL,
90117 + .name = "vhci_get_user",
90118 + .file = "drivers/bluetooth/hci_vhci.c",
90119 + .param3 = 1,
90120 +};
90121 +
90122 +struct size_overflow_hash _001295_hash = {
90123 + .next = NULL,
90124 + .name = "__vhost_add_used_n",
90125 + .file = "drivers/vhost/vhost.c",
90126 + .param3 = 1,
90127 +};
90128 +
90129 +struct size_overflow_hash _001296_hash = {
90130 + .next = NULL,
90131 + .name = "__videobuf_alloc_vb",
90132 + .file = "drivers/media/video/videobuf-dma-sg.c",
90133 + .param1 = 1,
90134 +};
90135 +
90136 +struct size_overflow_hash _001297_hash = {
90137 + .next = NULL,
90138 + .name = "__videobuf_alloc_vb",
90139 + .file = "drivers/media/video/videobuf-dma-contig.c",
90140 + .param1 = 1,
90141 +};
90142 +
90143 +struct size_overflow_hash _001298_hash = {
90144 + .next = NULL,
90145 + .name = "__videobuf_alloc_vb",
90146 + .file = "drivers/media/video/videobuf-vmalloc.c",
90147 + .param1 = 1,
90148 +};
90149 +
90150 +struct size_overflow_hash _001299_hash = {
90151 + .next = NULL,
90152 + .name = "__videobuf_copy_to_user",
90153 + .file = "drivers/media/video/videobuf-core.c",
90154 + .param4 = 1,
90155 +};
90156 +
90157 +struct size_overflow_hash _001300_hash = {
90158 + .next = NULL,
90159 + .name = "video_proc_write",
90160 + .file = "drivers/platform/x86/toshiba_acpi.c",
90161 + .param3 = 1,
90162 +};
90163 +
90164 +struct size_overflow_hash _001301_hash = {
90165 + .next = NULL,
90166 + .name = "vifs_state_read",
90167 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90168 + .param3 = 1,
90169 +};
90170 +
90171 +struct size_overflow_hash _001302_hash = {
90172 + .next = NULL,
90173 + .name = "vlsi_alloc_ring",
90174 + .file = "drivers/net/irda/vlsi_ir.c",
90175 + .param3 = 1,
90176 + .param4 = 1,
90177 +};
90178 +
90179 +struct size_overflow_hash _001304_hash = {
90180 + .next = NULL,
90181 + .name = "vol_cdev_direct_write",
90182 + .file = "drivers/mtd/ubi/cdev.c",
90183 + .param3 = 1,
90184 +};
90185 +
90186 +struct size_overflow_hash _001305_hash = {
90187 + .next = NULL,
90188 + .name = "vol_cdev_read",
90189 + .file = "drivers/mtd/ubi/cdev.c",
90190 + .param3 = 1,
90191 +};
90192 +
90193 +struct size_overflow_hash _001306_hash = {
90194 + .next = NULL,
90195 + .name = "vring_add_indirect",
90196 + .file = "drivers/virtio/virtio_ring.c",
90197 + .param3 = 1,
90198 + .param4 = 1,
90199 +};
90200 +
90201 +struct size_overflow_hash _001308_hash = {
90202 + .next = NULL,
90203 + .name = "vring_new_virtqueue",
90204 + .file = "include/linux/virtio_ring.h",
90205 + .param1 = 1,
90206 +};
90207 +
90208 +struct size_overflow_hash _001309_hash = {
90209 + .next = NULL,
90210 + .name = "__vxge_hw_channel_allocate",
90211 + .file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
90212 + .param3 = 1,
90213 +};
90214 +
90215 +struct size_overflow_hash _001310_hash = {
90216 + .next = NULL,
90217 + .name = "vxge_os_dma_malloc",
90218 + .file = "drivers/net/ethernet/neterion/vxge/vxge-config.h",
90219 + .param2 = 1,
90220 +};
90221 +
90222 +struct size_overflow_hash _001311_hash = {
90223 + .next = NULL,
90224 + .name = "vxge_os_dma_malloc_async",
90225 + .file = "drivers/net/ethernet/neterion/vxge/vxge-config.c",
90226 + .param3 = 1,
90227 +};
90228 +
90229 +struct size_overflow_hash _001312_hash = {
90230 + .next = NULL,
90231 + .name = "w9966_v4l_read",
90232 + .file = "drivers/media/video/w9966.c",
90233 + .param3 = 1,
90234 +};
90235 +
90236 +struct size_overflow_hash _001313_hash = {
90237 + .next = NULL,
90238 + .name = "waiters_read",
90239 + .file = "fs/dlm/debug_fs.c",
90240 + .param3 = 1,
90241 +};
90242 +
90243 +struct size_overflow_hash _001314_hash = {
90244 + .next = NULL,
90245 + .name = "wa_nep_queue",
90246 + .file = "drivers/usb/wusbcore/wa-nep.c",
90247 + .param2 = 1,
90248 +};
90249 +
90250 +struct size_overflow_hash _001315_hash = {
90251 + .next = NULL,
90252 + .name = "__wa_xfer_setup_segs",
90253 + .file = "drivers/usb/wusbcore/wa-xfer.c",
90254 + .param2 = 1,
90255 +};
90256 +
90257 +struct size_overflow_hash _001316_hash = {
90258 + .next = NULL,
90259 + .name = "wdm_read",
90260 + .file = "drivers/usb/class/cdc-wdm.c",
90261 + .param3 = 1,
90262 +};
90263 +
90264 +struct size_overflow_hash _001317_hash = {
90265 + .next = NULL,
90266 + .name = "wdm_write",
90267 + .file = "drivers/usb/class/cdc-wdm.c",
90268 + .param3 = 1,
90269 +};
90270 +
90271 +struct size_overflow_hash _001318_hash = {
90272 + .next = NULL,
90273 + .name = "wep_addr_key_count_read",
90274 + .file = "drivers/net/wireless/wl1251/debugfs.c",
90275 + .param3 = 1,
90276 +};
90277 +
90278 +struct size_overflow_hash _001319_hash = {
90279 + .next = &_000480_hash,
90280 + .name = "wep_decrypt_fail_read",
90281 + .file = "drivers/net/wireless/wl1251/debugfs.c",
90282 + .param3 = 1,
90283 +};
90284 +
90285 +struct size_overflow_hash _001320_hash = {
90286 + .next = NULL,
90287 + .name = "wep_default_key_count_read",
90288 + .file = "drivers/net/wireless/wl1251/debugfs.c",
90289 + .param3 = 1,
90290 +};
90291 +
90292 +struct size_overflow_hash _001321_hash = {
90293 + .next = NULL,
90294 + .name = "wep_interrupt_read",
90295 + .file = "drivers/net/wireless/wl1251/debugfs.c",
90296 + .param3 = 1,
90297 +};
90298 +
90299 +struct size_overflow_hash _001322_hash = {
90300 + .next = NULL,
90301 + .name = "wep_key_not_found_read",
90302 + .file = "drivers/net/wireless/wl1251/debugfs.c",
90303 + .param3 = 1,
90304 +};
90305 +
90306 +struct size_overflow_hash _001323_hash = {
90307 + .next = NULL,
90308 + .name = "wep_packets_read",
90309 + .file = "drivers/net/wireless/wl1251/debugfs.c",
90310 + .param3 = 1,
90311 +};
90312 +
90313 +struct size_overflow_hash _001324_hash = {
90314 + .next = NULL,
90315 + .name = "wiimote_hid_send",
90316 + .file = "drivers/hid/hid-wiimote-core.c",
90317 + .param3 = 1,
90318 +};
90319 +
90320 +struct size_overflow_hash _001325_hash = {
90321 + .next = NULL,
90322 + .name = "wl1271_format_buffer",
90323 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90324 + .param2 = 1,
90325 +};
90326 +
90327 +struct size_overflow_hash _001326_hash = {
90328 + .next = NULL,
90329 + .name = "wl1273_fm_fops_write",
90330 + .file = "drivers/media/radio/radio-wl1273.c",
90331 + .param3 = 1,
90332 +};
90333 +
90334 +struct size_overflow_hash _001327_hash = {
90335 + .next = NULL,
90336 + .name = "wlc_phy_loadsampletable_nphy",
90337 + .file = "drivers/net/wireless/brcm80211/brcmsmac/phy/phy_n.c",
90338 + .param3 = 1,
90339 +};
90340 +
90341 +struct size_overflow_hash _001328_hash = {
90342 + .next = NULL,
90343 + .name = "wpan_phy_alloc",
90344 + .file = "include/net/wpan-phy.h",
90345 + .param1 = 1,
90346 +};
90347 +
90348 +struct size_overflow_hash _001329_hash = {
90349 + .next = NULL,
90350 + .name = "write_flush",
90351 + .file = "net/sunrpc/cache.c",
90352 + .param3 = 1,
90353 +};
90354 +
90355 +struct size_overflow_hash _001330_hash = {
90356 + .next = NULL,
90357 + .name = "write_rio",
90358 + .file = "drivers/usb/misc/rio500.c",
90359 + .param3 = 1,
90360 +};
90361 +
90362 +struct size_overflow_hash _001331_hash = {
90363 + .next = NULL,
90364 + .name = "wusb_ccm_mac",
90365 + .file = "drivers/usb/wusbcore/crypto.c",
90366 + .param7 = 1,
90367 +};
90368 +
90369 +struct size_overflow_hash _001332_hash = {
90370 + .next = NULL,
90371 + .name = "xfs_attrmulti_attr_set",
90372 + .file = "fs/xfs/xfs_ioctl.c",
90373 + .param4 = 1,
90374 +};
90375 +
90376 +struct size_overflow_hash _001333_hash = {
90377 + .next = NULL,
90378 + .name = "xfs_handle_to_dentry",
90379 + .file = "fs/xfs/xfs_ioctl.c",
90380 + .param3 = 1,
90381 +};
90382 +
90383 +struct size_overflow_hash _001334_hash = {
90384 + .next = NULL,
90385 + .name = "xhci_alloc_stream_info",
90386 + .file = "drivers/usb/host/xhci-mem.c",
90387 + .param3 = 1,
90388 +};
90389 +
90390 +struct size_overflow_hash _001335_hash = {
90391 + .next = NULL,
90392 + .name = "xprt_alloc",
90393 + .file = "include/linux/sunrpc/xprt.h",
90394 + .param2 = 1,
90395 +};
90396 +
90397 +struct size_overflow_hash _001336_hash = {
90398 + .next = NULL,
90399 + .name = "xprt_rdma_allocate",
90400 + .file = "net/sunrpc/xprtrdma/transport.c",
90401 + .param2 = 1,
90402 +};
90403 +
90404 +struct size_overflow_hash _001337_hash = {
90405 + .next = NULL,
90406 + .name = "xt_alloc_table_info",
90407 + .file = "include/linux/netfilter/x_tables.h",
90408 + .param1 = 1,
90409 +};
90410 +
90411 +struct size_overflow_hash _001338_hash = {
90412 + .next = NULL,
90413 + .name = "zd_usb_iowrite16v_async",
90414 + .file = "drivers/net/wireless/zd1211rw/zd_usb.c",
90415 + .param3 = 1,
90416 +};
90417 +
90418 +struct size_overflow_hash _001339_hash = {
90419 + .next = NULL,
90420 + .name = "zd_usb_read_fw",
90421 + .file = "drivers/net/wireless/zd1211rw/zd_usb.c",
90422 + .param4 = 1,
90423 +};
90424 +
90425 +struct size_overflow_hash _001340_hash = {
90426 + .next = NULL,
90427 + .name = "zoran_write",
90428 + .file = "drivers/media/video/zoran/zoran_procfs.c",
90429 + .param3 = 1,
90430 +};
90431 +
90432 +struct size_overflow_hash _001341_hash = {
90433 + .next = NULL,
90434 + .name = "ad7879_spi_multi_read",
90435 + .file = "drivers/input/touchscreen/ad7879-spi.c",
90436 + .param3 = 1,
90437 +};
90438 +
90439 +struct size_overflow_hash _001342_hash = {
90440 + .next = NULL,
90441 + .name = "aes_decrypt_fail_read",
90442 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90443 + .param3 = 1,
90444 +};
90445 +
90446 +struct size_overflow_hash _001343_hash = {
90447 + .next = NULL,
90448 + .name = "aes_decrypt_interrupt_read",
90449 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90450 + .param3 = 1,
90451 +};
90452 +
90453 +struct size_overflow_hash _001344_hash = {
90454 + .next = NULL,
90455 + .name = "aes_decrypt_packets_read",
90456 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90457 + .param3 = 1,
90458 +};
90459 +
90460 +struct size_overflow_hash _001345_hash = {
90461 + .next = NULL,
90462 + .name = "aes_encrypt_fail_read",
90463 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90464 + .param3 = 1,
90465 +};
90466 +
90467 +struct size_overflow_hash _001346_hash = {
90468 + .next = NULL,
90469 + .name = "aes_encrypt_interrupt_read",
90470 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90471 + .param3 = 1,
90472 +};
90473 +
90474 +struct size_overflow_hash _001347_hash = {
90475 + .next = NULL,
90476 + .name = "aes_encrypt_packets_read",
90477 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90478 + .param3 = 1,
90479 +};
90480 +
90481 +struct size_overflow_hash _001348_hash = {
90482 + .next = NULL,
90483 + .name = "afs_cell_create",
90484 + .file = "fs/afs/cell.c",
90485 + .param2 = 1,
90486 +};
90487 +
90488 +struct size_overflow_hash _001349_hash = {
90489 + .next = NULL,
90490 + .name = "agp_create_user_memory",
90491 + .file = "drivers/char/agp/generic.c",
90492 + .param1 = 1,
90493 +};
90494 +
90495 +struct size_overflow_hash _001350_hash = {
90496 + .next = NULL,
90497 + .name = "alg_setsockopt",
90498 + .file = "crypto/af_alg.c",
90499 + .param5 = 1,
90500 +};
90501 +
90502 +struct size_overflow_hash _001351_hash = {
90503 + .next = NULL,
90504 + .name = "alloc_targets",
90505 + .file = "drivers/md/dm-table.c",
90506 + .param2 = 1,
90507 +};
90508 +
90509 +struct size_overflow_hash _001352_hash = {
90510 + .next = NULL,
90511 + .name = "aoechr_write",
90512 + .file = "drivers/block/aoe/aoechr.c",
90513 + .param3 = 1,
90514 +};
90515 +
90516 +struct size_overflow_hash _001353_hash = {
90517 + .next = NULL,
90518 + .name = "ath6kl_cfg80211_connect_event",
90519 + .file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
90520 + .param7 = 1,
90521 + .param9 = 1,
90522 + .param8 = 1,
90523 +};
90524 +
90525 +struct size_overflow_hash _001356_hash = {
90526 + .next = NULL,
90527 + .name = "ath6kl_mgmt_tx",
90528 + .file = "drivers/net/wireless/ath/ath6kl/cfg80211.c",
90529 + .param9 = 1,
90530 +};
90531 +
90532 +struct size_overflow_hash _001357_hash = {
90533 + .next = NULL,
90534 + .name = "atomic_read_file",
90535 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofilefs.c",
90536 + .param3 = 1,
90537 +};
90538 +
90539 +struct size_overflow_hash _001358_hash = {
90540 + .next = NULL,
90541 + .name = "beacon_interval_read",
90542 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90543 + .param3 = 1,
90544 +};
90545 +
90546 +struct size_overflow_hash _001359_hash = {
90547 + .next = NULL,
90548 + .name = "bm_entry_write",
90549 + .file = "fs/binfmt_misc.c",
90550 + .param3 = 1,
90551 +};
90552 +
90553 +struct size_overflow_hash _001360_hash = {
90554 + .next = NULL,
90555 + .name = "bm_init",
90556 + .file = "lib/ts_bm.c",
90557 + .param2 = 1,
90558 +};
90559 +
90560 +struct size_overflow_hash _001361_hash = {
90561 + .next = NULL,
90562 + .name = "bm_register_write",
90563 + .file = "fs/binfmt_misc.c",
90564 + .param3 = 1,
90565 +};
90566 +
90567 +struct size_overflow_hash _001362_hash = {
90568 + .next = NULL,
90569 + .name = "bm_status_write",
90570 + .file = "fs/binfmt_misc.c",
90571 + .param3 = 1,
90572 +};
90573 +
90574 +struct size_overflow_hash _001363_hash = {
90575 + .next = NULL,
90576 + .name = "brn_proc_write",
90577 + .file = "drivers/platform/x86/asus_acpi.c",
90578 + .param3 = 1,
90579 +};
90580 +
90581 +struct size_overflow_hash _001364_hash = {
90582 + .next = NULL,
90583 + .name = "btrfs_map_block",
90584 + .file = "fs/btrfs/volumes.c",
90585 + .param3 = 1,
90586 +};
90587 +
90588 +struct size_overflow_hash _001365_hash = {
90589 + .next = NULL,
90590 + .name = "cache_downcall",
90591 + .file = "net/sunrpc/cache.c",
90592 + .param3 = 1,
90593 +};
90594 +
90595 +struct size_overflow_hash _001366_hash = {
90596 + .next = NULL,
90597 + .name = "cache_slow_downcall",
90598 + .file = "net/sunrpc/cache.c",
90599 + .param2 = 1,
90600 +};
90601 +
90602 +struct size_overflow_hash _001367_hash = {
90603 + .next = NULL,
90604 + .name = "ceph_dns_resolve_name",
90605 + .file = "net/ceph/messenger.c",
90606 + .param1 = 1,
90607 +};
90608 +
90609 +struct size_overflow_hash _001368_hash = {
90610 + .next = NULL,
90611 + .name = "cfg80211_roamed",
90612 + .file = "include/net/cfg80211.h",
90613 + .param5 = 1,
90614 + .param7 = 1,
90615 +};
90616 +
90617 +struct size_overflow_hash _001370_hash = {
90618 + .next = NULL,
90619 + .name = "cifs_readv_from_socket",
90620 + .file = "fs/cifs/connect.c",
90621 + .param3 = 1,
90622 +};
90623 +
90624 +struct size_overflow_hash _001371_hash = {
90625 + .next = NULL,
90626 + .name = "configfs_write_file",
90627 + .file = "fs/configfs/file.c",
90628 + .param3 = 1,
90629 +};
90630 +
90631 +struct size_overflow_hash _001372_hash = {
90632 + .next = &_001370_hash,
90633 + .name = "cpu_type_read",
90634 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofile_files.c",
90635 + .param3 = 1,
90636 +};
90637 +
90638 +struct size_overflow_hash _001373_hash = {
90639 + .next = NULL,
90640 + .name = "cx18_copy_mdl_to_user",
90641 + .file = "drivers/media/video/cx18/cx18-fileops.c",
90642 + .param4 = 1,
90643 +};
90644 +
90645 +struct size_overflow_hash _001374_hash = {
90646 + .next = NULL,
90647 + .name = "cxgbi_ddp_reserve",
90648 + .file = "drivers/scsi/cxgbi/libcxgbi.c",
90649 + .param4 = 1,
90650 +};
90651 +
90652 +struct size_overflow_hash _001375_hash = {
90653 + .next = NULL,
90654 + .name = "cxgbi_device_portmap_create",
90655 + .file = "drivers/scsi/cxgbi/libcxgbi.c",
90656 + .param3 = 1,
90657 +};
90658 +
90659 +struct size_overflow_hash _001376_hash = {
90660 + .next = NULL,
90661 + .name = "datablob_hmac_append",
90662 + .file = "security/keys/encrypted-keys/encrypted.c",
90663 + .param3 = 1,
90664 +};
90665 +
90666 +struct size_overflow_hash _001377_hash = {
90667 + .next = NULL,
90668 + .name = "datablob_hmac_verify",
90669 + .file = "security/keys/encrypted-keys/encrypted.c",
90670 + .param4 = 1,
90671 +};
90672 +
90673 +struct size_overflow_hash _001378_hash = {
90674 + .next = NULL,
90675 + .name = "dataflash_read_fact_otp",
90676 + .file = "drivers/mtd/devices/mtd_dataflash.c",
90677 + .param3 = 1,
90678 +};
90679 +
90680 +struct size_overflow_hash _001379_hash = {
90681 + .next = NULL,
90682 + .name = "dataflash_read_user_otp",
90683 + .file = "drivers/mtd/devices/mtd_dataflash.c",
90684 + .param3 = 1,
90685 +};
90686 +
90687 +struct size_overflow_hash _001380_hash = {
90688 + .next = NULL,
90689 + .name = "depth_read",
90690 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofile_files.c",
90691 + .param3 = 1,
90692 +};
90693 +
90694 +struct size_overflow_hash _001381_hash = {
90695 + .next = NULL,
90696 + .name = "depth_write",
90697 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofile_files.c",
90698 + .param3 = 1,
90699 +};
90700 +
90701 +struct size_overflow_hash _001382_hash = {
90702 + .next = NULL,
90703 + .name = "dev_irnet_write",
90704 + .file = "net/irda/irnet/irnet_ppp.c",
90705 + .param3 = 1,
90706 +};
90707 +
90708 +struct size_overflow_hash _001383_hash = {
90709 + .next = NULL,
90710 + .name = "dev_write",
90711 + .file = "sound/oss/msnd_pinnacle.c",
90712 + .param3 = 1,
90713 +};
90714 +
90715 +struct size_overflow_hash _001384_hash = {
90716 + .next = NULL,
90717 + .name = "dfs_file_read",
90718 + .file = "fs/ubifs/debug.c",
90719 + .param3 = 1,
90720 +};
90721 +
90722 +struct size_overflow_hash _001385_hash = {
90723 + .next = NULL,
90724 + .name = "dfs_file_write",
90725 + .file = "fs/ubifs/debug.c",
90726 + .param3 = 1,
90727 +};
90728 +
90729 +struct size_overflow_hash _001386_hash = {
90730 + .next = NULL,
90731 + .name = "dfs_global_file_read",
90732 + .file = "fs/ubifs/debug.c",
90733 + .param3 = 1,
90734 +};
90735 +
90736 +struct size_overflow_hash _001387_hash = {
90737 + .next = NULL,
90738 + .name = "dfs_global_file_write",
90739 + .file = "fs/ubifs/debug.c",
90740 + .param3 = 1,
90741 +};
90742 +
90743 +struct size_overflow_hash _001388_hash = {
90744 + .next = NULL,
90745 + .name = "disconnect",
90746 + .file = "net/bluetooth/mgmt.c",
90747 + .param4 = 1,
90748 +};
90749 +
90750 +struct size_overflow_hash _001389_hash = {
90751 + .next = NULL,
90752 + .name = "disp_proc_write",
90753 + .file = "drivers/platform/x86/asus_acpi.c",
90754 + .param3 = 1,
90755 +};
90756 +
90757 +struct size_overflow_hash _001390_hash = {
90758 + .next = NULL,
90759 + .name = "dma_rx_errors_read",
90760 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90761 + .param3 = 1,
90762 +};
90763 +
90764 +struct size_overflow_hash _001391_hash = {
90765 + .next = NULL,
90766 + .name = "dma_rx_requested_read",
90767 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90768 + .param3 = 1,
90769 +};
90770 +
90771 +struct size_overflow_hash _001392_hash = {
90772 + .next = NULL,
90773 + .name = "dma_tx_errors_read",
90774 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90775 + .param3 = 1,
90776 +};
90777 +
90778 +struct size_overflow_hash _001393_hash = {
90779 + .next = NULL,
90780 + .name = "dma_tx_requested_read",
90781 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90782 + .param3 = 1,
90783 +};
90784 +
90785 +struct size_overflow_hash _001394_hash = {
90786 + .next = NULL,
90787 + .name = "dm_exception_table_init",
90788 + .file = "drivers/md/dm-snap.c",
90789 + .param2 = 1,
90790 +};
90791 +
90792 +struct size_overflow_hash _001395_hash = {
90793 + .next = NULL,
90794 + .name = "do_dccp_setsockopt",
90795 + .file = "net/dccp/proto.c",
90796 + .param5 = 1,
90797 +};
90798 +
90799 +struct size_overflow_hash _001396_hash = {
90800 + .next = NULL,
90801 + .name = "dtim_interval_read",
90802 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90803 + .param3 = 1,
90804 +};
90805 +
90806 +struct size_overflow_hash _001397_hash = {
90807 + .next = NULL,
90808 + .name = "dvb_audio_write",
90809 + .file = "drivers/media/dvb/ttpci/av7110_av.c",
90810 + .param3 = 1,
90811 +};
90812 +
90813 +struct size_overflow_hash _001398_hash = {
90814 + .next = NULL,
90815 + .name = "dvb_demux_do_ioctl",
90816 + .file = "drivers/media/dvb/dvb-core/dmxdev.c",
90817 + .param3 = 1,
90818 +};
90819 +
90820 +struct size_overflow_hash _001399_hash = {
90821 + .next = NULL,
90822 + .name = "dvb_dvr_do_ioctl",
90823 + .file = "drivers/media/dvb/dvb-core/dmxdev.c",
90824 + .param3 = 1,
90825 +};
90826 +
90827 +struct size_overflow_hash _001400_hash = {
90828 + .next = NULL,
90829 + .name = "dvb_video_write",
90830 + .file = "drivers/media/dvb/ttpci/av7110_av.c",
90831 + .param3 = 1,
90832 +};
90833 +
90834 +struct size_overflow_hash _001401_hash = {
90835 + .next = NULL,
90836 + .name = "ecryptfs_decode_and_decrypt_filename",
90837 + .file = "fs/ecryptfs/crypto.c",
90838 + .param5 = 1,
90839 +};
90840 +
90841 +struct size_overflow_hash _001402_hash = {
90842 + .next = NULL,
90843 + .name = "ecryptfs_encrypt_and_encode_filename",
90844 + .file = "fs/ecryptfs/crypto.c",
90845 + .param6 = 1,
90846 +};
90847 +
90848 +struct size_overflow_hash _001403_hash = {
90849 + .next = NULL,
90850 + .name = "enable_read",
90851 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofile_files.c",
90852 + .param3 = 1,
90853 +};
90854 +
90855 +struct size_overflow_hash _001404_hash = {
90856 + .next = NULL,
90857 + .name = "enable_write",
90858 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofile_files.c",
90859 + .param3 = 1,
90860 +};
90861 +
90862 +struct size_overflow_hash _001405_hash = {
90863 + .next = NULL,
90864 + .name = "event_calibration_read",
90865 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90866 + .param3 = 1,
90867 +};
90868 +
90869 +struct size_overflow_hash _001406_hash = {
90870 + .next = NULL,
90871 + .name = "event_heart_beat_read",
90872 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90873 + .param3 = 1,
90874 +};
90875 +
90876 +struct size_overflow_hash _001407_hash = {
90877 + .next = NULL,
90878 + .name = "event_oom_late_read",
90879 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90880 + .param3 = 1,
90881 +};
90882 +
90883 +struct size_overflow_hash _001408_hash = {
90884 + .next = NULL,
90885 + .name = "event_phy_transmit_error_read",
90886 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90887 + .param3 = 1,
90888 +};
90889 +
90890 +struct size_overflow_hash _001409_hash = {
90891 + .next = NULL,
90892 + .name = "event_rx_mem_empty_read",
90893 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90894 + .param3 = 1,
90895 +};
90896 +
90897 +struct size_overflow_hash _001410_hash = {
90898 + .next = NULL,
90899 + .name = "event_rx_mismatch_read",
90900 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90901 + .param3 = 1,
90902 +};
90903 +
90904 +struct size_overflow_hash _001411_hash = {
90905 + .next = NULL,
90906 + .name = "event_rx_pool_read",
90907 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90908 + .param3 = 1,
90909 +};
90910 +
90911 +struct size_overflow_hash _001412_hash = {
90912 + .next = NULL,
90913 + .name = "event_tx_stuck_read",
90914 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90915 + .param3 = 1,
90916 +};
90917 +
90918 +struct size_overflow_hash _001413_hash = {
90919 + .next = NULL,
90920 + .name = "excessive_retries_read",
90921 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
90922 + .param3 = 1,
90923 +};
90924 +
90925 +struct size_overflow_hash _001414_hash = {
90926 + .next = NULL,
90927 + .name = "exofs_read_kern",
90928 + .file = "fs/exofs/super.c",
90929 + .param6 = 1,
90930 +};
90931 +
90932 +struct size_overflow_hash _001415_hash = {
90933 + .next = NULL,
90934 + .name = "fallback_on_nodma_alloc",
90935 + .file = "drivers/block/floppy.c",
90936 + .param2 = 1,
90937 +};
90938 +
90939 +struct size_overflow_hash _001416_hash = {
90940 + .next = NULL,
90941 + .name = "__feat_register_sp",
90942 + .file = "net/dccp/feat.c",
90943 + .param6 = 1,
90944 +};
90945 +
90946 +struct size_overflow_hash _001417_hash = {
90947 + .next = NULL,
90948 + .name = "ffs_ep0_write",
90949 + .file = "drivers/usb/gadget/f_fs.c",
90950 + .param3 = 1,
90951 +};
90952 +
90953 +struct size_overflow_hash _001418_hash = {
90954 + .next = NULL,
90955 + .name = "ffs_epfile_read",
90956 + .file = "drivers/usb/gadget/f_fs.c",
90957 + .param3 = 1,
90958 +};
90959 +
90960 +struct size_overflow_hash _001419_hash = {
90961 + .next = NULL,
90962 + .name = "ffs_epfile_write",
90963 + .file = "drivers/usb/gadget/f_fs.c",
90964 + .param3 = 1,
90965 +};
90966 +
90967 +struct size_overflow_hash _001420_hash = {
90968 + .next = NULL,
90969 + .name = "frequency_read",
90970 + .file = "net/mac80211/debugfs.c",
90971 + .param3 = 1,
90972 +};
90973 +
90974 +struct size_overflow_hash _001421_hash = {
90975 + .next = NULL,
90976 + .name = "fsm_init",
90977 + .file = "lib/ts_fsm.c",
90978 + .param2 = 1,
90979 +};
90980 +
90981 +struct size_overflow_hash _001422_hash = {
90982 + .next = NULL,
90983 + .name = "garmin_read_process",
90984 + .file = "drivers/usb/serial/garmin_gps.c",
90985 + .param3 = 1,
90986 +};
90987 +
90988 +struct size_overflow_hash _001423_hash = {
90989 + .next = NULL,
90990 + .name = "garp_request_join",
90991 + .file = "include/net/garp.h",
90992 + .param4 = 1,
90993 +};
90994 +
90995 +struct size_overflow_hash _001424_hash = {
90996 + .next = NULL,
90997 + .name = "hcd_alloc_coherent",
90998 + .file = "drivers/usb/core/hcd.c",
90999 + .param5 = 1,
91000 +};
91001 +
91002 +struct size_overflow_hash _001425_hash = {
91003 + .next = NULL,
91004 + .name = "hci_sock_sendmsg",
91005 + .file = "net/bluetooth/hci_sock.c",
91006 + .param4 = 1,
91007 +};
91008 +
91009 +struct size_overflow_hash _001426_hash = {
91010 + .next = NULL,
91011 + .name = "__hwahc_op_set_gtk",
91012 + .file = "drivers/usb/host/hwa-hc.c",
91013 + .param4 = 1,
91014 +};
91015 +
91016 +struct size_overflow_hash _001427_hash = {
91017 + .next = NULL,
91018 + .name = "__hwahc_op_set_ptk",
91019 + .file = "drivers/usb/host/hwa-hc.c",
91020 + .param5 = 1,
91021 +};
91022 +
91023 +struct size_overflow_hash _001428_hash = {
91024 + .next = NULL,
91025 + .name = "ib_send_cm_drep",
91026 + .file = "include/rdma/ib_cm.h",
91027 + .param3 = 1,
91028 +};
91029 +
91030 +struct size_overflow_hash _001429_hash = {
91031 + .next = NULL,
91032 + .name = "ib_send_cm_mra",
91033 + .file = "include/rdma/ib_cm.h",
91034 + .param4 = 1,
91035 +};
91036 +
91037 +struct size_overflow_hash _001430_hash = {
91038 + .next = NULL,
91039 + .name = "ib_send_cm_rtu",
91040 + .file = "include/rdma/ib_cm.h",
91041 + .param3 = 1,
91042 +};
91043 +
91044 +struct size_overflow_hash _001431_hash = {
91045 + .next = NULL,
91046 + .name = "ieee80211_bss_info_update",
91047 + .file = "net/mac80211/scan.c",
91048 + .param4 = 1,
91049 +};
91050 +
91051 +struct size_overflow_hash _001432_hash = {
91052 + .next = NULL,
91053 + .name = "ieee80211_if_read_aid",
91054 + .file = "net/mac80211/debugfs_netdev.c",
91055 + .param3 = 1,
91056 +};
91057 +
91058 +struct size_overflow_hash _001433_hash = {
91059 + .next = NULL,
91060 + .name = "ieee80211_if_read_auto_open_plinks",
91061 + .file = "net/mac80211/debugfs_netdev.c",
91062 + .param3 = 1,
91063 +};
91064 +
91065 +struct size_overflow_hash _001434_hash = {
91066 + .next = NULL,
91067 + .name = "ieee80211_if_read_ave_beacon",
91068 + .file = "net/mac80211/debugfs_netdev.c",
91069 + .param3 = 1,
91070 +};
91071 +
91072 +struct size_overflow_hash _001435_hash = {
91073 + .next = NULL,
91074 + .name = "ieee80211_if_read_bssid",
91075 + .file = "net/mac80211/debugfs_netdev.c",
91076 + .param3 = 1,
91077 +};
91078 +
91079 +struct size_overflow_hash _001436_hash = {
91080 + .next = NULL,
91081 + .name = "ieee80211_if_read_channel_type",
91082 + .file = "net/mac80211/debugfs_netdev.c",
91083 + .param3 = 1,
91084 +};
91085 +
91086 +struct size_overflow_hash _001437_hash = {
91087 + .next = NULL,
91088 + .name = "ieee80211_if_read_dot11MeshConfirmTimeout",
91089 + .file = "net/mac80211/debugfs_netdev.c",
91090 + .param3 = 1,
91091 +};
91092 +
91093 +struct size_overflow_hash _001438_hash = {
91094 + .next = NULL,
91095 + .name = "ieee80211_if_read_dot11MeshGateAnnouncementProtocol",
91096 + .file = "net/mac80211/debugfs_netdev.c",
91097 + .param3 = 1,
91098 +};
91099 +
91100 +struct size_overflow_hash _001439_hash = {
91101 + .next = NULL,
91102 + .name = "ieee80211_if_read_dot11MeshHoldingTimeout",
91103 + .file = "net/mac80211/debugfs_netdev.c",
91104 + .param3 = 1,
91105 +};
91106 +
91107 +struct size_overflow_hash _001440_hash = {
91108 + .next = NULL,
91109 + .name = "ieee80211_if_read_dot11MeshHWMPactivePathTimeout",
91110 + .file = "net/mac80211/debugfs_netdev.c",
91111 + .param3 = 1,
91112 +};
91113 +
91114 +struct size_overflow_hash _001441_hash = {
91115 + .next = NULL,
91116 + .name = "ieee80211_if_read_dot11MeshHWMPmaxPREQretries",
91117 + .file = "net/mac80211/debugfs_netdev.c",
91118 + .param3 = 1,
91119 +};
91120 +
91121 +struct size_overflow_hash _001442_hash = {
91122 + .next = NULL,
91123 + .name = "ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime",
91124 + .file = "net/mac80211/debugfs_netdev.c",
91125 + .param3 = 1,
91126 +};
91127 +
91128 +struct size_overflow_hash _001443_hash = {
91129 + .next = NULL,
91130 + .name = "ieee80211_if_read_dot11MeshHWMPperrMinInterval",
91131 + .file = "net/mac80211/debugfs_netdev.c",
91132 + .param3 = 1,
91133 +};
91134 +
91135 +struct size_overflow_hash _001444_hash = {
91136 + .next = NULL,
91137 + .name = "ieee80211_if_read_dot11MeshHWMPpreqMinInterval",
91138 + .file = "net/mac80211/debugfs_netdev.c",
91139 + .param3 = 1,
91140 +};
91141 +
91142 +struct size_overflow_hash _001445_hash = {
91143 + .next = NULL,
91144 + .name = "ieee80211_if_read_dot11MeshHWMPRannInterval",
91145 + .file = "net/mac80211/debugfs_netdev.c",
91146 + .param3 = 1,
91147 +};
91148 +
91149 +struct size_overflow_hash _001446_hash = {
91150 + .next = NULL,
91151 + .name = "ieee80211_if_read_dot11MeshHWMPRootMode",
91152 + .file = "net/mac80211/debugfs_netdev.c",
91153 + .param3 = 1,
91154 +};
91155 +
91156 +struct size_overflow_hash _001447_hash = {
91157 + .next = NULL,
91158 + .name = "ieee80211_if_read_dot11MeshMaxPeerLinks",
91159 + .file = "net/mac80211/debugfs_netdev.c",
91160 + .param3 = 1,
91161 +};
91162 +
91163 +struct size_overflow_hash _001448_hash = {
91164 + .next = NULL,
91165 + .name = "ieee80211_if_read_dot11MeshMaxRetries",
91166 + .file = "net/mac80211/debugfs_netdev.c",
91167 + .param3 = 1,
91168 +};
91169 +
91170 +struct size_overflow_hash _001449_hash = {
91171 + .next = NULL,
91172 + .name = "ieee80211_if_read_dot11MeshRetryTimeout",
91173 + .file = "net/mac80211/debugfs_netdev.c",
91174 + .param3 = 1,
91175 +};
91176 +
91177 +struct size_overflow_hash _001450_hash = {
91178 + .next = NULL,
91179 + .name = "ieee80211_if_read_dot11MeshTTL",
91180 + .file = "net/mac80211/debugfs_netdev.c",
91181 + .param3 = 1,
91182 +};
91183 +
91184 +struct size_overflow_hash _001451_hash = {
91185 + .next = NULL,
91186 + .name = "ieee80211_if_read_dropped_frames_congestion",
91187 + .file = "net/mac80211/debugfs_netdev.c",
91188 + .param3 = 1,
91189 +};
91190 +
91191 +struct size_overflow_hash _001452_hash = {
91192 + .next = NULL,
91193 + .name = "ieee80211_if_read_dropped_frames_no_route",
91194 + .file = "net/mac80211/debugfs_netdev.c",
91195 + .param3 = 1,
91196 +};
91197 +
91198 +struct size_overflow_hash _001453_hash = {
91199 + .next = NULL,
91200 + .name = "ieee80211_if_read_dropped_frames_ttl",
91201 + .file = "net/mac80211/debugfs_netdev.c",
91202 + .param3 = 1,
91203 +};
91204 +
91205 +struct size_overflow_hash _001454_hash = {
91206 + .next = NULL,
91207 + .name = "ieee80211_if_read_drop_unencrypted",
91208 + .file = "net/mac80211/debugfs_netdev.c",
91209 + .param3 = 1,
91210 +};
91211 +
91212 +struct size_overflow_hash _001455_hash = {
91213 + .next = NULL,
91214 + .name = "ieee80211_if_read_dtim_count",
91215 + .file = "net/mac80211/debugfs_netdev.c",
91216 + .param3 = 1,
91217 +};
91218 +
91219 +struct size_overflow_hash _001456_hash = {
91220 + .next = NULL,
91221 + .name = "ieee80211_if_read_element_ttl",
91222 + .file = "net/mac80211/debugfs_netdev.c",
91223 + .param3 = 1,
91224 +};
91225 +
91226 +struct size_overflow_hash _001457_hash = {
91227 + .next = NULL,
91228 + .name = "ieee80211_if_read_estab_plinks",
91229 + .file = "net/mac80211/debugfs_netdev.c",
91230 + .param3 = 1,
91231 +};
91232 +
91233 +struct size_overflow_hash _001458_hash = {
91234 + .next = NULL,
91235 + .name = "ieee80211_if_read_flags",
91236 + .file = "net/mac80211/debugfs_netdev.c",
91237 + .param3 = 1,
91238 +};
91239 +
91240 +struct size_overflow_hash _001459_hash = {
91241 + .next = NULL,
91242 + .name = "ieee80211_if_read_fwded_frames",
91243 + .file = "net/mac80211/debugfs_netdev.c",
91244 + .param3 = 1,
91245 +};
91246 +
91247 +struct size_overflow_hash _001460_hash = {
91248 + .next = NULL,
91249 + .name = "ieee80211_if_read_fwded_mcast",
91250 + .file = "net/mac80211/debugfs_netdev.c",
91251 + .param3 = 1,
91252 +};
91253 +
91254 +struct size_overflow_hash _001461_hash = {
91255 + .next = NULL,
91256 + .name = "ieee80211_if_read_fwded_unicast",
91257 + .file = "net/mac80211/debugfs_netdev.c",
91258 + .param3 = 1,
91259 +};
91260 +
91261 +struct size_overflow_hash _001462_hash = {
91262 + .next = NULL,
91263 + .name = "ieee80211_if_read_last_beacon",
91264 + .file = "net/mac80211/debugfs_netdev.c",
91265 + .param3 = 1,
91266 +};
91267 +
91268 +struct size_overflow_hash _001463_hash = {
91269 + .next = NULL,
91270 + .name = "ieee80211_if_read_min_discovery_timeout",
91271 + .file = "net/mac80211/debugfs_netdev.c",
91272 + .param3 = 1,
91273 +};
91274 +
91275 +struct size_overflow_hash _001464_hash = {
91276 + .next = NULL,
91277 + .name = "ieee80211_if_read_num_buffered_multicast",
91278 + .file = "net/mac80211/debugfs_netdev.c",
91279 + .param3 = 1,
91280 +};
91281 +
91282 +struct size_overflow_hash _001465_hash = {
91283 + .next = NULL,
91284 + .name = "ieee80211_if_read_num_sta_authorized",
91285 + .file = "net/mac80211/debugfs_netdev.c",
91286 + .param3 = 1,
91287 +};
91288 +
91289 +struct size_overflow_hash _001466_hash = {
91290 + .next = NULL,
91291 + .name = "ieee80211_if_read_num_sta_ps",
91292 + .file = "net/mac80211/debugfs_netdev.c",
91293 + .param3 = 1,
91294 +};
91295 +
91296 +struct size_overflow_hash _001467_hash = {
91297 + .next = NULL,
91298 + .name = "ieee80211_if_read_path_refresh_time",
91299 + .file = "net/mac80211/debugfs_netdev.c",
91300 + .param3 = 1,
91301 +};
91302 +
91303 +struct size_overflow_hash _001468_hash = {
91304 + .next = NULL,
91305 + .name = "ieee80211_if_read_peer",
91306 + .file = "net/mac80211/debugfs_netdev.c",
91307 + .param3 = 1,
91308 +};
91309 +
91310 +struct size_overflow_hash _001469_hash = {
91311 + .next = NULL,
91312 + .name = "ieee80211_if_read_rc_rateidx_mask_2ghz",
91313 + .file = "net/mac80211/debugfs_netdev.c",
91314 + .param3 = 1,
91315 +};
91316 +
91317 +struct size_overflow_hash _001470_hash = {
91318 + .next = NULL,
91319 + .name = "ieee80211_if_read_rc_rateidx_mask_5ghz",
91320 + .file = "net/mac80211/debugfs_netdev.c",
91321 + .param3 = 1,
91322 +};
91323 +
91324 +struct size_overflow_hash _001471_hash = {
91325 + .next = NULL,
91326 + .name = "ieee80211_if_read_smps",
91327 + .file = "net/mac80211/debugfs_netdev.c",
91328 + .param3 = 1,
91329 +};
91330 +
91331 +struct size_overflow_hash _001472_hash = {
91332 + .next = NULL,
91333 + .name = "ieee80211_if_read_state",
91334 + .file = "net/mac80211/debugfs_netdev.c",
91335 + .param3 = 1,
91336 +};
91337 +
91338 +struct size_overflow_hash _001473_hash = {
91339 + .next = NULL,
91340 + .name = "ieee80211_if_read_tkip_mic_test",
91341 + .file = "net/mac80211/debugfs_netdev.c",
91342 + .param3 = 1,
91343 +};
91344 +
91345 +struct size_overflow_hash _001474_hash = {
91346 + .next = NULL,
91347 + .name = "ieee80211_if_read_tsf",
91348 + .file = "net/mac80211/debugfs_netdev.c",
91349 + .param3 = 1,
91350 +};
91351 +
91352 +struct size_overflow_hash _001475_hash = {
91353 + .next = NULL,
91354 + .name = "ieee80211_send_probe_req",
91355 + .file = "net/mac80211/util.c",
91356 + .param6 = 1,
91357 +};
91358 +
91359 +struct size_overflow_hash _001476_hash = {
91360 + .next = NULL,
91361 + .name = "init_map_ipmac",
91362 + .file = "net/netfilter/ipset/ip_set_bitmap_ipmac.c",
91363 + .param3 = 1,
91364 + .param4 = 1,
91365 +};
91366 +
91367 +struct size_overflow_hash _001478_hash = {
91368 + .next = NULL,
91369 + .name = "init_tid_tabs",
91370 + .file = "drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c",
91371 + .param2 = 1,
91372 + .param4 = 1,
91373 + .param3 = 1,
91374 +};
91375 +
91376 +struct size_overflow_hash _001481_hash = {
91377 + .next = NULL,
91378 + .name = "isr_cmd_cmplt_read",
91379 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91380 + .param3 = 1,
91381 +};
91382 +
91383 +struct size_overflow_hash _001482_hash = {
91384 + .next = NULL,
91385 + .name = "isr_commands_read",
91386 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91387 + .param3 = 1,
91388 +};
91389 +
91390 +struct size_overflow_hash _001483_hash = {
91391 + .next = NULL,
91392 + .name = "isr_decrypt_done_read",
91393 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91394 + .param3 = 1,
91395 +};
91396 +
91397 +struct size_overflow_hash _001484_hash = {
91398 + .next = NULL,
91399 + .name = "isr_dma0_done_read",
91400 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91401 + .param3 = 1,
91402 +};
91403 +
91404 +struct size_overflow_hash _001485_hash = {
91405 + .next = NULL,
91406 + .name = "isr_dma1_done_read",
91407 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91408 + .param3 = 1,
91409 +};
91410 +
91411 +struct size_overflow_hash _001486_hash = {
91412 + .next = NULL,
91413 + .name = "isr_fiqs_read",
91414 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91415 + .param3 = 1,
91416 +};
91417 +
91418 +struct size_overflow_hash _001487_hash = {
91419 + .next = NULL,
91420 + .name = "isr_host_acknowledges_read",
91421 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91422 + .param3 = 1,
91423 +};
91424 +
91425 +struct size_overflow_hash _001488_hash = {
91426 + .next = &_001393_hash,
91427 + .name = "isr_hw_pm_mode_changes_read",
91428 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91429 + .param3 = 1,
91430 +};
91431 +
91432 +struct size_overflow_hash _001489_hash = {
91433 + .next = &_001205_hash,
91434 + .name = "isr_irqs_read",
91435 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91436 + .param3 = 1,
91437 +};
91438 +
91439 +struct size_overflow_hash _001490_hash = {
91440 + .next = NULL,
91441 + .name = "isr_low_rssi_read",
91442 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91443 + .param3 = 1,
91444 +};
91445 +
91446 +struct size_overflow_hash _001491_hash = {
91447 + .next = NULL,
91448 + .name = "isr_pci_pm_read",
91449 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91450 + .param3 = 1,
91451 +};
91452 +
91453 +struct size_overflow_hash _001492_hash = {
91454 + .next = NULL,
91455 + .name = "isr_rx_headers_read",
91456 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91457 + .param3 = 1,
91458 +};
91459 +
91460 +struct size_overflow_hash _001493_hash = {
91461 + .next = NULL,
91462 + .name = "isr_rx_mem_overflow_read",
91463 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91464 + .param3 = 1,
91465 +};
91466 +
91467 +struct size_overflow_hash _001494_hash = {
91468 + .next = NULL,
91469 + .name = "isr_rx_procs_read",
91470 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91471 + .param3 = 1,
91472 +};
91473 +
91474 +struct size_overflow_hash _001495_hash = {
91475 + .next = NULL,
91476 + .name = "isr_rx_rdys_read",
91477 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91478 + .param3 = 1,
91479 +};
91480 +
91481 +struct size_overflow_hash _001496_hash = {
91482 + .next = NULL,
91483 + .name = "isr_tx_exch_complete_read",
91484 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91485 + .param3 = 1,
91486 +};
91487 +
91488 +struct size_overflow_hash _001497_hash = {
91489 + .next = NULL,
91490 + .name = "isr_tx_procs_read",
91491 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91492 + .param3 = 1,
91493 +};
91494 +
91495 +struct size_overflow_hash _001498_hash = {
91496 + .next = NULL,
91497 + .name = "isr_wakeups_read",
91498 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91499 + .param3 = 1,
91500 +};
91501 +
91502 +struct size_overflow_hash _001499_hash = {
91503 + .next = NULL,
91504 + .name = "ivtv_read",
91505 + .file = "drivers/media/video/ivtv/ivtv-fileops.c",
91506 + .param3 = 1,
91507 +};
91508 +
91509 +struct size_overflow_hash _001500_hash = {
91510 + .next = NULL,
91511 + .name = "kmem_realloc",
91512 + .file = "fs/xfs/kmem.c",
91513 + .param2 = 1,
91514 +};
91515 +
91516 +struct size_overflow_hash _001501_hash = {
91517 + .next = NULL,
91518 + .name = "kmem_zalloc",
91519 + .file = "fs/xfs/kmem.c",
91520 + .param1 = 1,
91521 +};
91522 +
91523 +struct size_overflow_hash _001502_hash = {
91524 + .next = NULL,
91525 + .name = "kmem_zalloc_greedy",
91526 + .file = "fs/xfs/kmem.c",
91527 + .param2 = 1,
91528 + .param3 = 1,
91529 +};
91530 +
91531 +struct size_overflow_hash _001504_hash = {
91532 + .next = NULL,
91533 + .name = "kmp_init",
91534 + .file = "lib/ts_kmp.c",
91535 + .param2 = 1,
91536 +};
91537 +
91538 +struct size_overflow_hash _001505_hash = {
91539 + .next = NULL,
91540 + .name = "lcd_proc_write",
91541 + .file = "drivers/platform/x86/asus_acpi.c",
91542 + .param3 = 1,
91543 +};
91544 +
91545 +struct size_overflow_hash _001506_hash = {
91546 + .next = NULL,
91547 + .name = "ledd_proc_write",
91548 + .file = "drivers/platform/x86/asus_acpi.c",
91549 + .param3 = 1,
91550 +};
91551 +
91552 +struct size_overflow_hash _001507_hash = {
91553 + .next = NULL,
91554 + .name = "mic_calc_failure_read",
91555 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91556 + .param3 = 1,
91557 +};
91558 +
91559 +struct size_overflow_hash _001508_hash = {
91560 + .next = NULL,
91561 + .name = "mic_rx_pkts_read",
91562 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91563 + .param3 = 1,
91564 +};
91565 +
91566 +struct size_overflow_hash _001509_hash = {
91567 + .next = NULL,
91568 + .name = "nfs4_realloc_slot_table",
91569 + .file = "fs/nfs/nfs4proc.c",
91570 + .param2 = 1,
91571 +};
91572 +
91573 +struct size_overflow_hash _001510_hash = {
91574 + .next = NULL,
91575 + .name = "nfs_idmap_request_key",
91576 + .file = "fs/nfs/idmap.c",
91577 + .param2 = 1,
91578 +};
91579 +
91580 +struct size_overflow_hash _001511_hash = {
91581 + .next = NULL,
91582 + .name = "nsm_get_handle",
91583 + .file = "include/linux/lockd/lockd.h",
91584 + .param4 = 1,
91585 +};
91586 +
91587 +struct size_overflow_hash _001512_hash = {
91588 + .next = NULL,
91589 + .name = "ntfs_copy_from_user_iovec",
91590 + .file = "fs/ntfs/file.c",
91591 + .param3 = 1,
91592 + .param6 = 1,
91593 +};
91594 +
91595 +struct size_overflow_hash _001514_hash = {
91596 + .next = NULL,
91597 + .name = "ntfs_file_buffered_write",
91598 + .file = "fs/ntfs/file.c",
91599 + .param6 = 1,
91600 +};
91601 +
91602 +struct size_overflow_hash _001515_hash = {
91603 + .next = NULL,
91604 + .name = "ntfs_malloc_nofs",
91605 + .file = "fs/ntfs/malloc.h",
91606 + .param1 = 1,
91607 +};
91608 +
91609 +struct size_overflow_hash _001516_hash = {
91610 + .next = NULL,
91611 + .name = "ntfs_malloc_nofs_nofail",
91612 + .file = "fs/ntfs/malloc.h",
91613 + .param1 = 1,
91614 +};
91615 +
91616 +struct size_overflow_hash _001517_hash = {
91617 + .next = NULL,
91618 + .name = "ocfs2_control_message",
91619 + .file = "fs/ocfs2/stack_user.c",
91620 + .param3 = 1,
91621 +};
91622 +
91623 +struct size_overflow_hash _001518_hash = {
91624 + .next = NULL,
91625 + .name = "opera1_usb_i2c_msgxfer",
91626 + .file = "drivers/media/dvb/dvb-usb/opera1.c",
91627 + .param4 = 1,
91628 +};
91629 +
91630 +struct size_overflow_hash _001519_hash = {
91631 + .next = NULL,
91632 + .name = "orinoco_add_extscan_result",
91633 + .file = "drivers/net/wireless/orinoco/scan.c",
91634 + .param3 = 1,
91635 +};
91636 +
91637 +struct size_overflow_hash _001520_hash = {
91638 + .next = NULL,
91639 + .name = "osd_req_list_collection_objects",
91640 + .file = "include/scsi/osd_initiator.h",
91641 + .param5 = 1,
91642 +};
91643 +
91644 +struct size_overflow_hash _001521_hash = {
91645 + .next = NULL,
91646 + .name = "osd_req_list_partition_objects",
91647 + .file = "include/scsi/osd_initiator.h",
91648 + .param5 = 1,
91649 +};
91650 +
91651 +struct size_overflow_hash _001522_hash = {
91652 + .next = NULL,
91653 + .name = "pair_device",
91654 + .file = "net/bluetooth/mgmt.c",
91655 + .param4 = 1,
91656 +};
91657 +
91658 +struct size_overflow_hash _001523_hash = {
91659 + .next = NULL,
91660 + .name = "pccard_store_cis",
91661 + .file = "drivers/pcmcia/cistpl.c",
91662 + .param6 = 1,
91663 +};
91664 +
91665 +struct size_overflow_hash _001524_hash = {
91666 + .next = NULL,
91667 + .name = "pin_code_reply",
91668 + .file = "net/bluetooth/mgmt.c",
91669 + .param4 = 1,
91670 +};
91671 +
91672 +struct size_overflow_hash _001525_hash = {
91673 + .next = NULL,
91674 + .name = "play_iframe",
91675 + .file = "drivers/media/dvb/ttpci/av7110_av.c",
91676 + .param3 = 1,
91677 +};
91678 +
91679 +struct size_overflow_hash _001526_hash = {
91680 + .next = NULL,
91681 + .name = "pointer_size_read",
91682 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofile_files.c",
91683 + .param3 = 1,
91684 +};
91685 +
91686 +struct size_overflow_hash _001527_hash = {
91687 + .next = NULL,
91688 + .name = "power_read",
91689 + .file = "net/mac80211/debugfs.c",
91690 + .param3 = 1,
91691 +};
91692 +
91693 +struct size_overflow_hash _001528_hash = {
91694 + .next = NULL,
91695 + .name = "ps_pspoll_max_apturn_read",
91696 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91697 + .param3 = 1,
91698 +};
91699 +
91700 +struct size_overflow_hash _001529_hash = {
91701 + .next = NULL,
91702 + .name = "ps_pspoll_timeouts_read",
91703 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91704 + .param3 = 1,
91705 +};
91706 +
91707 +struct size_overflow_hash _001530_hash = {
91708 + .next = NULL,
91709 + .name = "ps_pspoll_utilization_read",
91710 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91711 + .param3 = 1,
91712 +};
91713 +
91714 +struct size_overflow_hash _001531_hash = {
91715 + .next = NULL,
91716 + .name = "ps_upsd_max_apturn_read",
91717 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91718 + .param3 = 1,
91719 +};
91720 +
91721 +struct size_overflow_hash _001532_hash = {
91722 + .next = NULL,
91723 + .name = "ps_upsd_max_sptime_read",
91724 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91725 + .param3 = 1,
91726 +};
91727 +
91728 +struct size_overflow_hash _001533_hash = {
91729 + .next = NULL,
91730 + .name = "ps_upsd_timeouts_read",
91731 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91732 + .param3 = 1,
91733 +};
91734 +
91735 +struct size_overflow_hash _001534_hash = {
91736 + .next = NULL,
91737 + .name = "ps_upsd_utilization_read",
91738 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91739 + .param3 = 1,
91740 +};
91741 +
91742 +struct size_overflow_hash _001535_hash = {
91743 + .next = NULL,
91744 + .name = "pwr_disable_ps_read",
91745 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91746 + .param3 = 1,
91747 +};
91748 +
91749 +struct size_overflow_hash _001536_hash = {
91750 + .next = NULL,
91751 + .name = "pwr_elp_enter_read",
91752 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91753 + .param3 = 1,
91754 +};
91755 +
91756 +struct size_overflow_hash _001537_hash = {
91757 + .next = NULL,
91758 + .name = "pwr_enable_ps_read",
91759 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91760 + .param3 = 1,
91761 +};
91762 +
91763 +struct size_overflow_hash _001538_hash = {
91764 + .next = NULL,
91765 + .name = "pwr_fix_tsf_ps_read",
91766 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91767 + .param3 = 1,
91768 +};
91769 +
91770 +struct size_overflow_hash _001539_hash = {
91771 + .next = NULL,
91772 + .name = "pwr_missing_bcns_read",
91773 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91774 + .param3 = 1,
91775 +};
91776 +
91777 +struct size_overflow_hash _001540_hash = {
91778 + .next = NULL,
91779 + .name = "pwr_power_save_off_read",
91780 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91781 + .param3 = 1,
91782 +};
91783 +
91784 +struct size_overflow_hash _001541_hash = {
91785 + .next = NULL,
91786 + .name = "pwr_ps_enter_read",
91787 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91788 + .param3 = 1,
91789 +};
91790 +
91791 +struct size_overflow_hash _001542_hash = {
91792 + .next = NULL,
91793 + .name = "pwr_rcvd_awake_beacons_read",
91794 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91795 + .param3 = 1,
91796 +};
91797 +
91798 +struct size_overflow_hash _001543_hash = {
91799 + .next = NULL,
91800 + .name = "pwr_rcvd_beacons_read",
91801 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91802 + .param3 = 1,
91803 +};
91804 +
91805 +struct size_overflow_hash _001544_hash = {
91806 + .next = NULL,
91807 + .name = "pwr_tx_without_ps_read",
91808 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91809 + .param3 = 1,
91810 +};
91811 +
91812 +struct size_overflow_hash _001545_hash = {
91813 + .next = NULL,
91814 + .name = "pwr_tx_with_ps_read",
91815 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91816 + .param3 = 1,
91817 +};
91818 +
91819 +struct size_overflow_hash _001546_hash = {
91820 + .next = NULL,
91821 + .name = "pwr_wake_on_host_read",
91822 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91823 + .param3 = 1,
91824 +};
91825 +
91826 +struct size_overflow_hash _001547_hash = {
91827 + .next = NULL,
91828 + .name = "pwr_wake_on_timer_exp_read",
91829 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91830 + .param3 = 1,
91831 +};
91832 +
91833 +struct size_overflow_hash _001548_hash = {
91834 + .next = NULL,
91835 + .name = "qcam_read",
91836 + .file = "drivers/media/video/c-qcam.c",
91837 + .param3 = 1,
91838 +};
91839 +
91840 +struct size_overflow_hash _001549_hash = {
91841 + .next = NULL,
91842 + .name = "retry_count_read",
91843 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91844 + .param3 = 1,
91845 +};
91846 +
91847 +struct size_overflow_hash _001550_hash = {
91848 + .next = NULL,
91849 + .name = "rx_dropped_read",
91850 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91851 + .param3 = 1,
91852 +};
91853 +
91854 +struct size_overflow_hash _001551_hash = {
91855 + .next = NULL,
91856 + .name = "rx_fcs_err_read",
91857 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91858 + .param3 = 1,
91859 +};
91860 +
91861 +struct size_overflow_hash _001552_hash = {
91862 + .next = NULL,
91863 + .name = "rx_hdr_overflow_read",
91864 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91865 + .param3 = 1,
91866 +};
91867 +
91868 +struct size_overflow_hash _001553_hash = {
91869 + .next = NULL,
91870 + .name = "rx_hw_stuck_read",
91871 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91872 + .param3 = 1,
91873 +};
91874 +
91875 +struct size_overflow_hash _001554_hash = {
91876 + .next = NULL,
91877 + .name = "rx_out_of_mem_read",
91878 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91879 + .param3 = 1,
91880 +};
91881 +
91882 +struct size_overflow_hash _001555_hash = {
91883 + .next = NULL,
91884 + .name = "rx_path_reset_read",
91885 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91886 + .param3 = 1,
91887 +};
91888 +
91889 +struct size_overflow_hash _001556_hash = {
91890 + .next = NULL,
91891 + .name = "rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read",
91892 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91893 + .param3 = 1,
91894 +};
91895 +
91896 +struct size_overflow_hash _001557_hash = {
91897 + .next = NULL,
91898 + .name = "rxpipe_descr_host_int_trig_rx_data_read",
91899 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91900 + .param3 = 1,
91901 +};
91902 +
91903 +struct size_overflow_hash _001558_hash = {
91904 + .next = NULL,
91905 + .name = "rxpipe_missed_beacon_host_int_trig_rx_data_read",
91906 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91907 + .param3 = 1,
91908 +};
91909 +
91910 +struct size_overflow_hash _001559_hash = {
91911 + .next = NULL,
91912 + .name = "rxpipe_rx_prep_beacon_drop_read",
91913 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91914 + .param3 = 1,
91915 +};
91916 +
91917 +struct size_overflow_hash _001560_hash = {
91918 + .next = NULL,
91919 + .name = "rxpipe_tx_xfr_host_int_trig_rx_data_read",
91920 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91921 + .param3 = 1,
91922 +};
91923 +
91924 +struct size_overflow_hash _001561_hash = {
91925 + .next = NULL,
91926 + .name = "rx_reset_counter_read",
91927 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91928 + .param3 = 1,
91929 +};
91930 +
91931 +struct size_overflow_hash _001562_hash = {
91932 + .next = NULL,
91933 + .name = "rx_streaming_always_read",
91934 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91935 + .param3 = 1,
91936 +};
91937 +
91938 +struct size_overflow_hash _001563_hash = {
91939 + .next = NULL,
91940 + .name = "rx_streaming_interval_read",
91941 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91942 + .param3 = 1,
91943 +};
91944 +
91945 +struct size_overflow_hash _001564_hash = {
91946 + .next = NULL,
91947 + .name = "rx_xfr_hint_trig_read",
91948 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
91949 + .param3 = 1,
91950 +};
91951 +
91952 +struct size_overflow_hash _001565_hash = {
91953 + .next = NULL,
91954 + .name = "scsi_execute_req",
91955 + .file = "include/scsi/scsi_device.h",
91956 + .param5 = 1,
91957 +};
91958 +
91959 +struct size_overflow_hash _001566_hash = {
91960 + .next = NULL,
91961 + .name = "scsi_tgt_kspace_exec",
91962 + .file = "drivers/scsi/scsi_tgt_lib.c",
91963 + .param8 = 1,
91964 +};
91965 +
91966 +struct size_overflow_hash _001567_hash = {
91967 + .next = NULL,
91968 + .name = "sctp_sendmsg",
91969 + .file = "net/sctp/socket.c",
91970 + .param4 = 1,
91971 +};
91972 +
91973 +struct size_overflow_hash _001568_hash = {
91974 + .next = NULL,
91975 + .name = "sctp_setsockopt",
91976 + .file = "net/sctp/socket.c",
91977 + .param5 = 1,
91978 +};
91979 +
91980 +struct size_overflow_hash _001569_hash = {
91981 + .next = NULL,
91982 + .name = "set_connectable",
91983 + .file = "net/bluetooth/mgmt.c",
91984 + .param4 = 1,
91985 +};
91986 +
91987 +struct size_overflow_hash _001570_hash = {
91988 + .next = NULL,
91989 + .name = "set_discoverable",
91990 + .file = "net/bluetooth/mgmt.c",
91991 + .param4 = 1,
91992 +};
91993 +
91994 +struct size_overflow_hash _001571_hash = {
91995 + .next = NULL,
91996 + .name = "set_local_name",
91997 + .file = "net/bluetooth/mgmt.c",
91998 + .param4 = 1,
91999 +};
92000 +
92001 +struct size_overflow_hash _001572_hash = {
92002 + .next = NULL,
92003 + .name = "set_powered",
92004 + .file = "net/bluetooth/mgmt.c",
92005 + .param4 = 1,
92006 +};
92007 +
92008 +struct size_overflow_hash _001573_hash = {
92009 + .next = NULL,
92010 + .name = "simple_alloc_urb",
92011 + .file = "drivers/usb/misc/usbtest.c",
92012 + .param3 = 1,
92013 +};
92014 +
92015 +struct size_overflow_hash _001574_hash = {
92016 + .next = NULL,
92017 + .name = "sm_checker_extend",
92018 + .file = "drivers/md/persistent-data/dm-space-map-checker.c",
92019 + .param2 = 1,
92020 +};
92021 +
92022 +struct size_overflow_hash _001575_hash = {
92023 + .next = NULL,
92024 + .name = "snd_cs4281_BA0_read",
92025 + .file = "sound/pci/cs4281.c",
92026 + .param5 = 1,
92027 +};
92028 +
92029 +struct size_overflow_hash _001576_hash = {
92030 + .next = NULL,
92031 + .name = "snd_cs4281_BA1_read",
92032 + .file = "sound/pci/cs4281.c",
92033 + .param5 = 1,
92034 +};
92035 +
92036 +struct size_overflow_hash _001577_hash = {
92037 + .next = NULL,
92038 + .name = "snd_cs46xx_io_read",
92039 + .file = "sound/pci/cs46xx/cs46xx_lib.c",
92040 + .param5 = 1,
92041 +};
92042 +
92043 +struct size_overflow_hash _001578_hash = {
92044 + .next = NULL,
92045 + .name = "snd_gus_dram_read",
92046 + .file = "include/sound/gus.h",
92047 + .param4 = 1,
92048 +};
92049 +
92050 +struct size_overflow_hash _001579_hash = {
92051 + .next = NULL,
92052 + .name = "snd_gus_dram_write",
92053 + .file = "include/sound/gus.h",
92054 + .param4 = 1,
92055 +};
92056 +
92057 +struct size_overflow_hash _001580_hash = {
92058 + .next = NULL,
92059 + .name = "snd_mem_proc_write",
92060 + .file = "sound/core/memalloc.c",
92061 + .param3 = 1,
92062 +};
92063 +
92064 +struct size_overflow_hash _001581_hash = {
92065 + .next = NULL,
92066 + .name = "snd_pcm_oss_read",
92067 + .file = "sound/core/oss/pcm_oss.c",
92068 + .param3 = 1,
92069 +};
92070 +
92071 +struct size_overflow_hash _001582_hash = {
92072 + .next = NULL,
92073 + .name = "snd_pcm_oss_sync1",
92074 + .file = "sound/core/oss/pcm_oss.c",
92075 + .param2 = 1,
92076 +};
92077 +
92078 +struct size_overflow_hash _001583_hash = {
92079 + .next = NULL,
92080 + .name = "snd_pcm_oss_write",
92081 + .file = "sound/core/oss/pcm_oss.c",
92082 + .param3 = 1,
92083 +};
92084 +
92085 +struct size_overflow_hash _001584_hash = {
92086 + .next = NULL,
92087 + .name = "snd_rme32_capture_copy",
92088 + .file = "sound/pci/rme32.c",
92089 + .param5 = 1,
92090 +};
92091 +
92092 +struct size_overflow_hash _001585_hash = {
92093 + .next = NULL,
92094 + .name = "snd_rme32_playback_copy",
92095 + .file = "sound/pci/rme32.c",
92096 + .param5 = 1,
92097 +};
92098 +
92099 +struct size_overflow_hash _001586_hash = {
92100 + .next = NULL,
92101 + .name = "snd_rme96_capture_copy",
92102 + .file = "sound/pci/rme96.c",
92103 + .param5 = 1,
92104 +};
92105 +
92106 +struct size_overflow_hash _001587_hash = {
92107 + .next = NULL,
92108 + .name = "snd_rme96_playback_copy",
92109 + .file = "sound/pci/rme96.c",
92110 + .param5 = 1,
92111 +};
92112 +
92113 +struct size_overflow_hash _001588_hash = {
92114 + .next = NULL,
92115 + .name = "spi_execute",
92116 + .file = "drivers/scsi/scsi_transport_spi.c",
92117 + .param5 = 1,
92118 +};
92119 +
92120 +struct size_overflow_hash _001589_hash = {
92121 + .next = NULL,
92122 + .name = "srp_target_alloc",
92123 + .file = "include/scsi/libsrp.h",
92124 + .param3 = 1,
92125 +};
92126 +
92127 +struct size_overflow_hash _001590_hash = {
92128 + .next = NULL,
92129 + .name = "stats_dot11ACKFailureCount_read",
92130 + .file = "net/mac80211/debugfs.c",
92131 + .param3 = 1,
92132 +};
92133 +
92134 +struct size_overflow_hash _001591_hash = {
92135 + .next = NULL,
92136 + .name = "stats_dot11FCSErrorCount_read",
92137 + .file = "net/mac80211/debugfs.c",
92138 + .param3 = 1,
92139 +};
92140 +
92141 +struct size_overflow_hash _001592_hash = {
92142 + .next = NULL,
92143 + .name = "stats_dot11RTSFailureCount_read",
92144 + .file = "net/mac80211/debugfs.c",
92145 + .param3 = 1,
92146 +};
92147 +
92148 +struct size_overflow_hash _001593_hash = {
92149 + .next = NULL,
92150 + .name = "stats_dot11RTSSuccessCount_read",
92151 + .file = "net/mac80211/debugfs.c",
92152 + .param3 = 1,
92153 +};
92154 +
92155 +struct size_overflow_hash _001594_hash = {
92156 + .next = NULL,
92157 + .name = "stk_allocate_buffers",
92158 + .file = "drivers/media/video/stk-webcam.c",
92159 + .param2 = 1,
92160 +};
92161 +
92162 +struct size_overflow_hash _001595_hash = {
92163 + .next = NULL,
92164 + .name = "submit_inquiry",
92165 + .file = "drivers/scsi/device_handler/scsi_dh_rdac.c",
92166 + .param3 = 1,
92167 +};
92168 +
92169 +struct size_overflow_hash _001596_hash = {
92170 + .next = NULL,
92171 + .name = "team_options_register",
92172 + .file = "include/linux/if_team.h",
92173 + .param3 = 1,
92174 +};
92175 +
92176 +struct size_overflow_hash _001597_hash = {
92177 + .next = NULL,
92178 + .name = "test_unaligned_bulk",
92179 + .file = "drivers/usb/misc/usbtest.c",
92180 + .param3 = 1,
92181 +};
92182 +
92183 +struct size_overflow_hash _001598_hash = {
92184 + .next = NULL,
92185 + .name = "timeout_read",
92186 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofile_files.c",
92187 + .param3 = 1,
92188 +};
92189 +
92190 +struct size_overflow_hash _001599_hash = {
92191 + .next = NULL,
92192 + .name = "timeout_write",
92193 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofile_files.c",
92194 + .param3 = 1,
92195 +};
92196 +
92197 +struct size_overflow_hash _001600_hash = {
92198 + .next = NULL,
92199 + .name = "tipc_link_send_sections_fast",
92200 + .file = "net/tipc/link.c",
92201 + .param4 = 1,
92202 +};
92203 +
92204 +struct size_overflow_hash _001601_hash = {
92205 + .next = NULL,
92206 + .name = "total_ps_buffered_read",
92207 + .file = "net/mac80211/debugfs.c",
92208 + .param3 = 1,
92209 +};
92210 +
92211 +struct size_overflow_hash _001602_hash = {
92212 + .next = NULL,
92213 + .name = "ts_read",
92214 + .file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
92215 + .param3 = 1,
92216 +};
92217 +
92218 +struct size_overflow_hash _001603_hash = {
92219 + .next = NULL,
92220 + .name = "TSS_authhmac",
92221 + .file = "security/keys/trusted.c",
92222 + .param3 = 1,
92223 +};
92224 +
92225 +struct size_overflow_hash _001604_hash = {
92226 + .next = NULL,
92227 + .name = "TSS_checkhmac1",
92228 + .file = "security/keys/trusted.c",
92229 + .param5 = 1,
92230 +};
92231 +
92232 +struct size_overflow_hash _001605_hash = {
92233 + .next = NULL,
92234 + .name = "TSS_checkhmac2",
92235 + .file = "security/keys/trusted.c",
92236 + .param5 = 1,
92237 + .param7 = 1,
92238 +};
92239 +
92240 +struct size_overflow_hash _001607_hash = {
92241 + .next = NULL,
92242 + .name = "ts_write",
92243 + .file = "drivers/media/dvb/ddbridge/ddbridge-core.c",
92244 + .param3 = 1,
92245 +};
92246 +
92247 +struct size_overflow_hash _001608_hash = {
92248 + .next = NULL,
92249 + .name = "tx_internal_desc_overflow_read",
92250 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
92251 + .param3 = 1,
92252 +};
92253 +
92254 +struct size_overflow_hash _001609_hash = {
92255 + .next = NULL,
92256 + .name = "uapsd_max_sp_len_read",
92257 + .file = "net/mac80211/debugfs.c",
92258 + .param3 = 1,
92259 +};
92260 +
92261 +struct size_overflow_hash _001610_hash = {
92262 + .next = NULL,
92263 + .name = "uapsd_queues_read",
92264 + .file = "net/mac80211/debugfs.c",
92265 + .param3 = 1,
92266 +};
92267 +
92268 +struct size_overflow_hash _001611_hash = {
92269 + .next = NULL,
92270 + .name = "ulong_read_file",
92271 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofilefs.c",
92272 + .param3 = 1,
92273 +};
92274 +
92275 +struct size_overflow_hash _001612_hash = {
92276 + .next = NULL,
92277 + .name = "ulong_write_file",
92278 + .file = "arch/x86/oprofile/../../../drivers/oprofile/oprofilefs.c",
92279 + .param3 = 1,
92280 +};
92281 +
92282 +struct size_overflow_hash _001613_hash = {
92283 + .next = NULL,
92284 + .name = "usb_alloc_coherent",
92285 + .file = "include/linux/usb.h",
92286 + .param2 = 1,
92287 +};
92288 +
92289 +struct size_overflow_hash _001614_hash = {
92290 + .next = NULL,
92291 + .name = "user_power_read",
92292 + .file = "net/mac80211/debugfs.c",
92293 + .param3 = 1,
92294 +};
92295 +
92296 +struct size_overflow_hash _001615_hash = {
92297 + .next = NULL,
92298 + .name = "vb2_read",
92299 + .file = "include/media/videobuf2-core.h",
92300 + .param3 = 1,
92301 +};
92302 +
92303 +struct size_overflow_hash _001616_hash = {
92304 + .next = NULL,
92305 + .name = "vb2_write",
92306 + .file = "include/media/videobuf2-core.h",
92307 + .param3 = 1,
92308 +};
92309 +
92310 +struct size_overflow_hash _001617_hash = {
92311 + .next = NULL,
92312 + .name = "vhost_add_used_n",
92313 + .file = "drivers/vhost/vhost.c",
92314 + .param3 = 1,
92315 +};
92316 +
92317 +struct size_overflow_hash _001618_hash = {
92318 + .next = NULL,
92319 + .name = "virtqueue_add_buf",
92320 + .file = "include/linux/virtio.h",
92321 + .param3 = 1,
92322 + .param4 = 1,
92323 +};
92324 +
92325 +struct size_overflow_hash _001620_hash = {
92326 + .next = NULL,
92327 + .name = "vmbus_establish_gpadl",
92328 + .file = "include/linux/hyperv.h",
92329 + .param3 = 1,
92330 +};
92331 +
92332 +struct size_overflow_hash _001621_hash = {
92333 + .next = NULL,
92334 + .name = "wep_addr_key_count_read",
92335 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
92336 + .param3 = 1,
92337 +};
92338 +
92339 +struct size_overflow_hash _001622_hash = {
92340 + .next = NULL,
92341 + .name = "wep_decrypt_fail_read",
92342 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
92343 + .param3 = 1,
92344 +};
92345 +
92346 +struct size_overflow_hash _001623_hash = {
92347 + .next = NULL,
92348 + .name = "wep_default_key_count_read",
92349 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
92350 + .param3 = 1,
92351 +};
92352 +
92353 +struct size_overflow_hash _001624_hash = {
92354 + .next = NULL,
92355 + .name = "wep_interrupt_read",
92356 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
92357 + .param3 = 1,
92358 +};
92359 +
92360 +struct size_overflow_hash _001625_hash = {
92361 + .next = NULL,
92362 + .name = "wep_iv_read",
92363 + .file = "net/mac80211/debugfs.c",
92364 + .param3 = 1,
92365 +};
92366 +
92367 +struct size_overflow_hash _001626_hash = {
92368 + .next = NULL,
92369 + .name = "wep_key_not_found_read",
92370 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
92371 + .param3 = 1,
92372 +};
92373 +
92374 +struct size_overflow_hash _001627_hash = {
92375 + .next = NULL,
92376 + .name = "wep_packets_read",
92377 + .file = "drivers/net/wireless/wl12xx/debugfs.c",
92378 + .param3 = 1,
92379 +};
92380 +
92381 +struct size_overflow_hash _001628_hash = {
92382 + .next = NULL,
92383 + .name = "write_led",
92384 + .file = "drivers/platform/x86/asus_acpi.c",
92385 + .param2 = 1,
92386 +};
92387 +
92388 +struct size_overflow_hash _001629_hash = {
92389 + .next = NULL,
92390 + .name = "wusb_prf",
92391 + .file = "include/linux/usb/wusb.h",
92392 + .param7 = 1,
92393 +};
92394 +
92395 +struct size_overflow_hash _001630_hash = {
92396 + .next = NULL,
92397 + .name = "zd_usb_iowrite16v",
92398 + .file = "drivers/net/wireless/zd1211rw/zd_usb.c",
92399 + .param3 = 1,
92400 +};
92401 +
92402 +struct size_overflow_hash _001631_hash = {
92403 + .next = NULL,
92404 + .name = "afs_cell_lookup",
92405 + .file = "fs/afs/cell.c",
92406 + .param2 = 1,
92407 +};
92408 +
92409 +struct size_overflow_hash _001632_hash = {
92410 + .next = NULL,
92411 + .name = "agp_generic_alloc_user",
92412 + .file = "drivers/char/agp/generic.c",
92413 + .param1 = 1,
92414 +};
92415 +
92416 +struct size_overflow_hash _001634_hash = {
92417 + .next = NULL,
92418 + .name = "bluetooth_proc_write",
92419 + .file = "drivers/platform/x86/asus_acpi.c",
92420 + .param3 = 1,
92421 +};
92422 +
92423 +struct size_overflow_hash _001635_hash = {
92424 + .next = NULL,
92425 + .name = "cache_write",
92426 + .file = "net/sunrpc/cache.c",
92427 + .param3 = 1,
92428 +};
92429 +
92430 +struct size_overflow_hash _001636_hash = {
92431 + .next = NULL,
92432 + .name = "ch_do_scsi",
92433 + .file = "drivers/scsi/ch.c",
92434 + .param4 = 1,
92435 +};
92436 +
92437 +struct size_overflow_hash _001637_hash = {
92438 + .next = NULL,
92439 + .name = "cx18_read",
92440 + .file = "drivers/media/video/cx18/cx18-fileops.c",
92441 + .param3 = 1,
92442 +};
92443 +
92444 +struct size_overflow_hash _001638_hash = {
92445 + .next = NULL,
92446 + .name = "dccp_feat_register_sp",
92447 + .file = "net/dccp/feat.c",
92448 + .param5 = 1,
92449 +};
92450 +
92451 +struct size_overflow_hash _001640_hash = {
92452 + .next = NULL,
92453 + .name = "iso_alloc_urb",
92454 + .file = "drivers/usb/misc/usbtest.c",
92455 + .param5 = 1,
92456 +};
92457 +
92458 +struct size_overflow_hash _001641_hash = {
92459 + .next = NULL,
92460 + .name = "ivtv_read_pos",
92461 + .file = "drivers/media/video/ivtv/ivtv-fileops.c",
92462 + .param3 = 1,
92463 +};
92464 +
92465 +struct size_overflow_hash _001642_hash = {
92466 + .next = NULL,
92467 + .name = "mcam_v4l_read",
92468 + .file = "drivers/media/video/marvell-ccic/mcam-core.c",
92469 + .param3 = 1,
92470 +};
92471 +
92472 +struct size_overflow_hash _001643_hash = {
92473 + .next = NULL,
92474 + .name = "mled_proc_write",
92475 + .file = "drivers/platform/x86/asus_acpi.c",
92476 + .param3 = 1,
92477 +};
92478 +
92479 +struct size_overflow_hash _001644_hash = {
92480 + .next = NULL,
92481 + .name = "nfs_idmap_lookup_id",
92482 + .file = "fs/nfs/idmap.c",
92483 + .param2 = 1,
92484 +};
92485 +
92486 +struct size_overflow_hash _001645_hash = {
92487 + .next = NULL,
92488 + .name = "ocfs2_control_write",
92489 + .file = "fs/ocfs2/stack_user.c",
92490 + .param3 = 1,
92491 +};
92492 +
92493 +struct size_overflow_hash _001646_hash = {
92494 + .next = NULL,
92495 + .name = "osd_req_list_dev_partitions",
92496 + .file = "include/scsi/osd_initiator.h",
92497 + .param4 = 1,
92498 +};
92499 +
92500 +struct size_overflow_hash _001647_hash = {
92501 + .next = NULL,
92502 + .name = "osd_req_list_partition_collections",
92503 + .file = "include/scsi/osd_initiator.h",
92504 + .param5 = 1,
92505 +};
92506 +
92507 +struct size_overflow_hash _001648_hash = {
92508 + .next = NULL,
92509 + .name = "pwc_video_read",
92510 + .file = "drivers/media/video/pwc/pwc-if.c",
92511 + .param3 = 1,
92512 +};
92513 +
92514 +struct size_overflow_hash _001649_hash = {
92515 + .next = NULL,
92516 + .name = "scsi_vpd_inquiry",
92517 + .file = "drivers/scsi/scsi.c",
92518 + .param4 = 1,
92519 +};
92520 +
92521 +struct size_overflow_hash _001650_hash = {
92522 + .next = NULL,
92523 + .name = "snd_gf1_mem_proc_dump",
92524 + .file = "sound/isa/gus/gus_mem_proc.c",
92525 + .param5 = 1,
92526 +};
92527 +
92528 +struct size_overflow_hash _001651_hash = {
92529 + .next = NULL,
92530 + .name = "spi_dv_device_echo_buffer",
92531 + .file = "drivers/scsi/scsi_transport_spi.c",
92532 + .param2 = 1,
92533 + .param3 = 1,
92534 +};
92535 +
92536 +struct size_overflow_hash _001653_hash = {
92537 + .next = NULL,
92538 + .name = "tled_proc_write",
92539 + .file = "drivers/platform/x86/asus_acpi.c",
92540 + .param3 = 1,
92541 +};
92542 +
92543 +struct size_overflow_hash _001655_hash = {
92544 + .next = NULL,
92545 + .name = "usb_allocate_stream_buffers",
92546 + .file = "drivers/media/dvb/dvb-usb/usb-urb.c",
92547 + .param3 = 1,
92548 +};
92549 +
92550 +struct size_overflow_hash _001656_hash = {
92551 + .next = NULL,
92552 + .name = "_usb_writeN_sync",
92553 + .file = "drivers/net/wireless/rtlwifi/usb.c",
92554 + .param4 = 1,
92555 +};
92556 +
92557 +struct size_overflow_hash _001657_hash = {
92558 + .next = NULL,
92559 + .name = "vhost_add_used_and_signal_n",
92560 + .file = "drivers/vhost/vhost.c",
92561 + .param4 = 1,
92562 +};
92563 +
92564 +struct size_overflow_hash _001658_hash = {
92565 + .next = NULL,
92566 + .name = "vmbus_open",
92567 + .file = "include/linux/hyperv.h",
92568 + .param2 = 1,
92569 + .param3 = 1,
92570 +};
92571 +
92572 +struct size_overflow_hash _001660_hash = {
92573 + .next = NULL,
92574 + .name = "wled_proc_write",
92575 + .file = "drivers/platform/x86/asus_acpi.c",
92576 + .param3 = 1,
92577 +};
92578 +
92579 +struct size_overflow_hash _001661_hash = {
92580 + .next = NULL,
92581 + .name = "wusb_prf_256",
92582 + .file = "include/linux/usb/wusb.h",
92583 + .param7 = 1,
92584 +};
92585 +
92586 +struct size_overflow_hash _001662_hash = {
92587 + .next = NULL,
92588 + .name = "wusb_prf_64",
92589 + .file = "include/linux/usb/wusb.h",
92590 + .param7 = 1,
92591 +};
92592 +
92593 +struct size_overflow_hash _001663_hash = {
92594 + .next = NULL,
92595 + .name = "agp_allocate_memory",
92596 + .file = "include/linux/agp_backend.h",
92597 + .param2 = 1,
92598 +};
92599 +
92600 +struct size_overflow_hash _001664_hash = {
92601 + .next = NULL,
92602 + .name = "cx18_read_pos",
92603 + .file = "drivers/media/video/cx18/cx18-fileops.c",
92604 + .param3 = 1,
92605 +};
92606 +
92607 +struct size_overflow_hash _001665_hash = {
92608 + .next = NULL,
92609 + .name = "nfs_map_group_to_gid",
92610 + .file = "include/linux/nfs_idmap.h",
92611 + .param3 = 1,
92612 +};
92613 +
92614 +struct size_overflow_hash _001666_hash = {
92615 + .next = NULL,
92616 + .name = "nfs_map_name_to_uid",
92617 + .file = "include/linux/nfs_idmap.h",
92618 + .param3 = 1,
92619 +};
92620 +
92621 +struct size_overflow_hash _001667_hash = {
92622 + .next = NULL,
92623 + .name = "test_iso_queue",
92624 + .file = "drivers/usb/misc/usbtest.c",
92625 + .param5 = 1,
92626 +};
92627 +
92628 +struct size_overflow_hash _001668_hash = {
92629 + .next = NULL,
92630 + .name = "agp_allocate_memory_wrap",
92631 + .file = "drivers/char/agp/frontend.c",
92632 + .param1 = 1,
92633 +};
92634 +
92635 +struct size_overflow_hash _001669_hash = {
92636 + .next = NULL,
92637 + .name = "alloc_irq_cpu_rmap",
92638 + .file = "include/linux/cpu_rmap.h",
92639 + .param1 = 1,
92640 +};
92641 +
92642 +struct size_overflow_hash _001670_hash = {
92643 + .next = NULL,
92644 + .name = "alloc_ring",
92645 + .file = "drivers/net/ethernet/chelsio/cxgb4/sge.c",
92646 + .param2 = 1,
92647 + .param4 = 1,
92648 +};
92649 +
92650 +struct size_overflow_hash _001672_hash = {
92651 + .next = &_001124_hash,
92652 + .name = "atomic_counters_read",
92653 + .file = "drivers/infiniband/hw/ipath/ipath_fs.c",
92654 + .param3 = 1,
92655 +};
92656 +
92657 +struct size_overflow_hash _001673_hash = {
92658 + .next = NULL,
92659 + .name = "atomic_stats_read",
92660 + .file = "drivers/infiniband/hw/ipath/ipath_fs.c",
92661 + .param3 = 1,
92662 +};
92663 +
92664 +struct size_overflow_hash _001674_hash = {
92665 + .next = NULL,
92666 + .name = "c4iw_init_resource_fifo",
92667 + .file = "drivers/infiniband/hw/cxgb4/resource.c",
92668 + .param3 = 1,
92669 +};
92670 +
92671 +struct size_overflow_hash _001675_hash = {
92672 + .next = NULL,
92673 + .name = "c4iw_init_resource_fifo_random",
92674 + .file = "drivers/infiniband/hw/cxgb4/resource.c",
92675 + .param3 = 1,
92676 +};
92677 +
92678 +struct size_overflow_hash _001676_hash = {
92679 + .next = NULL,
92680 + .name = "compat_do_arpt_set_ctl",
92681 + .file = "net/ipv4/netfilter/arp_tables.c",
92682 + .param4 = 1,
92683 +};
92684 +
92685 +struct size_overflow_hash _001677_hash = {
92686 + .next = NULL,
92687 + .name = "compat_do_ip6t_set_ctl",
92688 + .file = "net/ipv6/netfilter/ip6_tables.c",
92689 + .param4 = 1,
92690 +};
92691 +
92692 +struct size_overflow_hash _001678_hash = {
92693 + .next = NULL,
92694 + .name = "compat_do_ipt_set_ctl",
92695 + .file = "net/ipv4/netfilter/ip_tables.c",
92696 + .param4 = 1,
92697 +};
92698 +
92699 +struct size_overflow_hash _001679_hash = {
92700 + .next = NULL,
92701 + .name = "cxio_init_resource_fifo",
92702 + .file = "drivers/infiniband/hw/cxgb3/cxio_resource.c",
92703 + .param3 = 1,
92704 +};
92705 +
92706 +struct size_overflow_hash _001680_hash = {
92707 + .next = NULL,
92708 + .name = "cxio_init_resource_fifo_random",
92709 + .file = "drivers/infiniband/hw/cxgb3/cxio_resource.c",
92710 + .param3 = 1,
92711 +};
92712 +
92713 +struct size_overflow_hash _001681_hash = {
92714 + .next = NULL,
92715 + .name = "dev_counters_read",
92716 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92717 + .param3 = 1,
92718 +};
92719 +
92720 +struct size_overflow_hash _001682_hash = {
92721 + .next = NULL,
92722 + .name = "dev_names_read",
92723 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92724 + .param3 = 1,
92725 +};
92726 +
92727 +struct size_overflow_hash _001683_hash = {
92728 + .next = &_001468_hash,
92729 + .name = "do_arpt_set_ctl",
92730 + .file = "net/ipv4/netfilter/arp_tables.c",
92731 + .param4 = 1,
92732 +};
92733 +
92734 +struct size_overflow_hash _001684_hash = {
92735 + .next = NULL,
92736 + .name = "do_ip6t_set_ctl",
92737 + .file = "net/ipv6/netfilter/ip6_tables.c",
92738 + .param4 = 1,
92739 +};
92740 +
92741 +struct size_overflow_hash _001685_hash = {
92742 + .next = NULL,
92743 + .name = "do_ipt_set_ctl",
92744 + .file = "net/ipv4/netfilter/ip_tables.c",
92745 + .param4 = 1,
92746 +};
92747 +
92748 +struct size_overflow_hash _001686_hash = {
92749 + .next = NULL,
92750 + .name = "drbd_bm_resize",
92751 + .file = "drivers/block/drbd/drbd_bitmap.c",
92752 + .param2 = 1,
92753 +};
92754 +
92755 +struct size_overflow_hash _001687_hash = {
92756 + .next = NULL,
92757 + .name = "driver_names_read",
92758 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92759 + .param3 = 1,
92760 +};
92761 +
92762 +struct size_overflow_hash _001688_hash = {
92763 + .next = NULL,
92764 + .name = "driver_stats_read",
92765 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92766 + .param3 = 1,
92767 +};
92768 +
92769 +struct size_overflow_hash _001689_hash = {
92770 + .next = NULL,
92771 + .name = "flash_read",
92772 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92773 + .param3 = 1,
92774 +};
92775 +
92776 +struct size_overflow_hash _001690_hash = {
92777 + .next = NULL,
92778 + .name = "flash_read",
92779 + .file = "drivers/infiniband/hw/ipath/ipath_fs.c",
92780 + .param3 = 1,
92781 +};
92782 +
92783 +struct size_overflow_hash _001691_hash = {
92784 + .next = NULL,
92785 + .name = "flash_write",
92786 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92787 + .param3 = 1,
92788 +};
92789 +
92790 +struct size_overflow_hash _001692_hash = {
92791 + .next = NULL,
92792 + .name = "flash_write",
92793 + .file = "drivers/infiniband/hw/ipath/ipath_fs.c",
92794 + .param3 = 1,
92795 +};
92796 +
92797 +struct size_overflow_hash _001693_hash = {
92798 + .next = NULL,
92799 + .name = "ghash_async_setkey",
92800 + .file = "arch/x86/crypto/ghash-clmulni-intel_glue.c",
92801 + .param3 = 1,
92802 +};
92803 +
92804 +struct size_overflow_hash _001694_hash = {
92805 + .next = NULL,
92806 + .name = "handle_eviocgbit",
92807 + .file = "drivers/input/evdev.c",
92808 + .param3 = 1,
92809 +};
92810 +
92811 +struct size_overflow_hash _001695_hash = {
92812 + .next = NULL,
92813 + .name = "hid_parse_report",
92814 + .file = "include/linux/hid.h",
92815 + .param3 = 1,
92816 +};
92817 +
92818 +struct size_overflow_hash _001696_hash = {
92819 + .next = NULL,
92820 + .name = "ipath_get_base_info",
92821 + .file = "drivers/infiniband/hw/ipath/ipath_file_ops.c",
92822 + .param3 = 1,
92823 +};
92824 +
92825 +struct size_overflow_hash _001697_hash = {
92826 + .next = NULL,
92827 + .name = "options_write",
92828 + .file = "drivers/misc/sgi-gru/gruprocfs.c",
92829 + .param3 = 1,
92830 +};
92831 +
92832 +struct size_overflow_hash _001698_hash = {
92833 + .next = NULL,
92834 + .name = "portcntrs_1_read",
92835 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92836 + .param3 = 1,
92837 +};
92838 +
92839 +struct size_overflow_hash _001699_hash = {
92840 + .next = NULL,
92841 + .name = "portcntrs_2_read",
92842 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92843 + .param3 = 1,
92844 +};
92845 +
92846 +struct size_overflow_hash _001700_hash = {
92847 + .next = NULL,
92848 + .name = "portnames_read",
92849 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92850 + .param3 = 1,
92851 +};
92852 +
92853 +struct size_overflow_hash _001701_hash = {
92854 + .next = NULL,
92855 + .name = "qib_alloc_devdata",
92856 + .file = "drivers/infiniband/hw/qib/qib_init.c",
92857 + .param2 = 1,
92858 +};
92859 +
92860 +struct size_overflow_hash _001702_hash = {
92861 + .next = NULL,
92862 + .name = "qib_diag_write",
92863 + .file = "drivers/infiniband/hw/qib/qib_diag.c",
92864 + .param3 = 1,
92865 +};
92866 +
92867 +struct size_overflow_hash _001703_hash = {
92868 + .next = NULL,
92869 + .name = "qib_get_base_info",
92870 + .file = "drivers/infiniband/hw/qib/qib_file_ops.c",
92871 + .param3 = 1,
92872 +};
92873 +
92874 +struct size_overflow_hash _001704_hash = {
92875 + .next = NULL,
92876 + .name = "qsfp_1_read",
92877 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92878 + .param3 = 1,
92879 +};
92880 +
92881 +struct size_overflow_hash _001705_hash = {
92882 + .next = NULL,
92883 + .name = "qsfp_2_read",
92884 + .file = "drivers/infiniband/hw/qib/qib_fs.c",
92885 + .param3 = 1,
92886 +};
92887 +
92888 +struct size_overflow_hash _001706_hash = {
92889 + .next = NULL,
92890 + .name = "rfc4106_set_key",
92891 + .file = "arch/x86/crypto/aesni-intel_glue.c",
92892 + .param3 = 1,
92893 +};
92894 +
92895 +struct size_overflow_hash _001707_hash = {
92896 + .next = &_000258_hash,
92897 + .name = "stats_read_ul",
92898 + .file = "drivers/idle/i7300_idle.c",
92899 + .param3 = 1,
92900 +};
92901 +
92902 +struct size_overflow_hash _001708_hash = {
92903 + .next = NULL,
92904 + .name = "xpc_kmalloc_cacheline_aligned",
92905 + .file = "drivers/misc/sgi-xp/xpc_partition.c",
92906 + .param1 = 1,
92907 +};
92908 +
92909 +struct size_overflow_hash _001709_hash = {
92910 + .next = NULL,
92911 + .name = "xpc_kzalloc_cacheline_aligned",
92912 + .file = "drivers/misc/sgi-xp/xpc_main.c",
92913 + .param1 = 1,
92914 +};
92915 +
92916 +struct size_overflow_hash _001710_hash = {
92917 + .next = NULL,
92918 + .name = "c4iw_init_resource",
92919 + .file = "drivers/infiniband/hw/cxgb4/resource.c",
92920 + .param2 = 1,
92921 + .param3 = 1,
92922 +};
92923 +
92924 +struct size_overflow_hash _001712_hash = {
92925 + .next = NULL,
92926 + .name = "cxio_hal_init_resource",
92927 + .file = "drivers/infiniband/hw/cxgb3/cxio_resource.c",
92928 + .param2 = 1,
92929 + .param7 = 1,
92930 + .param6 = 1,
92931 +};
92932 +
92933 +struct size_overflow_hash _001715_hash = {
92934 + .next = &_000734_hash,
92935 + .name = "cxio_hal_init_rhdl_resource",
92936 + .file = "drivers/infiniband/hw/cxgb3/cxio_resource.c",
92937 + .param1 = 1,
92938 +};
92939 +
92940 +struct size_overflow_hash _001716_hash = {
92941 + .next = NULL,
92942 + .name = "amthi_read",
92943 + .file = "drivers/staging/mei/iorw.c",
92944 + .param4 = 1,
92945 +};
92946 +
92947 +struct size_overflow_hash _001717_hash = {
92948 + .next = NULL,
92949 + .name = "bcm_char_read",
92950 + .file = "drivers/staging/bcm/Bcmchar.c",
92951 + .param3 = 1,
92952 +};
92953 +
92954 +struct size_overflow_hash _001718_hash = {
92955 + .next = NULL,
92956 + .name = "BcmCopySection",
92957 + .file = "drivers/staging/bcm/nvm.c",
92958 + .param5 = 1,
92959 +};
92960 +
92961 +struct size_overflow_hash _001719_hash = {
92962 + .next = NULL,
92963 + .name = "buffer_from_user",
92964 + .file = "drivers/staging/vme/devices/vme_user.c",
92965 + .param3 = 1,
92966 +};
92967 +
92968 +struct size_overflow_hash _001720_hash = {
92969 + .next = NULL,
92970 + .name = "buffer_to_user",
92971 + .file = "drivers/staging/vme/devices/vme_user.c",
92972 + .param3 = 1,
92973 +};
92974 +
92975 +struct size_overflow_hash _001721_hash = {
92976 + .next = NULL,
92977 + .name = "capabilities_read",
92978 + .file = "drivers/xen/xenfs/super.c",
92979 + .param3 = 1,
92980 +};
92981 +
92982 +struct size_overflow_hash _001722_hash = {
92983 + .next = NULL,
92984 + .name = "chd_dec_fetch_cdata",
92985 + .file = "drivers/staging/crystalhd/crystalhd_lnx.c",
92986 + .param3 = 1,
92987 +};
92988 +
92989 +struct size_overflow_hash _001723_hash = {
92990 + .next = NULL,
92991 + .name = "create_bounce_buffer",
92992 + .file = "drivers/staging/hv/storvsc_drv.c",
92993 + .param3 = 1,
92994 +};
92995 +
92996 +struct size_overflow_hash _001724_hash = {
92997 + .next = NULL,
92998 + .name = "crystalhd_create_dio_pool",
92999 + .file = "drivers/staging/crystalhd/crystalhd_misc.c",
93000 + .param2 = 1,
93001 +};
93002 +
93003 +struct size_overflow_hash _001725_hash = {
93004 + .next = NULL,
93005 + .name = "do_read_log_to_user",
93006 + .file = "drivers/staging/android/logger.c",
93007 + .param4 = 1,
93008 +};
93009 +
93010 +struct size_overflow_hash _001726_hash = {
93011 + .next = NULL,
93012 + .name = "do_write_log_from_user",
93013 + .file = "drivers/staging/android/logger.c",
93014 + .param3 = 1,
93015 +};
93016 +
93017 +struct size_overflow_hash _001727_hash = {
93018 + .next = NULL,
93019 + .name = "dt3155_read",
93020 + .file = "drivers/staging/media/dt3155v4l/dt3155v4l.c",
93021 + .param3 = 1,
93022 +};
93023 +
93024 +struct size_overflow_hash _001728_hash = {
93025 + .next = NULL,
93026 + .name = "easycap_alsa_vmalloc",
93027 + .file = "drivers/staging/media/easycap/easycap_sound.c",
93028 + .param2 = 1,
93029 +};
93030 +
93031 +struct size_overflow_hash _001729_hash = {
93032 + .next = NULL,
93033 + .name = "evm_read_key",
93034 + .file = "security/integrity/evm/evm_secfs.c",
93035 + .param3 = 1,
93036 +};
93037 +
93038 +struct size_overflow_hash _001730_hash = {
93039 + .next = NULL,
93040 + .name = "evm_write_key",
93041 + .file = "security/integrity/evm/evm_secfs.c",
93042 + .param3 = 1,
93043 +};
93044 +
93045 +struct size_overflow_hash _001731_hash = {
93046 + .next = NULL,
93047 + .name = "evtchn_read",
93048 + .file = "drivers/xen/evtchn.c",
93049 + .param3 = 1,
93050 +};
93051 +
93052 +struct size_overflow_hash _001732_hash = {
93053 + .next = NULL,
93054 + .name = "gather_array",
93055 + .file = "drivers/xen/privcmd.c",
93056 + .param3 = 1,
93057 +};
93058 +
93059 +struct size_overflow_hash _001733_hash = {
93060 + .next = NULL,
93061 + .name = "gnttab_map",
93062 + .file = "drivers/xen/grant-table.c",
93063 + .param2 = 1,
93064 +};
93065 +
93066 +struct size_overflow_hash _001734_hash = {
93067 + .next = NULL,
93068 + .name = "iio_read_first_n_kfifo",
93069 + .file = "drivers/staging/iio/kfifo_buf.c",
93070 + .param2 = 1,
93071 +};
93072 +
93073 +struct size_overflow_hash _001735_hash = {
93074 + .next = NULL,
93075 + .name = "iio_read_first_n_sw_rb",
93076 + .file = "drivers/staging/iio/ring_sw.c",
93077 + .param2 = 1,
93078 +};
93079 +
93080 +struct size_overflow_hash _001736_hash = {
93081 + .next = NULL,
93082 + .name = "keymap_store",
93083 + .file = "drivers/staging/speakup/kobjects.c",
93084 + .param4 = 1,
93085 +};
93086 +
93087 +struct size_overflow_hash _001737_hash = {
93088 + .next = NULL,
93089 + .name = "line6_dumpreq_initbuf",
93090 + .file = "drivers/staging/line6/dumprequest.c",
93091 + .param3 = 1,
93092 +};
93093 +
93094 +struct size_overflow_hash _001738_hash = {
93095 + .next = NULL,
93096 + .name = "lirc_write",
93097 + .file = "drivers/staging/media/lirc/lirc_parallel.c",
93098 + .param3 = 1,
93099 +};
93100 +
93101 +struct size_overflow_hash _001739_hash = {
93102 + .next = NULL,
93103 + .name = "lirc_write",
93104 + .file = "drivers/staging/media/lirc/lirc_sir.c",
93105 + .param3 = 1,
93106 +};
93107 +
93108 +struct size_overflow_hash _001740_hash = {
93109 + .next = &_000815_hash,
93110 + .name = "lirc_write",
93111 + .file = "drivers/staging/media/lirc/lirc_serial.c",
93112 + .param3 = 1,
93113 +};
93114 +
93115 +struct size_overflow_hash _001741_hash = {
93116 + .next = &_001021_hash,
93117 + .name = "_malloc",
93118 + .file = "drivers/staging/rtl8712/osdep_service.h",
93119 + .param1 = 1,
93120 +};
93121 +
93122 +struct size_overflow_hash _001742_hash = {
93123 + .next = NULL,
93124 + .name = "mei_read",
93125 + .file = "drivers/staging/mei/main.c",
93126 + .param3 = 1,
93127 +};
93128 +
93129 +struct size_overflow_hash _001743_hash = {
93130 + .next = NULL,
93131 + .name = "mei_write",
93132 + .file = "drivers/staging/mei/main.c",
93133 + .param3 = 1,
93134 +};
93135 +
93136 +struct size_overflow_hash _001744_hash = {
93137 + .next = NULL,
93138 + .name = "msg_set",
93139 + .file = "drivers/staging/speakup/i18n.c",
93140 + .param3 = 1,
93141 +};
93142 +
93143 +struct size_overflow_hash _001745_hash = {
93144 + .next = NULL,
93145 + .name = "OS_kmalloc",
93146 + .file = "drivers/staging/cxt1e1/sbecom_inline_linux.h",
93147 + .param1 = 1,
93148 +};
93149 +
93150 +struct size_overflow_hash _001746_hash = {
93151 + .next = NULL,
93152 + .name = "queue_reply",
93153 + .file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
93154 + .param3 = 1,
93155 +};
93156 +
93157 +struct size_overflow_hash _001747_hash = {
93158 + .next = &_000841_hash,
93159 + .name = "resource_from_user",
93160 + .file = "drivers/staging/vme/devices/vme_user.c",
93161 + .param3 = 1,
93162 +};
93163 +
93164 +struct size_overflow_hash _001748_hash = {
93165 + .next = NULL,
93166 + .name = "sca3000_read_first_n_hw_rb",
93167 + .file = "drivers/staging/iio/accel/sca3000_ring.c",
93168 + .param2 = 1,
93169 +};
93170 +
93171 +struct size_overflow_hash _001749_hash = {
93172 + .next = NULL,
93173 + .name = "sep_lock_user_pages",
93174 + .file = "drivers/staging/sep/sep_driver.c",
93175 + .param2 = 1,
93176 + .param3 = 1,
93177 +};
93178 +
93179 +struct size_overflow_hash _001751_hash = {
93180 + .next = NULL,
93181 + .name = "sep_prepare_input_output_dma_table_in_dcb",
93182 + .file = "drivers/staging/sep/sep_driver.c",
93183 + .param4 = 1,
93184 + .param5 = 1,
93185 + .param2 = 1,
93186 + .param3 = 1,
93187 +};
93188 +
93189 +struct size_overflow_hash _001753_hash = {
93190 + .next = NULL,
93191 + .name = "split",
93192 + .file = "drivers/xen/xenbus/xenbus_xs.c",
93193 + .param2 = 1,
93194 +};
93195 +
93196 +struct size_overflow_hash _001754_hash = {
93197 + .next = NULL,
93198 + .name = "storvsc_connect_to_vsp",
93199 + .file = "drivers/staging/hv/storvsc_drv.c",
93200 + .param2 = 1,
93201 +};
93202 +
93203 +struct size_overflow_hash _001755_hash = {
93204 + .next = NULL,
93205 + .name = "u32_array_read",
93206 + .file = "arch/x86/xen/debugfs.c",
93207 + .param3 = 1,
93208 +};
93209 +
93210 +struct size_overflow_hash _001756_hash = {
93211 + .next = NULL,
93212 + .name = "ValidateDSDParamsChecksum",
93213 + .file = "drivers/staging/bcm/led_control.c",
93214 + .param3 = 1,
93215 +};
93216 +
93217 +struct size_overflow_hash _001757_hash = {
93218 + .next = NULL,
93219 + .name = "vfd_write",
93220 + .file = "drivers/staging/media/lirc/lirc_sasem.c",
93221 + .param3 = 1,
93222 +};
93223 +
93224 +struct size_overflow_hash _001758_hash = {
93225 + .next = NULL,
93226 + .name = "vfd_write",
93227 + .file = "drivers/staging/media/lirc/lirc_imon.c",
93228 + .param3 = 1,
93229 +};
93230 +
93231 +struct size_overflow_hash _001759_hash = {
93232 + .next = NULL,
93233 + .name = "Wb35Reg_BurstWrite",
93234 + .file = "drivers/staging/winbond/wb35reg.c",
93235 + .param4 = 1,
93236 +};
93237 +
93238 +struct size_overflow_hash _001760_hash = {
93239 + .next = NULL,
93240 + .name = "xenbus_file_write",
93241 + .file = "drivers/xen/xenbus/xenbus_dev_frontend.c",
93242 + .param3 = 1,
93243 +};
93244 +
93245 +struct size_overflow_hash _001761_hash = {
93246 + .next = NULL,
93247 + .name = "xsd_read",
93248 + .file = "drivers/xen/xenfs/xenstored.c",
93249 + .param3 = 1,
93250 +};
93251 +
93252 +struct size_overflow_hash _001762_hash = {
93253 + .next = NULL,
93254 + .name = "line6_dumpreq_init",
93255 + .file = "drivers/staging/line6/dumprequest.c",
93256 + .param3 = 1,
93257 +};
93258 +
93259 +struct size_overflow_hash _001763_hash = {
93260 + .next = NULL,
93261 + .name = "r8712_usbctrl_vendorreq",
93262 + .file = "drivers/staging/rtl8712/usb_ops_linux.c",
93263 + .param6 = 1,
93264 +};
93265 +
93266 +struct size_overflow_hash _001764_hash = {
93267 + .next = NULL,
93268 + .name = "r871x_set_wpa_ie",
93269 + .file = "drivers/staging/rtl8712/rtl871x_ioctl_linux.c",
93270 + .param3 = 1,
93271 +};
93272 +
93273 +struct size_overflow_hash _001765_hash = {
93274 + .next = NULL,
93275 + .name = "sep_prepare_input_dma_table",
93276 + .file = "drivers/staging/sep/sep_driver.c",
93277 + .param2 = 1,
93278 + .param3 = 1,
93279 +};
93280 +
93281 +struct size_overflow_hash _001767_hash = {
93282 + .next = NULL,
93283 + .name = "sep_prepare_input_output_dma_table",
93284 + .file = "drivers/staging/sep/sep_driver.c",
93285 + .param2 = 1,
93286 + .param4 = 1,
93287 + .param3 = 1,
93288 +};
93289 +
93290 +struct size_overflow_hash _001770_hash = {
93291 + .next = NULL,
93292 + .name = "vme_user_write",
93293 + .file = "drivers/staging/vme/devices/vme_user.c",
93294 + .param3 = 1,
93295 +};
93296 +
93297 +struct size_overflow_hash _001771_hash = {
93298 + .next = NULL,
93299 + .name = "alloc_ebda_hpc",
93300 + .file = "drivers/pci/hotplug/ibmphp_ebda.c",
93301 + .param1 = 1,
93302 + .param2 = 1,
93303 +};
93304 +
93305 +struct size_overflow_hash _001772_hash = {
93306 + .next = NULL,
93307 + .name = "alloc_apertures",
93308 + .file = "include/linux/fb.h",
93309 + .param1 = 1,
93310 +};
93311 +
93312 +struct size_overflow_hash _001773_hash = {
93313 + .next = NULL,
93314 + .name = "bin_uuid",
93315 + .file = "kernel/sysctl_binary.c",
93316 + .param3 = 1,
93317 +};
93318 +
93319 +struct size_overflow_hash _001774_hash = {
93320 + .next = &_000640_hash,
93321 + .name = "__copy_from_user_inatomic_nocache",
93322 + .file = "arch/x86/include/asm/uaccess_64.h",
93323 + .param3 = 1,
93324 +};
93325 +
93326 +struct size_overflow_hash _001775_hash = {
93327 + .next = NULL,
93328 + .name = "do_dmabuf_dirty_sou",
93329 + .file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
93330 + .param7 = 1,
93331 +};
93332 +
93333 +struct size_overflow_hash _001776_hash = {
93334 + .next = NULL,
93335 + .name = "do_surface_dirty_sou",
93336 + .file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
93337 + .param7 = 1,
93338 +};
93339 +
93340 +struct size_overflow_hash _001777_hash = {
93341 + .next = NULL,
93342 + .name = "drm_agp_bind_pages",
93343 + .file = "drivers/gpu/drm/drm_agpsupport.c",
93344 + .param3 = 1,
93345 +};
93346 +
93347 +struct size_overflow_hash _001778_hash = {
93348 + .next = NULL,
93349 + .name = "drm_calloc_large",
93350 + .file = "include/drm/drm_mem_util.h",
93351 + .param1 = 1,
93352 + .param2 = 1,
93353 +};
93354 +
93355 +struct size_overflow_hash _001780_hash = {
93356 + .next = NULL,
93357 + .name = "drm_ht_create",
93358 + .file = "drivers/gpu/drm/drm_hashtab.c",
93359 + .param2 = 1,
93360 +};
93361 +
93362 +struct size_overflow_hash _001781_hash = {
93363 + .next = NULL,
93364 + .name = "drm_malloc_ab",
93365 + .file = "include/drm/drm_mem_util.h",
93366 + .param1 = 1,
93367 + .param2 = 1,
93368 +};
93369 +
93370 +struct size_overflow_hash _001783_hash = {
93371 + .next = NULL,
93372 + .name = "drm_plane_init",
93373 + .file = "drivers/gpu/drm/drm_crtc.c",
93374 + .param6 = 1,
93375 +};
93376 +
93377 +struct size_overflow_hash _001784_hash = {
93378 + .next = NULL,
93379 + .name = "drm_vmalloc_dma",
93380 + .file = "drivers/gpu/drm/drm_scatter.c",
93381 + .param1 = 1,
93382 +};
93383 +
93384 +struct size_overflow_hash _001785_hash = {
93385 + .next = NULL,
93386 + .name = "fb_read",
93387 + .file = "drivers/video/fbmem.c",
93388 + .param3 = 1,
93389 +};
93390 +
93391 +struct size_overflow_hash _001786_hash = {
93392 + .next = NULL,
93393 + .name = "fb_write",
93394 + .file = "drivers/video/fbmem.c",
93395 + .param3 = 1,
93396 +};
93397 +
93398 +struct size_overflow_hash _001787_hash = {
93399 + .next = NULL,
93400 + .name = "framebuffer_alloc",
93401 + .file = "include/linux/fb.h",
93402 + .param1 = 1,
93403 +};
93404 +
93405 +struct size_overflow_hash _001788_hash = {
93406 + .next = NULL,
93407 + .name = "i915_cache_sharing_read",
93408 + .file = "drivers/gpu/drm/i915/i915_debugfs.c",
93409 + .param3 = 1,
93410 +};
93411 +
93412 +struct size_overflow_hash _001789_hash = {
93413 + .next = NULL,
93414 + .name = "i915_cache_sharing_write",
93415 + .file = "drivers/gpu/drm/i915/i915_debugfs.c",
93416 + .param3 = 1,
93417 +};
93418 +
93419 +struct size_overflow_hash _001790_hash = {
93420 + .next = NULL,
93421 + .name = "i915_max_freq_read",
93422 + .file = "drivers/gpu/drm/i915/i915_debugfs.c",
93423 + .param3 = 1,
93424 +};
93425 +
93426 +struct size_overflow_hash _001791_hash = {
93427 + .next = NULL,
93428 + .name = "i915_max_freq_write",
93429 + .file = "drivers/gpu/drm/i915/i915_debugfs.c",
93430 + .param3 = 1,
93431 +};
93432 +
93433 +struct size_overflow_hash _001792_hash = {
93434 + .next = NULL,
93435 + .name = "i915_wedged_read",
93436 + .file = "drivers/gpu/drm/i915/i915_debugfs.c",
93437 + .param3 = 1,
93438 +};
93439 +
93440 +struct size_overflow_hash _001793_hash = {
93441 + .next = NULL,
93442 + .name = "i915_wedged_write",
93443 + .file = "drivers/gpu/drm/i915/i915_debugfs.c",
93444 + .param3 = 1,
93445 +};
93446 +
93447 +struct size_overflow_hash _001794_hash = {
93448 + .next = NULL,
93449 + .name = "__module_alloc",
93450 + .file = "arch/x86/kernel/module.c",
93451 + .param1 = 1,
93452 +};
93453 +
93454 +struct size_overflow_hash _001795_hash = {
93455 + .next = NULL,
93456 + .name = "module_alloc_update_bounds_rw",
93457 + .file = "kernel/module.c",
93458 + .param1 = 1,
93459 +};
93460 +
93461 +struct size_overflow_hash _001796_hash = {
93462 + .next = NULL,
93463 + .name = "module_alloc_update_bounds_rx",
93464 + .file = "kernel/module.c",
93465 + .param1 = 1,
93466 +};
93467 +
93468 +struct size_overflow_hash _001797_hash = {
93469 + .next = NULL,
93470 + .name = "p9_client_read",
93471 + .file = "include/net/9p/client.h",
93472 + .param5 = 1,
93473 +};
93474 +
93475 +struct size_overflow_hash _001798_hash = {
93476 + .next = NULL,
93477 + .name = "probe_kernel_write",
93478 + .file = "include/linux/uaccess.h",
93479 + .param3 = 1,
93480 +};
93481 +
93482 +struct size_overflow_hash _001799_hash = {
93483 + .next = NULL,
93484 + .name = "sched_feat_write",
93485 + .file = "kernel/sched/core.c",
93486 + .param3 = 1,
93487 +};
93488 +
93489 +struct size_overflow_hash _001800_hash = {
93490 + .next = NULL,
93491 + .name = "tstats_write",
93492 + .file = "kernel/time/timer_stats.c",
93493 + .param3 = 1,
93494 +};
93495 +
93496 +struct size_overflow_hash _001801_hash = {
93497 + .next = NULL,
93498 + .name = "ttm_bo_fbdev_io",
93499 + .file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
93500 + .param4 = 1,
93501 +};
93502 +
93503 +struct size_overflow_hash _001802_hash = {
93504 + .next = NULL,
93505 + .name = "ttm_bo_io",
93506 + .file = "drivers/gpu/drm/ttm/ttm_bo_vm.c",
93507 + .param5 = 1,
93508 +};
93509 +
93510 +struct size_overflow_hash _001803_hash = {
93511 + .next = NULL,
93512 + .name = "ttm_dma_page_pool_free",
93513 + .file = "drivers/gpu/drm/ttm/ttm_page_alloc_dma.c",
93514 + .param2 = 1,
93515 +};
93516 +
93517 +struct size_overflow_hash _001804_hash = {
93518 + .next = NULL,
93519 + .name = "ttm_page_pool_free",
93520 + .file = "drivers/gpu/drm/ttm/ttm_page_alloc.c",
93521 + .param2 = 1,
93522 +};
93523 +
93524 +struct size_overflow_hash _001805_hash = {
93525 + .next = NULL,
93526 + .name = "vmw_execbuf_process",
93527 + .file = "drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c",
93528 + .param5 = 1,
93529 +};
93530 +
93531 +struct size_overflow_hash _001806_hash = {
93532 + .next = NULL,
93533 + .name = "vmw_fifo_reserve",
93534 + .file = "drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c",
93535 + .param2 = 1,
93536 +};
93537 +
93538 +struct size_overflow_hash _001807_hash = {
93539 + .next = NULL,
93540 + .name = "vmw_kms_present",
93541 + .file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
93542 + .param9 = 1,
93543 +};
93544 +
93545 +struct size_overflow_hash _001808_hash = {
93546 + .next = NULL,
93547 + .name = "vmw_kms_readback",
93548 + .file = "drivers/gpu/drm/vmwgfx/vmwgfx_kms.c",
93549 + .param6 = 1,
93550 +};
93551 +
93552 +struct size_overflow_hash _001809_hash = {
93553 + .next = NULL,
93554 + .name = "acpi_system_write_alarm",
93555 + .file = "drivers/acpi/proc.c",
93556 + .param3 = 1,
93557 +};
93558 +
93559 +struct size_overflow_hash _001810_hash = {
93560 + .next = NULL,
93561 + .name = "kmalloc",
93562 + .file = "include/linux/slab_def.h",
93563 + .param1 = 1,
93564 +};
93565 +
93566 +struct size_overflow_hash _001811_hash = {
93567 + .next = NULL,
93568 + .name = "slabinfo_write",
93569 + .file = "mm/slab.c",
93570 + .param3 = 1,
93571 +};
93572 +
93573 +struct size_overflow_hash *size_overflow_hash[65536] = {
93574 + [56878] = &_000001_hash,
93575 + [11151] = &_000002_hash,
93576 + [17854] = &_000003_hash,
93577 + [4132] = &_000004_hash,
93578 + [39070] = &_000005_hash,
93579 + [35447] = &_000007_hash,
93580 + [47830] = &_000008_hash,
93581 + [65254] = &_000009_hash,
93582 + [17521] = &_000011_hash,
93583 + [41425] = &_000012_hash,
93584 + [5785] = &_000013_hash,
93585 + [19960] = &_000014_hash,
93586 + [26729] = &_000015_hash,
93587 + [7954] = &_000016_hash,
93588 + [22403] = &_000017_hash,
93589 + [23258] = &_000018_hash,
93590 + [55695] = &_000019_hash,
93591 + [38964] = &_000020_hash,
93592 + [64250] = &_000021_hash,
93593 + [31825] = &_000022_hash,
93594 + [47446] = &_000023_hash,
93595 + [61521] = &_000024_hash,
93596 + [64227] = &_000025_hash,
93597 + [53378] = &_000026_hash,
93598 + [8885] = &_000027_hash,
93599 + [62101] = &_000028_hash,
93600 + [18152] = &_000029_hash,
93601 + [37525] = &_000030_hash,
93602 + [25827] = &_000031_hash,
93603 + [1169] = &_000032_hash,
93604 + [11925] = &_000033_hash,
93605 + [20558] = &_000034_hash,
93606 + [44019] = &_000035_hash,
93607 + [21909] = &_000036_hash,
93608 + [63679] = &_000037_hash,
93609 + [39450] = &_000038_hash,
93610 + [25085] = &_000039_hash,
93611 + [17830] = &_000040_hash,
93612 + [14329] = &_000041_hash,
93613 + [31235] = &_000042_hash,
93614 + [48207] = &_000043_hash,
93615 + [34918] = &_000044_hash,
93616 + [46839] = &_000045_hash,
93617 + [57930] = &_000046_hash,
93618 + [41364] = &_000047_hash,
93619 + [17581] = &_000048_hash,
93620 + [45922] = &_000049_hash,
93621 + [49567] = &_000050_hash,
93622 + [18248] = &_000051_hash,
93623 + [25528] = &_000052_hash,
93624 + [61874] = &_000053_hash,
93625 + [22591] = &_000054_hash,
93626 + [48456] = &_000055_hash,
93627 + [8743] = &_000056_hash,
93628 + [39131] = &_000057_hash,
93629 + [48328] = &_000058_hash,
93630 + [47136] = &_000059_hash,
93631 + [6358] = &_000060_hash,
93632 + [12252] = &_000061_hash,
93633 + [49340] = &_000062_hash,
93634 + [45875] = &_000063_hash,
93635 + [52182] = &_000065_hash,
93636 + [31149] = &_000067_hash,
93637 + [20455] = &_000068_hash,
93638 + [19917] = &_000070_hash,
93639 + [64771] = &_000071_hash,
93640 + [25140] = &_000072_hash,
93641 + [34097] = &_000073_hash,
93642 + [58131] = &_000074_hash,
93643 + [65311] = &_000075_hash,
93644 + [60609] = &_000076_hash,
93645 + [1917] = &_000077_hash,
93646 + [15337] = &_000078_hash,
93647 + [4732] = &_000079_hash,
93648 + [38783] = &_000080_hash,
93649 + [37249] = &_000081_hash,
93650 + [9234] = &_000082_hash,
93651 + [33309] = &_000083_hash,
93652 + [22389] = &_000084_hash,
93653 + [56319] = &_000085_hash,
93654 + [21496] = &_000086_hash,
93655 + [8163] = &_000087_hash,
93656 + [58766] = &_000088_hash,
93657 + [21048] = &_000089_hash,
93658 + [51221] = &_000090_hash,
93659 + [21498] = &_000091_hash,
93660 + [42627] = &_000092_hash,
93661 + [53059] = &_000094_hash,
93662 + [52870] = &_000095_hash,
93663 + [1567] = &_000096_hash,
93664 + [38330] = &_000097_hash,
93665 + [30892] = &_000098_hash,
93666 + [16927] = &_000099_hash,
93667 + [16461] = &_000100_hash,
93668 + [5634] = &_000101_hash,
93669 + [16496] = &_000103_hash,
93670 + [40012] = &_000104_hash,
93671 + [46014] = &_000105_hash,
93672 + [39600] = &_000106_hash,
93673 + [7435] = &_000107_hash,
93674 + [13332] = &_000109_hash,
93675 + [36665] = &_000110_hash,
93676 + [12413] = &_000111_hash,
93677 + [27279] = &_000112_hash,
93678 + [44774] = &_000113_hash,
93679 + [14479] = &_000114_hash,
93680 + [32447] = &_000115_hash,
93681 + [15439] = &_000116_hash,
93682 + [17932] = &_000117_hash,
93683 + [26096] = &_000118_hash,
93684 + [50814] = &_000119_hash,
93685 + [22598] = &_000120_hash,
93686 + [48287] = &_000121_hash,
93687 + [15611] = &_000122_hash,
93688 + [13414] = &_000123_hash,
93689 + [40371] = &_000124_hash,
93690 + [284] = &_000125_hash,
93691 + [6293] = &_000127_hash,
93692 + [60587] = &_000128_hash,
93693 + [8181] = &_000129_hash,
93694 + [27451] = &_000130_hash,
93695 + [29259] = &_000131_hash,
93696 + [41172] = &_000132_hash,
93697 + [3315] = &_000133_hash,
93698 + [37550] = &_000134_hash,
93699 + [40395] = &_000135_hash,
93700 + [24124] = &_000136_hash,
93701 + [63535] = &_000137_hash,
93702 + [14981] = &_000138_hash,
93703 + [52008] = &_000139_hash,
93704 + [22091] = &_000140_hash,
93705 + [64800] = &_000141_hash,
93706 + [14919] = &_000142_hash,
93707 + [60340] = &_000143_hash,
93708 + [34205] = &_000145_hash,
93709 + [65246] = &_000146_hash,
93710 + [1299] = &_000147_hash,
93711 + [33165] = &_000148_hash,
93712 + [22394] = &_000149_hash,
93713 + [49562] = &_000150_hash,
93714 + [56881] = &_000151_hash,
93715 + [13870] = &_000152_hash,
93716 + [65074] = &_000153_hash,
93717 + [11553] = &_000154_hash,
93718 + [43222] = &_000155_hash,
93719 + [17984] = &_000156_hash,
93720 + [26811] = &_000157_hash,
93721 + [30848] = &_000158_hash,
93722 + [15627] = &_000159_hash,
93723 + [43101] = &_000160_hash,
93724 + [4082] = &_000161_hash,
93725 + [43692] = &_000162_hash,
93726 + [21622] = &_000163_hash,
93727 + [50734] = &_000164_hash,
93728 + [803] = &_000166_hash,
93729 + [64674] = &_000168_hash,
93730 + [57538] = &_000170_hash,
93731 + [42442] = &_000171_hash,
93732 + [23031] = &_000172_hash,
93733 + [40663] = &_000173_hash,
93734 + [51180] = &_000174_hash,
93735 + [24173] = &_000175_hash,
93736 + [9286] = &_000176_hash,
93737 + [49517] = &_000177_hash,
93738 + [34878] = &_000180_hash,
93739 + [22819] = &_000181_hash,
93740 + [64314] = &_000182_hash,
93741 + [20494] = &_000183_hash,
93742 + [9483] = &_000184_hash,
93743 + [26518] = &_000185_hash,
93744 + [44651] = &_000186_hash,
93745 + [1188] = &_000187_hash,
93746 + [36031] = &_000188_hash,
93747 + [33469] = &_000189_hash,
93748 + [19672] = &_000190_hash,
93749 + [3216] = &_000191_hash,
93750 + [25071] = &_000192_hash,
93751 + [11744] = &_000194_hash,
93752 + [2358] = &_000196_hash,
93753 + [10146] = &_000198_hash,
93754 + [58709] = &_000199_hash,
93755 + [64773] = &_000200_hash,
93756 + [6159] = &_000201_hash,
93757 + [28617] = &_000202_hash,
93758 + [61067] = &_000203_hash,
93759 + [12884] = &_000204_hash,
93760 + [37308] = &_000205_hash,
93761 + [59973] = &_000206_hash,
93762 + [35895] = &_000207_hash,
93763 + [24951] = &_000208_hash,
93764 + [3070] = &_000209_hash,
93765 + [61023] = &_000210_hash,
93766 + [45702] = &_000211_hash,
93767 + [5533] = &_000212_hash,
93768 + [29186] = &_000213_hash,
93769 + [26311] = &_000214_hash,
93770 + [40182] = &_000215_hash,
93771 + [50505] = &_000216_hash,
93772 + [59061] = &_000217_hash,
93773 + [27511] = &_000218_hash,
93774 + [63286] = &_000219_hash,
93775 + [6678] = &_000220_hash,
93776 + [23065] = &_000222_hash,
93777 + [18156] = &_000223_hash,
93778 + [53757] = &_000224_hash,
93779 + [53720] = &_000225_hash,
93780 + [50241] = &_000226_hash,
93781 + [22498] = &_000227_hash,
93782 + [10991] = &_000228_hash,
93783 + [40026] = &_000229_hash,
93784 + [19995] = &_000230_hash,
93785 + [30445] = &_000231_hash,
93786 + [57691] = &_000232_hash,
93787 + [23150] = &_000233_hash,
93788 + [9960] = &_000234_hash,
93789 + [8736] = &_000235_hash,
93790 + [23750] = &_000237_hash,
93791 + [18393] = &_000238_hash,
93792 + [28541] = &_000240_hash,
93793 + [59944] = &_000241_hash,
93794 + [35042] = &_000242_hash,
93795 + [63488] = &_000243_hash,
93796 + [27286] = &_000244_hash,
93797 + [46922] = &_000245_hash,
93798 + [11860] = &_000246_hash,
93799 + [52928] = &_000247_hash,
93800 + [46714] = &_000248_hash,
93801 + [57313] = &_000249_hash,
93802 + [61978] = &_000250_hash,
93803 + [61063] = &_000251_hash,
93804 + [22271] = &_000252_hash,
93805 + [4214] = &_000253_hash,
93806 + [46247] = &_000254_hash,
93807 + [33246] = &_000255_hash,
93808 + [58325] = &_000257_hash,
93809 + [47399] = &_000259_hash,
93810 + [34963] = &_000260_hash,
93811 + [21221] = &_000261_hash,
93812 + [32211] = &_000262_hash,
93813 + [20854] = &_000263_hash,
93814 + [49351] = &_000264_hash,
93815 + [52341] = &_000265_hash,
93816 + [53533] = &_000266_hash,
93817 + [52267] = &_000267_hash,
93818 + [46753] = &_000268_hash,
93819 + [2115] = &_000269_hash,
93820 + [44017] = &_000271_hash,
93821 + [13495] = &_000272_hash,
93822 + [12988] = &_000273_hash,
93823 + [55227] = &_000274_hash,
93824 + [47762] = &_000276_hash,
93825 + [17613] = &_000277_hash,
93826 + [52037] = &_000278_hash,
93827 + [5994] = &_000279_hash,
93828 + [46818] = &_000280_hash,
93829 + [13467] = &_000281_hash,
93830 + [61848] = &_000282_hash,
93831 + [43082] = &_000284_hash,
93832 + [55732] = &_000286_hash,
93833 + [2543] = &_000287_hash,
93834 + [51694] = &_000288_hash,
93835 + [18402] = &_000289_hash,
93836 + [38282] = &_000290_hash,
93837 + [5456] = &_000291_hash,
93838 + [58261] = &_000292_hash,
93839 + [24792] = &_000293_hash,
93840 + [6422] = &_000294_hash,
93841 + [63953] = &_000295_hash,
93842 + [27384] = &_000296_hash,
93843 + [47213] = &_000297_hash,
93844 + [23548] = &_000298_hash,
93845 + [47858] = &_000299_hash,
93846 + [52501] = &_000300_hash,
93847 + [12475] = &_000301_hash,
93848 + [52921] = &_000302_hash,
93849 + [19120] = &_000303_hash,
93850 + [14355] = &_000304_hash,
93851 + [30563] = &_000305_hash,
93852 + [14942] = &_000306_hash,
93853 + [30969] = &_000307_hash,
93854 + [57776] = &_000308_hash,
93855 + [21956] = &_000309_hash,
93856 + [44050] = &_000310_hash,
93857 + [2193] = &_000311_hash,
93858 + [44818] = &_000312_hash,
93859 + [50616] = &_000313_hash,
93860 + [49299] = &_000314_hash,
93861 + [2796] = &_000315_hash,
93862 + [4190] = &_000316_hash,
93863 + [11548] = &_000317_hash,
93864 + [53798] = &_000318_hash,
93865 + [60370] = &_000319_hash,
93866 + [35863] = &_000320_hash,
93867 + [54595] = &_000322_hash,
93868 + [2808] = &_000323_hash,
93869 + [24656] = &_000324_hash,
93870 + [895] = &_000325_hash,
93871 + [32809] = &_000326_hash,
93872 + [55621] = &_000327_hash,
93873 + [1733] = &_000328_hash,
93874 + [36069] = &_000330_hash,
93875 + [23714] = &_000331_hash,
93876 + [26020] = &_000332_hash,
93877 + [63875] = &_000333_hash,
93878 + [58608] = &_000334_hash,
93879 + [8919] = &_000335_hash,
93880 + [23906] = &_000336_hash,
93881 + [59497] = &_000337_hash,
93882 + [34782] = &_000338_hash,
93883 + [40998] = &_000339_hash,
93884 + [33328] = &_000340_hash,
93885 + [17866] = &_000341_hash,
93886 + [38741] = &_000342_hash,
93887 + [53939] = &_000343_hash,
93888 + [14658] = &_000344_hash,
93889 + [42465] = &_000345_hash,
93890 + [49600] = &_000346_hash,
93891 + [7391] = &_000347_hash,
93892 + [43616] = &_000348_hash,
93893 + [16775] = &_000349_hash,
93894 + [41393] = &_000350_hash,
93895 + [10532] = &_000351_hash,
93896 + [50366] = &_000352_hash,
93897 + [33324] = &_000353_hash,
93898 + [38200] = &_000354_hash,
93899 + [59315] = &_000355_hash,
93900 + [33916] = &_000356_hash,
93901 + [36593] = &_000357_hash,
93902 + [63079] = &_000358_hash,
93903 + [379] = &_000359_hash,
93904 + [34248] = &_000360_hash,
93905 + [27251] = &_000361_hash,
93906 + [29460] = &_000362_hash,
93907 + [7461] = &_000363_hash,
93908 + [9870] = &_000364_hash,
93909 + [44596] = &_000365_hash,
93910 + [45157] = &_000366_hash,
93911 + [55069] = &_000367_hash,
93912 + [29452] = &_000368_hash,
93913 + [54888] = &_000369_hash,
93914 + [31885] = &_000370_hash,
93915 + [20206] = &_000371_hash,
93916 + [59852] = &_000372_hash,
93917 + [20325] = &_000373_hash,
93918 + [18488] = &_000374_hash,
93919 + [22017] = &_000375_hash,
93920 + [57485] = &_000376_hash,
93921 + [49827] = &_000377_hash,
93922 + [37770] = &_000379_hash,
93923 + [52668] = &_000380_hash,
93924 + [13724] = &_000381_hash,
93925 + [59701] = &_000382_hash,
93926 + [11954] = &_000383_hash,
93927 + [9890] = &_000384_hash,
93928 + [17684] = &_000385_hash,
93929 + [18158] = &_000386_hash,
93930 + [61318] = &_000387_hash,
93931 + [2760] = &_000388_hash,
93932 + [38444] = &_000390_hash,
93933 + [55856] = &_000392_hash,
93934 + [34762] = &_000393_hash,
93935 + [48360] = &_000394_hash,
93936 + [40885] = &_000395_hash,
93937 + [36032] = &_000396_hash,
93938 + [52057] = &_000397_hash,
93939 + [12463] = &_000398_hash,
93940 + [30616] = &_000399_hash,
93941 + [38680] = &_000400_hash,
93942 + [41742] = &_000401_hash,
93943 + [50662] = &_000402_hash,
93944 + [48440] = &_000403_hash,
93945 + [34418] = &_000404_hash,
93946 + [64275] = &_000405_hash,
93947 + [12231] = &_000406_hash,
93948 + [53530] = &_000407_hash,
93949 + [54723] = &_000408_hash,
93950 + [19490] = &_000409_hash,
93951 + [11595] = &_000410_hash,
93952 + [15277] = &_000411_hash,
93953 + [4811] = &_000412_hash,
93954 + [42017] = &_000413_hash,
93955 + [17238] = &_000414_hash,
93956 + [55439] = &_000415_hash,
93957 + [45794] = &_000416_hash,
93958 + [60027] = &_000417_hash,
93959 + [3750] = &_000418_hash,
93960 + [11091] = &_000419_hash,
93961 + [32935] = &_000420_hash,
93962 + [22809] = &_000422_hash,
93963 + [60193] = &_000423_hash,
93964 + [14396] = &_000424_hash,
93965 + [18101] = &_000425_hash,
93966 + [46395] = &_000426_hash,
93967 + [24339] = &_000427_hash,
93968 + [26065] = &_000428_hash,
93969 + [43016] = &_000429_hash,
93970 + [41996] = &_000430_hash,
93971 + [7371] = &_000431_hash,
93972 + [32968] = &_000432_hash,
93973 + [53082] = &_000433_hash,
93974 + [38798] = &_000434_hash,
93975 + [12726] = &_000435_hash,
93976 + [55018] = &_000436_hash,
93977 + [26114] = &_000437_hash,
93978 + [31697] = &_000438_hash,
93979 + [21401] = &_000441_hash,
93980 + [33193] = &_000442_hash,
93981 + [52271] = &_000443_hash,
93982 + [20847] = &_000444_hash,
93983 + [30754] = &_000445_hash,
93984 + [54440] = &_000446_hash,
93985 + [22059] = &_000447_hash,
93986 + [47566] = &_000448_hash,
93987 + [22926] = &_000449_hash,
93988 + [20788] = &_000450_hash,
93989 + [18162] = &_000451_hash,
93990 + [65006] = &_000452_hash,
93991 + [11523] = &_000453_hash,
93992 + [29207] = &_000454_hash,
93993 + [18071] = &_000455_hash,
93994 + [7601] = &_000456_hash,
93995 + [12773] = &_000457_hash,
93996 + [61543] = &_000458_hash,
93997 + [5578] = &_000460_hash,
93998 + [49050] = &_000461_hash,
93999 + [51965] = &_000462_hash,
94000 + [6807] = &_000463_hash,
94001 + [22982] = &_000464_hash,
94002 + [36769] = &_000465_hash,
94003 + [53892] = &_000466_hash,
94004 + [2547] = &_000467_hash,
94005 + [53678] = &_000468_hash,
94006 + [61439] = &_000469_hash,
94007 + [31287] = &_000470_hash,
94008 + [6125] = &_000471_hash,
94009 + [57511] = &_000472_hash,
94010 + [13001] = &_000473_hash,
94011 + [62932] = &_000474_hash,
94012 + [62284] = &_000475_hash,
94013 + [9472] = &_000476_hash,
94014 + [26260] = &_000477_hash,
94015 + [63065] = &_000478_hash,
94016 + [18949] = &_000479_hash,
94017 + [29891] = &_000481_hash,
94018 + [41916] = &_000482_hash,
94019 + [40474] = &_000483_hash,
94020 + [63551] = &_000484_hash,
94021 + [36557] = &_000485_hash,
94022 + [2994] = &_000486_hash,
94023 + [5521] = &_000487_hash,
94024 + [51016] = &_000488_hash,
94025 + [7644] = &_000489_hash,
94026 + [55103] = &_000490_hash,
94027 + [11488] = &_000491_hash,
94028 + [7184] = &_000492_hash,
94029 + [36934] = &_000493_hash,
94030 + [54855] = &_000494_hash,
94031 + [63193] = &_000495_hash,
94032 + [12369] = &_000496_hash,
94033 + [15828] = &_000497_hash,
94034 + [61322] = &_000498_hash,
94035 + [5412] = &_000499_hash,
94036 + [28089] = &_000500_hash,
94037 + [64306] = &_000502_hash,
94038 + [24071] = &_000503_hash,
94039 + [50308] = &_000504_hash,
94040 + [38790] = &_000505_hash,
94041 + [9838] = &_000506_hash,
94042 + [18983] = &_000507_hash,
94043 + [9656] = &_000508_hash,
94044 + [18950] = &_000509_hash,
94045 + [59749] = &_000510_hash,
94046 + [20465] = &_000511_hash,
94047 + [4765] = &_000512_hash,
94048 + [16169] = &_000513_hash,
94049 + [6930] = &_000514_hash,
94050 + [16926] = &_000515_hash,
94051 + [35218] = &_000516_hash,
94052 + [19956] = &_000517_hash,
94053 + [55255] = &_000518_hash,
94054 + [861] = &_000519_hash,
94055 + [26574] = &_000520_hash,
94056 + [26794] = &_000521_hash,
94057 + [2133] = &_000522_hash,
94058 + [44616] = &_000523_hash,
94059 + [12840] = &_000524_hash,
94060 + [60426] = &_000525_hash,
94061 + [18133] = &_000526_hash,
94062 + [30479] = &_000527_hash,
94063 + [3219] = &_000528_hash,
94064 + [36488] = &_000529_hash,
94065 + [62043] = &_000530_hash,
94066 + [21714] = &_000532_hash,
94067 + [48007] = &_000533_hash,
94068 + [49969] = &_000534_hash,
94069 + [7701] = &_000535_hash,
94070 + [11521] = &_000536_hash,
94071 + [4269] = &_000537_hash,
94072 + [37627] = &_000539_hash,
94073 + [33555] = &_000540_hash,
94074 + [25900] = &_000541_hash,
94075 + [31709] = &_000542_hash,
94076 + [44626] = &_000544_hash,
94077 + [1679] = &_000545_hash,
94078 + [18349] = &_000546_hash,
94079 + [15338] = &_000547_hash,
94080 + [57935] = &_000548_hash,
94081 + [55850] = &_000549_hash,
94082 + [36063] = &_000550_hash,
94083 + [56674] = &_000551_hash,
94084 + [21379] = &_000552_hash,
94085 + [18507] = &_000553_hash,
94086 + [55719] = &_000554_hash,
94087 + [31210] = &_000555_hash,
94088 + [36207] = &_000556_hash,
94089 + [64180] = &_000557_hash,
94090 + [41770] = &_000558_hash,
94091 + [11600] = &_000559_hash,
94092 + [36638] = &_000560_hash,
94093 + [25576] = &_000561_hash,
94094 + [7000] = &_000562_hash,
94095 + [34187] = &_000563_hash,
94096 + [58533] = &_000564_hash,
94097 + [5083] = &_000565_hash,
94098 + [62614] = &_000566_hash,
94099 + [20085] = &_000567_hash,
94100 + [1135] = &_000568_hash,
94101 + [25613] = &_000569_hash,
94102 + [9541] = &_000570_hash,
94103 + [30577] = &_000571_hash,
94104 + [35722] = &_000572_hash,
94105 + [60407] = &_000573_hash,
94106 + [29465] = &_000574_hash,
94107 + [46891] = &_000575_hash,
94108 + [43633] = &_000576_hash,
94109 + [53743] = &_000577_hash,
94110 + [16196] = &_000578_hash,
94111 + [34425] = &_000580_hash,
94112 + [9646] = &_000581_hash,
94113 + [59756] = &_000583_hash,
94114 + [45524] = &_000584_hash,
94115 + [36702] = &_000585_hash,
94116 + [36747] = &_000586_hash,
94117 + [33643] = &_000588_hash,
94118 + [29158] = &_000589_hash,
94119 + [49662] = &_000590_hash,
94120 + [51062] = &_000591_hash,
94121 + [64755] = &_000592_hash,
94122 + [4829] = &_000594_hash,
94123 + [16413] = &_000595_hash,
94124 + [36125] = &_000596_hash,
94125 + [36293] = &_000597_hash,
94126 + [39712] = &_000598_hash,
94127 + [32160] = &_000599_hash,
94128 + [22962] = &_000600_hash,
94129 + [32001] = &_000601_hash,
94130 + [35828] = &_000602_hash,
94131 + [3106] = &_000603_hash,
94132 + [34039] = &_000604_hash,
94133 + [22393] = &_000605_hash,
94134 + [3560] = &_000606_hash,
94135 + [28195] = &_000607_hash,
94136 + [2062] = &_000608_hash,
94137 + [64001] = &_000609_hash,
94138 + [42407] = &_000610_hash,
94139 + [6253] = &_000611_hash,
94140 + [58640] = &_000612_hash,
94141 + [32195] = &_000613_hash,
94142 + [26197] = &_000614_hash,
94143 + [58003] = &_000615_hash,
94144 + [21662] = &_000616_hash,
94145 + [45750] = &_000617_hash,
94146 + [25798] = &_000618_hash,
94147 + [41052] = &_000619_hash,
94148 + [14096] = &_000620_hash,
94149 + [1439] = &_000621_hash,
94150 + [29074] = &_000622_hash,
94151 + [2376] = &_000623_hash,
94152 + [24068] = &_000625_hash,
94153 + [59519] = &_000627_hash,
94154 + [9893] = &_000628_hash,
94155 + [39979] = &_000630_hash,
94156 + [41540] = &_000631_hash,
94157 + [43200] = &_000633_hash,
94158 + [33494] = &_000634_hash,
94159 + [2028] = &_000635_hash,
94160 + [27206] = &_000636_hash,
94161 + [24302] = &_000637_hash,
94162 + [38112] = &_000638_hash,
94163 + [46538] = &_000639_hash,
94164 + [35228] = &_000641_hash,
94165 + [8339] = &_000642_hash,
94166 + [45349] = &_000643_hash,
94167 + [48404] = &_000644_hash,
94168 + [37865] = &_000645_hash,
94169 + [45763] = &_000646_hash,
94170 + [62347] = &_000647_hash,
94171 + [21644] = &_000648_hash,
94172 + [53135] = &_000649_hash,
94173 + [25095] = &_000650_hash,
94174 + [11697] = &_000651_hash,
94175 + [27003] = &_000652_hash,
94176 + [32464] = &_000653_hash,
94177 + [65339] = &_000654_hash,
94178 + [44248] = &_000655_hash,
94179 + [16] = &_000656_hash,
94180 + [29933] = &_000657_hash,
94181 + [34359] = &_000658_hash,
94182 + [3154] = &_000659_hash,
94183 + [59308] = &_000660_hash,
94184 + [61661] = &_000661_hash,
94185 + [23959] = &_000662_hash,
94186 + [6724] = &_000663_hash,
94187 + [54587] = &_000664_hash,
94188 + [28479] = &_000665_hash,
94189 + [56583] = &_000666_hash,
94190 + [64644] = &_000667_hash,
94191 + [23284] = &_000668_hash,
94192 + [61655] = &_000669_hash,
94193 + [20980] = &_000670_hash,
94194 + [19794] = &_000671_hash,
94195 + [30036] = &_000672_hash,
94196 + [25649] = &_000673_hash,
94197 + [47428] = &_000674_hash,
94198 + [47737] = &_000675_hash,
94199 + [8367] = &_000676_hash,
94200 + [2987] = &_000677_hash,
94201 + [50962] = &_000678_hash,
94202 + [10760] = &_000679_hash,
94203 + [31678] = &_000680_hash,
94204 + [48558] = &_000681_hash,
94205 + [2274] = &_000682_hash,
94206 + [831] = &_000683_hash,
94207 + [61833] = &_000684_hash,
94208 + [56864] = &_000685_hash,
94209 + [31040] = &_000686_hash,
94210 + [22196] = &_000687_hash,
94211 + [20076] = &_000688_hash,
94212 + [52821] = &_000689_hash,
94213 + [21896] = &_000690_hash,
94214 + [49367] = &_000691_hash,
94215 + [64731] = &_000692_hash,
94216 + [37110] = &_000693_hash,
94217 + [53694] = &_000694_hash,
94218 + [6175] = &_000695_hash,
94219 + [33048] = &_000696_hash,
94220 + [34746] = &_000697_hash,
94221 + [23777] = &_000698_hash,
94222 + [53828] = &_000699_hash,
94223 + [26539] = &_000700_hash,
94224 + [42628] = &_000701_hash,
94225 + [59115] = &_000702_hash,
94226 + [4456] = &_000703_hash,
94227 + [63619] = &_000704_hash,
94228 + [47329] = &_000705_hash,
94229 + [13534] = &_000706_hash,
94230 + [36955] = &_000707_hash,
94231 + [9841] = &_000708_hash,
94232 + [19308] = &_000709_hash,
94233 + [52439] = &_000710_hash,
94234 + [24680] = &_000711_hash,
94235 + [55652] = &_000712_hash,
94236 + [7842] = &_000713_hash,
94237 + [6500] = &_000714_hash,
94238 + [33485] = &_000715_hash,
94239 + [49920] = &_000716_hash,
94240 + [50750] = &_000717_hash,
94241 + [22318] = &_000718_hash,
94242 + [44599] = &_000719_hash,
94243 + [46403] = &_000720_hash,
94244 + [44534] = &_000721_hash,
94245 + [303] = &_000722_hash,
94246 + [22960] = &_000723_hash,
94247 + [10544] = &_000724_hash,
94248 + [8236] = &_000725_hash,
94249 + [21239] = &_000726_hash,
94250 + [24712] = &_000727_hash,
94251 + [37974] = &_000728_hash,
94252 + [62082] = &_000729_hash,
94253 + [57054] = &_000730_hash,
94254 + [53265] = &_000731_hash,
94255 + [52239] = &_000732_hash,
94256 + [14753] = &_000733_hash,
94257 + [60221] = &_000736_hash,
94258 + [27142] = &_000737_hash,
94259 + [14295] = &_000738_hash,
94260 + [25923] = &_000739_hash,
94261 + [29213] = &_000740_hash,
94262 + [31865] = &_000741_hash,
94263 + [4764] = &_000742_hash,
94264 + [10574] = &_000743_hash,
94265 + [55766] = &_000744_hash,
94266 + [22483] = &_000745_hash,
94267 + [61047] = &_000746_hash,
94268 + [41044] = &_000747_hash,
94269 + [58978] = &_000748_hash,
94270 + [47578] = &_000749_hash,
94271 + [7730] = &_000750_hash,
94272 + [15904] = &_000751_hash,
94273 + [25081] = &_000752_hash,
94274 + [45743] = &_000753_hash,
94275 + [58830] = &_000754_hash,
94276 + [59081] = &_000755_hash,
94277 + [47533] = &_000756_hash,
94278 + [11305] = &_000757_hash,
94279 + [29096] = &_000758_hash,
94280 + [19749] = &_000759_hash,
94281 + [56290] = &_000760_hash,
94282 + [44963] = &_000761_hash,
94283 + [30026] = &_000762_hash,
94284 + [27694] = &_000763_hash,
94285 + [8089] = &_000764_hash,
94286 + [38583] = &_000765_hash,
94287 + [1144] = &_000766_hash,
94288 + [20939] = &_000767_hash,
94289 + [22231] = &_000768_hash,
94290 + [17486] = &_000769_hash,
94291 + [51811] = &_000770_hash,
94292 + [62746] = &_000771_hash,
94293 + [19181] = &_000772_hash,
94294 + [52661] = &_000773_hash,
94295 + [51148] = &_000774_hash,
94296 + [49864] = &_000775_hash,
94297 + [37978] = &_000776_hash,
94298 + [6280] = &_000777_hash,
94299 + [12961] = &_000778_hash,
94300 + [60541] = &_000779_hash,
94301 + [37021] = &_000780_hash,
94302 + [26028] = &_000781_hash,
94303 + [41363] = &_000782_hash,
94304 + [42016] = &_000783_hash,
94305 + [58540] = &_000784_hash,
94306 + [2326] = &_000785_hash,
94307 + [60981] = &_000786_hash,
94308 + [13313] = &_000787_hash,
94309 + [44188] = &_000788_hash,
94310 + [34638] = &_000789_hash,
94311 + [20304] = &_000790_hash,
94312 + [60975] = &_000791_hash,
94313 + [12244] = &_000792_hash,
94314 + [16266] = &_000793_hash,
94315 + [3395] = &_000794_hash,
94316 + [63321] = &_000795_hash,
94317 + [20509] = &_000796_hash,
94318 + [57365] = &_000797_hash,
94319 + [47449] = &_000798_hash,
94320 + [56693] = &_000799_hash,
94321 + [33936] = &_000800_hash,
94322 + [52548] = &_000801_hash,
94323 + [18733] = &_000802_hash,
94324 + [15560] = &_000803_hash,
94325 + [13231] = &_000804_hash,
94326 + [64518] = &_000806_hash,
94327 + [54551] = &_000807_hash,
94328 + [54359] = &_000809_hash,
94329 + [46503] = &_000810_hash,
94330 + [22258] = &_000811_hash,
94331 + [39434] = &_000812_hash,
94332 + [52887] = &_000813_hash,
94333 + [3079] = &_000814_hash,
94334 + [18813] = &_000816_hash,
94335 + [47614] = &_000817_hash,
94336 + [38186] = &_000818_hash,
94337 + [57652] = &_000819_hash,
94338 + [10078] = &_000820_hash,
94339 + [17910] = &_000821_hash,
94340 + [13567] = &_000822_hash,
94341 + [21531] = &_000823_hash,
94342 + [46135] = &_000824_hash,
94343 + [10582] = &_000825_hash,
94344 + [4662] = &_000826_hash,
94345 + [17969] = &_000827_hash,
94346 + [43943] = &_000828_hash,
94347 + [46740] = &_000829_hash,
94348 + [26716] = &_000830_hash,
94349 + [58230] = &_000831_hash,
94350 + [252] = &_000832_hash,
94351 + [15704] = &_000833_hash,
94352 + [59765] = &_000834_hash,
94353 + [7322] = &_000835_hash,
94354 + [43950] = &_000836_hash,
94355 + [53093] = &_000837_hash,
94356 + [21646] = &_000838_hash,
94357 + [57063] = &_000839_hash,
94358 + [17132] = &_000840_hash,
94359 + [53922] = &_000842_hash,
94360 + [49155] = &_000843_hash,
94361 + [16356] = &_000844_hash,
94362 + [60037] = &_000845_hash,
94363 + [17299] = &_000846_hash,
94364 + [25678] = &_000847_hash,
94365 + [15494] = &_000848_hash,
94366 + [15159] = &_000849_hash,
94367 + [28442] = &_000850_hash,
94368 + [3514] = &_000851_hash,
94369 + [38151] = &_000852_hash,
94370 + [4173] = &_000853_hash,
94371 + [7258] = &_000854_hash,
94372 + [65109] = &_000855_hash,
94373 + [58827] = &_000856_hash,
94374 + [33575] = &_000857_hash,
94375 + [33078] = &_000858_hash,
94376 + [47234] = &_000859_hash,
94377 + [39193] = &_000860_hash,
94378 + [10950] = &_000861_hash,
94379 + [15613] = &_000862_hash,
94380 + [16046] = &_000863_hash,
94381 + [50172] = &_000864_hash,
94382 + [26107] = &_000865_hash,
94383 + [60543] = &_000866_hash,
94384 + [56337] = &_000867_hash,
94385 + [47626] = &_000868_hash,
94386 + [24409] = &_000869_hash,
94387 + [11732] = &_000870_hash,
94388 + [30010] = &_000871_hash,
94389 + [51480] = &_000872_hash,
94390 + [28518] = &_000873_hash,
94391 + [2061] = &_000874_hash,
94392 + [10885] = &_000875_hash,
94393 + [29517] = &_000876_hash,
94394 + [45913] = &_000877_hash,
94395 + [51774] = &_000878_hash,
94396 + [62298] = &_000879_hash,
94397 + [8892] = &_000880_hash,
94398 + [64891] = &_000881_hash,
94399 + [64537] = &_000882_hash,
94400 + [38103] = &_000883_hash,
94401 + [55518] = &_000884_hash,
94402 + [27419] = &_000885_hash,
94403 + [13869] = &_000886_hash,
94404 + [53150] = &_000887_hash,
94405 + [2884] = &_000888_hash,
94406 + [10362] = &_000889_hash,
94407 + [6961] = &_000890_hash,
94408 + [56975] = &_000891_hash,
94409 + [12508] = &_000892_hash,
94410 + [54597] = &_000893_hash,
94411 + [60499] = &_000894_hash,
94412 + [50109] = &_000895_hash,
94413 + [944] = &_000896_hash,
94414 + [29229] = &_000897_hash,
94415 + [37648] = &_000898_hash,
94416 + [1568] = &_000899_hash,
94417 + [61793] = &_000900_hash,
94418 + [53395] = &_000901_hash,
94419 + [5519] = &_000902_hash,
94420 + [28637] = &_000903_hash,
94421 + [53687] = &_000904_hash,
94422 + [6783] = &_000905_hash,
94423 + [43312] = &_000906_hash,
94424 + [2373] = &_000907_hash,
94425 + [33482] = &_000908_hash,
94426 + [24886] = &_000909_hash,
94427 + [48154] = &_000910_hash,
94428 + [12838] = &_000911_hash,
94429 + [47012] = &_000912_hash,
94430 + [23691] = &_000913_hash,
94431 + [37924] = &_000914_hash,
94432 + [47346] = &_000915_hash,
94433 + [5624] = &_000916_hash,
94434 + [16842] = &_000918_hash,
94435 + [60399] = &_000919_hash,
94436 + [2312] = &_000920_hash,
94437 + [59212] = &_000921_hash,
94438 + [11923] = &_000922_hash,
94439 + [10805] = &_000923_hash,
94440 + [36577] = &_000924_hash,
94441 + [60948] = &_000925_hash,
94442 + [21711] = &_000926_hash,
94443 + [54830] = &_000927_hash,
94444 + [1822] = &_000928_hash,
94445 + [44573] = &_000929_hash,
94446 + [23805] = &_000930_hash,
94447 + [46061] = &_000931_hash,
94448 + [33996] = &_000932_hash,
94449 + [40856] = &_000933_hash,
94450 + [16299] = &_000934_hash,
94451 + [63446] = &_000935_hash,
94452 + [31205] = &_000936_hash,
94453 + [33100] = &_000937_hash,
94454 + [40843] = &_000938_hash,
94455 + [23712] = &_000939_hash,
94456 + [36962] = &_000940_hash,
94457 + [9845] = &_000942_hash,
94458 + [13738] = &_000943_hash,
94459 + [58099] = &_000944_hash,
94460 + [31869] = &_000945_hash,
94461 + [63501] = &_000946_hash,
94462 + [58188] = &_000947_hash,
94463 + [51338] = &_000948_hash,
94464 + [54999] = &_000949_hash,
94465 + [2434] = &_000950_hash,
94466 + [34958] = &_000951_hash,
94467 + [41487] = &_000952_hash,
94468 + [11941] = &_000953_hash,
94469 + [56728] = &_000954_hash,
94470 + [48150] = &_000955_hash,
94471 + [13905] = &_000956_hash,
94472 + [9054] = &_000957_hash,
94473 + [10758] = &_000958_hash,
94474 + [48056] = &_000959_hash,
94475 + [24231] = &_000960_hash,
94476 + [43748] = &_000961_hash,
94477 + [24237] = &_000962_hash,
94478 + [14899] = &_000963_hash,
94479 + [38652] = &_000964_hash,
94480 + [65013] = &_000965_hash,
94481 + [16645] = &_000967_hash,
94482 + [55031] = &_000968_hash,
94483 + [23978] = &_000969_hash,
94484 + [24208] = &_000970_hash,
94485 + [18098] = &_000971_hash,
94486 + [2303] = &_000972_hash,
94487 + [3338] = &_000973_hash,
94488 + [39219] = &_000974_hash,
94489 + [18609] = &_000976_hash,
94490 + [64412] = &_000977_hash,
94491 + [16962] = &_000978_hash,
94492 + [26346] = &_000979_hash,
94493 + [39380] = &_000980_hash,
94494 + [33020] = &_000981_hash,
94495 + [22639] = &_000982_hash,
94496 + [6453] = &_000983_hash,
94497 + [58602] = &_000984_hash,
94498 + [50920] = &_000985_hash,
94499 + [56471] = &_000987_hash,
94500 + [15378] = &_000988_hash,
94501 + [3589] = &_000989_hash,
94502 + [12558] = &_000990_hash,
94503 + [3201] = &_000991_hash,
94504 + [28175] = &_000993_hash,
94505 + [43888] = &_000995_hash,
94506 + [56010] = &_000996_hash,
94507 + [32456] = &_000997_hash,
94508 + [29036] = &_000998_hash,
94509 + [32330] = &_000999_hash,
94510 + [25603] = &_001000_hash,
94511 + [17675] = &_001001_hash,
94512 + [36271] = &_001002_hash,
94513 + [49814] = &_001003_hash,
94514 + [5693] = &_001004_hash,
94515 + [51009] = &_001005_hash,
94516 + [62835] = &_001006_hash,
94517 + [27139] = &_001007_hash,
94518 + [45155] = &_001008_hash,
94519 + [17186] = &_001009_hash,
94520 + [46734] = &_001010_hash,
94521 + [61957] = &_001011_hash,
94522 + [51389] = &_001012_hash,
94523 + [23687] = &_001013_hash,
94524 + [46825] = &_001014_hash,
94525 + [52287] = &_001016_hash,
94526 + [31408] = &_001017_hash,
94527 + [5396] = &_001018_hash,
94528 + [62247] = &_001019_hash,
94529 + [7946] = &_001020_hash,
94530 + [58210] = &_001022_hash,
94531 + [15618] = &_001023_hash,
94532 + [61225] = &_001024_hash,
94533 + [13163] = &_001025_hash,
94534 + [36882] = &_001026_hash,
94535 + [8719] = &_001027_hash,
94536 + [8539] = &_001028_hash,
94537 + [27134] = &_001029_hash,
94538 + [53335] = &_001030_hash,
94539 + [30381] = &_001031_hash,
94540 + [32336] = &_001032_hash,
94541 + [32867] = &_001033_hash,
94542 + [1238] = &_001034_hash,
94543 + [8174] = &_001035_hash,
94544 + [6368] = &_001036_hash,
94545 + [29170] = &_001037_hash,
94546 + [9687] = &_001038_hash,
94547 + [61116] = &_001039_hash,
94548 + [31681] = &_001040_hash,
94549 + [22119] = &_001041_hash,
94550 + [59885] = &_001042_hash,
94551 + [47789] = &_001043_hash,
94552 + [5796] = &_001044_hash,
94553 + [43376] = &_001045_hash,
94554 + [36706] = &_001046_hash,
94555 + [47945] = &_001047_hash,
94556 + [33208] = &_001048_hash,
94557 + [55431] = &_001049_hash,
94558 + [25291] = &_001050_hash,
94559 + [58805] = &_001051_hash,
94560 + [23708] = &_001052_hash,
94561 + [29278] = &_001053_hash,
94562 + [1272] = &_001054_hash,
94563 + [10199] = &_001055_hash,
94564 + [34666] = &_001056_hash,
94565 + [49317] = &_001057_hash,
94566 + [18604] = &_001058_hash,
94567 + [42545] = &_001059_hash,
94568 + [33157] = &_001060_hash,
94569 + [53343] = &_001061_hash,
94570 + [64842] = &_001062_hash,
94571 + [61865] = &_001063_hash,
94572 + [54010] = &_001064_hash,
94573 + [64638] = &_001065_hash,
94574 + [20480] = &_001066_hash,
94575 + [23341] = &_001067_hash,
94576 + [10350] = &_001068_hash,
94577 + [30970] = &_001069_hash,
94578 + [62360] = &_001070_hash,
94579 + [52537] = &_001071_hash,
94580 + [51386] = &_001072_hash,
94581 + [48731] = &_001073_hash,
94582 + [58061] = &_001074_hash,
94583 + [40405] = &_001075_hash,
94584 + [57198] = &_001076_hash,
94585 + [19290] = &_001077_hash,
94586 + [60403] = &_001078_hash,
94587 + [2738] = &_001079_hash,
94588 + [59721] = &_001080_hash,
94589 + [24980] = &_001081_hash,
94590 + [55896] = &_001082_hash,
94591 + [57055] = &_001083_hash,
94592 + [46010] = &_001084_hash,
94593 + [712] = &_001085_hash,
94594 + [37747] = &_001086_hash,
94595 + [59996] = &_001087_hash,
94596 + [45219] = &_001088_hash,
94597 + [16917] = &_001089_hash,
94598 + [7415] = &_001090_hash,
94599 + [29576] = &_001091_hash,
94600 + [13584] = &_001092_hash,
94601 + [53364] = &_001093_hash,
94602 + [14813] = &_001094_hash,
94603 + [25543] = &_001095_hash,
94604 + [29240] = &_001096_hash,
94605 + [38748] = &_001097_hash,
94606 + [42270] = &_001098_hash,
94607 + [34848] = &_001099_hash,
94608 + [46226] = &_001100_hash,
94609 + [55526] = &_001101_hash,
94610 + [48271] = &_001102_hash,
94611 + [24658] = &_001104_hash,
94612 + [46964] = &_001105_hash,
94613 + [2637] = &_001106_hash,
94614 + [55601] = &_001107_hash,
94615 + [60275] = &_001108_hash,
94616 + [52645] = &_001109_hash,
94617 + [11712] = &_001110_hash,
94618 + [51364] = &_001111_hash,
94619 + [5106] = &_001112_hash,
94620 + [24710] = &_001113_hash,
94621 + [13101] = &_001114_hash,
94622 + [46963] = &_001115_hash,
94623 + [6779] = &_001116_hash,
94624 + [9237] = &_001117_hash,
94625 + [61524] = &_001118_hash,
94626 + [38247] = &_001119_hash,
94627 + [48715] = &_001120_hash,
94628 + [40797] = &_001121_hash,
94629 + [46780] = &_001122_hash,
94630 + [22071] = &_001123_hash,
94631 + [49735] = &_001125_hash,
94632 + [63925] = &_001126_hash,
94633 + [30902] = &_001127_hash,
94634 + [39828] = &_001128_hash,
94635 + [53089] = &_001129_hash,
94636 + [6394] = &_001130_hash,
94637 + [5116] = &_001131_hash,
94638 + [50702] = &_001132_hash,
94639 + [59565] = &_001133_hash,
94640 + [61042] = &_001134_hash,
94641 + [14533] = &_001135_hash,
94642 + [23807] = &_001136_hash,
94643 + [24296] = &_001137_hash,
94644 + [8808] = &_001138_hash,
94645 + [52383] = &_001139_hash,
94646 + [30487] = &_001140_hash,
94647 + [30125] = &_001141_hash,
94648 + [40665] = &_001142_hash,
94649 + [60809] = &_001143_hash,
94650 + [4842] = &_001144_hash,
94651 + [13955] = &_001145_hash,
94652 + [33237] = &_001146_hash,
94653 + [40673] = &_001147_hash,
94654 + [48026] = &_001148_hash,
94655 + [64033] = &_001149_hash,
94656 + [13879] = &_001150_hash,
94657 + [60114] = &_001151_hash,
94658 + [19472] = &_001152_hash,
94659 + [33552] = &_001153_hash,
94660 + [28575] = &_001154_hash,
94661 + [19696] = &_001155_hash,
94662 + [19742] = &_001156_hash,
94663 + [15286] = &_001157_hash,
94664 + [24629] = &_001158_hash,
94665 + [28382] = &_001159_hash,
94666 + [18962] = &_001160_hash,
94667 + [45796] = &_001161_hash,
94668 + [51632] = &_001162_hash,
94669 + [16907] = &_001163_hash,
94670 + [49336] = &_001164_hash,
94671 + [25316] = &_001165_hash,
94672 + [39978] = &_001166_hash,
94673 + [8091] = &_001167_hash,
94674 + [30680] = &_001168_hash,
94675 + [2066] = &_001169_hash,
94676 + [24271] = &_001170_hash,
94677 + [34934] = &_001171_hash,
94678 + [29208] = &_001172_hash,
94679 + [18591] = &_001173_hash,
94680 + [24373] = &_001174_hash,
94681 + [41485] = &_001175_hash,
94682 + [45487] = &_001176_hash,
94683 + [29299] = &_001177_hash,
94684 + [53920] = &_001178_hash,
94685 + [25407] = &_001179_hash,
94686 + [5525] = &_001180_hash,
94687 + [3531] = &_001181_hash,
94688 + [25143] = &_001182_hash,
94689 + [56046] = &_001183_hash,
94690 + [34693] = &_001184_hash,
94691 + [48644] = &_001185_hash,
94692 + [21226] = &_001186_hash,
94693 + [14051] = &_001187_hash,
94694 + [7715] = &_001188_hash,
94695 + [30413] = &_001189_hash,
94696 + [13681] = &_001190_hash,
94697 + [6554] = &_001191_hash,
94698 + [12228] = &_001192_hash,
94699 + [25497] = &_001193_hash,
94700 + [52228] = &_001194_hash,
94701 + [49069] = &_001195_hash,
94702 + [26961] = &_001196_hash,
94703 + [13768] = &_001197_hash,
94704 + [56185] = &_001198_hash,
94705 + [41838] = &_001199_hash,
94706 + [60119] = &_001200_hash,
94707 + [3112] = &_001201_hash,
94708 + [62001] = &_001202_hash,
94709 + [35888] = &_001203_hash,
94710 + [54718] = &_001206_hash,
94711 + [64177] = &_001207_hash,
94712 + [57222] = &_001208_hash,
94713 + [5260] = &_001209_hash,
94714 + [55517] = &_001210_hash,
94715 + [18186] = &_001211_hash,
94716 + [14257] = &_001212_hash,
94717 + [26846] = &_001213_hash,
94718 + [56097] = &_001214_hash,
94719 + [55151] = &_001215_hash,
94720 + [2999] = &_001216_hash,
94721 + [3602] = &_001217_hash,
94722 + [18460] = &_001218_hash,
94723 + [3507] = &_001219_hash,
94724 + [57847] = &_001220_hash,
94725 + [58077] = &_001221_hash,
94726 + [2659] = &_001222_hash,
94727 + [39846] = &_001223_hash,
94728 + [18629] = &_001224_hash,
94729 + [2723] = &_001225_hash,
94730 + [45230] = &_001226_hash,
94731 + [26941] = &_001227_hash,
94732 + [4344] = &_001228_hash,
94733 + [8487] = &_001229_hash,
94734 + [9901] = &_001230_hash,
94735 + [43061] = &_001231_hash,
94736 + [42551] = &_001232_hash,
94737 + [63272] = &_001233_hash,
94738 + [37771] = &_001234_hash,
94739 + [28261] = &_001235_hash,
94740 + [44694] = &_001236_hash,
94741 + [8573] = &_001237_hash,
94742 + [60174] = &_001238_hash,
94743 + [28040] = &_001239_hash,
94744 + [39423] = &_001240_hash,
94745 + [98] = &_001241_hash,
94746 + [62874] = &_001242_hash,
94747 + [38726] = &_001243_hash,
94748 + [55348] = &_001244_hash,
94749 + [10997] = &_001245_hash,
94750 + [88] = &_001246_hash,
94751 + [60639] = &_001247_hash,
94752 + [48159] = &_001248_hash,
94753 + [47899] = &_001249_hash,
94754 + [25367] = &_001250_hash,
94755 + [55681] = &_001251_hash,
94756 + [44716] = &_001252_hash,
94757 + [26161] = &_001253_hash,
94758 + [55347] = &_001254_hash,
94759 + [14518] = &_001255_hash,
94760 + [8887] = &_001256_hash,
94761 + [23009] = &_001257_hash,
94762 + [27962] = &_001258_hash,
94763 + [20004] = &_001259_hash,
94764 + [61750] = &_001260_hash,
94765 + [11661] = &_001261_hash,
94766 + [37118] = &_001262_hash,
94767 + [9370] = &_001263_hash,
94768 + [15099] = &_001264_hash,
94769 + [2404] = &_001265_hash,
94770 + [64074] = &_001266_hash,
94771 + [7538] = &_001267_hash,
94772 + [19736] = &_001268_hash,
94773 + [8199] = &_001269_hash,
94774 + [40711] = &_001270_hash,
94775 + [47859] = &_001271_hash,
94776 + [53925] = &_001272_hash,
94777 + [46888] = &_001273_hash,
94778 + [21783] = &_001274_hash,
94779 + [37305] = &_001275_hash,
94780 + [18414] = &_001276_hash,
94781 + [62423] = &_001277_hash,
94782 + [30371] = &_001278_hash,
94783 + [32617] = &_001279_hash,
94784 + [14530] = &_001281_hash,
94785 + [48623] = &_001282_hash,
94786 + [12845] = &_001283_hash,
94787 + [8895] = &_001284_hash,
94788 + [33661] = &_001285_hash,
94789 + [23178] = &_001286_hash,
94790 + [54706] = &_001287_hash,
94791 + [27133] = &_001288_hash,
94792 + [52745] = &_001289_hash,
94793 + [64420] = &_001290_hash,
94794 + [25617] = &_001291_hash,
94795 + [25414] = &_001292_hash,
94796 + [20445] = &_001293_hash,
94797 + [64006] = &_001294_hash,
94798 + [52646] = &_001295_hash,
94799 + [30281] = &_001296_hash,
94800 + [3761] = &_001297_hash,
94801 + [44345] = &_001298_hash,
94802 + [14713] = &_001299_hash,
94803 + [26043] = &_001300_hash,
94804 + [41679] = &_001301_hash,
94805 + [6267] = &_001302_hash,
94806 + [22247] = &_001304_hash,
94807 + [9440] = &_001305_hash,
94808 + [54676] = &_001306_hash,
94809 + [53982] = &_001308_hash,
94810 + [9467] = &_001309_hash,
94811 + [53419] = &_001310_hash,
94812 + [1424] = &_001311_hash,
94813 + [17561] = &_001312_hash,
94814 + [28161] = &_001313_hash,
94815 + [57262] = &_001314_hash,
94816 + [61071] = &_001315_hash,
94817 + [20067] = &_001316_hash,
94818 + [34321] = &_001317_hash,
94819 + [56199] = &_001318_hash,
94820 + [29070] = &_001319_hash,
94821 + [15698] = &_001320_hash,
94822 + [14173] = &_001321_hash,
94823 + [41224] = &_001322_hash,
94824 + [56438] = &_001323_hash,
94825 + [41894] = &_001324_hash,
94826 + [20885] = &_001325_hash,
94827 + [23275] = &_001326_hash,
94828 + [45043] = &_001327_hash,
94829 + [22143] = &_001328_hash,
94830 + [38029] = &_001329_hash,
94831 + [55343] = &_001330_hash,
94832 + [40624] = &_001331_hash,
94833 + [26476] = &_001332_hash,
94834 + [43128] = &_001333_hash,
94835 + [45115] = &_001334_hash,
94836 + [32958] = &_001335_hash,
94837 + [43091] = &_001336_hash,
94838 + [33299] = &_001337_hash,
94839 + [55021] = &_001338_hash,
94840 + [5509] = &_001339_hash,
94841 + [53012] = &_001340_hash,
94842 + [57849] = &_001341_hash,
94843 + [63282] = &_001342_hash,
94844 + [27883] = &_001343_hash,
94845 + [1670] = &_001344_hash,
94846 + [24095] = &_001345_hash,
94847 + [47810] = &_001346_hash,
94848 + [40759] = &_001347_hash,
94849 + [42139] = &_001348_hash,
94850 + [50484] = &_001349_hash,
94851 + [2305] = &_001350_hash,
94852 + [59832] = &_001351_hash,
94853 + [17662] = &_001352_hash,
94854 + [58943] = &_001353_hash,
94855 + [37417] = &_001356_hash,
94856 + [25127] = &_001357_hash,
94857 + [15006] = &_001358_hash,
94858 + [54292] = &_001359_hash,
94859 + [30642] = &_001360_hash,
94860 + [39939] = &_001361_hash,
94861 + [34818] = &_001362_hash,
94862 + [23378] = &_001363_hash,
94863 + [24090] = &_001364_hash,
94864 + [11111] = &_001365_hash,
94865 + [64141] = &_001366_hash,
94866 + [46457] = &_001367_hash,
94867 + [57927] = &_001368_hash,
94868 + [58877] = &_001371_hash,
94869 + [13880] = &_001372_hash,
94870 + [62888] = &_001373_hash,
94871 + [57962] = &_001374_hash,
94872 + [9117] = &_001375_hash,
94873 + [52012] = &_001376_hash,
94874 + [49246] = &_001377_hash,
94875 + [52701] = &_001378_hash,
94876 + [29857] = &_001379_hash,
94877 + [49420] = &_001380_hash,
94878 + [45897] = &_001381_hash,
94879 + [15141] = &_001382_hash,
94880 + [24177] = &_001383_hash,
94881 + [10325] = &_001384_hash,
94882 + [52861] = &_001385_hash,
94883 + [28922] = &_001386_hash,
94884 + [31089] = &_001387_hash,
94885 + [63084] = &_001388_hash,
94886 + [26245] = &_001389_hash,
94887 + [60000] = &_001390_hash,
94888 + [56935] = &_001391_hash,
94889 + [37569] = &_001392_hash,
94890 + [6446] = &_001394_hash,
94891 + [35883] = &_001395_hash,
94892 + [9123] = &_001396_hash,
94893 + [51457] = &_001397_hash,
94894 + [1787] = &_001398_hash,
94895 + [10135] = &_001399_hash,
94896 + [952] = &_001400_hash,
94897 + [53578] = &_001401_hash,
94898 + [9923] = &_001402_hash,
94899 + [45249] = &_001403_hash,
94900 + [52860] = &_001404_hash,
94901 + [29558] = &_001405_hash,
94902 + [40556] = &_001406_hash,
94903 + [53210] = &_001407_hash,
94904 + [2506] = &_001408_hash,
94905 + [48262] = &_001409_hash,
94906 + [46939] = &_001410_hash,
94907 + [17901] = &_001411_hash,
94908 + [27204] = &_001412_hash,
94909 + [52516] = &_001413_hash,
94910 + [55885] = &_001414_hash,
94911 + [6681] = &_001415_hash,
94912 + [42360] = &_001416_hash,
94913 + [20259] = &_001417_hash,
94914 + [8874] = &_001418_hash,
94915 + [53363] = &_001419_hash,
94916 + [17500] = &_001420_hash,
94917 + [63988] = &_001421_hash,
94918 + [26378] = &_001422_hash,
94919 + [7768] = &_001423_hash,
94920 + [12938] = &_001424_hash,
94921 + [6755] = &_001425_hash,
94922 + [43806] = &_001426_hash,
94923 + [15976] = &_001427_hash,
94924 + [2732] = &_001428_hash,
94925 + [2519] = &_001429_hash,
94926 + [14340] = &_001430_hash,
94927 + [34772] = &_001431_hash,
94928 + [36433] = &_001432_hash,
94929 + [16068] = &_001433_hash,
94930 + [22052] = &_001434_hash,
94931 + [8929] = &_001435_hash,
94932 + [63220] = &_001436_hash,
94933 + [18246] = &_001437_hash,
94934 + [37678] = &_001438_hash,
94935 + [4932] = &_001439_hash,
94936 + [46960] = &_001440_hash,
94937 + [16909] = &_001441_hash,
94938 + [44429] = &_001442_hash,
94939 + [59514] = &_001443_hash,
94940 + [62760] = &_001444_hash,
94941 + [41841] = &_001445_hash,
94942 + [25417] = &_001446_hash,
94943 + [63230] = &_001447_hash,
94944 + [39532] = &_001448_hash,
94945 + [24688] = &_001449_hash,
94946 + [18555] = &_001450_hash,
94947 + [54499] = &_001451_hash,
94948 + [10719] = &_001452_hash,
94949 + [1644] = &_001453_hash,
94950 + [15109] = &_001454_hash,
94951 + [15787] = &_001455_hash,
94952 + [57869] = &_001456_hash,
94953 + [54445] = &_001457_hash,
94954 + [19398] = &_001458_hash,
94955 + [9488] = &_001459_hash,
94956 + [12587] = &_001460_hash,
94957 + [17124] = &_001461_hash,
94958 + [53665] = &_001462_hash,
94959 + [40386] = &_001463_hash,
94960 + [39444] = &_001464_hash,
94961 + [28873] = &_001465_hash,
94962 + [11290] = &_001466_hash,
94963 + [51313] = &_001467_hash,
94964 + [23354] = &_001469_hash,
94965 + [49559] = &_001470_hash,
94966 + [49312] = &_001471_hash,
94967 + [36333] = &_001472_hash,
94968 + [59349] = &_001473_hash,
94969 + [60316] = &_001474_hash,
94970 + [2546] = &_001475_hash,
94971 + [57483] = &_001476_hash,
94972 + [14569] = &_001478_hash,
94973 + [61842] = &_001481_hash,
94974 + [32923] = &_001482_hash,
94975 + [57471] = &_001483_hash,
94976 + [83] = &_001484_hash,
94977 + [40242] = &_001485_hash,
94978 + [42578] = &_001486_hash,
94979 + [62037] = &_001487_hash,
94980 + [8131] = &_001488_hash,
94981 + [752] = &_001489_hash,
94982 + [56376] = &_001490_hash,
94983 + [22290] = &_001491_hash,
94984 + [46232] = &_001492_hash,
94985 + [35132] = &_001493_hash,
94986 + [23825] = &_001494_hash,
94987 + [43262] = &_001495_hash,
94988 + [8138] = &_001496_hash,
94989 + [31489] = &_001497_hash,
94990 + [57578] = &_001498_hash,
94991 + [28007] = &_001499_hash,
94992 + [28688] = &_001500_hash,
94993 + [19319] = &_001501_hash,
94994 + [12575] = &_001502_hash,
94995 + [62762] = &_001504_hash,
94996 + [47450] = &_001505_hash,
94997 + [1869] = &_001506_hash,
94998 + [51225] = &_001507_hash,
94999 + [19561] = &_001508_hash,
95000 + [64894] = &_001509_hash,
95001 + [6829] = &_001510_hash,
95002 + [30644] = &_001511_hash,
95003 + [63391] = &_001512_hash,
95004 + [11655] = &_001514_hash,
95005 + [28229] = &_001515_hash,
95006 + [22382] = &_001516_hash,
95007 + [22649] = &_001517_hash,
95008 + [42619] = &_001518_hash,
95009 + [19761] = &_001519_hash,
95010 + [56990] = &_001520_hash,
95011 + [19531] = &_001521_hash,
95012 + [26514] = &_001522_hash,
95013 + [56773] = &_001523_hash,
95014 + [15563] = &_001524_hash,
95015 + [26212] = &_001525_hash,
95016 + [29203] = &_001526_hash,
95017 + [32768] = &_001527_hash,
95018 + [15110] = &_001528_hash,
95019 + [3885] = &_001529_hash,
95020 + [13788] = &_001530_hash,
95021 + [27875] = &_001531_hash,
95022 + [54959] = &_001532_hash,
95023 + [20945] = &_001533_hash,
95024 + [59640] = &_001534_hash,
95025 + [4693] = &_001535_hash,
95026 + [13793] = &_001536_hash,
95027 + [25659] = &_001537_hash,
95028 + [18734] = &_001538_hash,
95029 + [17869] = &_001539_hash,
95030 + [26270] = &_001540_hash,
95031 + [18458] = &_001541_hash,
95032 + [58468] = &_001542_hash,
95033 + [61257] = &_001543_hash,
95034 + [39946] = &_001544_hash,
95035 + [52382] = &_001545_hash,
95036 + [18428] = &_001546_hash,
95037 + [31069] = &_001547_hash,
95038 + [61614] = &_001548_hash,
95039 + [60044] = &_001549_hash,
95040 + [36818] = &_001550_hash,
95041 + [54353] = &_001551_hash,
95042 + [55994] = &_001552_hash,
95043 + [65142] = &_001553_hash,
95044 + [1664] = &_001554_hash,
95045 + [32212] = &_001555_hash,
95046 + [63087] = &_001556_hash,
95047 + [29916] = &_001557_hash,
95048 + [54912] = &_001558_hash,
95049 + [10318] = &_001559_hash,
95050 + [44031] = &_001560_hash,
95051 + [50108] = &_001561_hash,
95052 + [57812] = &_001562_hash,
95053 + [63190] = &_001563_hash,
95054 + [48246] = &_001564_hash,
95055 + [3744] = &_001565_hash,
95056 + [56321] = &_001566_hash,
95057 + [42691] = &_001567_hash,
95058 + [62052] = &_001568_hash,
95059 + [21999] = &_001569_hash,
95060 + [13672] = &_001570_hash,
95061 + [20648] = &_001571_hash,
95062 + [42500] = &_001572_hash,
95063 + [22795] = &_001573_hash,
95064 + [19496] = &_001574_hash,
95065 + [35556] = &_001575_hash,
95066 + [57144] = &_001576_hash,
95067 + [1019] = &_001577_hash,
95068 + [28818] = &_001578_hash,
95069 + [52880] = &_001579_hash,
95070 + [6543] = &_001580_hash,
95071 + [18895] = &_001581_hash,
95072 + [857] = &_001582_hash,
95073 + [45966] = &_001583_hash,
95074 + [11785] = &_001584_hash,
95075 + [7736] = &_001585_hash,
95076 + [4308] = &_001586_hash,
95077 + [51095] = &_001587_hash,
95078 + [12101] = &_001588_hash,
95079 + [427] = &_001589_hash,
95080 + [4021] = &_001590_hash,
95081 + [54201] = &_001591_hash,
95082 + [5615] = &_001592_hash,
95083 + [16234] = &_001593_hash,
95084 + [51718] = &_001594_hash,
95085 + [42390] = &_001595_hash,
95086 + [55391] = &_001596_hash,
95087 + [28539] = &_001597_hash,
95088 + [943] = &_001598_hash,
95089 + [32683] = &_001599_hash,
95090 + [39182] = &_001600_hash,
95091 + [33198] = &_001601_hash,
95092 + [39446] = &_001602_hash,
95093 + [16394] = &_001603_hash,
95094 + [30791] = &_001604_hash,
95095 + [35530] = &_001605_hash,
95096 + [53193] = &_001607_hash,
95097 + [39401] = &_001608_hash,
95098 + [28624] = &_001609_hash,
95099 + [12066] = &_001610_hash,
95100 + [63492] = &_001611_hash,
95101 + [14897] = &_001612_hash,
95102 + [29641] = &_001613_hash,
95103 + [10165] = &_001614_hash,
95104 + [60046] = &_001615_hash,
95105 + [12429] = &_001616_hash,
95106 + [32788] = &_001617_hash,
95107 + [52698] = &_001618_hash,
95108 + [13130] = &_001620_hash,
95109 + [28643] = &_001621_hash,
95110 + [50666] = &_001622_hash,
95111 + [35126] = &_001623_hash,
95112 + [33593] = &_001624_hash,
95113 + [27547] = &_001625_hash,
95114 + [5484] = &_001626_hash,
95115 + [26642] = &_001627_hash,
95116 + [25586] = &_001628_hash,
95117 + [58757] = &_001629_hash,
95118 + [18701] = &_001630_hash,
95119 + [26271] = &_001631_hash,
95120 + [23829] = &_001632_hash,
95121 + [63659] = &_001634_hash,
95122 + [26603] = &_001635_hash,
95123 + [25704] = &_001636_hash,
95124 + [21149] = &_001637_hash,
95125 + [36900] = &_001638_hash,
95126 + [61577] = &_001640_hash,
95127 + [54095] = &_001641_hash,
95128 + [31650] = &_001642_hash,
95129 + [48970] = &_001643_hash,
95130 + [49357] = &_001644_hash,
95131 + [33835] = &_001645_hash,
95132 + [46861] = &_001646_hash,
95133 + [1428] = &_001647_hash,
95134 + [36247] = &_001648_hash,
95135 + [21600] = &_001649_hash,
95136 + [24747] = &_001650_hash,
95137 + [51012] = &_001651_hash,
95138 + [38974] = &_001653_hash,
95139 + [30549] = &_001655_hash,
95140 + [40146] = &_001656_hash,
95141 + [41756] = &_001657_hash,
95142 + [37010] = &_001658_hash,
95143 + [35072] = &_001660_hash,
95144 + [2114] = &_001661_hash,
95145 + [48424] = &_001662_hash,
95146 + [61522] = &_001663_hash,
95147 + [50633] = &_001664_hash,
95148 + [2283] = &_001665_hash,
95149 + [61763] = &_001666_hash,
95150 + [48195] = &_001667_hash,
95151 + [31000] = &_001668_hash,
95152 + [23856] = &_001669_hash,
95153 + [37421] = &_001670_hash,
95154 + [10019] = &_001672_hash,
95155 + [5148] = &_001673_hash,
95156 + [14363] = &_001674_hash,
95157 + [57354] = &_001675_hash,
95158 + [62460] = &_001676_hash,
95159 + [45174] = &_001677_hash,
95160 + [31054] = &_001678_hash,
95161 + [62195] = &_001679_hash,
95162 + [14976] = &_001680_hash,
95163 + [55676] = &_001681_hash,
95164 + [1025] = &_001682_hash,
95165 + [6921] = &_001683_hash,
95166 + [22158] = &_001684_hash,
95167 + [18050] = &_001685_hash,
95168 + [18612] = &_001686_hash,
95169 + [31107] = &_001687_hash,
95170 + [45212] = &_001688_hash,
95171 + [29599] = &_001689_hash,
95172 + [30827] = &_001690_hash,
95173 + [25086] = &_001691_hash,
95174 + [27146] = &_001692_hash,
95175 + [2467] = &_001693_hash,
95176 + [45786] = &_001694_hash,
95177 + [51909] = &_001695_hash,
95178 + [64604] = &_001696_hash,
95179 + [57819] = &_001697_hash,
95180 + [11001] = &_001698_hash,
95181 + [20326] = &_001699_hash,
95182 + [12682] = &_001700_hash,
95183 + [28932] = &_001701_hash,
95184 + [53491] = &_001702_hash,
95185 + [63894] = &_001703_hash,
95186 + [51191] = &_001704_hash,
95187 + [59759] = &_001705_hash,
95188 + [15691] = &_001706_hash,
95189 + [38786] = &_001707_hash,
95190 + [51546] = &_001708_hash,
95191 + [10121] = &_001709_hash,
95192 + [60786] = &_001710_hash,
95193 + [19952] = &_001712_hash,
95194 + [7271] = &_001715_hash,
95195 + [10729] = &_001716_hash,
95196 + [28883] = &_001717_hash,
95197 + [52042] = &_001718_hash,
95198 + [49606] = &_001719_hash,
95199 + [33243] = &_001720_hash,
95200 + [57341] = &_001721_hash,
95201 + [7978] = &_001722_hash,
95202 + [36330] = &_001723_hash,
95203 + [39035] = &_001724_hash,
95204 + [34498] = &_001725_hash,
95205 + [19789] = &_001726_hash,
95206 + [55685] = &_001727_hash,
95207 + [55419] = &_001728_hash,
95208 + [27798] = &_001729_hash,
95209 + [54599] = &_001730_hash,
95210 + [65522] = &_001731_hash,
95211 + [38111] = &_001732_hash,
95212 + [57077] = &_001733_hash,
95213 + [53053] = &_001734_hash,
95214 + [14190] = &_001735_hash,
95215 + [47037] = &_001736_hash,
95216 + [33296] = &_001737_hash,
95217 + [23803] = &_001738_hash,
95218 + [48773] = &_001739_hash,
95219 + [63014] = &_001740_hash,
95220 + [64392] = &_001741_hash,
95221 + [44203] = &_001742_hash,
95222 + [47717] = &_001743_hash,
95223 + [38399] = &_001744_hash,
95224 + [30385] = &_001745_hash,
95225 + [61693] = &_001746_hash,
95226 + [32049] = &_001747_hash,
95227 + [26133] = &_001748_hash,
95228 + [45038] = &_001749_hash,
95229 + [8582] = &_001751_hash,
95230 + [38182] = &_001753_hash,
95231 + [62457] = &_001754_hash,
95232 + [27937] = &_001755_hash,
95233 + [3795] = &_001756_hash,
95234 + [23228] = &_001757_hash,
95235 + [56511] = &_001758_hash,
95236 + [47807] = &_001759_hash,
95237 + [60528] = &_001760_hash,
95238 + [51858] = &_001761_hash,
95239 + [49183] = &_001762_hash,
95240 + [33807] = &_001763_hash,
95241 + [34791] = &_001764_hash,
95242 + [8150] = &_001765_hash,
95243 + [19691] = &_001767_hash,
95244 + [20519] = &_001770_hash,
95245 + [17144] = &_001771_hash,
95246 + [14000] = &_001772_hash,
95247 + [31148] = &_001773_hash,
95248 + [62594] = &_001774_hash,
95249 + [39210] = &_001775_hash,
95250 + [2077] = &_001776_hash,
95251 + [23497] = &_001777_hash,
95252 + [34512] = &_001778_hash,
95253 + [16268] = &_001780_hash,
95254 + [14562] = &_001781_hash,
95255 + [17606] = &_001783_hash,
95256 + [25654] = &_001784_hash,
95257 + [56078] = &_001785_hash,
95258 + [61088] = &_001786_hash,
95259 + [53442] = &_001787_hash,
95260 + [54456] = &_001788_hash,
95261 + [22038] = &_001789_hash,
95262 + [58394] = &_001790_hash,
95263 + [38953] = &_001791_hash,
95264 + [16109] = &_001792_hash,
95265 + [3812] = &_001793_hash,
95266 + [5084] = &_001794_hash,
95267 + [41893] = &_001795_hash,
95268 + [45486] = &_001796_hash,
95269 + [50226] = &_001797_hash,
95270 + [63694] = &_001798_hash,
95271 + [56763] = &_001799_hash,
95272 + [20905] = &_001800_hash,
95273 + [13080] = &_001801_hash,
95274 + [54700] = &_001802_hash,
95275 + [40947] = &_001803_hash,
95276 + [32645] = &_001804_hash,
95277 + [57462] = &_001805_hash,
95278 + [33853] = &_001806_hash,
95279 + [57940] = &_001807_hash,
95280 + [45583] = &_001808_hash,
95281 + [14237] = &_001809_hash,
95282 + [27495] = &_001810_hash,
95283 + [12489] = &_001811_hash,
95284 +};
95285 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
95286 new file mode 100644
95287 index 0000000..92b8ee6
95288 --- /dev/null
95289 +++ b/tools/gcc/size_overflow_plugin.c
95290 @@ -0,0 +1,1188 @@
95291 +/*
95292 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
95293 + * Licensed under the GPL v2, or (at your option) v3
95294 + *
95295 + * Homepage:
95296 + * http://www.grsecurity.net/~ephox/overflow_plugin/
95297 + *
95298 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
95299 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
95300 + * The recomputed argument is checked against INT_MAX and an event is logged on overflow and the triggering process is killed.
95301 + *
95302 + * Usage:
95303 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o size_overflow_plugin.so size_overflow_plugin.c
95304 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
95305 + */
95306 +
95307 +#include "gcc-plugin.h"
95308 +#include "config.h"
95309 +#include "system.h"
95310 +#include "coretypes.h"
95311 +#include "tree.h"
95312 +#include "tree-pass.h"
95313 +#include "intl.h"
95314 +#include "plugin-version.h"
95315 +#include "tm.h"
95316 +#include "toplev.h"
95317 +#include "function.h"
95318 +#include "tree-flow.h"
95319 +#include "plugin.h"
95320 +#include "gimple.h"
95321 +#include "c-common.h"
95322 +#include "diagnostic.h"
95323 +#include "cfgloop.h"
95324 +
95325 +struct size_overflow_hash {
95326 + struct size_overflow_hash *next;
95327 + const char *name;
95328 + const char *file;
95329 + unsigned short param1:1;
95330 + unsigned short param2:1;
95331 + unsigned short param3:1;
95332 + unsigned short param4:1;
95333 + unsigned short param5:1;
95334 + unsigned short param6:1;
95335 + unsigned short param7:1;
95336 + unsigned short param8:1;
95337 + unsigned short param9:1;
95338 +};
95339 +
95340 +#include "size_overflow_hash.h"
95341 +
95342 +#define __unused __attribute__((__unused__))
95343 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
95344 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
95345 +#define BEFORE_STMT true
95346 +#define AFTER_STMT false
95347 +#define CREATE_NEW_VAR NULL_TREE
95348 +
95349 +int plugin_is_GPL_compatible;
95350 +void debug_gimple_stmt(gimple gs);
95351 +
95352 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var);
95353 +static tree signed_size_overflow_type;
95354 +static tree unsigned_size_overflow_type;
95355 +static tree report_size_overflow_decl;
95356 +static tree const_char_ptr_type_node;
95357 +static unsigned int handle_function(void);
95358 +static bool file_match = true;
95359 +
95360 +static struct plugin_info size_overflow_plugin_info = {
95361 + .version = "20120521beta",
95362 + .help = "no-size_overflow\tturn off size overflow checking\n",
95363 +};
95364 +
95365 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
95366 +{
95367 + unsigned int arg_count = type_num_arguments(*node);
95368 +
95369 + for (; args; args = TREE_CHAIN(args)) {
95370 + tree position = TREE_VALUE(args);
95371 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
95372 + error("handle_size_overflow_attribute: overflow parameter outside range.");
95373 + *no_add_attrs = true;
95374 + }
95375 + }
95376 + return NULL_TREE;
95377 +}
95378 +
95379 +static struct attribute_spec no_size_overflow_attr = {
95380 + .name = "size_overflow",
95381 + .min_length = 1,
95382 + .max_length = -1,
95383 + .decl_required = false,
95384 + .type_required = true,
95385 + .function_type_required = true,
95386 + .handler = handle_size_overflow_attribute
95387 +};
95388 +
95389 +static void register_attributes(void __unused *event_data, void __unused *data)
95390 +{
95391 + register_attribute(&no_size_overflow_attr);
95392 +}
95393 +
95394 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
95395 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
95396 +{
95397 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
95398 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
95399 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
95400 +
95401 + const unsigned int m = 0x57559429;
95402 + const unsigned int n = 0x5052acdb;
95403 + const unsigned int *key4 = (const unsigned int *)key;
95404 + unsigned int h = len;
95405 + unsigned int k = len + seed + n;
95406 + unsigned long long p;
95407 +
95408 + while (len >= 8) {
95409 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
95410 + len -= 8;
95411 + }
95412 + if (len >= 4) {
95413 + cwmixb(key4[0]) key4 += 1;
95414 + len -= 4;
95415 + }
95416 + if (len)
95417 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
95418 + cwmixb(h ^ (k + n));
95419 + return k ^ h;
95420 +
95421 +#undef cwfold
95422 +#undef cwmixa
95423 +#undef cwmixb
95424 +}
95425 +
95426 +static inline unsigned int get_hash_num(const char *fndecl, const char *loc_file, unsigned int seed)
95427 +{
95428 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
95429 + unsigned int file = CrapWow(loc_file, strlen(loc_file), seed) & 0xffff;
95430 +
95431 + if (file_match)
95432 + return fn ^ file;
95433 + else
95434 + return fn;
95435 +}
95436 +
95437 +static inline tree get_original_function_decl(tree fndecl)
95438 +{
95439 + if (DECL_ABSTRACT_ORIGIN(fndecl))
95440 + return DECL_ABSTRACT_ORIGIN(fndecl);
95441 + return fndecl;
95442 +}
95443 +
95444 +static inline gimple get_def_stmt(tree node)
95445 +{
95446 + gcc_assert(TREE_CODE(node) == SSA_NAME);
95447 + return SSA_NAME_DEF_STMT(node);
95448 +}
95449 +
95450 +static struct size_overflow_hash *get_function_hash(tree fndecl, const char *loc_file)
95451 +{
95452 + unsigned int hash;
95453 + struct size_overflow_hash *entry;
95454 + const char *func_name = NAME(fndecl);
95455 +
95456 + hash = get_hash_num(NAME(fndecl), loc_file, 0);
95457 +
95458 + entry = size_overflow_hash[hash];
95459 + while (entry) {
95460 + if (!strcmp(entry->name, func_name) && (!file_match || !strcmp(entry->file, loc_file)))
95461 + return entry;
95462 + entry = entry->next;
95463 + }
95464 +
95465 + return NULL;
95466 +}
95467 +
95468 +static void check_arg_type(tree var)
95469 +{
95470 + tree type = TREE_TYPE(var);
95471 + enum tree_code code = TREE_CODE(type);
95472 +
95473 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
95474 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
95475 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
95476 +}
95477 +
95478 +static int find_arg_number(tree arg, tree func)
95479 +{
95480 + tree var;
95481 + bool match = false;
95482 + unsigned int argnum = 1;
95483 +
95484 + if (TREE_CODE(arg) == SSA_NAME)
95485 + arg = SSA_NAME_VAR(arg);
95486 +
95487 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
95488 + if (strcmp(NAME(arg), NAME(var))) {
95489 + argnum++;
95490 + continue;
95491 + }
95492 + check_arg_type(var);
95493 +
95494 + match = true;
95495 + if (!TYPE_UNSIGNED(TREE_TYPE(var)))
95496 + return 0;
95497 + break;
95498 + }
95499 + if (!match) {
95500 + warning(0, "find_arg_number: cannot find the %s argument in %s", NAME(arg), NAME(func));
95501 + return 0;
95502 + }
95503 + return argnum;
95504 +}
95505 +
95506 +static void print_missing_msg(tree func, const char *filename, unsigned int argnum)
95507 +{
95508 + unsigned int new_hash;
95509 + location_t loc = DECL_SOURCE_LOCATION(func);
95510 + const char *curfunc = NAME(func);
95511 +
95512 + new_hash = get_hash_num(curfunc, filename, 0);
95513 +// inform(loc, "Function %s is missing from the size_overflow hash table +%s+%d+%u+%s+", curfunc, curfunc, argnum, new_hash, filename);
95514 +}
95515 +
95516 +static void check_missing_attribute(tree arg)
95517 +{
95518 + tree type, func = get_original_function_decl(current_function_decl);
95519 + unsigned int argnum;
95520 + struct size_overflow_hash *hash;
95521 + const char *filename;
95522 +
95523 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
95524 +
95525 + type = TREE_TYPE(arg);
95526 + // skip function pointers
95527 + if (TREE_CODE(type) == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == FUNCTION_TYPE)
95528 + return;
95529 +
95530 + if (lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(func))))
95531 + return;
95532 +
95533 + argnum = find_arg_number(arg, func);
95534 + if (argnum == 0)
95535 + return;
95536 +
95537 + filename = DECL_SOURCE_FILE(func);
95538 +
95539 + hash = get_function_hash(func, filename);
95540 + if (!hash) {
95541 + print_missing_msg(func, filename, argnum);
95542 + return;
95543 + }
95544 +
95545 +#define check_param(num) \
95546 + if (num == argnum && hash->param##num) \
95547 + return;
95548 + check_param(1);
95549 + check_param(2);
95550 + check_param(3);
95551 + check_param(4);
95552 + check_param(5);
95553 + check_param(6);
95554 + check_param(7);
95555 + check_param(8);
95556 + check_param(9);
95557 +#undef check_param
95558 +
95559 + print_missing_msg(func, filename, argnum);
95560 +}
95561 +
95562 +static tree create_new_var(tree type)
95563 +{
95564 + tree new_var = create_tmp_var(type, "cicus");
95565 +
95566 + add_referenced_var(new_var);
95567 + mark_sym_for_renaming(new_var);
95568 + return new_var;
95569 +}
95570 +
95571 +static bool is_bool(tree node)
95572 +{
95573 + tree type;
95574 +
95575 + if (node == NULL_TREE)
95576 + return false;
95577 +
95578 + type = TREE_TYPE(node);
95579 + if (!INTEGRAL_TYPE_P(type))
95580 + return false;
95581 + if (TREE_CODE(type) == BOOLEAN_TYPE)
95582 + return true;
95583 + if (TYPE_PRECISION(type) == 1)
95584 + return true;
95585 + return false;
95586 +}
95587 +
95588 +static tree cast_a_tree(tree type, tree var)
95589 +{
95590 + gcc_assert(fold_convertible_p(type, var));
95591 +
95592 + return fold_convert(type, var);
95593 +}
95594 +
95595 +static gimple build_cast_stmt(tree type, tree var, tree new_var, location_t loc)
95596 +{
95597 + gimple assign;
95598 +
95599 + if (new_var == CREATE_NEW_VAR)
95600 + new_var = create_new_var(type);
95601 +
95602 + assign = gimple_build_assign(new_var, cast_a_tree(type, var));
95603 + gimple_set_location(assign, loc);
95604 + gimple_set_lhs(assign, make_ssa_name(new_var, assign));
95605 +
95606 + return assign;
95607 +}
95608 +
95609 +static tree create_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, bool before)
95610 +{
95611 + tree oldstmt_rhs1;
95612 + enum tree_code code;
95613 + gimple stmt;
95614 + gimple_stmt_iterator gsi;
95615 +
95616 + if (!*potentionally_overflowed)
95617 + return NULL_TREE;
95618 +
95619 + if (rhs1 == NULL_TREE) {
95620 + debug_gimple_stmt(oldstmt);
95621 + error("create_assign: rhs1 is NULL_TREE");
95622 + gcc_unreachable();
95623 + }
95624 +
95625 + oldstmt_rhs1 = gimple_assign_rhs1(oldstmt);
95626 + code = TREE_CODE(oldstmt_rhs1);
95627 + if (code == PARM_DECL || (code == SSA_NAME && gimple_code(get_def_stmt(oldstmt_rhs1)) == GIMPLE_NOP))
95628 + check_missing_attribute(oldstmt_rhs1);
95629 +
95630 + stmt = build_cast_stmt(signed_size_overflow_type, rhs1, CREATE_NEW_VAR, gimple_location(oldstmt));
95631 + gsi = gsi_for_stmt(oldstmt);
95632 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
95633 + basic_block next_bb, cur_bb;
95634 + edge e;
95635 +
95636 + gcc_assert(before == false);
95637 + gcc_assert(stmt_can_throw_internal(oldstmt));
95638 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
95639 + gcc_assert(!gsi_end_p(gsi));
95640 +
95641 + cur_bb = gimple_bb(oldstmt);
95642 + next_bb = cur_bb->next_bb;
95643 + e = find_edge(cur_bb, next_bb);
95644 + gcc_assert(e != NULL);
95645 + gcc_assert(e->flags & EDGE_FALLTHRU);
95646 +
95647 + gsi = gsi_after_labels(next_bb);
95648 + gcc_assert(!gsi_end_p(gsi));
95649 + before = true;
95650 + }
95651 + if (before)
95652 + gsi_insert_before(&gsi, stmt, GSI_NEW_STMT);
95653 + else
95654 + gsi_insert_after(&gsi, stmt, GSI_NEW_STMT);
95655 + update_stmt(stmt);
95656 + pointer_set_insert(visited, oldstmt);
95657 + return gimple_get_lhs(stmt);
95658 +}
95659 +
95660 +static tree dup_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt, tree rhs1, tree rhs2, tree __unused rhs3)
95661 +{
95662 + tree new_var, lhs = gimple_get_lhs(oldstmt);
95663 + gimple stmt;
95664 + gimple_stmt_iterator gsi;
95665 +
95666 + if (!*potentionally_overflowed)
95667 + return NULL_TREE;
95668 +
95669 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
95670 + rhs1 = gimple_assign_rhs1(oldstmt);
95671 + rhs1 = create_assign(visited, potentionally_overflowed, oldstmt, rhs1, BEFORE_STMT);
95672 + }
95673 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
95674 + rhs2 = gimple_assign_rhs2(oldstmt);
95675 + rhs2 = create_assign(visited, potentionally_overflowed, oldstmt, rhs2, BEFORE_STMT);
95676 + }
95677 +
95678 + stmt = gimple_copy(oldstmt);
95679 + gimple_set_location(stmt, gimple_location(oldstmt));
95680 +
95681 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
95682 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
95683 +
95684 + if (is_bool(lhs))
95685 + new_var = SSA_NAME_VAR(lhs);
95686 + else
95687 + new_var = create_new_var(signed_size_overflow_type);
95688 + new_var = make_ssa_name(new_var, stmt);
95689 + gimple_set_lhs(stmt, new_var);
95690 +
95691 + if (rhs1 != NULL_TREE) {
95692 + if (!gimple_assign_cast_p(oldstmt))
95693 + rhs1 = cast_a_tree(signed_size_overflow_type, rhs1);
95694 + gimple_assign_set_rhs1(stmt, rhs1);
95695 + }
95696 +
95697 + if (rhs2 != NULL_TREE)
95698 + gimple_assign_set_rhs2(stmt, rhs2);
95699 +#if BUILDING_GCC_VERSION >= 4007
95700 + if (rhs3 != NULL_TREE)
95701 + gimple_assign_set_rhs3(stmt, rhs3);
95702 +#endif
95703 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
95704 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
95705 +
95706 + gsi = gsi_for_stmt(oldstmt);
95707 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
95708 + update_stmt(stmt);
95709 + pointer_set_insert(visited, oldstmt);
95710 + return gimple_get_lhs(stmt);
95711 +}
95712 +
95713 +static gimple overflow_create_phi_node(gimple oldstmt, tree var)
95714 +{
95715 + basic_block bb;
95716 + gimple phi;
95717 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
95718 +
95719 + bb = gsi_bb(gsi);
95720 +
95721 + phi = create_phi_node(var, bb);
95722 + gsi = gsi_last(phi_nodes(bb));
95723 + gsi_remove(&gsi, false);
95724 +
95725 + gsi = gsi_for_stmt(oldstmt);
95726 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
95727 + gimple_set_bb(phi, bb);
95728 + return phi;
95729 +}
95730 +
95731 +static tree signed_cast_constant(tree node)
95732 +{
95733 + gcc_assert(is_gimple_constant(node));
95734 +
95735 + return cast_a_tree(signed_size_overflow_type, node);
95736 +}
95737 +
95738 +static basic_block create_a_first_bb(void)
95739 +{
95740 + basic_block first_bb;
95741 +
95742 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
95743 + if (dom_info_available_p(CDI_DOMINATORS))
95744 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
95745 + return first_bb;
95746 +}
95747 +
95748 +static gimple cast_old_phi_arg(gimple oldstmt, tree arg, tree new_var, unsigned int i)
95749 +{
95750 + basic_block bb;
95751 + gimple newstmt, def_stmt;
95752 + gimple_stmt_iterator gsi;
95753 +
95754 + newstmt = build_cast_stmt(signed_size_overflow_type, arg, new_var, gimple_location(oldstmt));
95755 + if (TREE_CODE(arg) == SSA_NAME) {
95756 + def_stmt = get_def_stmt(arg);
95757 + if (gimple_code(def_stmt) != GIMPLE_NOP) {
95758 + gsi = gsi_for_stmt(def_stmt);
95759 + gsi_insert_after(&gsi, newstmt, GSI_NEW_STMT);
95760 + return newstmt;
95761 + }
95762 + }
95763 +
95764 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
95765 + if (bb->index == 0)
95766 + bb = create_a_first_bb();
95767 + gsi = gsi_after_labels(bb);
95768 + gsi_insert_before(&gsi, newstmt, GSI_NEW_STMT);
95769 + return newstmt;
95770 +}
95771 +
95772 +static gimple handle_new_phi_arg(tree arg, tree new_var, tree new_rhs)
95773 +{
95774 + gimple newstmt;
95775 + gimple_stmt_iterator gsi;
95776 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
95777 + gimple def_newstmt = get_def_stmt(new_rhs);
95778 +
95779 + gsi_insert = gsi_insert_after;
95780 + gsi = gsi_for_stmt(def_newstmt);
95781 +
95782 + switch (gimple_code(get_def_stmt(arg))) {
95783 + case GIMPLE_PHI:
95784 + newstmt = gimple_build_assign(new_var, new_rhs);
95785 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
95786 + gsi_insert = gsi_insert_before;
95787 + break;
95788 + case GIMPLE_ASM:
95789 + case GIMPLE_CALL:
95790 + newstmt = gimple_build_assign(new_var, new_rhs);
95791 + break;
95792 + case GIMPLE_ASSIGN:
95793 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
95794 + break;
95795 + default:
95796 + /* unknown gimple_code (handle_build_new_phi_arg) */
95797 + gcc_unreachable();
95798 + }
95799 +
95800 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
95801 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
95802 + update_stmt(newstmt);
95803 + return newstmt;
95804 +}
95805 +
95806 +static tree build_new_phi_arg(struct pointer_set_t *visited, bool *potentionally_overflowed, tree arg, tree new_var)
95807 +{
95808 + gimple newstmt;
95809 + tree new_rhs;
95810 +
95811 + new_rhs = expand(visited, potentionally_overflowed, arg);
95812 +
95813 + if (new_rhs == NULL_TREE)
95814 + return NULL_TREE;
95815 +
95816 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
95817 + return gimple_get_lhs(newstmt);
95818 +}
95819 +
95820 +static tree build_new_phi(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple oldstmt)
95821 +{
95822 + gimple phi;
95823 + tree new_var = create_new_var(signed_size_overflow_type);
95824 + unsigned int i, n = gimple_phi_num_args(oldstmt);
95825 +
95826 + pointer_set_insert(visited, oldstmt);
95827 + phi = overflow_create_phi_node(oldstmt, new_var);
95828 + for (i = 0; i < n; i++) {
95829 + tree arg, lhs;
95830 +
95831 + arg = gimple_phi_arg_def(oldstmt, i);
95832 + if (is_gimple_constant(arg))
95833 + arg = signed_cast_constant(arg);
95834 + lhs = build_new_phi_arg(visited, potentionally_overflowed, arg, new_var);
95835 + if (lhs == NULL_TREE)
95836 + lhs = gimple_get_lhs(cast_old_phi_arg(oldstmt, arg, new_var, i));
95837 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
95838 + }
95839 +
95840 + update_stmt(phi);
95841 + return gimple_phi_result(phi);
95842 +}
95843 +
95844 +static tree handle_unary_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
95845 +{
95846 + gimple def_stmt = get_def_stmt(var);
95847 + tree new_rhs1, rhs1 = gimple_assign_rhs1(def_stmt);
95848 +
95849 + *potentionally_overflowed = true;
95850 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
95851 + if (new_rhs1 == NULL_TREE) {
95852 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
95853 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
95854 + else
95855 + return create_assign(visited, potentionally_overflowed, def_stmt, rhs1, AFTER_STMT);
95856 + }
95857 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, NULL_TREE, NULL_TREE);
95858 +}
95859 +
95860 +static tree handle_unary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
95861 +{
95862 + gimple def_stmt = get_def_stmt(var);
95863 + tree rhs1 = gimple_assign_rhs1(def_stmt);
95864 +
95865 + if (is_gimple_constant(rhs1))
95866 + return dup_assign(visited, potentionally_overflowed, def_stmt, signed_cast_constant(rhs1), NULL_TREE, NULL_TREE);
95867 +
95868 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
95869 + switch (TREE_CODE(rhs1)) {
95870 + case SSA_NAME:
95871 + return handle_unary_rhs(visited, potentionally_overflowed, var);
95872 +
95873 + case ARRAY_REF:
95874 + case BIT_FIELD_REF:
95875 + case ADDR_EXPR:
95876 + case COMPONENT_REF:
95877 + case INDIRECT_REF:
95878 +#if BUILDING_GCC_VERSION >= 4006
95879 + case MEM_REF:
95880 +#endif
95881 + case PARM_DECL:
95882 + case TARGET_MEM_REF:
95883 + case VAR_DECL:
95884 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
95885 +
95886 + default:
95887 + debug_gimple_stmt(def_stmt);
95888 + debug_tree(rhs1);
95889 + gcc_unreachable();
95890 + }
95891 +}
95892 +
95893 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
95894 +{
95895 + gimple cond_stmt;
95896 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
95897 +
95898 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
95899 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
95900 + update_stmt(cond_stmt);
95901 +}
95902 +
95903 +static tree create_string_param(tree string)
95904 +{
95905 + tree i_type, a_type;
95906 + int length = TREE_STRING_LENGTH(string);
95907 +
95908 + gcc_assert(length > 0);
95909 +
95910 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
95911 + a_type = build_array_type(char_type_node, i_type);
95912 +
95913 + TREE_TYPE(string) = a_type;
95914 + TREE_CONSTANT(string) = 1;
95915 + TREE_READONLY(string) = 1;
95916 +
95917 + return build1(ADDR_EXPR, ptr_type_node, string);
95918 +}
95919 +
95920 +static void insert_cond_result(basic_block bb_true, gimple stmt, tree arg)
95921 +{
95922 + gimple func_stmt, def_stmt;
95923 + tree current_func, loc_file, loc_line;
95924 + expanded_location xloc;
95925 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
95926 +
95927 + def_stmt = get_def_stmt(arg);
95928 + xloc = expand_location(gimple_location(def_stmt));
95929 +
95930 + if (!gimple_has_location(def_stmt)) {
95931 + xloc = expand_location(gimple_location(stmt));
95932 + if (!gimple_has_location(stmt))
95933 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
95934 + }
95935 +
95936 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
95937 +
95938 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
95939 + loc_file = create_string_param(loc_file);
95940 +
95941 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
95942 + current_func = create_string_param(current_func);
95943 +
95944 + // void report_size_overflow(const char *file, unsigned int line, const char *func)
95945 + func_stmt = gimple_build_call(report_size_overflow_decl, 3, loc_file, loc_line, current_func);
95946 +
95947 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
95948 +}
95949 +
95950 +static void __unused print_the_code_insertions(gimple stmt)
95951 +{
95952 + location_t loc = gimple_location(stmt);
95953 +
95954 + inform(loc, "Integer size_overflow check applied here.");
95955 +}
95956 +
95957 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value)
95958 +{
95959 + basic_block cond_bb, join_bb, bb_true;
95960 + edge e;
95961 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
95962 +
95963 + cond_bb = gimple_bb(stmt);
95964 + gsi_prev(&gsi);
95965 + if (gsi_end_p(gsi))
95966 + e = split_block_after_labels(cond_bb);
95967 + else
95968 + e = split_block(cond_bb, gsi_stmt(gsi));
95969 + cond_bb = e->src;
95970 + join_bb = e->dest;
95971 + e->flags = EDGE_FALSE_VALUE;
95972 + e->probability = REG_BR_PROB_BASE;
95973 +
95974 + bb_true = create_empty_bb(cond_bb);
95975 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
95976 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
95977 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
95978 +
95979 + if (dom_info_available_p(CDI_DOMINATORS)) {
95980 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
95981 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
95982 + }
95983 +
95984 + if (current_loops != NULL) {
95985 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
95986 + add_bb_to_loop(bb_true, cond_bb->loop_father);
95987 + }
95988 +
95989 + insert_cond(cond_bb, arg, cond_code, type_value);
95990 + insert_cond_result(bb_true, stmt, arg);
95991 +
95992 +// print_the_code_insertions(stmt);
95993 +}
95994 +
95995 +static tree get_type_for_check(tree rhs)
95996 +{
95997 + tree def_rhs;
95998 + gimple def_stmt = get_def_stmt(rhs);
95999 +
96000 + if (!gimple_assign_cast_p(def_stmt))
96001 + return TREE_TYPE(rhs);
96002 + def_rhs = gimple_assign_rhs1(def_stmt);
96003 + if (TREE_CODE(TREE_TYPE(def_rhs)) == INTEGER_TYPE)
96004 + return TREE_TYPE(def_rhs);
96005 + return TREE_TYPE(rhs);
96006 +}
96007 +
96008 +static gimple cast_to_unsigned_size_overflow_type(gimple stmt, tree cast_rhs)
96009 +{
96010 + gimple ucast_stmt;
96011 + gimple_stmt_iterator gsi;
96012 + location_t loc = gimple_location(stmt);
96013 +
96014 + ucast_stmt = build_cast_stmt(unsigned_size_overflow_type, cast_rhs, CREATE_NEW_VAR, loc);
96015 + gsi = gsi_for_stmt(stmt);
96016 + gsi_insert_before(&gsi, ucast_stmt, GSI_SAME_STMT);
96017 + return ucast_stmt;
96018 +}
96019 +
96020 +static void check_size_overflow(gimple stmt, tree cast_rhs, tree rhs, bool *potentionally_overflowed)
96021 +{
96022 + tree type_max, type_min, rhs_type;
96023 + gimple ucast_stmt;
96024 +
96025 + if (!*potentionally_overflowed)
96026 + return;
96027 +
96028 + rhs_type = get_type_for_check(rhs);
96029 +
96030 + if (TYPE_UNSIGNED(rhs_type)) {
96031 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, cast_rhs);
96032 + type_max = cast_a_tree(unsigned_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
96033 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
96034 + } else {
96035 + type_max = cast_a_tree(signed_size_overflow_type, TYPE_MAX_VALUE(rhs_type));
96036 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max);
96037 +
96038 + type_min = cast_a_tree(signed_size_overflow_type, TYPE_MIN_VALUE(rhs_type));
96039 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min);
96040 + }
96041 +}
96042 +
96043 +static tree change_assign_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple stmt, tree orig_rhs)
96044 +{
96045 + gimple assign;
96046 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
96047 + tree new_rhs, origtype = TREE_TYPE(orig_rhs);
96048 +
96049 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
96050 +
96051 + new_rhs = expand(visited, potentionally_overflowed, orig_rhs);
96052 + if (new_rhs == NULL_TREE)
96053 + return NULL_TREE;
96054 +
96055 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, gimple_location(stmt));
96056 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
96057 + update_stmt(assign);
96058 + return gimple_get_lhs(assign);
96059 +}
96060 +
96061 +static tree handle_const_assign(struct pointer_set_t *visited, bool *potentionally_overflowed, gimple def_stmt, tree var, tree rhs, tree new_rhs1, tree new_rhs2, void (*gimple_assign_set_rhs)(gimple, tree))
96062 +{
96063 + tree new_rhs, cast_rhs;
96064 +
96065 + if (gimple_assign_rhs_code(def_stmt) == MIN_EXPR)
96066 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
96067 +
96068 + new_rhs = change_assign_rhs(visited, potentionally_overflowed, def_stmt, rhs);
96069 + if (new_rhs != NULL_TREE) {
96070 + gimple_assign_set_rhs(def_stmt, new_rhs);
96071 + update_stmt(def_stmt);
96072 +
96073 + cast_rhs = gimple_assign_rhs1(get_def_stmt(new_rhs));
96074 +
96075 + check_size_overflow(def_stmt, cast_rhs, rhs, potentionally_overflowed);
96076 + }
96077 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
96078 +}
96079 +
96080 +static tree handle_binary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
96081 +{
96082 + tree rhs1, rhs2;
96083 + gimple def_stmt = get_def_stmt(var);
96084 + tree new_rhs1 = NULL_TREE;
96085 + tree new_rhs2 = NULL_TREE;
96086 +
96087 + rhs1 = gimple_assign_rhs1(def_stmt);
96088 + rhs2 = gimple_assign_rhs2(def_stmt);
96089 +
96090 + /* no DImode/TImode division in the 32/64 bit kernel */
96091 + switch (gimple_assign_rhs_code(def_stmt)) {
96092 + case RDIV_EXPR:
96093 + case TRUNC_DIV_EXPR:
96094 + case CEIL_DIV_EXPR:
96095 + case FLOOR_DIV_EXPR:
96096 + case ROUND_DIV_EXPR:
96097 + case TRUNC_MOD_EXPR:
96098 + case CEIL_MOD_EXPR:
96099 + case FLOOR_MOD_EXPR:
96100 + case ROUND_MOD_EXPR:
96101 + case EXACT_DIV_EXPR:
96102 + case POINTER_PLUS_EXPR:
96103 + case BIT_AND_EXPR:
96104 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
96105 + default:
96106 + break;
96107 + }
96108 +
96109 + *potentionally_overflowed = true;
96110 +
96111 + if (TREE_CODE(rhs1) == SSA_NAME)
96112 + new_rhs1 = expand(visited, potentionally_overflowed, rhs1);
96113 + if (TREE_CODE(rhs2) == SSA_NAME)
96114 + new_rhs2 = expand(visited, potentionally_overflowed, rhs2);
96115 +
96116 + if (is_gimple_constant(rhs2))
96117 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs1, new_rhs1, signed_cast_constant(rhs2), &gimple_assign_set_rhs1);
96118 +
96119 + if (is_gimple_constant(rhs1))
96120 + return handle_const_assign(visited, potentionally_overflowed, def_stmt, var, rhs2, signed_cast_constant(rhs1), new_rhs2, &gimple_assign_set_rhs2);
96121 +
96122 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, NULL_TREE);
96123 +}
96124 +
96125 +#if BUILDING_GCC_VERSION >= 4007
96126 +static tree get_new_rhs(struct pointer_set_t *visited, bool *potentionally_overflowed, tree rhs)
96127 +{
96128 + if (is_gimple_constant(rhs))
96129 + return signed_cast_constant(rhs);
96130 + if (TREE_CODE(rhs) != SSA_NAME)
96131 + return NULL_TREE;
96132 + return expand(visited, potentionally_overflowed, rhs);
96133 +}
96134 +
96135 +static tree handle_ternary_ops(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
96136 +{
96137 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3;
96138 + gimple def_stmt = get_def_stmt(var);
96139 +
96140 + *potentionally_overflowed = true;
96141 +
96142 + rhs1 = gimple_assign_rhs1(def_stmt);
96143 + rhs2 = gimple_assign_rhs2(def_stmt);
96144 + rhs3 = gimple_assign_rhs3(def_stmt);
96145 + new_rhs1 = get_new_rhs(visited, potentionally_overflowed, rhs1);
96146 + new_rhs2 = get_new_rhs(visited, potentionally_overflowed, rhs2);
96147 + new_rhs3 = get_new_rhs(visited, potentionally_overflowed, rhs3);
96148 +
96149 + if (new_rhs1 == NULL_TREE && new_rhs2 != NULL_TREE && new_rhs3 != NULL_TREE)
96150 + return dup_assign(visited, potentionally_overflowed, def_stmt, new_rhs1, new_rhs2, new_rhs3);
96151 + error("handle_ternary_ops: unknown rhs");
96152 + gcc_unreachable();
96153 +}
96154 +#endif
96155 +
96156 +static void set_size_overflow_type(tree node)
96157 +{
96158 + switch (TYPE_MODE(TREE_TYPE(node))) {
96159 + case SImode:
96160 + signed_size_overflow_type = intDI_type_node;
96161 + unsigned_size_overflow_type = unsigned_intDI_type_node;
96162 + break;
96163 + case DImode:
96164 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode)) {
96165 + signed_size_overflow_type = intDI_type_node;
96166 + unsigned_size_overflow_type = unsigned_intDI_type_node;
96167 + } else {
96168 + signed_size_overflow_type = intTI_type_node;
96169 + unsigned_size_overflow_type = unsigned_intTI_type_node;
96170 + }
96171 + break;
96172 + default:
96173 + error("set_size_overflow_type: unsupported gcc configuration.");
96174 + gcc_unreachable();
96175 + }
96176 +}
96177 +
96178 +static tree expand_visited(gimple def_stmt)
96179 +{
96180 + gimple tmp;
96181 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
96182 +
96183 + gsi_next(&gsi);
96184 + tmp = gsi_stmt(gsi);
96185 + switch (gimple_code(tmp)) {
96186 + case GIMPLE_ASSIGN:
96187 + return gimple_get_lhs(tmp);
96188 + case GIMPLE_PHI:
96189 + return gimple_phi_result(tmp);
96190 + case GIMPLE_CALL:
96191 + return gimple_call_lhs(tmp);
96192 + default:
96193 + return NULL_TREE;
96194 + }
96195 +}
96196 +
96197 +static tree expand(struct pointer_set_t *visited, bool *potentionally_overflowed, tree var)
96198 +{
96199 + gimple def_stmt;
96200 + enum tree_code code = TREE_CODE(TREE_TYPE(var));
96201 +
96202 + if (is_gimple_constant(var))
96203 + return NULL_TREE;
96204 +
96205 + if (TREE_CODE(var) == ADDR_EXPR)
96206 + return NULL_TREE;
96207 +
96208 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
96209 + if (code != INTEGER_TYPE)
96210 + return NULL_TREE;
96211 +
96212 + if (SSA_NAME_IS_DEFAULT_DEF(var)) {
96213 + check_missing_attribute(var);
96214 + return NULL_TREE;
96215 + }
96216 +
96217 + def_stmt = get_def_stmt(var);
96218 +
96219 + if (!def_stmt)
96220 + return NULL_TREE;
96221 +
96222 + if (pointer_set_contains(visited, def_stmt))
96223 + return expand_visited(def_stmt);
96224 +
96225 + switch (gimple_code(def_stmt)) {
96226 + case GIMPLE_NOP:
96227 + check_missing_attribute(var);
96228 + return NULL_TREE;
96229 + case GIMPLE_PHI:
96230 + return build_new_phi(visited, potentionally_overflowed, def_stmt);
96231 + case GIMPLE_CALL:
96232 + case GIMPLE_ASM:
96233 + return create_assign(visited, potentionally_overflowed, def_stmt, var, AFTER_STMT);
96234 + case GIMPLE_ASSIGN:
96235 + switch (gimple_num_ops(def_stmt)) {
96236 + case 2:
96237 + return handle_unary_ops(visited, potentionally_overflowed, var);
96238 + case 3:
96239 + return handle_binary_ops(visited, potentionally_overflowed, var);
96240 +#if BUILDING_GCC_VERSION >= 4007
96241 + case 4:
96242 + return handle_ternary_ops(visited, potentionally_overflowed, var);
96243 +#endif
96244 + }
96245 + default:
96246 + debug_gimple_stmt(def_stmt);
96247 + error("expand: unknown gimple code");
96248 + gcc_unreachable();
96249 + }
96250 +}
96251 +
96252 +static void change_function_arg(gimple stmt, tree origarg, unsigned int argnum, tree newarg)
96253 +{
96254 + gimple assign;
96255 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
96256 + tree origtype = TREE_TYPE(origarg);
96257 +
96258 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
96259 +
96260 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, gimple_location(stmt));
96261 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
96262 + update_stmt(assign);
96263 +
96264 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
96265 + update_stmt(stmt);
96266 +}
96267 +
96268 +static tree get_function_arg(unsigned int argnum, gimple stmt, tree fndecl)
96269 +{
96270 + const char *origid;
96271 + tree arg, origarg;
96272 +
96273 + if (!DECL_ABSTRACT_ORIGIN(fndecl)) {
96274 + gcc_assert(gimple_call_num_args(stmt) > argnum);
96275 + return gimple_call_arg(stmt, argnum);
96276 + }
96277 +
96278 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
96279 + while (origarg && argnum) {
96280 + argnum--;
96281 + origarg = TREE_CHAIN(origarg);
96282 + }
96283 +
96284 + gcc_assert(argnum == 0);
96285 +
96286 + gcc_assert(origarg != NULL_TREE);
96287 + origid = NAME(origarg);
96288 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
96289 + if (!strcmp(origid, NAME(arg)))
96290 + return arg;
96291 + }
96292 + return NULL_TREE;
96293 +}
96294 +
96295 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
96296 +{
96297 + struct pointer_set_t *visited;
96298 + tree arg, newarg, type_max;
96299 + gimple ucast_stmt;
96300 + bool potentionally_overflowed;
96301 +
96302 + arg = get_function_arg(argnum, stmt, fndecl);
96303 + if (arg == NULL_TREE)
96304 + return;
96305 +
96306 + if (is_gimple_constant(arg))
96307 + return;
96308 + if (TREE_CODE(arg) != SSA_NAME)
96309 + return;
96310 +
96311 + check_arg_type(arg);
96312 +
96313 + set_size_overflow_type(arg);
96314 +
96315 + visited = pointer_set_create();
96316 + potentionally_overflowed = false;
96317 + newarg = expand(visited, &potentionally_overflowed, arg);
96318 + pointer_set_destroy(visited);
96319 +
96320 + if (newarg == NULL_TREE || !potentionally_overflowed)
96321 + return;
96322 +
96323 + change_function_arg(stmt, arg, argnum, newarg);
96324 +
96325 + ucast_stmt = cast_to_unsigned_size_overflow_type(stmt, newarg);
96326 +
96327 + type_max = build_int_cstu(unsigned_size_overflow_type, 0x7fffffff);
96328 + insert_check_size_overflow(stmt, GT_EXPR, gimple_get_lhs(ucast_stmt), type_max);
96329 +}
96330 +
96331 +static void handle_function_by_attribute(gimple stmt, tree attr, tree fndecl)
96332 +{
96333 + tree p = TREE_VALUE(attr);
96334 + do {
96335 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
96336 + p = TREE_CHAIN(p);
96337 + } while (p);
96338 +}
96339 +
96340 +static void handle_function_by_hash(gimple stmt, tree fndecl)
96341 +{
96342 + tree orig_fndecl;
96343 + struct size_overflow_hash *hash;
96344 + const char *filename = DECL_SOURCE_FILE(fndecl);
96345 +
96346 + orig_fndecl = get_original_function_decl(fndecl);
96347 + hash = get_function_hash(orig_fndecl, filename);
96348 + if (!hash)
96349 + return;
96350 +
96351 +#define search_param(argnum) \
96352 + if (hash->param##argnum) \
96353 + handle_function_arg(stmt, fndecl, argnum - 1);
96354 +
96355 + search_param(1);
96356 + search_param(2);
96357 + search_param(3);
96358 + search_param(4);
96359 + search_param(5);
96360 + search_param(6);
96361 + search_param(7);
96362 + search_param(8);
96363 + search_param(9);
96364 +#undef search_param
96365 +}
96366 +
96367 +static unsigned int handle_function(void)
96368 +{
96369 + basic_block bb = ENTRY_BLOCK_PTR->next_bb;
96370 + int saved_last_basic_block = last_basic_block;
96371 +
96372 + do {
96373 + gimple_stmt_iterator gsi;
96374 + basic_block next = bb->next_bb;
96375 +
96376 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
96377 + tree fndecl, attr;
96378 + gimple stmt = gsi_stmt(gsi);
96379 +
96380 + if (!(is_gimple_call(stmt)))
96381 + continue;
96382 + fndecl = gimple_call_fndecl(stmt);
96383 + if (fndecl == NULL_TREE)
96384 + continue;
96385 + if (gimple_call_num_args(stmt) == 0)
96386 + continue;
96387 + attr = lookup_attribute("size_overflow", TYPE_ATTRIBUTES(TREE_TYPE(fndecl)));
96388 + if (!attr || !TREE_VALUE(attr))
96389 + handle_function_by_hash(stmt, fndecl);
96390 + else
96391 + handle_function_by_attribute(stmt, attr, fndecl);
96392 + gsi = gsi_for_stmt(stmt);
96393 + }
96394 + bb = next;
96395 + } while (bb && bb->index <= saved_last_basic_block);
96396 + return 0;
96397 +}
96398 +
96399 +static struct gimple_opt_pass size_overflow_pass = {
96400 + .pass = {
96401 + .type = GIMPLE_PASS,
96402 + .name = "size_overflow",
96403 + .gate = NULL,
96404 + .execute = handle_function,
96405 + .sub = NULL,
96406 + .next = NULL,
96407 + .static_pass_number = 0,
96408 + .tv_id = TV_NONE,
96409 + .properties_required = PROP_cfg | PROP_referenced_vars,
96410 + .properties_provided = 0,
96411 + .properties_destroyed = 0,
96412 + .todo_flags_start = 0,
96413 + .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
96414 + }
96415 +};
96416 +
96417 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
96418 +{
96419 + tree fntype;
96420 +
96421 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
96422 +
96423 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func)
96424 + fntype = build_function_type_list(void_type_node,
96425 + const_char_ptr_type_node,
96426 + unsigned_type_node,
96427 + const_char_ptr_type_node,
96428 + NULL_TREE);
96429 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
96430 +
96431 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
96432 + TREE_PUBLIC(report_size_overflow_decl) = 1;
96433 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
96434 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
96435 +}
96436 +
96437 +extern struct gimple_opt_pass pass_dce;
96438 +
96439 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
96440 +{
96441 + int i;
96442 + const char * const plugin_name = plugin_info->base_name;
96443 + const int argc = plugin_info->argc;
96444 + const struct plugin_argument * const argv = plugin_info->argv;
96445 + bool enable = true;
96446 +
96447 + struct register_pass_info size_overflow_pass_info = {
96448 + .pass = &size_overflow_pass.pass,
96449 + .reference_pass_name = "ssa",
96450 + .ref_pass_instance_number = 1,
96451 + .pos_op = PASS_POS_INSERT_AFTER
96452 + };
96453 +
96454 + if (!plugin_default_version_check(version, &gcc_version)) {
96455 + error(G_("incompatible gcc/plugin versions"));
96456 + return 1;
96457 + }
96458 +
96459 + for (i = 0; i < argc; ++i) {
96460 + if (!strcmp(argv[i].key, "no-size-overflow")) {
96461 + enable = false;
96462 + continue;
96463 + } else if (!(strcmp(argv[i].key, "no-file-match"))) {
96464 + file_match = false;
96465 + continue;
96466 + }
96467 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
96468 + }
96469 +
96470 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
96471 + if (enable) {
96472 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
96473 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
96474 + }
96475 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
96476 +
96477 + return 0;
96478 +}
96479 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
96480 new file mode 100644
96481 index 0000000..b87ec9d
96482 --- /dev/null
96483 +++ b/tools/gcc/stackleak_plugin.c
96484 @@ -0,0 +1,313 @@
96485 +/*
96486 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
96487 + * Licensed under the GPL v2
96488 + *
96489 + * Note: the choice of the license means that the compilation process is
96490 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
96491 + * but for the kernel it doesn't matter since it doesn't link against
96492 + * any of the gcc libraries
96493 + *
96494 + * gcc plugin to help implement various PaX features
96495 + *
96496 + * - track lowest stack pointer
96497 + *
96498 + * TODO:
96499 + * - initialize all local variables
96500 + *
96501 + * BUGS:
96502 + * - none known
96503 + */
96504 +#include "gcc-plugin.h"
96505 +#include "config.h"
96506 +#include "system.h"
96507 +#include "coretypes.h"
96508 +#include "tree.h"
96509 +#include "tree-pass.h"
96510 +#include "flags.h"
96511 +#include "intl.h"
96512 +#include "toplev.h"
96513 +#include "plugin.h"
96514 +//#include "expr.h" where are you...
96515 +#include "diagnostic.h"
96516 +#include "plugin-version.h"
96517 +#include "tm.h"
96518 +#include "function.h"
96519 +#include "basic-block.h"
96520 +#include "gimple.h"
96521 +#include "rtl.h"
96522 +#include "emit-rtl.h"
96523 +
96524 +extern void print_gimple_stmt(FILE *, gimple, int, int);
96525 +
96526 +int plugin_is_GPL_compatible;
96527 +
96528 +static int track_frame_size = -1;
96529 +static const char track_function[] = "pax_track_stack";
96530 +static const char check_function[] = "pax_check_alloca";
96531 +static bool init_locals;
96532 +
96533 +static struct plugin_info stackleak_plugin_info = {
96534 + .version = "201203140940",
96535 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
96536 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
96537 +};
96538 +
96539 +static bool gate_stackleak_track_stack(void);
96540 +static unsigned int execute_stackleak_tree_instrument(void);
96541 +static unsigned int execute_stackleak_final(void);
96542 +
96543 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
96544 + .pass = {
96545 + .type = GIMPLE_PASS,
96546 + .name = "stackleak_tree_instrument",
96547 + .gate = gate_stackleak_track_stack,
96548 + .execute = execute_stackleak_tree_instrument,
96549 + .sub = NULL,
96550 + .next = NULL,
96551 + .static_pass_number = 0,
96552 + .tv_id = TV_NONE,
96553 + .properties_required = PROP_gimple_leh | PROP_cfg,
96554 + .properties_provided = 0,
96555 + .properties_destroyed = 0,
96556 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
96557 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
96558 + }
96559 +};
96560 +
96561 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
96562 + .pass = {
96563 + .type = RTL_PASS,
96564 + .name = "stackleak_final",
96565 + .gate = gate_stackleak_track_stack,
96566 + .execute = execute_stackleak_final,
96567 + .sub = NULL,
96568 + .next = NULL,
96569 + .static_pass_number = 0,
96570 + .tv_id = TV_NONE,
96571 + .properties_required = 0,
96572 + .properties_provided = 0,
96573 + .properties_destroyed = 0,
96574 + .todo_flags_start = 0,
96575 + .todo_flags_finish = TODO_dump_func
96576 + }
96577 +};
96578 +
96579 +static bool gate_stackleak_track_stack(void)
96580 +{
96581 + return track_frame_size >= 0;
96582 +}
96583 +
96584 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
96585 +{
96586 + gimple check_alloca;
96587 + tree fntype, fndecl, alloca_size;
96588 +
96589 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
96590 + fndecl = build_fn_decl(check_function, fntype);
96591 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
96592 +
96593 + // insert call to void pax_check_alloca(unsigned long size)
96594 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
96595 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
96596 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
96597 +}
96598 +
96599 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
96600 +{
96601 + gimple track_stack;
96602 + tree fntype, fndecl;
96603 +
96604 + fntype = build_function_type_list(void_type_node, NULL_TREE);
96605 + fndecl = build_fn_decl(track_function, fntype);
96606 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
96607 +
96608 + // insert call to void pax_track_stack(void)
96609 + track_stack = gimple_build_call(fndecl, 0);
96610 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
96611 +}
96612 +
96613 +#if BUILDING_GCC_VERSION == 4005
96614 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
96615 +{
96616 + tree fndecl;
96617 +
96618 + if (!is_gimple_call(stmt))
96619 + return false;
96620 + fndecl = gimple_call_fndecl(stmt);
96621 + if (!fndecl)
96622 + return false;
96623 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
96624 + return false;
96625 +// print_node(stderr, "pax", fndecl, 4);
96626 + return DECL_FUNCTION_CODE(fndecl) == code;
96627 +}
96628 +#endif
96629 +
96630 +static bool is_alloca(gimple stmt)
96631 +{
96632 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
96633 + return true;
96634 +
96635 +#if BUILDING_GCC_VERSION >= 4007
96636 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
96637 + return true;
96638 +#endif
96639 +
96640 + return false;
96641 +}
96642 +
96643 +static unsigned int execute_stackleak_tree_instrument(void)
96644 +{
96645 + basic_block bb, entry_bb;
96646 + bool prologue_instrumented = false, is_leaf = true;
96647 +
96648 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
96649 +
96650 + // 1. loop through BBs and GIMPLE statements
96651 + FOR_EACH_BB(bb) {
96652 + gimple_stmt_iterator gsi;
96653 +
96654 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
96655 + gimple stmt;
96656 +
96657 + stmt = gsi_stmt(gsi);
96658 +
96659 + if (is_gimple_call(stmt))
96660 + is_leaf = false;
96661 +
96662 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
96663 + if (!is_alloca(stmt))
96664 + continue;
96665 +
96666 + // 2. insert stack overflow check before each __builtin_alloca call
96667 + stackleak_check_alloca(&gsi);
96668 +
96669 + // 3. insert track call after each __builtin_alloca call
96670 + stackleak_add_instrumentation(&gsi);
96671 + if (bb == entry_bb)
96672 + prologue_instrumented = true;
96673 + }
96674 + }
96675 +
96676 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
96677 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
96678 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
96679 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
96680 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
96681 + return 0;
96682 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
96683 + return 0;
96684 +
96685 + // 4. insert track call at the beginning
96686 + if (!prologue_instrumented) {
96687 + gimple_stmt_iterator gsi;
96688 +
96689 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
96690 + if (dom_info_available_p(CDI_DOMINATORS))
96691 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
96692 + gsi = gsi_start_bb(bb);
96693 + stackleak_add_instrumentation(&gsi);
96694 + }
96695 +
96696 + return 0;
96697 +}
96698 +
96699 +static unsigned int execute_stackleak_final(void)
96700 +{
96701 + rtx insn;
96702 +
96703 + if (cfun->calls_alloca)
96704 + return 0;
96705 +
96706 + // keep calls only if function frame is big enough
96707 + if (get_frame_size() >= track_frame_size)
96708 + return 0;
96709 +
96710 + // 1. find pax_track_stack calls
96711 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
96712 + // 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))
96713 + rtx body;
96714 +
96715 + if (!CALL_P(insn))
96716 + continue;
96717 + body = PATTERN(insn);
96718 + if (GET_CODE(body) != CALL)
96719 + continue;
96720 + body = XEXP(body, 0);
96721 + if (GET_CODE(body) != MEM)
96722 + continue;
96723 + body = XEXP(body, 0);
96724 + if (GET_CODE(body) != SYMBOL_REF)
96725 + continue;
96726 + if (strcmp(XSTR(body, 0), track_function))
96727 + continue;
96728 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
96729 + // 2. delete call
96730 + insn = delete_insn_and_edges(insn);
96731 +#if BUILDING_GCC_VERSION >= 4007
96732 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
96733 + insn = delete_insn_and_edges(insn);
96734 +#endif
96735 + }
96736 +
96737 +// print_simple_rtl(stderr, get_insns());
96738 +// print_rtl(stderr, get_insns());
96739 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
96740 +
96741 + return 0;
96742 +}
96743 +
96744 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
96745 +{
96746 + const char * const plugin_name = plugin_info->base_name;
96747 + const int argc = plugin_info->argc;
96748 + const struct plugin_argument * const argv = plugin_info->argv;
96749 + int i;
96750 + struct register_pass_info stackleak_tree_instrument_pass_info = {
96751 + .pass = &stackleak_tree_instrument_pass.pass,
96752 +// .reference_pass_name = "tree_profile",
96753 + .reference_pass_name = "optimized",
96754 + .ref_pass_instance_number = 0,
96755 + .pos_op = PASS_POS_INSERT_BEFORE
96756 + };
96757 + struct register_pass_info stackleak_final_pass_info = {
96758 + .pass = &stackleak_final_rtl_opt_pass.pass,
96759 + .reference_pass_name = "final",
96760 + .ref_pass_instance_number = 0,
96761 + .pos_op = PASS_POS_INSERT_BEFORE
96762 + };
96763 +
96764 + if (!plugin_default_version_check(version, &gcc_version)) {
96765 + error(G_("incompatible gcc/plugin versions"));
96766 + return 1;
96767 + }
96768 +
96769 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
96770 +
96771 + for (i = 0; i < argc; ++i) {
96772 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
96773 + if (!argv[i].value) {
96774 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
96775 + continue;
96776 + }
96777 + track_frame_size = atoi(argv[i].value);
96778 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
96779 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
96780 + continue;
96781 + }
96782 + if (!strcmp(argv[i].key, "initialize-locals")) {
96783 + if (argv[i].value) {
96784 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
96785 + continue;
96786 + }
96787 + init_locals = true;
96788 + continue;
96789 + }
96790 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
96791 + }
96792 +
96793 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
96794 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
96795 +
96796 + return 0;
96797 +}
96798 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
96799 index 6789d78..4afd019 100644
96800 --- a/tools/perf/util/include/asm/alternative-asm.h
96801 +++ b/tools/perf/util/include/asm/alternative-asm.h
96802 @@ -5,4 +5,7 @@
96803
96804 #define altinstruction_entry #
96805
96806 + .macro pax_force_retaddr rip=0, reload=0
96807 + .endm
96808 +
96809 #endif
96810 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
96811 index af0f22f..9a7d479 100644
96812 --- a/usr/gen_init_cpio.c
96813 +++ b/usr/gen_init_cpio.c
96814 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
96815 int retval;
96816 int rc = -1;
96817 int namesize;
96818 - int i;
96819 + unsigned int i;
96820
96821 mode |= S_IFREG;
96822
96823 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
96824 *env_var = *expanded = '\0';
96825 strncat(env_var, start + 2, end - start - 2);
96826 strncat(expanded, new_location, start - new_location);
96827 - strncat(expanded, getenv(env_var), PATH_MAX);
96828 - strncat(expanded, end + 1, PATH_MAX);
96829 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
96830 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
96831 strncpy(new_location, expanded, PATH_MAX);
96832 + new_location[PATH_MAX] = 0;
96833 } else
96834 break;
96835 }
96836 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
96837 index 7858228..2919715 100644
96838 --- a/virt/kvm/kvm_main.c
96839 +++ b/virt/kvm/kvm_main.c
96840 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
96841
96842 static cpumask_var_t cpus_hardware_enabled;
96843 static int kvm_usage_count = 0;
96844 -static atomic_t hardware_enable_failed;
96845 +static atomic_unchecked_t hardware_enable_failed;
96846
96847 struct kmem_cache *kvm_vcpu_cache;
96848 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
96849 @@ -2318,7 +2318,7 @@ static void hardware_enable_nolock(void *junk)
96850
96851 if (r) {
96852 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
96853 - atomic_inc(&hardware_enable_failed);
96854 + atomic_inc_unchecked(&hardware_enable_failed);
96855 printk(KERN_INFO "kvm: enabling virtualization on "
96856 "CPU%d failed\n", cpu);
96857 }
96858 @@ -2372,10 +2372,10 @@ static int hardware_enable_all(void)
96859
96860 kvm_usage_count++;
96861 if (kvm_usage_count == 1) {
96862 - atomic_set(&hardware_enable_failed, 0);
96863 + atomic_set_unchecked(&hardware_enable_failed, 0);
96864 on_each_cpu(hardware_enable_nolock, NULL, 1);
96865
96866 - if (atomic_read(&hardware_enable_failed)) {
96867 + if (atomic_read_unchecked(&hardware_enable_failed)) {
96868 hardware_disable_all_nolock();
96869 r = -EBUSY;
96870 }
96871 @@ -2738,7 +2738,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
96872 kvm_arch_vcpu_put(vcpu);
96873 }
96874
96875 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
96876 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
96877 struct module *module)
96878 {
96879 int r;
96880 @@ -2801,7 +2801,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
96881 if (!vcpu_align)
96882 vcpu_align = __alignof__(struct kvm_vcpu);
96883 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
96884 - 0, NULL);
96885 + SLAB_USERCOPY, NULL);
96886 if (!kvm_vcpu_cache) {
96887 r = -ENOMEM;
96888 goto out_free_3;
96889 @@ -2811,9 +2811,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
96890 if (r)
96891 goto out_free;
96892
96893 - kvm_chardev_ops.owner = module;
96894 - kvm_vm_fops.owner = module;
96895 - kvm_vcpu_fops.owner = module;
96896 + pax_open_kernel();
96897 + *(void **)&kvm_chardev_ops.owner = module;
96898 + *(void **)&kvm_vm_fops.owner = module;
96899 + *(void **)&kvm_vcpu_fops.owner = module;
96900 + pax_close_kernel();
96901
96902 r = misc_register(&kvm_dev);
96903 if (r) {