]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9-3.2.7-201202250918.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9-3.2.7-201202250918.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index dfa6fc6..0095943 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -5,6 +5,7 @@
6 *.cis
7 *.cpio
8 *.csp
9 +*.dbg
10 *.dsp
11 *.dvi
12 *.elf
13 @@ -14,6 +15,7 @@
14 *.gcov
15 *.gen.S
16 *.gif
17 +*.gmo
18 *.grep
19 *.grp
20 *.gz
21 @@ -48,9 +50,11 @@
22 *.tab.h
23 *.tex
24 *.ver
25 +*.vim
26 *.xml
27 *.xz
28 *_MODULES
29 +*_reg_safe.h
30 *_vga16.c
31 *~
32 \#*#
33 @@ -70,6 +74,7 @@ Kerntypes
34 Module.markers
35 Module.symvers
36 PENDING
37 +PERF*
38 SCCS
39 System.map*
40 TAGS
41 @@ -93,19 +98,24 @@ bounds.h
42 bsetup
43 btfixupprep
44 build
45 +builtin-policy.h
46 bvmlinux
47 bzImage*
48 capability_names.h
49 capflags.c
50 classlist.h*
51 +clut_vga16.c
52 +common-cmds.h
53 comp*.log
54 compile.h*
55 conf
56 config
57 config-*
58 config_data.h*
59 +config.c
60 config.mak
61 config.mak.autogen
62 +config.tmp
63 conmakehash
64 consolemap_deftbl.c*
65 cpustr.h
66 @@ -119,6 +129,7 @@ dslm
67 elf2ecoff
68 elfconfig.h*
69 evergreen_reg_safe.h
70 +exception_policy.conf
71 fixdep
72 flask.h
73 fore200e_mkfirm
74 @@ -126,12 +137,15 @@ fore200e_pca_fw.c*
75 gconf
76 gconf.glade.h
77 gen-devlist
78 +gen-kdb_cmds.c
79 gen_crc32table
80 gen_init_cpio
81 generated
82 genheaders
83 genksyms
84 *_gray256.c
85 +hash
86 +hid-example
87 hpet_example
88 hugepage-mmap
89 hugepage-shm
90 @@ -146,7 +160,7 @@ int32.c
91 int4.c
92 int8.c
93 kallsyms
94 -kconfig
95 +kern_constants.h
96 keywords.c
97 ksym.c*
98 ksym.h*
99 @@ -154,7 +168,6 @@ kxgettext
100 lkc_defs.h
101 lex.c
102 lex.*.c
103 -linux
104 logo_*.c
105 logo_*_clut224.c
106 logo_*_mono.c
107 @@ -166,14 +179,15 @@ machtypes.h
108 map
109 map_hugetlb
110 maui_boot.h
111 -media
112 mconf
113 +mdp
114 miboot*
115 mk_elfconfig
116 mkboot
117 mkbugboot
118 mkcpustr
119 mkdep
120 +mkpiggy
121 mkprep
122 mkregtable
123 mktables
124 @@ -209,6 +223,7 @@ r300_reg_safe.h
125 r420_reg_safe.h
126 r600_reg_safe.h
127 recordmcount
128 +regdb.c
129 relocs
130 rlim_names.h
131 rn50_reg_safe.h
132 @@ -219,6 +234,7 @@ setup
133 setup.bin
134 setup.elf
135 sImage
136 +slabinfo
137 sm_tbl*
138 split-include
139 syscalltab.h
140 @@ -229,6 +245,7 @@ tftpboot.img
141 timeconst.h
142 times.h*
143 trix_boot.h
144 +user_constants.h
145 utsrelease.h*
146 vdso-syms.lds
147 vdso.lds
148 @@ -246,7 +263,9 @@ vmlinux
149 vmlinux-*
150 vmlinux.aout
151 vmlinux.bin.all
152 +vmlinux.bin.bz2
153 vmlinux.lds
154 +vmlinux.relocs
155 vmlinuz
156 voffset.h
157 vsyscall.lds
158 @@ -254,9 +273,11 @@ vsyscall_32.lds
159 wanxlfw.inc
160 uImage
161 unifdef
162 +utsrelease.h
163 wakeup.bin
164 wakeup.elf
165 wakeup.lds
166 zImage*
167 zconf.hash.c
168 +zconf.lex.c
169 zoffset.h
170 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
171 index 81c287f..d456d02 100644
172 --- a/Documentation/kernel-parameters.txt
173 +++ b/Documentation/kernel-parameters.txt
174 @@ -1935,6 +1935,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
175 the specified number of seconds. This is to be used if
176 your oopses keep scrolling off the screen.
177
178 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
179 + virtualization environments that don't cope well with the
180 + expand down segment used by UDEREF on X86-32 or the frequent
181 + page table updates on X86-64.
182 +
183 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
184 +
185 pcbit= [HW,ISDN]
186
187 pcd. [PARIDE]
188 diff --git a/Makefile b/Makefile
189 index d1bdc90..e95fe1a 100644
190 --- a/Makefile
191 +++ b/Makefile
192 @@ -245,8 +245,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
193
194 HOSTCC = gcc
195 HOSTCXX = g++
196 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
197 -HOSTCXXFLAGS = -O2
198 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
199 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
200 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
201
202 # Decide whether to build built-in, modular, or both.
203 # Normally, just do built-in.
204 @@ -407,8 +408,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn --exc
205 # Rules shared between *config targets and build targets
206
207 # Basic helpers built in scripts/
208 -PHONY += scripts_basic
209 -scripts_basic:
210 +PHONY += scripts_basic gcc-plugins
211 +scripts_basic: gcc-plugins
212 $(Q)$(MAKE) $(build)=scripts/basic
213 $(Q)rm -f .tmp_quiet_recordmcount
214
215 @@ -564,6 +565,46 @@ else
216 KBUILD_CFLAGS += -O2
217 endif
218
219 +ifndef DISABLE_PAX_PLUGINS
220 +ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(CC)"), y)
221 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
222 +CONSTIFY_PLUGIN := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
223 +endif
224 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
225 +STACKLEAK_PLUGIN := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
226 +STACKLEAK_PLUGIN += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
227 +endif
228 +ifdef CONFIG_KALLOCSTAT_PLUGIN
229 +KALLOCSTAT_PLUGIN := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
230 +endif
231 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
232 +KERNEXEC_PLUGIN := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
233 +KERNEXEC_PLUGIN += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD)
234 +endif
235 +ifdef CONFIG_CHECKER_PLUGIN
236 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
237 +CHECKER_PLUGIN := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
238 +endif
239 +endif
240 +GCC_PLUGINS := $(CONSTIFY_PLUGIN) $(STACKLEAK_PLUGIN) $(KALLOCSTAT_PLUGIN) $(KERNEXEC_PLUGIN) $(CHECKER_PLUGIN)
241 +export CONSTIFY_PLUGIN STACKLEAK_PLUGIN KERNEXEC_PLUGIN CHECKER_PLUGIN
242 +ifeq ($(KBUILD_EXTMOD),)
243 +gcc-plugins:
244 + $(Q)$(MAKE) $(build)=tools/gcc
245 +else
246 +gcc-plugins: ;
247 +endif
248 +else
249 +gcc-plugins:
250 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
251 + $(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.))
252 +else
253 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
254 +endif
255 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
256 +endif
257 +endif
258 +
259 include $(srctree)/arch/$(SRCARCH)/Makefile
260
261 ifneq ($(CONFIG_FRAME_WARN),0)
262 @@ -708,7 +749,7 @@ export mod_strip_cmd
263
264
265 ifeq ($(KBUILD_EXTMOD),)
266 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
267 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
268
269 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
270 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
271 @@ -932,6 +973,7 @@ vmlinux.o: $(modpost-init) $(vmlinux-main) FORCE
272
273 # The actual objects are generated when descending,
274 # make sure no implicit rule kicks in
275 +$(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): KBUILD_CFLAGS += $(GCC_PLUGINS)
276 $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
277
278 # Handle descending into subdirectories listed in $(vmlinux-dirs)
279 @@ -941,7 +983,7 @@ $(sort $(vmlinux-init) $(vmlinux-main)) $(vmlinux-lds): $(vmlinux-dirs) ;
280 # Error messages still appears in the original language
281
282 PHONY += $(vmlinux-dirs)
283 -$(vmlinux-dirs): prepare scripts
284 +$(vmlinux-dirs): gcc-plugins prepare scripts
285 $(Q)$(MAKE) $(build)=$@
286
287 # Store (new) KERNELRELASE string in include/config/kernel.release
288 @@ -985,6 +1027,7 @@ prepare0: archprepare FORCE
289 $(Q)$(MAKE) $(build)=.
290
291 # All the preparing..
292 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS),$(KBUILD_CFLAGS))
293 prepare: prepare0
294
295 # Generate some files
296 @@ -1086,6 +1129,7 @@ all: modules
297 # using awk while concatenating to the final file.
298
299 PHONY += modules
300 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
301 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
302 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
303 @$(kecho) ' Building modules, stage 2.';
304 @@ -1101,7 +1145,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
305
306 # Target to prepare building external modules
307 PHONY += modules_prepare
308 -modules_prepare: prepare scripts
309 +modules_prepare: gcc-plugins prepare scripts
310
311 # Target to install modules
312 PHONY += modules_install
313 @@ -1198,6 +1242,7 @@ distclean: mrproper
314 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
315 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
316 -o -name '.*.rej' \
317 + -o -name '.*.rej' -o -name '*.so' \
318 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
319 -type f -print | xargs rm -f
320
321 @@ -1358,6 +1403,7 @@ PHONY += $(module-dirs) modules
322 $(module-dirs): crmodverdir $(objtree)/Module.symvers
323 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
324
325 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS)
326 modules: $(module-dirs)
327 @$(kecho) ' Building modules, stage 2.';
328 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
329 @@ -1484,17 +1530,19 @@ else
330 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
331 endif
332
333 -%.s: %.c prepare scripts FORCE
334 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS)
335 +%.s: %.c gcc-plugins prepare scripts FORCE
336 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
337 %.i: %.c prepare scripts FORCE
338 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
339 -%.o: %.c prepare scripts FORCE
340 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS)
341 +%.o: %.c gcc-plugins prepare scripts FORCE
342 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
343 %.lst: %.c prepare scripts FORCE
344 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
345 -%.s: %.S prepare scripts FORCE
346 +%.s: %.S gcc-plugins prepare scripts FORCE
347 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
348 -%.o: %.S prepare scripts FORCE
349 +%.o: %.S gcc-plugins prepare scripts FORCE
350 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
351 %.symtypes: %.c prepare scripts FORCE
352 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
353 @@ -1504,11 +1552,13 @@ endif
354 $(cmd_crmodverdir)
355 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
356 $(build)=$(build-dir)
357 -%/: prepare scripts FORCE
358 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS)
359 +%/: gcc-plugins prepare scripts FORCE
360 $(cmd_crmodverdir)
361 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
362 $(build)=$(build-dir)
363 -%.ko: prepare scripts FORCE
364 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS)
365 +%.ko: gcc-plugins prepare scripts FORCE
366 $(cmd_crmodverdir)
367 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
368 $(build)=$(build-dir) $(@:.ko=.o)
369 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
370 index 640f909..d0b7562 100644
371 --- a/arch/alpha/include/asm/atomic.h
372 +++ b/arch/alpha/include/asm/atomic.h
373 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
374 #define atomic_dec(v) atomic_sub(1,(v))
375 #define atomic64_dec(v) atomic64_sub(1,(v))
376
377 +#define atomic64_read_unchecked(v) atomic64_read(v)
378 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
379 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
380 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
381 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
382 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
383 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
384 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
385 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
386 +
387 #define smp_mb__before_atomic_dec() smp_mb()
388 #define smp_mb__after_atomic_dec() smp_mb()
389 #define smp_mb__before_atomic_inc() smp_mb()
390 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
391 index da5449e..7418343 100644
392 --- a/arch/alpha/include/asm/elf.h
393 +++ b/arch/alpha/include/asm/elf.h
394 @@ -90,6 +90,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
395
396 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
397
398 +#ifdef CONFIG_PAX_ASLR
399 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
400 +
401 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
402 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
403 +#endif
404 +
405 /* $0 is set by ld.so to a pointer to a function which might be
406 registered using atexit. This provides a mean for the dynamic
407 linker to call DT_FINI functions for shared libraries that have
408 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
409 index de98a73..bd4f1f8 100644
410 --- a/arch/alpha/include/asm/pgtable.h
411 +++ b/arch/alpha/include/asm/pgtable.h
412 @@ -101,6 +101,17 @@ struct vm_area_struct;
413 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
414 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
415 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
416 +
417 +#ifdef CONFIG_PAX_PAGEEXEC
418 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
419 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
420 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
421 +#else
422 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
423 +# define PAGE_COPY_NOEXEC PAGE_COPY
424 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
425 +#endif
426 +
427 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
428
429 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
430 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
431 index 2fd00b7..cfd5069 100644
432 --- a/arch/alpha/kernel/module.c
433 +++ b/arch/alpha/kernel/module.c
434 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
435
436 /* The small sections were sorted to the end of the segment.
437 The following should definitely cover them. */
438 - gp = (u64)me->module_core + me->core_size - 0x8000;
439 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
440 got = sechdrs[me->arch.gotsecindex].sh_addr;
441
442 for (i = 0; i < n; i++) {
443 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
444 index 01e8715..be0e80f 100644
445 --- a/arch/alpha/kernel/osf_sys.c
446 +++ b/arch/alpha/kernel/osf_sys.c
447 @@ -1147,7 +1147,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
448 /* At this point: (!vma || addr < vma->vm_end). */
449 if (limit - len < addr)
450 return -ENOMEM;
451 - if (!vma || addr + len <= vma->vm_start)
452 + if (check_heap_stack_gap(vma, addr, len))
453 return addr;
454 addr = vma->vm_end;
455 vma = vma->vm_next;
456 @@ -1183,6 +1183,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
457 merely specific addresses, but regions of memory -- perhaps
458 this feature should be incorporated into all ports? */
459
460 +#ifdef CONFIG_PAX_RANDMMAP
461 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
462 +#endif
463 +
464 if (addr) {
465 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
466 if (addr != (unsigned long) -ENOMEM)
467 @@ -1190,8 +1194,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
468 }
469
470 /* Next, try allocating at TASK_UNMAPPED_BASE. */
471 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
472 - len, limit);
473 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
474 +
475 if (addr != (unsigned long) -ENOMEM)
476 return addr;
477
478 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
479 index fadd5f8..904e73a 100644
480 --- a/arch/alpha/mm/fault.c
481 +++ b/arch/alpha/mm/fault.c
482 @@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
483 __reload_thread(pcb);
484 }
485
486 +#ifdef CONFIG_PAX_PAGEEXEC
487 +/*
488 + * PaX: decide what to do with offenders (regs->pc = fault address)
489 + *
490 + * returns 1 when task should be killed
491 + * 2 when patched PLT trampoline was detected
492 + * 3 when unpatched PLT trampoline was detected
493 + */
494 +static int pax_handle_fetch_fault(struct pt_regs *regs)
495 +{
496 +
497 +#ifdef CONFIG_PAX_EMUPLT
498 + int err;
499 +
500 + do { /* PaX: patched PLT emulation #1 */
501 + unsigned int ldah, ldq, jmp;
502 +
503 + err = get_user(ldah, (unsigned int *)regs->pc);
504 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
505 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
506 +
507 + if (err)
508 + break;
509 +
510 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
511 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
512 + jmp == 0x6BFB0000U)
513 + {
514 + unsigned long r27, addr;
515 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
516 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
517 +
518 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
519 + err = get_user(r27, (unsigned long *)addr);
520 + if (err)
521 + break;
522 +
523 + regs->r27 = r27;
524 + regs->pc = r27;
525 + return 2;
526 + }
527 + } while (0);
528 +
529 + do { /* PaX: patched PLT emulation #2 */
530 + unsigned int ldah, lda, br;
531 +
532 + err = get_user(ldah, (unsigned int *)regs->pc);
533 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
534 + err |= get_user(br, (unsigned int *)(regs->pc+8));
535 +
536 + if (err)
537 + break;
538 +
539 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
540 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
541 + (br & 0xFFE00000U) == 0xC3E00000U)
542 + {
543 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
544 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
545 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
546 +
547 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
548 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
549 + return 2;
550 + }
551 + } while (0);
552 +
553 + do { /* PaX: unpatched PLT emulation */
554 + unsigned int br;
555 +
556 + err = get_user(br, (unsigned int *)regs->pc);
557 +
558 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
559 + unsigned int br2, ldq, nop, jmp;
560 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
561 +
562 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
563 + err = get_user(br2, (unsigned int *)addr);
564 + err |= get_user(ldq, (unsigned int *)(addr+4));
565 + err |= get_user(nop, (unsigned int *)(addr+8));
566 + err |= get_user(jmp, (unsigned int *)(addr+12));
567 + err |= get_user(resolver, (unsigned long *)(addr+16));
568 +
569 + if (err)
570 + break;
571 +
572 + if (br2 == 0xC3600000U &&
573 + ldq == 0xA77B000CU &&
574 + nop == 0x47FF041FU &&
575 + jmp == 0x6B7B0000U)
576 + {
577 + regs->r28 = regs->pc+4;
578 + regs->r27 = addr+16;
579 + regs->pc = resolver;
580 + return 3;
581 + }
582 + }
583 + } while (0);
584 +#endif
585 +
586 + return 1;
587 +}
588 +
589 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
590 +{
591 + unsigned long i;
592 +
593 + printk(KERN_ERR "PAX: bytes at PC: ");
594 + for (i = 0; i < 5; i++) {
595 + unsigned int c;
596 + if (get_user(c, (unsigned int *)pc+i))
597 + printk(KERN_CONT "???????? ");
598 + else
599 + printk(KERN_CONT "%08x ", c);
600 + }
601 + printk("\n");
602 +}
603 +#endif
604
605 /*
606 * This routine handles page faults. It determines the address,
607 @@ -131,8 +249,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
608 good_area:
609 si_code = SEGV_ACCERR;
610 if (cause < 0) {
611 - if (!(vma->vm_flags & VM_EXEC))
612 + if (!(vma->vm_flags & VM_EXEC)) {
613 +
614 +#ifdef CONFIG_PAX_PAGEEXEC
615 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
616 + goto bad_area;
617 +
618 + up_read(&mm->mmap_sem);
619 + switch (pax_handle_fetch_fault(regs)) {
620 +
621 +#ifdef CONFIG_PAX_EMUPLT
622 + case 2:
623 + case 3:
624 + return;
625 +#endif
626 +
627 + }
628 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
629 + do_group_exit(SIGKILL);
630 +#else
631 goto bad_area;
632 +#endif
633 +
634 + }
635 } else if (!cause) {
636 /* Allow reads even for write-only mappings */
637 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
638 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
639 index 86976d0..b26ff39 100644
640 --- a/arch/arm/include/asm/atomic.h
641 +++ b/arch/arm/include/asm/atomic.h
642 @@ -239,6 +239,14 @@ typedef struct {
643 u64 __aligned(8) counter;
644 } atomic64_t;
645
646 +#ifdef CONFIG_PAX_REFCOUNT
647 +typedef struct {
648 + u64 __aligned(8) counter;
649 +} atomic64_unchecked_t;
650 +#else
651 +typedef atomic64_t atomic64_unchecked_t;
652 +#endif
653 +
654 #define ATOMIC64_INIT(i) { (i) }
655
656 static inline u64 atomic64_read(atomic64_t *v)
657 @@ -459,6 +467,16 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
658 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
659 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
660
661 +#define atomic64_read_unchecked(v) atomic64_read(v)
662 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
663 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
664 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
665 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
666 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
667 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
668 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
669 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
670 +
671 #endif /* !CONFIG_GENERIC_ATOMIC64 */
672 #endif
673 #endif
674 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
675 index 0e9ce8d..6ef1e03 100644
676 --- a/arch/arm/include/asm/elf.h
677 +++ b/arch/arm/include/asm/elf.h
678 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
679 the loader. We need to make sure that it is out of the way of the program
680 that it will "exec", and that there is sufficient room for the brk. */
681
682 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
683 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
684 +
685 +#ifdef CONFIG_PAX_ASLR
686 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
687 +
688 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
689 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
690 +#endif
691
692 /* When the program starts, a1 contains a pointer to a function to be
693 registered with atexit, as per the SVR4 ABI. A value of 0 means we
694 @@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
695 extern void elf_set_personality(const struct elf32_hdr *);
696 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
697
698 -struct mm_struct;
699 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
700 -#define arch_randomize_brk arch_randomize_brk
701 -
702 extern int vectors_user_mapping(void);
703 #define arch_setup_additional_pages(bprm, uses_interp) vectors_user_mapping()
704 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES
705 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
706 index e51b1e8..32a3113 100644
707 --- a/arch/arm/include/asm/kmap_types.h
708 +++ b/arch/arm/include/asm/kmap_types.h
709 @@ -21,6 +21,7 @@ enum km_type {
710 KM_L1_CACHE,
711 KM_L2_CACHE,
712 KM_KDB,
713 + KM_CLEARPAGE,
714 KM_TYPE_NR
715 };
716
717 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
718 index b293616..96310e5 100644
719 --- a/arch/arm/include/asm/uaccess.h
720 +++ b/arch/arm/include/asm/uaccess.h
721 @@ -22,6 +22,8 @@
722 #define VERIFY_READ 0
723 #define VERIFY_WRITE 1
724
725 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
726 +
727 /*
728 * The exception table consists of pairs of addresses: the first is the
729 * address of an instruction that is allowed to fault, and the second is
730 @@ -387,8 +389,23 @@ do { \
731
732
733 #ifdef CONFIG_MMU
734 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
735 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
736 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
737 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
738 +
739 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
740 +{
741 + if (!__builtin_constant_p(n))
742 + check_object_size(to, n, false);
743 + return ___copy_from_user(to, from, n);
744 +}
745 +
746 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
747 +{
748 + if (!__builtin_constant_p(n))
749 + check_object_size(from, n, true);
750 + return ___copy_to_user(to, from, n);
751 +}
752 +
753 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
754 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
755 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
756 @@ -403,6 +420,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
757
758 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
759 {
760 + if ((long)n < 0)
761 + return n;
762 +
763 if (access_ok(VERIFY_READ, from, n))
764 n = __copy_from_user(to, from, n);
765 else /* security hole - plug it */
766 @@ -412,6 +432,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
767
768 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
769 {
770 + if ((long)n < 0)
771 + return n;
772 +
773 if (access_ok(VERIFY_WRITE, to, n))
774 n = __copy_to_user(to, from, n);
775 return n;
776 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
777 index 5b0bce6..becd81c 100644
778 --- a/arch/arm/kernel/armksyms.c
779 +++ b/arch/arm/kernel/armksyms.c
780 @@ -95,8 +95,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
781 #ifdef CONFIG_MMU
782 EXPORT_SYMBOL(copy_page);
783
784 -EXPORT_SYMBOL(__copy_from_user);
785 -EXPORT_SYMBOL(__copy_to_user);
786 +EXPORT_SYMBOL(___copy_from_user);
787 +EXPORT_SYMBOL(___copy_to_user);
788 EXPORT_SYMBOL(__clear_user);
789
790 EXPORT_SYMBOL(__get_user_1);
791 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
792 index 3d0c6fb..3dcae52 100644
793 --- a/arch/arm/kernel/process.c
794 +++ b/arch/arm/kernel/process.c
795 @@ -28,7 +28,6 @@
796 #include <linux/tick.h>
797 #include <linux/utsname.h>
798 #include <linux/uaccess.h>
799 -#include <linux/random.h>
800 #include <linux/hw_breakpoint.h>
801 #include <linux/cpuidle.h>
802
803 @@ -484,12 +483,6 @@ unsigned long get_wchan(struct task_struct *p)
804 return 0;
805 }
806
807 -unsigned long arch_randomize_brk(struct mm_struct *mm)
808 -{
809 - unsigned long range_end = mm->brk + 0x02000000;
810 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
811 -}
812 -
813 #ifdef CONFIG_MMU
814 /*
815 * The vectors page is always readable from user space for the
816 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
817 index 99a5727..a3d5bb1 100644
818 --- a/arch/arm/kernel/traps.c
819 +++ b/arch/arm/kernel/traps.c
820 @@ -259,6 +259,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
821
822 static DEFINE_RAW_SPINLOCK(die_lock);
823
824 +extern void gr_handle_kernel_exploit(void);
825 +
826 /*
827 * This function is protected against re-entrancy.
828 */
829 @@ -288,6 +290,9 @@ void die(const char *str, struct pt_regs *regs, int err)
830 panic("Fatal exception in interrupt");
831 if (panic_on_oops)
832 panic("Fatal exception");
833 +
834 + gr_handle_kernel_exploit();
835 +
836 if (ret != NOTIFY_STOP)
837 do_exit(SIGSEGV);
838 }
839 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
840 index 66a477a..bee61d3 100644
841 --- a/arch/arm/lib/copy_from_user.S
842 +++ b/arch/arm/lib/copy_from_user.S
843 @@ -16,7 +16,7 @@
844 /*
845 * Prototype:
846 *
847 - * size_t __copy_from_user(void *to, const void *from, size_t n)
848 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
849 *
850 * Purpose:
851 *
852 @@ -84,11 +84,11 @@
853
854 .text
855
856 -ENTRY(__copy_from_user)
857 +ENTRY(___copy_from_user)
858
859 #include "copy_template.S"
860
861 -ENDPROC(__copy_from_user)
862 +ENDPROC(___copy_from_user)
863
864 .pushsection .fixup,"ax"
865 .align 0
866 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
867 index d066df6..df28194 100644
868 --- a/arch/arm/lib/copy_to_user.S
869 +++ b/arch/arm/lib/copy_to_user.S
870 @@ -16,7 +16,7 @@
871 /*
872 * Prototype:
873 *
874 - * size_t __copy_to_user(void *to, const void *from, size_t n)
875 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
876 *
877 * Purpose:
878 *
879 @@ -88,11 +88,11 @@
880 .text
881
882 ENTRY(__copy_to_user_std)
883 -WEAK(__copy_to_user)
884 +WEAK(___copy_to_user)
885
886 #include "copy_template.S"
887
888 -ENDPROC(__copy_to_user)
889 +ENDPROC(___copy_to_user)
890 ENDPROC(__copy_to_user_std)
891
892 .pushsection .fixup,"ax"
893 diff --git a/arch/arm/lib/uaccess.S b/arch/arm/lib/uaccess.S
894 index d0ece2a..5ae2f39 100644
895 --- a/arch/arm/lib/uaccess.S
896 +++ b/arch/arm/lib/uaccess.S
897 @@ -20,7 +20,7 @@
898
899 #define PAGE_SHIFT 12
900
901 -/* Prototype: int __copy_to_user(void *to, const char *from, size_t n)
902 +/* Prototype: int ___copy_to_user(void *to, const char *from, size_t n)
903 * Purpose : copy a block to user memory from kernel memory
904 * Params : to - user memory
905 * : from - kernel memory
906 @@ -40,7 +40,7 @@ USER( T(strgtb) r3, [r0], #1) @ May fault
907 sub r2, r2, ip
908 b .Lc2u_dest_aligned
909
910 -ENTRY(__copy_to_user)
911 +ENTRY(___copy_to_user)
912 stmfd sp!, {r2, r4 - r7, lr}
913 cmp r2, #4
914 blt .Lc2u_not_enough
915 @@ -278,14 +278,14 @@ USER( T(strgeb) r3, [r0], #1) @ May fault
916 ldrgtb r3, [r1], #0
917 USER( T(strgtb) r3, [r0], #1) @ May fault
918 b .Lc2u_finished
919 -ENDPROC(__copy_to_user)
920 +ENDPROC(___copy_to_user)
921
922 .pushsection .fixup,"ax"
923 .align 0
924 9001: ldmfd sp!, {r0, r4 - r7, pc}
925 .popsection
926
927 -/* Prototype: unsigned long __copy_from_user(void *to,const void *from,unsigned long n);
928 +/* Prototype: unsigned long ___copy_from_user(void *to,const void *from,unsigned long n);
929 * Purpose : copy a block from user memory to kernel memory
930 * Params : to - kernel memory
931 * : from - user memory
932 @@ -304,7 +304,7 @@ USER( T(ldrgtb) r3, [r1], #1) @ May fault
933 sub r2, r2, ip
934 b .Lcfu_dest_aligned
935
936 -ENTRY(__copy_from_user)
937 +ENTRY(___copy_from_user)
938 stmfd sp!, {r0, r2, r4 - r7, lr}
939 cmp r2, #4
940 blt .Lcfu_not_enough
941 @@ -544,7 +544,7 @@ USER( T(ldrgeb) r3, [r1], #1) @ May fault
942 USER( T(ldrgtb) r3, [r1], #1) @ May fault
943 strgtb r3, [r0], #1
944 b .Lcfu_finished
945 -ENDPROC(__copy_from_user)
946 +ENDPROC(___copy_from_user)
947
948 .pushsection .fixup,"ax"
949 .align 0
950 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
951 index 025f742..8432b08 100644
952 --- a/arch/arm/lib/uaccess_with_memcpy.c
953 +++ b/arch/arm/lib/uaccess_with_memcpy.c
954 @@ -104,7 +104,7 @@ out:
955 }
956
957 unsigned long
958 -__copy_to_user(void __user *to, const void *from, unsigned long n)
959 +___copy_to_user(void __user *to, const void *from, unsigned long n)
960 {
961 /*
962 * This test is stubbed out of the main function above to keep
963 diff --git a/arch/arm/mach-ux500/mbox-db5500.c b/arch/arm/mach-ux500/mbox-db5500.c
964 index 2b2d51c..0127490 100644
965 --- a/arch/arm/mach-ux500/mbox-db5500.c
966 +++ b/arch/arm/mach-ux500/mbox-db5500.c
967 @@ -168,7 +168,7 @@ static ssize_t mbox_read_fifo(struct device *dev,
968 return sprintf(buf, "0x%X\n", mbox_value);
969 }
970
971 -static DEVICE_ATTR(fifo, S_IWUGO | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
972 +static DEVICE_ATTR(fifo, S_IWUSR | S_IRUGO, mbox_read_fifo, mbox_write_fifo);
973
974 static int mbox_show(struct seq_file *s, void *data)
975 {
976 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
977 index aa33949..b242a2f 100644
978 --- a/arch/arm/mm/fault.c
979 +++ b/arch/arm/mm/fault.c
980 @@ -183,6 +183,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
981 }
982 #endif
983
984 +#ifdef CONFIG_PAX_PAGEEXEC
985 + if (fsr & FSR_LNX_PF) {
986 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
987 + do_group_exit(SIGKILL);
988 + }
989 +#endif
990 +
991 tsk->thread.address = addr;
992 tsk->thread.error_code = fsr;
993 tsk->thread.trap_no = 14;
994 @@ -384,6 +391,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
995 }
996 #endif /* CONFIG_MMU */
997
998 +#ifdef CONFIG_PAX_PAGEEXEC
999 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1000 +{
1001 + long i;
1002 +
1003 + printk(KERN_ERR "PAX: bytes at PC: ");
1004 + for (i = 0; i < 20; i++) {
1005 + unsigned char c;
1006 + if (get_user(c, (__force unsigned char __user *)pc+i))
1007 + printk(KERN_CONT "?? ");
1008 + else
1009 + printk(KERN_CONT "%02x ", c);
1010 + }
1011 + printk("\n");
1012 +
1013 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1014 + for (i = -1; i < 20; i++) {
1015 + unsigned long c;
1016 + if (get_user(c, (__force unsigned long __user *)sp+i))
1017 + printk(KERN_CONT "???????? ");
1018 + else
1019 + printk(KERN_CONT "%08lx ", c);
1020 + }
1021 + printk("\n");
1022 +}
1023 +#endif
1024 +
1025 /*
1026 * First Level Translation Fault Handler
1027 *
1028 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1029 index 44b628e..623ee2a 100644
1030 --- a/arch/arm/mm/mmap.c
1031 +++ b/arch/arm/mm/mmap.c
1032 @@ -54,6 +54,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1033 if (len > TASK_SIZE)
1034 return -ENOMEM;
1035
1036 +#ifdef CONFIG_PAX_RANDMMAP
1037 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1038 +#endif
1039 +
1040 if (addr) {
1041 if (do_align)
1042 addr = COLOUR_ALIGN(addr, pgoff);
1043 @@ -61,15 +65,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1044 addr = PAGE_ALIGN(addr);
1045
1046 vma = find_vma(mm, addr);
1047 - if (TASK_SIZE - len >= addr &&
1048 - (!vma || addr + len <= vma->vm_start))
1049 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1050 return addr;
1051 }
1052 if (len > mm->cached_hole_size) {
1053 - start_addr = addr = mm->free_area_cache;
1054 + start_addr = addr = mm->free_area_cache;
1055 } else {
1056 - start_addr = addr = TASK_UNMAPPED_BASE;
1057 - mm->cached_hole_size = 0;
1058 + start_addr = addr = mm->mmap_base;
1059 + mm->cached_hole_size = 0;
1060 }
1061 /* 8 bits of randomness in 20 address space bits */
1062 if ((current->flags & PF_RANDOMIZE) &&
1063 @@ -89,14 +92,14 @@ full_search:
1064 * Start a new search - just in case we missed
1065 * some holes.
1066 */
1067 - if (start_addr != TASK_UNMAPPED_BASE) {
1068 - start_addr = addr = TASK_UNMAPPED_BASE;
1069 + if (start_addr != mm->mmap_base) {
1070 + start_addr = addr = mm->mmap_base;
1071 mm->cached_hole_size = 0;
1072 goto full_search;
1073 }
1074 return -ENOMEM;
1075 }
1076 - if (!vma || addr + len <= vma->vm_start) {
1077 + if (check_heap_stack_gap(vma, addr, len)) {
1078 /*
1079 * Remember the place where we stopped the search:
1080 */
1081 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
1082 index 3b3159b..425ea94 100644
1083 --- a/arch/avr32/include/asm/elf.h
1084 +++ b/arch/avr32/include/asm/elf.h
1085 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
1086 the loader. We need to make sure that it is out of the way of the program
1087 that it will "exec", and that there is sufficient room for the brk. */
1088
1089 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1090 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1091
1092 +#ifdef CONFIG_PAX_ASLR
1093 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
1094 +
1095 +#define PAX_DELTA_MMAP_LEN 15
1096 +#define PAX_DELTA_STACK_LEN 15
1097 +#endif
1098
1099 /* This yields a mask that user programs can use to figure out what
1100 instruction set this CPU supports. This could be done in user space,
1101 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
1102 index b7f5c68..556135c 100644
1103 --- a/arch/avr32/include/asm/kmap_types.h
1104 +++ b/arch/avr32/include/asm/kmap_types.h
1105 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
1106 D(11) KM_IRQ1,
1107 D(12) KM_SOFTIRQ0,
1108 D(13) KM_SOFTIRQ1,
1109 -D(14) KM_TYPE_NR
1110 +D(14) KM_CLEARPAGE,
1111 +D(15) KM_TYPE_NR
1112 };
1113
1114 #undef D
1115 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
1116 index f7040a1..db9f300 100644
1117 --- a/arch/avr32/mm/fault.c
1118 +++ b/arch/avr32/mm/fault.c
1119 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
1120
1121 int exception_trace = 1;
1122
1123 +#ifdef CONFIG_PAX_PAGEEXEC
1124 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1125 +{
1126 + unsigned long i;
1127 +
1128 + printk(KERN_ERR "PAX: bytes at PC: ");
1129 + for (i = 0; i < 20; i++) {
1130 + unsigned char c;
1131 + if (get_user(c, (unsigned char *)pc+i))
1132 + printk(KERN_CONT "???????? ");
1133 + else
1134 + printk(KERN_CONT "%02x ", c);
1135 + }
1136 + printk("\n");
1137 +}
1138 +#endif
1139 +
1140 /*
1141 * This routine handles page faults. It determines the address and the
1142 * problem, and then passes it off to one of the appropriate routines.
1143 @@ -156,6 +173,16 @@ bad_area:
1144 up_read(&mm->mmap_sem);
1145
1146 if (user_mode(regs)) {
1147 +
1148 +#ifdef CONFIG_PAX_PAGEEXEC
1149 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
1150 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
1151 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
1152 + do_group_exit(SIGKILL);
1153 + }
1154 + }
1155 +#endif
1156 +
1157 if (exception_trace && printk_ratelimit())
1158 printk("%s%s[%d]: segfault at %08lx pc %08lx "
1159 "sp %08lx ecr %lu\n",
1160 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
1161 index 0d8a7d6..27278e4 100644
1162 --- a/arch/frv/include/asm/atomic.h
1163 +++ b/arch/frv/include/asm/atomic.h
1164 @@ -241,6 +241,16 @@ extern uint32_t __xchg_32(uint32_t i, volatile void *v);
1165 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
1166 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
1167
1168 +#define atomic64_read_unchecked(v) atomic64_read(v)
1169 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1170 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1171 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1172 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1173 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1174 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1175 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1176 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1177 +
1178 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
1179 {
1180 int c, old;
1181 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
1182 index f8e16b2..c73ff79 100644
1183 --- a/arch/frv/include/asm/kmap_types.h
1184 +++ b/arch/frv/include/asm/kmap_types.h
1185 @@ -23,6 +23,7 @@ enum km_type {
1186 KM_IRQ1,
1187 KM_SOFTIRQ0,
1188 KM_SOFTIRQ1,
1189 + KM_CLEARPAGE,
1190 KM_TYPE_NR
1191 };
1192
1193 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
1194 index 385fd30..6c3d97e 100644
1195 --- a/arch/frv/mm/elf-fdpic.c
1196 +++ b/arch/frv/mm/elf-fdpic.c
1197 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1198 if (addr) {
1199 addr = PAGE_ALIGN(addr);
1200 vma = find_vma(current->mm, addr);
1201 - if (TASK_SIZE - len >= addr &&
1202 - (!vma || addr + len <= vma->vm_start))
1203 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1204 goto success;
1205 }
1206
1207 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1208 for (; vma; vma = vma->vm_next) {
1209 if (addr > limit)
1210 break;
1211 - if (addr + len <= vma->vm_start)
1212 + if (check_heap_stack_gap(vma, addr, len))
1213 goto success;
1214 addr = vma->vm_end;
1215 }
1216 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
1217 for (; vma; vma = vma->vm_next) {
1218 if (addr > limit)
1219 break;
1220 - if (addr + len <= vma->vm_start)
1221 + if (check_heap_stack_gap(vma, addr, len))
1222 goto success;
1223 addr = vma->vm_end;
1224 }
1225 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
1226 index 3fad89e..3b07967 100644
1227 --- a/arch/ia64/include/asm/atomic.h
1228 +++ b/arch/ia64/include/asm/atomic.h
1229 @@ -209,6 +209,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
1230 #define atomic64_inc(v) atomic64_add(1, (v))
1231 #define atomic64_dec(v) atomic64_sub(1, (v))
1232
1233 +#define atomic64_read_unchecked(v) atomic64_read(v)
1234 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1235 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1236 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1237 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1238 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1239 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1240 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1241 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1242 +
1243 /* Atomic operations are already serializing */
1244 #define smp_mb__before_atomic_dec() barrier()
1245 #define smp_mb__after_atomic_dec() barrier()
1246 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
1247 index b5298eb..67c6e62 100644
1248 --- a/arch/ia64/include/asm/elf.h
1249 +++ b/arch/ia64/include/asm/elf.h
1250 @@ -42,6 +42,13 @@
1251 */
1252 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
1253
1254 +#ifdef CONFIG_PAX_ASLR
1255 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
1256 +
1257 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1258 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
1259 +#endif
1260 +
1261 #define PT_IA_64_UNWIND 0x70000001
1262
1263 /* IA-64 relocations: */
1264 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
1265 index 1a97af3..7529d31 100644
1266 --- a/arch/ia64/include/asm/pgtable.h
1267 +++ b/arch/ia64/include/asm/pgtable.h
1268 @@ -12,7 +12,7 @@
1269 * David Mosberger-Tang <davidm@hpl.hp.com>
1270 */
1271
1272 -
1273 +#include <linux/const.h>
1274 #include <asm/mman.h>
1275 #include <asm/page.h>
1276 #include <asm/processor.h>
1277 @@ -143,6 +143,17 @@
1278 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1279 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1280 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
1281 +
1282 +#ifdef CONFIG_PAX_PAGEEXEC
1283 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
1284 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1285 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
1286 +#else
1287 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1288 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1289 +# define PAGE_COPY_NOEXEC PAGE_COPY
1290 +#endif
1291 +
1292 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
1293 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
1294 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
1295 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
1296 index b77768d..e0795eb 100644
1297 --- a/arch/ia64/include/asm/spinlock.h
1298 +++ b/arch/ia64/include/asm/spinlock.h
1299 @@ -72,7 +72,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
1300 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
1301
1302 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
1303 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
1304 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
1305 }
1306
1307 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
1308 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
1309 index 449c8c0..432a3d2 100644
1310 --- a/arch/ia64/include/asm/uaccess.h
1311 +++ b/arch/ia64/include/asm/uaccess.h
1312 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1313 const void *__cu_from = (from); \
1314 long __cu_len = (n); \
1315 \
1316 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
1317 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
1318 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
1319 __cu_len; \
1320 })
1321 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
1322 long __cu_len = (n); \
1323 \
1324 __chk_user_ptr(__cu_from); \
1325 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
1326 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
1327 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
1328 __cu_len; \
1329 })
1330 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
1331 index 24603be..948052d 100644
1332 --- a/arch/ia64/kernel/module.c
1333 +++ b/arch/ia64/kernel/module.c
1334 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
1335 void
1336 module_free (struct module *mod, void *module_region)
1337 {
1338 - if (mod && mod->arch.init_unw_table &&
1339 - module_region == mod->module_init) {
1340 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
1341 unw_remove_unwind_table(mod->arch.init_unw_table);
1342 mod->arch.init_unw_table = NULL;
1343 }
1344 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
1345 }
1346
1347 static inline int
1348 +in_init_rx (const struct module *mod, uint64_t addr)
1349 +{
1350 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
1351 +}
1352 +
1353 +static inline int
1354 +in_init_rw (const struct module *mod, uint64_t addr)
1355 +{
1356 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
1357 +}
1358 +
1359 +static inline int
1360 in_init (const struct module *mod, uint64_t addr)
1361 {
1362 - return addr - (uint64_t) mod->module_init < mod->init_size;
1363 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
1364 +}
1365 +
1366 +static inline int
1367 +in_core_rx (const struct module *mod, uint64_t addr)
1368 +{
1369 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
1370 +}
1371 +
1372 +static inline int
1373 +in_core_rw (const struct module *mod, uint64_t addr)
1374 +{
1375 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
1376 }
1377
1378 static inline int
1379 in_core (const struct module *mod, uint64_t addr)
1380 {
1381 - return addr - (uint64_t) mod->module_core < mod->core_size;
1382 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
1383 }
1384
1385 static inline int
1386 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
1387 break;
1388
1389 case RV_BDREL:
1390 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
1391 + if (in_init_rx(mod, val))
1392 + val -= (uint64_t) mod->module_init_rx;
1393 + else if (in_init_rw(mod, val))
1394 + val -= (uint64_t) mod->module_init_rw;
1395 + else if (in_core_rx(mod, val))
1396 + val -= (uint64_t) mod->module_core_rx;
1397 + else if (in_core_rw(mod, val))
1398 + val -= (uint64_t) mod->module_core_rw;
1399 break;
1400
1401 case RV_LTV:
1402 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
1403 * addresses have been selected...
1404 */
1405 uint64_t gp;
1406 - if (mod->core_size > MAX_LTOFF)
1407 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
1408 /*
1409 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
1410 * at the end of the module.
1411 */
1412 - gp = mod->core_size - MAX_LTOFF / 2;
1413 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
1414 else
1415 - gp = mod->core_size / 2;
1416 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
1417 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
1418 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
1419 mod->arch.gp = gp;
1420 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
1421 }
1422 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
1423 index 609d500..7dde2a8 100644
1424 --- a/arch/ia64/kernel/sys_ia64.c
1425 +++ b/arch/ia64/kernel/sys_ia64.c
1426 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1427 if (REGION_NUMBER(addr) == RGN_HPAGE)
1428 addr = 0;
1429 #endif
1430 +
1431 +#ifdef CONFIG_PAX_RANDMMAP
1432 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1433 + addr = mm->free_area_cache;
1434 + else
1435 +#endif
1436 +
1437 if (!addr)
1438 addr = mm->free_area_cache;
1439
1440 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
1441 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
1442 /* At this point: (!vma || addr < vma->vm_end). */
1443 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
1444 - if (start_addr != TASK_UNMAPPED_BASE) {
1445 + if (start_addr != mm->mmap_base) {
1446 /* Start a new search --- just in case we missed some holes. */
1447 - addr = TASK_UNMAPPED_BASE;
1448 + addr = mm->mmap_base;
1449 goto full_search;
1450 }
1451 return -ENOMEM;
1452 }
1453 - if (!vma || addr + len <= vma->vm_start) {
1454 + if (check_heap_stack_gap(vma, addr, len)) {
1455 /* Remember the address where we stopped this search: */
1456 mm->free_area_cache = addr + len;
1457 return addr;
1458 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
1459 index 53c0ba0..2accdde 100644
1460 --- a/arch/ia64/kernel/vmlinux.lds.S
1461 +++ b/arch/ia64/kernel/vmlinux.lds.S
1462 @@ -199,7 +199,7 @@ SECTIONS {
1463 /* Per-cpu data: */
1464 . = ALIGN(PERCPU_PAGE_SIZE);
1465 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
1466 - __phys_per_cpu_start = __per_cpu_load;
1467 + __phys_per_cpu_start = per_cpu_load;
1468 /*
1469 * ensure percpu data fits
1470 * into percpu page size
1471 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
1472 index 20b3593..1ce77f0 100644
1473 --- a/arch/ia64/mm/fault.c
1474 +++ b/arch/ia64/mm/fault.c
1475 @@ -73,6 +73,23 @@ mapped_kernel_page_is_present (unsigned long address)
1476 return pte_present(pte);
1477 }
1478
1479 +#ifdef CONFIG_PAX_PAGEEXEC
1480 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1481 +{
1482 + unsigned long i;
1483 +
1484 + printk(KERN_ERR "PAX: bytes at PC: ");
1485 + for (i = 0; i < 8; i++) {
1486 + unsigned int c;
1487 + if (get_user(c, (unsigned int *)pc+i))
1488 + printk(KERN_CONT "???????? ");
1489 + else
1490 + printk(KERN_CONT "%08x ", c);
1491 + }
1492 + printk("\n");
1493 +}
1494 +#endif
1495 +
1496 void __kprobes
1497 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
1498 {
1499 @@ -146,9 +163,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
1500 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
1501 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
1502
1503 - if ((vma->vm_flags & mask) != mask)
1504 + if ((vma->vm_flags & mask) != mask) {
1505 +
1506 +#ifdef CONFIG_PAX_PAGEEXEC
1507 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
1508 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
1509 + goto bad_area;
1510 +
1511 + up_read(&mm->mmap_sem);
1512 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
1513 + do_group_exit(SIGKILL);
1514 + }
1515 +#endif
1516 +
1517 goto bad_area;
1518
1519 + }
1520 +
1521 /*
1522 * If for any reason at all we couldn't handle the fault, make
1523 * sure we exit gracefully rather than endlessly redo the
1524 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
1525 index 5ca674b..e0e1b70 100644
1526 --- a/arch/ia64/mm/hugetlbpage.c
1527 +++ b/arch/ia64/mm/hugetlbpage.c
1528 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
1529 /* At this point: (!vmm || addr < vmm->vm_end). */
1530 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
1531 return -ENOMEM;
1532 - if (!vmm || (addr + len) <= vmm->vm_start)
1533 + if (check_heap_stack_gap(vmm, addr, len))
1534 return addr;
1535 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
1536 }
1537 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
1538 index 00cb0e2..2ad8024 100644
1539 --- a/arch/ia64/mm/init.c
1540 +++ b/arch/ia64/mm/init.c
1541 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
1542 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
1543 vma->vm_end = vma->vm_start + PAGE_SIZE;
1544 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
1545 +
1546 +#ifdef CONFIG_PAX_PAGEEXEC
1547 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
1548 + vma->vm_flags &= ~VM_EXEC;
1549 +
1550 +#ifdef CONFIG_PAX_MPROTECT
1551 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
1552 + vma->vm_flags &= ~VM_MAYEXEC;
1553 +#endif
1554 +
1555 + }
1556 +#endif
1557 +
1558 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
1559 down_write(&current->mm->mmap_sem);
1560 if (insert_vm_struct(current->mm, vma)) {
1561 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
1562 index 82abd15..d95ae5d 100644
1563 --- a/arch/m32r/lib/usercopy.c
1564 +++ b/arch/m32r/lib/usercopy.c
1565 @@ -14,6 +14,9 @@
1566 unsigned long
1567 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1568 {
1569 + if ((long)n < 0)
1570 + return n;
1571 +
1572 prefetch(from);
1573 if (access_ok(VERIFY_WRITE, to, n))
1574 __copy_user(to,from,n);
1575 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
1576 unsigned long
1577 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
1578 {
1579 + if ((long)n < 0)
1580 + return n;
1581 +
1582 prefetchw(to);
1583 if (access_ok(VERIFY_READ, from, n))
1584 __copy_user_zeroing(to,from,n);
1585 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
1586 index 1d93f81..db26f2a 100644
1587 --- a/arch/mips/include/asm/atomic.h
1588 +++ b/arch/mips/include/asm/atomic.h
1589 @@ -765,6 +765,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
1590 */
1591 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
1592
1593 +#define atomic64_read_unchecked(v) atomic64_read(v)
1594 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1595 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1596 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1597 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1598 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1599 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1600 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1601 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1602 +
1603 #endif /* CONFIG_64BIT */
1604
1605 /*
1606 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
1607 index 455c0ac..ad65fbe 100644
1608 --- a/arch/mips/include/asm/elf.h
1609 +++ b/arch/mips/include/asm/elf.h
1610 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
1611 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1612 #endif
1613
1614 +#ifdef CONFIG_PAX_ASLR
1615 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1616 +
1617 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1618 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1619 +#endif
1620 +
1621 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1622 struct linux_binprm;
1623 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
1624 int uses_interp);
1625
1626 -struct mm_struct;
1627 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1628 -#define arch_randomize_brk arch_randomize_brk
1629 -
1630 #endif /* _ASM_ELF_H */
1631 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
1632 index e59cd1a..8e329d6 100644
1633 --- a/arch/mips/include/asm/page.h
1634 +++ b/arch/mips/include/asm/page.h
1635 @@ -93,7 +93,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
1636 #ifdef CONFIG_CPU_MIPS32
1637 typedef struct { unsigned long pte_low, pte_high; } pte_t;
1638 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
1639 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
1640 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
1641 #else
1642 typedef struct { unsigned long long pte; } pte_t;
1643 #define pte_val(x) ((x).pte)
1644 diff --git a/arch/mips/include/asm/system.h b/arch/mips/include/asm/system.h
1645 index 6018c80..7c37203 100644
1646 --- a/arch/mips/include/asm/system.h
1647 +++ b/arch/mips/include/asm/system.h
1648 @@ -230,6 +230,6 @@ extern void per_cpu_trap_init(void);
1649 */
1650 #define __ARCH_WANT_UNLOCKED_CTXSW
1651
1652 -extern unsigned long arch_align_stack(unsigned long sp);
1653 +#define arch_align_stack(x) ((x) & ~0xfUL)
1654
1655 #endif /* _ASM_SYSTEM_H */
1656 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
1657 index 9fdd8bc..4bd7f1a 100644
1658 --- a/arch/mips/kernel/binfmt_elfn32.c
1659 +++ b/arch/mips/kernel/binfmt_elfn32.c
1660 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1661 #undef ELF_ET_DYN_BASE
1662 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1663
1664 +#ifdef CONFIG_PAX_ASLR
1665 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1666 +
1667 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1668 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1669 +#endif
1670 +
1671 #include <asm/processor.h>
1672 #include <linux/module.h>
1673 #include <linux/elfcore.h>
1674 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
1675 index ff44823..97f8906 100644
1676 --- a/arch/mips/kernel/binfmt_elfo32.c
1677 +++ b/arch/mips/kernel/binfmt_elfo32.c
1678 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
1679 #undef ELF_ET_DYN_BASE
1680 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
1681
1682 +#ifdef CONFIG_PAX_ASLR
1683 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
1684 +
1685 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1686 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
1687 +#endif
1688 +
1689 #include <asm/processor.h>
1690
1691 /*
1692 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
1693 index c47f96e..661d418 100644
1694 --- a/arch/mips/kernel/process.c
1695 +++ b/arch/mips/kernel/process.c
1696 @@ -481,15 +481,3 @@ unsigned long get_wchan(struct task_struct *task)
1697 out:
1698 return pc;
1699 }
1700 -
1701 -/*
1702 - * Don't forget that the stack pointer must be aligned on a 8 bytes
1703 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
1704 - */
1705 -unsigned long arch_align_stack(unsigned long sp)
1706 -{
1707 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
1708 - sp -= get_random_int() & ~PAGE_MASK;
1709 -
1710 - return sp & ALMASK;
1711 -}
1712 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
1713 index 937cf33..adb39bb 100644
1714 --- a/arch/mips/mm/fault.c
1715 +++ b/arch/mips/mm/fault.c
1716 @@ -28,6 +28,23 @@
1717 #include <asm/highmem.h> /* For VMALLOC_END */
1718 #include <linux/kdebug.h>
1719
1720 +#ifdef CONFIG_PAX_PAGEEXEC
1721 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1722 +{
1723 + unsigned long i;
1724 +
1725 + printk(KERN_ERR "PAX: bytes at PC: ");
1726 + for (i = 0; i < 5; i++) {
1727 + unsigned int c;
1728 + if (get_user(c, (unsigned int *)pc+i))
1729 + printk(KERN_CONT "???????? ");
1730 + else
1731 + printk(KERN_CONT "%08x ", c);
1732 + }
1733 + printk("\n");
1734 +}
1735 +#endif
1736 +
1737 /*
1738 * This routine handles page faults. It determines the address,
1739 * and the problem, and then passes it off to one of the appropriate
1740 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
1741 index 302d779..7d35bf8 100644
1742 --- a/arch/mips/mm/mmap.c
1743 +++ b/arch/mips/mm/mmap.c
1744 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1745 do_color_align = 1;
1746
1747 /* requesting a specific address */
1748 +
1749 +#ifdef CONFIG_PAX_RANDMMAP
1750 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
1751 +#endif
1752 +
1753 if (addr) {
1754 if (do_color_align)
1755 addr = COLOUR_ALIGN(addr, pgoff);
1756 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1757 addr = PAGE_ALIGN(addr);
1758
1759 vma = find_vma(mm, addr);
1760 - if (TASK_SIZE - len >= addr &&
1761 - (!vma || addr + len <= vma->vm_start))
1762 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
1763 return addr;
1764 }
1765
1766 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1767 /* At this point: (!vma || addr < vma->vm_end). */
1768 if (TASK_SIZE - len < addr)
1769 return -ENOMEM;
1770 - if (!vma || addr + len <= vma->vm_start)
1771 + if (check_heap_stack_gap(vmm, addr, len))
1772 return addr;
1773 addr = vma->vm_end;
1774 if (do_color_align)
1775 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1776 /* make sure it can fit in the remaining address space */
1777 if (likely(addr > len)) {
1778 vma = find_vma(mm, addr - len);
1779 - if (!vma || addr <= vma->vm_start) {
1780 + if (check_heap_stack_gap(vmm, addr - len, len))
1781 /* cache the address as a hint for next time */
1782 return mm->free_area_cache = addr - len;
1783 }
1784 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
1785 * return with success:
1786 */
1787 vma = find_vma(mm, addr);
1788 - if (likely(!vma || addr + len <= vma->vm_start)) {
1789 + if (check_heap_stack_gap(vmm, addr, len)) {
1790 /* cache the address as a hint for next time */
1791 return mm->free_area_cache = addr;
1792 }
1793 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1794 mm->unmap_area = arch_unmap_area_topdown;
1795 }
1796 }
1797 -
1798 -static inline unsigned long brk_rnd(void)
1799 -{
1800 - unsigned long rnd = get_random_int();
1801 -
1802 - rnd = rnd << PAGE_SHIFT;
1803 - /* 8MB for 32bit, 256MB for 64bit */
1804 - if (TASK_IS_32BIT_ADDR)
1805 - rnd = rnd & 0x7ffffful;
1806 - else
1807 - rnd = rnd & 0xffffffful;
1808 -
1809 - return rnd;
1810 -}
1811 -
1812 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1813 -{
1814 - unsigned long base = mm->brk;
1815 - unsigned long ret;
1816 -
1817 - ret = PAGE_ALIGN(base + brk_rnd());
1818 -
1819 - if (ret < mm->brk)
1820 - return mm->brk;
1821 -
1822 - return ret;
1823 -}
1824 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
1825 index 4054b31..3c5ea1c 100644
1826 --- a/arch/parisc/include/asm/atomic.h
1827 +++ b/arch/parisc/include/asm/atomic.h
1828 @@ -335,6 +335,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
1829
1830 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
1831
1832 +#define atomic64_read_unchecked(v) atomic64_read(v)
1833 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
1834 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
1835 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
1836 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
1837 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
1838 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
1839 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
1840 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
1841 +
1842 #endif /* !CONFIG_64BIT */
1843
1844
1845 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
1846 index 19f6cb1..6c78cf2 100644
1847 --- a/arch/parisc/include/asm/elf.h
1848 +++ b/arch/parisc/include/asm/elf.h
1849 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
1850
1851 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
1852
1853 +#ifdef CONFIG_PAX_ASLR
1854 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
1855 +
1856 +#define PAX_DELTA_MMAP_LEN 16
1857 +#define PAX_DELTA_STACK_LEN 16
1858 +#endif
1859 +
1860 /* This yields a mask that user programs can use to figure out what
1861 instruction set this CPU supports. This could be done in user space,
1862 but it's not easy, and we've already done it here. */
1863 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
1864 index 22dadeb..f6c2be4 100644
1865 --- a/arch/parisc/include/asm/pgtable.h
1866 +++ b/arch/parisc/include/asm/pgtable.h
1867 @@ -210,6 +210,17 @@ struct vm_area_struct;
1868 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
1869 #define PAGE_COPY PAGE_EXECREAD
1870 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
1871 +
1872 +#ifdef CONFIG_PAX_PAGEEXEC
1873 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
1874 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1875 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
1876 +#else
1877 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
1878 +# define PAGE_COPY_NOEXEC PAGE_COPY
1879 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
1880 +#endif
1881 +
1882 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
1883 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
1884 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
1885 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
1886 index 5e34ccf..672bc9c 100644
1887 --- a/arch/parisc/kernel/module.c
1888 +++ b/arch/parisc/kernel/module.c
1889 @@ -98,16 +98,38 @@
1890
1891 /* three functions to determine where in the module core
1892 * or init pieces the location is */
1893 +static inline int in_init_rx(struct module *me, void *loc)
1894 +{
1895 + return (loc >= me->module_init_rx &&
1896 + loc < (me->module_init_rx + me->init_size_rx));
1897 +}
1898 +
1899 +static inline int in_init_rw(struct module *me, void *loc)
1900 +{
1901 + return (loc >= me->module_init_rw &&
1902 + loc < (me->module_init_rw + me->init_size_rw));
1903 +}
1904 +
1905 static inline int in_init(struct module *me, void *loc)
1906 {
1907 - return (loc >= me->module_init &&
1908 - loc <= (me->module_init + me->init_size));
1909 + return in_init_rx(me, loc) || in_init_rw(me, loc);
1910 +}
1911 +
1912 +static inline int in_core_rx(struct module *me, void *loc)
1913 +{
1914 + return (loc >= me->module_core_rx &&
1915 + loc < (me->module_core_rx + me->core_size_rx));
1916 +}
1917 +
1918 +static inline int in_core_rw(struct module *me, void *loc)
1919 +{
1920 + return (loc >= me->module_core_rw &&
1921 + loc < (me->module_core_rw + me->core_size_rw));
1922 }
1923
1924 static inline int in_core(struct module *me, void *loc)
1925 {
1926 - return (loc >= me->module_core &&
1927 - loc <= (me->module_core + me->core_size));
1928 + return in_core_rx(me, loc) || in_core_rw(me, loc);
1929 }
1930
1931 static inline int in_local(struct module *me, void *loc)
1932 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
1933 }
1934
1935 /* align things a bit */
1936 - me->core_size = ALIGN(me->core_size, 16);
1937 - me->arch.got_offset = me->core_size;
1938 - me->core_size += gots * sizeof(struct got_entry);
1939 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1940 + me->arch.got_offset = me->core_size_rw;
1941 + me->core_size_rw += gots * sizeof(struct got_entry);
1942
1943 - me->core_size = ALIGN(me->core_size, 16);
1944 - me->arch.fdesc_offset = me->core_size;
1945 - me->core_size += fdescs * sizeof(Elf_Fdesc);
1946 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
1947 + me->arch.fdesc_offset = me->core_size_rw;
1948 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
1949
1950 me->arch.got_max = gots;
1951 me->arch.fdesc_max = fdescs;
1952 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
1953
1954 BUG_ON(value == 0);
1955
1956 - got = me->module_core + me->arch.got_offset;
1957 + got = me->module_core_rw + me->arch.got_offset;
1958 for (i = 0; got[i].addr; i++)
1959 if (got[i].addr == value)
1960 goto out;
1961 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
1962 #ifdef CONFIG_64BIT
1963 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1964 {
1965 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
1966 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
1967
1968 if (!value) {
1969 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
1970 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
1971
1972 /* Create new one */
1973 fdesc->addr = value;
1974 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1975 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1976 return (Elf_Addr)fdesc;
1977 }
1978 #endif /* CONFIG_64BIT */
1979 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
1980
1981 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
1982 end = table + sechdrs[me->arch.unwind_section].sh_size;
1983 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
1984 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
1985
1986 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
1987 me->arch.unwind_section, table, end, gp);
1988 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
1989 index c9b9322..02d8940 100644
1990 --- a/arch/parisc/kernel/sys_parisc.c
1991 +++ b/arch/parisc/kernel/sys_parisc.c
1992 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
1993 /* At this point: (!vma || addr < vma->vm_end). */
1994 if (TASK_SIZE - len < addr)
1995 return -ENOMEM;
1996 - if (!vma || addr + len <= vma->vm_start)
1997 + if (check_heap_stack_gap(vma, addr, len))
1998 return addr;
1999 addr = vma->vm_end;
2000 }
2001 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
2002 /* At this point: (!vma || addr < vma->vm_end). */
2003 if (TASK_SIZE - len < addr)
2004 return -ENOMEM;
2005 - if (!vma || addr + len <= vma->vm_start)
2006 + if (check_heap_stack_gap(vma, addr, len))
2007 return addr;
2008 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
2009 if (addr < vma->vm_end) /* handle wraparound */
2010 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
2011 if (flags & MAP_FIXED)
2012 return addr;
2013 if (!addr)
2014 - addr = TASK_UNMAPPED_BASE;
2015 + addr = current->mm->mmap_base;
2016
2017 if (filp) {
2018 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2019 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
2020 index f19e660..414fe24 100644
2021 --- a/arch/parisc/kernel/traps.c
2022 +++ b/arch/parisc/kernel/traps.c
2023 @@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
2024
2025 down_read(&current->mm->mmap_sem);
2026 vma = find_vma(current->mm,regs->iaoq[0]);
2027 - if (vma && (regs->iaoq[0] >= vma->vm_start)
2028 - && (vma->vm_flags & VM_EXEC)) {
2029 -
2030 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2031 fault_address = regs->iaoq[0];
2032 fault_space = regs->iasq[0];
2033
2034 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
2035 index 18162ce..94de376 100644
2036 --- a/arch/parisc/mm/fault.c
2037 +++ b/arch/parisc/mm/fault.c
2038 @@ -15,6 +15,7 @@
2039 #include <linux/sched.h>
2040 #include <linux/interrupt.h>
2041 #include <linux/module.h>
2042 +#include <linux/unistd.h>
2043
2044 #include <asm/uaccess.h>
2045 #include <asm/traps.h>
2046 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
2047 static unsigned long
2048 parisc_acctyp(unsigned long code, unsigned int inst)
2049 {
2050 - if (code == 6 || code == 16)
2051 + if (code == 6 || code == 7 || code == 16)
2052 return VM_EXEC;
2053
2054 switch (inst & 0xf0000000) {
2055 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
2056 }
2057 #endif
2058
2059 +#ifdef CONFIG_PAX_PAGEEXEC
2060 +/*
2061 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2062 + *
2063 + * returns 1 when task should be killed
2064 + * 2 when rt_sigreturn trampoline was detected
2065 + * 3 when unpatched PLT trampoline was detected
2066 + */
2067 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2068 +{
2069 +
2070 +#ifdef CONFIG_PAX_EMUPLT
2071 + int err;
2072 +
2073 + do { /* PaX: unpatched PLT emulation */
2074 + unsigned int bl, depwi;
2075 +
2076 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2077 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2078 +
2079 + if (err)
2080 + break;
2081 +
2082 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2083 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2084 +
2085 + err = get_user(ldw, (unsigned int *)addr);
2086 + err |= get_user(bv, (unsigned int *)(addr+4));
2087 + err |= get_user(ldw2, (unsigned int *)(addr+8));
2088 +
2089 + if (err)
2090 + break;
2091 +
2092 + if (ldw == 0x0E801096U &&
2093 + bv == 0xEAC0C000U &&
2094 + ldw2 == 0x0E881095U)
2095 + {
2096 + unsigned int resolver, map;
2097 +
2098 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2099 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2100 + if (err)
2101 + break;
2102 +
2103 + regs->gr[20] = instruction_pointer(regs)+8;
2104 + regs->gr[21] = map;
2105 + regs->gr[22] = resolver;
2106 + regs->iaoq[0] = resolver | 3UL;
2107 + regs->iaoq[1] = regs->iaoq[0] + 4;
2108 + return 3;
2109 + }
2110 + }
2111 + } while (0);
2112 +#endif
2113 +
2114 +#ifdef CONFIG_PAX_EMUTRAMP
2115 +
2116 +#ifndef CONFIG_PAX_EMUSIGRT
2117 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2118 + return 1;
2119 +#endif
2120 +
2121 + do { /* PaX: rt_sigreturn emulation */
2122 + unsigned int ldi1, ldi2, bel, nop;
2123 +
2124 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2125 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2126 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2127 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2128 +
2129 + if (err)
2130 + break;
2131 +
2132 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2133 + ldi2 == 0x3414015AU &&
2134 + bel == 0xE4008200U &&
2135 + nop == 0x08000240U)
2136 + {
2137 + regs->gr[25] = (ldi1 & 2) >> 1;
2138 + regs->gr[20] = __NR_rt_sigreturn;
2139 + regs->gr[31] = regs->iaoq[1] + 16;
2140 + regs->sr[0] = regs->iasq[1];
2141 + regs->iaoq[0] = 0x100UL;
2142 + regs->iaoq[1] = regs->iaoq[0] + 4;
2143 + regs->iasq[0] = regs->sr[2];
2144 + regs->iasq[1] = regs->sr[2];
2145 + return 2;
2146 + }
2147 + } while (0);
2148 +#endif
2149 +
2150 + return 1;
2151 +}
2152 +
2153 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2154 +{
2155 + unsigned long i;
2156 +
2157 + printk(KERN_ERR "PAX: bytes at PC: ");
2158 + for (i = 0; i < 5; i++) {
2159 + unsigned int c;
2160 + if (get_user(c, (unsigned int *)pc+i))
2161 + printk(KERN_CONT "???????? ");
2162 + else
2163 + printk(KERN_CONT "%08x ", c);
2164 + }
2165 + printk("\n");
2166 +}
2167 +#endif
2168 +
2169 int fixup_exception(struct pt_regs *regs)
2170 {
2171 const struct exception_table_entry *fix;
2172 @@ -192,8 +303,33 @@ good_area:
2173
2174 acc_type = parisc_acctyp(code,regs->iir);
2175
2176 - if ((vma->vm_flags & acc_type) != acc_type)
2177 + if ((vma->vm_flags & acc_type) != acc_type) {
2178 +
2179 +#ifdef CONFIG_PAX_PAGEEXEC
2180 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2181 + (address & ~3UL) == instruction_pointer(regs))
2182 + {
2183 + up_read(&mm->mmap_sem);
2184 + switch (pax_handle_fetch_fault(regs)) {
2185 +
2186 +#ifdef CONFIG_PAX_EMUPLT
2187 + case 3:
2188 + return;
2189 +#endif
2190 +
2191 +#ifdef CONFIG_PAX_EMUTRAMP
2192 + case 2:
2193 + return;
2194 +#endif
2195 +
2196 + }
2197 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2198 + do_group_exit(SIGKILL);
2199 + }
2200 +#endif
2201 +
2202 goto bad_area;
2203 + }
2204
2205 /*
2206 * If for any reason at all we couldn't handle the fault, make
2207 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
2208 index 02e41b5..4892f88 100644
2209 --- a/arch/powerpc/include/asm/atomic.h
2210 +++ b/arch/powerpc/include/asm/atomic.h
2211 @@ -469,6 +469,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2212
2213 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
2214
2215 +#define atomic64_read_unchecked(v) atomic64_read(v)
2216 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2217 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2218 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2219 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2220 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2221 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2222 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2223 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2224 +
2225 #endif /* __powerpc64__ */
2226
2227 #endif /* __KERNEL__ */
2228 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
2229 index 3bf9cca..e7457d0 100644
2230 --- a/arch/powerpc/include/asm/elf.h
2231 +++ b/arch/powerpc/include/asm/elf.h
2232 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
2233 the loader. We need to make sure that it is out of the way of the program
2234 that it will "exec", and that there is sufficient room for the brk. */
2235
2236 -extern unsigned long randomize_et_dyn(unsigned long base);
2237 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
2238 +#define ELF_ET_DYN_BASE (0x20000000)
2239 +
2240 +#ifdef CONFIG_PAX_ASLR
2241 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
2242 +
2243 +#ifdef __powerpc64__
2244 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
2245 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
2246 +#else
2247 +#define PAX_DELTA_MMAP_LEN 15
2248 +#define PAX_DELTA_STACK_LEN 15
2249 +#endif
2250 +#endif
2251
2252 /*
2253 * Our registers are always unsigned longs, whether we're a 32 bit
2254 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2255 (0x7ff >> (PAGE_SHIFT - 12)) : \
2256 (0x3ffff >> (PAGE_SHIFT - 12)))
2257
2258 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2259 -#define arch_randomize_brk arch_randomize_brk
2260 -
2261 #endif /* __KERNEL__ */
2262
2263 /*
2264 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
2265 index bca8fdc..61e9580 100644
2266 --- a/arch/powerpc/include/asm/kmap_types.h
2267 +++ b/arch/powerpc/include/asm/kmap_types.h
2268 @@ -27,6 +27,7 @@ enum km_type {
2269 KM_PPC_SYNC_PAGE,
2270 KM_PPC_SYNC_ICACHE,
2271 KM_KDB,
2272 + KM_CLEARPAGE,
2273 KM_TYPE_NR
2274 };
2275
2276 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
2277 index d4a7f64..451de1c 100644
2278 --- a/arch/powerpc/include/asm/mman.h
2279 +++ b/arch/powerpc/include/asm/mman.h
2280 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
2281 }
2282 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
2283
2284 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
2285 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
2286 {
2287 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
2288 }
2289 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
2290 index dd9c4fd..a2ced87 100644
2291 --- a/arch/powerpc/include/asm/page.h
2292 +++ b/arch/powerpc/include/asm/page.h
2293 @@ -141,8 +141,9 @@ extern phys_addr_t kernstart_addr;
2294 * and needs to be executable. This means the whole heap ends
2295 * up being executable.
2296 */
2297 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2298 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2299 +#define VM_DATA_DEFAULT_FLAGS32 \
2300 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2301 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2302
2303 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2304 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2305 @@ -170,6 +171,9 @@ extern phys_addr_t kernstart_addr;
2306 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
2307 #endif
2308
2309 +#define ktla_ktva(addr) (addr)
2310 +#define ktva_ktla(addr) (addr)
2311 +
2312 /*
2313 * Use the top bit of the higher-level page table entries to indicate whether
2314 * the entries we point to contain hugepages. This works because we know that
2315 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
2316 index fb40ede..d3ce956 100644
2317 --- a/arch/powerpc/include/asm/page_64.h
2318 +++ b/arch/powerpc/include/asm/page_64.h
2319 @@ -144,15 +144,18 @@ do { \
2320 * stack by default, so in the absence of a PT_GNU_STACK program header
2321 * we turn execute permission off.
2322 */
2323 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
2324 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2325 +#define VM_STACK_DEFAULT_FLAGS32 \
2326 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
2327 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2328
2329 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
2330 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
2331
2332 +#ifndef CONFIG_PAX_PAGEEXEC
2333 #define VM_STACK_DEFAULT_FLAGS \
2334 (is_32bit_task() ? \
2335 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
2336 +#endif
2337
2338 #include <asm-generic/getorder.h>
2339
2340 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
2341 index 88b0bd9..e32bc67 100644
2342 --- a/arch/powerpc/include/asm/pgtable.h
2343 +++ b/arch/powerpc/include/asm/pgtable.h
2344 @@ -2,6 +2,7 @@
2345 #define _ASM_POWERPC_PGTABLE_H
2346 #ifdef __KERNEL__
2347
2348 +#include <linux/const.h>
2349 #ifndef __ASSEMBLY__
2350 #include <asm/processor.h> /* For TASK_SIZE */
2351 #include <asm/mmu.h>
2352 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
2353 index 4aad413..85d86bf 100644
2354 --- a/arch/powerpc/include/asm/pte-hash32.h
2355 +++ b/arch/powerpc/include/asm/pte-hash32.h
2356 @@ -21,6 +21,7 @@
2357 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
2358 #define _PAGE_USER 0x004 /* usermode access allowed */
2359 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
2360 +#define _PAGE_EXEC _PAGE_GUARDED
2361 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
2362 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
2363 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
2364 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
2365 index 559da19..7e5835c 100644
2366 --- a/arch/powerpc/include/asm/reg.h
2367 +++ b/arch/powerpc/include/asm/reg.h
2368 @@ -212,6 +212,7 @@
2369 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
2370 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
2371 #define DSISR_NOHPTE 0x40000000 /* no translation found */
2372 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
2373 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
2374 #define DSISR_ISSTORE 0x02000000 /* access was a store */
2375 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
2376 diff --git a/arch/powerpc/include/asm/system.h b/arch/powerpc/include/asm/system.h
2377 index e30a13d..2b7d994 100644
2378 --- a/arch/powerpc/include/asm/system.h
2379 +++ b/arch/powerpc/include/asm/system.h
2380 @@ -530,7 +530,7 @@ __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
2381 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
2382 #endif
2383
2384 -extern unsigned long arch_align_stack(unsigned long sp);
2385 +#define arch_align_stack(x) ((x) & ~0xfUL)
2386
2387 /* Used in very early kernel initialization. */
2388 extern unsigned long reloc_offset(void);
2389 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
2390 index bd0fb84..a42a14b 100644
2391 --- a/arch/powerpc/include/asm/uaccess.h
2392 +++ b/arch/powerpc/include/asm/uaccess.h
2393 @@ -13,6 +13,8 @@
2394 #define VERIFY_READ 0
2395 #define VERIFY_WRITE 1
2396
2397 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
2398 +
2399 /*
2400 * The fs value determines whether argument validity checking should be
2401 * performed or not. If get_fs() == USER_DS, checking is performed, with
2402 @@ -327,52 +329,6 @@ do { \
2403 extern unsigned long __copy_tofrom_user(void __user *to,
2404 const void __user *from, unsigned long size);
2405
2406 -#ifndef __powerpc64__
2407 -
2408 -static inline unsigned long copy_from_user(void *to,
2409 - const void __user *from, unsigned long n)
2410 -{
2411 - unsigned long over;
2412 -
2413 - if (access_ok(VERIFY_READ, from, n))
2414 - return __copy_tofrom_user((__force void __user *)to, from, n);
2415 - if ((unsigned long)from < TASK_SIZE) {
2416 - over = (unsigned long)from + n - TASK_SIZE;
2417 - return __copy_tofrom_user((__force void __user *)to, from,
2418 - n - over) + over;
2419 - }
2420 - return n;
2421 -}
2422 -
2423 -static inline unsigned long copy_to_user(void __user *to,
2424 - const void *from, unsigned long n)
2425 -{
2426 - unsigned long over;
2427 -
2428 - if (access_ok(VERIFY_WRITE, to, n))
2429 - return __copy_tofrom_user(to, (__force void __user *)from, n);
2430 - if ((unsigned long)to < TASK_SIZE) {
2431 - over = (unsigned long)to + n - TASK_SIZE;
2432 - return __copy_tofrom_user(to, (__force void __user *)from,
2433 - n - over) + over;
2434 - }
2435 - return n;
2436 -}
2437 -
2438 -#else /* __powerpc64__ */
2439 -
2440 -#define __copy_in_user(to, from, size) \
2441 - __copy_tofrom_user((to), (from), (size))
2442 -
2443 -extern unsigned long copy_from_user(void *to, const void __user *from,
2444 - unsigned long n);
2445 -extern unsigned long copy_to_user(void __user *to, const void *from,
2446 - unsigned long n);
2447 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
2448 - unsigned long n);
2449 -
2450 -#endif /* __powerpc64__ */
2451 -
2452 static inline unsigned long __copy_from_user_inatomic(void *to,
2453 const void __user *from, unsigned long n)
2454 {
2455 @@ -396,6 +352,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
2456 if (ret == 0)
2457 return 0;
2458 }
2459 +
2460 + if (!__builtin_constant_p(n))
2461 + check_object_size(to, n, false);
2462 +
2463 return __copy_tofrom_user((__force void __user *)to, from, n);
2464 }
2465
2466 @@ -422,6 +382,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
2467 if (ret == 0)
2468 return 0;
2469 }
2470 +
2471 + if (!__builtin_constant_p(n))
2472 + check_object_size(from, n, true);
2473 +
2474 return __copy_tofrom_user(to, (__force const void __user *)from, n);
2475 }
2476
2477 @@ -439,6 +403,92 @@ static inline unsigned long __copy_to_user(void __user *to,
2478 return __copy_to_user_inatomic(to, from, size);
2479 }
2480
2481 +#ifndef __powerpc64__
2482 +
2483 +static inline unsigned long __must_check copy_from_user(void *to,
2484 + const void __user *from, unsigned long n)
2485 +{
2486 + unsigned long over;
2487 +
2488 + if ((long)n < 0)
2489 + return n;
2490 +
2491 + if (access_ok(VERIFY_READ, from, n)) {
2492 + if (!__builtin_constant_p(n))
2493 + check_object_size(to, n, false);
2494 + return __copy_tofrom_user((__force void __user *)to, from, n);
2495 + }
2496 + if ((unsigned long)from < TASK_SIZE) {
2497 + over = (unsigned long)from + n - TASK_SIZE;
2498 + if (!__builtin_constant_p(n - over))
2499 + check_object_size(to, n - over, false);
2500 + return __copy_tofrom_user((__force void __user *)to, from,
2501 + n - over) + over;
2502 + }
2503 + return n;
2504 +}
2505 +
2506 +static inline unsigned long __must_check copy_to_user(void __user *to,
2507 + const void *from, unsigned long n)
2508 +{
2509 + unsigned long over;
2510 +
2511 + if ((long)n < 0)
2512 + return n;
2513 +
2514 + if (access_ok(VERIFY_WRITE, to, n)) {
2515 + if (!__builtin_constant_p(n))
2516 + check_object_size(from, n, true);
2517 + return __copy_tofrom_user(to, (__force void __user *)from, n);
2518 + }
2519 + if ((unsigned long)to < TASK_SIZE) {
2520 + over = (unsigned long)to + n - TASK_SIZE;
2521 + if (!__builtin_constant_p(n))
2522 + check_object_size(from, n - over, true);
2523 + return __copy_tofrom_user(to, (__force void __user *)from,
2524 + n - over) + over;
2525 + }
2526 + return n;
2527 +}
2528 +
2529 +#else /* __powerpc64__ */
2530 +
2531 +#define __copy_in_user(to, from, size) \
2532 + __copy_tofrom_user((to), (from), (size))
2533 +
2534 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2535 +{
2536 + if ((long)n < 0 || n > INT_MAX)
2537 + return n;
2538 +
2539 + if (!__builtin_constant_p(n))
2540 + check_object_size(to, n, false);
2541 +
2542 + if (likely(access_ok(VERIFY_READ, from, n)))
2543 + n = __copy_from_user(to, from, n);
2544 + else
2545 + memset(to, 0, n);
2546 + return n;
2547 +}
2548 +
2549 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2550 +{
2551 + if ((long)n < 0 || n > INT_MAX)
2552 + return n;
2553 +
2554 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
2555 + if (!__builtin_constant_p(n))
2556 + check_object_size(from, n, true);
2557 + n = __copy_to_user(to, from, n);
2558 + }
2559 + return n;
2560 +}
2561 +
2562 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
2563 + unsigned long n);
2564 +
2565 +#endif /* __powerpc64__ */
2566 +
2567 extern unsigned long __clear_user(void __user *addr, unsigned long size);
2568
2569 static inline unsigned long clear_user(void __user *addr, unsigned long size)
2570 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
2571 index 429983c..7af363b 100644
2572 --- a/arch/powerpc/kernel/exceptions-64e.S
2573 +++ b/arch/powerpc/kernel/exceptions-64e.S
2574 @@ -587,6 +587,7 @@ storage_fault_common:
2575 std r14,_DAR(r1)
2576 std r15,_DSISR(r1)
2577 addi r3,r1,STACK_FRAME_OVERHEAD
2578 + bl .save_nvgprs
2579 mr r4,r14
2580 mr r5,r15
2581 ld r14,PACA_EXGEN+EX_R14(r13)
2582 @@ -596,8 +597,7 @@ storage_fault_common:
2583 cmpdi r3,0
2584 bne- 1f
2585 b .ret_from_except_lite
2586 -1: bl .save_nvgprs
2587 - mr r5,r3
2588 +1: mr r5,r3
2589 addi r3,r1,STACK_FRAME_OVERHEAD
2590 ld r4,_DAR(r1)
2591 bl .bad_page_fault
2592 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
2593 index cf9c69b..ebc9640 100644
2594 --- a/arch/powerpc/kernel/exceptions-64s.S
2595 +++ b/arch/powerpc/kernel/exceptions-64s.S
2596 @@ -1004,10 +1004,10 @@ handle_page_fault:
2597 11: ld r4,_DAR(r1)
2598 ld r5,_DSISR(r1)
2599 addi r3,r1,STACK_FRAME_OVERHEAD
2600 + bl .save_nvgprs
2601 bl .do_page_fault
2602 cmpdi r3,0
2603 beq+ 13f
2604 - bl .save_nvgprs
2605 mr r5,r3
2606 addi r3,r1,STACK_FRAME_OVERHEAD
2607 lwz r4,_DAR(r1)
2608 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
2609 index 0b6d796..d760ddb 100644
2610 --- a/arch/powerpc/kernel/module_32.c
2611 +++ b/arch/powerpc/kernel/module_32.c
2612 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
2613 me->arch.core_plt_section = i;
2614 }
2615 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
2616 - printk("Module doesn't contain .plt or .init.plt sections.\n");
2617 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
2618 return -ENOEXEC;
2619 }
2620
2621 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
2622
2623 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
2624 /* Init, or core PLT? */
2625 - if (location >= mod->module_core
2626 - && location < mod->module_core + mod->core_size)
2627 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
2628 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
2629 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
2630 - else
2631 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
2632 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
2633 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
2634 + else {
2635 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
2636 + return ~0UL;
2637 + }
2638
2639 /* Find this entry, or if that fails, the next avail. entry */
2640 while (entry->jump[0]) {
2641 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
2642 index 6457574..08b28d3 100644
2643 --- a/arch/powerpc/kernel/process.c
2644 +++ b/arch/powerpc/kernel/process.c
2645 @@ -660,8 +660,8 @@ void show_regs(struct pt_regs * regs)
2646 * Lookup NIP late so we have the best change of getting the
2647 * above info out without failing
2648 */
2649 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
2650 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
2651 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
2652 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
2653 #endif
2654 show_stack(current, (unsigned long *) regs->gpr[1]);
2655 if (!user_mode(regs))
2656 @@ -1165,10 +1165,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
2657 newsp = stack[0];
2658 ip = stack[STACK_FRAME_LR_SAVE];
2659 if (!firstframe || ip != lr) {
2660 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
2661 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
2662 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
2663 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
2664 - printk(" (%pS)",
2665 + printk(" (%pA)",
2666 (void *)current->ret_stack[curr_frame].ret);
2667 curr_frame--;
2668 }
2669 @@ -1188,7 +1188,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
2670 struct pt_regs *regs = (struct pt_regs *)
2671 (sp + STACK_FRAME_OVERHEAD);
2672 lr = regs->link;
2673 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
2674 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
2675 regs->trap, (void *)regs->nip, (void *)lr);
2676 firstframe = 1;
2677 }
2678 @@ -1263,58 +1263,3 @@ void thread_info_cache_init(void)
2679 }
2680
2681 #endif /* THREAD_SHIFT < PAGE_SHIFT */
2682 -
2683 -unsigned long arch_align_stack(unsigned long sp)
2684 -{
2685 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2686 - sp -= get_random_int() & ~PAGE_MASK;
2687 - return sp & ~0xf;
2688 -}
2689 -
2690 -static inline unsigned long brk_rnd(void)
2691 -{
2692 - unsigned long rnd = 0;
2693 -
2694 - /* 8MB for 32bit, 1GB for 64bit */
2695 - if (is_32bit_task())
2696 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
2697 - else
2698 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
2699 -
2700 - return rnd << PAGE_SHIFT;
2701 -}
2702 -
2703 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2704 -{
2705 - unsigned long base = mm->brk;
2706 - unsigned long ret;
2707 -
2708 -#ifdef CONFIG_PPC_STD_MMU_64
2709 - /*
2710 - * If we are using 1TB segments and we are allowed to randomise
2711 - * the heap, we can put it above 1TB so it is backed by a 1TB
2712 - * segment. Otherwise the heap will be in the bottom 1TB
2713 - * which always uses 256MB segments and this may result in a
2714 - * performance penalty.
2715 - */
2716 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
2717 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
2718 -#endif
2719 -
2720 - ret = PAGE_ALIGN(base + brk_rnd());
2721 -
2722 - if (ret < mm->brk)
2723 - return mm->brk;
2724 -
2725 - return ret;
2726 -}
2727 -
2728 -unsigned long randomize_et_dyn(unsigned long base)
2729 -{
2730 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
2731 -
2732 - if (ret < base)
2733 - return base;
2734 -
2735 - return ret;
2736 -}
2737 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
2738 index 836a5a1..27289a3 100644
2739 --- a/arch/powerpc/kernel/signal_32.c
2740 +++ b/arch/powerpc/kernel/signal_32.c
2741 @@ -859,7 +859,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
2742 /* Save user registers on the stack */
2743 frame = &rt_sf->uc.uc_mcontext;
2744 addr = frame;
2745 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
2746 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2747 if (save_user_regs(regs, frame, 0, 1))
2748 goto badframe;
2749 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
2750 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
2751 index a50b5ec..547078a 100644
2752 --- a/arch/powerpc/kernel/signal_64.c
2753 +++ b/arch/powerpc/kernel/signal_64.c
2754 @@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
2755 current->thread.fpscr.val = 0;
2756
2757 /* Set up to return from userspace. */
2758 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
2759 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
2760 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
2761 } else {
2762 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
2763 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
2764 index 5459d14..10f8070 100644
2765 --- a/arch/powerpc/kernel/traps.c
2766 +++ b/arch/powerpc/kernel/traps.c
2767 @@ -98,6 +98,8 @@ static void pmac_backlight_unblank(void)
2768 static inline void pmac_backlight_unblank(void) { }
2769 #endif
2770
2771 +extern void gr_handle_kernel_exploit(void);
2772 +
2773 int die(const char *str, struct pt_regs *regs, long err)
2774 {
2775 static struct {
2776 @@ -171,6 +173,8 @@ int die(const char *str, struct pt_regs *regs, long err)
2777 if (panic_on_oops)
2778 panic("Fatal exception");
2779
2780 + gr_handle_kernel_exploit();
2781 +
2782 oops_exit();
2783 do_exit(err);
2784
2785 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
2786 index 7d14bb6..1305601 100644
2787 --- a/arch/powerpc/kernel/vdso.c
2788 +++ b/arch/powerpc/kernel/vdso.c
2789 @@ -35,6 +35,7 @@
2790 #include <asm/firmware.h>
2791 #include <asm/vdso.h>
2792 #include <asm/vdso_datapage.h>
2793 +#include <asm/mman.h>
2794
2795 #include "setup.h"
2796
2797 @@ -219,7 +220,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2798 vdso_base = VDSO32_MBASE;
2799 #endif
2800
2801 - current->mm->context.vdso_base = 0;
2802 + current->mm->context.vdso_base = ~0UL;
2803
2804 /* vDSO has a problem and was disabled, just don't "enable" it for the
2805 * process
2806 @@ -239,7 +240,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2807 vdso_base = get_unmapped_area(NULL, vdso_base,
2808 (vdso_pages << PAGE_SHIFT) +
2809 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
2810 - 0, 0);
2811 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
2812 if (IS_ERR_VALUE(vdso_base)) {
2813 rc = vdso_base;
2814 goto fail_mmapsem;
2815 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
2816 index 5eea6f3..5d10396 100644
2817 --- a/arch/powerpc/lib/usercopy_64.c
2818 +++ b/arch/powerpc/lib/usercopy_64.c
2819 @@ -9,22 +9,6 @@
2820 #include <linux/module.h>
2821 #include <asm/uaccess.h>
2822
2823 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
2824 -{
2825 - if (likely(access_ok(VERIFY_READ, from, n)))
2826 - n = __copy_from_user(to, from, n);
2827 - else
2828 - memset(to, 0, n);
2829 - return n;
2830 -}
2831 -
2832 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
2833 -{
2834 - if (likely(access_ok(VERIFY_WRITE, to, n)))
2835 - n = __copy_to_user(to, from, n);
2836 - return n;
2837 -}
2838 -
2839 unsigned long copy_in_user(void __user *to, const void __user *from,
2840 unsigned long n)
2841 {
2842 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
2843 return n;
2844 }
2845
2846 -EXPORT_SYMBOL(copy_from_user);
2847 -EXPORT_SYMBOL(copy_to_user);
2848 EXPORT_SYMBOL(copy_in_user);
2849
2850 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
2851 index 5efe8c9..db9ceef 100644
2852 --- a/arch/powerpc/mm/fault.c
2853 +++ b/arch/powerpc/mm/fault.c
2854 @@ -32,6 +32,10 @@
2855 #include <linux/perf_event.h>
2856 #include <linux/magic.h>
2857 #include <linux/ratelimit.h>
2858 +#include <linux/slab.h>
2859 +#include <linux/pagemap.h>
2860 +#include <linux/compiler.h>
2861 +#include <linux/unistd.h>
2862
2863 #include <asm/firmware.h>
2864 #include <asm/page.h>
2865 @@ -43,6 +47,7 @@
2866 #include <asm/tlbflush.h>
2867 #include <asm/siginfo.h>
2868 #include <mm/mmu_decl.h>
2869 +#include <asm/ptrace.h>
2870
2871 #ifdef CONFIG_KPROBES
2872 static inline int notify_page_fault(struct pt_regs *regs)
2873 @@ -66,6 +71,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
2874 }
2875 #endif
2876
2877 +#ifdef CONFIG_PAX_PAGEEXEC
2878 +/*
2879 + * PaX: decide what to do with offenders (regs->nip = fault address)
2880 + *
2881 + * returns 1 when task should be killed
2882 + */
2883 +static int pax_handle_fetch_fault(struct pt_regs *regs)
2884 +{
2885 + return 1;
2886 +}
2887 +
2888 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2889 +{
2890 + unsigned long i;
2891 +
2892 + printk(KERN_ERR "PAX: bytes at PC: ");
2893 + for (i = 0; i < 5; i++) {
2894 + unsigned int c;
2895 + if (get_user(c, (unsigned int __user *)pc+i))
2896 + printk(KERN_CONT "???????? ");
2897 + else
2898 + printk(KERN_CONT "%08x ", c);
2899 + }
2900 + printk("\n");
2901 +}
2902 +#endif
2903 +
2904 /*
2905 * Check whether the instruction at regs->nip is a store using
2906 * an update addressing form which will update r1.
2907 @@ -136,7 +168,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
2908 * indicate errors in DSISR but can validly be set in SRR1.
2909 */
2910 if (trap == 0x400)
2911 - error_code &= 0x48200000;
2912 + error_code &= 0x58200000;
2913 else
2914 is_write = error_code & DSISR_ISSTORE;
2915 #else
2916 @@ -259,7 +291,7 @@ good_area:
2917 * "undefined". Of those that can be set, this is the only
2918 * one which seems bad.
2919 */
2920 - if (error_code & 0x10000000)
2921 + if (error_code & DSISR_GUARDED)
2922 /* Guarded storage error. */
2923 goto bad_area;
2924 #endif /* CONFIG_8xx */
2925 @@ -274,7 +306,7 @@ good_area:
2926 * processors use the same I/D cache coherency mechanism
2927 * as embedded.
2928 */
2929 - if (error_code & DSISR_PROTFAULT)
2930 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
2931 goto bad_area;
2932 #endif /* CONFIG_PPC_STD_MMU */
2933
2934 @@ -343,6 +375,23 @@ bad_area:
2935 bad_area_nosemaphore:
2936 /* User mode accesses cause a SIGSEGV */
2937 if (user_mode(regs)) {
2938 +
2939 +#ifdef CONFIG_PAX_PAGEEXEC
2940 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2941 +#ifdef CONFIG_PPC_STD_MMU
2942 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
2943 +#else
2944 + if (is_exec && regs->nip == address) {
2945 +#endif
2946 + switch (pax_handle_fetch_fault(regs)) {
2947 + }
2948 +
2949 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
2950 + do_group_exit(SIGKILL);
2951 + }
2952 + }
2953 +#endif
2954 +
2955 _exception(SIGSEGV, regs, code, address);
2956 return 0;
2957 }
2958 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
2959 index 5a783d8..c23e14b 100644
2960 --- a/arch/powerpc/mm/mmap_64.c
2961 +++ b/arch/powerpc/mm/mmap_64.c
2962 @@ -99,10 +99,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2963 */
2964 if (mmap_is_legacy()) {
2965 mm->mmap_base = TASK_UNMAPPED_BASE;
2966 +
2967 +#ifdef CONFIG_PAX_RANDMMAP
2968 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2969 + mm->mmap_base += mm->delta_mmap;
2970 +#endif
2971 +
2972 mm->get_unmapped_area = arch_get_unmapped_area;
2973 mm->unmap_area = arch_unmap_area;
2974 } else {
2975 mm->mmap_base = mmap_base();
2976 +
2977 +#ifdef CONFIG_PAX_RANDMMAP
2978 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2979 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2980 +#endif
2981 +
2982 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2983 mm->unmap_area = arch_unmap_area_topdown;
2984 }
2985 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
2986 index 73709f7..6b90313 100644
2987 --- a/arch/powerpc/mm/slice.c
2988 +++ b/arch/powerpc/mm/slice.c
2989 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
2990 if ((mm->task_size - len) < addr)
2991 return 0;
2992 vma = find_vma(mm, addr);
2993 - return (!vma || (addr + len) <= vma->vm_start);
2994 + return check_heap_stack_gap(vma, addr, len);
2995 }
2996
2997 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
2998 @@ -256,7 +256,7 @@ full_search:
2999 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
3000 continue;
3001 }
3002 - if (!vma || addr + len <= vma->vm_start) {
3003 + if (check_heap_stack_gap(vma, addr, len)) {
3004 /*
3005 * Remember the place where we stopped the search:
3006 */
3007 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3008 }
3009 }
3010
3011 - addr = mm->mmap_base;
3012 - while (addr > len) {
3013 + if (mm->mmap_base < len)
3014 + addr = -ENOMEM;
3015 + else
3016 + addr = mm->mmap_base - len;
3017 +
3018 + while (!IS_ERR_VALUE(addr)) {
3019 /* Go down by chunk size */
3020 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
3021 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
3022
3023 /* Check for hit with different page size */
3024 mask = slice_range_to_mask(addr, len);
3025 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3026 * return with success:
3027 */
3028 vma = find_vma(mm, addr);
3029 - if (!vma || (addr + len) <= vma->vm_start) {
3030 + if (check_heap_stack_gap(vma, addr, len)) {
3031 /* remember the address as a hint for next time */
3032 if (use_cache)
3033 mm->free_area_cache = addr;
3034 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
3035 mm->cached_hole_size = vma->vm_start - addr;
3036
3037 /* try just below the current vma->vm_start */
3038 - addr = vma->vm_start;
3039 + addr = skip_heap_stack_gap(vma, len);
3040 }
3041
3042 /*
3043 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
3044 if (fixed && addr > (mm->task_size - len))
3045 return -EINVAL;
3046
3047 +#ifdef CONFIG_PAX_RANDMMAP
3048 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
3049 + addr = 0;
3050 +#endif
3051 +
3052 /* If hint, make sure it matches our alignment restrictions */
3053 if (!fixed && addr) {
3054 addr = _ALIGN_UP(addr, 1ul << pshift);
3055 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
3056 index 8517d2a..8cdd01a 100644
3057 --- a/arch/s390/include/asm/atomic.h
3058 +++ b/arch/s390/include/asm/atomic.h
3059 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
3060 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
3061 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3062
3063 +#define atomic64_read_unchecked(v) atomic64_read(v)
3064 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3065 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3066 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3067 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3068 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3069 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3070 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3071 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3072 +
3073 #define smp_mb__before_atomic_dec() smp_mb()
3074 #define smp_mb__after_atomic_dec() smp_mb()
3075 #define smp_mb__before_atomic_inc() smp_mb()
3076 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
3077 index 547f1a6..0b22b53 100644
3078 --- a/arch/s390/include/asm/elf.h
3079 +++ b/arch/s390/include/asm/elf.h
3080 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
3081 the loader. We need to make sure that it is out of the way of the program
3082 that it will "exec", and that there is sufficient room for the brk. */
3083
3084 -extern unsigned long randomize_et_dyn(unsigned long base);
3085 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
3086 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
3087 +
3088 +#ifdef CONFIG_PAX_ASLR
3089 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
3090 +
3091 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
3092 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
3093 +#endif
3094
3095 /* This yields a mask that user programs can use to figure out what
3096 instruction set this CPU supports. */
3097 @@ -211,7 +217,4 @@ struct linux_binprm;
3098 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3099 int arch_setup_additional_pages(struct linux_binprm *, int);
3100
3101 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3102 -#define arch_randomize_brk arch_randomize_brk
3103 -
3104 #endif
3105 diff --git a/arch/s390/include/asm/system.h b/arch/s390/include/asm/system.h
3106 index ef573c1..75a1ce6 100644
3107 --- a/arch/s390/include/asm/system.h
3108 +++ b/arch/s390/include/asm/system.h
3109 @@ -262,7 +262,7 @@ extern void (*_machine_restart)(char *command);
3110 extern void (*_machine_halt)(void);
3111 extern void (*_machine_power_off)(void);
3112
3113 -extern unsigned long arch_align_stack(unsigned long sp);
3114 +#define arch_align_stack(x) ((x) & ~0xfUL)
3115
3116 static inline int tprot(unsigned long addr)
3117 {
3118 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
3119 index 2b23885..e136e31 100644
3120 --- a/arch/s390/include/asm/uaccess.h
3121 +++ b/arch/s390/include/asm/uaccess.h
3122 @@ -235,6 +235,10 @@ static inline unsigned long __must_check
3123 copy_to_user(void __user *to, const void *from, unsigned long n)
3124 {
3125 might_fault();
3126 +
3127 + if ((long)n < 0)
3128 + return n;
3129 +
3130 if (access_ok(VERIFY_WRITE, to, n))
3131 n = __copy_to_user(to, from, n);
3132 return n;
3133 @@ -260,6 +264,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
3134 static inline unsigned long __must_check
3135 __copy_from_user(void *to, const void __user *from, unsigned long n)
3136 {
3137 + if ((long)n < 0)
3138 + return n;
3139 +
3140 if (__builtin_constant_p(n) && (n <= 256))
3141 return uaccess.copy_from_user_small(n, from, to);
3142 else
3143 @@ -294,6 +301,10 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
3144 unsigned int sz = __compiletime_object_size(to);
3145
3146 might_fault();
3147 +
3148 + if ((long)n < 0)
3149 + return n;
3150 +
3151 if (unlikely(sz != -1 && sz < n)) {
3152 copy_from_user_overflow();
3153 return n;
3154 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
3155 index dfcb343..eda788a 100644
3156 --- a/arch/s390/kernel/module.c
3157 +++ b/arch/s390/kernel/module.c
3158 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
3159
3160 /* Increase core size by size of got & plt and set start
3161 offsets for got and plt. */
3162 - me->core_size = ALIGN(me->core_size, 4);
3163 - me->arch.got_offset = me->core_size;
3164 - me->core_size += me->arch.got_size;
3165 - me->arch.plt_offset = me->core_size;
3166 - me->core_size += me->arch.plt_size;
3167 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
3168 + me->arch.got_offset = me->core_size_rw;
3169 + me->core_size_rw += me->arch.got_size;
3170 + me->arch.plt_offset = me->core_size_rx;
3171 + me->core_size_rx += me->arch.plt_size;
3172 return 0;
3173 }
3174
3175 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3176 if (info->got_initialized == 0) {
3177 Elf_Addr *gotent;
3178
3179 - gotent = me->module_core + me->arch.got_offset +
3180 + gotent = me->module_core_rw + me->arch.got_offset +
3181 info->got_offset;
3182 *gotent = val;
3183 info->got_initialized = 1;
3184 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3185 else if (r_type == R_390_GOTENT ||
3186 r_type == R_390_GOTPLTENT)
3187 *(unsigned int *) loc =
3188 - (val + (Elf_Addr) me->module_core - loc) >> 1;
3189 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3190 else if (r_type == R_390_GOT64 ||
3191 r_type == R_390_GOTPLT64)
3192 *(unsigned long *) loc = val;
3193 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3194 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3195 if (info->plt_initialized == 0) {
3196 unsigned int *ip;
3197 - ip = me->module_core + me->arch.plt_offset +
3198 + ip = me->module_core_rx + me->arch.plt_offset +
3199 info->plt_offset;
3200 #ifndef CONFIG_64BIT
3201 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3202 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3203 val - loc + 0xffffUL < 0x1ffffeUL) ||
3204 (r_type == R_390_PLT32DBL &&
3205 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
3206 - val = (Elf_Addr) me->module_core +
3207 + val = (Elf_Addr) me->module_core_rx +
3208 me->arch.plt_offset +
3209 info->plt_offset;
3210 val += rela->r_addend - loc;
3211 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3212 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3213 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3214 val = val + rela->r_addend -
3215 - ((Elf_Addr) me->module_core + me->arch.got_offset);
3216 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3217 if (r_type == R_390_GOTOFF16)
3218 *(unsigned short *) loc = val;
3219 else if (r_type == R_390_GOTOFF32)
3220 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
3221 break;
3222 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3223 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3224 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
3225 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3226 rela->r_addend - loc;
3227 if (r_type == R_390_GOTPC)
3228 *(unsigned int *) loc = val;
3229 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
3230 index 9451b21..ed8956f 100644
3231 --- a/arch/s390/kernel/process.c
3232 +++ b/arch/s390/kernel/process.c
3233 @@ -321,39 +321,3 @@ unsigned long get_wchan(struct task_struct *p)
3234 }
3235 return 0;
3236 }
3237 -
3238 -unsigned long arch_align_stack(unsigned long sp)
3239 -{
3240 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3241 - sp -= get_random_int() & ~PAGE_MASK;
3242 - return sp & ~0xf;
3243 -}
3244 -
3245 -static inline unsigned long brk_rnd(void)
3246 -{
3247 - /* 8MB for 32bit, 1GB for 64bit */
3248 - if (is_32bit_task())
3249 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
3250 - else
3251 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
3252 -}
3253 -
3254 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3255 -{
3256 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
3257 -
3258 - if (ret < mm->brk)
3259 - return mm->brk;
3260 - return ret;
3261 -}
3262 -
3263 -unsigned long randomize_et_dyn(unsigned long base)
3264 -{
3265 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
3266 -
3267 - if (!(current->flags & PF_RANDOMIZE))
3268 - return base;
3269 - if (ret < base)
3270 - return base;
3271 - return ret;
3272 -}
3273 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
3274 index f09c748..cf9ec1d 100644
3275 --- a/arch/s390/mm/mmap.c
3276 +++ b/arch/s390/mm/mmap.c
3277 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3278 */
3279 if (mmap_is_legacy()) {
3280 mm->mmap_base = TASK_UNMAPPED_BASE;
3281 +
3282 +#ifdef CONFIG_PAX_RANDMMAP
3283 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3284 + mm->mmap_base += mm->delta_mmap;
3285 +#endif
3286 +
3287 mm->get_unmapped_area = arch_get_unmapped_area;
3288 mm->unmap_area = arch_unmap_area;
3289 } else {
3290 mm->mmap_base = mmap_base();
3291 +
3292 +#ifdef CONFIG_PAX_RANDMMAP
3293 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3294 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3295 +#endif
3296 +
3297 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3298 mm->unmap_area = arch_unmap_area_topdown;
3299 }
3300 @@ -167,10 +179,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3301 */
3302 if (mmap_is_legacy()) {
3303 mm->mmap_base = TASK_UNMAPPED_BASE;
3304 +
3305 +#ifdef CONFIG_PAX_RANDMMAP
3306 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3307 + mm->mmap_base += mm->delta_mmap;
3308 +#endif
3309 +
3310 mm->get_unmapped_area = s390_get_unmapped_area;
3311 mm->unmap_area = arch_unmap_area;
3312 } else {
3313 mm->mmap_base = mmap_base();
3314 +
3315 +#ifdef CONFIG_PAX_RANDMMAP
3316 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3317 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3318 +#endif
3319 +
3320 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
3321 mm->unmap_area = arch_unmap_area_topdown;
3322 }
3323 diff --git a/arch/score/include/asm/system.h b/arch/score/include/asm/system.h
3324 index 589d5c7..669e274 100644
3325 --- a/arch/score/include/asm/system.h
3326 +++ b/arch/score/include/asm/system.h
3327 @@ -17,7 +17,7 @@ do { \
3328 #define finish_arch_switch(prev) do {} while (0)
3329
3330 typedef void (*vi_handler_t)(void);
3331 -extern unsigned long arch_align_stack(unsigned long sp);
3332 +#define arch_align_stack(x) (x)
3333
3334 #define mb() barrier()
3335 #define rmb() barrier()
3336 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
3337 index 25d0803..d6c8e36 100644
3338 --- a/arch/score/kernel/process.c
3339 +++ b/arch/score/kernel/process.c
3340 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
3341
3342 return task_pt_regs(task)->cp0_epc;
3343 }
3344 -
3345 -unsigned long arch_align_stack(unsigned long sp)
3346 -{
3347 - return sp;
3348 -}
3349 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
3350 index afeb710..d1d1289 100644
3351 --- a/arch/sh/mm/mmap.c
3352 +++ b/arch/sh/mm/mmap.c
3353 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3354 addr = PAGE_ALIGN(addr);
3355
3356 vma = find_vma(mm, addr);
3357 - if (TASK_SIZE - len >= addr &&
3358 - (!vma || addr + len <= vma->vm_start))
3359 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3360 return addr;
3361 }
3362
3363 @@ -106,7 +105,7 @@ full_search:
3364 }
3365 return -ENOMEM;
3366 }
3367 - if (likely(!vma || addr + len <= vma->vm_start)) {
3368 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3369 /*
3370 * Remember the place where we stopped the search:
3371 */
3372 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3373 addr = PAGE_ALIGN(addr);
3374
3375 vma = find_vma(mm, addr);
3376 - if (TASK_SIZE - len >= addr &&
3377 - (!vma || addr + len <= vma->vm_start))
3378 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
3379 return addr;
3380 }
3381
3382 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3383 /* make sure it can fit in the remaining address space */
3384 if (likely(addr > len)) {
3385 vma = find_vma(mm, addr-len);
3386 - if (!vma || addr <= vma->vm_start) {
3387 + if (check_heap_stack_gap(vma, addr - len, len)) {
3388 /* remember the address as a hint for next time */
3389 return (mm->free_area_cache = addr-len);
3390 }
3391 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3392 if (unlikely(mm->mmap_base < len))
3393 goto bottomup;
3394
3395 - addr = mm->mmap_base-len;
3396 - if (do_colour_align)
3397 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3398 + addr = mm->mmap_base - len;
3399
3400 do {
3401 + if (do_colour_align)
3402 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3403 /*
3404 * Lookup failure means no vma is above this address,
3405 * else if new region fits below vma->vm_start,
3406 * return with success:
3407 */
3408 vma = find_vma(mm, addr);
3409 - if (likely(!vma || addr+len <= vma->vm_start)) {
3410 + if (likely(check_heap_stack_gap(vma, addr, len))) {
3411 /* remember the address as a hint for next time */
3412 return (mm->free_area_cache = addr);
3413 }
3414 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3415 mm->cached_hole_size = vma->vm_start - addr;
3416
3417 /* try just below the current vma->vm_start */
3418 - addr = vma->vm_start-len;
3419 - if (do_colour_align)
3420 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
3421 - } while (likely(len < vma->vm_start));
3422 + addr = skip_heap_stack_gap(vma, len);
3423 + } while (!IS_ERR_VALUE(addr));
3424
3425 bottomup:
3426 /*
3427 diff --git a/arch/sparc/Makefile b/arch/sparc/Makefile
3428 index ad1fb5d..fc5315b 100644
3429 --- a/arch/sparc/Makefile
3430 +++ b/arch/sparc/Makefile
3431 @@ -75,7 +75,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc/oprofile/
3432 # Export what is needed by arch/sparc/boot/Makefile
3433 export VMLINUX_INIT VMLINUX_MAIN
3434 VMLINUX_INIT := $(head-y) $(init-y)
3435 -VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/
3436 +VMLINUX_MAIN := $(core-y) kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
3437 VMLINUX_MAIN += $(patsubst %/, %/lib.a, $(libs-y)) $(libs-y)
3438 VMLINUX_MAIN += $(drivers-y) $(net-y)
3439
3440 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
3441 index 9f421df..b81fc12 100644
3442 --- a/arch/sparc/include/asm/atomic_64.h
3443 +++ b/arch/sparc/include/asm/atomic_64.h
3444 @@ -14,18 +14,40 @@
3445 #define ATOMIC64_INIT(i) { (i) }
3446
3447 #define atomic_read(v) (*(volatile int *)&(v)->counter)
3448 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
3449 +{
3450 + return v->counter;
3451 +}
3452 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
3453 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
3454 +{
3455 + return v->counter;
3456 +}
3457
3458 #define atomic_set(v, i) (((v)->counter) = i)
3459 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
3460 +{
3461 + v->counter = i;
3462 +}
3463 #define atomic64_set(v, i) (((v)->counter) = i)
3464 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
3465 +{
3466 + v->counter = i;
3467 +}
3468
3469 extern void atomic_add(int, atomic_t *);
3470 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
3471 extern void atomic64_add(long, atomic64_t *);
3472 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
3473 extern void atomic_sub(int, atomic_t *);
3474 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
3475 extern void atomic64_sub(long, atomic64_t *);
3476 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
3477
3478 extern int atomic_add_ret(int, atomic_t *);
3479 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
3480 extern long atomic64_add_ret(long, atomic64_t *);
3481 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
3482 extern int atomic_sub_ret(int, atomic_t *);
3483 extern long atomic64_sub_ret(long, atomic64_t *);
3484
3485 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3486 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
3487
3488 #define atomic_inc_return(v) atomic_add_ret(1, v)
3489 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
3490 +{
3491 + return atomic_add_ret_unchecked(1, v);
3492 +}
3493 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
3494 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
3495 +{
3496 + return atomic64_add_ret_unchecked(1, v);
3497 +}
3498
3499 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
3500 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
3501
3502 #define atomic_add_return(i, v) atomic_add_ret(i, v)
3503 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
3504 +{
3505 + return atomic_add_ret_unchecked(i, v);
3506 +}
3507 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
3508 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
3509 +{
3510 + return atomic64_add_ret_unchecked(i, v);
3511 +}
3512
3513 /*
3514 * atomic_inc_and_test - increment and test
3515 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3516 * other cases.
3517 */
3518 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
3519 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
3520 +{
3521 + return atomic_inc_return_unchecked(v) == 0;
3522 +}
3523 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
3524
3525 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
3526 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
3527 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
3528
3529 #define atomic_inc(v) atomic_add(1, v)
3530 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
3531 +{
3532 + atomic_add_unchecked(1, v);
3533 +}
3534 #define atomic64_inc(v) atomic64_add(1, v)
3535 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
3536 +{
3537 + atomic64_add_unchecked(1, v);
3538 +}
3539
3540 #define atomic_dec(v) atomic_sub(1, v)
3541 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
3542 +{
3543 + atomic_sub_unchecked(1, v);
3544 +}
3545 #define atomic64_dec(v) atomic64_sub(1, v)
3546 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
3547 +{
3548 + atomic64_sub_unchecked(1, v);
3549 +}
3550
3551 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
3552 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
3553
3554 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
3555 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
3556 +{
3557 + return cmpxchg(&v->counter, old, new);
3558 +}
3559 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
3560 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
3561 +{
3562 + return xchg(&v->counter, new);
3563 +}
3564
3565 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
3566 {
3567 - int c, old;
3568 + int c, old, new;
3569 c = atomic_read(v);
3570 for (;;) {
3571 - if (unlikely(c == (u)))
3572 + if (unlikely(c == u))
3573 break;
3574 - old = atomic_cmpxchg((v), c, c + (a));
3575 +
3576 + asm volatile("addcc %2, %0, %0\n"
3577 +
3578 +#ifdef CONFIG_PAX_REFCOUNT
3579 + "tvs %%icc, 6\n"
3580 +#endif
3581 +
3582 + : "=r" (new)
3583 + : "0" (c), "ir" (a)
3584 + : "cc");
3585 +
3586 + old = atomic_cmpxchg(v, c, new);
3587 if (likely(old == c))
3588 break;
3589 c = old;
3590 @@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
3591 #define atomic64_cmpxchg(v, o, n) \
3592 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
3593 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
3594 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
3595 +{
3596 + return xchg(&v->counter, new);
3597 +}
3598
3599 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
3600 {
3601 - long c, old;
3602 + long c, old, new;
3603 c = atomic64_read(v);
3604 for (;;) {
3605 - if (unlikely(c == (u)))
3606 + if (unlikely(c == u))
3607 break;
3608 - old = atomic64_cmpxchg((v), c, c + (a));
3609 +
3610 + asm volatile("addcc %2, %0, %0\n"
3611 +
3612 +#ifdef CONFIG_PAX_REFCOUNT
3613 + "tvs %%xcc, 6\n"
3614 +#endif
3615 +
3616 + : "=r" (new)
3617 + : "0" (c), "ir" (a)
3618 + : "cc");
3619 +
3620 + old = atomic64_cmpxchg(v, c, new);
3621 if (likely(old == c))
3622 break;
3623 c = old;
3624 }
3625 - return c != (u);
3626 + return c != u;
3627 }
3628
3629 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3630 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
3631 index 69358b5..17b4745 100644
3632 --- a/arch/sparc/include/asm/cache.h
3633 +++ b/arch/sparc/include/asm/cache.h
3634 @@ -10,7 +10,7 @@
3635 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
3636
3637 #define L1_CACHE_SHIFT 5
3638 -#define L1_CACHE_BYTES 32
3639 +#define L1_CACHE_BYTES 32UL
3640
3641 #ifdef CONFIG_SPARC32
3642 #define SMP_CACHE_BYTES_SHIFT 5
3643 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
3644 index 4269ca6..e3da77f 100644
3645 --- a/arch/sparc/include/asm/elf_32.h
3646 +++ b/arch/sparc/include/asm/elf_32.h
3647 @@ -114,6 +114,13 @@ typedef struct {
3648
3649 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3650
3651 +#ifdef CONFIG_PAX_ASLR
3652 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3653 +
3654 +#define PAX_DELTA_MMAP_LEN 16
3655 +#define PAX_DELTA_STACK_LEN 16
3656 +#endif
3657 +
3658 /* This yields a mask that user programs can use to figure out what
3659 instruction set this cpu supports. This can NOT be done in userspace
3660 on Sparc. */
3661 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
3662 index 7df8b7f..4946269 100644
3663 --- a/arch/sparc/include/asm/elf_64.h
3664 +++ b/arch/sparc/include/asm/elf_64.h
3665 @@ -180,6 +180,13 @@ typedef struct {
3666 #define ELF_ET_DYN_BASE 0x0000010000000000UL
3667 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3668
3669 +#ifdef CONFIG_PAX_ASLR
3670 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3671 +
3672 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
3673 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
3674 +#endif
3675 +
3676 extern unsigned long sparc64_elf_hwcap;
3677 #define ELF_HWCAP sparc64_elf_hwcap
3678
3679 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
3680 index a790cc6..091ed94 100644
3681 --- a/arch/sparc/include/asm/pgtable_32.h
3682 +++ b/arch/sparc/include/asm/pgtable_32.h
3683 @@ -45,6 +45,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3684 BTFIXUPDEF_INT(page_none)
3685 BTFIXUPDEF_INT(page_copy)
3686 BTFIXUPDEF_INT(page_readonly)
3687 +
3688 +#ifdef CONFIG_PAX_PAGEEXEC
3689 +BTFIXUPDEF_INT(page_shared_noexec)
3690 +BTFIXUPDEF_INT(page_copy_noexec)
3691 +BTFIXUPDEF_INT(page_readonly_noexec)
3692 +#endif
3693 +
3694 BTFIXUPDEF_INT(page_kernel)
3695
3696 #define PMD_SHIFT SUN4C_PMD_SHIFT
3697 @@ -66,6 +73,16 @@ extern pgprot_t PAGE_SHARED;
3698 #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3699 #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3700
3701 +#ifdef CONFIG_PAX_PAGEEXEC
3702 +extern pgprot_t PAGE_SHARED_NOEXEC;
3703 +# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3704 +# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3705 +#else
3706 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3707 +# define PAGE_COPY_NOEXEC PAGE_COPY
3708 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3709 +#endif
3710 +
3711 extern unsigned long page_kernel;
3712
3713 #ifdef MODULE
3714 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
3715 index f6ae2b2..b03ffc7 100644
3716 --- a/arch/sparc/include/asm/pgtsrmmu.h
3717 +++ b/arch/sparc/include/asm/pgtsrmmu.h
3718 @@ -115,6 +115,13 @@
3719 SRMMU_EXEC | SRMMU_REF)
3720 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3721 SRMMU_EXEC | SRMMU_REF)
3722 +
3723 +#ifdef CONFIG_PAX_PAGEEXEC
3724 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3725 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3726 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3727 +#endif
3728 +
3729 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3730 SRMMU_DIRTY | SRMMU_REF)
3731
3732 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
3733 index 9689176..63c18ea 100644
3734 --- a/arch/sparc/include/asm/spinlock_64.h
3735 +++ b/arch/sparc/include/asm/spinlock_64.h
3736 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
3737
3738 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
3739
3740 -static void inline arch_read_lock(arch_rwlock_t *lock)
3741 +static inline void arch_read_lock(arch_rwlock_t *lock)
3742 {
3743 unsigned long tmp1, tmp2;
3744
3745 __asm__ __volatile__ (
3746 "1: ldsw [%2], %0\n"
3747 " brlz,pn %0, 2f\n"
3748 -"4: add %0, 1, %1\n"
3749 +"4: addcc %0, 1, %1\n"
3750 +
3751 +#ifdef CONFIG_PAX_REFCOUNT
3752 +" tvs %%icc, 6\n"
3753 +#endif
3754 +
3755 " cas [%2], %0, %1\n"
3756 " cmp %0, %1\n"
3757 " bne,pn %%icc, 1b\n"
3758 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
3759 " .previous"
3760 : "=&r" (tmp1), "=&r" (tmp2)
3761 : "r" (lock)
3762 - : "memory");
3763 + : "memory", "cc");
3764 }
3765
3766 -static int inline arch_read_trylock(arch_rwlock_t *lock)
3767 +static inline int arch_read_trylock(arch_rwlock_t *lock)
3768 {
3769 int tmp1, tmp2;
3770
3771 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
3772 "1: ldsw [%2], %0\n"
3773 " brlz,a,pn %0, 2f\n"
3774 " mov 0, %0\n"
3775 -" add %0, 1, %1\n"
3776 +" addcc %0, 1, %1\n"
3777 +
3778 +#ifdef CONFIG_PAX_REFCOUNT
3779 +" tvs %%icc, 6\n"
3780 +#endif
3781 +
3782 " cas [%2], %0, %1\n"
3783 " cmp %0, %1\n"
3784 " bne,pn %%icc, 1b\n"
3785 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
3786 return tmp1;
3787 }
3788
3789 -static void inline arch_read_unlock(arch_rwlock_t *lock)
3790 +static inline void arch_read_unlock(arch_rwlock_t *lock)
3791 {
3792 unsigned long tmp1, tmp2;
3793
3794 __asm__ __volatile__(
3795 "1: lduw [%2], %0\n"
3796 -" sub %0, 1, %1\n"
3797 +" subcc %0, 1, %1\n"
3798 +
3799 +#ifdef CONFIG_PAX_REFCOUNT
3800 +" tvs %%icc, 6\n"
3801 +#endif
3802 +
3803 " cas [%2], %0, %1\n"
3804 " cmp %0, %1\n"
3805 " bne,pn %%xcc, 1b\n"
3806 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
3807 : "memory");
3808 }
3809
3810 -static void inline arch_write_lock(arch_rwlock_t *lock)
3811 +static inline void arch_write_lock(arch_rwlock_t *lock)
3812 {
3813 unsigned long mask, tmp1, tmp2;
3814
3815 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
3816 : "memory");
3817 }
3818
3819 -static void inline arch_write_unlock(arch_rwlock_t *lock)
3820 +static inline void arch_write_unlock(arch_rwlock_t *lock)
3821 {
3822 __asm__ __volatile__(
3823 " stw %%g0, [%0]"
3824 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
3825 : "memory");
3826 }
3827
3828 -static int inline arch_write_trylock(arch_rwlock_t *lock)
3829 +static inline int arch_write_trylock(arch_rwlock_t *lock)
3830 {
3831 unsigned long mask, tmp1, tmp2, result;
3832
3833 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
3834 index fa57532..e1a4c53 100644
3835 --- a/arch/sparc/include/asm/thread_info_32.h
3836 +++ b/arch/sparc/include/asm/thread_info_32.h
3837 @@ -50,6 +50,8 @@ struct thread_info {
3838 unsigned long w_saved;
3839
3840 struct restart_block restart_block;
3841 +
3842 + unsigned long lowest_stack;
3843 };
3844
3845 /*
3846 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
3847 index 60d86be..952dea1 100644
3848 --- a/arch/sparc/include/asm/thread_info_64.h
3849 +++ b/arch/sparc/include/asm/thread_info_64.h
3850 @@ -63,6 +63,8 @@ struct thread_info {
3851 struct pt_regs *kern_una_regs;
3852 unsigned int kern_una_insn;
3853
3854 + unsigned long lowest_stack;
3855 +
3856 unsigned long fpregs[0] __attribute__ ((aligned(64)));
3857 };
3858
3859 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
3860 index e88fbe5..96b0ce5 100644
3861 --- a/arch/sparc/include/asm/uaccess.h
3862 +++ b/arch/sparc/include/asm/uaccess.h
3863 @@ -1,5 +1,13 @@
3864 #ifndef ___ASM_SPARC_UACCESS_H
3865 #define ___ASM_SPARC_UACCESS_H
3866 +
3867 +#ifdef __KERNEL__
3868 +#ifndef __ASSEMBLY__
3869 +#include <linux/types.h>
3870 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3871 +#endif
3872 +#endif
3873 +
3874 #if defined(__sparc__) && defined(__arch64__)
3875 #include <asm/uaccess_64.h>
3876 #else
3877 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
3878 index 8303ac4..07f333d 100644
3879 --- a/arch/sparc/include/asm/uaccess_32.h
3880 +++ b/arch/sparc/include/asm/uaccess_32.h
3881 @@ -249,27 +249,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
3882
3883 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
3884 {
3885 - if (n && __access_ok((unsigned long) to, n))
3886 + if ((long)n < 0)
3887 + return n;
3888 +
3889 + if (n && __access_ok((unsigned long) to, n)) {
3890 + if (!__builtin_constant_p(n))
3891 + check_object_size(from, n, true);
3892 return __copy_user(to, (__force void __user *) from, n);
3893 - else
3894 + } else
3895 return n;
3896 }
3897
3898 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
3899 {
3900 + if ((long)n < 0)
3901 + return n;
3902 +
3903 + if (!__builtin_constant_p(n))
3904 + check_object_size(from, n, true);
3905 +
3906 return __copy_user(to, (__force void __user *) from, n);
3907 }
3908
3909 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
3910 {
3911 - if (n && __access_ok((unsigned long) from, n))
3912 + if ((long)n < 0)
3913 + return n;
3914 +
3915 + if (n && __access_ok((unsigned long) from, n)) {
3916 + if (!__builtin_constant_p(n))
3917 + check_object_size(to, n, false);
3918 return __copy_user((__force void __user *) to, from, n);
3919 - else
3920 + } else
3921 return n;
3922 }
3923
3924 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
3925 {
3926 + if ((long)n < 0)
3927 + return n;
3928 +
3929 return __copy_user((__force void __user *) to, from, n);
3930 }
3931
3932 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
3933 index 3e1449f..5293a0e 100644
3934 --- a/arch/sparc/include/asm/uaccess_64.h
3935 +++ b/arch/sparc/include/asm/uaccess_64.h
3936 @@ -10,6 +10,7 @@
3937 #include <linux/compiler.h>
3938 #include <linux/string.h>
3939 #include <linux/thread_info.h>
3940 +#include <linux/kernel.h>
3941 #include <asm/asi.h>
3942 #include <asm/system.h>
3943 #include <asm/spitfire.h>
3944 @@ -213,8 +214,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
3945 static inline unsigned long __must_check
3946 copy_from_user(void *to, const void __user *from, unsigned long size)
3947 {
3948 - unsigned long ret = ___copy_from_user(to, from, size);
3949 + unsigned long ret;
3950
3951 + if ((long)size < 0 || size > INT_MAX)
3952 + return size;
3953 +
3954 + if (!__builtin_constant_p(size))
3955 + check_object_size(to, size, false);
3956 +
3957 + ret = ___copy_from_user(to, from, size);
3958 if (unlikely(ret))
3959 ret = copy_from_user_fixup(to, from, size);
3960
3961 @@ -230,8 +238,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
3962 static inline unsigned long __must_check
3963 copy_to_user(void __user *to, const void *from, unsigned long size)
3964 {
3965 - unsigned long ret = ___copy_to_user(to, from, size);
3966 + unsigned long ret;
3967
3968 + if ((long)size < 0 || size > INT_MAX)
3969 + return size;
3970 +
3971 + if (!__builtin_constant_p(size))
3972 + check_object_size(from, size, true);
3973 +
3974 + ret = ___copy_to_user(to, from, size);
3975 if (unlikely(ret))
3976 ret = copy_to_user_fixup(to, from, size);
3977 return ret;
3978 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
3979 index cb85458..e063f17 100644
3980 --- a/arch/sparc/kernel/Makefile
3981 +++ b/arch/sparc/kernel/Makefile
3982 @@ -3,7 +3,7 @@
3983 #
3984
3985 asflags-y := -ansi
3986 -ccflags-y := -Werror
3987 +#ccflags-y := -Werror
3988
3989 extra-y := head_$(BITS).o
3990 extra-y += init_task.o
3991 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
3992 index f793742..4d880af 100644
3993 --- a/arch/sparc/kernel/process_32.c
3994 +++ b/arch/sparc/kernel/process_32.c
3995 @@ -204,7 +204,7 @@ void __show_backtrace(unsigned long fp)
3996 rw->ins[4], rw->ins[5],
3997 rw->ins[6],
3998 rw->ins[7]);
3999 - printk("%pS\n", (void *) rw->ins[7]);
4000 + printk("%pA\n", (void *) rw->ins[7]);
4001 rw = (struct reg_window32 *) rw->ins[6];
4002 }
4003 spin_unlock_irqrestore(&sparc_backtrace_lock, flags);
4004 @@ -271,14 +271,14 @@ void show_regs(struct pt_regs *r)
4005
4006 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
4007 r->psr, r->pc, r->npc, r->y, print_tainted());
4008 - printk("PC: <%pS>\n", (void *) r->pc);
4009 + printk("PC: <%pA>\n", (void *) r->pc);
4010 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4011 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
4012 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
4013 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4014 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
4015 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
4016 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
4017 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
4018
4019 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
4020 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
4021 @@ -313,7 +313,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
4022 rw = (struct reg_window32 *) fp;
4023 pc = rw->ins[7];
4024 printk("[%08lx : ", pc);
4025 - printk("%pS ] ", (void *) pc);
4026 + printk("%pA ] ", (void *) pc);
4027 fp = rw->ins[6];
4028 } while (++count < 16);
4029 printk("\n");
4030 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
4031 index 3739a06..48b2ff0 100644
4032 --- a/arch/sparc/kernel/process_64.c
4033 +++ b/arch/sparc/kernel/process_64.c
4034 @@ -180,14 +180,14 @@ static void show_regwindow(struct pt_regs *regs)
4035 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
4036 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
4037 if (regs->tstate & TSTATE_PRIV)
4038 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
4039 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
4040 }
4041
4042 void show_regs(struct pt_regs *regs)
4043 {
4044 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
4045 regs->tpc, regs->tnpc, regs->y, print_tainted());
4046 - printk("TPC: <%pS>\n", (void *) regs->tpc);
4047 + printk("TPC: <%pA>\n", (void *) regs->tpc);
4048 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
4049 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
4050 regs->u_regs[3]);
4051 @@ -200,7 +200,7 @@ void show_regs(struct pt_regs *regs)
4052 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
4053 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
4054 regs->u_regs[15]);
4055 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
4056 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
4057 show_regwindow(regs);
4058 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
4059 }
4060 @@ -285,7 +285,7 @@ void arch_trigger_all_cpu_backtrace(void)
4061 ((tp && tp->task) ? tp->task->pid : -1));
4062
4063 if (gp->tstate & TSTATE_PRIV) {
4064 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
4065 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
4066 (void *) gp->tpc,
4067 (void *) gp->o7,
4068 (void *) gp->i7,
4069 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
4070 index 42b282f..28ce9f2 100644
4071 --- a/arch/sparc/kernel/sys_sparc_32.c
4072 +++ b/arch/sparc/kernel/sys_sparc_32.c
4073 @@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4074 if (ARCH_SUN4C && len > 0x20000000)
4075 return -ENOMEM;
4076 if (!addr)
4077 - addr = TASK_UNMAPPED_BASE;
4078 + addr = current->mm->mmap_base;
4079
4080 if (flags & MAP_SHARED)
4081 addr = COLOUR_ALIGN(addr);
4082 @@ -71,7 +71,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4083 }
4084 if (TASK_SIZE - PAGE_SIZE - len < addr)
4085 return -ENOMEM;
4086 - if (!vmm || addr + len <= vmm->vm_start)
4087 + if (check_heap_stack_gap(vmm, addr, len))
4088 return addr;
4089 addr = vmm->vm_end;
4090 if (flags & MAP_SHARED)
4091 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
4092 index 441521a..b767073 100644
4093 --- a/arch/sparc/kernel/sys_sparc_64.c
4094 +++ b/arch/sparc/kernel/sys_sparc_64.c
4095 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4096 /* We do not accept a shared mapping if it would violate
4097 * cache aliasing constraints.
4098 */
4099 - if ((flags & MAP_SHARED) &&
4100 + if ((filp || (flags & MAP_SHARED)) &&
4101 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4102 return -EINVAL;
4103 return addr;
4104 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4105 if (filp || (flags & MAP_SHARED))
4106 do_color_align = 1;
4107
4108 +#ifdef CONFIG_PAX_RANDMMAP
4109 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4110 +#endif
4111 +
4112 if (addr) {
4113 if (do_color_align)
4114 addr = COLOUR_ALIGN(addr, pgoff);
4115 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4116 addr = PAGE_ALIGN(addr);
4117
4118 vma = find_vma(mm, addr);
4119 - if (task_size - len >= addr &&
4120 - (!vma || addr + len <= vma->vm_start))
4121 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4122 return addr;
4123 }
4124
4125 if (len > mm->cached_hole_size) {
4126 - start_addr = addr = mm->free_area_cache;
4127 + start_addr = addr = mm->free_area_cache;
4128 } else {
4129 - start_addr = addr = TASK_UNMAPPED_BASE;
4130 + start_addr = addr = mm->mmap_base;
4131 mm->cached_hole_size = 0;
4132 }
4133
4134 @@ -174,14 +177,14 @@ full_search:
4135 vma = find_vma(mm, VA_EXCLUDE_END);
4136 }
4137 if (unlikely(task_size < addr)) {
4138 - if (start_addr != TASK_UNMAPPED_BASE) {
4139 - start_addr = addr = TASK_UNMAPPED_BASE;
4140 + if (start_addr != mm->mmap_base) {
4141 + start_addr = addr = mm->mmap_base;
4142 mm->cached_hole_size = 0;
4143 goto full_search;
4144 }
4145 return -ENOMEM;
4146 }
4147 - if (likely(!vma || addr + len <= vma->vm_start)) {
4148 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4149 /*
4150 * Remember the place where we stopped the search:
4151 */
4152 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4153 /* We do not accept a shared mapping if it would violate
4154 * cache aliasing constraints.
4155 */
4156 - if ((flags & MAP_SHARED) &&
4157 + if ((filp || (flags & MAP_SHARED)) &&
4158 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4159 return -EINVAL;
4160 return addr;
4161 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4162 addr = PAGE_ALIGN(addr);
4163
4164 vma = find_vma(mm, addr);
4165 - if (task_size - len >= addr &&
4166 - (!vma || addr + len <= vma->vm_start))
4167 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
4168 return addr;
4169 }
4170
4171 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4172 /* make sure it can fit in the remaining address space */
4173 if (likely(addr > len)) {
4174 vma = find_vma(mm, addr-len);
4175 - if (!vma || addr <= vma->vm_start) {
4176 + if (check_heap_stack_gap(vma, addr - len, len)) {
4177 /* remember the address as a hint for next time */
4178 return (mm->free_area_cache = addr-len);
4179 }
4180 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4181 if (unlikely(mm->mmap_base < len))
4182 goto bottomup;
4183
4184 - addr = mm->mmap_base-len;
4185 - if (do_color_align)
4186 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4187 + addr = mm->mmap_base - len;
4188
4189 do {
4190 + if (do_color_align)
4191 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4192 /*
4193 * Lookup failure means no vma is above this address,
4194 * else if new region fits below vma->vm_start,
4195 * return with success:
4196 */
4197 vma = find_vma(mm, addr);
4198 - if (likely(!vma || addr+len <= vma->vm_start)) {
4199 + if (likely(check_heap_stack_gap(vma, addr, len))) {
4200 /* remember the address as a hint for next time */
4201 return (mm->free_area_cache = addr);
4202 }
4203 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4204 mm->cached_hole_size = vma->vm_start - addr;
4205
4206 /* try just below the current vma->vm_start */
4207 - addr = vma->vm_start-len;
4208 - if (do_color_align)
4209 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4210 - } while (likely(len < vma->vm_start));
4211 + addr = skip_heap_stack_gap(vma, len);
4212 + } while (!IS_ERR_VALUE(addr));
4213
4214 bottomup:
4215 /*
4216 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4217 gap == RLIM_INFINITY ||
4218 sysctl_legacy_va_layout) {
4219 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4220 +
4221 +#ifdef CONFIG_PAX_RANDMMAP
4222 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4223 + mm->mmap_base += mm->delta_mmap;
4224 +#endif
4225 +
4226 mm->get_unmapped_area = arch_get_unmapped_area;
4227 mm->unmap_area = arch_unmap_area;
4228 } else {
4229 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4230 gap = (task_size / 6 * 5);
4231
4232 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4233 +
4234 +#ifdef CONFIG_PAX_RANDMMAP
4235 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4236 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4237 +#endif
4238 +
4239 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4240 mm->unmap_area = arch_unmap_area_topdown;
4241 }
4242 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
4243 index 591f20c..0f1b925 100644
4244 --- a/arch/sparc/kernel/traps_32.c
4245 +++ b/arch/sparc/kernel/traps_32.c
4246 @@ -45,6 +45,8 @@ static void instruction_dump(unsigned long *pc)
4247 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
4248 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
4249
4250 +extern void gr_handle_kernel_exploit(void);
4251 +
4252 void die_if_kernel(char *str, struct pt_regs *regs)
4253 {
4254 static int die_counter;
4255 @@ -77,15 +79,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4256 count++ < 30 &&
4257 (((unsigned long) rw) >= PAGE_OFFSET) &&
4258 !(((unsigned long) rw) & 0x7)) {
4259 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
4260 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
4261 (void *) rw->ins[7]);
4262 rw = (struct reg_window32 *)rw->ins[6];
4263 }
4264 }
4265 printk("Instruction DUMP:");
4266 instruction_dump ((unsigned long *) regs->pc);
4267 - if(regs->psr & PSR_PS)
4268 + if(regs->psr & PSR_PS) {
4269 + gr_handle_kernel_exploit();
4270 do_exit(SIGKILL);
4271 + }
4272 do_exit(SIGSEGV);
4273 }
4274
4275 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
4276 index 0cbdaa4..438e4c9 100644
4277 --- a/arch/sparc/kernel/traps_64.c
4278 +++ b/arch/sparc/kernel/traps_64.c
4279 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
4280 i + 1,
4281 p->trapstack[i].tstate, p->trapstack[i].tpc,
4282 p->trapstack[i].tnpc, p->trapstack[i].tt);
4283 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
4284 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
4285 }
4286 }
4287
4288 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
4289
4290 lvl -= 0x100;
4291 if (regs->tstate & TSTATE_PRIV) {
4292 +
4293 +#ifdef CONFIG_PAX_REFCOUNT
4294 + if (lvl == 6)
4295 + pax_report_refcount_overflow(regs);
4296 +#endif
4297 +
4298 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
4299 die_if_kernel(buffer, regs);
4300 }
4301 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
4302 void bad_trap_tl1(struct pt_regs *regs, long lvl)
4303 {
4304 char buffer[32];
4305 -
4306 +
4307 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
4308 0, lvl, SIGTRAP) == NOTIFY_STOP)
4309 return;
4310
4311 +#ifdef CONFIG_PAX_REFCOUNT
4312 + if (lvl == 6)
4313 + pax_report_refcount_overflow(regs);
4314 +#endif
4315 +
4316 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
4317
4318 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
4319 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
4320 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
4321 printk("%s" "ERROR(%d): ",
4322 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
4323 - printk("TPC<%pS>\n", (void *) regs->tpc);
4324 + printk("TPC<%pA>\n", (void *) regs->tpc);
4325 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
4326 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
4327 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
4328 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
4329 smp_processor_id(),
4330 (type & 0x1) ? 'I' : 'D',
4331 regs->tpc);
4332 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
4333 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
4334 panic("Irrecoverable Cheetah+ parity error.");
4335 }
4336
4337 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
4338 smp_processor_id(),
4339 (type & 0x1) ? 'I' : 'D',
4340 regs->tpc);
4341 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
4342 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
4343 }
4344
4345 struct sun4v_error_entry {
4346 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
4347
4348 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
4349 regs->tpc, tl);
4350 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
4351 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
4352 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4353 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
4354 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
4355 (void *) regs->u_regs[UREG_I7]);
4356 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
4357 "pte[%lx] error[%lx]\n",
4358 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
4359
4360 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
4361 regs->tpc, tl);
4362 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
4363 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
4364 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
4365 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
4366 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
4367 (void *) regs->u_regs[UREG_I7]);
4368 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
4369 "pte[%lx] error[%lx]\n",
4370 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
4371 fp = (unsigned long)sf->fp + STACK_BIAS;
4372 }
4373
4374 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4375 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4376 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4377 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
4378 int index = tsk->curr_ret_stack;
4379 if (tsk->ret_stack && index >= graph) {
4380 pc = tsk->ret_stack[index - graph].ret;
4381 - printk(" [%016lx] %pS\n", pc, (void *) pc);
4382 + printk(" [%016lx] %pA\n", pc, (void *) pc);
4383 graph++;
4384 }
4385 }
4386 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
4387 return (struct reg_window *) (fp + STACK_BIAS);
4388 }
4389
4390 +extern void gr_handle_kernel_exploit(void);
4391 +
4392 void die_if_kernel(char *str, struct pt_regs *regs)
4393 {
4394 static int die_counter;
4395 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4396 while (rw &&
4397 count++ < 30 &&
4398 kstack_valid(tp, (unsigned long) rw)) {
4399 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
4400 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
4401 (void *) rw->ins[7]);
4402
4403 rw = kernel_stack_up(rw);
4404 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
4405 }
4406 user_instruction_dump ((unsigned int __user *) regs->tpc);
4407 }
4408 - if (regs->tstate & TSTATE_PRIV)
4409 + if (regs->tstate & TSTATE_PRIV) {
4410 + gr_handle_kernel_exploit();
4411 do_exit(SIGKILL);
4412 + }
4413 do_exit(SIGSEGV);
4414 }
4415 EXPORT_SYMBOL(die_if_kernel);
4416 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
4417 index 76e4ac1..78f8bb1 100644
4418 --- a/arch/sparc/kernel/unaligned_64.c
4419 +++ b/arch/sparc/kernel/unaligned_64.c
4420 @@ -279,7 +279,7 @@ static void log_unaligned(struct pt_regs *regs)
4421 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
4422
4423 if (__ratelimit(&ratelimit)) {
4424 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
4425 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
4426 regs->tpc, (void *) regs->tpc);
4427 }
4428 }
4429 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
4430 index a3fc437..fea9957 100644
4431 --- a/arch/sparc/lib/Makefile
4432 +++ b/arch/sparc/lib/Makefile
4433 @@ -2,7 +2,7 @@
4434 #
4435
4436 asflags-y := -ansi -DST_DIV0=0x02
4437 -ccflags-y := -Werror
4438 +#ccflags-y := -Werror
4439
4440 lib-$(CONFIG_SPARC32) += mul.o rem.o sdiv.o udiv.o umul.o urem.o ashrdi3.o
4441 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
4442 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
4443 index 59186e0..f747d7a 100644
4444 --- a/arch/sparc/lib/atomic_64.S
4445 +++ b/arch/sparc/lib/atomic_64.S
4446 @@ -18,7 +18,12 @@
4447 atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4448 BACKOFF_SETUP(%o2)
4449 1: lduw [%o1], %g1
4450 - add %g1, %o0, %g7
4451 + addcc %g1, %o0, %g7
4452 +
4453 +#ifdef CONFIG_PAX_REFCOUNT
4454 + tvs %icc, 6
4455 +#endif
4456 +
4457 cas [%o1], %g1, %g7
4458 cmp %g1, %g7
4459 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4460 @@ -28,12 +33,32 @@ atomic_add: /* %o0 = increment, %o1 = atomic_ptr */
4461 2: BACKOFF_SPIN(%o2, %o3, 1b)
4462 .size atomic_add, .-atomic_add
4463
4464 + .globl atomic_add_unchecked
4465 + .type atomic_add_unchecked,#function
4466 +atomic_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4467 + BACKOFF_SETUP(%o2)
4468 +1: lduw [%o1], %g1
4469 + add %g1, %o0, %g7
4470 + cas [%o1], %g1, %g7
4471 + cmp %g1, %g7
4472 + bne,pn %icc, 2f
4473 + nop
4474 + retl
4475 + nop
4476 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4477 + .size atomic_add_unchecked, .-atomic_add_unchecked
4478 +
4479 .globl atomic_sub
4480 .type atomic_sub,#function
4481 atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4482 BACKOFF_SETUP(%o2)
4483 1: lduw [%o1], %g1
4484 - sub %g1, %o0, %g7
4485 + subcc %g1, %o0, %g7
4486 +
4487 +#ifdef CONFIG_PAX_REFCOUNT
4488 + tvs %icc, 6
4489 +#endif
4490 +
4491 cas [%o1], %g1, %g7
4492 cmp %g1, %g7
4493 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4494 @@ -43,12 +68,32 @@ atomic_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4495 2: BACKOFF_SPIN(%o2, %o3, 1b)
4496 .size atomic_sub, .-atomic_sub
4497
4498 + .globl atomic_sub_unchecked
4499 + .type atomic_sub_unchecked,#function
4500 +atomic_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4501 + BACKOFF_SETUP(%o2)
4502 +1: lduw [%o1], %g1
4503 + sub %g1, %o0, %g7
4504 + cas [%o1], %g1, %g7
4505 + cmp %g1, %g7
4506 + bne,pn %icc, 2f
4507 + nop
4508 + retl
4509 + nop
4510 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4511 + .size atomic_sub_unchecked, .-atomic_sub_unchecked
4512 +
4513 .globl atomic_add_ret
4514 .type atomic_add_ret,#function
4515 atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4516 BACKOFF_SETUP(%o2)
4517 1: lduw [%o1], %g1
4518 - add %g1, %o0, %g7
4519 + addcc %g1, %o0, %g7
4520 +
4521 +#ifdef CONFIG_PAX_REFCOUNT
4522 + tvs %icc, 6
4523 +#endif
4524 +
4525 cas [%o1], %g1, %g7
4526 cmp %g1, %g7
4527 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4528 @@ -58,12 +103,33 @@ atomic_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4529 2: BACKOFF_SPIN(%o2, %o3, 1b)
4530 .size atomic_add_ret, .-atomic_add_ret
4531
4532 + .globl atomic_add_ret_unchecked
4533 + .type atomic_add_ret_unchecked,#function
4534 +atomic_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4535 + BACKOFF_SETUP(%o2)
4536 +1: lduw [%o1], %g1
4537 + addcc %g1, %o0, %g7
4538 + cas [%o1], %g1, %g7
4539 + cmp %g1, %g7
4540 + bne,pn %icc, 2f
4541 + add %g7, %o0, %g7
4542 + sra %g7, 0, %o0
4543 + retl
4544 + nop
4545 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4546 + .size atomic_add_ret_unchecked, .-atomic_add_ret_unchecked
4547 +
4548 .globl atomic_sub_ret
4549 .type atomic_sub_ret,#function
4550 atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4551 BACKOFF_SETUP(%o2)
4552 1: lduw [%o1], %g1
4553 - sub %g1, %o0, %g7
4554 + subcc %g1, %o0, %g7
4555 +
4556 +#ifdef CONFIG_PAX_REFCOUNT
4557 + tvs %icc, 6
4558 +#endif
4559 +
4560 cas [%o1], %g1, %g7
4561 cmp %g1, %g7
4562 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
4563 @@ -78,7 +144,12 @@ atomic_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4564 atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4565 BACKOFF_SETUP(%o2)
4566 1: ldx [%o1], %g1
4567 - add %g1, %o0, %g7
4568 + addcc %g1, %o0, %g7
4569 +
4570 +#ifdef CONFIG_PAX_REFCOUNT
4571 + tvs %xcc, 6
4572 +#endif
4573 +
4574 casx [%o1], %g1, %g7
4575 cmp %g1, %g7
4576 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4577 @@ -88,12 +159,32 @@ atomic64_add: /* %o0 = increment, %o1 = atomic_ptr */
4578 2: BACKOFF_SPIN(%o2, %o3, 1b)
4579 .size atomic64_add, .-atomic64_add
4580
4581 + .globl atomic64_add_unchecked
4582 + .type atomic64_add_unchecked,#function
4583 +atomic64_add_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4584 + BACKOFF_SETUP(%o2)
4585 +1: ldx [%o1], %g1
4586 + addcc %g1, %o0, %g7
4587 + casx [%o1], %g1, %g7
4588 + cmp %g1, %g7
4589 + bne,pn %xcc, 2f
4590 + nop
4591 + retl
4592 + nop
4593 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4594 + .size atomic64_add_unchecked, .-atomic64_add_unchecked
4595 +
4596 .globl atomic64_sub
4597 .type atomic64_sub,#function
4598 atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4599 BACKOFF_SETUP(%o2)
4600 1: ldx [%o1], %g1
4601 - sub %g1, %o0, %g7
4602 + subcc %g1, %o0, %g7
4603 +
4604 +#ifdef CONFIG_PAX_REFCOUNT
4605 + tvs %xcc, 6
4606 +#endif
4607 +
4608 casx [%o1], %g1, %g7
4609 cmp %g1, %g7
4610 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4611 @@ -103,12 +194,32 @@ atomic64_sub: /* %o0 = decrement, %o1 = atomic_ptr */
4612 2: BACKOFF_SPIN(%o2, %o3, 1b)
4613 .size atomic64_sub, .-atomic64_sub
4614
4615 + .globl atomic64_sub_unchecked
4616 + .type atomic64_sub_unchecked,#function
4617 +atomic64_sub_unchecked: /* %o0 = decrement, %o1 = atomic_ptr */
4618 + BACKOFF_SETUP(%o2)
4619 +1: ldx [%o1], %g1
4620 + subcc %g1, %o0, %g7
4621 + casx [%o1], %g1, %g7
4622 + cmp %g1, %g7
4623 + bne,pn %xcc, 2f
4624 + nop
4625 + retl
4626 + nop
4627 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4628 + .size atomic64_sub_unchecked, .-atomic64_sub_unchecked
4629 +
4630 .globl atomic64_add_ret
4631 .type atomic64_add_ret,#function
4632 atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4633 BACKOFF_SETUP(%o2)
4634 1: ldx [%o1], %g1
4635 - add %g1, %o0, %g7
4636 + addcc %g1, %o0, %g7
4637 +
4638 +#ifdef CONFIG_PAX_REFCOUNT
4639 + tvs %xcc, 6
4640 +#endif
4641 +
4642 casx [%o1], %g1, %g7
4643 cmp %g1, %g7
4644 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4645 @@ -118,12 +229,33 @@ atomic64_add_ret: /* %o0 = increment, %o1 = atomic_ptr */
4646 2: BACKOFF_SPIN(%o2, %o3, 1b)
4647 .size atomic64_add_ret, .-atomic64_add_ret
4648
4649 + .globl atomic64_add_ret_unchecked
4650 + .type atomic64_add_ret_unchecked,#function
4651 +atomic64_add_ret_unchecked: /* %o0 = increment, %o1 = atomic_ptr */
4652 + BACKOFF_SETUP(%o2)
4653 +1: ldx [%o1], %g1
4654 + addcc %g1, %o0, %g7
4655 + casx [%o1], %g1, %g7
4656 + cmp %g1, %g7
4657 + bne,pn %xcc, 2f
4658 + add %g7, %o0, %g7
4659 + mov %g7, %o0
4660 + retl
4661 + nop
4662 +2: BACKOFF_SPIN(%o2, %o3, 1b)
4663 + .size atomic64_add_ret_unchecked, .-atomic64_add_ret_unchecked
4664 +
4665 .globl atomic64_sub_ret
4666 .type atomic64_sub_ret,#function
4667 atomic64_sub_ret: /* %o0 = decrement, %o1 = atomic_ptr */
4668 BACKOFF_SETUP(%o2)
4669 1: ldx [%o1], %g1
4670 - sub %g1, %o0, %g7
4671 + subcc %g1, %o0, %g7
4672 +
4673 +#ifdef CONFIG_PAX_REFCOUNT
4674 + tvs %xcc, 6
4675 +#endif
4676 +
4677 casx [%o1], %g1, %g7
4678 cmp %g1, %g7
4679 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
4680 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
4681 index 1b30bb3..b4a16c7 100644
4682 --- a/arch/sparc/lib/ksyms.c
4683 +++ b/arch/sparc/lib/ksyms.c
4684 @@ -142,12 +142,18 @@ EXPORT_SYMBOL(__downgrade_write);
4685
4686 /* Atomic counter implementation. */
4687 EXPORT_SYMBOL(atomic_add);
4688 +EXPORT_SYMBOL(atomic_add_unchecked);
4689 EXPORT_SYMBOL(atomic_add_ret);
4690 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
4691 EXPORT_SYMBOL(atomic_sub);
4692 +EXPORT_SYMBOL(atomic_sub_unchecked);
4693 EXPORT_SYMBOL(atomic_sub_ret);
4694 EXPORT_SYMBOL(atomic64_add);
4695 +EXPORT_SYMBOL(atomic64_add_unchecked);
4696 EXPORT_SYMBOL(atomic64_add_ret);
4697 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
4698 EXPORT_SYMBOL(atomic64_sub);
4699 +EXPORT_SYMBOL(atomic64_sub_unchecked);
4700 EXPORT_SYMBOL(atomic64_sub_ret);
4701
4702 /* Atomic bit operations. */
4703 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
4704 index 301421c..e2535d1 100644
4705 --- a/arch/sparc/mm/Makefile
4706 +++ b/arch/sparc/mm/Makefile
4707 @@ -2,7 +2,7 @@
4708 #
4709
4710 asflags-y := -ansi
4711 -ccflags-y := -Werror
4712 +#ccflags-y := -Werror
4713
4714 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
4715 obj-y += fault_$(BITS).o
4716 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
4717 index 8023fd7..c8e89e9 100644
4718 --- a/arch/sparc/mm/fault_32.c
4719 +++ b/arch/sparc/mm/fault_32.c
4720 @@ -21,6 +21,9 @@
4721 #include <linux/perf_event.h>
4722 #include <linux/interrupt.h>
4723 #include <linux/kdebug.h>
4724 +#include <linux/slab.h>
4725 +#include <linux/pagemap.h>
4726 +#include <linux/compiler.h>
4727
4728 #include <asm/system.h>
4729 #include <asm/page.h>
4730 @@ -208,6 +211,268 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
4731 return safe_compute_effective_address(regs, insn);
4732 }
4733
4734 +#ifdef CONFIG_PAX_PAGEEXEC
4735 +#ifdef CONFIG_PAX_DLRESOLVE
4736 +static void pax_emuplt_close(struct vm_area_struct *vma)
4737 +{
4738 + vma->vm_mm->call_dl_resolve = 0UL;
4739 +}
4740 +
4741 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4742 +{
4743 + unsigned int *kaddr;
4744 +
4745 + vmf->page = alloc_page(GFP_HIGHUSER);
4746 + if (!vmf->page)
4747 + return VM_FAULT_OOM;
4748 +
4749 + kaddr = kmap(vmf->page);
4750 + memset(kaddr, 0, PAGE_SIZE);
4751 + kaddr[0] = 0x9DE3BFA8U; /* save */
4752 + flush_dcache_page(vmf->page);
4753 + kunmap(vmf->page);
4754 + return VM_FAULT_MAJOR;
4755 +}
4756 +
4757 +static const struct vm_operations_struct pax_vm_ops = {
4758 + .close = pax_emuplt_close,
4759 + .fault = pax_emuplt_fault
4760 +};
4761 +
4762 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4763 +{
4764 + int ret;
4765 +
4766 + INIT_LIST_HEAD(&vma->anon_vma_chain);
4767 + vma->vm_mm = current->mm;
4768 + vma->vm_start = addr;
4769 + vma->vm_end = addr + PAGE_SIZE;
4770 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4771 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4772 + vma->vm_ops = &pax_vm_ops;
4773 +
4774 + ret = insert_vm_struct(current->mm, vma);
4775 + if (ret)
4776 + return ret;
4777 +
4778 + ++current->mm->total_vm;
4779 + return 0;
4780 +}
4781 +#endif
4782 +
4783 +/*
4784 + * PaX: decide what to do with offenders (regs->pc = fault address)
4785 + *
4786 + * returns 1 when task should be killed
4787 + * 2 when patched PLT trampoline was detected
4788 + * 3 when unpatched PLT trampoline was detected
4789 + */
4790 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4791 +{
4792 +
4793 +#ifdef CONFIG_PAX_EMUPLT
4794 + int err;
4795 +
4796 + do { /* PaX: patched PLT emulation #1 */
4797 + unsigned int sethi1, sethi2, jmpl;
4798 +
4799 + err = get_user(sethi1, (unsigned int *)regs->pc);
4800 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
4801 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
4802 +
4803 + if (err)
4804 + break;
4805 +
4806 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4807 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
4808 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
4809 + {
4810 + unsigned int addr;
4811 +
4812 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4813 + addr = regs->u_regs[UREG_G1];
4814 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4815 + regs->pc = addr;
4816 + regs->npc = addr+4;
4817 + return 2;
4818 + }
4819 + } while (0);
4820 +
4821 + { /* PaX: patched PLT emulation #2 */
4822 + unsigned int ba;
4823 +
4824 + err = get_user(ba, (unsigned int *)regs->pc);
4825 +
4826 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4827 + unsigned int addr;
4828 +
4829 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4830 + regs->pc = addr;
4831 + regs->npc = addr+4;
4832 + return 2;
4833 + }
4834 + }
4835 +
4836 + do { /* PaX: patched PLT emulation #3 */
4837 + unsigned int sethi, jmpl, nop;
4838 +
4839 + err = get_user(sethi, (unsigned int *)regs->pc);
4840 + err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
4841 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
4842 +
4843 + if (err)
4844 + break;
4845 +
4846 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
4847 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4848 + nop == 0x01000000U)
4849 + {
4850 + unsigned int addr;
4851 +
4852 + addr = (sethi & 0x003FFFFFU) << 10;
4853 + regs->u_regs[UREG_G1] = addr;
4854 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4855 + regs->pc = addr;
4856 + regs->npc = addr+4;
4857 + return 2;
4858 + }
4859 + } while (0);
4860 +
4861 + do { /* PaX: unpatched PLT emulation step 1 */
4862 + unsigned int sethi, ba, nop;
4863 +
4864 + err = get_user(sethi, (unsigned int *)regs->pc);
4865 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
4866 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
4867 +
4868 + if (err)
4869 + break;
4870 +
4871 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
4872 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4873 + nop == 0x01000000U)
4874 + {
4875 + unsigned int addr, save, call;
4876 +
4877 + if ((ba & 0xFFC00000U) == 0x30800000U)
4878 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4879 + else
4880 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
4881 +
4882 + err = get_user(save, (unsigned int *)addr);
4883 + err |= get_user(call, (unsigned int *)(addr+4));
4884 + err |= get_user(nop, (unsigned int *)(addr+8));
4885 + if (err)
4886 + break;
4887 +
4888 +#ifdef CONFIG_PAX_DLRESOLVE
4889 + if (save == 0x9DE3BFA8U &&
4890 + (call & 0xC0000000U) == 0x40000000U &&
4891 + nop == 0x01000000U)
4892 + {
4893 + struct vm_area_struct *vma;
4894 + unsigned long call_dl_resolve;
4895 +
4896 + down_read(&current->mm->mmap_sem);
4897 + call_dl_resolve = current->mm->call_dl_resolve;
4898 + up_read(&current->mm->mmap_sem);
4899 + if (likely(call_dl_resolve))
4900 + goto emulate;
4901 +
4902 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4903 +
4904 + down_write(&current->mm->mmap_sem);
4905 + if (current->mm->call_dl_resolve) {
4906 + call_dl_resolve = current->mm->call_dl_resolve;
4907 + up_write(&current->mm->mmap_sem);
4908 + if (vma)
4909 + kmem_cache_free(vm_area_cachep, vma);
4910 + goto emulate;
4911 + }
4912 +
4913 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4914 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4915 + up_write(&current->mm->mmap_sem);
4916 + if (vma)
4917 + kmem_cache_free(vm_area_cachep, vma);
4918 + return 1;
4919 + }
4920 +
4921 + if (pax_insert_vma(vma, call_dl_resolve)) {
4922 + up_write(&current->mm->mmap_sem);
4923 + kmem_cache_free(vm_area_cachep, vma);
4924 + return 1;
4925 + }
4926 +
4927 + current->mm->call_dl_resolve = call_dl_resolve;
4928 + up_write(&current->mm->mmap_sem);
4929 +
4930 +emulate:
4931 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4932 + regs->pc = call_dl_resolve;
4933 + regs->npc = addr+4;
4934 + return 3;
4935 + }
4936 +#endif
4937 +
4938 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
4939 + if ((save & 0xFFC00000U) == 0x05000000U &&
4940 + (call & 0xFFFFE000U) == 0x85C0A000U &&
4941 + nop == 0x01000000U)
4942 + {
4943 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4944 + regs->u_regs[UREG_G2] = addr + 4;
4945 + addr = (save & 0x003FFFFFU) << 10;
4946 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4947 + regs->pc = addr;
4948 + regs->npc = addr+4;
4949 + return 3;
4950 + }
4951 + }
4952 + } while (0);
4953 +
4954 + do { /* PaX: unpatched PLT emulation step 2 */
4955 + unsigned int save, call, nop;
4956 +
4957 + err = get_user(save, (unsigned int *)(regs->pc-4));
4958 + err |= get_user(call, (unsigned int *)regs->pc);
4959 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
4960 + if (err)
4961 + break;
4962 +
4963 + if (save == 0x9DE3BFA8U &&
4964 + (call & 0xC0000000U) == 0x40000000U &&
4965 + nop == 0x01000000U)
4966 + {
4967 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
4968 +
4969 + regs->u_regs[UREG_RETPC] = regs->pc;
4970 + regs->pc = dl_resolve;
4971 + regs->npc = dl_resolve+4;
4972 + return 3;
4973 + }
4974 + } while (0);
4975 +#endif
4976 +
4977 + return 1;
4978 +}
4979 +
4980 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4981 +{
4982 + unsigned long i;
4983 +
4984 + printk(KERN_ERR "PAX: bytes at PC: ");
4985 + for (i = 0; i < 8; i++) {
4986 + unsigned int c;
4987 + if (get_user(c, (unsigned int *)pc+i))
4988 + printk(KERN_CONT "???????? ");
4989 + else
4990 + printk(KERN_CONT "%08x ", c);
4991 + }
4992 + printk("\n");
4993 +}
4994 +#endif
4995 +
4996 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
4997 int text_fault)
4998 {
4999 @@ -280,6 +545,24 @@ good_area:
5000 if(!(vma->vm_flags & VM_WRITE))
5001 goto bad_area;
5002 } else {
5003 +
5004 +#ifdef CONFIG_PAX_PAGEEXEC
5005 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
5006 + up_read(&mm->mmap_sem);
5007 + switch (pax_handle_fetch_fault(regs)) {
5008 +
5009 +#ifdef CONFIG_PAX_EMUPLT
5010 + case 2:
5011 + case 3:
5012 + return;
5013 +#endif
5014 +
5015 + }
5016 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
5017 + do_group_exit(SIGKILL);
5018 + }
5019 +#endif
5020 +
5021 /* Allow reads even for write-only mappings */
5022 if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
5023 goto bad_area;
5024 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
5025 index 504c062..6fcb9c6 100644
5026 --- a/arch/sparc/mm/fault_64.c
5027 +++ b/arch/sparc/mm/fault_64.c
5028 @@ -21,6 +21,9 @@
5029 #include <linux/kprobes.h>
5030 #include <linux/kdebug.h>
5031 #include <linux/percpu.h>
5032 +#include <linux/slab.h>
5033 +#include <linux/pagemap.h>
5034 +#include <linux/compiler.h>
5035
5036 #include <asm/page.h>
5037 #include <asm/pgtable.h>
5038 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
5039 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
5040 regs->tpc);
5041 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
5042 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
5043 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
5044 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
5045 dump_stack();
5046 unhandled_fault(regs->tpc, current, regs);
5047 @@ -272,6 +275,457 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
5048 show_regs(regs);
5049 }
5050
5051 +#ifdef CONFIG_PAX_PAGEEXEC
5052 +#ifdef CONFIG_PAX_DLRESOLVE
5053 +static void pax_emuplt_close(struct vm_area_struct *vma)
5054 +{
5055 + vma->vm_mm->call_dl_resolve = 0UL;
5056 +}
5057 +
5058 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
5059 +{
5060 + unsigned int *kaddr;
5061 +
5062 + vmf->page = alloc_page(GFP_HIGHUSER);
5063 + if (!vmf->page)
5064 + return VM_FAULT_OOM;
5065 +
5066 + kaddr = kmap(vmf->page);
5067 + memset(kaddr, 0, PAGE_SIZE);
5068 + kaddr[0] = 0x9DE3BFA8U; /* save */
5069 + flush_dcache_page(vmf->page);
5070 + kunmap(vmf->page);
5071 + return VM_FAULT_MAJOR;
5072 +}
5073 +
5074 +static const struct vm_operations_struct pax_vm_ops = {
5075 + .close = pax_emuplt_close,
5076 + .fault = pax_emuplt_fault
5077 +};
5078 +
5079 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
5080 +{
5081 + int ret;
5082 +
5083 + INIT_LIST_HEAD(&vma->anon_vma_chain);
5084 + vma->vm_mm = current->mm;
5085 + vma->vm_start = addr;
5086 + vma->vm_end = addr + PAGE_SIZE;
5087 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
5088 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5089 + vma->vm_ops = &pax_vm_ops;
5090 +
5091 + ret = insert_vm_struct(current->mm, vma);
5092 + if (ret)
5093 + return ret;
5094 +
5095 + ++current->mm->total_vm;
5096 + return 0;
5097 +}
5098 +#endif
5099 +
5100 +/*
5101 + * PaX: decide what to do with offenders (regs->tpc = fault address)
5102 + *
5103 + * returns 1 when task should be killed
5104 + * 2 when patched PLT trampoline was detected
5105 + * 3 when unpatched PLT trampoline was detected
5106 + */
5107 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5108 +{
5109 +
5110 +#ifdef CONFIG_PAX_EMUPLT
5111 + int err;
5112 +
5113 + do { /* PaX: patched PLT emulation #1 */
5114 + unsigned int sethi1, sethi2, jmpl;
5115 +
5116 + err = get_user(sethi1, (unsigned int *)regs->tpc);
5117 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
5118 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
5119 +
5120 + if (err)
5121 + break;
5122 +
5123 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
5124 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
5125 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
5126 + {
5127 + unsigned long addr;
5128 +
5129 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
5130 + addr = regs->u_regs[UREG_G1];
5131 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5132 +
5133 + if (test_thread_flag(TIF_32BIT))
5134 + addr &= 0xFFFFFFFFUL;
5135 +
5136 + regs->tpc = addr;
5137 + regs->tnpc = addr+4;
5138 + return 2;
5139 + }
5140 + } while (0);
5141 +
5142 + { /* PaX: patched PLT emulation #2 */
5143 + unsigned int ba;
5144 +
5145 + err = get_user(ba, (unsigned int *)regs->tpc);
5146 +
5147 + if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
5148 + unsigned long addr;
5149 +
5150 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5151 +
5152 + if (test_thread_flag(TIF_32BIT))
5153 + addr &= 0xFFFFFFFFUL;
5154 +
5155 + regs->tpc = addr;
5156 + regs->tnpc = addr+4;
5157 + return 2;
5158 + }
5159 + }
5160 +
5161 + do { /* PaX: patched PLT emulation #3 */
5162 + unsigned int sethi, jmpl, nop;
5163 +
5164 + err = get_user(sethi, (unsigned int *)regs->tpc);
5165 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
5166 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5167 +
5168 + if (err)
5169 + break;
5170 +
5171 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5172 + (jmpl & 0xFFFFE000U) == 0x81C06000U &&
5173 + nop == 0x01000000U)
5174 + {
5175 + unsigned long addr;
5176 +
5177 + addr = (sethi & 0x003FFFFFU) << 10;
5178 + regs->u_regs[UREG_G1] = addr;
5179 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5180 +
5181 + if (test_thread_flag(TIF_32BIT))
5182 + addr &= 0xFFFFFFFFUL;
5183 +
5184 + regs->tpc = addr;
5185 + regs->tnpc = addr+4;
5186 + return 2;
5187 + }
5188 + } while (0);
5189 +
5190 + do { /* PaX: patched PLT emulation #4 */
5191 + unsigned int sethi, mov1, call, mov2;
5192 +
5193 + err = get_user(sethi, (unsigned int *)regs->tpc);
5194 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
5195 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
5196 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
5197 +
5198 + if (err)
5199 + break;
5200 +
5201 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5202 + mov1 == 0x8210000FU &&
5203 + (call & 0xC0000000U) == 0x40000000U &&
5204 + mov2 == 0x9E100001U)
5205 + {
5206 + unsigned long addr;
5207 +
5208 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
5209 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5210 +
5211 + if (test_thread_flag(TIF_32BIT))
5212 + addr &= 0xFFFFFFFFUL;
5213 +
5214 + regs->tpc = addr;
5215 + regs->tnpc = addr+4;
5216 + return 2;
5217 + }
5218 + } while (0);
5219 +
5220 + do { /* PaX: patched PLT emulation #5 */
5221 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
5222 +
5223 + err = get_user(sethi, (unsigned int *)regs->tpc);
5224 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5225 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5226 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
5227 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
5228 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
5229 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
5230 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
5231 +
5232 + if (err)
5233 + break;
5234 +
5235 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5236 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5237 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5238 + (or1 & 0xFFFFE000U) == 0x82106000U &&
5239 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5240 + sllx == 0x83287020U &&
5241 + jmpl == 0x81C04005U &&
5242 + nop == 0x01000000U)
5243 + {
5244 + unsigned long addr;
5245 +
5246 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5247 + regs->u_regs[UREG_G1] <<= 32;
5248 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5249 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5250 + regs->tpc = addr;
5251 + regs->tnpc = addr+4;
5252 + return 2;
5253 + }
5254 + } while (0);
5255 +
5256 + do { /* PaX: patched PLT emulation #6 */
5257 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
5258 +
5259 + err = get_user(sethi, (unsigned int *)regs->tpc);
5260 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
5261 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
5262 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
5263 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
5264 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
5265 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
5266 +
5267 + if (err)
5268 + break;
5269 +
5270 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5271 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
5272 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5273 + sllx == 0x83287020U &&
5274 + (or & 0xFFFFE000U) == 0x8A116000U &&
5275 + jmpl == 0x81C04005U &&
5276 + nop == 0x01000000U)
5277 + {
5278 + unsigned long addr;
5279 +
5280 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
5281 + regs->u_regs[UREG_G1] <<= 32;
5282 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
5283 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
5284 + regs->tpc = addr;
5285 + regs->tnpc = addr+4;
5286 + return 2;
5287 + }
5288 + } while (0);
5289 +
5290 + do { /* PaX: unpatched PLT emulation step 1 */
5291 + unsigned int sethi, ba, nop;
5292 +
5293 + err = get_user(sethi, (unsigned int *)regs->tpc);
5294 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5295 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5296 +
5297 + if (err)
5298 + break;
5299 +
5300 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5301 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
5302 + nop == 0x01000000U)
5303 + {
5304 + unsigned long addr;
5305 + unsigned int save, call;
5306 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
5307 +
5308 + if ((ba & 0xFFC00000U) == 0x30800000U)
5309 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
5310 + else
5311 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5312 +
5313 + if (test_thread_flag(TIF_32BIT))
5314 + addr &= 0xFFFFFFFFUL;
5315 +
5316 + err = get_user(save, (unsigned int *)addr);
5317 + err |= get_user(call, (unsigned int *)(addr+4));
5318 + err |= get_user(nop, (unsigned int *)(addr+8));
5319 + if (err)
5320 + break;
5321 +
5322 +#ifdef CONFIG_PAX_DLRESOLVE
5323 + if (save == 0x9DE3BFA8U &&
5324 + (call & 0xC0000000U) == 0x40000000U &&
5325 + nop == 0x01000000U)
5326 + {
5327 + struct vm_area_struct *vma;
5328 + unsigned long call_dl_resolve;
5329 +
5330 + down_read(&current->mm->mmap_sem);
5331 + call_dl_resolve = current->mm->call_dl_resolve;
5332 + up_read(&current->mm->mmap_sem);
5333 + if (likely(call_dl_resolve))
5334 + goto emulate;
5335 +
5336 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
5337 +
5338 + down_write(&current->mm->mmap_sem);
5339 + if (current->mm->call_dl_resolve) {
5340 + call_dl_resolve = current->mm->call_dl_resolve;
5341 + up_write(&current->mm->mmap_sem);
5342 + if (vma)
5343 + kmem_cache_free(vm_area_cachep, vma);
5344 + goto emulate;
5345 + }
5346 +
5347 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
5348 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
5349 + up_write(&current->mm->mmap_sem);
5350 + if (vma)
5351 + kmem_cache_free(vm_area_cachep, vma);
5352 + return 1;
5353 + }
5354 +
5355 + if (pax_insert_vma(vma, call_dl_resolve)) {
5356 + up_write(&current->mm->mmap_sem);
5357 + kmem_cache_free(vm_area_cachep, vma);
5358 + return 1;
5359 + }
5360 +
5361 + current->mm->call_dl_resolve = call_dl_resolve;
5362 + up_write(&current->mm->mmap_sem);
5363 +
5364 +emulate:
5365 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5366 + regs->tpc = call_dl_resolve;
5367 + regs->tnpc = addr+4;
5368 + return 3;
5369 + }
5370 +#endif
5371 +
5372 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
5373 + if ((save & 0xFFC00000U) == 0x05000000U &&
5374 + (call & 0xFFFFE000U) == 0x85C0A000U &&
5375 + nop == 0x01000000U)
5376 + {
5377 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5378 + regs->u_regs[UREG_G2] = addr + 4;
5379 + addr = (save & 0x003FFFFFU) << 10;
5380 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
5381 +
5382 + if (test_thread_flag(TIF_32BIT))
5383 + addr &= 0xFFFFFFFFUL;
5384 +
5385 + regs->tpc = addr;
5386 + regs->tnpc = addr+4;
5387 + return 3;
5388 + }
5389 +
5390 + /* PaX: 64-bit PLT stub */
5391 + err = get_user(sethi1, (unsigned int *)addr);
5392 + err |= get_user(sethi2, (unsigned int *)(addr+4));
5393 + err |= get_user(or1, (unsigned int *)(addr+8));
5394 + err |= get_user(or2, (unsigned int *)(addr+12));
5395 + err |= get_user(sllx, (unsigned int *)(addr+16));
5396 + err |= get_user(add, (unsigned int *)(addr+20));
5397 + err |= get_user(jmpl, (unsigned int *)(addr+24));
5398 + err |= get_user(nop, (unsigned int *)(addr+28));
5399 + if (err)
5400 + break;
5401 +
5402 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
5403 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
5404 + (or1 & 0xFFFFE000U) == 0x88112000U &&
5405 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
5406 + sllx == 0x89293020U &&
5407 + add == 0x8A010005U &&
5408 + jmpl == 0x89C14000U &&
5409 + nop == 0x01000000U)
5410 + {
5411 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
5412 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
5413 + regs->u_regs[UREG_G4] <<= 32;
5414 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
5415 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
5416 + regs->u_regs[UREG_G4] = addr + 24;
5417 + addr = regs->u_regs[UREG_G5];
5418 + regs->tpc = addr;
5419 + regs->tnpc = addr+4;
5420 + return 3;
5421 + }
5422 + }
5423 + } while (0);
5424 +
5425 +#ifdef CONFIG_PAX_DLRESOLVE
5426 + do { /* PaX: unpatched PLT emulation step 2 */
5427 + unsigned int save, call, nop;
5428 +
5429 + err = get_user(save, (unsigned int *)(regs->tpc-4));
5430 + err |= get_user(call, (unsigned int *)regs->tpc);
5431 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
5432 + if (err)
5433 + break;
5434 +
5435 + if (save == 0x9DE3BFA8U &&
5436 + (call & 0xC0000000U) == 0x40000000U &&
5437 + nop == 0x01000000U)
5438 + {
5439 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
5440 +
5441 + if (test_thread_flag(TIF_32BIT))
5442 + dl_resolve &= 0xFFFFFFFFUL;
5443 +
5444 + regs->u_regs[UREG_RETPC] = regs->tpc;
5445 + regs->tpc = dl_resolve;
5446 + regs->tnpc = dl_resolve+4;
5447 + return 3;
5448 + }
5449 + } while (0);
5450 +#endif
5451 +
5452 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
5453 + unsigned int sethi, ba, nop;
5454 +
5455 + err = get_user(sethi, (unsigned int *)regs->tpc);
5456 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
5457 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
5458 +
5459 + if (err)
5460 + break;
5461 +
5462 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
5463 + (ba & 0xFFF00000U) == 0x30600000U &&
5464 + nop == 0x01000000U)
5465 + {
5466 + unsigned long addr;
5467 +
5468 + addr = (sethi & 0x003FFFFFU) << 10;
5469 + regs->u_regs[UREG_G1] = addr;
5470 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
5471 +
5472 + if (test_thread_flag(TIF_32BIT))
5473 + addr &= 0xFFFFFFFFUL;
5474 +
5475 + regs->tpc = addr;
5476 + regs->tnpc = addr+4;
5477 + return 2;
5478 + }
5479 + } while (0);
5480 +
5481 +#endif
5482 +
5483 + return 1;
5484 +}
5485 +
5486 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5487 +{
5488 + unsigned long i;
5489 +
5490 + printk(KERN_ERR "PAX: bytes at PC: ");
5491 + for (i = 0; i < 8; i++) {
5492 + unsigned int c;
5493 + if (get_user(c, (unsigned int *)pc+i))
5494 + printk(KERN_CONT "???????? ");
5495 + else
5496 + printk(KERN_CONT "%08x ", c);
5497 + }
5498 + printk("\n");
5499 +}
5500 +#endif
5501 +
5502 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5503 {
5504 struct mm_struct *mm = current->mm;
5505 @@ -340,6 +794,29 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
5506 if (!vma)
5507 goto bad_area;
5508
5509 +#ifdef CONFIG_PAX_PAGEEXEC
5510 + /* PaX: detect ITLB misses on non-exec pages */
5511 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5512 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5513 + {
5514 + if (address != regs->tpc)
5515 + goto good_area;
5516 +
5517 + up_read(&mm->mmap_sem);
5518 + switch (pax_handle_fetch_fault(regs)) {
5519 +
5520 +#ifdef CONFIG_PAX_EMUPLT
5521 + case 2:
5522 + case 3:
5523 + return;
5524 +#endif
5525 +
5526 + }
5527 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5528 + do_group_exit(SIGKILL);
5529 + }
5530 +#endif
5531 +
5532 /* Pure DTLB misses do not tell us whether the fault causing
5533 * load/store/atomic was a write or not, it only says that there
5534 * was no match. So in such a case we (carefully) read the
5535 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
5536 index 07e1453..0a7d9e9 100644
5537 --- a/arch/sparc/mm/hugetlbpage.c
5538 +++ b/arch/sparc/mm/hugetlbpage.c
5539 @@ -67,7 +67,7 @@ full_search:
5540 }
5541 return -ENOMEM;
5542 }
5543 - if (likely(!vma || addr + len <= vma->vm_start)) {
5544 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5545 /*
5546 * Remember the place where we stopped the search:
5547 */
5548 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5549 /* make sure it can fit in the remaining address space */
5550 if (likely(addr > len)) {
5551 vma = find_vma(mm, addr-len);
5552 - if (!vma || addr <= vma->vm_start) {
5553 + if (check_heap_stack_gap(vma, addr - len, len)) {
5554 /* remember the address as a hint for next time */
5555 return (mm->free_area_cache = addr-len);
5556 }
5557 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5558 if (unlikely(mm->mmap_base < len))
5559 goto bottomup;
5560
5561 - addr = (mm->mmap_base-len) & HPAGE_MASK;
5562 + addr = mm->mmap_base - len;
5563
5564 do {
5565 + addr &= HPAGE_MASK;
5566 /*
5567 * Lookup failure means no vma is above this address,
5568 * else if new region fits below vma->vm_start,
5569 * return with success:
5570 */
5571 vma = find_vma(mm, addr);
5572 - if (likely(!vma || addr+len <= vma->vm_start)) {
5573 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5574 /* remember the address as a hint for next time */
5575 return (mm->free_area_cache = addr);
5576 }
5577 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5578 mm->cached_hole_size = vma->vm_start - addr;
5579
5580 /* try just below the current vma->vm_start */
5581 - addr = (vma->vm_start-len) & HPAGE_MASK;
5582 - } while (likely(len < vma->vm_start));
5583 + addr = skip_heap_stack_gap(vma, len);
5584 + } while (!IS_ERR_VALUE(addr));
5585
5586 bottomup:
5587 /*
5588 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
5589 if (addr) {
5590 addr = ALIGN(addr, HPAGE_SIZE);
5591 vma = find_vma(mm, addr);
5592 - if (task_size - len >= addr &&
5593 - (!vma || addr + len <= vma->vm_start))
5594 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5595 return addr;
5596 }
5597 if (mm->get_unmapped_area == arch_get_unmapped_area)
5598 diff --git a/arch/sparc/mm/init_32.c b/arch/sparc/mm/init_32.c
5599 index 7b00de6..78239f4 100644
5600 --- a/arch/sparc/mm/init_32.c
5601 +++ b/arch/sparc/mm/init_32.c
5602 @@ -316,6 +316,9 @@ extern void device_scan(void);
5603 pgprot_t PAGE_SHARED __read_mostly;
5604 EXPORT_SYMBOL(PAGE_SHARED);
5605
5606 +pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
5607 +EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
5608 +
5609 void __init paging_init(void)
5610 {
5611 switch(sparc_cpu_model) {
5612 @@ -344,17 +347,17 @@ void __init paging_init(void)
5613
5614 /* Initialize the protection map with non-constant, MMU dependent values. */
5615 protection_map[0] = PAGE_NONE;
5616 - protection_map[1] = PAGE_READONLY;
5617 - protection_map[2] = PAGE_COPY;
5618 - protection_map[3] = PAGE_COPY;
5619 + protection_map[1] = PAGE_READONLY_NOEXEC;
5620 + protection_map[2] = PAGE_COPY_NOEXEC;
5621 + protection_map[3] = PAGE_COPY_NOEXEC;
5622 protection_map[4] = PAGE_READONLY;
5623 protection_map[5] = PAGE_READONLY;
5624 protection_map[6] = PAGE_COPY;
5625 protection_map[7] = PAGE_COPY;
5626 protection_map[8] = PAGE_NONE;
5627 - protection_map[9] = PAGE_READONLY;
5628 - protection_map[10] = PAGE_SHARED;
5629 - protection_map[11] = PAGE_SHARED;
5630 + protection_map[9] = PAGE_READONLY_NOEXEC;
5631 + protection_map[10] = PAGE_SHARED_NOEXEC;
5632 + protection_map[11] = PAGE_SHARED_NOEXEC;
5633 protection_map[12] = PAGE_READONLY;
5634 protection_map[13] = PAGE_READONLY;
5635 protection_map[14] = PAGE_SHARED;
5636 diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
5637 index cbef74e..c38fead 100644
5638 --- a/arch/sparc/mm/srmmu.c
5639 +++ b/arch/sparc/mm/srmmu.c
5640 @@ -2200,6 +2200,13 @@ void __init ld_mmu_srmmu(void)
5641 PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
5642 BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
5643 BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
5644 +
5645 +#ifdef CONFIG_PAX_PAGEEXEC
5646 + PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
5647 + BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
5648 + BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
5649 +#endif
5650 +
5651 BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
5652 page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
5653
5654 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
5655 index 27fe667..875b049 100644
5656 --- a/arch/tile/include/asm/atomic_64.h
5657 +++ b/arch/tile/include/asm/atomic_64.h
5658 @@ -142,6 +142,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5659
5660 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5661
5662 +#define atomic64_read_unchecked(v) atomic64_read(v)
5663 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5664 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5665 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5666 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5667 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5668 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5669 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5670 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5671 +
5672 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
5673 #define smp_mb__before_atomic_dec() smp_mb()
5674 #define smp_mb__after_atomic_dec() smp_mb()
5675 diff --git a/arch/um/Makefile b/arch/um/Makefile
5676 index 7730af6..cce5b19 100644
5677 --- a/arch/um/Makefile
5678 +++ b/arch/um/Makefile
5679 @@ -61,6 +61,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
5680 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
5681 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
5682
5683 +ifdef CONSTIFY_PLUGIN
5684 +USER_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5685 +endif
5686 +
5687 #This will adjust *FLAGS accordingly to the platform.
5688 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
5689
5690 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
5691 index 6c03acd..a5e0215 100644
5692 --- a/arch/um/include/asm/kmap_types.h
5693 +++ b/arch/um/include/asm/kmap_types.h
5694 @@ -23,6 +23,7 @@ enum km_type {
5695 KM_IRQ1,
5696 KM_SOFTIRQ0,
5697 KM_SOFTIRQ1,
5698 + KM_CLEARPAGE,
5699 KM_TYPE_NR
5700 };
5701
5702 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
5703 index 7cfc3ce..cbd1a58 100644
5704 --- a/arch/um/include/asm/page.h
5705 +++ b/arch/um/include/asm/page.h
5706 @@ -14,6 +14,9 @@
5707 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5708 #define PAGE_MASK (~(PAGE_SIZE-1))
5709
5710 +#define ktla_ktva(addr) (addr)
5711 +#define ktva_ktla(addr) (addr)
5712 +
5713 #ifndef __ASSEMBLY__
5714
5715 struct page;
5716 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
5717 index c533835..84db18e 100644
5718 --- a/arch/um/kernel/process.c
5719 +++ b/arch/um/kernel/process.c
5720 @@ -406,22 +406,6 @@ int singlestepping(void * t)
5721 return 2;
5722 }
5723
5724 -/*
5725 - * Only x86 and x86_64 have an arch_align_stack().
5726 - * All other arches have "#define arch_align_stack(x) (x)"
5727 - * in their asm/system.h
5728 - * As this is included in UML from asm-um/system-generic.h,
5729 - * we can use it to behave as the subarch does.
5730 - */
5731 -#ifndef arch_align_stack
5732 -unsigned long arch_align_stack(unsigned long sp)
5733 -{
5734 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5735 - sp -= get_random_int() % 8192;
5736 - return sp & ~0xf;
5737 -}
5738 -#endif
5739 -
5740 unsigned long get_wchan(struct task_struct *p)
5741 {
5742 unsigned long stack_page, sp, ip;
5743 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
5744 index efb4294..61bc18c 100644
5745 --- a/arch/x86/Kconfig
5746 +++ b/arch/x86/Kconfig
5747 @@ -235,7 +235,7 @@ config X86_HT
5748
5749 config X86_32_LAZY_GS
5750 def_bool y
5751 - depends on X86_32 && !CC_STACKPROTECTOR
5752 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
5753
5754 config ARCH_HWEIGHT_CFLAGS
5755 string
5756 @@ -1022,7 +1022,7 @@ choice
5757
5758 config NOHIGHMEM
5759 bool "off"
5760 - depends on !X86_NUMAQ
5761 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
5762 ---help---
5763 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
5764 However, the address space of 32-bit x86 processors is only 4
5765 @@ -1059,7 +1059,7 @@ config NOHIGHMEM
5766
5767 config HIGHMEM4G
5768 bool "4GB"
5769 - depends on !X86_NUMAQ
5770 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
5771 ---help---
5772 Select this if you have a 32-bit processor and between 1 and 4
5773 gigabytes of physical RAM.
5774 @@ -1113,7 +1113,7 @@ config PAGE_OFFSET
5775 hex
5776 default 0xB0000000 if VMSPLIT_3G_OPT
5777 default 0x80000000 if VMSPLIT_2G
5778 - default 0x78000000 if VMSPLIT_2G_OPT
5779 + default 0x70000000 if VMSPLIT_2G_OPT
5780 default 0x40000000 if VMSPLIT_1G
5781 default 0xC0000000
5782 depends on X86_32
5783 @@ -1496,6 +1496,7 @@ config SECCOMP
5784
5785 config CC_STACKPROTECTOR
5786 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
5787 + depends on X86_64 || !PAX_MEMORY_UDEREF
5788 ---help---
5789 This option turns on the -fstack-protector GCC feature. This
5790 feature puts, at the beginning of functions, a canary value on
5791 @@ -1553,6 +1554,7 @@ config KEXEC_JUMP
5792 config PHYSICAL_START
5793 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
5794 default "0x1000000"
5795 + range 0x400000 0x40000000
5796 ---help---
5797 This gives the physical address where the kernel is loaded.
5798
5799 @@ -1616,6 +1618,7 @@ config X86_NEED_RELOCS
5800 config PHYSICAL_ALIGN
5801 hex "Alignment value to which kernel should be aligned" if X86_32
5802 default "0x1000000"
5803 + range 0x400000 0x1000000 if PAX_KERNEXEC
5804 range 0x2000 0x1000000
5805 ---help---
5806 This value puts the alignment restrictions on physical address
5807 @@ -1647,9 +1650,10 @@ config HOTPLUG_CPU
5808 Say N if you want to disable CPU hotplug.
5809
5810 config COMPAT_VDSO
5811 - def_bool y
5812 + def_bool n
5813 prompt "Compat VDSO support"
5814 depends on X86_32 || IA32_EMULATION
5815 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
5816 ---help---
5817 Map the 32-bit VDSO to the predictable old-style address too.
5818
5819 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
5820 index e3ca7e0..b30b28a 100644
5821 --- a/arch/x86/Kconfig.cpu
5822 +++ b/arch/x86/Kconfig.cpu
5823 @@ -341,7 +341,7 @@ config X86_PPRO_FENCE
5824
5825 config X86_F00F_BUG
5826 def_bool y
5827 - depends on M586MMX || M586TSC || M586 || M486 || M386
5828 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
5829
5830 config X86_INVD_BUG
5831 def_bool y
5832 @@ -365,7 +365,7 @@ config X86_POPAD_OK
5833
5834 config X86_ALIGNMENT_16
5835 def_bool y
5836 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5837 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5838
5839 config X86_INTEL_USERCOPY
5840 def_bool y
5841 @@ -411,7 +411,7 @@ config X86_CMPXCHG64
5842 # generates cmov.
5843 config X86_CMOV
5844 def_bool y
5845 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
5846 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
5847
5848 config X86_MINIMUM_CPU_FAMILY
5849 int
5850 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
5851 index bf56e17..05f9891 100644
5852 --- a/arch/x86/Kconfig.debug
5853 +++ b/arch/x86/Kconfig.debug
5854 @@ -81,7 +81,7 @@ config X86_PTDUMP
5855 config DEBUG_RODATA
5856 bool "Write protect kernel read-only data structures"
5857 default y
5858 - depends on DEBUG_KERNEL
5859 + depends on DEBUG_KERNEL && BROKEN
5860 ---help---
5861 Mark the kernel read-only data as write-protected in the pagetables,
5862 in order to catch accidental (and incorrect) writes to such const
5863 @@ -99,7 +99,7 @@ config DEBUG_RODATA_TEST
5864
5865 config DEBUG_SET_MODULE_RONX
5866 bool "Set loadable kernel module data as NX and text as RO"
5867 - depends on MODULES
5868 + depends on MODULES && BROKEN
5869 ---help---
5870 This option helps catch unintended modifications to loadable
5871 kernel module's text and read-only data. It also prevents execution
5872 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
5873 index b02e509..2631e48 100644
5874 --- a/arch/x86/Makefile
5875 +++ b/arch/x86/Makefile
5876 @@ -46,6 +46,7 @@ else
5877 UTS_MACHINE := x86_64
5878 CHECKFLAGS += -D__x86_64__ -m64
5879
5880 + biarch := $(call cc-option,-m64)
5881 KBUILD_AFLAGS += -m64
5882 KBUILD_CFLAGS += -m64
5883
5884 @@ -195,3 +196,12 @@ define archhelp
5885 echo ' FDARGS="..." arguments for the booted kernel'
5886 echo ' FDINITRD=file initrd for the booted kernel'
5887 endef
5888 +
5889 +define OLD_LD
5890 +
5891 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
5892 +*** Please upgrade your binutils to 2.18 or newer
5893 +endef
5894 +
5895 +archprepare:
5896 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
5897 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
5898 index 95365a8..52f857b 100644
5899 --- a/arch/x86/boot/Makefile
5900 +++ b/arch/x86/boot/Makefile
5901 @@ -63,6 +63,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
5902 $(call cc-option, -fno-stack-protector) \
5903 $(call cc-option, -mpreferred-stack-boundary=2)
5904 KBUILD_CFLAGS += $(call cc-option, -m32)
5905 +ifdef CONSTIFY_PLUGIN
5906 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5907 +endif
5908 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5909 GCOV_PROFILE := n
5910
5911 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
5912 index 878e4b9..20537ab 100644
5913 --- a/arch/x86/boot/bitops.h
5914 +++ b/arch/x86/boot/bitops.h
5915 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
5916 u8 v;
5917 const u32 *p = (const u32 *)addr;
5918
5919 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5920 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5921 return v;
5922 }
5923
5924 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
5925
5926 static inline void set_bit(int nr, void *addr)
5927 {
5928 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5929 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5930 }
5931
5932 #endif /* BOOT_BITOPS_H */
5933 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
5934 index c7093bd..d4247ffe0 100644
5935 --- a/arch/x86/boot/boot.h
5936 +++ b/arch/x86/boot/boot.h
5937 @@ -85,7 +85,7 @@ static inline void io_delay(void)
5938 static inline u16 ds(void)
5939 {
5940 u16 seg;
5941 - asm("movw %%ds,%0" : "=rm" (seg));
5942 + asm volatile("movw %%ds,%0" : "=rm" (seg));
5943 return seg;
5944 }
5945
5946 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
5947 static inline int memcmp(const void *s1, const void *s2, size_t len)
5948 {
5949 u8 diff;
5950 - asm("repe; cmpsb; setnz %0"
5951 + asm volatile("repe; cmpsb; setnz %0"
5952 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
5953 return diff;
5954 }
5955 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
5956 index 09664ef..edc5d03 100644
5957 --- a/arch/x86/boot/compressed/Makefile
5958 +++ b/arch/x86/boot/compressed/Makefile
5959 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
5960 KBUILD_CFLAGS += $(cflags-y)
5961 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
5962 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
5963 +ifdef CONSTIFY_PLUGIN
5964 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
5965 +endif
5966
5967 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
5968 GCOV_PROFILE := n
5969 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
5970 index 67a655a..b924059 100644
5971 --- a/arch/x86/boot/compressed/head_32.S
5972 +++ b/arch/x86/boot/compressed/head_32.S
5973 @@ -76,7 +76,7 @@ ENTRY(startup_32)
5974 notl %eax
5975 andl %eax, %ebx
5976 #else
5977 - movl $LOAD_PHYSICAL_ADDR, %ebx
5978 + movl $____LOAD_PHYSICAL_ADDR, %ebx
5979 #endif
5980
5981 /* Target address to relocate to for decompression */
5982 @@ -162,7 +162,7 @@ relocated:
5983 * and where it was actually loaded.
5984 */
5985 movl %ebp, %ebx
5986 - subl $LOAD_PHYSICAL_ADDR, %ebx
5987 + subl $____LOAD_PHYSICAL_ADDR, %ebx
5988 jz 2f /* Nothing to be done if loaded at compiled addr. */
5989 /*
5990 * Process relocations.
5991 @@ -170,8 +170,7 @@ relocated:
5992
5993 1: subl $4, %edi
5994 movl (%edi), %ecx
5995 - testl %ecx, %ecx
5996 - jz 2f
5997 + jecxz 2f
5998 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
5999 jmp 1b
6000 2:
6001 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
6002 index 35af09d..99c9676 100644
6003 --- a/arch/x86/boot/compressed/head_64.S
6004 +++ b/arch/x86/boot/compressed/head_64.S
6005 @@ -91,7 +91,7 @@ ENTRY(startup_32)
6006 notl %eax
6007 andl %eax, %ebx
6008 #else
6009 - movl $LOAD_PHYSICAL_ADDR, %ebx
6010 + movl $____LOAD_PHYSICAL_ADDR, %ebx
6011 #endif
6012
6013 /* Target address to relocate to for decompression */
6014 @@ -233,7 +233,7 @@ ENTRY(startup_64)
6015 notq %rax
6016 andq %rax, %rbp
6017 #else
6018 - movq $LOAD_PHYSICAL_ADDR, %rbp
6019 + movq $____LOAD_PHYSICAL_ADDR, %rbp
6020 #endif
6021
6022 /* Target address to relocate to for decompression */
6023 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
6024 index 3a19d04..7c1d55a 100644
6025 --- a/arch/x86/boot/compressed/misc.c
6026 +++ b/arch/x86/boot/compressed/misc.c
6027 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
6028 case PT_LOAD:
6029 #ifdef CONFIG_RELOCATABLE
6030 dest = output;
6031 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
6032 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
6033 #else
6034 dest = (void *)(phdr->p_paddr);
6035 #endif
6036 @@ -363,7 +363,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
6037 error("Destination address too large");
6038 #endif
6039 #ifndef CONFIG_RELOCATABLE
6040 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
6041 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
6042 error("Wrong destination address");
6043 #endif
6044
6045 diff --git a/arch/x86/boot/compressed/relocs.c b/arch/x86/boot/compressed/relocs.c
6046 index 89bbf4e..869908e 100644
6047 --- a/arch/x86/boot/compressed/relocs.c
6048 +++ b/arch/x86/boot/compressed/relocs.c
6049 @@ -13,8 +13,11 @@
6050
6051 static void die(char *fmt, ...);
6052
6053 +#include "../../../../include/generated/autoconf.h"
6054 +
6055 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
6056 static Elf32_Ehdr ehdr;
6057 +static Elf32_Phdr *phdr;
6058 static unsigned long reloc_count, reloc_idx;
6059 static unsigned long *relocs;
6060
6061 @@ -270,9 +273,39 @@ static void read_ehdr(FILE *fp)
6062 }
6063 }
6064
6065 +static void read_phdrs(FILE *fp)
6066 +{
6067 + unsigned int i;
6068 +
6069 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
6070 + if (!phdr) {
6071 + die("Unable to allocate %d program headers\n",
6072 + ehdr.e_phnum);
6073 + }
6074 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
6075 + die("Seek to %d failed: %s\n",
6076 + ehdr.e_phoff, strerror(errno));
6077 + }
6078 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
6079 + die("Cannot read ELF program headers: %s\n",
6080 + strerror(errno));
6081 + }
6082 + for(i = 0; i < ehdr.e_phnum; i++) {
6083 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
6084 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
6085 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
6086 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
6087 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
6088 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
6089 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
6090 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
6091 + }
6092 +
6093 +}
6094 +
6095 static void read_shdrs(FILE *fp)
6096 {
6097 - int i;
6098 + unsigned int i;
6099 Elf32_Shdr shdr;
6100
6101 secs = calloc(ehdr.e_shnum, sizeof(struct section));
6102 @@ -307,7 +340,7 @@ static void read_shdrs(FILE *fp)
6103
6104 static void read_strtabs(FILE *fp)
6105 {
6106 - int i;
6107 + unsigned int i;
6108 for (i = 0; i < ehdr.e_shnum; i++) {
6109 struct section *sec = &secs[i];
6110 if (sec->shdr.sh_type != SHT_STRTAB) {
6111 @@ -332,7 +365,7 @@ static void read_strtabs(FILE *fp)
6112
6113 static void read_symtabs(FILE *fp)
6114 {
6115 - int i,j;
6116 + unsigned int i,j;
6117 for (i = 0; i < ehdr.e_shnum; i++) {
6118 struct section *sec = &secs[i];
6119 if (sec->shdr.sh_type != SHT_SYMTAB) {
6120 @@ -365,7 +398,9 @@ static void read_symtabs(FILE *fp)
6121
6122 static void read_relocs(FILE *fp)
6123 {
6124 - int i,j;
6125 + unsigned int i,j;
6126 + uint32_t base;
6127 +
6128 for (i = 0; i < ehdr.e_shnum; i++) {
6129 struct section *sec = &secs[i];
6130 if (sec->shdr.sh_type != SHT_REL) {
6131 @@ -385,9 +420,18 @@ static void read_relocs(FILE *fp)
6132 die("Cannot read symbol table: %s\n",
6133 strerror(errno));
6134 }
6135 + base = 0;
6136 + for (j = 0; j < ehdr.e_phnum; j++) {
6137 + if (phdr[j].p_type != PT_LOAD )
6138 + continue;
6139 + 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)
6140 + continue;
6141 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
6142 + break;
6143 + }
6144 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
6145 Elf32_Rel *rel = &sec->reltab[j];
6146 - rel->r_offset = elf32_to_cpu(rel->r_offset);
6147 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
6148 rel->r_info = elf32_to_cpu(rel->r_info);
6149 }
6150 }
6151 @@ -396,14 +440,14 @@ static void read_relocs(FILE *fp)
6152
6153 static void print_absolute_symbols(void)
6154 {
6155 - int i;
6156 + unsigned int i;
6157 printf("Absolute symbols\n");
6158 printf(" Num: Value Size Type Bind Visibility Name\n");
6159 for (i = 0; i < ehdr.e_shnum; i++) {
6160 struct section *sec = &secs[i];
6161 char *sym_strtab;
6162 Elf32_Sym *sh_symtab;
6163 - int j;
6164 + unsigned int j;
6165
6166 if (sec->shdr.sh_type != SHT_SYMTAB) {
6167 continue;
6168 @@ -431,14 +475,14 @@ static void print_absolute_symbols(void)
6169
6170 static void print_absolute_relocs(void)
6171 {
6172 - int i, printed = 0;
6173 + unsigned int i, printed = 0;
6174
6175 for (i = 0; i < ehdr.e_shnum; i++) {
6176 struct section *sec = &secs[i];
6177 struct section *sec_applies, *sec_symtab;
6178 char *sym_strtab;
6179 Elf32_Sym *sh_symtab;
6180 - int j;
6181 + unsigned int j;
6182 if (sec->shdr.sh_type != SHT_REL) {
6183 continue;
6184 }
6185 @@ -499,13 +543,13 @@ static void print_absolute_relocs(void)
6186
6187 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6188 {
6189 - int i;
6190 + unsigned int i;
6191 /* Walk through the relocations */
6192 for (i = 0; i < ehdr.e_shnum; i++) {
6193 char *sym_strtab;
6194 Elf32_Sym *sh_symtab;
6195 struct section *sec_applies, *sec_symtab;
6196 - int j;
6197 + unsigned int j;
6198 struct section *sec = &secs[i];
6199
6200 if (sec->shdr.sh_type != SHT_REL) {
6201 @@ -530,6 +574,22 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym))
6202 !is_rel_reloc(sym_name(sym_strtab, sym))) {
6203 continue;
6204 }
6205 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
6206 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
6207 + continue;
6208 +
6209 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
6210 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
6211 + if (!strcmp(sec_name(sym->st_shndx), ".module.text") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
6212 + continue;
6213 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
6214 + continue;
6215 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
6216 + continue;
6217 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
6218 + continue;
6219 +#endif
6220 +
6221 switch (r_type) {
6222 case R_386_NONE:
6223 case R_386_PC32:
6224 @@ -571,7 +631,7 @@ static int cmp_relocs(const void *va, const void *vb)
6225
6226 static void emit_relocs(int as_text)
6227 {
6228 - int i;
6229 + unsigned int i;
6230 /* Count how many relocations I have and allocate space for them. */
6231 reloc_count = 0;
6232 walk_relocs(count_reloc);
6233 @@ -665,6 +725,7 @@ int main(int argc, char **argv)
6234 fname, strerror(errno));
6235 }
6236 read_ehdr(fp);
6237 + read_phdrs(fp);
6238 read_shdrs(fp);
6239 read_strtabs(fp);
6240 read_symtabs(fp);
6241 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
6242 index 4d3ff03..e4972ff 100644
6243 --- a/arch/x86/boot/cpucheck.c
6244 +++ b/arch/x86/boot/cpucheck.c
6245 @@ -74,7 +74,7 @@ static int has_fpu(void)
6246 u16 fcw = -1, fsw = -1;
6247 u32 cr0;
6248
6249 - asm("movl %%cr0,%0" : "=r" (cr0));
6250 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
6251 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
6252 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
6253 asm volatile("movl %0,%%cr0" : : "r" (cr0));
6254 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
6255 {
6256 u32 f0, f1;
6257
6258 - asm("pushfl ; "
6259 + asm volatile("pushfl ; "
6260 "pushfl ; "
6261 "popl %0 ; "
6262 "movl %0,%1 ; "
6263 @@ -115,7 +115,7 @@ static void get_flags(void)
6264 set_bit(X86_FEATURE_FPU, cpu.flags);
6265
6266 if (has_eflag(X86_EFLAGS_ID)) {
6267 - asm("cpuid"
6268 + asm volatile("cpuid"
6269 : "=a" (max_intel_level),
6270 "=b" (cpu_vendor[0]),
6271 "=d" (cpu_vendor[1]),
6272 @@ -124,7 +124,7 @@ static void get_flags(void)
6273
6274 if (max_intel_level >= 0x00000001 &&
6275 max_intel_level <= 0x0000ffff) {
6276 - asm("cpuid"
6277 + asm volatile("cpuid"
6278 : "=a" (tfms),
6279 "=c" (cpu.flags[4]),
6280 "=d" (cpu.flags[0])
6281 @@ -136,7 +136,7 @@ static void get_flags(void)
6282 cpu.model += ((tfms >> 16) & 0xf) << 4;
6283 }
6284
6285 - asm("cpuid"
6286 + asm volatile("cpuid"
6287 : "=a" (max_amd_level)
6288 : "a" (0x80000000)
6289 : "ebx", "ecx", "edx");
6290 @@ -144,7 +144,7 @@ static void get_flags(void)
6291 if (max_amd_level >= 0x80000001 &&
6292 max_amd_level <= 0x8000ffff) {
6293 u32 eax = 0x80000001;
6294 - asm("cpuid"
6295 + asm volatile("cpuid"
6296 : "+a" (eax),
6297 "=c" (cpu.flags[6]),
6298 "=d" (cpu.flags[1])
6299 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6300 u32 ecx = MSR_K7_HWCR;
6301 u32 eax, edx;
6302
6303 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6304 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6305 eax &= ~(1 << 15);
6306 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6307 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6308
6309 get_flags(); /* Make sure it really did something */
6310 err = check_flags();
6311 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6312 u32 ecx = MSR_VIA_FCR;
6313 u32 eax, edx;
6314
6315 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6316 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6317 eax |= (1<<1)|(1<<7);
6318 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6319 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6320
6321 set_bit(X86_FEATURE_CX8, cpu.flags);
6322 err = check_flags();
6323 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
6324 u32 eax, edx;
6325 u32 level = 1;
6326
6327 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6328 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6329 - asm("cpuid"
6330 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
6331 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
6332 + asm volatile("cpuid"
6333 : "+a" (level), "=d" (cpu.flags[0])
6334 : : "ecx", "ebx");
6335 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6336 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
6337
6338 err = check_flags();
6339 }
6340 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
6341 index bdb4d45..0476680 100644
6342 --- a/arch/x86/boot/header.S
6343 +++ b/arch/x86/boot/header.S
6344 @@ -224,7 +224,7 @@ setup_data: .quad 0 # 64-bit physical pointer to
6345 # single linked list of
6346 # struct setup_data
6347
6348 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
6349 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
6350
6351 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
6352 #define VO_INIT_SIZE (VO__end - VO__text)
6353 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
6354 index db75d07..8e6d0af 100644
6355 --- a/arch/x86/boot/memory.c
6356 +++ b/arch/x86/boot/memory.c
6357 @@ -19,7 +19,7 @@
6358
6359 static int detect_memory_e820(void)
6360 {
6361 - int count = 0;
6362 + unsigned int count = 0;
6363 struct biosregs ireg, oreg;
6364 struct e820entry *desc = boot_params.e820_map;
6365 static struct e820entry buf; /* static so it is zeroed */
6366 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
6367 index 11e8c6e..fdbb1ed 100644
6368 --- a/arch/x86/boot/video-vesa.c
6369 +++ b/arch/x86/boot/video-vesa.c
6370 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
6371
6372 boot_params.screen_info.vesapm_seg = oreg.es;
6373 boot_params.screen_info.vesapm_off = oreg.di;
6374 + boot_params.screen_info.vesapm_size = oreg.cx;
6375 }
6376
6377 /*
6378 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
6379 index 43eda28..5ab5fdb 100644
6380 --- a/arch/x86/boot/video.c
6381 +++ b/arch/x86/boot/video.c
6382 @@ -96,7 +96,7 @@ static void store_mode_params(void)
6383 static unsigned int get_entry(void)
6384 {
6385 char entry_buf[4];
6386 - int i, len = 0;
6387 + unsigned int i, len = 0;
6388 int key;
6389 unsigned int v;
6390
6391 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
6392 index 5b577d5..3c1fed4 100644
6393 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
6394 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
6395 @@ -8,6 +8,8 @@
6396 * including this sentence is retained in full.
6397 */
6398
6399 +#include <asm/alternative-asm.h>
6400 +
6401 .extern crypto_ft_tab
6402 .extern crypto_it_tab
6403 .extern crypto_fl_tab
6404 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
6405 je B192; \
6406 leaq 32(r9),r9;
6407
6408 +#define ret pax_force_retaddr 0, 1; ret
6409 +
6410 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
6411 movq r1,r2; \
6412 movq r3,r4; \
6413 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
6414 index be6d9e3..21fbbca 100644
6415 --- a/arch/x86/crypto/aesni-intel_asm.S
6416 +++ b/arch/x86/crypto/aesni-intel_asm.S
6417 @@ -31,6 +31,7 @@
6418
6419 #include <linux/linkage.h>
6420 #include <asm/inst.h>
6421 +#include <asm/alternative-asm.h>
6422
6423 #ifdef __x86_64__
6424 .data
6425 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
6426 pop %r14
6427 pop %r13
6428 pop %r12
6429 + pax_force_retaddr 0, 1
6430 ret
6431 +ENDPROC(aesni_gcm_dec)
6432
6433
6434 /*****************************************************************************
6435 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
6436 pop %r14
6437 pop %r13
6438 pop %r12
6439 + pax_force_retaddr 0, 1
6440 ret
6441 +ENDPROC(aesni_gcm_enc)
6442
6443 #endif
6444
6445 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
6446 pxor %xmm1, %xmm0
6447 movaps %xmm0, (TKEYP)
6448 add $0x10, TKEYP
6449 + pax_force_retaddr_bts
6450 ret
6451
6452 .align 4
6453 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
6454 shufps $0b01001110, %xmm2, %xmm1
6455 movaps %xmm1, 0x10(TKEYP)
6456 add $0x20, TKEYP
6457 + pax_force_retaddr_bts
6458 ret
6459
6460 .align 4
6461 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
6462
6463 movaps %xmm0, (TKEYP)
6464 add $0x10, TKEYP
6465 + pax_force_retaddr_bts
6466 ret
6467
6468 .align 4
6469 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
6470 pxor %xmm1, %xmm2
6471 movaps %xmm2, (TKEYP)
6472 add $0x10, TKEYP
6473 + pax_force_retaddr_bts
6474 ret
6475
6476 /*
6477 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
6478 #ifndef __x86_64__
6479 popl KEYP
6480 #endif
6481 + pax_force_retaddr 0, 1
6482 ret
6483 +ENDPROC(aesni_set_key)
6484
6485 /*
6486 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
6487 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
6488 popl KLEN
6489 popl KEYP
6490 #endif
6491 + pax_force_retaddr 0, 1
6492 ret
6493 +ENDPROC(aesni_enc)
6494
6495 /*
6496 * _aesni_enc1: internal ABI
6497 @@ -1959,6 +1972,7 @@ _aesni_enc1:
6498 AESENC KEY STATE
6499 movaps 0x70(TKEYP), KEY
6500 AESENCLAST KEY STATE
6501 + pax_force_retaddr_bts
6502 ret
6503
6504 /*
6505 @@ -2067,6 +2081,7 @@ _aesni_enc4:
6506 AESENCLAST KEY STATE2
6507 AESENCLAST KEY STATE3
6508 AESENCLAST KEY STATE4
6509 + pax_force_retaddr_bts
6510 ret
6511
6512 /*
6513 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
6514 popl KLEN
6515 popl KEYP
6516 #endif
6517 + pax_force_retaddr 0, 1
6518 ret
6519 +ENDPROC(aesni_dec)
6520
6521 /*
6522 * _aesni_dec1: internal ABI
6523 @@ -2146,6 +2163,7 @@ _aesni_dec1:
6524 AESDEC KEY STATE
6525 movaps 0x70(TKEYP), KEY
6526 AESDECLAST KEY STATE
6527 + pax_force_retaddr_bts
6528 ret
6529
6530 /*
6531 @@ -2254,6 +2272,7 @@ _aesni_dec4:
6532 AESDECLAST KEY STATE2
6533 AESDECLAST KEY STATE3
6534 AESDECLAST KEY STATE4
6535 + pax_force_retaddr_bts
6536 ret
6537
6538 /*
6539 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
6540 popl KEYP
6541 popl LEN
6542 #endif
6543 + pax_force_retaddr 0, 1
6544 ret
6545 +ENDPROC(aesni_ecb_enc)
6546
6547 /*
6548 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6549 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
6550 popl KEYP
6551 popl LEN
6552 #endif
6553 + pax_force_retaddr 0, 1
6554 ret
6555 +ENDPROC(aesni_ecb_dec)
6556
6557 /*
6558 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6559 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
6560 popl LEN
6561 popl IVP
6562 #endif
6563 + pax_force_retaddr 0, 1
6564 ret
6565 +ENDPROC(aesni_cbc_enc)
6566
6567 /*
6568 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
6569 @@ -2498,7 +2523,9 @@ ENTRY(aesni_cbc_dec)
6570 popl LEN
6571 popl IVP
6572 #endif
6573 + pax_force_retaddr 0, 1
6574 ret
6575 +ENDPROC(aesni_cbc_dec)
6576
6577 #ifdef __x86_64__
6578 .align 16
6579 @@ -2524,6 +2551,7 @@ _aesni_inc_init:
6580 mov $1, TCTR_LOW
6581 MOVQ_R64_XMM TCTR_LOW INC
6582 MOVQ_R64_XMM CTR TCTR_LOW
6583 + pax_force_retaddr_bts
6584 ret
6585
6586 /*
6587 @@ -2552,6 +2580,7 @@ _aesni_inc:
6588 .Linc_low:
6589 movaps CTR, IV
6590 PSHUFB_XMM BSWAP_MASK IV
6591 + pax_force_retaddr_bts
6592 ret
6593
6594 /*
6595 @@ -2612,5 +2641,7 @@ ENTRY(aesni_ctr_enc)
6596 .Lctr_enc_ret:
6597 movups IV, (IVP)
6598 .Lctr_enc_just_ret:
6599 + pax_force_retaddr 0, 1
6600 ret
6601 +ENDPROC(aesni_ctr_enc)
6602 #endif
6603 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
6604 index 391d245..67f35c2 100644
6605 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
6606 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
6607 @@ -20,6 +20,8 @@
6608 *
6609 */
6610
6611 +#include <asm/alternative-asm.h>
6612 +
6613 .file "blowfish-x86_64-asm.S"
6614 .text
6615
6616 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
6617 jnz __enc_xor;
6618
6619 write_block();
6620 + pax_force_retaddr 0, 1
6621 ret;
6622 __enc_xor:
6623 xor_block();
6624 + pax_force_retaddr 0, 1
6625 ret;
6626
6627 .align 8
6628 @@ -188,6 +192,7 @@ blowfish_dec_blk:
6629
6630 movq %r11, %rbp;
6631
6632 + pax_force_retaddr 0, 1
6633 ret;
6634
6635 /**********************************************************************
6636 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
6637
6638 popq %rbx;
6639 popq %rbp;
6640 + pax_force_retaddr 0, 1
6641 ret;
6642
6643 __enc_xor4:
6644 @@ -349,6 +355,7 @@ __enc_xor4:
6645
6646 popq %rbx;
6647 popq %rbp;
6648 + pax_force_retaddr 0, 1
6649 ret;
6650
6651 .align 8
6652 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
6653 popq %rbx;
6654 popq %rbp;
6655
6656 + pax_force_retaddr 0, 1
6657 ret;
6658
6659 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
6660 index 6214a9b..1f4fc9a 100644
6661 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
6662 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
6663 @@ -1,3 +1,5 @@
6664 +#include <asm/alternative-asm.h>
6665 +
6666 # enter ECRYPT_encrypt_bytes
6667 .text
6668 .p2align 5
6669 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
6670 add %r11,%rsp
6671 mov %rdi,%rax
6672 mov %rsi,%rdx
6673 + pax_force_retaddr 0, 1
6674 ret
6675 # bytesatleast65:
6676 ._bytesatleast65:
6677 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
6678 add %r11,%rsp
6679 mov %rdi,%rax
6680 mov %rsi,%rdx
6681 + pax_force_retaddr
6682 ret
6683 # enter ECRYPT_ivsetup
6684 .text
6685 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
6686 add %r11,%rsp
6687 mov %rdi,%rax
6688 mov %rsi,%rdx
6689 + pax_force_retaddr
6690 ret
6691 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
6692 index b2c2f57..8470cab 100644
6693 --- a/arch/x86/crypto/sha1_ssse3_asm.S
6694 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
6695 @@ -28,6 +28,8 @@
6696 * (at your option) any later version.
6697 */
6698
6699 +#include <asm/alternative-asm.h>
6700 +
6701 #define CTX %rdi // arg1
6702 #define BUF %rsi // arg2
6703 #define CNT %rdx // arg3
6704 @@ -104,6 +106,7 @@
6705 pop %r12
6706 pop %rbp
6707 pop %rbx
6708 + pax_force_retaddr 0, 1
6709 ret
6710
6711 .size \name, .-\name
6712 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6713 index 5b012a2..36d5364 100644
6714 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6715 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
6716 @@ -20,6 +20,8 @@
6717 *
6718 */
6719
6720 +#include <asm/alternative-asm.h>
6721 +
6722 .file "twofish-x86_64-asm-3way.S"
6723 .text
6724
6725 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
6726 popq %r13;
6727 popq %r14;
6728 popq %r15;
6729 + pax_force_retaddr 0, 1
6730 ret;
6731
6732 __enc_xor3:
6733 @@ -271,6 +274,7 @@ __enc_xor3:
6734 popq %r13;
6735 popq %r14;
6736 popq %r15;
6737 + pax_force_retaddr 0, 1
6738 ret;
6739
6740 .global twofish_dec_blk_3way
6741 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
6742 popq %r13;
6743 popq %r14;
6744 popq %r15;
6745 + pax_force_retaddr 0, 1
6746 ret;
6747
6748 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
6749 index 7bcf3fc..f53832f 100644
6750 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
6751 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
6752 @@ -21,6 +21,7 @@
6753 .text
6754
6755 #include <asm/asm-offsets.h>
6756 +#include <asm/alternative-asm.h>
6757
6758 #define a_offset 0
6759 #define b_offset 4
6760 @@ -268,6 +269,7 @@ twofish_enc_blk:
6761
6762 popq R1
6763 movq $1,%rax
6764 + pax_force_retaddr 0, 1
6765 ret
6766
6767 twofish_dec_blk:
6768 @@ -319,4 +321,5 @@ twofish_dec_blk:
6769
6770 popq R1
6771 movq $1,%rax
6772 + pax_force_retaddr 0, 1
6773 ret
6774 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
6775 index fd84387..0b4af7d 100644
6776 --- a/arch/x86/ia32/ia32_aout.c
6777 +++ b/arch/x86/ia32/ia32_aout.c
6778 @@ -162,6 +162,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
6779 unsigned long dump_start, dump_size;
6780 struct user32 dump;
6781
6782 + memset(&dump, 0, sizeof(dump));
6783 +
6784 fs = get_fs();
6785 set_fs(KERNEL_DS);
6786 has_dumped = 1;
6787 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
6788 index 6557769..ef6ae89 100644
6789 --- a/arch/x86/ia32/ia32_signal.c
6790 +++ b/arch/x86/ia32/ia32_signal.c
6791 @@ -169,7 +169,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
6792 }
6793 seg = get_fs();
6794 set_fs(KERNEL_DS);
6795 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
6796 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
6797 set_fs(seg);
6798 if (ret >= 0 && uoss_ptr) {
6799 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
6800 @@ -370,7 +370,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
6801 */
6802 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6803 size_t frame_size,
6804 - void **fpstate)
6805 + void __user **fpstate)
6806 {
6807 unsigned long sp;
6808
6809 @@ -391,7 +391,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6810
6811 if (used_math()) {
6812 sp = sp - sig_xstate_ia32_size;
6813 - *fpstate = (struct _fpstate_ia32 *) sp;
6814 + *fpstate = (struct _fpstate_ia32 __user *) sp;
6815 if (save_i387_xstate_ia32(*fpstate) < 0)
6816 return (void __user *) -1L;
6817 }
6818 @@ -399,7 +399,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
6819 sp -= frame_size;
6820 /* Align the stack pointer according to the i386 ABI,
6821 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
6822 - sp = ((sp + 4) & -16ul) - 4;
6823 + sp = ((sp - 12) & -16ul) - 4;
6824 return (void __user *) sp;
6825 }
6826
6827 @@ -457,7 +457,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
6828 * These are actually not used anymore, but left because some
6829 * gdb versions depend on them as a marker.
6830 */
6831 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6832 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
6833 } put_user_catch(err);
6834
6835 if (err)
6836 @@ -499,7 +499,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
6837 0xb8,
6838 __NR_ia32_rt_sigreturn,
6839 0x80cd,
6840 - 0,
6841 + 0
6842 };
6843
6844 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
6845 @@ -529,16 +529,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
6846
6847 if (ka->sa.sa_flags & SA_RESTORER)
6848 restorer = ka->sa.sa_restorer;
6849 + else if (current->mm->context.vdso)
6850 + /* Return stub is in 32bit vsyscall page */
6851 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
6852 else
6853 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
6854 - rt_sigreturn);
6855 + restorer = &frame->retcode;
6856 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
6857
6858 /*
6859 * Not actually used anymore, but left because some gdb
6860 * versions need it.
6861 */
6862 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
6863 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
6864 } put_user_catch(err);
6865
6866 if (err)
6867 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
6868 index a6253ec..4ad2120 100644
6869 --- a/arch/x86/ia32/ia32entry.S
6870 +++ b/arch/x86/ia32/ia32entry.S
6871 @@ -13,7 +13,9 @@
6872 #include <asm/thread_info.h>
6873 #include <asm/segment.h>
6874 #include <asm/irqflags.h>
6875 +#include <asm/pgtable.h>
6876 #include <linux/linkage.h>
6877 +#include <asm/alternative-asm.h>
6878
6879 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
6880 #include <linux/elf-em.h>
6881 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
6882 ENDPROC(native_irq_enable_sysexit)
6883 #endif
6884
6885 + .macro pax_enter_kernel_user
6886 + pax_set_fptr_mask
6887 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6888 + call pax_enter_kernel_user
6889 +#endif
6890 + .endm
6891 +
6892 + .macro pax_exit_kernel_user
6893 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6894 + call pax_exit_kernel_user
6895 +#endif
6896 +#ifdef CONFIG_PAX_RANDKSTACK
6897 + pushq %rax
6898 + pushq %r11
6899 + call pax_randomize_kstack
6900 + popq %r11
6901 + popq %rax
6902 +#endif
6903 + .endm
6904 +
6905 +.macro pax_erase_kstack
6906 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
6907 + call pax_erase_kstack
6908 +#endif
6909 +.endm
6910 +
6911 /*
6912 * 32bit SYSENTER instruction entry.
6913 *
6914 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
6915 CFI_REGISTER rsp,rbp
6916 SWAPGS_UNSAFE_STACK
6917 movq PER_CPU_VAR(kernel_stack), %rsp
6918 - addq $(KERNEL_STACK_OFFSET),%rsp
6919 - /*
6920 - * No need to follow this irqs on/off section: the syscall
6921 - * disabled irqs, here we enable it straight after entry:
6922 - */
6923 - ENABLE_INTERRUPTS(CLBR_NONE)
6924 movl %ebp,%ebp /* zero extension */
6925 pushq_cfi $__USER32_DS
6926 /*CFI_REL_OFFSET ss,0*/
6927 @@ -134,25 +156,39 @@ ENTRY(ia32_sysenter_target)
6928 CFI_REL_OFFSET rsp,0
6929 pushfq_cfi
6930 /*CFI_REL_OFFSET rflags,0*/
6931 - movl 8*3-THREAD_SIZE+TI_sysenter_return(%rsp), %r10d
6932 - CFI_REGISTER rip,r10
6933 + orl $X86_EFLAGS_IF,(%rsp)
6934 + GET_THREAD_INFO(%r11)
6935 + movl TI_sysenter_return(%r11), %r11d
6936 + CFI_REGISTER rip,r11
6937 pushq_cfi $__USER32_CS
6938 /*CFI_REL_OFFSET cs,0*/
6939 movl %eax, %eax
6940 - pushq_cfi %r10
6941 + pushq_cfi %r11
6942 CFI_REL_OFFSET rip,0
6943 pushq_cfi %rax
6944 cld
6945 SAVE_ARGS 0,1,0
6946 + pax_enter_kernel_user
6947 + /*
6948 + * No need to follow this irqs on/off section: the syscall
6949 + * disabled irqs, here we enable it straight after entry:
6950 + */
6951 + ENABLE_INTERRUPTS(CLBR_NONE)
6952 /* no need to do an access_ok check here because rbp has been
6953 32bit zero extended */
6954 +
6955 +#ifdef CONFIG_PAX_MEMORY_UDEREF
6956 + mov $PAX_USER_SHADOW_BASE,%r11
6957 + add %r11,%rbp
6958 +#endif
6959 +
6960 1: movl (%rbp),%ebp
6961 .section __ex_table,"a"
6962 .quad 1b,ia32_badarg
6963 .previous
6964 - GET_THREAD_INFO(%r10)
6965 - orl $TS_COMPAT,TI_status(%r10)
6966 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
6967 + GET_THREAD_INFO(%r11)
6968 + orl $TS_COMPAT,TI_status(%r11)
6969 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
6970 CFI_REMEMBER_STATE
6971 jnz sysenter_tracesys
6972 cmpq $(IA32_NR_syscalls-1),%rax
6973 @@ -162,13 +198,15 @@ sysenter_do_call:
6974 sysenter_dispatch:
6975 call *ia32_sys_call_table(,%rax,8)
6976 movq %rax,RAX-ARGOFFSET(%rsp)
6977 - GET_THREAD_INFO(%r10)
6978 + GET_THREAD_INFO(%r11)
6979 DISABLE_INTERRUPTS(CLBR_NONE)
6980 TRACE_IRQS_OFF
6981 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
6982 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
6983 jnz sysexit_audit
6984 sysexit_from_sys_call:
6985 - andl $~TS_COMPAT,TI_status(%r10)
6986 + pax_exit_kernel_user
6987 + pax_erase_kstack
6988 + andl $~TS_COMPAT,TI_status(%r11)
6989 /* clear IF, that popfq doesn't enable interrupts early */
6990 andl $~0x200,EFLAGS-R11(%rsp)
6991 movl RIP-R11(%rsp),%edx /* User %eip */
6992 @@ -194,6 +232,9 @@ sysexit_from_sys_call:
6993 movl %eax,%esi /* 2nd arg: syscall number */
6994 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
6995 call audit_syscall_entry
6996 +
6997 + pax_erase_kstack
6998 +
6999 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
7000 cmpq $(IA32_NR_syscalls-1),%rax
7001 ja ia32_badsys
7002 @@ -205,7 +246,7 @@ sysexit_from_sys_call:
7003 .endm
7004
7005 .macro auditsys_exit exit
7006 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7007 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7008 jnz ia32_ret_from_sys_call
7009 TRACE_IRQS_ON
7010 sti
7011 @@ -215,12 +256,12 @@ sysexit_from_sys_call:
7012 movzbl %al,%edi /* zero-extend that into %edi */
7013 inc %edi /* first arg, 0->1(AUDITSC_SUCCESS), 1->2(AUDITSC_FAILURE) */
7014 call audit_syscall_exit
7015 - GET_THREAD_INFO(%r10)
7016 + GET_THREAD_INFO(%r11)
7017 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall return value */
7018 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
7019 cli
7020 TRACE_IRQS_OFF
7021 - testl %edi,TI_flags(%r10)
7022 + testl %edi,TI_flags(%r11)
7023 jz \exit
7024 CLEAR_RREGS -ARGOFFSET
7025 jmp int_with_check
7026 @@ -238,7 +279,7 @@ sysexit_audit:
7027
7028 sysenter_tracesys:
7029 #ifdef CONFIG_AUDITSYSCALL
7030 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7031 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7032 jz sysenter_auditsys
7033 #endif
7034 SAVE_REST
7035 @@ -246,6 +287,9 @@ sysenter_tracesys:
7036 movq $-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
7037 movq %rsp,%rdi /* &pt_regs -> arg1 */
7038 call syscall_trace_enter
7039 +
7040 + pax_erase_kstack
7041 +
7042 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
7043 RESTORE_REST
7044 cmpq $(IA32_NR_syscalls-1),%rax
7045 @@ -277,19 +321,20 @@ ENDPROC(ia32_sysenter_target)
7046 ENTRY(ia32_cstar_target)
7047 CFI_STARTPROC32 simple
7048 CFI_SIGNAL_FRAME
7049 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
7050 + CFI_DEF_CFA rsp,0
7051 CFI_REGISTER rip,rcx
7052 /*CFI_REGISTER rflags,r11*/
7053 SWAPGS_UNSAFE_STACK
7054 movl %esp,%r8d
7055 CFI_REGISTER rsp,r8
7056 movq PER_CPU_VAR(kernel_stack),%rsp
7057 + SAVE_ARGS 8*6,0,0
7058 + pax_enter_kernel_user
7059 /*
7060 * No need to follow this irqs on/off section: the syscall
7061 * disabled irqs and here we enable it straight after entry:
7062 */
7063 ENABLE_INTERRUPTS(CLBR_NONE)
7064 - SAVE_ARGS 8,0,0
7065 movl %eax,%eax /* zero extension */
7066 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
7067 movq %rcx,RIP-ARGOFFSET(%rsp)
7068 @@ -305,13 +350,19 @@ ENTRY(ia32_cstar_target)
7069 /* no need to do an access_ok check here because r8 has been
7070 32bit zero extended */
7071 /* hardware stack frame is complete now */
7072 +
7073 +#ifdef CONFIG_PAX_MEMORY_UDEREF
7074 + mov $PAX_USER_SHADOW_BASE,%r11
7075 + add %r11,%r8
7076 +#endif
7077 +
7078 1: movl (%r8),%r9d
7079 .section __ex_table,"a"
7080 .quad 1b,ia32_badarg
7081 .previous
7082 - GET_THREAD_INFO(%r10)
7083 - orl $TS_COMPAT,TI_status(%r10)
7084 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
7085 + GET_THREAD_INFO(%r11)
7086 + orl $TS_COMPAT,TI_status(%r11)
7087 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
7088 CFI_REMEMBER_STATE
7089 jnz cstar_tracesys
7090 cmpq $IA32_NR_syscalls-1,%rax
7091 @@ -321,13 +372,15 @@ cstar_do_call:
7092 cstar_dispatch:
7093 call *ia32_sys_call_table(,%rax,8)
7094 movq %rax,RAX-ARGOFFSET(%rsp)
7095 - GET_THREAD_INFO(%r10)
7096 + GET_THREAD_INFO(%r11)
7097 DISABLE_INTERRUPTS(CLBR_NONE)
7098 TRACE_IRQS_OFF
7099 - testl $_TIF_ALLWORK_MASK,TI_flags(%r10)
7100 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
7101 jnz sysretl_audit
7102 sysretl_from_sys_call:
7103 - andl $~TS_COMPAT,TI_status(%r10)
7104 + pax_exit_kernel_user
7105 + pax_erase_kstack
7106 + andl $~TS_COMPAT,TI_status(%r11)
7107 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
7108 movl RIP-ARGOFFSET(%rsp),%ecx
7109 CFI_REGISTER rip,rcx
7110 @@ -355,7 +408,7 @@ sysretl_audit:
7111
7112 cstar_tracesys:
7113 #ifdef CONFIG_AUDITSYSCALL
7114 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
7115 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
7116 jz cstar_auditsys
7117 #endif
7118 xchgl %r9d,%ebp
7119 @@ -364,6 +417,9 @@ cstar_tracesys:
7120 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
7121 movq %rsp,%rdi /* &pt_regs -> arg1 */
7122 call syscall_trace_enter
7123 +
7124 + pax_erase_kstack
7125 +
7126 LOAD_ARGS32 ARGOFFSET, 1 /* reload args from stack in case ptrace changed it */
7127 RESTORE_REST
7128 xchgl %ebp,%r9d
7129 @@ -409,20 +465,21 @@ ENTRY(ia32_syscall)
7130 CFI_REL_OFFSET rip,RIP-RIP
7131 PARAVIRT_ADJUST_EXCEPTION_FRAME
7132 SWAPGS
7133 - /*
7134 - * No need to follow this irqs on/off section: the syscall
7135 - * disabled irqs and here we enable it straight after entry:
7136 - */
7137 - ENABLE_INTERRUPTS(CLBR_NONE)
7138 movl %eax,%eax
7139 pushq_cfi %rax
7140 cld
7141 /* note the registers are not zero extended to the sf.
7142 this could be a problem. */
7143 SAVE_ARGS 0,1,0
7144 - GET_THREAD_INFO(%r10)
7145 - orl $TS_COMPAT,TI_status(%r10)
7146 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
7147 + pax_enter_kernel_user
7148 + /*
7149 + * No need to follow this irqs on/off section: the syscall
7150 + * disabled irqs and here we enable it straight after entry:
7151 + */
7152 + ENABLE_INTERRUPTS(CLBR_NONE)
7153 + GET_THREAD_INFO(%r11)
7154 + orl $TS_COMPAT,TI_status(%r11)
7155 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
7156 jnz ia32_tracesys
7157 cmpq $(IA32_NR_syscalls-1),%rax
7158 ja ia32_badsys
7159 @@ -441,6 +498,9 @@ ia32_tracesys:
7160 movq $-ENOSYS,RAX(%rsp) /* ptrace can change this for a bad syscall */
7161 movq %rsp,%rdi /* &pt_regs -> arg1 */
7162 call syscall_trace_enter
7163 +
7164 + pax_erase_kstack
7165 +
7166 LOAD_ARGS32 ARGOFFSET /* reload args from stack in case ptrace changed it */
7167 RESTORE_REST
7168 cmpq $(IA32_NR_syscalls-1),%rax
7169 @@ -455,6 +515,7 @@ ia32_badsys:
7170
7171 quiet_ni_syscall:
7172 movq $-ENOSYS,%rax
7173 + pax_force_retaddr
7174 ret
7175 CFI_ENDPROC
7176
7177 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
7178 index f6f5c53..b358b28 100644
7179 --- a/arch/x86/ia32/sys_ia32.c
7180 +++ b/arch/x86/ia32/sys_ia32.c
7181 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
7182 */
7183 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
7184 {
7185 - typeof(ubuf->st_uid) uid = 0;
7186 - typeof(ubuf->st_gid) gid = 0;
7187 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
7188 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
7189 SET_UID(uid, stat->uid);
7190 SET_GID(gid, stat->gid);
7191 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
7192 @@ -308,8 +308,8 @@ asmlinkage long sys32_rt_sigprocmask(int how, compat_sigset_t __user *set,
7193 }
7194 set_fs(KERNEL_DS);
7195 ret = sys_rt_sigprocmask(how,
7196 - set ? (sigset_t __user *)&s : NULL,
7197 - oset ? (sigset_t __user *)&s : NULL,
7198 + set ? (sigset_t __force_user *)&s : NULL,
7199 + oset ? (sigset_t __force_user *)&s : NULL,
7200 sigsetsize);
7201 set_fs(old_fs);
7202 if (ret)
7203 @@ -332,7 +332,7 @@ asmlinkage long sys32_alarm(unsigned int seconds)
7204 return alarm_setitimer(seconds);
7205 }
7206
7207 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
7208 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
7209 int options)
7210 {
7211 return compat_sys_wait4(pid, stat_addr, options, NULL);
7212 @@ -353,7 +353,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
7213 mm_segment_t old_fs = get_fs();
7214
7215 set_fs(KERNEL_DS);
7216 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
7217 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
7218 set_fs(old_fs);
7219 if (put_compat_timespec(&t, interval))
7220 return -EFAULT;
7221 @@ -369,7 +369,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
7222 mm_segment_t old_fs = get_fs();
7223
7224 set_fs(KERNEL_DS);
7225 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
7226 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
7227 set_fs(old_fs);
7228 if (!ret) {
7229 switch (_NSIG_WORDS) {
7230 @@ -394,7 +394,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
7231 if (copy_siginfo_from_user32(&info, uinfo))
7232 return -EFAULT;
7233 set_fs(KERNEL_DS);
7234 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
7235 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
7236 set_fs(old_fs);
7237 return ret;
7238 }
7239 @@ -439,7 +439,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
7240 return -EFAULT;
7241
7242 set_fs(KERNEL_DS);
7243 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
7244 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
7245 count);
7246 set_fs(old_fs);
7247
7248 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
7249 index 091508b..e245ff2 100644
7250 --- a/arch/x86/include/asm/alternative-asm.h
7251 +++ b/arch/x86/include/asm/alternative-asm.h
7252 @@ -4,10 +4,10 @@
7253
7254 #ifdef CONFIG_SMP
7255 .macro LOCK_PREFIX
7256 -1: lock
7257 +672: lock
7258 .section .smp_locks,"a"
7259 .balign 4
7260 - .long 1b - .
7261 + .long 672b - .
7262 .previous
7263 .endm
7264 #else
7265 @@ -15,6 +15,45 @@
7266 .endm
7267 #endif
7268
7269 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
7270 + .macro pax_force_retaddr_bts rip=0
7271 + btsq $63,\rip(%rsp)
7272 + .endm
7273 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
7274 + .macro pax_force_retaddr rip=0, reload=0
7275 + btsq $63,\rip(%rsp)
7276 + .endm
7277 + .macro pax_force_fptr ptr
7278 + btsq $63,\ptr
7279 + .endm
7280 + .macro pax_set_fptr_mask
7281 + .endm
7282 +#endif
7283 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
7284 + .macro pax_force_retaddr rip=0, reload=0
7285 + .if \reload
7286 + pax_set_fptr_mask
7287 + .endif
7288 + orq %r10,\rip(%rsp)
7289 + .endm
7290 + .macro pax_force_fptr ptr
7291 + orq %r10,\ptr
7292 + .endm
7293 + .macro pax_set_fptr_mask
7294 + movabs $0x8000000000000000,%r10
7295 + .endm
7296 +#endif
7297 +#else
7298 + .macro pax_force_retaddr rip=0, reload=0
7299 + .endm
7300 + .macro pax_force_fptr ptr
7301 + .endm
7302 + .macro pax_force_retaddr_bts rip=0
7303 + .endm
7304 + .macro pax_set_fptr_mask
7305 + .endm
7306 +#endif
7307 +
7308 .macro altinstruction_entry orig alt feature orig_len alt_len
7309 .long \orig - .
7310 .long \alt - .
7311 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
7312 index 37ad100..7d47faa 100644
7313 --- a/arch/x86/include/asm/alternative.h
7314 +++ b/arch/x86/include/asm/alternative.h
7315 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
7316 ".section .discard,\"aw\",@progbits\n" \
7317 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
7318 ".previous\n" \
7319 - ".section .altinstr_replacement, \"ax\"\n" \
7320 + ".section .altinstr_replacement, \"a\"\n" \
7321 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
7322 ".previous"
7323
7324 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
7325 index 1a6c09a..fec2432 100644
7326 --- a/arch/x86/include/asm/apic.h
7327 +++ b/arch/x86/include/asm/apic.h
7328 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
7329
7330 #ifdef CONFIG_X86_LOCAL_APIC
7331
7332 -extern unsigned int apic_verbosity;
7333 +extern int apic_verbosity;
7334 extern int local_apic_timer_c2_ok;
7335
7336 extern int disable_apic;
7337 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
7338 index 20370c6..a2eb9b0 100644
7339 --- a/arch/x86/include/asm/apm.h
7340 +++ b/arch/x86/include/asm/apm.h
7341 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
7342 __asm__ __volatile__(APM_DO_ZERO_SEGS
7343 "pushl %%edi\n\t"
7344 "pushl %%ebp\n\t"
7345 - "lcall *%%cs:apm_bios_entry\n\t"
7346 + "lcall *%%ss:apm_bios_entry\n\t"
7347 "setc %%al\n\t"
7348 "popl %%ebp\n\t"
7349 "popl %%edi\n\t"
7350 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
7351 __asm__ __volatile__(APM_DO_ZERO_SEGS
7352 "pushl %%edi\n\t"
7353 "pushl %%ebp\n\t"
7354 - "lcall *%%cs:apm_bios_entry\n\t"
7355 + "lcall *%%ss:apm_bios_entry\n\t"
7356 "setc %%bl\n\t"
7357 "popl %%ebp\n\t"
7358 "popl %%edi\n\t"
7359 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
7360 index 58cb6d4..ca9010d 100644
7361 --- a/arch/x86/include/asm/atomic.h
7362 +++ b/arch/x86/include/asm/atomic.h
7363 @@ -22,7 +22,18 @@
7364 */
7365 static inline int atomic_read(const atomic_t *v)
7366 {
7367 - return (*(volatile int *)&(v)->counter);
7368 + return (*(volatile const int *)&(v)->counter);
7369 +}
7370 +
7371 +/**
7372 + * atomic_read_unchecked - read atomic variable
7373 + * @v: pointer of type atomic_unchecked_t
7374 + *
7375 + * Atomically reads the value of @v.
7376 + */
7377 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7378 +{
7379 + return (*(volatile const int *)&(v)->counter);
7380 }
7381
7382 /**
7383 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
7384 }
7385
7386 /**
7387 + * atomic_set_unchecked - set atomic variable
7388 + * @v: pointer of type atomic_unchecked_t
7389 + * @i: required value
7390 + *
7391 + * Atomically sets the value of @v to @i.
7392 + */
7393 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7394 +{
7395 + v->counter = i;
7396 +}
7397 +
7398 +/**
7399 * atomic_add - add integer to atomic variable
7400 * @i: integer value to add
7401 * @v: pointer of type atomic_t
7402 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
7403 */
7404 static inline void atomic_add(int i, atomic_t *v)
7405 {
7406 - asm volatile(LOCK_PREFIX "addl %1,%0"
7407 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7408 +
7409 +#ifdef CONFIG_PAX_REFCOUNT
7410 + "jno 0f\n"
7411 + LOCK_PREFIX "subl %1,%0\n"
7412 + "int $4\n0:\n"
7413 + _ASM_EXTABLE(0b, 0b)
7414 +#endif
7415 +
7416 + : "+m" (v->counter)
7417 + : "ir" (i));
7418 +}
7419 +
7420 +/**
7421 + * atomic_add_unchecked - add integer to atomic variable
7422 + * @i: integer value to add
7423 + * @v: pointer of type atomic_unchecked_t
7424 + *
7425 + * Atomically adds @i to @v.
7426 + */
7427 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
7428 +{
7429 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
7430 : "+m" (v->counter)
7431 : "ir" (i));
7432 }
7433 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
7434 */
7435 static inline void atomic_sub(int i, atomic_t *v)
7436 {
7437 - asm volatile(LOCK_PREFIX "subl %1,%0"
7438 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7439 +
7440 +#ifdef CONFIG_PAX_REFCOUNT
7441 + "jno 0f\n"
7442 + LOCK_PREFIX "addl %1,%0\n"
7443 + "int $4\n0:\n"
7444 + _ASM_EXTABLE(0b, 0b)
7445 +#endif
7446 +
7447 + : "+m" (v->counter)
7448 + : "ir" (i));
7449 +}
7450 +
7451 +/**
7452 + * atomic_sub_unchecked - subtract integer from atomic variable
7453 + * @i: integer value to subtract
7454 + * @v: pointer of type atomic_unchecked_t
7455 + *
7456 + * Atomically subtracts @i from @v.
7457 + */
7458 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
7459 +{
7460 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
7461 : "+m" (v->counter)
7462 : "ir" (i));
7463 }
7464 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
7465 {
7466 unsigned char c;
7467
7468 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
7469 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
7470 +
7471 +#ifdef CONFIG_PAX_REFCOUNT
7472 + "jno 0f\n"
7473 + LOCK_PREFIX "addl %2,%0\n"
7474 + "int $4\n0:\n"
7475 + _ASM_EXTABLE(0b, 0b)
7476 +#endif
7477 +
7478 + "sete %1\n"
7479 : "+m" (v->counter), "=qm" (c)
7480 : "ir" (i) : "memory");
7481 return c;
7482 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
7483 */
7484 static inline void atomic_inc(atomic_t *v)
7485 {
7486 - asm volatile(LOCK_PREFIX "incl %0"
7487 + asm volatile(LOCK_PREFIX "incl %0\n"
7488 +
7489 +#ifdef CONFIG_PAX_REFCOUNT
7490 + "jno 0f\n"
7491 + LOCK_PREFIX "decl %0\n"
7492 + "int $4\n0:\n"
7493 + _ASM_EXTABLE(0b, 0b)
7494 +#endif
7495 +
7496 + : "+m" (v->counter));
7497 +}
7498 +
7499 +/**
7500 + * atomic_inc_unchecked - increment atomic variable
7501 + * @v: pointer of type atomic_unchecked_t
7502 + *
7503 + * Atomically increments @v by 1.
7504 + */
7505 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7506 +{
7507 + asm volatile(LOCK_PREFIX "incl %0\n"
7508 : "+m" (v->counter));
7509 }
7510
7511 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
7512 */
7513 static inline void atomic_dec(atomic_t *v)
7514 {
7515 - asm volatile(LOCK_PREFIX "decl %0"
7516 + asm volatile(LOCK_PREFIX "decl %0\n"
7517 +
7518 +#ifdef CONFIG_PAX_REFCOUNT
7519 + "jno 0f\n"
7520 + LOCK_PREFIX "incl %0\n"
7521 + "int $4\n0:\n"
7522 + _ASM_EXTABLE(0b, 0b)
7523 +#endif
7524 +
7525 + : "+m" (v->counter));
7526 +}
7527 +
7528 +/**
7529 + * atomic_dec_unchecked - decrement atomic variable
7530 + * @v: pointer of type atomic_unchecked_t
7531 + *
7532 + * Atomically decrements @v by 1.
7533 + */
7534 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7535 +{
7536 + asm volatile(LOCK_PREFIX "decl %0\n"
7537 : "+m" (v->counter));
7538 }
7539
7540 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
7541 {
7542 unsigned char c;
7543
7544 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
7545 + asm volatile(LOCK_PREFIX "decl %0\n"
7546 +
7547 +#ifdef CONFIG_PAX_REFCOUNT
7548 + "jno 0f\n"
7549 + LOCK_PREFIX "incl %0\n"
7550 + "int $4\n0:\n"
7551 + _ASM_EXTABLE(0b, 0b)
7552 +#endif
7553 +
7554 + "sete %1\n"
7555 : "+m" (v->counter), "=qm" (c)
7556 : : "memory");
7557 return c != 0;
7558 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
7559 {
7560 unsigned char c;
7561
7562 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
7563 + asm volatile(LOCK_PREFIX "incl %0\n"
7564 +
7565 +#ifdef CONFIG_PAX_REFCOUNT
7566 + "jno 0f\n"
7567 + LOCK_PREFIX "decl %0\n"
7568 + "int $4\n0:\n"
7569 + _ASM_EXTABLE(0b, 0b)
7570 +#endif
7571 +
7572 + "sete %1\n"
7573 + : "+m" (v->counter), "=qm" (c)
7574 + : : "memory");
7575 + return c != 0;
7576 +}
7577 +
7578 +/**
7579 + * atomic_inc_and_test_unchecked - increment and test
7580 + * @v: pointer of type atomic_unchecked_t
7581 + *
7582 + * Atomically increments @v by 1
7583 + * and returns true if the result is zero, or false for all
7584 + * other cases.
7585 + */
7586 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7587 +{
7588 + unsigned char c;
7589 +
7590 + asm volatile(LOCK_PREFIX "incl %0\n"
7591 + "sete %1\n"
7592 : "+m" (v->counter), "=qm" (c)
7593 : : "memory");
7594 return c != 0;
7595 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
7596 {
7597 unsigned char c;
7598
7599 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
7600 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
7601 +
7602 +#ifdef CONFIG_PAX_REFCOUNT
7603 + "jno 0f\n"
7604 + LOCK_PREFIX "subl %2,%0\n"
7605 + "int $4\n0:\n"
7606 + _ASM_EXTABLE(0b, 0b)
7607 +#endif
7608 +
7609 + "sets %1\n"
7610 : "+m" (v->counter), "=qm" (c)
7611 : "ir" (i) : "memory");
7612 return c;
7613 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
7614 goto no_xadd;
7615 #endif
7616 /* Modern 486+ processor */
7617 - return i + xadd(&v->counter, i);
7618 + return i + xadd_check_overflow(&v->counter, i);
7619
7620 #ifdef CONFIG_M386
7621 no_xadd: /* Legacy 386 processor */
7622 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
7623 }
7624
7625 /**
7626 + * atomic_add_return_unchecked - add integer and return
7627 + * @i: integer value to add
7628 + * @v: pointer of type atomic_unchecked_t
7629 + *
7630 + * Atomically adds @i to @v and returns @i + @v
7631 + */
7632 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7633 +{
7634 +#ifdef CONFIG_M386
7635 + int __i;
7636 + unsigned long flags;
7637 + if (unlikely(boot_cpu_data.x86 <= 3))
7638 + goto no_xadd;
7639 +#endif
7640 + /* Modern 486+ processor */
7641 + return i + xadd(&v->counter, i);
7642 +
7643 +#ifdef CONFIG_M386
7644 +no_xadd: /* Legacy 386 processor */
7645 + raw_local_irq_save(flags);
7646 + __i = atomic_read_unchecked(v);
7647 + atomic_set_unchecked(v, i + __i);
7648 + raw_local_irq_restore(flags);
7649 + return i + __i;
7650 +#endif
7651 +}
7652 +
7653 +/**
7654 * atomic_sub_return - subtract integer and return
7655 * @v: pointer of type atomic_t
7656 * @i: integer value to subtract
7657 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
7658 }
7659
7660 #define atomic_inc_return(v) (atomic_add_return(1, v))
7661 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7662 +{
7663 + return atomic_add_return_unchecked(1, v);
7664 +}
7665 #define atomic_dec_return(v) (atomic_sub_return(1, v))
7666
7667 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7668 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
7669 return cmpxchg(&v->counter, old, new);
7670 }
7671
7672 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7673 +{
7674 + return cmpxchg(&v->counter, old, new);
7675 +}
7676 +
7677 static inline int atomic_xchg(atomic_t *v, int new)
7678 {
7679 return xchg(&v->counter, new);
7680 }
7681
7682 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7683 +{
7684 + return xchg(&v->counter, new);
7685 +}
7686 +
7687 /**
7688 * __atomic_add_unless - add unless the number is already a given value
7689 * @v: pointer of type atomic_t
7690 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
7691 */
7692 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7693 {
7694 - int c, old;
7695 + int c, old, new;
7696 c = atomic_read(v);
7697 for (;;) {
7698 - if (unlikely(c == (u)))
7699 + if (unlikely(c == u))
7700 break;
7701 - old = atomic_cmpxchg((v), c, c + (a));
7702 +
7703 + asm volatile("addl %2,%0\n"
7704 +
7705 +#ifdef CONFIG_PAX_REFCOUNT
7706 + "jno 0f\n"
7707 + "subl %2,%0\n"
7708 + "int $4\n0:\n"
7709 + _ASM_EXTABLE(0b, 0b)
7710 +#endif
7711 +
7712 + : "=r" (new)
7713 + : "0" (c), "ir" (a));
7714 +
7715 + old = atomic_cmpxchg(v, c, new);
7716 if (likely(old == c))
7717 break;
7718 c = old;
7719 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7720 return c;
7721 }
7722
7723 +/**
7724 + * atomic_inc_not_zero_hint - increment if not null
7725 + * @v: pointer of type atomic_t
7726 + * @hint: probable value of the atomic before the increment
7727 + *
7728 + * This version of atomic_inc_not_zero() gives a hint of probable
7729 + * value of the atomic. This helps processor to not read the memory
7730 + * before doing the atomic read/modify/write cycle, lowering
7731 + * number of bus transactions on some arches.
7732 + *
7733 + * Returns: 0 if increment was not done, 1 otherwise.
7734 + */
7735 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
7736 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
7737 +{
7738 + int val, c = hint, new;
7739 +
7740 + /* sanity test, should be removed by compiler if hint is a constant */
7741 + if (!hint)
7742 + return __atomic_add_unless(v, 1, 0);
7743 +
7744 + do {
7745 + asm volatile("incl %0\n"
7746 +
7747 +#ifdef CONFIG_PAX_REFCOUNT
7748 + "jno 0f\n"
7749 + "decl %0\n"
7750 + "int $4\n0:\n"
7751 + _ASM_EXTABLE(0b, 0b)
7752 +#endif
7753 +
7754 + : "=r" (new)
7755 + : "0" (c));
7756 +
7757 + val = atomic_cmpxchg(v, c, new);
7758 + if (val == c)
7759 + return 1;
7760 + c = val;
7761 + } while (c);
7762 +
7763 + return 0;
7764 +}
7765
7766 /*
7767 * atomic_dec_if_positive - decrement by 1 if old value positive
7768 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
7769 index 24098aa..1e37723 100644
7770 --- a/arch/x86/include/asm/atomic64_32.h
7771 +++ b/arch/x86/include/asm/atomic64_32.h
7772 @@ -12,6 +12,14 @@ typedef struct {
7773 u64 __aligned(8) counter;
7774 } atomic64_t;
7775
7776 +#ifdef CONFIG_PAX_REFCOUNT
7777 +typedef struct {
7778 + u64 __aligned(8) counter;
7779 +} atomic64_unchecked_t;
7780 +#else
7781 +typedef atomic64_t atomic64_unchecked_t;
7782 +#endif
7783 +
7784 #define ATOMIC64_INIT(val) { (val) }
7785
7786 #ifdef CONFIG_X86_CMPXCHG64
7787 @@ -38,6 +46,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
7788 }
7789
7790 /**
7791 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
7792 + * @p: pointer to type atomic64_unchecked_t
7793 + * @o: expected value
7794 + * @n: new value
7795 + *
7796 + * Atomically sets @v to @n if it was equal to @o and returns
7797 + * the old value.
7798 + */
7799 +
7800 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
7801 +{
7802 + return cmpxchg64(&v->counter, o, n);
7803 +}
7804 +
7805 +/**
7806 * atomic64_xchg - xchg atomic64 variable
7807 * @v: pointer to type atomic64_t
7808 * @n: value to assign
7809 @@ -77,6 +100,24 @@ static inline void atomic64_set(atomic64_t *v, long long i)
7810 }
7811
7812 /**
7813 + * atomic64_set_unchecked - set atomic64 variable
7814 + * @v: pointer to type atomic64_unchecked_t
7815 + * @n: value to assign
7816 + *
7817 + * Atomically sets the value of @v to @n.
7818 + */
7819 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
7820 +{
7821 + unsigned high = (unsigned)(i >> 32);
7822 + unsigned low = (unsigned)i;
7823 + asm volatile(ATOMIC64_ALTERNATIVE(set)
7824 + : "+b" (low), "+c" (high)
7825 + : "S" (v)
7826 + : "eax", "edx", "memory"
7827 + );
7828 +}
7829 +
7830 +/**
7831 * atomic64_read - read atomic64 variable
7832 * @v: pointer to type atomic64_t
7833 *
7834 @@ -93,6 +134,22 @@ static inline long long atomic64_read(atomic64_t *v)
7835 }
7836
7837 /**
7838 + * atomic64_read_unchecked - read atomic64 variable
7839 + * @v: pointer to type atomic64_unchecked_t
7840 + *
7841 + * Atomically reads the value of @v and returns it.
7842 + */
7843 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
7844 +{
7845 + long long r;
7846 + asm volatile(ATOMIC64_ALTERNATIVE(read_unchecked)
7847 + : "=A" (r), "+c" (v)
7848 + : : "memory"
7849 + );
7850 + return r;
7851 + }
7852 +
7853 +/**
7854 * atomic64_add_return - add and return
7855 * @i: integer value to add
7856 * @v: pointer to type atomic64_t
7857 @@ -108,6 +165,22 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
7858 return i;
7859 }
7860
7861 +/**
7862 + * atomic64_add_return_unchecked - add and return
7863 + * @i: integer value to add
7864 + * @v: pointer to type atomic64_unchecked_t
7865 + *
7866 + * Atomically adds @i to @v and returns @i + *@v
7867 + */
7868 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
7869 +{
7870 + asm volatile(ATOMIC64_ALTERNATIVE(add_return_unchecked)
7871 + : "+A" (i), "+c" (v)
7872 + : : "memory"
7873 + );
7874 + return i;
7875 +}
7876 +
7877 /*
7878 * Other variants with different arithmetic operators:
7879 */
7880 @@ -131,6 +204,17 @@ static inline long long atomic64_inc_return(atomic64_t *v)
7881 return a;
7882 }
7883
7884 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7885 +{
7886 + long long a;
7887 + asm volatile(ATOMIC64_ALTERNATIVE(inc_return_unchecked)
7888 + : "=A" (a)
7889 + : "S" (v)
7890 + : "memory", "ecx"
7891 + );
7892 + return a;
7893 +}
7894 +
7895 static inline long long atomic64_dec_return(atomic64_t *v)
7896 {
7897 long long a;
7898 @@ -159,6 +243,22 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
7899 }
7900
7901 /**
7902 + * atomic64_add_unchecked - add integer to atomic64 variable
7903 + * @i: integer value to add
7904 + * @v: pointer to type atomic64_unchecked_t
7905 + *
7906 + * Atomically adds @i to @v.
7907 + */
7908 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
7909 +{
7910 + asm volatile(ATOMIC64_ALTERNATIVE_(add_unchecked, add_return_unchecked)
7911 + : "+A" (i), "+c" (v)
7912 + : : "memory"
7913 + );
7914 + return i;
7915 +}
7916 +
7917 +/**
7918 * atomic64_sub - subtract the atomic64 variable
7919 * @i: integer value to subtract
7920 * @v: pointer to type atomic64_t
7921 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
7922 index 0e1cbfc..5623683 100644
7923 --- a/arch/x86/include/asm/atomic64_64.h
7924 +++ b/arch/x86/include/asm/atomic64_64.h
7925 @@ -18,7 +18,19 @@
7926 */
7927 static inline long atomic64_read(const atomic64_t *v)
7928 {
7929 - return (*(volatile long *)&(v)->counter);
7930 + return (*(volatile const long *)&(v)->counter);
7931 +}
7932 +
7933 +/**
7934 + * atomic64_read_unchecked - read atomic64 variable
7935 + * @v: pointer of type atomic64_unchecked_t
7936 + *
7937 + * Atomically reads the value of @v.
7938 + * Doesn't imply a read memory barrier.
7939 + */
7940 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7941 +{
7942 + return (*(volatile const long *)&(v)->counter);
7943 }
7944
7945 /**
7946 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
7947 }
7948
7949 /**
7950 + * atomic64_set_unchecked - set atomic64 variable
7951 + * @v: pointer to type atomic64_unchecked_t
7952 + * @i: required value
7953 + *
7954 + * Atomically sets the value of @v to @i.
7955 + */
7956 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7957 +{
7958 + v->counter = i;
7959 +}
7960 +
7961 +/**
7962 * atomic64_add - add integer to atomic64 variable
7963 * @i: integer value to add
7964 * @v: pointer to type atomic64_t
7965 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
7966 */
7967 static inline void atomic64_add(long i, atomic64_t *v)
7968 {
7969 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
7970 +
7971 +#ifdef CONFIG_PAX_REFCOUNT
7972 + "jno 0f\n"
7973 + LOCK_PREFIX "subq %1,%0\n"
7974 + "int $4\n0:\n"
7975 + _ASM_EXTABLE(0b, 0b)
7976 +#endif
7977 +
7978 + : "=m" (v->counter)
7979 + : "er" (i), "m" (v->counter));
7980 +}
7981 +
7982 +/**
7983 + * atomic64_add_unchecked - add integer to atomic64 variable
7984 + * @i: integer value to add
7985 + * @v: pointer to type atomic64_unchecked_t
7986 + *
7987 + * Atomically adds @i to @v.
7988 + */
7989 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
7990 +{
7991 asm volatile(LOCK_PREFIX "addq %1,%0"
7992 : "=m" (v->counter)
7993 : "er" (i), "m" (v->counter));
7994 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
7995 */
7996 static inline void atomic64_sub(long i, atomic64_t *v)
7997 {
7998 - asm volatile(LOCK_PREFIX "subq %1,%0"
7999 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8000 +
8001 +#ifdef CONFIG_PAX_REFCOUNT
8002 + "jno 0f\n"
8003 + LOCK_PREFIX "addq %1,%0\n"
8004 + "int $4\n0:\n"
8005 + _ASM_EXTABLE(0b, 0b)
8006 +#endif
8007 +
8008 + : "=m" (v->counter)
8009 + : "er" (i), "m" (v->counter));
8010 +}
8011 +
8012 +/**
8013 + * atomic64_sub_unchecked - subtract the atomic64 variable
8014 + * @i: integer value to subtract
8015 + * @v: pointer to type atomic64_unchecked_t
8016 + *
8017 + * Atomically subtracts @i from @v.
8018 + */
8019 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
8020 +{
8021 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
8022 : "=m" (v->counter)
8023 : "er" (i), "m" (v->counter));
8024 }
8025 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
8026 {
8027 unsigned char c;
8028
8029 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
8030 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
8031 +
8032 +#ifdef CONFIG_PAX_REFCOUNT
8033 + "jno 0f\n"
8034 + LOCK_PREFIX "addq %2,%0\n"
8035 + "int $4\n0:\n"
8036 + _ASM_EXTABLE(0b, 0b)
8037 +#endif
8038 +
8039 + "sete %1\n"
8040 : "=m" (v->counter), "=qm" (c)
8041 : "er" (i), "m" (v->counter) : "memory");
8042 return c;
8043 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
8044 */
8045 static inline void atomic64_inc(atomic64_t *v)
8046 {
8047 + asm volatile(LOCK_PREFIX "incq %0\n"
8048 +
8049 +#ifdef CONFIG_PAX_REFCOUNT
8050 + "jno 0f\n"
8051 + LOCK_PREFIX "decq %0\n"
8052 + "int $4\n0:\n"
8053 + _ASM_EXTABLE(0b, 0b)
8054 +#endif
8055 +
8056 + : "=m" (v->counter)
8057 + : "m" (v->counter));
8058 +}
8059 +
8060 +/**
8061 + * atomic64_inc_unchecked - increment atomic64 variable
8062 + * @v: pointer to type atomic64_unchecked_t
8063 + *
8064 + * Atomically increments @v by 1.
8065 + */
8066 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8067 +{
8068 asm volatile(LOCK_PREFIX "incq %0"
8069 : "=m" (v->counter)
8070 : "m" (v->counter));
8071 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
8072 */
8073 static inline void atomic64_dec(atomic64_t *v)
8074 {
8075 - asm volatile(LOCK_PREFIX "decq %0"
8076 + asm volatile(LOCK_PREFIX "decq %0\n"
8077 +
8078 +#ifdef CONFIG_PAX_REFCOUNT
8079 + "jno 0f\n"
8080 + LOCK_PREFIX "incq %0\n"
8081 + "int $4\n0:\n"
8082 + _ASM_EXTABLE(0b, 0b)
8083 +#endif
8084 +
8085 + : "=m" (v->counter)
8086 + : "m" (v->counter));
8087 +}
8088 +
8089 +/**
8090 + * atomic64_dec_unchecked - decrement atomic64 variable
8091 + * @v: pointer to type atomic64_t
8092 + *
8093 + * Atomically decrements @v by 1.
8094 + */
8095 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8096 +{
8097 + asm volatile(LOCK_PREFIX "decq %0\n"
8098 : "=m" (v->counter)
8099 : "m" (v->counter));
8100 }
8101 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
8102 {
8103 unsigned char c;
8104
8105 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
8106 + asm volatile(LOCK_PREFIX "decq %0\n"
8107 +
8108 +#ifdef CONFIG_PAX_REFCOUNT
8109 + "jno 0f\n"
8110 + LOCK_PREFIX "incq %0\n"
8111 + "int $4\n0:\n"
8112 + _ASM_EXTABLE(0b, 0b)
8113 +#endif
8114 +
8115 + "sete %1\n"
8116 : "=m" (v->counter), "=qm" (c)
8117 : "m" (v->counter) : "memory");
8118 return c != 0;
8119 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
8120 {
8121 unsigned char c;
8122
8123 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
8124 + asm volatile(LOCK_PREFIX "incq %0\n"
8125 +
8126 +#ifdef CONFIG_PAX_REFCOUNT
8127 + "jno 0f\n"
8128 + LOCK_PREFIX "decq %0\n"
8129 + "int $4\n0:\n"
8130 + _ASM_EXTABLE(0b, 0b)
8131 +#endif
8132 +
8133 + "sete %1\n"
8134 : "=m" (v->counter), "=qm" (c)
8135 : "m" (v->counter) : "memory");
8136 return c != 0;
8137 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
8138 {
8139 unsigned char c;
8140
8141 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
8142 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
8143 +
8144 +#ifdef CONFIG_PAX_REFCOUNT
8145 + "jno 0f\n"
8146 + LOCK_PREFIX "subq %2,%0\n"
8147 + "int $4\n0:\n"
8148 + _ASM_EXTABLE(0b, 0b)
8149 +#endif
8150 +
8151 + "sets %1\n"
8152 : "=m" (v->counter), "=qm" (c)
8153 : "er" (i), "m" (v->counter) : "memory");
8154 return c;
8155 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
8156 */
8157 static inline long atomic64_add_return(long i, atomic64_t *v)
8158 {
8159 + return i + xadd_check_overflow(&v->counter, i);
8160 +}
8161 +
8162 +/**
8163 + * atomic64_add_return_unchecked - add and return
8164 + * @i: integer value to add
8165 + * @v: pointer to type atomic64_unchecked_t
8166 + *
8167 + * Atomically adds @i to @v and returns @i + @v
8168 + */
8169 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8170 +{
8171 return i + xadd(&v->counter, i);
8172 }
8173
8174 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
8175 }
8176
8177 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
8178 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8179 +{
8180 + return atomic64_add_return_unchecked(1, v);
8181 +}
8182 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
8183
8184 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8185 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
8186 return cmpxchg(&v->counter, old, new);
8187 }
8188
8189 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8190 +{
8191 + return cmpxchg(&v->counter, old, new);
8192 +}
8193 +
8194 static inline long atomic64_xchg(atomic64_t *v, long new)
8195 {
8196 return xchg(&v->counter, new);
8197 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
8198 */
8199 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
8200 {
8201 - long c, old;
8202 + long c, old, new;
8203 c = atomic64_read(v);
8204 for (;;) {
8205 - if (unlikely(c == (u)))
8206 + if (unlikely(c == u))
8207 break;
8208 - old = atomic64_cmpxchg((v), c, c + (a));
8209 +
8210 + asm volatile("add %2,%0\n"
8211 +
8212 +#ifdef CONFIG_PAX_REFCOUNT
8213 + "jno 0f\n"
8214 + "sub %2,%0\n"
8215 + "int $4\n0:\n"
8216 + _ASM_EXTABLE(0b, 0b)
8217 +#endif
8218 +
8219 + : "=r" (new)
8220 + : "0" (c), "ir" (a));
8221 +
8222 + old = atomic64_cmpxchg(v, c, new);
8223 if (likely(old == c))
8224 break;
8225 c = old;
8226 }
8227 - return c != (u);
8228 + return c != u;
8229 }
8230
8231 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8232 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
8233 index 1775d6e..b65017f 100644
8234 --- a/arch/x86/include/asm/bitops.h
8235 +++ b/arch/x86/include/asm/bitops.h
8236 @@ -38,7 +38,7 @@
8237 * a mask operation on a byte.
8238 */
8239 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
8240 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
8241 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
8242 #define CONST_MASK(nr) (1 << ((nr) & 7))
8243
8244 /**
8245 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
8246 index 5e1a2ee..c9f9533 100644
8247 --- a/arch/x86/include/asm/boot.h
8248 +++ b/arch/x86/include/asm/boot.h
8249 @@ -11,10 +11,15 @@
8250 #include <asm/pgtable_types.h>
8251
8252 /* Physical address where kernel should be loaded. */
8253 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8254 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
8255 + (CONFIG_PHYSICAL_ALIGN - 1)) \
8256 & ~(CONFIG_PHYSICAL_ALIGN - 1))
8257
8258 +#ifndef __ASSEMBLY__
8259 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
8260 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
8261 +#endif
8262 +
8263 /* Minimum kernel alignment, as a power of two */
8264 #ifdef CONFIG_X86_64
8265 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
8266 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
8267 index 48f99f1..d78ebf9 100644
8268 --- a/arch/x86/include/asm/cache.h
8269 +++ b/arch/x86/include/asm/cache.h
8270 @@ -5,12 +5,13 @@
8271
8272 /* L1 cache line size */
8273 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8274 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8275 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8276
8277 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8278 +#define __read_only __attribute__((__section__(".data..read_only")))
8279
8280 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
8281 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
8282 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
8283
8284 #ifdef CONFIG_X86_VSMP
8285 #ifdef CONFIG_SMP
8286 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
8287 index 4e12668..501d239 100644
8288 --- a/arch/x86/include/asm/cacheflush.h
8289 +++ b/arch/x86/include/asm/cacheflush.h
8290 @@ -26,7 +26,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
8291 unsigned long pg_flags = pg->flags & _PGMT_MASK;
8292
8293 if (pg_flags == _PGMT_DEFAULT)
8294 - return -1;
8295 + return ~0UL;
8296 else if (pg_flags == _PGMT_WC)
8297 return _PAGE_CACHE_WC;
8298 else if (pg_flags == _PGMT_UC_MINUS)
8299 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
8300 index 46fc474..b02b0f9 100644
8301 --- a/arch/x86/include/asm/checksum_32.h
8302 +++ b/arch/x86/include/asm/checksum_32.h
8303 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
8304 int len, __wsum sum,
8305 int *src_err_ptr, int *dst_err_ptr);
8306
8307 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
8308 + int len, __wsum sum,
8309 + int *src_err_ptr, int *dst_err_ptr);
8310 +
8311 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
8312 + int len, __wsum sum,
8313 + int *src_err_ptr, int *dst_err_ptr);
8314 +
8315 /*
8316 * Note: when you get a NULL pointer exception here this means someone
8317 * passed in an incorrect kernel address to one of these functions.
8318 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
8319 int *err_ptr)
8320 {
8321 might_sleep();
8322 - return csum_partial_copy_generic((__force void *)src, dst,
8323 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
8324 len, sum, err_ptr, NULL);
8325 }
8326
8327 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
8328 {
8329 might_sleep();
8330 if (access_ok(VERIFY_WRITE, dst, len))
8331 - return csum_partial_copy_generic(src, (__force void *)dst,
8332 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
8333 len, sum, NULL, err_ptr);
8334
8335 if (len)
8336 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
8337 index 5d3acdf..6447a02 100644
8338 --- a/arch/x86/include/asm/cmpxchg.h
8339 +++ b/arch/x86/include/asm/cmpxchg.h
8340 @@ -14,6 +14,8 @@ extern void __cmpxchg_wrong_size(void)
8341 __compiletime_error("Bad argument size for cmpxchg");
8342 extern void __xadd_wrong_size(void)
8343 __compiletime_error("Bad argument size for xadd");
8344 +extern void __xadd_check_overflow_wrong_size(void)
8345 + __compiletime_error("Bad argument size for xadd_check_overflow");
8346
8347 /*
8348 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
8349 @@ -195,6 +197,34 @@ extern void __xadd_wrong_size(void)
8350 __ret; \
8351 })
8352
8353 +#define __xadd_check_overflow(ptr, inc, lock) \
8354 + ({ \
8355 + __typeof__ (*(ptr)) __ret = (inc); \
8356 + switch (sizeof(*(ptr))) { \
8357 + case __X86_CASE_L: \
8358 + asm volatile (lock "xaddl %0, %1\n" \
8359 + "jno 0f\n" \
8360 + "mov %0,%1\n" \
8361 + "int $4\n0:\n" \
8362 + _ASM_EXTABLE(0b, 0b) \
8363 + : "+r" (__ret), "+m" (*(ptr)) \
8364 + : : "memory", "cc"); \
8365 + break; \
8366 + case __X86_CASE_Q: \
8367 + asm volatile (lock "xaddq %q0, %1\n" \
8368 + "jno 0f\n" \
8369 + "mov %0,%1\n" \
8370 + "int $4\n0:\n" \
8371 + _ASM_EXTABLE(0b, 0b) \
8372 + : "+r" (__ret), "+m" (*(ptr)) \
8373 + : : "memory", "cc"); \
8374 + break; \
8375 + default: \
8376 + __xadd_check_overflow_wrong_size(); \
8377 + } \
8378 + __ret; \
8379 + })
8380 +
8381 /*
8382 * xadd() adds "inc" to "*ptr" and atomically returns the previous
8383 * value of "*ptr".
8384 @@ -207,4 +237,6 @@ extern void __xadd_wrong_size(void)
8385 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
8386 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
8387
8388 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
8389 +
8390 #endif /* ASM_X86_CMPXCHG_H */
8391 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
8392 index f3444f7..051a196 100644
8393 --- a/arch/x86/include/asm/cpufeature.h
8394 +++ b/arch/x86/include/asm/cpufeature.h
8395 @@ -363,7 +363,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
8396 ".section .discard,\"aw\",@progbits\n"
8397 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
8398 ".previous\n"
8399 - ".section .altinstr_replacement,\"ax\"\n"
8400 + ".section .altinstr_replacement,\"a\"\n"
8401 "3: movb $1,%0\n"
8402 "4:\n"
8403 ".previous\n"
8404 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
8405 index 41935fa..3b40db8 100644
8406 --- a/arch/x86/include/asm/desc.h
8407 +++ b/arch/x86/include/asm/desc.h
8408 @@ -4,6 +4,7 @@
8409 #include <asm/desc_defs.h>
8410 #include <asm/ldt.h>
8411 #include <asm/mmu.h>
8412 +#include <asm/pgtable.h>
8413
8414 #include <linux/smp.h>
8415
8416 @@ -16,6 +17,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
8417
8418 desc->type = (info->read_exec_only ^ 1) << 1;
8419 desc->type |= info->contents << 2;
8420 + desc->type |= info->seg_not_present ^ 1;
8421
8422 desc->s = 1;
8423 desc->dpl = 0x3;
8424 @@ -34,17 +36,12 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
8425 }
8426
8427 extern struct desc_ptr idt_descr;
8428 -extern gate_desc idt_table[];
8429 -
8430 -struct gdt_page {
8431 - struct desc_struct gdt[GDT_ENTRIES];
8432 -} __attribute__((aligned(PAGE_SIZE)));
8433 -
8434 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
8435 +extern gate_desc idt_table[256];
8436
8437 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
8438 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
8439 {
8440 - return per_cpu(gdt_page, cpu).gdt;
8441 + return cpu_gdt_table[cpu];
8442 }
8443
8444 #ifdef CONFIG_X86_64
8445 @@ -69,8 +66,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
8446 unsigned long base, unsigned dpl, unsigned flags,
8447 unsigned short seg)
8448 {
8449 - gate->a = (seg << 16) | (base & 0xffff);
8450 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
8451 + gate->gate.offset_low = base;
8452 + gate->gate.seg = seg;
8453 + gate->gate.reserved = 0;
8454 + gate->gate.type = type;
8455 + gate->gate.s = 0;
8456 + gate->gate.dpl = dpl;
8457 + gate->gate.p = 1;
8458 + gate->gate.offset_high = base >> 16;
8459 }
8460
8461 #endif
8462 @@ -115,12 +118,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
8463
8464 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
8465 {
8466 + pax_open_kernel();
8467 memcpy(&idt[entry], gate, sizeof(*gate));
8468 + pax_close_kernel();
8469 }
8470
8471 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
8472 {
8473 + pax_open_kernel();
8474 memcpy(&ldt[entry], desc, 8);
8475 + pax_close_kernel();
8476 }
8477
8478 static inline void
8479 @@ -134,7 +141,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
8480 default: size = sizeof(*gdt); break;
8481 }
8482
8483 + pax_open_kernel();
8484 memcpy(&gdt[entry], desc, size);
8485 + pax_close_kernel();
8486 }
8487
8488 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
8489 @@ -207,7 +216,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
8490
8491 static inline void native_load_tr_desc(void)
8492 {
8493 + pax_open_kernel();
8494 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
8495 + pax_close_kernel();
8496 }
8497
8498 static inline void native_load_gdt(const struct desc_ptr *dtr)
8499 @@ -244,8 +255,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
8500 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
8501 unsigned int i;
8502
8503 + pax_open_kernel();
8504 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
8505 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
8506 + pax_close_kernel();
8507 }
8508
8509 #define _LDT_empty(info) \
8510 @@ -307,7 +320,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
8511 desc->limit = (limit >> 16) & 0xf;
8512 }
8513
8514 -static inline void _set_gate(int gate, unsigned type, void *addr,
8515 +static inline void _set_gate(int gate, unsigned type, const void *addr,
8516 unsigned dpl, unsigned ist, unsigned seg)
8517 {
8518 gate_desc s;
8519 @@ -326,7 +339,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
8520 * Pentium F0 0F bugfix can have resulted in the mapped
8521 * IDT being write-protected.
8522 */
8523 -static inline void set_intr_gate(unsigned int n, void *addr)
8524 +static inline void set_intr_gate(unsigned int n, const void *addr)
8525 {
8526 BUG_ON((unsigned)n > 0xFF);
8527 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
8528 @@ -356,19 +369,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
8529 /*
8530 * This routine sets up an interrupt gate at directory privilege level 3.
8531 */
8532 -static inline void set_system_intr_gate(unsigned int n, void *addr)
8533 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
8534 {
8535 BUG_ON((unsigned)n > 0xFF);
8536 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
8537 }
8538
8539 -static inline void set_system_trap_gate(unsigned int n, void *addr)
8540 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
8541 {
8542 BUG_ON((unsigned)n > 0xFF);
8543 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
8544 }
8545
8546 -static inline void set_trap_gate(unsigned int n, void *addr)
8547 +static inline void set_trap_gate(unsigned int n, const void *addr)
8548 {
8549 BUG_ON((unsigned)n > 0xFF);
8550 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
8551 @@ -377,19 +390,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
8552 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
8553 {
8554 BUG_ON((unsigned)n > 0xFF);
8555 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
8556 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
8557 }
8558
8559 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
8560 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
8561 {
8562 BUG_ON((unsigned)n > 0xFF);
8563 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
8564 }
8565
8566 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
8567 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
8568 {
8569 BUG_ON((unsigned)n > 0xFF);
8570 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
8571 }
8572
8573 +#ifdef CONFIG_X86_32
8574 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
8575 +{
8576 + struct desc_struct d;
8577 +
8578 + if (likely(limit))
8579 + limit = (limit - 1UL) >> PAGE_SHIFT;
8580 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
8581 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
8582 +}
8583 +#endif
8584 +
8585 #endif /* _ASM_X86_DESC_H */
8586 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
8587 index 278441f..b95a174 100644
8588 --- a/arch/x86/include/asm/desc_defs.h
8589 +++ b/arch/x86/include/asm/desc_defs.h
8590 @@ -31,6 +31,12 @@ struct desc_struct {
8591 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
8592 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
8593 };
8594 + struct {
8595 + u16 offset_low;
8596 + u16 seg;
8597 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
8598 + unsigned offset_high: 16;
8599 + } gate;
8600 };
8601 } __attribute__((packed));
8602
8603 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
8604 index 908b969..a1f4eb4 100644
8605 --- a/arch/x86/include/asm/e820.h
8606 +++ b/arch/x86/include/asm/e820.h
8607 @@ -69,7 +69,7 @@ struct e820map {
8608 #define ISA_START_ADDRESS 0xa0000
8609 #define ISA_END_ADDRESS 0x100000
8610
8611 -#define BIOS_BEGIN 0x000a0000
8612 +#define BIOS_BEGIN 0x000c0000
8613 #define BIOS_END 0x00100000
8614
8615 #define BIOS_ROM_BASE 0xffe00000
8616 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
8617 index 5f962df..7289f09 100644
8618 --- a/arch/x86/include/asm/elf.h
8619 +++ b/arch/x86/include/asm/elf.h
8620 @@ -238,7 +238,25 @@ extern int force_personality32;
8621 the loader. We need to make sure that it is out of the way of the program
8622 that it will "exec", and that there is sufficient room for the brk. */
8623
8624 +#ifdef CONFIG_PAX_SEGMEXEC
8625 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
8626 +#else
8627 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
8628 +#endif
8629 +
8630 +#ifdef CONFIG_PAX_ASLR
8631 +#ifdef CONFIG_X86_32
8632 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
8633 +
8634 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8635 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
8636 +#else
8637 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
8638 +
8639 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8640 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
8641 +#endif
8642 +#endif
8643
8644 /* This yields a mask that user programs can use to figure out what
8645 instruction set this CPU supports. This could be done in user space,
8646 @@ -291,9 +309,7 @@ do { \
8647
8648 #define ARCH_DLINFO \
8649 do { \
8650 - if (vdso_enabled) \
8651 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
8652 - (unsigned long)current->mm->context.vdso); \
8653 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
8654 } while (0)
8655
8656 #define AT_SYSINFO 32
8657 @@ -304,7 +320,7 @@ do { \
8658
8659 #endif /* !CONFIG_X86_32 */
8660
8661 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
8662 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
8663
8664 #define VDSO_ENTRY \
8665 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
8666 @@ -318,9 +334,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8667 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
8668 #define compat_arch_setup_additional_pages syscall32_setup_pages
8669
8670 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8671 -#define arch_randomize_brk arch_randomize_brk
8672 -
8673 /*
8674 * True on X86_32 or when emulating IA32 on X86_64
8675 */
8676 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
8677 index cc70c1c..d96d011 100644
8678 --- a/arch/x86/include/asm/emergency-restart.h
8679 +++ b/arch/x86/include/asm/emergency-restart.h
8680 @@ -15,6 +15,6 @@ enum reboot_type {
8681
8682 extern enum reboot_type reboot_type;
8683
8684 -extern void machine_emergency_restart(void);
8685 +extern void machine_emergency_restart(void) __noreturn;
8686
8687 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
8688 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
8689 index d09bb03..4ea4194 100644
8690 --- a/arch/x86/include/asm/futex.h
8691 +++ b/arch/x86/include/asm/futex.h
8692 @@ -12,16 +12,18 @@
8693 #include <asm/system.h>
8694
8695 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
8696 + typecheck(u32 __user *, uaddr); \
8697 asm volatile("1:\t" insn "\n" \
8698 "2:\t.section .fixup,\"ax\"\n" \
8699 "3:\tmov\t%3, %1\n" \
8700 "\tjmp\t2b\n" \
8701 "\t.previous\n" \
8702 _ASM_EXTABLE(1b, 3b) \
8703 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
8704 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
8705 : "i" (-EFAULT), "0" (oparg), "1" (0))
8706
8707 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
8708 + typecheck(u32 __user *, uaddr); \
8709 asm volatile("1:\tmovl %2, %0\n" \
8710 "\tmovl\t%0, %3\n" \
8711 "\t" insn "\n" \
8712 @@ -34,7 +36,7 @@
8713 _ASM_EXTABLE(1b, 4b) \
8714 _ASM_EXTABLE(2b, 4b) \
8715 : "=&a" (oldval), "=&r" (ret), \
8716 - "+m" (*uaddr), "=&r" (tem) \
8717 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
8718 : "r" (oparg), "i" (-EFAULT), "1" (0))
8719
8720 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8721 @@ -61,10 +63,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
8722
8723 switch (op) {
8724 case FUTEX_OP_SET:
8725 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
8726 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
8727 break;
8728 case FUTEX_OP_ADD:
8729 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
8730 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
8731 uaddr, oparg);
8732 break;
8733 case FUTEX_OP_OR:
8734 @@ -123,13 +125,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
8735 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
8736 return -EFAULT;
8737
8738 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
8739 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
8740 "2:\t.section .fixup, \"ax\"\n"
8741 "3:\tmov %3, %0\n"
8742 "\tjmp 2b\n"
8743 "\t.previous\n"
8744 _ASM_EXTABLE(1b, 3b)
8745 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
8746 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
8747 : "i" (-EFAULT), "r" (newval), "1" (oldval)
8748 : "memory"
8749 );
8750 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
8751 index eb92a6e..b98b2f4 100644
8752 --- a/arch/x86/include/asm/hw_irq.h
8753 +++ b/arch/x86/include/asm/hw_irq.h
8754 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
8755 extern void enable_IO_APIC(void);
8756
8757 /* Statistics */
8758 -extern atomic_t irq_err_count;
8759 -extern atomic_t irq_mis_count;
8760 +extern atomic_unchecked_t irq_err_count;
8761 +extern atomic_unchecked_t irq_mis_count;
8762
8763 /* EISA */
8764 extern void eisa_set_level_irq(unsigned int irq);
8765 diff --git a/arch/x86/include/asm/i387.h b/arch/x86/include/asm/i387.h
8766 index c9e09ea..73888df 100644
8767 --- a/arch/x86/include/asm/i387.h
8768 +++ b/arch/x86/include/asm/i387.h
8769 @@ -92,6 +92,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
8770 {
8771 int err;
8772
8773 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8774 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8775 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
8776 +#endif
8777 +
8778 /* See comment in fxsave() below. */
8779 #ifdef CONFIG_AS_FXSAVEQ
8780 asm volatile("1: fxrstorq %[fx]\n\t"
8781 @@ -121,6 +126,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
8782 {
8783 int err;
8784
8785 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
8786 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
8787 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
8788 +#endif
8789 +
8790 /*
8791 * Clear the bytes not touched by the fxsave and reserved
8792 * for the SW usage.
8793 @@ -213,13 +223,8 @@ static inline void fpu_fxsave(struct fpu *fpu)
8794 #endif /* CONFIG_X86_64 */
8795
8796 /* We need a safe address that is cheap to find and that is already
8797 - in L1 during context switch. The best choices are unfortunately
8798 - different for UP and SMP */
8799 -#ifdef CONFIG_SMP
8800 -#define safe_address (__per_cpu_offset[0])
8801 -#else
8802 -#define safe_address (kstat_cpu(0).cpustat.user)
8803 -#endif
8804 + in L1 during context switch. */
8805 +#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
8806
8807 /*
8808 * These must be called with preempt disabled
8809 @@ -312,7 +317,7 @@ static inline void kernel_fpu_begin(void)
8810 struct thread_info *me = current_thread_info();
8811 preempt_disable();
8812 if (me->status & TS_USEDFPU)
8813 - __save_init_fpu(me->task);
8814 + __save_init_fpu(current);
8815 else
8816 clts();
8817 }
8818 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
8819 index d8e8eef..99f81ae 100644
8820 --- a/arch/x86/include/asm/io.h
8821 +++ b/arch/x86/include/asm/io.h
8822 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
8823
8824 #include <linux/vmalloc.h>
8825
8826 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
8827 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
8828 +{
8829 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8830 +}
8831 +
8832 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
8833 +{
8834 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
8835 +}
8836 +
8837 /*
8838 * Convert a virtual cached pointer to an uncached pointer
8839 */
8840 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
8841 index bba3cf8..06bc8da 100644
8842 --- a/arch/x86/include/asm/irqflags.h
8843 +++ b/arch/x86/include/asm/irqflags.h
8844 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
8845 sti; \
8846 sysexit
8847
8848 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
8849 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
8850 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
8851 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
8852 +
8853 #else
8854 #define INTERRUPT_RETURN iret
8855 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
8856 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
8857 index 5478825..839e88c 100644
8858 --- a/arch/x86/include/asm/kprobes.h
8859 +++ b/arch/x86/include/asm/kprobes.h
8860 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
8861 #define RELATIVEJUMP_SIZE 5
8862 #define RELATIVECALL_OPCODE 0xe8
8863 #define RELATIVE_ADDR_SIZE 4
8864 -#define MAX_STACK_SIZE 64
8865 -#define MIN_STACK_SIZE(ADDR) \
8866 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
8867 - THREAD_SIZE - (unsigned long)(ADDR))) \
8868 - ? (MAX_STACK_SIZE) \
8869 - : (((unsigned long)current_thread_info()) + \
8870 - THREAD_SIZE - (unsigned long)(ADDR)))
8871 +#define MAX_STACK_SIZE 64UL
8872 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
8873
8874 #define flush_insn_slot(p) do { } while (0)
8875
8876 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
8877 index b4973f4..7c4d3fc 100644
8878 --- a/arch/x86/include/asm/kvm_host.h
8879 +++ b/arch/x86/include/asm/kvm_host.h
8880 @@ -459,7 +459,7 @@ struct kvm_arch {
8881 unsigned int n_requested_mmu_pages;
8882 unsigned int n_max_mmu_pages;
8883 unsigned int indirect_shadow_pages;
8884 - atomic_t invlpg_counter;
8885 + atomic_unchecked_t invlpg_counter;
8886 struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
8887 /*
8888 * Hash table of struct kvm_mmu_page.
8889 @@ -638,7 +638,7 @@ struct kvm_x86_ops {
8890 int (*check_intercept)(struct kvm_vcpu *vcpu,
8891 struct x86_instruction_info *info,
8892 enum x86_intercept_stage stage);
8893 -};
8894 +} __do_const;
8895
8896 struct kvm_arch_async_pf {
8897 u32 token;
8898 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
8899 index 9cdae5d..300d20f 100644
8900 --- a/arch/x86/include/asm/local.h
8901 +++ b/arch/x86/include/asm/local.h
8902 @@ -18,26 +18,58 @@ typedef struct {
8903
8904 static inline void local_inc(local_t *l)
8905 {
8906 - asm volatile(_ASM_INC "%0"
8907 + asm volatile(_ASM_INC "%0\n"
8908 +
8909 +#ifdef CONFIG_PAX_REFCOUNT
8910 + "jno 0f\n"
8911 + _ASM_DEC "%0\n"
8912 + "int $4\n0:\n"
8913 + _ASM_EXTABLE(0b, 0b)
8914 +#endif
8915 +
8916 : "+m" (l->a.counter));
8917 }
8918
8919 static inline void local_dec(local_t *l)
8920 {
8921 - asm volatile(_ASM_DEC "%0"
8922 + asm volatile(_ASM_DEC "%0\n"
8923 +
8924 +#ifdef CONFIG_PAX_REFCOUNT
8925 + "jno 0f\n"
8926 + _ASM_INC "%0\n"
8927 + "int $4\n0:\n"
8928 + _ASM_EXTABLE(0b, 0b)
8929 +#endif
8930 +
8931 : "+m" (l->a.counter));
8932 }
8933
8934 static inline void local_add(long i, local_t *l)
8935 {
8936 - asm volatile(_ASM_ADD "%1,%0"
8937 + asm volatile(_ASM_ADD "%1,%0\n"
8938 +
8939 +#ifdef CONFIG_PAX_REFCOUNT
8940 + "jno 0f\n"
8941 + _ASM_SUB "%1,%0\n"
8942 + "int $4\n0:\n"
8943 + _ASM_EXTABLE(0b, 0b)
8944 +#endif
8945 +
8946 : "+m" (l->a.counter)
8947 : "ir" (i));
8948 }
8949
8950 static inline void local_sub(long i, local_t *l)
8951 {
8952 - asm volatile(_ASM_SUB "%1,%0"
8953 + asm volatile(_ASM_SUB "%1,%0\n"
8954 +
8955 +#ifdef CONFIG_PAX_REFCOUNT
8956 + "jno 0f\n"
8957 + _ASM_ADD "%1,%0\n"
8958 + "int $4\n0:\n"
8959 + _ASM_EXTABLE(0b, 0b)
8960 +#endif
8961 +
8962 : "+m" (l->a.counter)
8963 : "ir" (i));
8964 }
8965 @@ -55,7 +87,16 @@ static inline int local_sub_and_test(long i, local_t *l)
8966 {
8967 unsigned char c;
8968
8969 - asm volatile(_ASM_SUB "%2,%0; sete %1"
8970 + asm volatile(_ASM_SUB "%2,%0\n"
8971 +
8972 +#ifdef CONFIG_PAX_REFCOUNT
8973 + "jno 0f\n"
8974 + _ASM_ADD "%2,%0\n"
8975 + "int $4\n0:\n"
8976 + _ASM_EXTABLE(0b, 0b)
8977 +#endif
8978 +
8979 + "sete %1\n"
8980 : "+m" (l->a.counter), "=qm" (c)
8981 : "ir" (i) : "memory");
8982 return c;
8983 @@ -73,7 +114,16 @@ static inline int local_dec_and_test(local_t *l)
8984 {
8985 unsigned char c;
8986
8987 - asm volatile(_ASM_DEC "%0; sete %1"
8988 + asm volatile(_ASM_DEC "%0\n"
8989 +
8990 +#ifdef CONFIG_PAX_REFCOUNT
8991 + "jno 0f\n"
8992 + _ASM_INC "%0\n"
8993 + "int $4\n0:\n"
8994 + _ASM_EXTABLE(0b, 0b)
8995 +#endif
8996 +
8997 + "sete %1\n"
8998 : "+m" (l->a.counter), "=qm" (c)
8999 : : "memory");
9000 return c != 0;
9001 @@ -91,7 +141,16 @@ static inline int local_inc_and_test(local_t *l)
9002 {
9003 unsigned char c;
9004
9005 - asm volatile(_ASM_INC "%0; sete %1"
9006 + asm volatile(_ASM_INC "%0\n"
9007 +
9008 +#ifdef CONFIG_PAX_REFCOUNT
9009 + "jno 0f\n"
9010 + _ASM_DEC "%0\n"
9011 + "int $4\n0:\n"
9012 + _ASM_EXTABLE(0b, 0b)
9013 +#endif
9014 +
9015 + "sete %1\n"
9016 : "+m" (l->a.counter), "=qm" (c)
9017 : : "memory");
9018 return c != 0;
9019 @@ -110,7 +169,16 @@ static inline int local_add_negative(long i, local_t *l)
9020 {
9021 unsigned char c;
9022
9023 - asm volatile(_ASM_ADD "%2,%0; sets %1"
9024 + asm volatile(_ASM_ADD "%2,%0\n"
9025 +
9026 +#ifdef CONFIG_PAX_REFCOUNT
9027 + "jno 0f\n"
9028 + _ASM_SUB "%2,%0\n"
9029 + "int $4\n0:\n"
9030 + _ASM_EXTABLE(0b, 0b)
9031 +#endif
9032 +
9033 + "sets %1\n"
9034 : "+m" (l->a.counter), "=qm" (c)
9035 : "ir" (i) : "memory");
9036 return c;
9037 @@ -133,7 +201,15 @@ static inline long local_add_return(long i, local_t *l)
9038 #endif
9039 /* Modern 486+ processor */
9040 __i = i;
9041 - asm volatile(_ASM_XADD "%0, %1;"
9042 + asm volatile(_ASM_XADD "%0, %1\n"
9043 +
9044 +#ifdef CONFIG_PAX_REFCOUNT
9045 + "jno 0f\n"
9046 + _ASM_MOV "%0,%1\n"
9047 + "int $4\n0:\n"
9048 + _ASM_EXTABLE(0b, 0b)
9049 +#endif
9050 +
9051 : "+r" (i), "+m" (l->a.counter)
9052 : : "memory");
9053 return i + __i;
9054 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
9055 index 593e51d..fa69c9a 100644
9056 --- a/arch/x86/include/asm/mman.h
9057 +++ b/arch/x86/include/asm/mman.h
9058 @@ -5,4 +5,14 @@
9059
9060 #include <asm-generic/mman.h>
9061
9062 +#ifdef __KERNEL__
9063 +#ifndef __ASSEMBLY__
9064 +#ifdef CONFIG_X86_32
9065 +#define arch_mmap_check i386_mmap_check
9066 +int i386_mmap_check(unsigned long addr, unsigned long len,
9067 + unsigned long flags);
9068 +#endif
9069 +#endif
9070 +#endif
9071 +
9072 #endif /* _ASM_X86_MMAN_H */
9073 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
9074 index 5f55e69..e20bfb1 100644
9075 --- a/arch/x86/include/asm/mmu.h
9076 +++ b/arch/x86/include/asm/mmu.h
9077 @@ -9,7 +9,7 @@
9078 * we put the segment information here.
9079 */
9080 typedef struct {
9081 - void *ldt;
9082 + struct desc_struct *ldt;
9083 int size;
9084
9085 #ifdef CONFIG_X86_64
9086 @@ -18,7 +18,19 @@ typedef struct {
9087 #endif
9088
9089 struct mutex lock;
9090 - void *vdso;
9091 + unsigned long vdso;
9092 +
9093 +#ifdef CONFIG_X86_32
9094 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
9095 + unsigned long user_cs_base;
9096 + unsigned long user_cs_limit;
9097 +
9098 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9099 + cpumask_t cpu_user_cs_mask;
9100 +#endif
9101 +
9102 +#endif
9103 +#endif
9104 } mm_context_t;
9105
9106 #ifdef CONFIG_SMP
9107 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
9108 index 6902152..399f3a2 100644
9109 --- a/arch/x86/include/asm/mmu_context.h
9110 +++ b/arch/x86/include/asm/mmu_context.h
9111 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
9112
9113 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
9114 {
9115 +
9116 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9117 + unsigned int i;
9118 + pgd_t *pgd;
9119 +
9120 + pax_open_kernel();
9121 + pgd = get_cpu_pgd(smp_processor_id());
9122 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
9123 + set_pgd_batched(pgd+i, native_make_pgd(0));
9124 + pax_close_kernel();
9125 +#endif
9126 +
9127 #ifdef CONFIG_SMP
9128 if (percpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
9129 percpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
9130 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
9131 struct task_struct *tsk)
9132 {
9133 unsigned cpu = smp_processor_id();
9134 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9135 + int tlbstate = TLBSTATE_OK;
9136 +#endif
9137
9138 if (likely(prev != next)) {
9139 #ifdef CONFIG_SMP
9140 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9141 + tlbstate = percpu_read(cpu_tlbstate.state);
9142 +#endif
9143 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9144 percpu_write(cpu_tlbstate.active_mm, next);
9145 #endif
9146 cpumask_set_cpu(cpu, mm_cpumask(next));
9147
9148 /* Re-load page tables */
9149 +#ifdef CONFIG_PAX_PER_CPU_PGD
9150 + pax_open_kernel();
9151 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9152 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9153 + pax_close_kernel();
9154 + load_cr3(get_cpu_pgd(cpu));
9155 +#else
9156 load_cr3(next->pgd);
9157 +#endif
9158
9159 /* stop flush ipis for the previous mm */
9160 cpumask_clear_cpu(cpu, mm_cpumask(prev));
9161 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
9162 */
9163 if (unlikely(prev->context.ldt != next->context.ldt))
9164 load_LDT_nolock(&next->context);
9165 - }
9166 +
9167 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
9168 + if (!(__supported_pte_mask & _PAGE_NX)) {
9169 + smp_mb__before_clear_bit();
9170 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
9171 + smp_mb__after_clear_bit();
9172 + cpu_set(cpu, next->context.cpu_user_cs_mask);
9173 + }
9174 +#endif
9175 +
9176 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9177 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
9178 + prev->context.user_cs_limit != next->context.user_cs_limit))
9179 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9180 #ifdef CONFIG_SMP
9181 + else if (unlikely(tlbstate != TLBSTATE_OK))
9182 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9183 +#endif
9184 +#endif
9185 +
9186 + }
9187 else {
9188 +
9189 +#ifdef CONFIG_PAX_PER_CPU_PGD
9190 + pax_open_kernel();
9191 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd, USER_PGD_PTRS);
9192 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd, USER_PGD_PTRS);
9193 + pax_close_kernel();
9194 + load_cr3(get_cpu_pgd(cpu));
9195 +#endif
9196 +
9197 +#ifdef CONFIG_SMP
9198 percpu_write(cpu_tlbstate.state, TLBSTATE_OK);
9199 BUG_ON(percpu_read(cpu_tlbstate.active_mm) != next);
9200
9201 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
9202 * tlb flush IPI delivery. We must reload CR3
9203 * to make sure to use no freed page tables.
9204 */
9205 +
9206 +#ifndef CONFIG_PAX_PER_CPU_PGD
9207 load_cr3(next->pgd);
9208 +#endif
9209 +
9210 load_LDT_nolock(&next->context);
9211 +
9212 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
9213 + if (!(__supported_pte_mask & _PAGE_NX))
9214 + cpu_set(cpu, next->context.cpu_user_cs_mask);
9215 +#endif
9216 +
9217 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
9218 +#ifdef CONFIG_PAX_PAGEEXEC
9219 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
9220 +#endif
9221 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
9222 +#endif
9223 +
9224 }
9225 +#endif
9226 }
9227 -#endif
9228 }
9229
9230 #define activate_mm(prev, next) \
9231 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
9232 index 9eae775..c914fea 100644
9233 --- a/arch/x86/include/asm/module.h
9234 +++ b/arch/x86/include/asm/module.h
9235 @@ -5,6 +5,7 @@
9236
9237 #ifdef CONFIG_X86_64
9238 /* X86_64 does not define MODULE_PROC_FAMILY */
9239 +#define MODULE_PROC_FAMILY ""
9240 #elif defined CONFIG_M386
9241 #define MODULE_PROC_FAMILY "386 "
9242 #elif defined CONFIG_M486
9243 @@ -59,8 +60,20 @@
9244 #error unknown processor family
9245 #endif
9246
9247 -#ifdef CONFIG_X86_32
9248 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
9249 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9250 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
9251 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
9252 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
9253 +#else
9254 +#define MODULE_PAX_KERNEXEC ""
9255 #endif
9256
9257 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9258 +#define MODULE_PAX_UDEREF "UDEREF "
9259 +#else
9260 +#define MODULE_PAX_UDEREF ""
9261 +#endif
9262 +
9263 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
9264 +
9265 #endif /* _ASM_X86_MODULE_H */
9266 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
9267 index 7639dbf..e08a58c 100644
9268 --- a/arch/x86/include/asm/page_64_types.h
9269 +++ b/arch/x86/include/asm/page_64_types.h
9270 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
9271
9272 /* duplicated to the one in bootmem.h */
9273 extern unsigned long max_pfn;
9274 -extern unsigned long phys_base;
9275 +extern const unsigned long phys_base;
9276
9277 extern unsigned long __phys_addr(unsigned long);
9278 #define __phys_reloc_hide(x) (x)
9279 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
9280 index a7d2db9..edb023e 100644
9281 --- a/arch/x86/include/asm/paravirt.h
9282 +++ b/arch/x86/include/asm/paravirt.h
9283 @@ -667,6 +667,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
9284 val);
9285 }
9286
9287 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
9288 +{
9289 + pgdval_t val = native_pgd_val(pgd);
9290 +
9291 + if (sizeof(pgdval_t) > sizeof(long))
9292 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
9293 + val, (u64)val >> 32);
9294 + else
9295 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
9296 + val);
9297 +}
9298 +
9299 static inline void pgd_clear(pgd_t *pgdp)
9300 {
9301 set_pgd(pgdp, __pgd(0));
9302 @@ -748,6 +760,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
9303 pv_mmu_ops.set_fixmap(idx, phys, flags);
9304 }
9305
9306 +#ifdef CONFIG_PAX_KERNEXEC
9307 +static inline unsigned long pax_open_kernel(void)
9308 +{
9309 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
9310 +}
9311 +
9312 +static inline unsigned long pax_close_kernel(void)
9313 +{
9314 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
9315 +}
9316 +#else
9317 +static inline unsigned long pax_open_kernel(void) { return 0; }
9318 +static inline unsigned long pax_close_kernel(void) { return 0; }
9319 +#endif
9320 +
9321 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
9322
9323 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
9324 @@ -964,7 +991,7 @@ extern void default_banner(void);
9325
9326 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
9327 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
9328 -#define PARA_INDIRECT(addr) *%cs:addr
9329 +#define PARA_INDIRECT(addr) *%ss:addr
9330 #endif
9331
9332 #define INTERRUPT_RETURN \
9333 @@ -1041,6 +1068,21 @@ extern void default_banner(void);
9334 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
9335 CLBR_NONE, \
9336 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
9337 +
9338 +#define GET_CR0_INTO_RDI \
9339 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
9340 + mov %rax,%rdi
9341 +
9342 +#define SET_RDI_INTO_CR0 \
9343 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
9344 +
9345 +#define GET_CR3_INTO_RDI \
9346 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
9347 + mov %rax,%rdi
9348 +
9349 +#define SET_RDI_INTO_CR3 \
9350 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
9351 +
9352 #endif /* CONFIG_X86_32 */
9353
9354 #endif /* __ASSEMBLY__ */
9355 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
9356 index 8e8b9a4..f07d725 100644
9357 --- a/arch/x86/include/asm/paravirt_types.h
9358 +++ b/arch/x86/include/asm/paravirt_types.h
9359 @@ -84,20 +84,20 @@ struct pv_init_ops {
9360 */
9361 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
9362 unsigned long addr, unsigned len);
9363 -};
9364 +} __no_const;
9365
9366
9367 struct pv_lazy_ops {
9368 /* Set deferred update mode, used for batching operations. */
9369 void (*enter)(void);
9370 void (*leave)(void);
9371 -};
9372 +} __no_const;
9373
9374 struct pv_time_ops {
9375 unsigned long long (*sched_clock)(void);
9376 unsigned long long (*steal_clock)(int cpu);
9377 unsigned long (*get_tsc_khz)(void);
9378 -};
9379 +} __no_const;
9380
9381 struct pv_cpu_ops {
9382 /* hooks for various privileged instructions */
9383 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
9384
9385 void (*start_context_switch)(struct task_struct *prev);
9386 void (*end_context_switch)(struct task_struct *next);
9387 -};
9388 +} __no_const;
9389
9390 struct pv_irq_ops {
9391 /*
9392 @@ -224,7 +224,7 @@ struct pv_apic_ops {
9393 unsigned long start_eip,
9394 unsigned long start_esp);
9395 #endif
9396 -};
9397 +} __no_const;
9398
9399 struct pv_mmu_ops {
9400 unsigned long (*read_cr2)(void);
9401 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
9402 struct paravirt_callee_save make_pud;
9403
9404 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
9405 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
9406 #endif /* PAGETABLE_LEVELS == 4 */
9407 #endif /* PAGETABLE_LEVELS >= 3 */
9408
9409 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
9410 an mfn. We can tell which is which from the index. */
9411 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
9412 phys_addr_t phys, pgprot_t flags);
9413 +
9414 +#ifdef CONFIG_PAX_KERNEXEC
9415 + unsigned long (*pax_open_kernel)(void);
9416 + unsigned long (*pax_close_kernel)(void);
9417 +#endif
9418 +
9419 };
9420
9421 struct arch_spinlock;
9422 @@ -334,7 +341,7 @@ struct pv_lock_ops {
9423 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
9424 int (*spin_trylock)(struct arch_spinlock *lock);
9425 void (*spin_unlock)(struct arch_spinlock *lock);
9426 -};
9427 +} __no_const;
9428
9429 /* This contains all the paravirt structures: we get a convenient
9430 * number for each function using the offset which we use to indicate
9431 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
9432 index b4389a4..b7ff22c 100644
9433 --- a/arch/x86/include/asm/pgalloc.h
9434 +++ b/arch/x86/include/asm/pgalloc.h
9435 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
9436 pmd_t *pmd, pte_t *pte)
9437 {
9438 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9439 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
9440 +}
9441 +
9442 +static inline void pmd_populate_user(struct mm_struct *mm,
9443 + pmd_t *pmd, pte_t *pte)
9444 +{
9445 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
9446 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
9447 }
9448
9449 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
9450 index 98391db..8f6984e 100644
9451 --- a/arch/x86/include/asm/pgtable-2level.h
9452 +++ b/arch/x86/include/asm/pgtable-2level.h
9453 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
9454
9455 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9456 {
9457 + pax_open_kernel();
9458 *pmdp = pmd;
9459 + pax_close_kernel();
9460 }
9461
9462 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9463 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
9464 index effff47..f9e4035 100644
9465 --- a/arch/x86/include/asm/pgtable-3level.h
9466 +++ b/arch/x86/include/asm/pgtable-3level.h
9467 @@ -38,12 +38,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9468
9469 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9470 {
9471 + pax_open_kernel();
9472 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
9473 + pax_close_kernel();
9474 }
9475
9476 static inline void native_set_pud(pud_t *pudp, pud_t pud)
9477 {
9478 + pax_open_kernel();
9479 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
9480 + pax_close_kernel();
9481 }
9482
9483 /*
9484 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
9485 index 18601c8..3d716d1 100644
9486 --- a/arch/x86/include/asm/pgtable.h
9487 +++ b/arch/x86/include/asm/pgtable.h
9488 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
9489
9490 #ifndef __PAGETABLE_PUD_FOLDED
9491 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
9492 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
9493 #define pgd_clear(pgd) native_pgd_clear(pgd)
9494 #endif
9495
9496 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
9497
9498 #define arch_end_context_switch(prev) do {} while(0)
9499
9500 +#define pax_open_kernel() native_pax_open_kernel()
9501 +#define pax_close_kernel() native_pax_close_kernel()
9502 #endif /* CONFIG_PARAVIRT */
9503
9504 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
9505 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
9506 +
9507 +#ifdef CONFIG_PAX_KERNEXEC
9508 +static inline unsigned long native_pax_open_kernel(void)
9509 +{
9510 + unsigned long cr0;
9511 +
9512 + preempt_disable();
9513 + barrier();
9514 + cr0 = read_cr0() ^ X86_CR0_WP;
9515 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
9516 + write_cr0(cr0);
9517 + return cr0 ^ X86_CR0_WP;
9518 +}
9519 +
9520 +static inline unsigned long native_pax_close_kernel(void)
9521 +{
9522 + unsigned long cr0;
9523 +
9524 + cr0 = read_cr0() ^ X86_CR0_WP;
9525 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
9526 + write_cr0(cr0);
9527 + barrier();
9528 + preempt_enable_no_resched();
9529 + return cr0 ^ X86_CR0_WP;
9530 +}
9531 +#else
9532 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
9533 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
9534 +#endif
9535 +
9536 /*
9537 * The following only work if pte_present() is true.
9538 * Undefined behaviour if not..
9539 */
9540 +static inline int pte_user(pte_t pte)
9541 +{
9542 + return pte_val(pte) & _PAGE_USER;
9543 +}
9544 +
9545 static inline int pte_dirty(pte_t pte)
9546 {
9547 return pte_flags(pte) & _PAGE_DIRTY;
9548 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
9549 return pte_clear_flags(pte, _PAGE_RW);
9550 }
9551
9552 +static inline pte_t pte_mkread(pte_t pte)
9553 +{
9554 + return __pte(pte_val(pte) | _PAGE_USER);
9555 +}
9556 +
9557 static inline pte_t pte_mkexec(pte_t pte)
9558 {
9559 - return pte_clear_flags(pte, _PAGE_NX);
9560 +#ifdef CONFIG_X86_PAE
9561 + if (__supported_pte_mask & _PAGE_NX)
9562 + return pte_clear_flags(pte, _PAGE_NX);
9563 + else
9564 +#endif
9565 + return pte_set_flags(pte, _PAGE_USER);
9566 +}
9567 +
9568 +static inline pte_t pte_exprotect(pte_t pte)
9569 +{
9570 +#ifdef CONFIG_X86_PAE
9571 + if (__supported_pte_mask & _PAGE_NX)
9572 + return pte_set_flags(pte, _PAGE_NX);
9573 + else
9574 +#endif
9575 + return pte_clear_flags(pte, _PAGE_USER);
9576 }
9577
9578 static inline pte_t pte_mkdirty(pte_t pte)
9579 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
9580 #endif
9581
9582 #ifndef __ASSEMBLY__
9583 +
9584 +#ifdef CONFIG_PAX_PER_CPU_PGD
9585 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
9586 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
9587 +{
9588 + return cpu_pgd[cpu];
9589 +}
9590 +#endif
9591 +
9592 #include <linux/mm_types.h>
9593
9594 static inline int pte_none(pte_t pte)
9595 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
9596
9597 static inline int pgd_bad(pgd_t pgd)
9598 {
9599 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
9600 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
9601 }
9602
9603 static inline int pgd_none(pgd_t pgd)
9604 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
9605 * pgd_offset() returns a (pgd_t *)
9606 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
9607 */
9608 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
9609 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
9610 +
9611 +#ifdef CONFIG_PAX_PER_CPU_PGD
9612 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
9613 +#endif
9614 +
9615 /*
9616 * a shortcut which implies the use of the kernel's pgd, instead
9617 * of a process's
9618 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
9619 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
9620 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
9621
9622 +#ifdef CONFIG_X86_32
9623 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
9624 +#else
9625 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
9626 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
9627 +
9628 +#ifdef CONFIG_PAX_MEMORY_UDEREF
9629 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
9630 +#else
9631 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
9632 +#endif
9633 +
9634 +#endif
9635 +
9636 #ifndef __ASSEMBLY__
9637
9638 extern int direct_gbpages;
9639 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
9640 * dst and src can be on the same page, but the range must not overlap,
9641 * and must not cross a page boundary.
9642 */
9643 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
9644 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
9645 {
9646 - memcpy(dst, src, count * sizeof(pgd_t));
9647 + pax_open_kernel();
9648 + while (count--)
9649 + *dst++ = *src++;
9650 + pax_close_kernel();
9651 }
9652
9653 +#ifdef CONFIG_PAX_PER_CPU_PGD
9654 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9655 +#endif
9656 +
9657 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
9658 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count);
9659 +#else
9660 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count) {}
9661 +#endif
9662
9663 #include <asm-generic/pgtable.h>
9664 #endif /* __ASSEMBLY__ */
9665 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
9666 index 0c92113..34a77c6 100644
9667 --- a/arch/x86/include/asm/pgtable_32.h
9668 +++ b/arch/x86/include/asm/pgtable_32.h
9669 @@ -25,9 +25,6 @@
9670 struct mm_struct;
9671 struct vm_area_struct;
9672
9673 -extern pgd_t swapper_pg_dir[1024];
9674 -extern pgd_t initial_page_table[1024];
9675 -
9676 static inline void pgtable_cache_init(void) { }
9677 static inline void check_pgt_cache(void) { }
9678 void paging_init(void);
9679 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
9680 # include <asm/pgtable-2level.h>
9681 #endif
9682
9683 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
9684 +extern pgd_t initial_page_table[PTRS_PER_PGD];
9685 +#ifdef CONFIG_X86_PAE
9686 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
9687 +#endif
9688 +
9689 #if defined(CONFIG_HIGHPTE)
9690 #define pte_offset_map(dir, address) \
9691 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
9692 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
9693 /* Clear a kernel PTE and flush it from the TLB */
9694 #define kpte_clear_flush(ptep, vaddr) \
9695 do { \
9696 + pax_open_kernel(); \
9697 pte_clear(&init_mm, (vaddr), (ptep)); \
9698 + pax_close_kernel(); \
9699 __flush_tlb_one((vaddr)); \
9700 } while (0)
9701
9702 @@ -74,6 +79,9 @@ do { \
9703
9704 #endif /* !__ASSEMBLY__ */
9705
9706 +#define HAVE_ARCH_UNMAPPED_AREA
9707 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
9708 +
9709 /*
9710 * kern_addr_valid() is (1) for FLATMEM and (0) for
9711 * SPARSEMEM and DISCONTIGMEM
9712 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
9713 index ed5903b..c7fe163 100644
9714 --- a/arch/x86/include/asm/pgtable_32_types.h
9715 +++ b/arch/x86/include/asm/pgtable_32_types.h
9716 @@ -8,7 +8,7 @@
9717 */
9718 #ifdef CONFIG_X86_PAE
9719 # include <asm/pgtable-3level_types.h>
9720 -# define PMD_SIZE (1UL << PMD_SHIFT)
9721 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
9722 # define PMD_MASK (~(PMD_SIZE - 1))
9723 #else
9724 # include <asm/pgtable-2level_types.h>
9725 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
9726 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
9727 #endif
9728
9729 +#ifdef CONFIG_PAX_KERNEXEC
9730 +#ifndef __ASSEMBLY__
9731 +extern unsigned char MODULES_EXEC_VADDR[];
9732 +extern unsigned char MODULES_EXEC_END[];
9733 +#endif
9734 +#include <asm/boot.h>
9735 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
9736 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
9737 +#else
9738 +#define ktla_ktva(addr) (addr)
9739 +#define ktva_ktla(addr) (addr)
9740 +#endif
9741 +
9742 #define MODULES_VADDR VMALLOC_START
9743 #define MODULES_END VMALLOC_END
9744 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
9745 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
9746 index 975f709..107976d 100644
9747 --- a/arch/x86/include/asm/pgtable_64.h
9748 +++ b/arch/x86/include/asm/pgtable_64.h
9749 @@ -16,10 +16,14 @@
9750
9751 extern pud_t level3_kernel_pgt[512];
9752 extern pud_t level3_ident_pgt[512];
9753 +extern pud_t level3_vmalloc_start_pgt[512];
9754 +extern pud_t level3_vmalloc_end_pgt[512];
9755 +extern pud_t level3_vmemmap_pgt[512];
9756 +extern pud_t level2_vmemmap_pgt[512];
9757 extern pmd_t level2_kernel_pgt[512];
9758 extern pmd_t level2_fixmap_pgt[512];
9759 -extern pmd_t level2_ident_pgt[512];
9760 -extern pgd_t init_level4_pgt[];
9761 +extern pmd_t level2_ident_pgt[512*2];
9762 +extern pgd_t init_level4_pgt[512];
9763
9764 #define swapper_pg_dir init_level4_pgt
9765
9766 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
9767
9768 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
9769 {
9770 + pax_open_kernel();
9771 *pmdp = pmd;
9772 + pax_close_kernel();
9773 }
9774
9775 static inline void native_pmd_clear(pmd_t *pmd)
9776 @@ -107,6 +113,13 @@ static inline void native_pud_clear(pud_t *pud)
9777
9778 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
9779 {
9780 + pax_open_kernel();
9781 + *pgdp = pgd;
9782 + pax_close_kernel();
9783 +}
9784 +
9785 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
9786 +{
9787 *pgdp = pgd;
9788 }
9789
9790 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
9791 index 766ea16..5b96cb3 100644
9792 --- a/arch/x86/include/asm/pgtable_64_types.h
9793 +++ b/arch/x86/include/asm/pgtable_64_types.h
9794 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
9795 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
9796 #define MODULES_END _AC(0xffffffffff000000, UL)
9797 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
9798 +#define MODULES_EXEC_VADDR MODULES_VADDR
9799 +#define MODULES_EXEC_END MODULES_END
9800 +
9801 +#define ktla_ktva(addr) (addr)
9802 +#define ktva_ktla(addr) (addr)
9803
9804 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
9805 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
9806 index 013286a..8b42f4f 100644
9807 --- a/arch/x86/include/asm/pgtable_types.h
9808 +++ b/arch/x86/include/asm/pgtable_types.h
9809 @@ -16,13 +16,12 @@
9810 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
9811 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
9812 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
9813 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
9814 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
9815 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
9816 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
9817 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
9818 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
9819 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
9820 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
9821 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
9822 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
9823 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
9824
9825 /* If _PAGE_BIT_PRESENT is clear, we use these: */
9826 @@ -40,7 +39,6 @@
9827 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
9828 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
9829 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
9830 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
9831 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
9832 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
9833 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
9834 @@ -57,8 +55,10 @@
9835
9836 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
9837 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
9838 -#else
9839 +#elif defined(CONFIG_KMEMCHECK)
9840 #define _PAGE_NX (_AT(pteval_t, 0))
9841 +#else
9842 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
9843 #endif
9844
9845 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
9846 @@ -96,6 +96,9 @@
9847 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
9848 _PAGE_ACCESSED)
9849
9850 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
9851 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
9852 +
9853 #define __PAGE_KERNEL_EXEC \
9854 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
9855 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
9856 @@ -106,7 +109,7 @@
9857 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
9858 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
9859 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
9860 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
9861 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
9862 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
9863 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
9864 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
9865 @@ -168,8 +171,8 @@
9866 * bits are combined, this will alow user to access the high address mapped
9867 * VDSO in the presence of CONFIG_COMPAT_VDSO
9868 */
9869 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
9870 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
9871 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9872 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
9873 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
9874 #endif
9875
9876 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
9877 {
9878 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
9879 }
9880 +#endif
9881
9882 +#if PAGETABLE_LEVELS == 3
9883 +#include <asm-generic/pgtable-nopud.h>
9884 +#endif
9885 +
9886 +#if PAGETABLE_LEVELS == 2
9887 +#include <asm-generic/pgtable-nopmd.h>
9888 +#endif
9889 +
9890 +#ifndef __ASSEMBLY__
9891 #if PAGETABLE_LEVELS > 3
9892 typedef struct { pudval_t pud; } pud_t;
9893
9894 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
9895 return pud.pud;
9896 }
9897 #else
9898 -#include <asm-generic/pgtable-nopud.h>
9899 -
9900 static inline pudval_t native_pud_val(pud_t pud)
9901 {
9902 return native_pgd_val(pud.pgd);
9903 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
9904 return pmd.pmd;
9905 }
9906 #else
9907 -#include <asm-generic/pgtable-nopmd.h>
9908 -
9909 static inline pmdval_t native_pmd_val(pmd_t pmd)
9910 {
9911 return native_pgd_val(pmd.pud.pgd);
9912 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
9913
9914 extern pteval_t __supported_pte_mask;
9915 extern void set_nx(void);
9916 -extern int nx_enabled;
9917
9918 #define pgprot_writecombine pgprot_writecombine
9919 extern pgprot_t pgprot_writecombine(pgprot_t prot);
9920 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
9921 index b650435..eefa566 100644
9922 --- a/arch/x86/include/asm/processor.h
9923 +++ b/arch/x86/include/asm/processor.h
9924 @@ -268,7 +268,7 @@ struct tss_struct {
9925
9926 } ____cacheline_aligned;
9927
9928 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
9929 +extern struct tss_struct init_tss[NR_CPUS];
9930
9931 /*
9932 * Save the original ist values for checking stack pointers during debugging
9933 @@ -860,11 +860,18 @@ static inline void spin_lock_prefetch(const void *x)
9934 */
9935 #define TASK_SIZE PAGE_OFFSET
9936 #define TASK_SIZE_MAX TASK_SIZE
9937 +
9938 +#ifdef CONFIG_PAX_SEGMEXEC
9939 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
9940 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
9941 +#else
9942 #define STACK_TOP TASK_SIZE
9943 -#define STACK_TOP_MAX STACK_TOP
9944 +#endif
9945 +
9946 +#define STACK_TOP_MAX TASK_SIZE
9947
9948 #define INIT_THREAD { \
9949 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
9950 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9951 .vm86_info = NULL, \
9952 .sysenter_cs = __KERNEL_CS, \
9953 .io_bitmap_ptr = NULL, \
9954 @@ -878,7 +885,7 @@ static inline void spin_lock_prefetch(const void *x)
9955 */
9956 #define INIT_TSS { \
9957 .x86_tss = { \
9958 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
9959 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
9960 .ss0 = __KERNEL_DS, \
9961 .ss1 = __KERNEL_CS, \
9962 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
9963 @@ -889,11 +896,7 @@ static inline void spin_lock_prefetch(const void *x)
9964 extern unsigned long thread_saved_pc(struct task_struct *tsk);
9965
9966 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
9967 -#define KSTK_TOP(info) \
9968 -({ \
9969 - unsigned long *__ptr = (unsigned long *)(info); \
9970 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
9971 -})
9972 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
9973
9974 /*
9975 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
9976 @@ -908,7 +911,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
9977 #define task_pt_regs(task) \
9978 ({ \
9979 struct pt_regs *__regs__; \
9980 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
9981 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
9982 __regs__ - 1; \
9983 })
9984
9985 @@ -918,13 +921,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
9986 /*
9987 * User space process size. 47bits minus one guard page.
9988 */
9989 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
9990 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
9991
9992 /* This decides where the kernel will search for a free chunk of vm
9993 * space during mmap's.
9994 */
9995 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
9996 - 0xc0000000 : 0xFFFFe000)
9997 + 0xc0000000 : 0xFFFFf000)
9998
9999 #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
10000 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
10001 @@ -935,11 +938,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
10002 #define STACK_TOP_MAX TASK_SIZE_MAX
10003
10004 #define INIT_THREAD { \
10005 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10006 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10007 }
10008
10009 #define INIT_TSS { \
10010 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
10011 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
10012 }
10013
10014 /*
10015 @@ -961,6 +964,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
10016 */
10017 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
10018
10019 +#ifdef CONFIG_PAX_SEGMEXEC
10020 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
10021 +#endif
10022 +
10023 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
10024
10025 /* Get/set a process' ability to use the timestamp counter instruction */
10026 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
10027 index 3566454..4bdfb8c 100644
10028 --- a/arch/x86/include/asm/ptrace.h
10029 +++ b/arch/x86/include/asm/ptrace.h
10030 @@ -156,28 +156,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
10031 }
10032
10033 /*
10034 - * user_mode_vm(regs) determines whether a register set came from user mode.
10035 + * user_mode(regs) determines whether a register set came from user mode.
10036 * This is true if V8086 mode was enabled OR if the register set was from
10037 * protected mode with RPL-3 CS value. This tricky test checks that with
10038 * one comparison. Many places in the kernel can bypass this full check
10039 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
10040 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
10041 + * be used.
10042 */
10043 -static inline int user_mode(struct pt_regs *regs)
10044 +static inline int user_mode_novm(struct pt_regs *regs)
10045 {
10046 #ifdef CONFIG_X86_32
10047 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
10048 #else
10049 - return !!(regs->cs & 3);
10050 + return !!(regs->cs & SEGMENT_RPL_MASK);
10051 #endif
10052 }
10053
10054 -static inline int user_mode_vm(struct pt_regs *regs)
10055 +static inline int user_mode(struct pt_regs *regs)
10056 {
10057 #ifdef CONFIG_X86_32
10058 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
10059 USER_RPL;
10060 #else
10061 - return user_mode(regs);
10062 + return user_mode_novm(regs);
10063 #endif
10064 }
10065
10066 @@ -193,15 +194,16 @@ static inline int v8086_mode(struct pt_regs *regs)
10067 #ifdef CONFIG_X86_64
10068 static inline bool user_64bit_mode(struct pt_regs *regs)
10069 {
10070 + unsigned long cs = regs->cs & 0xffff;
10071 #ifndef CONFIG_PARAVIRT
10072 /*
10073 * On non-paravirt systems, this is the only long mode CPL 3
10074 * selector. We do not allow long mode selectors in the LDT.
10075 */
10076 - return regs->cs == __USER_CS;
10077 + return cs == __USER_CS;
10078 #else
10079 /* Headers are too twisted for this to go in paravirt.h. */
10080 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
10081 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
10082 #endif
10083 }
10084 #endif
10085 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
10086 index 92f29706..a79cbbb 100644
10087 --- a/arch/x86/include/asm/reboot.h
10088 +++ b/arch/x86/include/asm/reboot.h
10089 @@ -6,19 +6,19 @@
10090 struct pt_regs;
10091
10092 struct machine_ops {
10093 - void (*restart)(char *cmd);
10094 - void (*halt)(void);
10095 - void (*power_off)(void);
10096 + void (* __noreturn restart)(char *cmd);
10097 + void (* __noreturn halt)(void);
10098 + void (* __noreturn power_off)(void);
10099 void (*shutdown)(void);
10100 void (*crash_shutdown)(struct pt_regs *);
10101 - void (*emergency_restart)(void);
10102 -};
10103 + void (* __noreturn emergency_restart)(void);
10104 +} __no_const;
10105
10106 extern struct machine_ops machine_ops;
10107
10108 void native_machine_crash_shutdown(struct pt_regs *regs);
10109 void native_machine_shutdown(void);
10110 -void machine_real_restart(unsigned int type);
10111 +void machine_real_restart(unsigned int type) __noreturn;
10112 /* These must match dispatch_table in reboot_32.S */
10113 #define MRR_BIOS 0
10114 #define MRR_APM 1
10115 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
10116 index 2dbe4a7..ce1db00 100644
10117 --- a/arch/x86/include/asm/rwsem.h
10118 +++ b/arch/x86/include/asm/rwsem.h
10119 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
10120 {
10121 asm volatile("# beginning down_read\n\t"
10122 LOCK_PREFIX _ASM_INC "(%1)\n\t"
10123 +
10124 +#ifdef CONFIG_PAX_REFCOUNT
10125 + "jno 0f\n"
10126 + LOCK_PREFIX _ASM_DEC "(%1)\n"
10127 + "int $4\n0:\n"
10128 + _ASM_EXTABLE(0b, 0b)
10129 +#endif
10130 +
10131 /* adds 0x00000001 */
10132 " jns 1f\n"
10133 " call call_rwsem_down_read_failed\n"
10134 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
10135 "1:\n\t"
10136 " mov %1,%2\n\t"
10137 " add %3,%2\n\t"
10138 +
10139 +#ifdef CONFIG_PAX_REFCOUNT
10140 + "jno 0f\n"
10141 + "sub %3,%2\n"
10142 + "int $4\n0:\n"
10143 + _ASM_EXTABLE(0b, 0b)
10144 +#endif
10145 +
10146 " jle 2f\n\t"
10147 LOCK_PREFIX " cmpxchg %2,%0\n\t"
10148 " jnz 1b\n\t"
10149 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
10150 long tmp;
10151 asm volatile("# beginning down_write\n\t"
10152 LOCK_PREFIX " xadd %1,(%2)\n\t"
10153 +
10154 +#ifdef CONFIG_PAX_REFCOUNT
10155 + "jno 0f\n"
10156 + "mov %1,(%2)\n"
10157 + "int $4\n0:\n"
10158 + _ASM_EXTABLE(0b, 0b)
10159 +#endif
10160 +
10161 /* adds 0xffff0001, returns the old value */
10162 " test %1,%1\n\t"
10163 /* was the count 0 before? */
10164 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
10165 long tmp;
10166 asm volatile("# beginning __up_read\n\t"
10167 LOCK_PREFIX " xadd %1,(%2)\n\t"
10168 +
10169 +#ifdef CONFIG_PAX_REFCOUNT
10170 + "jno 0f\n"
10171 + "mov %1,(%2)\n"
10172 + "int $4\n0:\n"
10173 + _ASM_EXTABLE(0b, 0b)
10174 +#endif
10175 +
10176 /* subtracts 1, returns the old value */
10177 " jns 1f\n\t"
10178 " call call_rwsem_wake\n" /* expects old value in %edx */
10179 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
10180 long tmp;
10181 asm volatile("# beginning __up_write\n\t"
10182 LOCK_PREFIX " xadd %1,(%2)\n\t"
10183 +
10184 +#ifdef CONFIG_PAX_REFCOUNT
10185 + "jno 0f\n"
10186 + "mov %1,(%2)\n"
10187 + "int $4\n0:\n"
10188 + _ASM_EXTABLE(0b, 0b)
10189 +#endif
10190 +
10191 /* subtracts 0xffff0001, returns the old value */
10192 " jns 1f\n\t"
10193 " call call_rwsem_wake\n" /* expects old value in %edx */
10194 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
10195 {
10196 asm volatile("# beginning __downgrade_write\n\t"
10197 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
10198 +
10199 +#ifdef CONFIG_PAX_REFCOUNT
10200 + "jno 0f\n"
10201 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
10202 + "int $4\n0:\n"
10203 + _ASM_EXTABLE(0b, 0b)
10204 +#endif
10205 +
10206 /*
10207 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
10208 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
10209 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
10210 */
10211 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
10212 {
10213 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
10214 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
10215 +
10216 +#ifdef CONFIG_PAX_REFCOUNT
10217 + "jno 0f\n"
10218 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
10219 + "int $4\n0:\n"
10220 + _ASM_EXTABLE(0b, 0b)
10221 +#endif
10222 +
10223 : "+m" (sem->count)
10224 : "er" (delta));
10225 }
10226 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
10227 */
10228 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
10229 {
10230 - return delta + xadd(&sem->count, delta);
10231 + return delta + xadd_check_overflow(&sem->count, delta);
10232 }
10233
10234 #endif /* __KERNEL__ */
10235 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
10236 index 5e64171..f58957e 100644
10237 --- a/arch/x86/include/asm/segment.h
10238 +++ b/arch/x86/include/asm/segment.h
10239 @@ -64,10 +64,15 @@
10240 * 26 - ESPFIX small SS
10241 * 27 - per-cpu [ offset to per-cpu data area ]
10242 * 28 - stack_canary-20 [ for stack protector ]
10243 - * 29 - unused
10244 - * 30 - unused
10245 + * 29 - PCI BIOS CS
10246 + * 30 - PCI BIOS DS
10247 * 31 - TSS for double fault handler
10248 */
10249 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
10250 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
10251 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
10252 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
10253 +
10254 #define GDT_ENTRY_TLS_MIN 6
10255 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
10256
10257 @@ -79,6 +84,8 @@
10258
10259 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
10260
10261 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
10262 +
10263 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
10264
10265 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
10266 @@ -104,6 +111,12 @@
10267 #define __KERNEL_STACK_CANARY 0
10268 #endif
10269
10270 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
10271 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
10272 +
10273 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
10274 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
10275 +
10276 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
10277
10278 /*
10279 @@ -141,7 +154,7 @@
10280 */
10281
10282 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
10283 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
10284 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
10285
10286
10287 #else
10288 @@ -165,6 +178,8 @@
10289 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
10290 #define __USER32_DS __USER_DS
10291
10292 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
10293 +
10294 #define GDT_ENTRY_TSS 8 /* needs two entries */
10295 #define GDT_ENTRY_LDT 10 /* needs two entries */
10296 #define GDT_ENTRY_TLS_MIN 12
10297 @@ -185,6 +200,7 @@
10298 #endif
10299
10300 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
10301 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
10302 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
10303 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
10304 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
10305 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
10306 index 73b11bc..d4a3b63 100644
10307 --- a/arch/x86/include/asm/smp.h
10308 +++ b/arch/x86/include/asm/smp.h
10309 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
10310 /* cpus sharing the last level cache: */
10311 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
10312 DECLARE_PER_CPU(u16, cpu_llc_id);
10313 -DECLARE_PER_CPU(int, cpu_number);
10314 +DECLARE_PER_CPU(unsigned int, cpu_number);
10315
10316 static inline struct cpumask *cpu_sibling_mask(int cpu)
10317 {
10318 @@ -77,7 +77,7 @@ struct smp_ops {
10319
10320 void (*send_call_func_ipi)(const struct cpumask *mask);
10321 void (*send_call_func_single_ipi)(int cpu);
10322 -};
10323 +} __no_const;
10324
10325 /* Globals due to paravirt */
10326 extern void set_cpu_sibling_map(int cpu);
10327 @@ -192,14 +192,8 @@ extern unsigned disabled_cpus __cpuinitdata;
10328 extern int safe_smp_processor_id(void);
10329
10330 #elif defined(CONFIG_X86_64_SMP)
10331 -#define raw_smp_processor_id() (percpu_read(cpu_number))
10332 -
10333 -#define stack_smp_processor_id() \
10334 -({ \
10335 - struct thread_info *ti; \
10336 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
10337 - ti->cpu; \
10338 -})
10339 +#define raw_smp_processor_id() (percpu_read(cpu_number))
10340 +#define stack_smp_processor_id() raw_smp_processor_id()
10341 #define safe_smp_processor_id() smp_processor_id()
10342
10343 #endif
10344 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
10345 index 972c260..43ab1fd 100644
10346 --- a/arch/x86/include/asm/spinlock.h
10347 +++ b/arch/x86/include/asm/spinlock.h
10348 @@ -188,6 +188,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
10349 static inline void arch_read_lock(arch_rwlock_t *rw)
10350 {
10351 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
10352 +
10353 +#ifdef CONFIG_PAX_REFCOUNT
10354 + "jno 0f\n"
10355 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
10356 + "int $4\n0:\n"
10357 + _ASM_EXTABLE(0b, 0b)
10358 +#endif
10359 +
10360 "jns 1f\n"
10361 "call __read_lock_failed\n\t"
10362 "1:\n"
10363 @@ -197,6 +205,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
10364 static inline void arch_write_lock(arch_rwlock_t *rw)
10365 {
10366 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
10367 +
10368 +#ifdef CONFIG_PAX_REFCOUNT
10369 + "jno 0f\n"
10370 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
10371 + "int $4\n0:\n"
10372 + _ASM_EXTABLE(0b, 0b)
10373 +#endif
10374 +
10375 "jz 1f\n"
10376 "call __write_lock_failed\n\t"
10377 "1:\n"
10378 @@ -226,13 +242,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
10379
10380 static inline void arch_read_unlock(arch_rwlock_t *rw)
10381 {
10382 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
10383 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
10384 +
10385 +#ifdef CONFIG_PAX_REFCOUNT
10386 + "jno 0f\n"
10387 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
10388 + "int $4\n0:\n"
10389 + _ASM_EXTABLE(0b, 0b)
10390 +#endif
10391 +
10392 :"+m" (rw->lock) : : "memory");
10393 }
10394
10395 static inline void arch_write_unlock(arch_rwlock_t *rw)
10396 {
10397 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
10398 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
10399 +
10400 +#ifdef CONFIG_PAX_REFCOUNT
10401 + "jno 0f\n"
10402 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
10403 + "int $4\n0:\n"
10404 + _ASM_EXTABLE(0b, 0b)
10405 +#endif
10406 +
10407 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
10408 }
10409
10410 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
10411 index 1575177..cb23f52 100644
10412 --- a/arch/x86/include/asm/stackprotector.h
10413 +++ b/arch/x86/include/asm/stackprotector.h
10414 @@ -48,7 +48,7 @@
10415 * head_32 for boot CPU and setup_per_cpu_areas() for others.
10416 */
10417 #define GDT_STACK_CANARY_INIT \
10418 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
10419 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
10420
10421 /*
10422 * Initialize the stackprotector canary value.
10423 @@ -113,7 +113,7 @@ static inline void setup_stack_canary_segment(int cpu)
10424
10425 static inline void load_stack_canary_segment(void)
10426 {
10427 -#ifdef CONFIG_X86_32
10428 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
10429 asm volatile ("mov %0, %%gs" : : "r" (0));
10430 #endif
10431 }
10432 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
10433 index 70bbe39..4ae2bd4 100644
10434 --- a/arch/x86/include/asm/stacktrace.h
10435 +++ b/arch/x86/include/asm/stacktrace.h
10436 @@ -11,28 +11,20 @@
10437
10438 extern int kstack_depth_to_print;
10439
10440 -struct thread_info;
10441 +struct task_struct;
10442 struct stacktrace_ops;
10443
10444 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
10445 - unsigned long *stack,
10446 - unsigned long bp,
10447 - const struct stacktrace_ops *ops,
10448 - void *data,
10449 - unsigned long *end,
10450 - int *graph);
10451 +typedef unsigned long walk_stack_t(struct task_struct *task,
10452 + void *stack_start,
10453 + unsigned long *stack,
10454 + unsigned long bp,
10455 + const struct stacktrace_ops *ops,
10456 + void *data,
10457 + unsigned long *end,
10458 + int *graph);
10459
10460 -extern unsigned long
10461 -print_context_stack(struct thread_info *tinfo,
10462 - unsigned long *stack, unsigned long bp,
10463 - const struct stacktrace_ops *ops, void *data,
10464 - unsigned long *end, int *graph);
10465 -
10466 -extern unsigned long
10467 -print_context_stack_bp(struct thread_info *tinfo,
10468 - unsigned long *stack, unsigned long bp,
10469 - const struct stacktrace_ops *ops, void *data,
10470 - unsigned long *end, int *graph);
10471 +extern walk_stack_t print_context_stack;
10472 +extern walk_stack_t print_context_stack_bp;
10473
10474 /* Generic stack tracer with callbacks */
10475
10476 @@ -40,7 +32,7 @@ struct stacktrace_ops {
10477 void (*address)(void *data, unsigned long address, int reliable);
10478 /* On negative return stop dumping */
10479 int (*stack)(void *data, char *name);
10480 - walk_stack_t walk_stack;
10481 + walk_stack_t *walk_stack;
10482 };
10483
10484 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
10485 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
10486 index cb23852..2dde194 100644
10487 --- a/arch/x86/include/asm/sys_ia32.h
10488 +++ b/arch/x86/include/asm/sys_ia32.h
10489 @@ -40,7 +40,7 @@ asmlinkage long sys32_rt_sigprocmask(int, compat_sigset_t __user *,
10490 compat_sigset_t __user *, unsigned int);
10491 asmlinkage long sys32_alarm(unsigned int);
10492
10493 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
10494 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
10495 asmlinkage long sys32_sysfs(int, u32, u32);
10496
10497 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
10498 diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
10499 index 2d2f01c..f985723 100644
10500 --- a/arch/x86/include/asm/system.h
10501 +++ b/arch/x86/include/asm/system.h
10502 @@ -129,7 +129,7 @@ do { \
10503 "call __switch_to\n\t" \
10504 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
10505 __switch_canary \
10506 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
10507 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
10508 "movq %%rax,%%rdi\n\t" \
10509 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
10510 "jnz ret_from_fork\n\t" \
10511 @@ -140,7 +140,7 @@ do { \
10512 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
10513 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
10514 [_tif_fork] "i" (_TIF_FORK), \
10515 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
10516 + [thread_info] "m" (current_tinfo), \
10517 [current_task] "m" (current_task) \
10518 __switch_canary_iparam \
10519 : "memory", "cc" __EXTRA_CLOBBER)
10520 @@ -200,7 +200,7 @@ static inline unsigned long get_limit(unsigned long segment)
10521 {
10522 unsigned long __limit;
10523 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
10524 - return __limit + 1;
10525 + return __limit;
10526 }
10527
10528 static inline void native_clts(void)
10529 @@ -397,13 +397,13 @@ void enable_hlt(void);
10530
10531 void cpu_idle_wait(void);
10532
10533 -extern unsigned long arch_align_stack(unsigned long sp);
10534 +#define arch_align_stack(x) ((x) & ~0xfUL)
10535 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
10536
10537 void default_idle(void);
10538 bool set_pm_idle_to_default(void);
10539
10540 -void stop_this_cpu(void *dummy);
10541 +void stop_this_cpu(void *dummy) __noreturn;
10542
10543 /*
10544 * Force strict CPU ordering.
10545 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
10546 index a1fe5c1..ee326d8 100644
10547 --- a/arch/x86/include/asm/thread_info.h
10548 +++ b/arch/x86/include/asm/thread_info.h
10549 @@ -10,6 +10,7 @@
10550 #include <linux/compiler.h>
10551 #include <asm/page.h>
10552 #include <asm/types.h>
10553 +#include <asm/percpu.h>
10554
10555 /*
10556 * low level task data that entry.S needs immediate access to
10557 @@ -24,7 +25,6 @@ struct exec_domain;
10558 #include <linux/atomic.h>
10559
10560 struct thread_info {
10561 - struct task_struct *task; /* main task structure */
10562 struct exec_domain *exec_domain; /* execution domain */
10563 __u32 flags; /* low level flags */
10564 __u32 status; /* thread synchronous flags */
10565 @@ -34,18 +34,12 @@ struct thread_info {
10566 mm_segment_t addr_limit;
10567 struct restart_block restart_block;
10568 void __user *sysenter_return;
10569 -#ifdef CONFIG_X86_32
10570 - unsigned long previous_esp; /* ESP of the previous stack in
10571 - case of nested (IRQ) stacks
10572 - */
10573 - __u8 supervisor_stack[0];
10574 -#endif
10575 + unsigned long lowest_stack;
10576 int uaccess_err;
10577 };
10578
10579 -#define INIT_THREAD_INFO(tsk) \
10580 +#define INIT_THREAD_INFO \
10581 { \
10582 - .task = &tsk, \
10583 .exec_domain = &default_exec_domain, \
10584 .flags = 0, \
10585 .cpu = 0, \
10586 @@ -56,7 +50,7 @@ struct thread_info {
10587 }, \
10588 }
10589
10590 -#define init_thread_info (init_thread_union.thread_info)
10591 +#define init_thread_info (init_thread_union.stack)
10592 #define init_stack (init_thread_union.stack)
10593
10594 #else /* !__ASSEMBLY__ */
10595 @@ -170,45 +164,40 @@ struct thread_info {
10596 ret; \
10597 })
10598
10599 -#ifdef CONFIG_X86_32
10600 -
10601 -#define STACK_WARN (THREAD_SIZE/8)
10602 -/*
10603 - * macros/functions for gaining access to the thread information structure
10604 - *
10605 - * preempt_count needs to be 1 initially, until the scheduler is functional.
10606 - */
10607 -#ifndef __ASSEMBLY__
10608 -
10609 -
10610 -/* how to get the current stack pointer from C */
10611 -register unsigned long current_stack_pointer asm("esp") __used;
10612 -
10613 -/* how to get the thread information struct from C */
10614 -static inline struct thread_info *current_thread_info(void)
10615 -{
10616 - return (struct thread_info *)
10617 - (current_stack_pointer & ~(THREAD_SIZE - 1));
10618 -}
10619 -
10620 -#else /* !__ASSEMBLY__ */
10621 -
10622 +#ifdef __ASSEMBLY__
10623 /* how to get the thread information struct from ASM */
10624 #define GET_THREAD_INFO(reg) \
10625 - movl $-THREAD_SIZE, reg; \
10626 - andl %esp, reg
10627 + mov PER_CPU_VAR(current_tinfo), reg
10628
10629 /* use this one if reg already contains %esp */
10630 -#define GET_THREAD_INFO_WITH_ESP(reg) \
10631 - andl $-THREAD_SIZE, reg
10632 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
10633 +#else
10634 +/* how to get the thread information struct from C */
10635 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
10636 +
10637 +static __always_inline struct thread_info *current_thread_info(void)
10638 +{
10639 + return percpu_read_stable(current_tinfo);
10640 +}
10641 +#endif
10642 +
10643 +#ifdef CONFIG_X86_32
10644 +
10645 +#define STACK_WARN (THREAD_SIZE/8)
10646 +/*
10647 + * macros/functions for gaining access to the thread information structure
10648 + *
10649 + * preempt_count needs to be 1 initially, until the scheduler is functional.
10650 + */
10651 +#ifndef __ASSEMBLY__
10652 +
10653 +/* how to get the current stack pointer from C */
10654 +register unsigned long current_stack_pointer asm("esp") __used;
10655
10656 #endif
10657
10658 #else /* X86_32 */
10659
10660 -#include <asm/percpu.h>
10661 -#define KERNEL_STACK_OFFSET (5*8)
10662 -
10663 /*
10664 * macros/functions for gaining access to the thread information structure
10665 * preempt_count needs to be 1 initially, until the scheduler is functional.
10666 @@ -216,21 +205,8 @@ static inline struct thread_info *current_thread_info(void)
10667 #ifndef __ASSEMBLY__
10668 DECLARE_PER_CPU(unsigned long, kernel_stack);
10669
10670 -static inline struct thread_info *current_thread_info(void)
10671 -{
10672 - struct thread_info *ti;
10673 - ti = (void *)(percpu_read_stable(kernel_stack) +
10674 - KERNEL_STACK_OFFSET - THREAD_SIZE);
10675 - return ti;
10676 -}
10677 -
10678 -#else /* !__ASSEMBLY__ */
10679 -
10680 -/* how to get the thread information struct from ASM */
10681 -#define GET_THREAD_INFO(reg) \
10682 - movq PER_CPU_VAR(kernel_stack),reg ; \
10683 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
10684 -
10685 +/* how to get the current stack pointer from C */
10686 +register unsigned long current_stack_pointer asm("rsp") __used;
10687 #endif
10688
10689 #endif /* !X86_32 */
10690 @@ -266,5 +242,16 @@ extern void arch_task_cache_init(void);
10691 extern void free_thread_info(struct thread_info *ti);
10692 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
10693 #define arch_task_cache_init arch_task_cache_init
10694 +
10695 +#define __HAVE_THREAD_FUNCTIONS
10696 +#define task_thread_info(task) (&(task)->tinfo)
10697 +#define task_stack_page(task) ((task)->stack)
10698 +#define setup_thread_stack(p, org) do {} while (0)
10699 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
10700 +
10701 +#define __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
10702 +extern struct task_struct *alloc_task_struct_node(int node);
10703 +extern void free_task_struct(struct task_struct *);
10704 +
10705 #endif
10706 #endif /* _ASM_X86_THREAD_INFO_H */
10707 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
10708 index 36361bf..324f262 100644
10709 --- a/arch/x86/include/asm/uaccess.h
10710 +++ b/arch/x86/include/asm/uaccess.h
10711 @@ -7,12 +7,15 @@
10712 #include <linux/compiler.h>
10713 #include <linux/thread_info.h>
10714 #include <linux/string.h>
10715 +#include <linux/sched.h>
10716 #include <asm/asm.h>
10717 #include <asm/page.h>
10718
10719 #define VERIFY_READ 0
10720 #define VERIFY_WRITE 1
10721
10722 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
10723 +
10724 /*
10725 * The fs value determines whether argument validity checking should be
10726 * performed or not. If get_fs() == USER_DS, checking is performed, with
10727 @@ -28,7 +31,12 @@
10728
10729 #define get_ds() (KERNEL_DS)
10730 #define get_fs() (current_thread_info()->addr_limit)
10731 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10732 +void __set_fs(mm_segment_t x);
10733 +void set_fs(mm_segment_t x);
10734 +#else
10735 #define set_fs(x) (current_thread_info()->addr_limit = (x))
10736 +#endif
10737
10738 #define segment_eq(a, b) ((a).seg == (b).seg)
10739
10740 @@ -76,7 +84,33 @@
10741 * checks that the pointer is in the user space range - after calling
10742 * this function, memory access functions may still return -EFAULT.
10743 */
10744 -#define access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10745 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size) == 0))
10746 +#define access_ok(type, addr, size) \
10747 +({ \
10748 + long __size = size; \
10749 + unsigned long __addr = (unsigned long)addr; \
10750 + unsigned long __addr_ao = __addr & PAGE_MASK; \
10751 + unsigned long __end_ao = __addr + __size - 1; \
10752 + bool __ret_ao = __range_not_ok(__addr, __size) == 0; \
10753 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
10754 + while(__addr_ao <= __end_ao) { \
10755 + char __c_ao; \
10756 + __addr_ao += PAGE_SIZE; \
10757 + if (__size > PAGE_SIZE) \
10758 + cond_resched(); \
10759 + if (__get_user(__c_ao, (char __user *)__addr)) \
10760 + break; \
10761 + if (type != VERIFY_WRITE) { \
10762 + __addr = __addr_ao; \
10763 + continue; \
10764 + } \
10765 + if (__put_user(__c_ao, (char __user *)__addr)) \
10766 + break; \
10767 + __addr = __addr_ao; \
10768 + } \
10769 + } \
10770 + __ret_ao; \
10771 +})
10772
10773 /*
10774 * The exception table consists of pairs of addresses: the first is the
10775 @@ -182,12 +216,20 @@ extern int __get_user_bad(void);
10776 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
10777 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
10778
10779 -
10780 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
10781 +#define __copyuser_seg "gs;"
10782 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
10783 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
10784 +#else
10785 +#define __copyuser_seg
10786 +#define __COPYUSER_SET_ES
10787 +#define __COPYUSER_RESTORE_ES
10788 +#endif
10789
10790 #ifdef CONFIG_X86_32
10791 #define __put_user_asm_u64(x, addr, err, errret) \
10792 - asm volatile("1: movl %%eax,0(%2)\n" \
10793 - "2: movl %%edx,4(%2)\n" \
10794 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
10795 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
10796 "3:\n" \
10797 ".section .fixup,\"ax\"\n" \
10798 "4: movl %3,%0\n" \
10799 @@ -199,8 +241,8 @@ extern int __get_user_bad(void);
10800 : "A" (x), "r" (addr), "i" (errret), "0" (err))
10801
10802 #define __put_user_asm_ex_u64(x, addr) \
10803 - asm volatile("1: movl %%eax,0(%1)\n" \
10804 - "2: movl %%edx,4(%1)\n" \
10805 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
10806 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
10807 "3:\n" \
10808 _ASM_EXTABLE(1b, 2b - 1b) \
10809 _ASM_EXTABLE(2b, 3b - 2b) \
10810 @@ -252,7 +294,7 @@ extern void __put_user_8(void);
10811 __typeof__(*(ptr)) __pu_val; \
10812 __chk_user_ptr(ptr); \
10813 might_fault(); \
10814 - __pu_val = x; \
10815 + __pu_val = (x); \
10816 switch (sizeof(*(ptr))) { \
10817 case 1: \
10818 __put_user_x(1, __pu_val, ptr, __ret_pu); \
10819 @@ -373,7 +415,7 @@ do { \
10820 } while (0)
10821
10822 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10823 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
10824 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
10825 "2:\n" \
10826 ".section .fixup,\"ax\"\n" \
10827 "3: mov %3,%0\n" \
10828 @@ -381,7 +423,7 @@ do { \
10829 " jmp 2b\n" \
10830 ".previous\n" \
10831 _ASM_EXTABLE(1b, 3b) \
10832 - : "=r" (err), ltype(x) \
10833 + : "=r" (err), ltype (x) \
10834 : "m" (__m(addr)), "i" (errret), "0" (err))
10835
10836 #define __get_user_size_ex(x, ptr, size) \
10837 @@ -406,7 +448,7 @@ do { \
10838 } while (0)
10839
10840 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
10841 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
10842 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
10843 "2:\n" \
10844 _ASM_EXTABLE(1b, 2b - 1b) \
10845 : ltype(x) : "m" (__m(addr)))
10846 @@ -423,13 +465,24 @@ do { \
10847 int __gu_err; \
10848 unsigned long __gu_val; \
10849 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
10850 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
10851 + (x) = (__typeof__(*(ptr)))__gu_val; \
10852 __gu_err; \
10853 })
10854
10855 /* FIXME: this hack is definitely wrong -AK */
10856 struct __large_struct { unsigned long buf[100]; };
10857 -#define __m(x) (*(struct __large_struct __user *)(x))
10858 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10859 +#define ____m(x) \
10860 +({ \
10861 + unsigned long ____x = (unsigned long)(x); \
10862 + if (____x < PAX_USER_SHADOW_BASE) \
10863 + ____x += PAX_USER_SHADOW_BASE; \
10864 + (void __user *)____x; \
10865 +})
10866 +#else
10867 +#define ____m(x) (x)
10868 +#endif
10869 +#define __m(x) (*(struct __large_struct __user *)____m(x))
10870
10871 /*
10872 * Tell gcc we read from memory instead of writing: this is because
10873 @@ -437,7 +490,7 @@ struct __large_struct { unsigned long buf[100]; };
10874 * aliasing issues.
10875 */
10876 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
10877 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
10878 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
10879 "2:\n" \
10880 ".section .fixup,\"ax\"\n" \
10881 "3: mov %3,%0\n" \
10882 @@ -445,10 +498,10 @@ struct __large_struct { unsigned long buf[100]; };
10883 ".previous\n" \
10884 _ASM_EXTABLE(1b, 3b) \
10885 : "=r"(err) \
10886 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
10887 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
10888
10889 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
10890 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
10891 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
10892 "2:\n" \
10893 _ASM_EXTABLE(1b, 2b - 1b) \
10894 : : ltype(x), "m" (__m(addr)))
10895 @@ -487,8 +540,12 @@ struct __large_struct { unsigned long buf[100]; };
10896 * On error, the variable @x is set to zero.
10897 */
10898
10899 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10900 +#define __get_user(x, ptr) get_user((x), (ptr))
10901 +#else
10902 #define __get_user(x, ptr) \
10903 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
10904 +#endif
10905
10906 /**
10907 * __put_user: - Write a simple value into user space, with less checking.
10908 @@ -510,8 +567,12 @@ struct __large_struct { unsigned long buf[100]; };
10909 * Returns zero on success, or -EFAULT on error.
10910 */
10911
10912 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10913 +#define __put_user(x, ptr) put_user((x), (ptr))
10914 +#else
10915 #define __put_user(x, ptr) \
10916 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
10917 +#endif
10918
10919 #define __get_user_unaligned __get_user
10920 #define __put_user_unaligned __put_user
10921 @@ -529,7 +590,7 @@ struct __large_struct { unsigned long buf[100]; };
10922 #define get_user_ex(x, ptr) do { \
10923 unsigned long __gue_val; \
10924 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
10925 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
10926 + (x) = (__typeof__(*(ptr)))__gue_val; \
10927 } while (0)
10928
10929 #ifdef CONFIG_X86_WP_WORKS_OK
10930 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
10931 index 566e803..b9521e9 100644
10932 --- a/arch/x86/include/asm/uaccess_32.h
10933 +++ b/arch/x86/include/asm/uaccess_32.h
10934 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
10935 static __always_inline unsigned long __must_check
10936 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10937 {
10938 + if ((long)n < 0)
10939 + return n;
10940 +
10941 if (__builtin_constant_p(n)) {
10942 unsigned long ret;
10943
10944 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
10945 return ret;
10946 }
10947 }
10948 + if (!__builtin_constant_p(n))
10949 + check_object_size(from, n, true);
10950 return __copy_to_user_ll(to, from, n);
10951 }
10952
10953 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
10954 __copy_to_user(void __user *to, const void *from, unsigned long n)
10955 {
10956 might_fault();
10957 +
10958 return __copy_to_user_inatomic(to, from, n);
10959 }
10960
10961 static __always_inline unsigned long
10962 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
10963 {
10964 + if ((long)n < 0)
10965 + return n;
10966 +
10967 /* Avoid zeroing the tail if the copy fails..
10968 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
10969 * but as the zeroing behaviour is only significant when n is not
10970 @@ -137,6 +146,10 @@ static __always_inline unsigned long
10971 __copy_from_user(void *to, const void __user *from, unsigned long n)
10972 {
10973 might_fault();
10974 +
10975 + if ((long)n < 0)
10976 + return n;
10977 +
10978 if (__builtin_constant_p(n)) {
10979 unsigned long ret;
10980
10981 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
10982 return ret;
10983 }
10984 }
10985 + if (!__builtin_constant_p(n))
10986 + check_object_size(to, n, false);
10987 return __copy_from_user_ll(to, from, n);
10988 }
10989
10990 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
10991 const void __user *from, unsigned long n)
10992 {
10993 might_fault();
10994 +
10995 + if ((long)n < 0)
10996 + return n;
10997 +
10998 if (__builtin_constant_p(n)) {
10999 unsigned long ret;
11000
11001 @@ -181,15 +200,19 @@ static __always_inline unsigned long
11002 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
11003 unsigned long n)
11004 {
11005 - return __copy_from_user_ll_nocache_nozero(to, from, n);
11006 + if ((long)n < 0)
11007 + return n;
11008 +
11009 + return __copy_from_user_ll_nocache_nozero(to, from, n);
11010 }
11011
11012 -unsigned long __must_check copy_to_user(void __user *to,
11013 - const void *from, unsigned long n);
11014 -unsigned long __must_check _copy_from_user(void *to,
11015 - const void __user *from,
11016 - unsigned long n);
11017 -
11018 +extern void copy_to_user_overflow(void)
11019 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11020 + __compiletime_error("copy_to_user() buffer size is not provably correct")
11021 +#else
11022 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
11023 +#endif
11024 +;
11025
11026 extern void copy_from_user_overflow(void)
11027 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
11028 @@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
11029 #endif
11030 ;
11031
11032 -static inline unsigned long __must_check copy_from_user(void *to,
11033 - const void __user *from,
11034 - unsigned long n)
11035 +/**
11036 + * copy_to_user: - Copy a block of data into user space.
11037 + * @to: Destination address, in user space.
11038 + * @from: Source address, in kernel space.
11039 + * @n: Number of bytes to copy.
11040 + *
11041 + * Context: User context only. This function may sleep.
11042 + *
11043 + * Copy data from kernel space to user space.
11044 + *
11045 + * Returns number of bytes that could not be copied.
11046 + * On success, this will be zero.
11047 + */
11048 +static inline unsigned long __must_check
11049 +copy_to_user(void __user *to, const void *from, unsigned long n)
11050 +{
11051 + int sz = __compiletime_object_size(from);
11052 +
11053 + if (unlikely(sz != -1 && sz < n))
11054 + copy_to_user_overflow();
11055 + else if (access_ok(VERIFY_WRITE, to, n))
11056 + n = __copy_to_user(to, from, n);
11057 + return n;
11058 +}
11059 +
11060 +/**
11061 + * copy_from_user: - Copy a block of data from user space.
11062 + * @to: Destination address, in kernel space.
11063 + * @from: Source address, in user space.
11064 + * @n: Number of bytes to copy.
11065 + *
11066 + * Context: User context only. This function may sleep.
11067 + *
11068 + * Copy data from user space to kernel space.
11069 + *
11070 + * Returns number of bytes that could not be copied.
11071 + * On success, this will be zero.
11072 + *
11073 + * If some data could not be copied, this function will pad the copied
11074 + * data to the requested size using zero bytes.
11075 + */
11076 +static inline unsigned long __must_check
11077 +copy_from_user(void *to, const void __user *from, unsigned long n)
11078 {
11079 int sz = __compiletime_object_size(to);
11080
11081 - if (likely(sz == -1 || sz >= n))
11082 - n = _copy_from_user(to, from, n);
11083 - else
11084 + if (unlikely(sz != -1 && sz < n))
11085 copy_from_user_overflow();
11086 -
11087 + else if (access_ok(VERIFY_READ, from, n))
11088 + n = __copy_from_user(to, from, n);
11089 + else if ((long)n > 0) {
11090 + if (!__builtin_constant_p(n))
11091 + check_object_size(to, n, false);
11092 + memset(to, 0, n);
11093 + }
11094 return n;
11095 }
11096
11097 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
11098 index 1c66d30..e66922c 100644
11099 --- a/arch/x86/include/asm/uaccess_64.h
11100 +++ b/arch/x86/include/asm/uaccess_64.h
11101 @@ -10,6 +10,9 @@
11102 #include <asm/alternative.h>
11103 #include <asm/cpufeature.h>
11104 #include <asm/page.h>
11105 +#include <asm/pgtable.h>
11106 +
11107 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
11108
11109 /*
11110 * Copy To/From Userspace
11111 @@ -17,12 +20,12 @@
11112
11113 /* Handles exceptions in both to and from, but doesn't do access_ok */
11114 __must_check unsigned long
11115 -copy_user_generic_string(void *to, const void *from, unsigned len);
11116 +copy_user_generic_string(void *to, const void *from, unsigned long len);
11117 __must_check unsigned long
11118 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
11119 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len);
11120
11121 static __always_inline __must_check unsigned long
11122 -copy_user_generic(void *to, const void *from, unsigned len)
11123 +copy_user_generic(void *to, const void *from, unsigned long len)
11124 {
11125 unsigned ret;
11126
11127 @@ -32,142 +35,226 @@ copy_user_generic(void *to, const void *from, unsigned len)
11128 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
11129 "=d" (len)),
11130 "1" (to), "2" (from), "3" (len)
11131 - : "memory", "rcx", "r8", "r9", "r10", "r11");
11132 + : "memory", "rcx", "r8", "r9", "r11");
11133 return ret;
11134 }
11135
11136 +static __always_inline __must_check unsigned long
11137 +__copy_to_user(void __user *to, const void *from, unsigned long len);
11138 +static __always_inline __must_check unsigned long
11139 +__copy_from_user(void *to, const void __user *from, unsigned long len);
11140 __must_check unsigned long
11141 -_copy_to_user(void __user *to, const void *from, unsigned len);
11142 -__must_check unsigned long
11143 -_copy_from_user(void *to, const void __user *from, unsigned len);
11144 -__must_check unsigned long
11145 -copy_in_user(void __user *to, const void __user *from, unsigned len);
11146 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
11147
11148 static inline unsigned long __must_check copy_from_user(void *to,
11149 const void __user *from,
11150 unsigned long n)
11151 {
11152 - int sz = __compiletime_object_size(to);
11153 -
11154 might_fault();
11155 - if (likely(sz == -1 || sz >= n))
11156 - n = _copy_from_user(to, from, n);
11157 -#ifdef CONFIG_DEBUG_VM
11158 - else
11159 - WARN(1, "Buffer overflow detected!\n");
11160 -#endif
11161 +
11162 + if (access_ok(VERIFY_READ, from, n))
11163 + n = __copy_from_user(to, from, n);
11164 + else if (n < INT_MAX) {
11165 + if (!__builtin_constant_p(n))
11166 + check_object_size(to, n, false);
11167 + memset(to, 0, n);
11168 + }
11169 return n;
11170 }
11171
11172 static __always_inline __must_check
11173 -int copy_to_user(void __user *dst, const void *src, unsigned size)
11174 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
11175 {
11176 might_fault();
11177
11178 - return _copy_to_user(dst, src, size);
11179 + if (access_ok(VERIFY_WRITE, dst, size))
11180 + size = __copy_to_user(dst, src, size);
11181 + return size;
11182 }
11183
11184 static __always_inline __must_check
11185 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
11186 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
11187 {
11188 - int ret = 0;
11189 + int sz = __compiletime_object_size(dst);
11190 + unsigned ret = 0;
11191
11192 might_fault();
11193 - if (!__builtin_constant_p(size))
11194 - return copy_user_generic(dst, (__force void *)src, size);
11195 +
11196 + if (size > INT_MAX)
11197 + return size;
11198 +
11199 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11200 + if (!__access_ok(VERIFY_READ, src, size))
11201 + return size;
11202 +#endif
11203 +
11204 + if (unlikely(sz != -1 && sz < size)) {
11205 +#ifdef CONFIG_DEBUG_VM
11206 + WARN(1, "Buffer overflow detected!\n");
11207 +#endif
11208 + return size;
11209 + }
11210 +
11211 + if (!__builtin_constant_p(size)) {
11212 + check_object_size(dst, size, false);
11213 +
11214 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11215 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11216 + src += PAX_USER_SHADOW_BASE;
11217 +#endif
11218 +
11219 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11220 + }
11221 switch (size) {
11222 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
11223 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
11224 ret, "b", "b", "=q", 1);
11225 return ret;
11226 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
11227 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
11228 ret, "w", "w", "=r", 2);
11229 return ret;
11230 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
11231 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
11232 ret, "l", "k", "=r", 4);
11233 return ret;
11234 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
11235 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11236 ret, "q", "", "=r", 8);
11237 return ret;
11238 case 10:
11239 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11240 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11241 ret, "q", "", "=r", 10);
11242 if (unlikely(ret))
11243 return ret;
11244 __get_user_asm(*(u16 *)(8 + (char *)dst),
11245 - (u16 __user *)(8 + (char __user *)src),
11246 + (const u16 __user *)(8 + (const char __user *)src),
11247 ret, "w", "w", "=r", 2);
11248 return ret;
11249 case 16:
11250 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
11251 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
11252 ret, "q", "", "=r", 16);
11253 if (unlikely(ret))
11254 return ret;
11255 __get_user_asm(*(u64 *)(8 + (char *)dst),
11256 - (u64 __user *)(8 + (char __user *)src),
11257 + (const u64 __user *)(8 + (const char __user *)src),
11258 ret, "q", "", "=r", 8);
11259 return ret;
11260 default:
11261 - return copy_user_generic(dst, (__force void *)src, size);
11262 +
11263 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11264 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11265 + src += PAX_USER_SHADOW_BASE;
11266 +#endif
11267 +
11268 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11269 }
11270 }
11271
11272 static __always_inline __must_check
11273 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
11274 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
11275 {
11276 - int ret = 0;
11277 + int sz = __compiletime_object_size(src);
11278 + unsigned ret = 0;
11279
11280 might_fault();
11281 - if (!__builtin_constant_p(size))
11282 - return copy_user_generic((__force void *)dst, src, size);
11283 +
11284 + if (size > INT_MAX)
11285 + return size;
11286 +
11287 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11288 + if (!__access_ok(VERIFY_WRITE, dst, size))
11289 + return size;
11290 +#endif
11291 +
11292 + if (unlikely(sz != -1 && sz < size)) {
11293 +#ifdef CONFIG_DEBUG_VM
11294 + WARN(1, "Buffer overflow detected!\n");
11295 +#endif
11296 + return size;
11297 + }
11298 +
11299 + if (!__builtin_constant_p(size)) {
11300 + check_object_size(src, size, true);
11301 +
11302 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11303 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11304 + dst += PAX_USER_SHADOW_BASE;
11305 +#endif
11306 +
11307 + return copy_user_generic((__force_kernel void *)dst, src, size);
11308 + }
11309 switch (size) {
11310 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
11311 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
11312 ret, "b", "b", "iq", 1);
11313 return ret;
11314 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
11315 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
11316 ret, "w", "w", "ir", 2);
11317 return ret;
11318 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
11319 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
11320 ret, "l", "k", "ir", 4);
11321 return ret;
11322 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
11323 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11324 ret, "q", "", "er", 8);
11325 return ret;
11326 case 10:
11327 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11328 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11329 ret, "q", "", "er", 10);
11330 if (unlikely(ret))
11331 return ret;
11332 asm("":::"memory");
11333 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
11334 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
11335 ret, "w", "w", "ir", 2);
11336 return ret;
11337 case 16:
11338 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
11339 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
11340 ret, "q", "", "er", 16);
11341 if (unlikely(ret))
11342 return ret;
11343 asm("":::"memory");
11344 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
11345 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
11346 ret, "q", "", "er", 8);
11347 return ret;
11348 default:
11349 - return copy_user_generic((__force void *)dst, src, size);
11350 +
11351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11352 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11353 + dst += PAX_USER_SHADOW_BASE;
11354 +#endif
11355 +
11356 + return copy_user_generic((__force_kernel void *)dst, src, size);
11357 }
11358 }
11359
11360 static __always_inline __must_check
11361 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11362 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
11363 {
11364 - int ret = 0;
11365 + unsigned ret = 0;
11366
11367 might_fault();
11368 - if (!__builtin_constant_p(size))
11369 - return copy_user_generic((__force void *)dst,
11370 - (__force void *)src, size);
11371 +
11372 + if (size > INT_MAX)
11373 + return size;
11374 +
11375 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11376 + if (!__access_ok(VERIFY_READ, src, size))
11377 + return size;
11378 + if (!__access_ok(VERIFY_WRITE, dst, size))
11379 + return size;
11380 +#endif
11381 +
11382 + if (!__builtin_constant_p(size)) {
11383 +
11384 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11385 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11386 + src += PAX_USER_SHADOW_BASE;
11387 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11388 + dst += PAX_USER_SHADOW_BASE;
11389 +#endif
11390 +
11391 + return copy_user_generic((__force_kernel void *)dst,
11392 + (__force_kernel const void *)src, size);
11393 + }
11394 switch (size) {
11395 case 1: {
11396 u8 tmp;
11397 - __get_user_asm(tmp, (u8 __user *)src,
11398 + __get_user_asm(tmp, (const u8 __user *)src,
11399 ret, "b", "b", "=q", 1);
11400 if (likely(!ret))
11401 __put_user_asm(tmp, (u8 __user *)dst,
11402 @@ -176,7 +263,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11403 }
11404 case 2: {
11405 u16 tmp;
11406 - __get_user_asm(tmp, (u16 __user *)src,
11407 + __get_user_asm(tmp, (const u16 __user *)src,
11408 ret, "w", "w", "=r", 2);
11409 if (likely(!ret))
11410 __put_user_asm(tmp, (u16 __user *)dst,
11411 @@ -186,7 +273,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11412
11413 case 4: {
11414 u32 tmp;
11415 - __get_user_asm(tmp, (u32 __user *)src,
11416 + __get_user_asm(tmp, (const u32 __user *)src,
11417 ret, "l", "k", "=r", 4);
11418 if (likely(!ret))
11419 __put_user_asm(tmp, (u32 __user *)dst,
11420 @@ -195,7 +282,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11421 }
11422 case 8: {
11423 u64 tmp;
11424 - __get_user_asm(tmp, (u64 __user *)src,
11425 + __get_user_asm(tmp, (const u64 __user *)src,
11426 ret, "q", "", "=r", 8);
11427 if (likely(!ret))
11428 __put_user_asm(tmp, (u64 __user *)dst,
11429 @@ -203,8 +290,16 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
11430 return ret;
11431 }
11432 default:
11433 - return copy_user_generic((__force void *)dst,
11434 - (__force void *)src, size);
11435 +
11436 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11437 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11438 + src += PAX_USER_SHADOW_BASE;
11439 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11440 + dst += PAX_USER_SHADOW_BASE;
11441 +#endif
11442 +
11443 + return copy_user_generic((__force_kernel void *)dst,
11444 + (__force_kernel const void *)src, size);
11445 }
11446 }
11447
11448 @@ -219,35 +314,72 @@ __must_check unsigned long clear_user(void __user *mem, unsigned long len);
11449 __must_check unsigned long __clear_user(void __user *mem, unsigned long len);
11450
11451 static __must_check __always_inline int
11452 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
11453 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
11454 {
11455 - return copy_user_generic(dst, (__force const void *)src, size);
11456 + if (size > INT_MAX)
11457 + return size;
11458 +
11459 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11460 + if (!__access_ok(VERIFY_READ, src, size))
11461 + return size;
11462 +
11463 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
11464 + src += PAX_USER_SHADOW_BASE;
11465 +#endif
11466 +
11467 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
11468 }
11469
11470 -static __must_check __always_inline int
11471 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
11472 +static __must_check __always_inline unsigned long
11473 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
11474 {
11475 - return copy_user_generic((__force void *)dst, src, size);
11476 + if (size > INT_MAX)
11477 + return size;
11478 +
11479 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11480 + if (!__access_ok(VERIFY_WRITE, dst, size))
11481 + return size;
11482 +
11483 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
11484 + dst += PAX_USER_SHADOW_BASE;
11485 +#endif
11486 +
11487 + return copy_user_generic((__force_kernel void *)dst, src, size);
11488 }
11489
11490 -extern long __copy_user_nocache(void *dst, const void __user *src,
11491 - unsigned size, int zerorest);
11492 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
11493 + unsigned long size, int zerorest);
11494
11495 -static inline int
11496 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
11497 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
11498 {
11499 might_sleep();
11500 +
11501 + if (size > INT_MAX)
11502 + return size;
11503 +
11504 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11505 + if (!__access_ok(VERIFY_READ, src, size))
11506 + return size;
11507 +#endif
11508 +
11509 return __copy_user_nocache(dst, src, size, 1);
11510 }
11511
11512 -static inline int
11513 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11514 - unsigned size)
11515 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
11516 + unsigned long size)
11517 {
11518 + if (size > INT_MAX)
11519 + return size;
11520 +
11521 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11522 + if (!__access_ok(VERIFY_READ, src, size))
11523 + return size;
11524 +#endif
11525 +
11526 return __copy_user_nocache(dst, src, size, 0);
11527 }
11528
11529 -unsigned long
11530 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
11531 +extern unsigned long
11532 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest);
11533
11534 #endif /* _ASM_X86_UACCESS_64_H */
11535 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
11536 index bb05228..d763d5b 100644
11537 --- a/arch/x86/include/asm/vdso.h
11538 +++ b/arch/x86/include/asm/vdso.h
11539 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
11540 #define VDSO32_SYMBOL(base, name) \
11541 ({ \
11542 extern const char VDSO32_##name[]; \
11543 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
11544 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
11545 })
11546 #endif
11547
11548 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
11549 index 1971e65..1e3559b 100644
11550 --- a/arch/x86/include/asm/x86_init.h
11551 +++ b/arch/x86/include/asm/x86_init.h
11552 @@ -28,7 +28,7 @@ struct x86_init_mpparse {
11553 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
11554 void (*find_smp_config)(void);
11555 void (*get_smp_config)(unsigned int early);
11556 -};
11557 +} __no_const;
11558
11559 /**
11560 * struct x86_init_resources - platform specific resource related ops
11561 @@ -42,7 +42,7 @@ struct x86_init_resources {
11562 void (*probe_roms)(void);
11563 void (*reserve_resources)(void);
11564 char *(*memory_setup)(void);
11565 -};
11566 +} __no_const;
11567
11568 /**
11569 * struct x86_init_irqs - platform specific interrupt setup
11570 @@ -55,7 +55,7 @@ struct x86_init_irqs {
11571 void (*pre_vector_init)(void);
11572 void (*intr_init)(void);
11573 void (*trap_init)(void);
11574 -};
11575 +} __no_const;
11576
11577 /**
11578 * struct x86_init_oem - oem platform specific customizing functions
11579 @@ -65,7 +65,7 @@ struct x86_init_irqs {
11580 struct x86_init_oem {
11581 void (*arch_setup)(void);
11582 void (*banner)(void);
11583 -};
11584 +} __no_const;
11585
11586 /**
11587 * struct x86_init_mapping - platform specific initial kernel pagetable setup
11588 @@ -76,7 +76,7 @@ struct x86_init_oem {
11589 */
11590 struct x86_init_mapping {
11591 void (*pagetable_reserve)(u64 start, u64 end);
11592 -};
11593 +} __no_const;
11594
11595 /**
11596 * struct x86_init_paging - platform specific paging functions
11597 @@ -86,7 +86,7 @@ struct x86_init_mapping {
11598 struct x86_init_paging {
11599 void (*pagetable_setup_start)(pgd_t *base);
11600 void (*pagetable_setup_done)(pgd_t *base);
11601 -};
11602 +} __no_const;
11603
11604 /**
11605 * struct x86_init_timers - platform specific timer setup
11606 @@ -101,7 +101,7 @@ struct x86_init_timers {
11607 void (*tsc_pre_init)(void);
11608 void (*timer_init)(void);
11609 void (*wallclock_init)(void);
11610 -};
11611 +} __no_const;
11612
11613 /**
11614 * struct x86_init_iommu - platform specific iommu setup
11615 @@ -109,7 +109,7 @@ struct x86_init_timers {
11616 */
11617 struct x86_init_iommu {
11618 int (*iommu_init)(void);
11619 -};
11620 +} __no_const;
11621
11622 /**
11623 * struct x86_init_pci - platform specific pci init functions
11624 @@ -123,7 +123,7 @@ struct x86_init_pci {
11625 int (*init)(void);
11626 void (*init_irq)(void);
11627 void (*fixup_irqs)(void);
11628 -};
11629 +} __no_const;
11630
11631 /**
11632 * struct x86_init_ops - functions for platform specific setup
11633 @@ -139,7 +139,7 @@ struct x86_init_ops {
11634 struct x86_init_timers timers;
11635 struct x86_init_iommu iommu;
11636 struct x86_init_pci pci;
11637 -};
11638 +} __no_const;
11639
11640 /**
11641 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
11642 @@ -147,7 +147,7 @@ struct x86_init_ops {
11643 */
11644 struct x86_cpuinit_ops {
11645 void (*setup_percpu_clockev)(void);
11646 -};
11647 +} __no_const;
11648
11649 /**
11650 * struct x86_platform_ops - platform specific runtime functions
11651 @@ -169,7 +169,7 @@ struct x86_platform_ops {
11652 void (*nmi_init)(void);
11653 unsigned char (*get_nmi_reason)(void);
11654 int (*i8042_detect)(void);
11655 -};
11656 +} __no_const;
11657
11658 struct pci_dev;
11659
11660 @@ -177,7 +177,7 @@ struct x86_msi_ops {
11661 int (*setup_msi_irqs)(struct pci_dev *dev, int nvec, int type);
11662 void (*teardown_msi_irq)(unsigned int irq);
11663 void (*teardown_msi_irqs)(struct pci_dev *dev);
11664 -};
11665 +} __no_const;
11666
11667 extern struct x86_init_ops x86_init;
11668 extern struct x86_cpuinit_ops x86_cpuinit;
11669 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
11670 index c6ce245..ffbdab7 100644
11671 --- a/arch/x86/include/asm/xsave.h
11672 +++ b/arch/x86/include/asm/xsave.h
11673 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
11674 {
11675 int err;
11676
11677 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11678 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
11679 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
11680 +#endif
11681 +
11682 /*
11683 * Clear the xsave header first, so that reserved fields are
11684 * initialized to zero.
11685 @@ -96,10 +101,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
11686 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
11687 {
11688 int err;
11689 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
11690 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
11691 u32 lmask = mask;
11692 u32 hmask = mask >> 32;
11693
11694 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11695 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
11696 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
11697 +#endif
11698 +
11699 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
11700 "2:\n"
11701 ".section .fixup,\"ax\"\n"
11702 diff --git a/arch/x86/kernel/acpi/realmode/Makefile b/arch/x86/kernel/acpi/realmode/Makefile
11703 index 6a564ac..9b1340c 100644
11704 --- a/arch/x86/kernel/acpi/realmode/Makefile
11705 +++ b/arch/x86/kernel/acpi/realmode/Makefile
11706 @@ -41,6 +41,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D_WAKEUP -D__KERNEL__ \
11707 $(call cc-option, -fno-stack-protector) \
11708 $(call cc-option, -mpreferred-stack-boundary=2)
11709 KBUILD_CFLAGS += $(call cc-option, -m32)
11710 +ifdef CONSTIFY_PLUGIN
11711 +KBUILD_CFLAGS += $(CONSTIFY_PLUGIN) -fplugin-arg-constify_plugin-no-constify
11712 +endif
11713 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11714 GCOV_PROFILE := n
11715
11716 diff --git a/arch/x86/kernel/acpi/realmode/wakeup.S b/arch/x86/kernel/acpi/realmode/wakeup.S
11717 index b4fd836..4358fe3 100644
11718 --- a/arch/x86/kernel/acpi/realmode/wakeup.S
11719 +++ b/arch/x86/kernel/acpi/realmode/wakeup.S
11720 @@ -108,6 +108,9 @@ wakeup_code:
11721 /* Do any other stuff... */
11722
11723 #ifndef CONFIG_64BIT
11724 + /* Recheck NX bit overrides (64bit path does this in trampoline */
11725 + call verify_cpu
11726 +
11727 /* This could also be done in C code... */
11728 movl pmode_cr3, %eax
11729 movl %eax, %cr3
11730 @@ -131,6 +134,7 @@ wakeup_code:
11731 movl pmode_cr0, %eax
11732 movl %eax, %cr0
11733 jmp pmode_return
11734 +# include "../../verify_cpu.S"
11735 #else
11736 pushw $0
11737 pushw trampoline_segment
11738 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
11739 index 103b6ab..2004d0a 100644
11740 --- a/arch/x86/kernel/acpi/sleep.c
11741 +++ b/arch/x86/kernel/acpi/sleep.c
11742 @@ -94,8 +94,12 @@ int acpi_suspend_lowlevel(void)
11743 header->trampoline_segment = trampoline_address() >> 4;
11744 #ifdef CONFIG_SMP
11745 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
11746 +
11747 + pax_open_kernel();
11748 early_gdt_descr.address =
11749 (unsigned long)get_cpu_gdt_table(smp_processor_id());
11750 + pax_close_kernel();
11751 +
11752 initial_gs = per_cpu_offset(smp_processor_id());
11753 #endif
11754 initial_code = (unsigned long)wakeup_long64;
11755 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
11756 index 13ab720..95d5442 100644
11757 --- a/arch/x86/kernel/acpi/wakeup_32.S
11758 +++ b/arch/x86/kernel/acpi/wakeup_32.S
11759 @@ -30,13 +30,11 @@ wakeup_pmode_return:
11760 # and restore the stack ... but you need gdt for this to work
11761 movl saved_context_esp, %esp
11762
11763 - movl %cs:saved_magic, %eax
11764 - cmpl $0x12345678, %eax
11765 + cmpl $0x12345678, saved_magic
11766 jne bogus_magic
11767
11768 # jump to place where we left off
11769 - movl saved_eip, %eax
11770 - jmp *%eax
11771 + jmp *(saved_eip)
11772
11773 bogus_magic:
11774 jmp bogus_magic
11775 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
11776 index 1f84794..e23f862 100644
11777 --- a/arch/x86/kernel/alternative.c
11778 +++ b/arch/x86/kernel/alternative.c
11779 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
11780 */
11781 for (a = start; a < end; a++) {
11782 instr = (u8 *)&a->instr_offset + a->instr_offset;
11783 +
11784 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11785 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11786 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
11787 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11788 +#endif
11789 +
11790 replacement = (u8 *)&a->repl_offset + a->repl_offset;
11791 BUG_ON(a->replacementlen > a->instrlen);
11792 BUG_ON(a->instrlen > sizeof(insnbuf));
11793 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
11794 for (poff = start; poff < end; poff++) {
11795 u8 *ptr = (u8 *)poff + *poff;
11796
11797 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11798 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11799 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
11800 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11801 +#endif
11802 +
11803 if (!*poff || ptr < text || ptr >= text_end)
11804 continue;
11805 /* turn DS segment override prefix into lock prefix */
11806 - if (*ptr == 0x3e)
11807 + if (*ktla_ktva(ptr) == 0x3e)
11808 text_poke(ptr, ((unsigned char []){0xf0}), 1);
11809 };
11810 mutex_unlock(&text_mutex);
11811 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
11812 for (poff = start; poff < end; poff++) {
11813 u8 *ptr = (u8 *)poff + *poff;
11814
11815 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11816 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11817 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
11818 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
11819 +#endif
11820 +
11821 if (!*poff || ptr < text || ptr >= text_end)
11822 continue;
11823 /* turn lock prefix into DS segment override prefix */
11824 - if (*ptr == 0xf0)
11825 + if (*ktla_ktva(ptr) == 0xf0)
11826 text_poke(ptr, ((unsigned char []){0x3E}), 1);
11827 };
11828 mutex_unlock(&text_mutex);
11829 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
11830
11831 BUG_ON(p->len > MAX_PATCH_LEN);
11832 /* prep the buffer with the original instructions */
11833 - memcpy(insnbuf, p->instr, p->len);
11834 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
11835 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
11836 (unsigned long)p->instr, p->len);
11837
11838 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
11839 if (smp_alt_once)
11840 free_init_pages("SMP alternatives",
11841 (unsigned long)__smp_locks,
11842 - (unsigned long)__smp_locks_end);
11843 + PAGE_ALIGN((unsigned long)__smp_locks_end));
11844
11845 restart_nmi();
11846 }
11847 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
11848 * instructions. And on the local CPU you need to be protected again NMI or MCE
11849 * handlers seeing an inconsistent instruction while you patch.
11850 */
11851 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
11852 +void *__kprobes text_poke_early(void *addr, const void *opcode,
11853 size_t len)
11854 {
11855 unsigned long flags;
11856 local_irq_save(flags);
11857 - memcpy(addr, opcode, len);
11858 +
11859 + pax_open_kernel();
11860 + memcpy(ktla_ktva(addr), opcode, len);
11861 sync_core();
11862 + pax_close_kernel();
11863 +
11864 local_irq_restore(flags);
11865 /* Could also do a CLFLUSH here to speed up CPU recovery; but
11866 that causes hangs on some VIA CPUs. */
11867 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
11868 */
11869 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
11870 {
11871 - unsigned long flags;
11872 - char *vaddr;
11873 + unsigned char *vaddr = ktla_ktva(addr);
11874 struct page *pages[2];
11875 - int i;
11876 + size_t i;
11877
11878 if (!core_kernel_text((unsigned long)addr)) {
11879 - pages[0] = vmalloc_to_page(addr);
11880 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
11881 + pages[0] = vmalloc_to_page(vaddr);
11882 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
11883 } else {
11884 - pages[0] = virt_to_page(addr);
11885 + pages[0] = virt_to_page(vaddr);
11886 WARN_ON(!PageReserved(pages[0]));
11887 - pages[1] = virt_to_page(addr + PAGE_SIZE);
11888 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
11889 }
11890 BUG_ON(!pages[0]);
11891 - local_irq_save(flags);
11892 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
11893 - if (pages[1])
11894 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
11895 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
11896 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
11897 - clear_fixmap(FIX_TEXT_POKE0);
11898 - if (pages[1])
11899 - clear_fixmap(FIX_TEXT_POKE1);
11900 - local_flush_tlb();
11901 - sync_core();
11902 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
11903 - that causes hangs on some VIA CPUs. */
11904 + text_poke_early(addr, opcode, len);
11905 for (i = 0; i < len; i++)
11906 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
11907 - local_irq_restore(flags);
11908 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
11909 return addr;
11910 }
11911
11912 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
11913 index f98d84c..e402a69 100644
11914 --- a/arch/x86/kernel/apic/apic.c
11915 +++ b/arch/x86/kernel/apic/apic.c
11916 @@ -174,7 +174,7 @@ int first_system_vector = 0xfe;
11917 /*
11918 * Debug level, exported for io_apic.c
11919 */
11920 -unsigned int apic_verbosity;
11921 +int apic_verbosity;
11922
11923 int pic_mode;
11924
11925 @@ -1853,7 +1853,7 @@ void smp_error_interrupt(struct pt_regs *regs)
11926 apic_write(APIC_ESR, 0);
11927 v1 = apic_read(APIC_ESR);
11928 ack_APIC_irq();
11929 - atomic_inc(&irq_err_count);
11930 + atomic_inc_unchecked(&irq_err_count);
11931
11932 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
11933 smp_processor_id(), v0 , v1);
11934 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
11935 index 6d939d7..0697fcc 100644
11936 --- a/arch/x86/kernel/apic/io_apic.c
11937 +++ b/arch/x86/kernel/apic/io_apic.c
11938 @@ -1096,7 +1096,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
11939 }
11940 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
11941
11942 -void lock_vector_lock(void)
11943 +void lock_vector_lock(void) __acquires(vector_lock)
11944 {
11945 /* Used to the online set of cpus does not change
11946 * during assign_irq_vector.
11947 @@ -1104,7 +1104,7 @@ void lock_vector_lock(void)
11948 raw_spin_lock(&vector_lock);
11949 }
11950
11951 -void unlock_vector_lock(void)
11952 +void unlock_vector_lock(void) __releases(vector_lock)
11953 {
11954 raw_spin_unlock(&vector_lock);
11955 }
11956 @@ -2510,7 +2510,7 @@ static void ack_apic_edge(struct irq_data *data)
11957 ack_APIC_irq();
11958 }
11959
11960 -atomic_t irq_mis_count;
11961 +atomic_unchecked_t irq_mis_count;
11962
11963 static void ack_apic_level(struct irq_data *data)
11964 {
11965 @@ -2576,7 +2576,7 @@ static void ack_apic_level(struct irq_data *data)
11966 * at the cpu.
11967 */
11968 if (!(v & (1 << (i & 0x1f)))) {
11969 - atomic_inc(&irq_mis_count);
11970 + atomic_inc_unchecked(&irq_mis_count);
11971
11972 eoi_ioapic_irq(irq, cfg);
11973 }
11974 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
11975 index a46bd38..6b906d7 100644
11976 --- a/arch/x86/kernel/apm_32.c
11977 +++ b/arch/x86/kernel/apm_32.c
11978 @@ -411,7 +411,7 @@ static DEFINE_MUTEX(apm_mutex);
11979 * This is for buggy BIOS's that refer to (real mode) segment 0x40
11980 * even though they are called in protected mode.
11981 */
11982 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
11983 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
11984 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
11985
11986 static const char driver_version[] = "1.16ac"; /* no spaces */
11987 @@ -589,7 +589,10 @@ static long __apm_bios_call(void *_call)
11988 BUG_ON(cpu != 0);
11989 gdt = get_cpu_gdt_table(cpu);
11990 save_desc_40 = gdt[0x40 / 8];
11991 +
11992 + pax_open_kernel();
11993 gdt[0x40 / 8] = bad_bios_desc;
11994 + pax_close_kernel();
11995
11996 apm_irq_save(flags);
11997 APM_DO_SAVE_SEGS;
11998 @@ -598,7 +601,11 @@ static long __apm_bios_call(void *_call)
11999 &call->esi);
12000 APM_DO_RESTORE_SEGS;
12001 apm_irq_restore(flags);
12002 +
12003 + pax_open_kernel();
12004 gdt[0x40 / 8] = save_desc_40;
12005 + pax_close_kernel();
12006 +
12007 put_cpu();
12008
12009 return call->eax & 0xff;
12010 @@ -665,7 +672,10 @@ static long __apm_bios_call_simple(void *_call)
12011 BUG_ON(cpu != 0);
12012 gdt = get_cpu_gdt_table(cpu);
12013 save_desc_40 = gdt[0x40 / 8];
12014 +
12015 + pax_open_kernel();
12016 gdt[0x40 / 8] = bad_bios_desc;
12017 + pax_close_kernel();
12018
12019 apm_irq_save(flags);
12020 APM_DO_SAVE_SEGS;
12021 @@ -673,7 +683,11 @@ static long __apm_bios_call_simple(void *_call)
12022 &call->eax);
12023 APM_DO_RESTORE_SEGS;
12024 apm_irq_restore(flags);
12025 +
12026 + pax_open_kernel();
12027 gdt[0x40 / 8] = save_desc_40;
12028 + pax_close_kernel();
12029 +
12030 put_cpu();
12031 return error;
12032 }
12033 @@ -2347,12 +2361,15 @@ static int __init apm_init(void)
12034 * code to that CPU.
12035 */
12036 gdt = get_cpu_gdt_table(0);
12037 +
12038 + pax_open_kernel();
12039 set_desc_base(&gdt[APM_CS >> 3],
12040 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
12041 set_desc_base(&gdt[APM_CS_16 >> 3],
12042 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
12043 set_desc_base(&gdt[APM_DS >> 3],
12044 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
12045 + pax_close_kernel();
12046
12047 proc_create("apm", 0, NULL, &apm_file_ops);
12048
12049 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
12050 index 4f13faf..87db5d2 100644
12051 --- a/arch/x86/kernel/asm-offsets.c
12052 +++ b/arch/x86/kernel/asm-offsets.c
12053 @@ -33,6 +33,8 @@ void common(void) {
12054 OFFSET(TI_status, thread_info, status);
12055 OFFSET(TI_addr_limit, thread_info, addr_limit);
12056 OFFSET(TI_preempt_count, thread_info, preempt_count);
12057 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
12058 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
12059
12060 BLANK();
12061 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
12062 @@ -53,8 +55,26 @@ void common(void) {
12063 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
12064 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
12065 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
12066 +
12067 +#ifdef CONFIG_PAX_KERNEXEC
12068 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
12069 #endif
12070
12071 +#ifdef CONFIG_PAX_MEMORY_UDEREF
12072 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
12073 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
12074 +#ifdef CONFIG_X86_64
12075 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
12076 +#endif
12077 +#endif
12078 +
12079 +#endif
12080 +
12081 + BLANK();
12082 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
12083 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
12084 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
12085 +
12086 #ifdef CONFIG_XEN
12087 BLANK();
12088 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
12089 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
12090 index e72a119..6e2955d 100644
12091 --- a/arch/x86/kernel/asm-offsets_64.c
12092 +++ b/arch/x86/kernel/asm-offsets_64.c
12093 @@ -69,6 +69,7 @@ int main(void)
12094 BLANK();
12095 #undef ENTRY
12096
12097 + DEFINE(TSS_size, sizeof(struct tss_struct));
12098 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
12099 BLANK();
12100
12101 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
12102 index 25f24dc..4094a7f 100644
12103 --- a/arch/x86/kernel/cpu/Makefile
12104 +++ b/arch/x86/kernel/cpu/Makefile
12105 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
12106 CFLAGS_REMOVE_perf_event.o = -pg
12107 endif
12108
12109 -# Make sure load_percpu_segment has no stackprotector
12110 -nostackp := $(call cc-option, -fno-stack-protector)
12111 -CFLAGS_common.o := $(nostackp)
12112 -
12113 obj-y := intel_cacheinfo.o scattered.o topology.o
12114 obj-y += proc.o capflags.o powerflags.o common.o
12115 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
12116 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
12117 index 0bab2b1..d0a1bf8 100644
12118 --- a/arch/x86/kernel/cpu/amd.c
12119 +++ b/arch/x86/kernel/cpu/amd.c
12120 @@ -664,7 +664,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
12121 unsigned int size)
12122 {
12123 /* AMD errata T13 (order #21922) */
12124 - if ((c->x86 == 6)) {
12125 + if (c->x86 == 6) {
12126 /* Duron Rev A0 */
12127 if (c->x86_model == 3 && c->x86_mask == 0)
12128 size = 64;
12129 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
12130 index aa003b1..47ea638 100644
12131 --- a/arch/x86/kernel/cpu/common.c
12132 +++ b/arch/x86/kernel/cpu/common.c
12133 @@ -84,60 +84,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
12134
12135 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
12136
12137 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
12138 -#ifdef CONFIG_X86_64
12139 - /*
12140 - * We need valid kernel segments for data and code in long mode too
12141 - * IRET will check the segment types kkeil 2000/10/28
12142 - * Also sysret mandates a special GDT layout
12143 - *
12144 - * TLS descriptors are currently at a different place compared to i386.
12145 - * Hopefully nobody expects them at a fixed place (Wine?)
12146 - */
12147 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
12148 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
12149 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
12150 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
12151 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
12152 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
12153 -#else
12154 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
12155 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12156 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
12157 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
12158 - /*
12159 - * Segments used for calling PnP BIOS have byte granularity.
12160 - * They code segments and data segments have fixed 64k limits,
12161 - * the transfer segment sizes are set at run time.
12162 - */
12163 - /* 32-bit code */
12164 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12165 - /* 16-bit code */
12166 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12167 - /* 16-bit data */
12168 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
12169 - /* 16-bit data */
12170 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
12171 - /* 16-bit data */
12172 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
12173 - /*
12174 - * The APM segments have byte granularity and their bases
12175 - * are set at run time. All have 64k limits.
12176 - */
12177 - /* 32-bit code */
12178 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
12179 - /* 16-bit code */
12180 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
12181 - /* data */
12182 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
12183 -
12184 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12185 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
12186 - GDT_STACK_CANARY_INIT
12187 -#endif
12188 -} };
12189 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
12190 -
12191 static int __init x86_xsave_setup(char *s)
12192 {
12193 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
12194 @@ -372,7 +318,7 @@ void switch_to_new_gdt(int cpu)
12195 {
12196 struct desc_ptr gdt_descr;
12197
12198 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
12199 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
12200 gdt_descr.size = GDT_SIZE - 1;
12201 load_gdt(&gdt_descr);
12202 /* Reload the per-cpu base */
12203 @@ -844,6 +790,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
12204 /* Filter out anything that depends on CPUID levels we don't have */
12205 filter_cpuid_features(c, true);
12206
12207 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
12208 + setup_clear_cpu_cap(X86_FEATURE_SEP);
12209 +#endif
12210 +
12211 /* If the model name is still unset, do table lookup. */
12212 if (!c->x86_model_id[0]) {
12213 const char *p;
12214 @@ -1024,6 +974,9 @@ static __init int setup_disablecpuid(char *arg)
12215 }
12216 __setup("clearcpuid=", setup_disablecpuid);
12217
12218 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
12219 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
12220 +
12221 #ifdef CONFIG_X86_64
12222 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
12223
12224 @@ -1039,7 +992,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
12225 EXPORT_PER_CPU_SYMBOL(current_task);
12226
12227 DEFINE_PER_CPU(unsigned long, kernel_stack) =
12228 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
12229 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
12230 EXPORT_PER_CPU_SYMBOL(kernel_stack);
12231
12232 DEFINE_PER_CPU(char *, irq_stack_ptr) =
12233 @@ -1104,7 +1057,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
12234 {
12235 memset(regs, 0, sizeof(struct pt_regs));
12236 regs->fs = __KERNEL_PERCPU;
12237 - regs->gs = __KERNEL_STACK_CANARY;
12238 + savesegment(gs, regs->gs);
12239
12240 return regs;
12241 }
12242 @@ -1159,7 +1112,7 @@ void __cpuinit cpu_init(void)
12243 int i;
12244
12245 cpu = stack_smp_processor_id();
12246 - t = &per_cpu(init_tss, cpu);
12247 + t = init_tss + cpu;
12248 oist = &per_cpu(orig_ist, cpu);
12249
12250 #ifdef CONFIG_NUMA
12251 @@ -1185,7 +1138,7 @@ void __cpuinit cpu_init(void)
12252 switch_to_new_gdt(cpu);
12253 loadsegment(fs, 0);
12254
12255 - load_idt((const struct desc_ptr *)&idt_descr);
12256 + load_idt(&idt_descr);
12257
12258 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
12259 syscall_init();
12260 @@ -1194,7 +1147,6 @@ void __cpuinit cpu_init(void)
12261 wrmsrl(MSR_KERNEL_GS_BASE, 0);
12262 barrier();
12263
12264 - x86_configure_nx();
12265 if (cpu != 0)
12266 enable_x2apic();
12267
12268 @@ -1248,7 +1200,7 @@ void __cpuinit cpu_init(void)
12269 {
12270 int cpu = smp_processor_id();
12271 struct task_struct *curr = current;
12272 - struct tss_struct *t = &per_cpu(init_tss, cpu);
12273 + struct tss_struct *t = init_tss + cpu;
12274 struct thread_struct *thread = &curr->thread;
12275
12276 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
12277 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
12278 index 5231312..a78a987 100644
12279 --- a/arch/x86/kernel/cpu/intel.c
12280 +++ b/arch/x86/kernel/cpu/intel.c
12281 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
12282 * Update the IDT descriptor and reload the IDT so that
12283 * it uses the read-only mapped virtual address.
12284 */
12285 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
12286 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
12287 load_idt(&idt_descr);
12288 }
12289 #endif
12290 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
12291 index 2af127d..8ff7ac0 100644
12292 --- a/arch/x86/kernel/cpu/mcheck/mce.c
12293 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
12294 @@ -42,6 +42,7 @@
12295 #include <asm/processor.h>
12296 #include <asm/mce.h>
12297 #include <asm/msr.h>
12298 +#include <asm/local.h>
12299
12300 #include "mce-internal.h"
12301
12302 @@ -202,7 +203,7 @@ static void print_mce(struct mce *m)
12303 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
12304 m->cs, m->ip);
12305
12306 - if (m->cs == __KERNEL_CS)
12307 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
12308 print_symbol("{%s}", m->ip);
12309 pr_cont("\n");
12310 }
12311 @@ -235,10 +236,10 @@ static void print_mce(struct mce *m)
12312
12313 #define PANIC_TIMEOUT 5 /* 5 seconds */
12314
12315 -static atomic_t mce_paniced;
12316 +static atomic_unchecked_t mce_paniced;
12317
12318 static int fake_panic;
12319 -static atomic_t mce_fake_paniced;
12320 +static atomic_unchecked_t mce_fake_paniced;
12321
12322 /* Panic in progress. Enable interrupts and wait for final IPI */
12323 static void wait_for_panic(void)
12324 @@ -262,7 +263,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
12325 /*
12326 * Make sure only one CPU runs in machine check panic
12327 */
12328 - if (atomic_inc_return(&mce_paniced) > 1)
12329 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
12330 wait_for_panic();
12331 barrier();
12332
12333 @@ -270,7 +271,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
12334 console_verbose();
12335 } else {
12336 /* Don't log too much for fake panic */
12337 - if (atomic_inc_return(&mce_fake_paniced) > 1)
12338 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
12339 return;
12340 }
12341 /* First print corrected ones that are still unlogged */
12342 @@ -610,7 +611,7 @@ static int mce_timed_out(u64 *t)
12343 * might have been modified by someone else.
12344 */
12345 rmb();
12346 - if (atomic_read(&mce_paniced))
12347 + if (atomic_read_unchecked(&mce_paniced))
12348 wait_for_panic();
12349 if (!monarch_timeout)
12350 goto out;
12351 @@ -1398,7 +1399,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
12352 }
12353
12354 /* Call the installed machine check handler for this CPU setup. */
12355 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
12356 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
12357 unexpected_machine_check;
12358
12359 /*
12360 @@ -1421,7 +1422,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
12361 return;
12362 }
12363
12364 + pax_open_kernel();
12365 machine_check_vector = do_machine_check;
12366 + pax_close_kernel();
12367
12368 __mcheck_cpu_init_generic();
12369 __mcheck_cpu_init_vendor(c);
12370 @@ -1435,7 +1438,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
12371 */
12372
12373 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
12374 -static int mce_chrdev_open_count; /* #times opened */
12375 +static local_t mce_chrdev_open_count; /* #times opened */
12376 static int mce_chrdev_open_exclu; /* already open exclusive? */
12377
12378 static int mce_chrdev_open(struct inode *inode, struct file *file)
12379 @@ -1443,7 +1446,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
12380 spin_lock(&mce_chrdev_state_lock);
12381
12382 if (mce_chrdev_open_exclu ||
12383 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
12384 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
12385 spin_unlock(&mce_chrdev_state_lock);
12386
12387 return -EBUSY;
12388 @@ -1451,7 +1454,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
12389
12390 if (file->f_flags & O_EXCL)
12391 mce_chrdev_open_exclu = 1;
12392 - mce_chrdev_open_count++;
12393 + local_inc(&mce_chrdev_open_count);
12394
12395 spin_unlock(&mce_chrdev_state_lock);
12396
12397 @@ -1462,7 +1465,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
12398 {
12399 spin_lock(&mce_chrdev_state_lock);
12400
12401 - mce_chrdev_open_count--;
12402 + local_dec(&mce_chrdev_open_count);
12403 mce_chrdev_open_exclu = 0;
12404
12405 spin_unlock(&mce_chrdev_state_lock);
12406 @@ -2171,7 +2174,7 @@ struct dentry *mce_get_debugfs_dir(void)
12407 static void mce_reset(void)
12408 {
12409 cpu_missing = 0;
12410 - atomic_set(&mce_fake_paniced, 0);
12411 + atomic_set_unchecked(&mce_fake_paniced, 0);
12412 atomic_set(&mce_executing, 0);
12413 atomic_set(&mce_callin, 0);
12414 atomic_set(&global_nwo, 0);
12415 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
12416 index 5c0e653..0882b0a 100644
12417 --- a/arch/x86/kernel/cpu/mcheck/p5.c
12418 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
12419 @@ -12,6 +12,7 @@
12420 #include <asm/system.h>
12421 #include <asm/mce.h>
12422 #include <asm/msr.h>
12423 +#include <asm/pgtable.h>
12424
12425 /* By default disabled */
12426 int mce_p5_enabled __read_mostly;
12427 @@ -50,7 +51,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
12428 if (!cpu_has(c, X86_FEATURE_MCE))
12429 return;
12430
12431 + pax_open_kernel();
12432 machine_check_vector = pentium_machine_check;
12433 + pax_close_kernel();
12434 /* Make sure the vector pointer is visible before we enable MCEs: */
12435 wmb();
12436
12437 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
12438 index 54060f5..c1a7577 100644
12439 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
12440 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
12441 @@ -11,6 +11,7 @@
12442 #include <asm/system.h>
12443 #include <asm/mce.h>
12444 #include <asm/msr.h>
12445 +#include <asm/pgtable.h>
12446
12447 /* Machine check handler for WinChip C6: */
12448 static void winchip_machine_check(struct pt_regs *regs, long error_code)
12449 @@ -24,7 +25,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
12450 {
12451 u32 lo, hi;
12452
12453 + pax_open_kernel();
12454 machine_check_vector = winchip_machine_check;
12455 + pax_close_kernel();
12456 /* Make sure the vector pointer is visible before we enable MCEs: */
12457 wmb();
12458
12459 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
12460 index 6b96110..0da73eb 100644
12461 --- a/arch/x86/kernel/cpu/mtrr/main.c
12462 +++ b/arch/x86/kernel/cpu/mtrr/main.c
12463 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
12464 u64 size_or_mask, size_and_mask;
12465 static bool mtrr_aps_delayed_init;
12466
12467 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
12468 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
12469
12470 const struct mtrr_ops *mtrr_if;
12471
12472 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
12473 index df5e41f..816c719 100644
12474 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
12475 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
12476 @@ -25,7 +25,7 @@ struct mtrr_ops {
12477 int (*validate_add_page)(unsigned long base, unsigned long size,
12478 unsigned int type);
12479 int (*have_wrcomb)(void);
12480 -};
12481 +} __do_const;
12482
12483 extern int generic_get_free_region(unsigned long base, unsigned long size,
12484 int replace_reg);
12485 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
12486 index 2bda212..78cc605 100644
12487 --- a/arch/x86/kernel/cpu/perf_event.c
12488 +++ b/arch/x86/kernel/cpu/perf_event.c
12489 @@ -1529,7 +1529,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
12490 break;
12491
12492 perf_callchain_store(entry, frame.return_address);
12493 - fp = frame.next_frame;
12494 + fp = (const void __force_user *)frame.next_frame;
12495 }
12496 }
12497
12498 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
12499 index 13ad899..f642b9a 100644
12500 --- a/arch/x86/kernel/crash.c
12501 +++ b/arch/x86/kernel/crash.c
12502 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
12503 {
12504 #ifdef CONFIG_X86_32
12505 struct pt_regs fixed_regs;
12506 -#endif
12507
12508 -#ifdef CONFIG_X86_32
12509 - if (!user_mode_vm(regs)) {
12510 + if (!user_mode(regs)) {
12511 crash_fixup_ss_esp(&fixed_regs, regs);
12512 regs = &fixed_regs;
12513 }
12514 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
12515 index 37250fe..bf2ec74 100644
12516 --- a/arch/x86/kernel/doublefault_32.c
12517 +++ b/arch/x86/kernel/doublefault_32.c
12518 @@ -11,7 +11,7 @@
12519
12520 #define DOUBLEFAULT_STACKSIZE (1024)
12521 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
12522 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
12523 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
12524
12525 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
12526
12527 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
12528 unsigned long gdt, tss;
12529
12530 store_gdt(&gdt_desc);
12531 - gdt = gdt_desc.address;
12532 + gdt = (unsigned long)gdt_desc.address;
12533
12534 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
12535
12536 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
12537 /* 0x2 bit is always set */
12538 .flags = X86_EFLAGS_SF | 0x2,
12539 .sp = STACK_START,
12540 - .es = __USER_DS,
12541 + .es = __KERNEL_DS,
12542 .cs = __KERNEL_CS,
12543 .ss = __KERNEL_DS,
12544 - .ds = __USER_DS,
12545 + .ds = __KERNEL_DS,
12546 .fs = __KERNEL_PERCPU,
12547
12548 .__cr3 = __pa_nodebug(swapper_pg_dir),
12549 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
12550 index 1aae78f..aab3a3d 100644
12551 --- a/arch/x86/kernel/dumpstack.c
12552 +++ b/arch/x86/kernel/dumpstack.c
12553 @@ -2,6 +2,9 @@
12554 * Copyright (C) 1991, 1992 Linus Torvalds
12555 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
12556 */
12557 +#ifdef CONFIG_GRKERNSEC_HIDESYM
12558 +#define __INCLUDED_BY_HIDESYM 1
12559 +#endif
12560 #include <linux/kallsyms.h>
12561 #include <linux/kprobes.h>
12562 #include <linux/uaccess.h>
12563 @@ -35,9 +38,8 @@ void printk_address(unsigned long address, int reliable)
12564 static void
12565 print_ftrace_graph_addr(unsigned long addr, void *data,
12566 const struct stacktrace_ops *ops,
12567 - struct thread_info *tinfo, int *graph)
12568 + struct task_struct *task, int *graph)
12569 {
12570 - struct task_struct *task = tinfo->task;
12571 unsigned long ret_addr;
12572 int index = task->curr_ret_stack;
12573
12574 @@ -58,7 +60,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12575 static inline void
12576 print_ftrace_graph_addr(unsigned long addr, void *data,
12577 const struct stacktrace_ops *ops,
12578 - struct thread_info *tinfo, int *graph)
12579 + struct task_struct *task, int *graph)
12580 { }
12581 #endif
12582
12583 @@ -69,10 +71,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
12584 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
12585 */
12586
12587 -static inline int valid_stack_ptr(struct thread_info *tinfo,
12588 - void *p, unsigned int size, void *end)
12589 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
12590 {
12591 - void *t = tinfo;
12592 if (end) {
12593 if (p < end && p >= (end-THREAD_SIZE))
12594 return 1;
12595 @@ -83,14 +83,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
12596 }
12597
12598 unsigned long
12599 -print_context_stack(struct thread_info *tinfo,
12600 +print_context_stack(struct task_struct *task, void *stack_start,
12601 unsigned long *stack, unsigned long bp,
12602 const struct stacktrace_ops *ops, void *data,
12603 unsigned long *end, int *graph)
12604 {
12605 struct stack_frame *frame = (struct stack_frame *)bp;
12606
12607 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
12608 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
12609 unsigned long addr;
12610
12611 addr = *stack;
12612 @@ -102,7 +102,7 @@ print_context_stack(struct thread_info *tinfo,
12613 } else {
12614 ops->address(data, addr, 0);
12615 }
12616 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12617 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12618 }
12619 stack++;
12620 }
12621 @@ -111,7 +111,7 @@ print_context_stack(struct thread_info *tinfo,
12622 EXPORT_SYMBOL_GPL(print_context_stack);
12623
12624 unsigned long
12625 -print_context_stack_bp(struct thread_info *tinfo,
12626 +print_context_stack_bp(struct task_struct *task, void *stack_start,
12627 unsigned long *stack, unsigned long bp,
12628 const struct stacktrace_ops *ops, void *data,
12629 unsigned long *end, int *graph)
12630 @@ -119,7 +119,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12631 struct stack_frame *frame = (struct stack_frame *)bp;
12632 unsigned long *ret_addr = &frame->return_address;
12633
12634 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
12635 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
12636 unsigned long addr = *ret_addr;
12637
12638 if (!__kernel_text_address(addr))
12639 @@ -128,7 +128,7 @@ print_context_stack_bp(struct thread_info *tinfo,
12640 ops->address(data, addr, 1);
12641 frame = frame->next_frame;
12642 ret_addr = &frame->return_address;
12643 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
12644 + print_ftrace_graph_addr(addr, data, ops, task, graph);
12645 }
12646
12647 return (unsigned long)frame;
12648 @@ -186,7 +186,7 @@ void dump_stack(void)
12649
12650 bp = stack_frame(current, NULL);
12651 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
12652 - current->pid, current->comm, print_tainted(),
12653 + task_pid_nr(current), current->comm, print_tainted(),
12654 init_utsname()->release,
12655 (int)strcspn(init_utsname()->version, " "),
12656 init_utsname()->version);
12657 @@ -222,6 +222,8 @@ unsigned __kprobes long oops_begin(void)
12658 }
12659 EXPORT_SYMBOL_GPL(oops_begin);
12660
12661 +extern void gr_handle_kernel_exploit(void);
12662 +
12663 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12664 {
12665 if (regs && kexec_should_crash(current))
12666 @@ -243,7 +245,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
12667 panic("Fatal exception in interrupt");
12668 if (panic_on_oops)
12669 panic("Fatal exception");
12670 - do_exit(signr);
12671 +
12672 + gr_handle_kernel_exploit();
12673 +
12674 + do_group_exit(signr);
12675 }
12676
12677 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12678 @@ -269,7 +274,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
12679
12680 show_registers(regs);
12681 #ifdef CONFIG_X86_32
12682 - if (user_mode_vm(regs)) {
12683 + if (user_mode(regs)) {
12684 sp = regs->sp;
12685 ss = regs->ss & 0xffff;
12686 } else {
12687 @@ -297,7 +302,7 @@ void die(const char *str, struct pt_regs *regs, long err)
12688 unsigned long flags = oops_begin();
12689 int sig = SIGSEGV;
12690
12691 - if (!user_mode_vm(regs))
12692 + if (!user_mode(regs))
12693 report_bug(regs->ip, regs);
12694
12695 if (__die(str, regs, err))
12696 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
12697 index c99f9ed..2a15d80 100644
12698 --- a/arch/x86/kernel/dumpstack_32.c
12699 +++ b/arch/x86/kernel/dumpstack_32.c
12700 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12701 bp = stack_frame(task, regs);
12702
12703 for (;;) {
12704 - struct thread_info *context;
12705 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12706
12707 - context = (struct thread_info *)
12708 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
12709 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
12710 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12711
12712 - stack = (unsigned long *)context->previous_esp;
12713 - if (!stack)
12714 + if (stack_start == task_stack_page(task))
12715 break;
12716 + stack = *(unsigned long **)stack_start;
12717 if (ops->stack(data, "IRQ") < 0)
12718 break;
12719 touch_nmi_watchdog();
12720 @@ -96,21 +94,22 @@ void show_registers(struct pt_regs *regs)
12721 * When in-kernel, we also print out the stack and code at the
12722 * time of the fault..
12723 */
12724 - if (!user_mode_vm(regs)) {
12725 + if (!user_mode(regs)) {
12726 unsigned int code_prologue = code_bytes * 43 / 64;
12727 unsigned int code_len = code_bytes;
12728 unsigned char c;
12729 u8 *ip;
12730 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
12731
12732 printk(KERN_EMERG "Stack:\n");
12733 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
12734
12735 printk(KERN_EMERG "Code: ");
12736
12737 - ip = (u8 *)regs->ip - code_prologue;
12738 + ip = (u8 *)regs->ip - code_prologue + cs_base;
12739 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
12740 /* try starting at IP */
12741 - ip = (u8 *)regs->ip;
12742 + ip = (u8 *)regs->ip + cs_base;
12743 code_len = code_len - code_prologue + 1;
12744 }
12745 for (i = 0; i < code_len; i++, ip++) {
12746 @@ -119,7 +118,7 @@ void show_registers(struct pt_regs *regs)
12747 printk(KERN_CONT " Bad EIP value.");
12748 break;
12749 }
12750 - if (ip == (u8 *)regs->ip)
12751 + if (ip == (u8 *)regs->ip + cs_base)
12752 printk(KERN_CONT "<%02x> ", c);
12753 else
12754 printk(KERN_CONT "%02x ", c);
12755 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
12756 {
12757 unsigned short ud2;
12758
12759 + ip = ktla_ktva(ip);
12760 if (ip < PAGE_OFFSET)
12761 return 0;
12762 if (probe_kernel_address((unsigned short *)ip, ud2))
12763 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
12764
12765 return ud2 == 0x0b0f;
12766 }
12767 +
12768 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12769 +void pax_check_alloca(unsigned long size)
12770 +{
12771 + unsigned long sp = (unsigned long)&sp, stack_left;
12772 +
12773 + /* all kernel stacks are of the same size */
12774 + stack_left = sp & (THREAD_SIZE - 1);
12775 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12776 +}
12777 +EXPORT_SYMBOL(pax_check_alloca);
12778 +#endif
12779 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
12780 index 6d728d9..279514e 100644
12781 --- a/arch/x86/kernel/dumpstack_64.c
12782 +++ b/arch/x86/kernel/dumpstack_64.c
12783 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12784 unsigned long *irq_stack_end =
12785 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
12786 unsigned used = 0;
12787 - struct thread_info *tinfo;
12788 int graph = 0;
12789 unsigned long dummy;
12790 + void *stack_start;
12791
12792 if (!task)
12793 task = current;
12794 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12795 * current stack address. If the stacks consist of nested
12796 * exceptions
12797 */
12798 - tinfo = task_thread_info(task);
12799 for (;;) {
12800 char *id;
12801 unsigned long *estack_end;
12802 +
12803 estack_end = in_exception_stack(cpu, (unsigned long)stack,
12804 &used, &id);
12805
12806 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12807 if (ops->stack(data, id) < 0)
12808 break;
12809
12810 - bp = ops->walk_stack(tinfo, stack, bp, ops,
12811 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
12812 data, estack_end, &graph);
12813 ops->stack(data, "<EOE>");
12814 /*
12815 @@ -172,7 +172,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12816 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
12817 if (ops->stack(data, "IRQ") < 0)
12818 break;
12819 - bp = ops->walk_stack(tinfo, stack, bp,
12820 + bp = ops->walk_stack(task, irq_stack, stack, bp,
12821 ops, data, irq_stack_end, &graph);
12822 /*
12823 * We link to the next stack (which would be
12824 @@ -191,7 +191,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
12825 /*
12826 * This handles the process stack:
12827 */
12828 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
12829 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
12830 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
12831 put_cpu();
12832 }
12833 EXPORT_SYMBOL(dump_trace);
12834 @@ -305,3 +306,50 @@ int is_valid_bugaddr(unsigned long ip)
12835
12836 return ud2 == 0x0b0f;
12837 }
12838 +
12839 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12840 +void pax_check_alloca(unsigned long size)
12841 +{
12842 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
12843 + unsigned cpu, used;
12844 + char *id;
12845 +
12846 + /* check the process stack first */
12847 + stack_start = (unsigned long)task_stack_page(current);
12848 + stack_end = stack_start + THREAD_SIZE;
12849 + if (likely(stack_start <= sp && sp < stack_end)) {
12850 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
12851 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12852 + return;
12853 + }
12854 +
12855 + cpu = get_cpu();
12856 +
12857 + /* check the irq stacks */
12858 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
12859 + stack_start = stack_end - IRQ_STACK_SIZE;
12860 + if (stack_start <= sp && sp < stack_end) {
12861 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
12862 + put_cpu();
12863 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12864 + return;
12865 + }
12866 +
12867 + /* check the exception stacks */
12868 + used = 0;
12869 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
12870 + stack_start = stack_end - EXCEPTION_STKSZ;
12871 + if (stack_end && stack_start <= sp && sp < stack_end) {
12872 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
12873 + put_cpu();
12874 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
12875 + return;
12876 + }
12877 +
12878 + put_cpu();
12879 +
12880 + /* unknown stack */
12881 + BUG();
12882 +}
12883 +EXPORT_SYMBOL(pax_check_alloca);
12884 +#endif
12885 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
12886 index cd28a35..c72ed9a 100644
12887 --- a/arch/x86/kernel/early_printk.c
12888 +++ b/arch/x86/kernel/early_printk.c
12889 @@ -7,6 +7,7 @@
12890 #include <linux/pci_regs.h>
12891 #include <linux/pci_ids.h>
12892 #include <linux/errno.h>
12893 +#include <linux/sched.h>
12894 #include <asm/io.h>
12895 #include <asm/processor.h>
12896 #include <asm/fcntl.h>
12897 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
12898 index f3f6f53..0841b66 100644
12899 --- a/arch/x86/kernel/entry_32.S
12900 +++ b/arch/x86/kernel/entry_32.S
12901 @@ -186,13 +186,146 @@
12902 /*CFI_REL_OFFSET gs, PT_GS*/
12903 .endm
12904 .macro SET_KERNEL_GS reg
12905 +
12906 +#ifdef CONFIG_CC_STACKPROTECTOR
12907 movl $(__KERNEL_STACK_CANARY), \reg
12908 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
12909 + movl $(__USER_DS), \reg
12910 +#else
12911 + xorl \reg, \reg
12912 +#endif
12913 +
12914 movl \reg, %gs
12915 .endm
12916
12917 #endif /* CONFIG_X86_32_LAZY_GS */
12918
12919 -.macro SAVE_ALL
12920 +.macro pax_enter_kernel
12921 +#ifdef CONFIG_PAX_KERNEXEC
12922 + call pax_enter_kernel
12923 +#endif
12924 +.endm
12925 +
12926 +.macro pax_exit_kernel
12927 +#ifdef CONFIG_PAX_KERNEXEC
12928 + call pax_exit_kernel
12929 +#endif
12930 +.endm
12931 +
12932 +#ifdef CONFIG_PAX_KERNEXEC
12933 +ENTRY(pax_enter_kernel)
12934 +#ifdef CONFIG_PARAVIRT
12935 + pushl %eax
12936 + pushl %ecx
12937 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
12938 + mov %eax, %esi
12939 +#else
12940 + mov %cr0, %esi
12941 +#endif
12942 + bts $16, %esi
12943 + jnc 1f
12944 + mov %cs, %esi
12945 + cmp $__KERNEL_CS, %esi
12946 + jz 3f
12947 + ljmp $__KERNEL_CS, $3f
12948 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
12949 +2:
12950 +#ifdef CONFIG_PARAVIRT
12951 + mov %esi, %eax
12952 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12953 +#else
12954 + mov %esi, %cr0
12955 +#endif
12956 +3:
12957 +#ifdef CONFIG_PARAVIRT
12958 + popl %ecx
12959 + popl %eax
12960 +#endif
12961 + ret
12962 +ENDPROC(pax_enter_kernel)
12963 +
12964 +ENTRY(pax_exit_kernel)
12965 +#ifdef CONFIG_PARAVIRT
12966 + pushl %eax
12967 + pushl %ecx
12968 +#endif
12969 + mov %cs, %esi
12970 + cmp $__KERNEXEC_KERNEL_CS, %esi
12971 + jnz 2f
12972 +#ifdef CONFIG_PARAVIRT
12973 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
12974 + mov %eax, %esi
12975 +#else
12976 + mov %cr0, %esi
12977 +#endif
12978 + btr $16, %esi
12979 + ljmp $__KERNEL_CS, $1f
12980 +1:
12981 +#ifdef CONFIG_PARAVIRT
12982 + mov %esi, %eax
12983 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
12984 +#else
12985 + mov %esi, %cr0
12986 +#endif
12987 +2:
12988 +#ifdef CONFIG_PARAVIRT
12989 + popl %ecx
12990 + popl %eax
12991 +#endif
12992 + ret
12993 +ENDPROC(pax_exit_kernel)
12994 +#endif
12995 +
12996 +.macro pax_erase_kstack
12997 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
12998 + call pax_erase_kstack
12999 +#endif
13000 +.endm
13001 +
13002 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13003 +/*
13004 + * ebp: thread_info
13005 + * ecx, edx: can be clobbered
13006 + */
13007 +ENTRY(pax_erase_kstack)
13008 + pushl %edi
13009 + pushl %eax
13010 +
13011 + mov TI_lowest_stack(%ebp), %edi
13012 + mov $-0xBEEF, %eax
13013 + std
13014 +
13015 +1: mov %edi, %ecx
13016 + and $THREAD_SIZE_asm - 1, %ecx
13017 + shr $2, %ecx
13018 + repne scasl
13019 + jecxz 2f
13020 +
13021 + cmp $2*16, %ecx
13022 + jc 2f
13023 +
13024 + mov $2*16, %ecx
13025 + repe scasl
13026 + jecxz 2f
13027 + jne 1b
13028 +
13029 +2: cld
13030 + mov %esp, %ecx
13031 + sub %edi, %ecx
13032 + shr $2, %ecx
13033 + rep stosl
13034 +
13035 + mov TI_task_thread_sp0(%ebp), %edi
13036 + sub $128, %edi
13037 + mov %edi, TI_lowest_stack(%ebp)
13038 +
13039 + popl %eax
13040 + popl %edi
13041 + ret
13042 +ENDPROC(pax_erase_kstack)
13043 +#endif
13044 +
13045 +.macro __SAVE_ALL _DS
13046 cld
13047 PUSH_GS
13048 pushl_cfi %fs
13049 @@ -215,7 +348,7 @@
13050 CFI_REL_OFFSET ecx, 0
13051 pushl_cfi %ebx
13052 CFI_REL_OFFSET ebx, 0
13053 - movl $(__USER_DS), %edx
13054 + movl $\_DS, %edx
13055 movl %edx, %ds
13056 movl %edx, %es
13057 movl $(__KERNEL_PERCPU), %edx
13058 @@ -223,6 +356,15 @@
13059 SET_KERNEL_GS %edx
13060 .endm
13061
13062 +.macro SAVE_ALL
13063 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
13064 + __SAVE_ALL __KERNEL_DS
13065 + pax_enter_kernel
13066 +#else
13067 + __SAVE_ALL __USER_DS
13068 +#endif
13069 +.endm
13070 +
13071 .macro RESTORE_INT_REGS
13072 popl_cfi %ebx
13073 CFI_RESTORE ebx
13074 @@ -308,7 +450,7 @@ ENTRY(ret_from_fork)
13075 popfl_cfi
13076 jmp syscall_exit
13077 CFI_ENDPROC
13078 -END(ret_from_fork)
13079 +ENDPROC(ret_from_fork)
13080
13081 /*
13082 * Interrupt exit functions should be protected against kprobes
13083 @@ -333,7 +475,15 @@ check_userspace:
13084 movb PT_CS(%esp), %al
13085 andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
13086 cmpl $USER_RPL, %eax
13087 +
13088 +#ifdef CONFIG_PAX_KERNEXEC
13089 + jae resume_userspace
13090 +
13091 + PAX_EXIT_KERNEL
13092 + jmp resume_kernel
13093 +#else
13094 jb resume_kernel # not returning to v8086 or userspace
13095 +#endif
13096
13097 ENTRY(resume_userspace)
13098 LOCKDEP_SYS_EXIT
13099 @@ -345,8 +495,8 @@ ENTRY(resume_userspace)
13100 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
13101 # int/exception return?
13102 jne work_pending
13103 - jmp restore_all
13104 -END(ret_from_exception)
13105 + jmp restore_all_pax
13106 +ENDPROC(ret_from_exception)
13107
13108 #ifdef CONFIG_PREEMPT
13109 ENTRY(resume_kernel)
13110 @@ -361,7 +511,7 @@ need_resched:
13111 jz restore_all
13112 call preempt_schedule_irq
13113 jmp need_resched
13114 -END(resume_kernel)
13115 +ENDPROC(resume_kernel)
13116 #endif
13117 CFI_ENDPROC
13118 /*
13119 @@ -395,23 +545,34 @@ sysenter_past_esp:
13120 /*CFI_REL_OFFSET cs, 0*/
13121 /*
13122 * Push current_thread_info()->sysenter_return to the stack.
13123 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
13124 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
13125 */
13126 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
13127 + pushl_cfi $0
13128 CFI_REL_OFFSET eip, 0
13129
13130 pushl_cfi %eax
13131 SAVE_ALL
13132 + GET_THREAD_INFO(%ebp)
13133 + movl TI_sysenter_return(%ebp),%ebp
13134 + movl %ebp,PT_EIP(%esp)
13135 ENABLE_INTERRUPTS(CLBR_NONE)
13136
13137 /*
13138 * Load the potential sixth argument from user stack.
13139 * Careful about security.
13140 */
13141 + movl PT_OLDESP(%esp),%ebp
13142 +
13143 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13144 + mov PT_OLDSS(%esp),%ds
13145 +1: movl %ds:(%ebp),%ebp
13146 + push %ss
13147 + pop %ds
13148 +#else
13149 cmpl $__PAGE_OFFSET-3,%ebp
13150 jae syscall_fault
13151 1: movl (%ebp),%ebp
13152 +#endif
13153 +
13154 movl %ebp,PT_EBP(%esp)
13155 .section __ex_table,"a"
13156 .align 4
13157 @@ -434,12 +595,24 @@ sysenter_do_call:
13158 testl $_TIF_ALLWORK_MASK, %ecx
13159 jne sysexit_audit
13160 sysenter_exit:
13161 +
13162 +#ifdef CONFIG_PAX_RANDKSTACK
13163 + pushl_cfi %eax
13164 + movl %esp, %eax
13165 + call pax_randomize_kstack
13166 + popl_cfi %eax
13167 +#endif
13168 +
13169 + pax_erase_kstack
13170 +
13171 /* if something modifies registers it must also disable sysexit */
13172 movl PT_EIP(%esp), %edx
13173 movl PT_OLDESP(%esp), %ecx
13174 xorl %ebp,%ebp
13175 TRACE_IRQS_ON
13176 1: mov PT_FS(%esp), %fs
13177 +2: mov PT_DS(%esp), %ds
13178 +3: mov PT_ES(%esp), %es
13179 PTGS_TO_GS
13180 ENABLE_INTERRUPTS_SYSEXIT
13181
13182 @@ -456,6 +629,9 @@ sysenter_audit:
13183 movl %eax,%edx /* 2nd arg: syscall number */
13184 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
13185 call audit_syscall_entry
13186 +
13187 + pax_erase_kstack
13188 +
13189 pushl_cfi %ebx
13190 movl PT_EAX(%esp),%eax /* reload syscall number */
13191 jmp sysenter_do_call
13192 @@ -482,11 +658,17 @@ sysexit_audit:
13193
13194 CFI_ENDPROC
13195 .pushsection .fixup,"ax"
13196 -2: movl $0,PT_FS(%esp)
13197 +4: movl $0,PT_FS(%esp)
13198 + jmp 1b
13199 +5: movl $0,PT_DS(%esp)
13200 + jmp 1b
13201 +6: movl $0,PT_ES(%esp)
13202 jmp 1b
13203 .section __ex_table,"a"
13204 .align 4
13205 - .long 1b,2b
13206 + .long 1b,4b
13207 + .long 2b,5b
13208 + .long 3b,6b
13209 .popsection
13210 PTGS_TO_GS_EX
13211 ENDPROC(ia32_sysenter_target)
13212 @@ -519,6 +701,15 @@ syscall_exit:
13213 testl $_TIF_ALLWORK_MASK, %ecx # current->work
13214 jne syscall_exit_work
13215
13216 +restore_all_pax:
13217 +
13218 +#ifdef CONFIG_PAX_RANDKSTACK
13219 + movl %esp, %eax
13220 + call pax_randomize_kstack
13221 +#endif
13222 +
13223 + pax_erase_kstack
13224 +
13225 restore_all:
13226 TRACE_IRQS_IRET
13227 restore_all_notrace:
13228 @@ -578,14 +769,34 @@ ldt_ss:
13229 * compensating for the offset by changing to the ESPFIX segment with
13230 * a base address that matches for the difference.
13231 */
13232 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
13233 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
13234 mov %esp, %edx /* load kernel esp */
13235 mov PT_OLDESP(%esp), %eax /* load userspace esp */
13236 mov %dx, %ax /* eax: new kernel esp */
13237 sub %eax, %edx /* offset (low word is 0) */
13238 +#ifdef CONFIG_SMP
13239 + movl PER_CPU_VAR(cpu_number), %ebx
13240 + shll $PAGE_SHIFT_asm, %ebx
13241 + addl $cpu_gdt_table, %ebx
13242 +#else
13243 + movl $cpu_gdt_table, %ebx
13244 +#endif
13245 shr $16, %edx
13246 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
13247 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
13248 +
13249 +#ifdef CONFIG_PAX_KERNEXEC
13250 + mov %cr0, %esi
13251 + btr $16, %esi
13252 + mov %esi, %cr0
13253 +#endif
13254 +
13255 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
13256 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
13257 +
13258 +#ifdef CONFIG_PAX_KERNEXEC
13259 + bts $16, %esi
13260 + mov %esi, %cr0
13261 +#endif
13262 +
13263 pushl_cfi $__ESPFIX_SS
13264 pushl_cfi %eax /* new kernel esp */
13265 /* Disable interrupts, but do not irqtrace this section: we
13266 @@ -614,34 +825,28 @@ work_resched:
13267 movl TI_flags(%ebp), %ecx
13268 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
13269 # than syscall tracing?
13270 - jz restore_all
13271 + jz restore_all_pax
13272 testb $_TIF_NEED_RESCHED, %cl
13273 jnz work_resched
13274
13275 work_notifysig: # deal with pending signals and
13276 # notify-resume requests
13277 + movl %esp, %eax
13278 #ifdef CONFIG_VM86
13279 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
13280 - movl %esp, %eax
13281 - jne work_notifysig_v86 # returning to kernel-space or
13282 + jz 1f # returning to kernel-space or
13283 # vm86-space
13284 - xorl %edx, %edx
13285 - call do_notify_resume
13286 - jmp resume_userspace_sig
13287
13288 - ALIGN
13289 -work_notifysig_v86:
13290 pushl_cfi %ecx # save ti_flags for do_notify_resume
13291 call save_v86_state # %eax contains pt_regs pointer
13292 popl_cfi %ecx
13293 movl %eax, %esp
13294 -#else
13295 - movl %esp, %eax
13296 +1:
13297 #endif
13298 xorl %edx, %edx
13299 call do_notify_resume
13300 jmp resume_userspace_sig
13301 -END(work_pending)
13302 +ENDPROC(work_pending)
13303
13304 # perform syscall exit tracing
13305 ALIGN
13306 @@ -649,11 +854,14 @@ syscall_trace_entry:
13307 movl $-ENOSYS,PT_EAX(%esp)
13308 movl %esp, %eax
13309 call syscall_trace_enter
13310 +
13311 + pax_erase_kstack
13312 +
13313 /* What it returned is what we'll actually use. */
13314 cmpl $(nr_syscalls), %eax
13315 jnae syscall_call
13316 jmp syscall_exit
13317 -END(syscall_trace_entry)
13318 +ENDPROC(syscall_trace_entry)
13319
13320 # perform syscall exit tracing
13321 ALIGN
13322 @@ -666,20 +874,24 @@ syscall_exit_work:
13323 movl %esp, %eax
13324 call syscall_trace_leave
13325 jmp resume_userspace
13326 -END(syscall_exit_work)
13327 +ENDPROC(syscall_exit_work)
13328 CFI_ENDPROC
13329
13330 RING0_INT_FRAME # can't unwind into user space anyway
13331 syscall_fault:
13332 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13333 + push %ss
13334 + pop %ds
13335 +#endif
13336 GET_THREAD_INFO(%ebp)
13337 movl $-EFAULT,PT_EAX(%esp)
13338 jmp resume_userspace
13339 -END(syscall_fault)
13340 +ENDPROC(syscall_fault)
13341
13342 syscall_badsys:
13343 movl $-ENOSYS,PT_EAX(%esp)
13344 jmp resume_userspace
13345 -END(syscall_badsys)
13346 +ENDPROC(syscall_badsys)
13347 CFI_ENDPROC
13348 /*
13349 * End of kprobes section
13350 @@ -753,6 +965,36 @@ ptregs_clone:
13351 CFI_ENDPROC
13352 ENDPROC(ptregs_clone)
13353
13354 + ALIGN;
13355 +ENTRY(kernel_execve)
13356 + CFI_STARTPROC
13357 + pushl_cfi %ebp
13358 + sub $PT_OLDSS+4,%esp
13359 + pushl_cfi %edi
13360 + pushl_cfi %ecx
13361 + pushl_cfi %eax
13362 + lea 3*4(%esp),%edi
13363 + mov $PT_OLDSS/4+1,%ecx
13364 + xorl %eax,%eax
13365 + rep stosl
13366 + popl_cfi %eax
13367 + popl_cfi %ecx
13368 + popl_cfi %edi
13369 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
13370 + pushl_cfi %esp
13371 + call sys_execve
13372 + add $4,%esp
13373 + CFI_ADJUST_CFA_OFFSET -4
13374 + GET_THREAD_INFO(%ebp)
13375 + test %eax,%eax
13376 + jz syscall_exit
13377 + add $PT_OLDSS+4,%esp
13378 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
13379 + popl_cfi %ebp
13380 + ret
13381 + CFI_ENDPROC
13382 +ENDPROC(kernel_execve)
13383 +
13384 .macro FIXUP_ESPFIX_STACK
13385 /*
13386 * Switch back for ESPFIX stack to the normal zerobased stack
13387 @@ -762,8 +1004,15 @@ ENDPROC(ptregs_clone)
13388 * normal stack and adjusts ESP with the matching offset.
13389 */
13390 /* fixup the stack */
13391 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
13392 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
13393 +#ifdef CONFIG_SMP
13394 + movl PER_CPU_VAR(cpu_number), %ebx
13395 + shll $PAGE_SHIFT_asm, %ebx
13396 + addl $cpu_gdt_table, %ebx
13397 +#else
13398 + movl $cpu_gdt_table, %ebx
13399 +#endif
13400 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
13401 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
13402 shl $16, %eax
13403 addl %esp, %eax /* the adjusted stack pointer */
13404 pushl_cfi $__KERNEL_DS
13405 @@ -816,7 +1065,7 @@ vector=vector+1
13406 .endr
13407 2: jmp common_interrupt
13408 .endr
13409 -END(irq_entries_start)
13410 +ENDPROC(irq_entries_start)
13411
13412 .previous
13413 END(interrupt)
13414 @@ -864,7 +1113,7 @@ ENTRY(coprocessor_error)
13415 pushl_cfi $do_coprocessor_error
13416 jmp error_code
13417 CFI_ENDPROC
13418 -END(coprocessor_error)
13419 +ENDPROC(coprocessor_error)
13420
13421 ENTRY(simd_coprocessor_error)
13422 RING0_INT_FRAME
13423 @@ -885,7 +1134,7 @@ ENTRY(simd_coprocessor_error)
13424 #endif
13425 jmp error_code
13426 CFI_ENDPROC
13427 -END(simd_coprocessor_error)
13428 +ENDPROC(simd_coprocessor_error)
13429
13430 ENTRY(device_not_available)
13431 RING0_INT_FRAME
13432 @@ -893,7 +1142,7 @@ ENTRY(device_not_available)
13433 pushl_cfi $do_device_not_available
13434 jmp error_code
13435 CFI_ENDPROC
13436 -END(device_not_available)
13437 +ENDPROC(device_not_available)
13438
13439 #ifdef CONFIG_PARAVIRT
13440 ENTRY(native_iret)
13441 @@ -902,12 +1151,12 @@ ENTRY(native_iret)
13442 .align 4
13443 .long native_iret, iret_exc
13444 .previous
13445 -END(native_iret)
13446 +ENDPROC(native_iret)
13447
13448 ENTRY(native_irq_enable_sysexit)
13449 sti
13450 sysexit
13451 -END(native_irq_enable_sysexit)
13452 +ENDPROC(native_irq_enable_sysexit)
13453 #endif
13454
13455 ENTRY(overflow)
13456 @@ -916,7 +1165,7 @@ ENTRY(overflow)
13457 pushl_cfi $do_overflow
13458 jmp error_code
13459 CFI_ENDPROC
13460 -END(overflow)
13461 +ENDPROC(overflow)
13462
13463 ENTRY(bounds)
13464 RING0_INT_FRAME
13465 @@ -924,7 +1173,7 @@ ENTRY(bounds)
13466 pushl_cfi $do_bounds
13467 jmp error_code
13468 CFI_ENDPROC
13469 -END(bounds)
13470 +ENDPROC(bounds)
13471
13472 ENTRY(invalid_op)
13473 RING0_INT_FRAME
13474 @@ -932,7 +1181,7 @@ ENTRY(invalid_op)
13475 pushl_cfi $do_invalid_op
13476 jmp error_code
13477 CFI_ENDPROC
13478 -END(invalid_op)
13479 +ENDPROC(invalid_op)
13480
13481 ENTRY(coprocessor_segment_overrun)
13482 RING0_INT_FRAME
13483 @@ -940,35 +1189,35 @@ ENTRY(coprocessor_segment_overrun)
13484 pushl_cfi $do_coprocessor_segment_overrun
13485 jmp error_code
13486 CFI_ENDPROC
13487 -END(coprocessor_segment_overrun)
13488 +ENDPROC(coprocessor_segment_overrun)
13489
13490 ENTRY(invalid_TSS)
13491 RING0_EC_FRAME
13492 pushl_cfi $do_invalid_TSS
13493 jmp error_code
13494 CFI_ENDPROC
13495 -END(invalid_TSS)
13496 +ENDPROC(invalid_TSS)
13497
13498 ENTRY(segment_not_present)
13499 RING0_EC_FRAME
13500 pushl_cfi $do_segment_not_present
13501 jmp error_code
13502 CFI_ENDPROC
13503 -END(segment_not_present)
13504 +ENDPROC(segment_not_present)
13505
13506 ENTRY(stack_segment)
13507 RING0_EC_FRAME
13508 pushl_cfi $do_stack_segment
13509 jmp error_code
13510 CFI_ENDPROC
13511 -END(stack_segment)
13512 +ENDPROC(stack_segment)
13513
13514 ENTRY(alignment_check)
13515 RING0_EC_FRAME
13516 pushl_cfi $do_alignment_check
13517 jmp error_code
13518 CFI_ENDPROC
13519 -END(alignment_check)
13520 +ENDPROC(alignment_check)
13521
13522 ENTRY(divide_error)
13523 RING0_INT_FRAME
13524 @@ -976,7 +1225,7 @@ ENTRY(divide_error)
13525 pushl_cfi $do_divide_error
13526 jmp error_code
13527 CFI_ENDPROC
13528 -END(divide_error)
13529 +ENDPROC(divide_error)
13530
13531 #ifdef CONFIG_X86_MCE
13532 ENTRY(machine_check)
13533 @@ -985,7 +1234,7 @@ ENTRY(machine_check)
13534 pushl_cfi machine_check_vector
13535 jmp error_code
13536 CFI_ENDPROC
13537 -END(machine_check)
13538 +ENDPROC(machine_check)
13539 #endif
13540
13541 ENTRY(spurious_interrupt_bug)
13542 @@ -994,7 +1243,7 @@ ENTRY(spurious_interrupt_bug)
13543 pushl_cfi $do_spurious_interrupt_bug
13544 jmp error_code
13545 CFI_ENDPROC
13546 -END(spurious_interrupt_bug)
13547 +ENDPROC(spurious_interrupt_bug)
13548 /*
13549 * End of kprobes section
13550 */
13551 @@ -1109,7 +1358,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
13552
13553 ENTRY(mcount)
13554 ret
13555 -END(mcount)
13556 +ENDPROC(mcount)
13557
13558 ENTRY(ftrace_caller)
13559 cmpl $0, function_trace_stop
13560 @@ -1138,7 +1387,7 @@ ftrace_graph_call:
13561 .globl ftrace_stub
13562 ftrace_stub:
13563 ret
13564 -END(ftrace_caller)
13565 +ENDPROC(ftrace_caller)
13566
13567 #else /* ! CONFIG_DYNAMIC_FTRACE */
13568
13569 @@ -1174,7 +1423,7 @@ trace:
13570 popl %ecx
13571 popl %eax
13572 jmp ftrace_stub
13573 -END(mcount)
13574 +ENDPROC(mcount)
13575 #endif /* CONFIG_DYNAMIC_FTRACE */
13576 #endif /* CONFIG_FUNCTION_TRACER */
13577
13578 @@ -1195,7 +1444,7 @@ ENTRY(ftrace_graph_caller)
13579 popl %ecx
13580 popl %eax
13581 ret
13582 -END(ftrace_graph_caller)
13583 +ENDPROC(ftrace_graph_caller)
13584
13585 .globl return_to_handler
13586 return_to_handler:
13587 @@ -1209,7 +1458,6 @@ return_to_handler:
13588 jmp *%ecx
13589 #endif
13590
13591 -.section .rodata,"a"
13592 #include "syscall_table_32.S"
13593
13594 syscall_table_size=(.-sys_call_table)
13595 @@ -1255,15 +1503,18 @@ error_code:
13596 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
13597 REG_TO_PTGS %ecx
13598 SET_KERNEL_GS %ecx
13599 - movl $(__USER_DS), %ecx
13600 + movl $(__KERNEL_DS), %ecx
13601 movl %ecx, %ds
13602 movl %ecx, %es
13603 +
13604 + pax_enter_kernel
13605 +
13606 TRACE_IRQS_OFF
13607 movl %esp,%eax # pt_regs pointer
13608 call *%edi
13609 jmp ret_from_exception
13610 CFI_ENDPROC
13611 -END(page_fault)
13612 +ENDPROC(page_fault)
13613
13614 /*
13615 * Debug traps and NMI can happen at the one SYSENTER instruction
13616 @@ -1305,7 +1556,7 @@ debug_stack_correct:
13617 call do_debug
13618 jmp ret_from_exception
13619 CFI_ENDPROC
13620 -END(debug)
13621 +ENDPROC(debug)
13622
13623 /*
13624 * NMI is doubly nasty. It can happen _while_ we're handling
13625 @@ -1342,6 +1593,9 @@ nmi_stack_correct:
13626 xorl %edx,%edx # zero error code
13627 movl %esp,%eax # pt_regs pointer
13628 call do_nmi
13629 +
13630 + pax_exit_kernel
13631 +
13632 jmp restore_all_notrace
13633 CFI_ENDPROC
13634
13635 @@ -1378,12 +1632,15 @@ nmi_espfix_stack:
13636 FIXUP_ESPFIX_STACK # %eax == %esp
13637 xorl %edx,%edx # zero error code
13638 call do_nmi
13639 +
13640 + pax_exit_kernel
13641 +
13642 RESTORE_REGS
13643 lss 12+4(%esp), %esp # back to espfix stack
13644 CFI_ADJUST_CFA_OFFSET -24
13645 jmp irq_return
13646 CFI_ENDPROC
13647 -END(nmi)
13648 +ENDPROC(nmi)
13649
13650 ENTRY(int3)
13651 RING0_INT_FRAME
13652 @@ -1395,14 +1652,14 @@ ENTRY(int3)
13653 call do_int3
13654 jmp ret_from_exception
13655 CFI_ENDPROC
13656 -END(int3)
13657 +ENDPROC(int3)
13658
13659 ENTRY(general_protection)
13660 RING0_EC_FRAME
13661 pushl_cfi $do_general_protection
13662 jmp error_code
13663 CFI_ENDPROC
13664 -END(general_protection)
13665 +ENDPROC(general_protection)
13666
13667 #ifdef CONFIG_KVM_GUEST
13668 ENTRY(async_page_fault)
13669 @@ -1410,7 +1667,7 @@ ENTRY(async_page_fault)
13670 pushl_cfi $do_async_page_fault
13671 jmp error_code
13672 CFI_ENDPROC
13673 -END(async_page_fault)
13674 +ENDPROC(async_page_fault)
13675 #endif
13676
13677 /*
13678 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
13679 index faf8d5e..4f16a68 100644
13680 --- a/arch/x86/kernel/entry_64.S
13681 +++ b/arch/x86/kernel/entry_64.S
13682 @@ -55,6 +55,8 @@
13683 #include <asm/paravirt.h>
13684 #include <asm/ftrace.h>
13685 #include <asm/percpu.h>
13686 +#include <asm/pgtable.h>
13687 +#include <asm/alternative-asm.h>
13688
13689 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13690 #include <linux/elf-em.h>
13691 @@ -68,8 +70,9 @@
13692 #ifdef CONFIG_FUNCTION_TRACER
13693 #ifdef CONFIG_DYNAMIC_FTRACE
13694 ENTRY(mcount)
13695 + pax_force_retaddr
13696 retq
13697 -END(mcount)
13698 +ENDPROC(mcount)
13699
13700 ENTRY(ftrace_caller)
13701 cmpl $0, function_trace_stop
13702 @@ -92,8 +95,9 @@ GLOBAL(ftrace_graph_call)
13703 #endif
13704
13705 GLOBAL(ftrace_stub)
13706 + pax_force_retaddr
13707 retq
13708 -END(ftrace_caller)
13709 +ENDPROC(ftrace_caller)
13710
13711 #else /* ! CONFIG_DYNAMIC_FTRACE */
13712 ENTRY(mcount)
13713 @@ -112,6 +116,7 @@ ENTRY(mcount)
13714 #endif
13715
13716 GLOBAL(ftrace_stub)
13717 + pax_force_retaddr
13718 retq
13719
13720 trace:
13721 @@ -121,12 +126,13 @@ trace:
13722 movq 8(%rbp), %rsi
13723 subq $MCOUNT_INSN_SIZE, %rdi
13724
13725 + pax_force_fptr ftrace_trace_function
13726 call *ftrace_trace_function
13727
13728 MCOUNT_RESTORE_FRAME
13729
13730 jmp ftrace_stub
13731 -END(mcount)
13732 +ENDPROC(mcount)
13733 #endif /* CONFIG_DYNAMIC_FTRACE */
13734 #endif /* CONFIG_FUNCTION_TRACER */
13735
13736 @@ -146,8 +152,9 @@ ENTRY(ftrace_graph_caller)
13737
13738 MCOUNT_RESTORE_FRAME
13739
13740 + pax_force_retaddr
13741 retq
13742 -END(ftrace_graph_caller)
13743 +ENDPROC(ftrace_graph_caller)
13744
13745 GLOBAL(return_to_handler)
13746 subq $24, %rsp
13747 @@ -163,6 +170,7 @@ GLOBAL(return_to_handler)
13748 movq 8(%rsp), %rdx
13749 movq (%rsp), %rax
13750 addq $24, %rsp
13751 + pax_force_fptr %rdi
13752 jmp *%rdi
13753 #endif
13754
13755 @@ -178,6 +186,282 @@ ENTRY(native_usergs_sysret64)
13756 ENDPROC(native_usergs_sysret64)
13757 #endif /* CONFIG_PARAVIRT */
13758
13759 + .macro ljmpq sel, off
13760 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
13761 + .byte 0x48; ljmp *1234f(%rip)
13762 + .pushsection .rodata
13763 + .align 16
13764 + 1234: .quad \off; .word \sel
13765 + .popsection
13766 +#else
13767 + pushq $\sel
13768 + pushq $\off
13769 + lretq
13770 +#endif
13771 + .endm
13772 +
13773 + .macro pax_enter_kernel
13774 + pax_set_fptr_mask
13775 +#ifdef CONFIG_PAX_KERNEXEC
13776 + call pax_enter_kernel
13777 +#endif
13778 + .endm
13779 +
13780 + .macro pax_exit_kernel
13781 +#ifdef CONFIG_PAX_KERNEXEC
13782 + call pax_exit_kernel
13783 +#endif
13784 + .endm
13785 +
13786 +#ifdef CONFIG_PAX_KERNEXEC
13787 +ENTRY(pax_enter_kernel)
13788 + pushq %rdi
13789 +
13790 +#ifdef CONFIG_PARAVIRT
13791 + PV_SAVE_REGS(CLBR_RDI)
13792 +#endif
13793 +
13794 + GET_CR0_INTO_RDI
13795 + bts $16,%rdi
13796 + jnc 3f
13797 + mov %cs,%edi
13798 + cmp $__KERNEL_CS,%edi
13799 + jnz 2f
13800 +1:
13801 +
13802 +#ifdef CONFIG_PARAVIRT
13803 + PV_RESTORE_REGS(CLBR_RDI)
13804 +#endif
13805 +
13806 + popq %rdi
13807 + pax_force_retaddr
13808 + retq
13809 +
13810 +2: ljmpq __KERNEL_CS,1f
13811 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
13812 +4: SET_RDI_INTO_CR0
13813 + jmp 1b
13814 +ENDPROC(pax_enter_kernel)
13815 +
13816 +ENTRY(pax_exit_kernel)
13817 + pushq %rdi
13818 +
13819 +#ifdef CONFIG_PARAVIRT
13820 + PV_SAVE_REGS(CLBR_RDI)
13821 +#endif
13822 +
13823 + mov %cs,%rdi
13824 + cmp $__KERNEXEC_KERNEL_CS,%edi
13825 + jz 2f
13826 +1:
13827 +
13828 +#ifdef CONFIG_PARAVIRT
13829 + PV_RESTORE_REGS(CLBR_RDI);
13830 +#endif
13831 +
13832 + popq %rdi
13833 + pax_force_retaddr
13834 + retq
13835 +
13836 +2: GET_CR0_INTO_RDI
13837 + btr $16,%rdi
13838 + ljmpq __KERNEL_CS,3f
13839 +3: SET_RDI_INTO_CR0
13840 + jmp 1b
13841 +#ifdef CONFIG_PARAVIRT
13842 + PV_RESTORE_REGS(CLBR_RDI);
13843 +#endif
13844 +
13845 + popq %rdi
13846 + pax_force_retaddr
13847 + retq
13848 +ENDPROC(pax_exit_kernel)
13849 +#endif
13850 +
13851 + .macro pax_enter_kernel_user
13852 + pax_set_fptr_mask
13853 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13854 + call pax_enter_kernel_user
13855 +#endif
13856 + .endm
13857 +
13858 + .macro pax_exit_kernel_user
13859 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13860 + call pax_exit_kernel_user
13861 +#endif
13862 +#ifdef CONFIG_PAX_RANDKSTACK
13863 + pushq %rax
13864 + call pax_randomize_kstack
13865 + popq %rax
13866 +#endif
13867 + .endm
13868 +
13869 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13870 +ENTRY(pax_enter_kernel_user)
13871 + pushq %rdi
13872 + pushq %rbx
13873 +
13874 +#ifdef CONFIG_PARAVIRT
13875 + PV_SAVE_REGS(CLBR_RDI)
13876 +#endif
13877 +
13878 + GET_CR3_INTO_RDI
13879 + mov %rdi,%rbx
13880 + add $__START_KERNEL_map,%rbx
13881 + sub phys_base(%rip),%rbx
13882 +
13883 +#ifdef CONFIG_PARAVIRT
13884 + pushq %rdi
13885 + cmpl $0, pv_info+PARAVIRT_enabled
13886 + jz 1f
13887 + i = 0
13888 + .rept USER_PGD_PTRS
13889 + mov i*8(%rbx),%rsi
13890 + mov $0,%sil
13891 + lea i*8(%rbx),%rdi
13892 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13893 + i = i + 1
13894 + .endr
13895 + jmp 2f
13896 +1:
13897 +#endif
13898 +
13899 + i = 0
13900 + .rept USER_PGD_PTRS
13901 + movb $0,i*8(%rbx)
13902 + i = i + 1
13903 + .endr
13904 +
13905 +#ifdef CONFIG_PARAVIRT
13906 +2: popq %rdi
13907 +#endif
13908 + SET_RDI_INTO_CR3
13909 +
13910 +#ifdef CONFIG_PAX_KERNEXEC
13911 + GET_CR0_INTO_RDI
13912 + bts $16,%rdi
13913 + SET_RDI_INTO_CR0
13914 +#endif
13915 +
13916 +#ifdef CONFIG_PARAVIRT
13917 + PV_RESTORE_REGS(CLBR_RDI)
13918 +#endif
13919 +
13920 + popq %rbx
13921 + popq %rdi
13922 + pax_force_retaddr
13923 + retq
13924 +ENDPROC(pax_enter_kernel_user)
13925 +
13926 +ENTRY(pax_exit_kernel_user)
13927 + push %rdi
13928 +
13929 +#ifdef CONFIG_PARAVIRT
13930 + pushq %rbx
13931 + PV_SAVE_REGS(CLBR_RDI)
13932 +#endif
13933 +
13934 +#ifdef CONFIG_PAX_KERNEXEC
13935 + GET_CR0_INTO_RDI
13936 + btr $16,%rdi
13937 + SET_RDI_INTO_CR0
13938 +#endif
13939 +
13940 + GET_CR3_INTO_RDI
13941 + add $__START_KERNEL_map,%rdi
13942 + sub phys_base(%rip),%rdi
13943 +
13944 +#ifdef CONFIG_PARAVIRT
13945 + cmpl $0, pv_info+PARAVIRT_enabled
13946 + jz 1f
13947 + mov %rdi,%rbx
13948 + i = 0
13949 + .rept USER_PGD_PTRS
13950 + mov i*8(%rbx),%rsi
13951 + mov $0x67,%sil
13952 + lea i*8(%rbx),%rdi
13953 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
13954 + i = i + 1
13955 + .endr
13956 + jmp 2f
13957 +1:
13958 +#endif
13959 +
13960 + i = 0
13961 + .rept USER_PGD_PTRS
13962 + movb $0x67,i*8(%rdi)
13963 + i = i + 1
13964 + .endr
13965 +
13966 +#ifdef CONFIG_PARAVIRT
13967 +2: PV_RESTORE_REGS(CLBR_RDI)
13968 + popq %rbx
13969 +#endif
13970 +
13971 + popq %rdi
13972 + pax_force_retaddr
13973 + retq
13974 +ENDPROC(pax_exit_kernel_user)
13975 +#endif
13976 +
13977 +.macro pax_erase_kstack
13978 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13979 + call pax_erase_kstack
13980 +#endif
13981 +.endm
13982 +
13983 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13984 +/*
13985 + * r11: thread_info
13986 + * rcx, rdx: can be clobbered
13987 + */
13988 +ENTRY(pax_erase_kstack)
13989 + pushq %rdi
13990 + pushq %rax
13991 + pushq %r11
13992 +
13993 + GET_THREAD_INFO(%r11)
13994 + mov TI_lowest_stack(%r11), %rdi
13995 + mov $-0xBEEF, %rax
13996 + std
13997 +
13998 +1: mov %edi, %ecx
13999 + and $THREAD_SIZE_asm - 1, %ecx
14000 + shr $3, %ecx
14001 + repne scasq
14002 + jecxz 2f
14003 +
14004 + cmp $2*8, %ecx
14005 + jc 2f
14006 +
14007 + mov $2*8, %ecx
14008 + repe scasq
14009 + jecxz 2f
14010 + jne 1b
14011 +
14012 +2: cld
14013 + mov %esp, %ecx
14014 + sub %edi, %ecx
14015 +
14016 + cmp $THREAD_SIZE_asm, %rcx
14017 + jb 3f
14018 + ud2
14019 +3:
14020 +
14021 + shr $3, %ecx
14022 + rep stosq
14023 +
14024 + mov TI_task_thread_sp0(%r11), %rdi
14025 + sub $256, %rdi
14026 + mov %rdi, TI_lowest_stack(%r11)
14027 +
14028 + popq %r11
14029 + popq %rax
14030 + popq %rdi
14031 + pax_force_retaddr
14032 + ret
14033 +ENDPROC(pax_erase_kstack)
14034 +#endif
14035
14036 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
14037 #ifdef CONFIG_TRACE_IRQFLAGS
14038 @@ -231,8 +515,8 @@ ENDPROC(native_usergs_sysret64)
14039 .endm
14040
14041 .macro UNFAKE_STACK_FRAME
14042 - addq $8*6, %rsp
14043 - CFI_ADJUST_CFA_OFFSET -(6*8)
14044 + addq $8*6 + ARG_SKIP, %rsp
14045 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
14046 .endm
14047
14048 /*
14049 @@ -319,7 +603,7 @@ ENDPROC(native_usergs_sysret64)
14050 movq %rsp, %rsi
14051
14052 leaq -RBP(%rsp),%rdi /* arg1 for handler */
14053 - testl $3, CS(%rdi)
14054 + testb $3, CS(%rdi)
14055 je 1f
14056 SWAPGS
14057 /*
14058 @@ -355,9 +639,10 @@ ENTRY(save_rest)
14059 movq_cfi r15, R15+16
14060 movq %r11, 8(%rsp) /* return address */
14061 FIXUP_TOP_OF_STACK %r11, 16
14062 + pax_force_retaddr
14063 ret
14064 CFI_ENDPROC
14065 -END(save_rest)
14066 +ENDPROC(save_rest)
14067
14068 /* save complete stack frame */
14069 .pushsection .kprobes.text, "ax"
14070 @@ -386,9 +671,10 @@ ENTRY(save_paranoid)
14071 js 1f /* negative -> in kernel */
14072 SWAPGS
14073 xorl %ebx,%ebx
14074 -1: ret
14075 +1: pax_force_retaddr_bts
14076 + ret
14077 CFI_ENDPROC
14078 -END(save_paranoid)
14079 +ENDPROC(save_paranoid)
14080 .popsection
14081
14082 /*
14083 @@ -410,7 +696,7 @@ ENTRY(ret_from_fork)
14084
14085 RESTORE_REST
14086
14087 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14088 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
14089 je int_ret_from_sys_call
14090
14091 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
14092 @@ -420,7 +706,7 @@ ENTRY(ret_from_fork)
14093 jmp ret_from_sys_call # go to the SYSRET fastpath
14094
14095 CFI_ENDPROC
14096 -END(ret_from_fork)
14097 +ENDPROC(ret_from_fork)
14098
14099 /*
14100 * System call entry. Up to 6 arguments in registers are supported.
14101 @@ -456,7 +742,7 @@ END(ret_from_fork)
14102 ENTRY(system_call)
14103 CFI_STARTPROC simple
14104 CFI_SIGNAL_FRAME
14105 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14106 + CFI_DEF_CFA rsp,0
14107 CFI_REGISTER rip,rcx
14108 /*CFI_REGISTER rflags,r11*/
14109 SWAPGS_UNSAFE_STACK
14110 @@ -469,12 +755,13 @@ ENTRY(system_call_after_swapgs)
14111
14112 movq %rsp,PER_CPU_VAR(old_rsp)
14113 movq PER_CPU_VAR(kernel_stack),%rsp
14114 + SAVE_ARGS 8*6,0
14115 + pax_enter_kernel_user
14116 /*
14117 * No need to follow this irqs off/on section - it's straight
14118 * and short:
14119 */
14120 ENABLE_INTERRUPTS(CLBR_NONE)
14121 - SAVE_ARGS 8,0
14122 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14123 movq %rcx,RIP-ARGOFFSET(%rsp)
14124 CFI_REL_OFFSET rip,RIP-ARGOFFSET
14125 @@ -484,7 +771,7 @@ ENTRY(system_call_after_swapgs)
14126 system_call_fastpath:
14127 cmpq $__NR_syscall_max,%rax
14128 ja badsys
14129 - movq %r10,%rcx
14130 + movq R10-ARGOFFSET(%rsp),%rcx
14131 call *sys_call_table(,%rax,8) # XXX: rip relative
14132 movq %rax,RAX-ARGOFFSET(%rsp)
14133 /*
14134 @@ -503,6 +790,8 @@ sysret_check:
14135 andl %edi,%edx
14136 jnz sysret_careful
14137 CFI_REMEMBER_STATE
14138 + pax_exit_kernel_user
14139 + pax_erase_kstack
14140 /*
14141 * sysretq will re-enable interrupts:
14142 */
14143 @@ -554,14 +843,18 @@ badsys:
14144 * jump back to the normal fast path.
14145 */
14146 auditsys:
14147 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
14148 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
14149 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
14150 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
14151 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
14152 movq %rax,%rsi /* 2nd arg: syscall number */
14153 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
14154 call audit_syscall_entry
14155 +
14156 + pax_erase_kstack
14157 +
14158 LOAD_ARGS 0 /* reload call-clobbered registers */
14159 + pax_set_fptr_mask
14160 jmp system_call_fastpath
14161
14162 /*
14163 @@ -591,16 +884,20 @@ tracesys:
14164 FIXUP_TOP_OF_STACK %rdi
14165 movq %rsp,%rdi
14166 call syscall_trace_enter
14167 +
14168 + pax_erase_kstack
14169 +
14170 /*
14171 * Reload arg registers from stack in case ptrace changed them.
14172 * We don't reload %rax because syscall_trace_enter() returned
14173 * the value it wants us to use in the table lookup.
14174 */
14175 LOAD_ARGS ARGOFFSET, 1
14176 + pax_set_fptr_mask
14177 RESTORE_REST
14178 cmpq $__NR_syscall_max,%rax
14179 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
14180 - movq %r10,%rcx /* fixup for C */
14181 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
14182 call *sys_call_table(,%rax,8)
14183 movq %rax,RAX-ARGOFFSET(%rsp)
14184 /* Use IRET because user could have changed frame */
14185 @@ -612,7 +909,7 @@ tracesys:
14186 GLOBAL(int_ret_from_sys_call)
14187 DISABLE_INTERRUPTS(CLBR_NONE)
14188 TRACE_IRQS_OFF
14189 - testl $3,CS-ARGOFFSET(%rsp)
14190 + testb $3,CS-ARGOFFSET(%rsp)
14191 je retint_restore_args
14192 movl $_TIF_ALLWORK_MASK,%edi
14193 /* edi: mask to check */
14194 @@ -623,6 +920,7 @@ GLOBAL(int_with_check)
14195 andl %edi,%edx
14196 jnz int_careful
14197 andl $~TS_COMPAT,TI_status(%rcx)
14198 + pax_erase_kstack
14199 jmp retint_swapgs
14200
14201 /* Either reschedule or signal or syscall exit tracking needed. */
14202 @@ -669,7 +967,7 @@ int_restore_rest:
14203 TRACE_IRQS_OFF
14204 jmp int_with_check
14205 CFI_ENDPROC
14206 -END(system_call)
14207 +ENDPROC(system_call)
14208
14209 /*
14210 * Certain special system calls that need to save a complete full stack frame.
14211 @@ -685,7 +983,7 @@ ENTRY(\label)
14212 call \func
14213 jmp ptregscall_common
14214 CFI_ENDPROC
14215 -END(\label)
14216 +ENDPROC(\label)
14217 .endm
14218
14219 PTREGSCALL stub_clone, sys_clone, %r8
14220 @@ -703,9 +1001,10 @@ ENTRY(ptregscall_common)
14221 movq_cfi_restore R12+8, r12
14222 movq_cfi_restore RBP+8, rbp
14223 movq_cfi_restore RBX+8, rbx
14224 + pax_force_retaddr
14225 ret $REST_SKIP /* pop extended registers */
14226 CFI_ENDPROC
14227 -END(ptregscall_common)
14228 +ENDPROC(ptregscall_common)
14229
14230 ENTRY(stub_execve)
14231 CFI_STARTPROC
14232 @@ -720,7 +1019,7 @@ ENTRY(stub_execve)
14233 RESTORE_REST
14234 jmp int_ret_from_sys_call
14235 CFI_ENDPROC
14236 -END(stub_execve)
14237 +ENDPROC(stub_execve)
14238
14239 /*
14240 * sigreturn is special because it needs to restore all registers on return.
14241 @@ -738,7 +1037,7 @@ ENTRY(stub_rt_sigreturn)
14242 RESTORE_REST
14243 jmp int_ret_from_sys_call
14244 CFI_ENDPROC
14245 -END(stub_rt_sigreturn)
14246 +ENDPROC(stub_rt_sigreturn)
14247
14248 /*
14249 * Build the entry stubs and pointer table with some assembler magic.
14250 @@ -773,7 +1072,7 @@ vector=vector+1
14251 2: jmp common_interrupt
14252 .endr
14253 CFI_ENDPROC
14254 -END(irq_entries_start)
14255 +ENDPROC(irq_entries_start)
14256
14257 .previous
14258 END(interrupt)
14259 @@ -793,6 +1092,16 @@ END(interrupt)
14260 subq $ORIG_RAX-RBP, %rsp
14261 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
14262 SAVE_ARGS_IRQ
14263 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14264 + testb $3, CS(%rdi)
14265 + jnz 1f
14266 + pax_enter_kernel
14267 + jmp 2f
14268 +1: pax_enter_kernel_user
14269 +2:
14270 +#else
14271 + pax_enter_kernel
14272 +#endif
14273 call \func
14274 .endm
14275
14276 @@ -824,7 +1133,7 @@ ret_from_intr:
14277
14278 exit_intr:
14279 GET_THREAD_INFO(%rcx)
14280 - testl $3,CS-ARGOFFSET(%rsp)
14281 + testb $3,CS-ARGOFFSET(%rsp)
14282 je retint_kernel
14283
14284 /* Interrupt came from user space */
14285 @@ -846,12 +1155,15 @@ retint_swapgs: /* return to user-space */
14286 * The iretq could re-enable interrupts:
14287 */
14288 DISABLE_INTERRUPTS(CLBR_ANY)
14289 + pax_exit_kernel_user
14290 TRACE_IRQS_IRETQ
14291 SWAPGS
14292 jmp restore_args
14293
14294 retint_restore_args: /* return to kernel space */
14295 DISABLE_INTERRUPTS(CLBR_ANY)
14296 + pax_exit_kernel
14297 + pax_force_retaddr RIP-ARGOFFSET
14298 /*
14299 * The iretq could re-enable interrupts:
14300 */
14301 @@ -940,7 +1252,7 @@ ENTRY(retint_kernel)
14302 #endif
14303
14304 CFI_ENDPROC
14305 -END(common_interrupt)
14306 +ENDPROC(common_interrupt)
14307 /*
14308 * End of kprobes section
14309 */
14310 @@ -956,7 +1268,7 @@ ENTRY(\sym)
14311 interrupt \do_sym
14312 jmp ret_from_intr
14313 CFI_ENDPROC
14314 -END(\sym)
14315 +ENDPROC(\sym)
14316 .endm
14317
14318 #ifdef CONFIG_SMP
14319 @@ -1021,12 +1333,22 @@ ENTRY(\sym)
14320 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14321 call error_entry
14322 DEFAULT_FRAME 0
14323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14324 + testb $3, CS(%rsp)
14325 + jnz 1f
14326 + pax_enter_kernel
14327 + jmp 2f
14328 +1: pax_enter_kernel_user
14329 +2:
14330 +#else
14331 + pax_enter_kernel
14332 +#endif
14333 movq %rsp,%rdi /* pt_regs pointer */
14334 xorl %esi,%esi /* no error code */
14335 call \do_sym
14336 jmp error_exit /* %ebx: no swapgs flag */
14337 CFI_ENDPROC
14338 -END(\sym)
14339 +ENDPROC(\sym)
14340 .endm
14341
14342 .macro paranoidzeroentry sym do_sym
14343 @@ -1038,15 +1360,25 @@ ENTRY(\sym)
14344 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14345 call save_paranoid
14346 TRACE_IRQS_OFF
14347 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14348 + testb $3, CS(%rsp)
14349 + jnz 1f
14350 + pax_enter_kernel
14351 + jmp 2f
14352 +1: pax_enter_kernel_user
14353 +2:
14354 +#else
14355 + pax_enter_kernel
14356 +#endif
14357 movq %rsp,%rdi /* pt_regs pointer */
14358 xorl %esi,%esi /* no error code */
14359 call \do_sym
14360 jmp paranoid_exit /* %ebx: no swapgs flag */
14361 CFI_ENDPROC
14362 -END(\sym)
14363 +ENDPROC(\sym)
14364 .endm
14365
14366 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
14367 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
14368 .macro paranoidzeroentry_ist sym do_sym ist
14369 ENTRY(\sym)
14370 INTR_FRAME
14371 @@ -1056,14 +1388,30 @@ ENTRY(\sym)
14372 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14373 call save_paranoid
14374 TRACE_IRQS_OFF
14375 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14376 + testb $3, CS(%rsp)
14377 + jnz 1f
14378 + pax_enter_kernel
14379 + jmp 2f
14380 +1: pax_enter_kernel_user
14381 +2:
14382 +#else
14383 + pax_enter_kernel
14384 +#endif
14385 movq %rsp,%rdi /* pt_regs pointer */
14386 xorl %esi,%esi /* no error code */
14387 +#ifdef CONFIG_SMP
14388 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
14389 + lea init_tss(%r12), %r12
14390 +#else
14391 + lea init_tss(%rip), %r12
14392 +#endif
14393 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14394 call \do_sym
14395 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
14396 jmp paranoid_exit /* %ebx: no swapgs flag */
14397 CFI_ENDPROC
14398 -END(\sym)
14399 +ENDPROC(\sym)
14400 .endm
14401
14402 .macro errorentry sym do_sym
14403 @@ -1074,13 +1422,23 @@ ENTRY(\sym)
14404 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14405 call error_entry
14406 DEFAULT_FRAME 0
14407 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14408 + testb $3, CS(%rsp)
14409 + jnz 1f
14410 + pax_enter_kernel
14411 + jmp 2f
14412 +1: pax_enter_kernel_user
14413 +2:
14414 +#else
14415 + pax_enter_kernel
14416 +#endif
14417 movq %rsp,%rdi /* pt_regs pointer */
14418 movq ORIG_RAX(%rsp),%rsi /* get error code */
14419 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14420 call \do_sym
14421 jmp error_exit /* %ebx: no swapgs flag */
14422 CFI_ENDPROC
14423 -END(\sym)
14424 +ENDPROC(\sym)
14425 .endm
14426
14427 /* error code is on the stack already */
14428 @@ -1093,13 +1451,23 @@ ENTRY(\sym)
14429 call save_paranoid
14430 DEFAULT_FRAME 0
14431 TRACE_IRQS_OFF
14432 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14433 + testb $3, CS(%rsp)
14434 + jnz 1f
14435 + pax_enter_kernel
14436 + jmp 2f
14437 +1: pax_enter_kernel_user
14438 +2:
14439 +#else
14440 + pax_enter_kernel
14441 +#endif
14442 movq %rsp,%rdi /* pt_regs pointer */
14443 movq ORIG_RAX(%rsp),%rsi /* get error code */
14444 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
14445 call \do_sym
14446 jmp paranoid_exit /* %ebx: no swapgs flag */
14447 CFI_ENDPROC
14448 -END(\sym)
14449 +ENDPROC(\sym)
14450 .endm
14451
14452 zeroentry divide_error do_divide_error
14453 @@ -1129,9 +1497,10 @@ gs_change:
14454 2: mfence /* workaround */
14455 SWAPGS
14456 popfq_cfi
14457 + pax_force_retaddr
14458 ret
14459 CFI_ENDPROC
14460 -END(native_load_gs_index)
14461 +ENDPROC(native_load_gs_index)
14462
14463 .section __ex_table,"a"
14464 .align 8
14465 @@ -1153,13 +1522,14 @@ ENTRY(kernel_thread_helper)
14466 * Here we are in the child and the registers are set as they were
14467 * at kernel_thread() invocation in the parent.
14468 */
14469 + pax_force_fptr %rsi
14470 call *%rsi
14471 # exit
14472 mov %eax, %edi
14473 call do_exit
14474 ud2 # padding for call trace
14475 CFI_ENDPROC
14476 -END(kernel_thread_helper)
14477 +ENDPROC(kernel_thread_helper)
14478
14479 /*
14480 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
14481 @@ -1186,11 +1556,11 @@ ENTRY(kernel_execve)
14482 RESTORE_REST
14483 testq %rax,%rax
14484 je int_ret_from_sys_call
14485 - RESTORE_ARGS
14486 UNFAKE_STACK_FRAME
14487 + pax_force_retaddr
14488 ret
14489 CFI_ENDPROC
14490 -END(kernel_execve)
14491 +ENDPROC(kernel_execve)
14492
14493 /* Call softirq on interrupt stack. Interrupts are off. */
14494 ENTRY(call_softirq)
14495 @@ -1208,9 +1578,10 @@ ENTRY(call_softirq)
14496 CFI_DEF_CFA_REGISTER rsp
14497 CFI_ADJUST_CFA_OFFSET -8
14498 decl PER_CPU_VAR(irq_count)
14499 + pax_force_retaddr
14500 ret
14501 CFI_ENDPROC
14502 -END(call_softirq)
14503 +ENDPROC(call_softirq)
14504
14505 #ifdef CONFIG_XEN
14506 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
14507 @@ -1248,7 +1619,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
14508 decl PER_CPU_VAR(irq_count)
14509 jmp error_exit
14510 CFI_ENDPROC
14511 -END(xen_do_hypervisor_callback)
14512 +ENDPROC(xen_do_hypervisor_callback)
14513
14514 /*
14515 * Hypervisor uses this for application faults while it executes.
14516 @@ -1307,7 +1678,7 @@ ENTRY(xen_failsafe_callback)
14517 SAVE_ALL
14518 jmp error_exit
14519 CFI_ENDPROC
14520 -END(xen_failsafe_callback)
14521 +ENDPROC(xen_failsafe_callback)
14522
14523 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
14524 xen_hvm_callback_vector xen_evtchn_do_upcall
14525 @@ -1356,16 +1727,31 @@ ENTRY(paranoid_exit)
14526 TRACE_IRQS_OFF
14527 testl %ebx,%ebx /* swapgs needed? */
14528 jnz paranoid_restore
14529 - testl $3,CS(%rsp)
14530 + testb $3,CS(%rsp)
14531 jnz paranoid_userspace
14532 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14533 + pax_exit_kernel
14534 + TRACE_IRQS_IRETQ 0
14535 + SWAPGS_UNSAFE_STACK
14536 + RESTORE_ALL 8
14537 + pax_force_retaddr_bts
14538 + jmp irq_return
14539 +#endif
14540 paranoid_swapgs:
14541 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14542 + pax_exit_kernel_user
14543 +#else
14544 + pax_exit_kernel
14545 +#endif
14546 TRACE_IRQS_IRETQ 0
14547 SWAPGS_UNSAFE_STACK
14548 RESTORE_ALL 8
14549 jmp irq_return
14550 paranoid_restore:
14551 + pax_exit_kernel
14552 TRACE_IRQS_IRETQ 0
14553 RESTORE_ALL 8
14554 + pax_force_retaddr_bts
14555 jmp irq_return
14556 paranoid_userspace:
14557 GET_THREAD_INFO(%rcx)
14558 @@ -1394,7 +1780,7 @@ paranoid_schedule:
14559 TRACE_IRQS_OFF
14560 jmp paranoid_userspace
14561 CFI_ENDPROC
14562 -END(paranoid_exit)
14563 +ENDPROC(paranoid_exit)
14564
14565 /*
14566 * Exception entry point. This expects an error code/orig_rax on the stack.
14567 @@ -1421,12 +1807,13 @@ ENTRY(error_entry)
14568 movq_cfi r14, R14+8
14569 movq_cfi r15, R15+8
14570 xorl %ebx,%ebx
14571 - testl $3,CS+8(%rsp)
14572 + testb $3,CS+8(%rsp)
14573 je error_kernelspace
14574 error_swapgs:
14575 SWAPGS
14576 error_sti:
14577 TRACE_IRQS_OFF
14578 + pax_force_retaddr_bts
14579 ret
14580
14581 /*
14582 @@ -1453,7 +1840,7 @@ bstep_iret:
14583 movq %rcx,RIP+8(%rsp)
14584 jmp error_swapgs
14585 CFI_ENDPROC
14586 -END(error_entry)
14587 +ENDPROC(error_entry)
14588
14589
14590 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
14591 @@ -1473,7 +1860,7 @@ ENTRY(error_exit)
14592 jnz retint_careful
14593 jmp retint_swapgs
14594 CFI_ENDPROC
14595 -END(error_exit)
14596 +ENDPROC(error_exit)
14597
14598
14599 /* runs on exception stack */
14600 @@ -1485,6 +1872,16 @@ ENTRY(nmi)
14601 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
14602 call save_paranoid
14603 DEFAULT_FRAME 0
14604 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14605 + testb $3, CS(%rsp)
14606 + jnz 1f
14607 + pax_enter_kernel
14608 + jmp 2f
14609 +1: pax_enter_kernel_user
14610 +2:
14611 +#else
14612 + pax_enter_kernel
14613 +#endif
14614 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
14615 movq %rsp,%rdi
14616 movq $-1,%rsi
14617 @@ -1495,12 +1892,28 @@ ENTRY(nmi)
14618 DISABLE_INTERRUPTS(CLBR_NONE)
14619 testl %ebx,%ebx /* swapgs needed? */
14620 jnz nmi_restore
14621 - testl $3,CS(%rsp)
14622 + testb $3,CS(%rsp)
14623 jnz nmi_userspace
14624 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14625 + pax_exit_kernel
14626 + SWAPGS_UNSAFE_STACK
14627 + RESTORE_ALL 8
14628 + pax_force_retaddr_bts
14629 + jmp irq_return
14630 +#endif
14631 nmi_swapgs:
14632 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14633 + pax_exit_kernel_user
14634 +#else
14635 + pax_exit_kernel
14636 +#endif
14637 SWAPGS_UNSAFE_STACK
14638 + RESTORE_ALL 8
14639 + jmp irq_return
14640 nmi_restore:
14641 + pax_exit_kernel
14642 RESTORE_ALL 8
14643 + pax_force_retaddr_bts
14644 jmp irq_return
14645 nmi_userspace:
14646 GET_THREAD_INFO(%rcx)
14647 @@ -1529,14 +1942,14 @@ nmi_schedule:
14648 jmp paranoid_exit
14649 CFI_ENDPROC
14650 #endif
14651 -END(nmi)
14652 +ENDPROC(nmi)
14653
14654 ENTRY(ignore_sysret)
14655 CFI_STARTPROC
14656 mov $-ENOSYS,%eax
14657 sysret
14658 CFI_ENDPROC
14659 -END(ignore_sysret)
14660 +ENDPROC(ignore_sysret)
14661
14662 /*
14663 * End of kprobes section
14664 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
14665 index c9a281f..ce2f317 100644
14666 --- a/arch/x86/kernel/ftrace.c
14667 +++ b/arch/x86/kernel/ftrace.c
14668 @@ -126,7 +126,7 @@ static void *mod_code_ip; /* holds the IP to write to */
14669 static const void *mod_code_newcode; /* holds the text to write to the IP */
14670
14671 static unsigned nmi_wait_count;
14672 -static atomic_t nmi_update_count = ATOMIC_INIT(0);
14673 +static atomic_unchecked_t nmi_update_count = ATOMIC_INIT(0);
14674
14675 int ftrace_arch_read_dyn_info(char *buf, int size)
14676 {
14677 @@ -134,7 +134,7 @@ int ftrace_arch_read_dyn_info(char *buf, int size)
14678
14679 r = snprintf(buf, size, "%u %u",
14680 nmi_wait_count,
14681 - atomic_read(&nmi_update_count));
14682 + atomic_read_unchecked(&nmi_update_count));
14683 return r;
14684 }
14685
14686 @@ -177,8 +177,10 @@ void ftrace_nmi_enter(void)
14687
14688 if (atomic_inc_return(&nmi_running) & MOD_CODE_WRITE_FLAG) {
14689 smp_rmb();
14690 + pax_open_kernel();
14691 ftrace_mod_code();
14692 - atomic_inc(&nmi_update_count);
14693 + pax_close_kernel();
14694 + atomic_inc_unchecked(&nmi_update_count);
14695 }
14696 /* Must have previous changes seen before executions */
14697 smp_mb();
14698 @@ -271,6 +273,8 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
14699 {
14700 unsigned char replaced[MCOUNT_INSN_SIZE];
14701
14702 + ip = ktla_ktva(ip);
14703 +
14704 /*
14705 * Note: Due to modules and __init, code can
14706 * disappear and change, we need to protect against faulting
14707 @@ -327,7 +331,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
14708 unsigned char old[MCOUNT_INSN_SIZE], *new;
14709 int ret;
14710
14711 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
14712 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
14713 new = ftrace_call_replace(ip, (unsigned long)func);
14714 ret = ftrace_modify_code(ip, old, new);
14715
14716 @@ -353,6 +357,8 @@ static int ftrace_mod_jmp(unsigned long ip,
14717 {
14718 unsigned char code[MCOUNT_INSN_SIZE];
14719
14720 + ip = ktla_ktva(ip);
14721 +
14722 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
14723 return -EFAULT;
14724
14725 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
14726 index 3bb0850..55a56f4 100644
14727 --- a/arch/x86/kernel/head32.c
14728 +++ b/arch/x86/kernel/head32.c
14729 @@ -19,6 +19,7 @@
14730 #include <asm/io_apic.h>
14731 #include <asm/bios_ebda.h>
14732 #include <asm/tlbflush.h>
14733 +#include <asm/boot.h>
14734
14735 static void __init i386_default_early_setup(void)
14736 {
14737 @@ -33,7 +34,7 @@ void __init i386_start_kernel(void)
14738 {
14739 memblock_init();
14740
14741 - memblock_x86_reserve_range(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14742 + memblock_x86_reserve_range(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop), "TEXT DATA BSS");
14743
14744 #ifdef CONFIG_BLK_DEV_INITRD
14745 /* Reserve INITRD */
14746 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
14747 index ce0be7c..c41476e 100644
14748 --- a/arch/x86/kernel/head_32.S
14749 +++ b/arch/x86/kernel/head_32.S
14750 @@ -25,6 +25,12 @@
14751 /* Physical address */
14752 #define pa(X) ((X) - __PAGE_OFFSET)
14753
14754 +#ifdef CONFIG_PAX_KERNEXEC
14755 +#define ta(X) (X)
14756 +#else
14757 +#define ta(X) ((X) - __PAGE_OFFSET)
14758 +#endif
14759 +
14760 /*
14761 * References to members of the new_cpu_data structure.
14762 */
14763 @@ -54,11 +60,7 @@
14764 * and small than max_low_pfn, otherwise will waste some page table entries
14765 */
14766
14767 -#if PTRS_PER_PMD > 1
14768 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
14769 -#else
14770 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
14771 -#endif
14772 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
14773
14774 /* Number of possible pages in the lowmem region */
14775 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
14776 @@ -77,6 +79,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
14777 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14778
14779 /*
14780 + * Real beginning of normal "text" segment
14781 + */
14782 +ENTRY(stext)
14783 +ENTRY(_stext)
14784 +
14785 +/*
14786 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
14787 * %esi points to the real-mode code as a 32-bit pointer.
14788 * CS and DS must be 4 GB flat segments, but we don't depend on
14789 @@ -84,6 +92,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
14790 * can.
14791 */
14792 __HEAD
14793 +
14794 +#ifdef CONFIG_PAX_KERNEXEC
14795 + jmp startup_32
14796 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
14797 +.fill PAGE_SIZE-5,1,0xcc
14798 +#endif
14799 +
14800 ENTRY(startup_32)
14801 movl pa(stack_start),%ecx
14802
14803 @@ -105,6 +120,57 @@ ENTRY(startup_32)
14804 2:
14805 leal -__PAGE_OFFSET(%ecx),%esp
14806
14807 +#ifdef CONFIG_SMP
14808 + movl $pa(cpu_gdt_table),%edi
14809 + movl $__per_cpu_load,%eax
14810 + movw %ax,__KERNEL_PERCPU + 2(%edi)
14811 + rorl $16,%eax
14812 + movb %al,__KERNEL_PERCPU + 4(%edi)
14813 + movb %ah,__KERNEL_PERCPU + 7(%edi)
14814 + movl $__per_cpu_end - 1,%eax
14815 + subl $__per_cpu_start,%eax
14816 + movw %ax,__KERNEL_PERCPU + 0(%edi)
14817 +#endif
14818 +
14819 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14820 + movl $NR_CPUS,%ecx
14821 + movl $pa(cpu_gdt_table),%edi
14822 +1:
14823 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
14824 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
14825 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
14826 + addl $PAGE_SIZE_asm,%edi
14827 + loop 1b
14828 +#endif
14829 +
14830 +#ifdef CONFIG_PAX_KERNEXEC
14831 + movl $pa(boot_gdt),%edi
14832 + movl $__LOAD_PHYSICAL_ADDR,%eax
14833 + movw %ax,__BOOT_CS + 2(%edi)
14834 + rorl $16,%eax
14835 + movb %al,__BOOT_CS + 4(%edi)
14836 + movb %ah,__BOOT_CS + 7(%edi)
14837 + rorl $16,%eax
14838 +
14839 + ljmp $(__BOOT_CS),$1f
14840 +1:
14841 +
14842 + movl $NR_CPUS,%ecx
14843 + movl $pa(cpu_gdt_table),%edi
14844 + addl $__PAGE_OFFSET,%eax
14845 +1:
14846 + movw %ax,__KERNEL_CS + 2(%edi)
14847 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
14848 + rorl $16,%eax
14849 + movb %al,__KERNEL_CS + 4(%edi)
14850 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
14851 + movb %ah,__KERNEL_CS + 7(%edi)
14852 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
14853 + rorl $16,%eax
14854 + addl $PAGE_SIZE_asm,%edi
14855 + loop 1b
14856 +#endif
14857 +
14858 /*
14859 * Clear BSS first so that there are no surprises...
14860 */
14861 @@ -195,8 +261,11 @@ ENTRY(startup_32)
14862 movl %eax, pa(max_pfn_mapped)
14863
14864 /* Do early initialization of the fixmap area */
14865 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14866 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
14867 +#ifdef CONFIG_COMPAT_VDSO
14868 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
14869 +#else
14870 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
14871 +#endif
14872 #else /* Not PAE */
14873
14874 page_pde_offset = (__PAGE_OFFSET >> 20);
14875 @@ -226,8 +295,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14876 movl %eax, pa(max_pfn_mapped)
14877
14878 /* Do early initialization of the fixmap area */
14879 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
14880 - movl %eax,pa(initial_page_table+0xffc)
14881 +#ifdef CONFIG_COMPAT_VDSO
14882 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
14883 +#else
14884 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
14885 +#endif
14886 #endif
14887
14888 #ifdef CONFIG_PARAVIRT
14889 @@ -241,9 +313,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
14890 cmpl $num_subarch_entries, %eax
14891 jae bad_subarch
14892
14893 - movl pa(subarch_entries)(,%eax,4), %eax
14894 - subl $__PAGE_OFFSET, %eax
14895 - jmp *%eax
14896 + jmp *pa(subarch_entries)(,%eax,4)
14897
14898 bad_subarch:
14899 WEAK(lguest_entry)
14900 @@ -255,10 +325,10 @@ WEAK(xen_entry)
14901 __INITDATA
14902
14903 subarch_entries:
14904 - .long default_entry /* normal x86/PC */
14905 - .long lguest_entry /* lguest hypervisor */
14906 - .long xen_entry /* Xen hypervisor */
14907 - .long default_entry /* Moorestown MID */
14908 + .long ta(default_entry) /* normal x86/PC */
14909 + .long ta(lguest_entry) /* lguest hypervisor */
14910 + .long ta(xen_entry) /* Xen hypervisor */
14911 + .long ta(default_entry) /* Moorestown MID */
14912 num_subarch_entries = (. - subarch_entries) / 4
14913 .previous
14914 #else
14915 @@ -312,6 +382,7 @@ default_entry:
14916 orl %edx,%eax
14917 movl %eax,%cr4
14918
14919 +#ifdef CONFIG_X86_PAE
14920 testb $X86_CR4_PAE, %al # check if PAE is enabled
14921 jz 6f
14922
14923 @@ -340,6 +411,9 @@ default_entry:
14924 /* Make changes effective */
14925 wrmsr
14926
14927 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
14928 +#endif
14929 +
14930 6:
14931
14932 /*
14933 @@ -443,7 +517,7 @@ is386: movl $2,%ecx # set MP
14934 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
14935 movl %eax,%ss # after changing gdt.
14936
14937 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
14938 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
14939 movl %eax,%ds
14940 movl %eax,%es
14941
14942 @@ -457,15 +531,22 @@ is386: movl $2,%ecx # set MP
14943 */
14944 cmpb $0,ready
14945 jne 1f
14946 - movl $gdt_page,%eax
14947 + movl $cpu_gdt_table,%eax
14948 movl $stack_canary,%ecx
14949 +#ifdef CONFIG_SMP
14950 + addl $__per_cpu_load,%ecx
14951 +#endif
14952 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
14953 shrl $16, %ecx
14954 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
14955 movb %ch, 8 * GDT_ENTRY_STACK_CANARY + 7(%eax)
14956 1:
14957 -#endif
14958 movl $(__KERNEL_STACK_CANARY),%eax
14959 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14960 + movl $(__USER_DS),%eax
14961 +#else
14962 + xorl %eax,%eax
14963 +#endif
14964 movl %eax,%gs
14965
14966 xorl %eax,%eax # Clear LDT
14967 @@ -558,22 +639,22 @@ early_page_fault:
14968 jmp early_fault
14969
14970 early_fault:
14971 - cld
14972 #ifdef CONFIG_PRINTK
14973 + cmpl $1,%ss:early_recursion_flag
14974 + je hlt_loop
14975 + incl %ss:early_recursion_flag
14976 + cld
14977 pusha
14978 movl $(__KERNEL_DS),%eax
14979 movl %eax,%ds
14980 movl %eax,%es
14981 - cmpl $2,early_recursion_flag
14982 - je hlt_loop
14983 - incl early_recursion_flag
14984 movl %cr2,%eax
14985 pushl %eax
14986 pushl %edx /* trapno */
14987 pushl $fault_msg
14988 call printk
14989 +; call dump_stack
14990 #endif
14991 - call dump_stack
14992 hlt_loop:
14993 hlt
14994 jmp hlt_loop
14995 @@ -581,8 +662,11 @@ hlt_loop:
14996 /* This is the default interrupt "handler" :-) */
14997 ALIGN
14998 ignore_int:
14999 - cld
15000 #ifdef CONFIG_PRINTK
15001 + cmpl $2,%ss:early_recursion_flag
15002 + je hlt_loop
15003 + incl %ss:early_recursion_flag
15004 + cld
15005 pushl %eax
15006 pushl %ecx
15007 pushl %edx
15008 @@ -591,9 +675,6 @@ ignore_int:
15009 movl $(__KERNEL_DS),%eax
15010 movl %eax,%ds
15011 movl %eax,%es
15012 - cmpl $2,early_recursion_flag
15013 - je hlt_loop
15014 - incl early_recursion_flag
15015 pushl 16(%esp)
15016 pushl 24(%esp)
15017 pushl 32(%esp)
15018 @@ -622,29 +703,43 @@ ENTRY(initial_code)
15019 /*
15020 * BSS section
15021 */
15022 -__PAGE_ALIGNED_BSS
15023 - .align PAGE_SIZE
15024 #ifdef CONFIG_X86_PAE
15025 +.section .initial_pg_pmd,"a",@progbits
15026 initial_pg_pmd:
15027 .fill 1024*KPMDS,4,0
15028 #else
15029 +.section .initial_page_table,"a",@progbits
15030 ENTRY(initial_page_table)
15031 .fill 1024,4,0
15032 #endif
15033 +.section .initial_pg_fixmap,"a",@progbits
15034 initial_pg_fixmap:
15035 .fill 1024,4,0
15036 +.section .empty_zero_page,"a",@progbits
15037 ENTRY(empty_zero_page)
15038 .fill 4096,1,0
15039 +.section .swapper_pg_dir,"a",@progbits
15040 ENTRY(swapper_pg_dir)
15041 +#ifdef CONFIG_X86_PAE
15042 + .fill 4,8,0
15043 +#else
15044 .fill 1024,4,0
15045 +#endif
15046 +
15047 +/*
15048 + * The IDT has to be page-aligned to simplify the Pentium
15049 + * F0 0F bug workaround.. We have a special link segment
15050 + * for this.
15051 + */
15052 +.section .idt,"a",@progbits
15053 +ENTRY(idt_table)
15054 + .fill 256,8,0
15055
15056 /*
15057 * This starts the data section.
15058 */
15059 #ifdef CONFIG_X86_PAE
15060 -__PAGE_ALIGNED_DATA
15061 - /* Page-aligned for the benefit of paravirt? */
15062 - .align PAGE_SIZE
15063 +.section .initial_page_table,"a",@progbits
15064 ENTRY(initial_page_table)
15065 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
15066 # if KPMDS == 3
15067 @@ -663,18 +758,27 @@ ENTRY(initial_page_table)
15068 # error "Kernel PMDs should be 1, 2 or 3"
15069 # endif
15070 .align PAGE_SIZE /* needs to be page-sized too */
15071 +
15072 +#ifdef CONFIG_PAX_PER_CPU_PGD
15073 +ENTRY(cpu_pgd)
15074 + .rept NR_CPUS
15075 + .fill 4,8,0
15076 + .endr
15077 +#endif
15078 +
15079 #endif
15080
15081 .data
15082 .balign 4
15083 ENTRY(stack_start)
15084 - .long init_thread_union+THREAD_SIZE
15085 + .long init_thread_union+THREAD_SIZE-8
15086
15087 +ready: .byte 0
15088 +
15089 +.section .rodata,"a",@progbits
15090 early_recursion_flag:
15091 .long 0
15092
15093 -ready: .byte 0
15094 -
15095 int_msg:
15096 .asciz "Unknown interrupt or fault at: %p %p %p\n"
15097
15098 @@ -707,7 +811,7 @@ fault_msg:
15099 .word 0 # 32 bit align gdt_desc.address
15100 boot_gdt_descr:
15101 .word __BOOT_DS+7
15102 - .long boot_gdt - __PAGE_OFFSET
15103 + .long pa(boot_gdt)
15104
15105 .word 0 # 32-bit align idt_desc.address
15106 idt_descr:
15107 @@ -718,7 +822,7 @@ idt_descr:
15108 .word 0 # 32 bit align gdt_desc.address
15109 ENTRY(early_gdt_descr)
15110 .word GDT_ENTRIES*8-1
15111 - .long gdt_page /* Overwritten for secondary CPUs */
15112 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
15113
15114 /*
15115 * The boot_gdt must mirror the equivalent in setup.S and is
15116 @@ -727,5 +831,65 @@ ENTRY(early_gdt_descr)
15117 .align L1_CACHE_BYTES
15118 ENTRY(boot_gdt)
15119 .fill GDT_ENTRY_BOOT_CS,8,0
15120 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
15121 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
15122 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
15123 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
15124 +
15125 + .align PAGE_SIZE_asm
15126 +ENTRY(cpu_gdt_table)
15127 + .rept NR_CPUS
15128 + .quad 0x0000000000000000 /* NULL descriptor */
15129 + .quad 0x0000000000000000 /* 0x0b reserved */
15130 + .quad 0x0000000000000000 /* 0x13 reserved */
15131 + .quad 0x0000000000000000 /* 0x1b reserved */
15132 +
15133 +#ifdef CONFIG_PAX_KERNEXEC
15134 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
15135 +#else
15136 + .quad 0x0000000000000000 /* 0x20 unused */
15137 +#endif
15138 +
15139 + .quad 0x0000000000000000 /* 0x28 unused */
15140 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
15141 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
15142 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
15143 + .quad 0x0000000000000000 /* 0x4b reserved */
15144 + .quad 0x0000000000000000 /* 0x53 reserved */
15145 + .quad 0x0000000000000000 /* 0x5b reserved */
15146 +
15147 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
15148 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
15149 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
15150 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
15151 +
15152 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
15153 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
15154 +
15155 + /*
15156 + * Segments used for calling PnP BIOS have byte granularity.
15157 + * The code segments and data segments have fixed 64k limits,
15158 + * the transfer segment sizes are set at run time.
15159 + */
15160 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
15161 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
15162 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
15163 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
15164 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
15165 +
15166 + /*
15167 + * The APM segments have byte granularity and their bases
15168 + * are set at run time. All have 64k limits.
15169 + */
15170 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
15171 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
15172 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
15173 +
15174 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
15175 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
15176 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
15177 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
15178 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
15179 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
15180 +
15181 + /* Be sure this is zeroed to avoid false validations in Xen */
15182 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
15183 + .endr
15184 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
15185 index e11e394..9aebc5d 100644
15186 --- a/arch/x86/kernel/head_64.S
15187 +++ b/arch/x86/kernel/head_64.S
15188 @@ -19,6 +19,8 @@
15189 #include <asm/cache.h>
15190 #include <asm/processor-flags.h>
15191 #include <asm/percpu.h>
15192 +#include <asm/cpufeature.h>
15193 +#include <asm/alternative-asm.h>
15194
15195 #ifdef CONFIG_PARAVIRT
15196 #include <asm/asm-offsets.h>
15197 @@ -38,6 +40,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
15198 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
15199 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
15200 L3_START_KERNEL = pud_index(__START_KERNEL_map)
15201 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
15202 +L3_VMALLOC_START = pud_index(VMALLOC_START)
15203 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
15204 +L3_VMALLOC_END = pud_index(VMALLOC_END)
15205 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
15206 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
15207
15208 .text
15209 __HEAD
15210 @@ -85,35 +93,23 @@ startup_64:
15211 */
15212 addq %rbp, init_level4_pgt + 0(%rip)
15213 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
15214 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
15215 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
15216 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
15217 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
15218
15219 addq %rbp, level3_ident_pgt + 0(%rip)
15220 +#ifndef CONFIG_XEN
15221 + addq %rbp, level3_ident_pgt + 8(%rip)
15222 +#endif
15223
15224 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
15225 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
15226 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
15227 +
15228 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
15229 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
15230
15231 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
15232 -
15233 - /* Add an Identity mapping if I am above 1G */
15234 - leaq _text(%rip), %rdi
15235 - andq $PMD_PAGE_MASK, %rdi
15236 -
15237 - movq %rdi, %rax
15238 - shrq $PUD_SHIFT, %rax
15239 - andq $(PTRS_PER_PUD - 1), %rax
15240 - jz ident_complete
15241 -
15242 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
15243 - leaq level3_ident_pgt(%rip), %rbx
15244 - movq %rdx, 0(%rbx, %rax, 8)
15245 -
15246 - movq %rdi, %rax
15247 - shrq $PMD_SHIFT, %rax
15248 - andq $(PTRS_PER_PMD - 1), %rax
15249 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
15250 - leaq level2_spare_pgt(%rip), %rbx
15251 - movq %rdx, 0(%rbx, %rax, 8)
15252 -ident_complete:
15253 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
15254
15255 /*
15256 * Fixup the kernel text+data virtual addresses. Note that
15257 @@ -160,8 +156,8 @@ ENTRY(secondary_startup_64)
15258 * after the boot processor executes this code.
15259 */
15260
15261 - /* Enable PAE mode and PGE */
15262 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
15263 + /* Enable PAE mode and PSE/PGE */
15264 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
15265 movq %rax, %cr4
15266
15267 /* Setup early boot stage 4 level pagetables. */
15268 @@ -183,9 +179,17 @@ ENTRY(secondary_startup_64)
15269 movl $MSR_EFER, %ecx
15270 rdmsr
15271 btsl $_EFER_SCE, %eax /* Enable System Call */
15272 - btl $20,%edi /* No Execute supported? */
15273 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
15274 jnc 1f
15275 btsl $_EFER_NX, %eax
15276 + leaq init_level4_pgt(%rip), %rdi
15277 +#ifndef CONFIG_EFI
15278 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
15279 +#endif
15280 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
15281 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
15282 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
15283 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
15284 1: wrmsr /* Make changes effective */
15285
15286 /* Setup cr0 */
15287 @@ -247,6 +251,7 @@ ENTRY(secondary_startup_64)
15288 * jump. In addition we need to ensure %cs is set so we make this
15289 * a far return.
15290 */
15291 + pax_set_fptr_mask
15292 movq initial_code(%rip),%rax
15293 pushq $0 # fake return address to stop unwinder
15294 pushq $__KERNEL_CS # set correct cs
15295 @@ -269,7 +274,7 @@ ENTRY(secondary_startup_64)
15296 bad_address:
15297 jmp bad_address
15298
15299 - .section ".init.text","ax"
15300 + __INIT
15301 #ifdef CONFIG_EARLY_PRINTK
15302 .globl early_idt_handlers
15303 early_idt_handlers:
15304 @@ -314,18 +319,23 @@ ENTRY(early_idt_handler)
15305 #endif /* EARLY_PRINTK */
15306 1: hlt
15307 jmp 1b
15308 + .previous
15309
15310 #ifdef CONFIG_EARLY_PRINTK
15311 + __INITDATA
15312 early_recursion_flag:
15313 .long 0
15314 + .previous
15315
15316 + .section .rodata,"a",@progbits
15317 early_idt_msg:
15318 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
15319 early_idt_ripmsg:
15320 .asciz "RIP %s\n"
15321 + .previous
15322 #endif /* CONFIG_EARLY_PRINTK */
15323 - .previous
15324
15325 + .section .rodata,"a",@progbits
15326 #define NEXT_PAGE(name) \
15327 .balign PAGE_SIZE; \
15328 ENTRY(name)
15329 @@ -338,7 +348,6 @@ ENTRY(name)
15330 i = i + 1 ; \
15331 .endr
15332
15333 - .data
15334 /*
15335 * This default setting generates an ident mapping at address 0x100000
15336 * and a mapping for the kernel that precisely maps virtual address
15337 @@ -349,13 +358,41 @@ NEXT_PAGE(init_level4_pgt)
15338 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15339 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
15340 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15341 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
15342 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
15343 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
15344 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
15345 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
15346 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15347 .org init_level4_pgt + L4_START_KERNEL*8, 0
15348 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
15349 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
15350
15351 +#ifdef CONFIG_PAX_PER_CPU_PGD
15352 +NEXT_PAGE(cpu_pgd)
15353 + .rept NR_CPUS
15354 + .fill 512,8,0
15355 + .endr
15356 +#endif
15357 +
15358 NEXT_PAGE(level3_ident_pgt)
15359 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
15360 +#ifdef CONFIG_XEN
15361 .fill 511,8,0
15362 +#else
15363 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
15364 + .fill 510,8,0
15365 +#endif
15366 +
15367 +NEXT_PAGE(level3_vmalloc_start_pgt)
15368 + .fill 512,8,0
15369 +
15370 +NEXT_PAGE(level3_vmalloc_end_pgt)
15371 + .fill 512,8,0
15372 +
15373 +NEXT_PAGE(level3_vmemmap_pgt)
15374 + .fill L3_VMEMMAP_START,8,0
15375 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
15376
15377 NEXT_PAGE(level3_kernel_pgt)
15378 .fill L3_START_KERNEL,8,0
15379 @@ -363,20 +400,23 @@ NEXT_PAGE(level3_kernel_pgt)
15380 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
15381 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15382
15383 +NEXT_PAGE(level2_vmemmap_pgt)
15384 + .fill 512,8,0
15385 +
15386 NEXT_PAGE(level2_fixmap_pgt)
15387 - .fill 506,8,0
15388 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
15389 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
15390 - .fill 5,8,0
15391 + .fill 507,8,0
15392 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
15393 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
15394 + .fill 4,8,0
15395
15396 -NEXT_PAGE(level1_fixmap_pgt)
15397 +NEXT_PAGE(level1_vsyscall_pgt)
15398 .fill 512,8,0
15399
15400 -NEXT_PAGE(level2_ident_pgt)
15401 - /* Since I easily can, map the first 1G.
15402 + /* Since I easily can, map the first 2G.
15403 * Don't set NX because code runs from these pages.
15404 */
15405 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
15406 +NEXT_PAGE(level2_ident_pgt)
15407 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
15408
15409 NEXT_PAGE(level2_kernel_pgt)
15410 /*
15411 @@ -389,33 +429,55 @@ NEXT_PAGE(level2_kernel_pgt)
15412 * If you want to increase this then increase MODULES_VADDR
15413 * too.)
15414 */
15415 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
15416 - KERNEL_IMAGE_SIZE/PMD_SIZE)
15417 -
15418 -NEXT_PAGE(level2_spare_pgt)
15419 - .fill 512, 8, 0
15420 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
15421
15422 #undef PMDS
15423 #undef NEXT_PAGE
15424
15425 - .data
15426 + .align PAGE_SIZE
15427 +ENTRY(cpu_gdt_table)
15428 + .rept NR_CPUS
15429 + .quad 0x0000000000000000 /* NULL descriptor */
15430 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
15431 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
15432 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
15433 + .quad 0x00cffb000000ffff /* __USER32_CS */
15434 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
15435 + .quad 0x00affb000000ffff /* __USER_CS */
15436 +
15437 +#ifdef CONFIG_PAX_KERNEXEC
15438 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
15439 +#else
15440 + .quad 0x0 /* unused */
15441 +#endif
15442 +
15443 + .quad 0,0 /* TSS */
15444 + .quad 0,0 /* LDT */
15445 + .quad 0,0,0 /* three TLS descriptors */
15446 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
15447 + /* asm/segment.h:GDT_ENTRIES must match this */
15448 +
15449 + /* zero the remaining page */
15450 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
15451 + .endr
15452 +
15453 .align 16
15454 .globl early_gdt_descr
15455 early_gdt_descr:
15456 .word GDT_ENTRIES*8-1
15457 early_gdt_descr_base:
15458 - .quad INIT_PER_CPU_VAR(gdt_page)
15459 + .quad cpu_gdt_table
15460
15461 ENTRY(phys_base)
15462 /* This must match the first entry in level2_kernel_pgt */
15463 .quad 0x0000000000000000
15464
15465 #include "../../x86/xen/xen-head.S"
15466 -
15467 - .section .bss, "aw", @nobits
15468 +
15469 + .section .rodata,"a",@progbits
15470 .align L1_CACHE_BYTES
15471 ENTRY(idt_table)
15472 - .skip IDT_ENTRIES * 16
15473 + .fill 512,8,0
15474
15475 __PAGE_ALIGNED_BSS
15476 .align PAGE_SIZE
15477 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
15478 index 9c3bd4a..e1d9b35 100644
15479 --- a/arch/x86/kernel/i386_ksyms_32.c
15480 +++ b/arch/x86/kernel/i386_ksyms_32.c
15481 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
15482 EXPORT_SYMBOL(cmpxchg8b_emu);
15483 #endif
15484
15485 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
15486 +
15487 /* Networking helper routines. */
15488 EXPORT_SYMBOL(csum_partial_copy_generic);
15489 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
15490 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
15491
15492 EXPORT_SYMBOL(__get_user_1);
15493 EXPORT_SYMBOL(__get_user_2);
15494 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
15495
15496 EXPORT_SYMBOL(csum_partial);
15497 EXPORT_SYMBOL(empty_zero_page);
15498 +
15499 +#ifdef CONFIG_PAX_KERNEXEC
15500 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
15501 +#endif
15502 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
15503 index 6104852..6114160 100644
15504 --- a/arch/x86/kernel/i8259.c
15505 +++ b/arch/x86/kernel/i8259.c
15506 @@ -210,7 +210,7 @@ spurious_8259A_irq:
15507 "spurious 8259A interrupt: IRQ%d.\n", irq);
15508 spurious_irq_mask |= irqmask;
15509 }
15510 - atomic_inc(&irq_err_count);
15511 + atomic_inc_unchecked(&irq_err_count);
15512 /*
15513 * Theoretically we do not have to handle this IRQ,
15514 * but in Linux this does not cause problems and is
15515 diff --git a/arch/x86/kernel/init_task.c b/arch/x86/kernel/init_task.c
15516 index 43e9ccf..44ccf6f 100644
15517 --- a/arch/x86/kernel/init_task.c
15518 +++ b/arch/x86/kernel/init_task.c
15519 @@ -20,8 +20,7 @@ static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
15520 * way process stacks are handled. This is done by having a special
15521 * "init_task" linker map entry..
15522 */
15523 -union thread_union init_thread_union __init_task_data =
15524 - { INIT_THREAD_INFO(init_task) };
15525 +union thread_union init_thread_union __init_task_data;
15526
15527 /*
15528 * Initial task structure.
15529 @@ -38,5 +37,5 @@ EXPORT_SYMBOL(init_task);
15530 * section. Since TSS's are completely CPU-local, we want them
15531 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
15532 */
15533 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
15534 -
15535 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
15536 +EXPORT_SYMBOL(init_tss);
15537 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
15538 index 8c96897..be66bfa 100644
15539 --- a/arch/x86/kernel/ioport.c
15540 +++ b/arch/x86/kernel/ioport.c
15541 @@ -6,6 +6,7 @@
15542 #include <linux/sched.h>
15543 #include <linux/kernel.h>
15544 #include <linux/capability.h>
15545 +#include <linux/security.h>
15546 #include <linux/errno.h>
15547 #include <linux/types.h>
15548 #include <linux/ioport.h>
15549 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15550
15551 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
15552 return -EINVAL;
15553 +#ifdef CONFIG_GRKERNSEC_IO
15554 + if (turn_on && grsec_disable_privio) {
15555 + gr_handle_ioperm();
15556 + return -EPERM;
15557 + }
15558 +#endif
15559 if (turn_on && !capable(CAP_SYS_RAWIO))
15560 return -EPERM;
15561
15562 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
15563 * because the ->io_bitmap_max value must match the bitmap
15564 * contents:
15565 */
15566 - tss = &per_cpu(init_tss, get_cpu());
15567 + tss = init_tss + get_cpu();
15568
15569 if (turn_on)
15570 bitmap_clear(t->io_bitmap_ptr, from, num);
15571 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
15572 return -EINVAL;
15573 /* Trying to gain more privileges? */
15574 if (level > old) {
15575 +#ifdef CONFIG_GRKERNSEC_IO
15576 + if (grsec_disable_privio) {
15577 + gr_handle_iopl();
15578 + return -EPERM;
15579 + }
15580 +#endif
15581 if (!capable(CAP_SYS_RAWIO))
15582 return -EPERM;
15583 }
15584 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
15585 index 429e0c9..17b3ece 100644
15586 --- a/arch/x86/kernel/irq.c
15587 +++ b/arch/x86/kernel/irq.c
15588 @@ -18,7 +18,7 @@
15589 #include <asm/mce.h>
15590 #include <asm/hw_irq.h>
15591
15592 -atomic_t irq_err_count;
15593 +atomic_unchecked_t irq_err_count;
15594
15595 /* Function pointer for generic interrupt vector handling */
15596 void (*x86_platform_ipi_callback)(void) = NULL;
15597 @@ -117,9 +117,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
15598 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
15599 seq_printf(p, " Machine check polls\n");
15600 #endif
15601 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
15602 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
15603 #if defined(CONFIG_X86_IO_APIC)
15604 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
15605 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
15606 #endif
15607 return 0;
15608 }
15609 @@ -159,10 +159,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
15610
15611 u64 arch_irq_stat(void)
15612 {
15613 - u64 sum = atomic_read(&irq_err_count);
15614 + u64 sum = atomic_read_unchecked(&irq_err_count);
15615
15616 #ifdef CONFIG_X86_IO_APIC
15617 - sum += atomic_read(&irq_mis_count);
15618 + sum += atomic_read_unchecked(&irq_mis_count);
15619 #endif
15620 return sum;
15621 }
15622 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
15623 index 7209070..cbcd71a 100644
15624 --- a/arch/x86/kernel/irq_32.c
15625 +++ b/arch/x86/kernel/irq_32.c
15626 @@ -36,7 +36,7 @@ static int check_stack_overflow(void)
15627 __asm__ __volatile__("andl %%esp,%0" :
15628 "=r" (sp) : "0" (THREAD_SIZE - 1));
15629
15630 - return sp < (sizeof(struct thread_info) + STACK_WARN);
15631 + return sp < STACK_WARN;
15632 }
15633
15634 static void print_stack_overflow(void)
15635 @@ -54,8 +54,8 @@ static inline void print_stack_overflow(void) { }
15636 * per-CPU IRQ handling contexts (thread information and stack)
15637 */
15638 union irq_ctx {
15639 - struct thread_info tinfo;
15640 - u32 stack[THREAD_SIZE/sizeof(u32)];
15641 + unsigned long previous_esp;
15642 + u32 stack[THREAD_SIZE/sizeof(u32)];
15643 } __attribute__((aligned(THREAD_SIZE)));
15644
15645 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
15646 @@ -75,10 +75,9 @@ static void call_on_stack(void *func, void *stack)
15647 static inline int
15648 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15649 {
15650 - union irq_ctx *curctx, *irqctx;
15651 + union irq_ctx *irqctx;
15652 u32 *isp, arg1, arg2;
15653
15654 - curctx = (union irq_ctx *) current_thread_info();
15655 irqctx = __this_cpu_read(hardirq_ctx);
15656
15657 /*
15658 @@ -87,21 +86,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15659 * handler) we can't do that and just have to keep using the
15660 * current stack (which is the irq stack already after all)
15661 */
15662 - if (unlikely(curctx == irqctx))
15663 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
15664 return 0;
15665
15666 /* build the stack frame on the IRQ stack */
15667 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15668 - irqctx->tinfo.task = curctx->tinfo.task;
15669 - irqctx->tinfo.previous_esp = current_stack_pointer;
15670 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15671 + irqctx->previous_esp = current_stack_pointer;
15672
15673 - /*
15674 - * Copy the softirq bits in preempt_count so that the
15675 - * softirq checks work in the hardirq context.
15676 - */
15677 - irqctx->tinfo.preempt_count =
15678 - (irqctx->tinfo.preempt_count & ~SOFTIRQ_MASK) |
15679 - (curctx->tinfo.preempt_count & SOFTIRQ_MASK);
15680 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15681 + __set_fs(MAKE_MM_SEG(0));
15682 +#endif
15683
15684 if (unlikely(overflow))
15685 call_on_stack(print_stack_overflow, isp);
15686 @@ -113,6 +107,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15687 : "0" (irq), "1" (desc), "2" (isp),
15688 "D" (desc->handle_irq)
15689 : "memory", "cc", "ecx");
15690 +
15691 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15692 + __set_fs(current_thread_info()->addr_limit);
15693 +#endif
15694 +
15695 return 1;
15696 }
15697
15698 @@ -121,29 +120,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
15699 */
15700 void __cpuinit irq_ctx_init(int cpu)
15701 {
15702 - union irq_ctx *irqctx;
15703 -
15704 if (per_cpu(hardirq_ctx, cpu))
15705 return;
15706
15707 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15708 - THREAD_FLAGS,
15709 - THREAD_ORDER));
15710 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15711 - irqctx->tinfo.cpu = cpu;
15712 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
15713 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15714 -
15715 - per_cpu(hardirq_ctx, cpu) = irqctx;
15716 -
15717 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
15718 - THREAD_FLAGS,
15719 - THREAD_ORDER));
15720 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
15721 - irqctx->tinfo.cpu = cpu;
15722 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
15723 -
15724 - per_cpu(softirq_ctx, cpu) = irqctx;
15725 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15726 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREAD_FLAGS, THREAD_ORDER));
15727
15728 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
15729 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
15730 @@ -152,7 +133,6 @@ void __cpuinit irq_ctx_init(int cpu)
15731 asmlinkage void do_softirq(void)
15732 {
15733 unsigned long flags;
15734 - struct thread_info *curctx;
15735 union irq_ctx *irqctx;
15736 u32 *isp;
15737
15738 @@ -162,15 +142,22 @@ asmlinkage void do_softirq(void)
15739 local_irq_save(flags);
15740
15741 if (local_softirq_pending()) {
15742 - curctx = current_thread_info();
15743 irqctx = __this_cpu_read(softirq_ctx);
15744 - irqctx->tinfo.task = curctx->task;
15745 - irqctx->tinfo.previous_esp = current_stack_pointer;
15746 + irqctx->previous_esp = current_stack_pointer;
15747
15748 /* build the stack frame on the softirq stack */
15749 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
15750 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
15751 +
15752 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15753 + __set_fs(MAKE_MM_SEG(0));
15754 +#endif
15755
15756 call_on_stack(__do_softirq, isp);
15757 +
15758 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15759 + __set_fs(current_thread_info()->addr_limit);
15760 +#endif
15761 +
15762 /*
15763 * Shouldn't happen, we returned above if in_interrupt():
15764 */
15765 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
15766 index 69bca46..0bac999 100644
15767 --- a/arch/x86/kernel/irq_64.c
15768 +++ b/arch/x86/kernel/irq_64.c
15769 @@ -38,7 +38,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
15770 #ifdef CONFIG_DEBUG_STACKOVERFLOW
15771 u64 curbase = (u64)task_stack_page(current);
15772
15773 - if (user_mode_vm(regs))
15774 + if (user_mode(regs))
15775 return;
15776
15777 WARN_ONCE(regs->sp >= curbase &&
15778 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
15779 index faba577..93b9e71 100644
15780 --- a/arch/x86/kernel/kgdb.c
15781 +++ b/arch/x86/kernel/kgdb.c
15782 @@ -124,11 +124,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
15783 #ifdef CONFIG_X86_32
15784 switch (regno) {
15785 case GDB_SS:
15786 - if (!user_mode_vm(regs))
15787 + if (!user_mode(regs))
15788 *(unsigned long *)mem = __KERNEL_DS;
15789 break;
15790 case GDB_SP:
15791 - if (!user_mode_vm(regs))
15792 + if (!user_mode(regs))
15793 *(unsigned long *)mem = kernel_stack_pointer(regs);
15794 break;
15795 case GDB_GS:
15796 @@ -473,12 +473,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
15797 case 'k':
15798 /* clear the trace bit */
15799 linux_regs->flags &= ~X86_EFLAGS_TF;
15800 - atomic_set(&kgdb_cpu_doing_single_step, -1);
15801 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
15802
15803 /* set the trace bit if we're stepping */
15804 if (remcomInBuffer[0] == 's') {
15805 linux_regs->flags |= X86_EFLAGS_TF;
15806 - atomic_set(&kgdb_cpu_doing_single_step,
15807 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
15808 raw_smp_processor_id());
15809 }
15810
15811 @@ -543,7 +543,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
15812
15813 switch (cmd) {
15814 case DIE_DEBUG:
15815 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
15816 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
15817 if (user_mode(regs))
15818 return single_step_cont(regs, args);
15819 break;
15820 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
15821 index 7da647d..5d3c4c1 100644
15822 --- a/arch/x86/kernel/kprobes.c
15823 +++ b/arch/x86/kernel/kprobes.c
15824 @@ -118,8 +118,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
15825 } __attribute__((packed)) *insn;
15826
15827 insn = (struct __arch_relative_insn *)from;
15828 +
15829 + pax_open_kernel();
15830 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
15831 insn->op = op;
15832 + pax_close_kernel();
15833 }
15834
15835 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
15836 @@ -156,7 +159,7 @@ static int __kprobes can_boost(kprobe_opcode_t *opcodes)
15837 kprobe_opcode_t opcode;
15838 kprobe_opcode_t *orig_opcodes = opcodes;
15839
15840 - if (search_exception_tables((unsigned long)opcodes))
15841 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
15842 return 0; /* Page fault may occur on this address. */
15843
15844 retry:
15845 @@ -317,7 +320,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15846 }
15847 }
15848 insn_get_length(&insn);
15849 + pax_open_kernel();
15850 memcpy(dest, insn.kaddr, insn.length);
15851 + pax_close_kernel();
15852
15853 #ifdef CONFIG_X86_64
15854 if (insn_rip_relative(&insn)) {
15855 @@ -341,7 +346,9 @@ static int __kprobes __copy_instruction(u8 *dest, u8 *src, int recover)
15856 (u8 *) dest;
15857 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
15858 disp = (u8 *) dest + insn_offset_displacement(&insn);
15859 + pax_open_kernel();
15860 *(s32 *) disp = (s32) newdisp;
15861 + pax_close_kernel();
15862 }
15863 #endif
15864 return insn.length;
15865 @@ -355,12 +362,12 @@ static void __kprobes arch_copy_kprobe(struct kprobe *p)
15866 */
15867 __copy_instruction(p->ainsn.insn, p->addr, 0);
15868
15869 - if (can_boost(p->addr))
15870 + if (can_boost(ktla_ktva(p->addr)))
15871 p->ainsn.boostable = 0;
15872 else
15873 p->ainsn.boostable = -1;
15874
15875 - p->opcode = *p->addr;
15876 + p->opcode = *(ktla_ktva(p->addr));
15877 }
15878
15879 int __kprobes arch_prepare_kprobe(struct kprobe *p)
15880 @@ -477,7 +484,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15881 * nor set current_kprobe, because it doesn't use single
15882 * stepping.
15883 */
15884 - regs->ip = (unsigned long)p->ainsn.insn;
15885 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15886 preempt_enable_no_resched();
15887 return;
15888 }
15889 @@ -496,7 +503,7 @@ static void __kprobes setup_singlestep(struct kprobe *p, struct pt_regs *regs,
15890 if (p->opcode == BREAKPOINT_INSTRUCTION)
15891 regs->ip = (unsigned long)p->addr;
15892 else
15893 - regs->ip = (unsigned long)p->ainsn.insn;
15894 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
15895 }
15896
15897 /*
15898 @@ -575,7 +582,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
15899 setup_singlestep(p, regs, kcb, 0);
15900 return 1;
15901 }
15902 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
15903 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
15904 /*
15905 * The breakpoint instruction was removed right
15906 * after we hit it. Another cpu has removed
15907 @@ -683,6 +690,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
15908 " movq %rax, 152(%rsp)\n"
15909 RESTORE_REGS_STRING
15910 " popfq\n"
15911 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN
15912 + " btsq $63,(%rsp)\n"
15913 +#endif
15914 #else
15915 " pushf\n"
15916 SAVE_REGS_STRING
15917 @@ -820,7 +830,7 @@ static void __kprobes resume_execution(struct kprobe *p,
15918 struct pt_regs *regs, struct kprobe_ctlblk *kcb)
15919 {
15920 unsigned long *tos = stack_addr(regs);
15921 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
15922 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
15923 unsigned long orig_ip = (unsigned long)p->addr;
15924 kprobe_opcode_t *insn = p->ainsn.insn;
15925
15926 @@ -1002,7 +1012,7 @@ int __kprobes kprobe_exceptions_notify(struct notifier_block *self,
15927 struct die_args *args = data;
15928 int ret = NOTIFY_DONE;
15929
15930 - if (args->regs && user_mode_vm(args->regs))
15931 + if (args->regs && user_mode(args->regs))
15932 return ret;
15933
15934 switch (val) {
15935 @@ -1384,7 +1394,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
15936 * Verify if the address gap is in 2GB range, because this uses
15937 * a relative jump.
15938 */
15939 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
15940 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
15941 if (abs(rel) > 0x7fffffff)
15942 return -ERANGE;
15943
15944 @@ -1405,11 +1415,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
15945 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
15946
15947 /* Set probe function call */
15948 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
15949 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
15950
15951 /* Set returning jmp instruction at the tail of out-of-line buffer */
15952 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
15953 - (u8 *)op->kp.addr + op->optinsn.size);
15954 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
15955
15956 flush_icache_range((unsigned long) buf,
15957 (unsigned long) buf + TMPL_END_IDX +
15958 @@ -1431,7 +1441,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
15959 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
15960
15961 /* Backup instructions which will be replaced by jump address */
15962 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
15963 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
15964 RELATIVE_ADDR_SIZE);
15965
15966 insn_buf[0] = RELATIVEJUMP_OPCODE;
15967 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
15968 index a9c2116..a52d4fc 100644
15969 --- a/arch/x86/kernel/kvm.c
15970 +++ b/arch/x86/kernel/kvm.c
15971 @@ -437,6 +437,7 @@ static void __init paravirt_ops_setup(void)
15972 pv_mmu_ops.set_pud = kvm_set_pud;
15973 #if PAGETABLE_LEVELS == 4
15974 pv_mmu_ops.set_pgd = kvm_set_pgd;
15975 + pv_mmu_ops.set_pgd_batched = kvm_set_pgd;
15976 #endif
15977 #endif
15978 pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
15979 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
15980 index ea69726..604d066 100644
15981 --- a/arch/x86/kernel/ldt.c
15982 +++ b/arch/x86/kernel/ldt.c
15983 @@ -67,13 +67,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
15984 if (reload) {
15985 #ifdef CONFIG_SMP
15986 preempt_disable();
15987 - load_LDT(pc);
15988 + load_LDT_nolock(pc);
15989 if (!cpumask_equal(mm_cpumask(current->mm),
15990 cpumask_of(smp_processor_id())))
15991 smp_call_function(flush_ldt, current->mm, 1);
15992 preempt_enable();
15993 #else
15994 - load_LDT(pc);
15995 + load_LDT_nolock(pc);
15996 #endif
15997 }
15998 if (oldsize) {
15999 @@ -95,7 +95,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
16000 return err;
16001
16002 for (i = 0; i < old->size; i++)
16003 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
16004 + write_ldt_entry(new->ldt, i, old->ldt + i);
16005 return 0;
16006 }
16007
16008 @@ -116,6 +116,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
16009 retval = copy_ldt(&mm->context, &old_mm->context);
16010 mutex_unlock(&old_mm->context.lock);
16011 }
16012 +
16013 + if (tsk == current) {
16014 + mm->context.vdso = 0;
16015 +
16016 +#ifdef CONFIG_X86_32
16017 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16018 + mm->context.user_cs_base = 0UL;
16019 + mm->context.user_cs_limit = ~0UL;
16020 +
16021 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16022 + cpus_clear(mm->context.cpu_user_cs_mask);
16023 +#endif
16024 +
16025 +#endif
16026 +#endif
16027 +
16028 + }
16029 +
16030 return retval;
16031 }
16032
16033 @@ -230,6 +248,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
16034 }
16035 }
16036
16037 +#ifdef CONFIG_PAX_SEGMEXEC
16038 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
16039 + error = -EINVAL;
16040 + goto out_unlock;
16041 + }
16042 +#endif
16043 +
16044 fill_ldt(&ldt, &ldt_info);
16045 if (oldmode)
16046 ldt.avl = 0;
16047 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
16048 index a3fa43b..8966f4c 100644
16049 --- a/arch/x86/kernel/machine_kexec_32.c
16050 +++ b/arch/x86/kernel/machine_kexec_32.c
16051 @@ -27,7 +27,7 @@
16052 #include <asm/cacheflush.h>
16053 #include <asm/debugreg.h>
16054
16055 -static void set_idt(void *newidt, __u16 limit)
16056 +static void set_idt(struct desc_struct *newidt, __u16 limit)
16057 {
16058 struct desc_ptr curidt;
16059
16060 @@ -39,7 +39,7 @@ static void set_idt(void *newidt, __u16 limit)
16061 }
16062
16063
16064 -static void set_gdt(void *newgdt, __u16 limit)
16065 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
16066 {
16067 struct desc_ptr curgdt;
16068
16069 @@ -217,7 +217,7 @@ void machine_kexec(struct kimage *image)
16070 }
16071
16072 control_page = page_address(image->control_code_page);
16073 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
16074 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
16075
16076 relocate_kernel_ptr = control_page;
16077 page_list[PA_CONTROL_PAGE] = __pa(control_page);
16078 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
16079 index 3ca42d0..7cff8cc 100644
16080 --- a/arch/x86/kernel/microcode_intel.c
16081 +++ b/arch/x86/kernel/microcode_intel.c
16082 @@ -436,13 +436,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
16083
16084 static int get_ucode_user(void *to, const void *from, size_t n)
16085 {
16086 - return copy_from_user(to, from, n);
16087 + return copy_from_user(to, (const void __force_user *)from, n);
16088 }
16089
16090 static enum ucode_state
16091 request_microcode_user(int cpu, const void __user *buf, size_t size)
16092 {
16093 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
16094 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
16095 }
16096
16097 static void microcode_fini_cpu(int cpu)
16098 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
16099 index 925179f..267ac7a 100644
16100 --- a/arch/x86/kernel/module.c
16101 +++ b/arch/x86/kernel/module.c
16102 @@ -36,15 +36,60 @@
16103 #define DEBUGP(fmt...)
16104 #endif
16105
16106 -void *module_alloc(unsigned long size)
16107 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
16108 {
16109 - if (PAGE_ALIGN(size) > MODULES_LEN)
16110 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
16111 return NULL;
16112 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
16113 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
16114 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
16115 -1, __builtin_return_address(0));
16116 }
16117
16118 +void *module_alloc(unsigned long size)
16119 +{
16120 +
16121 +#ifdef CONFIG_PAX_KERNEXEC
16122 + return __module_alloc(size, PAGE_KERNEL);
16123 +#else
16124 + return __module_alloc(size, PAGE_KERNEL_EXEC);
16125 +#endif
16126 +
16127 +}
16128 +
16129 +#ifdef CONFIG_PAX_KERNEXEC
16130 +#ifdef CONFIG_X86_32
16131 +void *module_alloc_exec(unsigned long size)
16132 +{
16133 + struct vm_struct *area;
16134 +
16135 + if (size == 0)
16136 + return NULL;
16137 +
16138 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
16139 + return area ? area->addr : NULL;
16140 +}
16141 +EXPORT_SYMBOL(module_alloc_exec);
16142 +
16143 +void module_free_exec(struct module *mod, void *module_region)
16144 +{
16145 + vunmap(module_region);
16146 +}
16147 +EXPORT_SYMBOL(module_free_exec);
16148 +#else
16149 +void module_free_exec(struct module *mod, void *module_region)
16150 +{
16151 + module_free(mod, module_region);
16152 +}
16153 +EXPORT_SYMBOL(module_free_exec);
16154 +
16155 +void *module_alloc_exec(unsigned long size)
16156 +{
16157 + return __module_alloc(size, PAGE_KERNEL_RX);
16158 +}
16159 +EXPORT_SYMBOL(module_alloc_exec);
16160 +#endif
16161 +#endif
16162 +
16163 #ifdef CONFIG_X86_32
16164 int apply_relocate(Elf32_Shdr *sechdrs,
16165 const char *strtab,
16166 @@ -55,14 +100,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16167 unsigned int i;
16168 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
16169 Elf32_Sym *sym;
16170 - uint32_t *location;
16171 + uint32_t *plocation, location;
16172
16173 DEBUGP("Applying relocate section %u to %u\n", relsec,
16174 sechdrs[relsec].sh_info);
16175 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
16176 /* This is where to make the change */
16177 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
16178 - + rel[i].r_offset;
16179 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
16180 + location = (uint32_t)plocation;
16181 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
16182 + plocation = ktla_ktva((void *)plocation);
16183 /* This is the symbol it is referring to. Note that all
16184 undefined symbols have been resolved. */
16185 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
16186 @@ -71,11 +118,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
16187 switch (ELF32_R_TYPE(rel[i].r_info)) {
16188 case R_386_32:
16189 /* We add the value into the location given */
16190 - *location += sym->st_value;
16191 + pax_open_kernel();
16192 + *plocation += sym->st_value;
16193 + pax_close_kernel();
16194 break;
16195 case R_386_PC32:
16196 /* Add the value, subtract its postition */
16197 - *location += sym->st_value - (uint32_t)location;
16198 + pax_open_kernel();
16199 + *plocation += sym->st_value - location;
16200 + pax_close_kernel();
16201 break;
16202 default:
16203 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
16204 @@ -120,21 +171,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
16205 case R_X86_64_NONE:
16206 break;
16207 case R_X86_64_64:
16208 + pax_open_kernel();
16209 *(u64 *)loc = val;
16210 + pax_close_kernel();
16211 break;
16212 case R_X86_64_32:
16213 + pax_open_kernel();
16214 *(u32 *)loc = val;
16215 + pax_close_kernel();
16216 if (val != *(u32 *)loc)
16217 goto overflow;
16218 break;
16219 case R_X86_64_32S:
16220 + pax_open_kernel();
16221 *(s32 *)loc = val;
16222 + pax_close_kernel();
16223 if ((s64)val != *(s32 *)loc)
16224 goto overflow;
16225 break;
16226 case R_X86_64_PC32:
16227 val -= (u64)loc;
16228 + pax_open_kernel();
16229 *(u32 *)loc = val;
16230 + pax_close_kernel();
16231 +
16232 #if 0
16233 if ((s64)val != *(s32 *)loc)
16234 goto overflow;
16235 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
16236 index e88f37b..1353db6 100644
16237 --- a/arch/x86/kernel/nmi.c
16238 +++ b/arch/x86/kernel/nmi.c
16239 @@ -408,6 +408,17 @@ static notrace __kprobes void default_do_nmi(struct pt_regs *regs)
16240 dotraplinkage notrace __kprobes void
16241 do_nmi(struct pt_regs *regs, long error_code)
16242 {
16243 +
16244 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16245 + if (!user_mode(regs)) {
16246 + unsigned long cs = regs->cs & 0xFFFF;
16247 + unsigned long ip = ktva_ktla(regs->ip);
16248 +
16249 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
16250 + regs->ip = ip;
16251 + }
16252 +#endif
16253 +
16254 nmi_enter();
16255
16256 inc_irq_stat(__nmi_count);
16257 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
16258 index 676b8c7..870ba04 100644
16259 --- a/arch/x86/kernel/paravirt-spinlocks.c
16260 +++ b/arch/x86/kernel/paravirt-spinlocks.c
16261 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
16262 arch_spin_lock(lock);
16263 }
16264
16265 -struct pv_lock_ops pv_lock_ops = {
16266 +struct pv_lock_ops pv_lock_ops __read_only = {
16267 #ifdef CONFIG_SMP
16268 .spin_is_locked = __ticket_spin_is_locked,
16269 .spin_is_contended = __ticket_spin_is_contended,
16270 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
16271 index d90272e..6bb013b 100644
16272 --- a/arch/x86/kernel/paravirt.c
16273 +++ b/arch/x86/kernel/paravirt.c
16274 @@ -53,6 +53,9 @@ u64 _paravirt_ident_64(u64 x)
16275 {
16276 return x;
16277 }
16278 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16279 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
16280 +#endif
16281
16282 void __init default_banner(void)
16283 {
16284 @@ -145,15 +148,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
16285 if (opfunc == NULL)
16286 /* If there's no function, patch it with a ud2a (BUG) */
16287 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
16288 - else if (opfunc == _paravirt_nop)
16289 + else if (opfunc == (void *)_paravirt_nop)
16290 /* If the operation is a nop, then nop the callsite */
16291 ret = paravirt_patch_nop();
16292
16293 /* identity functions just return their single argument */
16294 - else if (opfunc == _paravirt_ident_32)
16295 + else if (opfunc == (void *)_paravirt_ident_32)
16296 ret = paravirt_patch_ident_32(insnbuf, len);
16297 - else if (opfunc == _paravirt_ident_64)
16298 + else if (opfunc == (void *)_paravirt_ident_64)
16299 ret = paravirt_patch_ident_64(insnbuf, len);
16300 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
16301 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
16302 + ret = paravirt_patch_ident_64(insnbuf, len);
16303 +#endif
16304
16305 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
16306 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
16307 @@ -178,7 +185,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
16308 if (insn_len > len || start == NULL)
16309 insn_len = len;
16310 else
16311 - memcpy(insnbuf, start, insn_len);
16312 + memcpy(insnbuf, ktla_ktva(start), insn_len);
16313
16314 return insn_len;
16315 }
16316 @@ -302,7 +309,7 @@ void arch_flush_lazy_mmu_mode(void)
16317 preempt_enable();
16318 }
16319
16320 -struct pv_info pv_info = {
16321 +struct pv_info pv_info __read_only = {
16322 .name = "bare hardware",
16323 .paravirt_enabled = 0,
16324 .kernel_rpl = 0,
16325 @@ -313,16 +320,16 @@ struct pv_info pv_info = {
16326 #endif
16327 };
16328
16329 -struct pv_init_ops pv_init_ops = {
16330 +struct pv_init_ops pv_init_ops __read_only = {
16331 .patch = native_patch,
16332 };
16333
16334 -struct pv_time_ops pv_time_ops = {
16335 +struct pv_time_ops pv_time_ops __read_only = {
16336 .sched_clock = native_sched_clock,
16337 .steal_clock = native_steal_clock,
16338 };
16339
16340 -struct pv_irq_ops pv_irq_ops = {
16341 +struct pv_irq_ops pv_irq_ops __read_only = {
16342 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
16343 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
16344 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
16345 @@ -334,7 +341,7 @@ struct pv_irq_ops pv_irq_ops = {
16346 #endif
16347 };
16348
16349 -struct pv_cpu_ops pv_cpu_ops = {
16350 +struct pv_cpu_ops pv_cpu_ops __read_only = {
16351 .cpuid = native_cpuid,
16352 .get_debugreg = native_get_debugreg,
16353 .set_debugreg = native_set_debugreg,
16354 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
16355 .end_context_switch = paravirt_nop,
16356 };
16357
16358 -struct pv_apic_ops pv_apic_ops = {
16359 +struct pv_apic_ops pv_apic_ops __read_only = {
16360 #ifdef CONFIG_X86_LOCAL_APIC
16361 .startup_ipi_hook = paravirt_nop,
16362 #endif
16363 };
16364
16365 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
16366 +#ifdef CONFIG_X86_32
16367 +#ifdef CONFIG_X86_PAE
16368 +/* 64-bit pagetable entries */
16369 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
16370 +#else
16371 /* 32-bit pagetable entries */
16372 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
16373 +#endif
16374 #else
16375 /* 64-bit pagetable entries */
16376 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
16377 #endif
16378
16379 -struct pv_mmu_ops pv_mmu_ops = {
16380 +struct pv_mmu_ops pv_mmu_ops __read_only = {
16381
16382 .read_cr2 = native_read_cr2,
16383 .write_cr2 = native_write_cr2,
16384 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
16385 .make_pud = PTE_IDENT,
16386
16387 .set_pgd = native_set_pgd,
16388 + .set_pgd_batched = native_set_pgd_batched,
16389 #endif
16390 #endif /* PAGETABLE_LEVELS >= 3 */
16391
16392 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
16393 },
16394
16395 .set_fixmap = native_set_fixmap,
16396 +
16397 +#ifdef CONFIG_PAX_KERNEXEC
16398 + .pax_open_kernel = native_pax_open_kernel,
16399 + .pax_close_kernel = native_pax_close_kernel,
16400 +#endif
16401 +
16402 };
16403
16404 EXPORT_SYMBOL_GPL(pv_time_ops);
16405 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
16406 index 35ccf75..7a15747 100644
16407 --- a/arch/x86/kernel/pci-iommu_table.c
16408 +++ b/arch/x86/kernel/pci-iommu_table.c
16409 @@ -2,7 +2,7 @@
16410 #include <asm/iommu_table.h>
16411 #include <linux/string.h>
16412 #include <linux/kallsyms.h>
16413 -
16414 +#include <linux/sched.h>
16415
16416 #define DEBUG 1
16417
16418 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
16419 index ee5d4fb..426649b 100644
16420 --- a/arch/x86/kernel/process.c
16421 +++ b/arch/x86/kernel/process.c
16422 @@ -48,16 +48,33 @@ void free_thread_xstate(struct task_struct *tsk)
16423
16424 void free_thread_info(struct thread_info *ti)
16425 {
16426 - free_thread_xstate(ti->task);
16427 free_pages((unsigned long)ti, THREAD_ORDER);
16428 }
16429
16430 +static struct kmem_cache *task_struct_cachep;
16431 +
16432 void arch_task_cache_init(void)
16433 {
16434 - task_xstate_cachep =
16435 - kmem_cache_create("task_xstate", xstate_size,
16436 + /* create a slab on which task_structs can be allocated */
16437 + task_struct_cachep =
16438 + kmem_cache_create("task_struct", sizeof(struct task_struct),
16439 + ARCH_MIN_TASKALIGN, SLAB_PANIC | SLAB_NOTRACK, NULL);
16440 +
16441 + task_xstate_cachep =
16442 + kmem_cache_create("task_xstate", xstate_size,
16443 __alignof__(union thread_xstate),
16444 - SLAB_PANIC | SLAB_NOTRACK, NULL);
16445 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
16446 +}
16447 +
16448 +struct task_struct *alloc_task_struct_node(int node)
16449 +{
16450 + return kmem_cache_alloc_node(task_struct_cachep, GFP_KERNEL, node);
16451 +}
16452 +
16453 +void free_task_struct(struct task_struct *task)
16454 +{
16455 + free_thread_xstate(task);
16456 + kmem_cache_free(task_struct_cachep, task);
16457 }
16458
16459 /*
16460 @@ -70,7 +87,7 @@ void exit_thread(void)
16461 unsigned long *bp = t->io_bitmap_ptr;
16462
16463 if (bp) {
16464 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
16465 + struct tss_struct *tss = init_tss + get_cpu();
16466
16467 t->io_bitmap_ptr = NULL;
16468 clear_thread_flag(TIF_IO_BITMAP);
16469 @@ -106,7 +123,7 @@ void show_regs_common(void)
16470
16471 printk(KERN_CONT "\n");
16472 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
16473 - current->pid, current->comm, print_tainted(),
16474 + task_pid_nr(current), current->comm, print_tainted(),
16475 init_utsname()->release,
16476 (int)strcspn(init_utsname()->version, " "),
16477 init_utsname()->version);
16478 @@ -120,6 +137,9 @@ void flush_thread(void)
16479 {
16480 struct task_struct *tsk = current;
16481
16482 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
16483 + loadsegment(gs, 0);
16484 +#endif
16485 flush_ptrace_hw_breakpoint(tsk);
16486 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
16487 /*
16488 @@ -282,10 +302,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
16489 regs.di = (unsigned long) arg;
16490
16491 #ifdef CONFIG_X86_32
16492 - regs.ds = __USER_DS;
16493 - regs.es = __USER_DS;
16494 + regs.ds = __KERNEL_DS;
16495 + regs.es = __KERNEL_DS;
16496 regs.fs = __KERNEL_PERCPU;
16497 - regs.gs = __KERNEL_STACK_CANARY;
16498 + savesegment(gs, regs.gs);
16499 #else
16500 regs.ss = __KERNEL_DS;
16501 #endif
16502 @@ -411,7 +431,7 @@ bool set_pm_idle_to_default(void)
16503
16504 return ret;
16505 }
16506 -void stop_this_cpu(void *dummy)
16507 +__noreturn void stop_this_cpu(void *dummy)
16508 {
16509 local_irq_disable();
16510 /*
16511 @@ -653,16 +673,37 @@ static int __init idle_setup(char *str)
16512 }
16513 early_param("idle", idle_setup);
16514
16515 -unsigned long arch_align_stack(unsigned long sp)
16516 +#ifdef CONFIG_PAX_RANDKSTACK
16517 +void pax_randomize_kstack(struct pt_regs *regs)
16518 {
16519 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
16520 - sp -= get_random_int() % 8192;
16521 - return sp & ~0xf;
16522 -}
16523 + struct thread_struct *thread = &current->thread;
16524 + unsigned long time;
16525
16526 -unsigned long arch_randomize_brk(struct mm_struct *mm)
16527 -{
16528 - unsigned long range_end = mm->brk + 0x02000000;
16529 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
16530 -}
16531 + if (!randomize_va_space)
16532 + return;
16533 +
16534 + if (v8086_mode(regs))
16535 + return;
16536
16537 + rdtscl(time);
16538 +
16539 + /* P4 seems to return a 0 LSB, ignore it */
16540 +#ifdef CONFIG_MPENTIUM4
16541 + time &= 0x3EUL;
16542 + time <<= 2;
16543 +#elif defined(CONFIG_X86_64)
16544 + time &= 0xFUL;
16545 + time <<= 4;
16546 +#else
16547 + time &= 0x1FUL;
16548 + time <<= 3;
16549 +#endif
16550 +
16551 + thread->sp0 ^= time;
16552 + load_sp0(init_tss + smp_processor_id(), thread);
16553 +
16554 +#ifdef CONFIG_X86_64
16555 + percpu_write(kernel_stack, thread->sp0);
16556 +#endif
16557 +}
16558 +#endif
16559 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
16560 index 795b79f..063767a 100644
16561 --- a/arch/x86/kernel/process_32.c
16562 +++ b/arch/x86/kernel/process_32.c
16563 @@ -67,6 +67,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
16564 unsigned long thread_saved_pc(struct task_struct *tsk)
16565 {
16566 return ((unsigned long *)tsk->thread.sp)[3];
16567 +//XXX return tsk->thread.eip;
16568 }
16569
16570 #ifndef CONFIG_SMP
16571 @@ -130,15 +131,14 @@ void __show_regs(struct pt_regs *regs, int all)
16572 unsigned long sp;
16573 unsigned short ss, gs;
16574
16575 - if (user_mode_vm(regs)) {
16576 + if (user_mode(regs)) {
16577 sp = regs->sp;
16578 ss = regs->ss & 0xffff;
16579 - gs = get_user_gs(regs);
16580 } else {
16581 sp = kernel_stack_pointer(regs);
16582 savesegment(ss, ss);
16583 - savesegment(gs, gs);
16584 }
16585 + gs = get_user_gs(regs);
16586
16587 show_regs_common();
16588
16589 @@ -200,13 +200,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16590 struct task_struct *tsk;
16591 int err;
16592
16593 - childregs = task_pt_regs(p);
16594 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
16595 *childregs = *regs;
16596 childregs->ax = 0;
16597 childregs->sp = sp;
16598
16599 p->thread.sp = (unsigned long) childregs;
16600 p->thread.sp0 = (unsigned long) (childregs+1);
16601 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16602
16603 p->thread.ip = (unsigned long) ret_from_fork;
16604
16605 @@ -296,7 +297,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16606 struct thread_struct *prev = &prev_p->thread,
16607 *next = &next_p->thread;
16608 int cpu = smp_processor_id();
16609 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16610 + struct tss_struct *tss = init_tss + cpu;
16611 bool preload_fpu;
16612
16613 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
16614 @@ -331,6 +332,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16615 */
16616 lazy_save_gs(prev->gs);
16617
16618 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16619 + __set_fs(task_thread_info(next_p)->addr_limit);
16620 +#endif
16621 +
16622 /*
16623 * Load the per-thread Thread-Local Storage descriptor.
16624 */
16625 @@ -366,6 +371,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16626 */
16627 arch_end_context_switch(next_p);
16628
16629 + percpu_write(current_task, next_p);
16630 + percpu_write(current_tinfo, &next_p->tinfo);
16631 +
16632 if (preload_fpu)
16633 __math_state_restore();
16634
16635 @@ -375,8 +383,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16636 if (prev->gs | next->gs)
16637 lazy_load_gs(next->gs);
16638
16639 - percpu_write(current_task, next_p);
16640 -
16641 return prev_p;
16642 }
16643
16644 @@ -406,4 +412,3 @@ unsigned long get_wchan(struct task_struct *p)
16645 } while (count++ < 16);
16646 return 0;
16647 }
16648 -
16649 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
16650 index 3bd7e6e..90b2bcf 100644
16651 --- a/arch/x86/kernel/process_64.c
16652 +++ b/arch/x86/kernel/process_64.c
16653 @@ -89,7 +89,7 @@ static void __exit_idle(void)
16654 void exit_idle(void)
16655 {
16656 /* idle loop has pid 0 */
16657 - if (current->pid)
16658 + if (task_pid_nr(current))
16659 return;
16660 __exit_idle();
16661 }
16662 @@ -264,8 +264,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16663 struct pt_regs *childregs;
16664 struct task_struct *me = current;
16665
16666 - childregs = ((struct pt_regs *)
16667 - (THREAD_SIZE + task_stack_page(p))) - 1;
16668 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
16669 *childregs = *regs;
16670
16671 childregs->ax = 0;
16672 @@ -277,6 +276,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
16673 p->thread.sp = (unsigned long) childregs;
16674 p->thread.sp0 = (unsigned long) (childregs+1);
16675 p->thread.usersp = me->thread.usersp;
16676 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
16677
16678 set_tsk_thread_flag(p, TIF_FORK);
16679
16680 @@ -379,7 +379,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16681 struct thread_struct *prev = &prev_p->thread;
16682 struct thread_struct *next = &next_p->thread;
16683 int cpu = smp_processor_id();
16684 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
16685 + struct tss_struct *tss = init_tss + cpu;
16686 unsigned fsindex, gsindex;
16687 bool preload_fpu;
16688
16689 @@ -475,10 +475,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
16690 prev->usersp = percpu_read(old_rsp);
16691 percpu_write(old_rsp, next->usersp);
16692 percpu_write(current_task, next_p);
16693 + percpu_write(current_tinfo, &next_p->tinfo);
16694
16695 - percpu_write(kernel_stack,
16696 - (unsigned long)task_stack_page(next_p) +
16697 - THREAD_SIZE - KERNEL_STACK_OFFSET);
16698 + percpu_write(kernel_stack, next->sp0);
16699
16700 /*
16701 * Now maybe reload the debug registers and handle I/O bitmaps
16702 @@ -540,12 +539,11 @@ unsigned long get_wchan(struct task_struct *p)
16703 if (!p || p == current || p->state == TASK_RUNNING)
16704 return 0;
16705 stack = (unsigned long)task_stack_page(p);
16706 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
16707 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
16708 return 0;
16709 fp = *(u64 *)(p->thread.sp);
16710 do {
16711 - if (fp < (unsigned long)stack ||
16712 - fp >= (unsigned long)stack+THREAD_SIZE)
16713 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
16714 return 0;
16715 ip = *(u64 *)(fp+8);
16716 if (!in_sched_functions(ip))
16717 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
16718 index 8252879..d3219e0 100644
16719 --- a/arch/x86/kernel/ptrace.c
16720 +++ b/arch/x86/kernel/ptrace.c
16721 @@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
16722 unsigned long addr, unsigned long data)
16723 {
16724 int ret;
16725 - unsigned long __user *datap = (unsigned long __user *)data;
16726 + unsigned long __user *datap = (__force unsigned long __user *)data;
16727
16728 switch (request) {
16729 /* read the word at location addr in the USER area. */
16730 @@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
16731 if ((int) addr < 0)
16732 return -EIO;
16733 ret = do_get_thread_area(child, addr,
16734 - (struct user_desc __user *)data);
16735 + (__force struct user_desc __user *) data);
16736 break;
16737
16738 case PTRACE_SET_THREAD_AREA:
16739 if ((int) addr < 0)
16740 return -EIO;
16741 ret = do_set_thread_area(child, addr,
16742 - (struct user_desc __user *)data, 0);
16743 + (__force struct user_desc __user *) data, 0);
16744 break;
16745 #endif
16746
16747 @@ -1331,7 +1331,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
16748 memset(info, 0, sizeof(*info));
16749 info->si_signo = SIGTRAP;
16750 info->si_code = si_code;
16751 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
16752 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
16753 }
16754
16755 void user_single_step_siginfo(struct task_struct *tsk,
16756 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
16757 index 42eb330..139955c 100644
16758 --- a/arch/x86/kernel/pvclock.c
16759 +++ b/arch/x86/kernel/pvclock.c
16760 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
16761 return pv_tsc_khz;
16762 }
16763
16764 -static atomic64_t last_value = ATOMIC64_INIT(0);
16765 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
16766
16767 void pvclock_resume(void)
16768 {
16769 - atomic64_set(&last_value, 0);
16770 + atomic64_set_unchecked(&last_value, 0);
16771 }
16772
16773 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16774 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
16775 * updating at the same time, and one of them could be slightly behind,
16776 * making the assumption that last_value always go forward fail to hold.
16777 */
16778 - last = atomic64_read(&last_value);
16779 + last = atomic64_read_unchecked(&last_value);
16780 do {
16781 if (ret < last)
16782 return last;
16783 - last = atomic64_cmpxchg(&last_value, last, ret);
16784 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
16785 } while (unlikely(last != ret));
16786
16787 return ret;
16788 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
16789 index 37a458b..e63d183 100644
16790 --- a/arch/x86/kernel/reboot.c
16791 +++ b/arch/x86/kernel/reboot.c
16792 @@ -35,7 +35,7 @@ void (*pm_power_off)(void);
16793 EXPORT_SYMBOL(pm_power_off);
16794
16795 static const struct desc_ptr no_idt = {};
16796 -static int reboot_mode;
16797 +static unsigned short reboot_mode;
16798 enum reboot_type reboot_type = BOOT_ACPI;
16799 int reboot_force;
16800
16801 @@ -324,13 +324,17 @@ core_initcall(reboot_init);
16802 extern const unsigned char machine_real_restart_asm[];
16803 extern const u64 machine_real_restart_gdt[3];
16804
16805 -void machine_real_restart(unsigned int type)
16806 +__noreturn void machine_real_restart(unsigned int type)
16807 {
16808 void *restart_va;
16809 unsigned long restart_pa;
16810 - void (*restart_lowmem)(unsigned int);
16811 + void (* __noreturn restart_lowmem)(unsigned int);
16812 u64 *lowmem_gdt;
16813
16814 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16815 + struct desc_struct *gdt;
16816 +#endif
16817 +
16818 local_irq_disable();
16819
16820 /* Write zero to CMOS register number 0x0f, which the BIOS POST
16821 @@ -356,14 +360,14 @@ void machine_real_restart(unsigned int type)
16822 boot)". This seems like a fairly standard thing that gets set by
16823 REBOOT.COM programs, and the previous reset routine did this
16824 too. */
16825 - *((unsigned short *)0x472) = reboot_mode;
16826 + *(unsigned short *)(__va(0x472)) = reboot_mode;
16827
16828 /* Patch the GDT in the low memory trampoline */
16829 lowmem_gdt = TRAMPOLINE_SYM(machine_real_restart_gdt);
16830
16831 restart_va = TRAMPOLINE_SYM(machine_real_restart_asm);
16832 restart_pa = virt_to_phys(restart_va);
16833 - restart_lowmem = (void (*)(unsigned int))restart_pa;
16834 + restart_lowmem = (void *)restart_pa;
16835
16836 /* GDT[0]: GDT self-pointer */
16837 lowmem_gdt[0] =
16838 @@ -374,7 +378,33 @@ void machine_real_restart(unsigned int type)
16839 GDT_ENTRY(0x009b, restart_pa, 0xffff);
16840
16841 /* Jump to the identity-mapped low memory code */
16842 +
16843 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16844 + gdt = get_cpu_gdt_table(smp_processor_id());
16845 + pax_open_kernel();
16846 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16847 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
16848 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
16849 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
16850 +#endif
16851 +#ifdef CONFIG_PAX_KERNEXEC
16852 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
16853 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
16854 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
16855 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
16856 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
16857 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
16858 +#endif
16859 + pax_close_kernel();
16860 +#endif
16861 +
16862 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16863 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
16864 + unreachable();
16865 +#else
16866 restart_lowmem(type);
16867 +#endif
16868 +
16869 }
16870 #ifdef CONFIG_APM_MODULE
16871 EXPORT_SYMBOL(machine_real_restart);
16872 @@ -540,7 +570,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
16873 * try to force a triple fault and then cycle between hitting the keyboard
16874 * controller and doing that
16875 */
16876 -static void native_machine_emergency_restart(void)
16877 +__noreturn static void native_machine_emergency_restart(void)
16878 {
16879 int i;
16880 int attempt = 0;
16881 @@ -664,13 +694,13 @@ void native_machine_shutdown(void)
16882 #endif
16883 }
16884
16885 -static void __machine_emergency_restart(int emergency)
16886 +static __noreturn void __machine_emergency_restart(int emergency)
16887 {
16888 reboot_emergency = emergency;
16889 machine_ops.emergency_restart();
16890 }
16891
16892 -static void native_machine_restart(char *__unused)
16893 +static __noreturn void native_machine_restart(char *__unused)
16894 {
16895 printk("machine restart\n");
16896
16897 @@ -679,7 +709,7 @@ static void native_machine_restart(char *__unused)
16898 __machine_emergency_restart(0);
16899 }
16900
16901 -static void native_machine_halt(void)
16902 +static __noreturn void native_machine_halt(void)
16903 {
16904 /* stop other cpus and apics */
16905 machine_shutdown();
16906 @@ -690,7 +720,7 @@ static void native_machine_halt(void)
16907 stop_this_cpu(NULL);
16908 }
16909
16910 -static void native_machine_power_off(void)
16911 +__noreturn static void native_machine_power_off(void)
16912 {
16913 if (pm_power_off) {
16914 if (!reboot_force)
16915 @@ -699,6 +729,7 @@ static void native_machine_power_off(void)
16916 }
16917 /* a fallback in case there is no PM info available */
16918 tboot_shutdown(TB_SHUTDOWN_HALT);
16919 + unreachable();
16920 }
16921
16922 struct machine_ops machine_ops = {
16923 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
16924 index 7a6f3b3..bed145d7 100644
16925 --- a/arch/x86/kernel/relocate_kernel_64.S
16926 +++ b/arch/x86/kernel/relocate_kernel_64.S
16927 @@ -11,6 +11,7 @@
16928 #include <asm/kexec.h>
16929 #include <asm/processor-flags.h>
16930 #include <asm/pgtable_types.h>
16931 +#include <asm/alternative-asm.h>
16932
16933 /*
16934 * Must be relocatable PIC code callable as a C function
16935 @@ -160,13 +161,14 @@ identity_mapped:
16936 xorq %rbp, %rbp
16937 xorq %r8, %r8
16938 xorq %r9, %r9
16939 - xorq %r10, %r9
16940 + xorq %r10, %r10
16941 xorq %r11, %r11
16942 xorq %r12, %r12
16943 xorq %r13, %r13
16944 xorq %r14, %r14
16945 xorq %r15, %r15
16946
16947 + pax_force_retaddr 0, 1
16948 ret
16949
16950 1:
16951 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
16952 index cf0ef98..e3f780b 100644
16953 --- a/arch/x86/kernel/setup.c
16954 +++ b/arch/x86/kernel/setup.c
16955 @@ -447,7 +447,7 @@ static void __init parse_setup_data(void)
16956
16957 switch (data->type) {
16958 case SETUP_E820_EXT:
16959 - parse_e820_ext(data);
16960 + parse_e820_ext((struct setup_data __force_kernel *)data);
16961 break;
16962 case SETUP_DTB:
16963 add_dtb(pa_data);
16964 @@ -650,7 +650,7 @@ static void __init trim_bios_range(void)
16965 * area (640->1Mb) as ram even though it is not.
16966 * take them out.
16967 */
16968 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
16969 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
16970 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
16971 }
16972
16973 @@ -773,14 +773,14 @@ void __init setup_arch(char **cmdline_p)
16974
16975 if (!boot_params.hdr.root_flags)
16976 root_mountflags &= ~MS_RDONLY;
16977 - init_mm.start_code = (unsigned long) _text;
16978 - init_mm.end_code = (unsigned long) _etext;
16979 + init_mm.start_code = ktla_ktva((unsigned long) _text);
16980 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
16981 init_mm.end_data = (unsigned long) _edata;
16982 init_mm.brk = _brk_end;
16983
16984 - code_resource.start = virt_to_phys(_text);
16985 - code_resource.end = virt_to_phys(_etext)-1;
16986 - data_resource.start = virt_to_phys(_etext);
16987 + code_resource.start = virt_to_phys(ktla_ktva(_text));
16988 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
16989 + data_resource.start = virt_to_phys(_sdata);
16990 data_resource.end = virt_to_phys(_edata)-1;
16991 bss_resource.start = virt_to_phys(&__bss_start);
16992 bss_resource.end = virt_to_phys(&__bss_stop)-1;
16993 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
16994 index 71f4727..16dc9f7 100644
16995 --- a/arch/x86/kernel/setup_percpu.c
16996 +++ b/arch/x86/kernel/setup_percpu.c
16997 @@ -21,19 +21,17 @@
16998 #include <asm/cpu.h>
16999 #include <asm/stackprotector.h>
17000
17001 -DEFINE_PER_CPU(int, cpu_number);
17002 +#ifdef CONFIG_SMP
17003 +DEFINE_PER_CPU(unsigned int, cpu_number);
17004 EXPORT_PER_CPU_SYMBOL(cpu_number);
17005 +#endif
17006
17007 -#ifdef CONFIG_X86_64
17008 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
17009 -#else
17010 -#define BOOT_PERCPU_OFFSET 0
17011 -#endif
17012
17013 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
17014 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
17015
17016 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
17017 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
17018 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
17019 };
17020 EXPORT_SYMBOL(__per_cpu_offset);
17021 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
17022 {
17023 #ifdef CONFIG_X86_32
17024 struct desc_struct gdt;
17025 + unsigned long base = per_cpu_offset(cpu);
17026
17027 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
17028 - 0x2 | DESCTYPE_S, 0x8);
17029 - gdt.s = 1;
17030 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
17031 + 0x83 | DESCTYPE_S, 0xC);
17032 write_gdt_entry(get_cpu_gdt_table(cpu),
17033 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
17034 #endif
17035 @@ -207,6 +205,11 @@ void __init setup_per_cpu_areas(void)
17036 /* alrighty, percpu areas up and running */
17037 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
17038 for_each_possible_cpu(cpu) {
17039 +#ifdef CONFIG_CC_STACKPROTECTOR
17040 +#ifdef CONFIG_X86_32
17041 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
17042 +#endif
17043 +#endif
17044 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
17045 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
17046 per_cpu(cpu_number, cpu) = cpu;
17047 @@ -247,6 +250,12 @@ void __init setup_per_cpu_areas(void)
17048 */
17049 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
17050 #endif
17051 +#ifdef CONFIG_CC_STACKPROTECTOR
17052 +#ifdef CONFIG_X86_32
17053 + if (!cpu)
17054 + per_cpu(stack_canary.canary, cpu) = canary;
17055 +#endif
17056 +#endif
17057 /*
17058 * Up to this point, the boot CPU has been using .init.data
17059 * area. Reload any changed state for the boot CPU.
17060 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
17061 index 54ddaeb2..22c3bdc 100644
17062 --- a/arch/x86/kernel/signal.c
17063 +++ b/arch/x86/kernel/signal.c
17064 @@ -198,7 +198,7 @@ static unsigned long align_sigframe(unsigned long sp)
17065 * Align the stack pointer according to the i386 ABI,
17066 * i.e. so that on function entry ((sp + 4) & 15) == 0.
17067 */
17068 - sp = ((sp + 4) & -16ul) - 4;
17069 + sp = ((sp - 12) & -16ul) - 4;
17070 #else /* !CONFIG_X86_32 */
17071 sp = round_down(sp, 16) - 8;
17072 #endif
17073 @@ -249,11 +249,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
17074 * Return an always-bogus address instead so we will die with SIGSEGV.
17075 */
17076 if (onsigstack && !likely(on_sig_stack(sp)))
17077 - return (void __user *)-1L;
17078 + return (__force void __user *)-1L;
17079
17080 /* save i387 state */
17081 if (used_math() && save_i387_xstate(*fpstate) < 0)
17082 - return (void __user *)-1L;
17083 + return (__force void __user *)-1L;
17084
17085 return (void __user *)sp;
17086 }
17087 @@ -308,9 +308,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
17088 }
17089
17090 if (current->mm->context.vdso)
17091 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17092 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
17093 else
17094 - restorer = &frame->retcode;
17095 + restorer = (void __user *)&frame->retcode;
17096 if (ka->sa.sa_flags & SA_RESTORER)
17097 restorer = ka->sa.sa_restorer;
17098
17099 @@ -324,7 +324,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
17100 * reasons and because gdb uses it as a signature to notice
17101 * signal handler stack frames.
17102 */
17103 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
17104 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
17105
17106 if (err)
17107 return -EFAULT;
17108 @@ -378,7 +378,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
17109 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
17110
17111 /* Set up to return from userspace. */
17112 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17113 + if (current->mm->context.vdso)
17114 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
17115 + else
17116 + restorer = (void __user *)&frame->retcode;
17117 if (ka->sa.sa_flags & SA_RESTORER)
17118 restorer = ka->sa.sa_restorer;
17119 put_user_ex(restorer, &frame->pretcode);
17120 @@ -390,7 +393,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
17121 * reasons and because gdb uses it as a signature to notice
17122 * signal handler stack frames.
17123 */
17124 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
17125 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
17126 } put_user_catch(err);
17127
17128 if (err)
17129 @@ -769,7 +772,7 @@ static void do_signal(struct pt_regs *regs)
17130 * X86_32: vm86 regs switched out by assembly code before reaching
17131 * here, so testing against kernel CS suffices.
17132 */
17133 - if (!user_mode(regs))
17134 + if (!user_mode_novm(regs))
17135 return;
17136
17137 signr = get_signal_to_deliver(&info, &ka, regs, NULL);
17138 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
17139 index 9f548cb..caf76f7 100644
17140 --- a/arch/x86/kernel/smpboot.c
17141 +++ b/arch/x86/kernel/smpboot.c
17142 @@ -709,17 +709,20 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)
17143 set_idle_for_cpu(cpu, c_idle.idle);
17144 do_rest:
17145 per_cpu(current_task, cpu) = c_idle.idle;
17146 + per_cpu(current_tinfo, cpu) = &c_idle.idle->tinfo;
17147 #ifdef CONFIG_X86_32
17148 /* Stack for startup_32 can be just as for start_secondary onwards */
17149 irq_ctx_init(cpu);
17150 #else
17151 clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
17152 initial_gs = per_cpu_offset(cpu);
17153 - per_cpu(kernel_stack, cpu) =
17154 - (unsigned long)task_stack_page(c_idle.idle) -
17155 - KERNEL_STACK_OFFSET + THREAD_SIZE;
17156 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(c_idle.idle) - 16 + THREAD_SIZE;
17157 #endif
17158 +
17159 + pax_open_kernel();
17160 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17161 + pax_close_kernel();
17162 +
17163 initial_code = (unsigned long)start_secondary;
17164 stack_start = c_idle.idle->thread.sp;
17165
17166 @@ -861,6 +864,12 @@ int __cpuinit native_cpu_up(unsigned int cpu)
17167
17168 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
17169
17170 +#ifdef CONFIG_PAX_PER_CPU_PGD
17171 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
17172 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
17173 + KERNEL_PGD_PTRS);
17174 +#endif
17175 +
17176 err = do_boot_cpu(apicid, cpu);
17177 if (err) {
17178 pr_debug("do_boot_cpu failed %d\n", err);
17179 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
17180 index c346d11..d43b163 100644
17181 --- a/arch/x86/kernel/step.c
17182 +++ b/arch/x86/kernel/step.c
17183 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
17184 struct desc_struct *desc;
17185 unsigned long base;
17186
17187 - seg &= ~7UL;
17188 + seg >>= 3;
17189
17190 mutex_lock(&child->mm->context.lock);
17191 - if (unlikely((seg >> 3) >= child->mm->context.size))
17192 + if (unlikely(seg >= child->mm->context.size))
17193 addr = -1L; /* bogus selector, access would fault */
17194 else {
17195 desc = child->mm->context.ldt + seg;
17196 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
17197 addr += base;
17198 }
17199 mutex_unlock(&child->mm->context.lock);
17200 - }
17201 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
17202 + addr = ktla_ktva(addr);
17203
17204 return addr;
17205 }
17206 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
17207 unsigned char opcode[15];
17208 unsigned long addr = convert_ip_to_linear(child, regs);
17209
17210 + if (addr == -EINVAL)
17211 + return 0;
17212 +
17213 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
17214 for (i = 0; i < copied; i++) {
17215 switch (opcode[i]) {
17216 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
17217 index 0b0cb5f..db6b9ed 100644
17218 --- a/arch/x86/kernel/sys_i386_32.c
17219 +++ b/arch/x86/kernel/sys_i386_32.c
17220 @@ -24,17 +24,224 @@
17221
17222 #include <asm/syscalls.h>
17223
17224 -/*
17225 - * Do a system call from kernel instead of calling sys_execve so we
17226 - * end up with proper pt_regs.
17227 - */
17228 -int kernel_execve(const char *filename,
17229 - const char *const argv[],
17230 - const char *const envp[])
17231 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
17232 {
17233 - long __res;
17234 - asm volatile ("int $0x80"
17235 - : "=a" (__res)
17236 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
17237 - return __res;
17238 + unsigned long pax_task_size = TASK_SIZE;
17239 +
17240 +#ifdef CONFIG_PAX_SEGMEXEC
17241 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
17242 + pax_task_size = SEGMEXEC_TASK_SIZE;
17243 +#endif
17244 +
17245 + if (len > pax_task_size || addr > pax_task_size - len)
17246 + return -EINVAL;
17247 +
17248 + return 0;
17249 +}
17250 +
17251 +unsigned long
17252 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
17253 + unsigned long len, unsigned long pgoff, unsigned long flags)
17254 +{
17255 + struct mm_struct *mm = current->mm;
17256 + struct vm_area_struct *vma;
17257 + unsigned long start_addr, pax_task_size = TASK_SIZE;
17258 +
17259 +#ifdef CONFIG_PAX_SEGMEXEC
17260 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17261 + pax_task_size = SEGMEXEC_TASK_SIZE;
17262 +#endif
17263 +
17264 + pax_task_size -= PAGE_SIZE;
17265 +
17266 + if (len > pax_task_size)
17267 + return -ENOMEM;
17268 +
17269 + if (flags & MAP_FIXED)
17270 + return addr;
17271 +
17272 +#ifdef CONFIG_PAX_RANDMMAP
17273 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17274 +#endif
17275 +
17276 + if (addr) {
17277 + addr = PAGE_ALIGN(addr);
17278 + if (pax_task_size - len >= addr) {
17279 + vma = find_vma(mm, addr);
17280 + if (check_heap_stack_gap(vma, addr, len))
17281 + return addr;
17282 + }
17283 + }
17284 + if (len > mm->cached_hole_size) {
17285 + start_addr = addr = mm->free_area_cache;
17286 + } else {
17287 + start_addr = addr = mm->mmap_base;
17288 + mm->cached_hole_size = 0;
17289 + }
17290 +
17291 +#ifdef CONFIG_PAX_PAGEEXEC
17292 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
17293 + start_addr = 0x00110000UL;
17294 +
17295 +#ifdef CONFIG_PAX_RANDMMAP
17296 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17297 + start_addr += mm->delta_mmap & 0x03FFF000UL;
17298 +#endif
17299 +
17300 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
17301 + start_addr = addr = mm->mmap_base;
17302 + else
17303 + addr = start_addr;
17304 + }
17305 +#endif
17306 +
17307 +full_search:
17308 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
17309 + /* At this point: (!vma || addr < vma->vm_end). */
17310 + if (pax_task_size - len < addr) {
17311 + /*
17312 + * Start a new search - just in case we missed
17313 + * some holes.
17314 + */
17315 + if (start_addr != mm->mmap_base) {
17316 + start_addr = addr = mm->mmap_base;
17317 + mm->cached_hole_size = 0;
17318 + goto full_search;
17319 + }
17320 + return -ENOMEM;
17321 + }
17322 + if (check_heap_stack_gap(vma, addr, len))
17323 + break;
17324 + if (addr + mm->cached_hole_size < vma->vm_start)
17325 + mm->cached_hole_size = vma->vm_start - addr;
17326 + addr = vma->vm_end;
17327 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
17328 + start_addr = addr = mm->mmap_base;
17329 + mm->cached_hole_size = 0;
17330 + goto full_search;
17331 + }
17332 + }
17333 +
17334 + /*
17335 + * Remember the place where we stopped the search:
17336 + */
17337 + mm->free_area_cache = addr + len;
17338 + return addr;
17339 +}
17340 +
17341 +unsigned long
17342 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17343 + const unsigned long len, const unsigned long pgoff,
17344 + const unsigned long flags)
17345 +{
17346 + struct vm_area_struct *vma;
17347 + struct mm_struct *mm = current->mm;
17348 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
17349 +
17350 +#ifdef CONFIG_PAX_SEGMEXEC
17351 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17352 + pax_task_size = SEGMEXEC_TASK_SIZE;
17353 +#endif
17354 +
17355 + pax_task_size -= PAGE_SIZE;
17356 +
17357 + /* requested length too big for entire address space */
17358 + if (len > pax_task_size)
17359 + return -ENOMEM;
17360 +
17361 + if (flags & MAP_FIXED)
17362 + return addr;
17363 +
17364 +#ifdef CONFIG_PAX_PAGEEXEC
17365 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
17366 + goto bottomup;
17367 +#endif
17368 +
17369 +#ifdef CONFIG_PAX_RANDMMAP
17370 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17371 +#endif
17372 +
17373 + /* requesting a specific address */
17374 + if (addr) {
17375 + addr = PAGE_ALIGN(addr);
17376 + if (pax_task_size - len >= addr) {
17377 + vma = find_vma(mm, addr);
17378 + if (check_heap_stack_gap(vma, addr, len))
17379 + return addr;
17380 + }
17381 + }
17382 +
17383 + /* check if free_area_cache is useful for us */
17384 + if (len <= mm->cached_hole_size) {
17385 + mm->cached_hole_size = 0;
17386 + mm->free_area_cache = mm->mmap_base;
17387 + }
17388 +
17389 + /* either no address requested or can't fit in requested address hole */
17390 + addr = mm->free_area_cache;
17391 +
17392 + /* make sure it can fit in the remaining address space */
17393 + if (addr > len) {
17394 + vma = find_vma(mm, addr-len);
17395 + if (check_heap_stack_gap(vma, addr - len, len))
17396 + /* remember the address as a hint for next time */
17397 + return (mm->free_area_cache = addr-len);
17398 + }
17399 +
17400 + if (mm->mmap_base < len)
17401 + goto bottomup;
17402 +
17403 + addr = mm->mmap_base-len;
17404 +
17405 + do {
17406 + /*
17407 + * Lookup failure means no vma is above this address,
17408 + * else if new region fits below vma->vm_start,
17409 + * return with success:
17410 + */
17411 + vma = find_vma(mm, addr);
17412 + if (check_heap_stack_gap(vma, addr, len))
17413 + /* remember the address as a hint for next time */
17414 + return (mm->free_area_cache = addr);
17415 +
17416 + /* remember the largest hole we saw so far */
17417 + if (addr + mm->cached_hole_size < vma->vm_start)
17418 + mm->cached_hole_size = vma->vm_start - addr;
17419 +
17420 + /* try just below the current vma->vm_start */
17421 + addr = skip_heap_stack_gap(vma, len);
17422 + } while (!IS_ERR_VALUE(addr));
17423 +
17424 +bottomup:
17425 + /*
17426 + * A failed mmap() very likely causes application failure,
17427 + * so fall back to the bottom-up function here. This scenario
17428 + * can happen with large stack limits and large mmap()
17429 + * allocations.
17430 + */
17431 +
17432 +#ifdef CONFIG_PAX_SEGMEXEC
17433 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
17434 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
17435 + else
17436 +#endif
17437 +
17438 + mm->mmap_base = TASK_UNMAPPED_BASE;
17439 +
17440 +#ifdef CONFIG_PAX_RANDMMAP
17441 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17442 + mm->mmap_base += mm->delta_mmap;
17443 +#endif
17444 +
17445 + mm->free_area_cache = mm->mmap_base;
17446 + mm->cached_hole_size = ~0UL;
17447 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17448 + /*
17449 + * Restore the topdown base:
17450 + */
17451 + mm->mmap_base = base;
17452 + mm->free_area_cache = base;
17453 + mm->cached_hole_size = ~0UL;
17454 +
17455 + return addr;
17456 }
17457 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
17458 index 0514890..3dbebce 100644
17459 --- a/arch/x86/kernel/sys_x86_64.c
17460 +++ b/arch/x86/kernel/sys_x86_64.c
17461 @@ -95,8 +95,8 @@ out:
17462 return error;
17463 }
17464
17465 -static void find_start_end(unsigned long flags, unsigned long *begin,
17466 - unsigned long *end)
17467 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
17468 + unsigned long *begin, unsigned long *end)
17469 {
17470 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
17471 unsigned long new_begin;
17472 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
17473 *begin = new_begin;
17474 }
17475 } else {
17476 - *begin = TASK_UNMAPPED_BASE;
17477 + *begin = mm->mmap_base;
17478 *end = TASK_SIZE;
17479 }
17480 }
17481 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
17482 if (flags & MAP_FIXED)
17483 return addr;
17484
17485 - find_start_end(flags, &begin, &end);
17486 + find_start_end(mm, flags, &begin, &end);
17487
17488 if (len > end)
17489 return -ENOMEM;
17490
17491 +#ifdef CONFIG_PAX_RANDMMAP
17492 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17493 +#endif
17494 +
17495 if (addr) {
17496 addr = PAGE_ALIGN(addr);
17497 vma = find_vma(mm, addr);
17498 - if (end - len >= addr &&
17499 - (!vma || addr + len <= vma->vm_start))
17500 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
17501 return addr;
17502 }
17503 if (((flags & MAP_32BIT) || test_thread_flag(TIF_IA32))
17504 @@ -172,7 +175,7 @@ full_search:
17505 }
17506 return -ENOMEM;
17507 }
17508 - if (!vma || addr + len <= vma->vm_start) {
17509 + if (check_heap_stack_gap(vma, addr, len)) {
17510 /*
17511 * Remember the place where we stopped the search:
17512 */
17513 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17514 {
17515 struct vm_area_struct *vma;
17516 struct mm_struct *mm = current->mm;
17517 - unsigned long addr = addr0;
17518 + unsigned long base = mm->mmap_base, addr = addr0;
17519
17520 /* requested length too big for entire address space */
17521 if (len > TASK_SIZE)
17522 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17523 if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
17524 goto bottomup;
17525
17526 +#ifdef CONFIG_PAX_RANDMMAP
17527 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
17528 +#endif
17529 +
17530 /* requesting a specific address */
17531 if (addr) {
17532 addr = PAGE_ALIGN(addr);
17533 - vma = find_vma(mm, addr);
17534 - if (TASK_SIZE - len >= addr &&
17535 - (!vma || addr + len <= vma->vm_start))
17536 - return addr;
17537 + if (TASK_SIZE - len >= addr) {
17538 + vma = find_vma(mm, addr);
17539 + if (check_heap_stack_gap(vma, addr, len))
17540 + return addr;
17541 + }
17542 }
17543
17544 /* check if free_area_cache is useful for us */
17545 @@ -232,7 +240,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17546 ALIGN_TOPDOWN);
17547
17548 vma = find_vma(mm, tmp_addr);
17549 - if (!vma || tmp_addr + len <= vma->vm_start)
17550 + if (check_heap_stack_gap(vma, tmp_addr, len))
17551 /* remember the address as a hint for next time */
17552 return mm->free_area_cache = tmp_addr;
17553 }
17554 @@ -251,7 +259,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17555 * return with success:
17556 */
17557 vma = find_vma(mm, addr);
17558 - if (!vma || addr+len <= vma->vm_start)
17559 + if (check_heap_stack_gap(vma, addr, len))
17560 /* remember the address as a hint for next time */
17561 return mm->free_area_cache = addr;
17562
17563 @@ -260,8 +268,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
17564 mm->cached_hole_size = vma->vm_start - addr;
17565
17566 /* try just below the current vma->vm_start */
17567 - addr = vma->vm_start-len;
17568 - } while (len < vma->vm_start);
17569 + addr = skip_heap_stack_gap(vma, len);
17570 + } while (!IS_ERR_VALUE(addr));
17571
17572 bottomup:
17573 /*
17574 @@ -270,13 +278,21 @@ bottomup:
17575 * can happen with large stack limits and large mmap()
17576 * allocations.
17577 */
17578 + mm->mmap_base = TASK_UNMAPPED_BASE;
17579 +
17580 +#ifdef CONFIG_PAX_RANDMMAP
17581 + if (mm->pax_flags & MF_PAX_RANDMMAP)
17582 + mm->mmap_base += mm->delta_mmap;
17583 +#endif
17584 +
17585 + mm->free_area_cache = mm->mmap_base;
17586 mm->cached_hole_size = ~0UL;
17587 - mm->free_area_cache = TASK_UNMAPPED_BASE;
17588 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
17589 /*
17590 * Restore the topdown base:
17591 */
17592 - mm->free_area_cache = mm->mmap_base;
17593 + mm->mmap_base = base;
17594 + mm->free_area_cache = base;
17595 mm->cached_hole_size = ~0UL;
17596
17597 return addr;
17598 diff --git a/arch/x86/kernel/syscall_table_32.S b/arch/x86/kernel/syscall_table_32.S
17599 index 9a0e312..e6f66f2 100644
17600 --- a/arch/x86/kernel/syscall_table_32.S
17601 +++ b/arch/x86/kernel/syscall_table_32.S
17602 @@ -1,3 +1,4 @@
17603 +.section .rodata,"a",@progbits
17604 ENTRY(sys_call_table)
17605 .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
17606 .long sys_exit
17607 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
17608 index e2410e2..4fe3fbc 100644
17609 --- a/arch/x86/kernel/tboot.c
17610 +++ b/arch/x86/kernel/tboot.c
17611 @@ -219,7 +219,7 @@ static int tboot_setup_sleep(void)
17612
17613 void tboot_shutdown(u32 shutdown_type)
17614 {
17615 - void (*shutdown)(void);
17616 + void (* __noreturn shutdown)(void);
17617
17618 if (!tboot_enabled())
17619 return;
17620 @@ -241,7 +241,7 @@ void tboot_shutdown(u32 shutdown_type)
17621
17622 switch_to_tboot_pt();
17623
17624 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
17625 + shutdown = (void *)tboot->shutdown_entry;
17626 shutdown();
17627
17628 /* should not reach here */
17629 @@ -298,7 +298,7 @@ void tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
17630 tboot_shutdown(acpi_shutdown_map[sleep_state]);
17631 }
17632
17633 -static atomic_t ap_wfs_count;
17634 +static atomic_unchecked_t ap_wfs_count;
17635
17636 static int tboot_wait_for_aps(int num_aps)
17637 {
17638 @@ -322,9 +322,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
17639 {
17640 switch (action) {
17641 case CPU_DYING:
17642 - atomic_inc(&ap_wfs_count);
17643 + atomic_inc_unchecked(&ap_wfs_count);
17644 if (num_online_cpus() == 1)
17645 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
17646 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
17647 return NOTIFY_BAD;
17648 break;
17649 }
17650 @@ -343,7 +343,7 @@ static __init int tboot_late_init(void)
17651
17652 tboot_create_trampoline();
17653
17654 - atomic_set(&ap_wfs_count, 0);
17655 + atomic_set_unchecked(&ap_wfs_count, 0);
17656 register_hotcpu_notifier(&tboot_cpu_notifier);
17657 return 0;
17658 }
17659 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
17660 index dd5fbf4..b7f2232 100644
17661 --- a/arch/x86/kernel/time.c
17662 +++ b/arch/x86/kernel/time.c
17663 @@ -31,9 +31,9 @@ unsigned long profile_pc(struct pt_regs *regs)
17664 {
17665 unsigned long pc = instruction_pointer(regs);
17666
17667 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
17668 + if (!user_mode(regs) && in_lock_functions(pc)) {
17669 #ifdef CONFIG_FRAME_POINTER
17670 - return *(unsigned long *)(regs->bp + sizeof(long));
17671 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
17672 #else
17673 unsigned long *sp =
17674 (unsigned long *)kernel_stack_pointer(regs);
17675 @@ -42,11 +42,17 @@ unsigned long profile_pc(struct pt_regs *regs)
17676 * or above a saved flags. Eflags has bits 22-31 zero,
17677 * kernel addresses don't.
17678 */
17679 +
17680 +#ifdef CONFIG_PAX_KERNEXEC
17681 + return ktla_ktva(sp[0]);
17682 +#else
17683 if (sp[0] >> 22)
17684 return sp[0];
17685 if (sp[1] >> 22)
17686 return sp[1];
17687 #endif
17688 +
17689 +#endif
17690 }
17691 return pc;
17692 }
17693 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
17694 index 6bb7b85..dd853e1 100644
17695 --- a/arch/x86/kernel/tls.c
17696 +++ b/arch/x86/kernel/tls.c
17697 @@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
17698 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
17699 return -EINVAL;
17700
17701 +#ifdef CONFIG_PAX_SEGMEXEC
17702 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
17703 + return -EINVAL;
17704 +#endif
17705 +
17706 set_tls_desc(p, idx, &info, 1);
17707
17708 return 0;
17709 diff --git a/arch/x86/kernel/trampoline_32.S b/arch/x86/kernel/trampoline_32.S
17710 index 451c0a7..e57f551 100644
17711 --- a/arch/x86/kernel/trampoline_32.S
17712 +++ b/arch/x86/kernel/trampoline_32.S
17713 @@ -32,6 +32,12 @@
17714 #include <asm/segment.h>
17715 #include <asm/page_types.h>
17716
17717 +#ifdef CONFIG_PAX_KERNEXEC
17718 +#define ta(X) (X)
17719 +#else
17720 +#define ta(X) ((X) - __PAGE_OFFSET)
17721 +#endif
17722 +
17723 #ifdef CONFIG_SMP
17724
17725 .section ".x86_trampoline","a"
17726 @@ -62,7 +68,7 @@ r_base = .
17727 inc %ax # protected mode (PE) bit
17728 lmsw %ax # into protected mode
17729 # flush prefetch and jump to startup_32_smp in arch/i386/kernel/head.S
17730 - ljmpl $__BOOT_CS, $(startup_32_smp-__PAGE_OFFSET)
17731 + ljmpl $__BOOT_CS, $ta(startup_32_smp)
17732
17733 # These need to be in the same 64K segment as the above;
17734 # hence we don't use the boot_gdt_descr defined in head.S
17735 diff --git a/arch/x86/kernel/trampoline_64.S b/arch/x86/kernel/trampoline_64.S
17736 index 09ff517..df19fbff 100644
17737 --- a/arch/x86/kernel/trampoline_64.S
17738 +++ b/arch/x86/kernel/trampoline_64.S
17739 @@ -90,7 +90,7 @@ startup_32:
17740 movl $__KERNEL_DS, %eax # Initialize the %ds segment register
17741 movl %eax, %ds
17742
17743 - movl $X86_CR4_PAE, %eax
17744 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17745 movl %eax, %cr4 # Enable PAE mode
17746
17747 # Setup trampoline 4 level pagetables
17748 @@ -138,7 +138,7 @@ tidt:
17749 # so the kernel can live anywhere
17750 .balign 4
17751 tgdt:
17752 - .short tgdt_end - tgdt # gdt limit
17753 + .short tgdt_end - tgdt - 1 # gdt limit
17754 .long tgdt - r_base
17755 .short 0
17756 .quad 0x00cf9b000000ffff # __KERNEL32_CS
17757 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
17758 index a8e3eb8..c9dbd7d 100644
17759 --- a/arch/x86/kernel/traps.c
17760 +++ b/arch/x86/kernel/traps.c
17761 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
17762
17763 /* Do we ignore FPU interrupts ? */
17764 char ignore_fpu_irq;
17765 -
17766 -/*
17767 - * The IDT has to be page-aligned to simplify the Pentium
17768 - * F0 0F bug workaround.
17769 - */
17770 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
17771 #endif
17772
17773 DECLARE_BITMAP(used_vectors, NR_VECTORS);
17774 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
17775 }
17776
17777 static void __kprobes
17778 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17779 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
17780 long error_code, siginfo_t *info)
17781 {
17782 struct task_struct *tsk = current;
17783
17784 #ifdef CONFIG_X86_32
17785 - if (regs->flags & X86_VM_MASK) {
17786 + if (v8086_mode(regs)) {
17787 /*
17788 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
17789 * On nmi (interrupt 2), do_trap should not be called.
17790 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
17791 }
17792 #endif
17793
17794 - if (!user_mode(regs))
17795 + if (!user_mode_novm(regs))
17796 goto kernel_trap;
17797
17798 #ifdef CONFIG_X86_32
17799 @@ -148,7 +142,7 @@ trap_signal:
17800 printk_ratelimit()) {
17801 printk(KERN_INFO
17802 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
17803 - tsk->comm, tsk->pid, str,
17804 + tsk->comm, task_pid_nr(tsk), str,
17805 regs->ip, regs->sp, error_code);
17806 print_vma_addr(" in ", regs->ip);
17807 printk("\n");
17808 @@ -165,8 +159,20 @@ kernel_trap:
17809 if (!fixup_exception(regs)) {
17810 tsk->thread.error_code = error_code;
17811 tsk->thread.trap_no = trapnr;
17812 +
17813 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17814 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
17815 + str = "PAX: suspicious stack segment fault";
17816 +#endif
17817 +
17818 die(str, regs, error_code);
17819 }
17820 +
17821 +#ifdef CONFIG_PAX_REFCOUNT
17822 + if (trapnr == 4)
17823 + pax_report_refcount_overflow(regs);
17824 +#endif
17825 +
17826 return;
17827
17828 #ifdef CONFIG_X86_32
17829 @@ -255,14 +261,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
17830 conditional_sti(regs);
17831
17832 #ifdef CONFIG_X86_32
17833 - if (regs->flags & X86_VM_MASK)
17834 + if (v8086_mode(regs))
17835 goto gp_in_vm86;
17836 #endif
17837
17838 tsk = current;
17839 - if (!user_mode(regs))
17840 + if (!user_mode_novm(regs))
17841 goto gp_in_kernel;
17842
17843 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17844 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
17845 + struct mm_struct *mm = tsk->mm;
17846 + unsigned long limit;
17847 +
17848 + down_write(&mm->mmap_sem);
17849 + limit = mm->context.user_cs_limit;
17850 + if (limit < TASK_SIZE) {
17851 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
17852 + up_write(&mm->mmap_sem);
17853 + return;
17854 + }
17855 + up_write(&mm->mmap_sem);
17856 + }
17857 +#endif
17858 +
17859 tsk->thread.error_code = error_code;
17860 tsk->thread.trap_no = 13;
17861
17862 @@ -295,6 +317,13 @@ gp_in_kernel:
17863 if (notify_die(DIE_GPF, "general protection fault", regs,
17864 error_code, 13, SIGSEGV) == NOTIFY_STOP)
17865 return;
17866 +
17867 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
17868 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
17869 + die("PAX: suspicious general protection fault", regs, error_code);
17870 + else
17871 +#endif
17872 +
17873 die("general protection fault", regs, error_code);
17874 }
17875
17876 @@ -414,7 +443,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17877 /* It's safe to allow irq's after DR6 has been saved */
17878 preempt_conditional_sti(regs);
17879
17880 - if (regs->flags & X86_VM_MASK) {
17881 + if (v8086_mode(regs)) {
17882 handle_vm86_trap((struct kernel_vm86_regs *) regs,
17883 error_code, 1);
17884 preempt_conditional_cli(regs);
17885 @@ -428,7 +457,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
17886 * We already checked v86 mode above, so we can check for kernel mode
17887 * by just checking the CPL of CS.
17888 */
17889 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
17890 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
17891 tsk->thread.debugreg6 &= ~DR_STEP;
17892 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
17893 regs->flags &= ~X86_EFLAGS_TF;
17894 @@ -457,7 +486,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
17895 return;
17896 conditional_sti(regs);
17897
17898 - if (!user_mode_vm(regs))
17899 + if (!user_mode(regs))
17900 {
17901 if (!fixup_exception(regs)) {
17902 task->thread.error_code = error_code;
17903 @@ -568,7 +597,7 @@ asmlinkage void __attribute__((weak)) smp_threshold_interrupt(void)
17904 void __math_state_restore(void)
17905 {
17906 struct thread_info *thread = current_thread_info();
17907 - struct task_struct *tsk = thread->task;
17908 + struct task_struct *tsk = current;
17909
17910 /*
17911 * Paranoid restore. send a SIGSEGV if we fail to restore the state.
17912 @@ -595,8 +624,7 @@ void __math_state_restore(void)
17913 */
17914 asmlinkage void math_state_restore(void)
17915 {
17916 - struct thread_info *thread = current_thread_info();
17917 - struct task_struct *tsk = thread->task;
17918 + struct task_struct *tsk = current;
17919
17920 if (!tsk_used_math(tsk)) {
17921 local_irq_enable();
17922 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
17923 index b9242ba..50c5edd 100644
17924 --- a/arch/x86/kernel/verify_cpu.S
17925 +++ b/arch/x86/kernel/verify_cpu.S
17926 @@ -20,6 +20,7 @@
17927 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
17928 * arch/x86/kernel/trampoline_64.S: secondary processor verification
17929 * arch/x86/kernel/head_32.S: processor startup
17930 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
17931 *
17932 * verify_cpu, returns the status of longmode and SSE in register %eax.
17933 * 0: Success 1: Failure
17934 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
17935 index 863f875..4307295 100644
17936 --- a/arch/x86/kernel/vm86_32.c
17937 +++ b/arch/x86/kernel/vm86_32.c
17938 @@ -41,6 +41,7 @@
17939 #include <linux/ptrace.h>
17940 #include <linux/audit.h>
17941 #include <linux/stddef.h>
17942 +#include <linux/grsecurity.h>
17943
17944 #include <asm/uaccess.h>
17945 #include <asm/io.h>
17946 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
17947 do_exit(SIGSEGV);
17948 }
17949
17950 - tss = &per_cpu(init_tss, get_cpu());
17951 + tss = init_tss + get_cpu();
17952 current->thread.sp0 = current->thread.saved_sp0;
17953 current->thread.sysenter_cs = __KERNEL_CS;
17954 load_sp0(tss, &current->thread);
17955 @@ -208,6 +209,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
17956 struct task_struct *tsk;
17957 int tmp, ret = -EPERM;
17958
17959 +#ifdef CONFIG_GRKERNSEC_VM86
17960 + if (!capable(CAP_SYS_RAWIO)) {
17961 + gr_handle_vm86();
17962 + goto out;
17963 + }
17964 +#endif
17965 +
17966 tsk = current;
17967 if (tsk->thread.saved_sp0)
17968 goto out;
17969 @@ -238,6 +246,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
17970 int tmp, ret;
17971 struct vm86plus_struct __user *v86;
17972
17973 +#ifdef CONFIG_GRKERNSEC_VM86
17974 + if (!capable(CAP_SYS_RAWIO)) {
17975 + gr_handle_vm86();
17976 + ret = -EPERM;
17977 + goto out;
17978 + }
17979 +#endif
17980 +
17981 tsk = current;
17982 switch (cmd) {
17983 case VM86_REQUEST_IRQ:
17984 @@ -324,7 +340,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
17985 tsk->thread.saved_fs = info->regs32->fs;
17986 tsk->thread.saved_gs = get_user_gs(info->regs32);
17987
17988 - tss = &per_cpu(init_tss, get_cpu());
17989 + tss = init_tss + get_cpu();
17990 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
17991 if (cpu_has_sep)
17992 tsk->thread.sysenter_cs = 0;
17993 @@ -529,7 +545,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
17994 goto cannot_handle;
17995 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
17996 goto cannot_handle;
17997 - intr_ptr = (unsigned long __user *) (i << 2);
17998 + intr_ptr = (__force unsigned long __user *) (i << 2);
17999 if (get_user(segoffs, intr_ptr))
18000 goto cannot_handle;
18001 if ((segoffs >> 16) == BIOSSEG)
18002 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
18003 index 0f703f1..9e15f64 100644
18004 --- a/arch/x86/kernel/vmlinux.lds.S
18005 +++ b/arch/x86/kernel/vmlinux.lds.S
18006 @@ -26,6 +26,13 @@
18007 #include <asm/page_types.h>
18008 #include <asm/cache.h>
18009 #include <asm/boot.h>
18010 +#include <asm/segment.h>
18011 +
18012 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18013 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
18014 +#else
18015 +#define __KERNEL_TEXT_OFFSET 0
18016 +#endif
18017
18018 #undef i386 /* in case the preprocessor is a 32bit one */
18019
18020 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
18021
18022 PHDRS {
18023 text PT_LOAD FLAGS(5); /* R_E */
18024 +#ifdef CONFIG_X86_32
18025 + module PT_LOAD FLAGS(5); /* R_E */
18026 +#endif
18027 +#ifdef CONFIG_XEN
18028 + rodata PT_LOAD FLAGS(5); /* R_E */
18029 +#else
18030 + rodata PT_LOAD FLAGS(4); /* R__ */
18031 +#endif
18032 data PT_LOAD FLAGS(6); /* RW_ */
18033 -#ifdef CONFIG_X86_64
18034 + init.begin PT_LOAD FLAGS(6); /* RW_ */
18035 #ifdef CONFIG_SMP
18036 percpu PT_LOAD FLAGS(6); /* RW_ */
18037 #endif
18038 + text.init PT_LOAD FLAGS(5); /* R_E */
18039 + text.exit PT_LOAD FLAGS(5); /* R_E */
18040 init PT_LOAD FLAGS(7); /* RWE */
18041 -#endif
18042 note PT_NOTE FLAGS(0); /* ___ */
18043 }
18044
18045 SECTIONS
18046 {
18047 #ifdef CONFIG_X86_32
18048 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
18049 - phys_startup_32 = startup_32 - LOAD_OFFSET;
18050 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
18051 #else
18052 - . = __START_KERNEL;
18053 - phys_startup_64 = startup_64 - LOAD_OFFSET;
18054 + . = __START_KERNEL;
18055 #endif
18056
18057 /* Text and read-only data */
18058 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
18059 - _text = .;
18060 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18061 /* bootstrapping code */
18062 +#ifdef CONFIG_X86_32
18063 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18064 +#else
18065 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18066 +#endif
18067 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
18068 + _text = .;
18069 HEAD_TEXT
18070 #ifdef CONFIG_X86_32
18071 . = ALIGN(PAGE_SIZE);
18072 @@ -108,13 +128,47 @@ SECTIONS
18073 IRQENTRY_TEXT
18074 *(.fixup)
18075 *(.gnu.warning)
18076 - /* End of text section */
18077 - _etext = .;
18078 } :text = 0x9090
18079
18080 - NOTES :text :note
18081 + . += __KERNEL_TEXT_OFFSET;
18082
18083 - EXCEPTION_TABLE(16) :text = 0x9090
18084 +#ifdef CONFIG_X86_32
18085 + . = ALIGN(PAGE_SIZE);
18086 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
18087 +
18088 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
18089 + MODULES_EXEC_VADDR = .;
18090 + BYTE(0)
18091 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
18092 + . = ALIGN(HPAGE_SIZE);
18093 + MODULES_EXEC_END = . - 1;
18094 +#endif
18095 +
18096 + } :module
18097 +#endif
18098 +
18099 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
18100 + /* End of text section */
18101 + _etext = . - __KERNEL_TEXT_OFFSET;
18102 + }
18103 +
18104 +#ifdef CONFIG_X86_32
18105 + . = ALIGN(PAGE_SIZE);
18106 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
18107 + *(.idt)
18108 + . = ALIGN(PAGE_SIZE);
18109 + *(.empty_zero_page)
18110 + *(.initial_pg_fixmap)
18111 + *(.initial_pg_pmd)
18112 + *(.initial_page_table)
18113 + *(.swapper_pg_dir)
18114 + } :rodata
18115 +#endif
18116 +
18117 + . = ALIGN(PAGE_SIZE);
18118 + NOTES :rodata :note
18119 +
18120 + EXCEPTION_TABLE(16) :rodata
18121
18122 #if defined(CONFIG_DEBUG_RODATA)
18123 /* .text should occupy whole number of pages */
18124 @@ -126,16 +180,20 @@ SECTIONS
18125
18126 /* Data */
18127 .data : AT(ADDR(.data) - LOAD_OFFSET) {
18128 +
18129 +#ifdef CONFIG_PAX_KERNEXEC
18130 + . = ALIGN(HPAGE_SIZE);
18131 +#else
18132 + . = ALIGN(PAGE_SIZE);
18133 +#endif
18134 +
18135 /* Start of data section */
18136 _sdata = .;
18137
18138 /* init_task */
18139 INIT_TASK_DATA(THREAD_SIZE)
18140
18141 -#ifdef CONFIG_X86_32
18142 - /* 32 bit has nosave before _edata */
18143 NOSAVE_DATA
18144 -#endif
18145
18146 PAGE_ALIGNED_DATA(PAGE_SIZE)
18147
18148 @@ -176,12 +234,19 @@ SECTIONS
18149 #endif /* CONFIG_X86_64 */
18150
18151 /* Init code and data - will be freed after init */
18152 - . = ALIGN(PAGE_SIZE);
18153 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
18154 + BYTE(0)
18155 +
18156 +#ifdef CONFIG_PAX_KERNEXEC
18157 + . = ALIGN(HPAGE_SIZE);
18158 +#else
18159 + . = ALIGN(PAGE_SIZE);
18160 +#endif
18161 +
18162 __init_begin = .; /* paired with __init_end */
18163 - }
18164 + } :init.begin
18165
18166 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
18167 +#ifdef CONFIG_SMP
18168 /*
18169 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
18170 * output PHDR, so the next output section - .init.text - should
18171 @@ -190,12 +255,27 @@ SECTIONS
18172 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
18173 #endif
18174
18175 - INIT_TEXT_SECTION(PAGE_SIZE)
18176 -#ifdef CONFIG_X86_64
18177 - :init
18178 -#endif
18179 + . = ALIGN(PAGE_SIZE);
18180 + init_begin = .;
18181 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
18182 + VMLINUX_SYMBOL(_sinittext) = .;
18183 + INIT_TEXT
18184 + VMLINUX_SYMBOL(_einittext) = .;
18185 + . = ALIGN(PAGE_SIZE);
18186 + } :text.init
18187
18188 - INIT_DATA_SECTION(16)
18189 + /*
18190 + * .exit.text is discard at runtime, not link time, to deal with
18191 + * references from .altinstructions and .eh_frame
18192 + */
18193 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
18194 + EXIT_TEXT
18195 + . = ALIGN(16);
18196 + } :text.exit
18197 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
18198 +
18199 + . = ALIGN(PAGE_SIZE);
18200 + INIT_DATA_SECTION(16) :init
18201
18202 /*
18203 * Code and data for a variety of lowlevel trampolines, to be
18204 @@ -269,19 +349,12 @@ SECTIONS
18205 }
18206
18207 . = ALIGN(8);
18208 - /*
18209 - * .exit.text is discard at runtime, not link time, to deal with
18210 - * references from .altinstructions and .eh_frame
18211 - */
18212 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
18213 - EXIT_TEXT
18214 - }
18215
18216 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
18217 EXIT_DATA
18218 }
18219
18220 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
18221 +#ifndef CONFIG_SMP
18222 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
18223 #endif
18224
18225 @@ -300,16 +373,10 @@ SECTIONS
18226 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
18227 __smp_locks = .;
18228 *(.smp_locks)
18229 - . = ALIGN(PAGE_SIZE);
18230 __smp_locks_end = .;
18231 + . = ALIGN(PAGE_SIZE);
18232 }
18233
18234 -#ifdef CONFIG_X86_64
18235 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
18236 - NOSAVE_DATA
18237 - }
18238 -#endif
18239 -
18240 /* BSS */
18241 . = ALIGN(PAGE_SIZE);
18242 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
18243 @@ -325,6 +392,7 @@ SECTIONS
18244 __brk_base = .;
18245 . += 64 * 1024; /* 64k alignment slop space */
18246 *(.brk_reservation) /* areas brk users have reserved */
18247 + . = ALIGN(HPAGE_SIZE);
18248 __brk_limit = .;
18249 }
18250
18251 @@ -351,13 +419,12 @@ SECTIONS
18252 * for the boot processor.
18253 */
18254 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
18255 -INIT_PER_CPU(gdt_page);
18256 INIT_PER_CPU(irq_stack_union);
18257
18258 /*
18259 * Build-time check on the image size:
18260 */
18261 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
18262 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
18263 "kernel image bigger than KERNEL_IMAGE_SIZE");
18264
18265 #ifdef CONFIG_SMP
18266 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
18267 index e4d4a22..47ee71f 100644
18268 --- a/arch/x86/kernel/vsyscall_64.c
18269 +++ b/arch/x86/kernel/vsyscall_64.c
18270 @@ -57,15 +57,13 @@ DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data) =
18271 .lock = __SEQLOCK_UNLOCKED(__vsyscall_gtod_data.lock),
18272 };
18273
18274 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = NATIVE;
18275 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
18276
18277 static int __init vsyscall_setup(char *str)
18278 {
18279 if (str) {
18280 if (!strcmp("emulate", str))
18281 vsyscall_mode = EMULATE;
18282 - else if (!strcmp("native", str))
18283 - vsyscall_mode = NATIVE;
18284 else if (!strcmp("none", str))
18285 vsyscall_mode = NONE;
18286 else
18287 @@ -178,7 +176,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18288
18289 tsk = current;
18290 if (seccomp_mode(&tsk->seccomp))
18291 - do_exit(SIGKILL);
18292 + do_group_exit(SIGKILL);
18293
18294 switch (vsyscall_nr) {
18295 case 0:
18296 @@ -220,8 +218,7 @@ bool emulate_vsyscall(struct pt_regs *regs, unsigned long address)
18297 return true;
18298
18299 sigsegv:
18300 - force_sig(SIGSEGV, current);
18301 - return true;
18302 + do_group_exit(SIGKILL);
18303 }
18304
18305 /*
18306 @@ -274,10 +271,7 @@ void __init map_vsyscall(void)
18307 extern char __vvar_page;
18308 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
18309
18310 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
18311 - vsyscall_mode == NATIVE
18312 - ? PAGE_KERNEL_VSYSCALL
18313 - : PAGE_KERNEL_VVAR);
18314 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
18315 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
18316 (unsigned long)VSYSCALL_START);
18317
18318 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
18319 index 9796c2f..f686fbf 100644
18320 --- a/arch/x86/kernel/x8664_ksyms_64.c
18321 +++ b/arch/x86/kernel/x8664_ksyms_64.c
18322 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
18323 EXPORT_SYMBOL(copy_user_generic_string);
18324 EXPORT_SYMBOL(copy_user_generic_unrolled);
18325 EXPORT_SYMBOL(__copy_user_nocache);
18326 -EXPORT_SYMBOL(_copy_from_user);
18327 -EXPORT_SYMBOL(_copy_to_user);
18328
18329 EXPORT_SYMBOL(copy_page);
18330 EXPORT_SYMBOL(clear_page);
18331 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
18332 index a391134..d0b63b6e 100644
18333 --- a/arch/x86/kernel/xsave.c
18334 +++ b/arch/x86/kernel/xsave.c
18335 @@ -130,7 +130,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
18336 fx_sw_user->xstate_size > fx_sw_user->extended_size)
18337 return -EINVAL;
18338
18339 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
18340 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
18341 fx_sw_user->extended_size -
18342 FP_XSTATE_MAGIC2_SIZE));
18343 if (err)
18344 @@ -267,7 +267,7 @@ fx_only:
18345 * the other extended state.
18346 */
18347 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
18348 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
18349 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
18350 }
18351
18352 /*
18353 @@ -299,7 +299,7 @@ int restore_i387_xstate(void __user *buf)
18354 if (use_xsave())
18355 err = restore_user_xstate(buf);
18356 else
18357 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
18358 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
18359 buf);
18360 if (unlikely(err)) {
18361 /*
18362 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
18363 index f1e3be1..588efc8 100644
18364 --- a/arch/x86/kvm/emulate.c
18365 +++ b/arch/x86/kvm/emulate.c
18366 @@ -249,6 +249,7 @@ struct gprefix {
18367
18368 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
18369 do { \
18370 + unsigned long _tmp; \
18371 __asm__ __volatile__ ( \
18372 _PRE_EFLAGS("0", "4", "2") \
18373 _op _suffix " %"_x"3,%1; " \
18374 @@ -263,8 +264,6 @@ struct gprefix {
18375 /* Raw emulation: instruction has two explicit operands. */
18376 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
18377 do { \
18378 - unsigned long _tmp; \
18379 - \
18380 switch ((ctxt)->dst.bytes) { \
18381 case 2: \
18382 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
18383 @@ -280,7 +279,6 @@ struct gprefix {
18384
18385 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
18386 do { \
18387 - unsigned long _tmp; \
18388 switch ((ctxt)->dst.bytes) { \
18389 case 1: \
18390 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
18391 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
18392 index 54abb40..a192606 100644
18393 --- a/arch/x86/kvm/lapic.c
18394 +++ b/arch/x86/kvm/lapic.c
18395 @@ -53,7 +53,7 @@
18396 #define APIC_BUS_CYCLE_NS 1
18397
18398 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
18399 -#define apic_debug(fmt, arg...)
18400 +#define apic_debug(fmt, arg...) do {} while (0)
18401
18402 #define APIC_LVT_NUM 6
18403 /* 14 is the version for Xeon and Pentium 8.4.8*/
18404 diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
18405 index f1b36cf..af8a124 100644
18406 --- a/arch/x86/kvm/mmu.c
18407 +++ b/arch/x86/kvm/mmu.c
18408 @@ -3555,7 +3555,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18409
18410 pgprintk("%s: gpa %llx bytes %d\n", __func__, gpa, bytes);
18411
18412 - invlpg_counter = atomic_read(&vcpu->kvm->arch.invlpg_counter);
18413 + invlpg_counter = atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter);
18414
18415 /*
18416 * Assume that the pte write on a page table of the same type
18417 @@ -3587,7 +3587,7 @@ void kvm_mmu_pte_write(struct kvm_vcpu *vcpu, gpa_t gpa,
18418 }
18419
18420 spin_lock(&vcpu->kvm->mmu_lock);
18421 - if (atomic_read(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18422 + if (atomic_read_unchecked(&vcpu->kvm->arch.invlpg_counter) != invlpg_counter)
18423 gentry = 0;
18424 kvm_mmu_free_some_pages(vcpu);
18425 ++vcpu->kvm->stat.mmu_pte_write;
18426 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
18427 index 9299410..ade2f9b 100644
18428 --- a/arch/x86/kvm/paging_tmpl.h
18429 +++ b/arch/x86/kvm/paging_tmpl.h
18430 @@ -197,7 +197,7 @@ retry_walk:
18431 if (unlikely(kvm_is_error_hva(host_addr)))
18432 goto error;
18433
18434 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
18435 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
18436 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
18437 goto error;
18438
18439 @@ -705,7 +705,7 @@ static void FNAME(invlpg)(struct kvm_vcpu *vcpu, gva_t gva)
18440 if (need_flush)
18441 kvm_flush_remote_tlbs(vcpu->kvm);
18442
18443 - atomic_inc(&vcpu->kvm->arch.invlpg_counter);
18444 + atomic_inc_unchecked(&vcpu->kvm->arch.invlpg_counter);
18445
18446 spin_unlock(&vcpu->kvm->mmu_lock);
18447
18448 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
18449 index e32243e..a6e6172 100644
18450 --- a/arch/x86/kvm/svm.c
18451 +++ b/arch/x86/kvm/svm.c
18452 @@ -3400,7 +3400,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
18453 int cpu = raw_smp_processor_id();
18454
18455 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
18456 +
18457 + pax_open_kernel();
18458 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
18459 + pax_close_kernel();
18460 +
18461 load_TR_desc();
18462 }
18463
18464 @@ -3778,6 +3782,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
18465 #endif
18466 #endif
18467
18468 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18469 + __set_fs(current_thread_info()->addr_limit);
18470 +#endif
18471 +
18472 reload_tss(vcpu);
18473
18474 local_irq_disable();
18475 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
18476 index 579a0b5..ed7bbf9 100644
18477 --- a/arch/x86/kvm/vmx.c
18478 +++ b/arch/x86/kvm/vmx.c
18479 @@ -1305,7 +1305,11 @@ static void reload_tss(void)
18480 struct desc_struct *descs;
18481
18482 descs = (void *)gdt->address;
18483 +
18484 + pax_open_kernel();
18485 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
18486 + pax_close_kernel();
18487 +
18488 load_TR_desc();
18489 }
18490
18491 @@ -2633,8 +2637,11 @@ static __init int hardware_setup(void)
18492 if (!cpu_has_vmx_flexpriority())
18493 flexpriority_enabled = 0;
18494
18495 - if (!cpu_has_vmx_tpr_shadow())
18496 - kvm_x86_ops->update_cr8_intercept = NULL;
18497 + if (!cpu_has_vmx_tpr_shadow()) {
18498 + pax_open_kernel();
18499 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
18500 + pax_close_kernel();
18501 + }
18502
18503 if (enable_ept && !cpu_has_vmx_ept_2m_page())
18504 kvm_disable_largepages();
18505 @@ -3648,7 +3655,7 @@ static void vmx_set_constant_host_state(void)
18506 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
18507
18508 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
18509 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
18510 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
18511
18512 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
18513 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
18514 @@ -6169,6 +6176,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18515 "jmp .Lkvm_vmx_return \n\t"
18516 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
18517 ".Lkvm_vmx_return: "
18518 +
18519 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18520 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
18521 + ".Lkvm_vmx_return2: "
18522 +#endif
18523 +
18524 /* Save guest registers, load host registers, keep flags */
18525 "mov %0, %c[wordsize](%%"R"sp) \n\t"
18526 "pop %0 \n\t"
18527 @@ -6217,6 +6230,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18528 #endif
18529 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
18530 [wordsize]"i"(sizeof(ulong))
18531 +
18532 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18533 + ,[cs]"i"(__KERNEL_CS)
18534 +#endif
18535 +
18536 : "cc", "memory"
18537 , R"ax", R"bx", R"di", R"si"
18538 #ifdef CONFIG_X86_64
18539 @@ -6245,7 +6263,16 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
18540 }
18541 }
18542
18543 - asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
18544 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r"(__KERNEL_DS));
18545 +
18546 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18547 + loadsegment(fs, __KERNEL_PERCPU);
18548 +#endif
18549 +
18550 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18551 + __set_fs(current_thread_info()->addr_limit);
18552 +#endif
18553 +
18554 vmx->loaded_vmcs->launched = 1;
18555
18556 vmx->exit_reason = vmcs_read32(VM_EXIT_REASON);
18557 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
18558 index 4c938da..4ddef65 100644
18559 --- a/arch/x86/kvm/x86.c
18560 +++ b/arch/x86/kvm/x86.c
18561 @@ -1345,8 +1345,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
18562 {
18563 struct kvm *kvm = vcpu->kvm;
18564 int lm = is_long_mode(vcpu);
18565 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18566 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18567 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
18568 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
18569 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
18570 : kvm->arch.xen_hvm_config.blob_size_32;
18571 u32 page_num = data & ~PAGE_MASK;
18572 @@ -2165,6 +2165,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
18573 if (n < msr_list.nmsrs)
18574 goto out;
18575 r = -EFAULT;
18576 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
18577 + goto out;
18578 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
18579 num_msrs_to_save * sizeof(u32)))
18580 goto out;
18581 @@ -2340,15 +2342,20 @@ static int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
18582 struct kvm_cpuid2 *cpuid,
18583 struct kvm_cpuid_entry2 __user *entries)
18584 {
18585 - int r;
18586 + int r, i;
18587
18588 r = -E2BIG;
18589 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
18590 goto out;
18591 r = -EFAULT;
18592 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
18593 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18594 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
18595 goto out;
18596 + for (i = 0; i < cpuid->nent; ++i) {
18597 + struct kvm_cpuid_entry2 cpuid_entry;
18598 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
18599 + goto out;
18600 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
18601 + }
18602 vcpu->arch.cpuid_nent = cpuid->nent;
18603 kvm_apic_set_version(vcpu);
18604 kvm_x86_ops->cpuid_update(vcpu);
18605 @@ -2363,15 +2370,19 @@ static int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
18606 struct kvm_cpuid2 *cpuid,
18607 struct kvm_cpuid_entry2 __user *entries)
18608 {
18609 - int r;
18610 + int r, i;
18611
18612 r = -E2BIG;
18613 if (cpuid->nent < vcpu->arch.cpuid_nent)
18614 goto out;
18615 r = -EFAULT;
18616 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
18617 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18618 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
18619 goto out;
18620 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
18621 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
18622 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
18623 + goto out;
18624 + }
18625 return 0;
18626
18627 out:
18628 @@ -2746,7 +2757,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
18629 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
18630 struct kvm_interrupt *irq)
18631 {
18632 - if (irq->irq < 0 || irq->irq >= 256)
18633 + if (irq->irq >= 256)
18634 return -EINVAL;
18635 if (irqchip_in_kernel(vcpu->kvm))
18636 return -ENXIO;
18637 @@ -5162,7 +5173,7 @@ static void kvm_set_mmio_spte_mask(void)
18638 kvm_mmu_set_mmio_spte_mask(mask);
18639 }
18640
18641 -int kvm_arch_init(void *opaque)
18642 +int kvm_arch_init(const void *opaque)
18643 {
18644 int r;
18645 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
18646 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
18647 index cf4603b..7cdde38 100644
18648 --- a/arch/x86/lguest/boot.c
18649 +++ b/arch/x86/lguest/boot.c
18650 @@ -1195,9 +1195,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
18651 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
18652 * Launcher to reboot us.
18653 */
18654 -static void lguest_restart(char *reason)
18655 +static __noreturn void lguest_restart(char *reason)
18656 {
18657 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
18658 + BUG();
18659 }
18660
18661 /*G:050
18662 diff --git a/arch/x86/lib/atomic64_32.c b/arch/x86/lib/atomic64_32.c
18663 index 042f682..c92afb6 100644
18664 --- a/arch/x86/lib/atomic64_32.c
18665 +++ b/arch/x86/lib/atomic64_32.c
18666 @@ -8,18 +8,30 @@
18667
18668 long long atomic64_read_cx8(long long, const atomic64_t *v);
18669 EXPORT_SYMBOL(atomic64_read_cx8);
18670 +long long atomic64_read_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18671 +EXPORT_SYMBOL(atomic64_read_unchecked_cx8);
18672 long long atomic64_set_cx8(long long, const atomic64_t *v);
18673 EXPORT_SYMBOL(atomic64_set_cx8);
18674 +long long atomic64_set_unchecked_cx8(long long, const atomic64_unchecked_t *v);
18675 +EXPORT_SYMBOL(atomic64_set_unchecked_cx8);
18676 long long atomic64_xchg_cx8(long long, unsigned high);
18677 EXPORT_SYMBOL(atomic64_xchg_cx8);
18678 long long atomic64_add_return_cx8(long long a, atomic64_t *v);
18679 EXPORT_SYMBOL(atomic64_add_return_cx8);
18680 +long long atomic64_add_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18681 +EXPORT_SYMBOL(atomic64_add_return_unchecked_cx8);
18682 long long atomic64_sub_return_cx8(long long a, atomic64_t *v);
18683 EXPORT_SYMBOL(atomic64_sub_return_cx8);
18684 +long long atomic64_sub_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18685 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_cx8);
18686 long long atomic64_inc_return_cx8(long long a, atomic64_t *v);
18687 EXPORT_SYMBOL(atomic64_inc_return_cx8);
18688 +long long atomic64_inc_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18689 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_cx8);
18690 long long atomic64_dec_return_cx8(long long a, atomic64_t *v);
18691 EXPORT_SYMBOL(atomic64_dec_return_cx8);
18692 +long long atomic64_dec_return_unchecked_cx8(long long a, atomic64_unchecked_t *v);
18693 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_cx8);
18694 long long atomic64_dec_if_positive_cx8(atomic64_t *v);
18695 EXPORT_SYMBOL(atomic64_dec_if_positive_cx8);
18696 int atomic64_inc_not_zero_cx8(atomic64_t *v);
18697 @@ -30,26 +42,46 @@ EXPORT_SYMBOL(atomic64_add_unless_cx8);
18698 #ifndef CONFIG_X86_CMPXCHG64
18699 long long atomic64_read_386(long long, const atomic64_t *v);
18700 EXPORT_SYMBOL(atomic64_read_386);
18701 +long long atomic64_read_unchecked_386(long long, const atomic64_unchecked_t *v);
18702 +EXPORT_SYMBOL(atomic64_read_unchecked_386);
18703 long long atomic64_set_386(long long, const atomic64_t *v);
18704 EXPORT_SYMBOL(atomic64_set_386);
18705 +long long atomic64_set_unchecked_386(long long, const atomic64_unchecked_t *v);
18706 +EXPORT_SYMBOL(atomic64_set_unchecked_386);
18707 long long atomic64_xchg_386(long long, unsigned high);
18708 EXPORT_SYMBOL(atomic64_xchg_386);
18709 long long atomic64_add_return_386(long long a, atomic64_t *v);
18710 EXPORT_SYMBOL(atomic64_add_return_386);
18711 +long long atomic64_add_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18712 +EXPORT_SYMBOL(atomic64_add_return_unchecked_386);
18713 long long atomic64_sub_return_386(long long a, atomic64_t *v);
18714 EXPORT_SYMBOL(atomic64_sub_return_386);
18715 +long long atomic64_sub_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18716 +EXPORT_SYMBOL(atomic64_sub_return_unchecked_386);
18717 long long atomic64_inc_return_386(long long a, atomic64_t *v);
18718 EXPORT_SYMBOL(atomic64_inc_return_386);
18719 +long long atomic64_inc_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18720 +EXPORT_SYMBOL(atomic64_inc_return_unchecked_386);
18721 long long atomic64_dec_return_386(long long a, atomic64_t *v);
18722 EXPORT_SYMBOL(atomic64_dec_return_386);
18723 +long long atomic64_dec_return_unchecked_386(long long a, atomic64_unchecked_t *v);
18724 +EXPORT_SYMBOL(atomic64_dec_return_unchecked_386);
18725 long long atomic64_add_386(long long a, atomic64_t *v);
18726 EXPORT_SYMBOL(atomic64_add_386);
18727 +long long atomic64_add_unchecked_386(long long a, atomic64_unchecked_t *v);
18728 +EXPORT_SYMBOL(atomic64_add_unchecked_386);
18729 long long atomic64_sub_386(long long a, atomic64_t *v);
18730 EXPORT_SYMBOL(atomic64_sub_386);
18731 +long long atomic64_sub_unchecked_386(long long a, atomic64_unchecked_t *v);
18732 +EXPORT_SYMBOL(atomic64_sub_unchecked_386);
18733 long long atomic64_inc_386(long long a, atomic64_t *v);
18734 EXPORT_SYMBOL(atomic64_inc_386);
18735 +long long atomic64_inc_unchecked_386(long long a, atomic64_unchecked_t *v);
18736 +EXPORT_SYMBOL(atomic64_inc_unchecked_386);
18737 long long atomic64_dec_386(long long a, atomic64_t *v);
18738 EXPORT_SYMBOL(atomic64_dec_386);
18739 +long long atomic64_dec_unchecked_386(long long a, atomic64_unchecked_t *v);
18740 +EXPORT_SYMBOL(atomic64_dec_unchecked_386);
18741 long long atomic64_dec_if_positive_386(atomic64_t *v);
18742 EXPORT_SYMBOL(atomic64_dec_if_positive_386);
18743 int atomic64_inc_not_zero_386(atomic64_t *v);
18744 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
18745 index e8e7e0d..56fd1b0 100644
18746 --- a/arch/x86/lib/atomic64_386_32.S
18747 +++ b/arch/x86/lib/atomic64_386_32.S
18748 @@ -48,6 +48,10 @@ BEGIN(read)
18749 movl (v), %eax
18750 movl 4(v), %edx
18751 RET_ENDP
18752 +BEGIN(read_unchecked)
18753 + movl (v), %eax
18754 + movl 4(v), %edx
18755 +RET_ENDP
18756 #undef v
18757
18758 #define v %esi
18759 @@ -55,6 +59,10 @@ BEGIN(set)
18760 movl %ebx, (v)
18761 movl %ecx, 4(v)
18762 RET_ENDP
18763 +BEGIN(set_unchecked)
18764 + movl %ebx, (v)
18765 + movl %ecx, 4(v)
18766 +RET_ENDP
18767 #undef v
18768
18769 #define v %esi
18770 @@ -70,6 +78,20 @@ RET_ENDP
18771 BEGIN(add)
18772 addl %eax, (v)
18773 adcl %edx, 4(v)
18774 +
18775 +#ifdef CONFIG_PAX_REFCOUNT
18776 + jno 0f
18777 + subl %eax, (v)
18778 + sbbl %edx, 4(v)
18779 + int $4
18780 +0:
18781 + _ASM_EXTABLE(0b, 0b)
18782 +#endif
18783 +
18784 +RET_ENDP
18785 +BEGIN(add_unchecked)
18786 + addl %eax, (v)
18787 + adcl %edx, 4(v)
18788 RET_ENDP
18789 #undef v
18790
18791 @@ -77,6 +99,24 @@ RET_ENDP
18792 BEGIN(add_return)
18793 addl (v), %eax
18794 adcl 4(v), %edx
18795 +
18796 +#ifdef CONFIG_PAX_REFCOUNT
18797 + into
18798 +1234:
18799 + _ASM_EXTABLE(1234b, 2f)
18800 +#endif
18801 +
18802 + movl %eax, (v)
18803 + movl %edx, 4(v)
18804 +
18805 +#ifdef CONFIG_PAX_REFCOUNT
18806 +2:
18807 +#endif
18808 +
18809 +RET_ENDP
18810 +BEGIN(add_return_unchecked)
18811 + addl (v), %eax
18812 + adcl 4(v), %edx
18813 movl %eax, (v)
18814 movl %edx, 4(v)
18815 RET_ENDP
18816 @@ -86,6 +126,20 @@ RET_ENDP
18817 BEGIN(sub)
18818 subl %eax, (v)
18819 sbbl %edx, 4(v)
18820 +
18821 +#ifdef CONFIG_PAX_REFCOUNT
18822 + jno 0f
18823 + addl %eax, (v)
18824 + adcl %edx, 4(v)
18825 + int $4
18826 +0:
18827 + _ASM_EXTABLE(0b, 0b)
18828 +#endif
18829 +
18830 +RET_ENDP
18831 +BEGIN(sub_unchecked)
18832 + subl %eax, (v)
18833 + sbbl %edx, 4(v)
18834 RET_ENDP
18835 #undef v
18836
18837 @@ -96,6 +150,27 @@ BEGIN(sub_return)
18838 sbbl $0, %edx
18839 addl (v), %eax
18840 adcl 4(v), %edx
18841 +
18842 +#ifdef CONFIG_PAX_REFCOUNT
18843 + into
18844 +1234:
18845 + _ASM_EXTABLE(1234b, 2f)
18846 +#endif
18847 +
18848 + movl %eax, (v)
18849 + movl %edx, 4(v)
18850 +
18851 +#ifdef CONFIG_PAX_REFCOUNT
18852 +2:
18853 +#endif
18854 +
18855 +RET_ENDP
18856 +BEGIN(sub_return_unchecked)
18857 + negl %edx
18858 + negl %eax
18859 + sbbl $0, %edx
18860 + addl (v), %eax
18861 + adcl 4(v), %edx
18862 movl %eax, (v)
18863 movl %edx, 4(v)
18864 RET_ENDP
18865 @@ -105,6 +180,20 @@ RET_ENDP
18866 BEGIN(inc)
18867 addl $1, (v)
18868 adcl $0, 4(v)
18869 +
18870 +#ifdef CONFIG_PAX_REFCOUNT
18871 + jno 0f
18872 + subl $1, (v)
18873 + sbbl $0, 4(v)
18874 + int $4
18875 +0:
18876 + _ASM_EXTABLE(0b, 0b)
18877 +#endif
18878 +
18879 +RET_ENDP
18880 +BEGIN(inc_unchecked)
18881 + addl $1, (v)
18882 + adcl $0, 4(v)
18883 RET_ENDP
18884 #undef v
18885
18886 @@ -114,6 +203,26 @@ BEGIN(inc_return)
18887 movl 4(v), %edx
18888 addl $1, %eax
18889 adcl $0, %edx
18890 +
18891 +#ifdef CONFIG_PAX_REFCOUNT
18892 + into
18893 +1234:
18894 + _ASM_EXTABLE(1234b, 2f)
18895 +#endif
18896 +
18897 + movl %eax, (v)
18898 + movl %edx, 4(v)
18899 +
18900 +#ifdef CONFIG_PAX_REFCOUNT
18901 +2:
18902 +#endif
18903 +
18904 +RET_ENDP
18905 +BEGIN(inc_return_unchecked)
18906 + movl (v), %eax
18907 + movl 4(v), %edx
18908 + addl $1, %eax
18909 + adcl $0, %edx
18910 movl %eax, (v)
18911 movl %edx, 4(v)
18912 RET_ENDP
18913 @@ -123,6 +232,20 @@ RET_ENDP
18914 BEGIN(dec)
18915 subl $1, (v)
18916 sbbl $0, 4(v)
18917 +
18918 +#ifdef CONFIG_PAX_REFCOUNT
18919 + jno 0f
18920 + addl $1, (v)
18921 + adcl $0, 4(v)
18922 + int $4
18923 +0:
18924 + _ASM_EXTABLE(0b, 0b)
18925 +#endif
18926 +
18927 +RET_ENDP
18928 +BEGIN(dec_unchecked)
18929 + subl $1, (v)
18930 + sbbl $0, 4(v)
18931 RET_ENDP
18932 #undef v
18933
18934 @@ -132,6 +255,26 @@ BEGIN(dec_return)
18935 movl 4(v), %edx
18936 subl $1, %eax
18937 sbbl $0, %edx
18938 +
18939 +#ifdef CONFIG_PAX_REFCOUNT
18940 + into
18941 +1234:
18942 + _ASM_EXTABLE(1234b, 2f)
18943 +#endif
18944 +
18945 + movl %eax, (v)
18946 + movl %edx, 4(v)
18947 +
18948 +#ifdef CONFIG_PAX_REFCOUNT
18949 +2:
18950 +#endif
18951 +
18952 +RET_ENDP
18953 +BEGIN(dec_return_unchecked)
18954 + movl (v), %eax
18955 + movl 4(v), %edx
18956 + subl $1, %eax
18957 + sbbl $0, %edx
18958 movl %eax, (v)
18959 movl %edx, 4(v)
18960 RET_ENDP
18961 @@ -143,6 +286,13 @@ BEGIN(add_unless)
18962 adcl %edx, %edi
18963 addl (v), %eax
18964 adcl 4(v), %edx
18965 +
18966 +#ifdef CONFIG_PAX_REFCOUNT
18967 + into
18968 +1234:
18969 + _ASM_EXTABLE(1234b, 2f)
18970 +#endif
18971 +
18972 cmpl %eax, %esi
18973 je 3f
18974 1:
18975 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
18976 1:
18977 addl $1, %eax
18978 adcl $0, %edx
18979 +
18980 +#ifdef CONFIG_PAX_REFCOUNT
18981 + into
18982 +1234:
18983 + _ASM_EXTABLE(1234b, 2f)
18984 +#endif
18985 +
18986 movl %eax, (v)
18987 movl %edx, 4(v)
18988 movl $1, %eax
18989 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
18990 movl 4(v), %edx
18991 subl $1, %eax
18992 sbbl $0, %edx
18993 +
18994 +#ifdef CONFIG_PAX_REFCOUNT
18995 + into
18996 +1234:
18997 + _ASM_EXTABLE(1234b, 1f)
18998 +#endif
18999 +
19000 js 1f
19001 movl %eax, (v)
19002 movl %edx, 4(v)
19003 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
19004 index 391a083..d658e9f 100644
19005 --- a/arch/x86/lib/atomic64_cx8_32.S
19006 +++ b/arch/x86/lib/atomic64_cx8_32.S
19007 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
19008 CFI_STARTPROC
19009
19010 read64 %ecx
19011 + pax_force_retaddr
19012 ret
19013 CFI_ENDPROC
19014 ENDPROC(atomic64_read_cx8)
19015
19016 +ENTRY(atomic64_read_unchecked_cx8)
19017 + CFI_STARTPROC
19018 +
19019 + read64 %ecx
19020 + pax_force_retaddr
19021 + ret
19022 + CFI_ENDPROC
19023 +ENDPROC(atomic64_read_unchecked_cx8)
19024 +
19025 ENTRY(atomic64_set_cx8)
19026 CFI_STARTPROC
19027
19028 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
19029 cmpxchg8b (%esi)
19030 jne 1b
19031
19032 + pax_force_retaddr
19033 ret
19034 CFI_ENDPROC
19035 ENDPROC(atomic64_set_cx8)
19036
19037 +ENTRY(atomic64_set_unchecked_cx8)
19038 + CFI_STARTPROC
19039 +
19040 +1:
19041 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
19042 + * are atomic on 586 and newer */
19043 + cmpxchg8b (%esi)
19044 + jne 1b
19045 +
19046 + pax_force_retaddr
19047 + ret
19048 + CFI_ENDPROC
19049 +ENDPROC(atomic64_set_unchecked_cx8)
19050 +
19051 ENTRY(atomic64_xchg_cx8)
19052 CFI_STARTPROC
19053
19054 @@ -62,12 +87,13 @@ ENTRY(atomic64_xchg_cx8)
19055 cmpxchg8b (%esi)
19056 jne 1b
19057
19058 + pax_force_retaddr
19059 ret
19060 CFI_ENDPROC
19061 ENDPROC(atomic64_xchg_cx8)
19062
19063 -.macro addsub_return func ins insc
19064 -ENTRY(atomic64_\func\()_return_cx8)
19065 +.macro addsub_return func ins insc unchecked=""
19066 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19067 CFI_STARTPROC
19068 SAVE ebp
19069 SAVE ebx
19070 @@ -84,27 +110,44 @@ ENTRY(atomic64_\func\()_return_cx8)
19071 movl %edx, %ecx
19072 \ins\()l %esi, %ebx
19073 \insc\()l %edi, %ecx
19074 +
19075 +.ifb \unchecked
19076 +#ifdef CONFIG_PAX_REFCOUNT
19077 + into
19078 +2:
19079 + _ASM_EXTABLE(2b, 3f)
19080 +#endif
19081 +.endif
19082 +
19083 LOCK_PREFIX
19084 cmpxchg8b (%ebp)
19085 jne 1b
19086 -
19087 -10:
19088 movl %ebx, %eax
19089 movl %ecx, %edx
19090 +
19091 +.ifb \unchecked
19092 +#ifdef CONFIG_PAX_REFCOUNT
19093 +3:
19094 +#endif
19095 +.endif
19096 +
19097 RESTORE edi
19098 RESTORE esi
19099 RESTORE ebx
19100 RESTORE ebp
19101 + pax_force_retaddr
19102 ret
19103 CFI_ENDPROC
19104 -ENDPROC(atomic64_\func\()_return_cx8)
19105 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19106 .endm
19107
19108 addsub_return add add adc
19109 addsub_return sub sub sbb
19110 +addsub_return add add adc _unchecked
19111 +addsub_return sub sub sbb _unchecked
19112
19113 -.macro incdec_return func ins insc
19114 -ENTRY(atomic64_\func\()_return_cx8)
19115 +.macro incdec_return func ins insc unchecked
19116 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
19117 CFI_STARTPROC
19118 SAVE ebx
19119
19120 @@ -114,21 +157,39 @@ ENTRY(atomic64_\func\()_return_cx8)
19121 movl %edx, %ecx
19122 \ins\()l $1, %ebx
19123 \insc\()l $0, %ecx
19124 +
19125 +.ifb \unchecked
19126 +#ifdef CONFIG_PAX_REFCOUNT
19127 + into
19128 +2:
19129 + _ASM_EXTABLE(2b, 3f)
19130 +#endif
19131 +.endif
19132 +
19133 LOCK_PREFIX
19134 cmpxchg8b (%esi)
19135 jne 1b
19136
19137 -10:
19138 movl %ebx, %eax
19139 movl %ecx, %edx
19140 +
19141 +.ifb \unchecked
19142 +#ifdef CONFIG_PAX_REFCOUNT
19143 +3:
19144 +#endif
19145 +.endif
19146 +
19147 RESTORE ebx
19148 + pax_force_retaddr
19149 ret
19150 CFI_ENDPROC
19151 -ENDPROC(atomic64_\func\()_return_cx8)
19152 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
19153 .endm
19154
19155 incdec_return inc add adc
19156 incdec_return dec sub sbb
19157 +incdec_return inc add adc _unchecked
19158 +incdec_return dec sub sbb _unchecked
19159
19160 ENTRY(atomic64_dec_if_positive_cx8)
19161 CFI_STARTPROC
19162 @@ -140,6 +201,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
19163 movl %edx, %ecx
19164 subl $1, %ebx
19165 sbb $0, %ecx
19166 +
19167 +#ifdef CONFIG_PAX_REFCOUNT
19168 + into
19169 +1234:
19170 + _ASM_EXTABLE(1234b, 2f)
19171 +#endif
19172 +
19173 js 2f
19174 LOCK_PREFIX
19175 cmpxchg8b (%esi)
19176 @@ -149,6 +217,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
19177 movl %ebx, %eax
19178 movl %ecx, %edx
19179 RESTORE ebx
19180 + pax_force_retaddr
19181 ret
19182 CFI_ENDPROC
19183 ENDPROC(atomic64_dec_if_positive_cx8)
19184 @@ -174,6 +243,13 @@ ENTRY(atomic64_add_unless_cx8)
19185 movl %edx, %ecx
19186 addl %esi, %ebx
19187 adcl %edi, %ecx
19188 +
19189 +#ifdef CONFIG_PAX_REFCOUNT
19190 + into
19191 +1234:
19192 + _ASM_EXTABLE(1234b, 3f)
19193 +#endif
19194 +
19195 LOCK_PREFIX
19196 cmpxchg8b (%ebp)
19197 jne 1b
19198 @@ -184,6 +260,7 @@ ENTRY(atomic64_add_unless_cx8)
19199 CFI_ADJUST_CFA_OFFSET -8
19200 RESTORE ebx
19201 RESTORE ebp
19202 + pax_force_retaddr
19203 ret
19204 4:
19205 cmpl %edx, 4(%esp)
19206 @@ -206,6 +283,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
19207 movl %edx, %ecx
19208 addl $1, %ebx
19209 adcl $0, %ecx
19210 +
19211 +#ifdef CONFIG_PAX_REFCOUNT
19212 + into
19213 +1234:
19214 + _ASM_EXTABLE(1234b, 3f)
19215 +#endif
19216 +
19217 LOCK_PREFIX
19218 cmpxchg8b (%esi)
19219 jne 1b
19220 @@ -213,6 +297,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
19221 movl $1, %eax
19222 3:
19223 RESTORE ebx
19224 + pax_force_retaddr
19225 ret
19226 4:
19227 testl %edx, %edx
19228 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
19229 index 78d16a5..fbcf666 100644
19230 --- a/arch/x86/lib/checksum_32.S
19231 +++ b/arch/x86/lib/checksum_32.S
19232 @@ -28,7 +28,8 @@
19233 #include <linux/linkage.h>
19234 #include <asm/dwarf2.h>
19235 #include <asm/errno.h>
19236 -
19237 +#include <asm/segment.h>
19238 +
19239 /*
19240 * computes a partial checksum, e.g. for TCP/UDP fragments
19241 */
19242 @@ -296,9 +297,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
19243
19244 #define ARGBASE 16
19245 #define FP 12
19246 -
19247 -ENTRY(csum_partial_copy_generic)
19248 +
19249 +ENTRY(csum_partial_copy_generic_to_user)
19250 CFI_STARTPROC
19251 +
19252 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19253 + pushl_cfi %gs
19254 + popl_cfi %es
19255 + jmp csum_partial_copy_generic
19256 +#endif
19257 +
19258 +ENTRY(csum_partial_copy_generic_from_user)
19259 +
19260 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19261 + pushl_cfi %gs
19262 + popl_cfi %ds
19263 +#endif
19264 +
19265 +ENTRY(csum_partial_copy_generic)
19266 subl $4,%esp
19267 CFI_ADJUST_CFA_OFFSET 4
19268 pushl_cfi %edi
19269 @@ -320,7 +336,7 @@ ENTRY(csum_partial_copy_generic)
19270 jmp 4f
19271 SRC(1: movw (%esi), %bx )
19272 addl $2, %esi
19273 -DST( movw %bx, (%edi) )
19274 +DST( movw %bx, %es:(%edi) )
19275 addl $2, %edi
19276 addw %bx, %ax
19277 adcl $0, %eax
19278 @@ -332,30 +348,30 @@ DST( movw %bx, (%edi) )
19279 SRC(1: movl (%esi), %ebx )
19280 SRC( movl 4(%esi), %edx )
19281 adcl %ebx, %eax
19282 -DST( movl %ebx, (%edi) )
19283 +DST( movl %ebx, %es:(%edi) )
19284 adcl %edx, %eax
19285 -DST( movl %edx, 4(%edi) )
19286 +DST( movl %edx, %es:4(%edi) )
19287
19288 SRC( movl 8(%esi), %ebx )
19289 SRC( movl 12(%esi), %edx )
19290 adcl %ebx, %eax
19291 -DST( movl %ebx, 8(%edi) )
19292 +DST( movl %ebx, %es:8(%edi) )
19293 adcl %edx, %eax
19294 -DST( movl %edx, 12(%edi) )
19295 +DST( movl %edx, %es:12(%edi) )
19296
19297 SRC( movl 16(%esi), %ebx )
19298 SRC( movl 20(%esi), %edx )
19299 adcl %ebx, %eax
19300 -DST( movl %ebx, 16(%edi) )
19301 +DST( movl %ebx, %es:16(%edi) )
19302 adcl %edx, %eax
19303 -DST( movl %edx, 20(%edi) )
19304 +DST( movl %edx, %es:20(%edi) )
19305
19306 SRC( movl 24(%esi), %ebx )
19307 SRC( movl 28(%esi), %edx )
19308 adcl %ebx, %eax
19309 -DST( movl %ebx, 24(%edi) )
19310 +DST( movl %ebx, %es:24(%edi) )
19311 adcl %edx, %eax
19312 -DST( movl %edx, 28(%edi) )
19313 +DST( movl %edx, %es:28(%edi) )
19314
19315 lea 32(%esi), %esi
19316 lea 32(%edi), %edi
19317 @@ -369,7 +385,7 @@ DST( movl %edx, 28(%edi) )
19318 shrl $2, %edx # This clears CF
19319 SRC(3: movl (%esi), %ebx )
19320 adcl %ebx, %eax
19321 -DST( movl %ebx, (%edi) )
19322 +DST( movl %ebx, %es:(%edi) )
19323 lea 4(%esi), %esi
19324 lea 4(%edi), %edi
19325 dec %edx
19326 @@ -381,12 +397,12 @@ DST( movl %ebx, (%edi) )
19327 jb 5f
19328 SRC( movw (%esi), %cx )
19329 leal 2(%esi), %esi
19330 -DST( movw %cx, (%edi) )
19331 +DST( movw %cx, %es:(%edi) )
19332 leal 2(%edi), %edi
19333 je 6f
19334 shll $16,%ecx
19335 SRC(5: movb (%esi), %cl )
19336 -DST( movb %cl, (%edi) )
19337 +DST( movb %cl, %es:(%edi) )
19338 6: addl %ecx, %eax
19339 adcl $0, %eax
19340 7:
19341 @@ -397,7 +413,7 @@ DST( movb %cl, (%edi) )
19342
19343 6001:
19344 movl ARGBASE+20(%esp), %ebx # src_err_ptr
19345 - movl $-EFAULT, (%ebx)
19346 + movl $-EFAULT, %ss:(%ebx)
19347
19348 # zero the complete destination - computing the rest
19349 # is too much work
19350 @@ -410,11 +426,15 @@ DST( movb %cl, (%edi) )
19351
19352 6002:
19353 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19354 - movl $-EFAULT,(%ebx)
19355 + movl $-EFAULT,%ss:(%ebx)
19356 jmp 5000b
19357
19358 .previous
19359
19360 + pushl_cfi %ss
19361 + popl_cfi %ds
19362 + pushl_cfi %ss
19363 + popl_cfi %es
19364 popl_cfi %ebx
19365 CFI_RESTORE ebx
19366 popl_cfi %esi
19367 @@ -424,26 +444,43 @@ DST( movb %cl, (%edi) )
19368 popl_cfi %ecx # equivalent to addl $4,%esp
19369 ret
19370 CFI_ENDPROC
19371 -ENDPROC(csum_partial_copy_generic)
19372 +ENDPROC(csum_partial_copy_generic_to_user)
19373
19374 #else
19375
19376 /* Version for PentiumII/PPro */
19377
19378 #define ROUND1(x) \
19379 + nop; nop; nop; \
19380 SRC(movl x(%esi), %ebx ) ; \
19381 addl %ebx, %eax ; \
19382 - DST(movl %ebx, x(%edi) ) ;
19383 + DST(movl %ebx, %es:x(%edi)) ;
19384
19385 #define ROUND(x) \
19386 + nop; nop; nop; \
19387 SRC(movl x(%esi), %ebx ) ; \
19388 adcl %ebx, %eax ; \
19389 - DST(movl %ebx, x(%edi) ) ;
19390 + DST(movl %ebx, %es:x(%edi)) ;
19391
19392 #define ARGBASE 12
19393 -
19394 -ENTRY(csum_partial_copy_generic)
19395 +
19396 +ENTRY(csum_partial_copy_generic_to_user)
19397 CFI_STARTPROC
19398 +
19399 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19400 + pushl_cfi %gs
19401 + popl_cfi %es
19402 + jmp csum_partial_copy_generic
19403 +#endif
19404 +
19405 +ENTRY(csum_partial_copy_generic_from_user)
19406 +
19407 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19408 + pushl_cfi %gs
19409 + popl_cfi %ds
19410 +#endif
19411 +
19412 +ENTRY(csum_partial_copy_generic)
19413 pushl_cfi %ebx
19414 CFI_REL_OFFSET ebx, 0
19415 pushl_cfi %edi
19416 @@ -464,7 +501,7 @@ ENTRY(csum_partial_copy_generic)
19417 subl %ebx, %edi
19418 lea -1(%esi),%edx
19419 andl $-32,%edx
19420 - lea 3f(%ebx,%ebx), %ebx
19421 + lea 3f(%ebx,%ebx,2), %ebx
19422 testl %esi, %esi
19423 jmp *%ebx
19424 1: addl $64,%esi
19425 @@ -485,19 +522,19 @@ ENTRY(csum_partial_copy_generic)
19426 jb 5f
19427 SRC( movw (%esi), %dx )
19428 leal 2(%esi), %esi
19429 -DST( movw %dx, (%edi) )
19430 +DST( movw %dx, %es:(%edi) )
19431 leal 2(%edi), %edi
19432 je 6f
19433 shll $16,%edx
19434 5:
19435 SRC( movb (%esi), %dl )
19436 -DST( movb %dl, (%edi) )
19437 +DST( movb %dl, %es:(%edi) )
19438 6: addl %edx, %eax
19439 adcl $0, %eax
19440 7:
19441 .section .fixup, "ax"
19442 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
19443 - movl $-EFAULT, (%ebx)
19444 + movl $-EFAULT, %ss:(%ebx)
19445 # zero the complete destination (computing the rest is too much work)
19446 movl ARGBASE+8(%esp),%edi # dst
19447 movl ARGBASE+12(%esp),%ecx # len
19448 @@ -505,10 +542,17 @@ DST( movb %dl, (%edi) )
19449 rep; stosb
19450 jmp 7b
19451 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
19452 - movl $-EFAULT, (%ebx)
19453 + movl $-EFAULT, %ss:(%ebx)
19454 jmp 7b
19455 .previous
19456
19457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19458 + pushl_cfi %ss
19459 + popl_cfi %ds
19460 + pushl_cfi %ss
19461 + popl_cfi %es
19462 +#endif
19463 +
19464 popl_cfi %esi
19465 CFI_RESTORE esi
19466 popl_cfi %edi
19467 @@ -517,7 +561,7 @@ DST( movb %dl, (%edi) )
19468 CFI_RESTORE ebx
19469 ret
19470 CFI_ENDPROC
19471 -ENDPROC(csum_partial_copy_generic)
19472 +ENDPROC(csum_partial_copy_generic_to_user)
19473
19474 #undef ROUND
19475 #undef ROUND1
19476 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
19477 index f2145cf..cea889d 100644
19478 --- a/arch/x86/lib/clear_page_64.S
19479 +++ b/arch/x86/lib/clear_page_64.S
19480 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
19481 movl $4096/8,%ecx
19482 xorl %eax,%eax
19483 rep stosq
19484 + pax_force_retaddr
19485 ret
19486 CFI_ENDPROC
19487 ENDPROC(clear_page_c)
19488 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
19489 movl $4096,%ecx
19490 xorl %eax,%eax
19491 rep stosb
19492 + pax_force_retaddr
19493 ret
19494 CFI_ENDPROC
19495 ENDPROC(clear_page_c_e)
19496 @@ -43,6 +45,7 @@ ENTRY(clear_page)
19497 leaq 64(%rdi),%rdi
19498 jnz .Lloop
19499 nop
19500 + pax_force_retaddr
19501 ret
19502 CFI_ENDPROC
19503 .Lclear_page_end:
19504 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
19505
19506 #include <asm/cpufeature.h>
19507
19508 - .section .altinstr_replacement,"ax"
19509 + .section .altinstr_replacement,"a"
19510 1: .byte 0xeb /* jmp <disp8> */
19511 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
19512 2: .byte 0xeb /* jmp <disp8> */
19513 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
19514 index 1e572c5..2a162cd 100644
19515 --- a/arch/x86/lib/cmpxchg16b_emu.S
19516 +++ b/arch/x86/lib/cmpxchg16b_emu.S
19517 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
19518
19519 popf
19520 mov $1, %al
19521 + pax_force_retaddr
19522 ret
19523
19524 not_same:
19525 popf
19526 xor %al,%al
19527 + pax_force_retaddr
19528 ret
19529
19530 CFI_ENDPROC
19531 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
19532 index 01c805b..dccb07f 100644
19533 --- a/arch/x86/lib/copy_page_64.S
19534 +++ b/arch/x86/lib/copy_page_64.S
19535 @@ -9,6 +9,7 @@ copy_page_c:
19536 CFI_STARTPROC
19537 movl $4096/8,%ecx
19538 rep movsq
19539 + pax_force_retaddr
19540 ret
19541 CFI_ENDPROC
19542 ENDPROC(copy_page_c)
19543 @@ -39,7 +40,7 @@ ENTRY(copy_page)
19544 movq 16 (%rsi), %rdx
19545 movq 24 (%rsi), %r8
19546 movq 32 (%rsi), %r9
19547 - movq 40 (%rsi), %r10
19548 + movq 40 (%rsi), %r13
19549 movq 48 (%rsi), %r11
19550 movq 56 (%rsi), %r12
19551
19552 @@ -50,7 +51,7 @@ ENTRY(copy_page)
19553 movq %rdx, 16 (%rdi)
19554 movq %r8, 24 (%rdi)
19555 movq %r9, 32 (%rdi)
19556 - movq %r10, 40 (%rdi)
19557 + movq %r13, 40 (%rdi)
19558 movq %r11, 48 (%rdi)
19559 movq %r12, 56 (%rdi)
19560
19561 @@ -69,7 +70,7 @@ ENTRY(copy_page)
19562 movq 16 (%rsi), %rdx
19563 movq 24 (%rsi), %r8
19564 movq 32 (%rsi), %r9
19565 - movq 40 (%rsi), %r10
19566 + movq 40 (%rsi), %r13
19567 movq 48 (%rsi), %r11
19568 movq 56 (%rsi), %r12
19569
19570 @@ -78,7 +79,7 @@ ENTRY(copy_page)
19571 movq %rdx, 16 (%rdi)
19572 movq %r8, 24 (%rdi)
19573 movq %r9, 32 (%rdi)
19574 - movq %r10, 40 (%rdi)
19575 + movq %r13, 40 (%rdi)
19576 movq %r11, 48 (%rdi)
19577 movq %r12, 56 (%rdi)
19578
19579 @@ -95,6 +96,7 @@ ENTRY(copy_page)
19580 CFI_RESTORE r13
19581 addq $3*8,%rsp
19582 CFI_ADJUST_CFA_OFFSET -3*8
19583 + pax_force_retaddr
19584 ret
19585 .Lcopy_page_end:
19586 CFI_ENDPROC
19587 @@ -105,7 +107,7 @@ ENDPROC(copy_page)
19588
19589 #include <asm/cpufeature.h>
19590
19591 - .section .altinstr_replacement,"ax"
19592 + .section .altinstr_replacement,"a"
19593 1: .byte 0xeb /* jmp <disp8> */
19594 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
19595 2:
19596 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
19597 index 0248402..821c786 100644
19598 --- a/arch/x86/lib/copy_user_64.S
19599 +++ b/arch/x86/lib/copy_user_64.S
19600 @@ -16,6 +16,7 @@
19601 #include <asm/thread_info.h>
19602 #include <asm/cpufeature.h>
19603 #include <asm/alternative-asm.h>
19604 +#include <asm/pgtable.h>
19605
19606 /*
19607 * By placing feature2 after feature1 in altinstructions section, we logically
19608 @@ -29,7 +30,7 @@
19609 .byte 0xe9 /* 32bit jump */
19610 .long \orig-1f /* by default jump to orig */
19611 1:
19612 - .section .altinstr_replacement,"ax"
19613 + .section .altinstr_replacement,"a"
19614 2: .byte 0xe9 /* near jump with 32bit immediate */
19615 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
19616 3: .byte 0xe9 /* near jump with 32bit immediate */
19617 @@ -71,47 +72,20 @@
19618 #endif
19619 .endm
19620
19621 -/* Standard copy_to_user with segment limit checking */
19622 -ENTRY(_copy_to_user)
19623 - CFI_STARTPROC
19624 - GET_THREAD_INFO(%rax)
19625 - movq %rdi,%rcx
19626 - addq %rdx,%rcx
19627 - jc bad_to_user
19628 - cmpq TI_addr_limit(%rax),%rcx
19629 - ja bad_to_user
19630 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19631 - copy_user_generic_unrolled,copy_user_generic_string, \
19632 - copy_user_enhanced_fast_string
19633 - CFI_ENDPROC
19634 -ENDPROC(_copy_to_user)
19635 -
19636 -/* Standard copy_from_user with segment limit checking */
19637 -ENTRY(_copy_from_user)
19638 - CFI_STARTPROC
19639 - GET_THREAD_INFO(%rax)
19640 - movq %rsi,%rcx
19641 - addq %rdx,%rcx
19642 - jc bad_from_user
19643 - cmpq TI_addr_limit(%rax),%rcx
19644 - ja bad_from_user
19645 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
19646 - copy_user_generic_unrolled,copy_user_generic_string, \
19647 - copy_user_enhanced_fast_string
19648 - CFI_ENDPROC
19649 -ENDPROC(_copy_from_user)
19650 -
19651 .section .fixup,"ax"
19652 /* must zero dest */
19653 ENTRY(bad_from_user)
19654 bad_from_user:
19655 CFI_STARTPROC
19656 + testl %edx,%edx
19657 + js bad_to_user
19658 movl %edx,%ecx
19659 xorl %eax,%eax
19660 rep
19661 stosb
19662 bad_to_user:
19663 movl %edx,%eax
19664 + pax_force_retaddr
19665 ret
19666 CFI_ENDPROC
19667 ENDPROC(bad_from_user)
19668 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
19669 jz 17f
19670 1: movq (%rsi),%r8
19671 2: movq 1*8(%rsi),%r9
19672 -3: movq 2*8(%rsi),%r10
19673 +3: movq 2*8(%rsi),%rax
19674 4: movq 3*8(%rsi),%r11
19675 5: movq %r8,(%rdi)
19676 6: movq %r9,1*8(%rdi)
19677 -7: movq %r10,2*8(%rdi)
19678 +7: movq %rax,2*8(%rdi)
19679 8: movq %r11,3*8(%rdi)
19680 9: movq 4*8(%rsi),%r8
19681 10: movq 5*8(%rsi),%r9
19682 -11: movq 6*8(%rsi),%r10
19683 +11: movq 6*8(%rsi),%rax
19684 12: movq 7*8(%rsi),%r11
19685 13: movq %r8,4*8(%rdi)
19686 14: movq %r9,5*8(%rdi)
19687 -15: movq %r10,6*8(%rdi)
19688 +15: movq %rax,6*8(%rdi)
19689 16: movq %r11,7*8(%rdi)
19690 leaq 64(%rsi),%rsi
19691 leaq 64(%rdi),%rdi
19692 @@ -179,6 +153,7 @@ ENTRY(copy_user_generic_unrolled)
19693 decl %ecx
19694 jnz 21b
19695 23: xor %eax,%eax
19696 + pax_force_retaddr
19697 ret
19698
19699 .section .fixup,"ax"
19700 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
19701 3: rep
19702 movsb
19703 4: xorl %eax,%eax
19704 + pax_force_retaddr
19705 ret
19706
19707 .section .fixup,"ax"
19708 @@ -287,6 +263,7 @@ ENTRY(copy_user_enhanced_fast_string)
19709 1: rep
19710 movsb
19711 2: xorl %eax,%eax
19712 + pax_force_retaddr
19713 ret
19714
19715 .section .fixup,"ax"
19716 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
19717 index cb0c112..e3a6895 100644
19718 --- a/arch/x86/lib/copy_user_nocache_64.S
19719 +++ b/arch/x86/lib/copy_user_nocache_64.S
19720 @@ -8,12 +8,14 @@
19721
19722 #include <linux/linkage.h>
19723 #include <asm/dwarf2.h>
19724 +#include <asm/alternative-asm.h>
19725
19726 #define FIX_ALIGNMENT 1
19727
19728 #include <asm/current.h>
19729 #include <asm/asm-offsets.h>
19730 #include <asm/thread_info.h>
19731 +#include <asm/pgtable.h>
19732
19733 .macro ALIGN_DESTINATION
19734 #ifdef FIX_ALIGNMENT
19735 @@ -50,6 +52,15 @@
19736 */
19737 ENTRY(__copy_user_nocache)
19738 CFI_STARTPROC
19739 +
19740 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19741 + mov $PAX_USER_SHADOW_BASE,%rcx
19742 + cmp %rcx,%rsi
19743 + jae 1f
19744 + add %rcx,%rsi
19745 +1:
19746 +#endif
19747 +
19748 cmpl $8,%edx
19749 jb 20f /* less then 8 bytes, go to byte copy loop */
19750 ALIGN_DESTINATION
19751 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
19752 jz 17f
19753 1: movq (%rsi),%r8
19754 2: movq 1*8(%rsi),%r9
19755 -3: movq 2*8(%rsi),%r10
19756 +3: movq 2*8(%rsi),%rax
19757 4: movq 3*8(%rsi),%r11
19758 5: movnti %r8,(%rdi)
19759 6: movnti %r9,1*8(%rdi)
19760 -7: movnti %r10,2*8(%rdi)
19761 +7: movnti %rax,2*8(%rdi)
19762 8: movnti %r11,3*8(%rdi)
19763 9: movq 4*8(%rsi),%r8
19764 10: movq 5*8(%rsi),%r9
19765 -11: movq 6*8(%rsi),%r10
19766 +11: movq 6*8(%rsi),%rax
19767 12: movq 7*8(%rsi),%r11
19768 13: movnti %r8,4*8(%rdi)
19769 14: movnti %r9,5*8(%rdi)
19770 -15: movnti %r10,6*8(%rdi)
19771 +15: movnti %rax,6*8(%rdi)
19772 16: movnti %r11,7*8(%rdi)
19773 leaq 64(%rsi),%rsi
19774 leaq 64(%rdi),%rdi
19775 @@ -98,6 +109,7 @@ ENTRY(__copy_user_nocache)
19776 jnz 21b
19777 23: xorl %eax,%eax
19778 sfence
19779 + pax_force_retaddr
19780 ret
19781
19782 .section .fixup,"ax"
19783 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
19784 index fb903b7..c92b7f7 100644
19785 --- a/arch/x86/lib/csum-copy_64.S
19786 +++ b/arch/x86/lib/csum-copy_64.S
19787 @@ -8,6 +8,7 @@
19788 #include <linux/linkage.h>
19789 #include <asm/dwarf2.h>
19790 #include <asm/errno.h>
19791 +#include <asm/alternative-asm.h>
19792
19793 /*
19794 * Checksum copy with exception handling.
19795 @@ -228,6 +229,7 @@ ENTRY(csum_partial_copy_generic)
19796 CFI_RESTORE rbp
19797 addq $7*8, %rsp
19798 CFI_ADJUST_CFA_OFFSET -7*8
19799 + pax_force_retaddr 0, 1
19800 ret
19801 CFI_RESTORE_STATE
19802
19803 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
19804 index 459b58a..9570bc7 100644
19805 --- a/arch/x86/lib/csum-wrappers_64.c
19806 +++ b/arch/x86/lib/csum-wrappers_64.c
19807 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
19808 len -= 2;
19809 }
19810 }
19811 - isum = csum_partial_copy_generic((__force const void *)src,
19812 +
19813 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19814 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
19815 + src += PAX_USER_SHADOW_BASE;
19816 +#endif
19817 +
19818 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
19819 dst, len, isum, errp, NULL);
19820 if (unlikely(*errp))
19821 goto out_err;
19822 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
19823 }
19824
19825 *errp = 0;
19826 - return csum_partial_copy_generic(src, (void __force *)dst,
19827 +
19828 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19829 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
19830 + dst += PAX_USER_SHADOW_BASE;
19831 +#endif
19832 +
19833 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
19834 len, isum, NULL, errp);
19835 }
19836 EXPORT_SYMBOL(csum_partial_copy_to_user);
19837 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
19838 index 51f1504..ddac4c1 100644
19839 --- a/arch/x86/lib/getuser.S
19840 +++ b/arch/x86/lib/getuser.S
19841 @@ -33,15 +33,38 @@
19842 #include <asm/asm-offsets.h>
19843 #include <asm/thread_info.h>
19844 #include <asm/asm.h>
19845 +#include <asm/segment.h>
19846 +#include <asm/pgtable.h>
19847 +#include <asm/alternative-asm.h>
19848 +
19849 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19850 +#define __copyuser_seg gs;
19851 +#else
19852 +#define __copyuser_seg
19853 +#endif
19854
19855 .text
19856 ENTRY(__get_user_1)
19857 CFI_STARTPROC
19858 +
19859 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19860 GET_THREAD_INFO(%_ASM_DX)
19861 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19862 jae bad_get_user
19863 -1: movzb (%_ASM_AX),%edx
19864 +
19865 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19866 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19867 + cmp %_ASM_DX,%_ASM_AX
19868 + jae 1234f
19869 + add %_ASM_DX,%_ASM_AX
19870 +1234:
19871 +#endif
19872 +
19873 +#endif
19874 +
19875 +1: __copyuser_seg movzb (%_ASM_AX),%edx
19876 xor %eax,%eax
19877 + pax_force_retaddr
19878 ret
19879 CFI_ENDPROC
19880 ENDPROC(__get_user_1)
19881 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
19882 ENTRY(__get_user_2)
19883 CFI_STARTPROC
19884 add $1,%_ASM_AX
19885 +
19886 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19887 jc bad_get_user
19888 GET_THREAD_INFO(%_ASM_DX)
19889 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19890 jae bad_get_user
19891 -2: movzwl -1(%_ASM_AX),%edx
19892 +
19893 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19894 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19895 + cmp %_ASM_DX,%_ASM_AX
19896 + jae 1234f
19897 + add %_ASM_DX,%_ASM_AX
19898 +1234:
19899 +#endif
19900 +
19901 +#endif
19902 +
19903 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
19904 xor %eax,%eax
19905 + pax_force_retaddr
19906 ret
19907 CFI_ENDPROC
19908 ENDPROC(__get_user_2)
19909 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
19910 ENTRY(__get_user_4)
19911 CFI_STARTPROC
19912 add $3,%_ASM_AX
19913 +
19914 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
19915 jc bad_get_user
19916 GET_THREAD_INFO(%_ASM_DX)
19917 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19918 jae bad_get_user
19919 -3: mov -3(%_ASM_AX),%edx
19920 +
19921 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19922 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19923 + cmp %_ASM_DX,%_ASM_AX
19924 + jae 1234f
19925 + add %_ASM_DX,%_ASM_AX
19926 +1234:
19927 +#endif
19928 +
19929 +#endif
19930 +
19931 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
19932 xor %eax,%eax
19933 + pax_force_retaddr
19934 ret
19935 CFI_ENDPROC
19936 ENDPROC(__get_user_4)
19937 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
19938 GET_THREAD_INFO(%_ASM_DX)
19939 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
19940 jae bad_get_user
19941 +
19942 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19943 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
19944 + cmp %_ASM_DX,%_ASM_AX
19945 + jae 1234f
19946 + add %_ASM_DX,%_ASM_AX
19947 +1234:
19948 +#endif
19949 +
19950 4: movq -7(%_ASM_AX),%_ASM_DX
19951 xor %eax,%eax
19952 + pax_force_retaddr
19953 ret
19954 CFI_ENDPROC
19955 ENDPROC(__get_user_8)
19956 @@ -91,6 +152,7 @@ bad_get_user:
19957 CFI_STARTPROC
19958 xor %edx,%edx
19959 mov $(-EFAULT),%_ASM_AX
19960 + pax_force_retaddr
19961 ret
19962 CFI_ENDPROC
19963 END(bad_get_user)
19964 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
19965 index 374562e..a75830b 100644
19966 --- a/arch/x86/lib/insn.c
19967 +++ b/arch/x86/lib/insn.c
19968 @@ -21,6 +21,11 @@
19969 #include <linux/string.h>
19970 #include <asm/inat.h>
19971 #include <asm/insn.h>
19972 +#ifdef __KERNEL__
19973 +#include <asm/pgtable_types.h>
19974 +#else
19975 +#define ktla_ktva(addr) addr
19976 +#endif
19977
19978 /* Verify next sizeof(t) bytes can be on the same instruction */
19979 #define validate_next(t, insn, n) \
19980 @@ -49,8 +54,8 @@
19981 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
19982 {
19983 memset(insn, 0, sizeof(*insn));
19984 - insn->kaddr = kaddr;
19985 - insn->next_byte = kaddr;
19986 + insn->kaddr = ktla_ktva(kaddr);
19987 + insn->next_byte = ktla_ktva(kaddr);
19988 insn->x86_64 = x86_64 ? 1 : 0;
19989 insn->opnd_bytes = 4;
19990 if (x86_64)
19991 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
19992 index 05a95e7..326f2fa 100644
19993 --- a/arch/x86/lib/iomap_copy_64.S
19994 +++ b/arch/x86/lib/iomap_copy_64.S
19995 @@ -17,6 +17,7 @@
19996
19997 #include <linux/linkage.h>
19998 #include <asm/dwarf2.h>
19999 +#include <asm/alternative-asm.h>
20000
20001 /*
20002 * override generic version in lib/iomap_copy.c
20003 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
20004 CFI_STARTPROC
20005 movl %edx,%ecx
20006 rep movsd
20007 + pax_force_retaddr
20008 ret
20009 CFI_ENDPROC
20010 ENDPROC(__iowrite32_copy)
20011 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
20012 index efbf2a0..8893637 100644
20013 --- a/arch/x86/lib/memcpy_64.S
20014 +++ b/arch/x86/lib/memcpy_64.S
20015 @@ -34,6 +34,7 @@
20016 rep movsq
20017 movl %edx, %ecx
20018 rep movsb
20019 + pax_force_retaddr
20020 ret
20021 .Lmemcpy_e:
20022 .previous
20023 @@ -51,6 +52,7 @@
20024
20025 movl %edx, %ecx
20026 rep movsb
20027 + pax_force_retaddr
20028 ret
20029 .Lmemcpy_e_e:
20030 .previous
20031 @@ -81,13 +83,13 @@ ENTRY(memcpy)
20032 */
20033 movq 0*8(%rsi), %r8
20034 movq 1*8(%rsi), %r9
20035 - movq 2*8(%rsi), %r10
20036 + movq 2*8(%rsi), %rcx
20037 movq 3*8(%rsi), %r11
20038 leaq 4*8(%rsi), %rsi
20039
20040 movq %r8, 0*8(%rdi)
20041 movq %r9, 1*8(%rdi)
20042 - movq %r10, 2*8(%rdi)
20043 + movq %rcx, 2*8(%rdi)
20044 movq %r11, 3*8(%rdi)
20045 leaq 4*8(%rdi), %rdi
20046 jae .Lcopy_forward_loop
20047 @@ -110,12 +112,12 @@ ENTRY(memcpy)
20048 subq $0x20, %rdx
20049 movq -1*8(%rsi), %r8
20050 movq -2*8(%rsi), %r9
20051 - movq -3*8(%rsi), %r10
20052 + movq -3*8(%rsi), %rcx
20053 movq -4*8(%rsi), %r11
20054 leaq -4*8(%rsi), %rsi
20055 movq %r8, -1*8(%rdi)
20056 movq %r9, -2*8(%rdi)
20057 - movq %r10, -3*8(%rdi)
20058 + movq %rcx, -3*8(%rdi)
20059 movq %r11, -4*8(%rdi)
20060 leaq -4*8(%rdi), %rdi
20061 jae .Lcopy_backward_loop
20062 @@ -135,12 +137,13 @@ ENTRY(memcpy)
20063 */
20064 movq 0*8(%rsi), %r8
20065 movq 1*8(%rsi), %r9
20066 - movq -2*8(%rsi, %rdx), %r10
20067 + movq -2*8(%rsi, %rdx), %rcx
20068 movq -1*8(%rsi, %rdx), %r11
20069 movq %r8, 0*8(%rdi)
20070 movq %r9, 1*8(%rdi)
20071 - movq %r10, -2*8(%rdi, %rdx)
20072 + movq %rcx, -2*8(%rdi, %rdx)
20073 movq %r11, -1*8(%rdi, %rdx)
20074 + pax_force_retaddr
20075 retq
20076 .p2align 4
20077 .Lless_16bytes:
20078 @@ -153,6 +156,7 @@ ENTRY(memcpy)
20079 movq -1*8(%rsi, %rdx), %r9
20080 movq %r8, 0*8(%rdi)
20081 movq %r9, -1*8(%rdi, %rdx)
20082 + pax_force_retaddr
20083 retq
20084 .p2align 4
20085 .Lless_8bytes:
20086 @@ -166,6 +170,7 @@ ENTRY(memcpy)
20087 movl -4(%rsi, %rdx), %r8d
20088 movl %ecx, (%rdi)
20089 movl %r8d, -4(%rdi, %rdx)
20090 + pax_force_retaddr
20091 retq
20092 .p2align 4
20093 .Lless_3bytes:
20094 @@ -183,6 +188,7 @@ ENTRY(memcpy)
20095 jnz .Lloop_1
20096
20097 .Lend:
20098 + pax_force_retaddr
20099 retq
20100 CFI_ENDPROC
20101 ENDPROC(memcpy)
20102 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
20103 index ee16461..c39c199 100644
20104 --- a/arch/x86/lib/memmove_64.S
20105 +++ b/arch/x86/lib/memmove_64.S
20106 @@ -61,13 +61,13 @@ ENTRY(memmove)
20107 5:
20108 sub $0x20, %rdx
20109 movq 0*8(%rsi), %r11
20110 - movq 1*8(%rsi), %r10
20111 + movq 1*8(%rsi), %rcx
20112 movq 2*8(%rsi), %r9
20113 movq 3*8(%rsi), %r8
20114 leaq 4*8(%rsi), %rsi
20115
20116 movq %r11, 0*8(%rdi)
20117 - movq %r10, 1*8(%rdi)
20118 + movq %rcx, 1*8(%rdi)
20119 movq %r9, 2*8(%rdi)
20120 movq %r8, 3*8(%rdi)
20121 leaq 4*8(%rdi), %rdi
20122 @@ -81,10 +81,10 @@ ENTRY(memmove)
20123 4:
20124 movq %rdx, %rcx
20125 movq -8(%rsi, %rdx), %r11
20126 - lea -8(%rdi, %rdx), %r10
20127 + lea -8(%rdi, %rdx), %r9
20128 shrq $3, %rcx
20129 rep movsq
20130 - movq %r11, (%r10)
20131 + movq %r11, (%r9)
20132 jmp 13f
20133 .Lmemmove_end_forward:
20134
20135 @@ -95,14 +95,14 @@ ENTRY(memmove)
20136 7:
20137 movq %rdx, %rcx
20138 movq (%rsi), %r11
20139 - movq %rdi, %r10
20140 + movq %rdi, %r9
20141 leaq -8(%rsi, %rdx), %rsi
20142 leaq -8(%rdi, %rdx), %rdi
20143 shrq $3, %rcx
20144 std
20145 rep movsq
20146 cld
20147 - movq %r11, (%r10)
20148 + movq %r11, (%r9)
20149 jmp 13f
20150
20151 /*
20152 @@ -127,13 +127,13 @@ ENTRY(memmove)
20153 8:
20154 subq $0x20, %rdx
20155 movq -1*8(%rsi), %r11
20156 - movq -2*8(%rsi), %r10
20157 + movq -2*8(%rsi), %rcx
20158 movq -3*8(%rsi), %r9
20159 movq -4*8(%rsi), %r8
20160 leaq -4*8(%rsi), %rsi
20161
20162 movq %r11, -1*8(%rdi)
20163 - movq %r10, -2*8(%rdi)
20164 + movq %rcx, -2*8(%rdi)
20165 movq %r9, -3*8(%rdi)
20166 movq %r8, -4*8(%rdi)
20167 leaq -4*8(%rdi), %rdi
20168 @@ -151,11 +151,11 @@ ENTRY(memmove)
20169 * Move data from 16 bytes to 31 bytes.
20170 */
20171 movq 0*8(%rsi), %r11
20172 - movq 1*8(%rsi), %r10
20173 + movq 1*8(%rsi), %rcx
20174 movq -2*8(%rsi, %rdx), %r9
20175 movq -1*8(%rsi, %rdx), %r8
20176 movq %r11, 0*8(%rdi)
20177 - movq %r10, 1*8(%rdi)
20178 + movq %rcx, 1*8(%rdi)
20179 movq %r9, -2*8(%rdi, %rdx)
20180 movq %r8, -1*8(%rdi, %rdx)
20181 jmp 13f
20182 @@ -167,9 +167,9 @@ ENTRY(memmove)
20183 * Move data from 8 bytes to 15 bytes.
20184 */
20185 movq 0*8(%rsi), %r11
20186 - movq -1*8(%rsi, %rdx), %r10
20187 + movq -1*8(%rsi, %rdx), %r9
20188 movq %r11, 0*8(%rdi)
20189 - movq %r10, -1*8(%rdi, %rdx)
20190 + movq %r9, -1*8(%rdi, %rdx)
20191 jmp 13f
20192 10:
20193 cmpq $4, %rdx
20194 @@ -178,9 +178,9 @@ ENTRY(memmove)
20195 * Move data from 4 bytes to 7 bytes.
20196 */
20197 movl (%rsi), %r11d
20198 - movl -4(%rsi, %rdx), %r10d
20199 + movl -4(%rsi, %rdx), %r9d
20200 movl %r11d, (%rdi)
20201 - movl %r10d, -4(%rdi, %rdx)
20202 + movl %r9d, -4(%rdi, %rdx)
20203 jmp 13f
20204 11:
20205 cmp $2, %rdx
20206 @@ -189,9 +189,9 @@ ENTRY(memmove)
20207 * Move data from 2 bytes to 3 bytes.
20208 */
20209 movw (%rsi), %r11w
20210 - movw -2(%rsi, %rdx), %r10w
20211 + movw -2(%rsi, %rdx), %r9w
20212 movw %r11w, (%rdi)
20213 - movw %r10w, -2(%rdi, %rdx)
20214 + movw %r9w, -2(%rdi, %rdx)
20215 jmp 13f
20216 12:
20217 cmp $1, %rdx
20218 @@ -202,6 +202,7 @@ ENTRY(memmove)
20219 movb (%rsi), %r11b
20220 movb %r11b, (%rdi)
20221 13:
20222 + pax_force_retaddr
20223 retq
20224 CFI_ENDPROC
20225
20226 @@ -210,6 +211,7 @@ ENTRY(memmove)
20227 /* Forward moving data. */
20228 movq %rdx, %rcx
20229 rep movsb
20230 + pax_force_retaddr
20231 retq
20232 .Lmemmove_end_forward_efs:
20233 .previous
20234 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
20235 index 79bd454..dff325a 100644
20236 --- a/arch/x86/lib/memset_64.S
20237 +++ b/arch/x86/lib/memset_64.S
20238 @@ -31,6 +31,7 @@
20239 movl %r8d,%ecx
20240 rep stosb
20241 movq %r9,%rax
20242 + pax_force_retaddr
20243 ret
20244 .Lmemset_e:
20245 .previous
20246 @@ -53,6 +54,7 @@
20247 movl %edx,%ecx
20248 rep stosb
20249 movq %r9,%rax
20250 + pax_force_retaddr
20251 ret
20252 .Lmemset_e_e:
20253 .previous
20254 @@ -60,13 +62,13 @@
20255 ENTRY(memset)
20256 ENTRY(__memset)
20257 CFI_STARTPROC
20258 - movq %rdi,%r10
20259 movq %rdx,%r11
20260
20261 /* expand byte value */
20262 movzbl %sil,%ecx
20263 movabs $0x0101010101010101,%rax
20264 mul %rcx /* with rax, clobbers rdx */
20265 + movq %rdi,%rdx
20266
20267 /* align dst */
20268 movl %edi,%r9d
20269 @@ -120,7 +122,8 @@ ENTRY(__memset)
20270 jnz .Lloop_1
20271
20272 .Lende:
20273 - movq %r10,%rax
20274 + movq %rdx,%rax
20275 + pax_force_retaddr
20276 ret
20277
20278 CFI_RESTORE_STATE
20279 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
20280 index c9f2d9b..e7fd2c0 100644
20281 --- a/arch/x86/lib/mmx_32.c
20282 +++ b/arch/x86/lib/mmx_32.c
20283 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20284 {
20285 void *p;
20286 int i;
20287 + unsigned long cr0;
20288
20289 if (unlikely(in_interrupt()))
20290 return __memcpy(to, from, len);
20291 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
20292 kernel_fpu_begin();
20293
20294 __asm__ __volatile__ (
20295 - "1: prefetch (%0)\n" /* This set is 28 bytes */
20296 - " prefetch 64(%0)\n"
20297 - " prefetch 128(%0)\n"
20298 - " prefetch 192(%0)\n"
20299 - " prefetch 256(%0)\n"
20300 + "1: prefetch (%1)\n" /* This set is 28 bytes */
20301 + " prefetch 64(%1)\n"
20302 + " prefetch 128(%1)\n"
20303 + " prefetch 192(%1)\n"
20304 + " prefetch 256(%1)\n"
20305 "2: \n"
20306 ".section .fixup, \"ax\"\n"
20307 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20308 + "3: \n"
20309 +
20310 +#ifdef CONFIG_PAX_KERNEXEC
20311 + " movl %%cr0, %0\n"
20312 + " movl %0, %%eax\n"
20313 + " andl $0xFFFEFFFF, %%eax\n"
20314 + " movl %%eax, %%cr0\n"
20315 +#endif
20316 +
20317 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20318 +
20319 +#ifdef CONFIG_PAX_KERNEXEC
20320 + " movl %0, %%cr0\n"
20321 +#endif
20322 +
20323 " jmp 2b\n"
20324 ".previous\n"
20325 _ASM_EXTABLE(1b, 3b)
20326 - : : "r" (from));
20327 + : "=&r" (cr0) : "r" (from) : "ax");
20328
20329 for ( ; i > 5; i--) {
20330 __asm__ __volatile__ (
20331 - "1: prefetch 320(%0)\n"
20332 - "2: movq (%0), %%mm0\n"
20333 - " movq 8(%0), %%mm1\n"
20334 - " movq 16(%0), %%mm2\n"
20335 - " movq 24(%0), %%mm3\n"
20336 - " movq %%mm0, (%1)\n"
20337 - " movq %%mm1, 8(%1)\n"
20338 - " movq %%mm2, 16(%1)\n"
20339 - " movq %%mm3, 24(%1)\n"
20340 - " movq 32(%0), %%mm0\n"
20341 - " movq 40(%0), %%mm1\n"
20342 - " movq 48(%0), %%mm2\n"
20343 - " movq 56(%0), %%mm3\n"
20344 - " movq %%mm0, 32(%1)\n"
20345 - " movq %%mm1, 40(%1)\n"
20346 - " movq %%mm2, 48(%1)\n"
20347 - " movq %%mm3, 56(%1)\n"
20348 + "1: prefetch 320(%1)\n"
20349 + "2: movq (%1), %%mm0\n"
20350 + " movq 8(%1), %%mm1\n"
20351 + " movq 16(%1), %%mm2\n"
20352 + " movq 24(%1), %%mm3\n"
20353 + " movq %%mm0, (%2)\n"
20354 + " movq %%mm1, 8(%2)\n"
20355 + " movq %%mm2, 16(%2)\n"
20356 + " movq %%mm3, 24(%2)\n"
20357 + " movq 32(%1), %%mm0\n"
20358 + " movq 40(%1), %%mm1\n"
20359 + " movq 48(%1), %%mm2\n"
20360 + " movq 56(%1), %%mm3\n"
20361 + " movq %%mm0, 32(%2)\n"
20362 + " movq %%mm1, 40(%2)\n"
20363 + " movq %%mm2, 48(%2)\n"
20364 + " movq %%mm3, 56(%2)\n"
20365 ".section .fixup, \"ax\"\n"
20366 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20367 + "3:\n"
20368 +
20369 +#ifdef CONFIG_PAX_KERNEXEC
20370 + " movl %%cr0, %0\n"
20371 + " movl %0, %%eax\n"
20372 + " andl $0xFFFEFFFF, %%eax\n"
20373 + " movl %%eax, %%cr0\n"
20374 +#endif
20375 +
20376 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20377 +
20378 +#ifdef CONFIG_PAX_KERNEXEC
20379 + " movl %0, %%cr0\n"
20380 +#endif
20381 +
20382 " jmp 2b\n"
20383 ".previous\n"
20384 _ASM_EXTABLE(1b, 3b)
20385 - : : "r" (from), "r" (to) : "memory");
20386 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20387
20388 from += 64;
20389 to += 64;
20390 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
20391 static void fast_copy_page(void *to, void *from)
20392 {
20393 int i;
20394 + unsigned long cr0;
20395
20396 kernel_fpu_begin();
20397
20398 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
20399 * but that is for later. -AV
20400 */
20401 __asm__ __volatile__(
20402 - "1: prefetch (%0)\n"
20403 - " prefetch 64(%0)\n"
20404 - " prefetch 128(%0)\n"
20405 - " prefetch 192(%0)\n"
20406 - " prefetch 256(%0)\n"
20407 + "1: prefetch (%1)\n"
20408 + " prefetch 64(%1)\n"
20409 + " prefetch 128(%1)\n"
20410 + " prefetch 192(%1)\n"
20411 + " prefetch 256(%1)\n"
20412 "2: \n"
20413 ".section .fixup, \"ax\"\n"
20414 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20415 + "3: \n"
20416 +
20417 +#ifdef CONFIG_PAX_KERNEXEC
20418 + " movl %%cr0, %0\n"
20419 + " movl %0, %%eax\n"
20420 + " andl $0xFFFEFFFF, %%eax\n"
20421 + " movl %%eax, %%cr0\n"
20422 +#endif
20423 +
20424 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20425 +
20426 +#ifdef CONFIG_PAX_KERNEXEC
20427 + " movl %0, %%cr0\n"
20428 +#endif
20429 +
20430 " jmp 2b\n"
20431 ".previous\n"
20432 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20433 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20434
20435 for (i = 0; i < (4096-320)/64; i++) {
20436 __asm__ __volatile__ (
20437 - "1: prefetch 320(%0)\n"
20438 - "2: movq (%0), %%mm0\n"
20439 - " movntq %%mm0, (%1)\n"
20440 - " movq 8(%0), %%mm1\n"
20441 - " movntq %%mm1, 8(%1)\n"
20442 - " movq 16(%0), %%mm2\n"
20443 - " movntq %%mm2, 16(%1)\n"
20444 - " movq 24(%0), %%mm3\n"
20445 - " movntq %%mm3, 24(%1)\n"
20446 - " movq 32(%0), %%mm4\n"
20447 - " movntq %%mm4, 32(%1)\n"
20448 - " movq 40(%0), %%mm5\n"
20449 - " movntq %%mm5, 40(%1)\n"
20450 - " movq 48(%0), %%mm6\n"
20451 - " movntq %%mm6, 48(%1)\n"
20452 - " movq 56(%0), %%mm7\n"
20453 - " movntq %%mm7, 56(%1)\n"
20454 + "1: prefetch 320(%1)\n"
20455 + "2: movq (%1), %%mm0\n"
20456 + " movntq %%mm0, (%2)\n"
20457 + " movq 8(%1), %%mm1\n"
20458 + " movntq %%mm1, 8(%2)\n"
20459 + " movq 16(%1), %%mm2\n"
20460 + " movntq %%mm2, 16(%2)\n"
20461 + " movq 24(%1), %%mm3\n"
20462 + " movntq %%mm3, 24(%2)\n"
20463 + " movq 32(%1), %%mm4\n"
20464 + " movntq %%mm4, 32(%2)\n"
20465 + " movq 40(%1), %%mm5\n"
20466 + " movntq %%mm5, 40(%2)\n"
20467 + " movq 48(%1), %%mm6\n"
20468 + " movntq %%mm6, 48(%2)\n"
20469 + " movq 56(%1), %%mm7\n"
20470 + " movntq %%mm7, 56(%2)\n"
20471 ".section .fixup, \"ax\"\n"
20472 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20473 + "3:\n"
20474 +
20475 +#ifdef CONFIG_PAX_KERNEXEC
20476 + " movl %%cr0, %0\n"
20477 + " movl %0, %%eax\n"
20478 + " andl $0xFFFEFFFF, %%eax\n"
20479 + " movl %%eax, %%cr0\n"
20480 +#endif
20481 +
20482 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20483 +
20484 +#ifdef CONFIG_PAX_KERNEXEC
20485 + " movl %0, %%cr0\n"
20486 +#endif
20487 +
20488 " jmp 2b\n"
20489 ".previous\n"
20490 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
20491 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20492
20493 from += 64;
20494 to += 64;
20495 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
20496 static void fast_copy_page(void *to, void *from)
20497 {
20498 int i;
20499 + unsigned long cr0;
20500
20501 kernel_fpu_begin();
20502
20503 __asm__ __volatile__ (
20504 - "1: prefetch (%0)\n"
20505 - " prefetch 64(%0)\n"
20506 - " prefetch 128(%0)\n"
20507 - " prefetch 192(%0)\n"
20508 - " prefetch 256(%0)\n"
20509 + "1: prefetch (%1)\n"
20510 + " prefetch 64(%1)\n"
20511 + " prefetch 128(%1)\n"
20512 + " prefetch 192(%1)\n"
20513 + " prefetch 256(%1)\n"
20514 "2: \n"
20515 ".section .fixup, \"ax\"\n"
20516 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20517 + "3: \n"
20518 +
20519 +#ifdef CONFIG_PAX_KERNEXEC
20520 + " movl %%cr0, %0\n"
20521 + " movl %0, %%eax\n"
20522 + " andl $0xFFFEFFFF, %%eax\n"
20523 + " movl %%eax, %%cr0\n"
20524 +#endif
20525 +
20526 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
20527 +
20528 +#ifdef CONFIG_PAX_KERNEXEC
20529 + " movl %0, %%cr0\n"
20530 +#endif
20531 +
20532 " jmp 2b\n"
20533 ".previous\n"
20534 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
20535 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
20536
20537 for (i = 0; i < 4096/64; i++) {
20538 __asm__ __volatile__ (
20539 - "1: prefetch 320(%0)\n"
20540 - "2: movq (%0), %%mm0\n"
20541 - " movq 8(%0), %%mm1\n"
20542 - " movq 16(%0), %%mm2\n"
20543 - " movq 24(%0), %%mm3\n"
20544 - " movq %%mm0, (%1)\n"
20545 - " movq %%mm1, 8(%1)\n"
20546 - " movq %%mm2, 16(%1)\n"
20547 - " movq %%mm3, 24(%1)\n"
20548 - " movq 32(%0), %%mm0\n"
20549 - " movq 40(%0), %%mm1\n"
20550 - " movq 48(%0), %%mm2\n"
20551 - " movq 56(%0), %%mm3\n"
20552 - " movq %%mm0, 32(%1)\n"
20553 - " movq %%mm1, 40(%1)\n"
20554 - " movq %%mm2, 48(%1)\n"
20555 - " movq %%mm3, 56(%1)\n"
20556 + "1: prefetch 320(%1)\n"
20557 + "2: movq (%1), %%mm0\n"
20558 + " movq 8(%1), %%mm1\n"
20559 + " movq 16(%1), %%mm2\n"
20560 + " movq 24(%1), %%mm3\n"
20561 + " movq %%mm0, (%2)\n"
20562 + " movq %%mm1, 8(%2)\n"
20563 + " movq %%mm2, 16(%2)\n"
20564 + " movq %%mm3, 24(%2)\n"
20565 + " movq 32(%1), %%mm0\n"
20566 + " movq 40(%1), %%mm1\n"
20567 + " movq 48(%1), %%mm2\n"
20568 + " movq 56(%1), %%mm3\n"
20569 + " movq %%mm0, 32(%2)\n"
20570 + " movq %%mm1, 40(%2)\n"
20571 + " movq %%mm2, 48(%2)\n"
20572 + " movq %%mm3, 56(%2)\n"
20573 ".section .fixup, \"ax\"\n"
20574 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20575 + "3:\n"
20576 +
20577 +#ifdef CONFIG_PAX_KERNEXEC
20578 + " movl %%cr0, %0\n"
20579 + " movl %0, %%eax\n"
20580 + " andl $0xFFFEFFFF, %%eax\n"
20581 + " movl %%eax, %%cr0\n"
20582 +#endif
20583 +
20584 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
20585 +
20586 +#ifdef CONFIG_PAX_KERNEXEC
20587 + " movl %0, %%cr0\n"
20588 +#endif
20589 +
20590 " jmp 2b\n"
20591 ".previous\n"
20592 _ASM_EXTABLE(1b, 3b)
20593 - : : "r" (from), "r" (to) : "memory");
20594 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
20595
20596 from += 64;
20597 to += 64;
20598 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
20599 index 69fa106..adda88b 100644
20600 --- a/arch/x86/lib/msr-reg.S
20601 +++ b/arch/x86/lib/msr-reg.S
20602 @@ -3,6 +3,7 @@
20603 #include <asm/dwarf2.h>
20604 #include <asm/asm.h>
20605 #include <asm/msr.h>
20606 +#include <asm/alternative-asm.h>
20607
20608 #ifdef CONFIG_X86_64
20609 /*
20610 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
20611 CFI_STARTPROC
20612 pushq_cfi %rbx
20613 pushq_cfi %rbp
20614 - movq %rdi, %r10 /* Save pointer */
20615 + movq %rdi, %r9 /* Save pointer */
20616 xorl %r11d, %r11d /* Return value */
20617 movl (%rdi), %eax
20618 movl 4(%rdi), %ecx
20619 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
20620 movl 28(%rdi), %edi
20621 CFI_REMEMBER_STATE
20622 1: \op
20623 -2: movl %eax, (%r10)
20624 +2: movl %eax, (%r9)
20625 movl %r11d, %eax /* Return value */
20626 - movl %ecx, 4(%r10)
20627 - movl %edx, 8(%r10)
20628 - movl %ebx, 12(%r10)
20629 - movl %ebp, 20(%r10)
20630 - movl %esi, 24(%r10)
20631 - movl %edi, 28(%r10)
20632 + movl %ecx, 4(%r9)
20633 + movl %edx, 8(%r9)
20634 + movl %ebx, 12(%r9)
20635 + movl %ebp, 20(%r9)
20636 + movl %esi, 24(%r9)
20637 + movl %edi, 28(%r9)
20638 popq_cfi %rbp
20639 popq_cfi %rbx
20640 + pax_force_retaddr
20641 ret
20642 3:
20643 CFI_RESTORE_STATE
20644 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
20645 index 36b0d15..d381858 100644
20646 --- a/arch/x86/lib/putuser.S
20647 +++ b/arch/x86/lib/putuser.S
20648 @@ -15,7 +15,9 @@
20649 #include <asm/thread_info.h>
20650 #include <asm/errno.h>
20651 #include <asm/asm.h>
20652 -
20653 +#include <asm/segment.h>
20654 +#include <asm/pgtable.h>
20655 +#include <asm/alternative-asm.h>
20656
20657 /*
20658 * __put_user_X
20659 @@ -29,52 +31,119 @@
20660 * as they get called from within inline assembly.
20661 */
20662
20663 -#define ENTER CFI_STARTPROC ; \
20664 - GET_THREAD_INFO(%_ASM_BX)
20665 -#define EXIT ret ; \
20666 +#define ENTER CFI_STARTPROC
20667 +#define EXIT pax_force_retaddr; ret ; \
20668 CFI_ENDPROC
20669
20670 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20671 +#define _DEST %_ASM_CX,%_ASM_BX
20672 +#else
20673 +#define _DEST %_ASM_CX
20674 +#endif
20675 +
20676 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20677 +#define __copyuser_seg gs;
20678 +#else
20679 +#define __copyuser_seg
20680 +#endif
20681 +
20682 .text
20683 ENTRY(__put_user_1)
20684 ENTER
20685 +
20686 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20687 + GET_THREAD_INFO(%_ASM_BX)
20688 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
20689 jae bad_put_user
20690 -1: movb %al,(%_ASM_CX)
20691 +
20692 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20693 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20694 + cmp %_ASM_BX,%_ASM_CX
20695 + jb 1234f
20696 + xor %ebx,%ebx
20697 +1234:
20698 +#endif
20699 +
20700 +#endif
20701 +
20702 +1: __copyuser_seg movb %al,(_DEST)
20703 xor %eax,%eax
20704 EXIT
20705 ENDPROC(__put_user_1)
20706
20707 ENTRY(__put_user_2)
20708 ENTER
20709 +
20710 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20711 + GET_THREAD_INFO(%_ASM_BX)
20712 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20713 sub $1,%_ASM_BX
20714 cmp %_ASM_BX,%_ASM_CX
20715 jae bad_put_user
20716 -2: movw %ax,(%_ASM_CX)
20717 +
20718 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20719 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20720 + cmp %_ASM_BX,%_ASM_CX
20721 + jb 1234f
20722 + xor %ebx,%ebx
20723 +1234:
20724 +#endif
20725 +
20726 +#endif
20727 +
20728 +2: __copyuser_seg movw %ax,(_DEST)
20729 xor %eax,%eax
20730 EXIT
20731 ENDPROC(__put_user_2)
20732
20733 ENTRY(__put_user_4)
20734 ENTER
20735 +
20736 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20737 + GET_THREAD_INFO(%_ASM_BX)
20738 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20739 sub $3,%_ASM_BX
20740 cmp %_ASM_BX,%_ASM_CX
20741 jae bad_put_user
20742 -3: movl %eax,(%_ASM_CX)
20743 +
20744 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20745 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20746 + cmp %_ASM_BX,%_ASM_CX
20747 + jb 1234f
20748 + xor %ebx,%ebx
20749 +1234:
20750 +#endif
20751 +
20752 +#endif
20753 +
20754 +3: __copyuser_seg movl %eax,(_DEST)
20755 xor %eax,%eax
20756 EXIT
20757 ENDPROC(__put_user_4)
20758
20759 ENTRY(__put_user_8)
20760 ENTER
20761 +
20762 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
20763 + GET_THREAD_INFO(%_ASM_BX)
20764 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
20765 sub $7,%_ASM_BX
20766 cmp %_ASM_BX,%_ASM_CX
20767 jae bad_put_user
20768 -4: mov %_ASM_AX,(%_ASM_CX)
20769 +
20770 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20771 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
20772 + cmp %_ASM_BX,%_ASM_CX
20773 + jb 1234f
20774 + xor %ebx,%ebx
20775 +1234:
20776 +#endif
20777 +
20778 +#endif
20779 +
20780 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
20781 #ifdef CONFIG_X86_32
20782 -5: movl %edx,4(%_ASM_CX)
20783 +5: __copyuser_seg movl %edx,4(_DEST)
20784 #endif
20785 xor %eax,%eax
20786 EXIT
20787 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
20788 index 1cad221..de671ee 100644
20789 --- a/arch/x86/lib/rwlock.S
20790 +++ b/arch/x86/lib/rwlock.S
20791 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
20792 FRAME
20793 0: LOCK_PREFIX
20794 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20795 +
20796 +#ifdef CONFIG_PAX_REFCOUNT
20797 + jno 1234f
20798 + LOCK_PREFIX
20799 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20800 + int $4
20801 +1234:
20802 + _ASM_EXTABLE(1234b, 1234b)
20803 +#endif
20804 +
20805 1: rep; nop
20806 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
20807 jne 1b
20808 LOCK_PREFIX
20809 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
20810 +
20811 +#ifdef CONFIG_PAX_REFCOUNT
20812 + jno 1234f
20813 + LOCK_PREFIX
20814 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
20815 + int $4
20816 +1234:
20817 + _ASM_EXTABLE(1234b, 1234b)
20818 +#endif
20819 +
20820 jnz 0b
20821 ENDFRAME
20822 + pax_force_retaddr
20823 ret
20824 CFI_ENDPROC
20825 END(__write_lock_failed)
20826 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
20827 FRAME
20828 0: LOCK_PREFIX
20829 READ_LOCK_SIZE(inc) (%__lock_ptr)
20830 +
20831 +#ifdef CONFIG_PAX_REFCOUNT
20832 + jno 1234f
20833 + LOCK_PREFIX
20834 + READ_LOCK_SIZE(dec) (%__lock_ptr)
20835 + int $4
20836 +1234:
20837 + _ASM_EXTABLE(1234b, 1234b)
20838 +#endif
20839 +
20840 1: rep; nop
20841 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
20842 js 1b
20843 LOCK_PREFIX
20844 READ_LOCK_SIZE(dec) (%__lock_ptr)
20845 +
20846 +#ifdef CONFIG_PAX_REFCOUNT
20847 + jno 1234f
20848 + LOCK_PREFIX
20849 + READ_LOCK_SIZE(inc) (%__lock_ptr)
20850 + int $4
20851 +1234:
20852 + _ASM_EXTABLE(1234b, 1234b)
20853 +#endif
20854 +
20855 js 0b
20856 ENDFRAME
20857 + pax_force_retaddr
20858 ret
20859 CFI_ENDPROC
20860 END(__read_lock_failed)
20861 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
20862 index 5dff5f0..cadebf4 100644
20863 --- a/arch/x86/lib/rwsem.S
20864 +++ b/arch/x86/lib/rwsem.S
20865 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
20866 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20867 CFI_RESTORE __ASM_REG(dx)
20868 restore_common_regs
20869 + pax_force_retaddr
20870 ret
20871 CFI_ENDPROC
20872 ENDPROC(call_rwsem_down_read_failed)
20873 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
20874 movq %rax,%rdi
20875 call rwsem_down_write_failed
20876 restore_common_regs
20877 + pax_force_retaddr
20878 ret
20879 CFI_ENDPROC
20880 ENDPROC(call_rwsem_down_write_failed)
20881 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
20882 movq %rax,%rdi
20883 call rwsem_wake
20884 restore_common_regs
20885 -1: ret
20886 +1: pax_force_retaddr
20887 + ret
20888 CFI_ENDPROC
20889 ENDPROC(call_rwsem_wake)
20890
20891 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
20892 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
20893 CFI_RESTORE __ASM_REG(dx)
20894 restore_common_regs
20895 + pax_force_retaddr
20896 ret
20897 CFI_ENDPROC
20898 ENDPROC(call_rwsem_downgrade_wake)
20899 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
20900 index a63efd6..ccecad8 100644
20901 --- a/arch/x86/lib/thunk_64.S
20902 +++ b/arch/x86/lib/thunk_64.S
20903 @@ -8,6 +8,7 @@
20904 #include <linux/linkage.h>
20905 #include <asm/dwarf2.h>
20906 #include <asm/calling.h>
20907 +#include <asm/alternative-asm.h>
20908
20909 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
20910 .macro THUNK name, func, put_ret_addr_in_rdi=0
20911 @@ -41,5 +42,6 @@
20912 SAVE_ARGS
20913 restore:
20914 RESTORE_ARGS
20915 + pax_force_retaddr
20916 ret
20917 CFI_ENDPROC
20918 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
20919 index e218d5d..35679b4 100644
20920 --- a/arch/x86/lib/usercopy_32.c
20921 +++ b/arch/x86/lib/usercopy_32.c
20922 @@ -43,7 +43,7 @@ do { \
20923 __asm__ __volatile__( \
20924 " testl %1,%1\n" \
20925 " jz 2f\n" \
20926 - "0: lodsb\n" \
20927 + "0: "__copyuser_seg"lodsb\n" \
20928 " stosb\n" \
20929 " testb %%al,%%al\n" \
20930 " jz 1f\n" \
20931 @@ -128,10 +128,12 @@ do { \
20932 int __d0; \
20933 might_fault(); \
20934 __asm__ __volatile__( \
20935 + __COPYUSER_SET_ES \
20936 "0: rep; stosl\n" \
20937 " movl %2,%0\n" \
20938 "1: rep; stosb\n" \
20939 "2:\n" \
20940 + __COPYUSER_RESTORE_ES \
20941 ".section .fixup,\"ax\"\n" \
20942 "3: lea 0(%2,%0,4),%0\n" \
20943 " jmp 2b\n" \
20944 @@ -200,6 +202,7 @@ long strnlen_user(const char __user *s, long n)
20945 might_fault();
20946
20947 __asm__ __volatile__(
20948 + __COPYUSER_SET_ES
20949 " testl %0, %0\n"
20950 " jz 3f\n"
20951 " andl %0,%%ecx\n"
20952 @@ -208,6 +211,7 @@ long strnlen_user(const char __user *s, long n)
20953 " subl %%ecx,%0\n"
20954 " addl %0,%%eax\n"
20955 "1:\n"
20956 + __COPYUSER_RESTORE_ES
20957 ".section .fixup,\"ax\"\n"
20958 "2: xorl %%eax,%%eax\n"
20959 " jmp 1b\n"
20960 @@ -227,7 +231,7 @@ EXPORT_SYMBOL(strnlen_user);
20961
20962 #ifdef CONFIG_X86_INTEL_USERCOPY
20963 static unsigned long
20964 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
20965 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
20966 {
20967 int d0, d1;
20968 __asm__ __volatile__(
20969 @@ -239,36 +243,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
20970 " .align 2,0x90\n"
20971 "3: movl 0(%4), %%eax\n"
20972 "4: movl 4(%4), %%edx\n"
20973 - "5: movl %%eax, 0(%3)\n"
20974 - "6: movl %%edx, 4(%3)\n"
20975 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
20976 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
20977 "7: movl 8(%4), %%eax\n"
20978 "8: movl 12(%4),%%edx\n"
20979 - "9: movl %%eax, 8(%3)\n"
20980 - "10: movl %%edx, 12(%3)\n"
20981 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
20982 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
20983 "11: movl 16(%4), %%eax\n"
20984 "12: movl 20(%4), %%edx\n"
20985 - "13: movl %%eax, 16(%3)\n"
20986 - "14: movl %%edx, 20(%3)\n"
20987 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
20988 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
20989 "15: movl 24(%4), %%eax\n"
20990 "16: movl 28(%4), %%edx\n"
20991 - "17: movl %%eax, 24(%3)\n"
20992 - "18: movl %%edx, 28(%3)\n"
20993 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
20994 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
20995 "19: movl 32(%4), %%eax\n"
20996 "20: movl 36(%4), %%edx\n"
20997 - "21: movl %%eax, 32(%3)\n"
20998 - "22: movl %%edx, 36(%3)\n"
20999 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
21000 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
21001 "23: movl 40(%4), %%eax\n"
21002 "24: movl 44(%4), %%edx\n"
21003 - "25: movl %%eax, 40(%3)\n"
21004 - "26: movl %%edx, 44(%3)\n"
21005 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
21006 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
21007 "27: movl 48(%4), %%eax\n"
21008 "28: movl 52(%4), %%edx\n"
21009 - "29: movl %%eax, 48(%3)\n"
21010 - "30: movl %%edx, 52(%3)\n"
21011 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
21012 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
21013 "31: movl 56(%4), %%eax\n"
21014 "32: movl 60(%4), %%edx\n"
21015 - "33: movl %%eax, 56(%3)\n"
21016 - "34: movl %%edx, 60(%3)\n"
21017 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
21018 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
21019 " addl $-64, %0\n"
21020 " addl $64, %4\n"
21021 " addl $64, %3\n"
21022 @@ -278,10 +282,119 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
21023 " shrl $2, %0\n"
21024 " andl $3, %%eax\n"
21025 " cld\n"
21026 + __COPYUSER_SET_ES
21027 "99: rep; movsl\n"
21028 "36: movl %%eax, %0\n"
21029 "37: rep; movsb\n"
21030 "100:\n"
21031 + __COPYUSER_RESTORE_ES
21032 + ".section .fixup,\"ax\"\n"
21033 + "101: lea 0(%%eax,%0,4),%0\n"
21034 + " jmp 100b\n"
21035 + ".previous\n"
21036 + ".section __ex_table,\"a\"\n"
21037 + " .align 4\n"
21038 + " .long 1b,100b\n"
21039 + " .long 2b,100b\n"
21040 + " .long 3b,100b\n"
21041 + " .long 4b,100b\n"
21042 + " .long 5b,100b\n"
21043 + " .long 6b,100b\n"
21044 + " .long 7b,100b\n"
21045 + " .long 8b,100b\n"
21046 + " .long 9b,100b\n"
21047 + " .long 10b,100b\n"
21048 + " .long 11b,100b\n"
21049 + " .long 12b,100b\n"
21050 + " .long 13b,100b\n"
21051 + " .long 14b,100b\n"
21052 + " .long 15b,100b\n"
21053 + " .long 16b,100b\n"
21054 + " .long 17b,100b\n"
21055 + " .long 18b,100b\n"
21056 + " .long 19b,100b\n"
21057 + " .long 20b,100b\n"
21058 + " .long 21b,100b\n"
21059 + " .long 22b,100b\n"
21060 + " .long 23b,100b\n"
21061 + " .long 24b,100b\n"
21062 + " .long 25b,100b\n"
21063 + " .long 26b,100b\n"
21064 + " .long 27b,100b\n"
21065 + " .long 28b,100b\n"
21066 + " .long 29b,100b\n"
21067 + " .long 30b,100b\n"
21068 + " .long 31b,100b\n"
21069 + " .long 32b,100b\n"
21070 + " .long 33b,100b\n"
21071 + " .long 34b,100b\n"
21072 + " .long 35b,100b\n"
21073 + " .long 36b,100b\n"
21074 + " .long 37b,100b\n"
21075 + " .long 99b,101b\n"
21076 + ".previous"
21077 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
21078 + : "1"(to), "2"(from), "0"(size)
21079 + : "eax", "edx", "memory");
21080 + return size;
21081 +}
21082 +
21083 +static unsigned long
21084 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
21085 +{
21086 + int d0, d1;
21087 + __asm__ __volatile__(
21088 + " .align 2,0x90\n"
21089 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
21090 + " cmpl $67, %0\n"
21091 + " jbe 3f\n"
21092 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
21093 + " .align 2,0x90\n"
21094 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
21095 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
21096 + "5: movl %%eax, 0(%3)\n"
21097 + "6: movl %%edx, 4(%3)\n"
21098 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
21099 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
21100 + "9: movl %%eax, 8(%3)\n"
21101 + "10: movl %%edx, 12(%3)\n"
21102 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
21103 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
21104 + "13: movl %%eax, 16(%3)\n"
21105 + "14: movl %%edx, 20(%3)\n"
21106 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
21107 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
21108 + "17: movl %%eax, 24(%3)\n"
21109 + "18: movl %%edx, 28(%3)\n"
21110 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
21111 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
21112 + "21: movl %%eax, 32(%3)\n"
21113 + "22: movl %%edx, 36(%3)\n"
21114 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
21115 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
21116 + "25: movl %%eax, 40(%3)\n"
21117 + "26: movl %%edx, 44(%3)\n"
21118 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
21119 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
21120 + "29: movl %%eax, 48(%3)\n"
21121 + "30: movl %%edx, 52(%3)\n"
21122 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
21123 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
21124 + "33: movl %%eax, 56(%3)\n"
21125 + "34: movl %%edx, 60(%3)\n"
21126 + " addl $-64, %0\n"
21127 + " addl $64, %4\n"
21128 + " addl $64, %3\n"
21129 + " cmpl $63, %0\n"
21130 + " ja 1b\n"
21131 + "35: movl %0, %%eax\n"
21132 + " shrl $2, %0\n"
21133 + " andl $3, %%eax\n"
21134 + " cld\n"
21135 + "99: rep; "__copyuser_seg" movsl\n"
21136 + "36: movl %%eax, %0\n"
21137 + "37: rep; "__copyuser_seg" movsb\n"
21138 + "100:\n"
21139 ".section .fixup,\"ax\"\n"
21140 "101: lea 0(%%eax,%0,4),%0\n"
21141 " jmp 100b\n"
21142 @@ -339,41 +452,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
21143 int d0, d1;
21144 __asm__ __volatile__(
21145 " .align 2,0x90\n"
21146 - "0: movl 32(%4), %%eax\n"
21147 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21148 " cmpl $67, %0\n"
21149 " jbe 2f\n"
21150 - "1: movl 64(%4), %%eax\n"
21151 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21152 " .align 2,0x90\n"
21153 - "2: movl 0(%4), %%eax\n"
21154 - "21: movl 4(%4), %%edx\n"
21155 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21156 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21157 " movl %%eax, 0(%3)\n"
21158 " movl %%edx, 4(%3)\n"
21159 - "3: movl 8(%4), %%eax\n"
21160 - "31: movl 12(%4),%%edx\n"
21161 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21162 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21163 " movl %%eax, 8(%3)\n"
21164 " movl %%edx, 12(%3)\n"
21165 - "4: movl 16(%4), %%eax\n"
21166 - "41: movl 20(%4), %%edx\n"
21167 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21168 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21169 " movl %%eax, 16(%3)\n"
21170 " movl %%edx, 20(%3)\n"
21171 - "10: movl 24(%4), %%eax\n"
21172 - "51: movl 28(%4), %%edx\n"
21173 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21174 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21175 " movl %%eax, 24(%3)\n"
21176 " movl %%edx, 28(%3)\n"
21177 - "11: movl 32(%4), %%eax\n"
21178 - "61: movl 36(%4), %%edx\n"
21179 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21180 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21181 " movl %%eax, 32(%3)\n"
21182 " movl %%edx, 36(%3)\n"
21183 - "12: movl 40(%4), %%eax\n"
21184 - "71: movl 44(%4), %%edx\n"
21185 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21186 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21187 " movl %%eax, 40(%3)\n"
21188 " movl %%edx, 44(%3)\n"
21189 - "13: movl 48(%4), %%eax\n"
21190 - "81: movl 52(%4), %%edx\n"
21191 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21192 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21193 " movl %%eax, 48(%3)\n"
21194 " movl %%edx, 52(%3)\n"
21195 - "14: movl 56(%4), %%eax\n"
21196 - "91: movl 60(%4), %%edx\n"
21197 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21198 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21199 " movl %%eax, 56(%3)\n"
21200 " movl %%edx, 60(%3)\n"
21201 " addl $-64, %0\n"
21202 @@ -385,9 +498,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
21203 " shrl $2, %0\n"
21204 " andl $3, %%eax\n"
21205 " cld\n"
21206 - "6: rep; movsl\n"
21207 + "6: rep; "__copyuser_seg" movsl\n"
21208 " movl %%eax,%0\n"
21209 - "7: rep; movsb\n"
21210 + "7: rep; "__copyuser_seg" movsb\n"
21211 "8:\n"
21212 ".section .fixup,\"ax\"\n"
21213 "9: lea 0(%%eax,%0,4),%0\n"
21214 @@ -440,41 +553,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21215
21216 __asm__ __volatile__(
21217 " .align 2,0x90\n"
21218 - "0: movl 32(%4), %%eax\n"
21219 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21220 " cmpl $67, %0\n"
21221 " jbe 2f\n"
21222 - "1: movl 64(%4), %%eax\n"
21223 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21224 " .align 2,0x90\n"
21225 - "2: movl 0(%4), %%eax\n"
21226 - "21: movl 4(%4), %%edx\n"
21227 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21228 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21229 " movnti %%eax, 0(%3)\n"
21230 " movnti %%edx, 4(%3)\n"
21231 - "3: movl 8(%4), %%eax\n"
21232 - "31: movl 12(%4),%%edx\n"
21233 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21234 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21235 " movnti %%eax, 8(%3)\n"
21236 " movnti %%edx, 12(%3)\n"
21237 - "4: movl 16(%4), %%eax\n"
21238 - "41: movl 20(%4), %%edx\n"
21239 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21240 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21241 " movnti %%eax, 16(%3)\n"
21242 " movnti %%edx, 20(%3)\n"
21243 - "10: movl 24(%4), %%eax\n"
21244 - "51: movl 28(%4), %%edx\n"
21245 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21246 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21247 " movnti %%eax, 24(%3)\n"
21248 " movnti %%edx, 28(%3)\n"
21249 - "11: movl 32(%4), %%eax\n"
21250 - "61: movl 36(%4), %%edx\n"
21251 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21252 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21253 " movnti %%eax, 32(%3)\n"
21254 " movnti %%edx, 36(%3)\n"
21255 - "12: movl 40(%4), %%eax\n"
21256 - "71: movl 44(%4), %%edx\n"
21257 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21258 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21259 " movnti %%eax, 40(%3)\n"
21260 " movnti %%edx, 44(%3)\n"
21261 - "13: movl 48(%4), %%eax\n"
21262 - "81: movl 52(%4), %%edx\n"
21263 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21264 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21265 " movnti %%eax, 48(%3)\n"
21266 " movnti %%edx, 52(%3)\n"
21267 - "14: movl 56(%4), %%eax\n"
21268 - "91: movl 60(%4), %%edx\n"
21269 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21270 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21271 " movnti %%eax, 56(%3)\n"
21272 " movnti %%edx, 60(%3)\n"
21273 " addl $-64, %0\n"
21274 @@ -487,9 +600,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
21275 " shrl $2, %0\n"
21276 " andl $3, %%eax\n"
21277 " cld\n"
21278 - "6: rep; movsl\n"
21279 + "6: rep; "__copyuser_seg" movsl\n"
21280 " movl %%eax,%0\n"
21281 - "7: rep; movsb\n"
21282 + "7: rep; "__copyuser_seg" movsb\n"
21283 "8:\n"
21284 ".section .fixup,\"ax\"\n"
21285 "9: lea 0(%%eax,%0,4),%0\n"
21286 @@ -537,41 +650,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
21287
21288 __asm__ __volatile__(
21289 " .align 2,0x90\n"
21290 - "0: movl 32(%4), %%eax\n"
21291 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
21292 " cmpl $67, %0\n"
21293 " jbe 2f\n"
21294 - "1: movl 64(%4), %%eax\n"
21295 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
21296 " .align 2,0x90\n"
21297 - "2: movl 0(%4), %%eax\n"
21298 - "21: movl 4(%4), %%edx\n"
21299 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
21300 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
21301 " movnti %%eax, 0(%3)\n"
21302 " movnti %%edx, 4(%3)\n"
21303 - "3: movl 8(%4), %%eax\n"
21304 - "31: movl 12(%4),%%edx\n"
21305 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
21306 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
21307 " movnti %%eax, 8(%3)\n"
21308 " movnti %%edx, 12(%3)\n"
21309 - "4: movl 16(%4), %%eax\n"
21310 - "41: movl 20(%4), %%edx\n"
21311 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
21312 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
21313 " movnti %%eax, 16(%3)\n"
21314 " movnti %%edx, 20(%3)\n"
21315 - "10: movl 24(%4), %%eax\n"
21316 - "51: movl 28(%4), %%edx\n"
21317 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
21318 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
21319 " movnti %%eax, 24(%3)\n"
21320 " movnti %%edx, 28(%3)\n"
21321 - "11: movl 32(%4), %%eax\n"
21322 - "61: movl 36(%4), %%edx\n"
21323 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
21324 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
21325 " movnti %%eax, 32(%3)\n"
21326 " movnti %%edx, 36(%3)\n"
21327 - "12: movl 40(%4), %%eax\n"
21328 - "71: movl 44(%4), %%edx\n"
21329 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
21330 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
21331 " movnti %%eax, 40(%3)\n"
21332 " movnti %%edx, 44(%3)\n"
21333 - "13: movl 48(%4), %%eax\n"
21334 - "81: movl 52(%4), %%edx\n"
21335 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
21336 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
21337 " movnti %%eax, 48(%3)\n"
21338 " movnti %%edx, 52(%3)\n"
21339 - "14: movl 56(%4), %%eax\n"
21340 - "91: movl 60(%4), %%edx\n"
21341 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
21342 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
21343 " movnti %%eax, 56(%3)\n"
21344 " movnti %%edx, 60(%3)\n"
21345 " addl $-64, %0\n"
21346 @@ -584,9 +697,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
21347 " shrl $2, %0\n"
21348 " andl $3, %%eax\n"
21349 " cld\n"
21350 - "6: rep; movsl\n"
21351 + "6: rep; "__copyuser_seg" movsl\n"
21352 " movl %%eax,%0\n"
21353 - "7: rep; movsb\n"
21354 + "7: rep; "__copyuser_seg" movsb\n"
21355 "8:\n"
21356 ".section .fixup,\"ax\"\n"
21357 "9: lea 0(%%eax,%0,4),%0\n"
21358 @@ -629,32 +742,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
21359 */
21360 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
21361 unsigned long size);
21362 -unsigned long __copy_user_intel(void __user *to, const void *from,
21363 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
21364 + unsigned long size);
21365 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
21366 unsigned long size);
21367 unsigned long __copy_user_zeroing_intel_nocache(void *to,
21368 const void __user *from, unsigned long size);
21369 #endif /* CONFIG_X86_INTEL_USERCOPY */
21370
21371 /* Generic arbitrary sized copy. */
21372 -#define __copy_user(to, from, size) \
21373 +#define __copy_user(to, from, size, prefix, set, restore) \
21374 do { \
21375 int __d0, __d1, __d2; \
21376 __asm__ __volatile__( \
21377 + set \
21378 " cmp $7,%0\n" \
21379 " jbe 1f\n" \
21380 " movl %1,%0\n" \
21381 " negl %0\n" \
21382 " andl $7,%0\n" \
21383 " subl %0,%3\n" \
21384 - "4: rep; movsb\n" \
21385 + "4: rep; "prefix"movsb\n" \
21386 " movl %3,%0\n" \
21387 " shrl $2,%0\n" \
21388 " andl $3,%3\n" \
21389 " .align 2,0x90\n" \
21390 - "0: rep; movsl\n" \
21391 + "0: rep; "prefix"movsl\n" \
21392 " movl %3,%0\n" \
21393 - "1: rep; movsb\n" \
21394 + "1: rep; "prefix"movsb\n" \
21395 "2:\n" \
21396 + restore \
21397 ".section .fixup,\"ax\"\n" \
21398 "5: addl %3,%0\n" \
21399 " jmp 2b\n" \
21400 @@ -682,14 +799,14 @@ do { \
21401 " negl %0\n" \
21402 " andl $7,%0\n" \
21403 " subl %0,%3\n" \
21404 - "4: rep; movsb\n" \
21405 + "4: rep; "__copyuser_seg"movsb\n" \
21406 " movl %3,%0\n" \
21407 " shrl $2,%0\n" \
21408 " andl $3,%3\n" \
21409 " .align 2,0x90\n" \
21410 - "0: rep; movsl\n" \
21411 + "0: rep; "__copyuser_seg"movsl\n" \
21412 " movl %3,%0\n" \
21413 - "1: rep; movsb\n" \
21414 + "1: rep; "__copyuser_seg"movsb\n" \
21415 "2:\n" \
21416 ".section .fixup,\"ax\"\n" \
21417 "5: addl %3,%0\n" \
21418 @@ -775,9 +892,9 @@ survive:
21419 }
21420 #endif
21421 if (movsl_is_ok(to, from, n))
21422 - __copy_user(to, from, n);
21423 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
21424 else
21425 - n = __copy_user_intel(to, from, n);
21426 + n = __generic_copy_to_user_intel(to, from, n);
21427 return n;
21428 }
21429 EXPORT_SYMBOL(__copy_to_user_ll);
21430 @@ -797,10 +914,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
21431 unsigned long n)
21432 {
21433 if (movsl_is_ok(to, from, n))
21434 - __copy_user(to, from, n);
21435 + __copy_user(to, from, n, __copyuser_seg, "", "");
21436 else
21437 - n = __copy_user_intel((void __user *)to,
21438 - (const void *)from, n);
21439 + n = __generic_copy_from_user_intel(to, from, n);
21440 return n;
21441 }
21442 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
21443 @@ -827,65 +943,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
21444 if (n > 64 && cpu_has_xmm2)
21445 n = __copy_user_intel_nocache(to, from, n);
21446 else
21447 - __copy_user(to, from, n);
21448 + __copy_user(to, from, n, __copyuser_seg, "", "");
21449 #else
21450 - __copy_user(to, from, n);
21451 + __copy_user(to, from, n, __copyuser_seg, "", "");
21452 #endif
21453 return n;
21454 }
21455 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
21456
21457 -/**
21458 - * copy_to_user: - Copy a block of data into user space.
21459 - * @to: Destination address, in user space.
21460 - * @from: Source address, in kernel space.
21461 - * @n: Number of bytes to copy.
21462 - *
21463 - * Context: User context only. This function may sleep.
21464 - *
21465 - * Copy data from kernel space to user space.
21466 - *
21467 - * Returns number of bytes that could not be copied.
21468 - * On success, this will be zero.
21469 - */
21470 -unsigned long
21471 -copy_to_user(void __user *to, const void *from, unsigned long n)
21472 -{
21473 - if (access_ok(VERIFY_WRITE, to, n))
21474 - n = __copy_to_user(to, from, n);
21475 - return n;
21476 -}
21477 -EXPORT_SYMBOL(copy_to_user);
21478 -
21479 -/**
21480 - * copy_from_user: - Copy a block of data from user space.
21481 - * @to: Destination address, in kernel space.
21482 - * @from: Source address, in user space.
21483 - * @n: Number of bytes to copy.
21484 - *
21485 - * Context: User context only. This function may sleep.
21486 - *
21487 - * Copy data from user space to kernel space.
21488 - *
21489 - * Returns number of bytes that could not be copied.
21490 - * On success, this will be zero.
21491 - *
21492 - * If some data could not be copied, this function will pad the copied
21493 - * data to the requested size using zero bytes.
21494 - */
21495 -unsigned long
21496 -_copy_from_user(void *to, const void __user *from, unsigned long n)
21497 -{
21498 - if (access_ok(VERIFY_READ, from, n))
21499 - n = __copy_from_user(to, from, n);
21500 - else
21501 - memset(to, 0, n);
21502 - return n;
21503 -}
21504 -EXPORT_SYMBOL(_copy_from_user);
21505 -
21506 void copy_from_user_overflow(void)
21507 {
21508 WARN(1, "Buffer overflow detected!\n");
21509 }
21510 EXPORT_SYMBOL(copy_from_user_overflow);
21511 +
21512 +void copy_to_user_overflow(void)
21513 +{
21514 + WARN(1, "Buffer overflow detected!\n");
21515 +}
21516 +EXPORT_SYMBOL(copy_to_user_overflow);
21517 +
21518 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21519 +void __set_fs(mm_segment_t x)
21520 +{
21521 + switch (x.seg) {
21522 + case 0:
21523 + loadsegment(gs, 0);
21524 + break;
21525 + case TASK_SIZE_MAX:
21526 + loadsegment(gs, __USER_DS);
21527 + break;
21528 + case -1UL:
21529 + loadsegment(gs, __KERNEL_DS);
21530 + break;
21531 + default:
21532 + BUG();
21533 + }
21534 + return;
21535 +}
21536 +EXPORT_SYMBOL(__set_fs);
21537 +
21538 +void set_fs(mm_segment_t x)
21539 +{
21540 + current_thread_info()->addr_limit = x;
21541 + __set_fs(x);
21542 +}
21543 +EXPORT_SYMBOL(set_fs);
21544 +#endif
21545 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
21546 index b7c2849..8633ad8 100644
21547 --- a/arch/x86/lib/usercopy_64.c
21548 +++ b/arch/x86/lib/usercopy_64.c
21549 @@ -42,6 +42,12 @@ long
21550 __strncpy_from_user(char *dst, const char __user *src, long count)
21551 {
21552 long res;
21553 +
21554 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21555 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21556 + src += PAX_USER_SHADOW_BASE;
21557 +#endif
21558 +
21559 __do_strncpy_from_user(dst, src, count, res);
21560 return res;
21561 }
21562 @@ -65,6 +71,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
21563 {
21564 long __d0;
21565 might_fault();
21566 +
21567 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21568 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
21569 + addr += PAX_USER_SHADOW_BASE;
21570 +#endif
21571 +
21572 /* no memory constraint because it doesn't change any memory gcc knows
21573 about */
21574 asm volatile(
21575 @@ -149,12 +161,20 @@ long strlen_user(const char __user *s)
21576 }
21577 EXPORT_SYMBOL(strlen_user);
21578
21579 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
21580 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
21581 {
21582 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21583 - return copy_user_generic((__force void *)to, (__force void *)from, len);
21584 - }
21585 - return len;
21586 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
21587 +
21588 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21589 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
21590 + to += PAX_USER_SHADOW_BASE;
21591 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
21592 + from += PAX_USER_SHADOW_BASE;
21593 +#endif
21594 +
21595 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
21596 + }
21597 + return len;
21598 }
21599 EXPORT_SYMBOL(copy_in_user);
21600
21601 @@ -164,7 +184,7 @@ EXPORT_SYMBOL(copy_in_user);
21602 * it is not necessary to optimize tail handling.
21603 */
21604 unsigned long
21605 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
21606 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
21607 {
21608 char c;
21609 unsigned zero_len;
21610 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
21611 index d0474ad..36e9257 100644
21612 --- a/arch/x86/mm/extable.c
21613 +++ b/arch/x86/mm/extable.c
21614 @@ -8,7 +8,7 @@ int fixup_exception(struct pt_regs *regs)
21615 const struct exception_table_entry *fixup;
21616
21617 #ifdef CONFIG_PNPBIOS
21618 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
21619 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
21620 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
21621 extern u32 pnp_bios_is_utter_crap;
21622 pnp_bios_is_utter_crap = 1;
21623 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
21624 index 5db0490..2ddce45 100644
21625 --- a/arch/x86/mm/fault.c
21626 +++ b/arch/x86/mm/fault.c
21627 @@ -13,11 +13,18 @@
21628 #include <linux/perf_event.h> /* perf_sw_event */
21629 #include <linux/hugetlb.h> /* hstate_index_to_shift */
21630 #include <linux/prefetch.h> /* prefetchw */
21631 +#include <linux/unistd.h>
21632 +#include <linux/compiler.h>
21633
21634 #include <asm/traps.h> /* dotraplinkage, ... */
21635 #include <asm/pgalloc.h> /* pgd_*(), ... */
21636 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
21637 #include <asm/fixmap.h> /* VSYSCALL_START */
21638 +#include <asm/tlbflush.h>
21639 +
21640 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21641 +#include <asm/stacktrace.h>
21642 +#endif
21643
21644 /*
21645 * Page fault error code bits:
21646 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
21647 int ret = 0;
21648
21649 /* kprobe_running() needs smp_processor_id() */
21650 - if (kprobes_built_in() && !user_mode_vm(regs)) {
21651 + if (kprobes_built_in() && !user_mode(regs)) {
21652 preempt_disable();
21653 if (kprobe_running() && kprobe_fault_handler(regs, 14))
21654 ret = 1;
21655 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
21656 return !instr_lo || (instr_lo>>1) == 1;
21657 case 0x00:
21658 /* Prefetch instruction is 0x0F0D or 0x0F18 */
21659 - if (probe_kernel_address(instr, opcode))
21660 + if (user_mode(regs)) {
21661 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21662 + return 0;
21663 + } else if (probe_kernel_address(instr, opcode))
21664 return 0;
21665
21666 *prefetch = (instr_lo == 0xF) &&
21667 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
21668 while (instr < max_instr) {
21669 unsigned char opcode;
21670
21671 - if (probe_kernel_address(instr, opcode))
21672 + if (user_mode(regs)) {
21673 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
21674 + break;
21675 + } else if (probe_kernel_address(instr, opcode))
21676 break;
21677
21678 instr++;
21679 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
21680 force_sig_info(si_signo, &info, tsk);
21681 }
21682
21683 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21684 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
21685 +#endif
21686 +
21687 +#ifdef CONFIG_PAX_EMUTRAMP
21688 +static int pax_handle_fetch_fault(struct pt_regs *regs);
21689 +#endif
21690 +
21691 +#ifdef CONFIG_PAX_PAGEEXEC
21692 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
21693 +{
21694 + pgd_t *pgd;
21695 + pud_t *pud;
21696 + pmd_t *pmd;
21697 +
21698 + pgd = pgd_offset(mm, address);
21699 + if (!pgd_present(*pgd))
21700 + return NULL;
21701 + pud = pud_offset(pgd, address);
21702 + if (!pud_present(*pud))
21703 + return NULL;
21704 + pmd = pmd_offset(pud, address);
21705 + if (!pmd_present(*pmd))
21706 + return NULL;
21707 + return pmd;
21708 +}
21709 +#endif
21710 +
21711 DEFINE_SPINLOCK(pgd_lock);
21712 LIST_HEAD(pgd_list);
21713
21714 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
21715 for (address = VMALLOC_START & PMD_MASK;
21716 address >= TASK_SIZE && address < FIXADDR_TOP;
21717 address += PMD_SIZE) {
21718 +
21719 +#ifdef CONFIG_PAX_PER_CPU_PGD
21720 + unsigned long cpu;
21721 +#else
21722 struct page *page;
21723 +#endif
21724
21725 spin_lock(&pgd_lock);
21726 +
21727 +#ifdef CONFIG_PAX_PER_CPU_PGD
21728 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
21729 + pgd_t *pgd = get_cpu_pgd(cpu);
21730 + pmd_t *ret;
21731 +#else
21732 list_for_each_entry(page, &pgd_list, lru) {
21733 + pgd_t *pgd = page_address(page);
21734 spinlock_t *pgt_lock;
21735 pmd_t *ret;
21736
21737 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
21738 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
21739
21740 spin_lock(pgt_lock);
21741 - ret = vmalloc_sync_one(page_address(page), address);
21742 +#endif
21743 +
21744 + ret = vmalloc_sync_one(pgd, address);
21745 +
21746 +#ifndef CONFIG_PAX_PER_CPU_PGD
21747 spin_unlock(pgt_lock);
21748 +#endif
21749
21750 if (!ret)
21751 break;
21752 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21753 * an interrupt in the middle of a task switch..
21754 */
21755 pgd_paddr = read_cr3();
21756 +
21757 +#ifdef CONFIG_PAX_PER_CPU_PGD
21758 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
21759 +#endif
21760 +
21761 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
21762 if (!pmd_k)
21763 return -1;
21764 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
21765 * happen within a race in page table update. In the later
21766 * case just flush:
21767 */
21768 +
21769 +#ifdef CONFIG_PAX_PER_CPU_PGD
21770 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
21771 + pgd = pgd_offset_cpu(smp_processor_id(), address);
21772 +#else
21773 pgd = pgd_offset(current->active_mm, address);
21774 +#endif
21775 +
21776 pgd_ref = pgd_offset_k(address);
21777 if (pgd_none(*pgd_ref))
21778 return -1;
21779 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
21780 static int is_errata100(struct pt_regs *regs, unsigned long address)
21781 {
21782 #ifdef CONFIG_X86_64
21783 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
21784 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
21785 return 1;
21786 #endif
21787 return 0;
21788 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
21789 }
21790
21791 static const char nx_warning[] = KERN_CRIT
21792 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
21793 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
21794
21795 static void
21796 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21797 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
21798 if (!oops_may_print())
21799 return;
21800
21801 - if (error_code & PF_INSTR) {
21802 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
21803 unsigned int level;
21804
21805 pte_t *pte = lookup_address(address, &level);
21806
21807 if (pte && pte_present(*pte) && !pte_exec(*pte))
21808 - printk(nx_warning, current_uid());
21809 + printk(nx_warning, current_uid(), current->comm, task_pid_nr(current));
21810 }
21811
21812 +#ifdef CONFIG_PAX_KERNEXEC
21813 + if (init_mm.start_code <= address && address < init_mm.end_code) {
21814 + if (current->signal->curr_ip)
21815 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21816 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
21817 + else
21818 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
21819 + current->comm, task_pid_nr(current), current_uid(), current_euid());
21820 + }
21821 +#endif
21822 +
21823 printk(KERN_ALERT "BUG: unable to handle kernel ");
21824 if (address < PAGE_SIZE)
21825 printk(KERN_CONT "NULL pointer dereference");
21826 @@ -739,6 +820,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
21827 }
21828 #endif
21829
21830 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21831 + if (pax_is_fetch_fault(regs, error_code, address)) {
21832 +
21833 +#ifdef CONFIG_PAX_EMUTRAMP
21834 + switch (pax_handle_fetch_fault(regs)) {
21835 + case 2:
21836 + return;
21837 + }
21838 +#endif
21839 +
21840 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21841 + do_group_exit(SIGKILL);
21842 + }
21843 +#endif
21844 +
21845 if (unlikely(show_unhandled_signals))
21846 show_signal_msg(regs, error_code, address, tsk);
21847
21848 @@ -835,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
21849 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
21850 printk(KERN_ERR
21851 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
21852 - tsk->comm, tsk->pid, address);
21853 + tsk->comm, task_pid_nr(tsk), address);
21854 code = BUS_MCEERR_AR;
21855 }
21856 #endif
21857 @@ -890,6 +986,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
21858 return 1;
21859 }
21860
21861 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21862 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
21863 +{
21864 + pte_t *pte;
21865 + pmd_t *pmd;
21866 + spinlock_t *ptl;
21867 + unsigned char pte_mask;
21868 +
21869 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
21870 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
21871 + return 0;
21872 +
21873 + /* PaX: it's our fault, let's handle it if we can */
21874 +
21875 + /* PaX: take a look at read faults before acquiring any locks */
21876 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
21877 + /* instruction fetch attempt from a protected page in user mode */
21878 + up_read(&mm->mmap_sem);
21879 +
21880 +#ifdef CONFIG_PAX_EMUTRAMP
21881 + switch (pax_handle_fetch_fault(regs)) {
21882 + case 2:
21883 + return 1;
21884 + }
21885 +#endif
21886 +
21887 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
21888 + do_group_exit(SIGKILL);
21889 + }
21890 +
21891 + pmd = pax_get_pmd(mm, address);
21892 + if (unlikely(!pmd))
21893 + return 0;
21894 +
21895 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
21896 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
21897 + pte_unmap_unlock(pte, ptl);
21898 + return 0;
21899 + }
21900 +
21901 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
21902 + /* write attempt to a protected page in user mode */
21903 + pte_unmap_unlock(pte, ptl);
21904 + return 0;
21905 + }
21906 +
21907 +#ifdef CONFIG_SMP
21908 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
21909 +#else
21910 + if (likely(address > get_limit(regs->cs)))
21911 +#endif
21912 + {
21913 + set_pte(pte, pte_mkread(*pte));
21914 + __flush_tlb_one(address);
21915 + pte_unmap_unlock(pte, ptl);
21916 + up_read(&mm->mmap_sem);
21917 + return 1;
21918 + }
21919 +
21920 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
21921 +
21922 + /*
21923 + * PaX: fill DTLB with user rights and retry
21924 + */
21925 + __asm__ __volatile__ (
21926 + "orb %2,(%1)\n"
21927 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
21928 +/*
21929 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
21930 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
21931 + * page fault when examined during a TLB load attempt. this is true not only
21932 + * for PTEs holding a non-present entry but also present entries that will
21933 + * raise a page fault (such as those set up by PaX, or the copy-on-write
21934 + * mechanism). in effect it means that we do *not* need to flush the TLBs
21935 + * for our target pages since their PTEs are simply not in the TLBs at all.
21936 +
21937 + * the best thing in omitting it is that we gain around 15-20% speed in the
21938 + * fast path of the page fault handler and can get rid of tracing since we
21939 + * can no longer flush unintended entries.
21940 + */
21941 + "invlpg (%0)\n"
21942 +#endif
21943 + __copyuser_seg"testb $0,(%0)\n"
21944 + "xorb %3,(%1)\n"
21945 + :
21946 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
21947 + : "memory", "cc");
21948 + pte_unmap_unlock(pte, ptl);
21949 + up_read(&mm->mmap_sem);
21950 + return 1;
21951 +}
21952 +#endif
21953 +
21954 /*
21955 * Handle a spurious fault caused by a stale TLB entry.
21956 *
21957 @@ -962,6 +1151,9 @@ int show_unhandled_signals = 1;
21958 static inline int
21959 access_error(unsigned long error_code, struct vm_area_struct *vma)
21960 {
21961 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
21962 + return 1;
21963 +
21964 if (error_code & PF_WRITE) {
21965 /* write, present and write, not present: */
21966 if (unlikely(!(vma->vm_flags & VM_WRITE)))
21967 @@ -995,18 +1187,32 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
21968 {
21969 struct vm_area_struct *vma;
21970 struct task_struct *tsk;
21971 - unsigned long address;
21972 struct mm_struct *mm;
21973 int fault;
21974 int write = error_code & PF_WRITE;
21975 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
21976 (write ? FAULT_FLAG_WRITE : 0);
21977
21978 - tsk = current;
21979 - mm = tsk->mm;
21980 -
21981 /* Get the faulting address: */
21982 - address = read_cr2();
21983 + unsigned long address = read_cr2();
21984 +
21985 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21986 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
21987 + if (!search_exception_tables(regs->ip)) {
21988 + bad_area_nosemaphore(regs, error_code, address);
21989 + return;
21990 + }
21991 + if (address < PAX_USER_SHADOW_BASE) {
21992 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
21993 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
21994 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
21995 + } else
21996 + address -= PAX_USER_SHADOW_BASE;
21997 + }
21998 +#endif
21999 +
22000 + tsk = current;
22001 + mm = tsk->mm;
22002
22003 /*
22004 * Detect and handle instructions that would cause a page fault for
22005 @@ -1067,7 +1273,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
22006 * User-mode registers count as a user access even for any
22007 * potential system fault or CPU buglet:
22008 */
22009 - if (user_mode_vm(regs)) {
22010 + if (user_mode(regs)) {
22011 local_irq_enable();
22012 error_code |= PF_USER;
22013 } else {
22014 @@ -1122,6 +1328,11 @@ retry:
22015 might_sleep();
22016 }
22017
22018 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22019 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
22020 + return;
22021 +#endif
22022 +
22023 vma = find_vma(mm, address);
22024 if (unlikely(!vma)) {
22025 bad_area(regs, error_code, address);
22026 @@ -1133,18 +1344,24 @@ retry:
22027 bad_area(regs, error_code, address);
22028 return;
22029 }
22030 - if (error_code & PF_USER) {
22031 - /*
22032 - * Accessing the stack below %sp is always a bug.
22033 - * The large cushion allows instructions like enter
22034 - * and pusha to work. ("enter $65535, $31" pushes
22035 - * 32 pointers and then decrements %sp by 65535.)
22036 - */
22037 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
22038 - bad_area(regs, error_code, address);
22039 - return;
22040 - }
22041 + /*
22042 + * Accessing the stack below %sp is always a bug.
22043 + * The large cushion allows instructions like enter
22044 + * and pusha to work. ("enter $65535, $31" pushes
22045 + * 32 pointers and then decrements %sp by 65535.)
22046 + */
22047 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
22048 + bad_area(regs, error_code, address);
22049 + return;
22050 }
22051 +
22052 +#ifdef CONFIG_PAX_SEGMEXEC
22053 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
22054 + bad_area(regs, error_code, address);
22055 + return;
22056 + }
22057 +#endif
22058 +
22059 if (unlikely(expand_stack(vma, address))) {
22060 bad_area(regs, error_code, address);
22061 return;
22062 @@ -1199,3 +1416,292 @@ good_area:
22063
22064 up_read(&mm->mmap_sem);
22065 }
22066 +
22067 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22068 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
22069 +{
22070 + struct mm_struct *mm = current->mm;
22071 + unsigned long ip = regs->ip;
22072 +
22073 + if (v8086_mode(regs))
22074 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
22075 +
22076 +#ifdef CONFIG_PAX_PAGEEXEC
22077 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
22078 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
22079 + return true;
22080 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
22081 + return true;
22082 + return false;
22083 + }
22084 +#endif
22085 +
22086 +#ifdef CONFIG_PAX_SEGMEXEC
22087 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
22088 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
22089 + return true;
22090 + return false;
22091 + }
22092 +#endif
22093 +
22094 + return false;
22095 +}
22096 +#endif
22097 +
22098 +#ifdef CONFIG_PAX_EMUTRAMP
22099 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
22100 +{
22101 + int err;
22102 +
22103 + do { /* PaX: libffi trampoline emulation */
22104 + unsigned char mov, jmp;
22105 + unsigned int addr1, addr2;
22106 +
22107 +#ifdef CONFIG_X86_64
22108 + if ((regs->ip + 9) >> 32)
22109 + break;
22110 +#endif
22111 +
22112 + err = get_user(mov, (unsigned char __user *)regs->ip);
22113 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
22114 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
22115 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
22116 +
22117 + if (err)
22118 + break;
22119 +
22120 + if (mov == 0xB8 && jmp == 0xE9) {
22121 + regs->ax = addr1;
22122 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
22123 + return 2;
22124 + }
22125 + } while (0);
22126 +
22127 + do { /* PaX: gcc trampoline emulation #1 */
22128 + unsigned char mov1, mov2;
22129 + unsigned short jmp;
22130 + unsigned int addr1, addr2;
22131 +
22132 +#ifdef CONFIG_X86_64
22133 + if ((regs->ip + 11) >> 32)
22134 + break;
22135 +#endif
22136 +
22137 + err = get_user(mov1, (unsigned char __user *)regs->ip);
22138 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
22139 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
22140 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
22141 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
22142 +
22143 + if (err)
22144 + break;
22145 +
22146 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
22147 + regs->cx = addr1;
22148 + regs->ax = addr2;
22149 + regs->ip = addr2;
22150 + return 2;
22151 + }
22152 + } while (0);
22153 +
22154 + do { /* PaX: gcc trampoline emulation #2 */
22155 + unsigned char mov, jmp;
22156 + unsigned int addr1, addr2;
22157 +
22158 +#ifdef CONFIG_X86_64
22159 + if ((regs->ip + 9) >> 32)
22160 + break;
22161 +#endif
22162 +
22163 + err = get_user(mov, (unsigned char __user *)regs->ip);
22164 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
22165 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
22166 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
22167 +
22168 + if (err)
22169 + break;
22170 +
22171 + if (mov == 0xB9 && jmp == 0xE9) {
22172 + regs->cx = addr1;
22173 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
22174 + return 2;
22175 + }
22176 + } while (0);
22177 +
22178 + return 1; /* PaX in action */
22179 +}
22180 +
22181 +#ifdef CONFIG_X86_64
22182 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
22183 +{
22184 + int err;
22185 +
22186 + do { /* PaX: libffi trampoline emulation */
22187 + unsigned short mov1, mov2, jmp1;
22188 + unsigned char stcclc, jmp2;
22189 + unsigned long addr1, addr2;
22190 +
22191 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22192 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22193 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22194 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22195 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
22196 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
22197 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
22198 +
22199 + if (err)
22200 + break;
22201 +
22202 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22203 + regs->r11 = addr1;
22204 + regs->r10 = addr2;
22205 + if (stcclc == 0xF8)
22206 + regs->flags &= ~X86_EFLAGS_CF;
22207 + else
22208 + regs->flags |= X86_EFLAGS_CF;
22209 + regs->ip = addr1;
22210 + return 2;
22211 + }
22212 + } while (0);
22213 +
22214 + do { /* PaX: gcc trampoline emulation #1 */
22215 + unsigned short mov1, mov2, jmp1;
22216 + unsigned char jmp2;
22217 + unsigned int addr1;
22218 + unsigned long addr2;
22219 +
22220 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22221 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
22222 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
22223 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
22224 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
22225 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
22226 +
22227 + if (err)
22228 + break;
22229 +
22230 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22231 + regs->r11 = addr1;
22232 + regs->r10 = addr2;
22233 + regs->ip = addr1;
22234 + return 2;
22235 + }
22236 + } while (0);
22237 +
22238 + do { /* PaX: gcc trampoline emulation #2 */
22239 + unsigned short mov1, mov2, jmp1;
22240 + unsigned char jmp2;
22241 + unsigned long addr1, addr2;
22242 +
22243 + err = get_user(mov1, (unsigned short __user *)regs->ip);
22244 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
22245 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
22246 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
22247 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
22248 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
22249 +
22250 + if (err)
22251 + break;
22252 +
22253 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
22254 + regs->r11 = addr1;
22255 + regs->r10 = addr2;
22256 + regs->ip = addr1;
22257 + return 2;
22258 + }
22259 + } while (0);
22260 +
22261 + return 1; /* PaX in action */
22262 +}
22263 +#endif
22264 +
22265 +/*
22266 + * PaX: decide what to do with offenders (regs->ip = fault address)
22267 + *
22268 + * returns 1 when task should be killed
22269 + * 2 when gcc trampoline was detected
22270 + */
22271 +static int pax_handle_fetch_fault(struct pt_regs *regs)
22272 +{
22273 + if (v8086_mode(regs))
22274 + return 1;
22275 +
22276 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
22277 + return 1;
22278 +
22279 +#ifdef CONFIG_X86_32
22280 + return pax_handle_fetch_fault_32(regs);
22281 +#else
22282 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
22283 + return pax_handle_fetch_fault_32(regs);
22284 + else
22285 + return pax_handle_fetch_fault_64(regs);
22286 +#endif
22287 +}
22288 +#endif
22289 +
22290 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22291 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
22292 +{
22293 + long i;
22294 +
22295 + printk(KERN_ERR "PAX: bytes at PC: ");
22296 + for (i = 0; i < 20; i++) {
22297 + unsigned char c;
22298 + if (get_user(c, (unsigned char __force_user *)pc+i))
22299 + printk(KERN_CONT "?? ");
22300 + else
22301 + printk(KERN_CONT "%02x ", c);
22302 + }
22303 + printk("\n");
22304 +
22305 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
22306 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
22307 + unsigned long c;
22308 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
22309 +#ifdef CONFIG_X86_32
22310 + printk(KERN_CONT "???????? ");
22311 +#else
22312 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
22313 + printk(KERN_CONT "???????? ???????? ");
22314 + else
22315 + printk(KERN_CONT "???????????????? ");
22316 +#endif
22317 + } else {
22318 +#ifdef CONFIG_X86_64
22319 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
22320 + printk(KERN_CONT "%08x ", (unsigned int)c);
22321 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
22322 + } else
22323 +#endif
22324 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
22325 + }
22326 + }
22327 + printk("\n");
22328 +}
22329 +#endif
22330 +
22331 +/**
22332 + * probe_kernel_write(): safely attempt to write to a location
22333 + * @dst: address to write to
22334 + * @src: pointer to the data that shall be written
22335 + * @size: size of the data chunk
22336 + *
22337 + * Safely write to address @dst from the buffer at @src. If a kernel fault
22338 + * happens, handle that and return -EFAULT.
22339 + */
22340 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
22341 +{
22342 + long ret;
22343 + mm_segment_t old_fs = get_fs();
22344 +
22345 + set_fs(KERNEL_DS);
22346 + pagefault_disable();
22347 + pax_open_kernel();
22348 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
22349 + pax_close_kernel();
22350 + pagefault_enable();
22351 + set_fs(old_fs);
22352 +
22353 + return ret ? -EFAULT : 0;
22354 +}
22355 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
22356 index dd74e46..7d26398 100644
22357 --- a/arch/x86/mm/gup.c
22358 +++ b/arch/x86/mm/gup.c
22359 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
22360 addr = start;
22361 len = (unsigned long) nr_pages << PAGE_SHIFT;
22362 end = start + len;
22363 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22364 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
22365 (void __user *)start, len)))
22366 return 0;
22367
22368 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
22369 index f4f29b1..5cac4fb 100644
22370 --- a/arch/x86/mm/highmem_32.c
22371 +++ b/arch/x86/mm/highmem_32.c
22372 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
22373 idx = type + KM_TYPE_NR*smp_processor_id();
22374 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
22375 BUG_ON(!pte_none(*(kmap_pte-idx)));
22376 +
22377 + pax_open_kernel();
22378 set_pte(kmap_pte-idx, mk_pte(page, prot));
22379 + pax_close_kernel();
22380 +
22381 arch_flush_lazy_mmu_mode();
22382
22383 return (void *)vaddr;
22384 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
22385 index f581a18..29efd37 100644
22386 --- a/arch/x86/mm/hugetlbpage.c
22387 +++ b/arch/x86/mm/hugetlbpage.c
22388 @@ -266,13 +266,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
22389 struct hstate *h = hstate_file(file);
22390 struct mm_struct *mm = current->mm;
22391 struct vm_area_struct *vma;
22392 - unsigned long start_addr;
22393 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22394 +
22395 +#ifdef CONFIG_PAX_SEGMEXEC
22396 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22397 + pax_task_size = SEGMEXEC_TASK_SIZE;
22398 +#endif
22399 +
22400 + pax_task_size -= PAGE_SIZE;
22401
22402 if (len > mm->cached_hole_size) {
22403 - start_addr = mm->free_area_cache;
22404 + start_addr = mm->free_area_cache;
22405 } else {
22406 - start_addr = TASK_UNMAPPED_BASE;
22407 - mm->cached_hole_size = 0;
22408 + start_addr = mm->mmap_base;
22409 + mm->cached_hole_size = 0;
22410 }
22411
22412 full_search:
22413 @@ -280,26 +287,27 @@ full_search:
22414
22415 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22416 /* At this point: (!vma || addr < vma->vm_end). */
22417 - if (TASK_SIZE - len < addr) {
22418 + if (pax_task_size - len < addr) {
22419 /*
22420 * Start a new search - just in case we missed
22421 * some holes.
22422 */
22423 - if (start_addr != TASK_UNMAPPED_BASE) {
22424 - start_addr = TASK_UNMAPPED_BASE;
22425 + if (start_addr != mm->mmap_base) {
22426 + start_addr = mm->mmap_base;
22427 mm->cached_hole_size = 0;
22428 goto full_search;
22429 }
22430 return -ENOMEM;
22431 }
22432 - if (!vma || addr + len <= vma->vm_start) {
22433 - mm->free_area_cache = addr + len;
22434 - return addr;
22435 - }
22436 + if (check_heap_stack_gap(vma, addr, len))
22437 + break;
22438 if (addr + mm->cached_hole_size < vma->vm_start)
22439 mm->cached_hole_size = vma->vm_start - addr;
22440 addr = ALIGN(vma->vm_end, huge_page_size(h));
22441 }
22442 +
22443 + mm->free_area_cache = addr + len;
22444 + return addr;
22445 }
22446
22447 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22448 @@ -308,10 +316,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22449 {
22450 struct hstate *h = hstate_file(file);
22451 struct mm_struct *mm = current->mm;
22452 - struct vm_area_struct *vma, *prev_vma;
22453 - unsigned long base = mm->mmap_base, addr = addr0;
22454 + struct vm_area_struct *vma;
22455 + unsigned long base = mm->mmap_base, addr;
22456 unsigned long largest_hole = mm->cached_hole_size;
22457 - int first_time = 1;
22458
22459 /* don't allow allocations above current base */
22460 if (mm->free_area_cache > base)
22461 @@ -321,64 +328,63 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
22462 largest_hole = 0;
22463 mm->free_area_cache = base;
22464 }
22465 -try_again:
22466 +
22467 /* make sure it can fit in the remaining address space */
22468 if (mm->free_area_cache < len)
22469 goto fail;
22470
22471 /* either no address requested or can't fit in requested address hole */
22472 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
22473 + addr = (mm->free_area_cache - len);
22474 do {
22475 + addr &= huge_page_mask(h);
22476 + vma = find_vma(mm, addr);
22477 /*
22478 * Lookup failure means no vma is above this address,
22479 * i.e. return with success:
22480 - */
22481 - if (!(vma = find_vma_prev(mm, addr, &prev_vma)))
22482 - return addr;
22483 -
22484 - /*
22485 * new region fits between prev_vma->vm_end and
22486 * vma->vm_start, use it:
22487 */
22488 - if (addr + len <= vma->vm_start &&
22489 - (!prev_vma || (addr >= prev_vma->vm_end))) {
22490 + if (check_heap_stack_gap(vma, addr, len)) {
22491 /* remember the address as a hint for next time */
22492 - mm->cached_hole_size = largest_hole;
22493 - return (mm->free_area_cache = addr);
22494 - } else {
22495 - /* pull free_area_cache down to the first hole */
22496 - if (mm->free_area_cache == vma->vm_end) {
22497 - mm->free_area_cache = vma->vm_start;
22498 - mm->cached_hole_size = largest_hole;
22499 - }
22500 + mm->cached_hole_size = largest_hole;
22501 + return (mm->free_area_cache = addr);
22502 + }
22503 + /* pull free_area_cache down to the first hole */
22504 + if (mm->free_area_cache == vma->vm_end) {
22505 + mm->free_area_cache = vma->vm_start;
22506 + mm->cached_hole_size = largest_hole;
22507 }
22508
22509 /* remember the largest hole we saw so far */
22510 if (addr + largest_hole < vma->vm_start)
22511 - largest_hole = vma->vm_start - addr;
22512 + largest_hole = vma->vm_start - addr;
22513
22514 /* try just below the current vma->vm_start */
22515 - addr = (vma->vm_start - len) & huge_page_mask(h);
22516 - } while (len <= vma->vm_start);
22517 + addr = skip_heap_stack_gap(vma, len);
22518 + } while (!IS_ERR_VALUE(addr));
22519
22520 fail:
22521 /*
22522 - * if hint left us with no space for the requested
22523 - * mapping then try again:
22524 - */
22525 - if (first_time) {
22526 - mm->free_area_cache = base;
22527 - largest_hole = 0;
22528 - first_time = 0;
22529 - goto try_again;
22530 - }
22531 - /*
22532 * A failed mmap() very likely causes application failure,
22533 * so fall back to the bottom-up function here. This scenario
22534 * can happen with large stack limits and large mmap()
22535 * allocations.
22536 */
22537 - mm->free_area_cache = TASK_UNMAPPED_BASE;
22538 +
22539 +#ifdef CONFIG_PAX_SEGMEXEC
22540 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22541 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22542 + else
22543 +#endif
22544 +
22545 + mm->mmap_base = TASK_UNMAPPED_BASE;
22546 +
22547 +#ifdef CONFIG_PAX_RANDMMAP
22548 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22549 + mm->mmap_base += mm->delta_mmap;
22550 +#endif
22551 +
22552 + mm->free_area_cache = mm->mmap_base;
22553 mm->cached_hole_size = ~0UL;
22554 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
22555 len, pgoff, flags);
22556 @@ -386,6 +392,7 @@ fail:
22557 /*
22558 * Restore the topdown base:
22559 */
22560 + mm->mmap_base = base;
22561 mm->free_area_cache = base;
22562 mm->cached_hole_size = ~0UL;
22563
22564 @@ -399,10 +406,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22565 struct hstate *h = hstate_file(file);
22566 struct mm_struct *mm = current->mm;
22567 struct vm_area_struct *vma;
22568 + unsigned long pax_task_size = TASK_SIZE;
22569
22570 if (len & ~huge_page_mask(h))
22571 return -EINVAL;
22572 - if (len > TASK_SIZE)
22573 +
22574 +#ifdef CONFIG_PAX_SEGMEXEC
22575 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22576 + pax_task_size = SEGMEXEC_TASK_SIZE;
22577 +#endif
22578 +
22579 + pax_task_size -= PAGE_SIZE;
22580 +
22581 + if (len > pax_task_size)
22582 return -ENOMEM;
22583
22584 if (flags & MAP_FIXED) {
22585 @@ -414,8 +430,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
22586 if (addr) {
22587 addr = ALIGN(addr, huge_page_size(h));
22588 vma = find_vma(mm, addr);
22589 - if (TASK_SIZE - len >= addr &&
22590 - (!vma || addr + len <= vma->vm_start))
22591 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
22592 return addr;
22593 }
22594 if (mm->get_unmapped_area == arch_get_unmapped_area)
22595 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
22596 index 87488b9..399f416 100644
22597 --- a/arch/x86/mm/init.c
22598 +++ b/arch/x86/mm/init.c
22599 @@ -15,6 +15,7 @@
22600 #include <asm/tlbflush.h>
22601 #include <asm/tlb.h>
22602 #include <asm/proto.h>
22603 +#include <asm/desc.h>
22604
22605 unsigned long __initdata pgt_buf_start;
22606 unsigned long __meminitdata pgt_buf_end;
22607 @@ -31,7 +32,7 @@ int direct_gbpages
22608 static void __init find_early_table_space(unsigned long end, int use_pse,
22609 int use_gbpages)
22610 {
22611 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
22612 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
22613 phys_addr_t base;
22614
22615 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
22616 @@ -312,8 +313,29 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
22617 */
22618 int devmem_is_allowed(unsigned long pagenr)
22619 {
22620 +#ifdef CONFIG_GRKERNSEC_KMEM
22621 + /* allow BDA */
22622 + if (!pagenr)
22623 + return 1;
22624 + /* allow EBDA */
22625 + if ((0x9f000 >> PAGE_SHIFT) == pagenr)
22626 + return 1;
22627 +#else
22628 + if (!pagenr)
22629 + return 1;
22630 +#ifdef CONFIG_VM86
22631 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
22632 + return 1;
22633 +#endif
22634 +#endif
22635 +
22636 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
22637 + return 1;
22638 +#ifdef CONFIG_GRKERNSEC_KMEM
22639 + /* throw out everything else below 1MB */
22640 if (pagenr <= 256)
22641 - return 1;
22642 + return 0;
22643 +#endif
22644 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
22645 return 0;
22646 if (!page_is_ram(pagenr))
22647 @@ -372,6 +394,86 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
22648
22649 void free_initmem(void)
22650 {
22651 +
22652 +#ifdef CONFIG_PAX_KERNEXEC
22653 +#ifdef CONFIG_X86_32
22654 + /* PaX: limit KERNEL_CS to actual size */
22655 + unsigned long addr, limit;
22656 + struct desc_struct d;
22657 + int cpu;
22658 +
22659 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
22660 + limit = (limit - 1UL) >> PAGE_SHIFT;
22661 +
22662 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
22663 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
22664 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
22665 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
22666 + }
22667 +
22668 + /* PaX: make KERNEL_CS read-only */
22669 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
22670 + if (!paravirt_enabled())
22671 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
22672 +/*
22673 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
22674 + pgd = pgd_offset_k(addr);
22675 + pud = pud_offset(pgd, addr);
22676 + pmd = pmd_offset(pud, addr);
22677 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22678 + }
22679 +*/
22680 +#ifdef CONFIG_X86_PAE
22681 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
22682 +/*
22683 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
22684 + pgd = pgd_offset_k(addr);
22685 + pud = pud_offset(pgd, addr);
22686 + pmd = pmd_offset(pud, addr);
22687 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22688 + }
22689 +*/
22690 +#endif
22691 +
22692 +#ifdef CONFIG_MODULES
22693 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
22694 +#endif
22695 +
22696 +#else
22697 + pgd_t *pgd;
22698 + pud_t *pud;
22699 + pmd_t *pmd;
22700 + unsigned long addr, end;
22701 +
22702 + /* PaX: make kernel code/rodata read-only, rest non-executable */
22703 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
22704 + pgd = pgd_offset_k(addr);
22705 + pud = pud_offset(pgd, addr);
22706 + pmd = pmd_offset(pud, addr);
22707 + if (!pmd_present(*pmd))
22708 + continue;
22709 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
22710 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22711 + else
22712 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
22713 + }
22714 +
22715 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
22716 + end = addr + KERNEL_IMAGE_SIZE;
22717 + for (; addr < end; addr += PMD_SIZE) {
22718 + pgd = pgd_offset_k(addr);
22719 + pud = pud_offset(pgd, addr);
22720 + pmd = pmd_offset(pud, addr);
22721 + if (!pmd_present(*pmd))
22722 + continue;
22723 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
22724 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
22725 + }
22726 +#endif
22727 +
22728 + flush_tlb_all();
22729 +#endif
22730 +
22731 free_init_pages("unused kernel memory",
22732 (unsigned long)(&__init_begin),
22733 (unsigned long)(&__init_end));
22734 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
22735 index 29f7c6d..b46b35b 100644
22736 --- a/arch/x86/mm/init_32.c
22737 +++ b/arch/x86/mm/init_32.c
22738 @@ -74,36 +74,6 @@ static __init void *alloc_low_page(void)
22739 }
22740
22741 /*
22742 - * Creates a middle page table and puts a pointer to it in the
22743 - * given global directory entry. This only returns the gd entry
22744 - * in non-PAE compilation mode, since the middle layer is folded.
22745 - */
22746 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
22747 -{
22748 - pud_t *pud;
22749 - pmd_t *pmd_table;
22750 -
22751 -#ifdef CONFIG_X86_PAE
22752 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
22753 - if (after_bootmem)
22754 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
22755 - else
22756 - pmd_table = (pmd_t *)alloc_low_page();
22757 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
22758 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
22759 - pud = pud_offset(pgd, 0);
22760 - BUG_ON(pmd_table != pmd_offset(pud, 0));
22761 -
22762 - return pmd_table;
22763 - }
22764 -#endif
22765 - pud = pud_offset(pgd, 0);
22766 - pmd_table = pmd_offset(pud, 0);
22767 -
22768 - return pmd_table;
22769 -}
22770 -
22771 -/*
22772 * Create a page table and place a pointer to it in a middle page
22773 * directory entry:
22774 */
22775 @@ -123,13 +93,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
22776 page_table = (pte_t *)alloc_low_page();
22777
22778 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
22779 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
22780 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
22781 +#else
22782 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
22783 +#endif
22784 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
22785 }
22786
22787 return pte_offset_kernel(pmd, 0);
22788 }
22789
22790 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
22791 +{
22792 + pud_t *pud;
22793 + pmd_t *pmd_table;
22794 +
22795 + pud = pud_offset(pgd, 0);
22796 + pmd_table = pmd_offset(pud, 0);
22797 +
22798 + return pmd_table;
22799 +}
22800 +
22801 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
22802 {
22803 int pgd_idx = pgd_index(vaddr);
22804 @@ -203,6 +188,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22805 int pgd_idx, pmd_idx;
22806 unsigned long vaddr;
22807 pgd_t *pgd;
22808 + pud_t *pud;
22809 pmd_t *pmd;
22810 pte_t *pte = NULL;
22811
22812 @@ -212,8 +198,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22813 pgd = pgd_base + pgd_idx;
22814
22815 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
22816 - pmd = one_md_table_init(pgd);
22817 - pmd = pmd + pmd_index(vaddr);
22818 + pud = pud_offset(pgd, vaddr);
22819 + pmd = pmd_offset(pud, vaddr);
22820 +
22821 +#ifdef CONFIG_X86_PAE
22822 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22823 +#endif
22824 +
22825 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
22826 pmd++, pmd_idx++) {
22827 pte = page_table_kmap_check(one_page_table_init(pmd),
22828 @@ -225,11 +216,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
22829 }
22830 }
22831
22832 -static inline int is_kernel_text(unsigned long addr)
22833 +static inline int is_kernel_text(unsigned long start, unsigned long end)
22834 {
22835 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
22836 - return 1;
22837 - return 0;
22838 + if ((start > ktla_ktva((unsigned long)_etext) ||
22839 + end <= ktla_ktva((unsigned long)_stext)) &&
22840 + (start > ktla_ktva((unsigned long)_einittext) ||
22841 + end <= ktla_ktva((unsigned long)_sinittext)) &&
22842 +
22843 +#ifdef CONFIG_ACPI_SLEEP
22844 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
22845 +#endif
22846 +
22847 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
22848 + return 0;
22849 + return 1;
22850 }
22851
22852 /*
22853 @@ -246,9 +246,10 @@ kernel_physical_mapping_init(unsigned long start,
22854 unsigned long last_map_addr = end;
22855 unsigned long start_pfn, end_pfn;
22856 pgd_t *pgd_base = swapper_pg_dir;
22857 - int pgd_idx, pmd_idx, pte_ofs;
22858 + unsigned int pgd_idx, pmd_idx, pte_ofs;
22859 unsigned long pfn;
22860 pgd_t *pgd;
22861 + pud_t *pud;
22862 pmd_t *pmd;
22863 pte_t *pte;
22864 unsigned pages_2m, pages_4k;
22865 @@ -281,8 +282,13 @@ repeat:
22866 pfn = start_pfn;
22867 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22868 pgd = pgd_base + pgd_idx;
22869 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
22870 - pmd = one_md_table_init(pgd);
22871 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
22872 + pud = pud_offset(pgd, 0);
22873 + pmd = pmd_offset(pud, 0);
22874 +
22875 +#ifdef CONFIG_X86_PAE
22876 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
22877 +#endif
22878
22879 if (pfn >= end_pfn)
22880 continue;
22881 @@ -294,14 +300,13 @@ repeat:
22882 #endif
22883 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
22884 pmd++, pmd_idx++) {
22885 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
22886 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
22887
22888 /*
22889 * Map with big pages if possible, otherwise
22890 * create normal page tables:
22891 */
22892 if (use_pse) {
22893 - unsigned int addr2;
22894 pgprot_t prot = PAGE_KERNEL_LARGE;
22895 /*
22896 * first pass will use the same initial
22897 @@ -311,11 +316,7 @@ repeat:
22898 __pgprot(PTE_IDENT_ATTR |
22899 _PAGE_PSE);
22900
22901 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
22902 - PAGE_OFFSET + PAGE_SIZE-1;
22903 -
22904 - if (is_kernel_text(addr) ||
22905 - is_kernel_text(addr2))
22906 + if (is_kernel_text(address, address + PMD_SIZE))
22907 prot = PAGE_KERNEL_LARGE_EXEC;
22908
22909 pages_2m++;
22910 @@ -332,7 +333,7 @@ repeat:
22911 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
22912 pte += pte_ofs;
22913 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
22914 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
22915 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
22916 pgprot_t prot = PAGE_KERNEL;
22917 /*
22918 * first pass will use the same initial
22919 @@ -340,7 +341,7 @@ repeat:
22920 */
22921 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
22922
22923 - if (is_kernel_text(addr))
22924 + if (is_kernel_text(address, address + PAGE_SIZE))
22925 prot = PAGE_KERNEL_EXEC;
22926
22927 pages_4k++;
22928 @@ -472,7 +473,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
22929
22930 pud = pud_offset(pgd, va);
22931 pmd = pmd_offset(pud, va);
22932 - if (!pmd_present(*pmd))
22933 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
22934 break;
22935
22936 pte = pte_offset_kernel(pmd, va);
22937 @@ -524,12 +525,10 @@ void __init early_ioremap_page_table_range_init(void)
22938
22939 static void __init pagetable_init(void)
22940 {
22941 - pgd_t *pgd_base = swapper_pg_dir;
22942 -
22943 - permanent_kmaps_init(pgd_base);
22944 + permanent_kmaps_init(swapper_pg_dir);
22945 }
22946
22947 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22948 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
22949 EXPORT_SYMBOL_GPL(__supported_pte_mask);
22950
22951 /* user-defined highmem size */
22952 @@ -757,6 +756,12 @@ void __init mem_init(void)
22953
22954 pci_iommu_alloc();
22955
22956 +#ifdef CONFIG_PAX_PER_CPU_PGD
22957 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
22958 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22959 + KERNEL_PGD_PTRS);
22960 +#endif
22961 +
22962 #ifdef CONFIG_FLATMEM
22963 BUG_ON(!mem_map);
22964 #endif
22965 @@ -774,7 +779,7 @@ void __init mem_init(void)
22966 set_highmem_pages_init();
22967
22968 codesize = (unsigned long) &_etext - (unsigned long) &_text;
22969 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
22970 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
22971 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
22972
22973 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
22974 @@ -815,10 +820,10 @@ void __init mem_init(void)
22975 ((unsigned long)&__init_end -
22976 (unsigned long)&__init_begin) >> 10,
22977
22978 - (unsigned long)&_etext, (unsigned long)&_edata,
22979 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
22980 + (unsigned long)&_sdata, (unsigned long)&_edata,
22981 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
22982
22983 - (unsigned long)&_text, (unsigned long)&_etext,
22984 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
22985 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
22986
22987 /*
22988 @@ -896,6 +901,7 @@ void set_kernel_text_rw(void)
22989 if (!kernel_set_to_readonly)
22990 return;
22991
22992 + start = ktla_ktva(start);
22993 pr_debug("Set kernel text: %lx - %lx for read write\n",
22994 start, start+size);
22995
22996 @@ -910,6 +916,7 @@ void set_kernel_text_ro(void)
22997 if (!kernel_set_to_readonly)
22998 return;
22999
23000 + start = ktla_ktva(start);
23001 pr_debug("Set kernel text: %lx - %lx for read only\n",
23002 start, start+size);
23003
23004 @@ -938,6 +945,7 @@ void mark_rodata_ro(void)
23005 unsigned long start = PFN_ALIGN(_text);
23006 unsigned long size = PFN_ALIGN(_etext) - start;
23007
23008 + start = ktla_ktva(start);
23009 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
23010 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
23011 size >> 10);
23012 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
23013 index bbaaa00..796fa65 100644
23014 --- a/arch/x86/mm/init_64.c
23015 +++ b/arch/x86/mm/init_64.c
23016 @@ -75,7 +75,7 @@ early_param("gbpages", parse_direct_gbpages_on);
23017 * around without checking the pgd every time.
23018 */
23019
23020 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
23021 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
23022 EXPORT_SYMBOL_GPL(__supported_pte_mask);
23023
23024 int force_personality32;
23025 @@ -108,12 +108,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
23026
23027 for (address = start; address <= end; address += PGDIR_SIZE) {
23028 const pgd_t *pgd_ref = pgd_offset_k(address);
23029 +
23030 +#ifdef CONFIG_PAX_PER_CPU_PGD
23031 + unsigned long cpu;
23032 +#else
23033 struct page *page;
23034 +#endif
23035
23036 if (pgd_none(*pgd_ref))
23037 continue;
23038
23039 spin_lock(&pgd_lock);
23040 +
23041 +#ifdef CONFIG_PAX_PER_CPU_PGD
23042 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23043 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
23044 +#else
23045 list_for_each_entry(page, &pgd_list, lru) {
23046 pgd_t *pgd;
23047 spinlock_t *pgt_lock;
23048 @@ -122,6 +132,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
23049 /* the pgt_lock only for Xen */
23050 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23051 spin_lock(pgt_lock);
23052 +#endif
23053
23054 if (pgd_none(*pgd))
23055 set_pgd(pgd, *pgd_ref);
23056 @@ -129,7 +140,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
23057 BUG_ON(pgd_page_vaddr(*pgd)
23058 != pgd_page_vaddr(*pgd_ref));
23059
23060 +#ifndef CONFIG_PAX_PER_CPU_PGD
23061 spin_unlock(pgt_lock);
23062 +#endif
23063 +
23064 }
23065 spin_unlock(&pgd_lock);
23066 }
23067 @@ -203,7 +217,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
23068 pmd = fill_pmd(pud, vaddr);
23069 pte = fill_pte(pmd, vaddr);
23070
23071 + pax_open_kernel();
23072 set_pte(pte, new_pte);
23073 + pax_close_kernel();
23074
23075 /*
23076 * It's enough to flush this one mapping.
23077 @@ -262,14 +278,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
23078 pgd = pgd_offset_k((unsigned long)__va(phys));
23079 if (pgd_none(*pgd)) {
23080 pud = (pud_t *) spp_getpage();
23081 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
23082 - _PAGE_USER));
23083 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
23084 }
23085 pud = pud_offset(pgd, (unsigned long)__va(phys));
23086 if (pud_none(*pud)) {
23087 pmd = (pmd_t *) spp_getpage();
23088 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
23089 - _PAGE_USER));
23090 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
23091 }
23092 pmd = pmd_offset(pud, phys);
23093 BUG_ON(!pmd_none(*pmd));
23094 @@ -330,7 +344,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
23095 if (pfn >= pgt_buf_top)
23096 panic("alloc_low_page: ran out of memory");
23097
23098 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
23099 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
23100 clear_page(adr);
23101 *phys = pfn * PAGE_SIZE;
23102 return adr;
23103 @@ -346,7 +360,7 @@ static __ref void *map_low_page(void *virt)
23104
23105 phys = __pa(virt);
23106 left = phys & (PAGE_SIZE - 1);
23107 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
23108 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
23109 adr = (void *)(((unsigned long)adr) | left);
23110
23111 return adr;
23112 @@ -693,6 +707,12 @@ void __init mem_init(void)
23113
23114 pci_iommu_alloc();
23115
23116 +#ifdef CONFIG_PAX_PER_CPU_PGD
23117 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
23118 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
23119 + KERNEL_PGD_PTRS);
23120 +#endif
23121 +
23122 /* clear_bss() already clear the empty_zero_page */
23123
23124 reservedpages = 0;
23125 @@ -853,8 +873,8 @@ int kern_addr_valid(unsigned long addr)
23126 static struct vm_area_struct gate_vma = {
23127 .vm_start = VSYSCALL_START,
23128 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
23129 - .vm_page_prot = PAGE_READONLY_EXEC,
23130 - .vm_flags = VM_READ | VM_EXEC
23131 + .vm_page_prot = PAGE_READONLY,
23132 + .vm_flags = VM_READ
23133 };
23134
23135 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
23136 @@ -888,7 +908,7 @@ int in_gate_area_no_mm(unsigned long addr)
23137
23138 const char *arch_vma_name(struct vm_area_struct *vma)
23139 {
23140 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
23141 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
23142 return "[vdso]";
23143 if (vma == &gate_vma)
23144 return "[vsyscall]";
23145 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
23146 index 7b179b4..6bd1777 100644
23147 --- a/arch/x86/mm/iomap_32.c
23148 +++ b/arch/x86/mm/iomap_32.c
23149 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
23150 type = kmap_atomic_idx_push();
23151 idx = type + KM_TYPE_NR * smp_processor_id();
23152 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
23153 +
23154 + pax_open_kernel();
23155 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
23156 + pax_close_kernel();
23157 +
23158 arch_flush_lazy_mmu_mode();
23159
23160 return (void *)vaddr;
23161 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
23162 index be1ef57..55f0160 100644
23163 --- a/arch/x86/mm/ioremap.c
23164 +++ b/arch/x86/mm/ioremap.c
23165 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
23166 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
23167 int is_ram = page_is_ram(pfn);
23168
23169 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
23170 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
23171 return NULL;
23172 WARN_ON_ONCE(is_ram);
23173 }
23174 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
23175
23176 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
23177 if (page_is_ram(start >> PAGE_SHIFT))
23178 +#ifdef CONFIG_HIGHMEM
23179 + if ((start >> PAGE_SHIFT) < max_low_pfn)
23180 +#endif
23181 return __va(phys);
23182
23183 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
23184 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
23185 early_param("early_ioremap_debug", early_ioremap_debug_setup);
23186
23187 static __initdata int after_paging_init;
23188 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
23189 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
23190
23191 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
23192 {
23193 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
23194 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
23195
23196 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
23197 - memset(bm_pte, 0, sizeof(bm_pte));
23198 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
23199 + pmd_populate_user(&init_mm, pmd, bm_pte);
23200
23201 /*
23202 * The boot-ioremap range spans multiple pmds, for which
23203 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
23204 index d87dd6d..bf3fa66 100644
23205 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
23206 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
23207 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
23208 * memory (e.g. tracked pages)? For now, we need this to avoid
23209 * invoking kmemcheck for PnP BIOS calls.
23210 */
23211 - if (regs->flags & X86_VM_MASK)
23212 + if (v8086_mode(regs))
23213 return false;
23214 - if (regs->cs != __KERNEL_CS)
23215 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
23216 return false;
23217
23218 pte = kmemcheck_pte_lookup(address);
23219 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
23220 index 845df68..1d8d29f 100644
23221 --- a/arch/x86/mm/mmap.c
23222 +++ b/arch/x86/mm/mmap.c
23223 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
23224 * Leave an at least ~128 MB hole with possible stack randomization.
23225 */
23226 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
23227 -#define MAX_GAP (TASK_SIZE/6*5)
23228 +#define MAX_GAP (pax_task_size/6*5)
23229
23230 static int mmap_is_legacy(void)
23231 {
23232 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
23233 return rnd << PAGE_SHIFT;
23234 }
23235
23236 -static unsigned long mmap_base(void)
23237 +static unsigned long mmap_base(struct mm_struct *mm)
23238 {
23239 unsigned long gap = rlimit(RLIMIT_STACK);
23240 + unsigned long pax_task_size = TASK_SIZE;
23241 +
23242 +#ifdef CONFIG_PAX_SEGMEXEC
23243 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23244 + pax_task_size = SEGMEXEC_TASK_SIZE;
23245 +#endif
23246
23247 if (gap < MIN_GAP)
23248 gap = MIN_GAP;
23249 else if (gap > MAX_GAP)
23250 gap = MAX_GAP;
23251
23252 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
23253 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
23254 }
23255
23256 /*
23257 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
23258 * does, but not when emulating X86_32
23259 */
23260 -static unsigned long mmap_legacy_base(void)
23261 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
23262 {
23263 - if (mmap_is_ia32())
23264 + if (mmap_is_ia32()) {
23265 +
23266 +#ifdef CONFIG_PAX_SEGMEXEC
23267 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
23268 + return SEGMEXEC_TASK_UNMAPPED_BASE;
23269 + else
23270 +#endif
23271 +
23272 return TASK_UNMAPPED_BASE;
23273 - else
23274 + } else
23275 return TASK_UNMAPPED_BASE + mmap_rnd();
23276 }
23277
23278 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
23279 void arch_pick_mmap_layout(struct mm_struct *mm)
23280 {
23281 if (mmap_is_legacy()) {
23282 - mm->mmap_base = mmap_legacy_base();
23283 + mm->mmap_base = mmap_legacy_base(mm);
23284 +
23285 +#ifdef CONFIG_PAX_RANDMMAP
23286 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23287 + mm->mmap_base += mm->delta_mmap;
23288 +#endif
23289 +
23290 mm->get_unmapped_area = arch_get_unmapped_area;
23291 mm->unmap_area = arch_unmap_area;
23292 } else {
23293 - mm->mmap_base = mmap_base();
23294 + mm->mmap_base = mmap_base(mm);
23295 +
23296 +#ifdef CONFIG_PAX_RANDMMAP
23297 + if (mm->pax_flags & MF_PAX_RANDMMAP)
23298 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
23299 +#endif
23300 +
23301 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
23302 mm->unmap_area = arch_unmap_area_topdown;
23303 }
23304 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
23305 index de54b9b..799051e 100644
23306 --- a/arch/x86/mm/mmio-mod.c
23307 +++ b/arch/x86/mm/mmio-mod.c
23308 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
23309 break;
23310 default:
23311 {
23312 - unsigned char *ip = (unsigned char *)instptr;
23313 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
23314 my_trace->opcode = MMIO_UNKNOWN_OP;
23315 my_trace->width = 0;
23316 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
23317 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
23318 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23319 void __iomem *addr)
23320 {
23321 - static atomic_t next_id;
23322 + static atomic_unchecked_t next_id;
23323 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
23324 /* These are page-unaligned. */
23325 struct mmiotrace_map map = {
23326 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
23327 .private = trace
23328 },
23329 .phys = offset,
23330 - .id = atomic_inc_return(&next_id)
23331 + .id = atomic_inc_return_unchecked(&next_id)
23332 };
23333 map.map_id = trace->id;
23334
23335 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
23336 index b008656..773eac2 100644
23337 --- a/arch/x86/mm/pageattr-test.c
23338 +++ b/arch/x86/mm/pageattr-test.c
23339 @@ -36,7 +36,7 @@ enum {
23340
23341 static int pte_testbit(pte_t pte)
23342 {
23343 - return pte_flags(pte) & _PAGE_UNUSED1;
23344 + return pte_flags(pte) & _PAGE_CPA_TEST;
23345 }
23346
23347 struct split_state {
23348 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
23349 index f9e5267..77b1a40 100644
23350 --- a/arch/x86/mm/pageattr.c
23351 +++ b/arch/x86/mm/pageattr.c
23352 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23353 */
23354 #ifdef CONFIG_PCI_BIOS
23355 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
23356 - pgprot_val(forbidden) |= _PAGE_NX;
23357 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23358 #endif
23359
23360 /*
23361 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23362 * Does not cover __inittext since that is gone later on. On
23363 * 64bit we do not enforce !NX on the low mapping
23364 */
23365 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
23366 - pgprot_val(forbidden) |= _PAGE_NX;
23367 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
23368 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23369
23370 +#ifdef CONFIG_DEBUG_RODATA
23371 /*
23372 * The .rodata section needs to be read-only. Using the pfn
23373 * catches all aliases.
23374 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23375 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
23376 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
23377 pgprot_val(forbidden) |= _PAGE_RW;
23378 +#endif
23379
23380 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
23381 /*
23382 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
23383 }
23384 #endif
23385
23386 +#ifdef CONFIG_PAX_KERNEXEC
23387 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
23388 + pgprot_val(forbidden) |= _PAGE_RW;
23389 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
23390 + }
23391 +#endif
23392 +
23393 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
23394
23395 return prot;
23396 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
23397 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
23398 {
23399 /* change init_mm */
23400 + pax_open_kernel();
23401 set_pte_atomic(kpte, pte);
23402 +
23403 #ifdef CONFIG_X86_32
23404 if (!SHARED_KERNEL_PMD) {
23405 +
23406 +#ifdef CONFIG_PAX_PER_CPU_PGD
23407 + unsigned long cpu;
23408 +#else
23409 struct page *page;
23410 +#endif
23411
23412 +#ifdef CONFIG_PAX_PER_CPU_PGD
23413 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23414 + pgd_t *pgd = get_cpu_pgd(cpu);
23415 +#else
23416 list_for_each_entry(page, &pgd_list, lru) {
23417 - pgd_t *pgd;
23418 + pgd_t *pgd = (pgd_t *)page_address(page);
23419 +#endif
23420 +
23421 pud_t *pud;
23422 pmd_t *pmd;
23423
23424 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
23425 + pgd += pgd_index(address);
23426 pud = pud_offset(pgd, address);
23427 pmd = pmd_offset(pud, address);
23428 set_pte_atomic((pte_t *)pmd, pte);
23429 }
23430 }
23431 #endif
23432 + pax_close_kernel();
23433 }
23434
23435 static int
23436 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
23437 index f6ff57b..481690f 100644
23438 --- a/arch/x86/mm/pat.c
23439 +++ b/arch/x86/mm/pat.c
23440 @@ -361,7 +361,7 @@ int free_memtype(u64 start, u64 end)
23441
23442 if (!entry) {
23443 printk(KERN_INFO "%s:%d freeing invalid memtype %Lx-%Lx\n",
23444 - current->comm, current->pid, start, end);
23445 + current->comm, task_pid_nr(current), start, end);
23446 return -EINVAL;
23447 }
23448
23449 @@ -492,8 +492,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
23450 while (cursor < to) {
23451 if (!devmem_is_allowed(pfn)) {
23452 printk(KERN_INFO
23453 - "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
23454 - current->comm, from, to);
23455 + "Program %s tried to access /dev/mem between %Lx->%Lx (%Lx).\n",
23456 + current->comm, from, to, cursor);
23457 return 0;
23458 }
23459 cursor += PAGE_SIZE;
23460 @@ -557,7 +557,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
23461 printk(KERN_INFO
23462 "%s:%d ioremap_change_attr failed %s "
23463 "for %Lx-%Lx\n",
23464 - current->comm, current->pid,
23465 + current->comm, task_pid_nr(current),
23466 cattr_name(flags),
23467 base, (unsigned long long)(base + size));
23468 return -EINVAL;
23469 @@ -593,7 +593,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23470 if (want_flags != flags) {
23471 printk(KERN_WARNING
23472 "%s:%d map pfn RAM range req %s for %Lx-%Lx, got %s\n",
23473 - current->comm, current->pid,
23474 + current->comm, task_pid_nr(current),
23475 cattr_name(want_flags),
23476 (unsigned long long)paddr,
23477 (unsigned long long)(paddr + size),
23478 @@ -615,7 +615,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
23479 free_memtype(paddr, paddr + size);
23480 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
23481 " for %Lx-%Lx, got %s\n",
23482 - current->comm, current->pid,
23483 + current->comm, task_pid_nr(current),
23484 cattr_name(want_flags),
23485 (unsigned long long)paddr,
23486 (unsigned long long)(paddr + size),
23487 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
23488 index 9f0614d..92ae64a 100644
23489 --- a/arch/x86/mm/pf_in.c
23490 +++ b/arch/x86/mm/pf_in.c
23491 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
23492 int i;
23493 enum reason_type rv = OTHERS;
23494
23495 - p = (unsigned char *)ins_addr;
23496 + p = (unsigned char *)ktla_ktva(ins_addr);
23497 p += skip_prefix(p, &prf);
23498 p += get_opcode(p, &opcode);
23499
23500 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
23501 struct prefix_bits prf;
23502 int i;
23503
23504 - p = (unsigned char *)ins_addr;
23505 + p = (unsigned char *)ktla_ktva(ins_addr);
23506 p += skip_prefix(p, &prf);
23507 p += get_opcode(p, &opcode);
23508
23509 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
23510 struct prefix_bits prf;
23511 int i;
23512
23513 - p = (unsigned char *)ins_addr;
23514 + p = (unsigned char *)ktla_ktva(ins_addr);
23515 p += skip_prefix(p, &prf);
23516 p += get_opcode(p, &opcode);
23517
23518 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
23519 struct prefix_bits prf;
23520 int i;
23521
23522 - p = (unsigned char *)ins_addr;
23523 + p = (unsigned char *)ktla_ktva(ins_addr);
23524 p += skip_prefix(p, &prf);
23525 p += get_opcode(p, &opcode);
23526 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
23527 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
23528 struct prefix_bits prf;
23529 int i;
23530
23531 - p = (unsigned char *)ins_addr;
23532 + p = (unsigned char *)ktla_ktva(ins_addr);
23533 p += skip_prefix(p, &prf);
23534 p += get_opcode(p, &opcode);
23535 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
23536 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
23537 index 8573b83..c3b1a30 100644
23538 --- a/arch/x86/mm/pgtable.c
23539 +++ b/arch/x86/mm/pgtable.c
23540 @@ -84,10 +84,52 @@ static inline void pgd_list_del(pgd_t *pgd)
23541 list_del(&page->lru);
23542 }
23543
23544 -#define UNSHARED_PTRS_PER_PGD \
23545 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23546 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23547 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
23548
23549 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23550 +{
23551 + while (count--)
23552 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
23553 +}
23554 +#endif
23555
23556 +#ifdef CONFIG_PAX_PER_CPU_PGD
23557 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src, int count)
23558 +{
23559 + while (count--)
23560 +
23561 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23562 + *dst++ = __pgd(pgd_val(*src++) & clone_pgd_mask);
23563 +#else
23564 + *dst++ = *src++;
23565 +#endif
23566 +
23567 +}
23568 +#endif
23569 +
23570 +#ifdef CONFIG_X86_64
23571 +#define pxd_t pud_t
23572 +#define pyd_t pgd_t
23573 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
23574 +#define pxd_free(mm, pud) pud_free((mm), (pud))
23575 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
23576 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
23577 +#define PYD_SIZE PGDIR_SIZE
23578 +#else
23579 +#define pxd_t pmd_t
23580 +#define pyd_t pud_t
23581 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
23582 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
23583 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
23584 +#define pyd_offset(mm, address) pud_offset((mm), (address))
23585 +#define PYD_SIZE PUD_SIZE
23586 +#endif
23587 +
23588 +#ifdef CONFIG_PAX_PER_CPU_PGD
23589 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
23590 +static inline void pgd_dtor(pgd_t *pgd) {}
23591 +#else
23592 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
23593 {
23594 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
23595 @@ -128,6 +170,7 @@ static void pgd_dtor(pgd_t *pgd)
23596 pgd_list_del(pgd);
23597 spin_unlock(&pgd_lock);
23598 }
23599 +#endif
23600
23601 /*
23602 * List of all pgd's needed for non-PAE so it can invalidate entries
23603 @@ -140,7 +183,7 @@ static void pgd_dtor(pgd_t *pgd)
23604 * -- wli
23605 */
23606
23607 -#ifdef CONFIG_X86_PAE
23608 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
23609 /*
23610 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
23611 * updating the top-level pagetable entries to guarantee the
23612 @@ -152,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
23613 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
23614 * and initialize the kernel pmds here.
23615 */
23616 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
23617 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
23618
23619 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23620 {
23621 @@ -170,36 +213,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
23622 */
23623 flush_tlb_mm(mm);
23624 }
23625 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
23626 +#define PREALLOCATED_PXDS USER_PGD_PTRS
23627 #else /* !CONFIG_X86_PAE */
23628
23629 /* No need to prepopulate any pagetable entries in non-PAE modes. */
23630 -#define PREALLOCATED_PMDS 0
23631 +#define PREALLOCATED_PXDS 0
23632
23633 #endif /* CONFIG_X86_PAE */
23634
23635 -static void free_pmds(pmd_t *pmds[])
23636 +static void free_pxds(pxd_t *pxds[])
23637 {
23638 int i;
23639
23640 - for(i = 0; i < PREALLOCATED_PMDS; i++)
23641 - if (pmds[i])
23642 - free_page((unsigned long)pmds[i]);
23643 + for(i = 0; i < PREALLOCATED_PXDS; i++)
23644 + if (pxds[i])
23645 + free_page((unsigned long)pxds[i]);
23646 }
23647
23648 -static int preallocate_pmds(pmd_t *pmds[])
23649 +static int preallocate_pxds(pxd_t *pxds[])
23650 {
23651 int i;
23652 bool failed = false;
23653
23654 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23655 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
23656 - if (pmd == NULL)
23657 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23658 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
23659 + if (pxd == NULL)
23660 failed = true;
23661 - pmds[i] = pmd;
23662 + pxds[i] = pxd;
23663 }
23664
23665 if (failed) {
23666 - free_pmds(pmds);
23667 + free_pxds(pxds);
23668 return -ENOMEM;
23669 }
23670
23671 @@ -212,51 +257,55 @@ static int preallocate_pmds(pmd_t *pmds[])
23672 * preallocate which never got a corresponding vma will need to be
23673 * freed manually.
23674 */
23675 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
23676 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
23677 {
23678 int i;
23679
23680 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
23681 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
23682 pgd_t pgd = pgdp[i];
23683
23684 if (pgd_val(pgd) != 0) {
23685 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
23686 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
23687
23688 - pgdp[i] = native_make_pgd(0);
23689 + set_pgd(pgdp + i, native_make_pgd(0));
23690
23691 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
23692 - pmd_free(mm, pmd);
23693 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
23694 + pxd_free(mm, pxd);
23695 }
23696 }
23697 }
23698
23699 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
23700 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
23701 {
23702 - pud_t *pud;
23703 + pyd_t *pyd;
23704 unsigned long addr;
23705 int i;
23706
23707 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
23708 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
23709 return;
23710
23711 - pud = pud_offset(pgd, 0);
23712 +#ifdef CONFIG_X86_64
23713 + pyd = pyd_offset(mm, 0L);
23714 +#else
23715 + pyd = pyd_offset(pgd, 0L);
23716 +#endif
23717
23718 - for (addr = i = 0; i < PREALLOCATED_PMDS;
23719 - i++, pud++, addr += PUD_SIZE) {
23720 - pmd_t *pmd = pmds[i];
23721 + for (addr = i = 0; i < PREALLOCATED_PXDS;
23722 + i++, pyd++, addr += PYD_SIZE) {
23723 + pxd_t *pxd = pxds[i];
23724
23725 if (i >= KERNEL_PGD_BOUNDARY)
23726 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23727 - sizeof(pmd_t) * PTRS_PER_PMD);
23728 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
23729 + sizeof(pxd_t) * PTRS_PER_PMD);
23730
23731 - pud_populate(mm, pud, pmd);
23732 + pyd_populate(mm, pyd, pxd);
23733 }
23734 }
23735
23736 pgd_t *pgd_alloc(struct mm_struct *mm)
23737 {
23738 pgd_t *pgd;
23739 - pmd_t *pmds[PREALLOCATED_PMDS];
23740 + pxd_t *pxds[PREALLOCATED_PXDS];
23741
23742 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
23743
23744 @@ -265,11 +314,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23745
23746 mm->pgd = pgd;
23747
23748 - if (preallocate_pmds(pmds) != 0)
23749 + if (preallocate_pxds(pxds) != 0)
23750 goto out_free_pgd;
23751
23752 if (paravirt_pgd_alloc(mm) != 0)
23753 - goto out_free_pmds;
23754 + goto out_free_pxds;
23755
23756 /*
23757 * Make sure that pre-populating the pmds is atomic with
23758 @@ -279,14 +328,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
23759 spin_lock(&pgd_lock);
23760
23761 pgd_ctor(mm, pgd);
23762 - pgd_prepopulate_pmd(mm, pgd, pmds);
23763 + pgd_prepopulate_pxd(mm, pgd, pxds);
23764
23765 spin_unlock(&pgd_lock);
23766
23767 return pgd;
23768
23769 -out_free_pmds:
23770 - free_pmds(pmds);
23771 +out_free_pxds:
23772 + free_pxds(pxds);
23773 out_free_pgd:
23774 free_page((unsigned long)pgd);
23775 out:
23776 @@ -295,7 +344,7 @@ out:
23777
23778 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
23779 {
23780 - pgd_mop_up_pmds(mm, pgd);
23781 + pgd_mop_up_pxds(mm, pgd);
23782 pgd_dtor(pgd);
23783 paravirt_pgd_free(mm, pgd);
23784 free_page((unsigned long)pgd);
23785 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
23786 index cac7184..09a39fa 100644
23787 --- a/arch/x86/mm/pgtable_32.c
23788 +++ b/arch/x86/mm/pgtable_32.c
23789 @@ -48,10 +48,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
23790 return;
23791 }
23792 pte = pte_offset_kernel(pmd, vaddr);
23793 +
23794 + pax_open_kernel();
23795 if (pte_val(pteval))
23796 set_pte_at(&init_mm, vaddr, pte, pteval);
23797 else
23798 pte_clear(&init_mm, vaddr, pte);
23799 + pax_close_kernel();
23800
23801 /*
23802 * It's enough to flush this one mapping.
23803 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
23804 index 410531d..0f16030 100644
23805 --- a/arch/x86/mm/setup_nx.c
23806 +++ b/arch/x86/mm/setup_nx.c
23807 @@ -5,8 +5,10 @@
23808 #include <asm/pgtable.h>
23809 #include <asm/proto.h>
23810
23811 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23812 static int disable_nx __cpuinitdata;
23813
23814 +#ifndef CONFIG_PAX_PAGEEXEC
23815 /*
23816 * noexec = on|off
23817 *
23818 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
23819 return 0;
23820 }
23821 early_param("noexec", noexec_setup);
23822 +#endif
23823 +
23824 +#endif
23825
23826 void __cpuinit x86_configure_nx(void)
23827 {
23828 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
23829 if (cpu_has_nx && !disable_nx)
23830 __supported_pte_mask |= _PAGE_NX;
23831 else
23832 +#endif
23833 __supported_pte_mask &= ~_PAGE_NX;
23834 }
23835
23836 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
23837 index d6c0418..06a0ad5 100644
23838 --- a/arch/x86/mm/tlb.c
23839 +++ b/arch/x86/mm/tlb.c
23840 @@ -65,7 +65,11 @@ void leave_mm(int cpu)
23841 BUG();
23842 cpumask_clear_cpu(cpu,
23843 mm_cpumask(percpu_read(cpu_tlbstate.active_mm)));
23844 +
23845 +#ifndef CONFIG_PAX_PER_CPU_PGD
23846 load_cr3(swapper_pg_dir);
23847 +#endif
23848 +
23849 }
23850 EXPORT_SYMBOL_GPL(leave_mm);
23851
23852 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
23853 index 6687022..ceabcfa 100644
23854 --- a/arch/x86/net/bpf_jit.S
23855 +++ b/arch/x86/net/bpf_jit.S
23856 @@ -9,6 +9,7 @@
23857 */
23858 #include <linux/linkage.h>
23859 #include <asm/dwarf2.h>
23860 +#include <asm/alternative-asm.h>
23861
23862 /*
23863 * Calling convention :
23864 @@ -35,6 +36,7 @@ sk_load_word:
23865 jle bpf_slow_path_word
23866 mov (SKBDATA,%rsi),%eax
23867 bswap %eax /* ntohl() */
23868 + pax_force_retaddr
23869 ret
23870
23871
23872 @@ -53,6 +55,7 @@ sk_load_half:
23873 jle bpf_slow_path_half
23874 movzwl (SKBDATA,%rsi),%eax
23875 rol $8,%ax # ntohs()
23876 + pax_force_retaddr
23877 ret
23878
23879 sk_load_byte_ind:
23880 @@ -66,6 +69,7 @@ sk_load_byte:
23881 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
23882 jle bpf_slow_path_byte
23883 movzbl (SKBDATA,%rsi),%eax
23884 + pax_force_retaddr
23885 ret
23886
23887 /**
23888 @@ -82,6 +86,7 @@ ENTRY(sk_load_byte_msh)
23889 movzbl (SKBDATA,%rsi),%ebx
23890 and $15,%bl
23891 shl $2,%bl
23892 + pax_force_retaddr
23893 ret
23894 CFI_ENDPROC
23895 ENDPROC(sk_load_byte_msh)
23896 @@ -91,6 +96,7 @@ bpf_error:
23897 xor %eax,%eax
23898 mov -8(%rbp),%rbx
23899 leaveq
23900 + pax_force_retaddr
23901 ret
23902
23903 /* rsi contains offset and can be scratched */
23904 @@ -113,6 +119,7 @@ bpf_slow_path_word:
23905 js bpf_error
23906 mov -12(%rbp),%eax
23907 bswap %eax
23908 + pax_force_retaddr
23909 ret
23910
23911 bpf_slow_path_half:
23912 @@ -121,12 +128,14 @@ bpf_slow_path_half:
23913 mov -12(%rbp),%ax
23914 rol $8,%ax
23915 movzwl %ax,%eax
23916 + pax_force_retaddr
23917 ret
23918
23919 bpf_slow_path_byte:
23920 bpf_slow_path_common(1)
23921 js bpf_error
23922 movzbl -12(%rbp),%eax
23923 + pax_force_retaddr
23924 ret
23925
23926 bpf_slow_path_byte_msh:
23927 @@ -137,4 +146,5 @@ bpf_slow_path_byte_msh:
23928 and $15,%al
23929 shl $2,%al
23930 xchg %eax,%ebx
23931 + pax_force_retaddr
23932 ret
23933 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
23934 index 7c1b765..8c072c6 100644
23935 --- a/arch/x86/net/bpf_jit_comp.c
23936 +++ b/arch/x86/net/bpf_jit_comp.c
23937 @@ -117,6 +117,10 @@ static inline void bpf_flush_icache(void *start, void *end)
23938 set_fs(old_fs);
23939 }
23940
23941 +struct bpf_jit_work {
23942 + struct work_struct work;
23943 + void *image;
23944 +};
23945
23946 void bpf_jit_compile(struct sk_filter *fp)
23947 {
23948 @@ -141,6 +145,10 @@ void bpf_jit_compile(struct sk_filter *fp)
23949 if (addrs == NULL)
23950 return;
23951
23952 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
23953 + if (!fp->work)
23954 + goto out;
23955 +
23956 /* Before first pass, make a rough estimation of addrs[]
23957 * each bpf instruction is translated to less than 64 bytes
23958 */
23959 @@ -476,7 +484,7 @@ void bpf_jit_compile(struct sk_filter *fp)
23960 func = sk_load_word;
23961 common_load: seen |= SEEN_DATAREF;
23962 if ((int)K < 0)
23963 - goto out;
23964 + goto error;
23965 t_offset = func - (image + addrs[i]);
23966 EMIT1_off32(0xbe, K); /* mov imm32,%esi */
23967 EMIT1_off32(0xe8, t_offset); /* call */
23968 @@ -586,17 +594,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23969 break;
23970 default:
23971 /* hmm, too complex filter, give up with jit compiler */
23972 - goto out;
23973 + goto error;
23974 }
23975 ilen = prog - temp;
23976 if (image) {
23977 if (unlikely(proglen + ilen > oldproglen)) {
23978 pr_err("bpb_jit_compile fatal error\n");
23979 - kfree(addrs);
23980 - module_free(NULL, image);
23981 - return;
23982 + module_free_exec(NULL, image);
23983 + goto error;
23984 }
23985 + pax_open_kernel();
23986 memcpy(image + proglen, temp, ilen);
23987 + pax_close_kernel();
23988 }
23989 proglen += ilen;
23990 addrs[i] = proglen;
23991 @@ -617,11 +626,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
23992 break;
23993 }
23994 if (proglen == oldproglen) {
23995 - image = module_alloc(max_t(unsigned int,
23996 - proglen,
23997 - sizeof(struct work_struct)));
23998 + image = module_alloc_exec(proglen);
23999 if (!image)
24000 - goto out;
24001 + goto error;
24002 }
24003 oldproglen = proglen;
24004 }
24005 @@ -637,7 +644,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
24006 bpf_flush_icache(image, image + proglen);
24007
24008 fp->bpf_func = (void *)image;
24009 - }
24010 + } else
24011 +error:
24012 + kfree(fp->work);
24013 +
24014 out:
24015 kfree(addrs);
24016 return;
24017 @@ -645,18 +655,20 @@ out:
24018
24019 static void jit_free_defer(struct work_struct *arg)
24020 {
24021 - module_free(NULL, arg);
24022 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
24023 + kfree(arg);
24024 }
24025
24026 /* run from softirq, we must use a work_struct to call
24027 - * module_free() from process context
24028 + * module_free_exec() from process context
24029 */
24030 void bpf_jit_free(struct sk_filter *fp)
24031 {
24032 if (fp->bpf_func != sk_run_filter) {
24033 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
24034 + struct work_struct *work = &fp->work->work;
24035
24036 INIT_WORK(work, jit_free_defer);
24037 + fp->work->image = fp->bpf_func;
24038 schedule_work(work);
24039 }
24040 }
24041 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
24042 index bff89df..377758a 100644
24043 --- a/arch/x86/oprofile/backtrace.c
24044 +++ b/arch/x86/oprofile/backtrace.c
24045 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
24046 struct stack_frame_ia32 *fp;
24047 unsigned long bytes;
24048
24049 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
24050 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
24051 if (bytes != sizeof(bufhead))
24052 return NULL;
24053
24054 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
24055 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
24056
24057 oprofile_add_trace(bufhead[0].return_address);
24058
24059 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
24060 struct stack_frame bufhead[2];
24061 unsigned long bytes;
24062
24063 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
24064 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
24065 if (bytes != sizeof(bufhead))
24066 return NULL;
24067
24068 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
24069 {
24070 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
24071
24072 - if (!user_mode_vm(regs)) {
24073 + if (!user_mode(regs)) {
24074 unsigned long stack = kernel_stack_pointer(regs);
24075 if (depth)
24076 dump_trace(NULL, regs, (unsigned long *)stack, 0,
24077 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
24078 index cb29191..036766d 100644
24079 --- a/arch/x86/pci/mrst.c
24080 +++ b/arch/x86/pci/mrst.c
24081 @@ -234,7 +234,9 @@ int __init pci_mrst_init(void)
24082 printk(KERN_INFO "Moorestown platform detected, using MRST PCI ops\n");
24083 pci_mmcfg_late_init();
24084 pcibios_enable_irq = mrst_pci_irq_enable;
24085 - pci_root_ops = pci_mrst_ops;
24086 + pax_open_kernel();
24087 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
24088 + pax_close_kernel();
24089 /* Continue with standard init */
24090 return 1;
24091 }
24092 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
24093 index db0e9a5..0372c14 100644
24094 --- a/arch/x86/pci/pcbios.c
24095 +++ b/arch/x86/pci/pcbios.c
24096 @@ -79,50 +79,93 @@ union bios32 {
24097 static struct {
24098 unsigned long address;
24099 unsigned short segment;
24100 -} bios32_indirect = { 0, __KERNEL_CS };
24101 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
24102
24103 /*
24104 * Returns the entry point for the given service, NULL on error
24105 */
24106
24107 -static unsigned long bios32_service(unsigned long service)
24108 +static unsigned long __devinit bios32_service(unsigned long service)
24109 {
24110 unsigned char return_code; /* %al */
24111 unsigned long address; /* %ebx */
24112 unsigned long length; /* %ecx */
24113 unsigned long entry; /* %edx */
24114 unsigned long flags;
24115 + struct desc_struct d, *gdt;
24116
24117 local_irq_save(flags);
24118 - __asm__("lcall *(%%edi); cld"
24119 +
24120 + gdt = get_cpu_gdt_table(smp_processor_id());
24121 +
24122 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
24123 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
24124 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
24125 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
24126 +
24127 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
24128 : "=a" (return_code),
24129 "=b" (address),
24130 "=c" (length),
24131 "=d" (entry)
24132 : "0" (service),
24133 "1" (0),
24134 - "D" (&bios32_indirect));
24135 + "D" (&bios32_indirect),
24136 + "r"(__PCIBIOS_DS)
24137 + : "memory");
24138 +
24139 + pax_open_kernel();
24140 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
24141 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
24142 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
24143 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
24144 + pax_close_kernel();
24145 +
24146 local_irq_restore(flags);
24147
24148 switch (return_code) {
24149 - case 0:
24150 - return address + entry;
24151 - case 0x80: /* Not present */
24152 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
24153 - return 0;
24154 - default: /* Shouldn't happen */
24155 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
24156 - service, return_code);
24157 + case 0: {
24158 + int cpu;
24159 + unsigned char flags;
24160 +
24161 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
24162 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
24163 + printk(KERN_WARNING "bios32_service: not valid\n");
24164 return 0;
24165 + }
24166 + address = address + PAGE_OFFSET;
24167 + length += 16UL; /* some BIOSs underreport this... */
24168 + flags = 4;
24169 + if (length >= 64*1024*1024) {
24170 + length >>= PAGE_SHIFT;
24171 + flags |= 8;
24172 + }
24173 +
24174 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24175 + gdt = get_cpu_gdt_table(cpu);
24176 + pack_descriptor(&d, address, length, 0x9b, flags);
24177 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
24178 + pack_descriptor(&d, address, length, 0x93, flags);
24179 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
24180 + }
24181 + return entry;
24182 + }
24183 + case 0x80: /* Not present */
24184 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
24185 + return 0;
24186 + default: /* Shouldn't happen */
24187 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
24188 + service, return_code);
24189 + return 0;
24190 }
24191 }
24192
24193 static struct {
24194 unsigned long address;
24195 unsigned short segment;
24196 -} pci_indirect = { 0, __KERNEL_CS };
24197 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
24198
24199 -static int pci_bios_present;
24200 +static int pci_bios_present __read_only;
24201
24202 static int __devinit check_pcibios(void)
24203 {
24204 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
24205 unsigned long flags, pcibios_entry;
24206
24207 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
24208 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
24209 + pci_indirect.address = pcibios_entry;
24210
24211 local_irq_save(flags);
24212 - __asm__(
24213 - "lcall *(%%edi); cld\n\t"
24214 + __asm__("movw %w6, %%ds\n\t"
24215 + "lcall *%%ss:(%%edi); cld\n\t"
24216 + "push %%ss\n\t"
24217 + "pop %%ds\n\t"
24218 "jc 1f\n\t"
24219 "xor %%ah, %%ah\n"
24220 "1:"
24221 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
24222 "=b" (ebx),
24223 "=c" (ecx)
24224 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
24225 - "D" (&pci_indirect)
24226 + "D" (&pci_indirect),
24227 + "r" (__PCIBIOS_DS)
24228 : "memory");
24229 local_irq_restore(flags);
24230
24231 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24232
24233 switch (len) {
24234 case 1:
24235 - __asm__("lcall *(%%esi); cld\n\t"
24236 + __asm__("movw %w6, %%ds\n\t"
24237 + "lcall *%%ss:(%%esi); cld\n\t"
24238 + "push %%ss\n\t"
24239 + "pop %%ds\n\t"
24240 "jc 1f\n\t"
24241 "xor %%ah, %%ah\n"
24242 "1:"
24243 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24244 : "1" (PCIBIOS_READ_CONFIG_BYTE),
24245 "b" (bx),
24246 "D" ((long)reg),
24247 - "S" (&pci_indirect));
24248 + "S" (&pci_indirect),
24249 + "r" (__PCIBIOS_DS));
24250 /*
24251 * Zero-extend the result beyond 8 bits, do not trust the
24252 * BIOS having done it:
24253 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24254 *value &= 0xff;
24255 break;
24256 case 2:
24257 - __asm__("lcall *(%%esi); cld\n\t"
24258 + __asm__("movw %w6, %%ds\n\t"
24259 + "lcall *%%ss:(%%esi); cld\n\t"
24260 + "push %%ss\n\t"
24261 + "pop %%ds\n\t"
24262 "jc 1f\n\t"
24263 "xor %%ah, %%ah\n"
24264 "1:"
24265 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24266 : "1" (PCIBIOS_READ_CONFIG_WORD),
24267 "b" (bx),
24268 "D" ((long)reg),
24269 - "S" (&pci_indirect));
24270 + "S" (&pci_indirect),
24271 + "r" (__PCIBIOS_DS));
24272 /*
24273 * Zero-extend the result beyond 16 bits, do not trust the
24274 * BIOS having done it:
24275 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24276 *value &= 0xffff;
24277 break;
24278 case 4:
24279 - __asm__("lcall *(%%esi); cld\n\t"
24280 + __asm__("movw %w6, %%ds\n\t"
24281 + "lcall *%%ss:(%%esi); cld\n\t"
24282 + "push %%ss\n\t"
24283 + "pop %%ds\n\t"
24284 "jc 1f\n\t"
24285 "xor %%ah, %%ah\n"
24286 "1:"
24287 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
24288 : "1" (PCIBIOS_READ_CONFIG_DWORD),
24289 "b" (bx),
24290 "D" ((long)reg),
24291 - "S" (&pci_indirect));
24292 + "S" (&pci_indirect),
24293 + "r" (__PCIBIOS_DS));
24294 break;
24295 }
24296
24297 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24298
24299 switch (len) {
24300 case 1:
24301 - __asm__("lcall *(%%esi); cld\n\t"
24302 + __asm__("movw %w6, %%ds\n\t"
24303 + "lcall *%%ss:(%%esi); cld\n\t"
24304 + "push %%ss\n\t"
24305 + "pop %%ds\n\t"
24306 "jc 1f\n\t"
24307 "xor %%ah, %%ah\n"
24308 "1:"
24309 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24310 "c" (value),
24311 "b" (bx),
24312 "D" ((long)reg),
24313 - "S" (&pci_indirect));
24314 + "S" (&pci_indirect),
24315 + "r" (__PCIBIOS_DS));
24316 break;
24317 case 2:
24318 - __asm__("lcall *(%%esi); cld\n\t"
24319 + __asm__("movw %w6, %%ds\n\t"
24320 + "lcall *%%ss:(%%esi); cld\n\t"
24321 + "push %%ss\n\t"
24322 + "pop %%ds\n\t"
24323 "jc 1f\n\t"
24324 "xor %%ah, %%ah\n"
24325 "1:"
24326 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24327 "c" (value),
24328 "b" (bx),
24329 "D" ((long)reg),
24330 - "S" (&pci_indirect));
24331 + "S" (&pci_indirect),
24332 + "r" (__PCIBIOS_DS));
24333 break;
24334 case 4:
24335 - __asm__("lcall *(%%esi); cld\n\t"
24336 + __asm__("movw %w6, %%ds\n\t"
24337 + "lcall *%%ss:(%%esi); cld\n\t"
24338 + "push %%ss\n\t"
24339 + "pop %%ds\n\t"
24340 "jc 1f\n\t"
24341 "xor %%ah, %%ah\n"
24342 "1:"
24343 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
24344 "c" (value),
24345 "b" (bx),
24346 "D" ((long)reg),
24347 - "S" (&pci_indirect));
24348 + "S" (&pci_indirect),
24349 + "r" (__PCIBIOS_DS));
24350 break;
24351 }
24352
24353 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24354
24355 DBG("PCI: Fetching IRQ routing table... ");
24356 __asm__("push %%es\n\t"
24357 + "movw %w8, %%ds\n\t"
24358 "push %%ds\n\t"
24359 "pop %%es\n\t"
24360 - "lcall *(%%esi); cld\n\t"
24361 + "lcall *%%ss:(%%esi); cld\n\t"
24362 "pop %%es\n\t"
24363 + "push %%ss\n\t"
24364 + "pop %%ds\n"
24365 "jc 1f\n\t"
24366 "xor %%ah, %%ah\n"
24367 "1:"
24368 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
24369 "1" (0),
24370 "D" ((long) &opt),
24371 "S" (&pci_indirect),
24372 - "m" (opt)
24373 + "m" (opt),
24374 + "r" (__PCIBIOS_DS)
24375 : "memory");
24376 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
24377 if (ret & 0xff00)
24378 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24379 {
24380 int ret;
24381
24382 - __asm__("lcall *(%%esi); cld\n\t"
24383 + __asm__("movw %w5, %%ds\n\t"
24384 + "lcall *%%ss:(%%esi); cld\n\t"
24385 + "push %%ss\n\t"
24386 + "pop %%ds\n"
24387 "jc 1f\n\t"
24388 "xor %%ah, %%ah\n"
24389 "1:"
24390 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
24391 : "0" (PCIBIOS_SET_PCI_HW_INT),
24392 "b" ((dev->bus->number << 8) | dev->devfn),
24393 "c" ((irq << 8) | (pin + 10)),
24394 - "S" (&pci_indirect));
24395 + "S" (&pci_indirect),
24396 + "r" (__PCIBIOS_DS));
24397 return !(ret & 0xff00);
24398 }
24399 EXPORT_SYMBOL(pcibios_set_irq_routing);
24400 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
24401 index 40e4469..1ab536e 100644
24402 --- a/arch/x86/platform/efi/efi_32.c
24403 +++ b/arch/x86/platform/efi/efi_32.c
24404 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
24405 {
24406 struct desc_ptr gdt_descr;
24407
24408 +#ifdef CONFIG_PAX_KERNEXEC
24409 + struct desc_struct d;
24410 +#endif
24411 +
24412 local_irq_save(efi_rt_eflags);
24413
24414 load_cr3(initial_page_table);
24415 __flush_tlb_all();
24416
24417 +#ifdef CONFIG_PAX_KERNEXEC
24418 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
24419 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24420 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
24421 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24422 +#endif
24423 +
24424 gdt_descr.address = __pa(get_cpu_gdt_table(0));
24425 gdt_descr.size = GDT_SIZE - 1;
24426 load_gdt(&gdt_descr);
24427 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
24428 {
24429 struct desc_ptr gdt_descr;
24430
24431 +#ifdef CONFIG_PAX_KERNEXEC
24432 + struct desc_struct d;
24433 +
24434 + memset(&d, 0, sizeof d);
24435 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
24436 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
24437 +#endif
24438 +
24439 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
24440 gdt_descr.size = GDT_SIZE - 1;
24441 load_gdt(&gdt_descr);
24442 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
24443 index fbe66e6..c5c0dd2 100644
24444 --- a/arch/x86/platform/efi/efi_stub_32.S
24445 +++ b/arch/x86/platform/efi/efi_stub_32.S
24446 @@ -6,7 +6,9 @@
24447 */
24448
24449 #include <linux/linkage.h>
24450 +#include <linux/init.h>
24451 #include <asm/page_types.h>
24452 +#include <asm/segment.h>
24453
24454 /*
24455 * efi_call_phys(void *, ...) is a function with variable parameters.
24456 @@ -20,7 +22,7 @@
24457 * service functions will comply with gcc calling convention, too.
24458 */
24459
24460 -.text
24461 +__INIT
24462 ENTRY(efi_call_phys)
24463 /*
24464 * 0. The function can only be called in Linux kernel. So CS has been
24465 @@ -36,9 +38,11 @@ ENTRY(efi_call_phys)
24466 * The mapping of lower virtual memory has been created in prelog and
24467 * epilog.
24468 */
24469 - movl $1f, %edx
24470 - subl $__PAGE_OFFSET, %edx
24471 - jmp *%edx
24472 + movl $(__KERNEXEC_EFI_DS), %edx
24473 + mov %edx, %ds
24474 + mov %edx, %es
24475 + mov %edx, %ss
24476 + ljmp $(__KERNEXEC_EFI_CS),$1f-__PAGE_OFFSET
24477 1:
24478
24479 /*
24480 @@ -47,14 +51,8 @@ ENTRY(efi_call_phys)
24481 * parameter 2, ..., param n. To make things easy, we save the return
24482 * address of efi_call_phys in a global variable.
24483 */
24484 - popl %edx
24485 - movl %edx, saved_return_addr
24486 - /* get the function pointer into ECX*/
24487 - popl %ecx
24488 - movl %ecx, efi_rt_function_ptr
24489 - movl $2f, %edx
24490 - subl $__PAGE_OFFSET, %edx
24491 - pushl %edx
24492 + popl (saved_return_addr)
24493 + popl (efi_rt_function_ptr)
24494
24495 /*
24496 * 3. Clear PG bit in %CR0.
24497 @@ -73,9 +71,8 @@ ENTRY(efi_call_phys)
24498 /*
24499 * 5. Call the physical function.
24500 */
24501 - jmp *%ecx
24502 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
24503
24504 -2:
24505 /*
24506 * 6. After EFI runtime service returns, control will return to
24507 * following instruction. We'd better readjust stack pointer first.
24508 @@ -88,35 +85,32 @@ ENTRY(efi_call_phys)
24509 movl %cr0, %edx
24510 orl $0x80000000, %edx
24511 movl %edx, %cr0
24512 - jmp 1f
24513 -1:
24514 +
24515 /*
24516 * 8. Now restore the virtual mode from flat mode by
24517 * adding EIP with PAGE_OFFSET.
24518 */
24519 - movl $1f, %edx
24520 - jmp *%edx
24521 + ljmp $(__KERNEL_CS),$1f+__PAGE_OFFSET
24522 1:
24523 + movl $(__KERNEL_DS), %edx
24524 + mov %edx, %ds
24525 + mov %edx, %es
24526 + mov %edx, %ss
24527
24528 /*
24529 * 9. Balance the stack. And because EAX contain the return value,
24530 * we'd better not clobber it.
24531 */
24532 - leal efi_rt_function_ptr, %edx
24533 - movl (%edx), %ecx
24534 - pushl %ecx
24535 + pushl (efi_rt_function_ptr)
24536
24537 /*
24538 - * 10. Push the saved return address onto the stack and return.
24539 + * 10. Return to the saved return address.
24540 */
24541 - leal saved_return_addr, %edx
24542 - movl (%edx), %ecx
24543 - pushl %ecx
24544 - ret
24545 + jmpl *(saved_return_addr)
24546 ENDPROC(efi_call_phys)
24547 .previous
24548
24549 -.data
24550 +__INITDATA
24551 saved_return_addr:
24552 .long 0
24553 efi_rt_function_ptr:
24554 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
24555 index 4c07cca..2c8427d 100644
24556 --- a/arch/x86/platform/efi/efi_stub_64.S
24557 +++ b/arch/x86/platform/efi/efi_stub_64.S
24558 @@ -7,6 +7,7 @@
24559 */
24560
24561 #include <linux/linkage.h>
24562 +#include <asm/alternative-asm.h>
24563
24564 #define SAVE_XMM \
24565 mov %rsp, %rax; \
24566 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
24567 call *%rdi
24568 addq $32, %rsp
24569 RESTORE_XMM
24570 + pax_force_retaddr 0, 1
24571 ret
24572 ENDPROC(efi_call0)
24573
24574 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
24575 call *%rdi
24576 addq $32, %rsp
24577 RESTORE_XMM
24578 + pax_force_retaddr 0, 1
24579 ret
24580 ENDPROC(efi_call1)
24581
24582 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
24583 call *%rdi
24584 addq $32, %rsp
24585 RESTORE_XMM
24586 + pax_force_retaddr 0, 1
24587 ret
24588 ENDPROC(efi_call2)
24589
24590 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
24591 call *%rdi
24592 addq $32, %rsp
24593 RESTORE_XMM
24594 + pax_force_retaddr 0, 1
24595 ret
24596 ENDPROC(efi_call3)
24597
24598 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
24599 call *%rdi
24600 addq $32, %rsp
24601 RESTORE_XMM
24602 + pax_force_retaddr 0, 1
24603 ret
24604 ENDPROC(efi_call4)
24605
24606 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
24607 call *%rdi
24608 addq $48, %rsp
24609 RESTORE_XMM
24610 + pax_force_retaddr 0, 1
24611 ret
24612 ENDPROC(efi_call5)
24613
24614 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
24615 call *%rdi
24616 addq $48, %rsp
24617 RESTORE_XMM
24618 + pax_force_retaddr 0, 1
24619 ret
24620 ENDPROC(efi_call6)
24621 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
24622 index ad4ec1c..686479e 100644
24623 --- a/arch/x86/platform/mrst/mrst.c
24624 +++ b/arch/x86/platform/mrst/mrst.c
24625 @@ -76,18 +76,20 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
24626 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
24627 int sfi_mrtc_num;
24628
24629 -static void mrst_power_off(void)
24630 +static __noreturn void mrst_power_off(void)
24631 {
24632 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
24633 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 1);
24634 + BUG();
24635 }
24636
24637 -static void mrst_reboot(void)
24638 +static __noreturn void mrst_reboot(void)
24639 {
24640 if (__mrst_cpu_chip == MRST_CPU_CHIP_LINCROFT)
24641 intel_scu_ipc_simple_command(IPCMSG_COLD_RESET, 0);
24642 else
24643 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
24644 + BUG();
24645 }
24646
24647 /* parse all the mtimer info to a static mtimer array */
24648 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
24649 index f10c0af..3ec1f95 100644
24650 --- a/arch/x86/power/cpu.c
24651 +++ b/arch/x86/power/cpu.c
24652 @@ -131,7 +131,7 @@ static void do_fpu_end(void)
24653 static void fix_processor_context(void)
24654 {
24655 int cpu = smp_processor_id();
24656 - struct tss_struct *t = &per_cpu(init_tss, cpu);
24657 + struct tss_struct *t = init_tss + cpu;
24658
24659 set_tss_desc(cpu, t); /*
24660 * This just modifies memory; should not be
24661 @@ -141,7 +141,9 @@ static void fix_processor_context(void)
24662 */
24663
24664 #ifdef CONFIG_X86_64
24665 + pax_open_kernel();
24666 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
24667 + pax_close_kernel();
24668
24669 syscall_init(); /* This sets MSR_*STAR and related */
24670 #endif
24671 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
24672 index 5d17950..2253fc9 100644
24673 --- a/arch/x86/vdso/Makefile
24674 +++ b/arch/x86/vdso/Makefile
24675 @@ -137,7 +137,7 @@ quiet_cmd_vdso = VDSO $@
24676 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
24677 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
24678
24679 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24680 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
24681 GCOV_PROFILE := n
24682
24683 #
24684 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
24685 index 468d591..8e80a0a 100644
24686 --- a/arch/x86/vdso/vdso32-setup.c
24687 +++ b/arch/x86/vdso/vdso32-setup.c
24688 @@ -25,6 +25,7 @@
24689 #include <asm/tlbflush.h>
24690 #include <asm/vdso.h>
24691 #include <asm/proto.h>
24692 +#include <asm/mman.h>
24693
24694 enum {
24695 VDSO_DISABLED = 0,
24696 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
24697 void enable_sep_cpu(void)
24698 {
24699 int cpu = get_cpu();
24700 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
24701 + struct tss_struct *tss = init_tss + cpu;
24702
24703 if (!boot_cpu_has(X86_FEATURE_SEP)) {
24704 put_cpu();
24705 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
24706 gate_vma.vm_start = FIXADDR_USER_START;
24707 gate_vma.vm_end = FIXADDR_USER_END;
24708 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
24709 - gate_vma.vm_page_prot = __P101;
24710 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
24711 /*
24712 * Make sure the vDSO gets into every core dump.
24713 * Dumping its contents makes post-mortem fully interpretable later
24714 @@ -331,14 +332,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24715 if (compat)
24716 addr = VDSO_HIGH_BASE;
24717 else {
24718 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
24719 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
24720 if (IS_ERR_VALUE(addr)) {
24721 ret = addr;
24722 goto up_fail;
24723 }
24724 }
24725
24726 - current->mm->context.vdso = (void *)addr;
24727 + current->mm->context.vdso = addr;
24728
24729 if (compat_uses_vma || !compat) {
24730 /*
24731 @@ -361,11 +362,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24732 }
24733
24734 current_thread_info()->sysenter_return =
24735 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24736 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
24737
24738 up_fail:
24739 if (ret)
24740 - current->mm->context.vdso = NULL;
24741 + current->mm->context.vdso = 0;
24742
24743 up_write(&mm->mmap_sem);
24744
24745 @@ -412,8 +413,14 @@ __initcall(ia32_binfmt_init);
24746
24747 const char *arch_vma_name(struct vm_area_struct *vma)
24748 {
24749 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
24750 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
24751 return "[vdso]";
24752 +
24753 +#ifdef CONFIG_PAX_SEGMEXEC
24754 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
24755 + return "[vdso]";
24756 +#endif
24757 +
24758 return NULL;
24759 }
24760
24761 @@ -423,7 +430,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
24762 * Check to see if the corresponding task was created in compat vdso
24763 * mode.
24764 */
24765 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
24766 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
24767 return &gate_vma;
24768 return NULL;
24769 }
24770 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
24771 index 153407c..611cba9 100644
24772 --- a/arch/x86/vdso/vma.c
24773 +++ b/arch/x86/vdso/vma.c
24774 @@ -16,8 +16,6 @@
24775 #include <asm/vdso.h>
24776 #include <asm/page.h>
24777
24778 -unsigned int __read_mostly vdso_enabled = 1;
24779 -
24780 extern char vdso_start[], vdso_end[];
24781 extern unsigned short vdso_sync_cpuid;
24782
24783 @@ -96,7 +94,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24784 * unaligned here as a result of stack start randomization.
24785 */
24786 addr = PAGE_ALIGN(addr);
24787 - addr = align_addr(addr, NULL, ALIGN_VDSO);
24788
24789 return addr;
24790 }
24791 @@ -106,40 +103,35 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
24792 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
24793 {
24794 struct mm_struct *mm = current->mm;
24795 - unsigned long addr;
24796 + unsigned long addr = 0;
24797 int ret;
24798
24799 - if (!vdso_enabled)
24800 - return 0;
24801 -
24802 down_write(&mm->mmap_sem);
24803 +
24804 +#ifdef CONFIG_PAX_RANDMMAP
24805 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
24806 +#endif
24807 +
24808 addr = vdso_addr(mm->start_stack, vdso_size);
24809 + addr = align_addr(addr, NULL, ALIGN_VDSO);
24810 addr = get_unmapped_area(NULL, addr, vdso_size, 0, 0);
24811 if (IS_ERR_VALUE(addr)) {
24812 ret = addr;
24813 goto up_fail;
24814 }
24815
24816 - current->mm->context.vdso = (void *)addr;
24817 + mm->context.vdso = addr;
24818
24819 ret = install_special_mapping(mm, addr, vdso_size,
24820 VM_READ|VM_EXEC|
24821 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC|
24822 VM_ALWAYSDUMP,
24823 vdso_pages);
24824 - if (ret) {
24825 - current->mm->context.vdso = NULL;
24826 - goto up_fail;
24827 - }
24828 +
24829 + if (ret)
24830 + mm->context.vdso = 0;
24831
24832 up_fail:
24833 up_write(&mm->mmap_sem);
24834 return ret;
24835 }
24836 -
24837 -static __init int vdso_setup(char *s)
24838 -{
24839 - vdso_enabled = simple_strtoul(s, NULL, 0);
24840 - return 0;
24841 -}
24842 -__setup("vdso=", vdso_setup);
24843 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
24844 index 1f92865..c843b20 100644
24845 --- a/arch/x86/xen/enlighten.c
24846 +++ b/arch/x86/xen/enlighten.c
24847 @@ -85,8 +85,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
24848
24849 struct shared_info xen_dummy_shared_info;
24850
24851 -void *xen_initial_gdt;
24852 -
24853 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
24854 __read_mostly int xen_have_vector_callback;
24855 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
24856 @@ -1029,7 +1027,7 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
24857 #endif
24858 };
24859
24860 -static void xen_reboot(int reason)
24861 +static __noreturn void xen_reboot(int reason)
24862 {
24863 struct sched_shutdown r = { .reason = reason };
24864
24865 @@ -1037,17 +1035,17 @@ static void xen_reboot(int reason)
24866 BUG();
24867 }
24868
24869 -static void xen_restart(char *msg)
24870 +static __noreturn void xen_restart(char *msg)
24871 {
24872 xen_reboot(SHUTDOWN_reboot);
24873 }
24874
24875 -static void xen_emergency_restart(void)
24876 +static __noreturn void xen_emergency_restart(void)
24877 {
24878 xen_reboot(SHUTDOWN_reboot);
24879 }
24880
24881 -static void xen_machine_halt(void)
24882 +static __noreturn void xen_machine_halt(void)
24883 {
24884 xen_reboot(SHUTDOWN_poweroff);
24885 }
24886 @@ -1153,7 +1151,17 @@ asmlinkage void __init xen_start_kernel(void)
24887 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
24888
24889 /* Work out if we support NX */
24890 - x86_configure_nx();
24891 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
24892 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
24893 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
24894 + unsigned l, h;
24895 +
24896 + __supported_pte_mask |= _PAGE_NX;
24897 + rdmsr(MSR_EFER, l, h);
24898 + l |= EFER_NX;
24899 + wrmsr(MSR_EFER, l, h);
24900 + }
24901 +#endif
24902
24903 xen_setup_features();
24904
24905 @@ -1184,13 +1192,6 @@ asmlinkage void __init xen_start_kernel(void)
24906
24907 machine_ops = xen_machine_ops;
24908
24909 - /*
24910 - * The only reliable way to retain the initial address of the
24911 - * percpu gdt_page is to remember it here, so we can go and
24912 - * mark it RW later, when the initial percpu area is freed.
24913 - */
24914 - xen_initial_gdt = &per_cpu(gdt_page, 0);
24915 -
24916 xen_smp_init();
24917
24918 #ifdef CONFIG_ACPI_NUMA
24919 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
24920 index 87f6673..e2555a6 100644
24921 --- a/arch/x86/xen/mmu.c
24922 +++ b/arch/x86/xen/mmu.c
24923 @@ -1733,6 +1733,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24924 convert_pfn_mfn(init_level4_pgt);
24925 convert_pfn_mfn(level3_ident_pgt);
24926 convert_pfn_mfn(level3_kernel_pgt);
24927 + convert_pfn_mfn(level3_vmalloc_start_pgt);
24928 + convert_pfn_mfn(level3_vmalloc_end_pgt);
24929 + convert_pfn_mfn(level3_vmemmap_pgt);
24930
24931 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
24932 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
24933 @@ -1751,7 +1754,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
24934 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
24935 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
24936 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
24937 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
24938 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
24939 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
24940 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
24941 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
24942 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
24943 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
24944
24945 @@ -1962,6 +1969,7 @@ static void __init xen_post_allocator_init(void)
24946 pv_mmu_ops.set_pud = xen_set_pud;
24947 #if PAGETABLE_LEVELS == 4
24948 pv_mmu_ops.set_pgd = xen_set_pgd;
24949 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
24950 #endif
24951
24952 /* This will work as long as patching hasn't happened yet
24953 @@ -2043,6 +2051,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
24954 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
24955 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
24956 .set_pgd = xen_set_pgd_hyper,
24957 + .set_pgd_batched = xen_set_pgd_hyper,
24958
24959 .alloc_pud = xen_alloc_pmd_init,
24960 .release_pud = xen_release_pmd_init,
24961 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
24962 index 041d4fe..7666b7e 100644
24963 --- a/arch/x86/xen/smp.c
24964 +++ b/arch/x86/xen/smp.c
24965 @@ -194,11 +194,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
24966 {
24967 BUG_ON(smp_processor_id() != 0);
24968 native_smp_prepare_boot_cpu();
24969 -
24970 - /* We've switched to the "real" per-cpu gdt, so make sure the
24971 - old memory can be recycled */
24972 - make_lowmem_page_readwrite(xen_initial_gdt);
24973 -
24974 xen_filter_cpu_maps();
24975 xen_setup_vcpu_info_placement();
24976 }
24977 @@ -275,12 +270,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
24978 gdt = get_cpu_gdt_table(cpu);
24979
24980 ctxt->flags = VGCF_IN_KERNEL;
24981 - ctxt->user_regs.ds = __USER_DS;
24982 - ctxt->user_regs.es = __USER_DS;
24983 + ctxt->user_regs.ds = __KERNEL_DS;
24984 + ctxt->user_regs.es = __KERNEL_DS;
24985 ctxt->user_regs.ss = __KERNEL_DS;
24986 #ifdef CONFIG_X86_32
24987 ctxt->user_regs.fs = __KERNEL_PERCPU;
24988 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
24989 + savesegment(gs, ctxt->user_regs.gs);
24990 #else
24991 ctxt->gs_base_kernel = per_cpu_offset(cpu);
24992 #endif
24993 @@ -331,13 +326,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)
24994 int rc;
24995
24996 per_cpu(current_task, cpu) = idle;
24997 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
24998 #ifdef CONFIG_X86_32
24999 irq_ctx_init(cpu);
25000 #else
25001 clear_tsk_thread_flag(idle, TIF_FORK);
25002 - per_cpu(kernel_stack, cpu) =
25003 - (unsigned long)task_stack_page(idle) -
25004 - KERNEL_STACK_OFFSET + THREAD_SIZE;
25005 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25006 #endif
25007 xen_setup_runstate_info(cpu);
25008 xen_setup_timer(cpu);
25009 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
25010 index b040b0e..8cc4fe0 100644
25011 --- a/arch/x86/xen/xen-asm_32.S
25012 +++ b/arch/x86/xen/xen-asm_32.S
25013 @@ -83,14 +83,14 @@ ENTRY(xen_iret)
25014 ESP_OFFSET=4 # bytes pushed onto stack
25015
25016 /*
25017 - * Store vcpu_info pointer for easy access. Do it this way to
25018 - * avoid having to reload %fs
25019 + * Store vcpu_info pointer for easy access.
25020 */
25021 #ifdef CONFIG_SMP
25022 - GET_THREAD_INFO(%eax)
25023 - movl TI_cpu(%eax), %eax
25024 - movl __per_cpu_offset(,%eax,4), %eax
25025 - mov xen_vcpu(%eax), %eax
25026 + push %fs
25027 + mov $(__KERNEL_PERCPU), %eax
25028 + mov %eax, %fs
25029 + mov PER_CPU_VAR(xen_vcpu), %eax
25030 + pop %fs
25031 #else
25032 movl xen_vcpu, %eax
25033 #endif
25034 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
25035 index aaa7291..3f77960 100644
25036 --- a/arch/x86/xen/xen-head.S
25037 +++ b/arch/x86/xen/xen-head.S
25038 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
25039 #ifdef CONFIG_X86_32
25040 mov %esi,xen_start_info
25041 mov $init_thread_union+THREAD_SIZE,%esp
25042 +#ifdef CONFIG_SMP
25043 + movl $cpu_gdt_table,%edi
25044 + movl $__per_cpu_load,%eax
25045 + movw %ax,__KERNEL_PERCPU + 2(%edi)
25046 + rorl $16,%eax
25047 + movb %al,__KERNEL_PERCPU + 4(%edi)
25048 + movb %ah,__KERNEL_PERCPU + 7(%edi)
25049 + movl $__per_cpu_end - 1,%eax
25050 + subl $__per_cpu_start,%eax
25051 + movw %ax,__KERNEL_PERCPU + 0(%edi)
25052 +#endif
25053 #else
25054 mov %rsi,xen_start_info
25055 mov $init_thread_union+THREAD_SIZE,%rsp
25056 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
25057 index b095739..8c17bcd 100644
25058 --- a/arch/x86/xen/xen-ops.h
25059 +++ b/arch/x86/xen/xen-ops.h
25060 @@ -10,8 +10,6 @@
25061 extern const char xen_hypervisor_callback[];
25062 extern const char xen_failsafe_callback[];
25063
25064 -extern void *xen_initial_gdt;
25065 -
25066 struct trap_info;
25067 void xen_copy_trap_info(struct trap_info *traps);
25068
25069 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
25070 index 58916af..9cb880b 100644
25071 --- a/block/blk-iopoll.c
25072 +++ b/block/blk-iopoll.c
25073 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
25074 }
25075 EXPORT_SYMBOL(blk_iopoll_complete);
25076
25077 -static void blk_iopoll_softirq(struct softirq_action *h)
25078 +static void blk_iopoll_softirq(void)
25079 {
25080 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
25081 int rearm = 0, budget = blk_iopoll_budget;
25082 diff --git a/block/blk-map.c b/block/blk-map.c
25083 index 623e1cd..ca1e109 100644
25084 --- a/block/blk-map.c
25085 +++ b/block/blk-map.c
25086 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
25087 if (!len || !kbuf)
25088 return -EINVAL;
25089
25090 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
25091 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
25092 if (do_copy)
25093 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
25094 else
25095 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
25096 index 1366a89..e17f54b 100644
25097 --- a/block/blk-softirq.c
25098 +++ b/block/blk-softirq.c
25099 @@ -17,7 +17,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
25100 * Softirq action handler - move entries to local list and loop over them
25101 * while passing them to the queue registered handler.
25102 */
25103 -static void blk_done_softirq(struct softirq_action *h)
25104 +static void blk_done_softirq(void)
25105 {
25106 struct list_head *cpu_list, local_list;
25107
25108 diff --git a/block/bsg.c b/block/bsg.c
25109 index 702f131..37808bf 100644
25110 --- a/block/bsg.c
25111 +++ b/block/bsg.c
25112 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
25113 struct sg_io_v4 *hdr, struct bsg_device *bd,
25114 fmode_t has_write_perm)
25115 {
25116 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25117 + unsigned char *cmdptr;
25118 +
25119 if (hdr->request_len > BLK_MAX_CDB) {
25120 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
25121 if (!rq->cmd)
25122 return -ENOMEM;
25123 - }
25124 + cmdptr = rq->cmd;
25125 + } else
25126 + cmdptr = tmpcmd;
25127
25128 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
25129 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
25130 hdr->request_len))
25131 return -EFAULT;
25132
25133 + if (cmdptr != rq->cmd)
25134 + memcpy(rq->cmd, cmdptr, hdr->request_len);
25135 +
25136 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
25137 if (blk_verify_command(rq->cmd, has_write_perm))
25138 return -EPERM;
25139 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
25140 index 7b72502..646105c 100644
25141 --- a/block/compat_ioctl.c
25142 +++ b/block/compat_ioctl.c
25143 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
25144 err |= __get_user(f->spec1, &uf->spec1);
25145 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
25146 err |= __get_user(name, &uf->name);
25147 - f->name = compat_ptr(name);
25148 + f->name = (void __force_kernel *)compat_ptr(name);
25149 if (err) {
25150 err = -EFAULT;
25151 goto out;
25152 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
25153 index 688be8a..8a37d98 100644
25154 --- a/block/scsi_ioctl.c
25155 +++ b/block/scsi_ioctl.c
25156 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
25157 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
25158 struct sg_io_hdr *hdr, fmode_t mode)
25159 {
25160 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
25161 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25162 + unsigned char *cmdptr;
25163 +
25164 + if (rq->cmd != rq->__cmd)
25165 + cmdptr = rq->cmd;
25166 + else
25167 + cmdptr = tmpcmd;
25168 +
25169 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
25170 return -EFAULT;
25171 +
25172 + if (cmdptr != rq->cmd)
25173 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
25174 +
25175 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
25176 return -EPERM;
25177
25178 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
25179 int err;
25180 unsigned int in_len, out_len, bytes, opcode, cmdlen;
25181 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
25182 + unsigned char tmpcmd[sizeof(rq->__cmd)];
25183 + unsigned char *cmdptr;
25184
25185 if (!sic)
25186 return -EINVAL;
25187 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
25188 */
25189 err = -EFAULT;
25190 rq->cmd_len = cmdlen;
25191 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
25192 +
25193 + if (rq->cmd != rq->__cmd)
25194 + cmdptr = rq->cmd;
25195 + else
25196 + cmdptr = tmpcmd;
25197 +
25198 + if (copy_from_user(cmdptr, sic->data, cmdlen))
25199 goto error;
25200
25201 + if (rq->cmd != cmdptr)
25202 + memcpy(rq->cmd, cmdptr, cmdlen);
25203 +
25204 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
25205 goto error;
25206
25207 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
25208 index 671d4d6..5f24030 100644
25209 --- a/crypto/cryptd.c
25210 +++ b/crypto/cryptd.c
25211 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
25212
25213 struct cryptd_blkcipher_request_ctx {
25214 crypto_completion_t complete;
25215 -};
25216 +} __no_const;
25217
25218 struct cryptd_hash_ctx {
25219 struct crypto_shash *child;
25220 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
25221
25222 struct cryptd_aead_request_ctx {
25223 crypto_completion_t complete;
25224 -};
25225 +} __no_const;
25226
25227 static void cryptd_queue_worker(struct work_struct *work);
25228
25229 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
25230 index 5d41894..22021e4 100644
25231 --- a/drivers/acpi/apei/cper.c
25232 +++ b/drivers/acpi/apei/cper.c
25233 @@ -38,12 +38,12 @@
25234 */
25235 u64 cper_next_record_id(void)
25236 {
25237 - static atomic64_t seq;
25238 + static atomic64_unchecked_t seq;
25239
25240 - if (!atomic64_read(&seq))
25241 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
25242 + if (!atomic64_read_unchecked(&seq))
25243 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
25244
25245 - return atomic64_inc_return(&seq);
25246 + return atomic64_inc_return_unchecked(&seq);
25247 }
25248 EXPORT_SYMBOL_GPL(cper_next_record_id);
25249
25250 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
25251 index 6c47ae9..abfdd63 100644
25252 --- a/drivers/acpi/ec_sys.c
25253 +++ b/drivers/acpi/ec_sys.c
25254 @@ -12,6 +12,7 @@
25255 #include <linux/acpi.h>
25256 #include <linux/debugfs.h>
25257 #include <linux/module.h>
25258 +#include <linux/uaccess.h>
25259 #include "internal.h"
25260
25261 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
25262 @@ -40,7 +41,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25263 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
25264 */
25265 unsigned int size = EC_SPACE_SIZE;
25266 - u8 *data = (u8 *) buf;
25267 + u8 data;
25268 loff_t init_off = *off;
25269 int err = 0;
25270
25271 @@ -53,9 +54,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
25272 size = count;
25273
25274 while (size) {
25275 - err = ec_read(*off, &data[*off - init_off]);
25276 + err = ec_read(*off, &data);
25277 if (err)
25278 return err;
25279 + if (put_user(data, &buf[*off - init_off]))
25280 + return -EFAULT;
25281 *off += 1;
25282 size--;
25283 }
25284 @@ -71,7 +74,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25285
25286 unsigned int size = count;
25287 loff_t init_off = *off;
25288 - u8 *data = (u8 *) buf;
25289 int err = 0;
25290
25291 if (*off >= EC_SPACE_SIZE)
25292 @@ -82,7 +84,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
25293 }
25294
25295 while (size) {
25296 - u8 byte_write = data[*off - init_off];
25297 + u8 byte_write;
25298 + if (get_user(byte_write, &buf[*off - init_off]))
25299 + return -EFAULT;
25300 err = ec_write(*off, byte_write);
25301 if (err)
25302 return err;
25303 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
25304 index 251c7b62..000462d 100644
25305 --- a/drivers/acpi/proc.c
25306 +++ b/drivers/acpi/proc.c
25307 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
25308 size_t count, loff_t * ppos)
25309 {
25310 struct list_head *node, *next;
25311 - char strbuf[5];
25312 - char str[5] = "";
25313 - unsigned int len = count;
25314 + char strbuf[5] = {0};
25315
25316 - if (len > 4)
25317 - len = 4;
25318 - if (len < 0)
25319 + if (count > 4)
25320 + count = 4;
25321 + if (copy_from_user(strbuf, buffer, count))
25322 return -EFAULT;
25323 -
25324 - if (copy_from_user(strbuf, buffer, len))
25325 - return -EFAULT;
25326 - strbuf[len] = '\0';
25327 - sscanf(strbuf, "%s", str);
25328 + strbuf[count] = '\0';
25329
25330 mutex_lock(&acpi_device_lock);
25331 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
25332 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
25333 if (!dev->wakeup.flags.valid)
25334 continue;
25335
25336 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
25337 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
25338 if (device_can_wakeup(&dev->dev)) {
25339 bool enable = !device_may_wakeup(&dev->dev);
25340 device_set_wakeup_enable(&dev->dev, enable);
25341 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
25342 index 9d7bc9f..a6fc091 100644
25343 --- a/drivers/acpi/processor_driver.c
25344 +++ b/drivers/acpi/processor_driver.c
25345 @@ -473,7 +473,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
25346 return 0;
25347 #endif
25348
25349 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
25350 + BUG_ON(pr->id >= nr_cpu_ids);
25351
25352 /*
25353 * Buggy BIOS check
25354 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
25355 index c04ad68..0b99473 100644
25356 --- a/drivers/ata/libata-core.c
25357 +++ b/drivers/ata/libata-core.c
25358 @@ -4733,7 +4733,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
25359 struct ata_port *ap;
25360 unsigned int tag;
25361
25362 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25363 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25364 ap = qc->ap;
25365
25366 qc->flags = 0;
25367 @@ -4749,7 +4749,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
25368 struct ata_port *ap;
25369 struct ata_link *link;
25370
25371 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25372 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
25373 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
25374 ap = qc->ap;
25375 link = qc->dev->link;
25376 @@ -5754,6 +5754,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25377 return;
25378
25379 spin_lock(&lock);
25380 + pax_open_kernel();
25381
25382 for (cur = ops->inherits; cur; cur = cur->inherits) {
25383 void **inherit = (void **)cur;
25384 @@ -5767,8 +5768,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
25385 if (IS_ERR(*pp))
25386 *pp = NULL;
25387
25388 - ops->inherits = NULL;
25389 + *(struct ata_port_operations **)&ops->inherits = NULL;
25390
25391 + pax_close_kernel();
25392 spin_unlock(&lock);
25393 }
25394
25395 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
25396 index e8574bb..f9f6a72 100644
25397 --- a/drivers/ata/pata_arasan_cf.c
25398 +++ b/drivers/ata/pata_arasan_cf.c
25399 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
25400 /* Handle platform specific quirks */
25401 if (pdata->quirk) {
25402 if (pdata->quirk & CF_BROKEN_PIO) {
25403 - ap->ops->set_piomode = NULL;
25404 + pax_open_kernel();
25405 + *(void **)&ap->ops->set_piomode = NULL;
25406 + pax_close_kernel();
25407 ap->pio_mask = 0;
25408 }
25409 if (pdata->quirk & CF_BROKEN_MWDMA)
25410 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
25411 index f9b983a..887b9d8 100644
25412 --- a/drivers/atm/adummy.c
25413 +++ b/drivers/atm/adummy.c
25414 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
25415 vcc->pop(vcc, skb);
25416 else
25417 dev_kfree_skb_any(skb);
25418 - atomic_inc(&vcc->stats->tx);
25419 + atomic_inc_unchecked(&vcc->stats->tx);
25420
25421 return 0;
25422 }
25423 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
25424 index f8f41e0..1f987dd 100644
25425 --- a/drivers/atm/ambassador.c
25426 +++ b/drivers/atm/ambassador.c
25427 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
25428 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
25429
25430 // VC layer stats
25431 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25432 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25433
25434 // free the descriptor
25435 kfree (tx_descr);
25436 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25437 dump_skb ("<<<", vc, skb);
25438
25439 // VC layer stats
25440 - atomic_inc(&atm_vcc->stats->rx);
25441 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25442 __net_timestamp(skb);
25443 // end of our responsibility
25444 atm_vcc->push (atm_vcc, skb);
25445 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
25446 } else {
25447 PRINTK (KERN_INFO, "dropped over-size frame");
25448 // should we count this?
25449 - atomic_inc(&atm_vcc->stats->rx_drop);
25450 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25451 }
25452
25453 } else {
25454 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
25455 }
25456
25457 if (check_area (skb->data, skb->len)) {
25458 - atomic_inc(&atm_vcc->stats->tx_err);
25459 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
25460 return -ENOMEM; // ?
25461 }
25462
25463 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
25464 index b22d71c..d6e1049 100644
25465 --- a/drivers/atm/atmtcp.c
25466 +++ b/drivers/atm/atmtcp.c
25467 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25468 if (vcc->pop) vcc->pop(vcc,skb);
25469 else dev_kfree_skb(skb);
25470 if (dev_data) return 0;
25471 - atomic_inc(&vcc->stats->tx_err);
25472 + atomic_inc_unchecked(&vcc->stats->tx_err);
25473 return -ENOLINK;
25474 }
25475 size = skb->len+sizeof(struct atmtcp_hdr);
25476 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25477 if (!new_skb) {
25478 if (vcc->pop) vcc->pop(vcc,skb);
25479 else dev_kfree_skb(skb);
25480 - atomic_inc(&vcc->stats->tx_err);
25481 + atomic_inc_unchecked(&vcc->stats->tx_err);
25482 return -ENOBUFS;
25483 }
25484 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
25485 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
25486 if (vcc->pop) vcc->pop(vcc,skb);
25487 else dev_kfree_skb(skb);
25488 out_vcc->push(out_vcc,new_skb);
25489 - atomic_inc(&vcc->stats->tx);
25490 - atomic_inc(&out_vcc->stats->rx);
25491 + atomic_inc_unchecked(&vcc->stats->tx);
25492 + atomic_inc_unchecked(&out_vcc->stats->rx);
25493 return 0;
25494 }
25495
25496 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25497 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
25498 read_unlock(&vcc_sklist_lock);
25499 if (!out_vcc) {
25500 - atomic_inc(&vcc->stats->tx_err);
25501 + atomic_inc_unchecked(&vcc->stats->tx_err);
25502 goto done;
25503 }
25504 skb_pull(skb,sizeof(struct atmtcp_hdr));
25505 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
25506 __net_timestamp(new_skb);
25507 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
25508 out_vcc->push(out_vcc,new_skb);
25509 - atomic_inc(&vcc->stats->tx);
25510 - atomic_inc(&out_vcc->stats->rx);
25511 + atomic_inc_unchecked(&vcc->stats->tx);
25512 + atomic_inc_unchecked(&out_vcc->stats->rx);
25513 done:
25514 if (vcc->pop) vcc->pop(vcc,skb);
25515 else dev_kfree_skb(skb);
25516 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
25517 index 956e9ac..133516d 100644
25518 --- a/drivers/atm/eni.c
25519 +++ b/drivers/atm/eni.c
25520 @@ -526,7 +526,7 @@ static int rx_aal0(struct atm_vcc *vcc)
25521 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
25522 vcc->dev->number);
25523 length = 0;
25524 - atomic_inc(&vcc->stats->rx_err);
25525 + atomic_inc_unchecked(&vcc->stats->rx_err);
25526 }
25527 else {
25528 length = ATM_CELL_SIZE-1; /* no HEC */
25529 @@ -581,7 +581,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25530 size);
25531 }
25532 eff = length = 0;
25533 - atomic_inc(&vcc->stats->rx_err);
25534 + atomic_inc_unchecked(&vcc->stats->rx_err);
25535 }
25536 else {
25537 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
25538 @@ -598,7 +598,7 @@ static int rx_aal5(struct atm_vcc *vcc)
25539 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
25540 vcc->dev->number,vcc->vci,length,size << 2,descr);
25541 length = eff = 0;
25542 - atomic_inc(&vcc->stats->rx_err);
25543 + atomic_inc_unchecked(&vcc->stats->rx_err);
25544 }
25545 }
25546 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
25547 @@ -771,7 +771,7 @@ rx_dequeued++;
25548 vcc->push(vcc,skb);
25549 pushed++;
25550 }
25551 - atomic_inc(&vcc->stats->rx);
25552 + atomic_inc_unchecked(&vcc->stats->rx);
25553 }
25554 wake_up(&eni_dev->rx_wait);
25555 }
25556 @@ -1229,7 +1229,7 @@ static void dequeue_tx(struct atm_dev *dev)
25557 PCI_DMA_TODEVICE);
25558 if (vcc->pop) vcc->pop(vcc,skb);
25559 else dev_kfree_skb_irq(skb);
25560 - atomic_inc(&vcc->stats->tx);
25561 + atomic_inc_unchecked(&vcc->stats->tx);
25562 wake_up(&eni_dev->tx_wait);
25563 dma_complete++;
25564 }
25565 @@ -1569,7 +1569,7 @@ tx_complete++;
25566 /*--------------------------------- entries ---------------------------------*/
25567
25568
25569 -static const char *media_name[] __devinitdata = {
25570 +static const char *media_name[] __devinitconst = {
25571 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
25572 "UTP", "05?", "06?", "07?", /* 4- 7 */
25573 "TAXI","09?", "10?", "11?", /* 8-11 */
25574 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
25575 index 5072f8a..fa52520d 100644
25576 --- a/drivers/atm/firestream.c
25577 +++ b/drivers/atm/firestream.c
25578 @@ -750,7 +750,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
25579 }
25580 }
25581
25582 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25583 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25584
25585 fs_dprintk (FS_DEBUG_TXMEM, "i");
25586 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
25587 @@ -817,7 +817,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25588 #endif
25589 skb_put (skb, qe->p1 & 0xffff);
25590 ATM_SKB(skb)->vcc = atm_vcc;
25591 - atomic_inc(&atm_vcc->stats->rx);
25592 + atomic_inc_unchecked(&atm_vcc->stats->rx);
25593 __net_timestamp(skb);
25594 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
25595 atm_vcc->push (atm_vcc, skb);
25596 @@ -838,12 +838,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
25597 kfree (pe);
25598 }
25599 if (atm_vcc)
25600 - atomic_inc(&atm_vcc->stats->rx_drop);
25601 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25602 break;
25603 case 0x1f: /* Reassembly abort: no buffers. */
25604 /* Silently increment error counter. */
25605 if (atm_vcc)
25606 - atomic_inc(&atm_vcc->stats->rx_drop);
25607 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
25608 break;
25609 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
25610 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
25611 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
25612 index 361f5ae..7fc552d 100644
25613 --- a/drivers/atm/fore200e.c
25614 +++ b/drivers/atm/fore200e.c
25615 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
25616 #endif
25617 /* check error condition */
25618 if (*entry->status & STATUS_ERROR)
25619 - atomic_inc(&vcc->stats->tx_err);
25620 + atomic_inc_unchecked(&vcc->stats->tx_err);
25621 else
25622 - atomic_inc(&vcc->stats->tx);
25623 + atomic_inc_unchecked(&vcc->stats->tx);
25624 }
25625 }
25626
25627 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25628 if (skb == NULL) {
25629 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
25630
25631 - atomic_inc(&vcc->stats->rx_drop);
25632 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25633 return -ENOMEM;
25634 }
25635
25636 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
25637
25638 dev_kfree_skb_any(skb);
25639
25640 - atomic_inc(&vcc->stats->rx_drop);
25641 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25642 return -ENOMEM;
25643 }
25644
25645 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25646
25647 vcc->push(vcc, skb);
25648 - atomic_inc(&vcc->stats->rx);
25649 + atomic_inc_unchecked(&vcc->stats->rx);
25650
25651 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
25652
25653 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
25654 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
25655 fore200e->atm_dev->number,
25656 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
25657 - atomic_inc(&vcc->stats->rx_err);
25658 + atomic_inc_unchecked(&vcc->stats->rx_err);
25659 }
25660 }
25661
25662 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
25663 goto retry_here;
25664 }
25665
25666 - atomic_inc(&vcc->stats->tx_err);
25667 + atomic_inc_unchecked(&vcc->stats->tx_err);
25668
25669 fore200e->tx_sat++;
25670 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
25671 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
25672 index 9a51df4..f3bb5f8 100644
25673 --- a/drivers/atm/he.c
25674 +++ b/drivers/atm/he.c
25675 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25676
25677 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
25678 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
25679 - atomic_inc(&vcc->stats->rx_drop);
25680 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25681 goto return_host_buffers;
25682 }
25683
25684 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25685 RBRQ_LEN_ERR(he_dev->rbrq_head)
25686 ? "LEN_ERR" : "",
25687 vcc->vpi, vcc->vci);
25688 - atomic_inc(&vcc->stats->rx_err);
25689 + atomic_inc_unchecked(&vcc->stats->rx_err);
25690 goto return_host_buffers;
25691 }
25692
25693 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
25694 vcc->push(vcc, skb);
25695 spin_lock(&he_dev->global_lock);
25696
25697 - atomic_inc(&vcc->stats->rx);
25698 + atomic_inc_unchecked(&vcc->stats->rx);
25699
25700 return_host_buffers:
25701 ++pdus_assembled;
25702 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
25703 tpd->vcc->pop(tpd->vcc, tpd->skb);
25704 else
25705 dev_kfree_skb_any(tpd->skb);
25706 - atomic_inc(&tpd->vcc->stats->tx_err);
25707 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
25708 }
25709 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
25710 return;
25711 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25712 vcc->pop(vcc, skb);
25713 else
25714 dev_kfree_skb_any(skb);
25715 - atomic_inc(&vcc->stats->tx_err);
25716 + atomic_inc_unchecked(&vcc->stats->tx_err);
25717 return -EINVAL;
25718 }
25719
25720 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25721 vcc->pop(vcc, skb);
25722 else
25723 dev_kfree_skb_any(skb);
25724 - atomic_inc(&vcc->stats->tx_err);
25725 + atomic_inc_unchecked(&vcc->stats->tx_err);
25726 return -EINVAL;
25727 }
25728 #endif
25729 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25730 vcc->pop(vcc, skb);
25731 else
25732 dev_kfree_skb_any(skb);
25733 - atomic_inc(&vcc->stats->tx_err);
25734 + atomic_inc_unchecked(&vcc->stats->tx_err);
25735 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25736 return -ENOMEM;
25737 }
25738 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25739 vcc->pop(vcc, skb);
25740 else
25741 dev_kfree_skb_any(skb);
25742 - atomic_inc(&vcc->stats->tx_err);
25743 + atomic_inc_unchecked(&vcc->stats->tx_err);
25744 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25745 return -ENOMEM;
25746 }
25747 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
25748 __enqueue_tpd(he_dev, tpd, cid);
25749 spin_unlock_irqrestore(&he_dev->global_lock, flags);
25750
25751 - atomic_inc(&vcc->stats->tx);
25752 + atomic_inc_unchecked(&vcc->stats->tx);
25753
25754 return 0;
25755 }
25756 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
25757 index b812103..e391a49 100644
25758 --- a/drivers/atm/horizon.c
25759 +++ b/drivers/atm/horizon.c
25760 @@ -1035,7 +1035,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
25761 {
25762 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
25763 // VC layer stats
25764 - atomic_inc(&vcc->stats->rx);
25765 + atomic_inc_unchecked(&vcc->stats->rx);
25766 __net_timestamp(skb);
25767 // end of our responsibility
25768 vcc->push (vcc, skb);
25769 @@ -1187,7 +1187,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
25770 dev->tx_iovec = NULL;
25771
25772 // VC layer stats
25773 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
25774 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
25775
25776 // free the skb
25777 hrz_kfree_skb (skb);
25778 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
25779 index 1c05212..c28e200 100644
25780 --- a/drivers/atm/idt77252.c
25781 +++ b/drivers/atm/idt77252.c
25782 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
25783 else
25784 dev_kfree_skb(skb);
25785
25786 - atomic_inc(&vcc->stats->tx);
25787 + atomic_inc_unchecked(&vcc->stats->tx);
25788 }
25789
25790 atomic_dec(&scq->used);
25791 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25792 if ((sb = dev_alloc_skb(64)) == NULL) {
25793 printk("%s: Can't allocate buffers for aal0.\n",
25794 card->name);
25795 - atomic_add(i, &vcc->stats->rx_drop);
25796 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
25797 break;
25798 }
25799 if (!atm_charge(vcc, sb->truesize)) {
25800 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
25801 card->name);
25802 - atomic_add(i - 1, &vcc->stats->rx_drop);
25803 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
25804 dev_kfree_skb(sb);
25805 break;
25806 }
25807 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25808 ATM_SKB(sb)->vcc = vcc;
25809 __net_timestamp(sb);
25810 vcc->push(vcc, sb);
25811 - atomic_inc(&vcc->stats->rx);
25812 + atomic_inc_unchecked(&vcc->stats->rx);
25813
25814 cell += ATM_CELL_PAYLOAD;
25815 }
25816 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25817 "(CDC: %08x)\n",
25818 card->name, len, rpp->len, readl(SAR_REG_CDC));
25819 recycle_rx_pool_skb(card, rpp);
25820 - atomic_inc(&vcc->stats->rx_err);
25821 + atomic_inc_unchecked(&vcc->stats->rx_err);
25822 return;
25823 }
25824 if (stat & SAR_RSQE_CRC) {
25825 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
25826 recycle_rx_pool_skb(card, rpp);
25827 - atomic_inc(&vcc->stats->rx_err);
25828 + atomic_inc_unchecked(&vcc->stats->rx_err);
25829 return;
25830 }
25831 if (skb_queue_len(&rpp->queue) > 1) {
25832 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25833 RXPRINTK("%s: Can't alloc RX skb.\n",
25834 card->name);
25835 recycle_rx_pool_skb(card, rpp);
25836 - atomic_inc(&vcc->stats->rx_err);
25837 + atomic_inc_unchecked(&vcc->stats->rx_err);
25838 return;
25839 }
25840 if (!atm_charge(vcc, skb->truesize)) {
25841 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25842 __net_timestamp(skb);
25843
25844 vcc->push(vcc, skb);
25845 - atomic_inc(&vcc->stats->rx);
25846 + atomic_inc_unchecked(&vcc->stats->rx);
25847
25848 return;
25849 }
25850 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
25851 __net_timestamp(skb);
25852
25853 vcc->push(vcc, skb);
25854 - atomic_inc(&vcc->stats->rx);
25855 + atomic_inc_unchecked(&vcc->stats->rx);
25856
25857 if (skb->truesize > SAR_FB_SIZE_3)
25858 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
25859 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
25860 if (vcc->qos.aal != ATM_AAL0) {
25861 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
25862 card->name, vpi, vci);
25863 - atomic_inc(&vcc->stats->rx_drop);
25864 + atomic_inc_unchecked(&vcc->stats->rx_drop);
25865 goto drop;
25866 }
25867
25868 if ((sb = dev_alloc_skb(64)) == NULL) {
25869 printk("%s: Can't allocate buffers for AAL0.\n",
25870 card->name);
25871 - atomic_inc(&vcc->stats->rx_err);
25872 + atomic_inc_unchecked(&vcc->stats->rx_err);
25873 goto drop;
25874 }
25875
25876 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
25877 ATM_SKB(sb)->vcc = vcc;
25878 __net_timestamp(sb);
25879 vcc->push(vcc, sb);
25880 - atomic_inc(&vcc->stats->rx);
25881 + atomic_inc_unchecked(&vcc->stats->rx);
25882
25883 drop:
25884 skb_pull(queue, 64);
25885 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25886
25887 if (vc == NULL) {
25888 printk("%s: NULL connection in send().\n", card->name);
25889 - atomic_inc(&vcc->stats->tx_err);
25890 + atomic_inc_unchecked(&vcc->stats->tx_err);
25891 dev_kfree_skb(skb);
25892 return -EINVAL;
25893 }
25894 if (!test_bit(VCF_TX, &vc->flags)) {
25895 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
25896 - atomic_inc(&vcc->stats->tx_err);
25897 + atomic_inc_unchecked(&vcc->stats->tx_err);
25898 dev_kfree_skb(skb);
25899 return -EINVAL;
25900 }
25901 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25902 break;
25903 default:
25904 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
25905 - atomic_inc(&vcc->stats->tx_err);
25906 + atomic_inc_unchecked(&vcc->stats->tx_err);
25907 dev_kfree_skb(skb);
25908 return -EINVAL;
25909 }
25910
25911 if (skb_shinfo(skb)->nr_frags != 0) {
25912 printk("%s: No scatter-gather yet.\n", card->name);
25913 - atomic_inc(&vcc->stats->tx_err);
25914 + atomic_inc_unchecked(&vcc->stats->tx_err);
25915 dev_kfree_skb(skb);
25916 return -EINVAL;
25917 }
25918 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
25919
25920 err = queue_skb(card, vc, skb, oam);
25921 if (err) {
25922 - atomic_inc(&vcc->stats->tx_err);
25923 + atomic_inc_unchecked(&vcc->stats->tx_err);
25924 dev_kfree_skb(skb);
25925 return err;
25926 }
25927 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
25928 skb = dev_alloc_skb(64);
25929 if (!skb) {
25930 printk("%s: Out of memory in send_oam().\n", card->name);
25931 - atomic_inc(&vcc->stats->tx_err);
25932 + atomic_inc_unchecked(&vcc->stats->tx_err);
25933 return -ENOMEM;
25934 }
25935 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
25936 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
25937 index 3d0c2b0..45441fa 100644
25938 --- a/drivers/atm/iphase.c
25939 +++ b/drivers/atm/iphase.c
25940 @@ -1146,7 +1146,7 @@ static int rx_pkt(struct atm_dev *dev)
25941 status = (u_short) (buf_desc_ptr->desc_mode);
25942 if (status & (RX_CER | RX_PTE | RX_OFL))
25943 {
25944 - atomic_inc(&vcc->stats->rx_err);
25945 + atomic_inc_unchecked(&vcc->stats->rx_err);
25946 IF_ERR(printk("IA: bad packet, dropping it");)
25947 if (status & RX_CER) {
25948 IF_ERR(printk(" cause: packet CRC error\n");)
25949 @@ -1169,7 +1169,7 @@ static int rx_pkt(struct atm_dev *dev)
25950 len = dma_addr - buf_addr;
25951 if (len > iadev->rx_buf_sz) {
25952 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
25953 - atomic_inc(&vcc->stats->rx_err);
25954 + atomic_inc_unchecked(&vcc->stats->rx_err);
25955 goto out_free_desc;
25956 }
25957
25958 @@ -1319,7 +1319,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25959 ia_vcc = INPH_IA_VCC(vcc);
25960 if (ia_vcc == NULL)
25961 {
25962 - atomic_inc(&vcc->stats->rx_err);
25963 + atomic_inc_unchecked(&vcc->stats->rx_err);
25964 dev_kfree_skb_any(skb);
25965 atm_return(vcc, atm_guess_pdu2truesize(len));
25966 goto INCR_DLE;
25967 @@ -1331,7 +1331,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25968 if ((length > iadev->rx_buf_sz) || (length >
25969 (skb->len - sizeof(struct cpcs_trailer))))
25970 {
25971 - atomic_inc(&vcc->stats->rx_err);
25972 + atomic_inc_unchecked(&vcc->stats->rx_err);
25973 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
25974 length, skb->len);)
25975 dev_kfree_skb_any(skb);
25976 @@ -1347,7 +1347,7 @@ static void rx_dle_intr(struct atm_dev *dev)
25977
25978 IF_RX(printk("rx_dle_intr: skb push");)
25979 vcc->push(vcc,skb);
25980 - atomic_inc(&vcc->stats->rx);
25981 + atomic_inc_unchecked(&vcc->stats->rx);
25982 iadev->rx_pkt_cnt++;
25983 }
25984 INCR_DLE:
25985 @@ -2827,15 +2827,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
25986 {
25987 struct k_sonet_stats *stats;
25988 stats = &PRIV(_ia_dev[board])->sonet_stats;
25989 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
25990 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
25991 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
25992 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
25993 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
25994 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
25995 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
25996 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
25997 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
25998 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
25999 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
26000 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
26001 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
26002 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
26003 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
26004 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
26005 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
26006 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
26007 }
26008 ia_cmds.status = 0;
26009 break;
26010 @@ -2940,7 +2940,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
26011 if ((desc == 0) || (desc > iadev->num_tx_desc))
26012 {
26013 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
26014 - atomic_inc(&vcc->stats->tx);
26015 + atomic_inc_unchecked(&vcc->stats->tx);
26016 if (vcc->pop)
26017 vcc->pop(vcc, skb);
26018 else
26019 @@ -3045,14 +3045,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
26020 ATM_DESC(skb) = vcc->vci;
26021 skb_queue_tail(&iadev->tx_dma_q, skb);
26022
26023 - atomic_inc(&vcc->stats->tx);
26024 + atomic_inc_unchecked(&vcc->stats->tx);
26025 iadev->tx_pkt_cnt++;
26026 /* Increment transaction counter */
26027 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
26028
26029 #if 0
26030 /* add flow control logic */
26031 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
26032 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
26033 if (iavcc->vc_desc_cnt > 10) {
26034 vcc->tx_quota = vcc->tx_quota * 3 / 4;
26035 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
26036 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
26037 index f556969..0da15eb 100644
26038 --- a/drivers/atm/lanai.c
26039 +++ b/drivers/atm/lanai.c
26040 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
26041 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
26042 lanai_endtx(lanai, lvcc);
26043 lanai_free_skb(lvcc->tx.atmvcc, skb);
26044 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
26045 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
26046 }
26047
26048 /* Try to fill the buffer - don't call unless there is backlog */
26049 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
26050 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
26051 __net_timestamp(skb);
26052 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
26053 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
26054 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
26055 out:
26056 lvcc->rx.buf.ptr = end;
26057 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
26058 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
26059 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
26060 "vcc %d\n", lanai->number, (unsigned int) s, vci);
26061 lanai->stats.service_rxnotaal5++;
26062 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26063 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26064 return 0;
26065 }
26066 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
26067 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
26068 int bytes;
26069 read_unlock(&vcc_sklist_lock);
26070 DPRINTK("got trashed rx pdu on vci %d\n", vci);
26071 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26072 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26073 lvcc->stats.x.aal5.service_trash++;
26074 bytes = (SERVICE_GET_END(s) * 16) -
26075 (((unsigned long) lvcc->rx.buf.ptr) -
26076 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
26077 }
26078 if (s & SERVICE_STREAM) {
26079 read_unlock(&vcc_sklist_lock);
26080 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26081 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26082 lvcc->stats.x.aal5.service_stream++;
26083 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
26084 "PDU on VCI %d!\n", lanai->number, vci);
26085 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
26086 return 0;
26087 }
26088 DPRINTK("got rx crc error on vci %d\n", vci);
26089 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
26090 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
26091 lvcc->stats.x.aal5.service_rxcrc++;
26092 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
26093 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
26094 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
26095 index 1c70c45..300718d 100644
26096 --- a/drivers/atm/nicstar.c
26097 +++ b/drivers/atm/nicstar.c
26098 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26099 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
26100 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
26101 card->index);
26102 - atomic_inc(&vcc->stats->tx_err);
26103 + atomic_inc_unchecked(&vcc->stats->tx_err);
26104 dev_kfree_skb_any(skb);
26105 return -EINVAL;
26106 }
26107 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26108 if (!vc->tx) {
26109 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
26110 card->index);
26111 - atomic_inc(&vcc->stats->tx_err);
26112 + atomic_inc_unchecked(&vcc->stats->tx_err);
26113 dev_kfree_skb_any(skb);
26114 return -EINVAL;
26115 }
26116 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26117 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
26118 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
26119 card->index);
26120 - atomic_inc(&vcc->stats->tx_err);
26121 + atomic_inc_unchecked(&vcc->stats->tx_err);
26122 dev_kfree_skb_any(skb);
26123 return -EINVAL;
26124 }
26125
26126 if (skb_shinfo(skb)->nr_frags != 0) {
26127 printk("nicstar%d: No scatter-gather yet.\n", card->index);
26128 - atomic_inc(&vcc->stats->tx_err);
26129 + atomic_inc_unchecked(&vcc->stats->tx_err);
26130 dev_kfree_skb_any(skb);
26131 return -EINVAL;
26132 }
26133 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
26134 }
26135
26136 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
26137 - atomic_inc(&vcc->stats->tx_err);
26138 + atomic_inc_unchecked(&vcc->stats->tx_err);
26139 dev_kfree_skb_any(skb);
26140 return -EIO;
26141 }
26142 - atomic_inc(&vcc->stats->tx);
26143 + atomic_inc_unchecked(&vcc->stats->tx);
26144
26145 return 0;
26146 }
26147 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26148 printk
26149 ("nicstar%d: Can't allocate buffers for aal0.\n",
26150 card->index);
26151 - atomic_add(i, &vcc->stats->rx_drop);
26152 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
26153 break;
26154 }
26155 if (!atm_charge(vcc, sb->truesize)) {
26156 RXPRINTK
26157 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
26158 card->index);
26159 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
26160 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
26161 dev_kfree_skb_any(sb);
26162 break;
26163 }
26164 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26165 ATM_SKB(sb)->vcc = vcc;
26166 __net_timestamp(sb);
26167 vcc->push(vcc, sb);
26168 - atomic_inc(&vcc->stats->rx);
26169 + atomic_inc_unchecked(&vcc->stats->rx);
26170 cell += ATM_CELL_PAYLOAD;
26171 }
26172
26173 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26174 if (iovb == NULL) {
26175 printk("nicstar%d: Out of iovec buffers.\n",
26176 card->index);
26177 - atomic_inc(&vcc->stats->rx_drop);
26178 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26179 recycle_rx_buf(card, skb);
26180 return;
26181 }
26182 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26183 small or large buffer itself. */
26184 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
26185 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
26186 - atomic_inc(&vcc->stats->rx_err);
26187 + atomic_inc_unchecked(&vcc->stats->rx_err);
26188 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26189 NS_MAX_IOVECS);
26190 NS_PRV_IOVCNT(iovb) = 0;
26191 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26192 ("nicstar%d: Expected a small buffer, and this is not one.\n",
26193 card->index);
26194 which_list(card, skb);
26195 - atomic_inc(&vcc->stats->rx_err);
26196 + atomic_inc_unchecked(&vcc->stats->rx_err);
26197 recycle_rx_buf(card, skb);
26198 vc->rx_iov = NULL;
26199 recycle_iov_buf(card, iovb);
26200 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26201 ("nicstar%d: Expected a large buffer, and this is not one.\n",
26202 card->index);
26203 which_list(card, skb);
26204 - atomic_inc(&vcc->stats->rx_err);
26205 + atomic_inc_unchecked(&vcc->stats->rx_err);
26206 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26207 NS_PRV_IOVCNT(iovb));
26208 vc->rx_iov = NULL;
26209 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26210 printk(" - PDU size mismatch.\n");
26211 else
26212 printk(".\n");
26213 - atomic_inc(&vcc->stats->rx_err);
26214 + atomic_inc_unchecked(&vcc->stats->rx_err);
26215 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
26216 NS_PRV_IOVCNT(iovb));
26217 vc->rx_iov = NULL;
26218 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26219 /* skb points to a small buffer */
26220 if (!atm_charge(vcc, skb->truesize)) {
26221 push_rxbufs(card, skb);
26222 - atomic_inc(&vcc->stats->rx_drop);
26223 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26224 } else {
26225 skb_put(skb, len);
26226 dequeue_sm_buf(card, skb);
26227 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26228 ATM_SKB(skb)->vcc = vcc;
26229 __net_timestamp(skb);
26230 vcc->push(vcc, skb);
26231 - atomic_inc(&vcc->stats->rx);
26232 + atomic_inc_unchecked(&vcc->stats->rx);
26233 }
26234 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
26235 struct sk_buff *sb;
26236 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26237 if (len <= NS_SMBUFSIZE) {
26238 if (!atm_charge(vcc, sb->truesize)) {
26239 push_rxbufs(card, sb);
26240 - atomic_inc(&vcc->stats->rx_drop);
26241 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26242 } else {
26243 skb_put(sb, len);
26244 dequeue_sm_buf(card, sb);
26245 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26246 ATM_SKB(sb)->vcc = vcc;
26247 __net_timestamp(sb);
26248 vcc->push(vcc, sb);
26249 - atomic_inc(&vcc->stats->rx);
26250 + atomic_inc_unchecked(&vcc->stats->rx);
26251 }
26252
26253 push_rxbufs(card, skb);
26254 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26255
26256 if (!atm_charge(vcc, skb->truesize)) {
26257 push_rxbufs(card, skb);
26258 - atomic_inc(&vcc->stats->rx_drop);
26259 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26260 } else {
26261 dequeue_lg_buf(card, skb);
26262 #ifdef NS_USE_DESTRUCTORS
26263 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26264 ATM_SKB(skb)->vcc = vcc;
26265 __net_timestamp(skb);
26266 vcc->push(vcc, skb);
26267 - atomic_inc(&vcc->stats->rx);
26268 + atomic_inc_unchecked(&vcc->stats->rx);
26269 }
26270
26271 push_rxbufs(card, sb);
26272 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26273 printk
26274 ("nicstar%d: Out of huge buffers.\n",
26275 card->index);
26276 - atomic_inc(&vcc->stats->rx_drop);
26277 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26278 recycle_iovec_rx_bufs(card,
26279 (struct iovec *)
26280 iovb->data,
26281 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26282 card->hbpool.count++;
26283 } else
26284 dev_kfree_skb_any(hb);
26285 - atomic_inc(&vcc->stats->rx_drop);
26286 + atomic_inc_unchecked(&vcc->stats->rx_drop);
26287 } else {
26288 /* Copy the small buffer to the huge buffer */
26289 sb = (struct sk_buff *)iov->iov_base;
26290 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
26291 #endif /* NS_USE_DESTRUCTORS */
26292 __net_timestamp(hb);
26293 vcc->push(vcc, hb);
26294 - atomic_inc(&vcc->stats->rx);
26295 + atomic_inc_unchecked(&vcc->stats->rx);
26296 }
26297 }
26298
26299 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
26300 index 5d1d076..12fbca4 100644
26301 --- a/drivers/atm/solos-pci.c
26302 +++ b/drivers/atm/solos-pci.c
26303 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
26304 }
26305 atm_charge(vcc, skb->truesize);
26306 vcc->push(vcc, skb);
26307 - atomic_inc(&vcc->stats->rx);
26308 + atomic_inc_unchecked(&vcc->stats->rx);
26309 break;
26310
26311 case PKT_STATUS:
26312 @@ -1008,7 +1008,7 @@ static uint32_t fpga_tx(struct solos_card *card)
26313 vcc = SKB_CB(oldskb)->vcc;
26314
26315 if (vcc) {
26316 - atomic_inc(&vcc->stats->tx);
26317 + atomic_inc_unchecked(&vcc->stats->tx);
26318 solos_pop(vcc, oldskb);
26319 } else
26320 dev_kfree_skb_irq(oldskb);
26321 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
26322 index 90f1ccc..04c4a1e 100644
26323 --- a/drivers/atm/suni.c
26324 +++ b/drivers/atm/suni.c
26325 @@ -50,8 +50,8 @@ static DEFINE_SPINLOCK(sunis_lock);
26326
26327
26328 #define ADD_LIMITED(s,v) \
26329 - atomic_add((v),&stats->s); \
26330 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
26331 + atomic_add_unchecked((v),&stats->s); \
26332 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
26333
26334
26335 static void suni_hz(unsigned long from_timer)
26336 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
26337 index 5120a96..e2572bd 100644
26338 --- a/drivers/atm/uPD98402.c
26339 +++ b/drivers/atm/uPD98402.c
26340 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
26341 struct sonet_stats tmp;
26342 int error = 0;
26343
26344 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26345 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
26346 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
26347 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
26348 if (zero && !error) {
26349 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
26350
26351
26352 #define ADD_LIMITED(s,v) \
26353 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
26354 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
26355 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26356 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
26357 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
26358 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
26359
26360
26361 static void stat_event(struct atm_dev *dev)
26362 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
26363 if (reason & uPD98402_INT_PFM) stat_event(dev);
26364 if (reason & uPD98402_INT_PCO) {
26365 (void) GET(PCOCR); /* clear interrupt cause */
26366 - atomic_add(GET(HECCT),
26367 + atomic_add_unchecked(GET(HECCT),
26368 &PRIV(dev)->sonet_stats.uncorr_hcs);
26369 }
26370 if ((reason & uPD98402_INT_RFO) &&
26371 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
26372 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
26373 uPD98402_INT_LOS),PIMR); /* enable them */
26374 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
26375 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26376 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
26377 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
26378 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
26379 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
26380 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
26381 return 0;
26382 }
26383
26384 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
26385 index d889f56..17eb71e 100644
26386 --- a/drivers/atm/zatm.c
26387 +++ b/drivers/atm/zatm.c
26388 @@ -460,7 +460,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26389 }
26390 if (!size) {
26391 dev_kfree_skb_irq(skb);
26392 - if (vcc) atomic_inc(&vcc->stats->rx_err);
26393 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
26394 continue;
26395 }
26396 if (!atm_charge(vcc,skb->truesize)) {
26397 @@ -470,7 +470,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
26398 skb->len = size;
26399 ATM_SKB(skb)->vcc = vcc;
26400 vcc->push(vcc,skb);
26401 - atomic_inc(&vcc->stats->rx);
26402 + atomic_inc_unchecked(&vcc->stats->rx);
26403 }
26404 zout(pos & 0xffff,MTA(mbx));
26405 #if 0 /* probably a stupid idea */
26406 @@ -734,7 +734,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
26407 skb_queue_head(&zatm_vcc->backlog,skb);
26408 break;
26409 }
26410 - atomic_inc(&vcc->stats->tx);
26411 + atomic_inc_unchecked(&vcc->stats->tx);
26412 wake_up(&zatm_vcc->tx_wait);
26413 }
26414
26415 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
26416 index a4760e0..51283cf 100644
26417 --- a/drivers/base/devtmpfs.c
26418 +++ b/drivers/base/devtmpfs.c
26419 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
26420 if (!thread)
26421 return 0;
26422
26423 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
26424 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
26425 if (err)
26426 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
26427 else
26428 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
26429 index caf995f..6f76697 100644
26430 --- a/drivers/base/power/wakeup.c
26431 +++ b/drivers/base/power/wakeup.c
26432 @@ -30,14 +30,14 @@ bool events_check_enabled;
26433 * They need to be modified together atomically, so it's better to use one
26434 * atomic variable to hold them both.
26435 */
26436 -static atomic_t combined_event_count = ATOMIC_INIT(0);
26437 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
26438
26439 #define IN_PROGRESS_BITS (sizeof(int) * 4)
26440 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
26441
26442 static void split_counters(unsigned int *cnt, unsigned int *inpr)
26443 {
26444 - unsigned int comb = atomic_read(&combined_event_count);
26445 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
26446
26447 *cnt = (comb >> IN_PROGRESS_BITS);
26448 *inpr = comb & MAX_IN_PROGRESS;
26449 @@ -353,7 +353,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
26450 ws->last_time = ktime_get();
26451
26452 /* Increment the counter of events in progress. */
26453 - atomic_inc(&combined_event_count);
26454 + atomic_inc_unchecked(&combined_event_count);
26455 }
26456
26457 /**
26458 @@ -443,7 +443,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
26459 * Increment the counter of registered wakeup events and decrement the
26460 * couter of wakeup events in progress simultaneously.
26461 */
26462 - atomic_add(MAX_IN_PROGRESS, &combined_event_count);
26463 + atomic_add_unchecked(MAX_IN_PROGRESS, &combined_event_count);
26464 }
26465
26466 /**
26467 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
26468 index b0f553b..77b928b 100644
26469 --- a/drivers/block/cciss.c
26470 +++ b/drivers/block/cciss.c
26471 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
26472 int err;
26473 u32 cp;
26474
26475 + memset(&arg64, 0, sizeof(arg64));
26476 +
26477 err = 0;
26478 err |=
26479 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
26480 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
26481 while (!list_empty(&h->reqQ)) {
26482 c = list_entry(h->reqQ.next, CommandList_struct, list);
26483 /* can't do anything if fifo is full */
26484 - if ((h->access.fifo_full(h))) {
26485 + if ((h->access->fifo_full(h))) {
26486 dev_warn(&h->pdev->dev, "fifo full\n");
26487 break;
26488 }
26489 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
26490 h->Qdepth--;
26491
26492 /* Tell the controller execute command */
26493 - h->access.submit_command(h, c);
26494 + h->access->submit_command(h, c);
26495
26496 /* Put job onto the completed Q */
26497 addQ(&h->cmpQ, c);
26498 @@ -3443,17 +3445,17 @@ startio:
26499
26500 static inline unsigned long get_next_completion(ctlr_info_t *h)
26501 {
26502 - return h->access.command_completed(h);
26503 + return h->access->command_completed(h);
26504 }
26505
26506 static inline int interrupt_pending(ctlr_info_t *h)
26507 {
26508 - return h->access.intr_pending(h);
26509 + return h->access->intr_pending(h);
26510 }
26511
26512 static inline long interrupt_not_for_us(ctlr_info_t *h)
26513 {
26514 - return ((h->access.intr_pending(h) == 0) ||
26515 + return ((h->access->intr_pending(h) == 0) ||
26516 (h->interrupts_enabled == 0));
26517 }
26518
26519 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
26520 u32 a;
26521
26522 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
26523 - return h->access.command_completed(h);
26524 + return h->access->command_completed(h);
26525
26526 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
26527 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
26528 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
26529 trans_support & CFGTBL_Trans_use_short_tags);
26530
26531 /* Change the access methods to the performant access methods */
26532 - h->access = SA5_performant_access;
26533 + h->access = &SA5_performant_access;
26534 h->transMethod = CFGTBL_Trans_Performant;
26535
26536 return;
26537 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
26538 if (prod_index < 0)
26539 return -ENODEV;
26540 h->product_name = products[prod_index].product_name;
26541 - h->access = *(products[prod_index].access);
26542 + h->access = products[prod_index].access;
26543
26544 if (cciss_board_disabled(h)) {
26545 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
26546 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
26547 }
26548
26549 /* make sure the board interrupts are off */
26550 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26551 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26552 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
26553 if (rc)
26554 goto clean2;
26555 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
26556 * fake ones to scoop up any residual completions.
26557 */
26558 spin_lock_irqsave(&h->lock, flags);
26559 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26560 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26561 spin_unlock_irqrestore(&h->lock, flags);
26562 free_irq(h->intr[h->intr_mode], h);
26563 rc = cciss_request_irq(h, cciss_msix_discard_completions,
26564 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
26565 dev_info(&h->pdev->dev, "Board READY.\n");
26566 dev_info(&h->pdev->dev,
26567 "Waiting for stale completions to drain.\n");
26568 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26569 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26570 msleep(10000);
26571 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26572 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26573
26574 rc = controller_reset_failed(h->cfgtable);
26575 if (rc)
26576 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
26577 cciss_scsi_setup(h);
26578
26579 /* Turn the interrupts on so we can service requests */
26580 - h->access.set_intr_mask(h, CCISS_INTR_ON);
26581 + h->access->set_intr_mask(h, CCISS_INTR_ON);
26582
26583 /* Get the firmware version */
26584 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
26585 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
26586 kfree(flush_buf);
26587 if (return_code != IO_OK)
26588 dev_warn(&h->pdev->dev, "Error flushing cache\n");
26589 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
26590 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
26591 free_irq(h->intr[h->intr_mode], h);
26592 }
26593
26594 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
26595 index 7fda30e..eb5dfe0 100644
26596 --- a/drivers/block/cciss.h
26597 +++ b/drivers/block/cciss.h
26598 @@ -101,7 +101,7 @@ struct ctlr_info
26599 /* information about each logical volume */
26600 drive_info_struct *drv[CISS_MAX_LUN];
26601
26602 - struct access_method access;
26603 + struct access_method *access;
26604
26605 /* queue and queue Info */
26606 struct list_head reqQ;
26607 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
26608 index 9125bbe..eede5c8 100644
26609 --- a/drivers/block/cpqarray.c
26610 +++ b/drivers/block/cpqarray.c
26611 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26612 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
26613 goto Enomem4;
26614 }
26615 - hba[i]->access.set_intr_mask(hba[i], 0);
26616 + hba[i]->access->set_intr_mask(hba[i], 0);
26617 if (request_irq(hba[i]->intr, do_ida_intr,
26618 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
26619 {
26620 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
26621 add_timer(&hba[i]->timer);
26622
26623 /* Enable IRQ now that spinlock and rate limit timer are set up */
26624 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26625 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
26626
26627 for(j=0; j<NWD; j++) {
26628 struct gendisk *disk = ida_gendisk[i][j];
26629 @@ -694,7 +694,7 @@ DBGINFO(
26630 for(i=0; i<NR_PRODUCTS; i++) {
26631 if (board_id == products[i].board_id) {
26632 c->product_name = products[i].product_name;
26633 - c->access = *(products[i].access);
26634 + c->access = products[i].access;
26635 break;
26636 }
26637 }
26638 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
26639 hba[ctlr]->intr = intr;
26640 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
26641 hba[ctlr]->product_name = products[j].product_name;
26642 - hba[ctlr]->access = *(products[j].access);
26643 + hba[ctlr]->access = products[j].access;
26644 hba[ctlr]->ctlr = ctlr;
26645 hba[ctlr]->board_id = board_id;
26646 hba[ctlr]->pci_dev = NULL; /* not PCI */
26647 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
26648
26649 while((c = h->reqQ) != NULL) {
26650 /* Can't do anything if we're busy */
26651 - if (h->access.fifo_full(h) == 0)
26652 + if (h->access->fifo_full(h) == 0)
26653 return;
26654
26655 /* Get the first entry from the request Q */
26656 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
26657 h->Qdepth--;
26658
26659 /* Tell the controller to do our bidding */
26660 - h->access.submit_command(h, c);
26661 + h->access->submit_command(h, c);
26662
26663 /* Get onto the completion Q */
26664 addQ(&h->cmpQ, c);
26665 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26666 unsigned long flags;
26667 __u32 a,a1;
26668
26669 - istat = h->access.intr_pending(h);
26670 + istat = h->access->intr_pending(h);
26671 /* Is this interrupt for us? */
26672 if (istat == 0)
26673 return IRQ_NONE;
26674 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
26675 */
26676 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
26677 if (istat & FIFO_NOT_EMPTY) {
26678 - while((a = h->access.command_completed(h))) {
26679 + while((a = h->access->command_completed(h))) {
26680 a1 = a; a &= ~3;
26681 if ((c = h->cmpQ) == NULL)
26682 {
26683 @@ -1449,11 +1449,11 @@ static int sendcmd(
26684 /*
26685 * Disable interrupt
26686 */
26687 - info_p->access.set_intr_mask(info_p, 0);
26688 + info_p->access->set_intr_mask(info_p, 0);
26689 /* Make sure there is room in the command FIFO */
26690 /* Actually it should be completely empty at this time. */
26691 for (i = 200000; i > 0; i--) {
26692 - temp = info_p->access.fifo_full(info_p);
26693 + temp = info_p->access->fifo_full(info_p);
26694 if (temp != 0) {
26695 break;
26696 }
26697 @@ -1466,7 +1466,7 @@ DBG(
26698 /*
26699 * Send the cmd
26700 */
26701 - info_p->access.submit_command(info_p, c);
26702 + info_p->access->submit_command(info_p, c);
26703 complete = pollcomplete(ctlr);
26704
26705 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
26706 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
26707 * we check the new geometry. Then turn interrupts back on when
26708 * we're done.
26709 */
26710 - host->access.set_intr_mask(host, 0);
26711 + host->access->set_intr_mask(host, 0);
26712 getgeometry(ctlr);
26713 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
26714 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
26715
26716 for(i=0; i<NWD; i++) {
26717 struct gendisk *disk = ida_gendisk[ctlr][i];
26718 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
26719 /* Wait (up to 2 seconds) for a command to complete */
26720
26721 for (i = 200000; i > 0; i--) {
26722 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
26723 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
26724 if (done == 0) {
26725 udelay(10); /* a short fixed delay */
26726 } else
26727 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
26728 index be73e9d..7fbf140 100644
26729 --- a/drivers/block/cpqarray.h
26730 +++ b/drivers/block/cpqarray.h
26731 @@ -99,7 +99,7 @@ struct ctlr_info {
26732 drv_info_t drv[NWD];
26733 struct proc_dir_entry *proc;
26734
26735 - struct access_method access;
26736 + struct access_method *access;
26737
26738 cmdlist_t *reqQ;
26739 cmdlist_t *cmpQ;
26740 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
26741 index 9cf2035..bffca95 100644
26742 --- a/drivers/block/drbd/drbd_int.h
26743 +++ b/drivers/block/drbd/drbd_int.h
26744 @@ -736,7 +736,7 @@ struct drbd_request;
26745 struct drbd_epoch {
26746 struct list_head list;
26747 unsigned int barrier_nr;
26748 - atomic_t epoch_size; /* increased on every request added. */
26749 + atomic_unchecked_t epoch_size; /* increased on every request added. */
26750 atomic_t active; /* increased on every req. added, and dec on every finished. */
26751 unsigned long flags;
26752 };
26753 @@ -1108,7 +1108,7 @@ struct drbd_conf {
26754 void *int_dig_in;
26755 void *int_dig_vv;
26756 wait_queue_head_t seq_wait;
26757 - atomic_t packet_seq;
26758 + atomic_unchecked_t packet_seq;
26759 unsigned int peer_seq;
26760 spinlock_t peer_seq_lock;
26761 unsigned int minor;
26762 @@ -1617,30 +1617,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
26763
26764 static inline void drbd_tcp_cork(struct socket *sock)
26765 {
26766 - int __user val = 1;
26767 + int val = 1;
26768 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26769 - (char __user *)&val, sizeof(val));
26770 + (char __force_user *)&val, sizeof(val));
26771 }
26772
26773 static inline void drbd_tcp_uncork(struct socket *sock)
26774 {
26775 - int __user val = 0;
26776 + int val = 0;
26777 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
26778 - (char __user *)&val, sizeof(val));
26779 + (char __force_user *)&val, sizeof(val));
26780 }
26781
26782 static inline void drbd_tcp_nodelay(struct socket *sock)
26783 {
26784 - int __user val = 1;
26785 + int val = 1;
26786 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
26787 - (char __user *)&val, sizeof(val));
26788 + (char __force_user *)&val, sizeof(val));
26789 }
26790
26791 static inline void drbd_tcp_quickack(struct socket *sock)
26792 {
26793 - int __user val = 2;
26794 + int val = 2;
26795 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
26796 - (char __user *)&val, sizeof(val));
26797 + (char __force_user *)&val, sizeof(val));
26798 }
26799
26800 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
26801 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
26802 index 0358e55..bc33689 100644
26803 --- a/drivers/block/drbd/drbd_main.c
26804 +++ b/drivers/block/drbd/drbd_main.c
26805 @@ -2397,7 +2397,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
26806 p.sector = sector;
26807 p.block_id = block_id;
26808 p.blksize = blksize;
26809 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
26810 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
26811
26812 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
26813 return false;
26814 @@ -2696,7 +2696,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
26815 p.sector = cpu_to_be64(req->sector);
26816 p.block_id = (unsigned long)req;
26817 p.seq_num = cpu_to_be32(req->seq_num =
26818 - atomic_add_return(1, &mdev->packet_seq));
26819 + atomic_add_return_unchecked(1, &mdev->packet_seq));
26820
26821 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
26822
26823 @@ -2981,7 +2981,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
26824 atomic_set(&mdev->unacked_cnt, 0);
26825 atomic_set(&mdev->local_cnt, 0);
26826 atomic_set(&mdev->net_cnt, 0);
26827 - atomic_set(&mdev->packet_seq, 0);
26828 + atomic_set_unchecked(&mdev->packet_seq, 0);
26829 atomic_set(&mdev->pp_in_use, 0);
26830 atomic_set(&mdev->pp_in_use_by_net, 0);
26831 atomic_set(&mdev->rs_sect_in, 0);
26832 @@ -3063,8 +3063,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
26833 mdev->receiver.t_state);
26834
26835 /* no need to lock it, I'm the only thread alive */
26836 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
26837 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
26838 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
26839 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
26840 mdev->al_writ_cnt =
26841 mdev->bm_writ_cnt =
26842 mdev->read_cnt =
26843 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
26844 index af2a250..219c74b 100644
26845 --- a/drivers/block/drbd/drbd_nl.c
26846 +++ b/drivers/block/drbd/drbd_nl.c
26847 @@ -2359,7 +2359,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
26848 module_put(THIS_MODULE);
26849 }
26850
26851 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26852 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
26853
26854 static unsigned short *
26855 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
26856 @@ -2430,7 +2430,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
26857 cn_reply->id.idx = CN_IDX_DRBD;
26858 cn_reply->id.val = CN_VAL_DRBD;
26859
26860 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26861 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26862 cn_reply->ack = 0; /* not used here. */
26863 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26864 (int)((char *)tl - (char *)reply->tag_list);
26865 @@ -2462,7 +2462,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
26866 cn_reply->id.idx = CN_IDX_DRBD;
26867 cn_reply->id.val = CN_VAL_DRBD;
26868
26869 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26870 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26871 cn_reply->ack = 0; /* not used here. */
26872 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26873 (int)((char *)tl - (char *)reply->tag_list);
26874 @@ -2540,7 +2540,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
26875 cn_reply->id.idx = CN_IDX_DRBD;
26876 cn_reply->id.val = CN_VAL_DRBD;
26877
26878 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
26879 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
26880 cn_reply->ack = 0; // not used here.
26881 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26882 (int)((char*)tl - (char*)reply->tag_list);
26883 @@ -2579,7 +2579,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
26884 cn_reply->id.idx = CN_IDX_DRBD;
26885 cn_reply->id.val = CN_VAL_DRBD;
26886
26887 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
26888 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
26889 cn_reply->ack = 0; /* not used here. */
26890 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
26891 (int)((char *)tl - (char *)reply->tag_list);
26892 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
26893 index 43beaca..4a5b1dd 100644
26894 --- a/drivers/block/drbd/drbd_receiver.c
26895 +++ b/drivers/block/drbd/drbd_receiver.c
26896 @@ -894,7 +894,7 @@ retry:
26897 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
26898 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
26899
26900 - atomic_set(&mdev->packet_seq, 0);
26901 + atomic_set_unchecked(&mdev->packet_seq, 0);
26902 mdev->peer_seq = 0;
26903
26904 drbd_thread_start(&mdev->asender);
26905 @@ -985,7 +985,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26906 do {
26907 next_epoch = NULL;
26908
26909 - epoch_size = atomic_read(&epoch->epoch_size);
26910 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
26911
26912 switch (ev & ~EV_CLEANUP) {
26913 case EV_PUT:
26914 @@ -1020,7 +1020,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
26915 rv = FE_DESTROYED;
26916 } else {
26917 epoch->flags = 0;
26918 - atomic_set(&epoch->epoch_size, 0);
26919 + atomic_set_unchecked(&epoch->epoch_size, 0);
26920 /* atomic_set(&epoch->active, 0); is already zero */
26921 if (rv == FE_STILL_LIVE)
26922 rv = FE_RECYCLED;
26923 @@ -1191,14 +1191,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26924 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
26925 drbd_flush(mdev);
26926
26927 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26928 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26929 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
26930 if (epoch)
26931 break;
26932 }
26933
26934 epoch = mdev->current_epoch;
26935 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
26936 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
26937
26938 D_ASSERT(atomic_read(&epoch->active) == 0);
26939 D_ASSERT(epoch->flags == 0);
26940 @@ -1210,11 +1210,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
26941 }
26942
26943 epoch->flags = 0;
26944 - atomic_set(&epoch->epoch_size, 0);
26945 + atomic_set_unchecked(&epoch->epoch_size, 0);
26946 atomic_set(&epoch->active, 0);
26947
26948 spin_lock(&mdev->epoch_lock);
26949 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
26950 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
26951 list_add(&epoch->list, &mdev->current_epoch->list);
26952 mdev->current_epoch = epoch;
26953 mdev->epochs++;
26954 @@ -1663,7 +1663,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26955 spin_unlock(&mdev->peer_seq_lock);
26956
26957 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
26958 - atomic_inc(&mdev->current_epoch->epoch_size);
26959 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
26960 return drbd_drain_block(mdev, data_size);
26961 }
26962
26963 @@ -1689,7 +1689,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
26964
26965 spin_lock(&mdev->epoch_lock);
26966 e->epoch = mdev->current_epoch;
26967 - atomic_inc(&e->epoch->epoch_size);
26968 + atomic_inc_unchecked(&e->epoch->epoch_size);
26969 atomic_inc(&e->epoch->active);
26970 spin_unlock(&mdev->epoch_lock);
26971
26972 @@ -3885,7 +3885,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
26973 D_ASSERT(list_empty(&mdev->done_ee));
26974
26975 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
26976 - atomic_set(&mdev->current_epoch->epoch_size, 0);
26977 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
26978 D_ASSERT(list_empty(&mdev->current_epoch->list));
26979 }
26980
26981 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
26982 index 1e888c9..05cf1b0 100644
26983 --- a/drivers/block/loop.c
26984 +++ b/drivers/block/loop.c
26985 @@ -227,7 +227,7 @@ static int __do_lo_send_write(struct file *file,
26986 mm_segment_t old_fs = get_fs();
26987
26988 set_fs(get_ds());
26989 - bw = file->f_op->write(file, buf, len, &pos);
26990 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
26991 set_fs(old_fs);
26992 if (likely(bw == len))
26993 return 0;
26994 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
26995 index 4364303..9adf4ee 100644
26996 --- a/drivers/char/Kconfig
26997 +++ b/drivers/char/Kconfig
26998 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
26999
27000 config DEVKMEM
27001 bool "/dev/kmem virtual device support"
27002 - default y
27003 + default n
27004 + depends on !GRKERNSEC_KMEM
27005 help
27006 Say Y here if you want to support the /dev/kmem device. The
27007 /dev/kmem device is rarely used, but can be used for certain
27008 @@ -596,6 +597,7 @@ config DEVPORT
27009 bool
27010 depends on !M68K
27011 depends on ISA || PCI
27012 + depends on !GRKERNSEC_KMEM
27013 default y
27014
27015 source "drivers/s390/char/Kconfig"
27016 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
27017 index 2e04433..22afc64 100644
27018 --- a/drivers/char/agp/frontend.c
27019 +++ b/drivers/char/agp/frontend.c
27020 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
27021 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
27022 return -EFAULT;
27023
27024 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
27025 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
27026 return -EFAULT;
27027
27028 client = agp_find_client_by_pid(reserve.pid);
27029 diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
27030 index 095ab90..afad0a4 100644
27031 --- a/drivers/char/briq_panel.c
27032 +++ b/drivers/char/briq_panel.c
27033 @@ -9,6 +9,7 @@
27034 #include <linux/types.h>
27035 #include <linux/errno.h>
27036 #include <linux/tty.h>
27037 +#include <linux/mutex.h>
27038 #include <linux/timer.h>
27039 #include <linux/kernel.h>
27040 #include <linux/wait.h>
27041 @@ -34,6 +35,7 @@ static int vfd_is_open;
27042 static unsigned char vfd[40];
27043 static int vfd_cursor;
27044 static unsigned char ledpb, led;
27045 +static DEFINE_MUTEX(vfd_mutex);
27046
27047 static void update_vfd(void)
27048 {
27049 @@ -140,12 +142,15 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
27050 if (!vfd_is_open)
27051 return -EBUSY;
27052
27053 + mutex_lock(&vfd_mutex);
27054 for (;;) {
27055 char c;
27056 if (!indx)
27057 break;
27058 - if (get_user(c, buf))
27059 + if (get_user(c, buf)) {
27060 + mutex_unlock(&vfd_mutex);
27061 return -EFAULT;
27062 + }
27063 if (esc) {
27064 set_led(c);
27065 esc = 0;
27066 @@ -175,6 +180,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
27067 buf++;
27068 }
27069 update_vfd();
27070 + mutex_unlock(&vfd_mutex);
27071
27072 return len;
27073 }
27074 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
27075 index f773a9d..65cd683 100644
27076 --- a/drivers/char/genrtc.c
27077 +++ b/drivers/char/genrtc.c
27078 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
27079 switch (cmd) {
27080
27081 case RTC_PLL_GET:
27082 + memset(&pll, 0, sizeof(pll));
27083 if (get_rtc_pll(&pll))
27084 return -EINVAL;
27085 else
27086 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
27087 index 0833896..cccce52 100644
27088 --- a/drivers/char/hpet.c
27089 +++ b/drivers/char/hpet.c
27090 @@ -572,7 +572,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
27091 }
27092
27093 static int
27094 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
27095 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
27096 struct hpet_info *info)
27097 {
27098 struct hpet_timer __iomem *timer;
27099 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
27100 index 58c0e63..46c16bf 100644
27101 --- a/drivers/char/ipmi/ipmi_msghandler.c
27102 +++ b/drivers/char/ipmi/ipmi_msghandler.c
27103 @@ -415,7 +415,7 @@ struct ipmi_smi {
27104 struct proc_dir_entry *proc_dir;
27105 char proc_dir_name[10];
27106
27107 - atomic_t stats[IPMI_NUM_STATS];
27108 + atomic_unchecked_t stats[IPMI_NUM_STATS];
27109
27110 /*
27111 * run_to_completion duplicate of smb_info, smi_info
27112 @@ -448,9 +448,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
27113
27114
27115 #define ipmi_inc_stat(intf, stat) \
27116 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
27117 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
27118 #define ipmi_get_stat(intf, stat) \
27119 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
27120 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
27121
27122 static int is_lan_addr(struct ipmi_addr *addr)
27123 {
27124 @@ -2868,7 +2868,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
27125 INIT_LIST_HEAD(&intf->cmd_rcvrs);
27126 init_waitqueue_head(&intf->waitq);
27127 for (i = 0; i < IPMI_NUM_STATS; i++)
27128 - atomic_set(&intf->stats[i], 0);
27129 + atomic_set_unchecked(&intf->stats[i], 0);
27130
27131 intf->proc_dir = NULL;
27132
27133 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
27134 index 9397ab4..d01bee1 100644
27135 --- a/drivers/char/ipmi/ipmi_si_intf.c
27136 +++ b/drivers/char/ipmi/ipmi_si_intf.c
27137 @@ -277,7 +277,7 @@ struct smi_info {
27138 unsigned char slave_addr;
27139
27140 /* Counters and things for the proc filesystem. */
27141 - atomic_t stats[SI_NUM_STATS];
27142 + atomic_unchecked_t stats[SI_NUM_STATS];
27143
27144 struct task_struct *thread;
27145
27146 @@ -286,9 +286,9 @@ struct smi_info {
27147 };
27148
27149 #define smi_inc_stat(smi, stat) \
27150 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
27151 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
27152 #define smi_get_stat(smi, stat) \
27153 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
27154 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
27155
27156 #define SI_MAX_PARMS 4
27157
27158 @@ -3230,7 +3230,7 @@ static int try_smi_init(struct smi_info *new_smi)
27159 atomic_set(&new_smi->req_events, 0);
27160 new_smi->run_to_completion = 0;
27161 for (i = 0; i < SI_NUM_STATS; i++)
27162 - atomic_set(&new_smi->stats[i], 0);
27163 + atomic_set_unchecked(&new_smi->stats[i], 0);
27164
27165 new_smi->interrupt_disabled = 1;
27166 atomic_set(&new_smi->stop_operation, 0);
27167 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
27168 index 1aeaaba..e018570 100644
27169 --- a/drivers/char/mbcs.c
27170 +++ b/drivers/char/mbcs.c
27171 @@ -800,7 +800,7 @@ static int mbcs_remove(struct cx_dev *dev)
27172 return 0;
27173 }
27174
27175 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
27176 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
27177 {
27178 .part_num = MBCS_PART_NUM,
27179 .mfg_num = MBCS_MFG_NUM,
27180 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
27181 index 1451790..f705c30 100644
27182 --- a/drivers/char/mem.c
27183 +++ b/drivers/char/mem.c
27184 @@ -18,6 +18,7 @@
27185 #include <linux/raw.h>
27186 #include <linux/tty.h>
27187 #include <linux/capability.h>
27188 +#include <linux/security.h>
27189 #include <linux/ptrace.h>
27190 #include <linux/device.h>
27191 #include <linux/highmem.h>
27192 @@ -35,6 +36,10 @@
27193 # include <linux/efi.h>
27194 #endif
27195
27196 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27197 +extern const struct file_operations grsec_fops;
27198 +#endif
27199 +
27200 static inline unsigned long size_inside_page(unsigned long start,
27201 unsigned long size)
27202 {
27203 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27204
27205 while (cursor < to) {
27206 if (!devmem_is_allowed(pfn)) {
27207 +#ifdef CONFIG_GRKERNSEC_KMEM
27208 + gr_handle_mem_readwrite(from, to);
27209 +#else
27210 printk(KERN_INFO
27211 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
27212 current->comm, from, to);
27213 +#endif
27214 return 0;
27215 }
27216 cursor += PAGE_SIZE;
27217 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27218 }
27219 return 1;
27220 }
27221 +#elif defined(CONFIG_GRKERNSEC_KMEM)
27222 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27223 +{
27224 + return 0;
27225 +}
27226 #else
27227 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27228 {
27229 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27230
27231 while (count > 0) {
27232 unsigned long remaining;
27233 + char *temp;
27234
27235 sz = size_inside_page(p, count);
27236
27237 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
27238 if (!ptr)
27239 return -EFAULT;
27240
27241 - remaining = copy_to_user(buf, ptr, sz);
27242 +#ifdef CONFIG_PAX_USERCOPY
27243 + temp = kmalloc(sz, GFP_KERNEL);
27244 + if (!temp) {
27245 + unxlate_dev_mem_ptr(p, ptr);
27246 + return -ENOMEM;
27247 + }
27248 + memcpy(temp, ptr, sz);
27249 +#else
27250 + temp = ptr;
27251 +#endif
27252 +
27253 + remaining = copy_to_user(buf, temp, sz);
27254 +
27255 +#ifdef CONFIG_PAX_USERCOPY
27256 + kfree(temp);
27257 +#endif
27258 +
27259 unxlate_dev_mem_ptr(p, ptr);
27260 if (remaining)
27261 return -EFAULT;
27262 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27263 size_t count, loff_t *ppos)
27264 {
27265 unsigned long p = *ppos;
27266 - ssize_t low_count, read, sz;
27267 + ssize_t low_count, read, sz, err = 0;
27268 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
27269 - int err = 0;
27270
27271 read = 0;
27272 if (p < (unsigned long) high_memory) {
27273 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27274 }
27275 #endif
27276 while (low_count > 0) {
27277 + char *temp;
27278 +
27279 sz = size_inside_page(p, low_count);
27280
27281 /*
27282 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
27283 */
27284 kbuf = xlate_dev_kmem_ptr((char *)p);
27285
27286 - if (copy_to_user(buf, kbuf, sz))
27287 +#ifdef CONFIG_PAX_USERCOPY
27288 + temp = kmalloc(sz, GFP_KERNEL);
27289 + if (!temp)
27290 + return -ENOMEM;
27291 + memcpy(temp, kbuf, sz);
27292 +#else
27293 + temp = kbuf;
27294 +#endif
27295 +
27296 + err = copy_to_user(buf, temp, sz);
27297 +
27298 +#ifdef CONFIG_PAX_USERCOPY
27299 + kfree(temp);
27300 +#endif
27301 +
27302 + if (err)
27303 return -EFAULT;
27304 buf += sz;
27305 p += sz;
27306 @@ -867,6 +914,9 @@ static const struct memdev {
27307 #ifdef CONFIG_CRASH_DUMP
27308 [12] = { "oldmem", 0, &oldmem_fops, NULL },
27309 #endif
27310 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
27311 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
27312 +#endif
27313 };
27314
27315 static int memory_open(struct inode *inode, struct file *filp)
27316 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
27317 index da3cfee..a5a6606 100644
27318 --- a/drivers/char/nvram.c
27319 +++ b/drivers/char/nvram.c
27320 @@ -248,7 +248,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
27321
27322 spin_unlock_irq(&rtc_lock);
27323
27324 - if (copy_to_user(buf, contents, tmp - contents))
27325 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
27326 return -EFAULT;
27327
27328 *ppos = i;
27329 diff --git a/drivers/char/random.c b/drivers/char/random.c
27330 index 6035ab8..bdfe4fd 100644
27331 --- a/drivers/char/random.c
27332 +++ b/drivers/char/random.c
27333 @@ -261,8 +261,13 @@
27334 /*
27335 * Configuration information
27336 */
27337 +#ifdef CONFIG_GRKERNSEC_RANDNET
27338 +#define INPUT_POOL_WORDS 512
27339 +#define OUTPUT_POOL_WORDS 128
27340 +#else
27341 #define INPUT_POOL_WORDS 128
27342 #define OUTPUT_POOL_WORDS 32
27343 +#endif
27344 #define SEC_XFER_SIZE 512
27345 #define EXTRACT_SIZE 10
27346
27347 @@ -300,10 +305,17 @@ static struct poolinfo {
27348 int poolwords;
27349 int tap1, tap2, tap3, tap4, tap5;
27350 } poolinfo_table[] = {
27351 +#ifdef CONFIG_GRKERNSEC_RANDNET
27352 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
27353 + { 512, 411, 308, 208, 104, 1 },
27354 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
27355 + { 128, 103, 76, 51, 25, 1 },
27356 +#else
27357 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
27358 { 128, 103, 76, 51, 25, 1 },
27359 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
27360 { 32, 26, 20, 14, 7, 1 },
27361 +#endif
27362 #if 0
27363 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
27364 { 2048, 1638, 1231, 819, 411, 1 },
27365 @@ -909,7 +921,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
27366
27367 extract_buf(r, tmp);
27368 i = min_t(int, nbytes, EXTRACT_SIZE);
27369 - if (copy_to_user(buf, tmp, i)) {
27370 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
27371 ret = -EFAULT;
27372 break;
27373 }
27374 @@ -1228,7 +1240,7 @@ EXPORT_SYMBOL(generate_random_uuid);
27375 #include <linux/sysctl.h>
27376
27377 static int min_read_thresh = 8, min_write_thresh;
27378 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
27379 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
27380 static int max_write_thresh = INPUT_POOL_WORDS * 32;
27381 static char sysctl_bootid[16];
27382
27383 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
27384 index 1ee8ce7..b778bef 100644
27385 --- a/drivers/char/sonypi.c
27386 +++ b/drivers/char/sonypi.c
27387 @@ -55,6 +55,7 @@
27388 #include <asm/uaccess.h>
27389 #include <asm/io.h>
27390 #include <asm/system.h>
27391 +#include <asm/local.h>
27392
27393 #include <linux/sonypi.h>
27394
27395 @@ -491,7 +492,7 @@ static struct sonypi_device {
27396 spinlock_t fifo_lock;
27397 wait_queue_head_t fifo_proc_list;
27398 struct fasync_struct *fifo_async;
27399 - int open_count;
27400 + local_t open_count;
27401 int model;
27402 struct input_dev *input_jog_dev;
27403 struct input_dev *input_key_dev;
27404 @@ -898,7 +899,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
27405 static int sonypi_misc_release(struct inode *inode, struct file *file)
27406 {
27407 mutex_lock(&sonypi_device.lock);
27408 - sonypi_device.open_count--;
27409 + local_dec(&sonypi_device.open_count);
27410 mutex_unlock(&sonypi_device.lock);
27411 return 0;
27412 }
27413 @@ -907,9 +908,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
27414 {
27415 mutex_lock(&sonypi_device.lock);
27416 /* Flush input queue on first open */
27417 - if (!sonypi_device.open_count)
27418 + if (!local_read(&sonypi_device.open_count))
27419 kfifo_reset(&sonypi_device.fifo);
27420 - sonypi_device.open_count++;
27421 + local_inc(&sonypi_device.open_count);
27422 mutex_unlock(&sonypi_device.lock);
27423
27424 return 0;
27425 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
27426 index 361a1df..2471eee 100644
27427 --- a/drivers/char/tpm/tpm.c
27428 +++ b/drivers/char/tpm/tpm.c
27429 @@ -414,7 +414,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
27430 chip->vendor.req_complete_val)
27431 goto out_recv;
27432
27433 - if ((status == chip->vendor.req_canceled)) {
27434 + if (status == chip->vendor.req_canceled) {
27435 dev_err(chip->dev, "Operation Canceled\n");
27436 rc = -ECANCELED;
27437 goto out;
27438 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
27439 index 0636520..169c1d0 100644
27440 --- a/drivers/char/tpm/tpm_bios.c
27441 +++ b/drivers/char/tpm/tpm_bios.c
27442 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
27443 event = addr;
27444
27445 if ((event->event_type == 0 && event->event_size == 0) ||
27446 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
27447 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
27448 return NULL;
27449
27450 return addr;
27451 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
27452 return NULL;
27453
27454 if ((event->event_type == 0 && event->event_size == 0) ||
27455 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
27456 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
27457 return NULL;
27458
27459 (*pos)++;
27460 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
27461 int i;
27462
27463 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
27464 - seq_putc(m, data[i]);
27465 + if (!seq_putc(m, data[i]))
27466 + return -EFAULT;
27467
27468 return 0;
27469 }
27470 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
27471 log->bios_event_log_end = log->bios_event_log + len;
27472
27473 virt = acpi_os_map_memory(start, len);
27474 + if (!virt) {
27475 + kfree(log->bios_event_log);
27476 + log->bios_event_log = NULL;
27477 + return -EFAULT;
27478 + }
27479
27480 - memcpy(log->bios_event_log, virt, len);
27481 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
27482
27483 acpi_os_unmap_memory(virt, len);
27484 return 0;
27485 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
27486 index 8e3c46d..c139b99 100644
27487 --- a/drivers/char/virtio_console.c
27488 +++ b/drivers/char/virtio_console.c
27489 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
27490 if (to_user) {
27491 ssize_t ret;
27492
27493 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
27494 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
27495 if (ret)
27496 return -EFAULT;
27497 } else {
27498 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
27499 if (!port_has_data(port) && !port->host_connected)
27500 return 0;
27501
27502 - return fill_readbuf(port, ubuf, count, true);
27503 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
27504 }
27505
27506 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
27507 diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
27508 index eb1d864..39ee5a7 100644
27509 --- a/drivers/dma/dmatest.c
27510 +++ b/drivers/dma/dmatest.c
27511 @@ -591,7 +591,7 @@ static int dmatest_add_channel(struct dma_chan *chan)
27512 }
27513 if (dma_has_cap(DMA_PQ, dma_dev->cap_mask)) {
27514 cnt = dmatest_add_threads(dtc, DMA_PQ);
27515 - thread_count += cnt > 0 ?: 0;
27516 + thread_count += cnt > 0 ? cnt : 0;
27517 }
27518
27519 pr_info("dmatest: Started %u threads using %s\n",
27520 diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
27521 index c9eee6d..f9d5280 100644
27522 --- a/drivers/edac/amd64_edac.c
27523 +++ b/drivers/edac/amd64_edac.c
27524 @@ -2685,7 +2685,7 @@ static void __devexit amd64_remove_one_instance(struct pci_dev *pdev)
27525 * PCI core identifies what devices are on a system during boot, and then
27526 * inquiry this table to see if this driver is for a given device found.
27527 */
27528 -static const struct pci_device_id amd64_pci_table[] __devinitdata = {
27529 +static const struct pci_device_id amd64_pci_table[] __devinitconst = {
27530 {
27531 .vendor = PCI_VENDOR_ID_AMD,
27532 .device = PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
27533 diff --git a/drivers/edac/amd76x_edac.c b/drivers/edac/amd76x_edac.c
27534 index e47e73b..348e0bd 100644
27535 --- a/drivers/edac/amd76x_edac.c
27536 +++ b/drivers/edac/amd76x_edac.c
27537 @@ -321,7 +321,7 @@ static void __devexit amd76x_remove_one(struct pci_dev *pdev)
27538 edac_mc_free(mci);
27539 }
27540
27541 -static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
27542 +static const struct pci_device_id amd76x_pci_tbl[] __devinitconst = {
27543 {
27544 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27545 AMD762},
27546 diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
27547 index 1af531a..3a8ff27 100644
27548 --- a/drivers/edac/e752x_edac.c
27549 +++ b/drivers/edac/e752x_edac.c
27550 @@ -1380,7 +1380,7 @@ static void __devexit e752x_remove_one(struct pci_dev *pdev)
27551 edac_mc_free(mci);
27552 }
27553
27554 -static const struct pci_device_id e752x_pci_tbl[] __devinitdata = {
27555 +static const struct pci_device_id e752x_pci_tbl[] __devinitconst = {
27556 {
27557 PCI_VEND_DEV(INTEL, 7520_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27558 E7520},
27559 diff --git a/drivers/edac/e7xxx_edac.c b/drivers/edac/e7xxx_edac.c
27560 index 6ffb6d2..383d8d7 100644
27561 --- a/drivers/edac/e7xxx_edac.c
27562 +++ b/drivers/edac/e7xxx_edac.c
27563 @@ -525,7 +525,7 @@ static void __devexit e7xxx_remove_one(struct pci_dev *pdev)
27564 edac_mc_free(mci);
27565 }
27566
27567 -static const struct pci_device_id e7xxx_pci_tbl[] __devinitdata = {
27568 +static const struct pci_device_id e7xxx_pci_tbl[] __devinitconst = {
27569 {
27570 PCI_VEND_DEV(INTEL, 7205_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27571 E7205},
27572 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
27573 index 495198a..ac08c85 100644
27574 --- a/drivers/edac/edac_pci_sysfs.c
27575 +++ b/drivers/edac/edac_pci_sysfs.c
27576 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
27577 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
27578 static int edac_pci_poll_msec = 1000; /* one second workq period */
27579
27580 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
27581 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
27582 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
27583 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
27584
27585 static struct kobject *edac_pci_top_main_kobj;
27586 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
27587 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27588 edac_printk(KERN_CRIT, EDAC_PCI,
27589 "Signaled System Error on %s\n",
27590 pci_name(dev));
27591 - atomic_inc(&pci_nonparity_count);
27592 + atomic_inc_unchecked(&pci_nonparity_count);
27593 }
27594
27595 if (status & (PCI_STATUS_PARITY)) {
27596 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27597 "Master Data Parity Error on %s\n",
27598 pci_name(dev));
27599
27600 - atomic_inc(&pci_parity_count);
27601 + atomic_inc_unchecked(&pci_parity_count);
27602 }
27603
27604 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27605 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27606 "Detected Parity Error on %s\n",
27607 pci_name(dev));
27608
27609 - atomic_inc(&pci_parity_count);
27610 + atomic_inc_unchecked(&pci_parity_count);
27611 }
27612 }
27613
27614 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27615 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
27616 "Signaled System Error on %s\n",
27617 pci_name(dev));
27618 - atomic_inc(&pci_nonparity_count);
27619 + atomic_inc_unchecked(&pci_nonparity_count);
27620 }
27621
27622 if (status & (PCI_STATUS_PARITY)) {
27623 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27624 "Master Data Parity Error on "
27625 "%s\n", pci_name(dev));
27626
27627 - atomic_inc(&pci_parity_count);
27628 + atomic_inc_unchecked(&pci_parity_count);
27629 }
27630
27631 if (status & (PCI_STATUS_DETECTED_PARITY)) {
27632 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
27633 "Detected Parity Error on %s\n",
27634 pci_name(dev));
27635
27636 - atomic_inc(&pci_parity_count);
27637 + atomic_inc_unchecked(&pci_parity_count);
27638 }
27639 }
27640 }
27641 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
27642 if (!check_pci_errors)
27643 return;
27644
27645 - before_count = atomic_read(&pci_parity_count);
27646 + before_count = atomic_read_unchecked(&pci_parity_count);
27647
27648 /* scan all PCI devices looking for a Parity Error on devices and
27649 * bridges.
27650 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
27651 /* Only if operator has selected panic on PCI Error */
27652 if (edac_pci_get_panic_on_pe()) {
27653 /* If the count is different 'after' from 'before' */
27654 - if (before_count != atomic_read(&pci_parity_count))
27655 + if (before_count != atomic_read_unchecked(&pci_parity_count))
27656 panic("EDAC: PCI Parity Error");
27657 }
27658 }
27659 diff --git a/drivers/edac/i3000_edac.c b/drivers/edac/i3000_edac.c
27660 index c0510b3..6e2a954 100644
27661 --- a/drivers/edac/i3000_edac.c
27662 +++ b/drivers/edac/i3000_edac.c
27663 @@ -470,7 +470,7 @@ static void __devexit i3000_remove_one(struct pci_dev *pdev)
27664 edac_mc_free(mci);
27665 }
27666
27667 -static const struct pci_device_id i3000_pci_tbl[] __devinitdata = {
27668 +static const struct pci_device_id i3000_pci_tbl[] __devinitconst = {
27669 {
27670 PCI_VEND_DEV(INTEL, 3000_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27671 I3000},
27672 diff --git a/drivers/edac/i3200_edac.c b/drivers/edac/i3200_edac.c
27673 index aa08497..7e6822a 100644
27674 --- a/drivers/edac/i3200_edac.c
27675 +++ b/drivers/edac/i3200_edac.c
27676 @@ -456,7 +456,7 @@ static void __devexit i3200_remove_one(struct pci_dev *pdev)
27677 edac_mc_free(mci);
27678 }
27679
27680 -static const struct pci_device_id i3200_pci_tbl[] __devinitdata = {
27681 +static const struct pci_device_id i3200_pci_tbl[] __devinitconst = {
27682 {
27683 PCI_VEND_DEV(INTEL, 3200_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27684 I3200},
27685 diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
27686 index 4dc3ac2..67d05a6 100644
27687 --- a/drivers/edac/i5000_edac.c
27688 +++ b/drivers/edac/i5000_edac.c
27689 @@ -1516,7 +1516,7 @@ static void __devexit i5000_remove_one(struct pci_dev *pdev)
27690 *
27691 * The "E500P" device is the first device supported.
27692 */
27693 -static const struct pci_device_id i5000_pci_tbl[] __devinitdata = {
27694 +static const struct pci_device_id i5000_pci_tbl[] __devinitconst = {
27695 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I5000_DEV16),
27696 .driver_data = I5000P},
27697
27698 diff --git a/drivers/edac/i5100_edac.c b/drivers/edac/i5100_edac.c
27699 index bcbdeec..9886d16 100644
27700 --- a/drivers/edac/i5100_edac.c
27701 +++ b/drivers/edac/i5100_edac.c
27702 @@ -1051,7 +1051,7 @@ static void __devexit i5100_remove_one(struct pci_dev *pdev)
27703 edac_mc_free(mci);
27704 }
27705
27706 -static const struct pci_device_id i5100_pci_tbl[] __devinitdata = {
27707 +static const struct pci_device_id i5100_pci_tbl[] __devinitconst = {
27708 /* Device 16, Function 0, Channel 0 Memory Map, Error Flag/Mask, ... */
27709 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5100_16) },
27710 { 0, }
27711 diff --git a/drivers/edac/i5400_edac.c b/drivers/edac/i5400_edac.c
27712 index 74d6ec34..baff517 100644
27713 --- a/drivers/edac/i5400_edac.c
27714 +++ b/drivers/edac/i5400_edac.c
27715 @@ -1383,7 +1383,7 @@ static void __devexit i5400_remove_one(struct pci_dev *pdev)
27716 *
27717 * The "E500P" device is the first device supported.
27718 */
27719 -static const struct pci_device_id i5400_pci_tbl[] __devinitdata = {
27720 +static const struct pci_device_id i5400_pci_tbl[] __devinitconst = {
27721 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_5400_ERR)},
27722 {0,} /* 0 terminated list. */
27723 };
27724 diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
27725 index 6104dba..e7ea8e1 100644
27726 --- a/drivers/edac/i7300_edac.c
27727 +++ b/drivers/edac/i7300_edac.c
27728 @@ -1192,7 +1192,7 @@ static void __devexit i7300_remove_one(struct pci_dev *pdev)
27729 *
27730 * Has only 8086:360c PCI ID
27731 */
27732 -static const struct pci_device_id i7300_pci_tbl[] __devinitdata = {
27733 +static const struct pci_device_id i7300_pci_tbl[] __devinitconst = {
27734 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I7300_MCH_ERR)},
27735 {0,} /* 0 terminated list. */
27736 };
27737 diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
27738 index 70ad892..178943c 100644
27739 --- a/drivers/edac/i7core_edac.c
27740 +++ b/drivers/edac/i7core_edac.c
27741 @@ -391,7 +391,7 @@ static const struct pci_id_table pci_dev_table[] = {
27742 /*
27743 * pci_device_id table for which devices we are looking for
27744 */
27745 -static const struct pci_device_id i7core_pci_tbl[] __devinitdata = {
27746 +static const struct pci_device_id i7core_pci_tbl[] __devinitconst = {
27747 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_X58_HUB_MGMT)},
27748 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LYNNFIELD_QPI_LINK0)},
27749 {0,} /* 0 terminated list. */
27750 diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
27751 index 4329d39..f3022ef 100644
27752 --- a/drivers/edac/i82443bxgx_edac.c
27753 +++ b/drivers/edac/i82443bxgx_edac.c
27754 @@ -380,7 +380,7 @@ static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
27755
27756 EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_remove_one);
27757
27758 -static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitdata = {
27759 +static const struct pci_device_id i82443bxgx_pci_tbl[] __devinitconst = {
27760 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0)},
27761 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2)},
27762 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0)},
27763 diff --git a/drivers/edac/i82860_edac.c b/drivers/edac/i82860_edac.c
27764 index 931a057..fd28340 100644
27765 --- a/drivers/edac/i82860_edac.c
27766 +++ b/drivers/edac/i82860_edac.c
27767 @@ -270,7 +270,7 @@ static void __devexit i82860_remove_one(struct pci_dev *pdev)
27768 edac_mc_free(mci);
27769 }
27770
27771 -static const struct pci_device_id i82860_pci_tbl[] __devinitdata = {
27772 +static const struct pci_device_id i82860_pci_tbl[] __devinitconst = {
27773 {
27774 PCI_VEND_DEV(INTEL, 82860_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27775 I82860},
27776 diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
27777 index 33864c6..01edc61 100644
27778 --- a/drivers/edac/i82875p_edac.c
27779 +++ b/drivers/edac/i82875p_edac.c
27780 @@ -511,7 +511,7 @@ static void __devexit i82875p_remove_one(struct pci_dev *pdev)
27781 edac_mc_free(mci);
27782 }
27783
27784 -static const struct pci_device_id i82875p_pci_tbl[] __devinitdata = {
27785 +static const struct pci_device_id i82875p_pci_tbl[] __devinitconst = {
27786 {
27787 PCI_VEND_DEV(INTEL, 82875_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27788 I82875P},
27789 diff --git a/drivers/edac/i82975x_edac.c b/drivers/edac/i82975x_edac.c
27790 index a5da732..983363b 100644
27791 --- a/drivers/edac/i82975x_edac.c
27792 +++ b/drivers/edac/i82975x_edac.c
27793 @@ -604,7 +604,7 @@ static void __devexit i82975x_remove_one(struct pci_dev *pdev)
27794 edac_mc_free(mci);
27795 }
27796
27797 -static const struct pci_device_id i82975x_pci_tbl[] __devinitdata = {
27798 +static const struct pci_device_id i82975x_pci_tbl[] __devinitconst = {
27799 {
27800 PCI_VEND_DEV(INTEL, 82975_0), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27801 I82975X
27802 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
27803 index 0106747..0b40417 100644
27804 --- a/drivers/edac/mce_amd.h
27805 +++ b/drivers/edac/mce_amd.h
27806 @@ -83,7 +83,7 @@ struct amd_decoder_ops {
27807 bool (*dc_mce)(u16, u8);
27808 bool (*ic_mce)(u16, u8);
27809 bool (*nb_mce)(u16, u8);
27810 -};
27811 +} __no_const;
27812
27813 void amd_report_gart_errors(bool);
27814 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
27815 diff --git a/drivers/edac/r82600_edac.c b/drivers/edac/r82600_edac.c
27816 index b153674..ad2ba9b 100644
27817 --- a/drivers/edac/r82600_edac.c
27818 +++ b/drivers/edac/r82600_edac.c
27819 @@ -373,7 +373,7 @@ static void __devexit r82600_remove_one(struct pci_dev *pdev)
27820 edac_mc_free(mci);
27821 }
27822
27823 -static const struct pci_device_id r82600_pci_tbl[] __devinitdata = {
27824 +static const struct pci_device_id r82600_pci_tbl[] __devinitconst = {
27825 {
27826 PCI_DEVICE(PCI_VENDOR_ID_RADISYS, R82600_BRIDGE_ID)
27827 },
27828 diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
27829 index 7a402bf..af0b211 100644
27830 --- a/drivers/edac/sb_edac.c
27831 +++ b/drivers/edac/sb_edac.c
27832 @@ -367,7 +367,7 @@ static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
27833 /*
27834 * pci_device_id table for which devices we are looking for
27835 */
27836 -static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
27837 +static const struct pci_device_id sbridge_pci_tbl[] __devinitconst = {
27838 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
27839 {0,} /* 0 terminated list. */
27840 };
27841 diff --git a/drivers/edac/x38_edac.c b/drivers/edac/x38_edac.c
27842 index b6f47de..c5acf3a 100644
27843 --- a/drivers/edac/x38_edac.c
27844 +++ b/drivers/edac/x38_edac.c
27845 @@ -440,7 +440,7 @@ static void __devexit x38_remove_one(struct pci_dev *pdev)
27846 edac_mc_free(mci);
27847 }
27848
27849 -static const struct pci_device_id x38_pci_tbl[] __devinitdata = {
27850 +static const struct pci_device_id x38_pci_tbl[] __devinitconst = {
27851 {
27852 PCI_VEND_DEV(INTEL, X38_HB), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
27853 X38},
27854 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
27855 index 85661b0..c784559a 100644
27856 --- a/drivers/firewire/core-card.c
27857 +++ b/drivers/firewire/core-card.c
27858 @@ -657,7 +657,7 @@ void fw_card_release(struct kref *kref)
27859
27860 void fw_core_remove_card(struct fw_card *card)
27861 {
27862 - struct fw_card_driver dummy_driver = dummy_driver_template;
27863 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
27864
27865 card->driver->update_phy_reg(card, 4,
27866 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
27867 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
27868 index 4799393..37bd3ab 100644
27869 --- a/drivers/firewire/core-cdev.c
27870 +++ b/drivers/firewire/core-cdev.c
27871 @@ -1331,8 +1331,7 @@ static int init_iso_resource(struct client *client,
27872 int ret;
27873
27874 if ((request->channels == 0 && request->bandwidth == 0) ||
27875 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
27876 - request->bandwidth < 0)
27877 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
27878 return -EINVAL;
27879
27880 r = kmalloc(sizeof(*r), GFP_KERNEL);
27881 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
27882 index 855ab3f..11f4bbd 100644
27883 --- a/drivers/firewire/core-transaction.c
27884 +++ b/drivers/firewire/core-transaction.c
27885 @@ -37,6 +37,7 @@
27886 #include <linux/timer.h>
27887 #include <linux/types.h>
27888 #include <linux/workqueue.h>
27889 +#include <linux/sched.h>
27890
27891 #include <asm/byteorder.h>
27892
27893 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
27894 index b45be57..5fad18b 100644
27895 --- a/drivers/firewire/core.h
27896 +++ b/drivers/firewire/core.h
27897 @@ -101,6 +101,7 @@ struct fw_card_driver {
27898
27899 int (*stop_iso)(struct fw_iso_context *ctx);
27900 };
27901 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
27902
27903 void fw_card_initialize(struct fw_card *card,
27904 const struct fw_card_driver *driver, struct device *device);
27905 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
27906 index 153980b..4b4d046 100644
27907 --- a/drivers/firmware/dmi_scan.c
27908 +++ b/drivers/firmware/dmi_scan.c
27909 @@ -449,11 +449,6 @@ void __init dmi_scan_machine(void)
27910 }
27911 }
27912 else {
27913 - /*
27914 - * no iounmap() for that ioremap(); it would be a no-op, but
27915 - * it's so early in setup that sucker gets confused into doing
27916 - * what it shouldn't if we actually call it.
27917 - */
27918 p = dmi_ioremap(0xF0000, 0x10000);
27919 if (p == NULL)
27920 goto error;
27921 @@ -723,7 +718,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
27922 if (buf == NULL)
27923 return -1;
27924
27925 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
27926 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
27927
27928 iounmap(buf);
27929 return 0;
27930 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
27931 index 98723cb..10ca85b 100644
27932 --- a/drivers/gpio/gpio-vr41xx.c
27933 +++ b/drivers/gpio/gpio-vr41xx.c
27934 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
27935 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
27936 maskl, pendl, maskh, pendh);
27937
27938 - atomic_inc(&irq_err_count);
27939 + atomic_inc_unchecked(&irq_err_count);
27940
27941 return -EINVAL;
27942 }
27943 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
27944 index 8323fc3..5c1d755 100644
27945 --- a/drivers/gpu/drm/drm_crtc.c
27946 +++ b/drivers/gpu/drm/drm_crtc.c
27947 @@ -1379,7 +1379,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27948 */
27949 if ((out_resp->count_modes >= mode_count) && mode_count) {
27950 copied = 0;
27951 - mode_ptr = (struct drm_mode_modeinfo *)(unsigned long)out_resp->modes_ptr;
27952 + mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
27953 list_for_each_entry(mode, &connector->modes, head) {
27954 drm_crtc_convert_to_umode(&u_mode, mode);
27955 if (copy_to_user(mode_ptr + copied,
27956 @@ -1394,8 +1394,8 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27957
27958 if ((out_resp->count_props >= props_count) && props_count) {
27959 copied = 0;
27960 - prop_ptr = (uint32_t *)(unsigned long)(out_resp->props_ptr);
27961 - prop_values = (uint64_t *)(unsigned long)(out_resp->prop_values_ptr);
27962 + prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
27963 + prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
27964 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
27965 if (connector->property_ids[i] != 0) {
27966 if (put_user(connector->property_ids[i],
27967 @@ -1417,7 +1417,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
27968
27969 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
27970 copied = 0;
27971 - encoder_ptr = (uint32_t *)(unsigned long)(out_resp->encoders_ptr);
27972 + encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
27973 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
27974 if (connector->encoder_ids[i] != 0) {
27975 if (put_user(connector->encoder_ids[i],
27976 @@ -1576,7 +1576,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
27977 }
27978
27979 for (i = 0; i < crtc_req->count_connectors; i++) {
27980 - set_connectors_ptr = (uint32_t *)(unsigned long)crtc_req->set_connectors_ptr;
27981 + set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
27982 if (get_user(out_id, &set_connectors_ptr[i])) {
27983 ret = -EFAULT;
27984 goto out;
27985 @@ -1857,7 +1857,7 @@ int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
27986 fb = obj_to_fb(obj);
27987
27988 num_clips = r->num_clips;
27989 - clips_ptr = (struct drm_clip_rect *)(unsigned long)r->clips_ptr;
27990 + clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
27991
27992 if (!num_clips != !clips_ptr) {
27993 ret = -EINVAL;
27994 @@ -2283,7 +2283,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
27995 out_resp->flags = property->flags;
27996
27997 if ((out_resp->count_values >= value_count) && value_count) {
27998 - values_ptr = (uint64_t *)(unsigned long)out_resp->values_ptr;
27999 + values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
28000 for (i = 0; i < value_count; i++) {
28001 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
28002 ret = -EFAULT;
28003 @@ -2296,7 +2296,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
28004 if (property->flags & DRM_MODE_PROP_ENUM) {
28005 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
28006 copied = 0;
28007 - enum_ptr = (struct drm_mode_property_enum *)(unsigned long)out_resp->enum_blob_ptr;
28008 + enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
28009 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
28010
28011 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
28012 @@ -2319,7 +2319,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
28013 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
28014 copied = 0;
28015 blob_id_ptr = (uint32_t *)(unsigned long)out_resp->enum_blob_ptr;
28016 - blob_length_ptr = (uint32_t *)(unsigned long)out_resp->values_ptr;
28017 + blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
28018
28019 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
28020 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
28021 @@ -2380,7 +2380,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
28022 struct drm_mode_get_blob *out_resp = data;
28023 struct drm_property_blob *blob;
28024 int ret = 0;
28025 - void *blob_ptr;
28026 + void __user *blob_ptr;
28027
28028 if (!drm_core_check_feature(dev, DRIVER_MODESET))
28029 return -EINVAL;
28030 @@ -2394,7 +2394,7 @@ int drm_mode_getblob_ioctl(struct drm_device *dev,
28031 blob = obj_to_blob(obj);
28032
28033 if (out_resp->length == blob->length) {
28034 - blob_ptr = (void *)(unsigned long)out_resp->data;
28035 + blob_ptr = (void __user *)(unsigned long)out_resp->data;
28036 if (copy_to_user(blob_ptr, blob->data, blob->length)){
28037 ret = -EFAULT;
28038 goto done;
28039 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
28040 index d2619d7..bd6bd00 100644
28041 --- a/drivers/gpu/drm/drm_crtc_helper.c
28042 +++ b/drivers/gpu/drm/drm_crtc_helper.c
28043 @@ -279,7 +279,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
28044 struct drm_crtc *tmp;
28045 int crtc_mask = 1;
28046
28047 - WARN(!crtc, "checking null crtc?\n");
28048 + BUG_ON(!crtc);
28049
28050 dev = crtc->dev;
28051
28052 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
28053 index 40c187c..5746164 100644
28054 --- a/drivers/gpu/drm/drm_drv.c
28055 +++ b/drivers/gpu/drm/drm_drv.c
28056 @@ -308,7 +308,7 @@ module_exit(drm_core_exit);
28057 /**
28058 * Copy and IOCTL return string to user space
28059 */
28060 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
28061 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
28062 {
28063 int len;
28064
28065 @@ -387,7 +387,7 @@ long drm_ioctl(struct file *filp,
28066
28067 dev = file_priv->minor->dev;
28068 atomic_inc(&dev->ioctl_count);
28069 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
28070 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
28071 ++file_priv->ioctl_count;
28072
28073 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
28074 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
28075 index 828bf65..cdaa0e9 100644
28076 --- a/drivers/gpu/drm/drm_fops.c
28077 +++ b/drivers/gpu/drm/drm_fops.c
28078 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
28079 }
28080
28081 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
28082 - atomic_set(&dev->counts[i], 0);
28083 + atomic_set_unchecked(&dev->counts[i], 0);
28084
28085 dev->sigdata.lock = NULL;
28086
28087 @@ -135,8 +135,8 @@ int drm_open(struct inode *inode, struct file *filp)
28088
28089 retcode = drm_open_helper(inode, filp, dev);
28090 if (!retcode) {
28091 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
28092 - if (!dev->open_count++)
28093 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
28094 + if (local_inc_return(&dev->open_count) == 1)
28095 retcode = drm_setup(dev);
28096 }
28097 if (!retcode) {
28098 @@ -473,7 +473,7 @@ int drm_release(struct inode *inode, struct file *filp)
28099
28100 mutex_lock(&drm_global_mutex);
28101
28102 - DRM_DEBUG("open_count = %d\n", dev->open_count);
28103 + DRM_DEBUG("open_count = %d\n", local_read(&dev->open_count));
28104
28105 if (dev->driver->preclose)
28106 dev->driver->preclose(dev, file_priv);
28107 @@ -485,7 +485,7 @@ int drm_release(struct inode *inode, struct file *filp)
28108 DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
28109 task_pid_nr(current),
28110 (long)old_encode_dev(file_priv->minor->device),
28111 - dev->open_count);
28112 + local_read(&dev->open_count));
28113
28114 /* Release any auth tokens that might point to this file_priv,
28115 (do that under the drm_global_mutex) */
28116 @@ -571,8 +571,8 @@ int drm_release(struct inode *inode, struct file *filp)
28117 * End inline drm_release
28118 */
28119
28120 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
28121 - if (!--dev->open_count) {
28122 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
28123 + if (local_dec_and_test(&dev->open_count)) {
28124 if (atomic_read(&dev->ioctl_count)) {
28125 DRM_ERROR("Device busy: %d\n",
28126 atomic_read(&dev->ioctl_count));
28127 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
28128 index c87dc96..326055d 100644
28129 --- a/drivers/gpu/drm/drm_global.c
28130 +++ b/drivers/gpu/drm/drm_global.c
28131 @@ -36,7 +36,7 @@
28132 struct drm_global_item {
28133 struct mutex mutex;
28134 void *object;
28135 - int refcount;
28136 + atomic_t refcount;
28137 };
28138
28139 static struct drm_global_item glob[DRM_GLOBAL_NUM];
28140 @@ -49,7 +49,7 @@ void drm_global_init(void)
28141 struct drm_global_item *item = &glob[i];
28142 mutex_init(&item->mutex);
28143 item->object = NULL;
28144 - item->refcount = 0;
28145 + atomic_set(&item->refcount, 0);
28146 }
28147 }
28148
28149 @@ -59,7 +59,7 @@ void drm_global_release(void)
28150 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
28151 struct drm_global_item *item = &glob[i];
28152 BUG_ON(item->object != NULL);
28153 - BUG_ON(item->refcount != 0);
28154 + BUG_ON(atomic_read(&item->refcount) != 0);
28155 }
28156 }
28157
28158 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28159 void *object;
28160
28161 mutex_lock(&item->mutex);
28162 - if (item->refcount == 0) {
28163 + if (atomic_read(&item->refcount) == 0) {
28164 item->object = kzalloc(ref->size, GFP_KERNEL);
28165 if (unlikely(item->object == NULL)) {
28166 ret = -ENOMEM;
28167 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
28168 goto out_err;
28169
28170 }
28171 - ++item->refcount;
28172 + atomic_inc(&item->refcount);
28173 ref->object = item->object;
28174 object = item->object;
28175 mutex_unlock(&item->mutex);
28176 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
28177 struct drm_global_item *item = &glob[ref->global_type];
28178
28179 mutex_lock(&item->mutex);
28180 - BUG_ON(item->refcount == 0);
28181 + BUG_ON(atomic_read(&item->refcount) == 0);
28182 BUG_ON(ref->object != item->object);
28183 - if (--item->refcount == 0) {
28184 + if (atomic_dec_and_test(&item->refcount)) {
28185 ref->release(ref);
28186 item->object = NULL;
28187 }
28188 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
28189 index ab1162d..42587b2 100644
28190 --- a/drivers/gpu/drm/drm_info.c
28191 +++ b/drivers/gpu/drm/drm_info.c
28192 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
28193 struct drm_local_map *map;
28194 struct drm_map_list *r_list;
28195
28196 - /* Hardcoded from _DRM_FRAME_BUFFER,
28197 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
28198 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
28199 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
28200 + static const char * const types[] = {
28201 + [_DRM_FRAME_BUFFER] = "FB",
28202 + [_DRM_REGISTERS] = "REG",
28203 + [_DRM_SHM] = "SHM",
28204 + [_DRM_AGP] = "AGP",
28205 + [_DRM_SCATTER_GATHER] = "SG",
28206 + [_DRM_CONSISTENT] = "PCI",
28207 + [_DRM_GEM] = "GEM" };
28208 const char *type;
28209 int i;
28210
28211 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
28212 map = r_list->map;
28213 if (!map)
28214 continue;
28215 - if (map->type < 0 || map->type > 5)
28216 + if (map->type >= ARRAY_SIZE(types))
28217 type = "??";
28218 else
28219 type = types[map->type];
28220 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
28221 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
28222 vma->vm_flags & VM_LOCKED ? 'l' : '-',
28223 vma->vm_flags & VM_IO ? 'i' : '-',
28224 +#ifdef CONFIG_GRKERNSEC_HIDESYM
28225 + 0);
28226 +#else
28227 vma->vm_pgoff);
28228 +#endif
28229
28230 #if defined(__i386__)
28231 pgprot = pgprot_val(vma->vm_page_prot);
28232 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
28233 index ddd70db..40321e6 100644
28234 --- a/drivers/gpu/drm/drm_ioc32.c
28235 +++ b/drivers/gpu/drm/drm_ioc32.c
28236 @@ -456,7 +456,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
28237 request = compat_alloc_user_space(nbytes);
28238 if (!access_ok(VERIFY_WRITE, request, nbytes))
28239 return -EFAULT;
28240 - list = (struct drm_buf_desc *) (request + 1);
28241 + list = (struct drm_buf_desc __user *) (request + 1);
28242
28243 if (__put_user(count, &request->count)
28244 || __put_user(list, &request->list))
28245 @@ -517,7 +517,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
28246 request = compat_alloc_user_space(nbytes);
28247 if (!access_ok(VERIFY_WRITE, request, nbytes))
28248 return -EFAULT;
28249 - list = (struct drm_buf_pub *) (request + 1);
28250 + list = (struct drm_buf_pub __user *) (request + 1);
28251
28252 if (__put_user(count, &request->count)
28253 || __put_user(list, &request->list))
28254 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
28255 index 904d7e9..ab88581 100644
28256 --- a/drivers/gpu/drm/drm_ioctl.c
28257 +++ b/drivers/gpu/drm/drm_ioctl.c
28258 @@ -256,7 +256,7 @@ int drm_getstats(struct drm_device *dev, void *data,
28259 stats->data[i].value =
28260 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
28261 else
28262 - stats->data[i].value = atomic_read(&dev->counts[i]);
28263 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
28264 stats->data[i].type = dev->types[i];
28265 }
28266
28267 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
28268 index 632ae24..244cf4a 100644
28269 --- a/drivers/gpu/drm/drm_lock.c
28270 +++ b/drivers/gpu/drm/drm_lock.c
28271 @@ -89,7 +89,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28272 if (drm_lock_take(&master->lock, lock->context)) {
28273 master->lock.file_priv = file_priv;
28274 master->lock.lock_time = jiffies;
28275 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
28276 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
28277 break; /* Got lock */
28278 }
28279
28280 @@ -160,7 +160,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
28281 return -EINVAL;
28282 }
28283
28284 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
28285 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
28286
28287 if (drm_lock_free(&master->lock, lock->context)) {
28288 /* FIXME: Should really bail out here. */
28289 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
28290 index 8f371e8..9f85d52 100644
28291 --- a/drivers/gpu/drm/i810/i810_dma.c
28292 +++ b/drivers/gpu/drm/i810/i810_dma.c
28293 @@ -950,8 +950,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
28294 dma->buflist[vertex->idx],
28295 vertex->discard, vertex->used);
28296
28297 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28298 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28299 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
28300 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28301 sarea_priv->last_enqueue = dev_priv->counter - 1;
28302 sarea_priv->last_dispatch = (int)hw_status[5];
28303
28304 @@ -1111,8 +1111,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
28305 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
28306 mc->last_render);
28307
28308 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28309 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
28310 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
28311 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
28312 sarea_priv->last_enqueue = dev_priv->counter - 1;
28313 sarea_priv->last_dispatch = (int)hw_status[5];
28314
28315 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
28316 index c9339f4..f5e1b9d 100644
28317 --- a/drivers/gpu/drm/i810/i810_drv.h
28318 +++ b/drivers/gpu/drm/i810/i810_drv.h
28319 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
28320 int page_flipping;
28321
28322 wait_queue_head_t irq_queue;
28323 - atomic_t irq_received;
28324 - atomic_t irq_emitted;
28325 + atomic_unchecked_t irq_received;
28326 + atomic_unchecked_t irq_emitted;
28327
28328 int front_offset;
28329 } drm_i810_private_t;
28330 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
28331 index b2e3c97..58cf079 100644
28332 --- a/drivers/gpu/drm/i915/i915_debugfs.c
28333 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
28334 @@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
28335 I915_READ(GTIMR));
28336 }
28337 seq_printf(m, "Interrupts received: %d\n",
28338 - atomic_read(&dev_priv->irq_received));
28339 + atomic_read_unchecked(&dev_priv->irq_received));
28340 for (i = 0; i < I915_NUM_RINGS; i++) {
28341 if (IS_GEN6(dev) || IS_GEN7(dev)) {
28342 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
28343 @@ -1232,7 +1232,7 @@ static int i915_opregion(struct seq_file *m, void *unused)
28344 return ret;
28345
28346 if (opregion->header)
28347 - seq_write(m, opregion->header, OPREGION_SIZE);
28348 + seq_write(m, (const void __force_kernel *)opregion->header, OPREGION_SIZE);
28349
28350 mutex_unlock(&dev->struct_mutex);
28351
28352 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
28353 index c4da951..3c59c5c 100644
28354 --- a/drivers/gpu/drm/i915/i915_dma.c
28355 +++ b/drivers/gpu/drm/i915/i915_dma.c
28356 @@ -1172,7 +1172,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
28357 bool can_switch;
28358
28359 spin_lock(&dev->count_lock);
28360 - can_switch = (dev->open_count == 0);
28361 + can_switch = (local_read(&dev->open_count) == 0);
28362 spin_unlock(&dev->count_lock);
28363 return can_switch;
28364 }
28365 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
28366 index ae294a0..1755461 100644
28367 --- a/drivers/gpu/drm/i915/i915_drv.h
28368 +++ b/drivers/gpu/drm/i915/i915_drv.h
28369 @@ -229,7 +229,7 @@ struct drm_i915_display_funcs {
28370 /* render clock increase/decrease */
28371 /* display clock increase/decrease */
28372 /* pll clock increase/decrease */
28373 -};
28374 +} __no_const;
28375
28376 struct intel_device_info {
28377 u8 gen;
28378 @@ -318,7 +318,7 @@ typedef struct drm_i915_private {
28379 int current_page;
28380 int page_flipping;
28381
28382 - atomic_t irq_received;
28383 + atomic_unchecked_t irq_received;
28384
28385 /* protects the irq masks */
28386 spinlock_t irq_lock;
28387 @@ -893,7 +893,7 @@ struct drm_i915_gem_object {
28388 * will be page flipped away on the next vblank. When it
28389 * reaches 0, dev_priv->pending_flip_queue will be woken up.
28390 */
28391 - atomic_t pending_flip;
28392 + atomic_unchecked_t pending_flip;
28393 };
28394
28395 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
28396 @@ -1273,7 +1273,7 @@ extern int intel_setup_gmbus(struct drm_device *dev);
28397 extern void intel_teardown_gmbus(struct drm_device *dev);
28398 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
28399 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
28400 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28401 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
28402 {
28403 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
28404 }
28405 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28406 index b9da890..cad1d98 100644
28407 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28408 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
28409 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
28410 i915_gem_clflush_object(obj);
28411
28412 if (obj->base.pending_write_domain)
28413 - cd->flips |= atomic_read(&obj->pending_flip);
28414 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
28415
28416 /* The actual obj->write_domain will be updated with
28417 * pending_write_domain after we emit the accumulated flush for all
28418 @@ -882,9 +882,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
28419
28420 static int
28421 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
28422 - int count)
28423 + unsigned int count)
28424 {
28425 - int i;
28426 + unsigned int i;
28427
28428 for (i = 0; i < count; i++) {
28429 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
28430 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
28431 index d47a53b..61154c2 100644
28432 --- a/drivers/gpu/drm/i915/i915_irq.c
28433 +++ b/drivers/gpu/drm/i915/i915_irq.c
28434 @@ -475,7 +475,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
28435 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
28436 struct drm_i915_master_private *master_priv;
28437
28438 - atomic_inc(&dev_priv->irq_received);
28439 + atomic_inc_unchecked(&dev_priv->irq_received);
28440
28441 /* disable master interrupt before clearing iir */
28442 de_ier = I915_READ(DEIER);
28443 @@ -566,7 +566,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
28444 struct drm_i915_master_private *master_priv;
28445 u32 bsd_usr_interrupt = GT_BSD_USER_INTERRUPT;
28446
28447 - atomic_inc(&dev_priv->irq_received);
28448 + atomic_inc_unchecked(&dev_priv->irq_received);
28449
28450 if (IS_GEN6(dev))
28451 bsd_usr_interrupt = GT_GEN6_BSD_USER_INTERRUPT;
28452 @@ -1231,7 +1231,7 @@ static irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS)
28453 int ret = IRQ_NONE, pipe;
28454 bool blc_event = false;
28455
28456 - atomic_inc(&dev_priv->irq_received);
28457 + atomic_inc_unchecked(&dev_priv->irq_received);
28458
28459 iir = I915_READ(IIR);
28460
28461 @@ -1750,7 +1750,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
28462 {
28463 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28464
28465 - atomic_set(&dev_priv->irq_received, 0);
28466 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28467
28468 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28469 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28470 @@ -1938,7 +1938,7 @@ static void i915_driver_irq_preinstall(struct drm_device * dev)
28471 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
28472 int pipe;
28473
28474 - atomic_set(&dev_priv->irq_received, 0);
28475 + atomic_set_unchecked(&dev_priv->irq_received, 0);
28476
28477 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
28478 INIT_WORK(&dev_priv->error_work, i915_error_work_func);
28479 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
28480 index daa5743..c0757a9 100644
28481 --- a/drivers/gpu/drm/i915/intel_display.c
28482 +++ b/drivers/gpu/drm/i915/intel_display.c
28483 @@ -2230,7 +2230,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
28484
28485 wait_event(dev_priv->pending_flip_queue,
28486 atomic_read(&dev_priv->mm.wedged) ||
28487 - atomic_read(&obj->pending_flip) == 0);
28488 + atomic_read_unchecked(&obj->pending_flip) == 0);
28489
28490 /* Big Hammer, we also need to ensure that any pending
28491 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
28492 @@ -2851,7 +2851,7 @@ static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
28493 obj = to_intel_framebuffer(crtc->fb)->obj;
28494 dev_priv = crtc->dev->dev_private;
28495 wait_event(dev_priv->pending_flip_queue,
28496 - atomic_read(&obj->pending_flip) == 0);
28497 + atomic_read_unchecked(&obj->pending_flip) == 0);
28498 }
28499
28500 static bool intel_crtc_driving_pch(struct drm_crtc *crtc)
28501 @@ -6952,7 +6952,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
28502
28503 atomic_clear_mask(1 << intel_crtc->plane,
28504 &obj->pending_flip.counter);
28505 - if (atomic_read(&obj->pending_flip) == 0)
28506 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
28507 wake_up(&dev_priv->pending_flip_queue);
28508
28509 schedule_work(&work->work);
28510 @@ -7242,7 +7242,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28511 /* Block clients from rendering to the new back buffer until
28512 * the flip occurs and the object is no longer visible.
28513 */
28514 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28515 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28516
28517 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
28518 if (ret)
28519 @@ -7256,7 +7256,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
28520 return 0;
28521
28522 cleanup_pending:
28523 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28524 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
28525 drm_gem_object_unreference(&work->old_fb_obj->base);
28526 drm_gem_object_unreference(&obj->base);
28527 mutex_unlock(&dev->struct_mutex);
28528 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
28529 index 54558a0..2d97005 100644
28530 --- a/drivers/gpu/drm/mga/mga_drv.h
28531 +++ b/drivers/gpu/drm/mga/mga_drv.h
28532 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
28533 u32 clear_cmd;
28534 u32 maccess;
28535
28536 - atomic_t vbl_received; /**< Number of vblanks received. */
28537 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
28538 wait_queue_head_t fence_queue;
28539 - atomic_t last_fence_retired;
28540 + atomic_unchecked_t last_fence_retired;
28541 u32 next_fence_to_post;
28542
28543 unsigned int fb_cpp;
28544 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
28545 index 2581202..f230a8d9 100644
28546 --- a/drivers/gpu/drm/mga/mga_irq.c
28547 +++ b/drivers/gpu/drm/mga/mga_irq.c
28548 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
28549 if (crtc != 0)
28550 return 0;
28551
28552 - return atomic_read(&dev_priv->vbl_received);
28553 + return atomic_read_unchecked(&dev_priv->vbl_received);
28554 }
28555
28556
28557 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28558 /* VBLANK interrupt */
28559 if (status & MGA_VLINEPEN) {
28560 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
28561 - atomic_inc(&dev_priv->vbl_received);
28562 + atomic_inc_unchecked(&dev_priv->vbl_received);
28563 drm_handle_vblank(dev, 0);
28564 handled = 1;
28565 }
28566 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
28567 if ((prim_start & ~0x03) != (prim_end & ~0x03))
28568 MGA_WRITE(MGA_PRIMEND, prim_end);
28569
28570 - atomic_inc(&dev_priv->last_fence_retired);
28571 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
28572 DRM_WAKEUP(&dev_priv->fence_queue);
28573 handled = 1;
28574 }
28575 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
28576 * using fences.
28577 */
28578 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
28579 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
28580 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
28581 - *sequence) <= (1 << 23)));
28582
28583 *sequence = cur_fence;
28584 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
28585 index 5fc201b..7b032b9 100644
28586 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
28587 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
28588 @@ -201,7 +201,7 @@ struct methods {
28589 const char desc[8];
28590 void (*loadbios)(struct drm_device *, uint8_t *);
28591 const bool rw;
28592 -};
28593 +} __do_const;
28594
28595 static struct methods shadow_methods[] = {
28596 { "PRAMIN", load_vbios_pramin, true },
28597 @@ -5474,7 +5474,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
28598 struct bit_table {
28599 const char id;
28600 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
28601 -};
28602 +} __no_const;
28603
28604 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
28605
28606 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
28607 index 4c0be3a..5757582 100644
28608 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
28609 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
28610 @@ -238,7 +238,7 @@ struct nouveau_channel {
28611 struct list_head pending;
28612 uint32_t sequence;
28613 uint32_t sequence_ack;
28614 - atomic_t last_sequence_irq;
28615 + atomic_unchecked_t last_sequence_irq;
28616 struct nouveau_vma vma;
28617 } fence;
28618
28619 @@ -319,7 +319,7 @@ struct nouveau_exec_engine {
28620 u32 handle, u16 class);
28621 void (*set_tile_region)(struct drm_device *dev, int i);
28622 void (*tlb_flush)(struct drm_device *, int engine);
28623 -};
28624 +} __no_const;
28625
28626 struct nouveau_instmem_engine {
28627 void *priv;
28628 @@ -341,13 +341,13 @@ struct nouveau_instmem_engine {
28629 struct nouveau_mc_engine {
28630 int (*init)(struct drm_device *dev);
28631 void (*takedown)(struct drm_device *dev);
28632 -};
28633 +} __no_const;
28634
28635 struct nouveau_timer_engine {
28636 int (*init)(struct drm_device *dev);
28637 void (*takedown)(struct drm_device *dev);
28638 uint64_t (*read)(struct drm_device *dev);
28639 -};
28640 +} __no_const;
28641
28642 struct nouveau_fb_engine {
28643 int num_tiles;
28644 @@ -558,7 +558,7 @@ struct nouveau_vram_engine {
28645 void (*put)(struct drm_device *, struct nouveau_mem **);
28646
28647 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
28648 -};
28649 +} __no_const;
28650
28651 struct nouveau_engine {
28652 struct nouveau_instmem_engine instmem;
28653 @@ -706,7 +706,7 @@ struct drm_nouveau_private {
28654 struct drm_global_reference mem_global_ref;
28655 struct ttm_bo_global_ref bo_global_ref;
28656 struct ttm_bo_device bdev;
28657 - atomic_t validate_sequence;
28658 + atomic_unchecked_t validate_sequence;
28659 } ttm;
28660
28661 struct {
28662 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c
28663 index 2f6daae..c9d7b9e 100644
28664 --- a/drivers/gpu/drm/nouveau/nouveau_fence.c
28665 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.c
28666 @@ -85,7 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan)
28667 if (USE_REFCNT(dev))
28668 sequence = nvchan_rd32(chan, 0x48);
28669 else
28670 - sequence = atomic_read(&chan->fence.last_sequence_irq);
28671 + sequence = atomic_read_unchecked(&chan->fence.last_sequence_irq);
28672
28673 if (chan->fence.sequence_ack == sequence)
28674 goto out;
28675 @@ -539,7 +539,7 @@ nouveau_fence_channel_init(struct nouveau_channel *chan)
28676 return ret;
28677 }
28678
28679 - atomic_set(&chan->fence.last_sequence_irq, 0);
28680 + atomic_set_unchecked(&chan->fence.last_sequence_irq, 0);
28681 return 0;
28682 }
28683
28684 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
28685 index 7ce3fde..cb3ea04 100644
28686 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
28687 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
28688 @@ -314,7 +314,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
28689 int trycnt = 0;
28690 int ret, i;
28691
28692 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
28693 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
28694 retry:
28695 if (++trycnt > 100000) {
28696 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
28697 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
28698 index d8831ab..0ba8356 100644
28699 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
28700 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
28701 @@ -542,7 +542,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
28702 bool can_switch;
28703
28704 spin_lock(&dev->count_lock);
28705 - can_switch = (dev->open_count == 0);
28706 + can_switch = (local_read(&dev->open_count) == 0);
28707 spin_unlock(&dev->count_lock);
28708 return can_switch;
28709 }
28710 diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c
28711 index dbdea8e..cd6eeeb 100644
28712 --- a/drivers/gpu/drm/nouveau/nv04_graph.c
28713 +++ b/drivers/gpu/drm/nouveau/nv04_graph.c
28714 @@ -554,7 +554,7 @@ static int
28715 nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
28716 u32 class, u32 mthd, u32 data)
28717 {
28718 - atomic_set(&chan->fence.last_sequence_irq, data);
28719 + atomic_set_unchecked(&chan->fence.last_sequence_irq, data);
28720 return 0;
28721 }
28722
28723 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
28724 index bcac90b..53bfc76 100644
28725 --- a/drivers/gpu/drm/r128/r128_cce.c
28726 +++ b/drivers/gpu/drm/r128/r128_cce.c
28727 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
28728
28729 /* GH: Simple idle check.
28730 */
28731 - atomic_set(&dev_priv->idle_count, 0);
28732 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28733
28734 /* We don't support anything other than bus-mastering ring mode,
28735 * but the ring can be in either AGP or PCI space for the ring
28736 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
28737 index 930c71b..499aded 100644
28738 --- a/drivers/gpu/drm/r128/r128_drv.h
28739 +++ b/drivers/gpu/drm/r128/r128_drv.h
28740 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
28741 int is_pci;
28742 unsigned long cce_buffers_offset;
28743
28744 - atomic_t idle_count;
28745 + atomic_unchecked_t idle_count;
28746
28747 int page_flipping;
28748 int current_page;
28749 u32 crtc_offset;
28750 u32 crtc_offset_cntl;
28751
28752 - atomic_t vbl_received;
28753 + atomic_unchecked_t vbl_received;
28754
28755 u32 color_fmt;
28756 unsigned int front_offset;
28757 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
28758 index 429d5a0..7e899ed 100644
28759 --- a/drivers/gpu/drm/r128/r128_irq.c
28760 +++ b/drivers/gpu/drm/r128/r128_irq.c
28761 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
28762 if (crtc != 0)
28763 return 0;
28764
28765 - return atomic_read(&dev_priv->vbl_received);
28766 + return atomic_read_unchecked(&dev_priv->vbl_received);
28767 }
28768
28769 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28770 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
28771 /* VBLANK interrupt */
28772 if (status & R128_CRTC_VBLANK_INT) {
28773 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
28774 - atomic_inc(&dev_priv->vbl_received);
28775 + atomic_inc_unchecked(&dev_priv->vbl_received);
28776 drm_handle_vblank(dev, 0);
28777 return IRQ_HANDLED;
28778 }
28779 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
28780 index a9e33ce..09edd4b 100644
28781 --- a/drivers/gpu/drm/r128/r128_state.c
28782 +++ b/drivers/gpu/drm/r128/r128_state.c
28783 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
28784
28785 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
28786 {
28787 - if (atomic_read(&dev_priv->idle_count) == 0)
28788 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
28789 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
28790 else
28791 - atomic_set(&dev_priv->idle_count, 0);
28792 + atomic_set_unchecked(&dev_priv->idle_count, 0);
28793 }
28794
28795 #endif
28796 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
28797 index 5a82b6b..9e69c73 100644
28798 --- a/drivers/gpu/drm/radeon/mkregtable.c
28799 +++ b/drivers/gpu/drm/radeon/mkregtable.c
28800 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
28801 regex_t mask_rex;
28802 regmatch_t match[4];
28803 char buf[1024];
28804 - size_t end;
28805 + long end;
28806 int len;
28807 int done = 0;
28808 int r;
28809 unsigned o;
28810 struct offset *offset;
28811 char last_reg_s[10];
28812 - int last_reg;
28813 + unsigned long last_reg;
28814
28815 if (regcomp
28816 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
28817 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
28818 index 8227e76..ce0b195 100644
28819 --- a/drivers/gpu/drm/radeon/radeon.h
28820 +++ b/drivers/gpu/drm/radeon/radeon.h
28821 @@ -192,7 +192,7 @@ extern int sumo_get_temp(struct radeon_device *rdev);
28822 */
28823 struct radeon_fence_driver {
28824 uint32_t scratch_reg;
28825 - atomic_t seq;
28826 + atomic_unchecked_t seq;
28827 uint32_t last_seq;
28828 unsigned long last_jiffies;
28829 unsigned long last_timeout;
28830 @@ -530,7 +530,7 @@ struct r600_blit_cp_primitives {
28831 int x2, int y2);
28832 void (*draw_auto)(struct radeon_device *rdev);
28833 void (*set_default_state)(struct radeon_device *rdev);
28834 -};
28835 +} __no_const;
28836
28837 struct r600_blit {
28838 struct mutex mutex;
28839 @@ -954,7 +954,7 @@ struct radeon_asic {
28840 void (*pre_page_flip)(struct radeon_device *rdev, int crtc);
28841 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
28842 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
28843 -};
28844 +} __no_const;
28845
28846 /*
28847 * Asic structures
28848 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
28849 index 9231564..78b00fd 100644
28850 --- a/drivers/gpu/drm/radeon/radeon_device.c
28851 +++ b/drivers/gpu/drm/radeon/radeon_device.c
28852 @@ -687,7 +687,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
28853 bool can_switch;
28854
28855 spin_lock(&dev->count_lock);
28856 - can_switch = (dev->open_count == 0);
28857 + can_switch = (local_read(&dev->open_count) == 0);
28858 spin_unlock(&dev->count_lock);
28859 return can_switch;
28860 }
28861 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
28862 index a1b59ca..86f2d44 100644
28863 --- a/drivers/gpu/drm/radeon/radeon_drv.h
28864 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
28865 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
28866
28867 /* SW interrupt */
28868 wait_queue_head_t swi_queue;
28869 - atomic_t swi_emitted;
28870 + atomic_unchecked_t swi_emitted;
28871 int vblank_crtc;
28872 uint32_t irq_enable_reg;
28873 uint32_t r500_disp_irq_reg;
28874 diff --git a/drivers/gpu/drm/radeon/radeon_fence.c b/drivers/gpu/drm/radeon/radeon_fence.c
28875 index 76ec0e9..6feb1a3 100644
28876 --- a/drivers/gpu/drm/radeon/radeon_fence.c
28877 +++ b/drivers/gpu/drm/radeon/radeon_fence.c
28878 @@ -78,7 +78,7 @@ int radeon_fence_emit(struct radeon_device *rdev, struct radeon_fence *fence)
28879 write_unlock_irqrestore(&rdev->fence_drv.lock, irq_flags);
28880 return 0;
28881 }
28882 - fence->seq = atomic_add_return(1, &rdev->fence_drv.seq);
28883 + fence->seq = atomic_add_return_unchecked(1, &rdev->fence_drv.seq);
28884 if (!rdev->cp.ready)
28885 /* FIXME: cp is not running assume everythings is done right
28886 * away
28887 @@ -373,7 +373,7 @@ int radeon_fence_driver_init(struct radeon_device *rdev)
28888 return r;
28889 }
28890 radeon_fence_write(rdev, 0);
28891 - atomic_set(&rdev->fence_drv.seq, 0);
28892 + atomic_set_unchecked(&rdev->fence_drv.seq, 0);
28893 INIT_LIST_HEAD(&rdev->fence_drv.created);
28894 INIT_LIST_HEAD(&rdev->fence_drv.emited);
28895 INIT_LIST_HEAD(&rdev->fence_drv.signaled);
28896 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
28897 index 48b7cea..342236f 100644
28898 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
28899 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
28900 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
28901 request = compat_alloc_user_space(sizeof(*request));
28902 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
28903 || __put_user(req32.param, &request->param)
28904 - || __put_user((void __user *)(unsigned long)req32.value,
28905 + || __put_user((unsigned long)req32.value,
28906 &request->value))
28907 return -EFAULT;
28908
28909 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
28910 index 00da384..32f972d 100644
28911 --- a/drivers/gpu/drm/radeon/radeon_irq.c
28912 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
28913 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
28914 unsigned int ret;
28915 RING_LOCALS;
28916
28917 - atomic_inc(&dev_priv->swi_emitted);
28918 - ret = atomic_read(&dev_priv->swi_emitted);
28919 + atomic_inc_unchecked(&dev_priv->swi_emitted);
28920 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
28921
28922 BEGIN_RING(4);
28923 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
28924 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
28925 drm_radeon_private_t *dev_priv =
28926 (drm_radeon_private_t *) dev->dev_private;
28927
28928 - atomic_set(&dev_priv->swi_emitted, 0);
28929 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
28930 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
28931
28932 dev->max_vblank_count = 0x001fffff;
28933 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
28934 index e8422ae..d22d4a8 100644
28935 --- a/drivers/gpu/drm/radeon/radeon_state.c
28936 +++ b/drivers/gpu/drm/radeon/radeon_state.c
28937 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
28938 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
28939 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
28940
28941 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
28942 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
28943 sarea_priv->nbox * sizeof(depth_boxes[0])))
28944 return -EFAULT;
28945
28946 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
28947 {
28948 drm_radeon_private_t *dev_priv = dev->dev_private;
28949 drm_radeon_getparam_t *param = data;
28950 - int value;
28951 + int value = 0;
28952
28953 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
28954
28955 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
28956 index 0b5468b..9c4b308 100644
28957 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
28958 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
28959 @@ -672,8 +672,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
28960 }
28961 if (unlikely(ttm_vm_ops == NULL)) {
28962 ttm_vm_ops = vma->vm_ops;
28963 - radeon_ttm_vm_ops = *ttm_vm_ops;
28964 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28965 + pax_open_kernel();
28966 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
28967 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
28968 + pax_close_kernel();
28969 }
28970 vma->vm_ops = &radeon_ttm_vm_ops;
28971 return 0;
28972 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
28973 index a9049ed..501f284 100644
28974 --- a/drivers/gpu/drm/radeon/rs690.c
28975 +++ b/drivers/gpu/drm/radeon/rs690.c
28976 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
28977 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
28978 rdev->pm.sideport_bandwidth.full)
28979 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
28980 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
28981 + read_delay_latency.full = dfixed_const(800 * 1000);
28982 read_delay_latency.full = dfixed_div(read_delay_latency,
28983 rdev->pm.igp_sideport_mclk);
28984 + a.full = dfixed_const(370);
28985 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
28986 } else {
28987 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
28988 rdev->pm.k8_bandwidth.full)
28989 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
28990 index 727e93d..1565650 100644
28991 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
28992 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
28993 @@ -398,9 +398,9 @@ static int ttm_pool_get_num_unused_pages(void)
28994 static int ttm_pool_mm_shrink(struct shrinker *shrink,
28995 struct shrink_control *sc)
28996 {
28997 - static atomic_t start_pool = ATOMIC_INIT(0);
28998 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
28999 unsigned i;
29000 - unsigned pool_offset = atomic_add_return(1, &start_pool);
29001 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
29002 struct ttm_page_pool *pool;
29003 int shrink_pages = sc->nr_to_scan;
29004
29005 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
29006 index 9cf87d9..2000b7d 100644
29007 --- a/drivers/gpu/drm/via/via_drv.h
29008 +++ b/drivers/gpu/drm/via/via_drv.h
29009 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
29010 typedef uint32_t maskarray_t[5];
29011
29012 typedef struct drm_via_irq {
29013 - atomic_t irq_received;
29014 + atomic_unchecked_t irq_received;
29015 uint32_t pending_mask;
29016 uint32_t enable_mask;
29017 wait_queue_head_t irq_queue;
29018 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
29019 struct timeval last_vblank;
29020 int last_vblank_valid;
29021 unsigned usec_per_vblank;
29022 - atomic_t vbl_received;
29023 + atomic_unchecked_t vbl_received;
29024 drm_via_state_t hc_state;
29025 char pci_buf[VIA_PCI_BUF_SIZE];
29026 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
29027 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
29028 index d391f48..10c8ca3 100644
29029 --- a/drivers/gpu/drm/via/via_irq.c
29030 +++ b/drivers/gpu/drm/via/via_irq.c
29031 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
29032 if (crtc != 0)
29033 return 0;
29034
29035 - return atomic_read(&dev_priv->vbl_received);
29036 + return atomic_read_unchecked(&dev_priv->vbl_received);
29037 }
29038
29039 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29040 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29041
29042 status = VIA_READ(VIA_REG_INTERRUPT);
29043 if (status & VIA_IRQ_VBLANK_PENDING) {
29044 - atomic_inc(&dev_priv->vbl_received);
29045 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
29046 + atomic_inc_unchecked(&dev_priv->vbl_received);
29047 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
29048 do_gettimeofday(&cur_vblank);
29049 if (dev_priv->last_vblank_valid) {
29050 dev_priv->usec_per_vblank =
29051 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29052 dev_priv->last_vblank = cur_vblank;
29053 dev_priv->last_vblank_valid = 1;
29054 }
29055 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
29056 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
29057 DRM_DEBUG("US per vblank is: %u\n",
29058 dev_priv->usec_per_vblank);
29059 }
29060 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
29061
29062 for (i = 0; i < dev_priv->num_irqs; ++i) {
29063 if (status & cur_irq->pending_mask) {
29064 - atomic_inc(&cur_irq->irq_received);
29065 + atomic_inc_unchecked(&cur_irq->irq_received);
29066 DRM_WAKEUP(&cur_irq->irq_queue);
29067 handled = 1;
29068 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
29069 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
29070 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29071 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
29072 masks[irq][4]));
29073 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
29074 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
29075 } else {
29076 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
29077 (((cur_irq_sequence =
29078 - atomic_read(&cur_irq->irq_received)) -
29079 + atomic_read_unchecked(&cur_irq->irq_received)) -
29080 *sequence) <= (1 << 23)));
29081 }
29082 *sequence = cur_irq_sequence;
29083 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
29084 }
29085
29086 for (i = 0; i < dev_priv->num_irqs; ++i) {
29087 - atomic_set(&cur_irq->irq_received, 0);
29088 + atomic_set_unchecked(&cur_irq->irq_received, 0);
29089 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
29090 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
29091 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
29092 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
29093 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
29094 case VIA_IRQ_RELATIVE:
29095 irqwait->request.sequence +=
29096 - atomic_read(&cur_irq->irq_received);
29097 + atomic_read_unchecked(&cur_irq->irq_received);
29098 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
29099 case VIA_IRQ_ABSOLUTE:
29100 break;
29101 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29102 index dc27970..f18b008 100644
29103 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29104 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
29105 @@ -260,7 +260,7 @@ struct vmw_private {
29106 * Fencing and IRQs.
29107 */
29108
29109 - atomic_t marker_seq;
29110 + atomic_unchecked_t marker_seq;
29111 wait_queue_head_t fence_queue;
29112 wait_queue_head_t fifo_queue;
29113 int fence_queue_waiters; /* Protected by hw_mutex */
29114 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29115 index a0c2f12..68ae6cb 100644
29116 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29117 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
29118 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
29119 (unsigned int) min,
29120 (unsigned int) fifo->capabilities);
29121
29122 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
29123 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
29124 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
29125 vmw_marker_queue_init(&fifo->marker_queue);
29126 return vmw_fifo_send_fence(dev_priv, &dummy);
29127 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
29128 if (reserveable)
29129 iowrite32(bytes, fifo_mem +
29130 SVGA_FIFO_RESERVED);
29131 - return fifo_mem + (next_cmd >> 2);
29132 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
29133 } else {
29134 need_bounce = true;
29135 }
29136 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
29137
29138 fm = vmw_fifo_reserve(dev_priv, bytes);
29139 if (unlikely(fm == NULL)) {
29140 - *seqno = atomic_read(&dev_priv->marker_seq);
29141 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
29142 ret = -ENOMEM;
29143 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
29144 false, 3*HZ);
29145 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
29146 }
29147
29148 do {
29149 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
29150 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
29151 } while (*seqno == 0);
29152
29153 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
29154 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29155 index cabc95f..14b3d77 100644
29156 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29157 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
29158 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
29159 * emitted. Then the fence is stale and signaled.
29160 */
29161
29162 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
29163 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
29164 > VMW_FENCE_WRAP);
29165
29166 return ret;
29167 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
29168
29169 if (fifo_idle)
29170 down_read(&fifo_state->rwsem);
29171 - signal_seq = atomic_read(&dev_priv->marker_seq);
29172 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
29173 ret = 0;
29174
29175 for (;;) {
29176 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29177 index 8a8725c..afed796 100644
29178 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29179 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
29180 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
29181 while (!vmw_lag_lt(queue, us)) {
29182 spin_lock(&queue->lock);
29183 if (list_empty(&queue->head))
29184 - seqno = atomic_read(&dev_priv->marker_seq);
29185 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
29186 else {
29187 marker = list_first_entry(&queue->head,
29188 struct vmw_marker, head);
29189 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
29190 index bb656d8..4169fca 100644
29191 --- a/drivers/hid/hid-core.c
29192 +++ b/drivers/hid/hid-core.c
29193 @@ -2012,7 +2012,7 @@ static bool hid_ignore(struct hid_device *hdev)
29194
29195 int hid_add_device(struct hid_device *hdev)
29196 {
29197 - static atomic_t id = ATOMIC_INIT(0);
29198 + static atomic_unchecked_t id = ATOMIC_INIT(0);
29199 int ret;
29200
29201 if (WARN_ON(hdev->status & HID_STAT_ADDED))
29202 @@ -2027,7 +2027,7 @@ int hid_add_device(struct hid_device *hdev)
29203 /* XXX hack, any other cleaner solution after the driver core
29204 * is converted to allow more than 20 bytes as the device name? */
29205 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
29206 - hdev->vendor, hdev->product, atomic_inc_return(&id));
29207 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
29208
29209 hid_debug_register(hdev, dev_name(&hdev->dev));
29210 ret = device_add(&hdev->dev);
29211 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
29212 index 4ef02b2..8a96831 100644
29213 --- a/drivers/hid/usbhid/hiddev.c
29214 +++ b/drivers/hid/usbhid/hiddev.c
29215 @@ -624,7 +624,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
29216 break;
29217
29218 case HIDIOCAPPLICATION:
29219 - if (arg < 0 || arg >= hid->maxapplication)
29220 + if (arg >= hid->maxapplication)
29221 break;
29222
29223 for (i = 0; i < hid->maxcollection; i++)
29224 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
29225 index 4065374..10ed7dc 100644
29226 --- a/drivers/hv/channel.c
29227 +++ b/drivers/hv/channel.c
29228 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
29229 int ret = 0;
29230 int t;
29231
29232 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
29233 - atomic_inc(&vmbus_connection.next_gpadl_handle);
29234 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
29235 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
29236
29237 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
29238 if (ret)
29239 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
29240 index 0fb100e..baf87e5 100644
29241 --- a/drivers/hv/hv.c
29242 +++ b/drivers/hv/hv.c
29243 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
29244 u64 output_address = (output) ? virt_to_phys(output) : 0;
29245 u32 output_address_hi = output_address >> 32;
29246 u32 output_address_lo = output_address & 0xFFFFFFFF;
29247 - void *hypercall_page = hv_context.hypercall_page;
29248 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
29249
29250 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
29251 "=a"(hv_status_lo) : "d" (control_hi),
29252 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
29253 index 0aee112..b72d21f 100644
29254 --- a/drivers/hv/hyperv_vmbus.h
29255 +++ b/drivers/hv/hyperv_vmbus.h
29256 @@ -556,7 +556,7 @@ enum vmbus_connect_state {
29257 struct vmbus_connection {
29258 enum vmbus_connect_state conn_state;
29259
29260 - atomic_t next_gpadl_handle;
29261 + atomic_unchecked_t next_gpadl_handle;
29262
29263 /*
29264 * Represents channel interrupts. Each bit position represents a
29265 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
29266 index d2d0a2a..90b8f4d 100644
29267 --- a/drivers/hv/vmbus_drv.c
29268 +++ b/drivers/hv/vmbus_drv.c
29269 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
29270 {
29271 int ret = 0;
29272
29273 - static atomic_t device_num = ATOMIC_INIT(0);
29274 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
29275
29276 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
29277 - atomic_inc_return(&device_num));
29278 + atomic_inc_return_unchecked(&device_num));
29279
29280 child_device_obj->device.bus = &hv_bus;
29281 child_device_obj->device.parent = &hv_acpi_dev->dev;
29282 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
29283 index 66f6729..2d6de0a 100644
29284 --- a/drivers/hwmon/acpi_power_meter.c
29285 +++ b/drivers/hwmon/acpi_power_meter.c
29286 @@ -316,8 +316,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
29287 return res;
29288
29289 temp /= 1000;
29290 - if (temp < 0)
29291 - return -EINVAL;
29292
29293 mutex_lock(&resource->lock);
29294 resource->trip[attr->index - 7] = temp;
29295 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
29296 index 5357925..6cf0418 100644
29297 --- a/drivers/hwmon/sht15.c
29298 +++ b/drivers/hwmon/sht15.c
29299 @@ -166,7 +166,7 @@ struct sht15_data {
29300 int supply_uV;
29301 bool supply_uV_valid;
29302 struct work_struct update_supply_work;
29303 - atomic_t interrupt_handled;
29304 + atomic_unchecked_t interrupt_handled;
29305 };
29306
29307 /**
29308 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
29309 return ret;
29310
29311 gpio_direction_input(data->pdata->gpio_data);
29312 - atomic_set(&data->interrupt_handled, 0);
29313 + atomic_set_unchecked(&data->interrupt_handled, 0);
29314
29315 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29316 if (gpio_get_value(data->pdata->gpio_data) == 0) {
29317 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
29318 /* Only relevant if the interrupt hasn't occurred. */
29319 - if (!atomic_read(&data->interrupt_handled))
29320 + if (!atomic_read_unchecked(&data->interrupt_handled))
29321 schedule_work(&data->read_work);
29322 }
29323 ret = wait_event_timeout(data->wait_queue,
29324 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
29325
29326 /* First disable the interrupt */
29327 disable_irq_nosync(irq);
29328 - atomic_inc(&data->interrupt_handled);
29329 + atomic_inc_unchecked(&data->interrupt_handled);
29330 /* Then schedule a reading work struct */
29331 if (data->state != SHT15_READING_NOTHING)
29332 schedule_work(&data->read_work);
29333 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
29334 * If not, then start the interrupt again - care here as could
29335 * have gone low in meantime so verify it hasn't!
29336 */
29337 - atomic_set(&data->interrupt_handled, 0);
29338 + atomic_set_unchecked(&data->interrupt_handled, 0);
29339 enable_irq(gpio_to_irq(data->pdata->gpio_data));
29340 /* If still not occurred or another handler has been scheduled */
29341 if (gpio_get_value(data->pdata->gpio_data)
29342 - || atomic_read(&data->interrupt_handled))
29343 + || atomic_read_unchecked(&data->interrupt_handled))
29344 return;
29345 }
29346
29347 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
29348 index 378fcb5..5e91fa8 100644
29349 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
29350 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
29351 @@ -43,7 +43,7 @@
29352 extern struct i2c_adapter amd756_smbus;
29353
29354 static struct i2c_adapter *s4882_adapter;
29355 -static struct i2c_algorithm *s4882_algo;
29356 +static i2c_algorithm_no_const *s4882_algo;
29357
29358 /* Wrapper access functions for multiplexed SMBus */
29359 static DEFINE_MUTEX(amd756_lock);
29360 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
29361 index 29015eb..af2d8e9 100644
29362 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
29363 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
29364 @@ -41,7 +41,7 @@
29365 extern struct i2c_adapter *nforce2_smbus;
29366
29367 static struct i2c_adapter *s4985_adapter;
29368 -static struct i2c_algorithm *s4985_algo;
29369 +static i2c_algorithm_no_const *s4985_algo;
29370
29371 /* Wrapper access functions for multiplexed SMBus */
29372 static DEFINE_MUTEX(nforce2_lock);
29373 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
29374 index d7a4833..7fae376 100644
29375 --- a/drivers/i2c/i2c-mux.c
29376 +++ b/drivers/i2c/i2c-mux.c
29377 @@ -28,7 +28,7 @@
29378 /* multiplexer per channel data */
29379 struct i2c_mux_priv {
29380 struct i2c_adapter adap;
29381 - struct i2c_algorithm algo;
29382 + i2c_algorithm_no_const algo;
29383
29384 struct i2c_adapter *parent;
29385 void *mux_dev; /* the mux chip/device */
29386 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
29387 index 57d00ca..0145194 100644
29388 --- a/drivers/ide/aec62xx.c
29389 +++ b/drivers/ide/aec62xx.c
29390 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
29391 .cable_detect = atp86x_cable_detect,
29392 };
29393
29394 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
29395 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
29396 { /* 0: AEC6210 */
29397 .name = DRV_NAME,
29398 .init_chipset = init_chipset_aec62xx,
29399 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
29400 index 2c8016a..911a27c 100644
29401 --- a/drivers/ide/alim15x3.c
29402 +++ b/drivers/ide/alim15x3.c
29403 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
29404 .dma_sff_read_status = ide_dma_sff_read_status,
29405 };
29406
29407 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
29408 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
29409 .name = DRV_NAME,
29410 .init_chipset = init_chipset_ali15x3,
29411 .init_hwif = init_hwif_ali15x3,
29412 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
29413 index 3747b25..56fc995 100644
29414 --- a/drivers/ide/amd74xx.c
29415 +++ b/drivers/ide/amd74xx.c
29416 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
29417 .udma_mask = udma, \
29418 }
29419
29420 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
29421 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
29422 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
29423 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
29424 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
29425 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
29426 index 15f0ead..cb43480 100644
29427 --- a/drivers/ide/atiixp.c
29428 +++ b/drivers/ide/atiixp.c
29429 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
29430 .cable_detect = atiixp_cable_detect,
29431 };
29432
29433 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
29434 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
29435 { /* 0: IXP200/300/400/700 */
29436 .name = DRV_NAME,
29437 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
29438 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
29439 index 5f80312..d1fc438 100644
29440 --- a/drivers/ide/cmd64x.c
29441 +++ b/drivers/ide/cmd64x.c
29442 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
29443 .dma_sff_read_status = ide_dma_sff_read_status,
29444 };
29445
29446 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
29447 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
29448 { /* 0: CMD643 */
29449 .name = DRV_NAME,
29450 .init_chipset = init_chipset_cmd64x,
29451 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
29452 index 2c1e5f7..1444762 100644
29453 --- a/drivers/ide/cs5520.c
29454 +++ b/drivers/ide/cs5520.c
29455 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
29456 .set_dma_mode = cs5520_set_dma_mode,
29457 };
29458
29459 -static const struct ide_port_info cyrix_chipset __devinitdata = {
29460 +static const struct ide_port_info cyrix_chipset __devinitconst = {
29461 .name = DRV_NAME,
29462 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
29463 .port_ops = &cs5520_port_ops,
29464 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
29465 index 4dc4eb9..49b40ad 100644
29466 --- a/drivers/ide/cs5530.c
29467 +++ b/drivers/ide/cs5530.c
29468 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
29469 .udma_filter = cs5530_udma_filter,
29470 };
29471
29472 -static const struct ide_port_info cs5530_chipset __devinitdata = {
29473 +static const struct ide_port_info cs5530_chipset __devinitconst = {
29474 .name = DRV_NAME,
29475 .init_chipset = init_chipset_cs5530,
29476 .init_hwif = init_hwif_cs5530,
29477 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
29478 index 5059faf..18d4c85 100644
29479 --- a/drivers/ide/cs5535.c
29480 +++ b/drivers/ide/cs5535.c
29481 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
29482 .cable_detect = cs5535_cable_detect,
29483 };
29484
29485 -static const struct ide_port_info cs5535_chipset __devinitdata = {
29486 +static const struct ide_port_info cs5535_chipset __devinitconst = {
29487 .name = DRV_NAME,
29488 .port_ops = &cs5535_port_ops,
29489 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
29490 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
29491 index 847553f..3ffb49d 100644
29492 --- a/drivers/ide/cy82c693.c
29493 +++ b/drivers/ide/cy82c693.c
29494 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
29495 .set_dma_mode = cy82c693_set_dma_mode,
29496 };
29497
29498 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
29499 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
29500 .name = DRV_NAME,
29501 .init_iops = init_iops_cy82c693,
29502 .port_ops = &cy82c693_port_ops,
29503 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
29504 index 58c51cd..4aec3b8 100644
29505 --- a/drivers/ide/hpt366.c
29506 +++ b/drivers/ide/hpt366.c
29507 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
29508 }
29509 };
29510
29511 -static const struct hpt_info hpt36x __devinitdata = {
29512 +static const struct hpt_info hpt36x __devinitconst = {
29513 .chip_name = "HPT36x",
29514 .chip_type = HPT36x,
29515 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
29516 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
29517 .timings = &hpt36x_timings
29518 };
29519
29520 -static const struct hpt_info hpt370 __devinitdata = {
29521 +static const struct hpt_info hpt370 __devinitconst = {
29522 .chip_name = "HPT370",
29523 .chip_type = HPT370,
29524 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29525 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
29526 .timings = &hpt37x_timings
29527 };
29528
29529 -static const struct hpt_info hpt370a __devinitdata = {
29530 +static const struct hpt_info hpt370a __devinitconst = {
29531 .chip_name = "HPT370A",
29532 .chip_type = HPT370A,
29533 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
29534 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
29535 .timings = &hpt37x_timings
29536 };
29537
29538 -static const struct hpt_info hpt374 __devinitdata = {
29539 +static const struct hpt_info hpt374 __devinitconst = {
29540 .chip_name = "HPT374",
29541 .chip_type = HPT374,
29542 .udma_mask = ATA_UDMA5,
29543 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
29544 .timings = &hpt37x_timings
29545 };
29546
29547 -static const struct hpt_info hpt372 __devinitdata = {
29548 +static const struct hpt_info hpt372 __devinitconst = {
29549 .chip_name = "HPT372",
29550 .chip_type = HPT372,
29551 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29552 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
29553 .timings = &hpt37x_timings
29554 };
29555
29556 -static const struct hpt_info hpt372a __devinitdata = {
29557 +static const struct hpt_info hpt372a __devinitconst = {
29558 .chip_name = "HPT372A",
29559 .chip_type = HPT372A,
29560 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29561 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
29562 .timings = &hpt37x_timings
29563 };
29564
29565 -static const struct hpt_info hpt302 __devinitdata = {
29566 +static const struct hpt_info hpt302 __devinitconst = {
29567 .chip_name = "HPT302",
29568 .chip_type = HPT302,
29569 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29570 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
29571 .timings = &hpt37x_timings
29572 };
29573
29574 -static const struct hpt_info hpt371 __devinitdata = {
29575 +static const struct hpt_info hpt371 __devinitconst = {
29576 .chip_name = "HPT371",
29577 .chip_type = HPT371,
29578 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29579 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
29580 .timings = &hpt37x_timings
29581 };
29582
29583 -static const struct hpt_info hpt372n __devinitdata = {
29584 +static const struct hpt_info hpt372n __devinitconst = {
29585 .chip_name = "HPT372N",
29586 .chip_type = HPT372N,
29587 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29588 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
29589 .timings = &hpt37x_timings
29590 };
29591
29592 -static const struct hpt_info hpt302n __devinitdata = {
29593 +static const struct hpt_info hpt302n __devinitconst = {
29594 .chip_name = "HPT302N",
29595 .chip_type = HPT302N,
29596 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29597 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
29598 .timings = &hpt37x_timings
29599 };
29600
29601 -static const struct hpt_info hpt371n __devinitdata = {
29602 +static const struct hpt_info hpt371n __devinitconst = {
29603 .chip_name = "HPT371N",
29604 .chip_type = HPT371N,
29605 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
29606 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
29607 .dma_sff_read_status = ide_dma_sff_read_status,
29608 };
29609
29610 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
29611 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
29612 { /* 0: HPT36x */
29613 .name = DRV_NAME,
29614 .init_chipset = init_chipset_hpt366,
29615 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
29616 index 8126824..55a2798 100644
29617 --- a/drivers/ide/ide-cd.c
29618 +++ b/drivers/ide/ide-cd.c
29619 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
29620 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
29621 if ((unsigned long)buf & alignment
29622 || blk_rq_bytes(rq) & q->dma_pad_mask
29623 - || object_is_on_stack(buf))
29624 + || object_starts_on_stack(buf))
29625 drive->dma = 0;
29626 }
29627 }
29628 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
29629 index a743e68..1cfd674 100644
29630 --- a/drivers/ide/ide-pci-generic.c
29631 +++ b/drivers/ide/ide-pci-generic.c
29632 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
29633 .udma_mask = ATA_UDMA6, \
29634 }
29635
29636 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
29637 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
29638 /* 0: Unknown */
29639 DECLARE_GENERIC_PCI_DEV(0),
29640
29641 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
29642 index 560e66d..d5dd180 100644
29643 --- a/drivers/ide/it8172.c
29644 +++ b/drivers/ide/it8172.c
29645 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
29646 .set_dma_mode = it8172_set_dma_mode,
29647 };
29648
29649 -static const struct ide_port_info it8172_port_info __devinitdata = {
29650 +static const struct ide_port_info it8172_port_info __devinitconst = {
29651 .name = DRV_NAME,
29652 .port_ops = &it8172_port_ops,
29653 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
29654 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
29655 index 46816ba..1847aeb 100644
29656 --- a/drivers/ide/it8213.c
29657 +++ b/drivers/ide/it8213.c
29658 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
29659 .cable_detect = it8213_cable_detect,
29660 };
29661
29662 -static const struct ide_port_info it8213_chipset __devinitdata = {
29663 +static const struct ide_port_info it8213_chipset __devinitconst = {
29664 .name = DRV_NAME,
29665 .enablebits = { {0x41, 0x80, 0x80} },
29666 .port_ops = &it8213_port_ops,
29667 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
29668 index 2e3169f..c5611db 100644
29669 --- a/drivers/ide/it821x.c
29670 +++ b/drivers/ide/it821x.c
29671 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
29672 .cable_detect = it821x_cable_detect,
29673 };
29674
29675 -static const struct ide_port_info it821x_chipset __devinitdata = {
29676 +static const struct ide_port_info it821x_chipset __devinitconst = {
29677 .name = DRV_NAME,
29678 .init_chipset = init_chipset_it821x,
29679 .init_hwif = init_hwif_it821x,
29680 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
29681 index 74c2c4a..efddd7d 100644
29682 --- a/drivers/ide/jmicron.c
29683 +++ b/drivers/ide/jmicron.c
29684 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
29685 .cable_detect = jmicron_cable_detect,
29686 };
29687
29688 -static const struct ide_port_info jmicron_chipset __devinitdata = {
29689 +static const struct ide_port_info jmicron_chipset __devinitconst = {
29690 .name = DRV_NAME,
29691 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
29692 .port_ops = &jmicron_port_ops,
29693 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
29694 index 95327a2..73f78d8 100644
29695 --- a/drivers/ide/ns87415.c
29696 +++ b/drivers/ide/ns87415.c
29697 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
29698 .dma_sff_read_status = superio_dma_sff_read_status,
29699 };
29700
29701 -static const struct ide_port_info ns87415_chipset __devinitdata = {
29702 +static const struct ide_port_info ns87415_chipset __devinitconst = {
29703 .name = DRV_NAME,
29704 .init_hwif = init_hwif_ns87415,
29705 .tp_ops = &ns87415_tp_ops,
29706 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
29707 index 1a53a4c..39edc66 100644
29708 --- a/drivers/ide/opti621.c
29709 +++ b/drivers/ide/opti621.c
29710 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
29711 .set_pio_mode = opti621_set_pio_mode,
29712 };
29713
29714 -static const struct ide_port_info opti621_chipset __devinitdata = {
29715 +static const struct ide_port_info opti621_chipset __devinitconst = {
29716 .name = DRV_NAME,
29717 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
29718 .port_ops = &opti621_port_ops,
29719 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
29720 index 9546fe2..2e5ceb6 100644
29721 --- a/drivers/ide/pdc202xx_new.c
29722 +++ b/drivers/ide/pdc202xx_new.c
29723 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
29724 .udma_mask = udma, \
29725 }
29726
29727 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
29728 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
29729 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
29730 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
29731 };
29732 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
29733 index 3a35ec6..5634510 100644
29734 --- a/drivers/ide/pdc202xx_old.c
29735 +++ b/drivers/ide/pdc202xx_old.c
29736 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
29737 .max_sectors = sectors, \
29738 }
29739
29740 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
29741 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
29742 { /* 0: PDC20246 */
29743 .name = DRV_NAME,
29744 .init_chipset = init_chipset_pdc202xx,
29745 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
29746 index 1892e81..fe0fd60 100644
29747 --- a/drivers/ide/piix.c
29748 +++ b/drivers/ide/piix.c
29749 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
29750 .udma_mask = udma, \
29751 }
29752
29753 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
29754 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
29755 /* 0: MPIIX */
29756 { /*
29757 * MPIIX actually has only a single IDE channel mapped to
29758 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
29759 index a6414a8..c04173e 100644
29760 --- a/drivers/ide/rz1000.c
29761 +++ b/drivers/ide/rz1000.c
29762 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
29763 }
29764 }
29765
29766 -static const struct ide_port_info rz1000_chipset __devinitdata = {
29767 +static const struct ide_port_info rz1000_chipset __devinitconst = {
29768 .name = DRV_NAME,
29769 .host_flags = IDE_HFLAG_NO_DMA,
29770 };
29771 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
29772 index 356b9b5..d4758eb 100644
29773 --- a/drivers/ide/sc1200.c
29774 +++ b/drivers/ide/sc1200.c
29775 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
29776 .dma_sff_read_status = ide_dma_sff_read_status,
29777 };
29778
29779 -static const struct ide_port_info sc1200_chipset __devinitdata = {
29780 +static const struct ide_port_info sc1200_chipset __devinitconst = {
29781 .name = DRV_NAME,
29782 .port_ops = &sc1200_port_ops,
29783 .dma_ops = &sc1200_dma_ops,
29784 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
29785 index b7f5b0c..9701038 100644
29786 --- a/drivers/ide/scc_pata.c
29787 +++ b/drivers/ide/scc_pata.c
29788 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
29789 .dma_sff_read_status = scc_dma_sff_read_status,
29790 };
29791
29792 -static const struct ide_port_info scc_chipset __devinitdata = {
29793 +static const struct ide_port_info scc_chipset __devinitconst = {
29794 .name = "sccIDE",
29795 .init_iops = init_iops_scc,
29796 .init_dma = scc_init_dma,
29797 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
29798 index 35fb8da..24d72ef 100644
29799 --- a/drivers/ide/serverworks.c
29800 +++ b/drivers/ide/serverworks.c
29801 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
29802 .cable_detect = svwks_cable_detect,
29803 };
29804
29805 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
29806 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
29807 { /* 0: OSB4 */
29808 .name = DRV_NAME,
29809 .init_chipset = init_chipset_svwks,
29810 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
29811 index ddeda44..46f7e30 100644
29812 --- a/drivers/ide/siimage.c
29813 +++ b/drivers/ide/siimage.c
29814 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
29815 .udma_mask = ATA_UDMA6, \
29816 }
29817
29818 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
29819 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
29820 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
29821 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
29822 };
29823 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
29824 index 4a00225..09e61b4 100644
29825 --- a/drivers/ide/sis5513.c
29826 +++ b/drivers/ide/sis5513.c
29827 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
29828 .cable_detect = sis_cable_detect,
29829 };
29830
29831 -static const struct ide_port_info sis5513_chipset __devinitdata = {
29832 +static const struct ide_port_info sis5513_chipset __devinitconst = {
29833 .name = DRV_NAME,
29834 .init_chipset = init_chipset_sis5513,
29835 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
29836 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
29837 index f21dc2a..d051cd2 100644
29838 --- a/drivers/ide/sl82c105.c
29839 +++ b/drivers/ide/sl82c105.c
29840 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
29841 .dma_sff_read_status = ide_dma_sff_read_status,
29842 };
29843
29844 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
29845 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
29846 .name = DRV_NAME,
29847 .init_chipset = init_chipset_sl82c105,
29848 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
29849 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
29850 index 864ffe0..863a5e9 100644
29851 --- a/drivers/ide/slc90e66.c
29852 +++ b/drivers/ide/slc90e66.c
29853 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
29854 .cable_detect = slc90e66_cable_detect,
29855 };
29856
29857 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
29858 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
29859 .name = DRV_NAME,
29860 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
29861 .port_ops = &slc90e66_port_ops,
29862 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
29863 index 4799d5c..1794678 100644
29864 --- a/drivers/ide/tc86c001.c
29865 +++ b/drivers/ide/tc86c001.c
29866 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
29867 .dma_sff_read_status = ide_dma_sff_read_status,
29868 };
29869
29870 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
29871 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
29872 .name = DRV_NAME,
29873 .init_hwif = init_hwif_tc86c001,
29874 .port_ops = &tc86c001_port_ops,
29875 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
29876 index 281c914..55ce1b8 100644
29877 --- a/drivers/ide/triflex.c
29878 +++ b/drivers/ide/triflex.c
29879 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
29880 .set_dma_mode = triflex_set_mode,
29881 };
29882
29883 -static const struct ide_port_info triflex_device __devinitdata = {
29884 +static const struct ide_port_info triflex_device __devinitconst = {
29885 .name = DRV_NAME,
29886 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
29887 .port_ops = &triflex_port_ops,
29888 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
29889 index 4b42ca0..e494a98 100644
29890 --- a/drivers/ide/trm290.c
29891 +++ b/drivers/ide/trm290.c
29892 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
29893 .dma_check = trm290_dma_check,
29894 };
29895
29896 -static const struct ide_port_info trm290_chipset __devinitdata = {
29897 +static const struct ide_port_info trm290_chipset __devinitconst = {
29898 .name = DRV_NAME,
29899 .init_hwif = init_hwif_trm290,
29900 .tp_ops = &trm290_tp_ops,
29901 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
29902 index f46f49c..eb77678 100644
29903 --- a/drivers/ide/via82cxxx.c
29904 +++ b/drivers/ide/via82cxxx.c
29905 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
29906 .cable_detect = via82cxxx_cable_detect,
29907 };
29908
29909 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
29910 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
29911 .name = DRV_NAME,
29912 .init_chipset = init_chipset_via82cxxx,
29913 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
29914 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
29915 index eb0e2cc..14241c7 100644
29916 --- a/drivers/ieee802154/fakehard.c
29917 +++ b/drivers/ieee802154/fakehard.c
29918 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
29919 phy->transmit_power = 0xbf;
29920
29921 dev->netdev_ops = &fake_ops;
29922 - dev->ml_priv = &fake_mlme;
29923 + dev->ml_priv = (void *)&fake_mlme;
29924
29925 priv = netdev_priv(dev);
29926 priv->phy = phy;
29927 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
29928 index 8b72f39..55df4c8 100644
29929 --- a/drivers/infiniband/core/cm.c
29930 +++ b/drivers/infiniband/core/cm.c
29931 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
29932
29933 struct cm_counter_group {
29934 struct kobject obj;
29935 - atomic_long_t counter[CM_ATTR_COUNT];
29936 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
29937 };
29938
29939 struct cm_counter_attribute {
29940 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
29941 struct ib_mad_send_buf *msg = NULL;
29942 int ret;
29943
29944 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29945 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29946 counter[CM_REQ_COUNTER]);
29947
29948 /* Quick state check to discard duplicate REQs. */
29949 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
29950 if (!cm_id_priv)
29951 return;
29952
29953 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29954 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29955 counter[CM_REP_COUNTER]);
29956 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
29957 if (ret)
29958 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
29959 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
29960 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
29961 spin_unlock_irq(&cm_id_priv->lock);
29962 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29963 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29964 counter[CM_RTU_COUNTER]);
29965 goto out;
29966 }
29967 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
29968 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
29969 dreq_msg->local_comm_id);
29970 if (!cm_id_priv) {
29971 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29972 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29973 counter[CM_DREQ_COUNTER]);
29974 cm_issue_drep(work->port, work->mad_recv_wc);
29975 return -EINVAL;
29976 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
29977 case IB_CM_MRA_REP_RCVD:
29978 break;
29979 case IB_CM_TIMEWAIT:
29980 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29981 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29982 counter[CM_DREQ_COUNTER]);
29983 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
29984 goto unlock;
29985 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
29986 cm_free_msg(msg);
29987 goto deref;
29988 case IB_CM_DREQ_RCVD:
29989 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
29990 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
29991 counter[CM_DREQ_COUNTER]);
29992 goto unlock;
29993 default:
29994 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
29995 ib_modify_mad(cm_id_priv->av.port->mad_agent,
29996 cm_id_priv->msg, timeout)) {
29997 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
29998 - atomic_long_inc(&work->port->
29999 + atomic_long_inc_unchecked(&work->port->
30000 counter_group[CM_RECV_DUPLICATES].
30001 counter[CM_MRA_COUNTER]);
30002 goto out;
30003 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
30004 break;
30005 case IB_CM_MRA_REQ_RCVD:
30006 case IB_CM_MRA_REP_RCVD:
30007 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30008 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30009 counter[CM_MRA_COUNTER]);
30010 /* fall through */
30011 default:
30012 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
30013 case IB_CM_LAP_IDLE:
30014 break;
30015 case IB_CM_MRA_LAP_SENT:
30016 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30017 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30018 counter[CM_LAP_COUNTER]);
30019 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
30020 goto unlock;
30021 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
30022 cm_free_msg(msg);
30023 goto deref;
30024 case IB_CM_LAP_RCVD:
30025 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30026 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30027 counter[CM_LAP_COUNTER]);
30028 goto unlock;
30029 default:
30030 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
30031 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
30032 if (cur_cm_id_priv) {
30033 spin_unlock_irq(&cm.lock);
30034 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
30035 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
30036 counter[CM_SIDR_REQ_COUNTER]);
30037 goto out; /* Duplicate message. */
30038 }
30039 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
30040 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
30041 msg->retries = 1;
30042
30043 - atomic_long_add(1 + msg->retries,
30044 + atomic_long_add_unchecked(1 + msg->retries,
30045 &port->counter_group[CM_XMIT].counter[attr_index]);
30046 if (msg->retries)
30047 - atomic_long_add(msg->retries,
30048 + atomic_long_add_unchecked(msg->retries,
30049 &port->counter_group[CM_XMIT_RETRIES].
30050 counter[attr_index]);
30051
30052 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
30053 }
30054
30055 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
30056 - atomic_long_inc(&port->counter_group[CM_RECV].
30057 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
30058 counter[attr_id - CM_ATTR_ID_OFFSET]);
30059
30060 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
30061 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
30062 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
30063
30064 return sprintf(buf, "%ld\n",
30065 - atomic_long_read(&group->counter[cm_attr->index]));
30066 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
30067 }
30068
30069 static const struct sysfs_ops cm_counter_ops = {
30070 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
30071 index 176c8f9..2627b62 100644
30072 --- a/drivers/infiniband/core/fmr_pool.c
30073 +++ b/drivers/infiniband/core/fmr_pool.c
30074 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
30075
30076 struct task_struct *thread;
30077
30078 - atomic_t req_ser;
30079 - atomic_t flush_ser;
30080 + atomic_unchecked_t req_ser;
30081 + atomic_unchecked_t flush_ser;
30082
30083 wait_queue_head_t force_wait;
30084 };
30085 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
30086 struct ib_fmr_pool *pool = pool_ptr;
30087
30088 do {
30089 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
30090 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
30091 ib_fmr_batch_release(pool);
30092
30093 - atomic_inc(&pool->flush_ser);
30094 + atomic_inc_unchecked(&pool->flush_ser);
30095 wake_up_interruptible(&pool->force_wait);
30096
30097 if (pool->flush_function)
30098 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
30099 }
30100
30101 set_current_state(TASK_INTERRUPTIBLE);
30102 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
30103 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
30104 !kthread_should_stop())
30105 schedule();
30106 __set_current_state(TASK_RUNNING);
30107 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
30108 pool->dirty_watermark = params->dirty_watermark;
30109 pool->dirty_len = 0;
30110 spin_lock_init(&pool->pool_lock);
30111 - atomic_set(&pool->req_ser, 0);
30112 - atomic_set(&pool->flush_ser, 0);
30113 + atomic_set_unchecked(&pool->req_ser, 0);
30114 + atomic_set_unchecked(&pool->flush_ser, 0);
30115 init_waitqueue_head(&pool->force_wait);
30116
30117 pool->thread = kthread_run(ib_fmr_cleanup_thread,
30118 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
30119 }
30120 spin_unlock_irq(&pool->pool_lock);
30121
30122 - serial = atomic_inc_return(&pool->req_ser);
30123 + serial = atomic_inc_return_unchecked(&pool->req_ser);
30124 wake_up_process(pool->thread);
30125
30126 if (wait_event_interruptible(pool->force_wait,
30127 - atomic_read(&pool->flush_ser) - serial >= 0))
30128 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
30129 return -EINTR;
30130
30131 return 0;
30132 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
30133 } else {
30134 list_add_tail(&fmr->list, &pool->dirty_list);
30135 if (++pool->dirty_len >= pool->dirty_watermark) {
30136 - atomic_inc(&pool->req_ser);
30137 + atomic_inc_unchecked(&pool->req_ser);
30138 wake_up_process(pool->thread);
30139 }
30140 }
30141 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
30142 index 40c8353..946b0e4 100644
30143 --- a/drivers/infiniband/hw/cxgb4/mem.c
30144 +++ b/drivers/infiniband/hw/cxgb4/mem.c
30145 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30146 int err;
30147 struct fw_ri_tpte tpt;
30148 u32 stag_idx;
30149 - static atomic_t key;
30150 + static atomic_unchecked_t key;
30151
30152 if (c4iw_fatal_error(rdev))
30153 return -EIO;
30154 @@ -135,7 +135,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
30155 &rdev->resource.tpt_fifo_lock);
30156 if (!stag_idx)
30157 return -ENOMEM;
30158 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
30159 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
30160 }
30161 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
30162 __func__, stag_state, type, pdid, stag_idx);
30163 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
30164 index 79b3dbc..96e5fcc 100644
30165 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
30166 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
30167 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30168 struct ib_atomic_eth *ateth;
30169 struct ipath_ack_entry *e;
30170 u64 vaddr;
30171 - atomic64_t *maddr;
30172 + atomic64_unchecked_t *maddr;
30173 u64 sdata;
30174 u32 rkey;
30175 u8 next;
30176 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
30177 IB_ACCESS_REMOTE_ATOMIC)))
30178 goto nack_acc_unlck;
30179 /* Perform atomic OP and save result. */
30180 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30181 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30182 sdata = be64_to_cpu(ateth->swap_data);
30183 e = &qp->s_ack_queue[qp->r_head_ack_queue];
30184 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
30185 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30186 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30187 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30188 be64_to_cpu(ateth->compare_data),
30189 sdata);
30190 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
30191 index 1f95bba..9530f87 100644
30192 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
30193 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
30194 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
30195 unsigned long flags;
30196 struct ib_wc wc;
30197 u64 sdata;
30198 - atomic64_t *maddr;
30199 + atomic64_unchecked_t *maddr;
30200 enum ib_wc_status send_status;
30201
30202 /*
30203 @@ -382,11 +382,11 @@ again:
30204 IB_ACCESS_REMOTE_ATOMIC)))
30205 goto acc_err;
30206 /* Perform atomic OP and save result. */
30207 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
30208 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
30209 sdata = wqe->wr.wr.atomic.compare_add;
30210 *(u64 *) sqp->s_sge.sge.vaddr =
30211 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
30212 - (u64) atomic64_add_return(sdata, maddr) - sdata :
30213 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
30214 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
30215 sdata, wqe->wr.wr.atomic.swap);
30216 goto send_comp;
30217 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
30218 index 5965b3d..16817fb 100644
30219 --- a/drivers/infiniband/hw/nes/nes.c
30220 +++ b/drivers/infiniband/hw/nes/nes.c
30221 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
30222 LIST_HEAD(nes_adapter_list);
30223 static LIST_HEAD(nes_dev_list);
30224
30225 -atomic_t qps_destroyed;
30226 +atomic_unchecked_t qps_destroyed;
30227
30228 static unsigned int ee_flsh_adapter;
30229 static unsigned int sysfs_nonidx_addr;
30230 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
30231 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
30232 struct nes_adapter *nesadapter = nesdev->nesadapter;
30233
30234 - atomic_inc(&qps_destroyed);
30235 + atomic_inc_unchecked(&qps_destroyed);
30236
30237 /* Free the control structures */
30238
30239 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
30240 index 568b4f1..5ea3eff 100644
30241 --- a/drivers/infiniband/hw/nes/nes.h
30242 +++ b/drivers/infiniband/hw/nes/nes.h
30243 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
30244 extern unsigned int wqm_quanta;
30245 extern struct list_head nes_adapter_list;
30246
30247 -extern atomic_t cm_connects;
30248 -extern atomic_t cm_accepts;
30249 -extern atomic_t cm_disconnects;
30250 -extern atomic_t cm_closes;
30251 -extern atomic_t cm_connecteds;
30252 -extern atomic_t cm_connect_reqs;
30253 -extern atomic_t cm_rejects;
30254 -extern atomic_t mod_qp_timouts;
30255 -extern atomic_t qps_created;
30256 -extern atomic_t qps_destroyed;
30257 -extern atomic_t sw_qps_destroyed;
30258 +extern atomic_unchecked_t cm_connects;
30259 +extern atomic_unchecked_t cm_accepts;
30260 +extern atomic_unchecked_t cm_disconnects;
30261 +extern atomic_unchecked_t cm_closes;
30262 +extern atomic_unchecked_t cm_connecteds;
30263 +extern atomic_unchecked_t cm_connect_reqs;
30264 +extern atomic_unchecked_t cm_rejects;
30265 +extern atomic_unchecked_t mod_qp_timouts;
30266 +extern atomic_unchecked_t qps_created;
30267 +extern atomic_unchecked_t qps_destroyed;
30268 +extern atomic_unchecked_t sw_qps_destroyed;
30269 extern u32 mh_detected;
30270 extern u32 mh_pauses_sent;
30271 extern u32 cm_packets_sent;
30272 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
30273 extern u32 cm_packets_received;
30274 extern u32 cm_packets_dropped;
30275 extern u32 cm_packets_retrans;
30276 -extern atomic_t cm_listens_created;
30277 -extern atomic_t cm_listens_destroyed;
30278 +extern atomic_unchecked_t cm_listens_created;
30279 +extern atomic_unchecked_t cm_listens_destroyed;
30280 extern u32 cm_backlog_drops;
30281 -extern atomic_t cm_loopbacks;
30282 -extern atomic_t cm_nodes_created;
30283 -extern atomic_t cm_nodes_destroyed;
30284 -extern atomic_t cm_accel_dropped_pkts;
30285 -extern atomic_t cm_resets_recvd;
30286 -extern atomic_t pau_qps_created;
30287 -extern atomic_t pau_qps_destroyed;
30288 +extern atomic_unchecked_t cm_loopbacks;
30289 +extern atomic_unchecked_t cm_nodes_created;
30290 +extern atomic_unchecked_t cm_nodes_destroyed;
30291 +extern atomic_unchecked_t cm_accel_dropped_pkts;
30292 +extern atomic_unchecked_t cm_resets_recvd;
30293 +extern atomic_unchecked_t pau_qps_created;
30294 +extern atomic_unchecked_t pau_qps_destroyed;
30295
30296 extern u32 int_mod_timer_init;
30297 extern u32 int_mod_cq_depth_256;
30298 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
30299 index 0a52d72..0642f36 100644
30300 --- a/drivers/infiniband/hw/nes/nes_cm.c
30301 +++ b/drivers/infiniband/hw/nes/nes_cm.c
30302 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
30303 u32 cm_packets_retrans;
30304 u32 cm_packets_created;
30305 u32 cm_packets_received;
30306 -atomic_t cm_listens_created;
30307 -atomic_t cm_listens_destroyed;
30308 +atomic_unchecked_t cm_listens_created;
30309 +atomic_unchecked_t cm_listens_destroyed;
30310 u32 cm_backlog_drops;
30311 -atomic_t cm_loopbacks;
30312 -atomic_t cm_nodes_created;
30313 -atomic_t cm_nodes_destroyed;
30314 -atomic_t cm_accel_dropped_pkts;
30315 -atomic_t cm_resets_recvd;
30316 +atomic_unchecked_t cm_loopbacks;
30317 +atomic_unchecked_t cm_nodes_created;
30318 +atomic_unchecked_t cm_nodes_destroyed;
30319 +atomic_unchecked_t cm_accel_dropped_pkts;
30320 +atomic_unchecked_t cm_resets_recvd;
30321
30322 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
30323 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
30324 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
30325
30326 static struct nes_cm_core *g_cm_core;
30327
30328 -atomic_t cm_connects;
30329 -atomic_t cm_accepts;
30330 -atomic_t cm_disconnects;
30331 -atomic_t cm_closes;
30332 -atomic_t cm_connecteds;
30333 -atomic_t cm_connect_reqs;
30334 -atomic_t cm_rejects;
30335 +atomic_unchecked_t cm_connects;
30336 +atomic_unchecked_t cm_accepts;
30337 +atomic_unchecked_t cm_disconnects;
30338 +atomic_unchecked_t cm_closes;
30339 +atomic_unchecked_t cm_connecteds;
30340 +atomic_unchecked_t cm_connect_reqs;
30341 +atomic_unchecked_t cm_rejects;
30342
30343 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
30344 {
30345 @@ -1271,7 +1271,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
30346 kfree(listener);
30347 listener = NULL;
30348 ret = 0;
30349 - atomic_inc(&cm_listens_destroyed);
30350 + atomic_inc_unchecked(&cm_listens_destroyed);
30351 } else {
30352 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
30353 }
30354 @@ -1473,7 +1473,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
30355 cm_node->rem_mac);
30356
30357 add_hte_node(cm_core, cm_node);
30358 - atomic_inc(&cm_nodes_created);
30359 + atomic_inc_unchecked(&cm_nodes_created);
30360
30361 return cm_node;
30362 }
30363 @@ -1531,7 +1531,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
30364 }
30365
30366 atomic_dec(&cm_core->node_cnt);
30367 - atomic_inc(&cm_nodes_destroyed);
30368 + atomic_inc_unchecked(&cm_nodes_destroyed);
30369 nesqp = cm_node->nesqp;
30370 if (nesqp) {
30371 nesqp->cm_node = NULL;
30372 @@ -1595,7 +1595,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
30373
30374 static void drop_packet(struct sk_buff *skb)
30375 {
30376 - atomic_inc(&cm_accel_dropped_pkts);
30377 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30378 dev_kfree_skb_any(skb);
30379 }
30380
30381 @@ -1658,7 +1658,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
30382 {
30383
30384 int reset = 0; /* whether to send reset in case of err.. */
30385 - atomic_inc(&cm_resets_recvd);
30386 + atomic_inc_unchecked(&cm_resets_recvd);
30387 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
30388 " refcnt=%d\n", cm_node, cm_node->state,
30389 atomic_read(&cm_node->ref_count));
30390 @@ -2299,7 +2299,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
30391 rem_ref_cm_node(cm_node->cm_core, cm_node);
30392 return NULL;
30393 }
30394 - atomic_inc(&cm_loopbacks);
30395 + atomic_inc_unchecked(&cm_loopbacks);
30396 loopbackremotenode->loopbackpartner = cm_node;
30397 loopbackremotenode->tcp_cntxt.rcv_wscale =
30398 NES_CM_DEFAULT_RCV_WND_SCALE;
30399 @@ -2574,7 +2574,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
30400 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
30401 else {
30402 rem_ref_cm_node(cm_core, cm_node);
30403 - atomic_inc(&cm_accel_dropped_pkts);
30404 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
30405 dev_kfree_skb_any(skb);
30406 }
30407 break;
30408 @@ -2880,7 +2880,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30409
30410 if ((cm_id) && (cm_id->event_handler)) {
30411 if (issue_disconn) {
30412 - atomic_inc(&cm_disconnects);
30413 + atomic_inc_unchecked(&cm_disconnects);
30414 cm_event.event = IW_CM_EVENT_DISCONNECT;
30415 cm_event.status = disconn_status;
30416 cm_event.local_addr = cm_id->local_addr;
30417 @@ -2902,7 +2902,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
30418 }
30419
30420 if (issue_close) {
30421 - atomic_inc(&cm_closes);
30422 + atomic_inc_unchecked(&cm_closes);
30423 nes_disconnect(nesqp, 1);
30424
30425 cm_id->provider_data = nesqp;
30426 @@ -3038,7 +3038,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30427
30428 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
30429 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
30430 - atomic_inc(&cm_accepts);
30431 + atomic_inc_unchecked(&cm_accepts);
30432
30433 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
30434 netdev_refcnt_read(nesvnic->netdev));
30435 @@ -3240,7 +3240,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
30436 struct nes_cm_core *cm_core;
30437 u8 *start_buff;
30438
30439 - atomic_inc(&cm_rejects);
30440 + atomic_inc_unchecked(&cm_rejects);
30441 cm_node = (struct nes_cm_node *)cm_id->provider_data;
30442 loopback = cm_node->loopbackpartner;
30443 cm_core = cm_node->cm_core;
30444 @@ -3300,7 +3300,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
30445 ntohl(cm_id->local_addr.sin_addr.s_addr),
30446 ntohs(cm_id->local_addr.sin_port));
30447
30448 - atomic_inc(&cm_connects);
30449 + atomic_inc_unchecked(&cm_connects);
30450 nesqp->active_conn = 1;
30451
30452 /* cache the cm_id in the qp */
30453 @@ -3406,7 +3406,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
30454 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
30455 return err;
30456 }
30457 - atomic_inc(&cm_listens_created);
30458 + atomic_inc_unchecked(&cm_listens_created);
30459 }
30460
30461 cm_id->add_ref(cm_id);
30462 @@ -3507,7 +3507,7 @@ static void cm_event_connected(struct nes_cm_event *event)
30463
30464 if (nesqp->destroyed)
30465 return;
30466 - atomic_inc(&cm_connecteds);
30467 + atomic_inc_unchecked(&cm_connecteds);
30468 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
30469 " local port 0x%04X. jiffies = %lu.\n",
30470 nesqp->hwqp.qp_id,
30471 @@ -3694,7 +3694,7 @@ static void cm_event_reset(struct nes_cm_event *event)
30472
30473 cm_id->add_ref(cm_id);
30474 ret = cm_id->event_handler(cm_id, &cm_event);
30475 - atomic_inc(&cm_closes);
30476 + atomic_inc_unchecked(&cm_closes);
30477 cm_event.event = IW_CM_EVENT_CLOSE;
30478 cm_event.status = 0;
30479 cm_event.provider_data = cm_id->provider_data;
30480 @@ -3730,7 +3730,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
30481 return;
30482 cm_id = cm_node->cm_id;
30483
30484 - atomic_inc(&cm_connect_reqs);
30485 + atomic_inc_unchecked(&cm_connect_reqs);
30486 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30487 cm_node, cm_id, jiffies);
30488
30489 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
30490 return;
30491 cm_id = cm_node->cm_id;
30492
30493 - atomic_inc(&cm_connect_reqs);
30494 + atomic_inc_unchecked(&cm_connect_reqs);
30495 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
30496 cm_node, cm_id, jiffies);
30497
30498 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
30499 index b3b2a24..7bfaf1e 100644
30500 --- a/drivers/infiniband/hw/nes/nes_mgt.c
30501 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
30502 @@ -40,8 +40,8 @@
30503 #include "nes.h"
30504 #include "nes_mgt.h"
30505
30506 -atomic_t pau_qps_created;
30507 -atomic_t pau_qps_destroyed;
30508 +atomic_unchecked_t pau_qps_created;
30509 +atomic_unchecked_t pau_qps_destroyed;
30510
30511 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
30512 {
30513 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
30514 {
30515 struct sk_buff *skb;
30516 unsigned long flags;
30517 - atomic_inc(&pau_qps_destroyed);
30518 + atomic_inc_unchecked(&pau_qps_destroyed);
30519
30520 /* Free packets that have not yet been forwarded */
30521 /* Lock is acquired by skb_dequeue when removing the skb */
30522 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
30523 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
30524 skb_queue_head_init(&nesqp->pau_list);
30525 spin_lock_init(&nesqp->pau_lock);
30526 - atomic_inc(&pau_qps_created);
30527 + atomic_inc_unchecked(&pau_qps_created);
30528 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
30529 }
30530
30531 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
30532 index c00d2f3..8834298 100644
30533 --- a/drivers/infiniband/hw/nes/nes_nic.c
30534 +++ b/drivers/infiniband/hw/nes/nes_nic.c
30535 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
30536 target_stat_values[++index] = mh_detected;
30537 target_stat_values[++index] = mh_pauses_sent;
30538 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
30539 - target_stat_values[++index] = atomic_read(&cm_connects);
30540 - target_stat_values[++index] = atomic_read(&cm_accepts);
30541 - target_stat_values[++index] = atomic_read(&cm_disconnects);
30542 - target_stat_values[++index] = atomic_read(&cm_connecteds);
30543 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
30544 - target_stat_values[++index] = atomic_read(&cm_rejects);
30545 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
30546 - target_stat_values[++index] = atomic_read(&qps_created);
30547 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
30548 - target_stat_values[++index] = atomic_read(&qps_destroyed);
30549 - target_stat_values[++index] = atomic_read(&cm_closes);
30550 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
30551 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
30552 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
30553 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
30554 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
30555 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
30556 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
30557 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
30558 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
30559 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
30560 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
30561 target_stat_values[++index] = cm_packets_sent;
30562 target_stat_values[++index] = cm_packets_bounced;
30563 target_stat_values[++index] = cm_packets_created;
30564 target_stat_values[++index] = cm_packets_received;
30565 target_stat_values[++index] = cm_packets_dropped;
30566 target_stat_values[++index] = cm_packets_retrans;
30567 - target_stat_values[++index] = atomic_read(&cm_listens_created);
30568 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
30569 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
30570 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
30571 target_stat_values[++index] = cm_backlog_drops;
30572 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
30573 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
30574 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
30575 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
30576 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
30577 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
30578 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
30579 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
30580 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
30581 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
30582 target_stat_values[++index] = nesadapter->free_4kpbl;
30583 target_stat_values[++index] = nesadapter->free_256pbl;
30584 target_stat_values[++index] = int_mod_timer_init;
30585 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
30586 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
30587 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
30588 - target_stat_values[++index] = atomic_read(&pau_qps_created);
30589 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
30590 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
30591 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
30592 }
30593
30594 /**
30595 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
30596 index 5095bc4..41e8fff 100644
30597 --- a/drivers/infiniband/hw/nes/nes_verbs.c
30598 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
30599 @@ -46,9 +46,9 @@
30600
30601 #include <rdma/ib_umem.h>
30602
30603 -atomic_t mod_qp_timouts;
30604 -atomic_t qps_created;
30605 -atomic_t sw_qps_destroyed;
30606 +atomic_unchecked_t mod_qp_timouts;
30607 +atomic_unchecked_t qps_created;
30608 +atomic_unchecked_t sw_qps_destroyed;
30609
30610 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
30611
30612 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
30613 if (init_attr->create_flags)
30614 return ERR_PTR(-EINVAL);
30615
30616 - atomic_inc(&qps_created);
30617 + atomic_inc_unchecked(&qps_created);
30618 switch (init_attr->qp_type) {
30619 case IB_QPT_RC:
30620 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
30621 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
30622 struct iw_cm_event cm_event;
30623 int ret = 0;
30624
30625 - atomic_inc(&sw_qps_destroyed);
30626 + atomic_inc_unchecked(&sw_qps_destroyed);
30627 nesqp->destroyed = 1;
30628
30629 /* Blow away the connection if it exists. */
30630 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
30631 index b881bdc..c2e360c 100644
30632 --- a/drivers/infiniband/hw/qib/qib.h
30633 +++ b/drivers/infiniband/hw/qib/qib.h
30634 @@ -51,6 +51,7 @@
30635 #include <linux/completion.h>
30636 #include <linux/kref.h>
30637 #include <linux/sched.h>
30638 +#include <linux/slab.h>
30639
30640 #include "qib_common.h"
30641 #include "qib_verbs.h"
30642 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
30643 index c351aa4..e6967c2 100644
30644 --- a/drivers/input/gameport/gameport.c
30645 +++ b/drivers/input/gameport/gameport.c
30646 @@ -488,14 +488,14 @@ EXPORT_SYMBOL(gameport_set_phys);
30647 */
30648 static void gameport_init_port(struct gameport *gameport)
30649 {
30650 - static atomic_t gameport_no = ATOMIC_INIT(0);
30651 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
30652
30653 __module_get(THIS_MODULE);
30654
30655 mutex_init(&gameport->drv_mutex);
30656 device_initialize(&gameport->dev);
30657 dev_set_name(&gameport->dev, "gameport%lu",
30658 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
30659 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
30660 gameport->dev.bus = &gameport_bus;
30661 gameport->dev.release = gameport_release_port;
30662 if (gameport->parent)
30663 diff --git a/drivers/input/input.c b/drivers/input/input.c
30664 index da38d97..2aa0b79 100644
30665 --- a/drivers/input/input.c
30666 +++ b/drivers/input/input.c
30667 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
30668 */
30669 int input_register_device(struct input_dev *dev)
30670 {
30671 - static atomic_t input_no = ATOMIC_INIT(0);
30672 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
30673 struct input_handler *handler;
30674 const char *path;
30675 int error;
30676 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
30677 dev->setkeycode = input_default_setkeycode;
30678
30679 dev_set_name(&dev->dev, "input%ld",
30680 - (unsigned long) atomic_inc_return(&input_no) - 1);
30681 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
30682
30683 error = device_add(&dev->dev);
30684 if (error)
30685 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
30686 index b8d8611..7a4a04b 100644
30687 --- a/drivers/input/joystick/sidewinder.c
30688 +++ b/drivers/input/joystick/sidewinder.c
30689 @@ -30,6 +30,7 @@
30690 #include <linux/kernel.h>
30691 #include <linux/module.h>
30692 #include <linux/slab.h>
30693 +#include <linux/sched.h>
30694 #include <linux/init.h>
30695 #include <linux/input.h>
30696 #include <linux/gameport.h>
30697 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
30698 index d728875..844c89b 100644
30699 --- a/drivers/input/joystick/xpad.c
30700 +++ b/drivers/input/joystick/xpad.c
30701 @@ -710,7 +710,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
30702
30703 static int xpad_led_probe(struct usb_xpad *xpad)
30704 {
30705 - static atomic_t led_seq = ATOMIC_INIT(0);
30706 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
30707 long led_no;
30708 struct xpad_led *led;
30709 struct led_classdev *led_cdev;
30710 @@ -723,7 +723,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
30711 if (!led)
30712 return -ENOMEM;
30713
30714 - led_no = (long)atomic_inc_return(&led_seq) - 1;
30715 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
30716
30717 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
30718 led->xpad = xpad;
30719 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
30720 index 0110b5a..d3ad144 100644
30721 --- a/drivers/input/mousedev.c
30722 +++ b/drivers/input/mousedev.c
30723 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
30724
30725 spin_unlock_irq(&client->packet_lock);
30726
30727 - if (copy_to_user(buffer, data, count))
30728 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
30729 return -EFAULT;
30730
30731 return count;
30732 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
30733 index ba70058..571d25d 100644
30734 --- a/drivers/input/serio/serio.c
30735 +++ b/drivers/input/serio/serio.c
30736 @@ -497,7 +497,7 @@ static void serio_release_port(struct device *dev)
30737 */
30738 static void serio_init_port(struct serio *serio)
30739 {
30740 - static atomic_t serio_no = ATOMIC_INIT(0);
30741 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
30742
30743 __module_get(THIS_MODULE);
30744
30745 @@ -508,7 +508,7 @@ static void serio_init_port(struct serio *serio)
30746 mutex_init(&serio->drv_mutex);
30747 device_initialize(&serio->dev);
30748 dev_set_name(&serio->dev, "serio%ld",
30749 - (long)atomic_inc_return(&serio_no) - 1);
30750 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
30751 serio->dev.bus = &serio_bus;
30752 serio->dev.release = serio_release_port;
30753 serio->dev.groups = serio_device_attr_groups;
30754 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
30755 index e44933d..9ba484a 100644
30756 --- a/drivers/isdn/capi/capi.c
30757 +++ b/drivers/isdn/capi/capi.c
30758 @@ -83,8 +83,8 @@ struct capiminor {
30759
30760 struct capi20_appl *ap;
30761 u32 ncci;
30762 - atomic_t datahandle;
30763 - atomic_t msgid;
30764 + atomic_unchecked_t datahandle;
30765 + atomic_unchecked_t msgid;
30766
30767 struct tty_port port;
30768 int ttyinstop;
30769 @@ -397,7 +397,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
30770 capimsg_setu16(s, 2, mp->ap->applid);
30771 capimsg_setu8 (s, 4, CAPI_DATA_B3);
30772 capimsg_setu8 (s, 5, CAPI_RESP);
30773 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
30774 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
30775 capimsg_setu32(s, 8, mp->ncci);
30776 capimsg_setu16(s, 12, datahandle);
30777 }
30778 @@ -518,14 +518,14 @@ static void handle_minor_send(struct capiminor *mp)
30779 mp->outbytes -= len;
30780 spin_unlock_bh(&mp->outlock);
30781
30782 - datahandle = atomic_inc_return(&mp->datahandle);
30783 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
30784 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
30785 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30786 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
30787 capimsg_setu16(skb->data, 2, mp->ap->applid);
30788 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
30789 capimsg_setu8 (skb->data, 5, CAPI_REQ);
30790 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
30791 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
30792 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
30793 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
30794 capimsg_setu16(skb->data, 16, len); /* Data length */
30795 diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
30796 index db621db..825ea1a 100644
30797 --- a/drivers/isdn/gigaset/common.c
30798 +++ b/drivers/isdn/gigaset/common.c
30799 @@ -723,7 +723,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
30800 cs->commands_pending = 0;
30801 cs->cur_at_seq = 0;
30802 cs->gotfwver = -1;
30803 - cs->open_count = 0;
30804 + local_set(&cs->open_count, 0);
30805 cs->dev = NULL;
30806 cs->tty = NULL;
30807 cs->tty_dev = NULL;
30808 diff --git a/drivers/isdn/gigaset/gigaset.h b/drivers/isdn/gigaset/gigaset.h
30809 index 212efaf..f187c6b 100644
30810 --- a/drivers/isdn/gigaset/gigaset.h
30811 +++ b/drivers/isdn/gigaset/gigaset.h
30812 @@ -35,6 +35,7 @@
30813 #include <linux/tty_driver.h>
30814 #include <linux/list.h>
30815 #include <linux/atomic.h>
30816 +#include <asm/local.h>
30817
30818 #define GIG_VERSION {0, 5, 0, 0}
30819 #define GIG_COMPAT {0, 4, 0, 0}
30820 @@ -433,7 +434,7 @@ struct cardstate {
30821 spinlock_t cmdlock;
30822 unsigned curlen, cmdbytes;
30823
30824 - unsigned open_count;
30825 + local_t open_count;
30826 struct tty_struct *tty;
30827 struct tasklet_struct if_wake_tasklet;
30828 unsigned control_state;
30829 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
30830 index ee0a549..a7c9798 100644
30831 --- a/drivers/isdn/gigaset/interface.c
30832 +++ b/drivers/isdn/gigaset/interface.c
30833 @@ -163,9 +163,7 @@ static int if_open(struct tty_struct *tty, struct file *filp)
30834 }
30835 tty->driver_data = cs;
30836
30837 - ++cs->open_count;
30838 -
30839 - if (cs->open_count == 1) {
30840 + if (local_inc_return(&cs->open_count) == 1) {
30841 spin_lock_irqsave(&cs->lock, flags);
30842 cs->tty = tty;
30843 spin_unlock_irqrestore(&cs->lock, flags);
30844 @@ -193,10 +191,10 @@ static void if_close(struct tty_struct *tty, struct file *filp)
30845
30846 if (!cs->connected)
30847 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30848 - else if (!cs->open_count)
30849 + else if (!local_read(&cs->open_count))
30850 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30851 else {
30852 - if (!--cs->open_count) {
30853 + if (!local_dec_return(&cs->open_count)) {
30854 spin_lock_irqsave(&cs->lock, flags);
30855 cs->tty = NULL;
30856 spin_unlock_irqrestore(&cs->lock, flags);
30857 @@ -231,7 +229,7 @@ static int if_ioctl(struct tty_struct *tty,
30858 if (!cs->connected) {
30859 gig_dbg(DEBUG_IF, "not connected");
30860 retval = -ENODEV;
30861 - } else if (!cs->open_count)
30862 + } else if (!local_read(&cs->open_count))
30863 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30864 else {
30865 retval = 0;
30866 @@ -361,7 +359,7 @@ static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
30867 retval = -ENODEV;
30868 goto done;
30869 }
30870 - if (!cs->open_count) {
30871 + if (!local_read(&cs->open_count)) {
30872 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30873 retval = -ENODEV;
30874 goto done;
30875 @@ -414,7 +412,7 @@ static int if_write_room(struct tty_struct *tty)
30876 if (!cs->connected) {
30877 gig_dbg(DEBUG_IF, "not connected");
30878 retval = -ENODEV;
30879 - } else if (!cs->open_count)
30880 + } else if (!local_read(&cs->open_count))
30881 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30882 else if (cs->mstate != MS_LOCKED) {
30883 dev_warn(cs->dev, "can't write to unlocked device\n");
30884 @@ -444,7 +442,7 @@ static int if_chars_in_buffer(struct tty_struct *tty)
30885
30886 if (!cs->connected)
30887 gig_dbg(DEBUG_IF, "not connected");
30888 - else if (!cs->open_count)
30889 + else if (!local_read(&cs->open_count))
30890 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30891 else if (cs->mstate != MS_LOCKED)
30892 dev_warn(cs->dev, "can't write to unlocked device\n");
30893 @@ -472,7 +470,7 @@ static void if_throttle(struct tty_struct *tty)
30894
30895 if (!cs->connected)
30896 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30897 - else if (!cs->open_count)
30898 + else if (!local_read(&cs->open_count))
30899 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30900 else
30901 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30902 @@ -496,7 +494,7 @@ static void if_unthrottle(struct tty_struct *tty)
30903
30904 if (!cs->connected)
30905 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
30906 - else if (!cs->open_count)
30907 + else if (!local_read(&cs->open_count))
30908 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30909 else
30910 gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
30911 @@ -527,7 +525,7 @@ static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
30912 goto out;
30913 }
30914
30915 - if (!cs->open_count) {
30916 + if (!local_read(&cs->open_count)) {
30917 dev_warn(cs->dev, "%s: device not opened\n", __func__);
30918 goto out;
30919 }
30920 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
30921 index 2a57da59..e7a12ed 100644
30922 --- a/drivers/isdn/hardware/avm/b1.c
30923 +++ b/drivers/isdn/hardware/avm/b1.c
30924 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart * t4file)
30925 }
30926 if (left) {
30927 if (t4file->user) {
30928 - if (copy_from_user(buf, dp, left))
30929 + if (left > sizeof buf || copy_from_user(buf, dp, left))
30930 return -EFAULT;
30931 } else {
30932 memcpy(buf, dp, left);
30933 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart * config)
30934 }
30935 if (left) {
30936 if (config->user) {
30937 - if (copy_from_user(buf, dp, left))
30938 + if (left > sizeof buf || copy_from_user(buf, dp, left))
30939 return -EFAULT;
30940 } else {
30941 memcpy(buf, dp, left);
30942 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
30943 index 85784a7..a19ca98 100644
30944 --- a/drivers/isdn/hardware/eicon/divasync.h
30945 +++ b/drivers/isdn/hardware/eicon/divasync.h
30946 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
30947 } diva_didd_add_adapter_t;
30948 typedef struct _diva_didd_remove_adapter {
30949 IDI_CALL p_request;
30950 -} diva_didd_remove_adapter_t;
30951 +} __no_const diva_didd_remove_adapter_t;
30952 typedef struct _diva_didd_read_adapter_array {
30953 void * buffer;
30954 dword length;
30955 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
30956 index a3bd163..8956575 100644
30957 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
30958 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
30959 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
30960 typedef struct _diva_os_idi_adapter_interface {
30961 diva_init_card_proc_t cleanup_adapter_proc;
30962 diva_cmd_card_proc_t cmd_proc;
30963 -} diva_os_idi_adapter_interface_t;
30964 +} __no_const diva_os_idi_adapter_interface_t;
30965
30966 typedef struct _diva_os_xdi_adapter {
30967 struct list_head link;
30968 diff --git a/drivers/isdn/i4l/isdn_net.c b/drivers/isdn/i4l/isdn_net.c
30969 index 2339d73..802ab87 100644
30970 --- a/drivers/isdn/i4l/isdn_net.c
30971 +++ b/drivers/isdn/i4l/isdn_net.c
30972 @@ -1901,7 +1901,7 @@ static int isdn_net_header(struct sk_buff *skb, struct net_device *dev,
30973 {
30974 isdn_net_local *lp = netdev_priv(dev);
30975 unsigned char *p;
30976 - ushort len = 0;
30977 + int len = 0;
30978
30979 switch (lp->p_encap) {
30980 case ISDN_NET_ENCAP_ETHER:
30981 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
30982 index 1f355bb..43f1fea 100644
30983 --- a/drivers/isdn/icn/icn.c
30984 +++ b/drivers/isdn/icn/icn.c
30985 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char * buf, int len, int user, icn_card * card)
30986 if (count > len)
30987 count = len;
30988 if (user) {
30989 - if (copy_from_user(msg, buf, count))
30990 + if (count > sizeof msg || copy_from_user(msg, buf, count))
30991 return -EFAULT;
30992 } else
30993 memcpy(msg, buf, count);
30994 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
30995 index b5fdcb7..5b6c59f 100644
30996 --- a/drivers/lguest/core.c
30997 +++ b/drivers/lguest/core.c
30998 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
30999 * it's worked so far. The end address needs +1 because __get_vm_area
31000 * allocates an extra guard page, so we need space for that.
31001 */
31002 +
31003 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31004 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31005 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
31006 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31007 +#else
31008 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
31009 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
31010 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
31011 +#endif
31012 +
31013 if (!switcher_vma) {
31014 err = -ENOMEM;
31015 printk("lguest: could not map switcher pages high\n");
31016 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
31017 * Now the Switcher is mapped at the right address, we can't fail!
31018 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
31019 */
31020 - memcpy(switcher_vma->addr, start_switcher_text,
31021 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
31022 end_switcher_text - start_switcher_text);
31023
31024 printk(KERN_INFO "lguest: mapped switcher at %p\n",
31025 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
31026 index 65af42f..530c87a 100644
31027 --- a/drivers/lguest/x86/core.c
31028 +++ b/drivers/lguest/x86/core.c
31029 @@ -59,7 +59,7 @@ static struct {
31030 /* Offset from where switcher.S was compiled to where we've copied it */
31031 static unsigned long switcher_offset(void)
31032 {
31033 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
31034 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
31035 }
31036
31037 /* This cpu's struct lguest_pages. */
31038 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
31039 * These copies are pretty cheap, so we do them unconditionally: */
31040 /* Save the current Host top-level page directory.
31041 */
31042 +
31043 +#ifdef CONFIG_PAX_PER_CPU_PGD
31044 + pages->state.host_cr3 = read_cr3();
31045 +#else
31046 pages->state.host_cr3 = __pa(current->mm->pgd);
31047 +#endif
31048 +
31049 /*
31050 * Set up the Guest's page tables to see this CPU's pages (and no
31051 * other CPU's pages).
31052 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
31053 * compiled-in switcher code and the high-mapped copy we just made.
31054 */
31055 for (i = 0; i < IDT_ENTRIES; i++)
31056 - default_idt_entries[i] += switcher_offset();
31057 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
31058
31059 /*
31060 * Set up the Switcher's per-cpu areas.
31061 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
31062 * it will be undisturbed when we switch. To change %cs and jump we
31063 * need this structure to feed to Intel's "lcall" instruction.
31064 */
31065 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
31066 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
31067 lguest_entry.segment = LGUEST_CS;
31068
31069 /*
31070 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
31071 index 40634b0..4f5855e 100644
31072 --- a/drivers/lguest/x86/switcher_32.S
31073 +++ b/drivers/lguest/x86/switcher_32.S
31074 @@ -87,6 +87,7 @@
31075 #include <asm/page.h>
31076 #include <asm/segment.h>
31077 #include <asm/lguest.h>
31078 +#include <asm/processor-flags.h>
31079
31080 // We mark the start of the code to copy
31081 // It's placed in .text tho it's never run here
31082 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
31083 // Changes type when we load it: damn Intel!
31084 // For after we switch over our page tables
31085 // That entry will be read-only: we'd crash.
31086 +
31087 +#ifdef CONFIG_PAX_KERNEXEC
31088 + mov %cr0, %edx
31089 + xor $X86_CR0_WP, %edx
31090 + mov %edx, %cr0
31091 +#endif
31092 +
31093 movl $(GDT_ENTRY_TSS*8), %edx
31094 ltr %dx
31095
31096 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
31097 // Let's clear it again for our return.
31098 // The GDT descriptor of the Host
31099 // Points to the table after two "size" bytes
31100 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
31101 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
31102 // Clear "used" from type field (byte 5, bit 2)
31103 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
31104 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
31105 +
31106 +#ifdef CONFIG_PAX_KERNEXEC
31107 + mov %cr0, %eax
31108 + xor $X86_CR0_WP, %eax
31109 + mov %eax, %cr0
31110 +#endif
31111
31112 // Once our page table's switched, the Guest is live!
31113 // The Host fades as we run this final step.
31114 @@ -295,13 +309,12 @@ deliver_to_host:
31115 // I consulted gcc, and it gave
31116 // These instructions, which I gladly credit:
31117 leal (%edx,%ebx,8), %eax
31118 - movzwl (%eax),%edx
31119 - movl 4(%eax), %eax
31120 - xorw %ax, %ax
31121 - orl %eax, %edx
31122 + movl 4(%eax), %edx
31123 + movw (%eax), %dx
31124 // Now the address of the handler's in %edx
31125 // We call it now: its "iret" drops us home.
31126 - jmp *%edx
31127 + ljmp $__KERNEL_CS, $1f
31128 +1: jmp *%edx
31129
31130 // Every interrupt can come to us here
31131 // But we must truly tell each apart.
31132 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
31133 index 4daf9e5..b8d1d0f 100644
31134 --- a/drivers/macintosh/macio_asic.c
31135 +++ b/drivers/macintosh/macio_asic.c
31136 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
31137 * MacIO is matched against any Apple ID, it's probe() function
31138 * will then decide wether it applies or not
31139 */
31140 -static const struct pci_device_id __devinitdata pci_ids [] = { {
31141 +static const struct pci_device_id __devinitconst pci_ids [] = { {
31142 .vendor = PCI_VENDOR_ID_APPLE,
31143 .device = PCI_ANY_ID,
31144 .subvendor = PCI_ANY_ID,
31145 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
31146 index 31c2dc2..a2de7a6 100644
31147 --- a/drivers/md/dm-ioctl.c
31148 +++ b/drivers/md/dm-ioctl.c
31149 @@ -1589,7 +1589,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
31150 cmd == DM_LIST_VERSIONS_CMD)
31151 return 0;
31152
31153 - if ((cmd == DM_DEV_CREATE_CMD)) {
31154 + if (cmd == DM_DEV_CREATE_CMD) {
31155 if (!*param->name) {
31156 DMWARN("name not supplied when creating device");
31157 return -EINVAL;
31158 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
31159 index 9bfd057..01180bc 100644
31160 --- a/drivers/md/dm-raid1.c
31161 +++ b/drivers/md/dm-raid1.c
31162 @@ -40,7 +40,7 @@ enum dm_raid1_error {
31163
31164 struct mirror {
31165 struct mirror_set *ms;
31166 - atomic_t error_count;
31167 + atomic_unchecked_t error_count;
31168 unsigned long error_type;
31169 struct dm_dev *dev;
31170 sector_t offset;
31171 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
31172 struct mirror *m;
31173
31174 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
31175 - if (!atomic_read(&m->error_count))
31176 + if (!atomic_read_unchecked(&m->error_count))
31177 return m;
31178
31179 return NULL;
31180 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
31181 * simple way to tell if a device has encountered
31182 * errors.
31183 */
31184 - atomic_inc(&m->error_count);
31185 + atomic_inc_unchecked(&m->error_count);
31186
31187 if (test_and_set_bit(error_type, &m->error_type))
31188 return;
31189 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
31190 struct mirror *m = get_default_mirror(ms);
31191
31192 do {
31193 - if (likely(!atomic_read(&m->error_count)))
31194 + if (likely(!atomic_read_unchecked(&m->error_count)))
31195 return m;
31196
31197 if (m-- == ms->mirror)
31198 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
31199 {
31200 struct mirror *default_mirror = get_default_mirror(m->ms);
31201
31202 - return !atomic_read(&default_mirror->error_count);
31203 + return !atomic_read_unchecked(&default_mirror->error_count);
31204 }
31205
31206 static int mirror_available(struct mirror_set *ms, struct bio *bio)
31207 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
31208 */
31209 if (likely(region_in_sync(ms, region, 1)))
31210 m = choose_mirror(ms, bio->bi_sector);
31211 - else if (m && atomic_read(&m->error_count))
31212 + else if (m && atomic_read_unchecked(&m->error_count))
31213 m = NULL;
31214
31215 if (likely(m))
31216 @@ -937,7 +937,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
31217 }
31218
31219 ms->mirror[mirror].ms = ms;
31220 - atomic_set(&(ms->mirror[mirror].error_count), 0);
31221 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
31222 ms->mirror[mirror].error_type = 0;
31223 ms->mirror[mirror].offset = offset;
31224
31225 @@ -1347,7 +1347,7 @@ static void mirror_resume(struct dm_target *ti)
31226 */
31227 static char device_status_char(struct mirror *m)
31228 {
31229 - if (!atomic_read(&(m->error_count)))
31230 + if (!atomic_read_unchecked(&(m->error_count)))
31231 return 'A';
31232
31233 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
31234 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
31235 index 3d80cf0..b77cc47 100644
31236 --- a/drivers/md/dm-stripe.c
31237 +++ b/drivers/md/dm-stripe.c
31238 @@ -20,7 +20,7 @@ struct stripe {
31239 struct dm_dev *dev;
31240 sector_t physical_start;
31241
31242 - atomic_t error_count;
31243 + atomic_unchecked_t error_count;
31244 };
31245
31246 struct stripe_c {
31247 @@ -192,7 +192,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
31248 kfree(sc);
31249 return r;
31250 }
31251 - atomic_set(&(sc->stripe[i].error_count), 0);
31252 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
31253 }
31254
31255 ti->private = sc;
31256 @@ -314,7 +314,7 @@ static int stripe_status(struct dm_target *ti,
31257 DMEMIT("%d ", sc->stripes);
31258 for (i = 0; i < sc->stripes; i++) {
31259 DMEMIT("%s ", sc->stripe[i].dev->name);
31260 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
31261 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
31262 'D' : 'A';
31263 }
31264 buffer[i] = '\0';
31265 @@ -361,8 +361,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
31266 */
31267 for (i = 0; i < sc->stripes; i++)
31268 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
31269 - atomic_inc(&(sc->stripe[i].error_count));
31270 - if (atomic_read(&(sc->stripe[i].error_count)) <
31271 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
31272 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
31273 DM_IO_ERROR_THRESHOLD)
31274 schedule_work(&sc->trigger_event);
31275 }
31276 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
31277 index 8e91321..fd17aef 100644
31278 --- a/drivers/md/dm-table.c
31279 +++ b/drivers/md/dm-table.c
31280 @@ -391,7 +391,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
31281 if (!dev_size)
31282 return 0;
31283
31284 - if ((start >= dev_size) || (start + len > dev_size)) {
31285 + if ((start >= dev_size) || (len > dev_size - start)) {
31286 DMWARN("%s: %s too small for target: "
31287 "start=%llu, len=%llu, dev_size=%llu",
31288 dm_device_name(ti->table->md), bdevname(bdev, b),
31289 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
31290 index 59c4f04..4c7b661 100644
31291 --- a/drivers/md/dm-thin-metadata.c
31292 +++ b/drivers/md/dm-thin-metadata.c
31293 @@ -431,7 +431,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
31294
31295 pmd->info.tm = tm;
31296 pmd->info.levels = 2;
31297 - pmd->info.value_type.context = pmd->data_sm;
31298 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
31299 pmd->info.value_type.size = sizeof(__le64);
31300 pmd->info.value_type.inc = data_block_inc;
31301 pmd->info.value_type.dec = data_block_dec;
31302 @@ -450,7 +450,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
31303
31304 pmd->bl_info.tm = tm;
31305 pmd->bl_info.levels = 1;
31306 - pmd->bl_info.value_type.context = pmd->data_sm;
31307 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
31308 pmd->bl_info.value_type.size = sizeof(__le64);
31309 pmd->bl_info.value_type.inc = data_block_inc;
31310 pmd->bl_info.value_type.dec = data_block_dec;
31311 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
31312 index 4720f68..78d1df7 100644
31313 --- a/drivers/md/dm.c
31314 +++ b/drivers/md/dm.c
31315 @@ -177,9 +177,9 @@ struct mapped_device {
31316 /*
31317 * Event handling.
31318 */
31319 - atomic_t event_nr;
31320 + atomic_unchecked_t event_nr;
31321 wait_queue_head_t eventq;
31322 - atomic_t uevent_seq;
31323 + atomic_unchecked_t uevent_seq;
31324 struct list_head uevent_list;
31325 spinlock_t uevent_lock; /* Protect access to uevent_list */
31326
31327 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
31328 rwlock_init(&md->map_lock);
31329 atomic_set(&md->holders, 1);
31330 atomic_set(&md->open_count, 0);
31331 - atomic_set(&md->event_nr, 0);
31332 - atomic_set(&md->uevent_seq, 0);
31333 + atomic_set_unchecked(&md->event_nr, 0);
31334 + atomic_set_unchecked(&md->uevent_seq, 0);
31335 INIT_LIST_HEAD(&md->uevent_list);
31336 spin_lock_init(&md->uevent_lock);
31337
31338 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
31339
31340 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
31341
31342 - atomic_inc(&md->event_nr);
31343 + atomic_inc_unchecked(&md->event_nr);
31344 wake_up(&md->eventq);
31345 }
31346
31347 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
31348
31349 uint32_t dm_next_uevent_seq(struct mapped_device *md)
31350 {
31351 - return atomic_add_return(1, &md->uevent_seq);
31352 + return atomic_add_return_unchecked(1, &md->uevent_seq);
31353 }
31354
31355 uint32_t dm_get_event_nr(struct mapped_device *md)
31356 {
31357 - return atomic_read(&md->event_nr);
31358 + return atomic_read_unchecked(&md->event_nr);
31359 }
31360
31361 int dm_wait_event(struct mapped_device *md, int event_nr)
31362 {
31363 return wait_event_interruptible(md->eventq,
31364 - (event_nr != atomic_read(&md->event_nr)));
31365 + (event_nr != atomic_read_unchecked(&md->event_nr)));
31366 }
31367
31368 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
31369 diff --git a/drivers/md/md.c b/drivers/md/md.c
31370 index f47f1f8..b7f559e 100644
31371 --- a/drivers/md/md.c
31372 +++ b/drivers/md/md.c
31373 @@ -278,10 +278,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
31374 * start build, activate spare
31375 */
31376 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
31377 -static atomic_t md_event_count;
31378 +static atomic_unchecked_t md_event_count;
31379 void md_new_event(struct mddev *mddev)
31380 {
31381 - atomic_inc(&md_event_count);
31382 + atomic_inc_unchecked(&md_event_count);
31383 wake_up(&md_event_waiters);
31384 }
31385 EXPORT_SYMBOL_GPL(md_new_event);
31386 @@ -291,7 +291,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
31387 */
31388 static void md_new_event_inintr(struct mddev *mddev)
31389 {
31390 - atomic_inc(&md_event_count);
31391 + atomic_inc_unchecked(&md_event_count);
31392 wake_up(&md_event_waiters);
31393 }
31394
31395 @@ -1525,7 +1525,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
31396
31397 rdev->preferred_minor = 0xffff;
31398 rdev->data_offset = le64_to_cpu(sb->data_offset);
31399 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31400 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
31401
31402 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
31403 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
31404 @@ -1742,7 +1742,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
31405 else
31406 sb->resync_offset = cpu_to_le64(0);
31407
31408 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
31409 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
31410
31411 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
31412 sb->size = cpu_to_le64(mddev->dev_sectors);
31413 @@ -2639,7 +2639,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
31414 static ssize_t
31415 errors_show(struct md_rdev *rdev, char *page)
31416 {
31417 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
31418 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
31419 }
31420
31421 static ssize_t
31422 @@ -2648,7 +2648,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
31423 char *e;
31424 unsigned long n = simple_strtoul(buf, &e, 10);
31425 if (*buf && (*e == 0 || *e == '\n')) {
31426 - atomic_set(&rdev->corrected_errors, n);
31427 + atomic_set_unchecked(&rdev->corrected_errors, n);
31428 return len;
31429 }
31430 return -EINVAL;
31431 @@ -3039,8 +3039,8 @@ int md_rdev_init(struct md_rdev *rdev)
31432 rdev->sb_loaded = 0;
31433 rdev->bb_page = NULL;
31434 atomic_set(&rdev->nr_pending, 0);
31435 - atomic_set(&rdev->read_errors, 0);
31436 - atomic_set(&rdev->corrected_errors, 0);
31437 + atomic_set_unchecked(&rdev->read_errors, 0);
31438 + atomic_set_unchecked(&rdev->corrected_errors, 0);
31439
31440 INIT_LIST_HEAD(&rdev->same_set);
31441 init_waitqueue_head(&rdev->blocked_wait);
31442 @@ -6683,7 +6683,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31443
31444 spin_unlock(&pers_lock);
31445 seq_printf(seq, "\n");
31446 - seq->poll_event = atomic_read(&md_event_count);
31447 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31448 return 0;
31449 }
31450 if (v == (void*)2) {
31451 @@ -6772,7 +6772,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
31452 chunk_kb ? "KB" : "B");
31453 if (bitmap->file) {
31454 seq_printf(seq, ", file: ");
31455 - seq_path(seq, &bitmap->file->f_path, " \t\n");
31456 + seq_path(seq, &bitmap->file->f_path, " \t\n\\");
31457 }
31458
31459 seq_printf(seq, "\n");
31460 @@ -6803,7 +6803,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
31461 return error;
31462
31463 seq = file->private_data;
31464 - seq->poll_event = atomic_read(&md_event_count);
31465 + seq->poll_event = atomic_read_unchecked(&md_event_count);
31466 return error;
31467 }
31468
31469 @@ -6817,7 +6817,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
31470 /* always allow read */
31471 mask = POLLIN | POLLRDNORM;
31472
31473 - if (seq->poll_event != atomic_read(&md_event_count))
31474 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
31475 mask |= POLLERR | POLLPRI;
31476 return mask;
31477 }
31478 @@ -6861,7 +6861,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
31479 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
31480 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
31481 (int)part_stat_read(&disk->part0, sectors[1]) -
31482 - atomic_read(&disk->sync_io);
31483 + atomic_read_unchecked(&disk->sync_io);
31484 /* sync IO will cause sync_io to increase before the disk_stats
31485 * as sync_io is counted when a request starts, and
31486 * disk_stats is counted when it completes.
31487 diff --git a/drivers/md/md.h b/drivers/md/md.h
31488 index cf742d9..7c7c745 100644
31489 --- a/drivers/md/md.h
31490 +++ b/drivers/md/md.h
31491 @@ -120,13 +120,13 @@ struct md_rdev {
31492 * only maintained for arrays that
31493 * support hot removal
31494 */
31495 - atomic_t read_errors; /* number of consecutive read errors that
31496 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
31497 * we have tried to ignore.
31498 */
31499 struct timespec last_read_error; /* monotonic time since our
31500 * last read error
31501 */
31502 - atomic_t corrected_errors; /* number of corrected read errors,
31503 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
31504 * for reporting to userspace and storing
31505 * in superblock.
31506 */
31507 @@ -410,7 +410,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
31508
31509 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
31510 {
31511 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31512 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
31513 }
31514
31515 struct md_personality
31516 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
31517 index 50ed53b..4f29d7d 100644
31518 --- a/drivers/md/persistent-data/dm-space-map-checker.c
31519 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
31520 @@ -159,7 +159,7 @@ static void ca_destroy(struct count_array *ca)
31521 /*----------------------------------------------------------------*/
31522
31523 struct sm_checker {
31524 - struct dm_space_map sm;
31525 + dm_space_map_no_const sm;
31526
31527 struct count_array old_counts;
31528 struct count_array counts;
31529 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
31530 index fc469ba..2d91555 100644
31531 --- a/drivers/md/persistent-data/dm-space-map-disk.c
31532 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
31533 @@ -23,7 +23,7 @@
31534 * Space map interface.
31535 */
31536 struct sm_disk {
31537 - struct dm_space_map sm;
31538 + dm_space_map_no_const sm;
31539
31540 struct ll_disk ll;
31541 struct ll_disk old_ll;
31542 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
31543 index e89ae5e..062e4c2 100644
31544 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
31545 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
31546 @@ -43,7 +43,7 @@ struct block_op {
31547 };
31548
31549 struct sm_metadata {
31550 - struct dm_space_map sm;
31551 + dm_space_map_no_const sm;
31552
31553 struct ll_disk ll;
31554 struct ll_disk old_ll;
31555 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
31556 index 1cbfc6b..56e1dbb 100644
31557 --- a/drivers/md/persistent-data/dm-space-map.h
31558 +++ b/drivers/md/persistent-data/dm-space-map.h
31559 @@ -60,6 +60,7 @@ struct dm_space_map {
31560 int (*root_size)(struct dm_space_map *sm, size_t *result);
31561 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
31562 };
31563 +typedef struct dm_space_map __no_const dm_space_map_no_const;
31564
31565 /*----------------------------------------------------------------*/
31566
31567 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
31568 index 7d9e071..015b1d5 100644
31569 --- a/drivers/md/raid1.c
31570 +++ b/drivers/md/raid1.c
31571 @@ -1568,7 +1568,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
31572 if (r1_sync_page_io(rdev, sect, s,
31573 bio->bi_io_vec[idx].bv_page,
31574 READ) != 0)
31575 - atomic_add(s, &rdev->corrected_errors);
31576 + atomic_add_unchecked(s, &rdev->corrected_errors);
31577 }
31578 sectors -= s;
31579 sect += s;
31580 @@ -1781,7 +1781,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
31581 test_bit(In_sync, &rdev->flags)) {
31582 if (r1_sync_page_io(rdev, sect, s,
31583 conf->tmppage, READ)) {
31584 - atomic_add(s, &rdev->corrected_errors);
31585 + atomic_add_unchecked(s, &rdev->corrected_errors);
31586 printk(KERN_INFO
31587 "md/raid1:%s: read error corrected "
31588 "(%d sectors at %llu on %s)\n",
31589 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
31590 index 685ddf3..955b087 100644
31591 --- a/drivers/md/raid10.c
31592 +++ b/drivers/md/raid10.c
31593 @@ -1440,7 +1440,7 @@ static void end_sync_read(struct bio *bio, int error)
31594 /* The write handler will notice the lack of
31595 * R10BIO_Uptodate and record any errors etc
31596 */
31597 - atomic_add(r10_bio->sectors,
31598 + atomic_add_unchecked(r10_bio->sectors,
31599 &conf->mirrors[d].rdev->corrected_errors);
31600
31601 /* for reconstruct, we always reschedule after a read.
31602 @@ -1740,7 +1740,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
31603 {
31604 struct timespec cur_time_mon;
31605 unsigned long hours_since_last;
31606 - unsigned int read_errors = atomic_read(&rdev->read_errors);
31607 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
31608
31609 ktime_get_ts(&cur_time_mon);
31610
31611 @@ -1762,9 +1762,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
31612 * overflowing the shift of read_errors by hours_since_last.
31613 */
31614 if (hours_since_last >= 8 * sizeof(read_errors))
31615 - atomic_set(&rdev->read_errors, 0);
31616 + atomic_set_unchecked(&rdev->read_errors, 0);
31617 else
31618 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
31619 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
31620 }
31621
31622 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
31623 @@ -1814,8 +1814,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31624 return;
31625
31626 check_decay_read_errors(mddev, rdev);
31627 - atomic_inc(&rdev->read_errors);
31628 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
31629 + atomic_inc_unchecked(&rdev->read_errors);
31630 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
31631 char b[BDEVNAME_SIZE];
31632 bdevname(rdev->bdev, b);
31633
31634 @@ -1823,7 +1823,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31635 "md/raid10:%s: %s: Raid device exceeded "
31636 "read_error threshold [cur %d:max %d]\n",
31637 mdname(mddev), b,
31638 - atomic_read(&rdev->read_errors), max_read_errors);
31639 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
31640 printk(KERN_NOTICE
31641 "md/raid10:%s: %s: Failing raid device\n",
31642 mdname(mddev), b);
31643 @@ -1968,7 +1968,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
31644 (unsigned long long)(
31645 sect + rdev->data_offset),
31646 bdevname(rdev->bdev, b));
31647 - atomic_add(s, &rdev->corrected_errors);
31648 + atomic_add_unchecked(s, &rdev->corrected_errors);
31649 }
31650
31651 rdev_dec_pending(rdev, mddev);
31652 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
31653 index 858fdbb..b2dac95 100644
31654 --- a/drivers/md/raid5.c
31655 +++ b/drivers/md/raid5.c
31656 @@ -1610,19 +1610,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
31657 (unsigned long long)(sh->sector
31658 + rdev->data_offset),
31659 bdevname(rdev->bdev, b));
31660 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
31661 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
31662 clear_bit(R5_ReadError, &sh->dev[i].flags);
31663 clear_bit(R5_ReWrite, &sh->dev[i].flags);
31664 }
31665 - if (atomic_read(&conf->disks[i].rdev->read_errors))
31666 - atomic_set(&conf->disks[i].rdev->read_errors, 0);
31667 + if (atomic_read_unchecked(&conf->disks[i].rdev->read_errors))
31668 + atomic_set_unchecked(&conf->disks[i].rdev->read_errors, 0);
31669 } else {
31670 const char *bdn = bdevname(conf->disks[i].rdev->bdev, b);
31671 int retry = 0;
31672 rdev = conf->disks[i].rdev;
31673
31674 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
31675 - atomic_inc(&rdev->read_errors);
31676 + atomic_inc_unchecked(&rdev->read_errors);
31677 if (conf->mddev->degraded >= conf->max_degraded)
31678 printk_ratelimited(
31679 KERN_WARNING
31680 @@ -1642,7 +1642,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
31681 (unsigned long long)(sh->sector
31682 + rdev->data_offset),
31683 bdn);
31684 - else if (atomic_read(&rdev->read_errors)
31685 + else if (atomic_read_unchecked(&rdev->read_errors)
31686 > conf->max_nr_stripes)
31687 printk(KERN_WARNING
31688 "md/raid:%s: Too many read errors, failing device %s.\n",
31689 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
31690 index ba9a643..e474ab5 100644
31691 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
31692 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
31693 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
31694 .subvendor = _subvend, .subdevice = _subdev, \
31695 .driver_data = (unsigned long)&_driverdata }
31696
31697 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
31698 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
31699 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
31700 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
31701 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
31702 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
31703 index a7d876f..8c21b61 100644
31704 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
31705 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
31706 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
31707 union {
31708 dmx_ts_cb ts;
31709 dmx_section_cb sec;
31710 - } cb;
31711 + } __no_const cb;
31712
31713 struct dvb_demux *demux;
31714 void *priv;
31715 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
31716 index f732877..d38c35a 100644
31717 --- a/drivers/media/dvb/dvb-core/dvbdev.c
31718 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
31719 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
31720 const struct dvb_device *template, void *priv, int type)
31721 {
31722 struct dvb_device *dvbdev;
31723 - struct file_operations *dvbdevfops;
31724 + file_operations_no_const *dvbdevfops;
31725 struct device *clsdev;
31726 int minor;
31727 int id;
31728 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
31729 index 9f2a02c..5920f88 100644
31730 --- a/drivers/media/dvb/dvb-usb/cxusb.c
31731 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
31732 @@ -1069,7 +1069,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
31733 struct dib0700_adapter_state {
31734 int (*set_param_save) (struct dvb_frontend *,
31735 struct dvb_frontend_parameters *);
31736 -};
31737 +} __no_const;
31738
31739 static int dib7070_set_param_override(struct dvb_frontend *fe,
31740 struct dvb_frontend_parameters *fep)
31741 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
31742 index f103ec1..5e8968b 100644
31743 --- a/drivers/media/dvb/dvb-usb/dw2102.c
31744 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
31745 @@ -95,7 +95,7 @@ struct su3000_state {
31746
31747 struct s6x0_state {
31748 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
31749 -};
31750 +} __no_const;
31751
31752 /* debug */
31753 static int dvb_usb_dw2102_debug;
31754 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
31755 index 404f63a..4796533 100644
31756 --- a/drivers/media/dvb/frontends/dib3000.h
31757 +++ b/drivers/media/dvb/frontends/dib3000.h
31758 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
31759 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
31760 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
31761 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
31762 -};
31763 +} __no_const;
31764
31765 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
31766 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
31767 diff --git a/drivers/media/dvb/frontends/ds3000.c b/drivers/media/dvb/frontends/ds3000.c
31768 index 90bf573..e8463da 100644
31769 --- a/drivers/media/dvb/frontends/ds3000.c
31770 +++ b/drivers/media/dvb/frontends/ds3000.c
31771 @@ -1210,7 +1210,7 @@ static int ds3000_set_frontend(struct dvb_frontend *fe,
31772
31773 for (i = 0; i < 30 ; i++) {
31774 ds3000_read_status(fe, &status);
31775 - if (status && FE_HAS_LOCK)
31776 + if (status & FE_HAS_LOCK)
31777 break;
31778
31779 msleep(10);
31780 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
31781 index 0564192..75b16f5 100644
31782 --- a/drivers/media/dvb/ngene/ngene-cards.c
31783 +++ b/drivers/media/dvb/ngene/ngene-cards.c
31784 @@ -477,7 +477,7 @@ static struct ngene_info ngene_info_m780 = {
31785
31786 /****************************************************************************/
31787
31788 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
31789 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
31790 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
31791 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
31792 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
31793 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
31794 index 16a089f..ab1667d 100644
31795 --- a/drivers/media/radio/radio-cadet.c
31796 +++ b/drivers/media/radio/radio-cadet.c
31797 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
31798 unsigned char readbuf[RDS_BUFFER];
31799 int i = 0;
31800
31801 + if (count > RDS_BUFFER)
31802 + return -EFAULT;
31803 mutex_lock(&dev->lock);
31804 if (dev->rdsstat == 0) {
31805 dev->rdsstat = 1;
31806 diff --git a/drivers/media/rc/redrat3.c b/drivers/media/rc/redrat3.c
31807 index 61287fc..8b08712 100644
31808 --- a/drivers/media/rc/redrat3.c
31809 +++ b/drivers/media/rc/redrat3.c
31810 @@ -905,7 +905,7 @@ static int redrat3_set_tx_carrier(struct rc_dev *dev, u32 carrier)
31811 return carrier;
31812 }
31813
31814 -static int redrat3_transmit_ir(struct rc_dev *rcdev, int *txbuf, u32 n)
31815 +static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf, u32 n)
31816 {
31817 struct redrat3_dev *rr3 = rcdev->priv;
31818 struct device *dev = rr3->dev;
31819 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
31820 index 9cde353..8c6a1c3 100644
31821 --- a/drivers/media/video/au0828/au0828.h
31822 +++ b/drivers/media/video/au0828/au0828.h
31823 @@ -191,7 +191,7 @@ struct au0828_dev {
31824
31825 /* I2C */
31826 struct i2c_adapter i2c_adap;
31827 - struct i2c_algorithm i2c_algo;
31828 + i2c_algorithm_no_const i2c_algo;
31829 struct i2c_client i2c_client;
31830 u32 i2c_rc;
31831
31832 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
31833 index 68d1240..46b32eb 100644
31834 --- a/drivers/media/video/cx88/cx88-alsa.c
31835 +++ b/drivers/media/video/cx88/cx88-alsa.c
31836 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
31837 * Only boards with eeprom and byte 1 at eeprom=1 have it
31838 */
31839
31840 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
31841 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
31842 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31843 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
31844 {0, }
31845 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31846 index 305e6aa..0143317 100644
31847 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31848 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
31849 @@ -196,7 +196,7 @@ struct pvr2_hdw {
31850
31851 /* I2C stuff */
31852 struct i2c_adapter i2c_adap;
31853 - struct i2c_algorithm i2c_algo;
31854 + i2c_algorithm_no_const i2c_algo;
31855 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
31856 int i2c_cx25840_hack_state;
31857 int i2c_linked;
31858 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
31859 index a0895bf..b7ebb1b 100644
31860 --- a/drivers/media/video/timblogiw.c
31861 +++ b/drivers/media/video/timblogiw.c
31862 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
31863
31864 /* Platform device functions */
31865
31866 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
31867 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
31868 .vidioc_querycap = timblogiw_querycap,
31869 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
31870 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
31871 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
31872 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
31873 };
31874
31875 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
31876 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
31877 .owner = THIS_MODULE,
31878 .open = timblogiw_open,
31879 .release = timblogiw_close,
31880 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
31881 index e9c6a60..daf6a33 100644
31882 --- a/drivers/message/fusion/mptbase.c
31883 +++ b/drivers/message/fusion/mptbase.c
31884 @@ -6753,8 +6753,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
31885 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
31886 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
31887
31888 +#ifdef CONFIG_GRKERNSEC_HIDESYM
31889 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
31890 +#else
31891 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
31892 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
31893 +#endif
31894 +
31895 /*
31896 * Rounding UP to nearest 4-kB boundary here...
31897 */
31898 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
31899 index 9d95042..b808101 100644
31900 --- a/drivers/message/fusion/mptsas.c
31901 +++ b/drivers/message/fusion/mptsas.c
31902 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
31903 return 0;
31904 }
31905
31906 +static inline void
31907 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
31908 +{
31909 + if (phy_info->port_details) {
31910 + phy_info->port_details->rphy = rphy;
31911 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
31912 + ioc->name, rphy));
31913 + }
31914 +
31915 + if (rphy) {
31916 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
31917 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
31918 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
31919 + ioc->name, rphy, rphy->dev.release));
31920 + }
31921 +}
31922 +
31923 /* no mutex */
31924 static void
31925 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
31926 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
31927 return NULL;
31928 }
31929
31930 -static inline void
31931 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
31932 -{
31933 - if (phy_info->port_details) {
31934 - phy_info->port_details->rphy = rphy;
31935 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
31936 - ioc->name, rphy));
31937 - }
31938 -
31939 - if (rphy) {
31940 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
31941 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
31942 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
31943 - ioc->name, rphy, rphy->dev.release));
31944 - }
31945 -}
31946 -
31947 static inline struct sas_port *
31948 mptsas_get_port(struct mptsas_phyinfo *phy_info)
31949 {
31950 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
31951 index 0c3ced7..1fe34ec 100644
31952 --- a/drivers/message/fusion/mptscsih.c
31953 +++ b/drivers/message/fusion/mptscsih.c
31954 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
31955
31956 h = shost_priv(SChost);
31957
31958 - if (h) {
31959 - if (h->info_kbuf == NULL)
31960 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
31961 - return h->info_kbuf;
31962 - h->info_kbuf[0] = '\0';
31963 + if (!h)
31964 + return NULL;
31965
31966 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
31967 - h->info_kbuf[size-1] = '\0';
31968 - }
31969 + if (h->info_kbuf == NULL)
31970 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
31971 + return h->info_kbuf;
31972 + h->info_kbuf[0] = '\0';
31973 +
31974 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
31975 + h->info_kbuf[size-1] = '\0';
31976
31977 return h->info_kbuf;
31978 }
31979 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
31980 index 07dbeaf..5533142 100644
31981 --- a/drivers/message/i2o/i2o_proc.c
31982 +++ b/drivers/message/i2o/i2o_proc.c
31983 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
31984 "Array Controller Device"
31985 };
31986
31987 -static char *chtostr(u8 * chars, int n)
31988 -{
31989 - char tmp[256];
31990 - tmp[0] = 0;
31991 - return strncat(tmp, (char *)chars, n);
31992 -}
31993 -
31994 static int i2o_report_query_status(struct seq_file *seq, int block_status,
31995 char *group)
31996 {
31997 @@ -838,8 +831,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
31998
31999 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
32000 seq_printf(seq, "%-#8x", ddm_table.module_id);
32001 - seq_printf(seq, "%-29s",
32002 - chtostr(ddm_table.module_name_version, 28));
32003 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
32004 seq_printf(seq, "%9d ", ddm_table.data_size);
32005 seq_printf(seq, "%8d", ddm_table.code_size);
32006
32007 @@ -940,8 +932,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
32008
32009 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
32010 seq_printf(seq, "%-#8x", dst->module_id);
32011 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
32012 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
32013 + seq_printf(seq, "%-.28s", dst->module_name_version);
32014 + seq_printf(seq, "%-.8s", dst->date);
32015 seq_printf(seq, "%8d ", dst->module_size);
32016 seq_printf(seq, "%8d ", dst->mpb_size);
32017 seq_printf(seq, "0x%04x", dst->module_flags);
32018 @@ -1272,14 +1264,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
32019 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
32020 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
32021 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
32022 - seq_printf(seq, "Vendor info : %s\n",
32023 - chtostr((u8 *) (work32 + 2), 16));
32024 - seq_printf(seq, "Product info : %s\n",
32025 - chtostr((u8 *) (work32 + 6), 16));
32026 - seq_printf(seq, "Description : %s\n",
32027 - chtostr((u8 *) (work32 + 10), 16));
32028 - seq_printf(seq, "Product rev. : %s\n",
32029 - chtostr((u8 *) (work32 + 14), 8));
32030 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
32031 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
32032 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
32033 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
32034
32035 seq_printf(seq, "Serial number : ");
32036 print_serial_number(seq, (u8 *) (work32 + 16),
32037 @@ -1324,10 +1312,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
32038 }
32039
32040 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
32041 - seq_printf(seq, "Module name : %s\n",
32042 - chtostr(result.module_name, 24));
32043 - seq_printf(seq, "Module revision : %s\n",
32044 - chtostr(result.module_rev, 8));
32045 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
32046 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
32047
32048 seq_printf(seq, "Serial number : ");
32049 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
32050 @@ -1358,14 +1344,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
32051 return 0;
32052 }
32053
32054 - seq_printf(seq, "Device name : %s\n",
32055 - chtostr(result.device_name, 64));
32056 - seq_printf(seq, "Service name : %s\n",
32057 - chtostr(result.service_name, 64));
32058 - seq_printf(seq, "Physical name : %s\n",
32059 - chtostr(result.physical_location, 64));
32060 - seq_printf(seq, "Instance number : %s\n",
32061 - chtostr(result.instance_number, 4));
32062 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
32063 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
32064 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
32065 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
32066
32067 return 0;
32068 }
32069 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
32070 index a8c08f3..155fe3d 100644
32071 --- a/drivers/message/i2o/iop.c
32072 +++ b/drivers/message/i2o/iop.c
32073 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
32074
32075 spin_lock_irqsave(&c->context_list_lock, flags);
32076
32077 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
32078 - atomic_inc(&c->context_list_counter);
32079 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
32080 + atomic_inc_unchecked(&c->context_list_counter);
32081
32082 - entry->context = atomic_read(&c->context_list_counter);
32083 + entry->context = atomic_read_unchecked(&c->context_list_counter);
32084
32085 list_add(&entry->list, &c->context_list);
32086
32087 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
32088
32089 #if BITS_PER_LONG == 64
32090 spin_lock_init(&c->context_list_lock);
32091 - atomic_set(&c->context_list_counter, 0);
32092 + atomic_set_unchecked(&c->context_list_counter, 0);
32093 INIT_LIST_HEAD(&c->context_list);
32094 #endif
32095
32096 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
32097 index 7ce65f4..e66e9bc 100644
32098 --- a/drivers/mfd/abx500-core.c
32099 +++ b/drivers/mfd/abx500-core.c
32100 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
32101
32102 struct abx500_device_entry {
32103 struct list_head list;
32104 - struct abx500_ops ops;
32105 + abx500_ops_no_const ops;
32106 struct device *dev;
32107 };
32108
32109 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
32110 index 5c2a06a..8fa077c 100644
32111 --- a/drivers/mfd/janz-cmodio.c
32112 +++ b/drivers/mfd/janz-cmodio.c
32113 @@ -13,6 +13,7 @@
32114
32115 #include <linux/kernel.h>
32116 #include <linux/module.h>
32117 +#include <linux/slab.h>
32118 #include <linux/init.h>
32119 #include <linux/pci.h>
32120 #include <linux/interrupt.h>
32121 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
32122 index 29d12a7..f900ba4 100644
32123 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
32124 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
32125 @@ -464,7 +464,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
32126 * the lid is closed. This leads to interrupts as soon as a little move
32127 * is done.
32128 */
32129 - atomic_inc(&lis3->count);
32130 + atomic_inc_unchecked(&lis3->count);
32131
32132 wake_up_interruptible(&lis3->misc_wait);
32133 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
32134 @@ -550,7 +550,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
32135 if (lis3->pm_dev)
32136 pm_runtime_get_sync(lis3->pm_dev);
32137
32138 - atomic_set(&lis3->count, 0);
32139 + atomic_set_unchecked(&lis3->count, 0);
32140 return 0;
32141 }
32142
32143 @@ -583,7 +583,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
32144 add_wait_queue(&lis3->misc_wait, &wait);
32145 while (true) {
32146 set_current_state(TASK_INTERRUPTIBLE);
32147 - data = atomic_xchg(&lis3->count, 0);
32148 + data = atomic_xchg_unchecked(&lis3->count, 0);
32149 if (data)
32150 break;
32151
32152 @@ -624,7 +624,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
32153 struct lis3lv02d, miscdev);
32154
32155 poll_wait(file, &lis3->misc_wait, wait);
32156 - if (atomic_read(&lis3->count))
32157 + if (atomic_read_unchecked(&lis3->count))
32158 return POLLIN | POLLRDNORM;
32159 return 0;
32160 }
32161 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
32162 index 2b1482a..5d33616 100644
32163 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
32164 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
32165 @@ -266,7 +266,7 @@ struct lis3lv02d {
32166 struct input_polled_dev *idev; /* input device */
32167 struct platform_device *pdev; /* platform device */
32168 struct regulator_bulk_data regulators[2];
32169 - atomic_t count; /* interrupt count after last read */
32170 + atomic_unchecked_t count; /* interrupt count after last read */
32171 union axis_conversion ac; /* hw -> logical axis */
32172 int mapped_btns[3];
32173
32174 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
32175 index 2f30bad..c4c13d0 100644
32176 --- a/drivers/misc/sgi-gru/gruhandles.c
32177 +++ b/drivers/misc/sgi-gru/gruhandles.c
32178 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
32179 unsigned long nsec;
32180
32181 nsec = CLKS2NSEC(clks);
32182 - atomic_long_inc(&mcs_op_statistics[op].count);
32183 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
32184 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
32185 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
32186 if (mcs_op_statistics[op].max < nsec)
32187 mcs_op_statistics[op].max = nsec;
32188 }
32189 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
32190 index 7768b87..f8aac38 100644
32191 --- a/drivers/misc/sgi-gru/gruprocfs.c
32192 +++ b/drivers/misc/sgi-gru/gruprocfs.c
32193 @@ -32,9 +32,9 @@
32194
32195 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
32196
32197 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
32198 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
32199 {
32200 - unsigned long val = atomic_long_read(v);
32201 + unsigned long val = atomic_long_read_unchecked(v);
32202
32203 seq_printf(s, "%16lu %s\n", val, id);
32204 }
32205 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
32206
32207 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
32208 for (op = 0; op < mcsop_last; op++) {
32209 - count = atomic_long_read(&mcs_op_statistics[op].count);
32210 - total = atomic_long_read(&mcs_op_statistics[op].total);
32211 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
32212 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
32213 max = mcs_op_statistics[op].max;
32214 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
32215 count ? total / count : 0, max);
32216 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
32217 index 5c3ce24..4915ccb 100644
32218 --- a/drivers/misc/sgi-gru/grutables.h
32219 +++ b/drivers/misc/sgi-gru/grutables.h
32220 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
32221 * GRU statistics.
32222 */
32223 struct gru_stats_s {
32224 - atomic_long_t vdata_alloc;
32225 - atomic_long_t vdata_free;
32226 - atomic_long_t gts_alloc;
32227 - atomic_long_t gts_free;
32228 - atomic_long_t gms_alloc;
32229 - atomic_long_t gms_free;
32230 - atomic_long_t gts_double_allocate;
32231 - atomic_long_t assign_context;
32232 - atomic_long_t assign_context_failed;
32233 - atomic_long_t free_context;
32234 - atomic_long_t load_user_context;
32235 - atomic_long_t load_kernel_context;
32236 - atomic_long_t lock_kernel_context;
32237 - atomic_long_t unlock_kernel_context;
32238 - atomic_long_t steal_user_context;
32239 - atomic_long_t steal_kernel_context;
32240 - atomic_long_t steal_context_failed;
32241 - atomic_long_t nopfn;
32242 - atomic_long_t asid_new;
32243 - atomic_long_t asid_next;
32244 - atomic_long_t asid_wrap;
32245 - atomic_long_t asid_reuse;
32246 - atomic_long_t intr;
32247 - atomic_long_t intr_cbr;
32248 - atomic_long_t intr_tfh;
32249 - atomic_long_t intr_spurious;
32250 - atomic_long_t intr_mm_lock_failed;
32251 - atomic_long_t call_os;
32252 - atomic_long_t call_os_wait_queue;
32253 - atomic_long_t user_flush_tlb;
32254 - atomic_long_t user_unload_context;
32255 - atomic_long_t user_exception;
32256 - atomic_long_t set_context_option;
32257 - atomic_long_t check_context_retarget_intr;
32258 - atomic_long_t check_context_unload;
32259 - atomic_long_t tlb_dropin;
32260 - atomic_long_t tlb_preload_page;
32261 - atomic_long_t tlb_dropin_fail_no_asid;
32262 - atomic_long_t tlb_dropin_fail_upm;
32263 - atomic_long_t tlb_dropin_fail_invalid;
32264 - atomic_long_t tlb_dropin_fail_range_active;
32265 - atomic_long_t tlb_dropin_fail_idle;
32266 - atomic_long_t tlb_dropin_fail_fmm;
32267 - atomic_long_t tlb_dropin_fail_no_exception;
32268 - atomic_long_t tfh_stale_on_fault;
32269 - atomic_long_t mmu_invalidate_range;
32270 - atomic_long_t mmu_invalidate_page;
32271 - atomic_long_t flush_tlb;
32272 - atomic_long_t flush_tlb_gru;
32273 - atomic_long_t flush_tlb_gru_tgh;
32274 - atomic_long_t flush_tlb_gru_zero_asid;
32275 + atomic_long_unchecked_t vdata_alloc;
32276 + atomic_long_unchecked_t vdata_free;
32277 + atomic_long_unchecked_t gts_alloc;
32278 + atomic_long_unchecked_t gts_free;
32279 + atomic_long_unchecked_t gms_alloc;
32280 + atomic_long_unchecked_t gms_free;
32281 + atomic_long_unchecked_t gts_double_allocate;
32282 + atomic_long_unchecked_t assign_context;
32283 + atomic_long_unchecked_t assign_context_failed;
32284 + atomic_long_unchecked_t free_context;
32285 + atomic_long_unchecked_t load_user_context;
32286 + atomic_long_unchecked_t load_kernel_context;
32287 + atomic_long_unchecked_t lock_kernel_context;
32288 + atomic_long_unchecked_t unlock_kernel_context;
32289 + atomic_long_unchecked_t steal_user_context;
32290 + atomic_long_unchecked_t steal_kernel_context;
32291 + atomic_long_unchecked_t steal_context_failed;
32292 + atomic_long_unchecked_t nopfn;
32293 + atomic_long_unchecked_t asid_new;
32294 + atomic_long_unchecked_t asid_next;
32295 + atomic_long_unchecked_t asid_wrap;
32296 + atomic_long_unchecked_t asid_reuse;
32297 + atomic_long_unchecked_t intr;
32298 + atomic_long_unchecked_t intr_cbr;
32299 + atomic_long_unchecked_t intr_tfh;
32300 + atomic_long_unchecked_t intr_spurious;
32301 + atomic_long_unchecked_t intr_mm_lock_failed;
32302 + atomic_long_unchecked_t call_os;
32303 + atomic_long_unchecked_t call_os_wait_queue;
32304 + atomic_long_unchecked_t user_flush_tlb;
32305 + atomic_long_unchecked_t user_unload_context;
32306 + atomic_long_unchecked_t user_exception;
32307 + atomic_long_unchecked_t set_context_option;
32308 + atomic_long_unchecked_t check_context_retarget_intr;
32309 + atomic_long_unchecked_t check_context_unload;
32310 + atomic_long_unchecked_t tlb_dropin;
32311 + atomic_long_unchecked_t tlb_preload_page;
32312 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
32313 + atomic_long_unchecked_t tlb_dropin_fail_upm;
32314 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
32315 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
32316 + atomic_long_unchecked_t tlb_dropin_fail_idle;
32317 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
32318 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
32319 + atomic_long_unchecked_t tfh_stale_on_fault;
32320 + atomic_long_unchecked_t mmu_invalidate_range;
32321 + atomic_long_unchecked_t mmu_invalidate_page;
32322 + atomic_long_unchecked_t flush_tlb;
32323 + atomic_long_unchecked_t flush_tlb_gru;
32324 + atomic_long_unchecked_t flush_tlb_gru_tgh;
32325 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
32326
32327 - atomic_long_t copy_gpa;
32328 - atomic_long_t read_gpa;
32329 + atomic_long_unchecked_t copy_gpa;
32330 + atomic_long_unchecked_t read_gpa;
32331
32332 - atomic_long_t mesq_receive;
32333 - atomic_long_t mesq_receive_none;
32334 - atomic_long_t mesq_send;
32335 - atomic_long_t mesq_send_failed;
32336 - atomic_long_t mesq_noop;
32337 - atomic_long_t mesq_send_unexpected_error;
32338 - atomic_long_t mesq_send_lb_overflow;
32339 - atomic_long_t mesq_send_qlimit_reached;
32340 - atomic_long_t mesq_send_amo_nacked;
32341 - atomic_long_t mesq_send_put_nacked;
32342 - atomic_long_t mesq_page_overflow;
32343 - atomic_long_t mesq_qf_locked;
32344 - atomic_long_t mesq_qf_noop_not_full;
32345 - atomic_long_t mesq_qf_switch_head_failed;
32346 - atomic_long_t mesq_qf_unexpected_error;
32347 - atomic_long_t mesq_noop_unexpected_error;
32348 - atomic_long_t mesq_noop_lb_overflow;
32349 - atomic_long_t mesq_noop_qlimit_reached;
32350 - atomic_long_t mesq_noop_amo_nacked;
32351 - atomic_long_t mesq_noop_put_nacked;
32352 - atomic_long_t mesq_noop_page_overflow;
32353 + atomic_long_unchecked_t mesq_receive;
32354 + atomic_long_unchecked_t mesq_receive_none;
32355 + atomic_long_unchecked_t mesq_send;
32356 + atomic_long_unchecked_t mesq_send_failed;
32357 + atomic_long_unchecked_t mesq_noop;
32358 + atomic_long_unchecked_t mesq_send_unexpected_error;
32359 + atomic_long_unchecked_t mesq_send_lb_overflow;
32360 + atomic_long_unchecked_t mesq_send_qlimit_reached;
32361 + atomic_long_unchecked_t mesq_send_amo_nacked;
32362 + atomic_long_unchecked_t mesq_send_put_nacked;
32363 + atomic_long_unchecked_t mesq_page_overflow;
32364 + atomic_long_unchecked_t mesq_qf_locked;
32365 + atomic_long_unchecked_t mesq_qf_noop_not_full;
32366 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
32367 + atomic_long_unchecked_t mesq_qf_unexpected_error;
32368 + atomic_long_unchecked_t mesq_noop_unexpected_error;
32369 + atomic_long_unchecked_t mesq_noop_lb_overflow;
32370 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
32371 + atomic_long_unchecked_t mesq_noop_amo_nacked;
32372 + atomic_long_unchecked_t mesq_noop_put_nacked;
32373 + atomic_long_unchecked_t mesq_noop_page_overflow;
32374
32375 };
32376
32377 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
32378 tghop_invalidate, mcsop_last};
32379
32380 struct mcs_op_statistic {
32381 - atomic_long_t count;
32382 - atomic_long_t total;
32383 + atomic_long_unchecked_t count;
32384 + atomic_long_unchecked_t total;
32385 unsigned long max;
32386 };
32387
32388 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
32389
32390 #define STAT(id) do { \
32391 if (gru_options & OPT_STATS) \
32392 - atomic_long_inc(&gru_stats.id); \
32393 + atomic_long_inc_unchecked(&gru_stats.id); \
32394 } while (0)
32395
32396 #ifdef CONFIG_SGI_GRU_DEBUG
32397 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
32398 index 851b2f2..a4ec097 100644
32399 --- a/drivers/misc/sgi-xp/xp.h
32400 +++ b/drivers/misc/sgi-xp/xp.h
32401 @@ -289,7 +289,7 @@ struct xpc_interface {
32402 xpc_notify_func, void *);
32403 void (*received) (short, int, void *);
32404 enum xp_retval (*partid_to_nasids) (short, void *);
32405 -};
32406 +} __no_const;
32407
32408 extern struct xpc_interface xpc_interface;
32409
32410 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
32411 index b94d5f7..7f494c5 100644
32412 --- a/drivers/misc/sgi-xp/xpc.h
32413 +++ b/drivers/misc/sgi-xp/xpc.h
32414 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
32415 void (*received_payload) (struct xpc_channel *, void *);
32416 void (*notify_senders_of_disconnect) (struct xpc_channel *);
32417 };
32418 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
32419
32420 /* struct xpc_partition act_state values (for XPC HB) */
32421
32422 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
32423 /* found in xpc_main.c */
32424 extern struct device *xpc_part;
32425 extern struct device *xpc_chan;
32426 -extern struct xpc_arch_operations xpc_arch_ops;
32427 +extern xpc_arch_operations_no_const xpc_arch_ops;
32428 extern int xpc_disengage_timelimit;
32429 extern int xpc_disengage_timedout;
32430 extern int xpc_activate_IRQ_rcvd;
32431 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
32432 index 8d082b4..aa749ae 100644
32433 --- a/drivers/misc/sgi-xp/xpc_main.c
32434 +++ b/drivers/misc/sgi-xp/xpc_main.c
32435 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
32436 .notifier_call = xpc_system_die,
32437 };
32438
32439 -struct xpc_arch_operations xpc_arch_ops;
32440 +xpc_arch_operations_no_const xpc_arch_ops;
32441
32442 /*
32443 * Timer function to enforce the timelimit on the partition disengage.
32444 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
32445 index 6878a94..fe5c5f1 100644
32446 --- a/drivers/mmc/host/sdhci-pci.c
32447 +++ b/drivers/mmc/host/sdhci-pci.c
32448 @@ -673,7 +673,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
32449 .probe = via_probe,
32450 };
32451
32452 -static const struct pci_device_id pci_ids[] __devinitdata = {
32453 +static const struct pci_device_id pci_ids[] __devinitconst = {
32454 {
32455 .vendor = PCI_VENDOR_ID_RICOH,
32456 .device = PCI_DEVICE_ID_RICOH_R5C822,
32457 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
32458 index e9fad91..0a7a16a 100644
32459 --- a/drivers/mtd/devices/doc2000.c
32460 +++ b/drivers/mtd/devices/doc2000.c
32461 @@ -773,7 +773,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
32462
32463 /* The ECC will not be calculated correctly if less than 512 is written */
32464 /* DBB-
32465 - if (len != 0x200 && eccbuf)
32466 + if (len != 0x200)
32467 printk(KERN_WARNING
32468 "ECC needs a full sector write (adr: %lx size %lx)\n",
32469 (long) to, (long) len);
32470 diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
32471 index a3f7a27..234016e 100644
32472 --- a/drivers/mtd/devices/doc2001.c
32473 +++ b/drivers/mtd/devices/doc2001.c
32474 @@ -392,7 +392,7 @@ static int doc_read (struct mtd_info *mtd, loff_t from, size_t len,
32475 struct Nand *mychip = &this->chips[from >> (this->chipshift)];
32476
32477 /* Don't allow read past end of device */
32478 - if (from >= this->totlen)
32479 + if (from >= this->totlen || !len)
32480 return -EINVAL;
32481
32482 /* Don't allow a single read to cross a 512-byte block boundary */
32483 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
32484 index 3984d48..28aa897 100644
32485 --- a/drivers/mtd/nand/denali.c
32486 +++ b/drivers/mtd/nand/denali.c
32487 @@ -26,6 +26,7 @@
32488 #include <linux/pci.h>
32489 #include <linux/mtd/mtd.h>
32490 #include <linux/module.h>
32491 +#include <linux/slab.h>
32492
32493 #include "denali.h"
32494
32495 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
32496 index ac40925..483b753 100644
32497 --- a/drivers/mtd/nftlmount.c
32498 +++ b/drivers/mtd/nftlmount.c
32499 @@ -24,6 +24,7 @@
32500 #include <asm/errno.h>
32501 #include <linux/delay.h>
32502 #include <linux/slab.h>
32503 +#include <linux/sched.h>
32504 #include <linux/mtd/mtd.h>
32505 #include <linux/mtd/nand.h>
32506 #include <linux/mtd/nftl.h>
32507 diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
32508 index 6c3fb5a..c542a81 100644
32509 --- a/drivers/mtd/ubi/build.c
32510 +++ b/drivers/mtd/ubi/build.c
32511 @@ -1311,7 +1311,7 @@ module_exit(ubi_exit);
32512 static int __init bytes_str_to_int(const char *str)
32513 {
32514 char *endp;
32515 - unsigned long result;
32516 + unsigned long result, scale = 1;
32517
32518 result = simple_strtoul(str, &endp, 0);
32519 if (str == endp || result >= INT_MAX) {
32520 @@ -1322,11 +1322,11 @@ static int __init bytes_str_to_int(const char *str)
32521
32522 switch (*endp) {
32523 case 'G':
32524 - result *= 1024;
32525 + scale *= 1024;
32526 case 'M':
32527 - result *= 1024;
32528 + scale *= 1024;
32529 case 'K':
32530 - result *= 1024;
32531 + scale *= 1024;
32532 if (endp[1] == 'i' && endp[2] == 'B')
32533 endp += 2;
32534 case '\0':
32535 @@ -1337,7 +1337,13 @@ static int __init bytes_str_to_int(const char *str)
32536 return -EINVAL;
32537 }
32538
32539 - return result;
32540 + if ((intoverflow_t)result*scale >= INT_MAX) {
32541 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
32542 + str);
32543 + return -EINVAL;
32544 + }
32545 +
32546 + return result*scale;
32547 }
32548
32549 /**
32550 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
32551 index 1feae59..c2a61d2 100644
32552 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
32553 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
32554 @@ -2857,7 +2857,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
32555 */
32556
32557 #define ATL2_PARAM(X, desc) \
32558 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32559 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
32560 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
32561 MODULE_PARM_DESC(X, desc);
32562 #else
32563 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32564 index 9a517c2..a50cfcb 100644
32565 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32566 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
32567 @@ -449,7 +449,7 @@ struct bnx2x_rx_mode_obj {
32568
32569 int (*wait_comp)(struct bnx2x *bp,
32570 struct bnx2x_rx_mode_ramrod_params *p);
32571 -};
32572 +} __no_const;
32573
32574 /********************** Set multicast group ***********************************/
32575
32576 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
32577 index 94b4bd0..73c02de 100644
32578 --- a/drivers/net/ethernet/broadcom/tg3.h
32579 +++ b/drivers/net/ethernet/broadcom/tg3.h
32580 @@ -134,6 +134,7 @@
32581 #define CHIPREV_ID_5750_A0 0x4000
32582 #define CHIPREV_ID_5750_A1 0x4001
32583 #define CHIPREV_ID_5750_A3 0x4003
32584 +#define CHIPREV_ID_5750_C1 0x4201
32585 #define CHIPREV_ID_5750_C2 0x4202
32586 #define CHIPREV_ID_5752_A0_HW 0x5000
32587 #define CHIPREV_ID_5752_A0 0x6000
32588 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32589 index c5f5479..2e8c260 100644
32590 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32591 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
32592 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
32593 */
32594 struct l2t_skb_cb {
32595 arp_failure_handler_func arp_failure_handler;
32596 -};
32597 +} __no_const;
32598
32599 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
32600
32601 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
32602 index 871bcaa..4043505 100644
32603 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
32604 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
32605 @@ -5397,7 +5397,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
32606 for (i=0; i<ETH_ALEN; i++) {
32607 tmp.addr[i] = dev->dev_addr[i];
32608 }
32609 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32610 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
32611 break;
32612
32613 case DE4X5_SET_HWADDR: /* Set the hardware address */
32614 @@ -5437,7 +5437,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
32615 spin_lock_irqsave(&lp->lock, flags);
32616 memcpy(&statbuf, &lp->pktStats, ioc->len);
32617 spin_unlock_irqrestore(&lp->lock, flags);
32618 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
32619 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
32620 return -EFAULT;
32621 break;
32622 }
32623 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
32624 index 14d5b61..1398636 100644
32625 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
32626 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
32627 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
32628 {NULL}};
32629
32630
32631 -static const char *block_name[] __devinitdata = {
32632 +static const char *block_name[] __devinitconst = {
32633 "21140 non-MII",
32634 "21140 MII PHY",
32635 "21142 Serial PHY",
32636 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
32637 index 4d01219..b58d26d 100644
32638 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
32639 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
32640 @@ -236,7 +236,7 @@ struct pci_id_info {
32641 int drv_flags; /* Driver use, intended as capability flags. */
32642 };
32643
32644 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
32645 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
32646 { /* Sometime a Level-One switch card. */
32647 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
32648 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
32649 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
32650 index dcd7f7a..ecb7fb3 100644
32651 --- a/drivers/net/ethernet/dlink/sundance.c
32652 +++ b/drivers/net/ethernet/dlink/sundance.c
32653 @@ -218,7 +218,7 @@ enum {
32654 struct pci_id_info {
32655 const char *name;
32656 };
32657 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
32658 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
32659 {"D-Link DFE-550TX FAST Ethernet Adapter"},
32660 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
32661 {"D-Link DFE-580TX 4 port Server Adapter"},
32662 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
32663 index bf266a0..e024af7 100644
32664 --- a/drivers/net/ethernet/emulex/benet/be_main.c
32665 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
32666 @@ -397,7 +397,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
32667
32668 if (wrapped)
32669 newacc += 65536;
32670 - ACCESS_ONCE(*acc) = newacc;
32671 + ACCESS_ONCE_RW(*acc) = newacc;
32672 }
32673
32674 void be_parse_stats(struct be_adapter *adapter)
32675 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
32676 index 61d2bdd..7f1154a 100644
32677 --- a/drivers/net/ethernet/fealnx.c
32678 +++ b/drivers/net/ethernet/fealnx.c
32679 @@ -150,7 +150,7 @@ struct chip_info {
32680 int flags;
32681 };
32682
32683 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
32684 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
32685 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
32686 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
32687 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
32688 diff --git a/drivers/net/ethernet/intel/e1000e/80003es2lan.c b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32689 index e1159e5..e18684d 100644
32690 --- a/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32691 +++ b/drivers/net/ethernet/intel/e1000e/80003es2lan.c
32692 @@ -205,7 +205,7 @@ static s32 e1000_init_mac_params_80003es2lan(struct e1000_adapter *adapter)
32693 {
32694 struct e1000_hw *hw = &adapter->hw;
32695 struct e1000_mac_info *mac = &hw->mac;
32696 - struct e1000_mac_operations *func = &mac->ops;
32697 + e1000_mac_operations_no_const *func = &mac->ops;
32698
32699 /* Set media type */
32700 switch (adapter->pdev->device) {
32701 diff --git a/drivers/net/ethernet/intel/e1000e/82571.c b/drivers/net/ethernet/intel/e1000e/82571.c
32702 index a3e65fd..f451444 100644
32703 --- a/drivers/net/ethernet/intel/e1000e/82571.c
32704 +++ b/drivers/net/ethernet/intel/e1000e/82571.c
32705 @@ -239,7 +239,7 @@ static s32 e1000_init_mac_params_82571(struct e1000_adapter *adapter)
32706 {
32707 struct e1000_hw *hw = &adapter->hw;
32708 struct e1000_mac_info *mac = &hw->mac;
32709 - struct e1000_mac_operations *func = &mac->ops;
32710 + e1000_mac_operations_no_const *func = &mac->ops;
32711 u32 swsm = 0;
32712 u32 swsm2 = 0;
32713 bool force_clear_smbi = false;
32714 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
32715 index 2967039..ca8c40c 100644
32716 --- a/drivers/net/ethernet/intel/e1000e/hw.h
32717 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
32718 @@ -778,6 +778,7 @@ struct e1000_mac_operations {
32719 void (*write_vfta)(struct e1000_hw *, u32, u32);
32720 s32 (*read_mac_addr)(struct e1000_hw *);
32721 };
32722 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32723
32724 /*
32725 * When to use various PHY register access functions:
32726 @@ -818,6 +819,7 @@ struct e1000_phy_operations {
32727 void (*power_up)(struct e1000_hw *);
32728 void (*power_down)(struct e1000_hw *);
32729 };
32730 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
32731
32732 /* Function pointers for the NVM. */
32733 struct e1000_nvm_operations {
32734 @@ -829,9 +831,10 @@ struct e1000_nvm_operations {
32735 s32 (*validate)(struct e1000_hw *);
32736 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
32737 };
32738 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
32739
32740 struct e1000_mac_info {
32741 - struct e1000_mac_operations ops;
32742 + e1000_mac_operations_no_const ops;
32743 u8 addr[ETH_ALEN];
32744 u8 perm_addr[ETH_ALEN];
32745
32746 @@ -872,7 +875,7 @@ struct e1000_mac_info {
32747 };
32748
32749 struct e1000_phy_info {
32750 - struct e1000_phy_operations ops;
32751 + e1000_phy_operations_no_const ops;
32752
32753 enum e1000_phy_type type;
32754
32755 @@ -906,7 +909,7 @@ struct e1000_phy_info {
32756 };
32757
32758 struct e1000_nvm_info {
32759 - struct e1000_nvm_operations ops;
32760 + e1000_nvm_operations_no_const ops;
32761
32762 enum e1000_nvm_type type;
32763 enum e1000_nvm_override override;
32764 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
32765 index 4519a13..f97fcd0 100644
32766 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
32767 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
32768 @@ -314,6 +314,7 @@ struct e1000_mac_operations {
32769 s32 (*read_mac_addr)(struct e1000_hw *);
32770 s32 (*get_speed_and_duplex)(struct e1000_hw *, u16 *, u16 *);
32771 };
32772 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32773
32774 struct e1000_phy_operations {
32775 s32 (*acquire)(struct e1000_hw *);
32776 @@ -330,6 +331,7 @@ struct e1000_phy_operations {
32777 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
32778 s32 (*write_reg)(struct e1000_hw *, u32, u16);
32779 };
32780 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
32781
32782 struct e1000_nvm_operations {
32783 s32 (*acquire)(struct e1000_hw *);
32784 @@ -339,6 +341,7 @@ struct e1000_nvm_operations {
32785 s32 (*update)(struct e1000_hw *);
32786 s32 (*validate)(struct e1000_hw *);
32787 };
32788 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
32789
32790 struct e1000_info {
32791 s32 (*get_invariants)(struct e1000_hw *);
32792 @@ -350,7 +353,7 @@ struct e1000_info {
32793 extern const struct e1000_info e1000_82575_info;
32794
32795 struct e1000_mac_info {
32796 - struct e1000_mac_operations ops;
32797 + e1000_mac_operations_no_const ops;
32798
32799 u8 addr[6];
32800 u8 perm_addr[6];
32801 @@ -388,7 +391,7 @@ struct e1000_mac_info {
32802 };
32803
32804 struct e1000_phy_info {
32805 - struct e1000_phy_operations ops;
32806 + e1000_phy_operations_no_const ops;
32807
32808 enum e1000_phy_type type;
32809
32810 @@ -423,7 +426,7 @@ struct e1000_phy_info {
32811 };
32812
32813 struct e1000_nvm_info {
32814 - struct e1000_nvm_operations ops;
32815 + e1000_nvm_operations_no_const ops;
32816 enum e1000_nvm_type type;
32817 enum e1000_nvm_override override;
32818
32819 @@ -468,6 +471,7 @@ struct e1000_mbx_operations {
32820 s32 (*check_for_ack)(struct e1000_hw *, u16);
32821 s32 (*check_for_rst)(struct e1000_hw *, u16);
32822 };
32823 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
32824
32825 struct e1000_mbx_stats {
32826 u32 msgs_tx;
32827 @@ -479,7 +483,7 @@ struct e1000_mbx_stats {
32828 };
32829
32830 struct e1000_mbx_info {
32831 - struct e1000_mbx_operations ops;
32832 + e1000_mbx_operations_no_const ops;
32833 struct e1000_mbx_stats stats;
32834 u32 timeout;
32835 u32 usec_delay;
32836 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
32837 index d7ed58f..64cde36 100644
32838 --- a/drivers/net/ethernet/intel/igbvf/vf.h
32839 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
32840 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
32841 s32 (*read_mac_addr)(struct e1000_hw *);
32842 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
32843 };
32844 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
32845
32846 struct e1000_mac_info {
32847 - struct e1000_mac_operations ops;
32848 + e1000_mac_operations_no_const ops;
32849 u8 addr[6];
32850 u8 perm_addr[6];
32851
32852 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
32853 s32 (*check_for_ack)(struct e1000_hw *);
32854 s32 (*check_for_rst)(struct e1000_hw *);
32855 };
32856 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
32857
32858 struct e1000_mbx_stats {
32859 u32 msgs_tx;
32860 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
32861 };
32862
32863 struct e1000_mbx_info {
32864 - struct e1000_mbx_operations ops;
32865 + e1000_mbx_operations_no_const ops;
32866 struct e1000_mbx_stats stats;
32867 u32 timeout;
32868 u32 usec_delay;
32869 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32870 index 6c5cca8..de8ef63 100644
32871 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32872 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
32873 @@ -2708,6 +2708,7 @@ struct ixgbe_eeprom_operations {
32874 s32 (*update_checksum)(struct ixgbe_hw *);
32875 u16 (*calc_checksum)(struct ixgbe_hw *);
32876 };
32877 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
32878
32879 struct ixgbe_mac_operations {
32880 s32 (*init_hw)(struct ixgbe_hw *);
32881 @@ -2769,6 +2770,7 @@ struct ixgbe_mac_operations {
32882 /* Manageability interface */
32883 s32 (*set_fw_drv_ver)(struct ixgbe_hw *, u8, u8, u8, u8);
32884 };
32885 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
32886
32887 struct ixgbe_phy_operations {
32888 s32 (*identify)(struct ixgbe_hw *);
32889 @@ -2788,9 +2790,10 @@ struct ixgbe_phy_operations {
32890 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
32891 s32 (*check_overtemp)(struct ixgbe_hw *);
32892 };
32893 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
32894
32895 struct ixgbe_eeprom_info {
32896 - struct ixgbe_eeprom_operations ops;
32897 + ixgbe_eeprom_operations_no_const ops;
32898 enum ixgbe_eeprom_type type;
32899 u32 semaphore_delay;
32900 u16 word_size;
32901 @@ -2800,7 +2803,7 @@ struct ixgbe_eeprom_info {
32902
32903 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
32904 struct ixgbe_mac_info {
32905 - struct ixgbe_mac_operations ops;
32906 + ixgbe_mac_operations_no_const ops;
32907 enum ixgbe_mac_type type;
32908 u8 addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
32909 u8 perm_addr[IXGBE_ETH_LENGTH_OF_ADDRESS];
32910 @@ -2828,7 +2831,7 @@ struct ixgbe_mac_info {
32911 };
32912
32913 struct ixgbe_phy_info {
32914 - struct ixgbe_phy_operations ops;
32915 + ixgbe_phy_operations_no_const ops;
32916 struct mdio_if_info mdio;
32917 enum ixgbe_phy_type type;
32918 u32 id;
32919 @@ -2856,6 +2859,7 @@ struct ixgbe_mbx_operations {
32920 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
32921 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
32922 };
32923 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
32924
32925 struct ixgbe_mbx_stats {
32926 u32 msgs_tx;
32927 @@ -2867,7 +2871,7 @@ struct ixgbe_mbx_stats {
32928 };
32929
32930 struct ixgbe_mbx_info {
32931 - struct ixgbe_mbx_operations ops;
32932 + ixgbe_mbx_operations_no_const ops;
32933 struct ixgbe_mbx_stats stats;
32934 u32 timeout;
32935 u32 usec_delay;
32936 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
32937 index 10306b4..28df758 100644
32938 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
32939 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
32940 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
32941 s32 (*clear_vfta)(struct ixgbe_hw *);
32942 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
32943 };
32944 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
32945
32946 enum ixgbe_mac_type {
32947 ixgbe_mac_unknown = 0,
32948 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
32949 };
32950
32951 struct ixgbe_mac_info {
32952 - struct ixgbe_mac_operations ops;
32953 + ixgbe_mac_operations_no_const ops;
32954 u8 addr[6];
32955 u8 perm_addr[6];
32956
32957 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
32958 s32 (*check_for_ack)(struct ixgbe_hw *);
32959 s32 (*check_for_rst)(struct ixgbe_hw *);
32960 };
32961 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
32962
32963 struct ixgbe_mbx_stats {
32964 u32 msgs_tx;
32965 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
32966 };
32967
32968 struct ixgbe_mbx_info {
32969 - struct ixgbe_mbx_operations ops;
32970 + ixgbe_mbx_operations_no_const ops;
32971 struct ixgbe_mbx_stats stats;
32972 u32 timeout;
32973 u32 udelay;
32974 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
32975 index 94bbc85..78c12e6 100644
32976 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
32977 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
32978 @@ -40,6 +40,7 @@
32979 #include <linux/dma-mapping.h>
32980 #include <linux/slab.h>
32981 #include <linux/io-mapping.h>
32982 +#include <linux/sched.h>
32983
32984 #include <linux/mlx4/device.h>
32985 #include <linux/mlx4/doorbell.h>
32986 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
32987 index 5046a64..71ca936 100644
32988 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
32989 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
32990 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
32991 void (*link_down)(struct __vxge_hw_device *devh);
32992 void (*crit_err)(struct __vxge_hw_device *devh,
32993 enum vxge_hw_event type, u64 ext_data);
32994 -};
32995 +} __no_const;
32996
32997 /*
32998 * struct __vxge_hw_blockpool_entry - Block private data structure
32999 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
33000 index 4a518a3..936b334 100644
33001 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
33002 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
33003 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
33004 struct vxge_hw_mempool_dma *dma_object,
33005 u32 index,
33006 u32 is_last);
33007 -};
33008 +} __no_const;
33009
33010 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
33011 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
33012 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
33013 index c8f47f1..5da9840 100644
33014 --- a/drivers/net/ethernet/realtek/r8169.c
33015 +++ b/drivers/net/ethernet/realtek/r8169.c
33016 @@ -698,17 +698,17 @@ struct rtl8169_private {
33017 struct mdio_ops {
33018 void (*write)(void __iomem *, int, int);
33019 int (*read)(void __iomem *, int);
33020 - } mdio_ops;
33021 + } __no_const mdio_ops;
33022
33023 struct pll_power_ops {
33024 void (*down)(struct rtl8169_private *);
33025 void (*up)(struct rtl8169_private *);
33026 - } pll_power_ops;
33027 + } __no_const pll_power_ops;
33028
33029 struct jumbo_ops {
33030 void (*enable)(struct rtl8169_private *);
33031 void (*disable)(struct rtl8169_private *);
33032 - } jumbo_ops;
33033 + } __no_const jumbo_ops;
33034
33035 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
33036 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
33037 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
33038 index 1b4658c..a30dabb 100644
33039 --- a/drivers/net/ethernet/sis/sis190.c
33040 +++ b/drivers/net/ethernet/sis/sis190.c
33041 @@ -1624,7 +1624,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
33042 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
33043 struct net_device *dev)
33044 {
33045 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
33046 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
33047 struct sis190_private *tp = netdev_priv(dev);
33048 struct pci_dev *isa_bridge;
33049 u8 reg, tmp8;
33050 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
33051 index edfa15d..002bfa9 100644
33052 --- a/drivers/net/ppp/ppp_generic.c
33053 +++ b/drivers/net/ppp/ppp_generic.c
33054 @@ -987,7 +987,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33055 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
33056 struct ppp_stats stats;
33057 struct ppp_comp_stats cstats;
33058 - char *vers;
33059
33060 switch (cmd) {
33061 case SIOCGPPPSTATS:
33062 @@ -1009,8 +1008,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33063 break;
33064
33065 case SIOCGPPPVER:
33066 - vers = PPP_VERSION;
33067 - if (copy_to_user(addr, vers, strlen(vers) + 1))
33068 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
33069 break;
33070 err = 0;
33071 break;
33072 diff --git a/drivers/net/tokenring/abyss.c b/drivers/net/tokenring/abyss.c
33073 index 515f122..41dd273 100644
33074 --- a/drivers/net/tokenring/abyss.c
33075 +++ b/drivers/net/tokenring/abyss.c
33076 @@ -451,10 +451,12 @@ static struct pci_driver abyss_driver = {
33077
33078 static int __init abyss_init (void)
33079 {
33080 - abyss_netdev_ops = tms380tr_netdev_ops;
33081 + pax_open_kernel();
33082 + memcpy((void *)&abyss_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33083
33084 - abyss_netdev_ops.ndo_open = abyss_open;
33085 - abyss_netdev_ops.ndo_stop = abyss_close;
33086 + *(void **)&abyss_netdev_ops.ndo_open = abyss_open;
33087 + *(void **)&abyss_netdev_ops.ndo_stop = abyss_close;
33088 + pax_close_kernel();
33089
33090 return pci_register_driver(&abyss_driver);
33091 }
33092 diff --git a/drivers/net/tokenring/madgemc.c b/drivers/net/tokenring/madgemc.c
33093 index 6153cfd..cf69c1c 100644
33094 --- a/drivers/net/tokenring/madgemc.c
33095 +++ b/drivers/net/tokenring/madgemc.c
33096 @@ -744,9 +744,11 @@ static struct mca_driver madgemc_driver = {
33097
33098 static int __init madgemc_init (void)
33099 {
33100 - madgemc_netdev_ops = tms380tr_netdev_ops;
33101 - madgemc_netdev_ops.ndo_open = madgemc_open;
33102 - madgemc_netdev_ops.ndo_stop = madgemc_close;
33103 + pax_open_kernel();
33104 + memcpy((void *)&madgemc_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33105 + *(void **)&madgemc_netdev_ops.ndo_open = madgemc_open;
33106 + *(void **)&madgemc_netdev_ops.ndo_stop = madgemc_close;
33107 + pax_close_kernel();
33108
33109 return mca_register_driver (&madgemc_driver);
33110 }
33111 diff --git a/drivers/net/tokenring/proteon.c b/drivers/net/tokenring/proteon.c
33112 index 8d362e6..f91cc52 100644
33113 --- a/drivers/net/tokenring/proteon.c
33114 +++ b/drivers/net/tokenring/proteon.c
33115 @@ -353,9 +353,11 @@ static int __init proteon_init(void)
33116 struct platform_device *pdev;
33117 int i, num = 0, err = 0;
33118
33119 - proteon_netdev_ops = tms380tr_netdev_ops;
33120 - proteon_netdev_ops.ndo_open = proteon_open;
33121 - proteon_netdev_ops.ndo_stop = tms380tr_close;
33122 + pax_open_kernel();
33123 + memcpy((void *)&proteon_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33124 + *(void **)&proteon_netdev_ops.ndo_open = proteon_open;
33125 + *(void **)&proteon_netdev_ops.ndo_stop = tms380tr_close;
33126 + pax_close_kernel();
33127
33128 err = platform_driver_register(&proteon_driver);
33129 if (err)
33130 diff --git a/drivers/net/tokenring/skisa.c b/drivers/net/tokenring/skisa.c
33131 index 46db5c5..37c1536 100644
33132 --- a/drivers/net/tokenring/skisa.c
33133 +++ b/drivers/net/tokenring/skisa.c
33134 @@ -363,9 +363,11 @@ static int __init sk_isa_init(void)
33135 struct platform_device *pdev;
33136 int i, num = 0, err = 0;
33137
33138 - sk_isa_netdev_ops = tms380tr_netdev_ops;
33139 - sk_isa_netdev_ops.ndo_open = sk_isa_open;
33140 - sk_isa_netdev_ops.ndo_stop = tms380tr_close;
33141 + pax_open_kernel();
33142 + memcpy((void *)&sk_isa_netdev_ops, &tms380tr_netdev_ops, sizeof(tms380tr_netdev_ops));
33143 + *(void **)&sk_isa_netdev_ops.ndo_open = sk_isa_open;
33144 + *(void **)&sk_isa_netdev_ops.ndo_stop = tms380tr_close;
33145 + pax_close_kernel();
33146
33147 err = platform_driver_register(&sk_isa_driver);
33148 if (err)
33149 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
33150 index 304fe78..db112fa 100644
33151 --- a/drivers/net/usb/hso.c
33152 +++ b/drivers/net/usb/hso.c
33153 @@ -71,7 +71,7 @@
33154 #include <asm/byteorder.h>
33155 #include <linux/serial_core.h>
33156 #include <linux/serial.h>
33157 -
33158 +#include <asm/local.h>
33159
33160 #define MOD_AUTHOR "Option Wireless"
33161 #define MOD_DESCRIPTION "USB High Speed Option driver"
33162 @@ -257,7 +257,7 @@ struct hso_serial {
33163
33164 /* from usb_serial_port */
33165 struct tty_struct *tty;
33166 - int open_count;
33167 + local_t open_count;
33168 spinlock_t serial_lock;
33169
33170 int (*write_data) (struct hso_serial *serial);
33171 @@ -1190,7 +1190,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
33172 struct urb *urb;
33173
33174 urb = serial->rx_urb[0];
33175 - if (serial->open_count > 0) {
33176 + if (local_read(&serial->open_count) > 0) {
33177 count = put_rxbuf_data(urb, serial);
33178 if (count == -1)
33179 return;
33180 @@ -1226,7 +1226,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
33181 DUMP1(urb->transfer_buffer, urb->actual_length);
33182
33183 /* Anyone listening? */
33184 - if (serial->open_count == 0)
33185 + if (local_read(&serial->open_count) == 0)
33186 return;
33187
33188 if (status == 0) {
33189 @@ -1311,8 +1311,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
33190 spin_unlock_irq(&serial->serial_lock);
33191
33192 /* check for port already opened, if not set the termios */
33193 - serial->open_count++;
33194 - if (serial->open_count == 1) {
33195 + if (local_inc_return(&serial->open_count) == 1) {
33196 serial->rx_state = RX_IDLE;
33197 /* Force default termio settings */
33198 _hso_serial_set_termios(tty, NULL);
33199 @@ -1324,7 +1323,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
33200 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
33201 if (result) {
33202 hso_stop_serial_device(serial->parent);
33203 - serial->open_count--;
33204 + local_dec(&serial->open_count);
33205 kref_put(&serial->parent->ref, hso_serial_ref_free);
33206 }
33207 } else {
33208 @@ -1361,10 +1360,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
33209
33210 /* reset the rts and dtr */
33211 /* do the actual close */
33212 - serial->open_count--;
33213 + local_dec(&serial->open_count);
33214
33215 - if (serial->open_count <= 0) {
33216 - serial->open_count = 0;
33217 + if (local_read(&serial->open_count) <= 0) {
33218 + local_set(&serial->open_count, 0);
33219 spin_lock_irq(&serial->serial_lock);
33220 if (serial->tty == tty) {
33221 serial->tty->driver_data = NULL;
33222 @@ -1446,7 +1445,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
33223
33224 /* the actual setup */
33225 spin_lock_irqsave(&serial->serial_lock, flags);
33226 - if (serial->open_count)
33227 + if (local_read(&serial->open_count))
33228 _hso_serial_set_termios(tty, old);
33229 else
33230 tty->termios = old;
33231 @@ -1905,7 +1904,7 @@ static void intr_callback(struct urb *urb)
33232 D1("Pending read interrupt on port %d\n", i);
33233 spin_lock(&serial->serial_lock);
33234 if (serial->rx_state == RX_IDLE &&
33235 - serial->open_count > 0) {
33236 + local_read(&serial->open_count) > 0) {
33237 /* Setup and send a ctrl req read on
33238 * port i */
33239 if (!serial->rx_urb_filled[0]) {
33240 @@ -3098,7 +3097,7 @@ static int hso_resume(struct usb_interface *iface)
33241 /* Start all serial ports */
33242 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
33243 if (serial_table[i] && (serial_table[i]->interface == iface)) {
33244 - if (dev2ser(serial_table[i])->open_count) {
33245 + if (local_read(&dev2ser(serial_table[i])->open_count)) {
33246 result =
33247 hso_start_serial_device(serial_table[i], GFP_NOIO);
33248 hso_kick_transmit(dev2ser(serial_table[i]));
33249 diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
33250 index e662cbc..8d4a102 100644
33251 --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
33252 +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
33253 @@ -601,8 +601,7 @@ vmxnet3_set_rss_indir(struct net_device *netdev,
33254 * Return with error code if any of the queue indices
33255 * is out of range
33256 */
33257 - if (p->ring_index[i] < 0 ||
33258 - p->ring_index[i] >= adapter->num_rx_queues)
33259 + if (p->ring_index[i] >= adapter->num_rx_queues)
33260 return -EINVAL;
33261 }
33262
33263 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
33264 index 0f9ee46..e2d6e65 100644
33265 --- a/drivers/net/wireless/ath/ath.h
33266 +++ b/drivers/net/wireless/ath/ath.h
33267 @@ -119,6 +119,7 @@ struct ath_ops {
33268 void (*write_flush) (void *);
33269 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
33270 };
33271 +typedef struct ath_ops __no_const ath_ops_no_const;
33272
33273 struct ath_common;
33274 struct ath_bus_ops;
33275 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33276 index b592016..fe47870 100644
33277 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33278 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
33279 @@ -183,8 +183,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33280 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
33281 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
33282
33283 - ACCESS_ONCE(ads->ds_link) = i->link;
33284 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
33285 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
33286 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
33287
33288 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
33289 ctl6 = SM(i->keytype, AR_EncrType);
33290 @@ -198,26 +198,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33291
33292 if ((i->is_first || i->is_last) &&
33293 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
33294 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
33295 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
33296 | set11nTries(i->rates, 1)
33297 | set11nTries(i->rates, 2)
33298 | set11nTries(i->rates, 3)
33299 | (i->dur_update ? AR_DurUpdateEna : 0)
33300 | SM(0, AR_BurstDur);
33301
33302 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
33303 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
33304 | set11nRate(i->rates, 1)
33305 | set11nRate(i->rates, 2)
33306 | set11nRate(i->rates, 3);
33307 } else {
33308 - ACCESS_ONCE(ads->ds_ctl2) = 0;
33309 - ACCESS_ONCE(ads->ds_ctl3) = 0;
33310 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
33311 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
33312 }
33313
33314 if (!i->is_first) {
33315 - ACCESS_ONCE(ads->ds_ctl0) = 0;
33316 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
33317 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
33318 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
33319 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
33320 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
33321 return;
33322 }
33323
33324 @@ -242,7 +242,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33325 break;
33326 }
33327
33328 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
33329 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
33330 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
33331 | SM(i->txpower, AR_XmitPower)
33332 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
33333 @@ -252,19 +252,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33334 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
33335 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
33336
33337 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
33338 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
33339 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
33340 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
33341
33342 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
33343 return;
33344
33345 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
33346 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
33347 | set11nPktDurRTSCTS(i->rates, 1);
33348
33349 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
33350 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
33351 | set11nPktDurRTSCTS(i->rates, 3);
33352
33353 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
33354 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
33355 | set11nRateFlags(i->rates, 1)
33356 | set11nRateFlags(i->rates, 2)
33357 | set11nRateFlags(i->rates, 3)
33358 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33359 index f5ae3c6..7936af3 100644
33360 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33361 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
33362 @@ -35,47 +35,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33363 (i->qcu << AR_TxQcuNum_S) | 0x17;
33364
33365 checksum += val;
33366 - ACCESS_ONCE(ads->info) = val;
33367 + ACCESS_ONCE_RW(ads->info) = val;
33368
33369 checksum += i->link;
33370 - ACCESS_ONCE(ads->link) = i->link;
33371 + ACCESS_ONCE_RW(ads->link) = i->link;
33372
33373 checksum += i->buf_addr[0];
33374 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
33375 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
33376 checksum += i->buf_addr[1];
33377 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
33378 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
33379 checksum += i->buf_addr[2];
33380 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
33381 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
33382 checksum += i->buf_addr[3];
33383 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
33384 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
33385
33386 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
33387 - ACCESS_ONCE(ads->ctl3) = val;
33388 + ACCESS_ONCE_RW(ads->ctl3) = val;
33389 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
33390 - ACCESS_ONCE(ads->ctl5) = val;
33391 + ACCESS_ONCE_RW(ads->ctl5) = val;
33392 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
33393 - ACCESS_ONCE(ads->ctl7) = val;
33394 + ACCESS_ONCE_RW(ads->ctl7) = val;
33395 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
33396 - ACCESS_ONCE(ads->ctl9) = val;
33397 + ACCESS_ONCE_RW(ads->ctl9) = val;
33398
33399 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
33400 - ACCESS_ONCE(ads->ctl10) = checksum;
33401 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
33402
33403 if (i->is_first || i->is_last) {
33404 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
33405 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
33406 | set11nTries(i->rates, 1)
33407 | set11nTries(i->rates, 2)
33408 | set11nTries(i->rates, 3)
33409 | (i->dur_update ? AR_DurUpdateEna : 0)
33410 | SM(0, AR_BurstDur);
33411
33412 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
33413 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
33414 | set11nRate(i->rates, 1)
33415 | set11nRate(i->rates, 2)
33416 | set11nRate(i->rates, 3);
33417 } else {
33418 - ACCESS_ONCE(ads->ctl13) = 0;
33419 - ACCESS_ONCE(ads->ctl14) = 0;
33420 + ACCESS_ONCE_RW(ads->ctl13) = 0;
33421 + ACCESS_ONCE_RW(ads->ctl14) = 0;
33422 }
33423
33424 ads->ctl20 = 0;
33425 @@ -84,17 +84,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33426
33427 ctl17 = SM(i->keytype, AR_EncrType);
33428 if (!i->is_first) {
33429 - ACCESS_ONCE(ads->ctl11) = 0;
33430 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
33431 - ACCESS_ONCE(ads->ctl15) = 0;
33432 - ACCESS_ONCE(ads->ctl16) = 0;
33433 - ACCESS_ONCE(ads->ctl17) = ctl17;
33434 - ACCESS_ONCE(ads->ctl18) = 0;
33435 - ACCESS_ONCE(ads->ctl19) = 0;
33436 + ACCESS_ONCE_RW(ads->ctl11) = 0;
33437 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
33438 + ACCESS_ONCE_RW(ads->ctl15) = 0;
33439 + ACCESS_ONCE_RW(ads->ctl16) = 0;
33440 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
33441 + ACCESS_ONCE_RW(ads->ctl18) = 0;
33442 + ACCESS_ONCE_RW(ads->ctl19) = 0;
33443 return;
33444 }
33445
33446 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
33447 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
33448 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
33449 | SM(i->txpower, AR_XmitPower)
33450 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
33451 @@ -130,22 +130,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
33452 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
33453 ctl12 |= SM(val, AR_PAPRDChainMask);
33454
33455 - ACCESS_ONCE(ads->ctl12) = ctl12;
33456 - ACCESS_ONCE(ads->ctl17) = ctl17;
33457 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
33458 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
33459
33460 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
33461 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
33462 | set11nPktDurRTSCTS(i->rates, 1);
33463
33464 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
33465 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
33466 | set11nPktDurRTSCTS(i->rates, 3);
33467
33468 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
33469 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
33470 | set11nRateFlags(i->rates, 1)
33471 | set11nRateFlags(i->rates, 2)
33472 | set11nRateFlags(i->rates, 3)
33473 | SM(i->rtscts_rate, AR_RTSCTSRate);
33474
33475 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
33476 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
33477 }
33478
33479 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
33480 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
33481 index f389b3c..7359e18 100644
33482 --- a/drivers/net/wireless/ath/ath9k/hw.h
33483 +++ b/drivers/net/wireless/ath/ath9k/hw.h
33484 @@ -605,7 +605,7 @@ struct ath_hw_private_ops {
33485
33486 /* ANI */
33487 void (*ani_cache_ini_regs)(struct ath_hw *ah);
33488 -};
33489 +} __no_const;
33490
33491 /**
33492 * struct ath_hw_ops - callbacks used by hardware code and driver code
33493 @@ -635,7 +635,7 @@ struct ath_hw_ops {
33494 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
33495 struct ath_hw_antcomb_conf *antconf);
33496
33497 -};
33498 +} __no_const;
33499
33500 struct ath_nf_limits {
33501 s16 max;
33502 @@ -655,7 +655,7 @@ enum ath_cal_list {
33503 #define AH_FASTCC 0x4
33504
33505 struct ath_hw {
33506 - struct ath_ops reg_ops;
33507 + ath_ops_no_const reg_ops;
33508
33509 struct ieee80211_hw *hw;
33510 struct ath_common common;
33511 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33512 index bea8524..c677c06 100644
33513 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33514 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
33515 @@ -547,7 +547,7 @@ struct phy_func_ptr {
33516 void (*carrsuppr)(struct brcms_phy *);
33517 s32 (*rxsigpwr)(struct brcms_phy *, s32);
33518 void (*detach)(struct brcms_phy *);
33519 -};
33520 +} __no_const;
33521
33522 struct brcms_phy {
33523 struct brcms_phy_pub pubpi_ro;
33524 diff --git a/drivers/net/wireless/iwlegacy/iwl3945-base.c b/drivers/net/wireless/iwlegacy/iwl3945-base.c
33525 index 05f2ad1..ae00eea 100644
33526 --- a/drivers/net/wireless/iwlegacy/iwl3945-base.c
33527 +++ b/drivers/net/wireless/iwlegacy/iwl3945-base.c
33528 @@ -3685,7 +3685,9 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
33529 */
33530 if (iwl3945_mod_params.disable_hw_scan) {
33531 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
33532 - iwl3945_hw_ops.hw_scan = NULL;
33533 + pax_open_kernel();
33534 + *(void **)&iwl3945_hw_ops.hw_scan = NULL;
33535 + pax_close_kernel();
33536 }
33537
33538 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
33539 diff --git a/drivers/net/wireless/iwlwifi/iwl-debug.h b/drivers/net/wireless/iwlwifi/iwl-debug.h
33540 index 69a77e2..552b42c 100644
33541 --- a/drivers/net/wireless/iwlwifi/iwl-debug.h
33542 +++ b/drivers/net/wireless/iwlwifi/iwl-debug.h
33543 @@ -71,8 +71,8 @@ do { \
33544 } while (0)
33545
33546 #else
33547 -#define IWL_DEBUG(m, level, fmt, args...)
33548 -#define IWL_DEBUG_LIMIT(m, level, fmt, args...)
33549 +#define IWL_DEBUG(m, level, fmt, args...) do {} while (0)
33550 +#define IWL_DEBUG_LIMIT(m, level, fmt, args...) do {} while (0)
33551 #define iwl_print_hex_dump(m, level, p, len)
33552 #endif /* CONFIG_IWLWIFI_DEBUG */
33553
33554 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
33555 index 523ad55..f8c5dc5 100644
33556 --- a/drivers/net/wireless/mac80211_hwsim.c
33557 +++ b/drivers/net/wireless/mac80211_hwsim.c
33558 @@ -1678,9 +1678,11 @@ static int __init init_mac80211_hwsim(void)
33559 return -EINVAL;
33560
33561 if (fake_hw_scan) {
33562 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
33563 - mac80211_hwsim_ops.sw_scan_start = NULL;
33564 - mac80211_hwsim_ops.sw_scan_complete = NULL;
33565 + pax_open_kernel();
33566 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
33567 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
33568 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
33569 + pax_close_kernel();
33570 }
33571
33572 spin_lock_init(&hwsim_radio_lock);
33573 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
33574 index 30f138b..c904585 100644
33575 --- a/drivers/net/wireless/mwifiex/main.h
33576 +++ b/drivers/net/wireless/mwifiex/main.h
33577 @@ -543,7 +543,7 @@ struct mwifiex_if_ops {
33578 void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
33579 int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
33580 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
33581 -};
33582 +} __no_const;
33583
33584 struct mwifiex_adapter {
33585 u8 iface_type;
33586 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
33587 index 0c13840..a5c3ed6 100644
33588 --- a/drivers/net/wireless/rndis_wlan.c
33589 +++ b/drivers/net/wireless/rndis_wlan.c
33590 @@ -1275,7 +1275,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
33591
33592 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
33593
33594 - if (rts_threshold < 0 || rts_threshold > 2347)
33595 + if (rts_threshold > 2347)
33596 rts_threshold = 2347;
33597
33598 tmp = cpu_to_le32(rts_threshold);
33599 diff --git a/drivers/net/wireless/wl1251/wl1251.h b/drivers/net/wireless/wl1251/wl1251.h
33600 index a77f1bb..c608b2b 100644
33601 --- a/drivers/net/wireless/wl1251/wl1251.h
33602 +++ b/drivers/net/wireless/wl1251/wl1251.h
33603 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
33604 void (*reset)(struct wl1251 *wl);
33605 void (*enable_irq)(struct wl1251 *wl);
33606 void (*disable_irq)(struct wl1251 *wl);
33607 -};
33608 +} __no_const;
33609
33610 struct wl1251 {
33611 struct ieee80211_hw *hw;
33612 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
33613 index f34b5b2..b5abb9f 100644
33614 --- a/drivers/oprofile/buffer_sync.c
33615 +++ b/drivers/oprofile/buffer_sync.c
33616 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
33617 if (cookie == NO_COOKIE)
33618 offset = pc;
33619 if (cookie == INVALID_COOKIE) {
33620 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
33621 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
33622 offset = pc;
33623 }
33624 if (cookie != last_cookie) {
33625 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
33626 /* add userspace sample */
33627
33628 if (!mm) {
33629 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
33630 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
33631 return 0;
33632 }
33633
33634 cookie = lookup_dcookie(mm, s->eip, &offset);
33635
33636 if (cookie == INVALID_COOKIE) {
33637 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
33638 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
33639 return 0;
33640 }
33641
33642 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
33643 /* ignore backtraces if failed to add a sample */
33644 if (state == sb_bt_start) {
33645 state = sb_bt_ignore;
33646 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
33647 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
33648 }
33649 }
33650 release_mm(mm);
33651 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
33652 index c0cc4e7..44d4e54 100644
33653 --- a/drivers/oprofile/event_buffer.c
33654 +++ b/drivers/oprofile/event_buffer.c
33655 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
33656 }
33657
33658 if (buffer_pos == buffer_size) {
33659 - atomic_inc(&oprofile_stats.event_lost_overflow);
33660 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
33661 return;
33662 }
33663
33664 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
33665 index f8c752e..28bf4fc 100644
33666 --- a/drivers/oprofile/oprof.c
33667 +++ b/drivers/oprofile/oprof.c
33668 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
33669 if (oprofile_ops.switch_events())
33670 return;
33671
33672 - atomic_inc(&oprofile_stats.multiplex_counter);
33673 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
33674 start_switch_worker();
33675 }
33676
33677 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
33678 index 917d28e..d62d981 100644
33679 --- a/drivers/oprofile/oprofile_stats.c
33680 +++ b/drivers/oprofile/oprofile_stats.c
33681 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
33682 cpu_buf->sample_invalid_eip = 0;
33683 }
33684
33685 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
33686 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
33687 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
33688 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
33689 - atomic_set(&oprofile_stats.multiplex_counter, 0);
33690 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
33691 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
33692 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
33693 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
33694 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
33695 }
33696
33697
33698 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
33699 index 38b6fc0..b5cbfce 100644
33700 --- a/drivers/oprofile/oprofile_stats.h
33701 +++ b/drivers/oprofile/oprofile_stats.h
33702 @@ -13,11 +13,11 @@
33703 #include <linux/atomic.h>
33704
33705 struct oprofile_stat_struct {
33706 - atomic_t sample_lost_no_mm;
33707 - atomic_t sample_lost_no_mapping;
33708 - atomic_t bt_lost_no_mapping;
33709 - atomic_t event_lost_overflow;
33710 - atomic_t multiplex_counter;
33711 + atomic_unchecked_t sample_lost_no_mm;
33712 + atomic_unchecked_t sample_lost_no_mapping;
33713 + atomic_unchecked_t bt_lost_no_mapping;
33714 + atomic_unchecked_t event_lost_overflow;
33715 + atomic_unchecked_t multiplex_counter;
33716 };
33717
33718 extern struct oprofile_stat_struct oprofile_stats;
33719 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
33720 index 2f0aa0f..90fab02 100644
33721 --- a/drivers/oprofile/oprofilefs.c
33722 +++ b/drivers/oprofile/oprofilefs.c
33723 @@ -193,7 +193,7 @@ static const struct file_operations atomic_ro_fops = {
33724
33725
33726 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
33727 - char const *name, atomic_t *val)
33728 + char const *name, atomic_unchecked_t *val)
33729 {
33730 return __oprofilefs_create_file(sb, root, name,
33731 &atomic_ro_fops, 0444, val);
33732 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
33733 index 3f56bc0..707d642 100644
33734 --- a/drivers/parport/procfs.c
33735 +++ b/drivers/parport/procfs.c
33736 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
33737
33738 *ppos += len;
33739
33740 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
33741 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
33742 }
33743
33744 #ifdef CONFIG_PARPORT_1284
33745 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
33746
33747 *ppos += len;
33748
33749 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
33750 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
33751 }
33752 #endif /* IEEE1284.3 support. */
33753
33754 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
33755 index 9fff878..ad0ad53 100644
33756 --- a/drivers/pci/hotplug/cpci_hotplug.h
33757 +++ b/drivers/pci/hotplug/cpci_hotplug.h
33758 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
33759 int (*hardware_test) (struct slot* slot, u32 value);
33760 u8 (*get_power) (struct slot* slot);
33761 int (*set_power) (struct slot* slot, int value);
33762 -};
33763 +} __no_const;
33764
33765 struct cpci_hp_controller {
33766 unsigned int irq;
33767 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
33768 index 76ba8a1..20ca857 100644
33769 --- a/drivers/pci/hotplug/cpqphp_nvram.c
33770 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
33771 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
33772
33773 void compaq_nvram_init (void __iomem *rom_start)
33774 {
33775 +
33776 +#ifndef CONFIG_PAX_KERNEXEC
33777 if (rom_start) {
33778 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
33779 }
33780 +#endif
33781 +
33782 dbg("int15 entry = %p\n", compaq_int15_entry_point);
33783
33784 /* initialize our int15 lock */
33785 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
33786 index 1cfbf22..be96487 100644
33787 --- a/drivers/pci/pcie/aspm.c
33788 +++ b/drivers/pci/pcie/aspm.c
33789 @@ -27,9 +27,9 @@
33790 #define MODULE_PARAM_PREFIX "pcie_aspm."
33791
33792 /* Note: those are not register definitions */
33793 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
33794 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
33795 -#define ASPM_STATE_L1 (4) /* L1 state */
33796 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
33797 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
33798 +#define ASPM_STATE_L1 (4U) /* L1 state */
33799 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
33800 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
33801
33802 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
33803 index 04e74f4..a960176 100644
33804 --- a/drivers/pci/probe.c
33805 +++ b/drivers/pci/probe.c
33806 @@ -136,7 +136,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
33807 u32 l, sz, mask;
33808 u16 orig_cmd;
33809
33810 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
33811 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
33812
33813 if (!dev->mmio_always_on) {
33814 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
33815 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
33816 index 27911b5..5b6db88 100644
33817 --- a/drivers/pci/proc.c
33818 +++ b/drivers/pci/proc.c
33819 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
33820 static int __init pci_proc_init(void)
33821 {
33822 struct pci_dev *dev = NULL;
33823 +
33824 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
33825 +#ifdef CONFIG_GRKERNSEC_PROC_USER
33826 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
33827 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33828 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
33829 +#endif
33830 +#else
33831 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
33832 +#endif
33833 proc_create("devices", 0, proc_bus_pci_dir,
33834 &proc_bus_pci_dev_operations);
33835 proc_initialized = 1;
33836 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
33837 index 7b82868..b9344c9 100644
33838 --- a/drivers/platform/x86/thinkpad_acpi.c
33839 +++ b/drivers/platform/x86/thinkpad_acpi.c
33840 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
33841 return 0;
33842 }
33843
33844 -void static hotkey_mask_warn_incomplete_mask(void)
33845 +static void hotkey_mask_warn_incomplete_mask(void)
33846 {
33847 /* log only what the user can fix... */
33848 const u32 wantedmask = hotkey_driver_mask &
33849 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
33850 }
33851 }
33852
33853 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33854 - struct tp_nvram_state *newn,
33855 - const u32 event_mask)
33856 -{
33857 -
33858 #define TPACPI_COMPARE_KEY(__scancode, __member) \
33859 do { \
33860 if ((event_mask & (1 << __scancode)) && \
33861 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33862 tpacpi_hotkey_send_key(__scancode); \
33863 } while (0)
33864
33865 - void issue_volchange(const unsigned int oldvol,
33866 - const unsigned int newvol)
33867 - {
33868 - unsigned int i = oldvol;
33869 +static void issue_volchange(const unsigned int oldvol,
33870 + const unsigned int newvol,
33871 + const u32 event_mask)
33872 +{
33873 + unsigned int i = oldvol;
33874
33875 - while (i > newvol) {
33876 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
33877 - i--;
33878 - }
33879 - while (i < newvol) {
33880 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33881 - i++;
33882 - }
33883 + while (i > newvol) {
33884 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
33885 + i--;
33886 }
33887 + while (i < newvol) {
33888 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33889 + i++;
33890 + }
33891 +}
33892
33893 - void issue_brightnesschange(const unsigned int oldbrt,
33894 - const unsigned int newbrt)
33895 - {
33896 - unsigned int i = oldbrt;
33897 +static void issue_brightnesschange(const unsigned int oldbrt,
33898 + const unsigned int newbrt,
33899 + const u32 event_mask)
33900 +{
33901 + unsigned int i = oldbrt;
33902
33903 - while (i > newbrt) {
33904 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
33905 - i--;
33906 - }
33907 - while (i < newbrt) {
33908 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33909 - i++;
33910 - }
33911 + while (i > newbrt) {
33912 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
33913 + i--;
33914 + }
33915 + while (i < newbrt) {
33916 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33917 + i++;
33918 }
33919 +}
33920
33921 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33922 + struct tp_nvram_state *newn,
33923 + const u32 event_mask)
33924 +{
33925 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
33926 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
33927 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
33928 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33929 oldn->volume_level != newn->volume_level) {
33930 /* recently muted, or repeated mute keypress, or
33931 * multiple presses ending in mute */
33932 - issue_volchange(oldn->volume_level, newn->volume_level);
33933 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
33934 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
33935 }
33936 } else {
33937 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33938 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
33939 }
33940 if (oldn->volume_level != newn->volume_level) {
33941 - issue_volchange(oldn->volume_level, newn->volume_level);
33942 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
33943 } else if (oldn->volume_toggle != newn->volume_toggle) {
33944 /* repeated vol up/down keypress at end of scale ? */
33945 if (newn->volume_level == 0)
33946 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33947 /* handle brightness */
33948 if (oldn->brightness_level != newn->brightness_level) {
33949 issue_brightnesschange(oldn->brightness_level,
33950 - newn->brightness_level);
33951 + newn->brightness_level,
33952 + event_mask);
33953 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
33954 /* repeated key presses that didn't change state */
33955 if (newn->brightness_level == 0)
33956 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
33957 && !tp_features.bright_unkfw)
33958 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
33959 }
33960 +}
33961
33962 #undef TPACPI_COMPARE_KEY
33963 #undef TPACPI_MAY_SEND_KEY
33964 -}
33965
33966 /*
33967 * Polling driver
33968 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
33969 index b859d16..5cc6b1a 100644
33970 --- a/drivers/pnp/pnpbios/bioscalls.c
33971 +++ b/drivers/pnp/pnpbios/bioscalls.c
33972 @@ -59,7 +59,7 @@ do { \
33973 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
33974 } while(0)
33975
33976 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
33977 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
33978 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
33979
33980 /*
33981 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
33982
33983 cpu = get_cpu();
33984 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
33985 +
33986 + pax_open_kernel();
33987 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
33988 + pax_close_kernel();
33989
33990 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
33991 spin_lock_irqsave(&pnp_bios_lock, flags);
33992 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
33993 :"memory");
33994 spin_unlock_irqrestore(&pnp_bios_lock, flags);
33995
33996 + pax_open_kernel();
33997 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
33998 + pax_close_kernel();
33999 +
34000 put_cpu();
34001
34002 /* If we get here and this is set then the PnP BIOS faulted on us. */
34003 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
34004 return status;
34005 }
34006
34007 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
34008 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
34009 {
34010 int i;
34011
34012 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
34013 pnp_bios_callpoint.offset = header->fields.pm16offset;
34014 pnp_bios_callpoint.segment = PNP_CS16;
34015
34016 + pax_open_kernel();
34017 +
34018 for_each_possible_cpu(i) {
34019 struct desc_struct *gdt = get_cpu_gdt_table(i);
34020 if (!gdt)
34021 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
34022 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
34023 (unsigned long)__va(header->fields.pm16dseg));
34024 }
34025 +
34026 + pax_close_kernel();
34027 }
34028 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
34029 index b0ecacb..7c9da2e 100644
34030 --- a/drivers/pnp/resource.c
34031 +++ b/drivers/pnp/resource.c
34032 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
34033 return 1;
34034
34035 /* check if the resource is valid */
34036 - if (*irq < 0 || *irq > 15)
34037 + if (*irq > 15)
34038 return 0;
34039
34040 /* check if the resource is reserved */
34041 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
34042 return 1;
34043
34044 /* check if the resource is valid */
34045 - if (*dma < 0 || *dma == 4 || *dma > 7)
34046 + if (*dma == 4 || *dma > 7)
34047 return 0;
34048
34049 /* check if the resource is reserved */
34050 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
34051 index bb16f5b..c751eef 100644
34052 --- a/drivers/power/bq27x00_battery.c
34053 +++ b/drivers/power/bq27x00_battery.c
34054 @@ -67,7 +67,7 @@
34055 struct bq27x00_device_info;
34056 struct bq27x00_access_methods {
34057 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
34058 -};
34059 +} __no_const;
34060
34061 enum bq27x00_chip { BQ27000, BQ27500 };
34062
34063 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
34064 index 33f5d9a..d957d3f 100644
34065 --- a/drivers/regulator/max8660.c
34066 +++ b/drivers/regulator/max8660.c
34067 @@ -383,8 +383,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
34068 max8660->shadow_regs[MAX8660_OVER1] = 5;
34069 } else {
34070 /* Otherwise devices can be toggled via software */
34071 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
34072 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
34073 + pax_open_kernel();
34074 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
34075 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
34076 + pax_close_kernel();
34077 }
34078
34079 /*
34080 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
34081 index 023d17d..74ef35b 100644
34082 --- a/drivers/regulator/mc13892-regulator.c
34083 +++ b/drivers/regulator/mc13892-regulator.c
34084 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
34085 }
34086 mc13xxx_unlock(mc13892);
34087
34088 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
34089 + pax_open_kernel();
34090 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
34091 = mc13892_vcam_set_mode;
34092 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
34093 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
34094 = mc13892_vcam_get_mode;
34095 + pax_close_kernel();
34096 for (i = 0; i < pdata->num_regulators; i++) {
34097 init_data = &pdata->regulators[i];
34098 priv->regulators[i] = regulator_register(
34099 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
34100 index cace6d3..f623fda 100644
34101 --- a/drivers/rtc/rtc-dev.c
34102 +++ b/drivers/rtc/rtc-dev.c
34103 @@ -14,6 +14,7 @@
34104 #include <linux/module.h>
34105 #include <linux/rtc.h>
34106 #include <linux/sched.h>
34107 +#include <linux/grsecurity.h>
34108 #include "rtc-core.h"
34109
34110 static dev_t rtc_devt;
34111 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
34112 if (copy_from_user(&tm, uarg, sizeof(tm)))
34113 return -EFAULT;
34114
34115 + gr_log_timechange();
34116 +
34117 return rtc_set_time(rtc, &tm);
34118
34119 case RTC_PIE_ON:
34120 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
34121 index ffb5878..e6d785c 100644
34122 --- a/drivers/scsi/aacraid/aacraid.h
34123 +++ b/drivers/scsi/aacraid/aacraid.h
34124 @@ -492,7 +492,7 @@ struct adapter_ops
34125 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
34126 /* Administrative operations */
34127 int (*adapter_comm)(struct aac_dev * dev, int comm);
34128 -};
34129 +} __no_const;
34130
34131 /*
34132 * Define which interrupt handler needs to be installed
34133 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
34134 index 705e13e..91c873c 100644
34135 --- a/drivers/scsi/aacraid/linit.c
34136 +++ b/drivers/scsi/aacraid/linit.c
34137 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
34138 #elif defined(__devinitconst)
34139 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
34140 #else
34141 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
34142 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
34143 #endif
34144 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
34145 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
34146 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
34147 index d5ff142..49c0ebb 100644
34148 --- a/drivers/scsi/aic94xx/aic94xx_init.c
34149 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
34150 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
34151 .lldd_control_phy = asd_control_phy,
34152 };
34153
34154 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
34155 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
34156 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
34157 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
34158 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
34159 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
34160 index a796de9..1ef20e1 100644
34161 --- a/drivers/scsi/bfa/bfa.h
34162 +++ b/drivers/scsi/bfa/bfa.h
34163 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
34164 u32 *end);
34165 int cpe_vec_q0;
34166 int rme_vec_q0;
34167 -};
34168 +} __no_const;
34169 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
34170
34171 struct bfa_faa_cbfn_s {
34172 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
34173 index e07bd47..cd1bbbb 100644
34174 --- a/drivers/scsi/bfa/bfa_fcpim.c
34175 +++ b/drivers/scsi/bfa/bfa_fcpim.c
34176 @@ -4121,7 +4121,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
34177
34178 bfa_iotag_attach(fcp);
34179
34180 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
34181 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
34182 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
34183 (fcp->num_itns * sizeof(struct bfa_itn_s));
34184 memset(fcp->itn_arr, 0,
34185 @@ -4179,7 +4179,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
34186 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
34187 {
34188 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
34189 - struct bfa_itn_s *itn;
34190 + bfa_itn_s_no_const *itn;
34191
34192 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
34193 itn->isr = isr;
34194 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
34195 index 1080bcb..a3b39e3 100644
34196 --- a/drivers/scsi/bfa/bfa_fcpim.h
34197 +++ b/drivers/scsi/bfa/bfa_fcpim.h
34198 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
34199 struct bfa_itn_s {
34200 bfa_isr_func_t isr;
34201 };
34202 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
34203
34204 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
34205 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
34206 @@ -149,7 +150,7 @@ struct bfa_fcp_mod_s {
34207 struct list_head iotag_tio_free_q; /* free IO resources */
34208 struct list_head iotag_unused_q; /* unused IO resources*/
34209 struct bfa_iotag_s *iotag_arr;
34210 - struct bfa_itn_s *itn_arr;
34211 + bfa_itn_s_no_const *itn_arr;
34212 int num_ioim_reqs;
34213 int num_fwtio_reqs;
34214 int num_itns;
34215 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
34216 index 546d46b..642fa5b 100644
34217 --- a/drivers/scsi/bfa/bfa_ioc.h
34218 +++ b/drivers/scsi/bfa/bfa_ioc.h
34219 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
34220 bfa_ioc_disable_cbfn_t disable_cbfn;
34221 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
34222 bfa_ioc_reset_cbfn_t reset_cbfn;
34223 -};
34224 +} __no_const;
34225
34226 /*
34227 * IOC event notification mechanism.
34228 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
34229 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
34230 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
34231 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
34232 -};
34233 +} __no_const;
34234
34235 /*
34236 * Queue element to wait for room in request queue. FIFO order is
34237 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
34238 index 351dc0b..951dc32 100644
34239 --- a/drivers/scsi/hosts.c
34240 +++ b/drivers/scsi/hosts.c
34241 @@ -42,7 +42,7 @@
34242 #include "scsi_logging.h"
34243
34244
34245 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
34246 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
34247
34248
34249 static void scsi_host_cls_release(struct device *dev)
34250 @@ -357,7 +357,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
34251 * subtract one because we increment first then return, but we need to
34252 * know what the next host number was before increment
34253 */
34254 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
34255 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
34256 shost->dma_channel = 0xff;
34257
34258 /* These three are default values which can be overridden */
34259 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
34260 index 865d452..e9b7fa7 100644
34261 --- a/drivers/scsi/hpsa.c
34262 +++ b/drivers/scsi/hpsa.c
34263 @@ -505,7 +505,7 @@ static inline u32 next_command(struct ctlr_info *h)
34264 u32 a;
34265
34266 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
34267 - return h->access.command_completed(h);
34268 + return h->access->command_completed(h);
34269
34270 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
34271 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
34272 @@ -2989,7 +2989,7 @@ static void start_io(struct ctlr_info *h)
34273 while (!list_empty(&h->reqQ)) {
34274 c = list_entry(h->reqQ.next, struct CommandList, list);
34275 /* can't do anything if fifo is full */
34276 - if ((h->access.fifo_full(h))) {
34277 + if ((h->access->fifo_full(h))) {
34278 dev_warn(&h->pdev->dev, "fifo full\n");
34279 break;
34280 }
34281 @@ -2999,7 +2999,7 @@ static void start_io(struct ctlr_info *h)
34282 h->Qdepth--;
34283
34284 /* Tell the controller execute command */
34285 - h->access.submit_command(h, c);
34286 + h->access->submit_command(h, c);
34287
34288 /* Put job onto the completed Q */
34289 addQ(&h->cmpQ, c);
34290 @@ -3008,17 +3008,17 @@ static void start_io(struct ctlr_info *h)
34291
34292 static inline unsigned long get_next_completion(struct ctlr_info *h)
34293 {
34294 - return h->access.command_completed(h);
34295 + return h->access->command_completed(h);
34296 }
34297
34298 static inline bool interrupt_pending(struct ctlr_info *h)
34299 {
34300 - return h->access.intr_pending(h);
34301 + return h->access->intr_pending(h);
34302 }
34303
34304 static inline long interrupt_not_for_us(struct ctlr_info *h)
34305 {
34306 - return (h->access.intr_pending(h) == 0) ||
34307 + return (h->access->intr_pending(h) == 0) ||
34308 (h->interrupts_enabled == 0);
34309 }
34310
34311 @@ -3917,7 +3917,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
34312 if (prod_index < 0)
34313 return -ENODEV;
34314 h->product_name = products[prod_index].product_name;
34315 - h->access = *(products[prod_index].access);
34316 + h->access = products[prod_index].access;
34317
34318 if (hpsa_board_disabled(h->pdev)) {
34319 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
34320 @@ -4162,7 +4162,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
34321
34322 assert_spin_locked(&lockup_detector_lock);
34323 remove_ctlr_from_lockup_detector_list(h);
34324 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34325 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34326 spin_lock_irqsave(&h->lock, flags);
34327 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
34328 spin_unlock_irqrestore(&h->lock, flags);
34329 @@ -4340,7 +4340,7 @@ reinit_after_soft_reset:
34330 }
34331
34332 /* make sure the board interrupts are off */
34333 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34334 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34335
34336 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
34337 goto clean2;
34338 @@ -4374,7 +4374,7 @@ reinit_after_soft_reset:
34339 * fake ones to scoop up any residual completions.
34340 */
34341 spin_lock_irqsave(&h->lock, flags);
34342 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34343 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34344 spin_unlock_irqrestore(&h->lock, flags);
34345 free_irq(h->intr[h->intr_mode], h);
34346 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
34347 @@ -4393,9 +4393,9 @@ reinit_after_soft_reset:
34348 dev_info(&h->pdev->dev, "Board READY.\n");
34349 dev_info(&h->pdev->dev,
34350 "Waiting for stale completions to drain.\n");
34351 - h->access.set_intr_mask(h, HPSA_INTR_ON);
34352 + h->access->set_intr_mask(h, HPSA_INTR_ON);
34353 msleep(10000);
34354 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34355 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34356
34357 rc = controller_reset_failed(h->cfgtable);
34358 if (rc)
34359 @@ -4416,7 +4416,7 @@ reinit_after_soft_reset:
34360 }
34361
34362 /* Turn the interrupts on so we can service requests */
34363 - h->access.set_intr_mask(h, HPSA_INTR_ON);
34364 + h->access->set_intr_mask(h, HPSA_INTR_ON);
34365
34366 hpsa_hba_inquiry(h);
34367 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
34368 @@ -4468,7 +4468,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
34369 * To write all data in the battery backed cache to disks
34370 */
34371 hpsa_flush_cache(h);
34372 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
34373 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
34374 free_irq(h->intr[h->intr_mode], h);
34375 #ifdef CONFIG_PCI_MSI
34376 if (h->msix_vector)
34377 @@ -4632,7 +4632,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
34378 return;
34379 }
34380 /* Change the access methods to the performant access methods */
34381 - h->access = SA5_performant_access;
34382 + h->access = &SA5_performant_access;
34383 h->transMethod = CFGTBL_Trans_Performant;
34384 }
34385
34386 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
34387 index 91edafb..a9b88ec 100644
34388 --- a/drivers/scsi/hpsa.h
34389 +++ b/drivers/scsi/hpsa.h
34390 @@ -73,7 +73,7 @@ struct ctlr_info {
34391 unsigned int msix_vector;
34392 unsigned int msi_vector;
34393 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
34394 - struct access_method access;
34395 + struct access_method *access;
34396
34397 /* queue and queue Info */
34398 struct list_head reqQ;
34399 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
34400 index f2df059..a3a9930 100644
34401 --- a/drivers/scsi/ips.h
34402 +++ b/drivers/scsi/ips.h
34403 @@ -1027,7 +1027,7 @@ typedef struct {
34404 int (*intr)(struct ips_ha *);
34405 void (*enableint)(struct ips_ha *);
34406 uint32_t (*statupd)(struct ips_ha *);
34407 -} ips_hw_func_t;
34408 +} __no_const ips_hw_func_t;
34409
34410 typedef struct ips_ha {
34411 uint8_t ha_id[IPS_MAX_CHANNELS+1];
34412 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
34413 index 9de9db2..1e09660 100644
34414 --- a/drivers/scsi/libfc/fc_exch.c
34415 +++ b/drivers/scsi/libfc/fc_exch.c
34416 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
34417 * all together if not used XXX
34418 */
34419 struct {
34420 - atomic_t no_free_exch;
34421 - atomic_t no_free_exch_xid;
34422 - atomic_t xid_not_found;
34423 - atomic_t xid_busy;
34424 - atomic_t seq_not_found;
34425 - atomic_t non_bls_resp;
34426 + atomic_unchecked_t no_free_exch;
34427 + atomic_unchecked_t no_free_exch_xid;
34428 + atomic_unchecked_t xid_not_found;
34429 + atomic_unchecked_t xid_busy;
34430 + atomic_unchecked_t seq_not_found;
34431 + atomic_unchecked_t non_bls_resp;
34432 } stats;
34433 };
34434
34435 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
34436 /* allocate memory for exchange */
34437 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
34438 if (!ep) {
34439 - atomic_inc(&mp->stats.no_free_exch);
34440 + atomic_inc_unchecked(&mp->stats.no_free_exch);
34441 goto out;
34442 }
34443 memset(ep, 0, sizeof(*ep));
34444 @@ -780,7 +780,7 @@ out:
34445 return ep;
34446 err:
34447 spin_unlock_bh(&pool->lock);
34448 - atomic_inc(&mp->stats.no_free_exch_xid);
34449 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
34450 mempool_free(ep, mp->ep_pool);
34451 return NULL;
34452 }
34453 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34454 xid = ntohs(fh->fh_ox_id); /* we originated exch */
34455 ep = fc_exch_find(mp, xid);
34456 if (!ep) {
34457 - atomic_inc(&mp->stats.xid_not_found);
34458 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34459 reject = FC_RJT_OX_ID;
34460 goto out;
34461 }
34462 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34463 ep = fc_exch_find(mp, xid);
34464 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
34465 if (ep) {
34466 - atomic_inc(&mp->stats.xid_busy);
34467 + atomic_inc_unchecked(&mp->stats.xid_busy);
34468 reject = FC_RJT_RX_ID;
34469 goto rel;
34470 }
34471 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34472 }
34473 xid = ep->xid; /* get our XID */
34474 } else if (!ep) {
34475 - atomic_inc(&mp->stats.xid_not_found);
34476 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34477 reject = FC_RJT_RX_ID; /* XID not found */
34478 goto out;
34479 }
34480 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
34481 } else {
34482 sp = &ep->seq;
34483 if (sp->id != fh->fh_seq_id) {
34484 - atomic_inc(&mp->stats.seq_not_found);
34485 + atomic_inc_unchecked(&mp->stats.seq_not_found);
34486 if (f_ctl & FC_FC_END_SEQ) {
34487 /*
34488 * Update sequence_id based on incoming last
34489 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34490
34491 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
34492 if (!ep) {
34493 - atomic_inc(&mp->stats.xid_not_found);
34494 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34495 goto out;
34496 }
34497 if (ep->esb_stat & ESB_ST_COMPLETE) {
34498 - atomic_inc(&mp->stats.xid_not_found);
34499 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34500 goto rel;
34501 }
34502 if (ep->rxid == FC_XID_UNKNOWN)
34503 ep->rxid = ntohs(fh->fh_rx_id);
34504 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
34505 - atomic_inc(&mp->stats.xid_not_found);
34506 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34507 goto rel;
34508 }
34509 if (ep->did != ntoh24(fh->fh_s_id) &&
34510 ep->did != FC_FID_FLOGI) {
34511 - atomic_inc(&mp->stats.xid_not_found);
34512 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34513 goto rel;
34514 }
34515 sof = fr_sof(fp);
34516 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34517 sp->ssb_stat |= SSB_ST_RESP;
34518 sp->id = fh->fh_seq_id;
34519 } else if (sp->id != fh->fh_seq_id) {
34520 - atomic_inc(&mp->stats.seq_not_found);
34521 + atomic_inc_unchecked(&mp->stats.seq_not_found);
34522 goto rel;
34523 }
34524
34525 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
34526 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
34527
34528 if (!sp)
34529 - atomic_inc(&mp->stats.xid_not_found);
34530 + atomic_inc_unchecked(&mp->stats.xid_not_found);
34531 else
34532 - atomic_inc(&mp->stats.non_bls_resp);
34533 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
34534
34535 fc_frame_free(fp);
34536 }
34537 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
34538 index db9238f..4378ed2 100644
34539 --- a/drivers/scsi/libsas/sas_ata.c
34540 +++ b/drivers/scsi/libsas/sas_ata.c
34541 @@ -368,7 +368,7 @@ static struct ata_port_operations sas_sata_ops = {
34542 .postreset = ata_std_postreset,
34543 .error_handler = ata_std_error_handler,
34544 .post_internal_cmd = sas_ata_post_internal,
34545 - .qc_defer = ata_std_qc_defer,
34546 + .qc_defer = ata_std_qc_defer,
34547 .qc_prep = ata_noop_qc_prep,
34548 .qc_issue = sas_ata_qc_issue,
34549 .qc_fill_rtf = sas_ata_qc_fill_rtf,
34550 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
34551 index bb4c8e0..f33d849 100644
34552 --- a/drivers/scsi/lpfc/lpfc.h
34553 +++ b/drivers/scsi/lpfc/lpfc.h
34554 @@ -425,7 +425,7 @@ struct lpfc_vport {
34555 struct dentry *debug_nodelist;
34556 struct dentry *vport_debugfs_root;
34557 struct lpfc_debugfs_trc *disc_trc;
34558 - atomic_t disc_trc_cnt;
34559 + atomic_unchecked_t disc_trc_cnt;
34560 #endif
34561 uint8_t stat_data_enabled;
34562 uint8_t stat_data_blocked;
34563 @@ -835,8 +835,8 @@ struct lpfc_hba {
34564 struct timer_list fabric_block_timer;
34565 unsigned long bit_flags;
34566 #define FABRIC_COMANDS_BLOCKED 0
34567 - atomic_t num_rsrc_err;
34568 - atomic_t num_cmd_success;
34569 + atomic_unchecked_t num_rsrc_err;
34570 + atomic_unchecked_t num_cmd_success;
34571 unsigned long last_rsrc_error_time;
34572 unsigned long last_ramp_down_time;
34573 unsigned long last_ramp_up_time;
34574 @@ -866,7 +866,7 @@ struct lpfc_hba {
34575
34576 struct dentry *debug_slow_ring_trc;
34577 struct lpfc_debugfs_trc *slow_ring_trc;
34578 - atomic_t slow_ring_trc_cnt;
34579 + atomic_unchecked_t slow_ring_trc_cnt;
34580 /* iDiag debugfs sub-directory */
34581 struct dentry *idiag_root;
34582 struct dentry *idiag_pci_cfg;
34583 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
34584 index 2838259..a07cfb5 100644
34585 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
34586 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
34587 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
34588
34589 #include <linux/debugfs.h>
34590
34591 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
34592 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
34593 static unsigned long lpfc_debugfs_start_time = 0L;
34594
34595 /* iDiag */
34596 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
34597 lpfc_debugfs_enable = 0;
34598
34599 len = 0;
34600 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
34601 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
34602 (lpfc_debugfs_max_disc_trc - 1);
34603 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
34604 dtp = vport->disc_trc + i;
34605 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
34606 lpfc_debugfs_enable = 0;
34607
34608 len = 0;
34609 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
34610 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
34611 (lpfc_debugfs_max_slow_ring_trc - 1);
34612 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
34613 dtp = phba->slow_ring_trc + i;
34614 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
34615 !vport || !vport->disc_trc)
34616 return;
34617
34618 - index = atomic_inc_return(&vport->disc_trc_cnt) &
34619 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
34620 (lpfc_debugfs_max_disc_trc - 1);
34621 dtp = vport->disc_trc + index;
34622 dtp->fmt = fmt;
34623 dtp->data1 = data1;
34624 dtp->data2 = data2;
34625 dtp->data3 = data3;
34626 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
34627 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
34628 dtp->jif = jiffies;
34629 #endif
34630 return;
34631 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
34632 !phba || !phba->slow_ring_trc)
34633 return;
34634
34635 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
34636 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
34637 (lpfc_debugfs_max_slow_ring_trc - 1);
34638 dtp = phba->slow_ring_trc + index;
34639 dtp->fmt = fmt;
34640 dtp->data1 = data1;
34641 dtp->data2 = data2;
34642 dtp->data3 = data3;
34643 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
34644 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
34645 dtp->jif = jiffies;
34646 #endif
34647 return;
34648 @@ -3986,7 +3986,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
34649 "slow_ring buffer\n");
34650 goto debug_failed;
34651 }
34652 - atomic_set(&phba->slow_ring_trc_cnt, 0);
34653 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
34654 memset(phba->slow_ring_trc, 0,
34655 (sizeof(struct lpfc_debugfs_trc) *
34656 lpfc_debugfs_max_slow_ring_trc));
34657 @@ -4032,7 +4032,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
34658 "buffer\n");
34659 goto debug_failed;
34660 }
34661 - atomic_set(&vport->disc_trc_cnt, 0);
34662 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
34663
34664 snprintf(name, sizeof(name), "discovery_trace");
34665 vport->debug_disc_trc =
34666 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
34667 index 55bc4fc..a2a109c 100644
34668 --- a/drivers/scsi/lpfc/lpfc_init.c
34669 +++ b/drivers/scsi/lpfc/lpfc_init.c
34670 @@ -10027,8 +10027,10 @@ lpfc_init(void)
34671 printk(LPFC_COPYRIGHT "\n");
34672
34673 if (lpfc_enable_npiv) {
34674 - lpfc_transport_functions.vport_create = lpfc_vport_create;
34675 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
34676 + pax_open_kernel();
34677 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
34678 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
34679 + pax_close_kernel();
34680 }
34681 lpfc_transport_template =
34682 fc_attach_transport(&lpfc_transport_functions);
34683 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
34684 index 2e1e54e..1af0a0d 100644
34685 --- a/drivers/scsi/lpfc/lpfc_scsi.c
34686 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
34687 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
34688 uint32_t evt_posted;
34689
34690 spin_lock_irqsave(&phba->hbalock, flags);
34691 - atomic_inc(&phba->num_rsrc_err);
34692 + atomic_inc_unchecked(&phba->num_rsrc_err);
34693 phba->last_rsrc_error_time = jiffies;
34694
34695 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
34696 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
34697 unsigned long flags;
34698 struct lpfc_hba *phba = vport->phba;
34699 uint32_t evt_posted;
34700 - atomic_inc(&phba->num_cmd_success);
34701 + atomic_inc_unchecked(&phba->num_cmd_success);
34702
34703 if (vport->cfg_lun_queue_depth <= queue_depth)
34704 return;
34705 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
34706 unsigned long num_rsrc_err, num_cmd_success;
34707 int i;
34708
34709 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
34710 - num_cmd_success = atomic_read(&phba->num_cmd_success);
34711 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
34712 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
34713
34714 vports = lpfc_create_vport_work_array(phba);
34715 if (vports != NULL)
34716 @@ -411,8 +411,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
34717 }
34718 }
34719 lpfc_destroy_vport_work_array(phba, vports);
34720 - atomic_set(&phba->num_rsrc_err, 0);
34721 - atomic_set(&phba->num_cmd_success, 0);
34722 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
34723 + atomic_set_unchecked(&phba->num_cmd_success, 0);
34724 }
34725
34726 /**
34727 @@ -446,8 +446,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
34728 }
34729 }
34730 lpfc_destroy_vport_work_array(phba, vports);
34731 - atomic_set(&phba->num_rsrc_err, 0);
34732 - atomic_set(&phba->num_cmd_success, 0);
34733 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
34734 + atomic_set_unchecked(&phba->num_cmd_success, 0);
34735 }
34736
34737 /**
34738 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
34739 index 5163edb..7b142bc 100644
34740 --- a/drivers/scsi/pmcraid.c
34741 +++ b/drivers/scsi/pmcraid.c
34742 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
34743 res->scsi_dev = scsi_dev;
34744 scsi_dev->hostdata = res;
34745 res->change_detected = 0;
34746 - atomic_set(&res->read_failures, 0);
34747 - atomic_set(&res->write_failures, 0);
34748 + atomic_set_unchecked(&res->read_failures, 0);
34749 + atomic_set_unchecked(&res->write_failures, 0);
34750 rc = 0;
34751 }
34752 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
34753 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
34754
34755 /* If this was a SCSI read/write command keep count of errors */
34756 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
34757 - atomic_inc(&res->read_failures);
34758 + atomic_inc_unchecked(&res->read_failures);
34759 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
34760 - atomic_inc(&res->write_failures);
34761 + atomic_inc_unchecked(&res->write_failures);
34762
34763 if (!RES_IS_GSCSI(res->cfg_entry) &&
34764 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
34765 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
34766 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
34767 * hrrq_id assigned here in queuecommand
34768 */
34769 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
34770 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
34771 pinstance->num_hrrq;
34772 cmd->cmd_done = pmcraid_io_done;
34773
34774 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
34775 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
34776 * hrrq_id assigned here in queuecommand
34777 */
34778 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
34779 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
34780 pinstance->num_hrrq;
34781
34782 if (request_size) {
34783 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
34784
34785 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
34786 /* add resources only after host is added into system */
34787 - if (!atomic_read(&pinstance->expose_resources))
34788 + if (!atomic_read_unchecked(&pinstance->expose_resources))
34789 return;
34790
34791 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
34792 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
34793 init_waitqueue_head(&pinstance->reset_wait_q);
34794
34795 atomic_set(&pinstance->outstanding_cmds, 0);
34796 - atomic_set(&pinstance->last_message_id, 0);
34797 - atomic_set(&pinstance->expose_resources, 0);
34798 + atomic_set_unchecked(&pinstance->last_message_id, 0);
34799 + atomic_set_unchecked(&pinstance->expose_resources, 0);
34800
34801 INIT_LIST_HEAD(&pinstance->free_res_q);
34802 INIT_LIST_HEAD(&pinstance->used_res_q);
34803 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
34804 /* Schedule worker thread to handle CCN and take care of adding and
34805 * removing devices to OS
34806 */
34807 - atomic_set(&pinstance->expose_resources, 1);
34808 + atomic_set_unchecked(&pinstance->expose_resources, 1);
34809 schedule_work(&pinstance->worker_q);
34810 return rc;
34811
34812 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
34813 index ca496c7..9c791d5 100644
34814 --- a/drivers/scsi/pmcraid.h
34815 +++ b/drivers/scsi/pmcraid.h
34816 @@ -748,7 +748,7 @@ struct pmcraid_instance {
34817 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
34818
34819 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
34820 - atomic_t last_message_id;
34821 + atomic_unchecked_t last_message_id;
34822
34823 /* configuration table */
34824 struct pmcraid_config_table *cfg_table;
34825 @@ -777,7 +777,7 @@ struct pmcraid_instance {
34826 atomic_t outstanding_cmds;
34827
34828 /* should add/delete resources to mid-layer now ?*/
34829 - atomic_t expose_resources;
34830 + atomic_unchecked_t expose_resources;
34831
34832
34833
34834 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
34835 struct pmcraid_config_table_entry_ext cfg_entry_ext;
34836 };
34837 struct scsi_device *scsi_dev; /* Link scsi_device structure */
34838 - atomic_t read_failures; /* count of failed READ commands */
34839 - atomic_t write_failures; /* count of failed WRITE commands */
34840 + atomic_unchecked_t read_failures; /* count of failed READ commands */
34841 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
34842
34843 /* To indicate add/delete/modify during CCN */
34844 u8 change_detected;
34845 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
34846 index fcf052c..a8025a4 100644
34847 --- a/drivers/scsi/qla2xxx/qla_def.h
34848 +++ b/drivers/scsi/qla2xxx/qla_def.h
34849 @@ -2244,7 +2244,7 @@ struct isp_operations {
34850 int (*get_flash_version) (struct scsi_qla_host *, void *);
34851 int (*start_scsi) (srb_t *);
34852 int (*abort_isp) (struct scsi_qla_host *);
34853 -};
34854 +} __no_const;
34855
34856 /* MSI-X Support *************************************************************/
34857
34858 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
34859 index fd5edc6..4906148 100644
34860 --- a/drivers/scsi/qla4xxx/ql4_def.h
34861 +++ b/drivers/scsi/qla4xxx/ql4_def.h
34862 @@ -258,7 +258,7 @@ struct ddb_entry {
34863 * (4000 only) */
34864 atomic_t relogin_timer; /* Max Time to wait for
34865 * relogin to complete */
34866 - atomic_t relogin_retry_count; /* Num of times relogin has been
34867 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
34868 * retried */
34869 uint32_t default_time2wait; /* Default Min time between
34870 * relogins (+aens) */
34871 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
34872 index 4169c8b..a8b896b 100644
34873 --- a/drivers/scsi/qla4xxx/ql4_os.c
34874 +++ b/drivers/scsi/qla4xxx/ql4_os.c
34875 @@ -2104,12 +2104,12 @@ void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
34876 */
34877 if (!iscsi_is_session_online(cls_sess)) {
34878 /* Reset retry relogin timer */
34879 - atomic_inc(&ddb_entry->relogin_retry_count);
34880 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
34881 DEBUG2(ql4_printk(KERN_INFO, ha,
34882 "%s: index[%d] relogin timed out-retrying"
34883 " relogin (%d), retry (%d)\n", __func__,
34884 ddb_entry->fw_ddb_index,
34885 - atomic_read(&ddb_entry->relogin_retry_count),
34886 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
34887 ddb_entry->default_time2wait + 4));
34888 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
34889 atomic_set(&ddb_entry->retry_relogin_timer,
34890 @@ -3835,7 +3835,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
34891
34892 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
34893 atomic_set(&ddb_entry->relogin_timer, 0);
34894 - atomic_set(&ddb_entry->relogin_retry_count, 0);
34895 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
34896
34897 ddb_entry->default_relogin_timeout =
34898 le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
34899 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
34900 index 2aeb2e9..46e3925 100644
34901 --- a/drivers/scsi/scsi.c
34902 +++ b/drivers/scsi/scsi.c
34903 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
34904 unsigned long timeout;
34905 int rtn = 0;
34906
34907 - atomic_inc(&cmd->device->iorequest_cnt);
34908 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
34909
34910 /* check if the device is still usable */
34911 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
34912 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
34913 index f85cfa6..a57c9e8 100644
34914 --- a/drivers/scsi/scsi_lib.c
34915 +++ b/drivers/scsi/scsi_lib.c
34916 @@ -1416,7 +1416,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
34917 shost = sdev->host;
34918 scsi_init_cmd_errh(cmd);
34919 cmd->result = DID_NO_CONNECT << 16;
34920 - atomic_inc(&cmd->device->iorequest_cnt);
34921 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
34922
34923 /*
34924 * SCSI request completion path will do scsi_device_unbusy(),
34925 @@ -1442,9 +1442,9 @@ static void scsi_softirq_done(struct request *rq)
34926
34927 INIT_LIST_HEAD(&cmd->eh_entry);
34928
34929 - atomic_inc(&cmd->device->iodone_cnt);
34930 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
34931 if (cmd->result)
34932 - atomic_inc(&cmd->device->ioerr_cnt);
34933 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
34934
34935 disposition = scsi_decide_disposition(cmd);
34936 if (disposition != SUCCESS &&
34937 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
34938 index 04c2a27..9d8bd66 100644
34939 --- a/drivers/scsi/scsi_sysfs.c
34940 +++ b/drivers/scsi/scsi_sysfs.c
34941 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
34942 char *buf) \
34943 { \
34944 struct scsi_device *sdev = to_scsi_device(dev); \
34945 - unsigned long long count = atomic_read(&sdev->field); \
34946 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
34947 return snprintf(buf, 20, "0x%llx\n", count); \
34948 } \
34949 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
34950 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
34951 index 84a1fdf..693b0d6 100644
34952 --- a/drivers/scsi/scsi_tgt_lib.c
34953 +++ b/drivers/scsi/scsi_tgt_lib.c
34954 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
34955 int err;
34956
34957 dprintk("%lx %u\n", uaddr, len);
34958 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
34959 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
34960 if (err) {
34961 /*
34962 * TODO: need to fixup sg_tablesize, max_segment_size,
34963 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
34964 index 1b21491..1b7f60e 100644
34965 --- a/drivers/scsi/scsi_transport_fc.c
34966 +++ b/drivers/scsi/scsi_transport_fc.c
34967 @@ -484,7 +484,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
34968 * Netlink Infrastructure
34969 */
34970
34971 -static atomic_t fc_event_seq;
34972 +static atomic_unchecked_t fc_event_seq;
34973
34974 /**
34975 * fc_get_event_number - Obtain the next sequential FC event number
34976 @@ -497,7 +497,7 @@ static atomic_t fc_event_seq;
34977 u32
34978 fc_get_event_number(void)
34979 {
34980 - return atomic_add_return(1, &fc_event_seq);
34981 + return atomic_add_return_unchecked(1, &fc_event_seq);
34982 }
34983 EXPORT_SYMBOL(fc_get_event_number);
34984
34985 @@ -645,7 +645,7 @@ static __init int fc_transport_init(void)
34986 {
34987 int error;
34988
34989 - atomic_set(&fc_event_seq, 0);
34990 + atomic_set_unchecked(&fc_event_seq, 0);
34991
34992 error = transport_class_register(&fc_host_class);
34993 if (error)
34994 @@ -835,7 +835,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
34995 char *cp;
34996
34997 *val = simple_strtoul(buf, &cp, 0);
34998 - if ((*cp && (*cp != '\n')) || (*val < 0))
34999 + if (*cp && (*cp != '\n'))
35000 return -EINVAL;
35001 /*
35002 * Check for overflow; dev_loss_tmo is u32
35003 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
35004 index 96029e6..4d77fa0 100644
35005 --- a/drivers/scsi/scsi_transport_iscsi.c
35006 +++ b/drivers/scsi/scsi_transport_iscsi.c
35007 @@ -79,7 +79,7 @@ struct iscsi_internal {
35008 struct transport_container session_cont;
35009 };
35010
35011 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
35012 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
35013 static struct workqueue_struct *iscsi_eh_timer_workq;
35014
35015 static DEFINE_IDA(iscsi_sess_ida);
35016 @@ -1062,7 +1062,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
35017 int err;
35018
35019 ihost = shost->shost_data;
35020 - session->sid = atomic_add_return(1, &iscsi_session_nr);
35021 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
35022
35023 if (target_id == ISCSI_MAX_TARGET) {
35024 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
35025 @@ -2663,7 +2663,7 @@ static __init int iscsi_transport_init(void)
35026 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
35027 ISCSI_TRANSPORT_VERSION);
35028
35029 - atomic_set(&iscsi_session_nr, 0);
35030 + atomic_set_unchecked(&iscsi_session_nr, 0);
35031
35032 err = class_register(&iscsi_transport_class);
35033 if (err)
35034 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
35035 index 21a045e..ec89e03 100644
35036 --- a/drivers/scsi/scsi_transport_srp.c
35037 +++ b/drivers/scsi/scsi_transport_srp.c
35038 @@ -33,7 +33,7 @@
35039 #include "scsi_transport_srp_internal.h"
35040
35041 struct srp_host_attrs {
35042 - atomic_t next_port_id;
35043 + atomic_unchecked_t next_port_id;
35044 };
35045 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
35046
35047 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
35048 struct Scsi_Host *shost = dev_to_shost(dev);
35049 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
35050
35051 - atomic_set(&srp_host->next_port_id, 0);
35052 + atomic_set_unchecked(&srp_host->next_port_id, 0);
35053 return 0;
35054 }
35055
35056 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
35057 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
35058 rport->roles = ids->roles;
35059
35060 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
35061 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
35062 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
35063
35064 transport_setup_device(&rport->dev);
35065 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
35066 index 441a1c5..07cece7 100644
35067 --- a/drivers/scsi/sg.c
35068 +++ b/drivers/scsi/sg.c
35069 @@ -1077,7 +1077,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
35070 sdp->disk->disk_name,
35071 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
35072 NULL,
35073 - (char *)arg);
35074 + (char __user *)arg);
35075 case BLKTRACESTART:
35076 return blk_trace_startstop(sdp->device->request_queue, 1);
35077 case BLKTRACESTOP:
35078 @@ -2312,7 +2312,7 @@ struct sg_proc_leaf {
35079 const struct file_operations * fops;
35080 };
35081
35082 -static struct sg_proc_leaf sg_proc_leaf_arr[] = {
35083 +static const struct sg_proc_leaf sg_proc_leaf_arr[] = {
35084 {"allow_dio", &adio_fops},
35085 {"debug", &debug_fops},
35086 {"def_reserved_size", &dressz_fops},
35087 @@ -2327,7 +2327,7 @@ sg_proc_init(void)
35088 {
35089 int k, mask;
35090 int num_leaves = ARRAY_SIZE(sg_proc_leaf_arr);
35091 - struct sg_proc_leaf * leaf;
35092 + const struct sg_proc_leaf * leaf;
35093
35094 sg_proc_sgp = proc_mkdir(sg_proc_sg_dirname, NULL);
35095 if (!sg_proc_sgp)
35096 diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
35097 index f64250e..1ee3049 100644
35098 --- a/drivers/spi/spi-dw-pci.c
35099 +++ b/drivers/spi/spi-dw-pci.c
35100 @@ -149,7 +149,7 @@ static int spi_resume(struct pci_dev *pdev)
35101 #define spi_resume NULL
35102 #endif
35103
35104 -static const struct pci_device_id pci_ids[] __devinitdata = {
35105 +static const struct pci_device_id pci_ids[] __devinitconst = {
35106 /* Intel MID platform SPI controller 0 */
35107 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0800) },
35108 {},
35109 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
35110 index 77eae99..b7cdcc9 100644
35111 --- a/drivers/spi/spi.c
35112 +++ b/drivers/spi/spi.c
35113 @@ -1024,7 +1024,7 @@ int spi_bus_unlock(struct spi_master *master)
35114 EXPORT_SYMBOL_GPL(spi_bus_unlock);
35115
35116 /* portable code must never pass more than 32 bytes */
35117 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
35118 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
35119
35120 static u8 *buf;
35121
35122 diff --git a/drivers/staging/gma500/power.c b/drivers/staging/gma500/power.c
35123 index 436fe97..4082570 100644
35124 --- a/drivers/staging/gma500/power.c
35125 +++ b/drivers/staging/gma500/power.c
35126 @@ -266,7 +266,7 @@ bool gma_power_begin(struct drm_device *dev, bool force_on)
35127 ret = gma_resume_pci(dev->pdev);
35128 if (ret == 0) {
35129 /* FIXME: we want to defer this for Medfield/Oaktrail */
35130 - gma_resume_display(dev);
35131 + gma_resume_display(dev->pdev);
35132 psb_irq_preinstall(dev);
35133 psb_irq_postinstall(dev);
35134 pm_runtime_get(&dev->pdev->dev);
35135 diff --git a/drivers/staging/hv/rndis_filter.c b/drivers/staging/hv/rndis_filter.c
35136 index bafccb3..e3ac78d 100644
35137 --- a/drivers/staging/hv/rndis_filter.c
35138 +++ b/drivers/staging/hv/rndis_filter.c
35139 @@ -42,7 +42,7 @@ struct rndis_device {
35140
35141 enum rndis_device_state state;
35142 bool link_state;
35143 - atomic_t new_req_id;
35144 + atomic_unchecked_t new_req_id;
35145
35146 spinlock_t request_lock;
35147 struct list_head req_list;
35148 @@ -116,7 +116,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35149 * template
35150 */
35151 set = &rndis_msg->msg.set_req;
35152 - set->req_id = atomic_inc_return(&dev->new_req_id);
35153 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35154
35155 /* Add to the request list */
35156 spin_lock_irqsave(&dev->request_lock, flags);
35157 @@ -646,7 +646,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35158
35159 /* Setup the rndis set */
35160 halt = &request->request_msg.msg.halt_req;
35161 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35162 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35163
35164 /* Ignore return since this msg is optional. */
35165 rndis_filter_send_request(dev, request);
35166 diff --git a/drivers/staging/iio/buffer_generic.h b/drivers/staging/iio/buffer_generic.h
35167 index 9e8f010..af9efb5 100644
35168 --- a/drivers/staging/iio/buffer_generic.h
35169 +++ b/drivers/staging/iio/buffer_generic.h
35170 @@ -64,7 +64,7 @@ struct iio_buffer_access_funcs {
35171
35172 int (*is_enabled)(struct iio_buffer *buffer);
35173 int (*enable)(struct iio_buffer *buffer);
35174 -};
35175 +} __no_const;
35176
35177 /**
35178 * struct iio_buffer_setup_ops - buffer setup related callbacks
35179 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
35180 index 8b307b4..a97ac91 100644
35181 --- a/drivers/staging/octeon/ethernet-rx.c
35182 +++ b/drivers/staging/octeon/ethernet-rx.c
35183 @@ -420,11 +420,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
35184 /* Increment RX stats for virtual ports */
35185 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
35186 #ifdef CONFIG_64BIT
35187 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
35188 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
35189 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
35190 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
35191 #else
35192 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
35193 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
35194 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
35195 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
35196 #endif
35197 }
35198 netif_receive_skb(skb);
35199 @@ -436,9 +436,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
35200 dev->name);
35201 */
35202 #ifdef CONFIG_64BIT
35203 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
35204 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
35205 #else
35206 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
35207 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
35208 #endif
35209 dev_kfree_skb_irq(skb);
35210 }
35211 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
35212 index 076f866..2308070 100644
35213 --- a/drivers/staging/octeon/ethernet.c
35214 +++ b/drivers/staging/octeon/ethernet.c
35215 @@ -258,11 +258,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
35216 * since the RX tasklet also increments it.
35217 */
35218 #ifdef CONFIG_64BIT
35219 - atomic64_add(rx_status.dropped_packets,
35220 - (atomic64_t *)&priv->stats.rx_dropped);
35221 + atomic64_add_unchecked(rx_status.dropped_packets,
35222 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
35223 #else
35224 - atomic_add(rx_status.dropped_packets,
35225 - (atomic_t *)&priv->stats.rx_dropped);
35226 + atomic_add_unchecked(rx_status.dropped_packets,
35227 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
35228 #endif
35229 }
35230
35231 diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
35232 index 7a19555..466456d 100644
35233 --- a/drivers/staging/pohmelfs/inode.c
35234 +++ b/drivers/staging/pohmelfs/inode.c
35235 @@ -1861,7 +1861,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
35236 mutex_init(&psb->mcache_lock);
35237 psb->mcache_root = RB_ROOT;
35238 psb->mcache_timeout = msecs_to_jiffies(5000);
35239 - atomic_long_set(&psb->mcache_gen, 0);
35240 + atomic_long_set_unchecked(&psb->mcache_gen, 0);
35241
35242 psb->trans_max_pages = 100;
35243
35244 @@ -1876,7 +1876,7 @@ static int pohmelfs_fill_super(struct super_block *sb, void *data, int silent)
35245 INIT_LIST_HEAD(&psb->crypto_ready_list);
35246 INIT_LIST_HEAD(&psb->crypto_active_list);
35247
35248 - atomic_set(&psb->trans_gen, 1);
35249 + atomic_set_unchecked(&psb->trans_gen, 1);
35250 atomic_long_set(&psb->total_inodes, 0);
35251
35252 mutex_init(&psb->state_lock);
35253 diff --git a/drivers/staging/pohmelfs/mcache.c b/drivers/staging/pohmelfs/mcache.c
35254 index e22665c..a2a9390 100644
35255 --- a/drivers/staging/pohmelfs/mcache.c
35256 +++ b/drivers/staging/pohmelfs/mcache.c
35257 @@ -121,7 +121,7 @@ struct pohmelfs_mcache *pohmelfs_mcache_alloc(struct pohmelfs_sb *psb, u64 start
35258 m->data = data;
35259 m->start = start;
35260 m->size = size;
35261 - m->gen = atomic_long_inc_return(&psb->mcache_gen);
35262 + m->gen = atomic_long_inc_return_unchecked(&psb->mcache_gen);
35263
35264 mutex_lock(&psb->mcache_lock);
35265 err = pohmelfs_mcache_insert(psb, m);
35266 diff --git a/drivers/staging/pohmelfs/netfs.h b/drivers/staging/pohmelfs/netfs.h
35267 index 985b6b7..7699e05 100644
35268 --- a/drivers/staging/pohmelfs/netfs.h
35269 +++ b/drivers/staging/pohmelfs/netfs.h
35270 @@ -571,14 +571,14 @@ struct pohmelfs_config;
35271 struct pohmelfs_sb {
35272 struct rb_root mcache_root;
35273 struct mutex mcache_lock;
35274 - atomic_long_t mcache_gen;
35275 + atomic_long_unchecked_t mcache_gen;
35276 unsigned long mcache_timeout;
35277
35278 unsigned int idx;
35279
35280 unsigned int trans_retries;
35281
35282 - atomic_t trans_gen;
35283 + atomic_unchecked_t trans_gen;
35284
35285 unsigned int crypto_attached_size;
35286 unsigned int crypto_align_size;
35287 diff --git a/drivers/staging/pohmelfs/trans.c b/drivers/staging/pohmelfs/trans.c
35288 index 06c1a74..866eebc 100644
35289 --- a/drivers/staging/pohmelfs/trans.c
35290 +++ b/drivers/staging/pohmelfs/trans.c
35291 @@ -492,7 +492,7 @@ int netfs_trans_finish(struct netfs_trans *t, struct pohmelfs_sb *psb)
35292 int err;
35293 struct netfs_cmd *cmd = t->iovec.iov_base;
35294
35295 - t->gen = atomic_inc_return(&psb->trans_gen);
35296 + t->gen = atomic_inc_return_unchecked(&psb->trans_gen);
35297
35298 cmd->size = t->iovec.iov_len - sizeof(struct netfs_cmd) +
35299 t->attached_size + t->attached_pages * sizeof(struct netfs_cmd);
35300 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
35301 index 86308a0..feaa925 100644
35302 --- a/drivers/staging/rtl8712/rtl871x_io.h
35303 +++ b/drivers/staging/rtl8712/rtl871x_io.h
35304 @@ -108,7 +108,7 @@ struct _io_ops {
35305 u8 *pmem);
35306 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
35307 u8 *pmem);
35308 -};
35309 +} __no_const;
35310
35311 struct io_req {
35312 struct list_head list;
35313 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
35314 index c7b5e8b..783d6cb 100644
35315 --- a/drivers/staging/sbe-2t3e3/netdev.c
35316 +++ b/drivers/staging/sbe-2t3e3/netdev.c
35317 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35318 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
35319
35320 if (rlen)
35321 - if (copy_to_user(data, &resp, rlen))
35322 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
35323 return -EFAULT;
35324
35325 return 0;
35326 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
35327 index be21617..0954e45 100644
35328 --- a/drivers/staging/usbip/usbip_common.h
35329 +++ b/drivers/staging/usbip/usbip_common.h
35330 @@ -289,7 +289,7 @@ struct usbip_device {
35331 void (*shutdown)(struct usbip_device *);
35332 void (*reset)(struct usbip_device *);
35333 void (*unusable)(struct usbip_device *);
35334 - } eh_ops;
35335 + } __no_const eh_ops;
35336 };
35337
35338 #if 0
35339 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
35340 index 88b3298..3783eee 100644
35341 --- a/drivers/staging/usbip/vhci.h
35342 +++ b/drivers/staging/usbip/vhci.h
35343 @@ -88,7 +88,7 @@ struct vhci_hcd {
35344 unsigned resuming:1;
35345 unsigned long re_timeout;
35346
35347 - atomic_t seqnum;
35348 + atomic_unchecked_t seqnum;
35349
35350 /*
35351 * NOTE:
35352 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
35353 index 2ee97e2..0420b86 100644
35354 --- a/drivers/staging/usbip/vhci_hcd.c
35355 +++ b/drivers/staging/usbip/vhci_hcd.c
35356 @@ -527,7 +527,7 @@ static void vhci_tx_urb(struct urb *urb)
35357 return;
35358 }
35359
35360 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
35361 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
35362 if (priv->seqnum == 0xffff)
35363 dev_info(&urb->dev->dev, "seqnum max\n");
35364
35365 @@ -779,7 +779,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
35366 return -ENOMEM;
35367 }
35368
35369 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
35370 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
35371 if (unlink->seqnum == 0xffff)
35372 pr_info("seqnum max\n");
35373
35374 @@ -969,7 +969,7 @@ static int vhci_start(struct usb_hcd *hcd)
35375 vdev->rhport = rhport;
35376 }
35377
35378 - atomic_set(&vhci->seqnum, 0);
35379 + atomic_set_unchecked(&vhci->seqnum, 0);
35380 spin_lock_init(&vhci->lock);
35381
35382 hcd->power_budget = 0; /* no limit */
35383 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
35384 index 3872b8c..fe6d2f4 100644
35385 --- a/drivers/staging/usbip/vhci_rx.c
35386 +++ b/drivers/staging/usbip/vhci_rx.c
35387 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
35388 if (!urb) {
35389 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
35390 pr_info("max seqnum %d\n",
35391 - atomic_read(&the_controller->seqnum));
35392 + atomic_read_unchecked(&the_controller->seqnum));
35393 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
35394 return;
35395 }
35396 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
35397 index 7735027..30eed13 100644
35398 --- a/drivers/staging/vt6655/hostap.c
35399 +++ b/drivers/staging/vt6655/hostap.c
35400 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
35401 *
35402 */
35403
35404 +static net_device_ops_no_const apdev_netdev_ops;
35405 +
35406 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35407 {
35408 PSDevice apdev_priv;
35409 struct net_device *dev = pDevice->dev;
35410 int ret;
35411 - const struct net_device_ops apdev_netdev_ops = {
35412 - .ndo_start_xmit = pDevice->tx_80211,
35413 - };
35414
35415 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
35416
35417 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35418 *apdev_priv = *pDevice;
35419 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
35420
35421 + /* only half broken now */
35422 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
35423 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
35424
35425 pDevice->apdev->type = ARPHRD_IEEE80211;
35426 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
35427 index 51b5adf..098e320 100644
35428 --- a/drivers/staging/vt6656/hostap.c
35429 +++ b/drivers/staging/vt6656/hostap.c
35430 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
35431 *
35432 */
35433
35434 +static net_device_ops_no_const apdev_netdev_ops;
35435 +
35436 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35437 {
35438 PSDevice apdev_priv;
35439 struct net_device *dev = pDevice->dev;
35440 int ret;
35441 - const struct net_device_ops apdev_netdev_ops = {
35442 - .ndo_start_xmit = pDevice->tx_80211,
35443 - };
35444
35445 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
35446
35447 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
35448 *apdev_priv = *pDevice;
35449 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
35450
35451 + /* only half broken now */
35452 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
35453 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
35454
35455 pDevice->apdev->type = ARPHRD_IEEE80211;
35456 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
35457 index 7843dfd..3db105f 100644
35458 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
35459 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
35460 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
35461
35462 struct usbctlx_completor {
35463 int (*complete) (struct usbctlx_completor *);
35464 -};
35465 +} __no_const;
35466
35467 static int
35468 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
35469 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
35470 index 1ca66ea..76f1343 100644
35471 --- a/drivers/staging/zcache/tmem.c
35472 +++ b/drivers/staging/zcache/tmem.c
35473 @@ -39,7 +39,7 @@
35474 * A tmem host implementation must use this function to register callbacks
35475 * for memory allocation.
35476 */
35477 -static struct tmem_hostops tmem_hostops;
35478 +static tmem_hostops_no_const tmem_hostops;
35479
35480 static void tmem_objnode_tree_init(void);
35481
35482 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
35483 * A tmem host implementation must use this function to register
35484 * callbacks for a page-accessible memory (PAM) implementation
35485 */
35486 -static struct tmem_pamops tmem_pamops;
35487 +static tmem_pamops_no_const tmem_pamops;
35488
35489 void tmem_register_pamops(struct tmem_pamops *m)
35490 {
35491 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
35492 index ed147c4..94fc3c6 100644
35493 --- a/drivers/staging/zcache/tmem.h
35494 +++ b/drivers/staging/zcache/tmem.h
35495 @@ -180,6 +180,7 @@ struct tmem_pamops {
35496 void (*new_obj)(struct tmem_obj *);
35497 int (*replace_in_obj)(void *, struct tmem_obj *);
35498 };
35499 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
35500 extern void tmem_register_pamops(struct tmem_pamops *m);
35501
35502 /* memory allocation methods provided by the host implementation */
35503 @@ -189,6 +190,7 @@ struct tmem_hostops {
35504 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
35505 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
35506 };
35507 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
35508 extern void tmem_register_hostops(struct tmem_hostops *m);
35509
35510 /* core tmem accessor functions */
35511 diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
35512 index 0c1d5c73..88e90a8 100644
35513 --- a/drivers/target/iscsi/iscsi_target.c
35514 +++ b/drivers/target/iscsi/iscsi_target.c
35515 @@ -1364,7 +1364,7 @@ static int iscsit_handle_data_out(struct iscsi_conn *conn, unsigned char *buf)
35516 * outstanding_r2ts reaches zero, go ahead and send the delayed
35517 * TASK_ABORTED status.
35518 */
35519 - if (atomic_read(&se_cmd->t_transport_aborted) != 0) {
35520 + if (atomic_read_unchecked(&se_cmd->t_transport_aborted) != 0) {
35521 if (hdr->flags & ISCSI_FLAG_CMD_FINAL)
35522 if (--cmd->outstanding_r2ts < 1) {
35523 iscsit_stop_dataout_timer(cmd);
35524 diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
35525 index 6845228..df77141 100644
35526 --- a/drivers/target/target_core_tmr.c
35527 +++ b/drivers/target/target_core_tmr.c
35528 @@ -250,7 +250,7 @@ static void core_tmr_drain_task_list(
35529 cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key,
35530 cmd->t_task_list_num,
35531 atomic_read(&cmd->t_task_cdbs_left),
35532 - atomic_read(&cmd->t_task_cdbs_sent),
35533 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
35534 atomic_read(&cmd->t_transport_active),
35535 atomic_read(&cmd->t_transport_stop),
35536 atomic_read(&cmd->t_transport_sent));
35537 @@ -281,7 +281,7 @@ static void core_tmr_drain_task_list(
35538 pr_debug("LUN_RESET: got t_transport_active = 1 for"
35539 " task: %p, t_fe_count: %d dev: %p\n", task,
35540 fe_count, dev);
35541 - atomic_set(&cmd->t_transport_aborted, 1);
35542 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
35543 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35544
35545 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
35546 @@ -289,7 +289,7 @@ static void core_tmr_drain_task_list(
35547 }
35548 pr_debug("LUN_RESET: Got t_transport_active = 0 for task: %p,"
35549 " t_fe_count: %d dev: %p\n", task, fe_count, dev);
35550 - atomic_set(&cmd->t_transport_aborted, 1);
35551 + atomic_set_unchecked(&cmd->t_transport_aborted, 1);
35552 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35553
35554 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
35555 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
35556 index 861628e..659ae80 100644
35557 --- a/drivers/target/target_core_transport.c
35558 +++ b/drivers/target/target_core_transport.c
35559 @@ -1343,7 +1343,7 @@ struct se_device *transport_add_device_to_core_hba(
35560
35561 dev->queue_depth = dev_limits->queue_depth;
35562 atomic_set(&dev->depth_left, dev->queue_depth);
35563 - atomic_set(&dev->dev_ordered_id, 0);
35564 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
35565
35566 se_dev_set_default_attribs(dev, dev_limits);
35567
35568 @@ -1530,7 +1530,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
35569 * Used to determine when ORDERED commands should go from
35570 * Dormant to Active status.
35571 */
35572 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
35573 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
35574 smp_mb__after_atomic_inc();
35575 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
35576 cmd->se_ordered_id, cmd->sam_task_attr,
35577 @@ -1800,7 +1800,7 @@ static void transport_generic_request_failure(struct se_cmd *cmd)
35578 " t_transport_active: %d t_transport_stop: %d"
35579 " t_transport_sent: %d\n", cmd->t_task_list_num,
35580 atomic_read(&cmd->t_task_cdbs_left),
35581 - atomic_read(&cmd->t_task_cdbs_sent),
35582 + atomic_read_unchecked(&cmd->t_task_cdbs_sent),
35583 atomic_read(&cmd->t_task_cdbs_ex_left),
35584 atomic_read(&cmd->t_transport_active),
35585 atomic_read(&cmd->t_transport_stop),
35586 @@ -2089,9 +2089,9 @@ check_depth:
35587
35588 spin_lock_irqsave(&cmd->t_state_lock, flags);
35589 task->task_flags |= (TF_ACTIVE | TF_SENT);
35590 - atomic_inc(&cmd->t_task_cdbs_sent);
35591 + atomic_inc_unchecked(&cmd->t_task_cdbs_sent);
35592
35593 - if (atomic_read(&cmd->t_task_cdbs_sent) ==
35594 + if (atomic_read_unchecked(&cmd->t_task_cdbs_sent) ==
35595 cmd->t_task_list_num)
35596 atomic_set(&cmd->t_transport_sent, 1);
35597
35598 @@ -4273,7 +4273,7 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
35599 atomic_set(&cmd->transport_lun_stop, 0);
35600 }
35601 if (!atomic_read(&cmd->t_transport_active) ||
35602 - atomic_read(&cmd->t_transport_aborted)) {
35603 + atomic_read_unchecked(&cmd->t_transport_aborted)) {
35604 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
35605 return false;
35606 }
35607 @@ -4522,7 +4522,7 @@ int transport_check_aborted_status(struct se_cmd *cmd, int send_status)
35608 {
35609 int ret = 0;
35610
35611 - if (atomic_read(&cmd->t_transport_aborted) != 0) {
35612 + if (atomic_read_unchecked(&cmd->t_transport_aborted) != 0) {
35613 if (!send_status ||
35614 (cmd->se_cmd_flags & SCF_SENT_DELAYED_TAS))
35615 return 1;
35616 @@ -4559,7 +4559,7 @@ void transport_send_task_abort(struct se_cmd *cmd)
35617 */
35618 if (cmd->data_direction == DMA_TO_DEVICE) {
35619 if (cmd->se_tfo->write_pending_status(cmd) != 0) {
35620 - atomic_inc(&cmd->t_transport_aborted);
35621 + atomic_inc_unchecked(&cmd->t_transport_aborted);
35622 smp_mb__after_atomic_inc();
35623 }
35624 }
35625 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
35626 index b9040be..e3f5aab 100644
35627 --- a/drivers/tty/hvc/hvcs.c
35628 +++ b/drivers/tty/hvc/hvcs.c
35629 @@ -83,6 +83,7 @@
35630 #include <asm/hvcserver.h>
35631 #include <asm/uaccess.h>
35632 #include <asm/vio.h>
35633 +#include <asm/local.h>
35634
35635 /*
35636 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
35637 @@ -270,7 +271,7 @@ struct hvcs_struct {
35638 unsigned int index;
35639
35640 struct tty_struct *tty;
35641 - int open_count;
35642 + local_t open_count;
35643
35644 /*
35645 * Used to tell the driver kernel_thread what operations need to take
35646 @@ -422,7 +423,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
35647
35648 spin_lock_irqsave(&hvcsd->lock, flags);
35649
35650 - if (hvcsd->open_count > 0) {
35651 + if (local_read(&hvcsd->open_count) > 0) {
35652 spin_unlock_irqrestore(&hvcsd->lock, flags);
35653 printk(KERN_INFO "HVCS: vterm state unchanged. "
35654 "The hvcs device node is still in use.\n");
35655 @@ -1145,7 +1146,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
35656 if ((retval = hvcs_partner_connect(hvcsd)))
35657 goto error_release;
35658
35659 - hvcsd->open_count = 1;
35660 + local_set(&hvcsd->open_count, 1);
35661 hvcsd->tty = tty;
35662 tty->driver_data = hvcsd;
35663
35664 @@ -1179,7 +1180,7 @@ fast_open:
35665
35666 spin_lock_irqsave(&hvcsd->lock, flags);
35667 kref_get(&hvcsd->kref);
35668 - hvcsd->open_count++;
35669 + local_inc(&hvcsd->open_count);
35670 hvcsd->todo_mask |= HVCS_SCHED_READ;
35671 spin_unlock_irqrestore(&hvcsd->lock, flags);
35672
35673 @@ -1223,7 +1224,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
35674 hvcsd = tty->driver_data;
35675
35676 spin_lock_irqsave(&hvcsd->lock, flags);
35677 - if (--hvcsd->open_count == 0) {
35678 + if (local_dec_and_test(&hvcsd->open_count)) {
35679
35680 vio_disable_interrupts(hvcsd->vdev);
35681
35682 @@ -1249,10 +1250,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
35683 free_irq(irq, hvcsd);
35684 kref_put(&hvcsd->kref, destroy_hvcs_struct);
35685 return;
35686 - } else if (hvcsd->open_count < 0) {
35687 + } else if (local_read(&hvcsd->open_count) < 0) {
35688 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
35689 " is missmanaged.\n",
35690 - hvcsd->vdev->unit_address, hvcsd->open_count);
35691 + hvcsd->vdev->unit_address, local_read(&hvcsd->open_count));
35692 }
35693
35694 spin_unlock_irqrestore(&hvcsd->lock, flags);
35695 @@ -1268,7 +1269,7 @@ static void hvcs_hangup(struct tty_struct * tty)
35696
35697 spin_lock_irqsave(&hvcsd->lock, flags);
35698 /* Preserve this so that we know how many kref refs to put */
35699 - temp_open_count = hvcsd->open_count;
35700 + temp_open_count = local_read(&hvcsd->open_count);
35701
35702 /*
35703 * Don't kref put inside the spinlock because the destruction
35704 @@ -1283,7 +1284,7 @@ static void hvcs_hangup(struct tty_struct * tty)
35705 hvcsd->tty->driver_data = NULL;
35706 hvcsd->tty = NULL;
35707
35708 - hvcsd->open_count = 0;
35709 + local_set(&hvcsd->open_count, 0);
35710
35711 /* This will drop any buffered data on the floor which is OK in a hangup
35712 * scenario. */
35713 @@ -1354,7 +1355,7 @@ static int hvcs_write(struct tty_struct *tty,
35714 * the middle of a write operation? This is a crummy place to do this
35715 * but we want to keep it all in the spinlock.
35716 */
35717 - if (hvcsd->open_count <= 0) {
35718 + if (local_read(&hvcsd->open_count) <= 0) {
35719 spin_unlock_irqrestore(&hvcsd->lock, flags);
35720 return -ENODEV;
35721 }
35722 @@ -1428,7 +1429,7 @@ static int hvcs_write_room(struct tty_struct *tty)
35723 {
35724 struct hvcs_struct *hvcsd = tty->driver_data;
35725
35726 - if (!hvcsd || hvcsd->open_count <= 0)
35727 + if (!hvcsd || local_read(&hvcsd->open_count) <= 0)
35728 return 0;
35729
35730 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
35731 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
35732 index ef92869..f4ebd88 100644
35733 --- a/drivers/tty/ipwireless/tty.c
35734 +++ b/drivers/tty/ipwireless/tty.c
35735 @@ -29,6 +29,7 @@
35736 #include <linux/tty_driver.h>
35737 #include <linux/tty_flip.h>
35738 #include <linux/uaccess.h>
35739 +#include <asm/local.h>
35740
35741 #include "tty.h"
35742 #include "network.h"
35743 @@ -51,7 +52,7 @@ struct ipw_tty {
35744 int tty_type;
35745 struct ipw_network *network;
35746 struct tty_struct *linux_tty;
35747 - int open_count;
35748 + local_t open_count;
35749 unsigned int control_lines;
35750 struct mutex ipw_tty_mutex;
35751 int tx_bytes_queued;
35752 @@ -127,10 +128,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
35753 mutex_unlock(&tty->ipw_tty_mutex);
35754 return -ENODEV;
35755 }
35756 - if (tty->open_count == 0)
35757 + if (local_read(&tty->open_count) == 0)
35758 tty->tx_bytes_queued = 0;
35759
35760 - tty->open_count++;
35761 + local_inc(&tty->open_count);
35762
35763 tty->linux_tty = linux_tty;
35764 linux_tty->driver_data = tty;
35765 @@ -146,9 +147,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
35766
35767 static void do_ipw_close(struct ipw_tty *tty)
35768 {
35769 - tty->open_count--;
35770 -
35771 - if (tty->open_count == 0) {
35772 + if (local_dec_return(&tty->open_count) == 0) {
35773 struct tty_struct *linux_tty = tty->linux_tty;
35774
35775 if (linux_tty != NULL) {
35776 @@ -169,7 +168,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
35777 return;
35778
35779 mutex_lock(&tty->ipw_tty_mutex);
35780 - if (tty->open_count == 0) {
35781 + if (local_read(&tty->open_count) == 0) {
35782 mutex_unlock(&tty->ipw_tty_mutex);
35783 return;
35784 }
35785 @@ -198,7 +197,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
35786 return;
35787 }
35788
35789 - if (!tty->open_count) {
35790 + if (!local_read(&tty->open_count)) {
35791 mutex_unlock(&tty->ipw_tty_mutex);
35792 return;
35793 }
35794 @@ -240,7 +239,7 @@ static int ipw_write(struct tty_struct *linux_tty,
35795 return -ENODEV;
35796
35797 mutex_lock(&tty->ipw_tty_mutex);
35798 - if (!tty->open_count) {
35799 + if (!local_read(&tty->open_count)) {
35800 mutex_unlock(&tty->ipw_tty_mutex);
35801 return -EINVAL;
35802 }
35803 @@ -280,7 +279,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
35804 if (!tty)
35805 return -ENODEV;
35806
35807 - if (!tty->open_count)
35808 + if (!local_read(&tty->open_count))
35809 return -EINVAL;
35810
35811 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
35812 @@ -322,7 +321,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
35813 if (!tty)
35814 return 0;
35815
35816 - if (!tty->open_count)
35817 + if (!local_read(&tty->open_count))
35818 return 0;
35819
35820 return tty->tx_bytes_queued;
35821 @@ -403,7 +402,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
35822 if (!tty)
35823 return -ENODEV;
35824
35825 - if (!tty->open_count)
35826 + if (!local_read(&tty->open_count))
35827 return -EINVAL;
35828
35829 return get_control_lines(tty);
35830 @@ -419,7 +418,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
35831 if (!tty)
35832 return -ENODEV;
35833
35834 - if (!tty->open_count)
35835 + if (!local_read(&tty->open_count))
35836 return -EINVAL;
35837
35838 return set_control_lines(tty, set, clear);
35839 @@ -433,7 +432,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
35840 if (!tty)
35841 return -ENODEV;
35842
35843 - if (!tty->open_count)
35844 + if (!local_read(&tty->open_count))
35845 return -EINVAL;
35846
35847 /* FIXME: Exactly how is the tty object locked here .. */
35848 @@ -582,7 +581,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
35849 against a parallel ioctl etc */
35850 mutex_lock(&ttyj->ipw_tty_mutex);
35851 }
35852 - while (ttyj->open_count)
35853 + while (local_read(&ttyj->open_count))
35854 do_ipw_close(ttyj);
35855 ipwireless_disassociate_network_ttys(network,
35856 ttyj->channel_idx);
35857 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
35858 index fc7bbba..9527e93 100644
35859 --- a/drivers/tty/n_gsm.c
35860 +++ b/drivers/tty/n_gsm.c
35861 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
35862 kref_init(&dlci->ref);
35863 mutex_init(&dlci->mutex);
35864 dlci->fifo = &dlci->_fifo;
35865 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
35866 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
35867 kfree(dlci);
35868 return NULL;
35869 }
35870 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
35871 index 39d6ab6..eb97f41 100644
35872 --- a/drivers/tty/n_tty.c
35873 +++ b/drivers/tty/n_tty.c
35874 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
35875 {
35876 *ops = tty_ldisc_N_TTY;
35877 ops->owner = NULL;
35878 - ops->refcount = ops->flags = 0;
35879 + atomic_set(&ops->refcount, 0);
35880 + ops->flags = 0;
35881 }
35882 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
35883 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
35884 index e18604b..a7d5a11 100644
35885 --- a/drivers/tty/pty.c
35886 +++ b/drivers/tty/pty.c
35887 @@ -773,8 +773,10 @@ static void __init unix98_pty_init(void)
35888 register_sysctl_table(pty_root_table);
35889
35890 /* Now create the /dev/ptmx special device */
35891 + pax_open_kernel();
35892 tty_default_fops(&ptmx_fops);
35893 - ptmx_fops.open = ptmx_open;
35894 + *(void **)&ptmx_fops.open = ptmx_open;
35895 + pax_close_kernel();
35896
35897 cdev_init(&ptmx_cdev, &ptmx_fops);
35898 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
35899 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
35900 index 2b42a01..32a2ed3 100644
35901 --- a/drivers/tty/serial/kgdboc.c
35902 +++ b/drivers/tty/serial/kgdboc.c
35903 @@ -24,8 +24,9 @@
35904 #define MAX_CONFIG_LEN 40
35905
35906 static struct kgdb_io kgdboc_io_ops;
35907 +static struct kgdb_io kgdboc_io_ops_console;
35908
35909 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
35910 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
35911 static int configured = -1;
35912
35913 static char config[MAX_CONFIG_LEN];
35914 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
35915 kgdboc_unregister_kbd();
35916 if (configured == 1)
35917 kgdb_unregister_io_module(&kgdboc_io_ops);
35918 + else if (configured == 2)
35919 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
35920 }
35921
35922 static int configure_kgdboc(void)
35923 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
35924 int err;
35925 char *cptr = config;
35926 struct console *cons;
35927 + int is_console = 0;
35928
35929 err = kgdboc_option_setup(config);
35930 if (err || !strlen(config) || isspace(config[0]))
35931 goto noconfig;
35932
35933 err = -ENODEV;
35934 - kgdboc_io_ops.is_console = 0;
35935 kgdb_tty_driver = NULL;
35936
35937 kgdboc_use_kms = 0;
35938 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
35939 int idx;
35940 if (cons->device && cons->device(cons, &idx) == p &&
35941 idx == tty_line) {
35942 - kgdboc_io_ops.is_console = 1;
35943 + is_console = 1;
35944 break;
35945 }
35946 cons = cons->next;
35947 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
35948 kgdb_tty_line = tty_line;
35949
35950 do_register:
35951 - err = kgdb_register_io_module(&kgdboc_io_ops);
35952 + if (is_console) {
35953 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
35954 + configured = 2;
35955 + } else {
35956 + err = kgdb_register_io_module(&kgdboc_io_ops);
35957 + configured = 1;
35958 + }
35959 if (err)
35960 goto noconfig;
35961
35962 - configured = 1;
35963 -
35964 return 0;
35965
35966 noconfig:
35967 @@ -213,7 +220,7 @@ noconfig:
35968 static int __init init_kgdboc(void)
35969 {
35970 /* Already configured? */
35971 - if (configured == 1)
35972 + if (configured >= 1)
35973 return 0;
35974
35975 return configure_kgdboc();
35976 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
35977 if (config[len - 1] == '\n')
35978 config[len - 1] = '\0';
35979
35980 - if (configured == 1)
35981 + if (configured >= 1)
35982 cleanup_kgdboc();
35983
35984 /* Go and configure with the new params. */
35985 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
35986 .post_exception = kgdboc_post_exp_handler,
35987 };
35988
35989 +static struct kgdb_io kgdboc_io_ops_console = {
35990 + .name = "kgdboc",
35991 + .read_char = kgdboc_get_char,
35992 + .write_char = kgdboc_put_char,
35993 + .pre_exception = kgdboc_pre_exp_handler,
35994 + .post_exception = kgdboc_post_exp_handler,
35995 + .is_console = 1
35996 +};
35997 +
35998 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
35999 /* This is only available if kgdboc is a built in for early debugging */
36000 static int __init kgdboc_early_init(char *opt)
36001 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
36002 index 05085be..67eadb0 100644
36003 --- a/drivers/tty/tty_io.c
36004 +++ b/drivers/tty/tty_io.c
36005 @@ -3240,7 +3240,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
36006
36007 void tty_default_fops(struct file_operations *fops)
36008 {
36009 - *fops = tty_fops;
36010 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
36011 }
36012
36013 /*
36014 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
36015 index 8e0924f..4204eb4 100644
36016 --- a/drivers/tty/tty_ldisc.c
36017 +++ b/drivers/tty/tty_ldisc.c
36018 @@ -75,7 +75,7 @@ static void put_ldisc(struct tty_ldisc *ld)
36019 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
36020 struct tty_ldisc_ops *ldo = ld->ops;
36021
36022 - ldo->refcount--;
36023 + atomic_dec(&ldo->refcount);
36024 module_put(ldo->owner);
36025 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
36026
36027 @@ -110,7 +110,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
36028 spin_lock_irqsave(&tty_ldisc_lock, flags);
36029 tty_ldiscs[disc] = new_ldisc;
36030 new_ldisc->num = disc;
36031 - new_ldisc->refcount = 0;
36032 + atomic_set(&new_ldisc->refcount, 0);
36033 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
36034
36035 return ret;
36036 @@ -138,7 +138,7 @@ int tty_unregister_ldisc(int disc)
36037 return -EINVAL;
36038
36039 spin_lock_irqsave(&tty_ldisc_lock, flags);
36040 - if (tty_ldiscs[disc]->refcount)
36041 + if (atomic_read(&tty_ldiscs[disc]->refcount))
36042 ret = -EBUSY;
36043 else
36044 tty_ldiscs[disc] = NULL;
36045 @@ -159,7 +159,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
36046 if (ldops) {
36047 ret = ERR_PTR(-EAGAIN);
36048 if (try_module_get(ldops->owner)) {
36049 - ldops->refcount++;
36050 + atomic_inc(&ldops->refcount);
36051 ret = ldops;
36052 }
36053 }
36054 @@ -172,7 +172,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
36055 unsigned long flags;
36056
36057 spin_lock_irqsave(&tty_ldisc_lock, flags);
36058 - ldops->refcount--;
36059 + atomic_dec(&ldops->refcount);
36060 module_put(ldops->owner);
36061 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
36062 }
36063 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
36064 index a605549..6bd3c96 100644
36065 --- a/drivers/tty/vt/keyboard.c
36066 +++ b/drivers/tty/vt/keyboard.c
36067 @@ -657,6 +657,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
36068 kbd->kbdmode == VC_OFF) &&
36069 value != KVAL(K_SAK))
36070 return; /* SAK is allowed even in raw mode */
36071 +
36072 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
36073 + {
36074 + void *func = fn_handler[value];
36075 + if (func == fn_show_state || func == fn_show_ptregs ||
36076 + func == fn_show_mem)
36077 + return;
36078 + }
36079 +#endif
36080 +
36081 fn_handler[value](vc);
36082 }
36083
36084 diff --git a/drivers/tty/vt/vt_ioctl.c b/drivers/tty/vt/vt_ioctl.c
36085 index 65447c5..0526f0a 100644
36086 --- a/drivers/tty/vt/vt_ioctl.c
36087 +++ b/drivers/tty/vt/vt_ioctl.c
36088 @@ -207,9 +207,6 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
36089 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
36090 return -EFAULT;
36091
36092 - if (!capable(CAP_SYS_TTY_CONFIG))
36093 - perm = 0;
36094 -
36095 switch (cmd) {
36096 case KDGKBENT:
36097 key_map = key_maps[s];
36098 @@ -221,6 +218,9 @@ do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm, struct kbd_str
36099 val = (i ? K_HOLE : K_NOSUCHMAP);
36100 return put_user(val, &user_kbe->kb_value);
36101 case KDSKBENT:
36102 + if (!capable(CAP_SYS_TTY_CONFIG))
36103 + perm = 0;
36104 +
36105 if (!perm)
36106 return -EPERM;
36107 if (!i && v == K_NOSUCHMAP) {
36108 @@ -322,9 +322,6 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
36109 int i, j, k;
36110 int ret;
36111
36112 - if (!capable(CAP_SYS_TTY_CONFIG))
36113 - perm = 0;
36114 -
36115 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
36116 if (!kbs) {
36117 ret = -ENOMEM;
36118 @@ -358,6 +355,9 @@ do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
36119 kfree(kbs);
36120 return ((p && *p) ? -EOVERFLOW : 0);
36121 case KDSKBSENT:
36122 + if (!capable(CAP_SYS_TTY_CONFIG))
36123 + perm = 0;
36124 +
36125 if (!perm) {
36126 ret = -EPERM;
36127 goto reterr;
36128 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
36129 index a783d53..cb30d94 100644
36130 --- a/drivers/uio/uio.c
36131 +++ b/drivers/uio/uio.c
36132 @@ -25,6 +25,7 @@
36133 #include <linux/kobject.h>
36134 #include <linux/cdev.h>
36135 #include <linux/uio_driver.h>
36136 +#include <asm/local.h>
36137
36138 #define UIO_MAX_DEVICES (1U << MINORBITS)
36139
36140 @@ -32,10 +33,10 @@ struct uio_device {
36141 struct module *owner;
36142 struct device *dev;
36143 int minor;
36144 - atomic_t event;
36145 + atomic_unchecked_t event;
36146 struct fasync_struct *async_queue;
36147 wait_queue_head_t wait;
36148 - int vma_count;
36149 + local_t vma_count;
36150 struct uio_info *info;
36151 struct kobject *map_dir;
36152 struct kobject *portio_dir;
36153 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
36154 struct device_attribute *attr, char *buf)
36155 {
36156 struct uio_device *idev = dev_get_drvdata(dev);
36157 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
36158 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
36159 }
36160
36161 static struct device_attribute uio_class_attributes[] = {
36162 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
36163 {
36164 struct uio_device *idev = info->uio_dev;
36165
36166 - atomic_inc(&idev->event);
36167 + atomic_inc_unchecked(&idev->event);
36168 wake_up_interruptible(&idev->wait);
36169 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
36170 }
36171 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
36172 }
36173
36174 listener->dev = idev;
36175 - listener->event_count = atomic_read(&idev->event);
36176 + listener->event_count = atomic_read_unchecked(&idev->event);
36177 filep->private_data = listener;
36178
36179 if (idev->info->open) {
36180 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
36181 return -EIO;
36182
36183 poll_wait(filep, &idev->wait, wait);
36184 - if (listener->event_count != atomic_read(&idev->event))
36185 + if (listener->event_count != atomic_read_unchecked(&idev->event))
36186 return POLLIN | POLLRDNORM;
36187 return 0;
36188 }
36189 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
36190 do {
36191 set_current_state(TASK_INTERRUPTIBLE);
36192
36193 - event_count = atomic_read(&idev->event);
36194 + event_count = atomic_read_unchecked(&idev->event);
36195 if (event_count != listener->event_count) {
36196 if (copy_to_user(buf, &event_count, count))
36197 retval = -EFAULT;
36198 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
36199 static void uio_vma_open(struct vm_area_struct *vma)
36200 {
36201 struct uio_device *idev = vma->vm_private_data;
36202 - idev->vma_count++;
36203 + local_inc(&idev->vma_count);
36204 }
36205
36206 static void uio_vma_close(struct vm_area_struct *vma)
36207 {
36208 struct uio_device *idev = vma->vm_private_data;
36209 - idev->vma_count--;
36210 + local_dec(&idev->vma_count);
36211 }
36212
36213 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36214 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
36215 idev->owner = owner;
36216 idev->info = info;
36217 init_waitqueue_head(&idev->wait);
36218 - atomic_set(&idev->event, 0);
36219 + atomic_set_unchecked(&idev->event, 0);
36220
36221 ret = uio_get_minor(idev);
36222 if (ret)
36223 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
36224 index a845f8b..4f54072 100644
36225 --- a/drivers/usb/atm/cxacru.c
36226 +++ b/drivers/usb/atm/cxacru.c
36227 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
36228 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
36229 if (ret < 2)
36230 return -EINVAL;
36231 - if (index < 0 || index > 0x7f)
36232 + if (index > 0x7f)
36233 return -EINVAL;
36234 pos += tmp;
36235
36236 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
36237 index d3448ca..d2864ca 100644
36238 --- a/drivers/usb/atm/usbatm.c
36239 +++ b/drivers/usb/atm/usbatm.c
36240 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36241 if (printk_ratelimit())
36242 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
36243 __func__, vpi, vci);
36244 - atomic_inc(&vcc->stats->rx_err);
36245 + atomic_inc_unchecked(&vcc->stats->rx_err);
36246 return;
36247 }
36248
36249 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36250 if (length > ATM_MAX_AAL5_PDU) {
36251 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
36252 __func__, length, vcc);
36253 - atomic_inc(&vcc->stats->rx_err);
36254 + atomic_inc_unchecked(&vcc->stats->rx_err);
36255 goto out;
36256 }
36257
36258 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36259 if (sarb->len < pdu_length) {
36260 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
36261 __func__, pdu_length, sarb->len, vcc);
36262 - atomic_inc(&vcc->stats->rx_err);
36263 + atomic_inc_unchecked(&vcc->stats->rx_err);
36264 goto out;
36265 }
36266
36267 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
36268 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
36269 __func__, vcc);
36270 - atomic_inc(&vcc->stats->rx_err);
36271 + atomic_inc_unchecked(&vcc->stats->rx_err);
36272 goto out;
36273 }
36274
36275 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36276 if (printk_ratelimit())
36277 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
36278 __func__, length);
36279 - atomic_inc(&vcc->stats->rx_drop);
36280 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36281 goto out;
36282 }
36283
36284 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
36285
36286 vcc->push(vcc, skb);
36287
36288 - atomic_inc(&vcc->stats->rx);
36289 + atomic_inc_unchecked(&vcc->stats->rx);
36290 out:
36291 skb_trim(sarb, 0);
36292 }
36293 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
36294 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
36295
36296 usbatm_pop(vcc, skb);
36297 - atomic_inc(&vcc->stats->tx);
36298 + atomic_inc_unchecked(&vcc->stats->tx);
36299
36300 skb = skb_dequeue(&instance->sndqueue);
36301 }
36302 @@ -773,11 +773,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
36303 if (!left--)
36304 return sprintf(page,
36305 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
36306 - atomic_read(&atm_dev->stats.aal5.tx),
36307 - atomic_read(&atm_dev->stats.aal5.tx_err),
36308 - atomic_read(&atm_dev->stats.aal5.rx),
36309 - atomic_read(&atm_dev->stats.aal5.rx_err),
36310 - atomic_read(&atm_dev->stats.aal5.rx_drop));
36311 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
36312 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
36313 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
36314 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
36315 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
36316
36317 if (!left--) {
36318 if (instance->disconnected)
36319 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
36320 index d956965..4179a77 100644
36321 --- a/drivers/usb/core/devices.c
36322 +++ b/drivers/usb/core/devices.c
36323 @@ -126,7 +126,7 @@ static const char format_endpt[] =
36324 * time it gets called.
36325 */
36326 static struct device_connect_event {
36327 - atomic_t count;
36328 + atomic_unchecked_t count;
36329 wait_queue_head_t wait;
36330 } device_event = {
36331 .count = ATOMIC_INIT(1),
36332 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
36333
36334 void usbfs_conn_disc_event(void)
36335 {
36336 - atomic_add(2, &device_event.count);
36337 + atomic_add_unchecked(2, &device_event.count);
36338 wake_up(&device_event.wait);
36339 }
36340
36341 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
36342
36343 poll_wait(file, &device_event.wait, wait);
36344
36345 - event_count = atomic_read(&device_event.count);
36346 + event_count = atomic_read_unchecked(&device_event.count);
36347 if (file->f_version != event_count) {
36348 file->f_version = event_count;
36349 return POLLIN | POLLRDNORM;
36350 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
36351 index b3bdfed..a9460e0 100644
36352 --- a/drivers/usb/core/message.c
36353 +++ b/drivers/usb/core/message.c
36354 @@ -869,8 +869,8 @@ char *usb_cache_string(struct usb_device *udev, int index)
36355 buf = kmalloc(MAX_USB_STRING_SIZE, GFP_NOIO);
36356 if (buf) {
36357 len = usb_string(udev, index, buf, MAX_USB_STRING_SIZE);
36358 - if (len > 0) {
36359 - smallbuf = kmalloc(++len, GFP_NOIO);
36360 + if (len++ > 0) {
36361 + smallbuf = kmalloc(len, GFP_NOIO);
36362 if (!smallbuf)
36363 return buf;
36364 memcpy(smallbuf, buf, len);
36365 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
36366 index 1fc8f12..20647c1 100644
36367 --- a/drivers/usb/early/ehci-dbgp.c
36368 +++ b/drivers/usb/early/ehci-dbgp.c
36369 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
36370
36371 #ifdef CONFIG_KGDB
36372 static struct kgdb_io kgdbdbgp_io_ops;
36373 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
36374 +static struct kgdb_io kgdbdbgp_io_ops_console;
36375 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
36376 #else
36377 #define dbgp_kgdb_mode (0)
36378 #endif
36379 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
36380 .write_char = kgdbdbgp_write_char,
36381 };
36382
36383 +static struct kgdb_io kgdbdbgp_io_ops_console = {
36384 + .name = "kgdbdbgp",
36385 + .read_char = kgdbdbgp_read_char,
36386 + .write_char = kgdbdbgp_write_char,
36387 + .is_console = 1
36388 +};
36389 +
36390 static int kgdbdbgp_wait_time;
36391
36392 static int __init kgdbdbgp_parse_config(char *str)
36393 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
36394 ptr++;
36395 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
36396 }
36397 - kgdb_register_io_module(&kgdbdbgp_io_ops);
36398 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
36399 + if (early_dbgp_console.index != -1)
36400 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
36401 + else
36402 + kgdb_register_io_module(&kgdbdbgp_io_ops);
36403
36404 return 0;
36405 }
36406 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
36407 index d6bea3e..60b250e 100644
36408 --- a/drivers/usb/wusbcore/wa-hc.h
36409 +++ b/drivers/usb/wusbcore/wa-hc.h
36410 @@ -192,7 +192,7 @@ struct wahc {
36411 struct list_head xfer_delayed_list;
36412 spinlock_t xfer_list_lock;
36413 struct work_struct xfer_work;
36414 - atomic_t xfer_id_count;
36415 + atomic_unchecked_t xfer_id_count;
36416 };
36417
36418
36419 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
36420 INIT_LIST_HEAD(&wa->xfer_delayed_list);
36421 spin_lock_init(&wa->xfer_list_lock);
36422 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
36423 - atomic_set(&wa->xfer_id_count, 1);
36424 + atomic_set_unchecked(&wa->xfer_id_count, 1);
36425 }
36426
36427 /**
36428 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
36429 index 57c01ab..8a05959 100644
36430 --- a/drivers/usb/wusbcore/wa-xfer.c
36431 +++ b/drivers/usb/wusbcore/wa-xfer.c
36432 @@ -296,7 +296,7 @@ out:
36433 */
36434 static void wa_xfer_id_init(struct wa_xfer *xfer)
36435 {
36436 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
36437 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
36438 }
36439
36440 /*
36441 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
36442 index c14c42b..f955cc2 100644
36443 --- a/drivers/vhost/vhost.c
36444 +++ b/drivers/vhost/vhost.c
36445 @@ -629,7 +629,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
36446 return 0;
36447 }
36448
36449 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
36450 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
36451 {
36452 struct file *eventfp, *filep = NULL,
36453 *pollstart = NULL, *pollstop = NULL;
36454 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
36455 index b0b2ac3..89a4399 100644
36456 --- a/drivers/video/aty/aty128fb.c
36457 +++ b/drivers/video/aty/aty128fb.c
36458 @@ -148,7 +148,7 @@ enum {
36459 };
36460
36461 /* Must match above enum */
36462 -static const char *r128_family[] __devinitdata = {
36463 +static const char *r128_family[] __devinitconst = {
36464 "AGP",
36465 "PCI",
36466 "PRO AGP",
36467 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
36468 index 5c3960d..15cf8fc 100644
36469 --- a/drivers/video/fbcmap.c
36470 +++ b/drivers/video/fbcmap.c
36471 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
36472 rc = -ENODEV;
36473 goto out;
36474 }
36475 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
36476 - !info->fbops->fb_setcmap)) {
36477 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
36478 rc = -EINVAL;
36479 goto out1;
36480 }
36481 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
36482 index ad93629..e020fc3 100644
36483 --- a/drivers/video/fbmem.c
36484 +++ b/drivers/video/fbmem.c
36485 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
36486 image->dx += image->width + 8;
36487 }
36488 } else if (rotate == FB_ROTATE_UD) {
36489 - for (x = 0; x < num && image->dx >= 0; x++) {
36490 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
36491 info->fbops->fb_imageblit(info, image);
36492 image->dx -= image->width + 8;
36493 }
36494 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
36495 image->dy += image->height + 8;
36496 }
36497 } else if (rotate == FB_ROTATE_CCW) {
36498 - for (x = 0; x < num && image->dy >= 0; x++) {
36499 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
36500 info->fbops->fb_imageblit(info, image);
36501 image->dy -= image->height + 8;
36502 }
36503 @@ -1143,7 +1143,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
36504 return -EFAULT;
36505 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
36506 return -EINVAL;
36507 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
36508 + if (con2fb.framebuffer >= FB_MAX)
36509 return -EINVAL;
36510 if (!registered_fb[con2fb.framebuffer])
36511 request_module("fb%d", con2fb.framebuffer);
36512 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
36513 index 5a5d092..265c5ed 100644
36514 --- a/drivers/video/geode/gx1fb_core.c
36515 +++ b/drivers/video/geode/gx1fb_core.c
36516 @@ -29,7 +29,7 @@ static int crt_option = 1;
36517 static char panel_option[32] = "";
36518
36519 /* Modes relevant to the GX1 (taken from modedb.c) */
36520 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
36521 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
36522 /* 640x480-60 VESA */
36523 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
36524 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
36525 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
36526 index 0fad23f..0e9afa4 100644
36527 --- a/drivers/video/gxt4500.c
36528 +++ b/drivers/video/gxt4500.c
36529 @@ -156,7 +156,7 @@ struct gxt4500_par {
36530 static char *mode_option;
36531
36532 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
36533 -static const struct fb_videomode defaultmode __devinitdata = {
36534 +static const struct fb_videomode defaultmode __devinitconst = {
36535 .refresh = 60,
36536 .xres = 1280,
36537 .yres = 1024,
36538 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
36539 return 0;
36540 }
36541
36542 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
36543 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
36544 .id = "IBM GXT4500P",
36545 .type = FB_TYPE_PACKED_PIXELS,
36546 .visual = FB_VISUAL_PSEUDOCOLOR,
36547 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
36548 index 7672d2e..b56437f 100644
36549 --- a/drivers/video/i810/i810_accel.c
36550 +++ b/drivers/video/i810/i810_accel.c
36551 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
36552 }
36553 }
36554 printk("ringbuffer lockup!!!\n");
36555 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
36556 i810_report_error(mmio);
36557 par->dev_flags |= LOCKUP;
36558 info->pixmap.scan_align = 1;
36559 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
36560 index 318f6fb..9a389c1 100644
36561 --- a/drivers/video/i810/i810_main.c
36562 +++ b/drivers/video/i810/i810_main.c
36563 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
36564 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
36565
36566 /* PCI */
36567 -static const char *i810_pci_list[] __devinitdata = {
36568 +static const char *i810_pci_list[] __devinitconst = {
36569 "Intel(R) 810 Framebuffer Device" ,
36570 "Intel(R) 810-DC100 Framebuffer Device" ,
36571 "Intel(R) 810E Framebuffer Device" ,
36572 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
36573 index de36693..3c63fc2 100644
36574 --- a/drivers/video/jz4740_fb.c
36575 +++ b/drivers/video/jz4740_fb.c
36576 @@ -136,7 +136,7 @@ struct jzfb {
36577 uint32_t pseudo_palette[16];
36578 };
36579
36580 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
36581 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
36582 .id = "JZ4740 FB",
36583 .type = FB_TYPE_PACKED_PIXELS,
36584 .visual = FB_VISUAL_TRUECOLOR,
36585 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
36586 index 3c14e43..eafa544 100644
36587 --- a/drivers/video/logo/logo_linux_clut224.ppm
36588 +++ b/drivers/video/logo/logo_linux_clut224.ppm
36589 @@ -1,1604 +1,1123 @@
36590 P3
36591 -# Standard 224-color Linux logo
36592 80 80
36593 255
36594 - 0 0 0 0 0 0 0 0 0 0 0 0
36595 - 0 0 0 0 0 0 0 0 0 0 0 0
36596 - 0 0 0 0 0 0 0 0 0 0 0 0
36597 - 0 0 0 0 0 0 0 0 0 0 0 0
36598 - 0 0 0 0 0 0 0 0 0 0 0 0
36599 - 0 0 0 0 0 0 0 0 0 0 0 0
36600 - 0 0 0 0 0 0 0 0 0 0 0 0
36601 - 0 0 0 0 0 0 0 0 0 0 0 0
36602 - 0 0 0 0 0 0 0 0 0 0 0 0
36603 - 6 6 6 6 6 6 10 10 10 10 10 10
36604 - 10 10 10 6 6 6 6 6 6 6 6 6
36605 - 0 0 0 0 0 0 0 0 0 0 0 0
36606 - 0 0 0 0 0 0 0 0 0 0 0 0
36607 - 0 0 0 0 0 0 0 0 0 0 0 0
36608 - 0 0 0 0 0 0 0 0 0 0 0 0
36609 - 0 0 0 0 0 0 0 0 0 0 0 0
36610 - 0 0 0 0 0 0 0 0 0 0 0 0
36611 - 0 0 0 0 0 0 0 0 0 0 0 0
36612 - 0 0 0 0 0 0 0 0 0 0 0 0
36613 - 0 0 0 0 0 0 0 0 0 0 0 0
36614 - 0 0 0 0 0 0 0 0 0 0 0 0
36615 - 0 0 0 0 0 0 0 0 0 0 0 0
36616 - 0 0 0 0 0 0 0 0 0 0 0 0
36617 - 0 0 0 0 0 0 0 0 0 0 0 0
36618 - 0 0 0 0 0 0 0 0 0 0 0 0
36619 - 0 0 0 0 0 0 0 0 0 0 0 0
36620 - 0 0 0 0 0 0 0 0 0 0 0 0
36621 - 0 0 0 0 0 0 0 0 0 0 0 0
36622 - 0 0 0 6 6 6 10 10 10 14 14 14
36623 - 22 22 22 26 26 26 30 30 30 34 34 34
36624 - 30 30 30 30 30 30 26 26 26 18 18 18
36625 - 14 14 14 10 10 10 6 6 6 0 0 0
36626 - 0 0 0 0 0 0 0 0 0 0 0 0
36627 - 0 0 0 0 0 0 0 0 0 0 0 0
36628 - 0 0 0 0 0 0 0 0 0 0 0 0
36629 - 0 0 0 0 0 0 0 0 0 0 0 0
36630 - 0 0 0 0 0 0 0 0 0 0 0 0
36631 - 0 0 0 0 0 0 0 0 0 0 0 0
36632 - 0 0 0 0 0 0 0 0 0 0 0 0
36633 - 0 0 0 0 0 0 0 0 0 0 0 0
36634 - 0 0 0 0 0 0 0 0 0 0 0 0
36635 - 0 0 0 0 0 1 0 0 1 0 0 0
36636 - 0 0 0 0 0 0 0 0 0 0 0 0
36637 - 0 0 0 0 0 0 0 0 0 0 0 0
36638 - 0 0 0 0 0 0 0 0 0 0 0 0
36639 - 0 0 0 0 0 0 0 0 0 0 0 0
36640 - 0 0 0 0 0 0 0 0 0 0 0 0
36641 - 0 0 0 0 0 0 0 0 0 0 0 0
36642 - 6 6 6 14 14 14 26 26 26 42 42 42
36643 - 54 54 54 66 66 66 78 78 78 78 78 78
36644 - 78 78 78 74 74 74 66 66 66 54 54 54
36645 - 42 42 42 26 26 26 18 18 18 10 10 10
36646 - 6 6 6 0 0 0 0 0 0 0 0 0
36647 - 0 0 0 0 0 0 0 0 0 0 0 0
36648 - 0 0 0 0 0 0 0 0 0 0 0 0
36649 - 0 0 0 0 0 0 0 0 0 0 0 0
36650 - 0 0 0 0 0 0 0 0 0 0 0 0
36651 - 0 0 0 0 0 0 0 0 0 0 0 0
36652 - 0 0 0 0 0 0 0 0 0 0 0 0
36653 - 0 0 0 0 0 0 0 0 0 0 0 0
36654 - 0 0 0 0 0 0 0 0 0 0 0 0
36655 - 0 0 1 0 0 0 0 0 0 0 0 0
36656 - 0 0 0 0 0 0 0 0 0 0 0 0
36657 - 0 0 0 0 0 0 0 0 0 0 0 0
36658 - 0 0 0 0 0 0 0 0 0 0 0 0
36659 - 0 0 0 0 0 0 0 0 0 0 0 0
36660 - 0 0 0 0 0 0 0 0 0 0 0 0
36661 - 0 0 0 0 0 0 0 0 0 10 10 10
36662 - 22 22 22 42 42 42 66 66 66 86 86 86
36663 - 66 66 66 38 38 38 38 38 38 22 22 22
36664 - 26 26 26 34 34 34 54 54 54 66 66 66
36665 - 86 86 86 70 70 70 46 46 46 26 26 26
36666 - 14 14 14 6 6 6 0 0 0 0 0 0
36667 - 0 0 0 0 0 0 0 0 0 0 0 0
36668 - 0 0 0 0 0 0 0 0 0 0 0 0
36669 - 0 0 0 0 0 0 0 0 0 0 0 0
36670 - 0 0 0 0 0 0 0 0 0 0 0 0
36671 - 0 0 0 0 0 0 0 0 0 0 0 0
36672 - 0 0 0 0 0 0 0 0 0 0 0 0
36673 - 0 0 0 0 0 0 0 0 0 0 0 0
36674 - 0 0 0 0 0 0 0 0 0 0 0 0
36675 - 0 0 1 0 0 1 0 0 1 0 0 0
36676 - 0 0 0 0 0 0 0 0 0 0 0 0
36677 - 0 0 0 0 0 0 0 0 0 0 0 0
36678 - 0 0 0 0 0 0 0 0 0 0 0 0
36679 - 0 0 0 0 0 0 0 0 0 0 0 0
36680 - 0 0 0 0 0 0 0 0 0 0 0 0
36681 - 0 0 0 0 0 0 10 10 10 26 26 26
36682 - 50 50 50 82 82 82 58 58 58 6 6 6
36683 - 2 2 6 2 2 6 2 2 6 2 2 6
36684 - 2 2 6 2 2 6 2 2 6 2 2 6
36685 - 6 6 6 54 54 54 86 86 86 66 66 66
36686 - 38 38 38 18 18 18 6 6 6 0 0 0
36687 - 0 0 0 0 0 0 0 0 0 0 0 0
36688 - 0 0 0 0 0 0 0 0 0 0 0 0
36689 - 0 0 0 0 0 0 0 0 0 0 0 0
36690 - 0 0 0 0 0 0 0 0 0 0 0 0
36691 - 0 0 0 0 0 0 0 0 0 0 0 0
36692 - 0 0 0 0 0 0 0 0 0 0 0 0
36693 - 0 0 0 0 0 0 0 0 0 0 0 0
36694 - 0 0 0 0 0 0 0 0 0 0 0 0
36695 - 0 0 0 0 0 0 0 0 0 0 0 0
36696 - 0 0 0 0 0 0 0 0 0 0 0 0
36697 - 0 0 0 0 0 0 0 0 0 0 0 0
36698 - 0 0 0 0 0 0 0 0 0 0 0 0
36699 - 0 0 0 0 0 0 0 0 0 0 0 0
36700 - 0 0 0 0 0 0 0 0 0 0 0 0
36701 - 0 0 0 6 6 6 22 22 22 50 50 50
36702 - 78 78 78 34 34 34 2 2 6 2 2 6
36703 - 2 2 6 2 2 6 2 2 6 2 2 6
36704 - 2 2 6 2 2 6 2 2 6 2 2 6
36705 - 2 2 6 2 2 6 6 6 6 70 70 70
36706 - 78 78 78 46 46 46 22 22 22 6 6 6
36707 - 0 0 0 0 0 0 0 0 0 0 0 0
36708 - 0 0 0 0 0 0 0 0 0 0 0 0
36709 - 0 0 0 0 0 0 0 0 0 0 0 0
36710 - 0 0 0 0 0 0 0 0 0 0 0 0
36711 - 0 0 0 0 0 0 0 0 0 0 0 0
36712 - 0 0 0 0 0 0 0 0 0 0 0 0
36713 - 0 0 0 0 0 0 0 0 0 0 0 0
36714 - 0 0 0 0 0 0 0 0 0 0 0 0
36715 - 0 0 1 0 0 1 0 0 1 0 0 0
36716 - 0 0 0 0 0 0 0 0 0 0 0 0
36717 - 0 0 0 0 0 0 0 0 0 0 0 0
36718 - 0 0 0 0 0 0 0 0 0 0 0 0
36719 - 0 0 0 0 0 0 0 0 0 0 0 0
36720 - 0 0 0 0 0 0 0 0 0 0 0 0
36721 - 6 6 6 18 18 18 42 42 42 82 82 82
36722 - 26 26 26 2 2 6 2 2 6 2 2 6
36723 - 2 2 6 2 2 6 2 2 6 2 2 6
36724 - 2 2 6 2 2 6 2 2 6 14 14 14
36725 - 46 46 46 34 34 34 6 6 6 2 2 6
36726 - 42 42 42 78 78 78 42 42 42 18 18 18
36727 - 6 6 6 0 0 0 0 0 0 0 0 0
36728 - 0 0 0 0 0 0 0 0 0 0 0 0
36729 - 0 0 0 0 0 0 0 0 0 0 0 0
36730 - 0 0 0 0 0 0 0 0 0 0 0 0
36731 - 0 0 0 0 0 0 0 0 0 0 0 0
36732 - 0 0 0 0 0 0 0 0 0 0 0 0
36733 - 0 0 0 0 0 0 0 0 0 0 0 0
36734 - 0 0 0 0 0 0 0 0 0 0 0 0
36735 - 0 0 1 0 0 0 0 0 1 0 0 0
36736 - 0 0 0 0 0 0 0 0 0 0 0 0
36737 - 0 0 0 0 0 0 0 0 0 0 0 0
36738 - 0 0 0 0 0 0 0 0 0 0 0 0
36739 - 0 0 0 0 0 0 0 0 0 0 0 0
36740 - 0 0 0 0 0 0 0 0 0 0 0 0
36741 - 10 10 10 30 30 30 66 66 66 58 58 58
36742 - 2 2 6 2 2 6 2 2 6 2 2 6
36743 - 2 2 6 2 2 6 2 2 6 2 2 6
36744 - 2 2 6 2 2 6 2 2 6 26 26 26
36745 - 86 86 86 101 101 101 46 46 46 10 10 10
36746 - 2 2 6 58 58 58 70 70 70 34 34 34
36747 - 10 10 10 0 0 0 0 0 0 0 0 0
36748 - 0 0 0 0 0 0 0 0 0 0 0 0
36749 - 0 0 0 0 0 0 0 0 0 0 0 0
36750 - 0 0 0 0 0 0 0 0 0 0 0 0
36751 - 0 0 0 0 0 0 0 0 0 0 0 0
36752 - 0 0 0 0 0 0 0 0 0 0 0 0
36753 - 0 0 0 0 0 0 0 0 0 0 0 0
36754 - 0 0 0 0 0 0 0 0 0 0 0 0
36755 - 0 0 1 0 0 1 0 0 1 0 0 0
36756 - 0 0 0 0 0 0 0 0 0 0 0 0
36757 - 0 0 0 0 0 0 0 0 0 0 0 0
36758 - 0 0 0 0 0 0 0 0 0 0 0 0
36759 - 0 0 0 0 0 0 0 0 0 0 0 0
36760 - 0 0 0 0 0 0 0 0 0 0 0 0
36761 - 14 14 14 42 42 42 86 86 86 10 10 10
36762 - 2 2 6 2 2 6 2 2 6 2 2 6
36763 - 2 2 6 2 2 6 2 2 6 2 2 6
36764 - 2 2 6 2 2 6 2 2 6 30 30 30
36765 - 94 94 94 94 94 94 58 58 58 26 26 26
36766 - 2 2 6 6 6 6 78 78 78 54 54 54
36767 - 22 22 22 6 6 6 0 0 0 0 0 0
36768 - 0 0 0 0 0 0 0 0 0 0 0 0
36769 - 0 0 0 0 0 0 0 0 0 0 0 0
36770 - 0 0 0 0 0 0 0 0 0 0 0 0
36771 - 0 0 0 0 0 0 0 0 0 0 0 0
36772 - 0 0 0 0 0 0 0 0 0 0 0 0
36773 - 0 0 0 0 0 0 0 0 0 0 0 0
36774 - 0 0 0 0 0 0 0 0 0 0 0 0
36775 - 0 0 0 0 0 0 0 0 0 0 0 0
36776 - 0 0 0 0 0 0 0 0 0 0 0 0
36777 - 0 0 0 0 0 0 0 0 0 0 0 0
36778 - 0 0 0 0 0 0 0 0 0 0 0 0
36779 - 0 0 0 0 0 0 0 0 0 0 0 0
36780 - 0 0 0 0 0 0 0 0 0 6 6 6
36781 - 22 22 22 62 62 62 62 62 62 2 2 6
36782 - 2 2 6 2 2 6 2 2 6 2 2 6
36783 - 2 2 6 2 2 6 2 2 6 2 2 6
36784 - 2 2 6 2 2 6 2 2 6 26 26 26
36785 - 54 54 54 38 38 38 18 18 18 10 10 10
36786 - 2 2 6 2 2 6 34 34 34 82 82 82
36787 - 38 38 38 14 14 14 0 0 0 0 0 0
36788 - 0 0 0 0 0 0 0 0 0 0 0 0
36789 - 0 0 0 0 0 0 0 0 0 0 0 0
36790 - 0 0 0 0 0 0 0 0 0 0 0 0
36791 - 0 0 0 0 0 0 0 0 0 0 0 0
36792 - 0 0 0 0 0 0 0 0 0 0 0 0
36793 - 0 0 0 0 0 0 0 0 0 0 0 0
36794 - 0 0 0 0 0 0 0 0 0 0 0 0
36795 - 0 0 0 0 0 1 0 0 1 0 0 0
36796 - 0 0 0 0 0 0 0 0 0 0 0 0
36797 - 0 0 0 0 0 0 0 0 0 0 0 0
36798 - 0 0 0 0 0 0 0 0 0 0 0 0
36799 - 0 0 0 0 0 0 0 0 0 0 0 0
36800 - 0 0 0 0 0 0 0 0 0 6 6 6
36801 - 30 30 30 78 78 78 30 30 30 2 2 6
36802 - 2 2 6 2 2 6 2 2 6 2 2 6
36803 - 2 2 6 2 2 6 2 2 6 2 2 6
36804 - 2 2 6 2 2 6 2 2 6 10 10 10
36805 - 10 10 10 2 2 6 2 2 6 2 2 6
36806 - 2 2 6 2 2 6 2 2 6 78 78 78
36807 - 50 50 50 18 18 18 6 6 6 0 0 0
36808 - 0 0 0 0 0 0 0 0 0 0 0 0
36809 - 0 0 0 0 0 0 0 0 0 0 0 0
36810 - 0 0 0 0 0 0 0 0 0 0 0 0
36811 - 0 0 0 0 0 0 0 0 0 0 0 0
36812 - 0 0 0 0 0 0 0 0 0 0 0 0
36813 - 0 0 0 0 0 0 0 0 0 0 0 0
36814 - 0 0 0 0 0 0 0 0 0 0 0 0
36815 - 0 0 1 0 0 0 0 0 0 0 0 0
36816 - 0 0 0 0 0 0 0 0 0 0 0 0
36817 - 0 0 0 0 0 0 0 0 0 0 0 0
36818 - 0 0 0 0 0 0 0 0 0 0 0 0
36819 - 0 0 0 0 0 0 0 0 0 0 0 0
36820 - 0 0 0 0 0 0 0 0 0 10 10 10
36821 - 38 38 38 86 86 86 14 14 14 2 2 6
36822 - 2 2 6 2 2 6 2 2 6 2 2 6
36823 - 2 2 6 2 2 6 2 2 6 2 2 6
36824 - 2 2 6 2 2 6 2 2 6 2 2 6
36825 - 2 2 6 2 2 6 2 2 6 2 2 6
36826 - 2 2 6 2 2 6 2 2 6 54 54 54
36827 - 66 66 66 26 26 26 6 6 6 0 0 0
36828 - 0 0 0 0 0 0 0 0 0 0 0 0
36829 - 0 0 0 0 0 0 0 0 0 0 0 0
36830 - 0 0 0 0 0 0 0 0 0 0 0 0
36831 - 0 0 0 0 0 0 0 0 0 0 0 0
36832 - 0 0 0 0 0 0 0 0 0 0 0 0
36833 - 0 0 0 0 0 0 0 0 0 0 0 0
36834 - 0 0 0 0 0 0 0 0 0 0 0 0
36835 - 0 0 0 0 0 1 0 0 1 0 0 0
36836 - 0 0 0 0 0 0 0 0 0 0 0 0
36837 - 0 0 0 0 0 0 0 0 0 0 0 0
36838 - 0 0 0 0 0 0 0 0 0 0 0 0
36839 - 0 0 0 0 0 0 0 0 0 0 0 0
36840 - 0 0 0 0 0 0 0 0 0 14 14 14
36841 - 42 42 42 82 82 82 2 2 6 2 2 6
36842 - 2 2 6 6 6 6 10 10 10 2 2 6
36843 - 2 2 6 2 2 6 2 2 6 2 2 6
36844 - 2 2 6 2 2 6 2 2 6 6 6 6
36845 - 14 14 14 10 10 10 2 2 6 2 2 6
36846 - 2 2 6 2 2 6 2 2 6 18 18 18
36847 - 82 82 82 34 34 34 10 10 10 0 0 0
36848 - 0 0 0 0 0 0 0 0 0 0 0 0
36849 - 0 0 0 0 0 0 0 0 0 0 0 0
36850 - 0 0 0 0 0 0 0 0 0 0 0 0
36851 - 0 0 0 0 0 0 0 0 0 0 0 0
36852 - 0 0 0 0 0 0 0 0 0 0 0 0
36853 - 0 0 0 0 0 0 0 0 0 0 0 0
36854 - 0 0 0 0 0 0 0 0 0 0 0 0
36855 - 0 0 1 0 0 0 0 0 0 0 0 0
36856 - 0 0 0 0 0 0 0 0 0 0 0 0
36857 - 0 0 0 0 0 0 0 0 0 0 0 0
36858 - 0 0 0 0 0 0 0 0 0 0 0 0
36859 - 0 0 0 0 0 0 0 0 0 0 0 0
36860 - 0 0 0 0 0 0 0 0 0 14 14 14
36861 - 46 46 46 86 86 86 2 2 6 2 2 6
36862 - 6 6 6 6 6 6 22 22 22 34 34 34
36863 - 6 6 6 2 2 6 2 2 6 2 2 6
36864 - 2 2 6 2 2 6 18 18 18 34 34 34
36865 - 10 10 10 50 50 50 22 22 22 2 2 6
36866 - 2 2 6 2 2 6 2 2 6 10 10 10
36867 - 86 86 86 42 42 42 14 14 14 0 0 0
36868 - 0 0 0 0 0 0 0 0 0 0 0 0
36869 - 0 0 0 0 0 0 0 0 0 0 0 0
36870 - 0 0 0 0 0 0 0 0 0 0 0 0
36871 - 0 0 0 0 0 0 0 0 0 0 0 0
36872 - 0 0 0 0 0 0 0 0 0 0 0 0
36873 - 0 0 0 0 0 0 0 0 0 0 0 0
36874 - 0 0 0 0 0 0 0 0 0 0 0 0
36875 - 0 0 1 0 0 1 0 0 1 0 0 0
36876 - 0 0 0 0 0 0 0 0 0 0 0 0
36877 - 0 0 0 0 0 0 0 0 0 0 0 0
36878 - 0 0 0 0 0 0 0 0 0 0 0 0
36879 - 0 0 0 0 0 0 0 0 0 0 0 0
36880 - 0 0 0 0 0 0 0 0 0 14 14 14
36881 - 46 46 46 86 86 86 2 2 6 2 2 6
36882 - 38 38 38 116 116 116 94 94 94 22 22 22
36883 - 22 22 22 2 2 6 2 2 6 2 2 6
36884 - 14 14 14 86 86 86 138 138 138 162 162 162
36885 -154 154 154 38 38 38 26 26 26 6 6 6
36886 - 2 2 6 2 2 6 2 2 6 2 2 6
36887 - 86 86 86 46 46 46 14 14 14 0 0 0
36888 - 0 0 0 0 0 0 0 0 0 0 0 0
36889 - 0 0 0 0 0 0 0 0 0 0 0 0
36890 - 0 0 0 0 0 0 0 0 0 0 0 0
36891 - 0 0 0 0 0 0 0 0 0 0 0 0
36892 - 0 0 0 0 0 0 0 0 0 0 0 0
36893 - 0 0 0 0 0 0 0 0 0 0 0 0
36894 - 0 0 0 0 0 0 0 0 0 0 0 0
36895 - 0 0 0 0 0 0 0 0 0 0 0 0
36896 - 0 0 0 0 0 0 0 0 0 0 0 0
36897 - 0 0 0 0 0 0 0 0 0 0 0 0
36898 - 0 0 0 0 0 0 0 0 0 0 0 0
36899 - 0 0 0 0 0 0 0 0 0 0 0 0
36900 - 0 0 0 0 0 0 0 0 0 14 14 14
36901 - 46 46 46 86 86 86 2 2 6 14 14 14
36902 -134 134 134 198 198 198 195 195 195 116 116 116
36903 - 10 10 10 2 2 6 2 2 6 6 6 6
36904 -101 98 89 187 187 187 210 210 210 218 218 218
36905 -214 214 214 134 134 134 14 14 14 6 6 6
36906 - 2 2 6 2 2 6 2 2 6 2 2 6
36907 - 86 86 86 50 50 50 18 18 18 6 6 6
36908 - 0 0 0 0 0 0 0 0 0 0 0 0
36909 - 0 0 0 0 0 0 0 0 0 0 0 0
36910 - 0 0 0 0 0 0 0 0 0 0 0 0
36911 - 0 0 0 0 0 0 0 0 0 0 0 0
36912 - 0 0 0 0 0 0 0 0 0 0 0 0
36913 - 0 0 0 0 0 0 0 0 0 0 0 0
36914 - 0 0 0 0 0 0 0 0 1 0 0 0
36915 - 0 0 1 0 0 1 0 0 1 0 0 0
36916 - 0 0 0 0 0 0 0 0 0 0 0 0
36917 - 0 0 0 0 0 0 0 0 0 0 0 0
36918 - 0 0 0 0 0 0 0 0 0 0 0 0
36919 - 0 0 0 0 0 0 0 0 0 0 0 0
36920 - 0 0 0 0 0 0 0 0 0 14 14 14
36921 - 46 46 46 86 86 86 2 2 6 54 54 54
36922 -218 218 218 195 195 195 226 226 226 246 246 246
36923 - 58 58 58 2 2 6 2 2 6 30 30 30
36924 -210 210 210 253 253 253 174 174 174 123 123 123
36925 -221 221 221 234 234 234 74 74 74 2 2 6
36926 - 2 2 6 2 2 6 2 2 6 2 2 6
36927 - 70 70 70 58 58 58 22 22 22 6 6 6
36928 - 0 0 0 0 0 0 0 0 0 0 0 0
36929 - 0 0 0 0 0 0 0 0 0 0 0 0
36930 - 0 0 0 0 0 0 0 0 0 0 0 0
36931 - 0 0 0 0 0 0 0 0 0 0 0 0
36932 - 0 0 0 0 0 0 0 0 0 0 0 0
36933 - 0 0 0 0 0 0 0 0 0 0 0 0
36934 - 0 0 0 0 0 0 0 0 0 0 0 0
36935 - 0 0 0 0 0 0 0 0 0 0 0 0
36936 - 0 0 0 0 0 0 0 0 0 0 0 0
36937 - 0 0 0 0 0 0 0 0 0 0 0 0
36938 - 0 0 0 0 0 0 0 0 0 0 0 0
36939 - 0 0 0 0 0 0 0 0 0 0 0 0
36940 - 0 0 0 0 0 0 0 0 0 14 14 14
36941 - 46 46 46 82 82 82 2 2 6 106 106 106
36942 -170 170 170 26 26 26 86 86 86 226 226 226
36943 -123 123 123 10 10 10 14 14 14 46 46 46
36944 -231 231 231 190 190 190 6 6 6 70 70 70
36945 - 90 90 90 238 238 238 158 158 158 2 2 6
36946 - 2 2 6 2 2 6 2 2 6 2 2 6
36947 - 70 70 70 58 58 58 22 22 22 6 6 6
36948 - 0 0 0 0 0 0 0 0 0 0 0 0
36949 - 0 0 0 0 0 0 0 0 0 0 0 0
36950 - 0 0 0 0 0 0 0 0 0 0 0 0
36951 - 0 0 0 0 0 0 0 0 0 0 0 0
36952 - 0 0 0 0 0 0 0 0 0 0 0 0
36953 - 0 0 0 0 0 0 0 0 0 0 0 0
36954 - 0 0 0 0 0 0 0 0 1 0 0 0
36955 - 0 0 1 0 0 1 0 0 1 0 0 0
36956 - 0 0 0 0 0 0 0 0 0 0 0 0
36957 - 0 0 0 0 0 0 0 0 0 0 0 0
36958 - 0 0 0 0 0 0 0 0 0 0 0 0
36959 - 0 0 0 0 0 0 0 0 0 0 0 0
36960 - 0 0 0 0 0 0 0 0 0 14 14 14
36961 - 42 42 42 86 86 86 6 6 6 116 116 116
36962 -106 106 106 6 6 6 70 70 70 149 149 149
36963 -128 128 128 18 18 18 38 38 38 54 54 54
36964 -221 221 221 106 106 106 2 2 6 14 14 14
36965 - 46 46 46 190 190 190 198 198 198 2 2 6
36966 - 2 2 6 2 2 6 2 2 6 2 2 6
36967 - 74 74 74 62 62 62 22 22 22 6 6 6
36968 - 0 0 0 0 0 0 0 0 0 0 0 0
36969 - 0 0 0 0 0 0 0 0 0 0 0 0
36970 - 0 0 0 0 0 0 0 0 0 0 0 0
36971 - 0 0 0 0 0 0 0 0 0 0 0 0
36972 - 0 0 0 0 0 0 0 0 0 0 0 0
36973 - 0 0 0 0 0 0 0 0 0 0 0 0
36974 - 0 0 0 0 0 0 0 0 1 0 0 0
36975 - 0 0 1 0 0 0 0 0 1 0 0 0
36976 - 0 0 0 0 0 0 0 0 0 0 0 0
36977 - 0 0 0 0 0 0 0 0 0 0 0 0
36978 - 0 0 0 0 0 0 0 0 0 0 0 0
36979 - 0 0 0 0 0 0 0 0 0 0 0 0
36980 - 0 0 0 0 0 0 0 0 0 14 14 14
36981 - 42 42 42 94 94 94 14 14 14 101 101 101
36982 -128 128 128 2 2 6 18 18 18 116 116 116
36983 -118 98 46 121 92 8 121 92 8 98 78 10
36984 -162 162 162 106 106 106 2 2 6 2 2 6
36985 - 2 2 6 195 195 195 195 195 195 6 6 6
36986 - 2 2 6 2 2 6 2 2 6 2 2 6
36987 - 74 74 74 62 62 62 22 22 22 6 6 6
36988 - 0 0 0 0 0 0 0 0 0 0 0 0
36989 - 0 0 0 0 0 0 0 0 0 0 0 0
36990 - 0 0 0 0 0 0 0 0 0 0 0 0
36991 - 0 0 0 0 0 0 0 0 0 0 0 0
36992 - 0 0 0 0 0 0 0 0 0 0 0 0
36993 - 0 0 0 0 0 0 0 0 0 0 0 0
36994 - 0 0 0 0 0 0 0 0 1 0 0 1
36995 - 0 0 1 0 0 0 0 0 1 0 0 0
36996 - 0 0 0 0 0 0 0 0 0 0 0 0
36997 - 0 0 0 0 0 0 0 0 0 0 0 0
36998 - 0 0 0 0 0 0 0 0 0 0 0 0
36999 - 0 0 0 0 0 0 0 0 0 0 0 0
37000 - 0 0 0 0 0 0 0 0 0 10 10 10
37001 - 38 38 38 90 90 90 14 14 14 58 58 58
37002 -210 210 210 26 26 26 54 38 6 154 114 10
37003 -226 170 11 236 186 11 225 175 15 184 144 12
37004 -215 174 15 175 146 61 37 26 9 2 2 6
37005 - 70 70 70 246 246 246 138 138 138 2 2 6
37006 - 2 2 6 2 2 6 2 2 6 2 2 6
37007 - 70 70 70 66 66 66 26 26 26 6 6 6
37008 - 0 0 0 0 0 0 0 0 0 0 0 0
37009 - 0 0 0 0 0 0 0 0 0 0 0 0
37010 - 0 0 0 0 0 0 0 0 0 0 0 0
37011 - 0 0 0 0 0 0 0 0 0 0 0 0
37012 - 0 0 0 0 0 0 0 0 0 0 0 0
37013 - 0 0 0 0 0 0 0 0 0 0 0 0
37014 - 0 0 0 0 0 0 0 0 0 0 0 0
37015 - 0 0 0 0 0 0 0 0 0 0 0 0
37016 - 0 0 0 0 0 0 0 0 0 0 0 0
37017 - 0 0 0 0 0 0 0 0 0 0 0 0
37018 - 0 0 0 0 0 0 0 0 0 0 0 0
37019 - 0 0 0 0 0 0 0 0 0 0 0 0
37020 - 0 0 0 0 0 0 0 0 0 10 10 10
37021 - 38 38 38 86 86 86 14 14 14 10 10 10
37022 -195 195 195 188 164 115 192 133 9 225 175 15
37023 -239 182 13 234 190 10 232 195 16 232 200 30
37024 -245 207 45 241 208 19 232 195 16 184 144 12
37025 -218 194 134 211 206 186 42 42 42 2 2 6
37026 - 2 2 6 2 2 6 2 2 6 2 2 6
37027 - 50 50 50 74 74 74 30 30 30 6 6 6
37028 - 0 0 0 0 0 0 0 0 0 0 0 0
37029 - 0 0 0 0 0 0 0 0 0 0 0 0
37030 - 0 0 0 0 0 0 0 0 0 0 0 0
37031 - 0 0 0 0 0 0 0 0 0 0 0 0
37032 - 0 0 0 0 0 0 0 0 0 0 0 0
37033 - 0 0 0 0 0 0 0 0 0 0 0 0
37034 - 0 0 0 0 0 0 0 0 0 0 0 0
37035 - 0 0 0 0 0 0 0 0 0 0 0 0
37036 - 0 0 0 0 0 0 0 0 0 0 0 0
37037 - 0 0 0 0 0 0 0 0 0 0 0 0
37038 - 0 0 0 0 0 0 0 0 0 0 0 0
37039 - 0 0 0 0 0 0 0 0 0 0 0 0
37040 - 0 0 0 0 0 0 0 0 0 10 10 10
37041 - 34 34 34 86 86 86 14 14 14 2 2 6
37042 -121 87 25 192 133 9 219 162 10 239 182 13
37043 -236 186 11 232 195 16 241 208 19 244 214 54
37044 -246 218 60 246 218 38 246 215 20 241 208 19
37045 -241 208 19 226 184 13 121 87 25 2 2 6
37046 - 2 2 6 2 2 6 2 2 6 2 2 6
37047 - 50 50 50 82 82 82 34 34 34 10 10 10
37048 - 0 0 0 0 0 0 0 0 0 0 0 0
37049 - 0 0 0 0 0 0 0 0 0 0 0 0
37050 - 0 0 0 0 0 0 0 0 0 0 0 0
37051 - 0 0 0 0 0 0 0 0 0 0 0 0
37052 - 0 0 0 0 0 0 0 0 0 0 0 0
37053 - 0 0 0 0 0 0 0 0 0 0 0 0
37054 - 0 0 0 0 0 0 0 0 0 0 0 0
37055 - 0 0 0 0 0 0 0 0 0 0 0 0
37056 - 0 0 0 0 0 0 0 0 0 0 0 0
37057 - 0 0 0 0 0 0 0 0 0 0 0 0
37058 - 0 0 0 0 0 0 0 0 0 0 0 0
37059 - 0 0 0 0 0 0 0 0 0 0 0 0
37060 - 0 0 0 0 0 0 0 0 0 10 10 10
37061 - 34 34 34 82 82 82 30 30 30 61 42 6
37062 -180 123 7 206 145 10 230 174 11 239 182 13
37063 -234 190 10 238 202 15 241 208 19 246 218 74
37064 -246 218 38 246 215 20 246 215 20 246 215 20
37065 -226 184 13 215 174 15 184 144 12 6 6 6
37066 - 2 2 6 2 2 6 2 2 6 2 2 6
37067 - 26 26 26 94 94 94 42 42 42 14 14 14
37068 - 0 0 0 0 0 0 0 0 0 0 0 0
37069 - 0 0 0 0 0 0 0 0 0 0 0 0
37070 - 0 0 0 0 0 0 0 0 0 0 0 0
37071 - 0 0 0 0 0 0 0 0 0 0 0 0
37072 - 0 0 0 0 0 0 0 0 0 0 0 0
37073 - 0 0 0 0 0 0 0 0 0 0 0 0
37074 - 0 0 0 0 0 0 0 0 0 0 0 0
37075 - 0 0 0 0 0 0 0 0 0 0 0 0
37076 - 0 0 0 0 0 0 0 0 0 0 0 0
37077 - 0 0 0 0 0 0 0 0 0 0 0 0
37078 - 0 0 0 0 0 0 0 0 0 0 0 0
37079 - 0 0 0 0 0 0 0 0 0 0 0 0
37080 - 0 0 0 0 0 0 0 0 0 10 10 10
37081 - 30 30 30 78 78 78 50 50 50 104 69 6
37082 -192 133 9 216 158 10 236 178 12 236 186 11
37083 -232 195 16 241 208 19 244 214 54 245 215 43
37084 -246 215 20 246 215 20 241 208 19 198 155 10
37085 -200 144 11 216 158 10 156 118 10 2 2 6
37086 - 2 2 6 2 2 6 2 2 6 2 2 6
37087 - 6 6 6 90 90 90 54 54 54 18 18 18
37088 - 6 6 6 0 0 0 0 0 0 0 0 0
37089 - 0 0 0 0 0 0 0 0 0 0 0 0
37090 - 0 0 0 0 0 0 0 0 0 0 0 0
37091 - 0 0 0 0 0 0 0 0 0 0 0 0
37092 - 0 0 0 0 0 0 0 0 0 0 0 0
37093 - 0 0 0 0 0 0 0 0 0 0 0 0
37094 - 0 0 0 0 0 0 0 0 0 0 0 0
37095 - 0 0 0 0 0 0 0 0 0 0 0 0
37096 - 0 0 0 0 0 0 0 0 0 0 0 0
37097 - 0 0 0 0 0 0 0 0 0 0 0 0
37098 - 0 0 0 0 0 0 0 0 0 0 0 0
37099 - 0 0 0 0 0 0 0 0 0 0 0 0
37100 - 0 0 0 0 0 0 0 0 0 10 10 10
37101 - 30 30 30 78 78 78 46 46 46 22 22 22
37102 -137 92 6 210 162 10 239 182 13 238 190 10
37103 -238 202 15 241 208 19 246 215 20 246 215 20
37104 -241 208 19 203 166 17 185 133 11 210 150 10
37105 -216 158 10 210 150 10 102 78 10 2 2 6
37106 - 6 6 6 54 54 54 14 14 14 2 2 6
37107 - 2 2 6 62 62 62 74 74 74 30 30 30
37108 - 10 10 10 0 0 0 0 0 0 0 0 0
37109 - 0 0 0 0 0 0 0 0 0 0 0 0
37110 - 0 0 0 0 0 0 0 0 0 0 0 0
37111 - 0 0 0 0 0 0 0 0 0 0 0 0
37112 - 0 0 0 0 0 0 0 0 0 0 0 0
37113 - 0 0 0 0 0 0 0 0 0 0 0 0
37114 - 0 0 0 0 0 0 0 0 0 0 0 0
37115 - 0 0 0 0 0 0 0 0 0 0 0 0
37116 - 0 0 0 0 0 0 0 0 0 0 0 0
37117 - 0 0 0 0 0 0 0 0 0 0 0 0
37118 - 0 0 0 0 0 0 0 0 0 0 0 0
37119 - 0 0 0 0 0 0 0 0 0 0 0 0
37120 - 0 0 0 0 0 0 0 0 0 10 10 10
37121 - 34 34 34 78 78 78 50 50 50 6 6 6
37122 - 94 70 30 139 102 15 190 146 13 226 184 13
37123 -232 200 30 232 195 16 215 174 15 190 146 13
37124 -168 122 10 192 133 9 210 150 10 213 154 11
37125 -202 150 34 182 157 106 101 98 89 2 2 6
37126 - 2 2 6 78 78 78 116 116 116 58 58 58
37127 - 2 2 6 22 22 22 90 90 90 46 46 46
37128 - 18 18 18 6 6 6 0 0 0 0 0 0
37129 - 0 0 0 0 0 0 0 0 0 0 0 0
37130 - 0 0 0 0 0 0 0 0 0 0 0 0
37131 - 0 0 0 0 0 0 0 0 0 0 0 0
37132 - 0 0 0 0 0 0 0 0 0 0 0 0
37133 - 0 0 0 0 0 0 0 0 0 0 0 0
37134 - 0 0 0 0 0 0 0 0 0 0 0 0
37135 - 0 0 0 0 0 0 0 0 0 0 0 0
37136 - 0 0 0 0 0 0 0 0 0 0 0 0
37137 - 0 0 0 0 0 0 0 0 0 0 0 0
37138 - 0 0 0 0 0 0 0 0 0 0 0 0
37139 - 0 0 0 0 0 0 0 0 0 0 0 0
37140 - 0 0 0 0 0 0 0 0 0 10 10 10
37141 - 38 38 38 86 86 86 50 50 50 6 6 6
37142 -128 128 128 174 154 114 156 107 11 168 122 10
37143 -198 155 10 184 144 12 197 138 11 200 144 11
37144 -206 145 10 206 145 10 197 138 11 188 164 115
37145 -195 195 195 198 198 198 174 174 174 14 14 14
37146 - 2 2 6 22 22 22 116 116 116 116 116 116
37147 - 22 22 22 2 2 6 74 74 74 70 70 70
37148 - 30 30 30 10 10 10 0 0 0 0 0 0
37149 - 0 0 0 0 0 0 0 0 0 0 0 0
37150 - 0 0 0 0 0 0 0 0 0 0 0 0
37151 - 0 0 0 0 0 0 0 0 0 0 0 0
37152 - 0 0 0 0 0 0 0 0 0 0 0 0
37153 - 0 0 0 0 0 0 0 0 0 0 0 0
37154 - 0 0 0 0 0 0 0 0 0 0 0 0
37155 - 0 0 0 0 0 0 0 0 0 0 0 0
37156 - 0 0 0 0 0 0 0 0 0 0 0 0
37157 - 0 0 0 0 0 0 0 0 0 0 0 0
37158 - 0 0 0 0 0 0 0 0 0 0 0 0
37159 - 0 0 0 0 0 0 0 0 0 0 0 0
37160 - 0 0 0 0 0 0 6 6 6 18 18 18
37161 - 50 50 50 101 101 101 26 26 26 10 10 10
37162 -138 138 138 190 190 190 174 154 114 156 107 11
37163 -197 138 11 200 144 11 197 138 11 192 133 9
37164 -180 123 7 190 142 34 190 178 144 187 187 187
37165 -202 202 202 221 221 221 214 214 214 66 66 66
37166 - 2 2 6 2 2 6 50 50 50 62 62 62
37167 - 6 6 6 2 2 6 10 10 10 90 90 90
37168 - 50 50 50 18 18 18 6 6 6 0 0 0
37169 - 0 0 0 0 0 0 0 0 0 0 0 0
37170 - 0 0 0 0 0 0 0 0 0 0 0 0
37171 - 0 0 0 0 0 0 0 0 0 0 0 0
37172 - 0 0 0 0 0 0 0 0 0 0 0 0
37173 - 0 0 0 0 0 0 0 0 0 0 0 0
37174 - 0 0 0 0 0 0 0 0 0 0 0 0
37175 - 0 0 0 0 0 0 0 0 0 0 0 0
37176 - 0 0 0 0 0 0 0 0 0 0 0 0
37177 - 0 0 0 0 0 0 0 0 0 0 0 0
37178 - 0 0 0 0 0 0 0 0 0 0 0 0
37179 - 0 0 0 0 0 0 0 0 0 0 0 0
37180 - 0 0 0 0 0 0 10 10 10 34 34 34
37181 - 74 74 74 74 74 74 2 2 6 6 6 6
37182 -144 144 144 198 198 198 190 190 190 178 166 146
37183 -154 121 60 156 107 11 156 107 11 168 124 44
37184 -174 154 114 187 187 187 190 190 190 210 210 210
37185 -246 246 246 253 253 253 253 253 253 182 182 182
37186 - 6 6 6 2 2 6 2 2 6 2 2 6
37187 - 2 2 6 2 2 6 2 2 6 62 62 62
37188 - 74 74 74 34 34 34 14 14 14 0 0 0
37189 - 0 0 0 0 0 0 0 0 0 0 0 0
37190 - 0 0 0 0 0 0 0 0 0 0 0 0
37191 - 0 0 0 0 0 0 0 0 0 0 0 0
37192 - 0 0 0 0 0 0 0 0 0 0 0 0
37193 - 0 0 0 0 0 0 0 0 0 0 0 0
37194 - 0 0 0 0 0 0 0 0 0 0 0 0
37195 - 0 0 0 0 0 0 0 0 0 0 0 0
37196 - 0 0 0 0 0 0 0 0 0 0 0 0
37197 - 0 0 0 0 0 0 0 0 0 0 0 0
37198 - 0 0 0 0 0 0 0 0 0 0 0 0
37199 - 0 0 0 0 0 0 0 0 0 0 0 0
37200 - 0 0 0 10 10 10 22 22 22 54 54 54
37201 - 94 94 94 18 18 18 2 2 6 46 46 46
37202 -234 234 234 221 221 221 190 190 190 190 190 190
37203 -190 190 190 187 187 187 187 187 187 190 190 190
37204 -190 190 190 195 195 195 214 214 214 242 242 242
37205 -253 253 253 253 253 253 253 253 253 253 253 253
37206 - 82 82 82 2 2 6 2 2 6 2 2 6
37207 - 2 2 6 2 2 6 2 2 6 14 14 14
37208 - 86 86 86 54 54 54 22 22 22 6 6 6
37209 - 0 0 0 0 0 0 0 0 0 0 0 0
37210 - 0 0 0 0 0 0 0 0 0 0 0 0
37211 - 0 0 0 0 0 0 0 0 0 0 0 0
37212 - 0 0 0 0 0 0 0 0 0 0 0 0
37213 - 0 0 0 0 0 0 0 0 0 0 0 0
37214 - 0 0 0 0 0 0 0 0 0 0 0 0
37215 - 0 0 0 0 0 0 0 0 0 0 0 0
37216 - 0 0 0 0 0 0 0 0 0 0 0 0
37217 - 0 0 0 0 0 0 0 0 0 0 0 0
37218 - 0 0 0 0 0 0 0 0 0 0 0 0
37219 - 0 0 0 0 0 0 0 0 0 0 0 0
37220 - 6 6 6 18 18 18 46 46 46 90 90 90
37221 - 46 46 46 18 18 18 6 6 6 182 182 182
37222 -253 253 253 246 246 246 206 206 206 190 190 190
37223 -190 190 190 190 190 190 190 190 190 190 190 190
37224 -206 206 206 231 231 231 250 250 250 253 253 253
37225 -253 253 253 253 253 253 253 253 253 253 253 253
37226 -202 202 202 14 14 14 2 2 6 2 2 6
37227 - 2 2 6 2 2 6 2 2 6 2 2 6
37228 - 42 42 42 86 86 86 42 42 42 18 18 18
37229 - 6 6 6 0 0 0 0 0 0 0 0 0
37230 - 0 0 0 0 0 0 0 0 0 0 0 0
37231 - 0 0 0 0 0 0 0 0 0 0 0 0
37232 - 0 0 0 0 0 0 0 0 0 0 0 0
37233 - 0 0 0 0 0 0 0 0 0 0 0 0
37234 - 0 0 0 0 0 0 0 0 0 0 0 0
37235 - 0 0 0 0 0 0 0 0 0 0 0 0
37236 - 0 0 0 0 0 0 0 0 0 0 0 0
37237 - 0 0 0 0 0 0 0 0 0 0 0 0
37238 - 0 0 0 0 0 0 0 0 0 0 0 0
37239 - 0 0 0 0 0 0 0 0 0 6 6 6
37240 - 14 14 14 38 38 38 74 74 74 66 66 66
37241 - 2 2 6 6 6 6 90 90 90 250 250 250
37242 -253 253 253 253 253 253 238 238 238 198 198 198
37243 -190 190 190 190 190 190 195 195 195 221 221 221
37244 -246 246 246 253 253 253 253 253 253 253 253 253
37245 -253 253 253 253 253 253 253 253 253 253 253 253
37246 -253 253 253 82 82 82 2 2 6 2 2 6
37247 - 2 2 6 2 2 6 2 2 6 2 2 6
37248 - 2 2 6 78 78 78 70 70 70 34 34 34
37249 - 14 14 14 6 6 6 0 0 0 0 0 0
37250 - 0 0 0 0 0 0 0 0 0 0 0 0
37251 - 0 0 0 0 0 0 0 0 0 0 0 0
37252 - 0 0 0 0 0 0 0 0 0 0 0 0
37253 - 0 0 0 0 0 0 0 0 0 0 0 0
37254 - 0 0 0 0 0 0 0 0 0 0 0 0
37255 - 0 0 0 0 0 0 0 0 0 0 0 0
37256 - 0 0 0 0 0 0 0 0 0 0 0 0
37257 - 0 0 0 0 0 0 0 0 0 0 0 0
37258 - 0 0 0 0 0 0 0 0 0 0 0 0
37259 - 0 0 0 0 0 0 0 0 0 14 14 14
37260 - 34 34 34 66 66 66 78 78 78 6 6 6
37261 - 2 2 6 18 18 18 218 218 218 253 253 253
37262 -253 253 253 253 253 253 253 253 253 246 246 246
37263 -226 226 226 231 231 231 246 246 246 253 253 253
37264 -253 253 253 253 253 253 253 253 253 253 253 253
37265 -253 253 253 253 253 253 253 253 253 253 253 253
37266 -253 253 253 178 178 178 2 2 6 2 2 6
37267 - 2 2 6 2 2 6 2 2 6 2 2 6
37268 - 2 2 6 18 18 18 90 90 90 62 62 62
37269 - 30 30 30 10 10 10 0 0 0 0 0 0
37270 - 0 0 0 0 0 0 0 0 0 0 0 0
37271 - 0 0 0 0 0 0 0 0 0 0 0 0
37272 - 0 0 0 0 0 0 0 0 0 0 0 0
37273 - 0 0 0 0 0 0 0 0 0 0 0 0
37274 - 0 0 0 0 0 0 0 0 0 0 0 0
37275 - 0 0 0 0 0 0 0 0 0 0 0 0
37276 - 0 0 0 0 0 0 0 0 0 0 0 0
37277 - 0 0 0 0 0 0 0 0 0 0 0 0
37278 - 0 0 0 0 0 0 0 0 0 0 0 0
37279 - 0 0 0 0 0 0 10 10 10 26 26 26
37280 - 58 58 58 90 90 90 18 18 18 2 2 6
37281 - 2 2 6 110 110 110 253 253 253 253 253 253
37282 -253 253 253 253 253 253 253 253 253 253 253 253
37283 -250 250 250 253 253 253 253 253 253 253 253 253
37284 -253 253 253 253 253 253 253 253 253 253 253 253
37285 -253 253 253 253 253 253 253 253 253 253 253 253
37286 -253 253 253 231 231 231 18 18 18 2 2 6
37287 - 2 2 6 2 2 6 2 2 6 2 2 6
37288 - 2 2 6 2 2 6 18 18 18 94 94 94
37289 - 54 54 54 26 26 26 10 10 10 0 0 0
37290 - 0 0 0 0 0 0 0 0 0 0 0 0
37291 - 0 0 0 0 0 0 0 0 0 0 0 0
37292 - 0 0 0 0 0 0 0 0 0 0 0 0
37293 - 0 0 0 0 0 0 0 0 0 0 0 0
37294 - 0 0 0 0 0 0 0 0 0 0 0 0
37295 - 0 0 0 0 0 0 0 0 0 0 0 0
37296 - 0 0 0 0 0 0 0 0 0 0 0 0
37297 - 0 0 0 0 0 0 0 0 0 0 0 0
37298 - 0 0 0 0 0 0 0 0 0 0 0 0
37299 - 0 0 0 6 6 6 22 22 22 50 50 50
37300 - 90 90 90 26 26 26 2 2 6 2 2 6
37301 - 14 14 14 195 195 195 250 250 250 253 253 253
37302 -253 253 253 253 253 253 253 253 253 253 253 253
37303 -253 253 253 253 253 253 253 253 253 253 253 253
37304 -253 253 253 253 253 253 253 253 253 253 253 253
37305 -253 253 253 253 253 253 253 253 253 253 253 253
37306 -250 250 250 242 242 242 54 54 54 2 2 6
37307 - 2 2 6 2 2 6 2 2 6 2 2 6
37308 - 2 2 6 2 2 6 2 2 6 38 38 38
37309 - 86 86 86 50 50 50 22 22 22 6 6 6
37310 - 0 0 0 0 0 0 0 0 0 0 0 0
37311 - 0 0 0 0 0 0 0 0 0 0 0 0
37312 - 0 0 0 0 0 0 0 0 0 0 0 0
37313 - 0 0 0 0 0 0 0 0 0 0 0 0
37314 - 0 0 0 0 0 0 0 0 0 0 0 0
37315 - 0 0 0 0 0 0 0 0 0 0 0 0
37316 - 0 0 0 0 0 0 0 0 0 0 0 0
37317 - 0 0 0 0 0 0 0 0 0 0 0 0
37318 - 0 0 0 0 0 0 0 0 0 0 0 0
37319 - 6 6 6 14 14 14 38 38 38 82 82 82
37320 - 34 34 34 2 2 6 2 2 6 2 2 6
37321 - 42 42 42 195 195 195 246 246 246 253 253 253
37322 -253 253 253 253 253 253 253 253 253 250 250 250
37323 -242 242 242 242 242 242 250 250 250 253 253 253
37324 -253 253 253 253 253 253 253 253 253 253 253 253
37325 -253 253 253 250 250 250 246 246 246 238 238 238
37326 -226 226 226 231 231 231 101 101 101 6 6 6
37327 - 2 2 6 2 2 6 2 2 6 2 2 6
37328 - 2 2 6 2 2 6 2 2 6 2 2 6
37329 - 38 38 38 82 82 82 42 42 42 14 14 14
37330 - 6 6 6 0 0 0 0 0 0 0 0 0
37331 - 0 0 0 0 0 0 0 0 0 0 0 0
37332 - 0 0 0 0 0 0 0 0 0 0 0 0
37333 - 0 0 0 0 0 0 0 0 0 0 0 0
37334 - 0 0 0 0 0 0 0 0 0 0 0 0
37335 - 0 0 0 0 0 0 0 0 0 0 0 0
37336 - 0 0 0 0 0 0 0 0 0 0 0 0
37337 - 0 0 0 0 0 0 0 0 0 0 0 0
37338 - 0 0 0 0 0 0 0 0 0 0 0 0
37339 - 10 10 10 26 26 26 62 62 62 66 66 66
37340 - 2 2 6 2 2 6 2 2 6 6 6 6
37341 - 70 70 70 170 170 170 206 206 206 234 234 234
37342 -246 246 246 250 250 250 250 250 250 238 238 238
37343 -226 226 226 231 231 231 238 238 238 250 250 250
37344 -250 250 250 250 250 250 246 246 246 231 231 231
37345 -214 214 214 206 206 206 202 202 202 202 202 202
37346 -198 198 198 202 202 202 182 182 182 18 18 18
37347 - 2 2 6 2 2 6 2 2 6 2 2 6
37348 - 2 2 6 2 2 6 2 2 6 2 2 6
37349 - 2 2 6 62 62 62 66 66 66 30 30 30
37350 - 10 10 10 0 0 0 0 0 0 0 0 0
37351 - 0 0 0 0 0 0 0 0 0 0 0 0
37352 - 0 0 0 0 0 0 0 0 0 0 0 0
37353 - 0 0 0 0 0 0 0 0 0 0 0 0
37354 - 0 0 0 0 0 0 0 0 0 0 0 0
37355 - 0 0 0 0 0 0 0 0 0 0 0 0
37356 - 0 0 0 0 0 0 0 0 0 0 0 0
37357 - 0 0 0 0 0 0 0 0 0 0 0 0
37358 - 0 0 0 0 0 0 0 0 0 0 0 0
37359 - 14 14 14 42 42 42 82 82 82 18 18 18
37360 - 2 2 6 2 2 6 2 2 6 10 10 10
37361 - 94 94 94 182 182 182 218 218 218 242 242 242
37362 -250 250 250 253 253 253 253 253 253 250 250 250
37363 -234 234 234 253 253 253 253 253 253 253 253 253
37364 -253 253 253 253 253 253 253 253 253 246 246 246
37365 -238 238 238 226 226 226 210 210 210 202 202 202
37366 -195 195 195 195 195 195 210 210 210 158 158 158
37367 - 6 6 6 14 14 14 50 50 50 14 14 14
37368 - 2 2 6 2 2 6 2 2 6 2 2 6
37369 - 2 2 6 6 6 6 86 86 86 46 46 46
37370 - 18 18 18 6 6 6 0 0 0 0 0 0
37371 - 0 0 0 0 0 0 0 0 0 0 0 0
37372 - 0 0 0 0 0 0 0 0 0 0 0 0
37373 - 0 0 0 0 0 0 0 0 0 0 0 0
37374 - 0 0 0 0 0 0 0 0 0 0 0 0
37375 - 0 0 0 0 0 0 0 0 0 0 0 0
37376 - 0 0 0 0 0 0 0 0 0 0 0 0
37377 - 0 0 0 0 0 0 0 0 0 0 0 0
37378 - 0 0 0 0 0 0 0 0 0 6 6 6
37379 - 22 22 22 54 54 54 70 70 70 2 2 6
37380 - 2 2 6 10 10 10 2 2 6 22 22 22
37381 -166 166 166 231 231 231 250 250 250 253 253 253
37382 -253 253 253 253 253 253 253 253 253 250 250 250
37383 -242 242 242 253 253 253 253 253 253 253 253 253
37384 -253 253 253 253 253 253 253 253 253 253 253 253
37385 -253 253 253 253 253 253 253 253 253 246 246 246
37386 -231 231 231 206 206 206 198 198 198 226 226 226
37387 - 94 94 94 2 2 6 6 6 6 38 38 38
37388 - 30 30 30 2 2 6 2 2 6 2 2 6
37389 - 2 2 6 2 2 6 62 62 62 66 66 66
37390 - 26 26 26 10 10 10 0 0 0 0 0 0
37391 - 0 0 0 0 0 0 0 0 0 0 0 0
37392 - 0 0 0 0 0 0 0 0 0 0 0 0
37393 - 0 0 0 0 0 0 0 0 0 0 0 0
37394 - 0 0 0 0 0 0 0 0 0 0 0 0
37395 - 0 0 0 0 0 0 0 0 0 0 0 0
37396 - 0 0 0 0 0 0 0 0 0 0 0 0
37397 - 0 0 0 0 0 0 0 0 0 0 0 0
37398 - 0 0 0 0 0 0 0 0 0 10 10 10
37399 - 30 30 30 74 74 74 50 50 50 2 2 6
37400 - 26 26 26 26 26 26 2 2 6 106 106 106
37401 -238 238 238 253 253 253 253 253 253 253 253 253
37402 -253 253 253 253 253 253 253 253 253 253 253 253
37403 -253 253 253 253 253 253 253 253 253 253 253 253
37404 -253 253 253 253 253 253 253 253 253 253 253 253
37405 -253 253 253 253 253 253 253 253 253 253 253 253
37406 -253 253 253 246 246 246 218 218 218 202 202 202
37407 -210 210 210 14 14 14 2 2 6 2 2 6
37408 - 30 30 30 22 22 22 2 2 6 2 2 6
37409 - 2 2 6 2 2 6 18 18 18 86 86 86
37410 - 42 42 42 14 14 14 0 0 0 0 0 0
37411 - 0 0 0 0 0 0 0 0 0 0 0 0
37412 - 0 0 0 0 0 0 0 0 0 0 0 0
37413 - 0 0 0 0 0 0 0 0 0 0 0 0
37414 - 0 0 0 0 0 0 0 0 0 0 0 0
37415 - 0 0 0 0 0 0 0 0 0 0 0 0
37416 - 0 0 0 0 0 0 0 0 0 0 0 0
37417 - 0 0 0 0 0 0 0 0 0 0 0 0
37418 - 0 0 0 0 0 0 0 0 0 14 14 14
37419 - 42 42 42 90 90 90 22 22 22 2 2 6
37420 - 42 42 42 2 2 6 18 18 18 218 218 218
37421 -253 253 253 253 253 253 253 253 253 253 253 253
37422 -253 253 253 253 253 253 253 253 253 253 253 253
37423 -253 253 253 253 253 253 253 253 253 253 253 253
37424 -253 253 253 253 253 253 253 253 253 253 253 253
37425 -253 253 253 253 253 253 253 253 253 253 253 253
37426 -253 253 253 253 253 253 250 250 250 221 221 221
37427 -218 218 218 101 101 101 2 2 6 14 14 14
37428 - 18 18 18 38 38 38 10 10 10 2 2 6
37429 - 2 2 6 2 2 6 2 2 6 78 78 78
37430 - 58 58 58 22 22 22 6 6 6 0 0 0
37431 - 0 0 0 0 0 0 0 0 0 0 0 0
37432 - 0 0 0 0 0 0 0 0 0 0 0 0
37433 - 0 0 0 0 0 0 0 0 0 0 0 0
37434 - 0 0 0 0 0 0 0 0 0 0 0 0
37435 - 0 0 0 0 0 0 0 0 0 0 0 0
37436 - 0 0 0 0 0 0 0 0 0 0 0 0
37437 - 0 0 0 0 0 0 0 0 0 0 0 0
37438 - 0 0 0 0 0 0 6 6 6 18 18 18
37439 - 54 54 54 82 82 82 2 2 6 26 26 26
37440 - 22 22 22 2 2 6 123 123 123 253 253 253
37441 -253 253 253 253 253 253 253 253 253 253 253 253
37442 -253 253 253 253 253 253 253 253 253 253 253 253
37443 -253 253 253 253 253 253 253 253 253 253 253 253
37444 -253 253 253 253 253 253 253 253 253 253 253 253
37445 -253 253 253 253 253 253 253 253 253 253 253 253
37446 -253 253 253 253 253 253 253 253 253 250 250 250
37447 -238 238 238 198 198 198 6 6 6 38 38 38
37448 - 58 58 58 26 26 26 38 38 38 2 2 6
37449 - 2 2 6 2 2 6 2 2 6 46 46 46
37450 - 78 78 78 30 30 30 10 10 10 0 0 0
37451 - 0 0 0 0 0 0 0 0 0 0 0 0
37452 - 0 0 0 0 0 0 0 0 0 0 0 0
37453 - 0 0 0 0 0 0 0 0 0 0 0 0
37454 - 0 0 0 0 0 0 0 0 0 0 0 0
37455 - 0 0 0 0 0 0 0 0 0 0 0 0
37456 - 0 0 0 0 0 0 0 0 0 0 0 0
37457 - 0 0 0 0 0 0 0 0 0 0 0 0
37458 - 0 0 0 0 0 0 10 10 10 30 30 30
37459 - 74 74 74 58 58 58 2 2 6 42 42 42
37460 - 2 2 6 22 22 22 231 231 231 253 253 253
37461 -253 253 253 253 253 253 253 253 253 253 253 253
37462 -253 253 253 253 253 253 253 253 253 250 250 250
37463 -253 253 253 253 253 253 253 253 253 253 253 253
37464 -253 253 253 253 253 253 253 253 253 253 253 253
37465 -253 253 253 253 253 253 253 253 253 253 253 253
37466 -253 253 253 253 253 253 253 253 253 253 253 253
37467 -253 253 253 246 246 246 46 46 46 38 38 38
37468 - 42 42 42 14 14 14 38 38 38 14 14 14
37469 - 2 2 6 2 2 6 2 2 6 6 6 6
37470 - 86 86 86 46 46 46 14 14 14 0 0 0
37471 - 0 0 0 0 0 0 0 0 0 0 0 0
37472 - 0 0 0 0 0 0 0 0 0 0 0 0
37473 - 0 0 0 0 0 0 0 0 0 0 0 0
37474 - 0 0 0 0 0 0 0 0 0 0 0 0
37475 - 0 0 0 0 0 0 0 0 0 0 0 0
37476 - 0 0 0 0 0 0 0 0 0 0 0 0
37477 - 0 0 0 0 0 0 0 0 0 0 0 0
37478 - 0 0 0 6 6 6 14 14 14 42 42 42
37479 - 90 90 90 18 18 18 18 18 18 26 26 26
37480 - 2 2 6 116 116 116 253 253 253 253 253 253
37481 -253 253 253 253 253 253 253 253 253 253 253 253
37482 -253 253 253 253 253 253 250 250 250 238 238 238
37483 -253 253 253 253 253 253 253 253 253 253 253 253
37484 -253 253 253 253 253 253 253 253 253 253 253 253
37485 -253 253 253 253 253 253 253 253 253 253 253 253
37486 -253 253 253 253 253 253 253 253 253 253 253 253
37487 -253 253 253 253 253 253 94 94 94 6 6 6
37488 - 2 2 6 2 2 6 10 10 10 34 34 34
37489 - 2 2 6 2 2 6 2 2 6 2 2 6
37490 - 74 74 74 58 58 58 22 22 22 6 6 6
37491 - 0 0 0 0 0 0 0 0 0 0 0 0
37492 - 0 0 0 0 0 0 0 0 0 0 0 0
37493 - 0 0 0 0 0 0 0 0 0 0 0 0
37494 - 0 0 0 0 0 0 0 0 0 0 0 0
37495 - 0 0 0 0 0 0 0 0 0 0 0 0
37496 - 0 0 0 0 0 0 0 0 0 0 0 0
37497 - 0 0 0 0 0 0 0 0 0 0 0 0
37498 - 0 0 0 10 10 10 26 26 26 66 66 66
37499 - 82 82 82 2 2 6 38 38 38 6 6 6
37500 - 14 14 14 210 210 210 253 253 253 253 253 253
37501 -253 253 253 253 253 253 253 253 253 253 253 253
37502 -253 253 253 253 253 253 246 246 246 242 242 242
37503 -253 253 253 253 253 253 253 253 253 253 253 253
37504 -253 253 253 253 253 253 253 253 253 253 253 253
37505 -253 253 253 253 253 253 253 253 253 253 253 253
37506 -253 253 253 253 253 253 253 253 253 253 253 253
37507 -253 253 253 253 253 253 144 144 144 2 2 6
37508 - 2 2 6 2 2 6 2 2 6 46 46 46
37509 - 2 2 6 2 2 6 2 2 6 2 2 6
37510 - 42 42 42 74 74 74 30 30 30 10 10 10
37511 - 0 0 0 0 0 0 0 0 0 0 0 0
37512 - 0 0 0 0 0 0 0 0 0 0 0 0
37513 - 0 0 0 0 0 0 0 0 0 0 0 0
37514 - 0 0 0 0 0 0 0 0 0 0 0 0
37515 - 0 0 0 0 0 0 0 0 0 0 0 0
37516 - 0 0 0 0 0 0 0 0 0 0 0 0
37517 - 0 0 0 0 0 0 0 0 0 0 0 0
37518 - 6 6 6 14 14 14 42 42 42 90 90 90
37519 - 26 26 26 6 6 6 42 42 42 2 2 6
37520 - 74 74 74 250 250 250 253 253 253 253 253 253
37521 -253 253 253 253 253 253 253 253 253 253 253 253
37522 -253 253 253 253 253 253 242 242 242 242 242 242
37523 -253 253 253 253 253 253 253 253 253 253 253 253
37524 -253 253 253 253 253 253 253 253 253 253 253 253
37525 -253 253 253 253 253 253 253 253 253 253 253 253
37526 -253 253 253 253 253 253 253 253 253 253 253 253
37527 -253 253 253 253 253 253 182 182 182 2 2 6
37528 - 2 2 6 2 2 6 2 2 6 46 46 46
37529 - 2 2 6 2 2 6 2 2 6 2 2 6
37530 - 10 10 10 86 86 86 38 38 38 10 10 10
37531 - 0 0 0 0 0 0 0 0 0 0 0 0
37532 - 0 0 0 0 0 0 0 0 0 0 0 0
37533 - 0 0 0 0 0 0 0 0 0 0 0 0
37534 - 0 0 0 0 0 0 0 0 0 0 0 0
37535 - 0 0 0 0 0 0 0 0 0 0 0 0
37536 - 0 0 0 0 0 0 0 0 0 0 0 0
37537 - 0 0 0 0 0 0 0 0 0 0 0 0
37538 - 10 10 10 26 26 26 66 66 66 82 82 82
37539 - 2 2 6 22 22 22 18 18 18 2 2 6
37540 -149 149 149 253 253 253 253 253 253 253 253 253
37541 -253 253 253 253 253 253 253 253 253 253 253 253
37542 -253 253 253 253 253 253 234 234 234 242 242 242
37543 -253 253 253 253 253 253 253 253 253 253 253 253
37544 -253 253 253 253 253 253 253 253 253 253 253 253
37545 -253 253 253 253 253 253 253 253 253 253 253 253
37546 -253 253 253 253 253 253 253 253 253 253 253 253
37547 -253 253 253 253 253 253 206 206 206 2 2 6
37548 - 2 2 6 2 2 6 2 2 6 38 38 38
37549 - 2 2 6 2 2 6 2 2 6 2 2 6
37550 - 6 6 6 86 86 86 46 46 46 14 14 14
37551 - 0 0 0 0 0 0 0 0 0 0 0 0
37552 - 0 0 0 0 0 0 0 0 0 0 0 0
37553 - 0 0 0 0 0 0 0 0 0 0 0 0
37554 - 0 0 0 0 0 0 0 0 0 0 0 0
37555 - 0 0 0 0 0 0 0 0 0 0 0 0
37556 - 0 0 0 0 0 0 0 0 0 0 0 0
37557 - 0 0 0 0 0 0 0 0 0 6 6 6
37558 - 18 18 18 46 46 46 86 86 86 18 18 18
37559 - 2 2 6 34 34 34 10 10 10 6 6 6
37560 -210 210 210 253 253 253 253 253 253 253 253 253
37561 -253 253 253 253 253 253 253 253 253 253 253 253
37562 -253 253 253 253 253 253 234 234 234 242 242 242
37563 -253 253 253 253 253 253 253 253 253 253 253 253
37564 -253 253 253 253 253 253 253 253 253 253 253 253
37565 -253 253 253 253 253 253 253 253 253 253 253 253
37566 -253 253 253 253 253 253 253 253 253 253 253 253
37567 -253 253 253 253 253 253 221 221 221 6 6 6
37568 - 2 2 6 2 2 6 6 6 6 30 30 30
37569 - 2 2 6 2 2 6 2 2 6 2 2 6
37570 - 2 2 6 82 82 82 54 54 54 18 18 18
37571 - 6 6 6 0 0 0 0 0 0 0 0 0
37572 - 0 0 0 0 0 0 0 0 0 0 0 0
37573 - 0 0 0 0 0 0 0 0 0 0 0 0
37574 - 0 0 0 0 0 0 0 0 0 0 0 0
37575 - 0 0 0 0 0 0 0 0 0 0 0 0
37576 - 0 0 0 0 0 0 0 0 0 0 0 0
37577 - 0 0 0 0 0 0 0 0 0 10 10 10
37578 - 26 26 26 66 66 66 62 62 62 2 2 6
37579 - 2 2 6 38 38 38 10 10 10 26 26 26
37580 -238 238 238 253 253 253 253 253 253 253 253 253
37581 -253 253 253 253 253 253 253 253 253 253 253 253
37582 -253 253 253 253 253 253 231 231 231 238 238 238
37583 -253 253 253 253 253 253 253 253 253 253 253 253
37584 -253 253 253 253 253 253 253 253 253 253 253 253
37585 -253 253 253 253 253 253 253 253 253 253 253 253
37586 -253 253 253 253 253 253 253 253 253 253 253 253
37587 -253 253 253 253 253 253 231 231 231 6 6 6
37588 - 2 2 6 2 2 6 10 10 10 30 30 30
37589 - 2 2 6 2 2 6 2 2 6 2 2 6
37590 - 2 2 6 66 66 66 58 58 58 22 22 22
37591 - 6 6 6 0 0 0 0 0 0 0 0 0
37592 - 0 0 0 0 0 0 0 0 0 0 0 0
37593 - 0 0 0 0 0 0 0 0 0 0 0 0
37594 - 0 0 0 0 0 0 0 0 0 0 0 0
37595 - 0 0 0 0 0 0 0 0 0 0 0 0
37596 - 0 0 0 0 0 0 0 0 0 0 0 0
37597 - 0 0 0 0 0 0 0 0 0 10 10 10
37598 - 38 38 38 78 78 78 6 6 6 2 2 6
37599 - 2 2 6 46 46 46 14 14 14 42 42 42
37600 -246 246 246 253 253 253 253 253 253 253 253 253
37601 -253 253 253 253 253 253 253 253 253 253 253 253
37602 -253 253 253 253 253 253 231 231 231 242 242 242
37603 -253 253 253 253 253 253 253 253 253 253 253 253
37604 -253 253 253 253 253 253 253 253 253 253 253 253
37605 -253 253 253 253 253 253 253 253 253 253 253 253
37606 -253 253 253 253 253 253 253 253 253 253 253 253
37607 -253 253 253 253 253 253 234 234 234 10 10 10
37608 - 2 2 6 2 2 6 22 22 22 14 14 14
37609 - 2 2 6 2 2 6 2 2 6 2 2 6
37610 - 2 2 6 66 66 66 62 62 62 22 22 22
37611 - 6 6 6 0 0 0 0 0 0 0 0 0
37612 - 0 0 0 0 0 0 0 0 0 0 0 0
37613 - 0 0 0 0 0 0 0 0 0 0 0 0
37614 - 0 0 0 0 0 0 0 0 0 0 0 0
37615 - 0 0 0 0 0 0 0 0 0 0 0 0
37616 - 0 0 0 0 0 0 0 0 0 0 0 0
37617 - 0 0 0 0 0 0 6 6 6 18 18 18
37618 - 50 50 50 74 74 74 2 2 6 2 2 6
37619 - 14 14 14 70 70 70 34 34 34 62 62 62
37620 -250 250 250 253 253 253 253 253 253 253 253 253
37621 -253 253 253 253 253 253 253 253 253 253 253 253
37622 -253 253 253 253 253 253 231 231 231 246 246 246
37623 -253 253 253 253 253 253 253 253 253 253 253 253
37624 -253 253 253 253 253 253 253 253 253 253 253 253
37625 -253 253 253 253 253 253 253 253 253 253 253 253
37626 -253 253 253 253 253 253 253 253 253 253 253 253
37627 -253 253 253 253 253 253 234 234 234 14 14 14
37628 - 2 2 6 2 2 6 30 30 30 2 2 6
37629 - 2 2 6 2 2 6 2 2 6 2 2 6
37630 - 2 2 6 66 66 66 62 62 62 22 22 22
37631 - 6 6 6 0 0 0 0 0 0 0 0 0
37632 - 0 0 0 0 0 0 0 0 0 0 0 0
37633 - 0 0 0 0 0 0 0 0 0 0 0 0
37634 - 0 0 0 0 0 0 0 0 0 0 0 0
37635 - 0 0 0 0 0 0 0 0 0 0 0 0
37636 - 0 0 0 0 0 0 0 0 0 0 0 0
37637 - 0 0 0 0 0 0 6 6 6 18 18 18
37638 - 54 54 54 62 62 62 2 2 6 2 2 6
37639 - 2 2 6 30 30 30 46 46 46 70 70 70
37640 -250 250 250 253 253 253 253 253 253 253 253 253
37641 -253 253 253 253 253 253 253 253 253 253 253 253
37642 -253 253 253 253 253 253 231 231 231 246 246 246
37643 -253 253 253 253 253 253 253 253 253 253 253 253
37644 -253 253 253 253 253 253 253 253 253 253 253 253
37645 -253 253 253 253 253 253 253 253 253 253 253 253
37646 -253 253 253 253 253 253 253 253 253 253 253 253
37647 -253 253 253 253 253 253 226 226 226 10 10 10
37648 - 2 2 6 6 6 6 30 30 30 2 2 6
37649 - 2 2 6 2 2 6 2 2 6 2 2 6
37650 - 2 2 6 66 66 66 58 58 58 22 22 22
37651 - 6 6 6 0 0 0 0 0 0 0 0 0
37652 - 0 0 0 0 0 0 0 0 0 0 0 0
37653 - 0 0 0 0 0 0 0 0 0 0 0 0
37654 - 0 0 0 0 0 0 0 0 0 0 0 0
37655 - 0 0 0 0 0 0 0 0 0 0 0 0
37656 - 0 0 0 0 0 0 0 0 0 0 0 0
37657 - 0 0 0 0 0 0 6 6 6 22 22 22
37658 - 58 58 58 62 62 62 2 2 6 2 2 6
37659 - 2 2 6 2 2 6 30 30 30 78 78 78
37660 -250 250 250 253 253 253 253 253 253 253 253 253
37661 -253 253 253 253 253 253 253 253 253 253 253 253
37662 -253 253 253 253 253 253 231 231 231 246 246 246
37663 -253 253 253 253 253 253 253 253 253 253 253 253
37664 -253 253 253 253 253 253 253 253 253 253 253 253
37665 -253 253 253 253 253 253 253 253 253 253 253 253
37666 -253 253 253 253 253 253 253 253 253 253 253 253
37667 -253 253 253 253 253 253 206 206 206 2 2 6
37668 - 22 22 22 34 34 34 18 14 6 22 22 22
37669 - 26 26 26 18 18 18 6 6 6 2 2 6
37670 - 2 2 6 82 82 82 54 54 54 18 18 18
37671 - 6 6 6 0 0 0 0 0 0 0 0 0
37672 - 0 0 0 0 0 0 0 0 0 0 0 0
37673 - 0 0 0 0 0 0 0 0 0 0 0 0
37674 - 0 0 0 0 0 0 0 0 0 0 0 0
37675 - 0 0 0 0 0 0 0 0 0 0 0 0
37676 - 0 0 0 0 0 0 0 0 0 0 0 0
37677 - 0 0 0 0 0 0 6 6 6 26 26 26
37678 - 62 62 62 106 106 106 74 54 14 185 133 11
37679 -210 162 10 121 92 8 6 6 6 62 62 62
37680 -238 238 238 253 253 253 253 253 253 253 253 253
37681 -253 253 253 253 253 253 253 253 253 253 253 253
37682 -253 253 253 253 253 253 231 231 231 246 246 246
37683 -253 253 253 253 253 253 253 253 253 253 253 253
37684 -253 253 253 253 253 253 253 253 253 253 253 253
37685 -253 253 253 253 253 253 253 253 253 253 253 253
37686 -253 253 253 253 253 253 253 253 253 253 253 253
37687 -253 253 253 253 253 253 158 158 158 18 18 18
37688 - 14 14 14 2 2 6 2 2 6 2 2 6
37689 - 6 6 6 18 18 18 66 66 66 38 38 38
37690 - 6 6 6 94 94 94 50 50 50 18 18 18
37691 - 6 6 6 0 0 0 0 0 0 0 0 0
37692 - 0 0 0 0 0 0 0 0 0 0 0 0
37693 - 0 0 0 0 0 0 0 0 0 0 0 0
37694 - 0 0 0 0 0 0 0 0 0 0 0 0
37695 - 0 0 0 0 0 0 0 0 0 0 0 0
37696 - 0 0 0 0 0 0 0 0 0 6 6 6
37697 - 10 10 10 10 10 10 18 18 18 38 38 38
37698 - 78 78 78 142 134 106 216 158 10 242 186 14
37699 -246 190 14 246 190 14 156 118 10 10 10 10
37700 - 90 90 90 238 238 238 253 253 253 253 253 253
37701 -253 253 253 253 253 253 253 253 253 253 253 253
37702 -253 253 253 253 253 253 231 231 231 250 250 250
37703 -253 253 253 253 253 253 253 253 253 253 253 253
37704 -253 253 253 253 253 253 253 253 253 253 253 253
37705 -253 253 253 253 253 253 253 253 253 253 253 253
37706 -253 253 253 253 253 253 253 253 253 246 230 190
37707 -238 204 91 238 204 91 181 142 44 37 26 9
37708 - 2 2 6 2 2 6 2 2 6 2 2 6
37709 - 2 2 6 2 2 6 38 38 38 46 46 46
37710 - 26 26 26 106 106 106 54 54 54 18 18 18
37711 - 6 6 6 0 0 0 0 0 0 0 0 0
37712 - 0 0 0 0 0 0 0 0 0 0 0 0
37713 - 0 0 0 0 0 0 0 0 0 0 0 0
37714 - 0 0 0 0 0 0 0 0 0 0 0 0
37715 - 0 0 0 0 0 0 0 0 0 0 0 0
37716 - 0 0 0 6 6 6 14 14 14 22 22 22
37717 - 30 30 30 38 38 38 50 50 50 70 70 70
37718 -106 106 106 190 142 34 226 170 11 242 186 14
37719 -246 190 14 246 190 14 246 190 14 154 114 10
37720 - 6 6 6 74 74 74 226 226 226 253 253 253
37721 -253 253 253 253 253 253 253 253 253 253 253 253
37722 -253 253 253 253 253 253 231 231 231 250 250 250
37723 -253 253 253 253 253 253 253 253 253 253 253 253
37724 -253 253 253 253 253 253 253 253 253 253 253 253
37725 -253 253 253 253 253 253 253 253 253 253 253 253
37726 -253 253 253 253 253 253 253 253 253 228 184 62
37727 -241 196 14 241 208 19 232 195 16 38 30 10
37728 - 2 2 6 2 2 6 2 2 6 2 2 6
37729 - 2 2 6 6 6 6 30 30 30 26 26 26
37730 -203 166 17 154 142 90 66 66 66 26 26 26
37731 - 6 6 6 0 0 0 0 0 0 0 0 0
37732 - 0 0 0 0 0 0 0 0 0 0 0 0
37733 - 0 0 0 0 0 0 0 0 0 0 0 0
37734 - 0 0 0 0 0 0 0 0 0 0 0 0
37735 - 0 0 0 0 0 0 0 0 0 0 0 0
37736 - 6 6 6 18 18 18 38 38 38 58 58 58
37737 - 78 78 78 86 86 86 101 101 101 123 123 123
37738 -175 146 61 210 150 10 234 174 13 246 186 14
37739 -246 190 14 246 190 14 246 190 14 238 190 10
37740 -102 78 10 2 2 6 46 46 46 198 198 198
37741 -253 253 253 253 253 253 253 253 253 253 253 253
37742 -253 253 253 253 253 253 234 234 234 242 242 242
37743 -253 253 253 253 253 253 253 253 253 253 253 253
37744 -253 253 253 253 253 253 253 253 253 253 253 253
37745 -253 253 253 253 253 253 253 253 253 253 253 253
37746 -253 253 253 253 253 253 253 253 253 224 178 62
37747 -242 186 14 241 196 14 210 166 10 22 18 6
37748 - 2 2 6 2 2 6 2 2 6 2 2 6
37749 - 2 2 6 2 2 6 6 6 6 121 92 8
37750 -238 202 15 232 195 16 82 82 82 34 34 34
37751 - 10 10 10 0 0 0 0 0 0 0 0 0
37752 - 0 0 0 0 0 0 0 0 0 0 0 0
37753 - 0 0 0 0 0 0 0 0 0 0 0 0
37754 - 0 0 0 0 0 0 0 0 0 0 0 0
37755 - 0 0 0 0 0 0 0 0 0 0 0 0
37756 - 14 14 14 38 38 38 70 70 70 154 122 46
37757 -190 142 34 200 144 11 197 138 11 197 138 11
37758 -213 154 11 226 170 11 242 186 14 246 190 14
37759 -246 190 14 246 190 14 246 190 14 246 190 14
37760 -225 175 15 46 32 6 2 2 6 22 22 22
37761 -158 158 158 250 250 250 253 253 253 253 253 253
37762 -253 253 253 253 253 253 253 253 253 253 253 253
37763 -253 253 253 253 253 253 253 253 253 253 253 253
37764 -253 253 253 253 253 253 253 253 253 253 253 253
37765 -253 253 253 253 253 253 253 253 253 253 253 253
37766 -253 253 253 250 250 250 242 242 242 224 178 62
37767 -239 182 13 236 186 11 213 154 11 46 32 6
37768 - 2 2 6 2 2 6 2 2 6 2 2 6
37769 - 2 2 6 2 2 6 61 42 6 225 175 15
37770 -238 190 10 236 186 11 112 100 78 42 42 42
37771 - 14 14 14 0 0 0 0 0 0 0 0 0
37772 - 0 0 0 0 0 0 0 0 0 0 0 0
37773 - 0 0 0 0 0 0 0 0 0 0 0 0
37774 - 0 0 0 0 0 0 0 0 0 0 0 0
37775 - 0 0 0 0 0 0 0 0 0 6 6 6
37776 - 22 22 22 54 54 54 154 122 46 213 154 11
37777 -226 170 11 230 174 11 226 170 11 226 170 11
37778 -236 178 12 242 186 14 246 190 14 246 190 14
37779 -246 190 14 246 190 14 246 190 14 246 190 14
37780 -241 196 14 184 144 12 10 10 10 2 2 6
37781 - 6 6 6 116 116 116 242 242 242 253 253 253
37782 -253 253 253 253 253 253 253 253 253 253 253 253
37783 -253 253 253 253 253 253 253 253 253 253 253 253
37784 -253 253 253 253 253 253 253 253 253 253 253 253
37785 -253 253 253 253 253 253 253 253 253 253 253 253
37786 -253 253 253 231 231 231 198 198 198 214 170 54
37787 -236 178 12 236 178 12 210 150 10 137 92 6
37788 - 18 14 6 2 2 6 2 2 6 2 2 6
37789 - 6 6 6 70 47 6 200 144 11 236 178 12
37790 -239 182 13 239 182 13 124 112 88 58 58 58
37791 - 22 22 22 6 6 6 0 0 0 0 0 0
37792 - 0 0 0 0 0 0 0 0 0 0 0 0
37793 - 0 0 0 0 0 0 0 0 0 0 0 0
37794 - 0 0 0 0 0 0 0 0 0 0 0 0
37795 - 0 0 0 0 0 0 0 0 0 10 10 10
37796 - 30 30 30 70 70 70 180 133 36 226 170 11
37797 -239 182 13 242 186 14 242 186 14 246 186 14
37798 -246 190 14 246 190 14 246 190 14 246 190 14
37799 -246 190 14 246 190 14 246 190 14 246 190 14
37800 -246 190 14 232 195 16 98 70 6 2 2 6
37801 - 2 2 6 2 2 6 66 66 66 221 221 221
37802 -253 253 253 253 253 253 253 253 253 253 253 253
37803 -253 253 253 253 253 253 253 253 253 253 253 253
37804 -253 253 253 253 253 253 253 253 253 253 253 253
37805 -253 253 253 253 253 253 253 253 253 253 253 253
37806 -253 253 253 206 206 206 198 198 198 214 166 58
37807 -230 174 11 230 174 11 216 158 10 192 133 9
37808 -163 110 8 116 81 8 102 78 10 116 81 8
37809 -167 114 7 197 138 11 226 170 11 239 182 13
37810 -242 186 14 242 186 14 162 146 94 78 78 78
37811 - 34 34 34 14 14 14 6 6 6 0 0 0
37812 - 0 0 0 0 0 0 0 0 0 0 0 0
37813 - 0 0 0 0 0 0 0 0 0 0 0 0
37814 - 0 0 0 0 0 0 0 0 0 0 0 0
37815 - 0 0 0 0 0 0 0 0 0 6 6 6
37816 - 30 30 30 78 78 78 190 142 34 226 170 11
37817 -239 182 13 246 190 14 246 190 14 246 190 14
37818 -246 190 14 246 190 14 246 190 14 246 190 14
37819 -246 190 14 246 190 14 246 190 14 246 190 14
37820 -246 190 14 241 196 14 203 166 17 22 18 6
37821 - 2 2 6 2 2 6 2 2 6 38 38 38
37822 -218 218 218 253 253 253 253 253 253 253 253 253
37823 -253 253 253 253 253 253 253 253 253 253 253 253
37824 -253 253 253 253 253 253 253 253 253 253 253 253
37825 -253 253 253 253 253 253 253 253 253 253 253 253
37826 -250 250 250 206 206 206 198 198 198 202 162 69
37827 -226 170 11 236 178 12 224 166 10 210 150 10
37828 -200 144 11 197 138 11 192 133 9 197 138 11
37829 -210 150 10 226 170 11 242 186 14 246 190 14
37830 -246 190 14 246 186 14 225 175 15 124 112 88
37831 - 62 62 62 30 30 30 14 14 14 6 6 6
37832 - 0 0 0 0 0 0 0 0 0 0 0 0
37833 - 0 0 0 0 0 0 0 0 0 0 0 0
37834 - 0 0 0 0 0 0 0 0 0 0 0 0
37835 - 0 0 0 0 0 0 0 0 0 10 10 10
37836 - 30 30 30 78 78 78 174 135 50 224 166 10
37837 -239 182 13 246 190 14 246 190 14 246 190 14
37838 -246 190 14 246 190 14 246 190 14 246 190 14
37839 -246 190 14 246 190 14 246 190 14 246 190 14
37840 -246 190 14 246 190 14 241 196 14 139 102 15
37841 - 2 2 6 2 2 6 2 2 6 2 2 6
37842 - 78 78 78 250 250 250 253 253 253 253 253 253
37843 -253 253 253 253 253 253 253 253 253 253 253 253
37844 -253 253 253 253 253 253 253 253 253 253 253 253
37845 -253 253 253 253 253 253 253 253 253 253 253 253
37846 -250 250 250 214 214 214 198 198 198 190 150 46
37847 -219 162 10 236 178 12 234 174 13 224 166 10
37848 -216 158 10 213 154 11 213 154 11 216 158 10
37849 -226 170 11 239 182 13 246 190 14 246 190 14
37850 -246 190 14 246 190 14 242 186 14 206 162 42
37851 -101 101 101 58 58 58 30 30 30 14 14 14
37852 - 6 6 6 0 0 0 0 0 0 0 0 0
37853 - 0 0 0 0 0 0 0 0 0 0 0 0
37854 - 0 0 0 0 0 0 0 0 0 0 0 0
37855 - 0 0 0 0 0 0 0 0 0 10 10 10
37856 - 30 30 30 74 74 74 174 135 50 216 158 10
37857 -236 178 12 246 190 14 246 190 14 246 190 14
37858 -246 190 14 246 190 14 246 190 14 246 190 14
37859 -246 190 14 246 190 14 246 190 14 246 190 14
37860 -246 190 14 246 190 14 241 196 14 226 184 13
37861 - 61 42 6 2 2 6 2 2 6 2 2 6
37862 - 22 22 22 238 238 238 253 253 253 253 253 253
37863 -253 253 253 253 253 253 253 253 253 253 253 253
37864 -253 253 253 253 253 253 253 253 253 253 253 253
37865 -253 253 253 253 253 253 253 253 253 253 253 253
37866 -253 253 253 226 226 226 187 187 187 180 133 36
37867 -216 158 10 236 178 12 239 182 13 236 178 12
37868 -230 174 11 226 170 11 226 170 11 230 174 11
37869 -236 178 12 242 186 14 246 190 14 246 190 14
37870 -246 190 14 246 190 14 246 186 14 239 182 13
37871 -206 162 42 106 106 106 66 66 66 34 34 34
37872 - 14 14 14 6 6 6 0 0 0 0 0 0
37873 - 0 0 0 0 0 0 0 0 0 0 0 0
37874 - 0 0 0 0 0 0 0 0 0 0 0 0
37875 - 0 0 0 0 0 0 0 0 0 6 6 6
37876 - 26 26 26 70 70 70 163 133 67 213 154 11
37877 -236 178 12 246 190 14 246 190 14 246 190 14
37878 -246 190 14 246 190 14 246 190 14 246 190 14
37879 -246 190 14 246 190 14 246 190 14 246 190 14
37880 -246 190 14 246 190 14 246 190 14 241 196 14
37881 -190 146 13 18 14 6 2 2 6 2 2 6
37882 - 46 46 46 246 246 246 253 253 253 253 253 253
37883 -253 253 253 253 253 253 253 253 253 253 253 253
37884 -253 253 253 253 253 253 253 253 253 253 253 253
37885 -253 253 253 253 253 253 253 253 253 253 253 253
37886 -253 253 253 221 221 221 86 86 86 156 107 11
37887 -216 158 10 236 178 12 242 186 14 246 186 14
37888 -242 186 14 239 182 13 239 182 13 242 186 14
37889 -242 186 14 246 186 14 246 190 14 246 190 14
37890 -246 190 14 246 190 14 246 190 14 246 190 14
37891 -242 186 14 225 175 15 142 122 72 66 66 66
37892 - 30 30 30 10 10 10 0 0 0 0 0 0
37893 - 0 0 0 0 0 0 0 0 0 0 0 0
37894 - 0 0 0 0 0 0 0 0 0 0 0 0
37895 - 0 0 0 0 0 0 0 0 0 6 6 6
37896 - 26 26 26 70 70 70 163 133 67 210 150 10
37897 -236 178 12 246 190 14 246 190 14 246 190 14
37898 -246 190 14 246 190 14 246 190 14 246 190 14
37899 -246 190 14 246 190 14 246 190 14 246 190 14
37900 -246 190 14 246 190 14 246 190 14 246 190 14
37901 -232 195 16 121 92 8 34 34 34 106 106 106
37902 -221 221 221 253 253 253 253 253 253 253 253 253
37903 -253 253 253 253 253 253 253 253 253 253 253 253
37904 -253 253 253 253 253 253 253 253 253 253 253 253
37905 -253 253 253 253 253 253 253 253 253 253 253 253
37906 -242 242 242 82 82 82 18 14 6 163 110 8
37907 -216 158 10 236 178 12 242 186 14 246 190 14
37908 -246 190 14 246 190 14 246 190 14 246 190 14
37909 -246 190 14 246 190 14 246 190 14 246 190 14
37910 -246 190 14 246 190 14 246 190 14 246 190 14
37911 -246 190 14 246 190 14 242 186 14 163 133 67
37912 - 46 46 46 18 18 18 6 6 6 0 0 0
37913 - 0 0 0 0 0 0 0 0 0 0 0 0
37914 - 0 0 0 0 0 0 0 0 0 0 0 0
37915 - 0 0 0 0 0 0 0 0 0 10 10 10
37916 - 30 30 30 78 78 78 163 133 67 210 150 10
37917 -236 178 12 246 186 14 246 190 14 246 190 14
37918 -246 190 14 246 190 14 246 190 14 246 190 14
37919 -246 190 14 246 190 14 246 190 14 246 190 14
37920 -246 190 14 246 190 14 246 190 14 246 190 14
37921 -241 196 14 215 174 15 190 178 144 253 253 253
37922 -253 253 253 253 253 253 253 253 253 253 253 253
37923 -253 253 253 253 253 253 253 253 253 253 253 253
37924 -253 253 253 253 253 253 253 253 253 253 253 253
37925 -253 253 253 253 253 253 253 253 253 218 218 218
37926 - 58 58 58 2 2 6 22 18 6 167 114 7
37927 -216 158 10 236 178 12 246 186 14 246 190 14
37928 -246 190 14 246 190 14 246 190 14 246 190 14
37929 -246 190 14 246 190 14 246 190 14 246 190 14
37930 -246 190 14 246 190 14 246 190 14 246 190 14
37931 -246 190 14 246 186 14 242 186 14 190 150 46
37932 - 54 54 54 22 22 22 6 6 6 0 0 0
37933 - 0 0 0 0 0 0 0 0 0 0 0 0
37934 - 0 0 0 0 0 0 0 0 0 0 0 0
37935 - 0 0 0 0 0 0 0 0 0 14 14 14
37936 - 38 38 38 86 86 86 180 133 36 213 154 11
37937 -236 178 12 246 186 14 246 190 14 246 190 14
37938 -246 190 14 246 190 14 246 190 14 246 190 14
37939 -246 190 14 246 190 14 246 190 14 246 190 14
37940 -246 190 14 246 190 14 246 190 14 246 190 14
37941 -246 190 14 232 195 16 190 146 13 214 214 214
37942 -253 253 253 253 253 253 253 253 253 253 253 253
37943 -253 253 253 253 253 253 253 253 253 253 253 253
37944 -253 253 253 253 253 253 253 253 253 253 253 253
37945 -253 253 253 250 250 250 170 170 170 26 26 26
37946 - 2 2 6 2 2 6 37 26 9 163 110 8
37947 -219 162 10 239 182 13 246 186 14 246 190 14
37948 -246 190 14 246 190 14 246 190 14 246 190 14
37949 -246 190 14 246 190 14 246 190 14 246 190 14
37950 -246 190 14 246 190 14 246 190 14 246 190 14
37951 -246 186 14 236 178 12 224 166 10 142 122 72
37952 - 46 46 46 18 18 18 6 6 6 0 0 0
37953 - 0 0 0 0 0 0 0 0 0 0 0 0
37954 - 0 0 0 0 0 0 0 0 0 0 0 0
37955 - 0 0 0 0 0 0 6 6 6 18 18 18
37956 - 50 50 50 109 106 95 192 133 9 224 166 10
37957 -242 186 14 246 190 14 246 190 14 246 190 14
37958 -246 190 14 246 190 14 246 190 14 246 190 14
37959 -246 190 14 246 190 14 246 190 14 246 190 14
37960 -246 190 14 246 190 14 246 190 14 246 190 14
37961 -242 186 14 226 184 13 210 162 10 142 110 46
37962 -226 226 226 253 253 253 253 253 253 253 253 253
37963 -253 253 253 253 253 253 253 253 253 253 253 253
37964 -253 253 253 253 253 253 253 253 253 253 253 253
37965 -198 198 198 66 66 66 2 2 6 2 2 6
37966 - 2 2 6 2 2 6 50 34 6 156 107 11
37967 -219 162 10 239 182 13 246 186 14 246 190 14
37968 -246 190 14 246 190 14 246 190 14 246 190 14
37969 -246 190 14 246 190 14 246 190 14 246 190 14
37970 -246 190 14 246 190 14 246 190 14 242 186 14
37971 -234 174 13 213 154 11 154 122 46 66 66 66
37972 - 30 30 30 10 10 10 0 0 0 0 0 0
37973 - 0 0 0 0 0 0 0 0 0 0 0 0
37974 - 0 0 0 0 0 0 0 0 0 0 0 0
37975 - 0 0 0 0 0 0 6 6 6 22 22 22
37976 - 58 58 58 154 121 60 206 145 10 234 174 13
37977 -242 186 14 246 186 14 246 190 14 246 190 14
37978 -246 190 14 246 190 14 246 190 14 246 190 14
37979 -246 190 14 246 190 14 246 190 14 246 190 14
37980 -246 190 14 246 190 14 246 190 14 246 190 14
37981 -246 186 14 236 178 12 210 162 10 163 110 8
37982 - 61 42 6 138 138 138 218 218 218 250 250 250
37983 -253 253 253 253 253 253 253 253 253 250 250 250
37984 -242 242 242 210 210 210 144 144 144 66 66 66
37985 - 6 6 6 2 2 6 2 2 6 2 2 6
37986 - 2 2 6 2 2 6 61 42 6 163 110 8
37987 -216 158 10 236 178 12 246 190 14 246 190 14
37988 -246 190 14 246 190 14 246 190 14 246 190 14
37989 -246 190 14 246 190 14 246 190 14 246 190 14
37990 -246 190 14 239 182 13 230 174 11 216 158 10
37991 -190 142 34 124 112 88 70 70 70 38 38 38
37992 - 18 18 18 6 6 6 0 0 0 0 0 0
37993 - 0 0 0 0 0 0 0 0 0 0 0 0
37994 - 0 0 0 0 0 0 0 0 0 0 0 0
37995 - 0 0 0 0 0 0 6 6 6 22 22 22
37996 - 62 62 62 168 124 44 206 145 10 224 166 10
37997 -236 178 12 239 182 13 242 186 14 242 186 14
37998 -246 186 14 246 190 14 246 190 14 246 190 14
37999 -246 190 14 246 190 14 246 190 14 246 190 14
38000 -246 190 14 246 190 14 246 190 14 246 190 14
38001 -246 190 14 236 178 12 216 158 10 175 118 6
38002 - 80 54 7 2 2 6 6 6 6 30 30 30
38003 - 54 54 54 62 62 62 50 50 50 38 38 38
38004 - 14 14 14 2 2 6 2 2 6 2 2 6
38005 - 2 2 6 2 2 6 2 2 6 2 2 6
38006 - 2 2 6 6 6 6 80 54 7 167 114 7
38007 -213 154 11 236 178 12 246 190 14 246 190 14
38008 -246 190 14 246 190 14 246 190 14 246 190 14
38009 -246 190 14 242 186 14 239 182 13 239 182 13
38010 -230 174 11 210 150 10 174 135 50 124 112 88
38011 - 82 82 82 54 54 54 34 34 34 18 18 18
38012 - 6 6 6 0 0 0 0 0 0 0 0 0
38013 - 0 0 0 0 0 0 0 0 0 0 0 0
38014 - 0 0 0 0 0 0 0 0 0 0 0 0
38015 - 0 0 0 0 0 0 6 6 6 18 18 18
38016 - 50 50 50 158 118 36 192 133 9 200 144 11
38017 -216 158 10 219 162 10 224 166 10 226 170 11
38018 -230 174 11 236 178 12 239 182 13 239 182 13
38019 -242 186 14 246 186 14 246 190 14 246 190 14
38020 -246 190 14 246 190 14 246 190 14 246 190 14
38021 -246 186 14 230 174 11 210 150 10 163 110 8
38022 -104 69 6 10 10 10 2 2 6 2 2 6
38023 - 2 2 6 2 2 6 2 2 6 2 2 6
38024 - 2 2 6 2 2 6 2 2 6 2 2 6
38025 - 2 2 6 2 2 6 2 2 6 2 2 6
38026 - 2 2 6 6 6 6 91 60 6 167 114 7
38027 -206 145 10 230 174 11 242 186 14 246 190 14
38028 -246 190 14 246 190 14 246 186 14 242 186 14
38029 -239 182 13 230 174 11 224 166 10 213 154 11
38030 -180 133 36 124 112 88 86 86 86 58 58 58
38031 - 38 38 38 22 22 22 10 10 10 6 6 6
38032 - 0 0 0 0 0 0 0 0 0 0 0 0
38033 - 0 0 0 0 0 0 0 0 0 0 0 0
38034 - 0 0 0 0 0 0 0 0 0 0 0 0
38035 - 0 0 0 0 0 0 0 0 0 14 14 14
38036 - 34 34 34 70 70 70 138 110 50 158 118 36
38037 -167 114 7 180 123 7 192 133 9 197 138 11
38038 -200 144 11 206 145 10 213 154 11 219 162 10
38039 -224 166 10 230 174 11 239 182 13 242 186 14
38040 -246 186 14 246 186 14 246 186 14 246 186 14
38041 -239 182 13 216 158 10 185 133 11 152 99 6
38042 -104 69 6 18 14 6 2 2 6 2 2 6
38043 - 2 2 6 2 2 6 2 2 6 2 2 6
38044 - 2 2 6 2 2 6 2 2 6 2 2 6
38045 - 2 2 6 2 2 6 2 2 6 2 2 6
38046 - 2 2 6 6 6 6 80 54 7 152 99 6
38047 -192 133 9 219 162 10 236 178 12 239 182 13
38048 -246 186 14 242 186 14 239 182 13 236 178 12
38049 -224 166 10 206 145 10 192 133 9 154 121 60
38050 - 94 94 94 62 62 62 42 42 42 22 22 22
38051 - 14 14 14 6 6 6 0 0 0 0 0 0
38052 - 0 0 0 0 0 0 0 0 0 0 0 0
38053 - 0 0 0 0 0 0 0 0 0 0 0 0
38054 - 0 0 0 0 0 0 0 0 0 0 0 0
38055 - 0 0 0 0 0 0 0 0 0 6 6 6
38056 - 18 18 18 34 34 34 58 58 58 78 78 78
38057 -101 98 89 124 112 88 142 110 46 156 107 11
38058 -163 110 8 167 114 7 175 118 6 180 123 7
38059 -185 133 11 197 138 11 210 150 10 219 162 10
38060 -226 170 11 236 178 12 236 178 12 234 174 13
38061 -219 162 10 197 138 11 163 110 8 130 83 6
38062 - 91 60 6 10 10 10 2 2 6 2 2 6
38063 - 18 18 18 38 38 38 38 38 38 38 38 38
38064 - 38 38 38 38 38 38 38 38 38 38 38 38
38065 - 38 38 38 38 38 38 26 26 26 2 2 6
38066 - 2 2 6 6 6 6 70 47 6 137 92 6
38067 -175 118 6 200 144 11 219 162 10 230 174 11
38068 -234 174 13 230 174 11 219 162 10 210 150 10
38069 -192 133 9 163 110 8 124 112 88 82 82 82
38070 - 50 50 50 30 30 30 14 14 14 6 6 6
38071 - 0 0 0 0 0 0 0 0 0 0 0 0
38072 - 0 0 0 0 0 0 0 0 0 0 0 0
38073 - 0 0 0 0 0 0 0 0 0 0 0 0
38074 - 0 0 0 0 0 0 0 0 0 0 0 0
38075 - 0 0 0 0 0 0 0 0 0 0 0 0
38076 - 6 6 6 14 14 14 22 22 22 34 34 34
38077 - 42 42 42 58 58 58 74 74 74 86 86 86
38078 -101 98 89 122 102 70 130 98 46 121 87 25
38079 -137 92 6 152 99 6 163 110 8 180 123 7
38080 -185 133 11 197 138 11 206 145 10 200 144 11
38081 -180 123 7 156 107 11 130 83 6 104 69 6
38082 - 50 34 6 54 54 54 110 110 110 101 98 89
38083 - 86 86 86 82 82 82 78 78 78 78 78 78
38084 - 78 78 78 78 78 78 78 78 78 78 78 78
38085 - 78 78 78 82 82 82 86 86 86 94 94 94
38086 -106 106 106 101 101 101 86 66 34 124 80 6
38087 -156 107 11 180 123 7 192 133 9 200 144 11
38088 -206 145 10 200 144 11 192 133 9 175 118 6
38089 -139 102 15 109 106 95 70 70 70 42 42 42
38090 - 22 22 22 10 10 10 0 0 0 0 0 0
38091 - 0 0 0 0 0 0 0 0 0 0 0 0
38092 - 0 0 0 0 0 0 0 0 0 0 0 0
38093 - 0 0 0 0 0 0 0 0 0 0 0 0
38094 - 0 0 0 0 0 0 0 0 0 0 0 0
38095 - 0 0 0 0 0 0 0 0 0 0 0 0
38096 - 0 0 0 0 0 0 6 6 6 10 10 10
38097 - 14 14 14 22 22 22 30 30 30 38 38 38
38098 - 50 50 50 62 62 62 74 74 74 90 90 90
38099 -101 98 89 112 100 78 121 87 25 124 80 6
38100 -137 92 6 152 99 6 152 99 6 152 99 6
38101 -138 86 6 124 80 6 98 70 6 86 66 30
38102 -101 98 89 82 82 82 58 58 58 46 46 46
38103 - 38 38 38 34 34 34 34 34 34 34 34 34
38104 - 34 34 34 34 34 34 34 34 34 34 34 34
38105 - 34 34 34 34 34 34 38 38 38 42 42 42
38106 - 54 54 54 82 82 82 94 86 76 91 60 6
38107 -134 86 6 156 107 11 167 114 7 175 118 6
38108 -175 118 6 167 114 7 152 99 6 121 87 25
38109 -101 98 89 62 62 62 34 34 34 18 18 18
38110 - 6 6 6 0 0 0 0 0 0 0 0 0
38111 - 0 0 0 0 0 0 0 0 0 0 0 0
38112 - 0 0 0 0 0 0 0 0 0 0 0 0
38113 - 0 0 0 0 0 0 0 0 0 0 0 0
38114 - 0 0 0 0 0 0 0 0 0 0 0 0
38115 - 0 0 0 0 0 0 0 0 0 0 0 0
38116 - 0 0 0 0 0 0 0 0 0 0 0 0
38117 - 0 0 0 6 6 6 6 6 6 10 10 10
38118 - 18 18 18 22 22 22 30 30 30 42 42 42
38119 - 50 50 50 66 66 66 86 86 86 101 98 89
38120 -106 86 58 98 70 6 104 69 6 104 69 6
38121 -104 69 6 91 60 6 82 62 34 90 90 90
38122 - 62 62 62 38 38 38 22 22 22 14 14 14
38123 - 10 10 10 10 10 10 10 10 10 10 10 10
38124 - 10 10 10 10 10 10 6 6 6 10 10 10
38125 - 10 10 10 10 10 10 10 10 10 14 14 14
38126 - 22 22 22 42 42 42 70 70 70 89 81 66
38127 - 80 54 7 104 69 6 124 80 6 137 92 6
38128 -134 86 6 116 81 8 100 82 52 86 86 86
38129 - 58 58 58 30 30 30 14 14 14 6 6 6
38130 - 0 0 0 0 0 0 0 0 0 0 0 0
38131 - 0 0 0 0 0 0 0 0 0 0 0 0
38132 - 0 0 0 0 0 0 0 0 0 0 0 0
38133 - 0 0 0 0 0 0 0 0 0 0 0 0
38134 - 0 0 0 0 0 0 0 0 0 0 0 0
38135 - 0 0 0 0 0 0 0 0 0 0 0 0
38136 - 0 0 0 0 0 0 0 0 0 0 0 0
38137 - 0 0 0 0 0 0 0 0 0 0 0 0
38138 - 0 0 0 6 6 6 10 10 10 14 14 14
38139 - 18 18 18 26 26 26 38 38 38 54 54 54
38140 - 70 70 70 86 86 86 94 86 76 89 81 66
38141 - 89 81 66 86 86 86 74 74 74 50 50 50
38142 - 30 30 30 14 14 14 6 6 6 0 0 0
38143 - 0 0 0 0 0 0 0 0 0 0 0 0
38144 - 0 0 0 0 0 0 0 0 0 0 0 0
38145 - 0 0 0 0 0 0 0 0 0 0 0 0
38146 - 6 6 6 18 18 18 34 34 34 58 58 58
38147 - 82 82 82 89 81 66 89 81 66 89 81 66
38148 - 94 86 66 94 86 76 74 74 74 50 50 50
38149 - 26 26 26 14 14 14 6 6 6 0 0 0
38150 - 0 0 0 0 0 0 0 0 0 0 0 0
38151 - 0 0 0 0 0 0 0 0 0 0 0 0
38152 - 0 0 0 0 0 0 0 0 0 0 0 0
38153 - 0 0 0 0 0 0 0 0 0 0 0 0
38154 - 0 0 0 0 0 0 0 0 0 0 0 0
38155 - 0 0 0 0 0 0 0 0 0 0 0 0
38156 - 0 0 0 0 0 0 0 0 0 0 0 0
38157 - 0 0 0 0 0 0 0 0 0 0 0 0
38158 - 0 0 0 0 0 0 0 0 0 0 0 0
38159 - 6 6 6 6 6 6 14 14 14 18 18 18
38160 - 30 30 30 38 38 38 46 46 46 54 54 54
38161 - 50 50 50 42 42 42 30 30 30 18 18 18
38162 - 10 10 10 0 0 0 0 0 0 0 0 0
38163 - 0 0 0 0 0 0 0 0 0 0 0 0
38164 - 0 0 0 0 0 0 0 0 0 0 0 0
38165 - 0 0 0 0 0 0 0 0 0 0 0 0
38166 - 0 0 0 6 6 6 14 14 14 26 26 26
38167 - 38 38 38 50 50 50 58 58 58 58 58 58
38168 - 54 54 54 42 42 42 30 30 30 18 18 18
38169 - 10 10 10 0 0 0 0 0 0 0 0 0
38170 - 0 0 0 0 0 0 0 0 0 0 0 0
38171 - 0 0 0 0 0 0 0 0 0 0 0 0
38172 - 0 0 0 0 0 0 0 0 0 0 0 0
38173 - 0 0 0 0 0 0 0 0 0 0 0 0
38174 - 0 0 0 0 0 0 0 0 0 0 0 0
38175 - 0 0 0 0 0 0 0 0 0 0 0 0
38176 - 0 0 0 0 0 0 0 0 0 0 0 0
38177 - 0 0 0 0 0 0 0 0 0 0 0 0
38178 - 0 0 0 0 0 0 0 0 0 0 0 0
38179 - 0 0 0 0 0 0 0 0 0 6 6 6
38180 - 6 6 6 10 10 10 14 14 14 18 18 18
38181 - 18 18 18 14 14 14 10 10 10 6 6 6
38182 - 0 0 0 0 0 0 0 0 0 0 0 0
38183 - 0 0 0 0 0 0 0 0 0 0 0 0
38184 - 0 0 0 0 0 0 0 0 0 0 0 0
38185 - 0 0 0 0 0 0 0 0 0 0 0 0
38186 - 0 0 0 0 0 0 0 0 0 6 6 6
38187 - 14 14 14 18 18 18 22 22 22 22 22 22
38188 - 18 18 18 14 14 14 10 10 10 6 6 6
38189 - 0 0 0 0 0 0 0 0 0 0 0 0
38190 - 0 0 0 0 0 0 0 0 0 0 0 0
38191 - 0 0 0 0 0 0 0 0 0 0 0 0
38192 - 0 0 0 0 0 0 0 0 0 0 0 0
38193 - 0 0 0 0 0 0 0 0 0 0 0 0
38194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38207 +4 4 4 4 4 4
38208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38221 +4 4 4 4 4 4
38222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38235 +4 4 4 4 4 4
38236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38249 +4 4 4 4 4 4
38250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38263 +4 4 4 4 4 4
38264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38277 +4 4 4 4 4 4
38278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38282 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
38283 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
38284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38287 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
38288 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38289 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
38290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38291 +4 4 4 4 4 4
38292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38296 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
38297 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
38298 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38301 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
38302 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
38303 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
38304 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38305 +4 4 4 4 4 4
38306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38310 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
38311 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
38312 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38315 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
38316 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
38317 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
38318 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
38319 +4 4 4 4 4 4
38320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38323 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
38324 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
38325 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
38326 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
38327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38328 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
38329 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
38330 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
38331 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
38332 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
38333 +4 4 4 4 4 4
38334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38337 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
38338 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
38339 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
38340 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
38341 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
38342 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
38343 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
38344 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
38345 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
38346 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
38347 +4 4 4 4 4 4
38348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
38351 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
38352 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
38353 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
38354 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
38355 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
38356 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
38357 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
38358 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
38359 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
38360 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
38361 +4 4 4 4 4 4
38362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38364 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
38365 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
38366 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
38367 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
38368 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
38369 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
38370 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
38371 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
38372 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
38373 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
38374 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
38375 +4 4 4 4 4 4
38376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38378 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
38379 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
38380 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
38381 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
38382 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
38383 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
38384 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
38385 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
38386 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
38387 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
38388 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
38389 +4 4 4 4 4 4
38390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38392 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
38393 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
38394 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
38395 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
38396 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
38397 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
38398 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
38399 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
38400 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
38401 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
38402 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
38403 +4 4 4 4 4 4
38404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38405 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38406 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
38407 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
38408 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
38409 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
38410 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
38411 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
38412 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
38413 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
38414 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
38415 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
38416 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
38417 +4 4 4 4 4 4
38418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38419 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
38420 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
38421 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
38422 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
38423 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
38424 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
38425 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
38426 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
38427 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
38428 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
38429 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
38430 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
38431 +4 4 4 4 4 4
38432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38433 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
38434 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
38435 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
38436 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
38437 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
38438 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
38439 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
38440 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
38441 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
38442 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
38443 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
38444 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
38445 +0 0 0 4 4 4
38446 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
38447 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
38448 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
38449 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
38450 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
38451 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
38452 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
38453 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
38454 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
38455 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
38456 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
38457 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
38458 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
38459 +2 0 0 0 0 0
38460 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
38461 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
38462 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
38463 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
38464 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
38465 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
38466 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
38467 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
38468 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
38469 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
38470 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
38471 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
38472 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
38473 +37 38 37 0 0 0
38474 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
38475 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
38476 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
38477 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
38478 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
38479 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
38480 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
38481 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
38482 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
38483 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
38484 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
38485 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
38486 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
38487 +85 115 134 4 0 0
38488 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
38489 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
38490 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
38491 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
38492 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
38493 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
38494 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
38495 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
38496 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
38497 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
38498 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
38499 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
38500 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
38501 +60 73 81 4 0 0
38502 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
38503 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
38504 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
38505 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
38506 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
38507 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
38508 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
38509 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
38510 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
38511 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
38512 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
38513 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
38514 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
38515 +16 19 21 4 0 0
38516 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
38517 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
38518 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
38519 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
38520 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
38521 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
38522 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
38523 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
38524 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
38525 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
38526 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
38527 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
38528 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
38529 +4 0 0 4 3 3
38530 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
38531 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
38532 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
38533 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
38534 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
38535 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
38536 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
38537 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
38538 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
38539 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
38540 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
38541 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
38542 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
38543 +3 2 2 4 4 4
38544 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
38545 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
38546 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
38547 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
38548 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
38549 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
38550 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
38551 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
38552 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
38553 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
38554 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
38555 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
38556 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
38557 +4 4 4 4 4 4
38558 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
38559 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
38560 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
38561 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
38562 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
38563 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
38564 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
38565 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
38566 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
38567 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
38568 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
38569 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
38570 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
38571 +4 4 4 4 4 4
38572 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
38573 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
38574 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
38575 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
38576 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
38577 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
38578 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
38579 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
38580 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
38581 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
38582 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
38583 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
38584 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
38585 +5 5 5 5 5 5
38586 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
38587 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
38588 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
38589 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
38590 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
38591 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38592 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
38593 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
38594 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
38595 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
38596 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
38597 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
38598 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
38599 +5 5 5 4 4 4
38600 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
38601 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
38602 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
38603 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
38604 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38605 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
38606 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
38607 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
38608 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
38609 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
38610 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
38611 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
38612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38613 +4 4 4 4 4 4
38614 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
38615 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
38616 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
38617 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
38618 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
38619 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38620 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38621 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
38622 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
38623 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
38624 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
38625 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
38626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38627 +4 4 4 4 4 4
38628 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
38629 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
38630 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
38631 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
38632 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38633 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
38634 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
38635 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
38636 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
38637 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
38638 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
38639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38641 +4 4 4 4 4 4
38642 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
38643 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
38644 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
38645 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
38646 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38647 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38648 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
38649 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
38650 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
38651 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
38652 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
38653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38655 +4 4 4 4 4 4
38656 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
38657 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
38658 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
38659 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
38660 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38661 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
38662 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
38663 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
38664 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
38665 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
38666 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38669 +4 4 4 4 4 4
38670 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
38671 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
38672 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
38673 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
38674 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
38675 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
38676 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
38677 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
38678 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
38679 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
38680 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
38681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38683 +4 4 4 4 4 4
38684 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
38685 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
38686 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
38687 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
38688 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
38689 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
38690 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
38691 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
38692 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
38693 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
38694 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
38695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38697 +4 4 4 4 4 4
38698 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
38699 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
38700 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
38701 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
38702 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
38703 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
38704 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
38705 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
38706 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
38707 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
38708 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38711 +4 4 4 4 4 4
38712 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
38713 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
38714 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
38715 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
38716 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38717 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
38718 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
38719 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
38720 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
38721 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
38722 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38725 +4 4 4 4 4 4
38726 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
38727 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
38728 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
38729 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
38730 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38731 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
38732 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
38733 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
38734 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
38735 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
38736 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38739 +4 4 4 4 4 4
38740 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
38741 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
38742 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
38743 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
38744 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38745 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
38746 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
38747 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
38748 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
38749 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38750 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38753 +4 4 4 4 4 4
38754 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
38755 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
38756 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
38757 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
38758 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
38759 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
38760 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
38761 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
38762 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38763 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38764 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38767 +4 4 4 4 4 4
38768 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
38769 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
38770 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
38771 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
38772 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38773 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
38774 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
38775 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
38776 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38777 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38778 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38781 +4 4 4 4 4 4
38782 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
38783 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
38784 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
38785 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
38786 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
38787 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
38788 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
38789 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
38790 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38791 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38792 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38795 +4 4 4 4 4 4
38796 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
38797 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
38798 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38799 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
38800 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
38801 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
38802 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
38803 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
38804 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
38805 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38806 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38807 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38808 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38809 +4 4 4 4 4 4
38810 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
38811 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
38812 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
38813 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
38814 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
38815 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
38816 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
38817 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
38818 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38819 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38820 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38821 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38822 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38823 +4 4 4 4 4 4
38824 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
38825 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
38826 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38827 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
38828 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
38829 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
38830 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
38831 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
38832 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
38833 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38834 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38835 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38836 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38837 +4 4 4 4 4 4
38838 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
38839 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
38840 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
38841 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
38842 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
38843 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
38844 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
38845 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
38846 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38847 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38848 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38849 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38851 +4 4 4 4 4 4
38852 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38853 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
38854 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
38855 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
38856 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
38857 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
38858 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
38859 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
38860 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38861 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38862 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38863 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38865 +4 4 4 4 4 4
38866 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
38867 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
38868 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
38869 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
38870 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
38871 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
38872 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38873 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
38874 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
38875 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38876 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38877 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38879 +4 4 4 4 4 4
38880 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38881 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
38882 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
38883 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
38884 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
38885 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
38886 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
38887 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
38888 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
38889 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38890 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38891 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38893 +4 4 4 4 4 4
38894 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
38895 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
38896 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
38897 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
38898 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
38899 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
38900 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
38901 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
38902 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
38903 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38904 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38905 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38907 +4 4 4 4 4 4
38908 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38909 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
38910 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
38911 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
38912 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
38913 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
38914 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
38915 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
38916 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
38917 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38918 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38921 +4 4 4 4 4 4
38922 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
38923 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
38924 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
38925 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
38926 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
38927 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
38928 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
38929 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
38930 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
38931 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38932 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38935 +4 4 4 4 4 4
38936 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
38937 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
38938 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
38939 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
38940 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
38941 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
38942 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
38943 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
38944 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
38945 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
38946 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38949 +4 4 4 4 4 4
38950 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
38951 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
38952 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
38953 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
38954 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
38955 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
38956 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
38957 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
38958 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
38959 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
38960 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
38961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38963 +4 4 4 4 4 4
38964 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
38965 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
38966 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
38967 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
38968 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
38969 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
38970 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
38971 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
38972 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
38973 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
38974 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38977 +4 4 4 4 4 4
38978 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
38979 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
38980 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
38981 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
38982 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
38983 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
38984 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38985 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
38986 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
38987 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
38988 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
38989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
38991 +4 4 4 4 4 4
38992 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
38993 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
38994 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
38995 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
38996 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
38997 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
38998 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
38999 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
39000 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
39001 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
39002 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39005 +4 4 4 4 4 4
39006 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
39007 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
39008 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
39009 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
39010 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
39011 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
39012 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
39013 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
39014 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
39015 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
39016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39019 +4 4 4 4 4 4
39020 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
39021 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
39022 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
39023 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
39024 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
39025 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
39026 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
39027 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
39028 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
39029 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
39030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39033 +4 4 4 4 4 4
39034 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
39035 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
39036 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
39037 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
39038 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
39039 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
39040 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
39041 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
39042 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
39043 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
39044 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39047 +4 4 4 4 4 4
39048 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
39049 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
39050 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
39051 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
39052 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
39053 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
39054 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
39055 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
39056 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
39057 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39058 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39061 +4 4 4 4 4 4
39062 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
39063 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
39064 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
39065 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
39066 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
39067 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
39068 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
39069 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
39070 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
39071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39072 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39075 +4 4 4 4 4 4
39076 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
39077 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
39078 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
39079 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
39080 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
39081 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
39082 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
39083 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
39084 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
39085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39086 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39089 +4 4 4 4 4 4
39090 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
39091 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
39092 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
39093 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
39094 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
39095 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
39096 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
39097 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
39098 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39100 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39103 +4 4 4 4 4 4
39104 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
39105 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
39106 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
39107 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
39108 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
39109 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
39110 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
39111 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
39112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39114 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39117 +4 4 4 4 4 4
39118 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
39119 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
39120 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
39121 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
39122 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
39123 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
39124 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
39125 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
39126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39128 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39131 +4 4 4 4 4 4
39132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39133 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
39134 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39135 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
39136 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
39137 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
39138 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
39139 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
39140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39145 +4 4 4 4 4 4
39146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39147 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
39148 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
39149 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
39150 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
39151 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
39152 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
39153 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
39154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39159 +4 4 4 4 4 4
39160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39161 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
39162 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
39163 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
39164 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
39165 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
39166 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
39167 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39173 +4 4 4 4 4 4
39174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39176 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
39177 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
39178 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
39179 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
39180 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
39181 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
39182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39187 +4 4 4 4 4 4
39188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39191 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39192 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
39193 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
39194 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
39195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39201 +4 4 4 4 4 4
39202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39205 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
39206 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
39207 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
39208 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
39209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39215 +4 4 4 4 4 4
39216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39219 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
39220 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
39221 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
39222 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
39223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39229 +4 4 4 4 4 4
39230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39233 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
39234 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
39235 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
39236 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
39237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39243 +4 4 4 4 4 4
39244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
39248 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
39249 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
39250 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
39251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39257 +4 4 4 4 4 4
39258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39262 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
39263 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
39264 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
39265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39271 +4 4 4 4 4 4
39272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39276 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
39277 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
39278 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39285 +4 4 4 4 4 4
39286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39290 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
39291 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
39292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39299 +4 4 4 4 4 4
39300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39304 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
39305 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
39306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
39313 +4 4 4 4 4 4
39314 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
39315 index 3473e75..c930142 100644
39316 --- a/drivers/video/udlfb.c
39317 +++ b/drivers/video/udlfb.c
39318 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
39319 dlfb_urb_completion(urb);
39320
39321 error:
39322 - atomic_add(bytes_sent, &dev->bytes_sent);
39323 - atomic_add(bytes_identical, &dev->bytes_identical);
39324 - atomic_add(width*height*2, &dev->bytes_rendered);
39325 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
39326 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
39327 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
39328 end_cycles = get_cycles();
39329 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
39330 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
39331 >> 10)), /* Kcycles */
39332 &dev->cpu_kcycles_used);
39333
39334 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
39335 dlfb_urb_completion(urb);
39336
39337 error:
39338 - atomic_add(bytes_sent, &dev->bytes_sent);
39339 - atomic_add(bytes_identical, &dev->bytes_identical);
39340 - atomic_add(bytes_rendered, &dev->bytes_rendered);
39341 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
39342 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
39343 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
39344 end_cycles = get_cycles();
39345 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
39346 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
39347 >> 10)), /* Kcycles */
39348 &dev->cpu_kcycles_used);
39349 }
39350 @@ -1368,7 +1368,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
39351 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39352 struct dlfb_data *dev = fb_info->par;
39353 return snprintf(buf, PAGE_SIZE, "%u\n",
39354 - atomic_read(&dev->bytes_rendered));
39355 + atomic_read_unchecked(&dev->bytes_rendered));
39356 }
39357
39358 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
39359 @@ -1376,7 +1376,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
39360 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39361 struct dlfb_data *dev = fb_info->par;
39362 return snprintf(buf, PAGE_SIZE, "%u\n",
39363 - atomic_read(&dev->bytes_identical));
39364 + atomic_read_unchecked(&dev->bytes_identical));
39365 }
39366
39367 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
39368 @@ -1384,7 +1384,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
39369 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39370 struct dlfb_data *dev = fb_info->par;
39371 return snprintf(buf, PAGE_SIZE, "%u\n",
39372 - atomic_read(&dev->bytes_sent));
39373 + atomic_read_unchecked(&dev->bytes_sent));
39374 }
39375
39376 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
39377 @@ -1392,7 +1392,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
39378 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39379 struct dlfb_data *dev = fb_info->par;
39380 return snprintf(buf, PAGE_SIZE, "%u\n",
39381 - atomic_read(&dev->cpu_kcycles_used));
39382 + atomic_read_unchecked(&dev->cpu_kcycles_used));
39383 }
39384
39385 static ssize_t edid_show(
39386 @@ -1449,10 +1449,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
39387 struct fb_info *fb_info = dev_get_drvdata(fbdev);
39388 struct dlfb_data *dev = fb_info->par;
39389
39390 - atomic_set(&dev->bytes_rendered, 0);
39391 - atomic_set(&dev->bytes_identical, 0);
39392 - atomic_set(&dev->bytes_sent, 0);
39393 - atomic_set(&dev->cpu_kcycles_used, 0);
39394 + atomic_set_unchecked(&dev->bytes_rendered, 0);
39395 + atomic_set_unchecked(&dev->bytes_identical, 0);
39396 + atomic_set_unchecked(&dev->bytes_sent, 0);
39397 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
39398
39399 return count;
39400 }
39401 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
39402 index 7f8472c..9842e87 100644
39403 --- a/drivers/video/uvesafb.c
39404 +++ b/drivers/video/uvesafb.c
39405 @@ -19,6 +19,7 @@
39406 #include <linux/io.h>
39407 #include <linux/mutex.h>
39408 #include <linux/slab.h>
39409 +#include <linux/moduleloader.h>
39410 #include <video/edid.h>
39411 #include <video/uvesafb.h>
39412 #ifdef CONFIG_X86
39413 @@ -121,7 +122,7 @@ static int uvesafb_helper_start(void)
39414 NULL,
39415 };
39416
39417 - return call_usermodehelper(v86d_path, argv, envp, 1);
39418 + return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
39419 }
39420
39421 /*
39422 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
39423 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
39424 par->pmi_setpal = par->ypan = 0;
39425 } else {
39426 +
39427 +#ifdef CONFIG_PAX_KERNEXEC
39428 +#ifdef CONFIG_MODULES
39429 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
39430 +#endif
39431 + if (!par->pmi_code) {
39432 + par->pmi_setpal = par->ypan = 0;
39433 + return 0;
39434 + }
39435 +#endif
39436 +
39437 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
39438 + task->t.regs.edi);
39439 +
39440 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39441 + pax_open_kernel();
39442 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
39443 + pax_close_kernel();
39444 +
39445 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
39446 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
39447 +#else
39448 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
39449 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
39450 +#endif
39451 +
39452 printk(KERN_INFO "uvesafb: protected mode interface info at "
39453 "%04x:%04x\n",
39454 (u16)task->t.regs.es, (u16)task->t.regs.edi);
39455 @@ -1821,6 +1844,11 @@ out:
39456 if (par->vbe_modes)
39457 kfree(par->vbe_modes);
39458
39459 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39460 + if (par->pmi_code)
39461 + module_free_exec(NULL, par->pmi_code);
39462 +#endif
39463 +
39464 framebuffer_release(info);
39465 return err;
39466 }
39467 @@ -1847,6 +1875,12 @@ static int uvesafb_remove(struct platform_device *dev)
39468 kfree(par->vbe_state_orig);
39469 if (par->vbe_state_saved)
39470 kfree(par->vbe_state_saved);
39471 +
39472 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39473 + if (par->pmi_code)
39474 + module_free_exec(NULL, par->pmi_code);
39475 +#endif
39476 +
39477 }
39478
39479 framebuffer_release(info);
39480 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
39481 index 501b340..86bd4cf 100644
39482 --- a/drivers/video/vesafb.c
39483 +++ b/drivers/video/vesafb.c
39484 @@ -9,6 +9,7 @@
39485 */
39486
39487 #include <linux/module.h>
39488 +#include <linux/moduleloader.h>
39489 #include <linux/kernel.h>
39490 #include <linux/errno.h>
39491 #include <linux/string.h>
39492 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
39493 static int vram_total __initdata; /* Set total amount of memory */
39494 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
39495 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
39496 -static void (*pmi_start)(void) __read_mostly;
39497 -static void (*pmi_pal) (void) __read_mostly;
39498 +static void (*pmi_start)(void) __read_only;
39499 +static void (*pmi_pal) (void) __read_only;
39500 static int depth __read_mostly;
39501 static int vga_compat __read_mostly;
39502 /* --------------------------------------------------------------------- */
39503 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
39504 unsigned int size_vmode;
39505 unsigned int size_remap;
39506 unsigned int size_total;
39507 + void *pmi_code = NULL;
39508
39509 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
39510 return -ENODEV;
39511 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
39512 size_remap = size_total;
39513 vesafb_fix.smem_len = size_remap;
39514
39515 -#ifndef __i386__
39516 - screen_info.vesapm_seg = 0;
39517 -#endif
39518 -
39519 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
39520 printk(KERN_WARNING
39521 "vesafb: cannot reserve video memory at 0x%lx\n",
39522 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
39523 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
39524 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
39525
39526 +#ifdef __i386__
39527 +
39528 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39529 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
39530 + if (!pmi_code)
39531 +#elif !defined(CONFIG_PAX_KERNEXEC)
39532 + if (0)
39533 +#endif
39534 +
39535 +#endif
39536 + screen_info.vesapm_seg = 0;
39537 +
39538 if (screen_info.vesapm_seg) {
39539 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
39540 - screen_info.vesapm_seg,screen_info.vesapm_off);
39541 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
39542 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
39543 }
39544
39545 if (screen_info.vesapm_seg < 0xc000)
39546 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
39547
39548 if (ypan || pmi_setpal) {
39549 unsigned short *pmi_base;
39550 +
39551 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
39552 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
39553 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
39554 +
39555 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39556 + pax_open_kernel();
39557 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
39558 +#else
39559 + pmi_code = pmi_base;
39560 +#endif
39561 +
39562 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
39563 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
39564 +
39565 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39566 + pmi_start = ktva_ktla(pmi_start);
39567 + pmi_pal = ktva_ktla(pmi_pal);
39568 + pax_close_kernel();
39569 +#endif
39570 +
39571 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
39572 if (pmi_base[3]) {
39573 printk(KERN_INFO "vesafb: pmi: ports = ");
39574 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
39575 info->node, info->fix.id);
39576 return 0;
39577 err:
39578 +
39579 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
39580 + module_free_exec(NULL, pmi_code);
39581 +#endif
39582 +
39583 if (info->screen_base)
39584 iounmap(info->screen_base);
39585 framebuffer_release(info);
39586 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
39587 index 88714ae..16c2e11 100644
39588 --- a/drivers/video/via/via_clock.h
39589 +++ b/drivers/video/via/via_clock.h
39590 @@ -56,7 +56,7 @@ struct via_clock {
39591
39592 void (*set_engine_pll_state)(u8 state);
39593 void (*set_engine_pll)(struct via_pll_config config);
39594 -};
39595 +} __no_const;
39596
39597
39598 static inline u32 get_pll_internal_frequency(u32 ref_freq,
39599 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
39600 index e56c934..fc22f4b 100644
39601 --- a/drivers/xen/xen-pciback/conf_space.h
39602 +++ b/drivers/xen/xen-pciback/conf_space.h
39603 @@ -44,15 +44,15 @@ struct config_field {
39604 struct {
39605 conf_dword_write write;
39606 conf_dword_read read;
39607 - } dw;
39608 + } __no_const dw;
39609 struct {
39610 conf_word_write write;
39611 conf_word_read read;
39612 - } w;
39613 + } __no_const w;
39614 struct {
39615 conf_byte_write write;
39616 conf_byte_read read;
39617 - } b;
39618 + } __no_const b;
39619 } u;
39620 struct list_head list;
39621 };
39622 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
39623 index 879ed88..bc03a01 100644
39624 --- a/fs/9p/vfs_inode.c
39625 +++ b/fs/9p/vfs_inode.c
39626 @@ -1286,7 +1286,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
39627 void
39628 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39629 {
39630 - char *s = nd_get_link(nd);
39631 + const char *s = nd_get_link(nd);
39632
39633 P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
39634 IS_ERR(s) ? "<error>" : s);
39635 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
39636 index 79e2ca7..5828ad1 100644
39637 --- a/fs/Kconfig.binfmt
39638 +++ b/fs/Kconfig.binfmt
39639 @@ -86,7 +86,7 @@ config HAVE_AOUT
39640
39641 config BINFMT_AOUT
39642 tristate "Kernel support for a.out and ECOFF binaries"
39643 - depends on HAVE_AOUT
39644 + depends on HAVE_AOUT && BROKEN
39645 ---help---
39646 A.out (Assembler.OUTput) is a set of formats for libraries and
39647 executables used in the earliest versions of UNIX. Linux used
39648 diff --git a/fs/aio.c b/fs/aio.c
39649 index 969beb0..09fab51 100644
39650 --- a/fs/aio.c
39651 +++ b/fs/aio.c
39652 @@ -119,7 +119,7 @@ static int aio_setup_ring(struct kioctx *ctx)
39653 size += sizeof(struct io_event) * nr_events;
39654 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
39655
39656 - if (nr_pages < 0)
39657 + if (nr_pages <= 0)
39658 return -EINVAL;
39659
39660 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
39661 @@ -1461,22 +1461,27 @@ static ssize_t aio_fsync(struct kiocb *iocb)
39662 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
39663 {
39664 ssize_t ret;
39665 + struct iovec iovstack;
39666
39667 #ifdef CONFIG_COMPAT
39668 if (compat)
39669 ret = compat_rw_copy_check_uvector(type,
39670 (struct compat_iovec __user *)kiocb->ki_buf,
39671 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
39672 + kiocb->ki_nbytes, 1, &iovstack,
39673 &kiocb->ki_iovec, 1);
39674 else
39675 #endif
39676 ret = rw_copy_check_uvector(type,
39677 (struct iovec __user *)kiocb->ki_buf,
39678 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
39679 + kiocb->ki_nbytes, 1, &iovstack,
39680 &kiocb->ki_iovec, 1);
39681 if (ret < 0)
39682 goto out;
39683
39684 + if (kiocb->ki_iovec == &iovstack) {
39685 + kiocb->ki_inline_vec = iovstack;
39686 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
39687 + }
39688 kiocb->ki_nr_segs = kiocb->ki_nbytes;
39689 kiocb->ki_cur_seg = 0;
39690 /* ki_nbytes/left now reflect bytes instead of segs */
39691 diff --git a/fs/attr.c b/fs/attr.c
39692 index 7ee7ba4..0c61a60 100644
39693 --- a/fs/attr.c
39694 +++ b/fs/attr.c
39695 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
39696 unsigned long limit;
39697
39698 limit = rlimit(RLIMIT_FSIZE);
39699 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
39700 if (limit != RLIM_INFINITY && offset > limit)
39701 goto out_sig;
39702 if (offset > inode->i_sb->s_maxbytes)
39703 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
39704 index e1fbdee..cd5ea56 100644
39705 --- a/fs/autofs4/waitq.c
39706 +++ b/fs/autofs4/waitq.c
39707 @@ -60,7 +60,7 @@ static int autofs4_write(struct file *file, const void *addr, int bytes)
39708 {
39709 unsigned long sigpipe, flags;
39710 mm_segment_t fs;
39711 - const char *data = (const char *)addr;
39712 + const char __user *data = (const char __force_user *)addr;
39713 ssize_t wr = 0;
39714
39715 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
39716 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
39717 index 8342ca6..82fd192 100644
39718 --- a/fs/befs/linuxvfs.c
39719 +++ b/fs/befs/linuxvfs.c
39720 @@ -503,7 +503,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
39721 {
39722 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
39723 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
39724 - char *link = nd_get_link(nd);
39725 + const char *link = nd_get_link(nd);
39726 if (!IS_ERR(link))
39727 kfree(link);
39728 }
39729 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
39730 index a6395bd..a5b24c4 100644
39731 --- a/fs/binfmt_aout.c
39732 +++ b/fs/binfmt_aout.c
39733 @@ -16,6 +16,7 @@
39734 #include <linux/string.h>
39735 #include <linux/fs.h>
39736 #include <linux/file.h>
39737 +#include <linux/security.h>
39738 #include <linux/stat.h>
39739 #include <linux/fcntl.h>
39740 #include <linux/ptrace.h>
39741 @@ -86,6 +87,8 @@ static int aout_core_dump(struct coredump_params *cprm)
39742 #endif
39743 # define START_STACK(u) ((void __user *)u.start_stack)
39744
39745 + memset(&dump, 0, sizeof(dump));
39746 +
39747 fs = get_fs();
39748 set_fs(KERNEL_DS);
39749 has_dumped = 1;
39750 @@ -97,10 +100,12 @@ static int aout_core_dump(struct coredump_params *cprm)
39751
39752 /* If the size of the dump file exceeds the rlimit, then see what would happen
39753 if we wrote the stack, but not the data area. */
39754 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
39755 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
39756 dump.u_dsize = 0;
39757
39758 /* Make sure we have enough room to write the stack and data areas. */
39759 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
39760 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
39761 dump.u_ssize = 0;
39762
39763 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39764 rlim = rlimit(RLIMIT_DATA);
39765 if (rlim >= RLIM_INFINITY)
39766 rlim = ~0;
39767 +
39768 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
39769 if (ex.a_data + ex.a_bss > rlim)
39770 return -ENOMEM;
39771
39772 @@ -262,6 +269,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39773 install_exec_creds(bprm);
39774 current->flags &= ~PF_FORKNOEXEC;
39775
39776 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
39777 + current->mm->pax_flags = 0UL;
39778 +#endif
39779 +
39780 +#ifdef CONFIG_PAX_PAGEEXEC
39781 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
39782 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
39783 +
39784 +#ifdef CONFIG_PAX_EMUTRAMP
39785 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
39786 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
39787 +#endif
39788 +
39789 +#ifdef CONFIG_PAX_MPROTECT
39790 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
39791 + current->mm->pax_flags |= MF_PAX_MPROTECT;
39792 +#endif
39793 +
39794 + }
39795 +#endif
39796 +
39797 if (N_MAGIC(ex) == OMAGIC) {
39798 unsigned long text_addr, map_size;
39799 loff_t pos;
39800 @@ -334,7 +362,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
39801
39802 down_write(&current->mm->mmap_sem);
39803 error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
39804 - PROT_READ | PROT_WRITE | PROT_EXEC,
39805 + PROT_READ | PROT_WRITE,
39806 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
39807 fd_offset + ex.a_text);
39808 up_write(&current->mm->mmap_sem);
39809 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
39810 index 21ac5ee..31d14e9 100644
39811 --- a/fs/binfmt_elf.c
39812 +++ b/fs/binfmt_elf.c
39813 @@ -32,6 +32,7 @@
39814 #include <linux/elf.h>
39815 #include <linux/utsname.h>
39816 #include <linux/coredump.h>
39817 +#include <linux/xattr.h>
39818 #include <asm/uaccess.h>
39819 #include <asm/param.h>
39820 #include <asm/page.h>
39821 @@ -51,6 +52,10 @@ static int elf_core_dump(struct coredump_params *cprm);
39822 #define elf_core_dump NULL
39823 #endif
39824
39825 +#ifdef CONFIG_PAX_MPROTECT
39826 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
39827 +#endif
39828 +
39829 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
39830 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
39831 #else
39832 @@ -70,6 +75,11 @@ static struct linux_binfmt elf_format = {
39833 .load_binary = load_elf_binary,
39834 .load_shlib = load_elf_library,
39835 .core_dump = elf_core_dump,
39836 +
39837 +#ifdef CONFIG_PAX_MPROTECT
39838 + .handle_mprotect= elf_handle_mprotect,
39839 +#endif
39840 +
39841 .min_coredump = ELF_EXEC_PAGESIZE,
39842 };
39843
39844 @@ -77,6 +87,8 @@ static struct linux_binfmt elf_format = {
39845
39846 static int set_brk(unsigned long start, unsigned long end)
39847 {
39848 + unsigned long e = end;
39849 +
39850 start = ELF_PAGEALIGN(start);
39851 end = ELF_PAGEALIGN(end);
39852 if (end > start) {
39853 @@ -87,7 +99,7 @@ static int set_brk(unsigned long start, unsigned long end)
39854 if (BAD_ADDR(addr))
39855 return addr;
39856 }
39857 - current->mm->start_brk = current->mm->brk = end;
39858 + current->mm->start_brk = current->mm->brk = e;
39859 return 0;
39860 }
39861
39862 @@ -148,12 +160,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39863 elf_addr_t __user *u_rand_bytes;
39864 const char *k_platform = ELF_PLATFORM;
39865 const char *k_base_platform = ELF_BASE_PLATFORM;
39866 - unsigned char k_rand_bytes[16];
39867 + u32 k_rand_bytes[4];
39868 int items;
39869 elf_addr_t *elf_info;
39870 int ei_index = 0;
39871 const struct cred *cred = current_cred();
39872 struct vm_area_struct *vma;
39873 + unsigned long saved_auxv[AT_VECTOR_SIZE];
39874
39875 /*
39876 * In some cases (e.g. Hyper-Threading), we want to avoid L1
39877 @@ -195,8 +208,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39878 * Generate 16 random bytes for userspace PRNG seeding.
39879 */
39880 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
39881 - u_rand_bytes = (elf_addr_t __user *)
39882 - STACK_ALLOC(p, sizeof(k_rand_bytes));
39883 + srandom32(k_rand_bytes[0] ^ random32());
39884 + srandom32(k_rand_bytes[1] ^ random32());
39885 + srandom32(k_rand_bytes[2] ^ random32());
39886 + srandom32(k_rand_bytes[3] ^ random32());
39887 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
39888 + u_rand_bytes = (elf_addr_t __user *) p;
39889 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
39890 return -EFAULT;
39891
39892 @@ -308,9 +325,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
39893 return -EFAULT;
39894 current->mm->env_end = p;
39895
39896 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
39897 +
39898 /* Put the elf_info on the stack in the right place. */
39899 sp = (elf_addr_t __user *)envp + 1;
39900 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
39901 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
39902 return -EFAULT;
39903 return 0;
39904 }
39905 @@ -381,10 +400,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39906 {
39907 struct elf_phdr *elf_phdata;
39908 struct elf_phdr *eppnt;
39909 - unsigned long load_addr = 0;
39910 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
39911 int load_addr_set = 0;
39912 unsigned long last_bss = 0, elf_bss = 0;
39913 - unsigned long error = ~0UL;
39914 + unsigned long error = -EINVAL;
39915 unsigned long total_size;
39916 int retval, i, size;
39917
39918 @@ -430,6 +449,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39919 goto out_close;
39920 }
39921
39922 +#ifdef CONFIG_PAX_SEGMEXEC
39923 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
39924 + pax_task_size = SEGMEXEC_TASK_SIZE;
39925 +#endif
39926 +
39927 eppnt = elf_phdata;
39928 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
39929 if (eppnt->p_type == PT_LOAD) {
39930 @@ -473,8 +497,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
39931 k = load_addr + eppnt->p_vaddr;
39932 if (BAD_ADDR(k) ||
39933 eppnt->p_filesz > eppnt->p_memsz ||
39934 - eppnt->p_memsz > TASK_SIZE ||
39935 - TASK_SIZE - eppnt->p_memsz < k) {
39936 + eppnt->p_memsz > pax_task_size ||
39937 + pax_task_size - eppnt->p_memsz < k) {
39938 error = -ENOMEM;
39939 goto out_close;
39940 }
39941 @@ -528,6 +552,351 @@ out:
39942 return error;
39943 }
39944
39945 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
39946 +{
39947 + unsigned long pax_flags = 0UL;
39948 +
39949 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
39950 +
39951 +#ifdef CONFIG_PAX_PAGEEXEC
39952 + if (elf_phdata->p_flags & PF_PAGEEXEC)
39953 + pax_flags |= MF_PAX_PAGEEXEC;
39954 +#endif
39955 +
39956 +#ifdef CONFIG_PAX_SEGMEXEC
39957 + if (elf_phdata->p_flags & PF_SEGMEXEC)
39958 + pax_flags |= MF_PAX_SEGMEXEC;
39959 +#endif
39960 +
39961 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
39962 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
39963 + if ((__supported_pte_mask & _PAGE_NX))
39964 + pax_flags &= ~MF_PAX_SEGMEXEC;
39965 + else
39966 + pax_flags &= ~MF_PAX_PAGEEXEC;
39967 + }
39968 +#endif
39969 +
39970 +#ifdef CONFIG_PAX_EMUTRAMP
39971 + if (elf_phdata->p_flags & PF_EMUTRAMP)
39972 + pax_flags |= MF_PAX_EMUTRAMP;
39973 +#endif
39974 +
39975 +#ifdef CONFIG_PAX_MPROTECT
39976 + if (elf_phdata->p_flags & PF_MPROTECT)
39977 + pax_flags |= MF_PAX_MPROTECT;
39978 +#endif
39979 +
39980 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
39981 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
39982 + pax_flags |= MF_PAX_RANDMMAP;
39983 +#endif
39984 +
39985 +#endif
39986 +
39987 + return pax_flags;
39988 +}
39989 +
39990 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
39991 +{
39992 + unsigned long pax_flags = 0UL;
39993 +
39994 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
39995 +
39996 +#ifdef CONFIG_PAX_PAGEEXEC
39997 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
39998 + pax_flags |= MF_PAX_PAGEEXEC;
39999 +#endif
40000 +
40001 +#ifdef CONFIG_PAX_SEGMEXEC
40002 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
40003 + pax_flags |= MF_PAX_SEGMEXEC;
40004 +#endif
40005 +
40006 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40007 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40008 + if ((__supported_pte_mask & _PAGE_NX))
40009 + pax_flags &= ~MF_PAX_SEGMEXEC;
40010 + else
40011 + pax_flags &= ~MF_PAX_PAGEEXEC;
40012 + }
40013 +#endif
40014 +
40015 +#ifdef CONFIG_PAX_EMUTRAMP
40016 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
40017 + pax_flags |= MF_PAX_EMUTRAMP;
40018 +#endif
40019 +
40020 +#ifdef CONFIG_PAX_MPROTECT
40021 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
40022 + pax_flags |= MF_PAX_MPROTECT;
40023 +#endif
40024 +
40025 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40026 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
40027 + pax_flags |= MF_PAX_RANDMMAP;
40028 +#endif
40029 +
40030 +#endif
40031 +
40032 + return pax_flags;
40033 +}
40034 +
40035 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
40036 +{
40037 + unsigned long pax_flags = 0UL;
40038 +
40039 +#ifdef CONFIG_PAX_EI_PAX
40040 +
40041 +#ifdef CONFIG_PAX_PAGEEXEC
40042 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
40043 + pax_flags |= MF_PAX_PAGEEXEC;
40044 +#endif
40045 +
40046 +#ifdef CONFIG_PAX_SEGMEXEC
40047 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
40048 + pax_flags |= MF_PAX_SEGMEXEC;
40049 +#endif
40050 +
40051 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40052 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40053 + if ((__supported_pte_mask & _PAGE_NX))
40054 + pax_flags &= ~MF_PAX_SEGMEXEC;
40055 + else
40056 + pax_flags &= ~MF_PAX_PAGEEXEC;
40057 + }
40058 +#endif
40059 +
40060 +#ifdef CONFIG_PAX_EMUTRAMP
40061 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
40062 + pax_flags |= MF_PAX_EMUTRAMP;
40063 +#endif
40064 +
40065 +#ifdef CONFIG_PAX_MPROTECT
40066 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
40067 + pax_flags |= MF_PAX_MPROTECT;
40068 +#endif
40069 +
40070 +#ifdef CONFIG_PAX_ASLR
40071 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
40072 + pax_flags |= MF_PAX_RANDMMAP;
40073 +#endif
40074 +
40075 +#else
40076 +
40077 +#ifdef CONFIG_PAX_PAGEEXEC
40078 + pax_flags |= MF_PAX_PAGEEXEC;
40079 +#endif
40080 +
40081 +#ifdef CONFIG_PAX_MPROTECT
40082 + pax_flags |= MF_PAX_MPROTECT;
40083 +#endif
40084 +
40085 +#ifdef CONFIG_PAX_RANDMMAP
40086 + pax_flags |= MF_PAX_RANDMMAP;
40087 +#endif
40088 +
40089 +#ifdef CONFIG_PAX_SEGMEXEC
40090 + if (!(__supported_pte_mask & _PAGE_NX)) {
40091 + pax_flags &= ~MF_PAX_PAGEEXEC;
40092 + pax_flags |= MF_PAX_SEGMEXEC;
40093 + }
40094 +#endif
40095 +
40096 +#endif
40097 +
40098 + return pax_flags;
40099 +}
40100 +
40101 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
40102 +{
40103 +
40104 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
40105 + unsigned long i;
40106 +
40107 + for (i = 0UL; i < elf_ex->e_phnum; i++)
40108 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
40109 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
40110 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
40111 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
40112 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
40113 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
40114 + return ~0UL;
40115 +
40116 +#ifdef CONFIG_PAX_SOFTMODE
40117 + if (pax_softmode)
40118 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
40119 + else
40120 +#endif
40121 +
40122 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
40123 + break;
40124 + }
40125 +#endif
40126 +
40127 + return ~0UL;
40128 +}
40129 +
40130 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
40131 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
40132 +{
40133 + unsigned long pax_flags = 0UL;
40134 +
40135 +#ifdef CONFIG_PAX_PAGEEXEC
40136 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
40137 + pax_flags |= MF_PAX_PAGEEXEC;
40138 +#endif
40139 +
40140 +#ifdef CONFIG_PAX_SEGMEXEC
40141 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
40142 + pax_flags |= MF_PAX_SEGMEXEC;
40143 +#endif
40144 +
40145 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40146 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40147 + if ((__supported_pte_mask & _PAGE_NX))
40148 + pax_flags &= ~MF_PAX_SEGMEXEC;
40149 + else
40150 + pax_flags &= ~MF_PAX_PAGEEXEC;
40151 + }
40152 +#endif
40153 +
40154 +#ifdef CONFIG_PAX_EMUTRAMP
40155 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
40156 + pax_flags |= MF_PAX_EMUTRAMP;
40157 +#endif
40158 +
40159 +#ifdef CONFIG_PAX_MPROTECT
40160 + if (pax_flags_softmode & MF_PAX_MPROTECT)
40161 + pax_flags |= MF_PAX_MPROTECT;
40162 +#endif
40163 +
40164 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40165 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
40166 + pax_flags |= MF_PAX_RANDMMAP;
40167 +#endif
40168 +
40169 + return pax_flags;
40170 +}
40171 +
40172 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
40173 +{
40174 + unsigned long pax_flags = 0UL;
40175 +
40176 +#ifdef CONFIG_PAX_PAGEEXEC
40177 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
40178 + pax_flags |= MF_PAX_PAGEEXEC;
40179 +#endif
40180 +
40181 +#ifdef CONFIG_PAX_SEGMEXEC
40182 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
40183 + pax_flags |= MF_PAX_SEGMEXEC;
40184 +#endif
40185 +
40186 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
40187 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40188 + if ((__supported_pte_mask & _PAGE_NX))
40189 + pax_flags &= ~MF_PAX_SEGMEXEC;
40190 + else
40191 + pax_flags &= ~MF_PAX_PAGEEXEC;
40192 + }
40193 +#endif
40194 +
40195 +#ifdef CONFIG_PAX_EMUTRAMP
40196 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
40197 + pax_flags |= MF_PAX_EMUTRAMP;
40198 +#endif
40199 +
40200 +#ifdef CONFIG_PAX_MPROTECT
40201 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
40202 + pax_flags |= MF_PAX_MPROTECT;
40203 +#endif
40204 +
40205 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
40206 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
40207 + pax_flags |= MF_PAX_RANDMMAP;
40208 +#endif
40209 +
40210 + return pax_flags;
40211 +}
40212 +#endif
40213 +
40214 +static unsigned long pax_parse_xattr_pax(struct file * const file)
40215 +{
40216 +
40217 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
40218 + ssize_t xattr_size, i;
40219 + unsigned char xattr_value[5];
40220 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
40221 +
40222 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
40223 + if (xattr_size <= 0)
40224 + return ~0UL;
40225 +
40226 + for (i = 0; i < xattr_size; i++)
40227 + switch (xattr_value[i]) {
40228 + default:
40229 + return ~0UL;
40230 +
40231 +#define parse_flag(option1, option2, flag) \
40232 + case option1: \
40233 + pax_flags_hardmode |= MF_PAX_##flag; \
40234 + break; \
40235 + case option2: \
40236 + pax_flags_softmode |= MF_PAX_##flag; \
40237 + break;
40238 +
40239 + parse_flag('p', 'P', PAGEEXEC);
40240 + parse_flag('e', 'E', EMUTRAMP);
40241 + parse_flag('m', 'M', MPROTECT);
40242 + parse_flag('r', 'R', RANDMMAP);
40243 + parse_flag('s', 'S', SEGMEXEC);
40244 +
40245 +#undef parse_flag
40246 + }
40247 +
40248 + if (pax_flags_hardmode & pax_flags_softmode)
40249 + return ~0UL;
40250 +
40251 +#ifdef CONFIG_PAX_SOFTMODE
40252 + if (pax_softmode)
40253 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
40254 + else
40255 +#endif
40256 +
40257 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
40258 +#else
40259 + return ~0UL;
40260 +#endif
40261 +
40262 +}
40263 +
40264 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
40265 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
40266 +{
40267 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
40268 +
40269 + pax_flags = pax_parse_ei_pax(elf_ex);
40270 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
40271 + xattr_pax_flags = pax_parse_xattr_pax(file);
40272 +
40273 + if (pt_pax_flags == ~0UL)
40274 + pt_pax_flags = xattr_pax_flags;
40275 + else if (xattr_pax_flags == ~0UL)
40276 + xattr_pax_flags = pt_pax_flags;
40277 + if (pt_pax_flags != xattr_pax_flags)
40278 + return -EINVAL;
40279 + if (pt_pax_flags != ~0UL)
40280 + pax_flags = pt_pax_flags;
40281 +
40282 + if (0 > pax_check_flags(&pax_flags))
40283 + return -EINVAL;
40284 +
40285 + current->mm->pax_flags = pax_flags;
40286 + return 0;
40287 +}
40288 +#endif
40289 +
40290 /*
40291 * These are the functions used to load ELF style executables and shared
40292 * libraries. There is no binary dependent code anywhere else.
40293 @@ -544,6 +913,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
40294 {
40295 unsigned int random_variable = 0;
40296
40297 +#ifdef CONFIG_PAX_RANDUSTACK
40298 + if (randomize_va_space)
40299 + return stack_top - current->mm->delta_stack;
40300 +#endif
40301 +
40302 if ((current->flags & PF_RANDOMIZE) &&
40303 !(current->personality & ADDR_NO_RANDOMIZE)) {
40304 random_variable = get_random_int() & STACK_RND_MASK;
40305 @@ -562,7 +936,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40306 unsigned long load_addr = 0, load_bias = 0;
40307 int load_addr_set = 0;
40308 char * elf_interpreter = NULL;
40309 - unsigned long error;
40310 + unsigned long error = 0;
40311 struct elf_phdr *elf_ppnt, *elf_phdata;
40312 unsigned long elf_bss, elf_brk;
40313 int retval, i;
40314 @@ -572,11 +946,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40315 unsigned long start_code, end_code, start_data, end_data;
40316 unsigned long reloc_func_desc __maybe_unused = 0;
40317 int executable_stack = EXSTACK_DEFAULT;
40318 - unsigned long def_flags = 0;
40319 struct {
40320 struct elfhdr elf_ex;
40321 struct elfhdr interp_elf_ex;
40322 } *loc;
40323 + unsigned long pax_task_size = TASK_SIZE;
40324
40325 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
40326 if (!loc) {
40327 @@ -713,11 +1087,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40328
40329 /* OK, This is the point of no return */
40330 current->flags &= ~PF_FORKNOEXEC;
40331 - current->mm->def_flags = def_flags;
40332 +
40333 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
40334 + current->mm->pax_flags = 0UL;
40335 +#endif
40336 +
40337 +#ifdef CONFIG_PAX_DLRESOLVE
40338 + current->mm->call_dl_resolve = 0UL;
40339 +#endif
40340 +
40341 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
40342 + current->mm->call_syscall = 0UL;
40343 +#endif
40344 +
40345 +#ifdef CONFIG_PAX_ASLR
40346 + current->mm->delta_mmap = 0UL;
40347 + current->mm->delta_stack = 0UL;
40348 +#endif
40349 +
40350 + current->mm->def_flags = 0;
40351 +
40352 +#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_XATTR_PAX_FLAGS)
40353 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
40354 + send_sig(SIGKILL, current, 0);
40355 + goto out_free_dentry;
40356 + }
40357 +#endif
40358 +
40359 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
40360 + pax_set_initial_flags(bprm);
40361 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
40362 + if (pax_set_initial_flags_func)
40363 + (pax_set_initial_flags_func)(bprm);
40364 +#endif
40365 +
40366 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
40367 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
40368 + current->mm->context.user_cs_limit = PAGE_SIZE;
40369 + current->mm->def_flags |= VM_PAGEEXEC;
40370 + }
40371 +#endif
40372 +
40373 +#ifdef CONFIG_PAX_SEGMEXEC
40374 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
40375 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
40376 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
40377 + pax_task_size = SEGMEXEC_TASK_SIZE;
40378 + current->mm->def_flags |= VM_NOHUGEPAGE;
40379 + }
40380 +#endif
40381 +
40382 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
40383 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40384 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
40385 + put_cpu();
40386 + }
40387 +#endif
40388
40389 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
40390 may depend on the personality. */
40391 SET_PERSONALITY(loc->elf_ex);
40392 +
40393 +#ifdef CONFIG_PAX_ASLR
40394 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
40395 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
40396 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
40397 + }
40398 +#endif
40399 +
40400 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
40401 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
40402 + executable_stack = EXSTACK_DISABLE_X;
40403 + current->personality &= ~READ_IMPLIES_EXEC;
40404 + } else
40405 +#endif
40406 +
40407 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
40408 current->personality |= READ_IMPLIES_EXEC;
40409
40410 @@ -808,6 +1252,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40411 #else
40412 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
40413 #endif
40414 +
40415 +#ifdef CONFIG_PAX_RANDMMAP
40416 + /* PaX: randomize base address at the default exe base if requested */
40417 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
40418 +#ifdef CONFIG_SPARC64
40419 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
40420 +#else
40421 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
40422 +#endif
40423 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
40424 + elf_flags |= MAP_FIXED;
40425 + }
40426 +#endif
40427 +
40428 }
40429
40430 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
40431 @@ -840,9 +1298,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40432 * allowed task size. Note that p_filesz must always be
40433 * <= p_memsz so it is only necessary to check p_memsz.
40434 */
40435 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40436 - elf_ppnt->p_memsz > TASK_SIZE ||
40437 - TASK_SIZE - elf_ppnt->p_memsz < k) {
40438 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
40439 + elf_ppnt->p_memsz > pax_task_size ||
40440 + pax_task_size - elf_ppnt->p_memsz < k) {
40441 /* set_brk can never work. Avoid overflows. */
40442 send_sig(SIGKILL, current, 0);
40443 retval = -EINVAL;
40444 @@ -870,6 +1328,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40445 start_data += load_bias;
40446 end_data += load_bias;
40447
40448 +#ifdef CONFIG_PAX_RANDMMAP
40449 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
40450 + elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
40451 +#endif
40452 +
40453 /* Calling set_brk effectively mmaps the pages that we need
40454 * for the bss and break sections. We must do this before
40455 * mapping in the interpreter, to make sure it doesn't wind
40456 @@ -881,9 +1344,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
40457 goto out_free_dentry;
40458 }
40459 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
40460 - send_sig(SIGSEGV, current, 0);
40461 - retval = -EFAULT; /* Nobody gets to see this, but.. */
40462 - goto out_free_dentry;
40463 + /*
40464 + * This bss-zeroing can fail if the ELF
40465 + * file specifies odd protections. So
40466 + * we don't check the return value
40467 + */
40468 }
40469
40470 if (elf_interpreter) {
40471 @@ -1098,7 +1563,7 @@ out:
40472 * Decide what to dump of a segment, part, all or none.
40473 */
40474 static unsigned long vma_dump_size(struct vm_area_struct *vma,
40475 - unsigned long mm_flags)
40476 + unsigned long mm_flags, long signr)
40477 {
40478 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
40479
40480 @@ -1132,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
40481 if (vma->vm_file == NULL)
40482 return 0;
40483
40484 - if (FILTER(MAPPED_PRIVATE))
40485 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
40486 goto whole;
40487
40488 /*
40489 @@ -1354,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
40490 {
40491 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
40492 int i = 0;
40493 - do
40494 + do {
40495 i += 2;
40496 - while (auxv[i - 2] != AT_NULL);
40497 + } while (auxv[i - 2] != AT_NULL);
40498 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
40499 }
40500
40501 @@ -1862,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
40502 }
40503
40504 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
40505 - unsigned long mm_flags)
40506 + struct coredump_params *cprm)
40507 {
40508 struct vm_area_struct *vma;
40509 size_t size = 0;
40510
40511 for (vma = first_vma(current, gate_vma); vma != NULL;
40512 vma = next_vma(vma, gate_vma))
40513 - size += vma_dump_size(vma, mm_flags);
40514 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40515 return size;
40516 }
40517
40518 @@ -1963,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40519
40520 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
40521
40522 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
40523 + offset += elf_core_vma_data_size(gate_vma, cprm);
40524 offset += elf_core_extra_data_size();
40525 e_shoff = offset;
40526
40527 @@ -1977,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
40528 offset = dataoff;
40529
40530 size += sizeof(*elf);
40531 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40532 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
40533 goto end_coredump;
40534
40535 size += sizeof(*phdr4note);
40536 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40537 if (size > cprm->limit
40538 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
40539 goto end_coredump;
40540 @@ -1994,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40541 phdr.p_offset = offset;
40542 phdr.p_vaddr = vma->vm_start;
40543 phdr.p_paddr = 0;
40544 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
40545 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40546 phdr.p_memsz = vma->vm_end - vma->vm_start;
40547 offset += phdr.p_filesz;
40548 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
40549 @@ -2005,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40550 phdr.p_align = ELF_EXEC_PAGESIZE;
40551
40552 size += sizeof(phdr);
40553 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40554 if (size > cprm->limit
40555 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
40556 goto end_coredump;
40557 @@ -2029,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40558 unsigned long addr;
40559 unsigned long end;
40560
40561 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
40562 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
40563
40564 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
40565 struct page *page;
40566 @@ -2038,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40567 page = get_dump_page(addr);
40568 if (page) {
40569 void *kaddr = kmap(page);
40570 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
40571 stop = ((size += PAGE_SIZE) > cprm->limit) ||
40572 !dump_write(cprm->file, kaddr,
40573 PAGE_SIZE);
40574 @@ -2055,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
40575
40576 if (e_phnum == PN_XNUM) {
40577 size += sizeof(*shdr4extnum);
40578 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
40579 if (size > cprm->limit
40580 || !dump_write(cprm->file, shdr4extnum,
40581 sizeof(*shdr4extnum)))
40582 @@ -2075,6 +2545,97 @@ out:
40583
40584 #endif /* CONFIG_ELF_CORE */
40585
40586 +#ifdef CONFIG_PAX_MPROTECT
40587 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
40588 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
40589 + * we'll remove VM_MAYWRITE for good on RELRO segments.
40590 + *
40591 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
40592 + * basis because we want to allow the common case and not the special ones.
40593 + */
40594 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
40595 +{
40596 + struct elfhdr elf_h;
40597 + struct elf_phdr elf_p;
40598 + unsigned long i;
40599 + unsigned long oldflags;
40600 + bool is_textrel_rw, is_textrel_rx, is_relro;
40601 +
40602 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
40603 + return;
40604 +
40605 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
40606 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
40607 +
40608 +#ifdef CONFIG_PAX_ELFRELOCS
40609 + /* possible TEXTREL */
40610 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
40611 + 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);
40612 +#else
40613 + is_textrel_rw = false;
40614 + is_textrel_rx = false;
40615 +#endif
40616 +
40617 + /* possible RELRO */
40618 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
40619 +
40620 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
40621 + return;
40622 +
40623 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
40624 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
40625 +
40626 +#ifdef CONFIG_PAX_ETEXECRELOCS
40627 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40628 +#else
40629 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
40630 +#endif
40631 +
40632 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
40633 + !elf_check_arch(&elf_h) ||
40634 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
40635 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
40636 + return;
40637 +
40638 + for (i = 0UL; i < elf_h.e_phnum; i++) {
40639 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
40640 + return;
40641 + switch (elf_p.p_type) {
40642 + case PT_DYNAMIC:
40643 + if (!is_textrel_rw && !is_textrel_rx)
40644 + continue;
40645 + i = 0UL;
40646 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
40647 + elf_dyn dyn;
40648 +
40649 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
40650 + return;
40651 + if (dyn.d_tag == DT_NULL)
40652 + return;
40653 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
40654 + gr_log_textrel(vma);
40655 + if (is_textrel_rw)
40656 + vma->vm_flags |= VM_MAYWRITE;
40657 + else
40658 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
40659 + vma->vm_flags &= ~VM_MAYWRITE;
40660 + return;
40661 + }
40662 + i++;
40663 + }
40664 + return;
40665 +
40666 + case PT_GNU_RELRO:
40667 + if (!is_relro)
40668 + continue;
40669 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
40670 + vma->vm_flags &= ~VM_MAYWRITE;
40671 + return;
40672 + }
40673 + }
40674 +}
40675 +#endif
40676 +
40677 static int __init init_elf_binfmt(void)
40678 {
40679 return register_binfmt(&elf_format);
40680 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
40681 index 1bffbe0..c8c283e 100644
40682 --- a/fs/binfmt_flat.c
40683 +++ b/fs/binfmt_flat.c
40684 @@ -567,7 +567,9 @@ static int load_flat_file(struct linux_binprm * bprm,
40685 realdatastart = (unsigned long) -ENOMEM;
40686 printk("Unable to allocate RAM for process data, errno %d\n",
40687 (int)-realdatastart);
40688 + down_write(&current->mm->mmap_sem);
40689 do_munmap(current->mm, textpos, text_len);
40690 + up_write(&current->mm->mmap_sem);
40691 ret = realdatastart;
40692 goto err;
40693 }
40694 @@ -591,8 +593,10 @@ static int load_flat_file(struct linux_binprm * bprm,
40695 }
40696 if (IS_ERR_VALUE(result)) {
40697 printk("Unable to read data+bss, errno %d\n", (int)-result);
40698 + down_write(&current->mm->mmap_sem);
40699 do_munmap(current->mm, textpos, text_len);
40700 do_munmap(current->mm, realdatastart, len);
40701 + up_write(&current->mm->mmap_sem);
40702 ret = result;
40703 goto err;
40704 }
40705 @@ -661,8 +665,10 @@ static int load_flat_file(struct linux_binprm * bprm,
40706 }
40707 if (IS_ERR_VALUE(result)) {
40708 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
40709 + down_write(&current->mm->mmap_sem);
40710 do_munmap(current->mm, textpos, text_len + data_len + extra +
40711 MAX_SHARED_LIBS * sizeof(unsigned long));
40712 + up_write(&current->mm->mmap_sem);
40713 ret = result;
40714 goto err;
40715 }
40716 diff --git a/fs/bio.c b/fs/bio.c
40717 index b1fe82c..84da0a9 100644
40718 --- a/fs/bio.c
40719 +++ b/fs/bio.c
40720 @@ -1233,7 +1233,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
40721 const int read = bio_data_dir(bio) == READ;
40722 struct bio_map_data *bmd = bio->bi_private;
40723 int i;
40724 - char *p = bmd->sgvecs[0].iov_base;
40725 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
40726
40727 __bio_for_each_segment(bvec, bio, i, 0) {
40728 char *addr = page_address(bvec->bv_page);
40729 diff --git a/fs/block_dev.c b/fs/block_dev.c
40730 index b07f1da..9efcb92 100644
40731 --- a/fs/block_dev.c
40732 +++ b/fs/block_dev.c
40733 @@ -681,7 +681,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
40734 else if (bdev->bd_contains == bdev)
40735 return true; /* is a whole device which isn't held */
40736
40737 - else if (whole->bd_holder == bd_may_claim)
40738 + else if (whole->bd_holder == (void *)bd_may_claim)
40739 return true; /* is a partition of a device that is being partitioned */
40740 else if (whole->bd_holder != NULL)
40741 return false; /* is a partition of a held device */
40742 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
40743 index dede441..f2a2507 100644
40744 --- a/fs/btrfs/ctree.c
40745 +++ b/fs/btrfs/ctree.c
40746 @@ -488,9 +488,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
40747 free_extent_buffer(buf);
40748 add_root_to_dirty_list(root);
40749 } else {
40750 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
40751 - parent_start = parent->start;
40752 - else
40753 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
40754 + if (parent)
40755 + parent_start = parent->start;
40756 + else
40757 + parent_start = 0;
40758 + } else
40759 parent_start = 0;
40760
40761 WARN_ON(trans->transid != btrfs_header_generation(parent));
40762 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
40763 index fd1a06d..6e9033d 100644
40764 --- a/fs/btrfs/inode.c
40765 +++ b/fs/btrfs/inode.c
40766 @@ -6895,7 +6895,7 @@ fail:
40767 return -ENOMEM;
40768 }
40769
40770 -static int btrfs_getattr(struct vfsmount *mnt,
40771 +int btrfs_getattr(struct vfsmount *mnt,
40772 struct dentry *dentry, struct kstat *stat)
40773 {
40774 struct inode *inode = dentry->d_inode;
40775 @@ -6909,6 +6909,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
40776 return 0;
40777 }
40778
40779 +EXPORT_SYMBOL(btrfs_getattr);
40780 +
40781 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
40782 +{
40783 + return BTRFS_I(inode)->root->anon_dev;
40784 +}
40785 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
40786 +
40787 /*
40788 * If a file is moved, it will inherit the cow and compression flags of the new
40789 * directory.
40790 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
40791 index c04f02c..f5c9e2e 100644
40792 --- a/fs/btrfs/ioctl.c
40793 +++ b/fs/btrfs/ioctl.c
40794 @@ -2733,9 +2733,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
40795 for (i = 0; i < num_types; i++) {
40796 struct btrfs_space_info *tmp;
40797
40798 + /* Don't copy in more than we allocated */
40799 if (!slot_count)
40800 break;
40801
40802 + slot_count--;
40803 +
40804 info = NULL;
40805 rcu_read_lock();
40806 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
40807 @@ -2757,15 +2760,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
40808 memcpy(dest, &space, sizeof(space));
40809 dest++;
40810 space_args.total_spaces++;
40811 - slot_count--;
40812 }
40813 - if (!slot_count)
40814 - break;
40815 }
40816 up_read(&info->groups_sem);
40817 }
40818
40819 - user_dest = (struct btrfs_ioctl_space_info *)
40820 + user_dest = (struct btrfs_ioctl_space_info __user *)
40821 (arg + sizeof(struct btrfs_ioctl_space_args));
40822
40823 if (copy_to_user(user_dest, dest_orig, alloc_size))
40824 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
40825 index cfb5543..1ae7347 100644
40826 --- a/fs/btrfs/relocation.c
40827 +++ b/fs/btrfs/relocation.c
40828 @@ -1244,7 +1244,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
40829 }
40830 spin_unlock(&rc->reloc_root_tree.lock);
40831
40832 - BUG_ON((struct btrfs_root *)node->data != root);
40833 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
40834
40835 if (!del) {
40836 spin_lock(&rc->reloc_root_tree.lock);
40837 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
40838 index 622f469..e8d2d55 100644
40839 --- a/fs/cachefiles/bind.c
40840 +++ b/fs/cachefiles/bind.c
40841 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
40842 args);
40843
40844 /* start by checking things over */
40845 - ASSERT(cache->fstop_percent >= 0 &&
40846 - cache->fstop_percent < cache->fcull_percent &&
40847 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
40848 cache->fcull_percent < cache->frun_percent &&
40849 cache->frun_percent < 100);
40850
40851 - ASSERT(cache->bstop_percent >= 0 &&
40852 - cache->bstop_percent < cache->bcull_percent &&
40853 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
40854 cache->bcull_percent < cache->brun_percent &&
40855 cache->brun_percent < 100);
40856
40857 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
40858 index 0a1467b..6a53245 100644
40859 --- a/fs/cachefiles/daemon.c
40860 +++ b/fs/cachefiles/daemon.c
40861 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
40862 if (n > buflen)
40863 return -EMSGSIZE;
40864
40865 - if (copy_to_user(_buffer, buffer, n) != 0)
40866 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
40867 return -EFAULT;
40868
40869 return n;
40870 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
40871 if (test_bit(CACHEFILES_DEAD, &cache->flags))
40872 return -EIO;
40873
40874 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
40875 + if (datalen > PAGE_SIZE - 1)
40876 return -EOPNOTSUPP;
40877
40878 /* drag the command string into the kernel so we can parse it */
40879 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
40880 if (args[0] != '%' || args[1] != '\0')
40881 return -EINVAL;
40882
40883 - if (fstop < 0 || fstop >= cache->fcull_percent)
40884 + if (fstop >= cache->fcull_percent)
40885 return cachefiles_daemon_range_error(cache, args);
40886
40887 cache->fstop_percent = fstop;
40888 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
40889 if (args[0] != '%' || args[1] != '\0')
40890 return -EINVAL;
40891
40892 - if (bstop < 0 || bstop >= cache->bcull_percent)
40893 + if (bstop >= cache->bcull_percent)
40894 return cachefiles_daemon_range_error(cache, args);
40895
40896 cache->bstop_percent = bstop;
40897 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
40898 index bd6bc1b..b627b53 100644
40899 --- a/fs/cachefiles/internal.h
40900 +++ b/fs/cachefiles/internal.h
40901 @@ -57,7 +57,7 @@ struct cachefiles_cache {
40902 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
40903 struct rb_root active_nodes; /* active nodes (can't be culled) */
40904 rwlock_t active_lock; /* lock for active_nodes */
40905 - atomic_t gravecounter; /* graveyard uniquifier */
40906 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
40907 unsigned frun_percent; /* when to stop culling (% files) */
40908 unsigned fcull_percent; /* when to start culling (% files) */
40909 unsigned fstop_percent; /* when to stop allocating (% files) */
40910 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
40911 * proc.c
40912 */
40913 #ifdef CONFIG_CACHEFILES_HISTOGRAM
40914 -extern atomic_t cachefiles_lookup_histogram[HZ];
40915 -extern atomic_t cachefiles_mkdir_histogram[HZ];
40916 -extern atomic_t cachefiles_create_histogram[HZ];
40917 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40918 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40919 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
40920
40921 extern int __init cachefiles_proc_init(void);
40922 extern void cachefiles_proc_cleanup(void);
40923 static inline
40924 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
40925 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
40926 {
40927 unsigned long jif = jiffies - start_jif;
40928 if (jif >= HZ)
40929 jif = HZ - 1;
40930 - atomic_inc(&histogram[jif]);
40931 + atomic_inc_unchecked(&histogram[jif]);
40932 }
40933
40934 #else
40935 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
40936 index a0358c2..d6137f2 100644
40937 --- a/fs/cachefiles/namei.c
40938 +++ b/fs/cachefiles/namei.c
40939 @@ -318,7 +318,7 @@ try_again:
40940 /* first step is to make up a grave dentry in the graveyard */
40941 sprintf(nbuffer, "%08x%08x",
40942 (uint32_t) get_seconds(),
40943 - (uint32_t) atomic_inc_return(&cache->gravecounter));
40944 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
40945
40946 /* do the multiway lock magic */
40947 trap = lock_rename(cache->graveyard, dir);
40948 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
40949 index eccd339..4c1d995 100644
40950 --- a/fs/cachefiles/proc.c
40951 +++ b/fs/cachefiles/proc.c
40952 @@ -14,9 +14,9 @@
40953 #include <linux/seq_file.h>
40954 #include "internal.h"
40955
40956 -atomic_t cachefiles_lookup_histogram[HZ];
40957 -atomic_t cachefiles_mkdir_histogram[HZ];
40958 -atomic_t cachefiles_create_histogram[HZ];
40959 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
40960 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
40961 +atomic_unchecked_t cachefiles_create_histogram[HZ];
40962
40963 /*
40964 * display the latency histogram
40965 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
40966 return 0;
40967 default:
40968 index = (unsigned long) v - 3;
40969 - x = atomic_read(&cachefiles_lookup_histogram[index]);
40970 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
40971 - z = atomic_read(&cachefiles_create_histogram[index]);
40972 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
40973 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
40974 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
40975 if (x == 0 && y == 0 && z == 0)
40976 return 0;
40977
40978 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
40979 index 0e3c092..818480e 100644
40980 --- a/fs/cachefiles/rdwr.c
40981 +++ b/fs/cachefiles/rdwr.c
40982 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
40983 old_fs = get_fs();
40984 set_fs(KERNEL_DS);
40985 ret = file->f_op->write(
40986 - file, (const void __user *) data, len, &pos);
40987 + file, (const void __force_user *) data, len, &pos);
40988 set_fs(old_fs);
40989 kunmap(page);
40990 if (ret != len)
40991 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
40992 index 9895400..fa40a7d 100644
40993 --- a/fs/ceph/dir.c
40994 +++ b/fs/ceph/dir.c
40995 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
40996 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
40997 struct ceph_mds_client *mdsc = fsc->mdsc;
40998 unsigned frag = fpos_frag(filp->f_pos);
40999 - int off = fpos_off(filp->f_pos);
41000 + unsigned int off = fpos_off(filp->f_pos);
41001 int err;
41002 u32 ftype;
41003 struct ceph_mds_reply_info_parsed *rinfo;
41004 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
41005 index 84e8c07..6170d31 100644
41006 --- a/fs/cifs/cifs_debug.c
41007 +++ b/fs/cifs/cifs_debug.c
41008 @@ -265,8 +265,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
41009
41010 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
41011 #ifdef CONFIG_CIFS_STATS2
41012 - atomic_set(&totBufAllocCount, 0);
41013 - atomic_set(&totSmBufAllocCount, 0);
41014 + atomic_set_unchecked(&totBufAllocCount, 0);
41015 + atomic_set_unchecked(&totSmBufAllocCount, 0);
41016 #endif /* CONFIG_CIFS_STATS2 */
41017 spin_lock(&cifs_tcp_ses_lock);
41018 list_for_each(tmp1, &cifs_tcp_ses_list) {
41019 @@ -279,25 +279,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
41020 tcon = list_entry(tmp3,
41021 struct cifs_tcon,
41022 tcon_list);
41023 - atomic_set(&tcon->num_smbs_sent, 0);
41024 - atomic_set(&tcon->num_writes, 0);
41025 - atomic_set(&tcon->num_reads, 0);
41026 - atomic_set(&tcon->num_oplock_brks, 0);
41027 - atomic_set(&tcon->num_opens, 0);
41028 - atomic_set(&tcon->num_posixopens, 0);
41029 - atomic_set(&tcon->num_posixmkdirs, 0);
41030 - atomic_set(&tcon->num_closes, 0);
41031 - atomic_set(&tcon->num_deletes, 0);
41032 - atomic_set(&tcon->num_mkdirs, 0);
41033 - atomic_set(&tcon->num_rmdirs, 0);
41034 - atomic_set(&tcon->num_renames, 0);
41035 - atomic_set(&tcon->num_t2renames, 0);
41036 - atomic_set(&tcon->num_ffirst, 0);
41037 - atomic_set(&tcon->num_fnext, 0);
41038 - atomic_set(&tcon->num_fclose, 0);
41039 - atomic_set(&tcon->num_hardlinks, 0);
41040 - atomic_set(&tcon->num_symlinks, 0);
41041 - atomic_set(&tcon->num_locks, 0);
41042 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
41043 + atomic_set_unchecked(&tcon->num_writes, 0);
41044 + atomic_set_unchecked(&tcon->num_reads, 0);
41045 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
41046 + atomic_set_unchecked(&tcon->num_opens, 0);
41047 + atomic_set_unchecked(&tcon->num_posixopens, 0);
41048 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
41049 + atomic_set_unchecked(&tcon->num_closes, 0);
41050 + atomic_set_unchecked(&tcon->num_deletes, 0);
41051 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
41052 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
41053 + atomic_set_unchecked(&tcon->num_renames, 0);
41054 + atomic_set_unchecked(&tcon->num_t2renames, 0);
41055 + atomic_set_unchecked(&tcon->num_ffirst, 0);
41056 + atomic_set_unchecked(&tcon->num_fnext, 0);
41057 + atomic_set_unchecked(&tcon->num_fclose, 0);
41058 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
41059 + atomic_set_unchecked(&tcon->num_symlinks, 0);
41060 + atomic_set_unchecked(&tcon->num_locks, 0);
41061 }
41062 }
41063 }
41064 @@ -327,8 +327,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
41065 smBufAllocCount.counter, cifs_min_small);
41066 #ifdef CONFIG_CIFS_STATS2
41067 seq_printf(m, "Total Large %d Small %d Allocations\n",
41068 - atomic_read(&totBufAllocCount),
41069 - atomic_read(&totSmBufAllocCount));
41070 + atomic_read_unchecked(&totBufAllocCount),
41071 + atomic_read_unchecked(&totSmBufAllocCount));
41072 #endif /* CONFIG_CIFS_STATS2 */
41073
41074 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
41075 @@ -357,41 +357,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
41076 if (tcon->need_reconnect)
41077 seq_puts(m, "\tDISCONNECTED ");
41078 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
41079 - atomic_read(&tcon->num_smbs_sent),
41080 - atomic_read(&tcon->num_oplock_brks));
41081 + atomic_read_unchecked(&tcon->num_smbs_sent),
41082 + atomic_read_unchecked(&tcon->num_oplock_brks));
41083 seq_printf(m, "\nReads: %d Bytes: %lld",
41084 - atomic_read(&tcon->num_reads),
41085 + atomic_read_unchecked(&tcon->num_reads),
41086 (long long)(tcon->bytes_read));
41087 seq_printf(m, "\nWrites: %d Bytes: %lld",
41088 - atomic_read(&tcon->num_writes),
41089 + atomic_read_unchecked(&tcon->num_writes),
41090 (long long)(tcon->bytes_written));
41091 seq_printf(m, "\nFlushes: %d",
41092 - atomic_read(&tcon->num_flushes));
41093 + atomic_read_unchecked(&tcon->num_flushes));
41094 seq_printf(m, "\nLocks: %d HardLinks: %d "
41095 "Symlinks: %d",
41096 - atomic_read(&tcon->num_locks),
41097 - atomic_read(&tcon->num_hardlinks),
41098 - atomic_read(&tcon->num_symlinks));
41099 + atomic_read_unchecked(&tcon->num_locks),
41100 + atomic_read_unchecked(&tcon->num_hardlinks),
41101 + atomic_read_unchecked(&tcon->num_symlinks));
41102 seq_printf(m, "\nOpens: %d Closes: %d "
41103 "Deletes: %d",
41104 - atomic_read(&tcon->num_opens),
41105 - atomic_read(&tcon->num_closes),
41106 - atomic_read(&tcon->num_deletes));
41107 + atomic_read_unchecked(&tcon->num_opens),
41108 + atomic_read_unchecked(&tcon->num_closes),
41109 + atomic_read_unchecked(&tcon->num_deletes));
41110 seq_printf(m, "\nPosix Opens: %d "
41111 "Posix Mkdirs: %d",
41112 - atomic_read(&tcon->num_posixopens),
41113 - atomic_read(&tcon->num_posixmkdirs));
41114 + atomic_read_unchecked(&tcon->num_posixopens),
41115 + atomic_read_unchecked(&tcon->num_posixmkdirs));
41116 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
41117 - atomic_read(&tcon->num_mkdirs),
41118 - atomic_read(&tcon->num_rmdirs));
41119 + atomic_read_unchecked(&tcon->num_mkdirs),
41120 + atomic_read_unchecked(&tcon->num_rmdirs));
41121 seq_printf(m, "\nRenames: %d T2 Renames %d",
41122 - atomic_read(&tcon->num_renames),
41123 - atomic_read(&tcon->num_t2renames));
41124 + atomic_read_unchecked(&tcon->num_renames),
41125 + atomic_read_unchecked(&tcon->num_t2renames));
41126 seq_printf(m, "\nFindFirst: %d FNext %d "
41127 "FClose %d",
41128 - atomic_read(&tcon->num_ffirst),
41129 - atomic_read(&tcon->num_fnext),
41130 - atomic_read(&tcon->num_fclose));
41131 + atomic_read_unchecked(&tcon->num_ffirst),
41132 + atomic_read_unchecked(&tcon->num_fnext),
41133 + atomic_read_unchecked(&tcon->num_fclose));
41134 }
41135 }
41136 }
41137 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
41138 index 8f1fe32..38f9e27 100644
41139 --- a/fs/cifs/cifsfs.c
41140 +++ b/fs/cifs/cifsfs.c
41141 @@ -989,7 +989,7 @@ cifs_init_request_bufs(void)
41142 cifs_req_cachep = kmem_cache_create("cifs_request",
41143 CIFSMaxBufSize +
41144 MAX_CIFS_HDR_SIZE, 0,
41145 - SLAB_HWCACHE_ALIGN, NULL);
41146 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
41147 if (cifs_req_cachep == NULL)
41148 return -ENOMEM;
41149
41150 @@ -1016,7 +1016,7 @@ cifs_init_request_bufs(void)
41151 efficient to alloc 1 per page off the slab compared to 17K (5page)
41152 alloc of large cifs buffers even when page debugging is on */
41153 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
41154 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
41155 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
41156 NULL);
41157 if (cifs_sm_req_cachep == NULL) {
41158 mempool_destroy(cifs_req_poolp);
41159 @@ -1101,8 +1101,8 @@ init_cifs(void)
41160 atomic_set(&bufAllocCount, 0);
41161 atomic_set(&smBufAllocCount, 0);
41162 #ifdef CONFIG_CIFS_STATS2
41163 - atomic_set(&totBufAllocCount, 0);
41164 - atomic_set(&totSmBufAllocCount, 0);
41165 + atomic_set_unchecked(&totBufAllocCount, 0);
41166 + atomic_set_unchecked(&totSmBufAllocCount, 0);
41167 #endif /* CONFIG_CIFS_STATS2 */
41168
41169 atomic_set(&midCount, 0);
41170 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
41171 index 8238aa1..0347196 100644
41172 --- a/fs/cifs/cifsglob.h
41173 +++ b/fs/cifs/cifsglob.h
41174 @@ -392,28 +392,28 @@ struct cifs_tcon {
41175 __u16 Flags; /* optional support bits */
41176 enum statusEnum tidStatus;
41177 #ifdef CONFIG_CIFS_STATS
41178 - atomic_t num_smbs_sent;
41179 - atomic_t num_writes;
41180 - atomic_t num_reads;
41181 - atomic_t num_flushes;
41182 - atomic_t num_oplock_brks;
41183 - atomic_t num_opens;
41184 - atomic_t num_closes;
41185 - atomic_t num_deletes;
41186 - atomic_t num_mkdirs;
41187 - atomic_t num_posixopens;
41188 - atomic_t num_posixmkdirs;
41189 - atomic_t num_rmdirs;
41190 - atomic_t num_renames;
41191 - atomic_t num_t2renames;
41192 - atomic_t num_ffirst;
41193 - atomic_t num_fnext;
41194 - atomic_t num_fclose;
41195 - atomic_t num_hardlinks;
41196 - atomic_t num_symlinks;
41197 - atomic_t num_locks;
41198 - atomic_t num_acl_get;
41199 - atomic_t num_acl_set;
41200 + atomic_unchecked_t num_smbs_sent;
41201 + atomic_unchecked_t num_writes;
41202 + atomic_unchecked_t num_reads;
41203 + atomic_unchecked_t num_flushes;
41204 + atomic_unchecked_t num_oplock_brks;
41205 + atomic_unchecked_t num_opens;
41206 + atomic_unchecked_t num_closes;
41207 + atomic_unchecked_t num_deletes;
41208 + atomic_unchecked_t num_mkdirs;
41209 + atomic_unchecked_t num_posixopens;
41210 + atomic_unchecked_t num_posixmkdirs;
41211 + atomic_unchecked_t num_rmdirs;
41212 + atomic_unchecked_t num_renames;
41213 + atomic_unchecked_t num_t2renames;
41214 + atomic_unchecked_t num_ffirst;
41215 + atomic_unchecked_t num_fnext;
41216 + atomic_unchecked_t num_fclose;
41217 + atomic_unchecked_t num_hardlinks;
41218 + atomic_unchecked_t num_symlinks;
41219 + atomic_unchecked_t num_locks;
41220 + atomic_unchecked_t num_acl_get;
41221 + atomic_unchecked_t num_acl_set;
41222 #ifdef CONFIG_CIFS_STATS2
41223 unsigned long long time_writes;
41224 unsigned long long time_reads;
41225 @@ -628,7 +628,7 @@ convert_delimiter(char *path, char delim)
41226 }
41227
41228 #ifdef CONFIG_CIFS_STATS
41229 -#define cifs_stats_inc atomic_inc
41230 +#define cifs_stats_inc atomic_inc_unchecked
41231
41232 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
41233 unsigned int bytes)
41234 @@ -985,8 +985,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
41235 /* Various Debug counters */
41236 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
41237 #ifdef CONFIG_CIFS_STATS2
41238 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
41239 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
41240 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
41241 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
41242 #endif
41243 GLOBAL_EXTERN atomic_t smBufAllocCount;
41244 GLOBAL_EXTERN atomic_t midCount;
41245 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
41246 index 6b0e064..94e6c3c 100644
41247 --- a/fs/cifs/link.c
41248 +++ b/fs/cifs/link.c
41249 @@ -600,7 +600,7 @@ symlink_exit:
41250
41251 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
41252 {
41253 - char *p = nd_get_link(nd);
41254 + const char *p = nd_get_link(nd);
41255 if (!IS_ERR(p))
41256 kfree(p);
41257 }
41258 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
41259 index 703ef5c..2a44ed5 100644
41260 --- a/fs/cifs/misc.c
41261 +++ b/fs/cifs/misc.c
41262 @@ -156,7 +156,7 @@ cifs_buf_get(void)
41263 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
41264 atomic_inc(&bufAllocCount);
41265 #ifdef CONFIG_CIFS_STATS2
41266 - atomic_inc(&totBufAllocCount);
41267 + atomic_inc_unchecked(&totBufAllocCount);
41268 #endif /* CONFIG_CIFS_STATS2 */
41269 }
41270
41271 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
41272 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
41273 atomic_inc(&smBufAllocCount);
41274 #ifdef CONFIG_CIFS_STATS2
41275 - atomic_inc(&totSmBufAllocCount);
41276 + atomic_inc_unchecked(&totSmBufAllocCount);
41277 #endif /* CONFIG_CIFS_STATS2 */
41278
41279 }
41280 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
41281 index 6901578..d402eb5 100644
41282 --- a/fs/coda/cache.c
41283 +++ b/fs/coda/cache.c
41284 @@ -24,7 +24,7 @@
41285 #include "coda_linux.h"
41286 #include "coda_cache.h"
41287
41288 -static atomic_t permission_epoch = ATOMIC_INIT(0);
41289 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
41290
41291 /* replace or extend an acl cache hit */
41292 void coda_cache_enter(struct inode *inode, int mask)
41293 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
41294 struct coda_inode_info *cii = ITOC(inode);
41295
41296 spin_lock(&cii->c_lock);
41297 - cii->c_cached_epoch = atomic_read(&permission_epoch);
41298 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
41299 if (cii->c_uid != current_fsuid()) {
41300 cii->c_uid = current_fsuid();
41301 cii->c_cached_perm = mask;
41302 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
41303 {
41304 struct coda_inode_info *cii = ITOC(inode);
41305 spin_lock(&cii->c_lock);
41306 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
41307 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
41308 spin_unlock(&cii->c_lock);
41309 }
41310
41311 /* remove all acl caches */
41312 void coda_cache_clear_all(struct super_block *sb)
41313 {
41314 - atomic_inc(&permission_epoch);
41315 + atomic_inc_unchecked(&permission_epoch);
41316 }
41317
41318
41319 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
41320 spin_lock(&cii->c_lock);
41321 hit = (mask & cii->c_cached_perm) == mask &&
41322 cii->c_uid == current_fsuid() &&
41323 - cii->c_cached_epoch == atomic_read(&permission_epoch);
41324 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
41325 spin_unlock(&cii->c_lock);
41326
41327 return hit;
41328 diff --git a/fs/compat.c b/fs/compat.c
41329 index c987875..08771ca 100644
41330 --- a/fs/compat.c
41331 +++ b/fs/compat.c
41332 @@ -132,8 +132,8 @@ asmlinkage long compat_sys_utimes(const char __user *filename, struct compat_tim
41333 static int cp_compat_stat(struct kstat *stat, struct compat_stat __user *ubuf)
41334 {
41335 compat_ino_t ino = stat->ino;
41336 - typeof(ubuf->st_uid) uid = 0;
41337 - typeof(ubuf->st_gid) gid = 0;
41338 + typeof(((struct compat_stat *)0)->st_uid) uid = 0;
41339 + typeof(((struct compat_stat *)0)->st_gid) gid = 0;
41340 int err;
41341
41342 SET_UID(uid, stat->uid);
41343 @@ -504,7 +504,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
41344
41345 set_fs(KERNEL_DS);
41346 /* The __user pointer cast is valid because of the set_fs() */
41347 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
41348 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
41349 set_fs(oldfs);
41350 /* truncating is ok because it's a user address */
41351 if (!ret)
41352 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
41353 goto out;
41354
41355 ret = -EINVAL;
41356 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
41357 + if (nr_segs > UIO_MAXIOV)
41358 goto out;
41359 if (nr_segs > fast_segs) {
41360 ret = -ENOMEM;
41361 @@ -845,6 +845,7 @@ struct compat_old_linux_dirent {
41362
41363 struct compat_readdir_callback {
41364 struct compat_old_linux_dirent __user *dirent;
41365 + struct file * file;
41366 int result;
41367 };
41368
41369 @@ -862,6 +863,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
41370 buf->result = -EOVERFLOW;
41371 return -EOVERFLOW;
41372 }
41373 +
41374 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41375 + return 0;
41376 +
41377 buf->result++;
41378 dirent = buf->dirent;
41379 if (!access_ok(VERIFY_WRITE, dirent,
41380 @@ -894,6 +899,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
41381
41382 buf.result = 0;
41383 buf.dirent = dirent;
41384 + buf.file = file;
41385
41386 error = vfs_readdir(file, compat_fillonedir, &buf);
41387 if (buf.result)
41388 @@ -914,6 +920,7 @@ struct compat_linux_dirent {
41389 struct compat_getdents_callback {
41390 struct compat_linux_dirent __user *current_dir;
41391 struct compat_linux_dirent __user *previous;
41392 + struct file * file;
41393 int count;
41394 int error;
41395 };
41396 @@ -935,6 +942,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
41397 buf->error = -EOVERFLOW;
41398 return -EOVERFLOW;
41399 }
41400 +
41401 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41402 + return 0;
41403 +
41404 dirent = buf->previous;
41405 if (dirent) {
41406 if (__put_user(offset, &dirent->d_off))
41407 @@ -982,6 +993,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
41408 buf.previous = NULL;
41409 buf.count = count;
41410 buf.error = 0;
41411 + buf.file = file;
41412
41413 error = vfs_readdir(file, compat_filldir, &buf);
41414 if (error >= 0)
41415 @@ -1003,6 +1015,7 @@ out:
41416 struct compat_getdents_callback64 {
41417 struct linux_dirent64 __user *current_dir;
41418 struct linux_dirent64 __user *previous;
41419 + struct file * file;
41420 int count;
41421 int error;
41422 };
41423 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
41424 buf->error = -EINVAL; /* only used if we fail.. */
41425 if (reclen > buf->count)
41426 return -EINVAL;
41427 +
41428 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
41429 + return 0;
41430 +
41431 dirent = buf->previous;
41432
41433 if (dirent) {
41434 @@ -1070,13 +1087,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
41435 buf.previous = NULL;
41436 buf.count = count;
41437 buf.error = 0;
41438 + buf.file = file;
41439
41440 error = vfs_readdir(file, compat_filldir64, &buf);
41441 if (error >= 0)
41442 error = buf.error;
41443 lastdirent = buf.previous;
41444 if (lastdirent) {
41445 - typeof(lastdirent->d_off) d_off = file->f_pos;
41446 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
41447 if (__put_user_unaligned(d_off, &lastdirent->d_off))
41448 error = -EFAULT;
41449 else
41450 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
41451 index 112e45a..b59845b 100644
41452 --- a/fs/compat_binfmt_elf.c
41453 +++ b/fs/compat_binfmt_elf.c
41454 @@ -30,11 +30,13 @@
41455 #undef elf_phdr
41456 #undef elf_shdr
41457 #undef elf_note
41458 +#undef elf_dyn
41459 #undef elf_addr_t
41460 #define elfhdr elf32_hdr
41461 #define elf_phdr elf32_phdr
41462 #define elf_shdr elf32_shdr
41463 #define elf_note elf32_note
41464 +#define elf_dyn Elf32_Dyn
41465 #define elf_addr_t Elf32_Addr
41466
41467 /*
41468 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
41469 index 51352de..93292ff 100644
41470 --- a/fs/compat_ioctl.c
41471 +++ b/fs/compat_ioctl.c
41472 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
41473
41474 err = get_user(palp, &up->palette);
41475 err |= get_user(length, &up->length);
41476 + if (err)
41477 + return -EFAULT;
41478
41479 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
41480 err = put_user(compat_ptr(palp), &up_native->palette);
41481 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
41482 return -EFAULT;
41483 if (__get_user(udata, &ss32->iomem_base))
41484 return -EFAULT;
41485 - ss.iomem_base = compat_ptr(udata);
41486 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
41487 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
41488 __get_user(ss.port_high, &ss32->port_high))
41489 return -EFAULT;
41490 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
41491 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
41492 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
41493 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
41494 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
41495 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
41496 return -EFAULT;
41497
41498 return ioctl_preallocate(file, p);
41499 @@ -1644,8 +1646,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
41500 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
41501 {
41502 unsigned int a, b;
41503 - a = *(unsigned int *)p;
41504 - b = *(unsigned int *)q;
41505 + a = *(const unsigned int *)p;
41506 + b = *(const unsigned int *)q;
41507 if (a > b)
41508 return 1;
41509 if (a < b)
41510 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
41511 index 9a37a9b..35792b6 100644
41512 --- a/fs/configfs/dir.c
41513 +++ b/fs/configfs/dir.c
41514 @@ -1575,7 +1575,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
41515 }
41516 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
41517 struct configfs_dirent *next;
41518 - const char * name;
41519 + const unsigned char * name;
41520 + char d_name[sizeof(next->s_dentry->d_iname)];
41521 int len;
41522 struct inode *inode = NULL;
41523
41524 @@ -1585,7 +1586,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
41525 continue;
41526
41527 name = configfs_get_name(next);
41528 - len = strlen(name);
41529 + if (next->s_dentry && name == next->s_dentry->d_iname) {
41530 + len = next->s_dentry->d_name.len;
41531 + memcpy(d_name, name, len);
41532 + name = d_name;
41533 + } else
41534 + len = strlen(name);
41535
41536 /*
41537 * We'll have a dentry and an inode for
41538 diff --git a/fs/dcache.c b/fs/dcache.c
41539 index f7908ae..920a680 100644
41540 --- a/fs/dcache.c
41541 +++ b/fs/dcache.c
41542 @@ -3042,7 +3042,7 @@ void __init vfs_caches_init(unsigned long mempages)
41543 mempages -= reserve;
41544
41545 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
41546 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
41547 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
41548
41549 dcache_init();
41550 inode_init();
41551 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
41552 index f3a257d..715ac0f 100644
41553 --- a/fs/debugfs/inode.c
41554 +++ b/fs/debugfs/inode.c
41555 @@ -261,7 +261,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
41556 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
41557 {
41558 return debugfs_create_file(name,
41559 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
41560 + S_IFDIR | S_IRWXU,
41561 +#else
41562 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
41563 +#endif
41564 parent, NULL, NULL);
41565 }
41566 EXPORT_SYMBOL_GPL(debugfs_create_dir);
41567 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
41568 index d2039ca..a766407 100644
41569 --- a/fs/ecryptfs/inode.c
41570 +++ b/fs/ecryptfs/inode.c
41571 @@ -691,7 +691,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
41572 old_fs = get_fs();
41573 set_fs(get_ds());
41574 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
41575 - (char __user *)lower_buf,
41576 + (char __force_user *)lower_buf,
41577 lower_bufsiz);
41578 set_fs(old_fs);
41579 if (rc < 0)
41580 @@ -737,7 +737,7 @@ static void *ecryptfs_follow_link(struct dentry *dentry, struct nameidata *nd)
41581 }
41582 old_fs = get_fs();
41583 set_fs(get_ds());
41584 - rc = dentry->d_inode->i_op->readlink(dentry, (char __user *)buf, len);
41585 + rc = dentry->d_inode->i_op->readlink(dentry, (char __force_user *)buf, len);
41586 set_fs(old_fs);
41587 if (rc < 0) {
41588 kfree(buf);
41589 @@ -752,7 +752,7 @@ out:
41590 static void
41591 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
41592 {
41593 - char *buf = nd_get_link(nd);
41594 + const char *buf = nd_get_link(nd);
41595 if (!IS_ERR(buf)) {
41596 /* Free the char* */
41597 kfree(buf);
41598 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
41599 index 0dc5a3d..d3cdeea 100644
41600 --- a/fs/ecryptfs/miscdev.c
41601 +++ b/fs/ecryptfs/miscdev.c
41602 @@ -328,7 +328,7 @@ check_list:
41603 goto out_unlock_msg_ctx;
41604 i = 5;
41605 if (msg_ctx->msg) {
41606 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
41607 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
41608 goto out_unlock_msg_ctx;
41609 i += packet_length_size;
41610 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
41611 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
41612 index 608c1c3..7d040a8 100644
41613 --- a/fs/ecryptfs/read_write.c
41614 +++ b/fs/ecryptfs/read_write.c
41615 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
41616 return -EIO;
41617 fs_save = get_fs();
41618 set_fs(get_ds());
41619 - rc = vfs_write(lower_file, data, size, &offset);
41620 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
41621 set_fs(fs_save);
41622 mark_inode_dirty_sync(ecryptfs_inode);
41623 return rc;
41624 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
41625 return -EIO;
41626 fs_save = get_fs();
41627 set_fs(get_ds());
41628 - rc = vfs_read(lower_file, data, size, &offset);
41629 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
41630 set_fs(fs_save);
41631 return rc;
41632 }
41633 diff --git a/fs/exec.c b/fs/exec.c
41634 index 3625464..04855f9 100644
41635 --- a/fs/exec.c
41636 +++ b/fs/exec.c
41637 @@ -55,12 +55,28 @@
41638 #include <linux/pipe_fs_i.h>
41639 #include <linux/oom.h>
41640 #include <linux/compat.h>
41641 +#include <linux/random.h>
41642 +#include <linux/seq_file.h>
41643 +
41644 +#ifdef CONFIG_PAX_REFCOUNT
41645 +#include <linux/kallsyms.h>
41646 +#include <linux/kdebug.h>
41647 +#endif
41648
41649 #include <asm/uaccess.h>
41650 #include <asm/mmu_context.h>
41651 #include <asm/tlb.h>
41652 #include "internal.h"
41653
41654 +#ifndef CONFIG_PAX_HAVE_ACL_FLAGS
41655 +void __weak pax_set_initial_flags(struct linux_binprm *bprm) {}
41656 +#endif
41657 +
41658 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
41659 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
41660 +EXPORT_SYMBOL(pax_set_initial_flags_func);
41661 +#endif
41662 +
41663 int core_uses_pid;
41664 char core_pattern[CORENAME_MAX_SIZE] = "core";
41665 unsigned int core_pipe_limit;
41666 @@ -70,7 +86,7 @@ struct core_name {
41667 char *corename;
41668 int used, size;
41669 };
41670 -static atomic_t call_count = ATOMIC_INIT(1);
41671 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
41672
41673 /* The maximal length of core_pattern is also specified in sysctl.c */
41674
41675 @@ -188,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
41676 int write)
41677 {
41678 struct page *page;
41679 - int ret;
41680
41681 -#ifdef CONFIG_STACK_GROWSUP
41682 - if (write) {
41683 - ret = expand_downwards(bprm->vma, pos);
41684 - if (ret < 0)
41685 - return NULL;
41686 - }
41687 -#endif
41688 - ret = get_user_pages(current, bprm->mm, pos,
41689 - 1, write, 1, &page, NULL);
41690 - if (ret <= 0)
41691 + if (0 > expand_downwards(bprm->vma, pos))
41692 + return NULL;
41693 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
41694 return NULL;
41695
41696 if (write) {
41697 @@ -215,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
41698 if (size <= ARG_MAX)
41699 return page;
41700
41701 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41702 + // only allow 1MB for argv+env on suid/sgid binaries
41703 + // to prevent easy ASLR exhaustion
41704 + if (((bprm->cred->euid != current_euid()) ||
41705 + (bprm->cred->egid != current_egid())) &&
41706 + (size > (1024 * 1024))) {
41707 + put_page(page);
41708 + return NULL;
41709 + }
41710 +#endif
41711 +
41712 /*
41713 * Limit to 1/4-th the stack size for the argv+env strings.
41714 * This ensures that:
41715 @@ -274,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
41716 vma->vm_end = STACK_TOP_MAX;
41717 vma->vm_start = vma->vm_end - PAGE_SIZE;
41718 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
41719 +
41720 +#ifdef CONFIG_PAX_SEGMEXEC
41721 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
41722 +#endif
41723 +
41724 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
41725 INIT_LIST_HEAD(&vma->anon_vma_chain);
41726
41727 @@ -288,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
41728 mm->stack_vm = mm->total_vm = 1;
41729 up_write(&mm->mmap_sem);
41730 bprm->p = vma->vm_end - sizeof(void *);
41731 +
41732 +#ifdef CONFIG_PAX_RANDUSTACK
41733 + if (randomize_va_space)
41734 + bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
41735 +#endif
41736 +
41737 return 0;
41738 err:
41739 up_write(&mm->mmap_sem);
41740 @@ -396,19 +426,7 @@ err:
41741 return err;
41742 }
41743
41744 -struct user_arg_ptr {
41745 -#ifdef CONFIG_COMPAT
41746 - bool is_compat;
41747 -#endif
41748 - union {
41749 - const char __user *const __user *native;
41750 -#ifdef CONFIG_COMPAT
41751 - compat_uptr_t __user *compat;
41752 -#endif
41753 - } ptr;
41754 -};
41755 -
41756 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41757 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41758 {
41759 const char __user *native;
41760
41761 @@ -417,14 +435,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
41762 compat_uptr_t compat;
41763
41764 if (get_user(compat, argv.ptr.compat + nr))
41765 - return ERR_PTR(-EFAULT);
41766 + return (const char __force_user *)ERR_PTR(-EFAULT);
41767
41768 return compat_ptr(compat);
41769 }
41770 #endif
41771
41772 if (get_user(native, argv.ptr.native + nr))
41773 - return ERR_PTR(-EFAULT);
41774 + return (const char __force_user *)ERR_PTR(-EFAULT);
41775
41776 return native;
41777 }
41778 @@ -443,7 +461,7 @@ static int count(struct user_arg_ptr argv, int max)
41779 if (!p)
41780 break;
41781
41782 - if (IS_ERR(p))
41783 + if (IS_ERR((const char __force_kernel *)p))
41784 return -EFAULT;
41785
41786 if (i++ >= max)
41787 @@ -477,7 +495,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
41788
41789 ret = -EFAULT;
41790 str = get_user_arg_ptr(argv, argc);
41791 - if (IS_ERR(str))
41792 + if (IS_ERR((const char __force_kernel *)str))
41793 goto out;
41794
41795 len = strnlen_user(str, MAX_ARG_STRLEN);
41796 @@ -559,7 +577,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
41797 int r;
41798 mm_segment_t oldfs = get_fs();
41799 struct user_arg_ptr argv = {
41800 - .ptr.native = (const char __user *const __user *)__argv,
41801 + .ptr.native = (const char __force_user *const __force_user *)__argv,
41802 };
41803
41804 set_fs(KERNEL_DS);
41805 @@ -594,7 +612,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
41806 unsigned long new_end = old_end - shift;
41807 struct mmu_gather tlb;
41808
41809 - BUG_ON(new_start > new_end);
41810 + if (new_start >= new_end || new_start < mmap_min_addr)
41811 + return -ENOMEM;
41812
41813 /*
41814 * ensure there are no vmas between where we want to go
41815 @@ -603,6 +622,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
41816 if (vma != find_vma(mm, new_start))
41817 return -EFAULT;
41818
41819 +#ifdef CONFIG_PAX_SEGMEXEC
41820 + BUG_ON(pax_find_mirror_vma(vma));
41821 +#endif
41822 +
41823 /*
41824 * cover the whole range: [new_start, old_end)
41825 */
41826 @@ -683,10 +706,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
41827 stack_top = arch_align_stack(stack_top);
41828 stack_top = PAGE_ALIGN(stack_top);
41829
41830 - if (unlikely(stack_top < mmap_min_addr) ||
41831 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
41832 - return -ENOMEM;
41833 -
41834 stack_shift = vma->vm_end - stack_top;
41835
41836 bprm->p -= stack_shift;
41837 @@ -698,8 +717,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
41838 bprm->exec -= stack_shift;
41839
41840 down_write(&mm->mmap_sem);
41841 +
41842 + /* Move stack pages down in memory. */
41843 + if (stack_shift) {
41844 + ret = shift_arg_pages(vma, stack_shift);
41845 + if (ret)
41846 + goto out_unlock;
41847 + }
41848 +
41849 vm_flags = VM_STACK_FLAGS;
41850
41851 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
41852 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
41853 + vm_flags &= ~VM_EXEC;
41854 +
41855 +#ifdef CONFIG_PAX_MPROTECT
41856 + if (mm->pax_flags & MF_PAX_MPROTECT)
41857 + vm_flags &= ~VM_MAYEXEC;
41858 +#endif
41859 +
41860 + }
41861 +#endif
41862 +
41863 /*
41864 * Adjust stack execute permissions; explicitly enable for
41865 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
41866 @@ -718,13 +757,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
41867 goto out_unlock;
41868 BUG_ON(prev != vma);
41869
41870 - /* Move stack pages down in memory. */
41871 - if (stack_shift) {
41872 - ret = shift_arg_pages(vma, stack_shift);
41873 - if (ret)
41874 - goto out_unlock;
41875 - }
41876 -
41877 /* mprotect_fixup is overkill to remove the temporary stack flags */
41878 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
41879
41880 @@ -805,7 +837,7 @@ int kernel_read(struct file *file, loff_t offset,
41881 old_fs = get_fs();
41882 set_fs(get_ds());
41883 /* The cast to a user pointer is valid due to the set_fs() */
41884 - result = vfs_read(file, (void __user *)addr, count, &pos);
41885 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
41886 set_fs(old_fs);
41887 return result;
41888 }
41889 @@ -1067,6 +1099,21 @@ void set_task_comm(struct task_struct *tsk, char *buf)
41890 perf_event_comm(tsk);
41891 }
41892
41893 +static void filename_to_taskname(char *tcomm, const char *fn, unsigned int len)
41894 +{
41895 + int i, ch;
41896 +
41897 + /* Copies the binary name from after last slash */
41898 + for (i = 0; (ch = *(fn++)) != '\0';) {
41899 + if (ch == '/')
41900 + i = 0; /* overwrite what we wrote */
41901 + else
41902 + if (i < len - 1)
41903 + tcomm[i++] = ch;
41904 + }
41905 + tcomm[i] = '\0';
41906 +}
41907 +
41908 int flush_old_exec(struct linux_binprm * bprm)
41909 {
41910 int retval;
41911 @@ -1081,6 +1128,7 @@ int flush_old_exec(struct linux_binprm * bprm)
41912
41913 set_mm_exe_file(bprm->mm, bprm->file);
41914
41915 + filename_to_taskname(bprm->tcomm, bprm->filename, sizeof(bprm->tcomm));
41916 /*
41917 * Release all of the old mmap stuff
41918 */
41919 @@ -1112,10 +1160,6 @@ EXPORT_SYMBOL(would_dump);
41920
41921 void setup_new_exec(struct linux_binprm * bprm)
41922 {
41923 - int i, ch;
41924 - const char *name;
41925 - char tcomm[sizeof(current->comm)];
41926 -
41927 arch_pick_mmap_layout(current->mm);
41928
41929 /* This is the point of no return */
41930 @@ -1126,18 +1170,7 @@ void setup_new_exec(struct linux_binprm * bprm)
41931 else
41932 set_dumpable(current->mm, suid_dumpable);
41933
41934 - name = bprm->filename;
41935 -
41936 - /* Copies the binary name from after last slash */
41937 - for (i=0; (ch = *(name++)) != '\0';) {
41938 - if (ch == '/')
41939 - i = 0; /* overwrite what we wrote */
41940 - else
41941 - if (i < (sizeof(tcomm) - 1))
41942 - tcomm[i++] = ch;
41943 - }
41944 - tcomm[i] = '\0';
41945 - set_task_comm(current, tcomm);
41946 + set_task_comm(current, bprm->tcomm);
41947
41948 /* Set the new mm task size. We have to do that late because it may
41949 * depend on TIF_32BIT which is only updated in flush_thread() on
41950 @@ -1247,7 +1280,7 @@ int check_unsafe_exec(struct linux_binprm *bprm)
41951 }
41952 rcu_read_unlock();
41953
41954 - if (p->fs->users > n_fs) {
41955 + if (atomic_read(&p->fs->users) > n_fs) {
41956 bprm->unsafe |= LSM_UNSAFE_SHARE;
41957 } else {
41958 res = -EAGAIN;
41959 @@ -1442,6 +1475,10 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
41960
41961 EXPORT_SYMBOL(search_binary_handler);
41962
41963 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
41964 +static atomic64_unchecked_t global_exec_counter = ATOMIC64_INIT(0);
41965 +#endif
41966 +
41967 /*
41968 * sys_execve() executes a new program.
41969 */
41970 @@ -1450,6 +1487,11 @@ static int do_execve_common(const char *filename,
41971 struct user_arg_ptr envp,
41972 struct pt_regs *regs)
41973 {
41974 +#ifdef CONFIG_GRKERNSEC
41975 + struct file *old_exec_file;
41976 + struct acl_subject_label *old_acl;
41977 + struct rlimit old_rlim[RLIM_NLIMITS];
41978 +#endif
41979 struct linux_binprm *bprm;
41980 struct file *file;
41981 struct files_struct *displaced;
41982 @@ -1457,6 +1499,8 @@ static int do_execve_common(const char *filename,
41983 int retval;
41984 const struct cred *cred = current_cred();
41985
41986 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
41987 +
41988 /*
41989 * We move the actual failure in case of RLIMIT_NPROC excess from
41990 * set*uid() to execve() because too many poorly written programs
41991 @@ -1497,12 +1541,27 @@ static int do_execve_common(const char *filename,
41992 if (IS_ERR(file))
41993 goto out_unmark;
41994
41995 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
41996 + retval = -EPERM;
41997 + goto out_file;
41998 + }
41999 +
42000 sched_exec();
42001
42002 bprm->file = file;
42003 bprm->filename = filename;
42004 bprm->interp = filename;
42005
42006 + if (gr_process_user_ban()) {
42007 + retval = -EPERM;
42008 + goto out_file;
42009 + }
42010 +
42011 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
42012 + retval = -EACCES;
42013 + goto out_file;
42014 + }
42015 +
42016 retval = bprm_mm_init(bprm);
42017 if (retval)
42018 goto out_file;
42019 @@ -1532,11 +1591,46 @@ static int do_execve_common(const char *filename,
42020 if (retval < 0)
42021 goto out;
42022
42023 + if (!gr_tpe_allow(file)) {
42024 + retval = -EACCES;
42025 + goto out;
42026 + }
42027 +
42028 + if (gr_check_crash_exec(file)) {
42029 + retval = -EACCES;
42030 + goto out;
42031 + }
42032 +
42033 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
42034 +
42035 + gr_handle_exec_args(bprm, argv);
42036 +
42037 +#ifdef CONFIG_GRKERNSEC
42038 + old_acl = current->acl;
42039 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
42040 + old_exec_file = current->exec_file;
42041 + get_file(file);
42042 + current->exec_file = file;
42043 +#endif
42044 +
42045 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
42046 + bprm->unsafe);
42047 + if (retval < 0)
42048 + goto out_fail;
42049 +
42050 retval = search_binary_handler(bprm,regs);
42051 if (retval < 0)
42052 - goto out;
42053 + goto out_fail;
42054 +#ifdef CONFIG_GRKERNSEC
42055 + if (old_exec_file)
42056 + fput(old_exec_file);
42057 +#endif
42058
42059 /* execve succeeded */
42060 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
42061 + current->exec_id = atomic64_inc_return_unchecked(&global_exec_counter);
42062 +#endif
42063 +
42064 current->fs->in_exec = 0;
42065 current->in_execve = 0;
42066 acct_update_integrals(current);
42067 @@ -1545,6 +1639,14 @@ static int do_execve_common(const char *filename,
42068 put_files_struct(displaced);
42069 return retval;
42070
42071 +out_fail:
42072 +#ifdef CONFIG_GRKERNSEC
42073 + current->acl = old_acl;
42074 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
42075 + fput(current->exec_file);
42076 + current->exec_file = old_exec_file;
42077 +#endif
42078 +
42079 out:
42080 if (bprm->mm) {
42081 acct_arg_size(bprm, 0);
42082 @@ -1618,7 +1720,7 @@ static int expand_corename(struct core_name *cn)
42083 {
42084 char *old_corename = cn->corename;
42085
42086 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
42087 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
42088 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
42089
42090 if (!cn->corename) {
42091 @@ -1715,7 +1817,7 @@ static int format_corename(struct core_name *cn, long signr)
42092 int pid_in_pattern = 0;
42093 int err = 0;
42094
42095 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
42096 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
42097 cn->corename = kmalloc(cn->size, GFP_KERNEL);
42098 cn->used = 0;
42099
42100 @@ -1812,6 +1914,218 @@ out:
42101 return ispipe;
42102 }
42103
42104 +int pax_check_flags(unsigned long *flags)
42105 +{
42106 + int retval = 0;
42107 +
42108 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
42109 + if (*flags & MF_PAX_SEGMEXEC)
42110 + {
42111 + *flags &= ~MF_PAX_SEGMEXEC;
42112 + retval = -EINVAL;
42113 + }
42114 +#endif
42115 +
42116 + if ((*flags & MF_PAX_PAGEEXEC)
42117 +
42118 +#ifdef CONFIG_PAX_PAGEEXEC
42119 + && (*flags & MF_PAX_SEGMEXEC)
42120 +#endif
42121 +
42122 + )
42123 + {
42124 + *flags &= ~MF_PAX_PAGEEXEC;
42125 + retval = -EINVAL;
42126 + }
42127 +
42128 + if ((*flags & MF_PAX_MPROTECT)
42129 +
42130 +#ifdef CONFIG_PAX_MPROTECT
42131 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
42132 +#endif
42133 +
42134 + )
42135 + {
42136 + *flags &= ~MF_PAX_MPROTECT;
42137 + retval = -EINVAL;
42138 + }
42139 +
42140 + if ((*flags & MF_PAX_EMUTRAMP)
42141 +
42142 +#ifdef CONFIG_PAX_EMUTRAMP
42143 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
42144 +#endif
42145 +
42146 + )
42147 + {
42148 + *flags &= ~MF_PAX_EMUTRAMP;
42149 + retval = -EINVAL;
42150 + }
42151 +
42152 + return retval;
42153 +}
42154 +
42155 +EXPORT_SYMBOL(pax_check_flags);
42156 +
42157 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
42158 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
42159 +{
42160 + struct task_struct *tsk = current;
42161 + struct mm_struct *mm = current->mm;
42162 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
42163 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
42164 + char *path_exec = NULL;
42165 + char *path_fault = NULL;
42166 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
42167 +
42168 + if (buffer_exec && buffer_fault) {
42169 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
42170 +
42171 + down_read(&mm->mmap_sem);
42172 + vma = mm->mmap;
42173 + while (vma && (!vma_exec || !vma_fault)) {
42174 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
42175 + vma_exec = vma;
42176 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
42177 + vma_fault = vma;
42178 + vma = vma->vm_next;
42179 + }
42180 + if (vma_exec) {
42181 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
42182 + if (IS_ERR(path_exec))
42183 + path_exec = "<path too long>";
42184 + else {
42185 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
42186 + if (path_exec) {
42187 + *path_exec = 0;
42188 + path_exec = buffer_exec;
42189 + } else
42190 + path_exec = "<path too long>";
42191 + }
42192 + }
42193 + if (vma_fault) {
42194 + start = vma_fault->vm_start;
42195 + end = vma_fault->vm_end;
42196 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
42197 + if (vma_fault->vm_file) {
42198 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
42199 + if (IS_ERR(path_fault))
42200 + path_fault = "<path too long>";
42201 + else {
42202 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
42203 + if (path_fault) {
42204 + *path_fault = 0;
42205 + path_fault = buffer_fault;
42206 + } else
42207 + path_fault = "<path too long>";
42208 + }
42209 + } else
42210 + path_fault = "<anonymous mapping>";
42211 + }
42212 + up_read(&mm->mmap_sem);
42213 + }
42214 + if (tsk->signal->curr_ip)
42215 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
42216 + else
42217 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
42218 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
42219 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
42220 + task_uid(tsk), task_euid(tsk), pc, sp);
42221 + free_page((unsigned long)buffer_exec);
42222 + free_page((unsigned long)buffer_fault);
42223 + pax_report_insns(regs, pc, sp);
42224 + do_coredump(SIGKILL, SIGKILL, regs);
42225 +}
42226 +#endif
42227 +
42228 +#ifdef CONFIG_PAX_REFCOUNT
42229 +void pax_report_refcount_overflow(struct pt_regs *regs)
42230 +{
42231 + if (current->signal->curr_ip)
42232 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
42233 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
42234 + else
42235 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
42236 + current->comm, task_pid_nr(current), current_uid(), current_euid());
42237 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
42238 + show_regs(regs);
42239 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
42240 +}
42241 +#endif
42242 +
42243 +#ifdef CONFIG_PAX_USERCOPY
42244 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
42245 +int object_is_on_stack(const void *obj, unsigned long len)
42246 +{
42247 + const void * const stack = task_stack_page(current);
42248 + const void * const stackend = stack + THREAD_SIZE;
42249 +
42250 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
42251 + const void *frame = NULL;
42252 + const void *oldframe;
42253 +#endif
42254 +
42255 + if (obj + len < obj)
42256 + return -1;
42257 +
42258 + if (obj + len <= stack || stackend <= obj)
42259 + return 0;
42260 +
42261 + if (obj < stack || stackend < obj + len)
42262 + return -1;
42263 +
42264 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
42265 + oldframe = __builtin_frame_address(1);
42266 + if (oldframe)
42267 + frame = __builtin_frame_address(2);
42268 + /*
42269 + low ----------------------------------------------> high
42270 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
42271 + ^----------------^
42272 + allow copies only within here
42273 + */
42274 + while (stack <= frame && frame < stackend) {
42275 + /* if obj + len extends past the last frame, this
42276 + check won't pass and the next frame will be 0,
42277 + causing us to bail out and correctly report
42278 + the copy as invalid
42279 + */
42280 + if (obj + len <= frame)
42281 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
42282 + oldframe = frame;
42283 + frame = *(const void * const *)frame;
42284 + }
42285 + return -1;
42286 +#else
42287 + return 1;
42288 +#endif
42289 +}
42290 +
42291 +NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
42292 +{
42293 + if (current->signal->curr_ip)
42294 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
42295 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
42296 + else
42297 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
42298 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
42299 + dump_stack();
42300 + gr_handle_kernel_exploit();
42301 + do_group_exit(SIGKILL);
42302 +}
42303 +#endif
42304 +
42305 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
42306 +void pax_track_stack(void)
42307 +{
42308 + unsigned long sp = (unsigned long)&sp;
42309 + if (sp < current_thread_info()->lowest_stack &&
42310 + sp > (unsigned long)task_stack_page(current))
42311 + current_thread_info()->lowest_stack = sp;
42312 +}
42313 +EXPORT_SYMBOL(pax_track_stack);
42314 +#endif
42315 +
42316 static int zap_process(struct task_struct *start, int exit_code)
42317 {
42318 struct task_struct *t;
42319 @@ -2023,17 +2337,17 @@ static void wait_for_dump_helpers(struct file *file)
42320 pipe = file->f_path.dentry->d_inode->i_pipe;
42321
42322 pipe_lock(pipe);
42323 - pipe->readers++;
42324 - pipe->writers--;
42325 + atomic_inc(&pipe->readers);
42326 + atomic_dec(&pipe->writers);
42327
42328 - while ((pipe->readers > 1) && (!signal_pending(current))) {
42329 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
42330 wake_up_interruptible_sync(&pipe->wait);
42331 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
42332 pipe_wait(pipe);
42333 }
42334
42335 - pipe->readers--;
42336 - pipe->writers++;
42337 + atomic_dec(&pipe->readers);
42338 + atomic_inc(&pipe->writers);
42339 pipe_unlock(pipe);
42340
42341 }
42342 @@ -2094,7 +2408,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42343 int retval = 0;
42344 int flag = 0;
42345 int ispipe;
42346 - static atomic_t core_dump_count = ATOMIC_INIT(0);
42347 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
42348 struct coredump_params cprm = {
42349 .signr = signr,
42350 .regs = regs,
42351 @@ -2109,6 +2423,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42352
42353 audit_core_dumps(signr);
42354
42355 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
42356 + gr_handle_brute_attach(current, cprm.mm_flags);
42357 +
42358 binfmt = mm->binfmt;
42359 if (!binfmt || !binfmt->core_dump)
42360 goto fail;
42361 @@ -2176,7 +2493,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42362 }
42363 cprm.limit = RLIM_INFINITY;
42364
42365 - dump_count = atomic_inc_return(&core_dump_count);
42366 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
42367 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
42368 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
42369 task_tgid_vnr(current), current->comm);
42370 @@ -2203,6 +2520,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
42371 } else {
42372 struct inode *inode;
42373
42374 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
42375 +
42376 if (cprm.limit < binfmt->min_coredump)
42377 goto fail_unlock;
42378
42379 @@ -2246,7 +2565,7 @@ close_fail:
42380 filp_close(cprm.file, NULL);
42381 fail_dropcount:
42382 if (ispipe)
42383 - atomic_dec(&core_dump_count);
42384 + atomic_dec_unchecked(&core_dump_count);
42385 fail_unlock:
42386 kfree(cn.corename);
42387 fail_corename:
42388 @@ -2265,7 +2584,7 @@ fail:
42389 */
42390 int dump_write(struct file *file, const void *addr, int nr)
42391 {
42392 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
42393 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
42394 }
42395 EXPORT_SYMBOL(dump_write);
42396
42397 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
42398 index a8cbe1b..fed04cb 100644
42399 --- a/fs/ext2/balloc.c
42400 +++ b/fs/ext2/balloc.c
42401 @@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
42402
42403 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
42404 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
42405 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
42406 + if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
42407 sbi->s_resuid != current_fsuid() &&
42408 (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
42409 return 0;
42410 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
42411 index a203892..4e64db5 100644
42412 --- a/fs/ext3/balloc.c
42413 +++ b/fs/ext3/balloc.c
42414 @@ -1446,9 +1446,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
42415
42416 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
42417 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
42418 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
42419 + if (free_blocks < root_blocks + 1 &&
42420 !use_reservation && sbi->s_resuid != current_fsuid() &&
42421 - (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
42422 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid)) &&
42423 + !capable_nolog(CAP_SYS_RESOURCE)) {
42424 return 0;
42425 }
42426 return 1;
42427 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
42428 index 12ccacd..a6035fce0 100644
42429 --- a/fs/ext4/balloc.c
42430 +++ b/fs/ext4/balloc.c
42431 @@ -436,8 +436,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
42432 /* Hm, nope. Are (enough) root reserved clusters available? */
42433 if (sbi->s_resuid == current_fsuid() ||
42434 ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
42435 - capable(CAP_SYS_RESOURCE) ||
42436 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
42437 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
42438 + capable_nolog(CAP_SYS_RESOURCE)) {
42439
42440 if (free_clusters >= (nclusters + dirty_clusters))
42441 return 1;
42442 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
42443 index 5b0e26a..0aa002d 100644
42444 --- a/fs/ext4/ext4.h
42445 +++ b/fs/ext4/ext4.h
42446 @@ -1208,19 +1208,19 @@ struct ext4_sb_info {
42447 unsigned long s_mb_last_start;
42448
42449 /* stats for buddy allocator */
42450 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
42451 - atomic_t s_bal_success; /* we found long enough chunks */
42452 - atomic_t s_bal_allocated; /* in blocks */
42453 - atomic_t s_bal_ex_scanned; /* total extents scanned */
42454 - atomic_t s_bal_goals; /* goal hits */
42455 - atomic_t s_bal_breaks; /* too long searches */
42456 - atomic_t s_bal_2orders; /* 2^order hits */
42457 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
42458 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
42459 + atomic_unchecked_t s_bal_allocated; /* in blocks */
42460 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
42461 + atomic_unchecked_t s_bal_goals; /* goal hits */
42462 + atomic_unchecked_t s_bal_breaks; /* too long searches */
42463 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
42464 spinlock_t s_bal_lock;
42465 unsigned long s_mb_buddies_generated;
42466 unsigned long long s_mb_generation_time;
42467 - atomic_t s_mb_lost_chunks;
42468 - atomic_t s_mb_preallocated;
42469 - atomic_t s_mb_discarded;
42470 + atomic_unchecked_t s_mb_lost_chunks;
42471 + atomic_unchecked_t s_mb_preallocated;
42472 + atomic_unchecked_t s_mb_discarded;
42473 atomic_t s_lock_busy;
42474
42475 /* locality groups */
42476 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
42477 index e2d8be8..c7f0ce9 100644
42478 --- a/fs/ext4/mballoc.c
42479 +++ b/fs/ext4/mballoc.c
42480 @@ -1794,7 +1794,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
42481 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
42482
42483 if (EXT4_SB(sb)->s_mb_stats)
42484 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
42485 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
42486
42487 break;
42488 }
42489 @@ -2088,7 +2088,7 @@ repeat:
42490 ac->ac_status = AC_STATUS_CONTINUE;
42491 ac->ac_flags |= EXT4_MB_HINT_FIRST;
42492 cr = 3;
42493 - atomic_inc(&sbi->s_mb_lost_chunks);
42494 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
42495 goto repeat;
42496 }
42497 }
42498 @@ -2592,25 +2592,25 @@ int ext4_mb_release(struct super_block *sb)
42499 if (sbi->s_mb_stats) {
42500 ext4_msg(sb, KERN_INFO,
42501 "mballoc: %u blocks %u reqs (%u success)",
42502 - atomic_read(&sbi->s_bal_allocated),
42503 - atomic_read(&sbi->s_bal_reqs),
42504 - atomic_read(&sbi->s_bal_success));
42505 + atomic_read_unchecked(&sbi->s_bal_allocated),
42506 + atomic_read_unchecked(&sbi->s_bal_reqs),
42507 + atomic_read_unchecked(&sbi->s_bal_success));
42508 ext4_msg(sb, KERN_INFO,
42509 "mballoc: %u extents scanned, %u goal hits, "
42510 "%u 2^N hits, %u breaks, %u lost",
42511 - atomic_read(&sbi->s_bal_ex_scanned),
42512 - atomic_read(&sbi->s_bal_goals),
42513 - atomic_read(&sbi->s_bal_2orders),
42514 - atomic_read(&sbi->s_bal_breaks),
42515 - atomic_read(&sbi->s_mb_lost_chunks));
42516 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
42517 + atomic_read_unchecked(&sbi->s_bal_goals),
42518 + atomic_read_unchecked(&sbi->s_bal_2orders),
42519 + atomic_read_unchecked(&sbi->s_bal_breaks),
42520 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
42521 ext4_msg(sb, KERN_INFO,
42522 "mballoc: %lu generated and it took %Lu",
42523 sbi->s_mb_buddies_generated,
42524 sbi->s_mb_generation_time);
42525 ext4_msg(sb, KERN_INFO,
42526 "mballoc: %u preallocated, %u discarded",
42527 - atomic_read(&sbi->s_mb_preallocated),
42528 - atomic_read(&sbi->s_mb_discarded));
42529 + atomic_read_unchecked(&sbi->s_mb_preallocated),
42530 + atomic_read_unchecked(&sbi->s_mb_discarded));
42531 }
42532
42533 free_percpu(sbi->s_locality_groups);
42534 @@ -3096,16 +3096,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
42535 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
42536
42537 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
42538 - atomic_inc(&sbi->s_bal_reqs);
42539 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42540 + atomic_inc_unchecked(&sbi->s_bal_reqs);
42541 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
42542 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
42543 - atomic_inc(&sbi->s_bal_success);
42544 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
42545 + atomic_inc_unchecked(&sbi->s_bal_success);
42546 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
42547 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
42548 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
42549 - atomic_inc(&sbi->s_bal_goals);
42550 + atomic_inc_unchecked(&sbi->s_bal_goals);
42551 if (ac->ac_found > sbi->s_mb_max_to_scan)
42552 - atomic_inc(&sbi->s_bal_breaks);
42553 + atomic_inc_unchecked(&sbi->s_bal_breaks);
42554 }
42555
42556 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
42557 @@ -3509,7 +3509,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
42558 trace_ext4_mb_new_inode_pa(ac, pa);
42559
42560 ext4_mb_use_inode_pa(ac, pa);
42561 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
42562 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
42563
42564 ei = EXT4_I(ac->ac_inode);
42565 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42566 @@ -3569,7 +3569,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
42567 trace_ext4_mb_new_group_pa(ac, pa);
42568
42569 ext4_mb_use_group_pa(ac, pa);
42570 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42571 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
42572
42573 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
42574 lg = ac->ac_lg;
42575 @@ -3658,7 +3658,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
42576 * from the bitmap and continue.
42577 */
42578 }
42579 - atomic_add(free, &sbi->s_mb_discarded);
42580 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
42581
42582 return err;
42583 }
42584 @@ -3676,7 +3676,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
42585 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
42586 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
42587 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
42588 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42589 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
42590 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
42591
42592 return 0;
42593 diff --git a/fs/fcntl.c b/fs/fcntl.c
42594 index 22764c7..86372c9 100644
42595 --- a/fs/fcntl.c
42596 +++ b/fs/fcntl.c
42597 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
42598 if (err)
42599 return err;
42600
42601 + if (gr_handle_chroot_fowner(pid, type))
42602 + return -ENOENT;
42603 + if (gr_check_protected_task_fowner(pid, type))
42604 + return -EACCES;
42605 +
42606 f_modown(filp, pid, type, force);
42607 return 0;
42608 }
42609 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
42610
42611 static int f_setown_ex(struct file *filp, unsigned long arg)
42612 {
42613 - struct f_owner_ex * __user owner_p = (void * __user)arg;
42614 + struct f_owner_ex __user *owner_p = (void __user *)arg;
42615 struct f_owner_ex owner;
42616 struct pid *pid;
42617 int type;
42618 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
42619
42620 static int f_getown_ex(struct file *filp, unsigned long arg)
42621 {
42622 - struct f_owner_ex * __user owner_p = (void * __user)arg;
42623 + struct f_owner_ex __user *owner_p = (void __user *)arg;
42624 struct f_owner_ex owner;
42625 int ret = 0;
42626
42627 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
42628 switch (cmd) {
42629 case F_DUPFD:
42630 case F_DUPFD_CLOEXEC:
42631 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
42632 if (arg >= rlimit(RLIMIT_NOFILE))
42633 break;
42634 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
42635 diff --git a/fs/fifo.c b/fs/fifo.c
42636 index b1a524d..4ee270e 100644
42637 --- a/fs/fifo.c
42638 +++ b/fs/fifo.c
42639 @@ -58,10 +58,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
42640 */
42641 filp->f_op = &read_pipefifo_fops;
42642 pipe->r_counter++;
42643 - if (pipe->readers++ == 0)
42644 + if (atomic_inc_return(&pipe->readers) == 1)
42645 wake_up_partner(inode);
42646
42647 - if (!pipe->writers) {
42648 + if (!atomic_read(&pipe->writers)) {
42649 if ((filp->f_flags & O_NONBLOCK)) {
42650 /* suppress POLLHUP until we have
42651 * seen a writer */
42652 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
42653 * errno=ENXIO when there is no process reading the FIFO.
42654 */
42655 ret = -ENXIO;
42656 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
42657 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
42658 goto err;
42659
42660 filp->f_op = &write_pipefifo_fops;
42661 pipe->w_counter++;
42662 - if (!pipe->writers++)
42663 + if (atomic_inc_return(&pipe->writers) == 1)
42664 wake_up_partner(inode);
42665
42666 - if (!pipe->readers) {
42667 + if (!atomic_read(&pipe->readers)) {
42668 wait_for_partner(inode, &pipe->r_counter);
42669 if (signal_pending(current))
42670 goto err_wr;
42671 @@ -105,11 +105,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
42672 */
42673 filp->f_op = &rdwr_pipefifo_fops;
42674
42675 - pipe->readers++;
42676 - pipe->writers++;
42677 + atomic_inc(&pipe->readers);
42678 + atomic_inc(&pipe->writers);
42679 pipe->r_counter++;
42680 pipe->w_counter++;
42681 - if (pipe->readers == 1 || pipe->writers == 1)
42682 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
42683 wake_up_partner(inode);
42684 break;
42685
42686 @@ -123,19 +123,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
42687 return 0;
42688
42689 err_rd:
42690 - if (!--pipe->readers)
42691 + if (atomic_dec_and_test(&pipe->readers))
42692 wake_up_interruptible(&pipe->wait);
42693 ret = -ERESTARTSYS;
42694 goto err;
42695
42696 err_wr:
42697 - if (!--pipe->writers)
42698 + if (atomic_dec_and_test(&pipe->writers))
42699 wake_up_interruptible(&pipe->wait);
42700 ret = -ERESTARTSYS;
42701 goto err;
42702
42703 err:
42704 - if (!pipe->readers && !pipe->writers)
42705 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
42706 free_pipe_info(inode);
42707
42708 err_nocleanup:
42709 diff --git a/fs/file.c b/fs/file.c
42710 index 4c6992d..104cdea 100644
42711 --- a/fs/file.c
42712 +++ b/fs/file.c
42713 @@ -15,6 +15,7 @@
42714 #include <linux/slab.h>
42715 #include <linux/vmalloc.h>
42716 #include <linux/file.h>
42717 +#include <linux/security.h>
42718 #include <linux/fdtable.h>
42719 #include <linux/bitops.h>
42720 #include <linux/interrupt.h>
42721 @@ -254,6 +255,7 @@ int expand_files(struct files_struct *files, int nr)
42722 * N.B. For clone tasks sharing a files structure, this test
42723 * will limit the total number of files that can be opened.
42724 */
42725 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
42726 if (nr >= rlimit(RLIMIT_NOFILE))
42727 return -EMFILE;
42728
42729 diff --git a/fs/filesystems.c b/fs/filesystems.c
42730 index 0845f84..7b4ebef 100644
42731 --- a/fs/filesystems.c
42732 +++ b/fs/filesystems.c
42733 @@ -274,7 +274,12 @@ struct file_system_type *get_fs_type(const char *name)
42734 int len = dot ? dot - name : strlen(name);
42735
42736 fs = __get_fs_type(name, len);
42737 +
42738 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
42739 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
42740 +#else
42741 if (!fs && (request_module("%.*s", len, name) == 0))
42742 +#endif
42743 fs = __get_fs_type(name, len);
42744
42745 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
42746 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
42747 index 78b519c..a8b4979 100644
42748 --- a/fs/fs_struct.c
42749 +++ b/fs/fs_struct.c
42750 @@ -4,6 +4,7 @@
42751 #include <linux/path.h>
42752 #include <linux/slab.h>
42753 #include <linux/fs_struct.h>
42754 +#include <linux/grsecurity.h>
42755 #include "internal.h"
42756
42757 static inline void path_get_longterm(struct path *path)
42758 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
42759 old_root = fs->root;
42760 fs->root = *path;
42761 path_get_longterm(path);
42762 + gr_set_chroot_entries(current, path);
42763 write_seqcount_end(&fs->seq);
42764 spin_unlock(&fs->lock);
42765 if (old_root.dentry)
42766 @@ -74,6 +76,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
42767 && fs->root.mnt == old_root->mnt) {
42768 path_get_longterm(new_root);
42769 fs->root = *new_root;
42770 + gr_set_chroot_entries(p, new_root);
42771 count++;
42772 }
42773 if (fs->pwd.dentry == old_root->dentry
42774 @@ -109,7 +112,8 @@ void exit_fs(struct task_struct *tsk)
42775 spin_lock(&fs->lock);
42776 write_seqcount_begin(&fs->seq);
42777 tsk->fs = NULL;
42778 - kill = !--fs->users;
42779 + gr_clear_chroot_entries(tsk);
42780 + kill = !atomic_dec_return(&fs->users);
42781 write_seqcount_end(&fs->seq);
42782 spin_unlock(&fs->lock);
42783 task_unlock(tsk);
42784 @@ -123,7 +127,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
42785 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
42786 /* We don't need to lock fs - think why ;-) */
42787 if (fs) {
42788 - fs->users = 1;
42789 + atomic_set(&fs->users, 1);
42790 fs->in_exec = 0;
42791 spin_lock_init(&fs->lock);
42792 seqcount_init(&fs->seq);
42793 @@ -132,6 +136,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
42794 spin_lock(&old->lock);
42795 fs->root = old->root;
42796 path_get_longterm(&fs->root);
42797 + /* instead of calling gr_set_chroot_entries here,
42798 + we call it from every caller of this function
42799 + */
42800 fs->pwd = old->pwd;
42801 path_get_longterm(&fs->pwd);
42802 spin_unlock(&old->lock);
42803 @@ -150,8 +157,9 @@ int unshare_fs_struct(void)
42804
42805 task_lock(current);
42806 spin_lock(&fs->lock);
42807 - kill = !--fs->users;
42808 + kill = !atomic_dec_return(&fs->users);
42809 current->fs = new_fs;
42810 + gr_set_chroot_entries(current, &new_fs->root);
42811 spin_unlock(&fs->lock);
42812 task_unlock(current);
42813
42814 @@ -164,13 +172,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
42815
42816 int current_umask(void)
42817 {
42818 - return current->fs->umask;
42819 + return current->fs->umask | gr_acl_umask();
42820 }
42821 EXPORT_SYMBOL(current_umask);
42822
42823 /* to be mentioned only in INIT_TASK */
42824 struct fs_struct init_fs = {
42825 - .users = 1,
42826 + .users = ATOMIC_INIT(1),
42827 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
42828 .seq = SEQCNT_ZERO,
42829 .umask = 0022,
42830 @@ -186,12 +194,13 @@ void daemonize_fs_struct(void)
42831 task_lock(current);
42832
42833 spin_lock(&init_fs.lock);
42834 - init_fs.users++;
42835 + atomic_inc(&init_fs.users);
42836 spin_unlock(&init_fs.lock);
42837
42838 spin_lock(&fs->lock);
42839 current->fs = &init_fs;
42840 - kill = !--fs->users;
42841 + gr_set_chroot_entries(current, &current->fs->root);
42842 + kill = !atomic_dec_return(&fs->users);
42843 spin_unlock(&fs->lock);
42844
42845 task_unlock(current);
42846 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
42847 index 9905350..02eaec4 100644
42848 --- a/fs/fscache/cookie.c
42849 +++ b/fs/fscache/cookie.c
42850 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
42851 parent ? (char *) parent->def->name : "<no-parent>",
42852 def->name, netfs_data);
42853
42854 - fscache_stat(&fscache_n_acquires);
42855 + fscache_stat_unchecked(&fscache_n_acquires);
42856
42857 /* if there's no parent cookie, then we don't create one here either */
42858 if (!parent) {
42859 - fscache_stat(&fscache_n_acquires_null);
42860 + fscache_stat_unchecked(&fscache_n_acquires_null);
42861 _leave(" [no parent]");
42862 return NULL;
42863 }
42864 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
42865 /* allocate and initialise a cookie */
42866 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
42867 if (!cookie) {
42868 - fscache_stat(&fscache_n_acquires_oom);
42869 + fscache_stat_unchecked(&fscache_n_acquires_oom);
42870 _leave(" [ENOMEM]");
42871 return NULL;
42872 }
42873 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
42874
42875 switch (cookie->def->type) {
42876 case FSCACHE_COOKIE_TYPE_INDEX:
42877 - fscache_stat(&fscache_n_cookie_index);
42878 + fscache_stat_unchecked(&fscache_n_cookie_index);
42879 break;
42880 case FSCACHE_COOKIE_TYPE_DATAFILE:
42881 - fscache_stat(&fscache_n_cookie_data);
42882 + fscache_stat_unchecked(&fscache_n_cookie_data);
42883 break;
42884 default:
42885 - fscache_stat(&fscache_n_cookie_special);
42886 + fscache_stat_unchecked(&fscache_n_cookie_special);
42887 break;
42888 }
42889
42890 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
42891 if (fscache_acquire_non_index_cookie(cookie) < 0) {
42892 atomic_dec(&parent->n_children);
42893 __fscache_cookie_put(cookie);
42894 - fscache_stat(&fscache_n_acquires_nobufs);
42895 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
42896 _leave(" = NULL");
42897 return NULL;
42898 }
42899 }
42900
42901 - fscache_stat(&fscache_n_acquires_ok);
42902 + fscache_stat_unchecked(&fscache_n_acquires_ok);
42903 _leave(" = %p", cookie);
42904 return cookie;
42905 }
42906 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
42907 cache = fscache_select_cache_for_object(cookie->parent);
42908 if (!cache) {
42909 up_read(&fscache_addremove_sem);
42910 - fscache_stat(&fscache_n_acquires_no_cache);
42911 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
42912 _leave(" = -ENOMEDIUM [no cache]");
42913 return -ENOMEDIUM;
42914 }
42915 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
42916 object = cache->ops->alloc_object(cache, cookie);
42917 fscache_stat_d(&fscache_n_cop_alloc_object);
42918 if (IS_ERR(object)) {
42919 - fscache_stat(&fscache_n_object_no_alloc);
42920 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
42921 ret = PTR_ERR(object);
42922 goto error;
42923 }
42924
42925 - fscache_stat(&fscache_n_object_alloc);
42926 + fscache_stat_unchecked(&fscache_n_object_alloc);
42927
42928 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
42929
42930 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
42931 struct fscache_object *object;
42932 struct hlist_node *_p;
42933
42934 - fscache_stat(&fscache_n_updates);
42935 + fscache_stat_unchecked(&fscache_n_updates);
42936
42937 if (!cookie) {
42938 - fscache_stat(&fscache_n_updates_null);
42939 + fscache_stat_unchecked(&fscache_n_updates_null);
42940 _leave(" [no cookie]");
42941 return;
42942 }
42943 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
42944 struct fscache_object *object;
42945 unsigned long event;
42946
42947 - fscache_stat(&fscache_n_relinquishes);
42948 + fscache_stat_unchecked(&fscache_n_relinquishes);
42949 if (retire)
42950 - fscache_stat(&fscache_n_relinquishes_retire);
42951 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
42952
42953 if (!cookie) {
42954 - fscache_stat(&fscache_n_relinquishes_null);
42955 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
42956 _leave(" [no cookie]");
42957 return;
42958 }
42959 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
42960
42961 /* wait for the cookie to finish being instantiated (or to fail) */
42962 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
42963 - fscache_stat(&fscache_n_relinquishes_waitcrt);
42964 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
42965 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
42966 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
42967 }
42968 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
42969 index f6aad48..88dcf26 100644
42970 --- a/fs/fscache/internal.h
42971 +++ b/fs/fscache/internal.h
42972 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
42973 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
42974 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
42975
42976 -extern atomic_t fscache_n_op_pend;
42977 -extern atomic_t fscache_n_op_run;
42978 -extern atomic_t fscache_n_op_enqueue;
42979 -extern atomic_t fscache_n_op_deferred_release;
42980 -extern atomic_t fscache_n_op_release;
42981 -extern atomic_t fscache_n_op_gc;
42982 -extern atomic_t fscache_n_op_cancelled;
42983 -extern atomic_t fscache_n_op_rejected;
42984 +extern atomic_unchecked_t fscache_n_op_pend;
42985 +extern atomic_unchecked_t fscache_n_op_run;
42986 +extern atomic_unchecked_t fscache_n_op_enqueue;
42987 +extern atomic_unchecked_t fscache_n_op_deferred_release;
42988 +extern atomic_unchecked_t fscache_n_op_release;
42989 +extern atomic_unchecked_t fscache_n_op_gc;
42990 +extern atomic_unchecked_t fscache_n_op_cancelled;
42991 +extern atomic_unchecked_t fscache_n_op_rejected;
42992
42993 -extern atomic_t fscache_n_attr_changed;
42994 -extern atomic_t fscache_n_attr_changed_ok;
42995 -extern atomic_t fscache_n_attr_changed_nobufs;
42996 -extern atomic_t fscache_n_attr_changed_nomem;
42997 -extern atomic_t fscache_n_attr_changed_calls;
42998 +extern atomic_unchecked_t fscache_n_attr_changed;
42999 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
43000 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
43001 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
43002 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
43003
43004 -extern atomic_t fscache_n_allocs;
43005 -extern atomic_t fscache_n_allocs_ok;
43006 -extern atomic_t fscache_n_allocs_wait;
43007 -extern atomic_t fscache_n_allocs_nobufs;
43008 -extern atomic_t fscache_n_allocs_intr;
43009 -extern atomic_t fscache_n_allocs_object_dead;
43010 -extern atomic_t fscache_n_alloc_ops;
43011 -extern atomic_t fscache_n_alloc_op_waits;
43012 +extern atomic_unchecked_t fscache_n_allocs;
43013 +extern atomic_unchecked_t fscache_n_allocs_ok;
43014 +extern atomic_unchecked_t fscache_n_allocs_wait;
43015 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
43016 +extern atomic_unchecked_t fscache_n_allocs_intr;
43017 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
43018 +extern atomic_unchecked_t fscache_n_alloc_ops;
43019 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
43020
43021 -extern atomic_t fscache_n_retrievals;
43022 -extern atomic_t fscache_n_retrievals_ok;
43023 -extern atomic_t fscache_n_retrievals_wait;
43024 -extern atomic_t fscache_n_retrievals_nodata;
43025 -extern atomic_t fscache_n_retrievals_nobufs;
43026 -extern atomic_t fscache_n_retrievals_intr;
43027 -extern atomic_t fscache_n_retrievals_nomem;
43028 -extern atomic_t fscache_n_retrievals_object_dead;
43029 -extern atomic_t fscache_n_retrieval_ops;
43030 -extern atomic_t fscache_n_retrieval_op_waits;
43031 +extern atomic_unchecked_t fscache_n_retrievals;
43032 +extern atomic_unchecked_t fscache_n_retrievals_ok;
43033 +extern atomic_unchecked_t fscache_n_retrievals_wait;
43034 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
43035 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
43036 +extern atomic_unchecked_t fscache_n_retrievals_intr;
43037 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
43038 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
43039 +extern atomic_unchecked_t fscache_n_retrieval_ops;
43040 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
43041
43042 -extern atomic_t fscache_n_stores;
43043 -extern atomic_t fscache_n_stores_ok;
43044 -extern atomic_t fscache_n_stores_again;
43045 -extern atomic_t fscache_n_stores_nobufs;
43046 -extern atomic_t fscache_n_stores_oom;
43047 -extern atomic_t fscache_n_store_ops;
43048 -extern atomic_t fscache_n_store_calls;
43049 -extern atomic_t fscache_n_store_pages;
43050 -extern atomic_t fscache_n_store_radix_deletes;
43051 -extern atomic_t fscache_n_store_pages_over_limit;
43052 +extern atomic_unchecked_t fscache_n_stores;
43053 +extern atomic_unchecked_t fscache_n_stores_ok;
43054 +extern atomic_unchecked_t fscache_n_stores_again;
43055 +extern atomic_unchecked_t fscache_n_stores_nobufs;
43056 +extern atomic_unchecked_t fscache_n_stores_oom;
43057 +extern atomic_unchecked_t fscache_n_store_ops;
43058 +extern atomic_unchecked_t fscache_n_store_calls;
43059 +extern atomic_unchecked_t fscache_n_store_pages;
43060 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
43061 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
43062
43063 -extern atomic_t fscache_n_store_vmscan_not_storing;
43064 -extern atomic_t fscache_n_store_vmscan_gone;
43065 -extern atomic_t fscache_n_store_vmscan_busy;
43066 -extern atomic_t fscache_n_store_vmscan_cancelled;
43067 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
43068 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
43069 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
43070 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
43071
43072 -extern atomic_t fscache_n_marks;
43073 -extern atomic_t fscache_n_uncaches;
43074 +extern atomic_unchecked_t fscache_n_marks;
43075 +extern atomic_unchecked_t fscache_n_uncaches;
43076
43077 -extern atomic_t fscache_n_acquires;
43078 -extern atomic_t fscache_n_acquires_null;
43079 -extern atomic_t fscache_n_acquires_no_cache;
43080 -extern atomic_t fscache_n_acquires_ok;
43081 -extern atomic_t fscache_n_acquires_nobufs;
43082 -extern atomic_t fscache_n_acquires_oom;
43083 +extern atomic_unchecked_t fscache_n_acquires;
43084 +extern atomic_unchecked_t fscache_n_acquires_null;
43085 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
43086 +extern atomic_unchecked_t fscache_n_acquires_ok;
43087 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
43088 +extern atomic_unchecked_t fscache_n_acquires_oom;
43089
43090 -extern atomic_t fscache_n_updates;
43091 -extern atomic_t fscache_n_updates_null;
43092 -extern atomic_t fscache_n_updates_run;
43093 +extern atomic_unchecked_t fscache_n_updates;
43094 +extern atomic_unchecked_t fscache_n_updates_null;
43095 +extern atomic_unchecked_t fscache_n_updates_run;
43096
43097 -extern atomic_t fscache_n_relinquishes;
43098 -extern atomic_t fscache_n_relinquishes_null;
43099 -extern atomic_t fscache_n_relinquishes_waitcrt;
43100 -extern atomic_t fscache_n_relinquishes_retire;
43101 +extern atomic_unchecked_t fscache_n_relinquishes;
43102 +extern atomic_unchecked_t fscache_n_relinquishes_null;
43103 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
43104 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
43105
43106 -extern atomic_t fscache_n_cookie_index;
43107 -extern atomic_t fscache_n_cookie_data;
43108 -extern atomic_t fscache_n_cookie_special;
43109 +extern atomic_unchecked_t fscache_n_cookie_index;
43110 +extern atomic_unchecked_t fscache_n_cookie_data;
43111 +extern atomic_unchecked_t fscache_n_cookie_special;
43112
43113 -extern atomic_t fscache_n_object_alloc;
43114 -extern atomic_t fscache_n_object_no_alloc;
43115 -extern atomic_t fscache_n_object_lookups;
43116 -extern atomic_t fscache_n_object_lookups_negative;
43117 -extern atomic_t fscache_n_object_lookups_positive;
43118 -extern atomic_t fscache_n_object_lookups_timed_out;
43119 -extern atomic_t fscache_n_object_created;
43120 -extern atomic_t fscache_n_object_avail;
43121 -extern atomic_t fscache_n_object_dead;
43122 +extern atomic_unchecked_t fscache_n_object_alloc;
43123 +extern atomic_unchecked_t fscache_n_object_no_alloc;
43124 +extern atomic_unchecked_t fscache_n_object_lookups;
43125 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
43126 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
43127 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
43128 +extern atomic_unchecked_t fscache_n_object_created;
43129 +extern atomic_unchecked_t fscache_n_object_avail;
43130 +extern atomic_unchecked_t fscache_n_object_dead;
43131
43132 -extern atomic_t fscache_n_checkaux_none;
43133 -extern atomic_t fscache_n_checkaux_okay;
43134 -extern atomic_t fscache_n_checkaux_update;
43135 -extern atomic_t fscache_n_checkaux_obsolete;
43136 +extern atomic_unchecked_t fscache_n_checkaux_none;
43137 +extern atomic_unchecked_t fscache_n_checkaux_okay;
43138 +extern atomic_unchecked_t fscache_n_checkaux_update;
43139 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
43140
43141 extern atomic_t fscache_n_cop_alloc_object;
43142 extern atomic_t fscache_n_cop_lookup_object;
43143 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
43144 atomic_inc(stat);
43145 }
43146
43147 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
43148 +{
43149 + atomic_inc_unchecked(stat);
43150 +}
43151 +
43152 static inline void fscache_stat_d(atomic_t *stat)
43153 {
43154 atomic_dec(stat);
43155 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
43156
43157 #define __fscache_stat(stat) (NULL)
43158 #define fscache_stat(stat) do {} while (0)
43159 +#define fscache_stat_unchecked(stat) do {} while (0)
43160 #define fscache_stat_d(stat) do {} while (0)
43161 #endif
43162
43163 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
43164 index b6b897c..0ffff9c 100644
43165 --- a/fs/fscache/object.c
43166 +++ b/fs/fscache/object.c
43167 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
43168 /* update the object metadata on disk */
43169 case FSCACHE_OBJECT_UPDATING:
43170 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
43171 - fscache_stat(&fscache_n_updates_run);
43172 + fscache_stat_unchecked(&fscache_n_updates_run);
43173 fscache_stat(&fscache_n_cop_update_object);
43174 object->cache->ops->update_object(object);
43175 fscache_stat_d(&fscache_n_cop_update_object);
43176 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
43177 spin_lock(&object->lock);
43178 object->state = FSCACHE_OBJECT_DEAD;
43179 spin_unlock(&object->lock);
43180 - fscache_stat(&fscache_n_object_dead);
43181 + fscache_stat_unchecked(&fscache_n_object_dead);
43182 goto terminal_transit;
43183
43184 /* handle the parent cache of this object being withdrawn from
43185 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
43186 spin_lock(&object->lock);
43187 object->state = FSCACHE_OBJECT_DEAD;
43188 spin_unlock(&object->lock);
43189 - fscache_stat(&fscache_n_object_dead);
43190 + fscache_stat_unchecked(&fscache_n_object_dead);
43191 goto terminal_transit;
43192
43193 /* complain about the object being woken up once it is
43194 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
43195 parent->cookie->def->name, cookie->def->name,
43196 object->cache->tag->name);
43197
43198 - fscache_stat(&fscache_n_object_lookups);
43199 + fscache_stat_unchecked(&fscache_n_object_lookups);
43200 fscache_stat(&fscache_n_cop_lookup_object);
43201 ret = object->cache->ops->lookup_object(object);
43202 fscache_stat_d(&fscache_n_cop_lookup_object);
43203 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
43204 if (ret == -ETIMEDOUT) {
43205 /* probably stuck behind another object, so move this one to
43206 * the back of the queue */
43207 - fscache_stat(&fscache_n_object_lookups_timed_out);
43208 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
43209 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
43210 }
43211
43212 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
43213
43214 spin_lock(&object->lock);
43215 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
43216 - fscache_stat(&fscache_n_object_lookups_negative);
43217 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
43218
43219 /* transit here to allow write requests to begin stacking up
43220 * and read requests to begin returning ENODATA */
43221 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
43222 * result, in which case there may be data available */
43223 spin_lock(&object->lock);
43224 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
43225 - fscache_stat(&fscache_n_object_lookups_positive);
43226 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
43227
43228 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
43229
43230 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
43231 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
43232 } else {
43233 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
43234 - fscache_stat(&fscache_n_object_created);
43235 + fscache_stat_unchecked(&fscache_n_object_created);
43236
43237 object->state = FSCACHE_OBJECT_AVAILABLE;
43238 spin_unlock(&object->lock);
43239 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
43240 fscache_enqueue_dependents(object);
43241
43242 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
43243 - fscache_stat(&fscache_n_object_avail);
43244 + fscache_stat_unchecked(&fscache_n_object_avail);
43245
43246 _leave("");
43247 }
43248 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
43249 enum fscache_checkaux result;
43250
43251 if (!object->cookie->def->check_aux) {
43252 - fscache_stat(&fscache_n_checkaux_none);
43253 + fscache_stat_unchecked(&fscache_n_checkaux_none);
43254 return FSCACHE_CHECKAUX_OKAY;
43255 }
43256
43257 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
43258 switch (result) {
43259 /* entry okay as is */
43260 case FSCACHE_CHECKAUX_OKAY:
43261 - fscache_stat(&fscache_n_checkaux_okay);
43262 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
43263 break;
43264
43265 /* entry requires update */
43266 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
43267 - fscache_stat(&fscache_n_checkaux_update);
43268 + fscache_stat_unchecked(&fscache_n_checkaux_update);
43269 break;
43270
43271 /* entry requires deletion */
43272 case FSCACHE_CHECKAUX_OBSOLETE:
43273 - fscache_stat(&fscache_n_checkaux_obsolete);
43274 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
43275 break;
43276
43277 default:
43278 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
43279 index 30afdfa..2256596 100644
43280 --- a/fs/fscache/operation.c
43281 +++ b/fs/fscache/operation.c
43282 @@ -17,7 +17,7 @@
43283 #include <linux/slab.h>
43284 #include "internal.h"
43285
43286 -atomic_t fscache_op_debug_id;
43287 +atomic_unchecked_t fscache_op_debug_id;
43288 EXPORT_SYMBOL(fscache_op_debug_id);
43289
43290 /**
43291 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
43292 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
43293 ASSERTCMP(atomic_read(&op->usage), >, 0);
43294
43295 - fscache_stat(&fscache_n_op_enqueue);
43296 + fscache_stat_unchecked(&fscache_n_op_enqueue);
43297 switch (op->flags & FSCACHE_OP_TYPE) {
43298 case FSCACHE_OP_ASYNC:
43299 _debug("queue async");
43300 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
43301 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
43302 if (op->processor)
43303 fscache_enqueue_operation(op);
43304 - fscache_stat(&fscache_n_op_run);
43305 + fscache_stat_unchecked(&fscache_n_op_run);
43306 }
43307
43308 /*
43309 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
43310 if (object->n_ops > 1) {
43311 atomic_inc(&op->usage);
43312 list_add_tail(&op->pend_link, &object->pending_ops);
43313 - fscache_stat(&fscache_n_op_pend);
43314 + fscache_stat_unchecked(&fscache_n_op_pend);
43315 } else if (!list_empty(&object->pending_ops)) {
43316 atomic_inc(&op->usage);
43317 list_add_tail(&op->pend_link, &object->pending_ops);
43318 - fscache_stat(&fscache_n_op_pend);
43319 + fscache_stat_unchecked(&fscache_n_op_pend);
43320 fscache_start_operations(object);
43321 } else {
43322 ASSERTCMP(object->n_in_progress, ==, 0);
43323 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
43324 object->n_exclusive++; /* reads and writes must wait */
43325 atomic_inc(&op->usage);
43326 list_add_tail(&op->pend_link, &object->pending_ops);
43327 - fscache_stat(&fscache_n_op_pend);
43328 + fscache_stat_unchecked(&fscache_n_op_pend);
43329 ret = 0;
43330 } else {
43331 /* not allowed to submit ops in any other state */
43332 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
43333 if (object->n_exclusive > 0) {
43334 atomic_inc(&op->usage);
43335 list_add_tail(&op->pend_link, &object->pending_ops);
43336 - fscache_stat(&fscache_n_op_pend);
43337 + fscache_stat_unchecked(&fscache_n_op_pend);
43338 } else if (!list_empty(&object->pending_ops)) {
43339 atomic_inc(&op->usage);
43340 list_add_tail(&op->pend_link, &object->pending_ops);
43341 - fscache_stat(&fscache_n_op_pend);
43342 + fscache_stat_unchecked(&fscache_n_op_pend);
43343 fscache_start_operations(object);
43344 } else {
43345 ASSERTCMP(object->n_exclusive, ==, 0);
43346 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
43347 object->n_ops++;
43348 atomic_inc(&op->usage);
43349 list_add_tail(&op->pend_link, &object->pending_ops);
43350 - fscache_stat(&fscache_n_op_pend);
43351 + fscache_stat_unchecked(&fscache_n_op_pend);
43352 ret = 0;
43353 } else if (object->state == FSCACHE_OBJECT_DYING ||
43354 object->state == FSCACHE_OBJECT_LC_DYING ||
43355 object->state == FSCACHE_OBJECT_WITHDRAWING) {
43356 - fscache_stat(&fscache_n_op_rejected);
43357 + fscache_stat_unchecked(&fscache_n_op_rejected);
43358 ret = -ENOBUFS;
43359 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
43360 fscache_report_unexpected_submission(object, op, ostate);
43361 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
43362
43363 ret = -EBUSY;
43364 if (!list_empty(&op->pend_link)) {
43365 - fscache_stat(&fscache_n_op_cancelled);
43366 + fscache_stat_unchecked(&fscache_n_op_cancelled);
43367 list_del_init(&op->pend_link);
43368 object->n_ops--;
43369 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
43370 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
43371 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
43372 BUG();
43373
43374 - fscache_stat(&fscache_n_op_release);
43375 + fscache_stat_unchecked(&fscache_n_op_release);
43376
43377 if (op->release) {
43378 op->release(op);
43379 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
43380 * lock, and defer it otherwise */
43381 if (!spin_trylock(&object->lock)) {
43382 _debug("defer put");
43383 - fscache_stat(&fscache_n_op_deferred_release);
43384 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
43385
43386 cache = object->cache;
43387 spin_lock(&cache->op_gc_list_lock);
43388 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
43389
43390 _debug("GC DEFERRED REL OBJ%x OP%x",
43391 object->debug_id, op->debug_id);
43392 - fscache_stat(&fscache_n_op_gc);
43393 + fscache_stat_unchecked(&fscache_n_op_gc);
43394
43395 ASSERTCMP(atomic_read(&op->usage), ==, 0);
43396
43397 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
43398 index 3f7a59b..cf196cc 100644
43399 --- a/fs/fscache/page.c
43400 +++ b/fs/fscache/page.c
43401 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
43402 val = radix_tree_lookup(&cookie->stores, page->index);
43403 if (!val) {
43404 rcu_read_unlock();
43405 - fscache_stat(&fscache_n_store_vmscan_not_storing);
43406 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
43407 __fscache_uncache_page(cookie, page);
43408 return true;
43409 }
43410 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
43411 spin_unlock(&cookie->stores_lock);
43412
43413 if (xpage) {
43414 - fscache_stat(&fscache_n_store_vmscan_cancelled);
43415 - fscache_stat(&fscache_n_store_radix_deletes);
43416 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
43417 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
43418 ASSERTCMP(xpage, ==, page);
43419 } else {
43420 - fscache_stat(&fscache_n_store_vmscan_gone);
43421 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
43422 }
43423
43424 wake_up_bit(&cookie->flags, 0);
43425 @@ -107,7 +107,7 @@ page_busy:
43426 /* we might want to wait here, but that could deadlock the allocator as
43427 * the work threads writing to the cache may all end up sleeping
43428 * on memory allocation */
43429 - fscache_stat(&fscache_n_store_vmscan_busy);
43430 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
43431 return false;
43432 }
43433 EXPORT_SYMBOL(__fscache_maybe_release_page);
43434 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
43435 FSCACHE_COOKIE_STORING_TAG);
43436 if (!radix_tree_tag_get(&cookie->stores, page->index,
43437 FSCACHE_COOKIE_PENDING_TAG)) {
43438 - fscache_stat(&fscache_n_store_radix_deletes);
43439 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
43440 xpage = radix_tree_delete(&cookie->stores, page->index);
43441 }
43442 spin_unlock(&cookie->stores_lock);
43443 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
43444
43445 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
43446
43447 - fscache_stat(&fscache_n_attr_changed_calls);
43448 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
43449
43450 if (fscache_object_is_active(object)) {
43451 fscache_stat(&fscache_n_cop_attr_changed);
43452 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43453
43454 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43455
43456 - fscache_stat(&fscache_n_attr_changed);
43457 + fscache_stat_unchecked(&fscache_n_attr_changed);
43458
43459 op = kzalloc(sizeof(*op), GFP_KERNEL);
43460 if (!op) {
43461 - fscache_stat(&fscache_n_attr_changed_nomem);
43462 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
43463 _leave(" = -ENOMEM");
43464 return -ENOMEM;
43465 }
43466 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43467 if (fscache_submit_exclusive_op(object, op) < 0)
43468 goto nobufs;
43469 spin_unlock(&cookie->lock);
43470 - fscache_stat(&fscache_n_attr_changed_ok);
43471 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
43472 fscache_put_operation(op);
43473 _leave(" = 0");
43474 return 0;
43475 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
43476 nobufs:
43477 spin_unlock(&cookie->lock);
43478 kfree(op);
43479 - fscache_stat(&fscache_n_attr_changed_nobufs);
43480 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
43481 _leave(" = %d", -ENOBUFS);
43482 return -ENOBUFS;
43483 }
43484 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
43485 /* allocate a retrieval operation and attempt to submit it */
43486 op = kzalloc(sizeof(*op), GFP_NOIO);
43487 if (!op) {
43488 - fscache_stat(&fscache_n_retrievals_nomem);
43489 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43490 return NULL;
43491 }
43492
43493 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
43494 return 0;
43495 }
43496
43497 - fscache_stat(&fscache_n_retrievals_wait);
43498 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
43499
43500 jif = jiffies;
43501 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
43502 fscache_wait_bit_interruptible,
43503 TASK_INTERRUPTIBLE) != 0) {
43504 - fscache_stat(&fscache_n_retrievals_intr);
43505 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43506 _leave(" = -ERESTARTSYS");
43507 return -ERESTARTSYS;
43508 }
43509 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
43510 */
43511 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43512 struct fscache_retrieval *op,
43513 - atomic_t *stat_op_waits,
43514 - atomic_t *stat_object_dead)
43515 + atomic_unchecked_t *stat_op_waits,
43516 + atomic_unchecked_t *stat_object_dead)
43517 {
43518 int ret;
43519
43520 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43521 goto check_if_dead;
43522
43523 _debug(">>> WT");
43524 - fscache_stat(stat_op_waits);
43525 + fscache_stat_unchecked(stat_op_waits);
43526 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
43527 fscache_wait_bit_interruptible,
43528 TASK_INTERRUPTIBLE) < 0) {
43529 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
43530
43531 check_if_dead:
43532 if (unlikely(fscache_object_is_dead(object))) {
43533 - fscache_stat(stat_object_dead);
43534 + fscache_stat_unchecked(stat_object_dead);
43535 return -ENOBUFS;
43536 }
43537 return 0;
43538 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43539
43540 _enter("%p,%p,,,", cookie, page);
43541
43542 - fscache_stat(&fscache_n_retrievals);
43543 + fscache_stat_unchecked(&fscache_n_retrievals);
43544
43545 if (hlist_empty(&cookie->backing_objects))
43546 goto nobufs;
43547 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43548 goto nobufs_unlock;
43549 spin_unlock(&cookie->lock);
43550
43551 - fscache_stat(&fscache_n_retrieval_ops);
43552 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
43553
43554 /* pin the netfs read context in case we need to do the actual netfs
43555 * read because we've encountered a cache read failure */
43556 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
43557
43558 error:
43559 if (ret == -ENOMEM)
43560 - fscache_stat(&fscache_n_retrievals_nomem);
43561 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43562 else if (ret == -ERESTARTSYS)
43563 - fscache_stat(&fscache_n_retrievals_intr);
43564 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43565 else if (ret == -ENODATA)
43566 - fscache_stat(&fscache_n_retrievals_nodata);
43567 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
43568 else if (ret < 0)
43569 - fscache_stat(&fscache_n_retrievals_nobufs);
43570 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43571 else
43572 - fscache_stat(&fscache_n_retrievals_ok);
43573 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
43574
43575 fscache_put_retrieval(op);
43576 _leave(" = %d", ret);
43577 @@ -429,7 +429,7 @@ nobufs_unlock:
43578 spin_unlock(&cookie->lock);
43579 kfree(op);
43580 nobufs:
43581 - fscache_stat(&fscache_n_retrievals_nobufs);
43582 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43583 _leave(" = -ENOBUFS");
43584 return -ENOBUFS;
43585 }
43586 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43587
43588 _enter("%p,,%d,,,", cookie, *nr_pages);
43589
43590 - fscache_stat(&fscache_n_retrievals);
43591 + fscache_stat_unchecked(&fscache_n_retrievals);
43592
43593 if (hlist_empty(&cookie->backing_objects))
43594 goto nobufs;
43595 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43596 goto nobufs_unlock;
43597 spin_unlock(&cookie->lock);
43598
43599 - fscache_stat(&fscache_n_retrieval_ops);
43600 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
43601
43602 /* pin the netfs read context in case we need to do the actual netfs
43603 * read because we've encountered a cache read failure */
43604 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
43605
43606 error:
43607 if (ret == -ENOMEM)
43608 - fscache_stat(&fscache_n_retrievals_nomem);
43609 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
43610 else if (ret == -ERESTARTSYS)
43611 - fscache_stat(&fscache_n_retrievals_intr);
43612 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
43613 else if (ret == -ENODATA)
43614 - fscache_stat(&fscache_n_retrievals_nodata);
43615 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
43616 else if (ret < 0)
43617 - fscache_stat(&fscache_n_retrievals_nobufs);
43618 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43619 else
43620 - fscache_stat(&fscache_n_retrievals_ok);
43621 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
43622
43623 fscache_put_retrieval(op);
43624 _leave(" = %d", ret);
43625 @@ -545,7 +545,7 @@ nobufs_unlock:
43626 spin_unlock(&cookie->lock);
43627 kfree(op);
43628 nobufs:
43629 - fscache_stat(&fscache_n_retrievals_nobufs);
43630 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
43631 _leave(" = -ENOBUFS");
43632 return -ENOBUFS;
43633 }
43634 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43635
43636 _enter("%p,%p,,,", cookie, page);
43637
43638 - fscache_stat(&fscache_n_allocs);
43639 + fscache_stat_unchecked(&fscache_n_allocs);
43640
43641 if (hlist_empty(&cookie->backing_objects))
43642 goto nobufs;
43643 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43644 goto nobufs_unlock;
43645 spin_unlock(&cookie->lock);
43646
43647 - fscache_stat(&fscache_n_alloc_ops);
43648 + fscache_stat_unchecked(&fscache_n_alloc_ops);
43649
43650 ret = fscache_wait_for_retrieval_activation(
43651 object, op,
43652 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
43653
43654 error:
43655 if (ret == -ERESTARTSYS)
43656 - fscache_stat(&fscache_n_allocs_intr);
43657 + fscache_stat_unchecked(&fscache_n_allocs_intr);
43658 else if (ret < 0)
43659 - fscache_stat(&fscache_n_allocs_nobufs);
43660 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43661 else
43662 - fscache_stat(&fscache_n_allocs_ok);
43663 + fscache_stat_unchecked(&fscache_n_allocs_ok);
43664
43665 fscache_put_retrieval(op);
43666 _leave(" = %d", ret);
43667 @@ -625,7 +625,7 @@ nobufs_unlock:
43668 spin_unlock(&cookie->lock);
43669 kfree(op);
43670 nobufs:
43671 - fscache_stat(&fscache_n_allocs_nobufs);
43672 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
43673 _leave(" = -ENOBUFS");
43674 return -ENOBUFS;
43675 }
43676 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43677
43678 spin_lock(&cookie->stores_lock);
43679
43680 - fscache_stat(&fscache_n_store_calls);
43681 + fscache_stat_unchecked(&fscache_n_store_calls);
43682
43683 /* find a page to store */
43684 page = NULL;
43685 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43686 page = results[0];
43687 _debug("gang %d [%lx]", n, page->index);
43688 if (page->index > op->store_limit) {
43689 - fscache_stat(&fscache_n_store_pages_over_limit);
43690 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
43691 goto superseded;
43692 }
43693
43694 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
43695 spin_unlock(&cookie->stores_lock);
43696 spin_unlock(&object->lock);
43697
43698 - fscache_stat(&fscache_n_store_pages);
43699 + fscache_stat_unchecked(&fscache_n_store_pages);
43700 fscache_stat(&fscache_n_cop_write_page);
43701 ret = object->cache->ops->write_page(op, page);
43702 fscache_stat_d(&fscache_n_cop_write_page);
43703 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43704 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43705 ASSERT(PageFsCache(page));
43706
43707 - fscache_stat(&fscache_n_stores);
43708 + fscache_stat_unchecked(&fscache_n_stores);
43709
43710 op = kzalloc(sizeof(*op), GFP_NOIO);
43711 if (!op)
43712 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43713 spin_unlock(&cookie->stores_lock);
43714 spin_unlock(&object->lock);
43715
43716 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
43717 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
43718 op->store_limit = object->store_limit;
43719
43720 if (fscache_submit_op(object, &op->op) < 0)
43721 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43722
43723 spin_unlock(&cookie->lock);
43724 radix_tree_preload_end();
43725 - fscache_stat(&fscache_n_store_ops);
43726 - fscache_stat(&fscache_n_stores_ok);
43727 + fscache_stat_unchecked(&fscache_n_store_ops);
43728 + fscache_stat_unchecked(&fscache_n_stores_ok);
43729
43730 /* the work queue now carries its own ref on the object */
43731 fscache_put_operation(&op->op);
43732 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
43733 return 0;
43734
43735 already_queued:
43736 - fscache_stat(&fscache_n_stores_again);
43737 + fscache_stat_unchecked(&fscache_n_stores_again);
43738 already_pending:
43739 spin_unlock(&cookie->stores_lock);
43740 spin_unlock(&object->lock);
43741 spin_unlock(&cookie->lock);
43742 radix_tree_preload_end();
43743 kfree(op);
43744 - fscache_stat(&fscache_n_stores_ok);
43745 + fscache_stat_unchecked(&fscache_n_stores_ok);
43746 _leave(" = 0");
43747 return 0;
43748
43749 @@ -851,14 +851,14 @@ nobufs:
43750 spin_unlock(&cookie->lock);
43751 radix_tree_preload_end();
43752 kfree(op);
43753 - fscache_stat(&fscache_n_stores_nobufs);
43754 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
43755 _leave(" = -ENOBUFS");
43756 return -ENOBUFS;
43757
43758 nomem_free:
43759 kfree(op);
43760 nomem:
43761 - fscache_stat(&fscache_n_stores_oom);
43762 + fscache_stat_unchecked(&fscache_n_stores_oom);
43763 _leave(" = -ENOMEM");
43764 return -ENOMEM;
43765 }
43766 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
43767 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
43768 ASSERTCMP(page, !=, NULL);
43769
43770 - fscache_stat(&fscache_n_uncaches);
43771 + fscache_stat_unchecked(&fscache_n_uncaches);
43772
43773 /* cache withdrawal may beat us to it */
43774 if (!PageFsCache(page))
43775 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
43776 unsigned long loop;
43777
43778 #ifdef CONFIG_FSCACHE_STATS
43779 - atomic_add(pagevec->nr, &fscache_n_marks);
43780 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
43781 #endif
43782
43783 for (loop = 0; loop < pagevec->nr; loop++) {
43784 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
43785 index 4765190..2a067f2 100644
43786 --- a/fs/fscache/stats.c
43787 +++ b/fs/fscache/stats.c
43788 @@ -18,95 +18,95 @@
43789 /*
43790 * operation counters
43791 */
43792 -atomic_t fscache_n_op_pend;
43793 -atomic_t fscache_n_op_run;
43794 -atomic_t fscache_n_op_enqueue;
43795 -atomic_t fscache_n_op_requeue;
43796 -atomic_t fscache_n_op_deferred_release;
43797 -atomic_t fscache_n_op_release;
43798 -atomic_t fscache_n_op_gc;
43799 -atomic_t fscache_n_op_cancelled;
43800 -atomic_t fscache_n_op_rejected;
43801 +atomic_unchecked_t fscache_n_op_pend;
43802 +atomic_unchecked_t fscache_n_op_run;
43803 +atomic_unchecked_t fscache_n_op_enqueue;
43804 +atomic_unchecked_t fscache_n_op_requeue;
43805 +atomic_unchecked_t fscache_n_op_deferred_release;
43806 +atomic_unchecked_t fscache_n_op_release;
43807 +atomic_unchecked_t fscache_n_op_gc;
43808 +atomic_unchecked_t fscache_n_op_cancelled;
43809 +atomic_unchecked_t fscache_n_op_rejected;
43810
43811 -atomic_t fscache_n_attr_changed;
43812 -atomic_t fscache_n_attr_changed_ok;
43813 -atomic_t fscache_n_attr_changed_nobufs;
43814 -atomic_t fscache_n_attr_changed_nomem;
43815 -atomic_t fscache_n_attr_changed_calls;
43816 +atomic_unchecked_t fscache_n_attr_changed;
43817 +atomic_unchecked_t fscache_n_attr_changed_ok;
43818 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
43819 +atomic_unchecked_t fscache_n_attr_changed_nomem;
43820 +atomic_unchecked_t fscache_n_attr_changed_calls;
43821
43822 -atomic_t fscache_n_allocs;
43823 -atomic_t fscache_n_allocs_ok;
43824 -atomic_t fscache_n_allocs_wait;
43825 -atomic_t fscache_n_allocs_nobufs;
43826 -atomic_t fscache_n_allocs_intr;
43827 -atomic_t fscache_n_allocs_object_dead;
43828 -atomic_t fscache_n_alloc_ops;
43829 -atomic_t fscache_n_alloc_op_waits;
43830 +atomic_unchecked_t fscache_n_allocs;
43831 +atomic_unchecked_t fscache_n_allocs_ok;
43832 +atomic_unchecked_t fscache_n_allocs_wait;
43833 +atomic_unchecked_t fscache_n_allocs_nobufs;
43834 +atomic_unchecked_t fscache_n_allocs_intr;
43835 +atomic_unchecked_t fscache_n_allocs_object_dead;
43836 +atomic_unchecked_t fscache_n_alloc_ops;
43837 +atomic_unchecked_t fscache_n_alloc_op_waits;
43838
43839 -atomic_t fscache_n_retrievals;
43840 -atomic_t fscache_n_retrievals_ok;
43841 -atomic_t fscache_n_retrievals_wait;
43842 -atomic_t fscache_n_retrievals_nodata;
43843 -atomic_t fscache_n_retrievals_nobufs;
43844 -atomic_t fscache_n_retrievals_intr;
43845 -atomic_t fscache_n_retrievals_nomem;
43846 -atomic_t fscache_n_retrievals_object_dead;
43847 -atomic_t fscache_n_retrieval_ops;
43848 -atomic_t fscache_n_retrieval_op_waits;
43849 +atomic_unchecked_t fscache_n_retrievals;
43850 +atomic_unchecked_t fscache_n_retrievals_ok;
43851 +atomic_unchecked_t fscache_n_retrievals_wait;
43852 +atomic_unchecked_t fscache_n_retrievals_nodata;
43853 +atomic_unchecked_t fscache_n_retrievals_nobufs;
43854 +atomic_unchecked_t fscache_n_retrievals_intr;
43855 +atomic_unchecked_t fscache_n_retrievals_nomem;
43856 +atomic_unchecked_t fscache_n_retrievals_object_dead;
43857 +atomic_unchecked_t fscache_n_retrieval_ops;
43858 +atomic_unchecked_t fscache_n_retrieval_op_waits;
43859
43860 -atomic_t fscache_n_stores;
43861 -atomic_t fscache_n_stores_ok;
43862 -atomic_t fscache_n_stores_again;
43863 -atomic_t fscache_n_stores_nobufs;
43864 -atomic_t fscache_n_stores_oom;
43865 -atomic_t fscache_n_store_ops;
43866 -atomic_t fscache_n_store_calls;
43867 -atomic_t fscache_n_store_pages;
43868 -atomic_t fscache_n_store_radix_deletes;
43869 -atomic_t fscache_n_store_pages_over_limit;
43870 +atomic_unchecked_t fscache_n_stores;
43871 +atomic_unchecked_t fscache_n_stores_ok;
43872 +atomic_unchecked_t fscache_n_stores_again;
43873 +atomic_unchecked_t fscache_n_stores_nobufs;
43874 +atomic_unchecked_t fscache_n_stores_oom;
43875 +atomic_unchecked_t fscache_n_store_ops;
43876 +atomic_unchecked_t fscache_n_store_calls;
43877 +atomic_unchecked_t fscache_n_store_pages;
43878 +atomic_unchecked_t fscache_n_store_radix_deletes;
43879 +atomic_unchecked_t fscache_n_store_pages_over_limit;
43880
43881 -atomic_t fscache_n_store_vmscan_not_storing;
43882 -atomic_t fscache_n_store_vmscan_gone;
43883 -atomic_t fscache_n_store_vmscan_busy;
43884 -atomic_t fscache_n_store_vmscan_cancelled;
43885 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
43886 +atomic_unchecked_t fscache_n_store_vmscan_gone;
43887 +atomic_unchecked_t fscache_n_store_vmscan_busy;
43888 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
43889
43890 -atomic_t fscache_n_marks;
43891 -atomic_t fscache_n_uncaches;
43892 +atomic_unchecked_t fscache_n_marks;
43893 +atomic_unchecked_t fscache_n_uncaches;
43894
43895 -atomic_t fscache_n_acquires;
43896 -atomic_t fscache_n_acquires_null;
43897 -atomic_t fscache_n_acquires_no_cache;
43898 -atomic_t fscache_n_acquires_ok;
43899 -atomic_t fscache_n_acquires_nobufs;
43900 -atomic_t fscache_n_acquires_oom;
43901 +atomic_unchecked_t fscache_n_acquires;
43902 +atomic_unchecked_t fscache_n_acquires_null;
43903 +atomic_unchecked_t fscache_n_acquires_no_cache;
43904 +atomic_unchecked_t fscache_n_acquires_ok;
43905 +atomic_unchecked_t fscache_n_acquires_nobufs;
43906 +atomic_unchecked_t fscache_n_acquires_oom;
43907
43908 -atomic_t fscache_n_updates;
43909 -atomic_t fscache_n_updates_null;
43910 -atomic_t fscache_n_updates_run;
43911 +atomic_unchecked_t fscache_n_updates;
43912 +atomic_unchecked_t fscache_n_updates_null;
43913 +atomic_unchecked_t fscache_n_updates_run;
43914
43915 -atomic_t fscache_n_relinquishes;
43916 -atomic_t fscache_n_relinquishes_null;
43917 -atomic_t fscache_n_relinquishes_waitcrt;
43918 -atomic_t fscache_n_relinquishes_retire;
43919 +atomic_unchecked_t fscache_n_relinquishes;
43920 +atomic_unchecked_t fscache_n_relinquishes_null;
43921 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
43922 +atomic_unchecked_t fscache_n_relinquishes_retire;
43923
43924 -atomic_t fscache_n_cookie_index;
43925 -atomic_t fscache_n_cookie_data;
43926 -atomic_t fscache_n_cookie_special;
43927 +atomic_unchecked_t fscache_n_cookie_index;
43928 +atomic_unchecked_t fscache_n_cookie_data;
43929 +atomic_unchecked_t fscache_n_cookie_special;
43930
43931 -atomic_t fscache_n_object_alloc;
43932 -atomic_t fscache_n_object_no_alloc;
43933 -atomic_t fscache_n_object_lookups;
43934 -atomic_t fscache_n_object_lookups_negative;
43935 -atomic_t fscache_n_object_lookups_positive;
43936 -atomic_t fscache_n_object_lookups_timed_out;
43937 -atomic_t fscache_n_object_created;
43938 -atomic_t fscache_n_object_avail;
43939 -atomic_t fscache_n_object_dead;
43940 +atomic_unchecked_t fscache_n_object_alloc;
43941 +atomic_unchecked_t fscache_n_object_no_alloc;
43942 +atomic_unchecked_t fscache_n_object_lookups;
43943 +atomic_unchecked_t fscache_n_object_lookups_negative;
43944 +atomic_unchecked_t fscache_n_object_lookups_positive;
43945 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
43946 +atomic_unchecked_t fscache_n_object_created;
43947 +atomic_unchecked_t fscache_n_object_avail;
43948 +atomic_unchecked_t fscache_n_object_dead;
43949
43950 -atomic_t fscache_n_checkaux_none;
43951 -atomic_t fscache_n_checkaux_okay;
43952 -atomic_t fscache_n_checkaux_update;
43953 -atomic_t fscache_n_checkaux_obsolete;
43954 +atomic_unchecked_t fscache_n_checkaux_none;
43955 +atomic_unchecked_t fscache_n_checkaux_okay;
43956 +atomic_unchecked_t fscache_n_checkaux_update;
43957 +atomic_unchecked_t fscache_n_checkaux_obsolete;
43958
43959 atomic_t fscache_n_cop_alloc_object;
43960 atomic_t fscache_n_cop_lookup_object;
43961 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
43962 seq_puts(m, "FS-Cache statistics\n");
43963
43964 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
43965 - atomic_read(&fscache_n_cookie_index),
43966 - atomic_read(&fscache_n_cookie_data),
43967 - atomic_read(&fscache_n_cookie_special));
43968 + atomic_read_unchecked(&fscache_n_cookie_index),
43969 + atomic_read_unchecked(&fscache_n_cookie_data),
43970 + atomic_read_unchecked(&fscache_n_cookie_special));
43971
43972 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
43973 - atomic_read(&fscache_n_object_alloc),
43974 - atomic_read(&fscache_n_object_no_alloc),
43975 - atomic_read(&fscache_n_object_avail),
43976 - atomic_read(&fscache_n_object_dead));
43977 + atomic_read_unchecked(&fscache_n_object_alloc),
43978 + atomic_read_unchecked(&fscache_n_object_no_alloc),
43979 + atomic_read_unchecked(&fscache_n_object_avail),
43980 + atomic_read_unchecked(&fscache_n_object_dead));
43981 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
43982 - atomic_read(&fscache_n_checkaux_none),
43983 - atomic_read(&fscache_n_checkaux_okay),
43984 - atomic_read(&fscache_n_checkaux_update),
43985 - atomic_read(&fscache_n_checkaux_obsolete));
43986 + atomic_read_unchecked(&fscache_n_checkaux_none),
43987 + atomic_read_unchecked(&fscache_n_checkaux_okay),
43988 + atomic_read_unchecked(&fscache_n_checkaux_update),
43989 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
43990
43991 seq_printf(m, "Pages : mrk=%u unc=%u\n",
43992 - atomic_read(&fscache_n_marks),
43993 - atomic_read(&fscache_n_uncaches));
43994 + atomic_read_unchecked(&fscache_n_marks),
43995 + atomic_read_unchecked(&fscache_n_uncaches));
43996
43997 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
43998 " oom=%u\n",
43999 - atomic_read(&fscache_n_acquires),
44000 - atomic_read(&fscache_n_acquires_null),
44001 - atomic_read(&fscache_n_acquires_no_cache),
44002 - atomic_read(&fscache_n_acquires_ok),
44003 - atomic_read(&fscache_n_acquires_nobufs),
44004 - atomic_read(&fscache_n_acquires_oom));
44005 + atomic_read_unchecked(&fscache_n_acquires),
44006 + atomic_read_unchecked(&fscache_n_acquires_null),
44007 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
44008 + atomic_read_unchecked(&fscache_n_acquires_ok),
44009 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
44010 + atomic_read_unchecked(&fscache_n_acquires_oom));
44011
44012 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
44013 - atomic_read(&fscache_n_object_lookups),
44014 - atomic_read(&fscache_n_object_lookups_negative),
44015 - atomic_read(&fscache_n_object_lookups_positive),
44016 - atomic_read(&fscache_n_object_created),
44017 - atomic_read(&fscache_n_object_lookups_timed_out));
44018 + atomic_read_unchecked(&fscache_n_object_lookups),
44019 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
44020 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
44021 + atomic_read_unchecked(&fscache_n_object_created),
44022 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
44023
44024 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
44025 - atomic_read(&fscache_n_updates),
44026 - atomic_read(&fscache_n_updates_null),
44027 - atomic_read(&fscache_n_updates_run));
44028 + atomic_read_unchecked(&fscache_n_updates),
44029 + atomic_read_unchecked(&fscache_n_updates_null),
44030 + atomic_read_unchecked(&fscache_n_updates_run));
44031
44032 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
44033 - atomic_read(&fscache_n_relinquishes),
44034 - atomic_read(&fscache_n_relinquishes_null),
44035 - atomic_read(&fscache_n_relinquishes_waitcrt),
44036 - atomic_read(&fscache_n_relinquishes_retire));
44037 + atomic_read_unchecked(&fscache_n_relinquishes),
44038 + atomic_read_unchecked(&fscache_n_relinquishes_null),
44039 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
44040 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
44041
44042 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
44043 - atomic_read(&fscache_n_attr_changed),
44044 - atomic_read(&fscache_n_attr_changed_ok),
44045 - atomic_read(&fscache_n_attr_changed_nobufs),
44046 - atomic_read(&fscache_n_attr_changed_nomem),
44047 - atomic_read(&fscache_n_attr_changed_calls));
44048 + atomic_read_unchecked(&fscache_n_attr_changed),
44049 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
44050 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
44051 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
44052 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
44053
44054 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
44055 - atomic_read(&fscache_n_allocs),
44056 - atomic_read(&fscache_n_allocs_ok),
44057 - atomic_read(&fscache_n_allocs_wait),
44058 - atomic_read(&fscache_n_allocs_nobufs),
44059 - atomic_read(&fscache_n_allocs_intr));
44060 + atomic_read_unchecked(&fscache_n_allocs),
44061 + atomic_read_unchecked(&fscache_n_allocs_ok),
44062 + atomic_read_unchecked(&fscache_n_allocs_wait),
44063 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
44064 + atomic_read_unchecked(&fscache_n_allocs_intr));
44065 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
44066 - atomic_read(&fscache_n_alloc_ops),
44067 - atomic_read(&fscache_n_alloc_op_waits),
44068 - atomic_read(&fscache_n_allocs_object_dead));
44069 + atomic_read_unchecked(&fscache_n_alloc_ops),
44070 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
44071 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
44072
44073 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
44074 " int=%u oom=%u\n",
44075 - atomic_read(&fscache_n_retrievals),
44076 - atomic_read(&fscache_n_retrievals_ok),
44077 - atomic_read(&fscache_n_retrievals_wait),
44078 - atomic_read(&fscache_n_retrievals_nodata),
44079 - atomic_read(&fscache_n_retrievals_nobufs),
44080 - atomic_read(&fscache_n_retrievals_intr),
44081 - atomic_read(&fscache_n_retrievals_nomem));
44082 + atomic_read_unchecked(&fscache_n_retrievals),
44083 + atomic_read_unchecked(&fscache_n_retrievals_ok),
44084 + atomic_read_unchecked(&fscache_n_retrievals_wait),
44085 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
44086 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
44087 + atomic_read_unchecked(&fscache_n_retrievals_intr),
44088 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
44089 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
44090 - atomic_read(&fscache_n_retrieval_ops),
44091 - atomic_read(&fscache_n_retrieval_op_waits),
44092 - atomic_read(&fscache_n_retrievals_object_dead));
44093 + atomic_read_unchecked(&fscache_n_retrieval_ops),
44094 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
44095 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
44096
44097 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
44098 - atomic_read(&fscache_n_stores),
44099 - atomic_read(&fscache_n_stores_ok),
44100 - atomic_read(&fscache_n_stores_again),
44101 - atomic_read(&fscache_n_stores_nobufs),
44102 - atomic_read(&fscache_n_stores_oom));
44103 + atomic_read_unchecked(&fscache_n_stores),
44104 + atomic_read_unchecked(&fscache_n_stores_ok),
44105 + atomic_read_unchecked(&fscache_n_stores_again),
44106 + atomic_read_unchecked(&fscache_n_stores_nobufs),
44107 + atomic_read_unchecked(&fscache_n_stores_oom));
44108 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
44109 - atomic_read(&fscache_n_store_ops),
44110 - atomic_read(&fscache_n_store_calls),
44111 - atomic_read(&fscache_n_store_pages),
44112 - atomic_read(&fscache_n_store_radix_deletes),
44113 - atomic_read(&fscache_n_store_pages_over_limit));
44114 + atomic_read_unchecked(&fscache_n_store_ops),
44115 + atomic_read_unchecked(&fscache_n_store_calls),
44116 + atomic_read_unchecked(&fscache_n_store_pages),
44117 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
44118 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
44119
44120 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
44121 - atomic_read(&fscache_n_store_vmscan_not_storing),
44122 - atomic_read(&fscache_n_store_vmscan_gone),
44123 - atomic_read(&fscache_n_store_vmscan_busy),
44124 - atomic_read(&fscache_n_store_vmscan_cancelled));
44125 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
44126 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
44127 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
44128 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
44129
44130 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
44131 - atomic_read(&fscache_n_op_pend),
44132 - atomic_read(&fscache_n_op_run),
44133 - atomic_read(&fscache_n_op_enqueue),
44134 - atomic_read(&fscache_n_op_cancelled),
44135 - atomic_read(&fscache_n_op_rejected));
44136 + atomic_read_unchecked(&fscache_n_op_pend),
44137 + atomic_read_unchecked(&fscache_n_op_run),
44138 + atomic_read_unchecked(&fscache_n_op_enqueue),
44139 + atomic_read_unchecked(&fscache_n_op_cancelled),
44140 + atomic_read_unchecked(&fscache_n_op_rejected));
44141 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
44142 - atomic_read(&fscache_n_op_deferred_release),
44143 - atomic_read(&fscache_n_op_release),
44144 - atomic_read(&fscache_n_op_gc));
44145 + atomic_read_unchecked(&fscache_n_op_deferred_release),
44146 + atomic_read_unchecked(&fscache_n_op_release),
44147 + atomic_read_unchecked(&fscache_n_op_gc));
44148
44149 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
44150 atomic_read(&fscache_n_cop_alloc_object),
44151 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
44152 index 3426521..3b75162 100644
44153 --- a/fs/fuse/cuse.c
44154 +++ b/fs/fuse/cuse.c
44155 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
44156 INIT_LIST_HEAD(&cuse_conntbl[i]);
44157
44158 /* inherit and extend fuse_dev_operations */
44159 - cuse_channel_fops = fuse_dev_operations;
44160 - cuse_channel_fops.owner = THIS_MODULE;
44161 - cuse_channel_fops.open = cuse_channel_open;
44162 - cuse_channel_fops.release = cuse_channel_release;
44163 + pax_open_kernel();
44164 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
44165 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
44166 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
44167 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
44168 + pax_close_kernel();
44169
44170 cuse_class = class_create(THIS_MODULE, "cuse");
44171 if (IS_ERR(cuse_class))
44172 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
44173 index 2aaf3ea..8e50863 100644
44174 --- a/fs/fuse/dev.c
44175 +++ b/fs/fuse/dev.c
44176 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
44177 ret = 0;
44178 pipe_lock(pipe);
44179
44180 - if (!pipe->readers) {
44181 + if (!atomic_read(&pipe->readers)) {
44182 send_sig(SIGPIPE, current, 0);
44183 if (!ret)
44184 ret = -EPIPE;
44185 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
44186 index 9f63e49..d8a64c0 100644
44187 --- a/fs/fuse/dir.c
44188 +++ b/fs/fuse/dir.c
44189 @@ -1147,7 +1147,7 @@ static char *read_link(struct dentry *dentry)
44190 return link;
44191 }
44192
44193 -static void free_link(char *link)
44194 +static void free_link(const char *link)
44195 {
44196 if (!IS_ERR(link))
44197 free_page((unsigned long) link);
44198 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
44199 index cfd4959..a780959 100644
44200 --- a/fs/gfs2/inode.c
44201 +++ b/fs/gfs2/inode.c
44202 @@ -1490,7 +1490,7 @@ out:
44203
44204 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44205 {
44206 - char *s = nd_get_link(nd);
44207 + const char *s = nd_get_link(nd);
44208 if (!IS_ERR(s))
44209 kfree(s);
44210 }
44211 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
44212 index 0be5a78..9cfb853 100644
44213 --- a/fs/hugetlbfs/inode.c
44214 +++ b/fs/hugetlbfs/inode.c
44215 @@ -915,7 +915,7 @@ static struct file_system_type hugetlbfs_fs_type = {
44216 .kill_sb = kill_litter_super,
44217 };
44218
44219 -static struct vfsmount *hugetlbfs_vfsmount;
44220 +struct vfsmount *hugetlbfs_vfsmount;
44221
44222 static int can_do_hugetlb_shm(void)
44223 {
44224 diff --git a/fs/inode.c b/fs/inode.c
44225 index ee4e66b..0451521 100644
44226 --- a/fs/inode.c
44227 +++ b/fs/inode.c
44228 @@ -787,8 +787,8 @@ unsigned int get_next_ino(void)
44229
44230 #ifdef CONFIG_SMP
44231 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
44232 - static atomic_t shared_last_ino;
44233 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
44234 + static atomic_unchecked_t shared_last_ino;
44235 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
44236
44237 res = next - LAST_INO_BATCH;
44238 }
44239 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
44240 index e513f19..2ab1351 100644
44241 --- a/fs/jffs2/erase.c
44242 +++ b/fs/jffs2/erase.c
44243 @@ -439,7 +439,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
44244 struct jffs2_unknown_node marker = {
44245 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
44246 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
44247 - .totlen = cpu_to_je32(c->cleanmarker_size)
44248 + .totlen = cpu_to_je32(c->cleanmarker_size),
44249 + .hdr_crc = cpu_to_je32(0)
44250 };
44251
44252 jffs2_prealloc_raw_node_refs(c, jeb, 1);
44253 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
44254 index b09e51d..e482afa 100644
44255 --- a/fs/jffs2/wbuf.c
44256 +++ b/fs/jffs2/wbuf.c
44257 @@ -1011,7 +1011,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
44258 {
44259 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
44260 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
44261 - .totlen = constant_cpu_to_je32(8)
44262 + .totlen = constant_cpu_to_je32(8),
44263 + .hdr_crc = constant_cpu_to_je32(0)
44264 };
44265
44266 /*
44267 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
44268 index a44eff0..462e07d 100644
44269 --- a/fs/jfs/super.c
44270 +++ b/fs/jfs/super.c
44271 @@ -802,7 +802,7 @@ static int __init init_jfs_fs(void)
44272
44273 jfs_inode_cachep =
44274 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
44275 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
44276 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
44277 init_once);
44278 if (jfs_inode_cachep == NULL)
44279 return -ENOMEM;
44280 diff --git a/fs/libfs.c b/fs/libfs.c
44281 index f6d411e..e82a08d 100644
44282 --- a/fs/libfs.c
44283 +++ b/fs/libfs.c
44284 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
44285
44286 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
44287 struct dentry *next;
44288 + char d_name[sizeof(next->d_iname)];
44289 + const unsigned char *name;
44290 +
44291 next = list_entry(p, struct dentry, d_u.d_child);
44292 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
44293 if (!simple_positive(next)) {
44294 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
44295
44296 spin_unlock(&next->d_lock);
44297 spin_unlock(&dentry->d_lock);
44298 - if (filldir(dirent, next->d_name.name,
44299 + name = next->d_name.name;
44300 + if (name == next->d_iname) {
44301 + memcpy(d_name, name, next->d_name.len);
44302 + name = d_name;
44303 + }
44304 + if (filldir(dirent, name,
44305 next->d_name.len, filp->f_pos,
44306 next->d_inode->i_ino,
44307 dt_type(next->d_inode)) < 0)
44308 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
44309 index 8392cb8..80d6193 100644
44310 --- a/fs/lockd/clntproc.c
44311 +++ b/fs/lockd/clntproc.c
44312 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
44313 /*
44314 * Cookie counter for NLM requests
44315 */
44316 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
44317 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
44318
44319 void nlmclnt_next_cookie(struct nlm_cookie *c)
44320 {
44321 - u32 cookie = atomic_inc_return(&nlm_cookie);
44322 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
44323
44324 memcpy(c->data, &cookie, 4);
44325 c->len=4;
44326 diff --git a/fs/locks.c b/fs/locks.c
44327 index 637694b..f84a121 100644
44328 --- a/fs/locks.c
44329 +++ b/fs/locks.c
44330 @@ -2074,16 +2074,16 @@ void locks_remove_flock(struct file *filp)
44331 return;
44332
44333 if (filp->f_op && filp->f_op->flock) {
44334 - struct file_lock fl = {
44335 + struct file_lock flock = {
44336 .fl_pid = current->tgid,
44337 .fl_file = filp,
44338 .fl_flags = FL_FLOCK,
44339 .fl_type = F_UNLCK,
44340 .fl_end = OFFSET_MAX,
44341 };
44342 - filp->f_op->flock(filp, F_SETLKW, &fl);
44343 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
44344 - fl.fl_ops->fl_release_private(&fl);
44345 + filp->f_op->flock(filp, F_SETLKW, &flock);
44346 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
44347 + flock.fl_ops->fl_release_private(&flock);
44348 }
44349
44350 lock_flocks();
44351 diff --git a/fs/namei.c b/fs/namei.c
44352 index 5008f01..90328a7 100644
44353 --- a/fs/namei.c
44354 +++ b/fs/namei.c
44355 @@ -279,16 +279,32 @@ int generic_permission(struct inode *inode, int mask)
44356 if (ret != -EACCES)
44357 return ret;
44358
44359 +#ifdef CONFIG_GRKERNSEC
44360 + /* we'll block if we have to log due to a denied capability use */
44361 + if (mask & MAY_NOT_BLOCK)
44362 + return -ECHILD;
44363 +#endif
44364 +
44365 if (S_ISDIR(inode->i_mode)) {
44366 /* DACs are overridable for directories */
44367 - if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44368 - return 0;
44369 if (!(mask & MAY_WRITE))
44370 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44371 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
44372 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44373 return 0;
44374 + if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44375 + return 0;
44376 return -EACCES;
44377 }
44378 /*
44379 + * Searching includes executable on directories, else just read.
44380 + */
44381 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44382 + if (mask == MAY_READ)
44383 + if (ns_capable_nolog(inode_userns(inode), CAP_DAC_OVERRIDE) ||
44384 + ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44385 + return 0;
44386 +
44387 + /*
44388 * Read/write DACs are always overridable.
44389 * Executable DACs are overridable when there is
44390 * at least one exec bit set.
44391 @@ -297,14 +313,6 @@ int generic_permission(struct inode *inode, int mask)
44392 if (ns_capable(inode_userns(inode), CAP_DAC_OVERRIDE))
44393 return 0;
44394
44395 - /*
44396 - * Searching includes executable on directories, else just read.
44397 - */
44398 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
44399 - if (mask == MAY_READ)
44400 - if (ns_capable(inode_userns(inode), CAP_DAC_READ_SEARCH))
44401 - return 0;
44402 -
44403 return -EACCES;
44404 }
44405
44406 @@ -653,11 +661,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
44407 return error;
44408 }
44409
44410 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
44411 + dentry->d_inode, dentry, nd->path.mnt)) {
44412 + error = -EACCES;
44413 + *p = ERR_PTR(error); /* no ->put_link(), please */
44414 + path_put(&nd->path);
44415 + return error;
44416 + }
44417 +
44418 nd->last_type = LAST_BIND;
44419 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
44420 error = PTR_ERR(*p);
44421 if (!IS_ERR(*p)) {
44422 - char *s = nd_get_link(nd);
44423 + const char *s = nd_get_link(nd);
44424 error = 0;
44425 if (s)
44426 error = __vfs_follow_link(nd, s);
44427 @@ -1622,6 +1638,21 @@ static int path_lookupat(int dfd, const char *name,
44428 if (!err)
44429 err = complete_walk(nd);
44430
44431 + if (!(nd->flags & LOOKUP_PARENT)) {
44432 +#ifdef CONFIG_GRKERNSEC
44433 + if (flags & LOOKUP_RCU) {
44434 + if (!err)
44435 + path_put(&nd->path);
44436 + err = -ECHILD;
44437 + } else
44438 +#endif
44439 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44440 + if (!err)
44441 + path_put(&nd->path);
44442 + err = -ENOENT;
44443 + }
44444 + }
44445 +
44446 if (!err && nd->flags & LOOKUP_DIRECTORY) {
44447 if (!nd->inode->i_op->lookup) {
44448 path_put(&nd->path);
44449 @@ -1649,6 +1680,15 @@ static int do_path_lookup(int dfd, const char *name,
44450 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
44451
44452 if (likely(!retval)) {
44453 + if (*name != '/' && nd->path.dentry && nd->inode) {
44454 +#ifdef CONFIG_GRKERNSEC
44455 + if (flags & LOOKUP_RCU)
44456 + return -ECHILD;
44457 +#endif
44458 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
44459 + return -ENOENT;
44460 + }
44461 +
44462 if (unlikely(!audit_dummy_context())) {
44463 if (nd->path.dentry && nd->inode)
44464 audit_inode(name, nd->path.dentry);
44465 @@ -2046,6 +2086,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
44466 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
44467 return -EPERM;
44468
44469 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
44470 + return -EPERM;
44471 + if (gr_handle_rawio(inode))
44472 + return -EPERM;
44473 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
44474 + return -EACCES;
44475 +
44476 return 0;
44477 }
44478
44479 @@ -2107,6 +2154,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44480 error = complete_walk(nd);
44481 if (error)
44482 return ERR_PTR(error);
44483 +#ifdef CONFIG_GRKERNSEC
44484 + if (nd->flags & LOOKUP_RCU) {
44485 + error = -ECHILD;
44486 + goto exit;
44487 + }
44488 +#endif
44489 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44490 + error = -ENOENT;
44491 + goto exit;
44492 + }
44493 audit_inode(pathname, nd->path.dentry);
44494 if (open_flag & O_CREAT) {
44495 error = -EISDIR;
44496 @@ -2117,6 +2174,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44497 error = complete_walk(nd);
44498 if (error)
44499 return ERR_PTR(error);
44500 +#ifdef CONFIG_GRKERNSEC
44501 + if (nd->flags & LOOKUP_RCU) {
44502 + error = -ECHILD;
44503 + goto exit;
44504 + }
44505 +#endif
44506 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
44507 + error = -ENOENT;
44508 + goto exit;
44509 + }
44510 audit_inode(pathname, dir);
44511 goto ok;
44512 }
44513 @@ -2138,6 +2205,16 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44514 error = complete_walk(nd);
44515 if (error)
44516 return ERR_PTR(-ECHILD);
44517 +#ifdef CONFIG_GRKERNSEC
44518 + if (nd->flags & LOOKUP_RCU) {
44519 + error = -ECHILD;
44520 + goto exit;
44521 + }
44522 +#endif
44523 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
44524 + error = -ENOENT;
44525 + goto exit;
44526 + }
44527
44528 error = -ENOTDIR;
44529 if (nd->flags & LOOKUP_DIRECTORY) {
44530 @@ -2178,6 +2255,12 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44531 /* Negative dentry, just create the file */
44532 if (!dentry->d_inode) {
44533 int mode = op->mode;
44534 +
44535 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
44536 + error = -EACCES;
44537 + goto exit_mutex_unlock;
44538 + }
44539 +
44540 if (!IS_POSIXACL(dir->d_inode))
44541 mode &= ~current_umask();
44542 /*
44543 @@ -2201,6 +2284,8 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44544 error = vfs_create(dir->d_inode, dentry, mode, nd);
44545 if (error)
44546 goto exit_mutex_unlock;
44547 + else
44548 + gr_handle_create(path->dentry, path->mnt);
44549 mutex_unlock(&dir->d_inode->i_mutex);
44550 dput(nd->path.dentry);
44551 nd->path.dentry = dentry;
44552 @@ -2210,6 +2295,19 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
44553 /*
44554 * It already exists.
44555 */
44556 +
44557 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
44558 + error = -ENOENT;
44559 + goto exit_mutex_unlock;
44560 + }
44561 +
44562 + /* only check if O_CREAT is specified, all other checks need to go
44563 + into may_open */
44564 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
44565 + error = -EACCES;
44566 + goto exit_mutex_unlock;
44567 + }
44568 +
44569 mutex_unlock(&dir->d_inode->i_mutex);
44570 audit_inode(pathname, path->dentry);
44571
44572 @@ -2422,6 +2520,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
44573 *path = nd.path;
44574 return dentry;
44575 eexist:
44576 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
44577 + dput(dentry);
44578 + dentry = ERR_PTR(-ENOENT);
44579 + goto fail;
44580 + }
44581 dput(dentry);
44582 dentry = ERR_PTR(-EEXIST);
44583 fail:
44584 @@ -2444,6 +2547,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
44585 }
44586 EXPORT_SYMBOL(user_path_create);
44587
44588 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
44589 +{
44590 + char *tmp = getname(pathname);
44591 + struct dentry *res;
44592 + if (IS_ERR(tmp))
44593 + return ERR_CAST(tmp);
44594 + res = kern_path_create(dfd, tmp, path, is_dir);
44595 + if (IS_ERR(res))
44596 + putname(tmp);
44597 + else
44598 + *to = tmp;
44599 + return res;
44600 +}
44601 +
44602 int vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t dev)
44603 {
44604 int error = may_create(dir, dentry);
44605 @@ -2511,6 +2628,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
44606 error = mnt_want_write(path.mnt);
44607 if (error)
44608 goto out_dput;
44609 +
44610 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
44611 + error = -EPERM;
44612 + goto out_drop_write;
44613 + }
44614 +
44615 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
44616 + error = -EACCES;
44617 + goto out_drop_write;
44618 + }
44619 +
44620 error = security_path_mknod(&path, dentry, mode, dev);
44621 if (error)
44622 goto out_drop_write;
44623 @@ -2528,6 +2656,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
44624 }
44625 out_drop_write:
44626 mnt_drop_write(path.mnt);
44627 +
44628 + if (!error)
44629 + gr_handle_create(dentry, path.mnt);
44630 out_dput:
44631 dput(dentry);
44632 mutex_unlock(&path.dentry->d_inode->i_mutex);
44633 @@ -2577,12 +2708,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
44634 error = mnt_want_write(path.mnt);
44635 if (error)
44636 goto out_dput;
44637 +
44638 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
44639 + error = -EACCES;
44640 + goto out_drop_write;
44641 + }
44642 +
44643 error = security_path_mkdir(&path, dentry, mode);
44644 if (error)
44645 goto out_drop_write;
44646 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
44647 out_drop_write:
44648 mnt_drop_write(path.mnt);
44649 +
44650 + if (!error)
44651 + gr_handle_create(dentry, path.mnt);
44652 out_dput:
44653 dput(dentry);
44654 mutex_unlock(&path.dentry->d_inode->i_mutex);
44655 @@ -2662,6 +2802,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
44656 char * name;
44657 struct dentry *dentry;
44658 struct nameidata nd;
44659 + ino_t saved_ino = 0;
44660 + dev_t saved_dev = 0;
44661
44662 error = user_path_parent(dfd, pathname, &nd, &name);
44663 if (error)
44664 @@ -2690,6 +2832,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
44665 error = -ENOENT;
44666 goto exit3;
44667 }
44668 +
44669 + saved_ino = dentry->d_inode->i_ino;
44670 + saved_dev = gr_get_dev_from_dentry(dentry);
44671 +
44672 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
44673 + error = -EACCES;
44674 + goto exit3;
44675 + }
44676 +
44677 error = mnt_want_write(nd.path.mnt);
44678 if (error)
44679 goto exit3;
44680 @@ -2697,6 +2848,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
44681 if (error)
44682 goto exit4;
44683 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
44684 + if (!error && (saved_dev || saved_ino))
44685 + gr_handle_delete(saved_ino, saved_dev);
44686 exit4:
44687 mnt_drop_write(nd.path.mnt);
44688 exit3:
44689 @@ -2759,6 +2912,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44690 struct dentry *dentry;
44691 struct nameidata nd;
44692 struct inode *inode = NULL;
44693 + ino_t saved_ino = 0;
44694 + dev_t saved_dev = 0;
44695
44696 error = user_path_parent(dfd, pathname, &nd, &name);
44697 if (error)
44698 @@ -2781,6 +2936,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44699 if (!inode)
44700 goto slashes;
44701 ihold(inode);
44702 +
44703 + if (inode->i_nlink <= 1) {
44704 + saved_ino = inode->i_ino;
44705 + saved_dev = gr_get_dev_from_dentry(dentry);
44706 + }
44707 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
44708 + error = -EACCES;
44709 + goto exit2;
44710 + }
44711 +
44712 error = mnt_want_write(nd.path.mnt);
44713 if (error)
44714 goto exit2;
44715 @@ -2788,6 +2953,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
44716 if (error)
44717 goto exit3;
44718 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
44719 + if (!error && (saved_ino || saved_dev))
44720 + gr_handle_delete(saved_ino, saved_dev);
44721 exit3:
44722 mnt_drop_write(nd.path.mnt);
44723 exit2:
44724 @@ -2863,10 +3030,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
44725 error = mnt_want_write(path.mnt);
44726 if (error)
44727 goto out_dput;
44728 +
44729 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
44730 + error = -EACCES;
44731 + goto out_drop_write;
44732 + }
44733 +
44734 error = security_path_symlink(&path, dentry, from);
44735 if (error)
44736 goto out_drop_write;
44737 error = vfs_symlink(path.dentry->d_inode, dentry, from);
44738 + if (!error)
44739 + gr_handle_create(dentry, path.mnt);
44740 out_drop_write:
44741 mnt_drop_write(path.mnt);
44742 out_dput:
44743 @@ -2938,6 +3113,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44744 {
44745 struct dentry *new_dentry;
44746 struct path old_path, new_path;
44747 + char *to = NULL;
44748 int how = 0;
44749 int error;
44750
44751 @@ -2961,7 +3137,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44752 if (error)
44753 return error;
44754
44755 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
44756 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
44757 error = PTR_ERR(new_dentry);
44758 if (IS_ERR(new_dentry))
44759 goto out;
44760 @@ -2972,13 +3148,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
44761 error = mnt_want_write(new_path.mnt);
44762 if (error)
44763 goto out_dput;
44764 +
44765 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
44766 + old_path.dentry->d_inode,
44767 + old_path.dentry->d_inode->i_mode, to)) {
44768 + error = -EACCES;
44769 + goto out_drop_write;
44770 + }
44771 +
44772 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
44773 + old_path.dentry, old_path.mnt, to)) {
44774 + error = -EACCES;
44775 + goto out_drop_write;
44776 + }
44777 +
44778 error = security_path_link(old_path.dentry, &new_path, new_dentry);
44779 if (error)
44780 goto out_drop_write;
44781 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
44782 + if (!error)
44783 + gr_handle_create(new_dentry, new_path.mnt);
44784 out_drop_write:
44785 mnt_drop_write(new_path.mnt);
44786 out_dput:
44787 + putname(to);
44788 dput(new_dentry);
44789 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
44790 path_put(&new_path);
44791 @@ -3206,6 +3399,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
44792 if (new_dentry == trap)
44793 goto exit5;
44794
44795 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
44796 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
44797 + to);
44798 + if (error)
44799 + goto exit5;
44800 +
44801 error = mnt_want_write(oldnd.path.mnt);
44802 if (error)
44803 goto exit5;
44804 @@ -3215,6 +3414,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
44805 goto exit6;
44806 error = vfs_rename(old_dir->d_inode, old_dentry,
44807 new_dir->d_inode, new_dentry);
44808 + if (!error)
44809 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
44810 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
44811 exit6:
44812 mnt_drop_write(oldnd.path.mnt);
44813 exit5:
44814 @@ -3240,6 +3442,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
44815
44816 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
44817 {
44818 + char tmpbuf[64];
44819 + const char *newlink;
44820 int len;
44821
44822 len = PTR_ERR(link);
44823 @@ -3249,7 +3453,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
44824 len = strlen(link);
44825 if (len > (unsigned) buflen)
44826 len = buflen;
44827 - if (copy_to_user(buffer, link, len))
44828 +
44829 + if (len < sizeof(tmpbuf)) {
44830 + memcpy(tmpbuf, link, len);
44831 + newlink = tmpbuf;
44832 + } else
44833 + newlink = link;
44834 +
44835 + if (copy_to_user(buffer, newlink, len))
44836 len = -EFAULT;
44837 out:
44838 return len;
44839 diff --git a/fs/namespace.c b/fs/namespace.c
44840 index cfc6d44..b4632a5 100644
44841 --- a/fs/namespace.c
44842 +++ b/fs/namespace.c
44843 @@ -1326,6 +1326,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
44844 if (!(sb->s_flags & MS_RDONLY))
44845 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
44846 up_write(&sb->s_umount);
44847 +
44848 + gr_log_remount(mnt->mnt_devname, retval);
44849 +
44850 return retval;
44851 }
44852
44853 @@ -1345,6 +1348,9 @@ static int do_umount(struct vfsmount *mnt, int flags)
44854 br_write_unlock(vfsmount_lock);
44855 up_write(&namespace_sem);
44856 release_mounts(&umount_list);
44857 +
44858 + gr_log_unmount(mnt->mnt_devname, retval);
44859 +
44860 return retval;
44861 }
44862
44863 @@ -2336,6 +2342,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
44864 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
44865 MS_STRICTATIME);
44866
44867 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
44868 + retval = -EPERM;
44869 + goto dput_out;
44870 + }
44871 +
44872 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
44873 + retval = -EPERM;
44874 + goto dput_out;
44875 + }
44876 +
44877 if (flags & MS_REMOUNT)
44878 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
44879 data_page);
44880 @@ -2350,6 +2366,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
44881 dev_name, data_page);
44882 dput_out:
44883 path_put(&path);
44884 +
44885 + gr_log_mount(dev_name, dir_name, retval);
44886 +
44887 return retval;
44888 }
44889
44890 @@ -2605,6 +2624,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
44891 if (error)
44892 goto out2;
44893
44894 + if (gr_handle_chroot_pivot()) {
44895 + error = -EPERM;
44896 + goto out2;
44897 + }
44898 +
44899 get_fs_root(current->fs, &root);
44900 error = lock_mount(&old);
44901 if (error)
44902 diff --git a/fs/nfs/blocklayout/blocklayout.c b/fs/nfs/blocklayout/blocklayout.c
44903 index 3db6b82..a57597e 100644
44904 --- a/fs/nfs/blocklayout/blocklayout.c
44905 +++ b/fs/nfs/blocklayout/blocklayout.c
44906 @@ -90,7 +90,7 @@ static int is_writable(struct pnfs_block_extent *be, sector_t isect)
44907 */
44908 struct parallel_io {
44909 struct kref refcnt;
44910 - struct rpc_call_ops call_ops;
44911 + rpc_call_ops_no_const call_ops;
44912 void (*pnfs_callback) (void *data);
44913 void *data;
44914 };
44915 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
44916 index 50a15fa..ca113f9 100644
44917 --- a/fs/nfs/inode.c
44918 +++ b/fs/nfs/inode.c
44919 @@ -150,7 +150,7 @@ static void nfs_zap_caches_locked(struct inode *inode)
44920 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
44921 nfsi->attrtimeo_timestamp = jiffies;
44922
44923 - memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_COOKIEVERF(inode)));
44924 + memset(NFS_COOKIEVERF(inode), 0, sizeof(NFS_I(inode)->cookieverf));
44925 if (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode))
44926 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA|NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL|NFS_INO_REVAL_PAGECACHE;
44927 else
44928 @@ -1002,16 +1002,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
44929 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
44930 }
44931
44932 -static atomic_long_t nfs_attr_generation_counter;
44933 +static atomic_long_unchecked_t nfs_attr_generation_counter;
44934
44935 static unsigned long nfs_read_attr_generation_counter(void)
44936 {
44937 - return atomic_long_read(&nfs_attr_generation_counter);
44938 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
44939 }
44940
44941 unsigned long nfs_inc_attr_generation_counter(void)
44942 {
44943 - return atomic_long_inc_return(&nfs_attr_generation_counter);
44944 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
44945 }
44946
44947 void nfs_fattr_init(struct nfs_fattr *fattr)
44948 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
44949 index 7a2e442..8e544cc 100644
44950 --- a/fs/nfsd/vfs.c
44951 +++ b/fs/nfsd/vfs.c
44952 @@ -914,7 +914,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
44953 } else {
44954 oldfs = get_fs();
44955 set_fs(KERNEL_DS);
44956 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
44957 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
44958 set_fs(oldfs);
44959 }
44960
44961 @@ -1018,7 +1018,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
44962
44963 /* Write the data. */
44964 oldfs = get_fs(); set_fs(KERNEL_DS);
44965 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
44966 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
44967 set_fs(oldfs);
44968 if (host_err < 0)
44969 goto out_nfserr;
44970 @@ -1553,7 +1553,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
44971 */
44972
44973 oldfs = get_fs(); set_fs(KERNEL_DS);
44974 - host_err = inode->i_op->readlink(dentry, buf, *lenp);
44975 + host_err = inode->i_op->readlink(dentry, (char __force_user *)buf, *lenp);
44976 set_fs(oldfs);
44977
44978 if (host_err < 0)
44979 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
44980 index 9fde1c0..14e8827 100644
44981 --- a/fs/notify/fanotify/fanotify_user.c
44982 +++ b/fs/notify/fanotify/fanotify_user.c
44983 @@ -276,7 +276,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
44984 goto out_close_fd;
44985
44986 ret = -EFAULT;
44987 - if (copy_to_user(buf, &fanotify_event_metadata,
44988 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
44989 + copy_to_user(buf, &fanotify_event_metadata,
44990 fanotify_event_metadata.event_len))
44991 goto out_kill_access_response;
44992
44993 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
44994 index ee18815..7aa5d01 100644
44995 --- a/fs/notify/notification.c
44996 +++ b/fs/notify/notification.c
44997 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
44998 * get set to 0 so it will never get 'freed'
44999 */
45000 static struct fsnotify_event *q_overflow_event;
45001 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
45002 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
45003
45004 /**
45005 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
45006 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
45007 */
45008 u32 fsnotify_get_cookie(void)
45009 {
45010 - return atomic_inc_return(&fsnotify_sync_cookie);
45011 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
45012 }
45013 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
45014
45015 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
45016 index 99e3610..02c1068 100644
45017 --- a/fs/ntfs/dir.c
45018 +++ b/fs/ntfs/dir.c
45019 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
45020 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
45021 ~(s64)(ndir->itype.index.block_size - 1)));
45022 /* Bounds checks. */
45023 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
45024 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
45025 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
45026 "inode 0x%lx or driver bug.", vdir->i_ino);
45027 goto err_out;
45028 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
45029 index c587e2d..3641eaa 100644
45030 --- a/fs/ntfs/file.c
45031 +++ b/fs/ntfs/file.c
45032 @@ -2229,6 +2229,6 @@ const struct inode_operations ntfs_file_inode_ops = {
45033 #endif /* NTFS_RW */
45034 };
45035
45036 -const struct file_operations ntfs_empty_file_ops = {};
45037 +const struct file_operations ntfs_empty_file_ops __read_only;
45038
45039 -const struct inode_operations ntfs_empty_inode_ops = {};
45040 +const struct inode_operations ntfs_empty_inode_ops __read_only;
45041 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
45042 index 210c352..a174f83 100644
45043 --- a/fs/ocfs2/localalloc.c
45044 +++ b/fs/ocfs2/localalloc.c
45045 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
45046 goto bail;
45047 }
45048
45049 - atomic_inc(&osb->alloc_stats.moves);
45050 + atomic_inc_unchecked(&osb->alloc_stats.moves);
45051
45052 bail:
45053 if (handle)
45054 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
45055 index d355e6e..578d905 100644
45056 --- a/fs/ocfs2/ocfs2.h
45057 +++ b/fs/ocfs2/ocfs2.h
45058 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
45059
45060 struct ocfs2_alloc_stats
45061 {
45062 - atomic_t moves;
45063 - atomic_t local_data;
45064 - atomic_t bitmap_data;
45065 - atomic_t bg_allocs;
45066 - atomic_t bg_extends;
45067 + atomic_unchecked_t moves;
45068 + atomic_unchecked_t local_data;
45069 + atomic_unchecked_t bitmap_data;
45070 + atomic_unchecked_t bg_allocs;
45071 + atomic_unchecked_t bg_extends;
45072 };
45073
45074 enum ocfs2_local_alloc_state
45075 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
45076 index ba5d97e..c77db25 100644
45077 --- a/fs/ocfs2/suballoc.c
45078 +++ b/fs/ocfs2/suballoc.c
45079 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
45080 mlog_errno(status);
45081 goto bail;
45082 }
45083 - atomic_inc(&osb->alloc_stats.bg_extends);
45084 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
45085
45086 /* You should never ask for this much metadata */
45087 BUG_ON(bits_wanted >
45088 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
45089 mlog_errno(status);
45090 goto bail;
45091 }
45092 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45093 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45094
45095 *suballoc_loc = res.sr_bg_blkno;
45096 *suballoc_bit_start = res.sr_bit_offset;
45097 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
45098 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
45099 res->sr_bits);
45100
45101 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45102 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45103
45104 BUG_ON(res->sr_bits != 1);
45105
45106 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
45107 mlog_errno(status);
45108 goto bail;
45109 }
45110 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45111 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
45112
45113 BUG_ON(res.sr_bits != 1);
45114
45115 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
45116 cluster_start,
45117 num_clusters);
45118 if (!status)
45119 - atomic_inc(&osb->alloc_stats.local_data);
45120 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
45121 } else {
45122 if (min_clusters > (osb->bitmap_cpg - 1)) {
45123 /* The only paths asking for contiguousness
45124 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
45125 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
45126 res.sr_bg_blkno,
45127 res.sr_bit_offset);
45128 - atomic_inc(&osb->alloc_stats.bitmap_data);
45129 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
45130 *num_clusters = res.sr_bits;
45131 }
45132 }
45133 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
45134 index 4994f8b..eaab8eb 100644
45135 --- a/fs/ocfs2/super.c
45136 +++ b/fs/ocfs2/super.c
45137 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
45138 "%10s => GlobalAllocs: %d LocalAllocs: %d "
45139 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
45140 "Stats",
45141 - atomic_read(&osb->alloc_stats.bitmap_data),
45142 - atomic_read(&osb->alloc_stats.local_data),
45143 - atomic_read(&osb->alloc_stats.bg_allocs),
45144 - atomic_read(&osb->alloc_stats.moves),
45145 - atomic_read(&osb->alloc_stats.bg_extends));
45146 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
45147 + atomic_read_unchecked(&osb->alloc_stats.local_data),
45148 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
45149 + atomic_read_unchecked(&osb->alloc_stats.moves),
45150 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
45151
45152 out += snprintf(buf + out, len - out,
45153 "%10s => State: %u Descriptor: %llu Size: %u bits "
45154 @@ -2119,11 +2119,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
45155 spin_lock_init(&osb->osb_xattr_lock);
45156 ocfs2_init_steal_slots(osb);
45157
45158 - atomic_set(&osb->alloc_stats.moves, 0);
45159 - atomic_set(&osb->alloc_stats.local_data, 0);
45160 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
45161 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
45162 - atomic_set(&osb->alloc_stats.bg_extends, 0);
45163 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
45164 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
45165 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
45166 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
45167 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
45168
45169 /* Copy the blockcheck stats from the superblock probe */
45170 osb->osb_ecc_stats = *stats;
45171 diff --git a/fs/ocfs2/symlink.c b/fs/ocfs2/symlink.c
45172 index 5d22872..523db20 100644
45173 --- a/fs/ocfs2/symlink.c
45174 +++ b/fs/ocfs2/symlink.c
45175 @@ -142,7 +142,7 @@ bail:
45176
45177 static void ocfs2_fast_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
45178 {
45179 - char *link = nd_get_link(nd);
45180 + const char *link = nd_get_link(nd);
45181 if (!IS_ERR(link))
45182 kfree(link);
45183 }
45184 diff --git a/fs/open.c b/fs/open.c
45185 index 22c41b5..78894cf 100644
45186 --- a/fs/open.c
45187 +++ b/fs/open.c
45188 @@ -112,6 +112,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
45189 error = locks_verify_truncate(inode, NULL, length);
45190 if (!error)
45191 error = security_path_truncate(&path);
45192 +
45193 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
45194 + error = -EACCES;
45195 +
45196 if (!error)
45197 error = do_truncate(path.dentry, length, 0, NULL);
45198
45199 @@ -358,6 +362,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
45200 if (__mnt_is_readonly(path.mnt))
45201 res = -EROFS;
45202
45203 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
45204 + res = -EACCES;
45205 +
45206 out_path_release:
45207 path_put(&path);
45208 out:
45209 @@ -384,6 +391,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
45210 if (error)
45211 goto dput_and_out;
45212
45213 + gr_log_chdir(path.dentry, path.mnt);
45214 +
45215 set_fs_pwd(current->fs, &path);
45216
45217 dput_and_out:
45218 @@ -410,6 +419,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
45219 goto out_putf;
45220
45221 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
45222 +
45223 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
45224 + error = -EPERM;
45225 +
45226 + if (!error)
45227 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
45228 +
45229 if (!error)
45230 set_fs_pwd(current->fs, &file->f_path);
45231 out_putf:
45232 @@ -438,7 +454,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
45233 if (error)
45234 goto dput_and_out;
45235
45236 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
45237 + goto dput_and_out;
45238 +
45239 set_fs_root(current->fs, &path);
45240 +
45241 + gr_handle_chroot_chdir(&path);
45242 +
45243 error = 0;
45244 dput_and_out:
45245 path_put(&path);
45246 @@ -456,6 +478,16 @@ static int chmod_common(struct path *path, umode_t mode)
45247 if (error)
45248 return error;
45249 mutex_lock(&inode->i_mutex);
45250 +
45251 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
45252 + error = -EACCES;
45253 + goto out_unlock;
45254 + }
45255 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
45256 + error = -EACCES;
45257 + goto out_unlock;
45258 + }
45259 +
45260 error = security_path_chmod(path->dentry, path->mnt, mode);
45261 if (error)
45262 goto out_unlock;
45263 @@ -506,6 +538,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
45264 int error;
45265 struct iattr newattrs;
45266
45267 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
45268 + return -EACCES;
45269 +
45270 newattrs.ia_valid = ATTR_CTIME;
45271 if (user != (uid_t) -1) {
45272 newattrs.ia_valid |= ATTR_UID;
45273 diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
45274 index 6296b40..417c00f 100644
45275 --- a/fs/partitions/efi.c
45276 +++ b/fs/partitions/efi.c
45277 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
45278 if (!gpt)
45279 return NULL;
45280
45281 + if (!le32_to_cpu(gpt->num_partition_entries))
45282 + return NULL;
45283 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
45284 + if (!pte)
45285 + return NULL;
45286 +
45287 count = le32_to_cpu(gpt->num_partition_entries) *
45288 le32_to_cpu(gpt->sizeof_partition_entry);
45289 - if (!count)
45290 - return NULL;
45291 - pte = kzalloc(count, GFP_KERNEL);
45292 - if (!pte)
45293 - return NULL;
45294 -
45295 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
45296 (u8 *) pte,
45297 count) < count) {
45298 diff --git a/fs/partitions/ldm.c b/fs/partitions/ldm.c
45299 index bd8ae78..539d250 100644
45300 --- a/fs/partitions/ldm.c
45301 +++ b/fs/partitions/ldm.c
45302 @@ -1324,7 +1324,7 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags)
45303 goto found;
45304 }
45305
45306 - f = kmalloc (sizeof (*f) + size*num, GFP_KERNEL);
45307 + f = kmalloc (size*num + sizeof (*f), GFP_KERNEL);
45308 if (!f) {
45309 ldm_crit ("Out of memory.");
45310 return false;
45311 diff --git a/fs/pipe.c b/fs/pipe.c
45312 index 4065f07..68c0706 100644
45313 --- a/fs/pipe.c
45314 +++ b/fs/pipe.c
45315 @@ -420,9 +420,9 @@ redo:
45316 }
45317 if (bufs) /* More to do? */
45318 continue;
45319 - if (!pipe->writers)
45320 + if (!atomic_read(&pipe->writers))
45321 break;
45322 - if (!pipe->waiting_writers) {
45323 + if (!atomic_read(&pipe->waiting_writers)) {
45324 /* syscall merging: Usually we must not sleep
45325 * if O_NONBLOCK is set, or if we got some data.
45326 * But if a writer sleeps in kernel space, then
45327 @@ -481,7 +481,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
45328 mutex_lock(&inode->i_mutex);
45329 pipe = inode->i_pipe;
45330
45331 - if (!pipe->readers) {
45332 + if (!atomic_read(&pipe->readers)) {
45333 send_sig(SIGPIPE, current, 0);
45334 ret = -EPIPE;
45335 goto out;
45336 @@ -530,7 +530,7 @@ redo1:
45337 for (;;) {
45338 int bufs;
45339
45340 - if (!pipe->readers) {
45341 + if (!atomic_read(&pipe->readers)) {
45342 send_sig(SIGPIPE, current, 0);
45343 if (!ret)
45344 ret = -EPIPE;
45345 @@ -616,9 +616,9 @@ redo2:
45346 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45347 do_wakeup = 0;
45348 }
45349 - pipe->waiting_writers++;
45350 + atomic_inc(&pipe->waiting_writers);
45351 pipe_wait(pipe);
45352 - pipe->waiting_writers--;
45353 + atomic_dec(&pipe->waiting_writers);
45354 }
45355 out:
45356 mutex_unlock(&inode->i_mutex);
45357 @@ -685,7 +685,7 @@ pipe_poll(struct file *filp, poll_table *wait)
45358 mask = 0;
45359 if (filp->f_mode & FMODE_READ) {
45360 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
45361 - if (!pipe->writers && filp->f_version != pipe->w_counter)
45362 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
45363 mask |= POLLHUP;
45364 }
45365
45366 @@ -695,7 +695,7 @@ pipe_poll(struct file *filp, poll_table *wait)
45367 * Most Unices do not set POLLERR for FIFOs but on Linux they
45368 * behave exactly like pipes for poll().
45369 */
45370 - if (!pipe->readers)
45371 + if (!atomic_read(&pipe->readers))
45372 mask |= POLLERR;
45373 }
45374
45375 @@ -709,10 +709,10 @@ pipe_release(struct inode *inode, int decr, int decw)
45376
45377 mutex_lock(&inode->i_mutex);
45378 pipe = inode->i_pipe;
45379 - pipe->readers -= decr;
45380 - pipe->writers -= decw;
45381 + atomic_sub(decr, &pipe->readers);
45382 + atomic_sub(decw, &pipe->writers);
45383
45384 - if (!pipe->readers && !pipe->writers) {
45385 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
45386 free_pipe_info(inode);
45387 } else {
45388 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
45389 @@ -802,7 +802,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
45390
45391 if (inode->i_pipe) {
45392 ret = 0;
45393 - inode->i_pipe->readers++;
45394 + atomic_inc(&inode->i_pipe->readers);
45395 }
45396
45397 mutex_unlock(&inode->i_mutex);
45398 @@ -819,7 +819,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
45399
45400 if (inode->i_pipe) {
45401 ret = 0;
45402 - inode->i_pipe->writers++;
45403 + atomic_inc(&inode->i_pipe->writers);
45404 }
45405
45406 mutex_unlock(&inode->i_mutex);
45407 @@ -837,9 +837,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
45408 if (inode->i_pipe) {
45409 ret = 0;
45410 if (filp->f_mode & FMODE_READ)
45411 - inode->i_pipe->readers++;
45412 + atomic_inc(&inode->i_pipe->readers);
45413 if (filp->f_mode & FMODE_WRITE)
45414 - inode->i_pipe->writers++;
45415 + atomic_inc(&inode->i_pipe->writers);
45416 }
45417
45418 mutex_unlock(&inode->i_mutex);
45419 @@ -931,7 +931,7 @@ void free_pipe_info(struct inode *inode)
45420 inode->i_pipe = NULL;
45421 }
45422
45423 -static struct vfsmount *pipe_mnt __read_mostly;
45424 +struct vfsmount *pipe_mnt __read_mostly;
45425
45426 /*
45427 * pipefs_dname() is called from d_path().
45428 @@ -961,7 +961,8 @@ static struct inode * get_pipe_inode(void)
45429 goto fail_iput;
45430 inode->i_pipe = pipe;
45431
45432 - pipe->readers = pipe->writers = 1;
45433 + atomic_set(&pipe->readers, 1);
45434 + atomic_set(&pipe->writers, 1);
45435 inode->i_fop = &rdwr_pipefifo_fops;
45436
45437 /*
45438 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
45439 index 15af622..0e9f4467 100644
45440 --- a/fs/proc/Kconfig
45441 +++ b/fs/proc/Kconfig
45442 @@ -30,12 +30,12 @@ config PROC_FS
45443
45444 config PROC_KCORE
45445 bool "/proc/kcore support" if !ARM
45446 - depends on PROC_FS && MMU
45447 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
45448
45449 config PROC_VMCORE
45450 bool "/proc/vmcore support"
45451 - depends on PROC_FS && CRASH_DUMP
45452 - default y
45453 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
45454 + default n
45455 help
45456 Exports the dump image of crashed kernel in ELF format.
45457
45458 @@ -59,8 +59,8 @@ config PROC_SYSCTL
45459 limited in memory.
45460
45461 config PROC_PAGE_MONITOR
45462 - default y
45463 - depends on PROC_FS && MMU
45464 + default n
45465 + depends on PROC_FS && MMU && !GRKERNSEC
45466 bool "Enable /proc page monitoring" if EXPERT
45467 help
45468 Various /proc files exist to monitor process memory utilization:
45469 diff --git a/fs/proc/array.c b/fs/proc/array.c
45470 index 3a1dafd..1456746 100644
45471 --- a/fs/proc/array.c
45472 +++ b/fs/proc/array.c
45473 @@ -60,6 +60,7 @@
45474 #include <linux/tty.h>
45475 #include <linux/string.h>
45476 #include <linux/mman.h>
45477 +#include <linux/grsecurity.h>
45478 #include <linux/proc_fs.h>
45479 #include <linux/ioport.h>
45480 #include <linux/uaccess.h>
45481 @@ -337,6 +338,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
45482 seq_putc(m, '\n');
45483 }
45484
45485 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45486 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
45487 +{
45488 + if (p->mm)
45489 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
45490 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
45491 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
45492 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
45493 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
45494 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
45495 + else
45496 + seq_printf(m, "PaX:\t-----\n");
45497 +}
45498 +#endif
45499 +
45500 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45501 struct pid *pid, struct task_struct *task)
45502 {
45503 @@ -354,9 +370,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
45504 task_cpus_allowed(m, task);
45505 cpuset_task_status_allowed(m, task);
45506 task_context_switch_counts(m, task);
45507 +
45508 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45509 + task_pax(m, task);
45510 +#endif
45511 +
45512 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
45513 + task_grsec_rbac(m, task);
45514 +#endif
45515 +
45516 return 0;
45517 }
45518
45519 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45520 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45521 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
45522 + _mm->pax_flags & MF_PAX_SEGMEXEC))
45523 +#endif
45524 +
45525 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45526 struct pid *pid, struct task_struct *task, int whole)
45527 {
45528 @@ -378,6 +409,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45529 char tcomm[sizeof(task->comm)];
45530 unsigned long flags;
45531
45532 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45533 + if (current->exec_id != m->exec_id) {
45534 + gr_log_badprocpid("stat");
45535 + return 0;
45536 + }
45537 +#endif
45538 +
45539 state = *get_task_state(task);
45540 vsize = eip = esp = 0;
45541 permitted = ptrace_may_access(task, PTRACE_MODE_READ);
45542 @@ -449,6 +487,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45543 gtime = task->gtime;
45544 }
45545
45546 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45547 + if (PAX_RAND_FLAGS(mm)) {
45548 + eip = 0;
45549 + esp = 0;
45550 + wchan = 0;
45551 + }
45552 +#endif
45553 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45554 + wchan = 0;
45555 + eip =0;
45556 + esp =0;
45557 +#endif
45558 +
45559 /* scale priority and nice values from timeslices to -20..20 */
45560 /* to make it look like a "normal" Unix priority/nice value */
45561 priority = task_prio(task);
45562 @@ -489,9 +540,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
45563 vsize,
45564 mm ? get_mm_rss(mm) : 0,
45565 rsslim,
45566 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45567 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0),
45568 + PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0),
45569 + PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0),
45570 +#else
45571 mm ? (permitted ? mm->start_code : 1) : 0,
45572 mm ? (permitted ? mm->end_code : 1) : 0,
45573 (permitted && mm) ? mm->start_stack : 0,
45574 +#endif
45575 esp,
45576 eip,
45577 /* The signal information here is obsolete.
45578 @@ -535,6 +592,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45579 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
45580 struct mm_struct *mm = get_task_mm(task);
45581
45582 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45583 + if (current->exec_id != m->exec_id) {
45584 + gr_log_badprocpid("statm");
45585 + return 0;
45586 + }
45587 +#endif
45588 +
45589 if (mm) {
45590 size = task_statm(mm, &shared, &text, &data, &resident);
45591 mmput(mm);
45592 @@ -544,3 +608,18 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
45593
45594 return 0;
45595 }
45596 +
45597 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45598 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
45599 +{
45600 + u32 curr_ip = 0;
45601 + unsigned long flags;
45602 +
45603 + if (lock_task_sighand(task, &flags)) {
45604 + curr_ip = task->signal->curr_ip;
45605 + unlock_task_sighand(task, &flags);
45606 + }
45607 +
45608 + return sprintf(buffer, "%pI4\n", &curr_ip);
45609 +}
45610 +#endif
45611 diff --git a/fs/proc/base.c b/fs/proc/base.c
45612 index 1ace83d..f5e575d 100644
45613 --- a/fs/proc/base.c
45614 +++ b/fs/proc/base.c
45615 @@ -107,6 +107,22 @@ struct pid_entry {
45616 union proc_op op;
45617 };
45618
45619 +struct getdents_callback {
45620 + struct linux_dirent __user * current_dir;
45621 + struct linux_dirent __user * previous;
45622 + struct file * file;
45623 + int count;
45624 + int error;
45625 +};
45626 +
45627 +static int gr_fake_filldir(void * __buf, const char *name, int namlen,
45628 + loff_t offset, u64 ino, unsigned int d_type)
45629 +{
45630 + struct getdents_callback * buf = (struct getdents_callback *) __buf;
45631 + buf->error = -EINVAL;
45632 + return 0;
45633 +}
45634 +
45635 #define NOD(NAME, MODE, IOP, FOP, OP) { \
45636 .name = (NAME), \
45637 .len = sizeof(NAME) - 1, \
45638 @@ -194,26 +210,6 @@ static int proc_root_link(struct inode *inode, struct path *path)
45639 return result;
45640 }
45641
45642 -static struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
45643 -{
45644 - struct mm_struct *mm;
45645 - int err;
45646 -
45647 - err = mutex_lock_killable(&task->signal->cred_guard_mutex);
45648 - if (err)
45649 - return ERR_PTR(err);
45650 -
45651 - mm = get_task_mm(task);
45652 - if (mm && mm != current->mm &&
45653 - !ptrace_may_access(task, mode)) {
45654 - mmput(mm);
45655 - mm = ERR_PTR(-EACCES);
45656 - }
45657 - mutex_unlock(&task->signal->cred_guard_mutex);
45658 -
45659 - return mm;
45660 -}
45661 -
45662 struct mm_struct *mm_for_maps(struct task_struct *task)
45663 {
45664 return mm_access(task, PTRACE_MODE_READ);
45665 @@ -229,6 +225,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
45666 if (!mm->arg_end)
45667 goto out_mm; /* Shh! No looking before we're done */
45668
45669 + if (gr_acl_handle_procpidmem(task))
45670 + goto out_mm;
45671 +
45672 len = mm->arg_end - mm->arg_start;
45673
45674 if (len > PAGE_SIZE)
45675 @@ -256,12 +255,28 @@ out:
45676 return res;
45677 }
45678
45679 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45680 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
45681 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
45682 + _mm->pax_flags & MF_PAX_SEGMEXEC))
45683 +#endif
45684 +
45685 static int proc_pid_auxv(struct task_struct *task, char *buffer)
45686 {
45687 struct mm_struct *mm = mm_for_maps(task);
45688 int res = PTR_ERR(mm);
45689 if (mm && !IS_ERR(mm)) {
45690 unsigned int nwords = 0;
45691 +
45692 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45693 + /* allow if we're currently ptracing this task */
45694 + if (PAX_RAND_FLAGS(mm) &&
45695 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
45696 + mmput(mm);
45697 + return 0;
45698 + }
45699 +#endif
45700 +
45701 do {
45702 nwords += 2;
45703 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
45704 @@ -275,7 +290,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
45705 }
45706
45707
45708 -#ifdef CONFIG_KALLSYMS
45709 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45710 /*
45711 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
45712 * Returns the resolved symbol. If that fails, simply return the address.
45713 @@ -314,7 +329,7 @@ static void unlock_trace(struct task_struct *task)
45714 mutex_unlock(&task->signal->cred_guard_mutex);
45715 }
45716
45717 -#ifdef CONFIG_STACKTRACE
45718 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45719
45720 #define MAX_STACK_TRACE_DEPTH 64
45721
45722 @@ -505,7 +520,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
45723 return count;
45724 }
45725
45726 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45727 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45728 static int proc_pid_syscall(struct task_struct *task, char *buffer)
45729 {
45730 long nr;
45731 @@ -534,7 +549,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
45732 /************************************************************************/
45733
45734 /* permission checks */
45735 -static int proc_fd_access_allowed(struct inode *inode)
45736 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
45737 {
45738 struct task_struct *task;
45739 int allowed = 0;
45740 @@ -544,7 +559,10 @@ static int proc_fd_access_allowed(struct inode *inode)
45741 */
45742 task = get_proc_task(inode);
45743 if (task) {
45744 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45745 + if (log)
45746 + allowed = ptrace_may_access_log(task, PTRACE_MODE_READ);
45747 + else
45748 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
45749 put_task_struct(task);
45750 }
45751 return allowed;
45752 @@ -786,6 +804,10 @@ static int mem_open(struct inode* inode, struct file* file)
45753 file->f_mode |= FMODE_UNSIGNED_OFFSET;
45754 file->private_data = mm;
45755
45756 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45757 + file->f_version = current->exec_id;
45758 +#endif
45759 +
45760 return 0;
45761 }
45762
45763 @@ -797,6 +819,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
45764 ssize_t copied;
45765 char *page;
45766
45767 +#ifdef CONFIG_GRKERNSEC
45768 + if (write)
45769 + return -EPERM;
45770 +#endif
45771 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45772 + if (file->f_version != current->exec_id) {
45773 + gr_log_badprocpid("mem");
45774 + return 0;
45775 + }
45776 +#endif
45777 +
45778 if (!mm)
45779 return 0;
45780
45781 @@ -897,6 +930,9 @@ static ssize_t environ_read(struct file *file, char __user *buf,
45782 if (!task)
45783 goto out_no_task;
45784
45785 + if (gr_acl_handle_procpidmem(task))
45786 + goto out;
45787 +
45788 ret = -ENOMEM;
45789 page = (char *)__get_free_page(GFP_TEMPORARY);
45790 if (!page)
45791 @@ -1519,7 +1555,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
45792 path_put(&nd->path);
45793
45794 /* Are we allowed to snoop on the tasks file descriptors? */
45795 - if (!proc_fd_access_allowed(inode))
45796 + if (!proc_fd_access_allowed(inode,0))
45797 goto out;
45798
45799 error = PROC_I(inode)->op.proc_get_link(inode, &nd->path);
45800 @@ -1558,8 +1594,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
45801 struct path path;
45802
45803 /* Are we allowed to snoop on the tasks file descriptors? */
45804 - if (!proc_fd_access_allowed(inode))
45805 - goto out;
45806 + /* logging this is needed for learning on chromium to work properly,
45807 + but we don't want to flood the logs from 'ps' which does a readlink
45808 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
45809 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
45810 + */
45811 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
45812 + if (!proc_fd_access_allowed(inode,0))
45813 + goto out;
45814 + } else {
45815 + if (!proc_fd_access_allowed(inode,1))
45816 + goto out;
45817 + }
45818
45819 error = PROC_I(inode)->op.proc_get_link(inode, &path);
45820 if (error)
45821 @@ -1624,7 +1670,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
45822 rcu_read_lock();
45823 cred = __task_cred(task);
45824 inode->i_uid = cred->euid;
45825 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45826 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45827 +#else
45828 inode->i_gid = cred->egid;
45829 +#endif
45830 rcu_read_unlock();
45831 }
45832 security_task_to_inode(task, inode);
45833 @@ -1642,6 +1692,9 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
45834 struct inode *inode = dentry->d_inode;
45835 struct task_struct *task;
45836 const struct cred *cred;
45837 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45838 + const struct cred *tmpcred = current_cred();
45839 +#endif
45840
45841 generic_fillattr(inode, stat);
45842
45843 @@ -1649,13 +1702,41 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
45844 stat->uid = 0;
45845 stat->gid = 0;
45846 task = pid_task(proc_pid(inode), PIDTYPE_PID);
45847 +
45848 + if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
45849 + rcu_read_unlock();
45850 + return -ENOENT;
45851 + }
45852 +
45853 if (task) {
45854 + cred = __task_cred(task);
45855 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45856 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
45857 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45858 + || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
45859 +#endif
45860 + ) {
45861 +#endif
45862 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45863 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45864 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45865 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45866 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45867 +#endif
45868 task_dumpable(task)) {
45869 - cred = __task_cred(task);
45870 stat->uid = cred->euid;
45871 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45872 + stat->gid = CONFIG_GRKERNSEC_PROC_GID;
45873 +#else
45874 stat->gid = cred->egid;
45875 +#endif
45876 }
45877 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45878 + } else {
45879 + rcu_read_unlock();
45880 + return -ENOENT;
45881 + }
45882 +#endif
45883 }
45884 rcu_read_unlock();
45885 return 0;
45886 @@ -1692,11 +1773,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
45887
45888 if (task) {
45889 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
45890 +#ifdef CONFIG_GRKERNSEC_PROC_USER
45891 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
45892 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45893 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
45894 +#endif
45895 task_dumpable(task)) {
45896 rcu_read_lock();
45897 cred = __task_cred(task);
45898 inode->i_uid = cred->euid;
45899 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
45900 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
45901 +#else
45902 inode->i_gid = cred->egid;
45903 +#endif
45904 rcu_read_unlock();
45905 } else {
45906 inode->i_uid = 0;
45907 @@ -1814,7 +1904,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
45908 int fd = proc_fd(inode);
45909
45910 if (task) {
45911 - files = get_files_struct(task);
45912 + if (!gr_acl_handle_procpidmem(task))
45913 + files = get_files_struct(task);
45914 put_task_struct(task);
45915 }
45916 if (files) {
45917 @@ -2082,11 +2173,21 @@ static const struct file_operations proc_fd_operations = {
45918 */
45919 static int proc_fd_permission(struct inode *inode, int mask)
45920 {
45921 + struct task_struct *task;
45922 int rv = generic_permission(inode, mask);
45923 - if (rv == 0)
45924 - return 0;
45925 +
45926 if (task_pid(current) == proc_pid(inode))
45927 rv = 0;
45928 +
45929 + task = get_proc_task(inode);
45930 + if (task == NULL)
45931 + return rv;
45932 +
45933 + if (gr_acl_handle_procpidmem(task))
45934 + rv = -EACCES;
45935 +
45936 + put_task_struct(task);
45937 +
45938 return rv;
45939 }
45940
45941 @@ -2196,6 +2297,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
45942 if (!task)
45943 goto out_no_task;
45944
45945 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45946 + goto out;
45947 +
45948 /*
45949 * Yes, it does not scale. And it should not. Don't add
45950 * new entries into /proc/<tgid>/ without very good reasons.
45951 @@ -2240,6 +2344,9 @@ static int proc_pident_readdir(struct file *filp,
45952 if (!task)
45953 goto out_no_task;
45954
45955 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
45956 + goto out;
45957 +
45958 ret = 0;
45959 i = filp->f_pos;
45960 switch (i) {
45961 @@ -2510,7 +2617,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
45962 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
45963 void *cookie)
45964 {
45965 - char *s = nd_get_link(nd);
45966 + const char *s = nd_get_link(nd);
45967 if (!IS_ERR(s))
45968 __putname(s);
45969 }
45970 @@ -2708,7 +2815,7 @@ static const struct pid_entry tgid_base_stuff[] = {
45971 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
45972 #endif
45973 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
45974 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
45975 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
45976 INF("syscall", S_IRUGO, proc_pid_syscall),
45977 #endif
45978 INF("cmdline", S_IRUGO, proc_pid_cmdline),
45979 @@ -2733,10 +2840,10 @@ static const struct pid_entry tgid_base_stuff[] = {
45980 #ifdef CONFIG_SECURITY
45981 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
45982 #endif
45983 -#ifdef CONFIG_KALLSYMS
45984 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45985 INF("wchan", S_IRUGO, proc_pid_wchan),
45986 #endif
45987 -#ifdef CONFIG_STACKTRACE
45988 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
45989 ONE("stack", S_IRUGO, proc_pid_stack),
45990 #endif
45991 #ifdef CONFIG_SCHEDSTATS
45992 @@ -2770,6 +2877,9 @@ static const struct pid_entry tgid_base_stuff[] = {
45993 #ifdef CONFIG_HARDWALL
45994 INF("hardwall", S_IRUGO, proc_pid_hardwall),
45995 #endif
45996 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
45997 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
45998 +#endif
45999 };
46000
46001 static int proc_tgid_base_readdir(struct file * filp,
46002 @@ -2895,7 +3005,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
46003 if (!inode)
46004 goto out;
46005
46006 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46007 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
46008 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46009 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
46010 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
46011 +#else
46012 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
46013 +#endif
46014 inode->i_op = &proc_tgid_base_inode_operations;
46015 inode->i_fop = &proc_tgid_base_operations;
46016 inode->i_flags|=S_IMMUTABLE;
46017 @@ -2937,7 +3054,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
46018 if (!task)
46019 goto out;
46020
46021 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
46022 + goto out_put_task;
46023 +
46024 result = proc_pid_instantiate(dir, dentry, task, NULL);
46025 +out_put_task:
46026 put_task_struct(task);
46027 out:
46028 return result;
46029 @@ -3002,6 +3123,11 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
46030 {
46031 unsigned int nr;
46032 struct task_struct *reaper;
46033 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46034 + const struct cred *tmpcred = current_cred();
46035 + const struct cred *itercred;
46036 +#endif
46037 + filldir_t __filldir = filldir;
46038 struct tgid_iter iter;
46039 struct pid_namespace *ns;
46040
46041 @@ -3025,8 +3151,27 @@ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir)
46042 for (iter = next_tgid(ns, iter);
46043 iter.task;
46044 iter.tgid += 1, iter = next_tgid(ns, iter)) {
46045 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46046 + rcu_read_lock();
46047 + itercred = __task_cred(iter.task);
46048 +#endif
46049 + if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
46050 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46051 + || (tmpcred->uid && (itercred->uid != tmpcred->uid)
46052 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46053 + && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
46054 +#endif
46055 + )
46056 +#endif
46057 + )
46058 + __filldir = &gr_fake_filldir;
46059 + else
46060 + __filldir = filldir;
46061 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46062 + rcu_read_unlock();
46063 +#endif
46064 filp->f_pos = iter.tgid + TGID_OFFSET;
46065 - if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
46066 + if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
46067 put_task_struct(iter.task);
46068 goto out;
46069 }
46070 @@ -3054,7 +3199,7 @@ static const struct pid_entry tid_base_stuff[] = {
46071 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
46072 #endif
46073 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
46074 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
46075 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
46076 INF("syscall", S_IRUGO, proc_pid_syscall),
46077 #endif
46078 INF("cmdline", S_IRUGO, proc_pid_cmdline),
46079 @@ -3078,10 +3223,10 @@ static const struct pid_entry tid_base_stuff[] = {
46080 #ifdef CONFIG_SECURITY
46081 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
46082 #endif
46083 -#ifdef CONFIG_KALLSYMS
46084 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46085 INF("wchan", S_IRUGO, proc_pid_wchan),
46086 #endif
46087 -#ifdef CONFIG_STACKTRACE
46088 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
46089 ONE("stack", S_IRUGO, proc_pid_stack),
46090 #endif
46091 #ifdef CONFIG_SCHEDSTATS
46092 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
46093 index 82676e3..5f8518a 100644
46094 --- a/fs/proc/cmdline.c
46095 +++ b/fs/proc/cmdline.c
46096 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
46097
46098 static int __init proc_cmdline_init(void)
46099 {
46100 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46101 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
46102 +#else
46103 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
46104 +#endif
46105 return 0;
46106 }
46107 module_init(proc_cmdline_init);
46108 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
46109 index b143471..bb105e5 100644
46110 --- a/fs/proc/devices.c
46111 +++ b/fs/proc/devices.c
46112 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
46113
46114 static int __init proc_devices_init(void)
46115 {
46116 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46117 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
46118 +#else
46119 proc_create("devices", 0, NULL, &proc_devinfo_operations);
46120 +#endif
46121 return 0;
46122 }
46123 module_init(proc_devices_init);
46124 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
46125 index 7737c54..7172574 100644
46126 --- a/fs/proc/inode.c
46127 +++ b/fs/proc/inode.c
46128 @@ -18,12 +18,18 @@
46129 #include <linux/module.h>
46130 #include <linux/sysctl.h>
46131 #include <linux/slab.h>
46132 +#include <linux/grsecurity.h>
46133
46134 #include <asm/system.h>
46135 #include <asm/uaccess.h>
46136
46137 #include "internal.h"
46138
46139 +#ifdef CONFIG_PROC_SYSCTL
46140 +extern const struct inode_operations proc_sys_inode_operations;
46141 +extern const struct inode_operations proc_sys_dir_operations;
46142 +#endif
46143 +
46144 static void proc_evict_inode(struct inode *inode)
46145 {
46146 struct proc_dir_entry *de;
46147 @@ -49,6 +55,13 @@ static void proc_evict_inode(struct inode *inode)
46148 ns_ops = PROC_I(inode)->ns_ops;
46149 if (ns_ops && ns_ops->put)
46150 ns_ops->put(PROC_I(inode)->ns);
46151 +
46152 +#ifdef CONFIG_PROC_SYSCTL
46153 + if (inode->i_op == &proc_sys_inode_operations ||
46154 + inode->i_op == &proc_sys_dir_operations)
46155 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
46156 +#endif
46157 +
46158 }
46159
46160 static struct kmem_cache * proc_inode_cachep;
46161 @@ -440,7 +453,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
46162 if (de->mode) {
46163 inode->i_mode = de->mode;
46164 inode->i_uid = de->uid;
46165 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
46166 + inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
46167 +#else
46168 inode->i_gid = de->gid;
46169 +#endif
46170 }
46171 if (de->size)
46172 inode->i_size = de->size;
46173 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
46174 index 7838e5c..ff92cbc 100644
46175 --- a/fs/proc/internal.h
46176 +++ b/fs/proc/internal.h
46177 @@ -51,6 +51,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
46178 struct pid *pid, struct task_struct *task);
46179 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
46180 struct pid *pid, struct task_struct *task);
46181 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
46182 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
46183 +#endif
46184 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
46185
46186 extern const struct file_operations proc_maps_operations;
46187 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
46188 index d245cb2..f4e8498 100644
46189 --- a/fs/proc/kcore.c
46190 +++ b/fs/proc/kcore.c
46191 @@ -478,9 +478,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46192 * the addresses in the elf_phdr on our list.
46193 */
46194 start = kc_offset_to_vaddr(*fpos - elf_buflen);
46195 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
46196 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
46197 + if (tsz > buflen)
46198 tsz = buflen;
46199 -
46200 +
46201 while (buflen) {
46202 struct kcore_list *m;
46203
46204 @@ -509,20 +510,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46205 kfree(elf_buf);
46206 } else {
46207 if (kern_addr_valid(start)) {
46208 - unsigned long n;
46209 + char *elf_buf;
46210 + mm_segment_t oldfs;
46211
46212 - n = copy_to_user(buffer, (char *)start, tsz);
46213 - /*
46214 - * We cannot distingush between fault on source
46215 - * and fault on destination. When this happens
46216 - * we clear too and hope it will trigger the
46217 - * EFAULT again.
46218 - */
46219 - if (n) {
46220 - if (clear_user(buffer + tsz - n,
46221 - n))
46222 + elf_buf = kmalloc(tsz, GFP_KERNEL);
46223 + if (!elf_buf)
46224 + return -ENOMEM;
46225 + oldfs = get_fs();
46226 + set_fs(KERNEL_DS);
46227 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
46228 + set_fs(oldfs);
46229 + if (copy_to_user(buffer, elf_buf, tsz)) {
46230 + kfree(elf_buf);
46231 return -EFAULT;
46232 + }
46233 }
46234 + set_fs(oldfs);
46235 + kfree(elf_buf);
46236 } else {
46237 if (clear_user(buffer, tsz))
46238 return -EFAULT;
46239 @@ -542,6 +546,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
46240
46241 static int open_kcore(struct inode *inode, struct file *filp)
46242 {
46243 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
46244 + return -EPERM;
46245 +#endif
46246 if (!capable(CAP_SYS_RAWIO))
46247 return -EPERM;
46248 if (kcore_need_update)
46249 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
46250 index 80e4645..53e5fcf 100644
46251 --- a/fs/proc/meminfo.c
46252 +++ b/fs/proc/meminfo.c
46253 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
46254 vmi.used >> 10,
46255 vmi.largest_chunk >> 10
46256 #ifdef CONFIG_MEMORY_FAILURE
46257 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
46258 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
46259 #endif
46260 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
46261 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
46262 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
46263 index b1822dd..df622cb 100644
46264 --- a/fs/proc/nommu.c
46265 +++ b/fs/proc/nommu.c
46266 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
46267 if (len < 1)
46268 len = 1;
46269 seq_printf(m, "%*c", len, ' ');
46270 - seq_path(m, &file->f_path, "");
46271 + seq_path(m, &file->f_path, "\n\\");
46272 }
46273
46274 seq_putc(m, '\n');
46275 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
46276 index f738024..876984a 100644
46277 --- a/fs/proc/proc_net.c
46278 +++ b/fs/proc/proc_net.c
46279 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
46280 struct task_struct *task;
46281 struct nsproxy *ns;
46282 struct net *net = NULL;
46283 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46284 + const struct cred *cred = current_cred();
46285 +#endif
46286 +
46287 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46288 + if (cred->fsuid)
46289 + return net;
46290 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46291 + if (cred->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
46292 + return net;
46293 +#endif
46294
46295 rcu_read_lock();
46296 task = pid_task(proc_pid(dir), PIDTYPE_PID);
46297 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
46298 index a6b6217..1e0579d 100644
46299 --- a/fs/proc/proc_sysctl.c
46300 +++ b/fs/proc/proc_sysctl.c
46301 @@ -9,11 +9,13 @@
46302 #include <linux/namei.h>
46303 #include "internal.h"
46304
46305 +extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
46306 +
46307 static const struct dentry_operations proc_sys_dentry_operations;
46308 static const struct file_operations proc_sys_file_operations;
46309 -static const struct inode_operations proc_sys_inode_operations;
46310 +const struct inode_operations proc_sys_inode_operations;
46311 static const struct file_operations proc_sys_dir_file_operations;
46312 -static const struct inode_operations proc_sys_dir_operations;
46313 +const struct inode_operations proc_sys_dir_operations;
46314
46315 void proc_sys_poll_notify(struct ctl_table_poll *poll)
46316 {
46317 @@ -131,8 +133,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
46318
46319 err = NULL;
46320 d_set_d_op(dentry, &proc_sys_dentry_operations);
46321 +
46322 + gr_handle_proc_create(dentry, inode);
46323 +
46324 d_add(dentry, inode);
46325
46326 + if (gr_handle_sysctl(p, MAY_EXEC))
46327 + err = ERR_PTR(-ENOENT);
46328 +
46329 out:
46330 sysctl_head_finish(head);
46331 return err;
46332 @@ -163,6 +171,12 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
46333 if (!table->proc_handler)
46334 goto out;
46335
46336 +#ifdef CONFIG_GRKERNSEC
46337 + error = -EPERM;
46338 + if (write && !capable(CAP_SYS_ADMIN))
46339 + goto out;
46340 +#endif
46341 +
46342 /* careful: calling conventions are nasty here */
46343 res = count;
46344 error = table->proc_handler(table, write, buf, &res, ppos);
46345 @@ -245,6 +259,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
46346 return -ENOMEM;
46347 } else {
46348 d_set_d_op(child, &proc_sys_dentry_operations);
46349 +
46350 + gr_handle_proc_create(child, inode);
46351 +
46352 d_add(child, inode);
46353 }
46354 } else {
46355 @@ -273,6 +290,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
46356 if (*pos < file->f_pos)
46357 continue;
46358
46359 + if (gr_handle_sysctl(table, 0))
46360 + continue;
46361 +
46362 res = proc_sys_fill_cache(file, dirent, filldir, head, table);
46363 if (res)
46364 return res;
46365 @@ -398,6 +418,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
46366 if (IS_ERR(head))
46367 return PTR_ERR(head);
46368
46369 + if (table && gr_handle_sysctl(table, MAY_EXEC))
46370 + return -ENOENT;
46371 +
46372 generic_fillattr(inode, stat);
46373 if (table)
46374 stat->mode = (stat->mode & S_IFMT) | table->mode;
46375 @@ -420,13 +443,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
46376 .llseek = generic_file_llseek,
46377 };
46378
46379 -static const struct inode_operations proc_sys_inode_operations = {
46380 +const struct inode_operations proc_sys_inode_operations = {
46381 .permission = proc_sys_permission,
46382 .setattr = proc_sys_setattr,
46383 .getattr = proc_sys_getattr,
46384 };
46385
46386 -static const struct inode_operations proc_sys_dir_operations = {
46387 +const struct inode_operations proc_sys_dir_operations = {
46388 .lookup = proc_sys_lookup,
46389 .permission = proc_sys_permission,
46390 .setattr = proc_sys_setattr,
46391 diff --git a/fs/proc/root.c b/fs/proc/root.c
46392 index 03102d9..4ae347e 100644
46393 --- a/fs/proc/root.c
46394 +++ b/fs/proc/root.c
46395 @@ -121,7 +121,15 @@ void __init proc_root_init(void)
46396 #ifdef CONFIG_PROC_DEVICETREE
46397 proc_device_tree_init();
46398 #endif
46399 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
46400 +#ifdef CONFIG_GRKERNSEC_PROC_USER
46401 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
46402 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
46403 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
46404 +#endif
46405 +#else
46406 proc_mkdir("bus", NULL);
46407 +#endif
46408 proc_sys_init();
46409 }
46410
46411 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
46412 index 7dcd2a2..b2f410e 100644
46413 --- a/fs/proc/task_mmu.c
46414 +++ b/fs/proc/task_mmu.c
46415 @@ -11,6 +11,7 @@
46416 #include <linux/rmap.h>
46417 #include <linux/swap.h>
46418 #include <linux/swapops.h>
46419 +#include <linux/grsecurity.h>
46420
46421 #include <asm/elf.h>
46422 #include <asm/uaccess.h>
46423 @@ -52,8 +53,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46424 "VmExe:\t%8lu kB\n"
46425 "VmLib:\t%8lu kB\n"
46426 "VmPTE:\t%8lu kB\n"
46427 - "VmSwap:\t%8lu kB\n",
46428 - hiwater_vm << (PAGE_SHIFT-10),
46429 + "VmSwap:\t%8lu kB\n"
46430 +
46431 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46432 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
46433 +#endif
46434 +
46435 + ,hiwater_vm << (PAGE_SHIFT-10),
46436 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
46437 mm->locked_vm << (PAGE_SHIFT-10),
46438 mm->pinned_vm << (PAGE_SHIFT-10),
46439 @@ -62,7 +68,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46440 data << (PAGE_SHIFT-10),
46441 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
46442 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
46443 - swap << (PAGE_SHIFT-10));
46444 + swap << (PAGE_SHIFT-10)
46445 +
46446 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
46447 + , mm->context.user_cs_base, mm->context.user_cs_limit
46448 +#endif
46449 +
46450 + );
46451 }
46452
46453 unsigned long task_vsize(struct mm_struct *mm)
46454 @@ -209,6 +221,12 @@ static int do_maps_open(struct inode *inode, struct file *file,
46455 return ret;
46456 }
46457
46458 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46459 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
46460 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
46461 + _mm->pax_flags & MF_PAX_SEGMEXEC))
46462 +#endif
46463 +
46464 static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46465 {
46466 struct mm_struct *mm = vma->vm_mm;
46467 @@ -227,13 +245,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46468 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
46469 }
46470
46471 - /* We don't show the stack guard page in /proc/maps */
46472 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46473 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
46474 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
46475 +#else
46476 start = vma->vm_start;
46477 - if (stack_guard_page_start(vma, start))
46478 - start += PAGE_SIZE;
46479 end = vma->vm_end;
46480 - if (stack_guard_page_end(vma, end))
46481 - end -= PAGE_SIZE;
46482 +#endif
46483
46484 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
46485 start,
46486 @@ -242,7 +260,11 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46487 flags & VM_WRITE ? 'w' : '-',
46488 flags & VM_EXEC ? 'x' : '-',
46489 flags & VM_MAYSHARE ? 's' : 'p',
46490 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46491 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
46492 +#else
46493 pgoff,
46494 +#endif
46495 MAJOR(dev), MINOR(dev), ino, &len);
46496
46497 /*
46498 @@ -251,7 +273,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46499 */
46500 if (file) {
46501 pad_len_spaces(m, len);
46502 - seq_path(m, &file->f_path, "\n");
46503 + seq_path(m, &file->f_path, "\n\\");
46504 } else {
46505 const char *name = arch_vma_name(vma);
46506 if (!name) {
46507 @@ -259,8 +281,9 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
46508 if (vma->vm_start <= mm->brk &&
46509 vma->vm_end >= mm->start_brk) {
46510 name = "[heap]";
46511 - } else if (vma->vm_start <= mm->start_stack &&
46512 - vma->vm_end >= mm->start_stack) {
46513 + } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
46514 + (vma->vm_start <= mm->start_stack &&
46515 + vma->vm_end >= mm->start_stack)) {
46516 name = "[stack]";
46517 }
46518 } else {
46519 @@ -281,6 +304,13 @@ static int show_map(struct seq_file *m, void *v)
46520 struct proc_maps_private *priv = m->private;
46521 struct task_struct *task = priv->task;
46522
46523 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46524 + if (current->exec_id != m->exec_id) {
46525 + gr_log_badprocpid("maps");
46526 + return 0;
46527 + }
46528 +#endif
46529 +
46530 show_map_vma(m, vma);
46531
46532 if (m->count < m->size) /* vma is copied successfully */
46533 @@ -434,12 +464,23 @@ static int show_smap(struct seq_file *m, void *v)
46534 .private = &mss,
46535 };
46536
46537 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46538 + if (current->exec_id != m->exec_id) {
46539 + gr_log_badprocpid("smaps");
46540 + return 0;
46541 + }
46542 +#endif
46543 memset(&mss, 0, sizeof mss);
46544 - mss.vma = vma;
46545 - /* mmap_sem is held in m_start */
46546 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46547 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46548 -
46549 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46550 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
46551 +#endif
46552 + mss.vma = vma;
46553 + /* mmap_sem is held in m_start */
46554 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
46555 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
46556 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46557 + }
46558 +#endif
46559 show_map_vma(m, vma);
46560
46561 seq_printf(m,
46562 @@ -457,7 +498,11 @@ static int show_smap(struct seq_file *m, void *v)
46563 "KernelPageSize: %8lu kB\n"
46564 "MMUPageSize: %8lu kB\n"
46565 "Locked: %8lu kB\n",
46566 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46567 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
46568 +#else
46569 (vma->vm_end - vma->vm_start) >> 10,
46570 +#endif
46571 mss.resident >> 10,
46572 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
46573 mss.shared_clean >> 10,
46574 @@ -1015,6 +1060,13 @@ static int show_numa_map(struct seq_file *m, void *v)
46575 int n;
46576 char buffer[50];
46577
46578 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46579 + if (current->exec_id != m->exec_id) {
46580 + gr_log_badprocpid("numa_maps");
46581 + return 0;
46582 + }
46583 +#endif
46584 +
46585 if (!mm)
46586 return 0;
46587
46588 @@ -1032,11 +1084,15 @@ static int show_numa_map(struct seq_file *m, void *v)
46589 mpol_to_str(buffer, sizeof(buffer), pol, 0);
46590 mpol_cond_put(pol);
46591
46592 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46593 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
46594 +#else
46595 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
46596 +#endif
46597
46598 if (file) {
46599 seq_printf(m, " file=");
46600 - seq_path(m, &file->f_path, "\n\t= ");
46601 + seq_path(m, &file->f_path, "\n\t\\= ");
46602 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
46603 seq_printf(m, " heap");
46604 } else if (vma->vm_start <= mm->start_stack &&
46605 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
46606 index 980de54..2a4db5f 100644
46607 --- a/fs/proc/task_nommu.c
46608 +++ b/fs/proc/task_nommu.c
46609 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
46610 else
46611 bytes += kobjsize(mm);
46612
46613 - if (current->fs && current->fs->users > 1)
46614 + if (current->fs && atomic_read(&current->fs->users) > 1)
46615 sbytes += kobjsize(current->fs);
46616 else
46617 bytes += kobjsize(current->fs);
46618 @@ -166,7 +166,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
46619
46620 if (file) {
46621 pad_len_spaces(m, len);
46622 - seq_path(m, &file->f_path, "");
46623 + seq_path(m, &file->f_path, "\n\\");
46624 } else if (mm) {
46625 if (vma->vm_start <= mm->start_stack &&
46626 vma->vm_end >= mm->start_stack) {
46627 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
46628 index d67908b..d13f6a6 100644
46629 --- a/fs/quota/netlink.c
46630 +++ b/fs/quota/netlink.c
46631 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
46632 void quota_send_warning(short type, unsigned int id, dev_t dev,
46633 const char warntype)
46634 {
46635 - static atomic_t seq;
46636 + static atomic_unchecked_t seq;
46637 struct sk_buff *skb;
46638 void *msg_head;
46639 int ret;
46640 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
46641 "VFS: Not enough memory to send quota warning.\n");
46642 return;
46643 }
46644 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
46645 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
46646 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
46647 if (!msg_head) {
46648 printk(KERN_ERR
46649 diff --git a/fs/readdir.c b/fs/readdir.c
46650 index 356f715..c918d38 100644
46651 --- a/fs/readdir.c
46652 +++ b/fs/readdir.c
46653 @@ -17,6 +17,7 @@
46654 #include <linux/security.h>
46655 #include <linux/syscalls.h>
46656 #include <linux/unistd.h>
46657 +#include <linux/namei.h>
46658
46659 #include <asm/uaccess.h>
46660
46661 @@ -67,6 +68,7 @@ struct old_linux_dirent {
46662
46663 struct readdir_callback {
46664 struct old_linux_dirent __user * dirent;
46665 + struct file * file;
46666 int result;
46667 };
46668
46669 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
46670 buf->result = -EOVERFLOW;
46671 return -EOVERFLOW;
46672 }
46673 +
46674 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46675 + return 0;
46676 +
46677 buf->result++;
46678 dirent = buf->dirent;
46679 if (!access_ok(VERIFY_WRITE, dirent,
46680 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
46681
46682 buf.result = 0;
46683 buf.dirent = dirent;
46684 + buf.file = file;
46685
46686 error = vfs_readdir(file, fillonedir, &buf);
46687 if (buf.result)
46688 @@ -142,6 +149,7 @@ struct linux_dirent {
46689 struct getdents_callback {
46690 struct linux_dirent __user * current_dir;
46691 struct linux_dirent __user * previous;
46692 + struct file * file;
46693 int count;
46694 int error;
46695 };
46696 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
46697 buf->error = -EOVERFLOW;
46698 return -EOVERFLOW;
46699 }
46700 +
46701 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46702 + return 0;
46703 +
46704 dirent = buf->previous;
46705 if (dirent) {
46706 if (__put_user(offset, &dirent->d_off))
46707 @@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
46708 buf.previous = NULL;
46709 buf.count = count;
46710 buf.error = 0;
46711 + buf.file = file;
46712
46713 error = vfs_readdir(file, filldir, &buf);
46714 if (error >= 0)
46715 @@ -229,6 +242,7 @@ out:
46716 struct getdents_callback64 {
46717 struct linux_dirent64 __user * current_dir;
46718 struct linux_dirent64 __user * previous;
46719 + struct file *file;
46720 int count;
46721 int error;
46722 };
46723 @@ -244,6 +258,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
46724 buf->error = -EINVAL; /* only used if we fail.. */
46725 if (reclen > buf->count)
46726 return -EINVAL;
46727 +
46728 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46729 + return 0;
46730 +
46731 dirent = buf->previous;
46732 if (dirent) {
46733 if (__put_user(offset, &dirent->d_off))
46734 @@ -291,6 +309,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
46735
46736 buf.current_dir = dirent;
46737 buf.previous = NULL;
46738 + buf.file = file;
46739 buf.count = count;
46740 buf.error = 0;
46741
46742 @@ -299,7 +318,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
46743 error = buf.error;
46744 lastdirent = buf.previous;
46745 if (lastdirent) {
46746 - typeof(lastdirent->d_off) d_off = file->f_pos;
46747 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
46748 if (__put_user(d_off, &lastdirent->d_off))
46749 error = -EFAULT;
46750 else
46751 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
46752 index 60c0804..d814f98 100644
46753 --- a/fs/reiserfs/do_balan.c
46754 +++ b/fs/reiserfs/do_balan.c
46755 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
46756 return;
46757 }
46758
46759 - atomic_inc(&(fs_generation(tb->tb_sb)));
46760 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
46761 do_balance_starts(tb);
46762
46763 /* balance leaf returns 0 except if combining L R and S into
46764 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
46765 index 7a99811..a7c96c4 100644
46766 --- a/fs/reiserfs/procfs.c
46767 +++ b/fs/reiserfs/procfs.c
46768 @@ -113,7 +113,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
46769 "SMALL_TAILS " : "NO_TAILS ",
46770 replay_only(sb) ? "REPLAY_ONLY " : "",
46771 convert_reiserfs(sb) ? "CONV " : "",
46772 - atomic_read(&r->s_generation_counter),
46773 + atomic_read_unchecked(&r->s_generation_counter),
46774 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
46775 SF(s_do_balance), SF(s_unneeded_left_neighbor),
46776 SF(s_good_search_by_key_reada), SF(s_bmaps),
46777 diff --git a/fs/select.c b/fs/select.c
46778 index d33418f..2a5345e 100644
46779 --- a/fs/select.c
46780 +++ b/fs/select.c
46781 @@ -20,6 +20,7 @@
46782 #include <linux/module.h>
46783 #include <linux/slab.h>
46784 #include <linux/poll.h>
46785 +#include <linux/security.h>
46786 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
46787 #include <linux/file.h>
46788 #include <linux/fdtable.h>
46789 @@ -837,6 +838,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
46790 struct poll_list *walk = head;
46791 unsigned long todo = nfds;
46792
46793 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
46794 if (nfds > rlimit(RLIMIT_NOFILE))
46795 return -EINVAL;
46796
46797 diff --git a/fs/seq_file.c b/fs/seq_file.c
46798 index dba43c3..9fb8511 100644
46799 --- a/fs/seq_file.c
46800 +++ b/fs/seq_file.c
46801 @@ -9,6 +9,7 @@
46802 #include <linux/module.h>
46803 #include <linux/seq_file.h>
46804 #include <linux/slab.h>
46805 +#include <linux/sched.h>
46806
46807 #include <asm/uaccess.h>
46808 #include <asm/page.h>
46809 @@ -40,6 +41,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
46810 memset(p, 0, sizeof(*p));
46811 mutex_init(&p->lock);
46812 p->op = op;
46813 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46814 + p->exec_id = current->exec_id;
46815 +#endif
46816
46817 /*
46818 * Wrappers around seq_open(e.g. swaps_open) need to be
46819 @@ -76,7 +80,8 @@ static int traverse(struct seq_file *m, loff_t offset)
46820 return 0;
46821 }
46822 if (!m->buf) {
46823 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46824 + m->size = PAGE_SIZE;
46825 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46826 if (!m->buf)
46827 return -ENOMEM;
46828 }
46829 @@ -116,7 +121,8 @@ static int traverse(struct seq_file *m, loff_t offset)
46830 Eoverflow:
46831 m->op->stop(m, p);
46832 kfree(m->buf);
46833 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46834 + m->size <<= 1;
46835 + m->buf = kmalloc(m->size, GFP_KERNEL);
46836 return !m->buf ? -ENOMEM : -EAGAIN;
46837 }
46838
46839 @@ -169,7 +175,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
46840 m->version = file->f_version;
46841 /* grab buffer if we didn't have one */
46842 if (!m->buf) {
46843 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
46844 + m->size = PAGE_SIZE;
46845 + m->buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
46846 if (!m->buf)
46847 goto Enomem;
46848 }
46849 @@ -210,7 +217,8 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
46850 goto Fill;
46851 m->op->stop(m, p);
46852 kfree(m->buf);
46853 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
46854 + m->size <<= 1;
46855 + m->buf = kmalloc(m->size, GFP_KERNEL);
46856 if (!m->buf)
46857 goto Enomem;
46858 m->count = 0;
46859 @@ -549,7 +557,7 @@ static void single_stop(struct seq_file *p, void *v)
46860 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
46861 void *data)
46862 {
46863 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
46864 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
46865 int res = -ENOMEM;
46866
46867 if (op) {
46868 diff --git a/fs/splice.c b/fs/splice.c
46869 index fa2defa..8601650 100644
46870 --- a/fs/splice.c
46871 +++ b/fs/splice.c
46872 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
46873 pipe_lock(pipe);
46874
46875 for (;;) {
46876 - if (!pipe->readers) {
46877 + if (!atomic_read(&pipe->readers)) {
46878 send_sig(SIGPIPE, current, 0);
46879 if (!ret)
46880 ret = -EPIPE;
46881 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
46882 do_wakeup = 0;
46883 }
46884
46885 - pipe->waiting_writers++;
46886 + atomic_inc(&pipe->waiting_writers);
46887 pipe_wait(pipe);
46888 - pipe->waiting_writers--;
46889 + atomic_dec(&pipe->waiting_writers);
46890 }
46891
46892 pipe_unlock(pipe);
46893 @@ -560,7 +560,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
46894 old_fs = get_fs();
46895 set_fs(get_ds());
46896 /* The cast to a user pointer is valid due to the set_fs() */
46897 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
46898 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
46899 set_fs(old_fs);
46900
46901 return res;
46902 @@ -575,7 +575,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
46903 old_fs = get_fs();
46904 set_fs(get_ds());
46905 /* The cast to a user pointer is valid due to the set_fs() */
46906 - res = vfs_write(file, (const char __user *)buf, count, &pos);
46907 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
46908 set_fs(old_fs);
46909
46910 return res;
46911 @@ -626,7 +626,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
46912 goto err;
46913
46914 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
46915 - vec[i].iov_base = (void __user *) page_address(page);
46916 + vec[i].iov_base = (void __force_user *) page_address(page);
46917 vec[i].iov_len = this_len;
46918 spd.pages[i] = page;
46919 spd.nr_pages++;
46920 @@ -846,10 +846,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
46921 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
46922 {
46923 while (!pipe->nrbufs) {
46924 - if (!pipe->writers)
46925 + if (!atomic_read(&pipe->writers))
46926 return 0;
46927
46928 - if (!pipe->waiting_writers && sd->num_spliced)
46929 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
46930 return 0;
46931
46932 if (sd->flags & SPLICE_F_NONBLOCK)
46933 @@ -1182,7 +1182,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
46934 * out of the pipe right after the splice_to_pipe(). So set
46935 * PIPE_READERS appropriately.
46936 */
46937 - pipe->readers = 1;
46938 + atomic_set(&pipe->readers, 1);
46939
46940 current->splice_pipe = pipe;
46941 }
46942 @@ -1734,9 +1734,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46943 ret = -ERESTARTSYS;
46944 break;
46945 }
46946 - if (!pipe->writers)
46947 + if (!atomic_read(&pipe->writers))
46948 break;
46949 - if (!pipe->waiting_writers) {
46950 + if (!atomic_read(&pipe->waiting_writers)) {
46951 if (flags & SPLICE_F_NONBLOCK) {
46952 ret = -EAGAIN;
46953 break;
46954 @@ -1768,7 +1768,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46955 pipe_lock(pipe);
46956
46957 while (pipe->nrbufs >= pipe->buffers) {
46958 - if (!pipe->readers) {
46959 + if (!atomic_read(&pipe->readers)) {
46960 send_sig(SIGPIPE, current, 0);
46961 ret = -EPIPE;
46962 break;
46963 @@ -1781,9 +1781,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
46964 ret = -ERESTARTSYS;
46965 break;
46966 }
46967 - pipe->waiting_writers++;
46968 + atomic_inc(&pipe->waiting_writers);
46969 pipe_wait(pipe);
46970 - pipe->waiting_writers--;
46971 + atomic_dec(&pipe->waiting_writers);
46972 }
46973
46974 pipe_unlock(pipe);
46975 @@ -1819,14 +1819,14 @@ retry:
46976 pipe_double_lock(ipipe, opipe);
46977
46978 do {
46979 - if (!opipe->readers) {
46980 + if (!atomic_read(&opipe->readers)) {
46981 send_sig(SIGPIPE, current, 0);
46982 if (!ret)
46983 ret = -EPIPE;
46984 break;
46985 }
46986
46987 - if (!ipipe->nrbufs && !ipipe->writers)
46988 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
46989 break;
46990
46991 /*
46992 @@ -1923,7 +1923,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
46993 pipe_double_lock(ipipe, opipe);
46994
46995 do {
46996 - if (!opipe->readers) {
46997 + if (!atomic_read(&opipe->readers)) {
46998 send_sig(SIGPIPE, current, 0);
46999 if (!ret)
47000 ret = -EPIPE;
47001 @@ -1968,7 +1968,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
47002 * return EAGAIN if we have the potential of some data in the
47003 * future, otherwise just return 0
47004 */
47005 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
47006 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
47007 ret = -EAGAIN;
47008
47009 pipe_unlock(ipipe);
47010 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
47011 index 7fdf6a7..e6cd8ad 100644
47012 --- a/fs/sysfs/dir.c
47013 +++ b/fs/sysfs/dir.c
47014 @@ -642,6 +642,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
47015 struct sysfs_dirent *sd;
47016 int rc;
47017
47018 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47019 + const char *parent_name = parent_sd->s_name;
47020 +
47021 + mode = S_IFDIR | S_IRWXU;
47022 +
47023 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
47024 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
47025 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
47026 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
47027 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
47028 +#endif
47029 +
47030 /* allocate */
47031 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
47032 if (!sd)
47033 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
47034 index 779789a..f58193c 100644
47035 --- a/fs/sysfs/file.c
47036 +++ b/fs/sysfs/file.c
47037 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
47038
47039 struct sysfs_open_dirent {
47040 atomic_t refcnt;
47041 - atomic_t event;
47042 + atomic_unchecked_t event;
47043 wait_queue_head_t poll;
47044 struct list_head buffers; /* goes through sysfs_buffer.list */
47045 };
47046 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
47047 if (!sysfs_get_active(attr_sd))
47048 return -ENODEV;
47049
47050 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
47051 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
47052 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
47053
47054 sysfs_put_active(attr_sd);
47055 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
47056 return -ENOMEM;
47057
47058 atomic_set(&new_od->refcnt, 0);
47059 - atomic_set(&new_od->event, 1);
47060 + atomic_set_unchecked(&new_od->event, 1);
47061 init_waitqueue_head(&new_od->poll);
47062 INIT_LIST_HEAD(&new_od->buffers);
47063 goto retry;
47064 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
47065
47066 sysfs_put_active(attr_sd);
47067
47068 - if (buffer->event != atomic_read(&od->event))
47069 + if (buffer->event != atomic_read_unchecked(&od->event))
47070 goto trigger;
47071
47072 return DEFAULT_POLLMASK;
47073 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
47074
47075 od = sd->s_attr.open;
47076 if (od) {
47077 - atomic_inc(&od->event);
47078 + atomic_inc_unchecked(&od->event);
47079 wake_up_interruptible(&od->poll);
47080 }
47081
47082 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
47083 index a7ac78f..02158e1 100644
47084 --- a/fs/sysfs/symlink.c
47085 +++ b/fs/sysfs/symlink.c
47086 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47087
47088 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
47089 {
47090 - char *page = nd_get_link(nd);
47091 + const char *page = nd_get_link(nd);
47092 if (!IS_ERR(page))
47093 free_page((unsigned long)page);
47094 }
47095 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
47096 index c175b4d..8f36a16 100644
47097 --- a/fs/udf/misc.c
47098 +++ b/fs/udf/misc.c
47099 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
47100
47101 u8 udf_tag_checksum(const struct tag *t)
47102 {
47103 - u8 *data = (u8 *)t;
47104 + const u8 *data = (const u8 *)t;
47105 u8 checksum = 0;
47106 int i;
47107 for (i = 0; i < sizeof(struct tag); ++i)
47108 diff --git a/fs/utimes.c b/fs/utimes.c
47109 index ba653f3..06ea4b1 100644
47110 --- a/fs/utimes.c
47111 +++ b/fs/utimes.c
47112 @@ -1,6 +1,7 @@
47113 #include <linux/compiler.h>
47114 #include <linux/file.h>
47115 #include <linux/fs.h>
47116 +#include <linux/security.h>
47117 #include <linux/linkage.h>
47118 #include <linux/mount.h>
47119 #include <linux/namei.h>
47120 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
47121 goto mnt_drop_write_and_out;
47122 }
47123 }
47124 +
47125 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
47126 + error = -EACCES;
47127 + goto mnt_drop_write_and_out;
47128 + }
47129 +
47130 mutex_lock(&inode->i_mutex);
47131 error = notify_change(path->dentry, &newattrs);
47132 mutex_unlock(&inode->i_mutex);
47133 diff --git a/fs/xattr.c b/fs/xattr.c
47134 index 67583de..c5aad14 100644
47135 --- a/fs/xattr.c
47136 +++ b/fs/xattr.c
47137 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
47138 * Extended attribute SET operations
47139 */
47140 static long
47141 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
47142 +setxattr(struct path *path, const char __user *name, const void __user *value,
47143 size_t size, int flags)
47144 {
47145 int error;
47146 @@ -339,7 +339,13 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
47147 return PTR_ERR(kvalue);
47148 }
47149
47150 - error = vfs_setxattr(d, kname, kvalue, size, flags);
47151 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
47152 + error = -EACCES;
47153 + goto out;
47154 + }
47155 +
47156 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
47157 +out:
47158 kfree(kvalue);
47159 return error;
47160 }
47161 @@ -356,7 +362,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
47162 return error;
47163 error = mnt_want_write(path.mnt);
47164 if (!error) {
47165 - error = setxattr(path.dentry, name, value, size, flags);
47166 + error = setxattr(&path, name, value, size, flags);
47167 mnt_drop_write(path.mnt);
47168 }
47169 path_put(&path);
47170 @@ -375,7 +381,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
47171 return error;
47172 error = mnt_want_write(path.mnt);
47173 if (!error) {
47174 - error = setxattr(path.dentry, name, value, size, flags);
47175 + error = setxattr(&path, name, value, size, flags);
47176 mnt_drop_write(path.mnt);
47177 }
47178 path_put(&path);
47179 @@ -386,17 +392,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
47180 const void __user *,value, size_t, size, int, flags)
47181 {
47182 struct file *f;
47183 - struct dentry *dentry;
47184 int error = -EBADF;
47185
47186 f = fget(fd);
47187 if (!f)
47188 return error;
47189 - dentry = f->f_path.dentry;
47190 - audit_inode(NULL, dentry);
47191 + audit_inode(NULL, f->f_path.dentry);
47192 error = mnt_want_write_file(f);
47193 if (!error) {
47194 - error = setxattr(dentry, name, value, size, flags);
47195 + error = setxattr(&f->f_path, name, value, size, flags);
47196 mnt_drop_write(f->f_path.mnt);
47197 }
47198 fput(f);
47199 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
47200 index 8d5a506..7f62712 100644
47201 --- a/fs/xattr_acl.c
47202 +++ b/fs/xattr_acl.c
47203 @@ -17,8 +17,8 @@
47204 struct posix_acl *
47205 posix_acl_from_xattr(const void *value, size_t size)
47206 {
47207 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
47208 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
47209 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
47210 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
47211 int count;
47212 struct posix_acl *acl;
47213 struct posix_acl_entry *acl_e;
47214 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
47215 index d0ab788..827999b 100644
47216 --- a/fs/xfs/xfs_bmap.c
47217 +++ b/fs/xfs/xfs_bmap.c
47218 @@ -190,7 +190,7 @@ xfs_bmap_validate_ret(
47219 int nmap,
47220 int ret_nmap);
47221 #else
47222 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
47223 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
47224 #endif /* DEBUG */
47225
47226 STATIC int
47227 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
47228 index 79d05e8..e3e5861 100644
47229 --- a/fs/xfs/xfs_dir2_sf.c
47230 +++ b/fs/xfs/xfs_dir2_sf.c
47231 @@ -852,7 +852,15 @@ xfs_dir2_sf_getdents(
47232 }
47233
47234 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
47235 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
47236 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
47237 + char name[sfep->namelen];
47238 + memcpy(name, sfep->name, sfep->namelen);
47239 + if (filldir(dirent, name, sfep->namelen,
47240 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
47241 + *offset = off & 0x7fffffff;
47242 + return 0;
47243 + }
47244 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
47245 off & 0x7fffffff, ino, DT_UNKNOWN)) {
47246 *offset = off & 0x7fffffff;
47247 return 0;
47248 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
47249 index d99a905..9f88202 100644
47250 --- a/fs/xfs/xfs_ioctl.c
47251 +++ b/fs/xfs/xfs_ioctl.c
47252 @@ -128,7 +128,7 @@ xfs_find_handle(
47253 }
47254
47255 error = -EFAULT;
47256 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
47257 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
47258 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
47259 goto out_put;
47260
47261 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
47262 index 23ce927..e274cc1 100644
47263 --- a/fs/xfs/xfs_iops.c
47264 +++ b/fs/xfs/xfs_iops.c
47265 @@ -447,7 +447,7 @@ xfs_vn_put_link(
47266 struct nameidata *nd,
47267 void *p)
47268 {
47269 - char *s = nd_get_link(nd);
47270 + const char *s = nd_get_link(nd);
47271
47272 if (!IS_ERR(s))
47273 kfree(s);
47274 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
47275 new file mode 100644
47276 index 0000000..41df561
47277 --- /dev/null
47278 +++ b/grsecurity/Kconfig
47279 @@ -0,0 +1,1075 @@
47280 +#
47281 +# grecurity configuration
47282 +#
47283 +
47284 +menu "Grsecurity"
47285 +
47286 +config GRKERNSEC
47287 + bool "Grsecurity"
47288 + select CRYPTO
47289 + select CRYPTO_SHA256
47290 + help
47291 + If you say Y here, you will be able to configure many features
47292 + that will enhance the security of your system. It is highly
47293 + recommended that you say Y here and read through the help
47294 + for each option so that you fully understand the features and
47295 + can evaluate their usefulness for your machine.
47296 +
47297 +choice
47298 + prompt "Security Level"
47299 + depends on GRKERNSEC
47300 + default GRKERNSEC_CUSTOM
47301 +
47302 +config GRKERNSEC_LOW
47303 + bool "Low"
47304 + select GRKERNSEC_LINK
47305 + select GRKERNSEC_FIFO
47306 + select GRKERNSEC_RANDNET
47307 + select GRKERNSEC_DMESG
47308 + select GRKERNSEC_CHROOT
47309 + select GRKERNSEC_CHROOT_CHDIR
47310 +
47311 + help
47312 + If you choose this option, several of the grsecurity options will
47313 + be enabled that will give you greater protection against a number
47314 + of attacks, while assuring that none of your software will have any
47315 + conflicts with the additional security measures. If you run a lot
47316 + of unusual software, or you are having problems with the higher
47317 + security levels, you should say Y here. With this option, the
47318 + following features are enabled:
47319 +
47320 + - Linking restrictions
47321 + - FIFO restrictions
47322 + - Restricted dmesg
47323 + - Enforced chdir("/") on chroot
47324 + - Runtime module disabling
47325 +
47326 +config GRKERNSEC_MEDIUM
47327 + bool "Medium"
47328 + select PAX
47329 + select PAX_EI_PAX
47330 + select PAX_PT_PAX_FLAGS
47331 + select PAX_HAVE_ACL_FLAGS
47332 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
47333 + select GRKERNSEC_CHROOT
47334 + select GRKERNSEC_CHROOT_SYSCTL
47335 + select GRKERNSEC_LINK
47336 + select GRKERNSEC_FIFO
47337 + select GRKERNSEC_DMESG
47338 + select GRKERNSEC_RANDNET
47339 + select GRKERNSEC_FORKFAIL
47340 + select GRKERNSEC_TIME
47341 + select GRKERNSEC_SIGNAL
47342 + select GRKERNSEC_CHROOT
47343 + select GRKERNSEC_CHROOT_UNIX
47344 + select GRKERNSEC_CHROOT_MOUNT
47345 + select GRKERNSEC_CHROOT_PIVOT
47346 + select GRKERNSEC_CHROOT_DOUBLE
47347 + select GRKERNSEC_CHROOT_CHDIR
47348 + select GRKERNSEC_CHROOT_MKNOD
47349 + select GRKERNSEC_PROC
47350 + select GRKERNSEC_PROC_USERGROUP
47351 + select PAX_RANDUSTACK
47352 + select PAX_ASLR
47353 + select PAX_RANDMMAP
47354 + select PAX_REFCOUNT if (X86 || SPARC64)
47355 + select PAX_USERCOPY if ((X86 || SPARC || PPC || ARM) && (SLAB || SLUB || SLOB))
47356 +
47357 + help
47358 + If you say Y here, several features in addition to those included
47359 + in the low additional security level will be enabled. These
47360 + features provide even more security to your system, though in rare
47361 + cases they may be incompatible with very old or poorly written
47362 + software. If you enable this option, make sure that your auth
47363 + service (identd) is running as gid 1001. With this option,
47364 + the following features (in addition to those provided in the
47365 + low additional security level) will be enabled:
47366 +
47367 + - Failed fork logging
47368 + - Time change logging
47369 + - Signal logging
47370 + - Deny mounts in chroot
47371 + - Deny double chrooting
47372 + - Deny sysctl writes in chroot
47373 + - Deny mknod in chroot
47374 + - Deny access to abstract AF_UNIX sockets out of chroot
47375 + - Deny pivot_root in chroot
47376 + - Denied reads/writes of /dev/kmem, /dev/mem, and /dev/port
47377 + - /proc restrictions with special GID set to 10 (usually wheel)
47378 + - Address Space Layout Randomization (ASLR)
47379 + - Prevent exploitation of most refcount overflows
47380 + - Bounds checking of copying between the kernel and userland
47381 +
47382 +config GRKERNSEC_HIGH
47383 + bool "High"
47384 + select GRKERNSEC_LINK
47385 + select GRKERNSEC_FIFO
47386 + select GRKERNSEC_DMESG
47387 + select GRKERNSEC_FORKFAIL
47388 + select GRKERNSEC_TIME
47389 + select GRKERNSEC_SIGNAL
47390 + select GRKERNSEC_CHROOT
47391 + select GRKERNSEC_CHROOT_SHMAT
47392 + select GRKERNSEC_CHROOT_UNIX
47393 + select GRKERNSEC_CHROOT_MOUNT
47394 + select GRKERNSEC_CHROOT_FCHDIR
47395 + select GRKERNSEC_CHROOT_PIVOT
47396 + select GRKERNSEC_CHROOT_DOUBLE
47397 + select GRKERNSEC_CHROOT_CHDIR
47398 + select GRKERNSEC_CHROOT_MKNOD
47399 + select GRKERNSEC_CHROOT_CAPS
47400 + select GRKERNSEC_CHROOT_SYSCTL
47401 + select GRKERNSEC_CHROOT_FINDTASK
47402 + select GRKERNSEC_SYSFS_RESTRICT
47403 + select GRKERNSEC_PROC
47404 + select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
47405 + select GRKERNSEC_HIDESYM
47406 + select GRKERNSEC_BRUTE
47407 + select GRKERNSEC_PROC_USERGROUP
47408 + select GRKERNSEC_KMEM
47409 + select GRKERNSEC_RESLOG
47410 + select GRKERNSEC_RANDNET
47411 + select GRKERNSEC_PROC_ADD
47412 + select GRKERNSEC_CHROOT_CHMOD
47413 + select GRKERNSEC_CHROOT_NICE
47414 + select GRKERNSEC_SETXID
47415 + select GRKERNSEC_AUDIT_MOUNT
47416 + select GRKERNSEC_MODHARDEN if (MODULES)
47417 + select GRKERNSEC_HARDEN_PTRACE
47418 + select GRKERNSEC_PTRACE_READEXEC
47419 + select GRKERNSEC_VM86 if (X86_32)
47420 + select GRKERNSEC_KERN_LOCKOUT if (X86 || ARM || PPC || SPARC)
47421 + select PAX
47422 + select PAX_RANDUSTACK
47423 + select PAX_ASLR
47424 + select PAX_RANDMMAP
47425 + select PAX_NOEXEC
47426 + select PAX_MPROTECT
47427 + select PAX_EI_PAX
47428 + select PAX_PT_PAX_FLAGS
47429 + select PAX_HAVE_ACL_FLAGS
47430 + select PAX_KERNEXEC if ((PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN)
47431 + select PAX_MEMORY_UDEREF if (X86 && !XEN)
47432 + select PAX_RANDKSTACK if (X86_TSC && X86)
47433 + select PAX_SEGMEXEC if (X86_32)
47434 + select PAX_PAGEEXEC
47435 + select PAX_EMUPLT if (ALPHA || PARISC || SPARC)
47436 + select PAX_EMUTRAMP if (PARISC)
47437 + select PAX_EMUSIGRT if (PARISC)
47438 + select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
47439 + select PAX_ELFRELOCS if (PAX_ETEXECRELOCS || (IA64 || PPC || X86))
47440 + select PAX_REFCOUNT if (X86 || SPARC64)
47441 + select PAX_USERCOPY if ((X86 || PPC || SPARC || ARM) && (SLAB || SLUB || SLOB))
47442 + help
47443 + If you say Y here, many of the features of grsecurity will be
47444 + enabled, which will protect you against many kinds of attacks
47445 + against your system. The heightened security comes at a cost
47446 + of an increased chance of incompatibilities with rare software
47447 + on your machine. Since this security level enables PaX, you should
47448 + view <http://pax.grsecurity.net> and read about the PaX
47449 + project. While you are there, download chpax and run it on
47450 + binaries that cause problems with PaX. Also remember that
47451 + since the /proc restrictions are enabled, you must run your
47452 + identd as gid 1001. This security level enables the following
47453 + features in addition to those listed in the low and medium
47454 + security levels:
47455 +
47456 + - Additional /proc restrictions
47457 + - Chmod restrictions in chroot
47458 + - No signals, ptrace, or viewing of processes outside of chroot
47459 + - Capability restrictions in chroot
47460 + - Deny fchdir out of chroot
47461 + - Priority restrictions in chroot
47462 + - Segmentation-based implementation of PaX
47463 + - Mprotect restrictions
47464 + - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
47465 + - Kernel stack randomization
47466 + - Mount/unmount/remount logging
47467 + - Kernel symbol hiding
47468 + - Hardening of module auto-loading
47469 + - Ptrace restrictions
47470 + - Restricted vm86 mode
47471 + - Restricted sysfs/debugfs
47472 + - Active kernel exploit response
47473 +
47474 +config GRKERNSEC_CUSTOM
47475 + bool "Custom"
47476 + help
47477 + If you say Y here, you will be able to configure every grsecurity
47478 + option, which allows you to enable many more features that aren't
47479 + covered in the basic security levels. These additional features
47480 + include TPE, socket restrictions, and the sysctl system for
47481 + grsecurity. It is advised that you read through the help for
47482 + each option to determine its usefulness in your situation.
47483 +
47484 +endchoice
47485 +
47486 +menu "Memory Protections"
47487 +depends on GRKERNSEC
47488 +
47489 +config GRKERNSEC_KMEM
47490 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
47491 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
47492 + help
47493 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
47494 + be written to or read from to modify or leak the contents of the running
47495 + kernel. /dev/port will also not be allowed to be opened. If you have module
47496 + support disabled, enabling this will close up four ways that are
47497 + currently used to insert malicious code into the running kernel.
47498 + Even with all these features enabled, we still highly recommend that
47499 + you use the RBAC system, as it is still possible for an attacker to
47500 + modify the running kernel through privileged I/O granted by ioperm/iopl.
47501 + If you are not using XFree86, you may be able to stop this additional
47502 + case by enabling the 'Disable privileged I/O' option. Though nothing
47503 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
47504 + but only to video memory, which is the only writing we allow in this
47505 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
47506 + not be allowed to mprotect it with PROT_WRITE later.
47507 + It is highly recommended that you say Y here if you meet all the
47508 + conditions above.
47509 +
47510 +config GRKERNSEC_VM86
47511 + bool "Restrict VM86 mode"
47512 + depends on X86_32
47513 +
47514 + help
47515 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
47516 + make use of a special execution mode on 32bit x86 processors called
47517 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
47518 + video cards and will still work with this option enabled. The purpose
47519 + of the option is to prevent exploitation of emulation errors in
47520 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
47521 + Nearly all users should be able to enable this option.
47522 +
47523 +config GRKERNSEC_IO
47524 + bool "Disable privileged I/O"
47525 + depends on X86
47526 + select RTC_CLASS
47527 + select RTC_INTF_DEV
47528 + select RTC_DRV_CMOS
47529 +
47530 + help
47531 + If you say Y here, all ioperm and iopl calls will return an error.
47532 + Ioperm and iopl can be used to modify the running kernel.
47533 + Unfortunately, some programs need this access to operate properly,
47534 + the most notable of which are XFree86 and hwclock. hwclock can be
47535 + remedied by having RTC support in the kernel, so real-time
47536 + clock support is enabled if this option is enabled, to ensure
47537 + that hwclock operates correctly. XFree86 still will not
47538 + operate correctly with this option enabled, so DO NOT CHOOSE Y
47539 + IF YOU USE XFree86. If you use XFree86 and you still want to
47540 + protect your kernel against modification, use the RBAC system.
47541 +
47542 +config GRKERNSEC_PROC_MEMMAP
47543 + bool "Harden ASLR against information leaks and entropy reduction"
47544 + default y if (PAX_NOEXEC || PAX_ASLR)
47545 + depends on PAX_NOEXEC || PAX_ASLR
47546 + help
47547 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
47548 + give no information about the addresses of its mappings if
47549 + PaX features that rely on random addresses are enabled on the task.
47550 + In addition to sanitizing this information and disabling other
47551 + dangerous sources of information, this option causes reads of sensitive
47552 + /proc/<pid> entries where the file descriptor was opened in a different
47553 + task than the one performing the read. Such attempts are logged.
47554 + Finally, this option limits argv/env strings for suid/sgid binaries
47555 + to 1MB to prevent a complete exhaustion of the stack entropy provided
47556 + by ASLR.
47557 + If you use PaX it is essential that you say Y here as it closes up
47558 + several holes that make full ASLR useless for suid/sgid binaries.
47559 +
47560 +config GRKERNSEC_BRUTE
47561 + bool "Deter exploit bruteforcing"
47562 + help
47563 + If you say Y here, attempts to bruteforce exploits against forking
47564 + daemons such as apache or sshd, as well as against suid/sgid binaries
47565 + will be deterred. When a child of a forking daemon is killed by PaX
47566 + or crashes due to an illegal instruction or other suspicious signal,
47567 + the parent process will be delayed 30 seconds upon every subsequent
47568 + fork until the administrator is able to assess the situation and
47569 + restart the daemon.
47570 + In the suid/sgid case, the attempt is logged, the user has all their
47571 + processes terminated, and they are prevented from executing any further
47572 + processes for 15 minutes.
47573 + It is recommended that you also enable signal logging in the auditing
47574 + section so that logs are generated when a process triggers a suspicious
47575 + signal.
47576 + If the sysctl option is enabled, a sysctl option with name
47577 + "deter_bruteforce" is created.
47578 +
47579 +
47580 +config GRKERNSEC_MODHARDEN
47581 + bool "Harden module auto-loading"
47582 + depends on MODULES
47583 + help
47584 + If you say Y here, module auto-loading in response to use of some
47585 + feature implemented by an unloaded module will be restricted to
47586 + root users. Enabling this option helps defend against attacks
47587 + by unprivileged users who abuse the auto-loading behavior to
47588 + cause a vulnerable module to load that is then exploited.
47589 +
47590 + If this option prevents a legitimate use of auto-loading for a
47591 + non-root user, the administrator can execute modprobe manually
47592 + with the exact name of the module mentioned in the alert log.
47593 + Alternatively, the administrator can add the module to the list
47594 + of modules loaded at boot by modifying init scripts.
47595 +
47596 + Modification of init scripts will most likely be needed on
47597 + Ubuntu servers with encrypted home directory support enabled,
47598 + as the first non-root user logging in will cause the ecb(aes),
47599 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
47600 +
47601 +config GRKERNSEC_HIDESYM
47602 + bool "Hide kernel symbols"
47603 + help
47604 + If you say Y here, getting information on loaded modules, and
47605 + displaying all kernel symbols through a syscall will be restricted
47606 + to users with CAP_SYS_MODULE. For software compatibility reasons,
47607 + /proc/kallsyms will be restricted to the root user. The RBAC
47608 + system can hide that entry even from root.
47609 +
47610 + This option also prevents leaking of kernel addresses through
47611 + several /proc entries.
47612 +
47613 + Note that this option is only effective provided the following
47614 + conditions are met:
47615 + 1) The kernel using grsecurity is not precompiled by some distribution
47616 + 2) You have also enabled GRKERNSEC_DMESG
47617 + 3) You are using the RBAC system and hiding other files such as your
47618 + kernel image and System.map. Alternatively, enabling this option
47619 + causes the permissions on /boot, /lib/modules, and the kernel
47620 + source directory to change at compile time to prevent
47621 + reading by non-root users.
47622 + If the above conditions are met, this option will aid in providing a
47623 + useful protection against local kernel exploitation of overflows
47624 + and arbitrary read/write vulnerabilities.
47625 +
47626 +config GRKERNSEC_KERN_LOCKOUT
47627 + bool "Active kernel exploit response"
47628 + depends on X86 || ARM || PPC || SPARC
47629 + help
47630 + If you say Y here, when a PaX alert is triggered due to suspicious
47631 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
47632 + or an OOPs occurs due to bad memory accesses, instead of just
47633 + terminating the offending process (and potentially allowing
47634 + a subsequent exploit from the same user), we will take one of two
47635 + actions:
47636 + If the user was root, we will panic the system
47637 + If the user was non-root, we will log the attempt, terminate
47638 + all processes owned by the user, then prevent them from creating
47639 + any new processes until the system is restarted
47640 + This deters repeated kernel exploitation/bruteforcing attempts
47641 + and is useful for later forensics.
47642 +
47643 +endmenu
47644 +menu "Role Based Access Control Options"
47645 +depends on GRKERNSEC
47646 +
47647 +config GRKERNSEC_RBAC_DEBUG
47648 + bool
47649 +
47650 +config GRKERNSEC_NO_RBAC
47651 + bool "Disable RBAC system"
47652 + help
47653 + If you say Y here, the /dev/grsec device will be removed from the kernel,
47654 + preventing the RBAC system from being enabled. You should only say Y
47655 + here if you have no intention of using the RBAC system, so as to prevent
47656 + an attacker with root access from misusing the RBAC system to hide files
47657 + and processes when loadable module support and /dev/[k]mem have been
47658 + locked down.
47659 +
47660 +config GRKERNSEC_ACL_HIDEKERN
47661 + bool "Hide kernel processes"
47662 + help
47663 + If you say Y here, all kernel threads will be hidden to all
47664 + processes but those whose subject has the "view hidden processes"
47665 + flag.
47666 +
47667 +config GRKERNSEC_ACL_MAXTRIES
47668 + int "Maximum tries before password lockout"
47669 + default 3
47670 + help
47671 + This option enforces the maximum number of times a user can attempt
47672 + to authorize themselves with the grsecurity RBAC system before being
47673 + denied the ability to attempt authorization again for a specified time.
47674 + The lower the number, the harder it will be to brute-force a password.
47675 +
47676 +config GRKERNSEC_ACL_TIMEOUT
47677 + int "Time to wait after max password tries, in seconds"
47678 + default 30
47679 + help
47680 + This option specifies the time the user must wait after attempting to
47681 + authorize to the RBAC system with the maximum number of invalid
47682 + passwords. The higher the number, the harder it will be to brute-force
47683 + a password.
47684 +
47685 +endmenu
47686 +menu "Filesystem Protections"
47687 +depends on GRKERNSEC
47688 +
47689 +config GRKERNSEC_PROC
47690 + bool "Proc restrictions"
47691 + help
47692 + If you say Y here, the permissions of the /proc filesystem
47693 + will be altered to enhance system security and privacy. You MUST
47694 + choose either a user only restriction or a user and group restriction.
47695 + Depending upon the option you choose, you can either restrict users to
47696 + see only the processes they themselves run, or choose a group that can
47697 + view all processes and files normally restricted to root if you choose
47698 + the "restrict to user only" option. NOTE: If you're running identd as
47699 + a non-root user, you will have to run it as the group you specify here.
47700 +
47701 +config GRKERNSEC_PROC_USER
47702 + bool "Restrict /proc to user only"
47703 + depends on GRKERNSEC_PROC
47704 + help
47705 + If you say Y here, non-root users will only be able to view their own
47706 + processes, and restricts them from viewing network-related information,
47707 + and viewing kernel symbol and module information.
47708 +
47709 +config GRKERNSEC_PROC_USERGROUP
47710 + bool "Allow special group"
47711 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
47712 + help
47713 + If you say Y here, you will be able to select a group that will be
47714 + able to view all processes and network-related information. If you've
47715 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
47716 + remain hidden. This option is useful if you want to run identd as
47717 + a non-root user.
47718 +
47719 +config GRKERNSEC_PROC_GID
47720 + int "GID for special group"
47721 + depends on GRKERNSEC_PROC_USERGROUP
47722 + default 1001
47723 +
47724 +config GRKERNSEC_PROC_ADD
47725 + bool "Additional restrictions"
47726 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
47727 + help
47728 + If you say Y here, additional restrictions will be placed on
47729 + /proc that keep normal users from viewing device information and
47730 + slabinfo information that could be useful for exploits.
47731 +
47732 +config GRKERNSEC_LINK
47733 + bool "Linking restrictions"
47734 + help
47735 + If you say Y here, /tmp race exploits will be prevented, since users
47736 + will no longer be able to follow symlinks owned by other users in
47737 + world-writable +t directories (e.g. /tmp), unless the owner of the
47738 + symlink is the owner of the directory. users will also not be
47739 + able to hardlink to files they do not own. If the sysctl option is
47740 + enabled, a sysctl option with name "linking_restrictions" is created.
47741 +
47742 +config GRKERNSEC_FIFO
47743 + bool "FIFO restrictions"
47744 + help
47745 + If you say Y here, users will not be able to write to FIFOs they don't
47746 + own in world-writable +t directories (e.g. /tmp), unless the owner of
47747 + the FIFO is the same owner of the directory it's held in. If the sysctl
47748 + option is enabled, a sysctl option with name "fifo_restrictions" is
47749 + created.
47750 +
47751 +config GRKERNSEC_SYSFS_RESTRICT
47752 + bool "Sysfs/debugfs restriction"
47753 + depends on SYSFS
47754 + help
47755 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
47756 + any filesystem normally mounted under it (e.g. debugfs) will be
47757 + mostly accessible only by root. These filesystems generally provide access
47758 + to hardware and debug information that isn't appropriate for unprivileged
47759 + users of the system. Sysfs and debugfs have also become a large source
47760 + of new vulnerabilities, ranging from infoleaks to local compromise.
47761 + There has been very little oversight with an eye toward security involved
47762 + in adding new exporters of information to these filesystems, so their
47763 + use is discouraged.
47764 + For reasons of compatibility, a few directories have been whitelisted
47765 + for access by non-root users:
47766 + /sys/fs/selinux
47767 + /sys/fs/fuse
47768 + /sys/devices/system/cpu
47769 +
47770 +config GRKERNSEC_ROFS
47771 + bool "Runtime read-only mount protection"
47772 + help
47773 + If you say Y here, a sysctl option with name "romount_protect" will
47774 + be created. By setting this option to 1 at runtime, filesystems
47775 + will be protected in the following ways:
47776 + * No new writable mounts will be allowed
47777 + * Existing read-only mounts won't be able to be remounted read/write
47778 + * Write operations will be denied on all block devices
47779 + This option acts independently of grsec_lock: once it is set to 1,
47780 + it cannot be turned off. Therefore, please be mindful of the resulting
47781 + behavior if this option is enabled in an init script on a read-only
47782 + filesystem. This feature is mainly intended for secure embedded systems.
47783 +
47784 +config GRKERNSEC_CHROOT
47785 + bool "Chroot jail restrictions"
47786 + help
47787 + If you say Y here, you will be able to choose several options that will
47788 + make breaking out of a chrooted jail much more difficult. If you
47789 + encounter no software incompatibilities with the following options, it
47790 + is recommended that you enable each one.
47791 +
47792 +config GRKERNSEC_CHROOT_MOUNT
47793 + bool "Deny mounts"
47794 + depends on GRKERNSEC_CHROOT
47795 + help
47796 + If you say Y here, processes inside a chroot will not be able to
47797 + mount or remount filesystems. If the sysctl option is enabled, a
47798 + sysctl option with name "chroot_deny_mount" is created.
47799 +
47800 +config GRKERNSEC_CHROOT_DOUBLE
47801 + bool "Deny double-chroots"
47802 + depends on GRKERNSEC_CHROOT
47803 + help
47804 + If you say Y here, processes inside a chroot will not be able to chroot
47805 + again outside the chroot. This is a widely used method of breaking
47806 + out of a chroot jail and should not be allowed. If the sysctl
47807 + option is enabled, a sysctl option with name
47808 + "chroot_deny_chroot" is created.
47809 +
47810 +config GRKERNSEC_CHROOT_PIVOT
47811 + bool "Deny pivot_root in chroot"
47812 + depends on GRKERNSEC_CHROOT
47813 + help
47814 + If you say Y here, processes inside a chroot will not be able to use
47815 + a function called pivot_root() that was introduced in Linux 2.3.41. It
47816 + works similar to chroot in that it changes the root filesystem. This
47817 + function could be misused in a chrooted process to attempt to break out
47818 + of the chroot, and therefore should not be allowed. If the sysctl
47819 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
47820 + created.
47821 +
47822 +config GRKERNSEC_CHROOT_CHDIR
47823 + bool "Enforce chdir(\"/\") on all chroots"
47824 + depends on GRKERNSEC_CHROOT
47825 + help
47826 + If you say Y here, the current working directory of all newly-chrooted
47827 + applications will be set to the the root directory of the chroot.
47828 + The man page on chroot(2) states:
47829 + Note that this call does not change the current working
47830 + directory, so that `.' can be outside the tree rooted at
47831 + `/'. In particular, the super-user can escape from a
47832 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
47833 +
47834 + It is recommended that you say Y here, since it's not known to break
47835 + any software. If the sysctl option is enabled, a sysctl option with
47836 + name "chroot_enforce_chdir" is created.
47837 +
47838 +config GRKERNSEC_CHROOT_CHMOD
47839 + bool "Deny (f)chmod +s"
47840 + depends on GRKERNSEC_CHROOT
47841 + help
47842 + If you say Y here, processes inside a chroot will not be able to chmod
47843 + or fchmod files to make them have suid or sgid bits. This protects
47844 + against another published method of breaking a chroot. If the sysctl
47845 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
47846 + created.
47847 +
47848 +config GRKERNSEC_CHROOT_FCHDIR
47849 + bool "Deny fchdir out of chroot"
47850 + depends on GRKERNSEC_CHROOT
47851 + help
47852 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
47853 + to a file descriptor of the chrooting process that points to a directory
47854 + outside the filesystem will be stopped. If the sysctl option
47855 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
47856 +
47857 +config GRKERNSEC_CHROOT_MKNOD
47858 + bool "Deny mknod"
47859 + depends on GRKERNSEC_CHROOT
47860 + help
47861 + If you say Y here, processes inside a chroot will not be allowed to
47862 + mknod. The problem with using mknod inside a chroot is that it
47863 + would allow an attacker to create a device entry that is the same
47864 + as one on the physical root of your system, which could range from
47865 + anything from the console device to a device for your harddrive (which
47866 + they could then use to wipe the drive or steal data). It is recommended
47867 + that you say Y here, unless you run into software incompatibilities.
47868 + If the sysctl option is enabled, a sysctl option with name
47869 + "chroot_deny_mknod" is created.
47870 +
47871 +config GRKERNSEC_CHROOT_SHMAT
47872 + bool "Deny shmat() out of chroot"
47873 + depends on GRKERNSEC_CHROOT
47874 + help
47875 + If you say Y here, processes inside a chroot will not be able to attach
47876 + to shared memory segments that were created outside of the chroot jail.
47877 + It is recommended that you say Y here. If the sysctl option is enabled,
47878 + a sysctl option with name "chroot_deny_shmat" is created.
47879 +
47880 +config GRKERNSEC_CHROOT_UNIX
47881 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
47882 + depends on GRKERNSEC_CHROOT
47883 + help
47884 + If you say Y here, processes inside a chroot will not be able to
47885 + connect to abstract (meaning not belonging to a filesystem) Unix
47886 + domain sockets that were bound outside of a chroot. It is recommended
47887 + that you say Y here. If the sysctl option is enabled, a sysctl option
47888 + with name "chroot_deny_unix" is created.
47889 +
47890 +config GRKERNSEC_CHROOT_FINDTASK
47891 + bool "Protect outside processes"
47892 + depends on GRKERNSEC_CHROOT
47893 + help
47894 + If you say Y here, processes inside a chroot will not be able to
47895 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
47896 + getsid, or view any process outside of the chroot. If the sysctl
47897 + option is enabled, a sysctl option with name "chroot_findtask" is
47898 + created.
47899 +
47900 +config GRKERNSEC_CHROOT_NICE
47901 + bool "Restrict priority changes"
47902 + depends on GRKERNSEC_CHROOT
47903 + help
47904 + If you say Y here, processes inside a chroot will not be able to raise
47905 + the priority of processes in the chroot, or alter the priority of
47906 + processes outside the chroot. This provides more security than simply
47907 + removing CAP_SYS_NICE from the process' capability set. If the
47908 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
47909 + is created.
47910 +
47911 +config GRKERNSEC_CHROOT_SYSCTL
47912 + bool "Deny sysctl writes"
47913 + depends on GRKERNSEC_CHROOT
47914 + help
47915 + If you say Y here, an attacker in a chroot will not be able to
47916 + write to sysctl entries, either by sysctl(2) or through a /proc
47917 + interface. It is strongly recommended that you say Y here. If the
47918 + sysctl option is enabled, a sysctl option with name
47919 + "chroot_deny_sysctl" is created.
47920 +
47921 +config GRKERNSEC_CHROOT_CAPS
47922 + bool "Capability restrictions"
47923 + depends on GRKERNSEC_CHROOT
47924 + help
47925 + If you say Y here, the capabilities on all processes within a
47926 + chroot jail will be lowered to stop module insertion, raw i/o,
47927 + system and net admin tasks, rebooting the system, modifying immutable
47928 + files, modifying IPC owned by another, and changing the system time.
47929 + This is left an option because it can break some apps. Disable this
47930 + if your chrooted apps are having problems performing those kinds of
47931 + tasks. If the sysctl option is enabled, a sysctl option with
47932 + name "chroot_caps" is created.
47933 +
47934 +endmenu
47935 +menu "Kernel Auditing"
47936 +depends on GRKERNSEC
47937 +
47938 +config GRKERNSEC_AUDIT_GROUP
47939 + bool "Single group for auditing"
47940 + help
47941 + If you say Y here, the exec, chdir, and (un)mount logging features
47942 + will only operate on a group you specify. This option is recommended
47943 + if you only want to watch certain users instead of having a large
47944 + amount of logs from the entire system. If the sysctl option is enabled,
47945 + a sysctl option with name "audit_group" is created.
47946 +
47947 +config GRKERNSEC_AUDIT_GID
47948 + int "GID for auditing"
47949 + depends on GRKERNSEC_AUDIT_GROUP
47950 + default 1007
47951 +
47952 +config GRKERNSEC_EXECLOG
47953 + bool "Exec logging"
47954 + help
47955 + If you say Y here, all execve() calls will be logged (since the
47956 + other exec*() calls are frontends to execve(), all execution
47957 + will be logged). Useful for shell-servers that like to keep track
47958 + of their users. If the sysctl option is enabled, a sysctl option with
47959 + name "exec_logging" is created.
47960 + WARNING: This option when enabled will produce a LOT of logs, especially
47961 + on an active system.
47962 +
47963 +config GRKERNSEC_RESLOG
47964 + bool "Resource logging"
47965 + help
47966 + If you say Y here, all attempts to overstep resource limits will
47967 + be logged with the resource name, the requested size, and the current
47968 + limit. It is highly recommended that you say Y here. If the sysctl
47969 + option is enabled, a sysctl option with name "resource_logging" is
47970 + created. If the RBAC system is enabled, the sysctl value is ignored.
47971 +
47972 +config GRKERNSEC_CHROOT_EXECLOG
47973 + bool "Log execs within chroot"
47974 + help
47975 + If you say Y here, all executions inside a chroot jail will be logged
47976 + to syslog. This can cause a large amount of logs if certain
47977 + applications (eg. djb's daemontools) are installed on the system, and
47978 + is therefore left as an option. If the sysctl option is enabled, a
47979 + sysctl option with name "chroot_execlog" is created.
47980 +
47981 +config GRKERNSEC_AUDIT_PTRACE
47982 + bool "Ptrace logging"
47983 + help
47984 + If you say Y here, all attempts to attach to a process via ptrace
47985 + will be logged. If the sysctl option is enabled, a sysctl option
47986 + with name "audit_ptrace" is created.
47987 +
47988 +config GRKERNSEC_AUDIT_CHDIR
47989 + bool "Chdir logging"
47990 + help
47991 + If you say Y here, all chdir() calls will be logged. If the sysctl
47992 + option is enabled, a sysctl option with name "audit_chdir" is created.
47993 +
47994 +config GRKERNSEC_AUDIT_MOUNT
47995 + bool "(Un)Mount logging"
47996 + help
47997 + If you say Y here, all mounts and unmounts will be logged. If the
47998 + sysctl option is enabled, a sysctl option with name "audit_mount" is
47999 + created.
48000 +
48001 +config GRKERNSEC_SIGNAL
48002 + bool "Signal logging"
48003 + help
48004 + If you say Y here, certain important signals will be logged, such as
48005 + SIGSEGV, which will as a result inform you of when a error in a program
48006 + occurred, which in some cases could mean a possible exploit attempt.
48007 + If the sysctl option is enabled, a sysctl option with name
48008 + "signal_logging" is created.
48009 +
48010 +config GRKERNSEC_FORKFAIL
48011 + bool "Fork failure logging"
48012 + help
48013 + If you say Y here, all failed fork() attempts will be logged.
48014 + This could suggest a fork bomb, or someone attempting to overstep
48015 + their process limit. If the sysctl option is enabled, a sysctl option
48016 + with name "forkfail_logging" is created.
48017 +
48018 +config GRKERNSEC_TIME
48019 + bool "Time change logging"
48020 + help
48021 + If you say Y here, any changes of the system clock will be logged.
48022 + If the sysctl option is enabled, a sysctl option with name
48023 + "timechange_logging" is created.
48024 +
48025 +config GRKERNSEC_PROC_IPADDR
48026 + bool "/proc/<pid>/ipaddr support"
48027 + help
48028 + If you say Y here, a new entry will be added to each /proc/<pid>
48029 + directory that contains the IP address of the person using the task.
48030 + The IP is carried across local TCP and AF_UNIX stream sockets.
48031 + This information can be useful for IDS/IPSes to perform remote response
48032 + to a local attack. The entry is readable by only the owner of the
48033 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
48034 + the RBAC system), and thus does not create privacy concerns.
48035 +
48036 +config GRKERNSEC_RWXMAP_LOG
48037 + bool 'Denied RWX mmap/mprotect logging'
48038 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
48039 + help
48040 + If you say Y here, calls to mmap() and mprotect() with explicit
48041 + usage of PROT_WRITE and PROT_EXEC together will be logged when
48042 + denied by the PAX_MPROTECT feature. If the sysctl option is
48043 + enabled, a sysctl option with name "rwxmap_logging" is created.
48044 +
48045 +config GRKERNSEC_AUDIT_TEXTREL
48046 + bool 'ELF text relocations logging (READ HELP)'
48047 + depends on PAX_MPROTECT
48048 + help
48049 + If you say Y here, text relocations will be logged with the filename
48050 + of the offending library or binary. The purpose of the feature is
48051 + to help Linux distribution developers get rid of libraries and
48052 + binaries that need text relocations which hinder the future progress
48053 + of PaX. Only Linux distribution developers should say Y here, and
48054 + never on a production machine, as this option creates an information
48055 + leak that could aid an attacker in defeating the randomization of
48056 + a single memory region. If the sysctl option is enabled, a sysctl
48057 + option with name "audit_textrel" is created.
48058 +
48059 +endmenu
48060 +
48061 +menu "Executable Protections"
48062 +depends on GRKERNSEC
48063 +
48064 +config GRKERNSEC_DMESG
48065 + bool "Dmesg(8) restriction"
48066 + help
48067 + If you say Y here, non-root users will not be able to use dmesg(8)
48068 + to view up to the last 4kb of messages in the kernel's log buffer.
48069 + The kernel's log buffer often contains kernel addresses and other
48070 + identifying information useful to an attacker in fingerprinting a
48071 + system for a targeted exploit.
48072 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
48073 + created.
48074 +
48075 +config GRKERNSEC_HARDEN_PTRACE
48076 + bool "Deter ptrace-based process snooping"
48077 + help
48078 + If you say Y here, TTY sniffers and other malicious monitoring
48079 + programs implemented through ptrace will be defeated. If you
48080 + have been using the RBAC system, this option has already been
48081 + enabled for several years for all users, with the ability to make
48082 + fine-grained exceptions.
48083 +
48084 + This option only affects the ability of non-root users to ptrace
48085 + processes that are not a descendent of the ptracing process.
48086 + This means that strace ./binary and gdb ./binary will still work,
48087 + but attaching to arbitrary processes will not. If the sysctl
48088 + option is enabled, a sysctl option with name "harden_ptrace" is
48089 + created.
48090 +
48091 +config GRKERNSEC_PTRACE_READEXEC
48092 + bool "Require read access to ptrace sensitive binaries"
48093 + help
48094 + If you say Y here, unprivileged users will not be able to ptrace unreadable
48095 + binaries. This option is useful in environments that
48096 + remove the read bits (e.g. file mode 4711) from suid binaries to
48097 + prevent infoleaking of their contents. This option adds
48098 + consistency to the use of that file mode, as the binary could normally
48099 + be read out when run without privileges while ptracing.
48100 +
48101 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
48102 + is created.
48103 +
48104 +config GRKERNSEC_SETXID
48105 + bool "Enforce consistent multithreaded privileges"
48106 + help
48107 + If you say Y here, a change from a root uid to a non-root uid
48108 + in a multithreaded application will cause the resulting uids,
48109 + gids, supplementary groups, and capabilities in that thread
48110 + to be propagated to the other threads of the process. In most
48111 + cases this is unnecessary, as glibc will emulate this behavior
48112 + on behalf of the application. Other libcs do not act in the
48113 + same way, allowing the other threads of the process to continue
48114 + running with root privileges. If the sysctl option is enabled,
48115 + a sysctl option with name "consistent_setxid" is created.
48116 +
48117 +config GRKERNSEC_TPE
48118 + bool "Trusted Path Execution (TPE)"
48119 + help
48120 + If you say Y here, you will be able to choose a gid to add to the
48121 + supplementary groups of users you want to mark as "untrusted."
48122 + These users will not be able to execute any files that are not in
48123 + root-owned directories writable only by root. If the sysctl option
48124 + is enabled, a sysctl option with name "tpe" is created.
48125 +
48126 +config GRKERNSEC_TPE_ALL
48127 + bool "Partially restrict all non-root users"
48128 + depends on GRKERNSEC_TPE
48129 + help
48130 + If you say Y here, all non-root users will be covered under
48131 + a weaker TPE restriction. This is separate from, and in addition to,
48132 + the main TPE options that you have selected elsewhere. Thus, if a
48133 + "trusted" GID is chosen, this restriction applies to even that GID.
48134 + Under this restriction, all non-root users will only be allowed to
48135 + execute files in directories they own that are not group or
48136 + world-writable, or in directories owned by root and writable only by
48137 + root. If the sysctl option is enabled, a sysctl option with name
48138 + "tpe_restrict_all" is created.
48139 +
48140 +config GRKERNSEC_TPE_INVERT
48141 + bool "Invert GID option"
48142 + depends on GRKERNSEC_TPE
48143 + help
48144 + If you say Y here, the group you specify in the TPE configuration will
48145 + decide what group TPE restrictions will be *disabled* for. This
48146 + option is useful if you want TPE restrictions to be applied to most
48147 + users on the system. If the sysctl option is enabled, a sysctl option
48148 + with name "tpe_invert" is created. Unlike other sysctl options, this
48149 + entry will default to on for backward-compatibility.
48150 +
48151 +config GRKERNSEC_TPE_GID
48152 + int "GID for untrusted users"
48153 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
48154 + default 1005
48155 + help
48156 + Setting this GID determines what group TPE restrictions will be
48157 + *enabled* for. If the sysctl option is enabled, a sysctl option
48158 + with name "tpe_gid" is created.
48159 +
48160 +config GRKERNSEC_TPE_GID
48161 + int "GID for trusted users"
48162 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
48163 + default 1005
48164 + help
48165 + Setting this GID determines what group TPE restrictions will be
48166 + *disabled* for. If the sysctl option is enabled, a sysctl option
48167 + with name "tpe_gid" is created.
48168 +
48169 +endmenu
48170 +menu "Network Protections"
48171 +depends on GRKERNSEC
48172 +
48173 +config GRKERNSEC_RANDNET
48174 + bool "Larger entropy pools"
48175 + help
48176 + If you say Y here, the entropy pools used for many features of Linux
48177 + and grsecurity will be doubled in size. Since several grsecurity
48178 + features use additional randomness, it is recommended that you say Y
48179 + here. Saying Y here has a similar effect as modifying
48180 + /proc/sys/kernel/random/poolsize.
48181 +
48182 +config GRKERNSEC_BLACKHOLE
48183 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
48184 + depends on NET
48185 + help
48186 + If you say Y here, neither TCP resets nor ICMP
48187 + destination-unreachable packets will be sent in response to packets
48188 + sent to ports for which no associated listening process exists.
48189 + This feature supports both IPV4 and IPV6 and exempts the
48190 + loopback interface from blackholing. Enabling this feature
48191 + makes a host more resilient to DoS attacks and reduces network
48192 + visibility against scanners.
48193 +
48194 + The blackhole feature as-implemented is equivalent to the FreeBSD
48195 + blackhole feature, as it prevents RST responses to all packets, not
48196 + just SYNs. Under most application behavior this causes no
48197 + problems, but applications (like haproxy) may not close certain
48198 + connections in a way that cleanly terminates them on the remote
48199 + end, leaving the remote host in LAST_ACK state. Because of this
48200 + side-effect and to prevent intentional LAST_ACK DoSes, this
48201 + feature also adds automatic mitigation against such attacks.
48202 + The mitigation drastically reduces the amount of time a socket
48203 + can spend in LAST_ACK state. If you're using haproxy and not
48204 + all servers it connects to have this option enabled, consider
48205 + disabling this feature on the haproxy host.
48206 +
48207 + If the sysctl option is enabled, two sysctl options with names
48208 + "ip_blackhole" and "lastack_retries" will be created.
48209 + While "ip_blackhole" takes the standard zero/non-zero on/off
48210 + toggle, "lastack_retries" uses the same kinds of values as
48211 + "tcp_retries1" and "tcp_retries2". The default value of 4
48212 + prevents a socket from lasting more than 45 seconds in LAST_ACK
48213 + state.
48214 +
48215 +config GRKERNSEC_SOCKET
48216 + bool "Socket restrictions"
48217 + depends on NET
48218 + help
48219 + If you say Y here, you will be able to choose from several options.
48220 + If you assign a GID on your system and add it to the supplementary
48221 + groups of users you want to restrict socket access to, this patch
48222 + will perform up to three things, based on the option(s) you choose.
48223 +
48224 +config GRKERNSEC_SOCKET_ALL
48225 + bool "Deny any sockets to group"
48226 + depends on GRKERNSEC_SOCKET
48227 + help
48228 + If you say Y here, you will be able to choose a GID of whose users will
48229 + be unable to connect to other hosts from your machine or run server
48230 + applications from your machine. If the sysctl option is enabled, a
48231 + sysctl option with name "socket_all" is created.
48232 +
48233 +config GRKERNSEC_SOCKET_ALL_GID
48234 + int "GID to deny all sockets for"
48235 + depends on GRKERNSEC_SOCKET_ALL
48236 + default 1004
48237 + help
48238 + Here you can choose the GID to disable socket access for. Remember to
48239 + add the users you want socket access disabled for to the GID
48240 + specified here. If the sysctl option is enabled, a sysctl option
48241 + with name "socket_all_gid" is created.
48242 +
48243 +config GRKERNSEC_SOCKET_CLIENT
48244 + bool "Deny client sockets to group"
48245 + depends on GRKERNSEC_SOCKET
48246 + help
48247 + If you say Y here, you will be able to choose a GID of whose users will
48248 + be unable to connect to other hosts from your machine, but will be
48249 + able to run servers. If this option is enabled, all users in the group
48250 + you specify will have to use passive mode when initiating ftp transfers
48251 + from the shell on your machine. If the sysctl option is enabled, a
48252 + sysctl option with name "socket_client" is created.
48253 +
48254 +config GRKERNSEC_SOCKET_CLIENT_GID
48255 + int "GID to deny client sockets for"
48256 + depends on GRKERNSEC_SOCKET_CLIENT
48257 + default 1003
48258 + help
48259 + Here you can choose the GID to disable client socket access for.
48260 + Remember to add the users you want client socket access disabled for to
48261 + the GID specified here. If the sysctl option is enabled, a sysctl
48262 + option with name "socket_client_gid" is created.
48263 +
48264 +config GRKERNSEC_SOCKET_SERVER
48265 + bool "Deny server sockets to group"
48266 + depends on GRKERNSEC_SOCKET
48267 + help
48268 + If you say Y here, you will be able to choose a GID of whose users will
48269 + be unable to run server applications from your machine. If the sysctl
48270 + option is enabled, a sysctl option with name "socket_server" is created.
48271 +
48272 +config GRKERNSEC_SOCKET_SERVER_GID
48273 + int "GID to deny server sockets for"
48274 + depends on GRKERNSEC_SOCKET_SERVER
48275 + default 1002
48276 + help
48277 + Here you can choose the GID to disable server socket access for.
48278 + Remember to add the users you want server socket access disabled for to
48279 + the GID specified here. If the sysctl option is enabled, a sysctl
48280 + option with name "socket_server_gid" is created.
48281 +
48282 +endmenu
48283 +menu "Sysctl support"
48284 +depends on GRKERNSEC && SYSCTL
48285 +
48286 +config GRKERNSEC_SYSCTL
48287 + bool "Sysctl support"
48288 + help
48289 + If you say Y here, you will be able to change the options that
48290 + grsecurity runs with at bootup, without having to recompile your
48291 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
48292 + to enable (1) or disable (0) various features. All the sysctl entries
48293 + are mutable until the "grsec_lock" entry is set to a non-zero value.
48294 + All features enabled in the kernel configuration are disabled at boot
48295 + if you do not say Y to the "Turn on features by default" option.
48296 + All options should be set at startup, and the grsec_lock entry should
48297 + be set to a non-zero value after all the options are set.
48298 + *THIS IS EXTREMELY IMPORTANT*
48299 +
48300 +config GRKERNSEC_SYSCTL_DISTRO
48301 + bool "Extra sysctl support for distro makers (READ HELP)"
48302 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
48303 + help
48304 + If you say Y here, additional sysctl options will be created
48305 + for features that affect processes running as root. Therefore,
48306 + it is critical when using this option that the grsec_lock entry be
48307 + enabled after boot. Only distros with prebuilt kernel packages
48308 + with this option enabled that can ensure grsec_lock is enabled
48309 + after boot should use this option.
48310 + *Failure to set grsec_lock after boot makes all grsec features
48311 + this option covers useless*
48312 +
48313 + Currently this option creates the following sysctl entries:
48314 + "Disable Privileged I/O": "disable_priv_io"
48315 +
48316 +config GRKERNSEC_SYSCTL_ON
48317 + bool "Turn on features by default"
48318 + depends on GRKERNSEC_SYSCTL
48319 + help
48320 + If you say Y here, instead of having all features enabled in the
48321 + kernel configuration disabled at boot time, the features will be
48322 + enabled at boot time. It is recommended you say Y here unless
48323 + there is some reason you would want all sysctl-tunable features to
48324 + be disabled by default. As mentioned elsewhere, it is important
48325 + to enable the grsec_lock entry once you have finished modifying
48326 + the sysctl entries.
48327 +
48328 +endmenu
48329 +menu "Logging Options"
48330 +depends on GRKERNSEC
48331 +
48332 +config GRKERNSEC_FLOODTIME
48333 + int "Seconds in between log messages (minimum)"
48334 + default 10
48335 + help
48336 + This option allows you to enforce the number of seconds between
48337 + grsecurity log messages. The default should be suitable for most
48338 + people, however, if you choose to change it, choose a value small enough
48339 + to allow informative logs to be produced, but large enough to
48340 + prevent flooding.
48341 +
48342 +config GRKERNSEC_FLOODBURST
48343 + int "Number of messages in a burst (maximum)"
48344 + default 6
48345 + help
48346 + This option allows you to choose the maximum number of messages allowed
48347 + within the flood time interval you chose in a separate option. The
48348 + default should be suitable for most people, however if you find that
48349 + many of your logs are being interpreted as flooding, you may want to
48350 + raise this value.
48351 +
48352 +endmenu
48353 +
48354 +endmenu
48355 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
48356 new file mode 100644
48357 index 0000000..496e60d
48358 --- /dev/null
48359 +++ b/grsecurity/Makefile
48360 @@ -0,0 +1,40 @@
48361 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
48362 +# during 2001-2009 it has been completely redesigned by Brad Spengler
48363 +# into an RBAC system
48364 +#
48365 +# All code in this directory and various hooks inserted throughout the kernel
48366 +# are copyright Brad Spengler - Open Source Security, Inc., and released
48367 +# under the GPL v2 or higher
48368 +
48369 +ifndef CONFIG_IA64
48370 +KBUILD_CFLAGS += -Werror
48371 +endif
48372 +
48373 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
48374 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
48375 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
48376 +
48377 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
48378 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
48379 + gracl_learn.o grsec_log.o
48380 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
48381 +
48382 +ifdef CONFIG_NET
48383 +obj-y += grsec_sock.o
48384 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
48385 +endif
48386 +
48387 +ifndef CONFIG_GRKERNSEC
48388 +obj-y += grsec_disabled.o
48389 +endif
48390 +
48391 +ifdef CONFIG_GRKERNSEC_HIDESYM
48392 +extra-y := grsec_hidesym.o
48393 +$(obj)/grsec_hidesym.o:
48394 + @-chmod -f 500 /boot
48395 + @-chmod -f 500 /lib/modules
48396 + @-chmod -f 500 /lib64/modules
48397 + @-chmod -f 500 /lib32/modules
48398 + @-chmod -f 700 .
48399 + @echo ' grsec: protected kernel image paths'
48400 +endif
48401 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
48402 new file mode 100644
48403 index 0000000..7715893
48404 --- /dev/null
48405 +++ b/grsecurity/gracl.c
48406 @@ -0,0 +1,4164 @@
48407 +#include <linux/kernel.h>
48408 +#include <linux/module.h>
48409 +#include <linux/sched.h>
48410 +#include <linux/mm.h>
48411 +#include <linux/file.h>
48412 +#include <linux/fs.h>
48413 +#include <linux/namei.h>
48414 +#include <linux/mount.h>
48415 +#include <linux/tty.h>
48416 +#include <linux/proc_fs.h>
48417 +#include <linux/lglock.h>
48418 +#include <linux/slab.h>
48419 +#include <linux/vmalloc.h>
48420 +#include <linux/types.h>
48421 +#include <linux/sysctl.h>
48422 +#include <linux/netdevice.h>
48423 +#include <linux/ptrace.h>
48424 +#include <linux/gracl.h>
48425 +#include <linux/gralloc.h>
48426 +#include <linux/security.h>
48427 +#include <linux/grinternal.h>
48428 +#include <linux/pid_namespace.h>
48429 +#include <linux/fdtable.h>
48430 +#include <linux/percpu.h>
48431 +
48432 +#include <asm/uaccess.h>
48433 +#include <asm/errno.h>
48434 +#include <asm/mman.h>
48435 +
48436 +static struct acl_role_db acl_role_set;
48437 +static struct name_db name_set;
48438 +static struct inodev_db inodev_set;
48439 +
48440 +/* for keeping track of userspace pointers used for subjects, so we
48441 + can share references in the kernel as well
48442 +*/
48443 +
48444 +static struct path real_root;
48445 +
48446 +static struct acl_subj_map_db subj_map_set;
48447 +
48448 +static struct acl_role_label *default_role;
48449 +
48450 +static struct acl_role_label *role_list;
48451 +
48452 +static u16 acl_sp_role_value;
48453 +
48454 +extern char *gr_shared_page[4];
48455 +static DEFINE_MUTEX(gr_dev_mutex);
48456 +DEFINE_RWLOCK(gr_inode_lock);
48457 +
48458 +struct gr_arg *gr_usermode;
48459 +
48460 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
48461 +
48462 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
48463 +extern void gr_clear_learn_entries(void);
48464 +
48465 +#ifdef CONFIG_GRKERNSEC_RESLOG
48466 +extern void gr_log_resource(const struct task_struct *task,
48467 + const int res, const unsigned long wanted, const int gt);
48468 +#endif
48469 +
48470 +unsigned char *gr_system_salt;
48471 +unsigned char *gr_system_sum;
48472 +
48473 +static struct sprole_pw **acl_special_roles = NULL;
48474 +static __u16 num_sprole_pws = 0;
48475 +
48476 +static struct acl_role_label *kernel_role = NULL;
48477 +
48478 +static unsigned int gr_auth_attempts = 0;
48479 +static unsigned long gr_auth_expires = 0UL;
48480 +
48481 +#ifdef CONFIG_NET
48482 +extern struct vfsmount *sock_mnt;
48483 +#endif
48484 +
48485 +extern struct vfsmount *pipe_mnt;
48486 +extern struct vfsmount *shm_mnt;
48487 +#ifdef CONFIG_HUGETLBFS
48488 +extern struct vfsmount *hugetlbfs_vfsmount;
48489 +#endif
48490 +
48491 +static struct acl_object_label *fakefs_obj_rw;
48492 +static struct acl_object_label *fakefs_obj_rwx;
48493 +
48494 +extern int gr_init_uidset(void);
48495 +extern void gr_free_uidset(void);
48496 +extern void gr_remove_uid(uid_t uid);
48497 +extern int gr_find_uid(uid_t uid);
48498 +
48499 +DECLARE_BRLOCK(vfsmount_lock);
48500 +
48501 +__inline__ int
48502 +gr_acl_is_enabled(void)
48503 +{
48504 + return (gr_status & GR_READY);
48505 +}
48506 +
48507 +#ifdef CONFIG_BTRFS_FS
48508 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
48509 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
48510 +#endif
48511 +
48512 +static inline dev_t __get_dev(const struct dentry *dentry)
48513 +{
48514 +#ifdef CONFIG_BTRFS_FS
48515 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
48516 + return get_btrfs_dev_from_inode(dentry->d_inode);
48517 + else
48518 +#endif
48519 + return dentry->d_inode->i_sb->s_dev;
48520 +}
48521 +
48522 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
48523 +{
48524 + return __get_dev(dentry);
48525 +}
48526 +
48527 +static char gr_task_roletype_to_char(struct task_struct *task)
48528 +{
48529 + switch (task->role->roletype &
48530 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
48531 + GR_ROLE_SPECIAL)) {
48532 + case GR_ROLE_DEFAULT:
48533 + return 'D';
48534 + case GR_ROLE_USER:
48535 + return 'U';
48536 + case GR_ROLE_GROUP:
48537 + return 'G';
48538 + case GR_ROLE_SPECIAL:
48539 + return 'S';
48540 + }
48541 +
48542 + return 'X';
48543 +}
48544 +
48545 +char gr_roletype_to_char(void)
48546 +{
48547 + return gr_task_roletype_to_char(current);
48548 +}
48549 +
48550 +__inline__ int
48551 +gr_acl_tpe_check(void)
48552 +{
48553 + if (unlikely(!(gr_status & GR_READY)))
48554 + return 0;
48555 + if (current->role->roletype & GR_ROLE_TPE)
48556 + return 1;
48557 + else
48558 + return 0;
48559 +}
48560 +
48561 +int
48562 +gr_handle_rawio(const struct inode *inode)
48563 +{
48564 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
48565 + if (inode && S_ISBLK(inode->i_mode) &&
48566 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
48567 + !capable(CAP_SYS_RAWIO))
48568 + return 1;
48569 +#endif
48570 + return 0;
48571 +}
48572 +
48573 +static int
48574 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
48575 +{
48576 + if (likely(lena != lenb))
48577 + return 0;
48578 +
48579 + return !memcmp(a, b, lena);
48580 +}
48581 +
48582 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
48583 +{
48584 + *buflen -= namelen;
48585 + if (*buflen < 0)
48586 + return -ENAMETOOLONG;
48587 + *buffer -= namelen;
48588 + memcpy(*buffer, str, namelen);
48589 + return 0;
48590 +}
48591 +
48592 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
48593 +{
48594 + return prepend(buffer, buflen, name->name, name->len);
48595 +}
48596 +
48597 +static int prepend_path(const struct path *path, struct path *root,
48598 + char **buffer, int *buflen)
48599 +{
48600 + struct dentry *dentry = path->dentry;
48601 + struct vfsmount *vfsmnt = path->mnt;
48602 + bool slash = false;
48603 + int error = 0;
48604 +
48605 + while (dentry != root->dentry || vfsmnt != root->mnt) {
48606 + struct dentry * parent;
48607 +
48608 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
48609 + /* Global root? */
48610 + if (vfsmnt->mnt_parent == vfsmnt) {
48611 + goto out;
48612 + }
48613 + dentry = vfsmnt->mnt_mountpoint;
48614 + vfsmnt = vfsmnt->mnt_parent;
48615 + continue;
48616 + }
48617 + parent = dentry->d_parent;
48618 + prefetch(parent);
48619 + spin_lock(&dentry->d_lock);
48620 + error = prepend_name(buffer, buflen, &dentry->d_name);
48621 + spin_unlock(&dentry->d_lock);
48622 + if (!error)
48623 + error = prepend(buffer, buflen, "/", 1);
48624 + if (error)
48625 + break;
48626 +
48627 + slash = true;
48628 + dentry = parent;
48629 + }
48630 +
48631 +out:
48632 + if (!error && !slash)
48633 + error = prepend(buffer, buflen, "/", 1);
48634 +
48635 + return error;
48636 +}
48637 +
48638 +/* this must be called with vfsmount_lock and rename_lock held */
48639 +
48640 +static char *__our_d_path(const struct path *path, struct path *root,
48641 + char *buf, int buflen)
48642 +{
48643 + char *res = buf + buflen;
48644 + int error;
48645 +
48646 + prepend(&res, &buflen, "\0", 1);
48647 + error = prepend_path(path, root, &res, &buflen);
48648 + if (error)
48649 + return ERR_PTR(error);
48650 +
48651 + return res;
48652 +}
48653 +
48654 +static char *
48655 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
48656 +{
48657 + char *retval;
48658 +
48659 + retval = __our_d_path(path, root, buf, buflen);
48660 + if (unlikely(IS_ERR(retval)))
48661 + retval = strcpy(buf, "<path too long>");
48662 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
48663 + retval[1] = '\0';
48664 +
48665 + return retval;
48666 +}
48667 +
48668 +static char *
48669 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
48670 + char *buf, int buflen)
48671 +{
48672 + struct path path;
48673 + char *res;
48674 +
48675 + path.dentry = (struct dentry *)dentry;
48676 + path.mnt = (struct vfsmount *)vfsmnt;
48677 +
48678 + /* we can use real_root.dentry, real_root.mnt, because this is only called
48679 + by the RBAC system */
48680 + res = gen_full_path(&path, &real_root, buf, buflen);
48681 +
48682 + return res;
48683 +}
48684 +
48685 +static char *
48686 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
48687 + char *buf, int buflen)
48688 +{
48689 + char *res;
48690 + struct path path;
48691 + struct path root;
48692 + struct task_struct *reaper = &init_task;
48693 +
48694 + path.dentry = (struct dentry *)dentry;
48695 + path.mnt = (struct vfsmount *)vfsmnt;
48696 +
48697 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
48698 + get_fs_root(reaper->fs, &root);
48699 +
48700 + write_seqlock(&rename_lock);
48701 + br_read_lock(vfsmount_lock);
48702 + res = gen_full_path(&path, &root, buf, buflen);
48703 + br_read_unlock(vfsmount_lock);
48704 + write_sequnlock(&rename_lock);
48705 +
48706 + path_put(&root);
48707 + return res;
48708 +}
48709 +
48710 +static char *
48711 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
48712 +{
48713 + char *ret;
48714 + write_seqlock(&rename_lock);
48715 + br_read_lock(vfsmount_lock);
48716 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
48717 + PAGE_SIZE);
48718 + br_read_unlock(vfsmount_lock);
48719 + write_sequnlock(&rename_lock);
48720 + return ret;
48721 +}
48722 +
48723 +static char *
48724 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
48725 +{
48726 + char *ret;
48727 + char *buf;
48728 + int buflen;
48729 +
48730 + write_seqlock(&rename_lock);
48731 + br_read_lock(vfsmount_lock);
48732 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
48733 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
48734 + buflen = (int)(ret - buf);
48735 + if (buflen >= 5)
48736 + prepend(&ret, &buflen, "/proc", 5);
48737 + else
48738 + ret = strcpy(buf, "<path too long>");
48739 + br_read_unlock(vfsmount_lock);
48740 + write_sequnlock(&rename_lock);
48741 + return ret;
48742 +}
48743 +
48744 +char *
48745 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
48746 +{
48747 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
48748 + PAGE_SIZE);
48749 +}
48750 +
48751 +char *
48752 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
48753 +{
48754 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
48755 + PAGE_SIZE);
48756 +}
48757 +
48758 +char *
48759 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
48760 +{
48761 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
48762 + PAGE_SIZE);
48763 +}
48764 +
48765 +char *
48766 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
48767 +{
48768 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
48769 + PAGE_SIZE);
48770 +}
48771 +
48772 +char *
48773 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
48774 +{
48775 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
48776 + PAGE_SIZE);
48777 +}
48778 +
48779 +__inline__ __u32
48780 +to_gr_audit(const __u32 reqmode)
48781 +{
48782 + /* masks off auditable permission flags, then shifts them to create
48783 + auditing flags, and adds the special case of append auditing if
48784 + we're requesting write */
48785 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
48786 +}
48787 +
48788 +struct acl_subject_label *
48789 +lookup_subject_map(const struct acl_subject_label *userp)
48790 +{
48791 + unsigned int index = shash(userp, subj_map_set.s_size);
48792 + struct subject_map *match;
48793 +
48794 + match = subj_map_set.s_hash[index];
48795 +
48796 + while (match && match->user != userp)
48797 + match = match->next;
48798 +
48799 + if (match != NULL)
48800 + return match->kernel;
48801 + else
48802 + return NULL;
48803 +}
48804 +
48805 +static void
48806 +insert_subj_map_entry(struct subject_map *subjmap)
48807 +{
48808 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
48809 + struct subject_map **curr;
48810 +
48811 + subjmap->prev = NULL;
48812 +
48813 + curr = &subj_map_set.s_hash[index];
48814 + if (*curr != NULL)
48815 + (*curr)->prev = subjmap;
48816 +
48817 + subjmap->next = *curr;
48818 + *curr = subjmap;
48819 +
48820 + return;
48821 +}
48822 +
48823 +static struct acl_role_label *
48824 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
48825 + const gid_t gid)
48826 +{
48827 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
48828 + struct acl_role_label *match;
48829 + struct role_allowed_ip *ipp;
48830 + unsigned int x;
48831 + u32 curr_ip = task->signal->curr_ip;
48832 +
48833 + task->signal->saved_ip = curr_ip;
48834 +
48835 + match = acl_role_set.r_hash[index];
48836 +
48837 + while (match) {
48838 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
48839 + for (x = 0; x < match->domain_child_num; x++) {
48840 + if (match->domain_children[x] == uid)
48841 + goto found;
48842 + }
48843 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
48844 + break;
48845 + match = match->next;
48846 + }
48847 +found:
48848 + if (match == NULL) {
48849 + try_group:
48850 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
48851 + match = acl_role_set.r_hash[index];
48852 +
48853 + while (match) {
48854 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
48855 + for (x = 0; x < match->domain_child_num; x++) {
48856 + if (match->domain_children[x] == gid)
48857 + goto found2;
48858 + }
48859 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
48860 + break;
48861 + match = match->next;
48862 + }
48863 +found2:
48864 + if (match == NULL)
48865 + match = default_role;
48866 + if (match->allowed_ips == NULL)
48867 + return match;
48868 + else {
48869 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
48870 + if (likely
48871 + ((ntohl(curr_ip) & ipp->netmask) ==
48872 + (ntohl(ipp->addr) & ipp->netmask)))
48873 + return match;
48874 + }
48875 + match = default_role;
48876 + }
48877 + } else if (match->allowed_ips == NULL) {
48878 + return match;
48879 + } else {
48880 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
48881 + if (likely
48882 + ((ntohl(curr_ip) & ipp->netmask) ==
48883 + (ntohl(ipp->addr) & ipp->netmask)))
48884 + return match;
48885 + }
48886 + goto try_group;
48887 + }
48888 +
48889 + return match;
48890 +}
48891 +
48892 +struct acl_subject_label *
48893 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
48894 + const struct acl_role_label *role)
48895 +{
48896 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
48897 + struct acl_subject_label *match;
48898 +
48899 + match = role->subj_hash[index];
48900 +
48901 + while (match && (match->inode != ino || match->device != dev ||
48902 + (match->mode & GR_DELETED))) {
48903 + match = match->next;
48904 + }
48905 +
48906 + if (match && !(match->mode & GR_DELETED))
48907 + return match;
48908 + else
48909 + return NULL;
48910 +}
48911 +
48912 +struct acl_subject_label *
48913 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
48914 + const struct acl_role_label *role)
48915 +{
48916 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
48917 + struct acl_subject_label *match;
48918 +
48919 + match = role->subj_hash[index];
48920 +
48921 + while (match && (match->inode != ino || match->device != dev ||
48922 + !(match->mode & GR_DELETED))) {
48923 + match = match->next;
48924 + }
48925 +
48926 + if (match && (match->mode & GR_DELETED))
48927 + return match;
48928 + else
48929 + return NULL;
48930 +}
48931 +
48932 +static struct acl_object_label *
48933 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
48934 + const struct acl_subject_label *subj)
48935 +{
48936 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
48937 + struct acl_object_label *match;
48938 +
48939 + match = subj->obj_hash[index];
48940 +
48941 + while (match && (match->inode != ino || match->device != dev ||
48942 + (match->mode & GR_DELETED))) {
48943 + match = match->next;
48944 + }
48945 +
48946 + if (match && !(match->mode & GR_DELETED))
48947 + return match;
48948 + else
48949 + return NULL;
48950 +}
48951 +
48952 +static struct acl_object_label *
48953 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
48954 + const struct acl_subject_label *subj)
48955 +{
48956 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
48957 + struct acl_object_label *match;
48958 +
48959 + match = subj->obj_hash[index];
48960 +
48961 + while (match && (match->inode != ino || match->device != dev ||
48962 + !(match->mode & GR_DELETED))) {
48963 + match = match->next;
48964 + }
48965 +
48966 + if (match && (match->mode & GR_DELETED))
48967 + return match;
48968 +
48969 + match = subj->obj_hash[index];
48970 +
48971 + while (match && (match->inode != ino || match->device != dev ||
48972 + (match->mode & GR_DELETED))) {
48973 + match = match->next;
48974 + }
48975 +
48976 + if (match && !(match->mode & GR_DELETED))
48977 + return match;
48978 + else
48979 + return NULL;
48980 +}
48981 +
48982 +static struct name_entry *
48983 +lookup_name_entry(const char *name)
48984 +{
48985 + unsigned int len = strlen(name);
48986 + unsigned int key = full_name_hash(name, len);
48987 + unsigned int index = key % name_set.n_size;
48988 + struct name_entry *match;
48989 +
48990 + match = name_set.n_hash[index];
48991 +
48992 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
48993 + match = match->next;
48994 +
48995 + return match;
48996 +}
48997 +
48998 +static struct name_entry *
48999 +lookup_name_entry_create(const char *name)
49000 +{
49001 + unsigned int len = strlen(name);
49002 + unsigned int key = full_name_hash(name, len);
49003 + unsigned int index = key % name_set.n_size;
49004 + struct name_entry *match;
49005 +
49006 + match = name_set.n_hash[index];
49007 +
49008 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
49009 + !match->deleted))
49010 + match = match->next;
49011 +
49012 + if (match && match->deleted)
49013 + return match;
49014 +
49015 + match = name_set.n_hash[index];
49016 +
49017 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
49018 + match->deleted))
49019 + match = match->next;
49020 +
49021 + if (match && !match->deleted)
49022 + return match;
49023 + else
49024 + return NULL;
49025 +}
49026 +
49027 +static struct inodev_entry *
49028 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
49029 +{
49030 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
49031 + struct inodev_entry *match;
49032 +
49033 + match = inodev_set.i_hash[index];
49034 +
49035 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
49036 + match = match->next;
49037 +
49038 + return match;
49039 +}
49040 +
49041 +static void
49042 +insert_inodev_entry(struct inodev_entry *entry)
49043 +{
49044 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
49045 + inodev_set.i_size);
49046 + struct inodev_entry **curr;
49047 +
49048 + entry->prev = NULL;
49049 +
49050 + curr = &inodev_set.i_hash[index];
49051 + if (*curr != NULL)
49052 + (*curr)->prev = entry;
49053 +
49054 + entry->next = *curr;
49055 + *curr = entry;
49056 +
49057 + return;
49058 +}
49059 +
49060 +static void
49061 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
49062 +{
49063 + unsigned int index =
49064 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
49065 + struct acl_role_label **curr;
49066 + struct acl_role_label *tmp;
49067 +
49068 + curr = &acl_role_set.r_hash[index];
49069 +
49070 + /* if role was already inserted due to domains and already has
49071 + a role in the same bucket as it attached, then we need to
49072 + combine these two buckets
49073 + */
49074 + if (role->next) {
49075 + tmp = role->next;
49076 + while (tmp->next)
49077 + tmp = tmp->next;
49078 + tmp->next = *curr;
49079 + } else
49080 + role->next = *curr;
49081 + *curr = role;
49082 +
49083 + return;
49084 +}
49085 +
49086 +static void
49087 +insert_acl_role_label(struct acl_role_label *role)
49088 +{
49089 + int i;
49090 +
49091 + if (role_list == NULL) {
49092 + role_list = role;
49093 + role->prev = NULL;
49094 + } else {
49095 + role->prev = role_list;
49096 + role_list = role;
49097 + }
49098 +
49099 + /* used for hash chains */
49100 + role->next = NULL;
49101 +
49102 + if (role->roletype & GR_ROLE_DOMAIN) {
49103 + for (i = 0; i < role->domain_child_num; i++)
49104 + __insert_acl_role_label(role, role->domain_children[i]);
49105 + } else
49106 + __insert_acl_role_label(role, role->uidgid);
49107 +}
49108 +
49109 +static int
49110 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
49111 +{
49112 + struct name_entry **curr, *nentry;
49113 + struct inodev_entry *ientry;
49114 + unsigned int len = strlen(name);
49115 + unsigned int key = full_name_hash(name, len);
49116 + unsigned int index = key % name_set.n_size;
49117 +
49118 + curr = &name_set.n_hash[index];
49119 +
49120 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
49121 + curr = &((*curr)->next);
49122 +
49123 + if (*curr != NULL)
49124 + return 1;
49125 +
49126 + nentry = acl_alloc(sizeof (struct name_entry));
49127 + if (nentry == NULL)
49128 + return 0;
49129 + ientry = acl_alloc(sizeof (struct inodev_entry));
49130 + if (ientry == NULL)
49131 + return 0;
49132 + ientry->nentry = nentry;
49133 +
49134 + nentry->key = key;
49135 + nentry->name = name;
49136 + nentry->inode = inode;
49137 + nentry->device = device;
49138 + nentry->len = len;
49139 + nentry->deleted = deleted;
49140 +
49141 + nentry->prev = NULL;
49142 + curr = &name_set.n_hash[index];
49143 + if (*curr != NULL)
49144 + (*curr)->prev = nentry;
49145 + nentry->next = *curr;
49146 + *curr = nentry;
49147 +
49148 + /* insert us into the table searchable by inode/dev */
49149 + insert_inodev_entry(ientry);
49150 +
49151 + return 1;
49152 +}
49153 +
49154 +static void
49155 +insert_acl_obj_label(struct acl_object_label *obj,
49156 + struct acl_subject_label *subj)
49157 +{
49158 + unsigned int index =
49159 + fhash(obj->inode, obj->device, subj->obj_hash_size);
49160 + struct acl_object_label **curr;
49161 +
49162 +
49163 + obj->prev = NULL;
49164 +
49165 + curr = &subj->obj_hash[index];
49166 + if (*curr != NULL)
49167 + (*curr)->prev = obj;
49168 +
49169 + obj->next = *curr;
49170 + *curr = obj;
49171 +
49172 + return;
49173 +}
49174 +
49175 +static void
49176 +insert_acl_subj_label(struct acl_subject_label *obj,
49177 + struct acl_role_label *role)
49178 +{
49179 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
49180 + struct acl_subject_label **curr;
49181 +
49182 + obj->prev = NULL;
49183 +
49184 + curr = &role->subj_hash[index];
49185 + if (*curr != NULL)
49186 + (*curr)->prev = obj;
49187 +
49188 + obj->next = *curr;
49189 + *curr = obj;
49190 +
49191 + return;
49192 +}
49193 +
49194 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
49195 +
49196 +static void *
49197 +create_table(__u32 * len, int elementsize)
49198 +{
49199 + unsigned int table_sizes[] = {
49200 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
49201 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
49202 + 4194301, 8388593, 16777213, 33554393, 67108859
49203 + };
49204 + void *newtable = NULL;
49205 + unsigned int pwr = 0;
49206 +
49207 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
49208 + table_sizes[pwr] <= *len)
49209 + pwr++;
49210 +
49211 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
49212 + return newtable;
49213 +
49214 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
49215 + newtable =
49216 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
49217 + else
49218 + newtable = vmalloc(table_sizes[pwr] * elementsize);
49219 +
49220 + *len = table_sizes[pwr];
49221 +
49222 + return newtable;
49223 +}
49224 +
49225 +static int
49226 +init_variables(const struct gr_arg *arg)
49227 +{
49228 + struct task_struct *reaper = &init_task;
49229 + unsigned int stacksize;
49230 +
49231 + subj_map_set.s_size = arg->role_db.num_subjects;
49232 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
49233 + name_set.n_size = arg->role_db.num_objects;
49234 + inodev_set.i_size = arg->role_db.num_objects;
49235 +
49236 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
49237 + !name_set.n_size || !inodev_set.i_size)
49238 + return 1;
49239 +
49240 + if (!gr_init_uidset())
49241 + return 1;
49242 +
49243 + /* set up the stack that holds allocation info */
49244 +
49245 + stacksize = arg->role_db.num_pointers + 5;
49246 +
49247 + if (!acl_alloc_stack_init(stacksize))
49248 + return 1;
49249 +
49250 + /* grab reference for the real root dentry and vfsmount */
49251 + get_fs_root(reaper->fs, &real_root);
49252 +
49253 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49254 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
49255 +#endif
49256 +
49257 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
49258 + if (fakefs_obj_rw == NULL)
49259 + return 1;
49260 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
49261 +
49262 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
49263 + if (fakefs_obj_rwx == NULL)
49264 + return 1;
49265 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
49266 +
49267 + subj_map_set.s_hash =
49268 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
49269 + acl_role_set.r_hash =
49270 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
49271 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
49272 + inodev_set.i_hash =
49273 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
49274 +
49275 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
49276 + !name_set.n_hash || !inodev_set.i_hash)
49277 + return 1;
49278 +
49279 + memset(subj_map_set.s_hash, 0,
49280 + sizeof(struct subject_map *) * subj_map_set.s_size);
49281 + memset(acl_role_set.r_hash, 0,
49282 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
49283 + memset(name_set.n_hash, 0,
49284 + sizeof (struct name_entry *) * name_set.n_size);
49285 + memset(inodev_set.i_hash, 0,
49286 + sizeof (struct inodev_entry *) * inodev_set.i_size);
49287 +
49288 + return 0;
49289 +}
49290 +
49291 +/* free information not needed after startup
49292 + currently contains user->kernel pointer mappings for subjects
49293 +*/
49294 +
49295 +static void
49296 +free_init_variables(void)
49297 +{
49298 + __u32 i;
49299 +
49300 + if (subj_map_set.s_hash) {
49301 + for (i = 0; i < subj_map_set.s_size; i++) {
49302 + if (subj_map_set.s_hash[i]) {
49303 + kfree(subj_map_set.s_hash[i]);
49304 + subj_map_set.s_hash[i] = NULL;
49305 + }
49306 + }
49307 +
49308 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
49309 + PAGE_SIZE)
49310 + kfree(subj_map_set.s_hash);
49311 + else
49312 + vfree(subj_map_set.s_hash);
49313 + }
49314 +
49315 + return;
49316 +}
49317 +
49318 +static void
49319 +free_variables(void)
49320 +{
49321 + struct acl_subject_label *s;
49322 + struct acl_role_label *r;
49323 + struct task_struct *task, *task2;
49324 + unsigned int x;
49325 +
49326 + gr_clear_learn_entries();
49327 +
49328 + read_lock(&tasklist_lock);
49329 + do_each_thread(task2, task) {
49330 + task->acl_sp_role = 0;
49331 + task->acl_role_id = 0;
49332 + task->acl = NULL;
49333 + task->role = NULL;
49334 + } while_each_thread(task2, task);
49335 + read_unlock(&tasklist_lock);
49336 +
49337 + /* release the reference to the real root dentry and vfsmount */
49338 + path_put(&real_root);
49339 +
49340 + /* free all object hash tables */
49341 +
49342 + FOR_EACH_ROLE_START(r)
49343 + if (r->subj_hash == NULL)
49344 + goto next_role;
49345 + FOR_EACH_SUBJECT_START(r, s, x)
49346 + if (s->obj_hash == NULL)
49347 + break;
49348 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
49349 + kfree(s->obj_hash);
49350 + else
49351 + vfree(s->obj_hash);
49352 + FOR_EACH_SUBJECT_END(s, x)
49353 + FOR_EACH_NESTED_SUBJECT_START(r, s)
49354 + if (s->obj_hash == NULL)
49355 + break;
49356 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
49357 + kfree(s->obj_hash);
49358 + else
49359 + vfree(s->obj_hash);
49360 + FOR_EACH_NESTED_SUBJECT_END(s)
49361 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
49362 + kfree(r->subj_hash);
49363 + else
49364 + vfree(r->subj_hash);
49365 + r->subj_hash = NULL;
49366 +next_role:
49367 + FOR_EACH_ROLE_END(r)
49368 +
49369 + acl_free_all();
49370 +
49371 + if (acl_role_set.r_hash) {
49372 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
49373 + PAGE_SIZE)
49374 + kfree(acl_role_set.r_hash);
49375 + else
49376 + vfree(acl_role_set.r_hash);
49377 + }
49378 + if (name_set.n_hash) {
49379 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
49380 + PAGE_SIZE)
49381 + kfree(name_set.n_hash);
49382 + else
49383 + vfree(name_set.n_hash);
49384 + }
49385 +
49386 + if (inodev_set.i_hash) {
49387 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
49388 + PAGE_SIZE)
49389 + kfree(inodev_set.i_hash);
49390 + else
49391 + vfree(inodev_set.i_hash);
49392 + }
49393 +
49394 + gr_free_uidset();
49395 +
49396 + memset(&name_set, 0, sizeof (struct name_db));
49397 + memset(&inodev_set, 0, sizeof (struct inodev_db));
49398 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
49399 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
49400 +
49401 + default_role = NULL;
49402 + role_list = NULL;
49403 +
49404 + return;
49405 +}
49406 +
49407 +static __u32
49408 +count_user_objs(struct acl_object_label *userp)
49409 +{
49410 + struct acl_object_label o_tmp;
49411 + __u32 num = 0;
49412 +
49413 + while (userp) {
49414 + if (copy_from_user(&o_tmp, userp,
49415 + sizeof (struct acl_object_label)))
49416 + break;
49417 +
49418 + userp = o_tmp.prev;
49419 + num++;
49420 + }
49421 +
49422 + return num;
49423 +}
49424 +
49425 +static struct acl_subject_label *
49426 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
49427 +
49428 +static int
49429 +copy_user_glob(struct acl_object_label *obj)
49430 +{
49431 + struct acl_object_label *g_tmp, **guser;
49432 + unsigned int len;
49433 + char *tmp;
49434 +
49435 + if (obj->globbed == NULL)
49436 + return 0;
49437 +
49438 + guser = &obj->globbed;
49439 + while (*guser) {
49440 + g_tmp = (struct acl_object_label *)
49441 + acl_alloc(sizeof (struct acl_object_label));
49442 + if (g_tmp == NULL)
49443 + return -ENOMEM;
49444 +
49445 + if (copy_from_user(g_tmp, *guser,
49446 + sizeof (struct acl_object_label)))
49447 + return -EFAULT;
49448 +
49449 + len = strnlen_user(g_tmp->filename, PATH_MAX);
49450 +
49451 + if (!len || len >= PATH_MAX)
49452 + return -EINVAL;
49453 +
49454 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49455 + return -ENOMEM;
49456 +
49457 + if (copy_from_user(tmp, g_tmp->filename, len))
49458 + return -EFAULT;
49459 + tmp[len-1] = '\0';
49460 + g_tmp->filename = tmp;
49461 +
49462 + *guser = g_tmp;
49463 + guser = &(g_tmp->next);
49464 + }
49465 +
49466 + return 0;
49467 +}
49468 +
49469 +static int
49470 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
49471 + struct acl_role_label *role)
49472 +{
49473 + struct acl_object_label *o_tmp;
49474 + unsigned int len;
49475 + int ret;
49476 + char *tmp;
49477 +
49478 + while (userp) {
49479 + if ((o_tmp = (struct acl_object_label *)
49480 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
49481 + return -ENOMEM;
49482 +
49483 + if (copy_from_user(o_tmp, userp,
49484 + sizeof (struct acl_object_label)))
49485 + return -EFAULT;
49486 +
49487 + userp = o_tmp->prev;
49488 +
49489 + len = strnlen_user(o_tmp->filename, PATH_MAX);
49490 +
49491 + if (!len || len >= PATH_MAX)
49492 + return -EINVAL;
49493 +
49494 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49495 + return -ENOMEM;
49496 +
49497 + if (copy_from_user(tmp, o_tmp->filename, len))
49498 + return -EFAULT;
49499 + tmp[len-1] = '\0';
49500 + o_tmp->filename = tmp;
49501 +
49502 + insert_acl_obj_label(o_tmp, subj);
49503 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
49504 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
49505 + return -ENOMEM;
49506 +
49507 + ret = copy_user_glob(o_tmp);
49508 + if (ret)
49509 + return ret;
49510 +
49511 + if (o_tmp->nested) {
49512 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
49513 + if (IS_ERR(o_tmp->nested))
49514 + return PTR_ERR(o_tmp->nested);
49515 +
49516 + /* insert into nested subject list */
49517 + o_tmp->nested->next = role->hash->first;
49518 + role->hash->first = o_tmp->nested;
49519 + }
49520 + }
49521 +
49522 + return 0;
49523 +}
49524 +
49525 +static __u32
49526 +count_user_subjs(struct acl_subject_label *userp)
49527 +{
49528 + struct acl_subject_label s_tmp;
49529 + __u32 num = 0;
49530 +
49531 + while (userp) {
49532 + if (copy_from_user(&s_tmp, userp,
49533 + sizeof (struct acl_subject_label)))
49534 + break;
49535 +
49536 + userp = s_tmp.prev;
49537 + /* do not count nested subjects against this count, since
49538 + they are not included in the hash table, but are
49539 + attached to objects. We have already counted
49540 + the subjects in userspace for the allocation
49541 + stack
49542 + */
49543 + if (!(s_tmp.mode & GR_NESTED))
49544 + num++;
49545 + }
49546 +
49547 + return num;
49548 +}
49549 +
49550 +static int
49551 +copy_user_allowedips(struct acl_role_label *rolep)
49552 +{
49553 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
49554 +
49555 + ruserip = rolep->allowed_ips;
49556 +
49557 + while (ruserip) {
49558 + rlast = rtmp;
49559 +
49560 + if ((rtmp = (struct role_allowed_ip *)
49561 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
49562 + return -ENOMEM;
49563 +
49564 + if (copy_from_user(rtmp, ruserip,
49565 + sizeof (struct role_allowed_ip)))
49566 + return -EFAULT;
49567 +
49568 + ruserip = rtmp->prev;
49569 +
49570 + if (!rlast) {
49571 + rtmp->prev = NULL;
49572 + rolep->allowed_ips = rtmp;
49573 + } else {
49574 + rlast->next = rtmp;
49575 + rtmp->prev = rlast;
49576 + }
49577 +
49578 + if (!ruserip)
49579 + rtmp->next = NULL;
49580 + }
49581 +
49582 + return 0;
49583 +}
49584 +
49585 +static int
49586 +copy_user_transitions(struct acl_role_label *rolep)
49587 +{
49588 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
49589 +
49590 + unsigned int len;
49591 + char *tmp;
49592 +
49593 + rusertp = rolep->transitions;
49594 +
49595 + while (rusertp) {
49596 + rlast = rtmp;
49597 +
49598 + if ((rtmp = (struct role_transition *)
49599 + acl_alloc(sizeof (struct role_transition))) == NULL)
49600 + return -ENOMEM;
49601 +
49602 + if (copy_from_user(rtmp, rusertp,
49603 + sizeof (struct role_transition)))
49604 + return -EFAULT;
49605 +
49606 + rusertp = rtmp->prev;
49607 +
49608 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
49609 +
49610 + if (!len || len >= GR_SPROLE_LEN)
49611 + return -EINVAL;
49612 +
49613 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49614 + return -ENOMEM;
49615 +
49616 + if (copy_from_user(tmp, rtmp->rolename, len))
49617 + return -EFAULT;
49618 + tmp[len-1] = '\0';
49619 + rtmp->rolename = tmp;
49620 +
49621 + if (!rlast) {
49622 + rtmp->prev = NULL;
49623 + rolep->transitions = rtmp;
49624 + } else {
49625 + rlast->next = rtmp;
49626 + rtmp->prev = rlast;
49627 + }
49628 +
49629 + if (!rusertp)
49630 + rtmp->next = NULL;
49631 + }
49632 +
49633 + return 0;
49634 +}
49635 +
49636 +static struct acl_subject_label *
49637 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
49638 +{
49639 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
49640 + unsigned int len;
49641 + char *tmp;
49642 + __u32 num_objs;
49643 + struct acl_ip_label **i_tmp, *i_utmp2;
49644 + struct gr_hash_struct ghash;
49645 + struct subject_map *subjmap;
49646 + unsigned int i_num;
49647 + int err;
49648 +
49649 + s_tmp = lookup_subject_map(userp);
49650 +
49651 + /* we've already copied this subject into the kernel, just return
49652 + the reference to it, and don't copy it over again
49653 + */
49654 + if (s_tmp)
49655 + return(s_tmp);
49656 +
49657 + if ((s_tmp = (struct acl_subject_label *)
49658 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
49659 + return ERR_PTR(-ENOMEM);
49660 +
49661 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
49662 + if (subjmap == NULL)
49663 + return ERR_PTR(-ENOMEM);
49664 +
49665 + subjmap->user = userp;
49666 + subjmap->kernel = s_tmp;
49667 + insert_subj_map_entry(subjmap);
49668 +
49669 + if (copy_from_user(s_tmp, userp,
49670 + sizeof (struct acl_subject_label)))
49671 + return ERR_PTR(-EFAULT);
49672 +
49673 + len = strnlen_user(s_tmp->filename, PATH_MAX);
49674 +
49675 + if (!len || len >= PATH_MAX)
49676 + return ERR_PTR(-EINVAL);
49677 +
49678 + if ((tmp = (char *) acl_alloc(len)) == NULL)
49679 + return ERR_PTR(-ENOMEM);
49680 +
49681 + if (copy_from_user(tmp, s_tmp->filename, len))
49682 + return ERR_PTR(-EFAULT);
49683 + tmp[len-1] = '\0';
49684 + s_tmp->filename = tmp;
49685 +
49686 + if (!strcmp(s_tmp->filename, "/"))
49687 + role->root_label = s_tmp;
49688 +
49689 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
49690 + return ERR_PTR(-EFAULT);
49691 +
49692 + /* copy user and group transition tables */
49693 +
49694 + if (s_tmp->user_trans_num) {
49695 + uid_t *uidlist;
49696 +
49697 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
49698 + if (uidlist == NULL)
49699 + return ERR_PTR(-ENOMEM);
49700 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
49701 + return ERR_PTR(-EFAULT);
49702 +
49703 + s_tmp->user_transitions = uidlist;
49704 + }
49705 +
49706 + if (s_tmp->group_trans_num) {
49707 + gid_t *gidlist;
49708 +
49709 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
49710 + if (gidlist == NULL)
49711 + return ERR_PTR(-ENOMEM);
49712 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
49713 + return ERR_PTR(-EFAULT);
49714 +
49715 + s_tmp->group_transitions = gidlist;
49716 + }
49717 +
49718 + /* set up object hash table */
49719 + num_objs = count_user_objs(ghash.first);
49720 +
49721 + s_tmp->obj_hash_size = num_objs;
49722 + s_tmp->obj_hash =
49723 + (struct acl_object_label **)
49724 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
49725 +
49726 + if (!s_tmp->obj_hash)
49727 + return ERR_PTR(-ENOMEM);
49728 +
49729 + memset(s_tmp->obj_hash, 0,
49730 + s_tmp->obj_hash_size *
49731 + sizeof (struct acl_object_label *));
49732 +
49733 + /* add in objects */
49734 + err = copy_user_objs(ghash.first, s_tmp, role);
49735 +
49736 + if (err)
49737 + return ERR_PTR(err);
49738 +
49739 + /* set pointer for parent subject */
49740 + if (s_tmp->parent_subject) {
49741 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
49742 +
49743 + if (IS_ERR(s_tmp2))
49744 + return s_tmp2;
49745 +
49746 + s_tmp->parent_subject = s_tmp2;
49747 + }
49748 +
49749 + /* add in ip acls */
49750 +
49751 + if (!s_tmp->ip_num) {
49752 + s_tmp->ips = NULL;
49753 + goto insert;
49754 + }
49755 +
49756 + i_tmp =
49757 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
49758 + sizeof (struct acl_ip_label *));
49759 +
49760 + if (!i_tmp)
49761 + return ERR_PTR(-ENOMEM);
49762 +
49763 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
49764 + *(i_tmp + i_num) =
49765 + (struct acl_ip_label *)
49766 + acl_alloc(sizeof (struct acl_ip_label));
49767 + if (!*(i_tmp + i_num))
49768 + return ERR_PTR(-ENOMEM);
49769 +
49770 + if (copy_from_user
49771 + (&i_utmp2, s_tmp->ips + i_num,
49772 + sizeof (struct acl_ip_label *)))
49773 + return ERR_PTR(-EFAULT);
49774 +
49775 + if (copy_from_user
49776 + (*(i_tmp + i_num), i_utmp2,
49777 + sizeof (struct acl_ip_label)))
49778 + return ERR_PTR(-EFAULT);
49779 +
49780 + if ((*(i_tmp + i_num))->iface == NULL)
49781 + continue;
49782 +
49783 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
49784 + if (!len || len >= IFNAMSIZ)
49785 + return ERR_PTR(-EINVAL);
49786 + tmp = acl_alloc(len);
49787 + if (tmp == NULL)
49788 + return ERR_PTR(-ENOMEM);
49789 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
49790 + return ERR_PTR(-EFAULT);
49791 + (*(i_tmp + i_num))->iface = tmp;
49792 + }
49793 +
49794 + s_tmp->ips = i_tmp;
49795 +
49796 +insert:
49797 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
49798 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
49799 + return ERR_PTR(-ENOMEM);
49800 +
49801 + return s_tmp;
49802 +}
49803 +
49804 +static int
49805 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
49806 +{
49807 + struct acl_subject_label s_pre;
49808 + struct acl_subject_label * ret;
49809 + int err;
49810 +
49811 + while (userp) {
49812 + if (copy_from_user(&s_pre, userp,
49813 + sizeof (struct acl_subject_label)))
49814 + return -EFAULT;
49815 +
49816 + /* do not add nested subjects here, add
49817 + while parsing objects
49818 + */
49819 +
49820 + if (s_pre.mode & GR_NESTED) {
49821 + userp = s_pre.prev;
49822 + continue;
49823 + }
49824 +
49825 + ret = do_copy_user_subj(userp, role);
49826 +
49827 + err = PTR_ERR(ret);
49828 + if (IS_ERR(ret))
49829 + return err;
49830 +
49831 + insert_acl_subj_label(ret, role);
49832 +
49833 + userp = s_pre.prev;
49834 + }
49835 +
49836 + return 0;
49837 +}
49838 +
49839 +static int
49840 +copy_user_acl(struct gr_arg *arg)
49841 +{
49842 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
49843 + struct sprole_pw *sptmp;
49844 + struct gr_hash_struct *ghash;
49845 + uid_t *domainlist;
49846 + unsigned int r_num;
49847 + unsigned int len;
49848 + char *tmp;
49849 + int err = 0;
49850 + __u16 i;
49851 + __u32 num_subjs;
49852 +
49853 + /* we need a default and kernel role */
49854 + if (arg->role_db.num_roles < 2)
49855 + return -EINVAL;
49856 +
49857 + /* copy special role authentication info from userspace */
49858 +
49859 + num_sprole_pws = arg->num_sprole_pws;
49860 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
49861 +
49862 + if (!acl_special_roles) {
49863 + err = -ENOMEM;
49864 + goto cleanup;
49865 + }
49866 +
49867 + for (i = 0; i < num_sprole_pws; i++) {
49868 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
49869 + if (!sptmp) {
49870 + err = -ENOMEM;
49871 + goto cleanup;
49872 + }
49873 + if (copy_from_user(sptmp, arg->sprole_pws + i,
49874 + sizeof (struct sprole_pw))) {
49875 + err = -EFAULT;
49876 + goto cleanup;
49877 + }
49878 +
49879 + len =
49880 + strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
49881 +
49882 + if (!len || len >= GR_SPROLE_LEN) {
49883 + err = -EINVAL;
49884 + goto cleanup;
49885 + }
49886 +
49887 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
49888 + err = -ENOMEM;
49889 + goto cleanup;
49890 + }
49891 +
49892 + if (copy_from_user(tmp, sptmp->rolename, len)) {
49893 + err = -EFAULT;
49894 + goto cleanup;
49895 + }
49896 + tmp[len-1] = '\0';
49897 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
49898 + printk(KERN_ALERT "Copying special role %s\n", tmp);
49899 +#endif
49900 + sptmp->rolename = tmp;
49901 + acl_special_roles[i] = sptmp;
49902 + }
49903 +
49904 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
49905 +
49906 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
49907 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
49908 +
49909 + if (!r_tmp) {
49910 + err = -ENOMEM;
49911 + goto cleanup;
49912 + }
49913 +
49914 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
49915 + sizeof (struct acl_role_label *))) {
49916 + err = -EFAULT;
49917 + goto cleanup;
49918 + }
49919 +
49920 + if (copy_from_user(r_tmp, r_utmp2,
49921 + sizeof (struct acl_role_label))) {
49922 + err = -EFAULT;
49923 + goto cleanup;
49924 + }
49925 +
49926 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
49927 +
49928 + if (!len || len >= PATH_MAX) {
49929 + err = -EINVAL;
49930 + goto cleanup;
49931 + }
49932 +
49933 + if ((tmp = (char *) acl_alloc(len)) == NULL) {
49934 + err = -ENOMEM;
49935 + goto cleanup;
49936 + }
49937 + if (copy_from_user(tmp, r_tmp->rolename, len)) {
49938 + err = -EFAULT;
49939 + goto cleanup;
49940 + }
49941 + tmp[len-1] = '\0';
49942 + r_tmp->rolename = tmp;
49943 +
49944 + if (!strcmp(r_tmp->rolename, "default")
49945 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
49946 + default_role = r_tmp;
49947 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
49948 + kernel_role = r_tmp;
49949 + }
49950 +
49951 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
49952 + err = -ENOMEM;
49953 + goto cleanup;
49954 + }
49955 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
49956 + err = -EFAULT;
49957 + goto cleanup;
49958 + }
49959 +
49960 + r_tmp->hash = ghash;
49961 +
49962 + num_subjs = count_user_subjs(r_tmp->hash->first);
49963 +
49964 + r_tmp->subj_hash_size = num_subjs;
49965 + r_tmp->subj_hash =
49966 + (struct acl_subject_label **)
49967 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
49968 +
49969 + if (!r_tmp->subj_hash) {
49970 + err = -ENOMEM;
49971 + goto cleanup;
49972 + }
49973 +
49974 + err = copy_user_allowedips(r_tmp);
49975 + if (err)
49976 + goto cleanup;
49977 +
49978 + /* copy domain info */
49979 + if (r_tmp->domain_children != NULL) {
49980 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
49981 + if (domainlist == NULL) {
49982 + err = -ENOMEM;
49983 + goto cleanup;
49984 + }
49985 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
49986 + err = -EFAULT;
49987 + goto cleanup;
49988 + }
49989 + r_tmp->domain_children = domainlist;
49990 + }
49991 +
49992 + err = copy_user_transitions(r_tmp);
49993 + if (err)
49994 + goto cleanup;
49995 +
49996 + memset(r_tmp->subj_hash, 0,
49997 + r_tmp->subj_hash_size *
49998 + sizeof (struct acl_subject_label *));
49999 +
50000 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
50001 +
50002 + if (err)
50003 + goto cleanup;
50004 +
50005 + /* set nested subject list to null */
50006 + r_tmp->hash->first = NULL;
50007 +
50008 + insert_acl_role_label(r_tmp);
50009 + }
50010 +
50011 + goto return_err;
50012 + cleanup:
50013 + free_variables();
50014 + return_err:
50015 + return err;
50016 +
50017 +}
50018 +
50019 +static int
50020 +gracl_init(struct gr_arg *args)
50021 +{
50022 + int error = 0;
50023 +
50024 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
50025 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
50026 +
50027 + if (init_variables(args)) {
50028 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
50029 + error = -ENOMEM;
50030 + free_variables();
50031 + goto out;
50032 + }
50033 +
50034 + error = copy_user_acl(args);
50035 + free_init_variables();
50036 + if (error) {
50037 + free_variables();
50038 + goto out;
50039 + }
50040 +
50041 + if ((error = gr_set_acls(0))) {
50042 + free_variables();
50043 + goto out;
50044 + }
50045 +
50046 + pax_open_kernel();
50047 + gr_status |= GR_READY;
50048 + pax_close_kernel();
50049 +
50050 + out:
50051 + return error;
50052 +}
50053 +
50054 +/* derived from glibc fnmatch() 0: match, 1: no match*/
50055 +
50056 +static int
50057 +glob_match(const char *p, const char *n)
50058 +{
50059 + char c;
50060 +
50061 + while ((c = *p++) != '\0') {
50062 + switch (c) {
50063 + case '?':
50064 + if (*n == '\0')
50065 + return 1;
50066 + else if (*n == '/')
50067 + return 1;
50068 + break;
50069 + case '\\':
50070 + if (*n != c)
50071 + return 1;
50072 + break;
50073 + case '*':
50074 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
50075 + if (*n == '/')
50076 + return 1;
50077 + else if (c == '?') {
50078 + if (*n == '\0')
50079 + return 1;
50080 + else
50081 + ++n;
50082 + }
50083 + }
50084 + if (c == '\0') {
50085 + return 0;
50086 + } else {
50087 + const char *endp;
50088 +
50089 + if ((endp = strchr(n, '/')) == NULL)
50090 + endp = n + strlen(n);
50091 +
50092 + if (c == '[') {
50093 + for (--p; n < endp; ++n)
50094 + if (!glob_match(p, n))
50095 + return 0;
50096 + } else if (c == '/') {
50097 + while (*n != '\0' && *n != '/')
50098 + ++n;
50099 + if (*n == '/' && !glob_match(p, n + 1))
50100 + return 0;
50101 + } else {
50102 + for (--p; n < endp; ++n)
50103 + if (*n == c && !glob_match(p, n))
50104 + return 0;
50105 + }
50106 +
50107 + return 1;
50108 + }
50109 + case '[':
50110 + {
50111 + int not;
50112 + char cold;
50113 +
50114 + if (*n == '\0' || *n == '/')
50115 + return 1;
50116 +
50117 + not = (*p == '!' || *p == '^');
50118 + if (not)
50119 + ++p;
50120 +
50121 + c = *p++;
50122 + for (;;) {
50123 + unsigned char fn = (unsigned char)*n;
50124 +
50125 + if (c == '\0')
50126 + return 1;
50127 + else {
50128 + if (c == fn)
50129 + goto matched;
50130 + cold = c;
50131 + c = *p++;
50132 +
50133 + if (c == '-' && *p != ']') {
50134 + unsigned char cend = *p++;
50135 +
50136 + if (cend == '\0')
50137 + return 1;
50138 +
50139 + if (cold <= fn && fn <= cend)
50140 + goto matched;
50141 +
50142 + c = *p++;
50143 + }
50144 + }
50145 +
50146 + if (c == ']')
50147 + break;
50148 + }
50149 + if (!not)
50150 + return 1;
50151 + break;
50152 + matched:
50153 + while (c != ']') {
50154 + if (c == '\0')
50155 + return 1;
50156 +
50157 + c = *p++;
50158 + }
50159 + if (not)
50160 + return 1;
50161 + }
50162 + break;
50163 + default:
50164 + if (c != *n)
50165 + return 1;
50166 + }
50167 +
50168 + ++n;
50169 + }
50170 +
50171 + if (*n == '\0')
50172 + return 0;
50173 +
50174 + if (*n == '/')
50175 + return 0;
50176 +
50177 + return 1;
50178 +}
50179 +
50180 +static struct acl_object_label *
50181 +chk_glob_label(struct acl_object_label *globbed,
50182 + struct dentry *dentry, struct vfsmount *mnt, char **path)
50183 +{
50184 + struct acl_object_label *tmp;
50185 +
50186 + if (*path == NULL)
50187 + *path = gr_to_filename_nolock(dentry, mnt);
50188 +
50189 + tmp = globbed;
50190 +
50191 + while (tmp) {
50192 + if (!glob_match(tmp->filename, *path))
50193 + return tmp;
50194 + tmp = tmp->next;
50195 + }
50196 +
50197 + return NULL;
50198 +}
50199 +
50200 +static struct acl_object_label *
50201 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
50202 + const ino_t curr_ino, const dev_t curr_dev,
50203 + const struct acl_subject_label *subj, char **path, const int checkglob)
50204 +{
50205 + struct acl_subject_label *tmpsubj;
50206 + struct acl_object_label *retval;
50207 + struct acl_object_label *retval2;
50208 +
50209 + tmpsubj = (struct acl_subject_label *) subj;
50210 + read_lock(&gr_inode_lock);
50211 + do {
50212 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
50213 + if (retval) {
50214 + if (checkglob && retval->globbed) {
50215 + retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
50216 + (struct vfsmount *)orig_mnt, path);
50217 + if (retval2)
50218 + retval = retval2;
50219 + }
50220 + break;
50221 + }
50222 + } while ((tmpsubj = tmpsubj->parent_subject));
50223 + read_unlock(&gr_inode_lock);
50224 +
50225 + return retval;
50226 +}
50227 +
50228 +static __inline__ struct acl_object_label *
50229 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
50230 + struct dentry *curr_dentry,
50231 + const struct acl_subject_label *subj, char **path, const int checkglob)
50232 +{
50233 + int newglob = checkglob;
50234 + ino_t inode;
50235 + dev_t device;
50236 +
50237 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
50238 + as we don't want a / * rule to match instead of the / object
50239 + don't do this for create lookups that call this function though, since they're looking up
50240 + on the parent and thus need globbing checks on all paths
50241 + */
50242 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
50243 + newglob = GR_NO_GLOB;
50244 +
50245 + spin_lock(&curr_dentry->d_lock);
50246 + inode = curr_dentry->d_inode->i_ino;
50247 + device = __get_dev(curr_dentry);
50248 + spin_unlock(&curr_dentry->d_lock);
50249 +
50250 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
50251 +}
50252 +
50253 +static struct acl_object_label *
50254 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50255 + const struct acl_subject_label *subj, char *path, const int checkglob)
50256 +{
50257 + struct dentry *dentry = (struct dentry *) l_dentry;
50258 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
50259 + struct acl_object_label *retval;
50260 + struct dentry *parent;
50261 +
50262 + write_seqlock(&rename_lock);
50263 + br_read_lock(vfsmount_lock);
50264 +
50265 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
50266 +#ifdef CONFIG_NET
50267 + mnt == sock_mnt ||
50268 +#endif
50269 +#ifdef CONFIG_HUGETLBFS
50270 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
50271 +#endif
50272 + /* ignore Eric Biederman */
50273 + IS_PRIVATE(l_dentry->d_inode))) {
50274 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
50275 + goto out;
50276 + }
50277 +
50278 + for (;;) {
50279 + if (dentry == real_root.dentry && mnt == real_root.mnt)
50280 + break;
50281 +
50282 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
50283 + if (mnt->mnt_parent == mnt)
50284 + break;
50285 +
50286 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50287 + if (retval != NULL)
50288 + goto out;
50289 +
50290 + dentry = mnt->mnt_mountpoint;
50291 + mnt = mnt->mnt_parent;
50292 + continue;
50293 + }
50294 +
50295 + parent = dentry->d_parent;
50296 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50297 + if (retval != NULL)
50298 + goto out;
50299 +
50300 + dentry = parent;
50301 + }
50302 +
50303 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
50304 +
50305 + /* real_root is pinned so we don't have to hold a reference */
50306 + if (retval == NULL)
50307 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
50308 +out:
50309 + br_read_unlock(vfsmount_lock);
50310 + write_sequnlock(&rename_lock);
50311 +
50312 + BUG_ON(retval == NULL);
50313 +
50314 + return retval;
50315 +}
50316 +
50317 +static __inline__ struct acl_object_label *
50318 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50319 + const struct acl_subject_label *subj)
50320 +{
50321 + char *path = NULL;
50322 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
50323 +}
50324 +
50325 +static __inline__ struct acl_object_label *
50326 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50327 + const struct acl_subject_label *subj)
50328 +{
50329 + char *path = NULL;
50330 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
50331 +}
50332 +
50333 +static __inline__ struct acl_object_label *
50334 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50335 + const struct acl_subject_label *subj, char *path)
50336 +{
50337 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
50338 +}
50339 +
50340 +static struct acl_subject_label *
50341 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
50342 + const struct acl_role_label *role)
50343 +{
50344 + struct dentry *dentry = (struct dentry *) l_dentry;
50345 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
50346 + struct acl_subject_label *retval;
50347 + struct dentry *parent;
50348 +
50349 + write_seqlock(&rename_lock);
50350 + br_read_lock(vfsmount_lock);
50351 +
50352 + for (;;) {
50353 + if (dentry == real_root.dentry && mnt == real_root.mnt)
50354 + break;
50355 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
50356 + if (mnt->mnt_parent == mnt)
50357 + break;
50358 +
50359 + spin_lock(&dentry->d_lock);
50360 + read_lock(&gr_inode_lock);
50361 + retval =
50362 + lookup_acl_subj_label(dentry->d_inode->i_ino,
50363 + __get_dev(dentry), role);
50364 + read_unlock(&gr_inode_lock);
50365 + spin_unlock(&dentry->d_lock);
50366 + if (retval != NULL)
50367 + goto out;
50368 +
50369 + dentry = mnt->mnt_mountpoint;
50370 + mnt = mnt->mnt_parent;
50371 + continue;
50372 + }
50373 +
50374 + spin_lock(&dentry->d_lock);
50375 + read_lock(&gr_inode_lock);
50376 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
50377 + __get_dev(dentry), role);
50378 + read_unlock(&gr_inode_lock);
50379 + parent = dentry->d_parent;
50380 + spin_unlock(&dentry->d_lock);
50381 +
50382 + if (retval != NULL)
50383 + goto out;
50384 +
50385 + dentry = parent;
50386 + }
50387 +
50388 + spin_lock(&dentry->d_lock);
50389 + read_lock(&gr_inode_lock);
50390 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
50391 + __get_dev(dentry), role);
50392 + read_unlock(&gr_inode_lock);
50393 + spin_unlock(&dentry->d_lock);
50394 +
50395 + if (unlikely(retval == NULL)) {
50396 + /* real_root is pinned, we don't need to hold a reference */
50397 + read_lock(&gr_inode_lock);
50398 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
50399 + __get_dev(real_root.dentry), role);
50400 + read_unlock(&gr_inode_lock);
50401 + }
50402 +out:
50403 + br_read_unlock(vfsmount_lock);
50404 + write_sequnlock(&rename_lock);
50405 +
50406 + BUG_ON(retval == NULL);
50407 +
50408 + return retval;
50409 +}
50410 +
50411 +static void
50412 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
50413 +{
50414 + struct task_struct *task = current;
50415 + const struct cred *cred = current_cred();
50416 +
50417 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
50418 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50419 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50420 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
50421 +
50422 + return;
50423 +}
50424 +
50425 +static void
50426 +gr_log_learn_sysctl(const char *path, const __u32 mode)
50427 +{
50428 + struct task_struct *task = current;
50429 + const struct cred *cred = current_cred();
50430 +
50431 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
50432 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50433 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50434 + 1UL, 1UL, path, (unsigned long) mode, &task->signal->saved_ip);
50435 +
50436 + return;
50437 +}
50438 +
50439 +static void
50440 +gr_log_learn_id_change(const char type, const unsigned int real,
50441 + const unsigned int effective, const unsigned int fs)
50442 +{
50443 + struct task_struct *task = current;
50444 + const struct cred *cred = current_cred();
50445 +
50446 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
50447 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
50448 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
50449 + type, real, effective, fs, &task->signal->saved_ip);
50450 +
50451 + return;
50452 +}
50453 +
50454 +__u32
50455 +gr_search_file(const struct dentry * dentry, const __u32 mode,
50456 + const struct vfsmount * mnt)
50457 +{
50458 + __u32 retval = mode;
50459 + struct acl_subject_label *curracl;
50460 + struct acl_object_label *currobj;
50461 +
50462 + if (unlikely(!(gr_status & GR_READY)))
50463 + return (mode & ~GR_AUDITS);
50464 +
50465 + curracl = current->acl;
50466 +
50467 + currobj = chk_obj_label(dentry, mnt, curracl);
50468 + retval = currobj->mode & mode;
50469 +
50470 + /* if we're opening a specified transfer file for writing
50471 + (e.g. /dev/initctl), then transfer our role to init
50472 + */
50473 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
50474 + current->role->roletype & GR_ROLE_PERSIST)) {
50475 + struct task_struct *task = init_pid_ns.child_reaper;
50476 +
50477 + if (task->role != current->role) {
50478 + task->acl_sp_role = 0;
50479 + task->acl_role_id = current->acl_role_id;
50480 + task->role = current->role;
50481 + rcu_read_lock();
50482 + read_lock(&grsec_exec_file_lock);
50483 + gr_apply_subject_to_task(task);
50484 + read_unlock(&grsec_exec_file_lock);
50485 + rcu_read_unlock();
50486 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
50487 + }
50488 + }
50489 +
50490 + if (unlikely
50491 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
50492 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
50493 + __u32 new_mode = mode;
50494 +
50495 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50496 +
50497 + retval = new_mode;
50498 +
50499 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
50500 + new_mode |= GR_INHERIT;
50501 +
50502 + if (!(mode & GR_NOLEARN))
50503 + gr_log_learn(dentry, mnt, new_mode);
50504 + }
50505 +
50506 + return retval;
50507 +}
50508 +
50509 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
50510 + const struct dentry *parent,
50511 + const struct vfsmount *mnt)
50512 +{
50513 + struct name_entry *match;
50514 + struct acl_object_label *matchpo;
50515 + struct acl_subject_label *curracl;
50516 + char *path;
50517 +
50518 + if (unlikely(!(gr_status & GR_READY)))
50519 + return NULL;
50520 +
50521 + preempt_disable();
50522 + path = gr_to_filename_rbac(new_dentry, mnt);
50523 + match = lookup_name_entry_create(path);
50524 +
50525 + curracl = current->acl;
50526 +
50527 + if (match) {
50528 + read_lock(&gr_inode_lock);
50529 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
50530 + read_unlock(&gr_inode_lock);
50531 +
50532 + if (matchpo) {
50533 + preempt_enable();
50534 + return matchpo;
50535 + }
50536 + }
50537 +
50538 + // lookup parent
50539 +
50540 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
50541 +
50542 + preempt_enable();
50543 + return matchpo;
50544 +}
50545 +
50546 +__u32
50547 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
50548 + const struct vfsmount * mnt, const __u32 mode)
50549 +{
50550 + struct acl_object_label *matchpo;
50551 + __u32 retval;
50552 +
50553 + if (unlikely(!(gr_status & GR_READY)))
50554 + return (mode & ~GR_AUDITS);
50555 +
50556 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
50557 +
50558 + retval = matchpo->mode & mode;
50559 +
50560 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
50561 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
50562 + __u32 new_mode = mode;
50563 +
50564 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
50565 +
50566 + gr_log_learn(new_dentry, mnt, new_mode);
50567 + return new_mode;
50568 + }
50569 +
50570 + return retval;
50571 +}
50572 +
50573 +__u32
50574 +gr_check_link(const struct dentry * new_dentry,
50575 + const struct dentry * parent_dentry,
50576 + const struct vfsmount * parent_mnt,
50577 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
50578 +{
50579 + struct acl_object_label *obj;
50580 + __u32 oldmode, newmode;
50581 + __u32 needmode;
50582 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
50583 + GR_DELETE | GR_INHERIT;
50584 +
50585 + if (unlikely(!(gr_status & GR_READY)))
50586 + return (GR_CREATE | GR_LINK);
50587 +
50588 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
50589 + oldmode = obj->mode;
50590 +
50591 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
50592 + newmode = obj->mode;
50593 +
50594 + needmode = newmode & checkmodes;
50595 +
50596 + // old name for hardlink must have at least the permissions of the new name
50597 + if ((oldmode & needmode) != needmode)
50598 + goto bad;
50599 +
50600 + // if old name had restrictions/auditing, make sure the new name does as well
50601 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
50602 +
50603 + // don't allow hardlinking of suid/sgid files without permission
50604 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
50605 + needmode |= GR_SETID;
50606 +
50607 + if ((newmode & needmode) != needmode)
50608 + goto bad;
50609 +
50610 + // enforce minimum permissions
50611 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
50612 + return newmode;
50613 +bad:
50614 + needmode = oldmode;
50615 + if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
50616 + needmode |= GR_SETID;
50617 +
50618 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
50619 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
50620 + return (GR_CREATE | GR_LINK);
50621 + } else if (newmode & GR_SUPPRESS)
50622 + return GR_SUPPRESS;
50623 + else
50624 + return 0;
50625 +}
50626 +
50627 +int
50628 +gr_check_hidden_task(const struct task_struct *task)
50629 +{
50630 + if (unlikely(!(gr_status & GR_READY)))
50631 + return 0;
50632 +
50633 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
50634 + return 1;
50635 +
50636 + return 0;
50637 +}
50638 +
50639 +int
50640 +gr_check_protected_task(const struct task_struct *task)
50641 +{
50642 + if (unlikely(!(gr_status & GR_READY) || !task))
50643 + return 0;
50644 +
50645 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
50646 + task->acl != current->acl)
50647 + return 1;
50648 +
50649 + return 0;
50650 +}
50651 +
50652 +int
50653 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
50654 +{
50655 + struct task_struct *p;
50656 + int ret = 0;
50657 +
50658 + if (unlikely(!(gr_status & GR_READY) || !pid))
50659 + return ret;
50660 +
50661 + read_lock(&tasklist_lock);
50662 + do_each_pid_task(pid, type, p) {
50663 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
50664 + p->acl != current->acl) {
50665 + ret = 1;
50666 + goto out;
50667 + }
50668 + } while_each_pid_task(pid, type, p);
50669 +out:
50670 + read_unlock(&tasklist_lock);
50671 +
50672 + return ret;
50673 +}
50674 +
50675 +void
50676 +gr_copy_label(struct task_struct *tsk)
50677 +{
50678 + /* plain copying of fields is already done by dup_task_struct */
50679 + tsk->signal->used_accept = 0;
50680 + tsk->acl_sp_role = 0;
50681 + //tsk->acl_role_id = current->acl_role_id;
50682 + //tsk->acl = current->acl;
50683 + //tsk->role = current->role;
50684 + tsk->signal->curr_ip = current->signal->curr_ip;
50685 + tsk->signal->saved_ip = current->signal->saved_ip;
50686 + if (current->exec_file)
50687 + get_file(current->exec_file);
50688 + //tsk->exec_file = current->exec_file;
50689 + //tsk->is_writable = current->is_writable;
50690 + if (unlikely(current->signal->used_accept)) {
50691 + current->signal->curr_ip = 0;
50692 + current->signal->saved_ip = 0;
50693 + }
50694 +
50695 + return;
50696 +}
50697 +
50698 +static void
50699 +gr_set_proc_res(struct task_struct *task)
50700 +{
50701 + struct acl_subject_label *proc;
50702 + unsigned short i;
50703 +
50704 + proc = task->acl;
50705 +
50706 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
50707 + return;
50708 +
50709 + for (i = 0; i < RLIM_NLIMITS; i++) {
50710 + if (!(proc->resmask & (1 << i)))
50711 + continue;
50712 +
50713 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
50714 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
50715 + }
50716 +
50717 + return;
50718 +}
50719 +
50720 +extern int __gr_process_user_ban(struct user_struct *user);
50721 +
50722 +int
50723 +gr_check_user_change(int real, int effective, int fs)
50724 +{
50725 + unsigned int i;
50726 + __u16 num;
50727 + uid_t *uidlist;
50728 + int curuid;
50729 + int realok = 0;
50730 + int effectiveok = 0;
50731 + int fsok = 0;
50732 +
50733 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
50734 + struct user_struct *user;
50735 +
50736 + if (real == -1)
50737 + goto skipit;
50738 +
50739 + user = find_user(real);
50740 + if (user == NULL)
50741 + goto skipit;
50742 +
50743 + if (__gr_process_user_ban(user)) {
50744 + /* for find_user */
50745 + free_uid(user);
50746 + return 1;
50747 + }
50748 +
50749 + /* for find_user */
50750 + free_uid(user);
50751 +
50752 +skipit:
50753 +#endif
50754 +
50755 + if (unlikely(!(gr_status & GR_READY)))
50756 + return 0;
50757 +
50758 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50759 + gr_log_learn_id_change('u', real, effective, fs);
50760 +
50761 + num = current->acl->user_trans_num;
50762 + uidlist = current->acl->user_transitions;
50763 +
50764 + if (uidlist == NULL)
50765 + return 0;
50766 +
50767 + if (real == -1)
50768 + realok = 1;
50769 + if (effective == -1)
50770 + effectiveok = 1;
50771 + if (fs == -1)
50772 + fsok = 1;
50773 +
50774 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
50775 + for (i = 0; i < num; i++) {
50776 + curuid = (int)uidlist[i];
50777 + if (real == curuid)
50778 + realok = 1;
50779 + if (effective == curuid)
50780 + effectiveok = 1;
50781 + if (fs == curuid)
50782 + fsok = 1;
50783 + }
50784 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
50785 + for (i = 0; i < num; i++) {
50786 + curuid = (int)uidlist[i];
50787 + if (real == curuid)
50788 + break;
50789 + if (effective == curuid)
50790 + break;
50791 + if (fs == curuid)
50792 + break;
50793 + }
50794 + /* not in deny list */
50795 + if (i == num) {
50796 + realok = 1;
50797 + effectiveok = 1;
50798 + fsok = 1;
50799 + }
50800 + }
50801 +
50802 + if (realok && effectiveok && fsok)
50803 + return 0;
50804 + else {
50805 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
50806 + return 1;
50807 + }
50808 +}
50809 +
50810 +int
50811 +gr_check_group_change(int real, int effective, int fs)
50812 +{
50813 + unsigned int i;
50814 + __u16 num;
50815 + gid_t *gidlist;
50816 + int curgid;
50817 + int realok = 0;
50818 + int effectiveok = 0;
50819 + int fsok = 0;
50820 +
50821 + if (unlikely(!(gr_status & GR_READY)))
50822 + return 0;
50823 +
50824 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
50825 + gr_log_learn_id_change('g', real, effective, fs);
50826 +
50827 + num = current->acl->group_trans_num;
50828 + gidlist = current->acl->group_transitions;
50829 +
50830 + if (gidlist == NULL)
50831 + return 0;
50832 +
50833 + if (real == -1)
50834 + realok = 1;
50835 + if (effective == -1)
50836 + effectiveok = 1;
50837 + if (fs == -1)
50838 + fsok = 1;
50839 +
50840 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
50841 + for (i = 0; i < num; i++) {
50842 + curgid = (int)gidlist[i];
50843 + if (real == curgid)
50844 + realok = 1;
50845 + if (effective == curgid)
50846 + effectiveok = 1;
50847 + if (fs == curgid)
50848 + fsok = 1;
50849 + }
50850 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
50851 + for (i = 0; i < num; i++) {
50852 + curgid = (int)gidlist[i];
50853 + if (real == curgid)
50854 + break;
50855 + if (effective == curgid)
50856 + break;
50857 + if (fs == curgid)
50858 + break;
50859 + }
50860 + /* not in deny list */
50861 + if (i == num) {
50862 + realok = 1;
50863 + effectiveok = 1;
50864 + fsok = 1;
50865 + }
50866 + }
50867 +
50868 + if (realok && effectiveok && fsok)
50869 + return 0;
50870 + else {
50871 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
50872 + return 1;
50873 + }
50874 +}
50875 +
50876 +extern int gr_acl_is_capable(const int cap);
50877 +
50878 +void
50879 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
50880 +{
50881 + struct acl_role_label *role = task->role;
50882 + struct acl_subject_label *subj = NULL;
50883 + struct acl_object_label *obj;
50884 + struct file *filp;
50885 +
50886 + if (unlikely(!(gr_status & GR_READY)))
50887 + return;
50888 +
50889 + filp = task->exec_file;
50890 +
50891 + /* kernel process, we'll give them the kernel role */
50892 + if (unlikely(!filp)) {
50893 + task->role = kernel_role;
50894 + task->acl = kernel_role->root_label;
50895 + return;
50896 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
50897 + role = lookup_acl_role_label(task, uid, gid);
50898 +
50899 + /* don't change the role if we're not a privileged process */
50900 + if (role && task->role != role &&
50901 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
50902 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
50903 + return;
50904 +
50905 + /* perform subject lookup in possibly new role
50906 + we can use this result below in the case where role == task->role
50907 + */
50908 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
50909 +
50910 + /* if we changed uid/gid, but result in the same role
50911 + and are using inheritance, don't lose the inherited subject
50912 + if current subject is other than what normal lookup
50913 + would result in, we arrived via inheritance, don't
50914 + lose subject
50915 + */
50916 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
50917 + (subj == task->acl)))
50918 + task->acl = subj;
50919 +
50920 + task->role = role;
50921 +
50922 + task->is_writable = 0;
50923 +
50924 + /* ignore additional mmap checks for processes that are writable
50925 + by the default ACL */
50926 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
50927 + if (unlikely(obj->mode & GR_WRITE))
50928 + task->is_writable = 1;
50929 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
50930 + if (unlikely(obj->mode & GR_WRITE))
50931 + task->is_writable = 1;
50932 +
50933 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50934 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
50935 +#endif
50936 +
50937 + gr_set_proc_res(task);
50938 +
50939 + return;
50940 +}
50941 +
50942 +int
50943 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
50944 + const int unsafe_flags)
50945 +{
50946 + struct task_struct *task = current;
50947 + struct acl_subject_label *newacl;
50948 + struct acl_object_label *obj;
50949 + __u32 retmode;
50950 +
50951 + if (unlikely(!(gr_status & GR_READY)))
50952 + return 0;
50953 +
50954 + newacl = chk_subj_label(dentry, mnt, task->role);
50955 +
50956 + task_lock(task);
50957 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
50958 + !(task->role->roletype & GR_ROLE_GOD) &&
50959 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
50960 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
50961 + task_unlock(task);
50962 + if (unsafe_flags & LSM_UNSAFE_SHARE)
50963 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
50964 + else
50965 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
50966 + return -EACCES;
50967 + }
50968 + task_unlock(task);
50969 +
50970 + obj = chk_obj_label(dentry, mnt, task->acl);
50971 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
50972 +
50973 + if (!(task->acl->mode & GR_INHERITLEARN) &&
50974 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
50975 + if (obj->nested)
50976 + task->acl = obj->nested;
50977 + else
50978 + task->acl = newacl;
50979 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
50980 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
50981 +
50982 + task->is_writable = 0;
50983 +
50984 + /* ignore additional mmap checks for processes that are writable
50985 + by the default ACL */
50986 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
50987 + if (unlikely(obj->mode & GR_WRITE))
50988 + task->is_writable = 1;
50989 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
50990 + if (unlikely(obj->mode & GR_WRITE))
50991 + task->is_writable = 1;
50992 +
50993 + gr_set_proc_res(task);
50994 +
50995 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
50996 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
50997 +#endif
50998 + return 0;
50999 +}
51000 +
51001 +/* always called with valid inodev ptr */
51002 +static void
51003 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
51004 +{
51005 + struct acl_object_label *matchpo;
51006 + struct acl_subject_label *matchps;
51007 + struct acl_subject_label *subj;
51008 + struct acl_role_label *role;
51009 + unsigned int x;
51010 +
51011 + FOR_EACH_ROLE_START(role)
51012 + FOR_EACH_SUBJECT_START(role, subj, x)
51013 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
51014 + matchpo->mode |= GR_DELETED;
51015 + FOR_EACH_SUBJECT_END(subj,x)
51016 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
51017 + if (subj->inode == ino && subj->device == dev)
51018 + subj->mode |= GR_DELETED;
51019 + FOR_EACH_NESTED_SUBJECT_END(subj)
51020 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
51021 + matchps->mode |= GR_DELETED;
51022 + FOR_EACH_ROLE_END(role)
51023 +
51024 + inodev->nentry->deleted = 1;
51025 +
51026 + return;
51027 +}
51028 +
51029 +void
51030 +gr_handle_delete(const ino_t ino, const dev_t dev)
51031 +{
51032 + struct inodev_entry *inodev;
51033 +
51034 + if (unlikely(!(gr_status & GR_READY)))
51035 + return;
51036 +
51037 + write_lock(&gr_inode_lock);
51038 + inodev = lookup_inodev_entry(ino, dev);
51039 + if (inodev != NULL)
51040 + do_handle_delete(inodev, ino, dev);
51041 + write_unlock(&gr_inode_lock);
51042 +
51043 + return;
51044 +}
51045 +
51046 +static void
51047 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
51048 + const ino_t newinode, const dev_t newdevice,
51049 + struct acl_subject_label *subj)
51050 +{
51051 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
51052 + struct acl_object_label *match;
51053 +
51054 + match = subj->obj_hash[index];
51055 +
51056 + while (match && (match->inode != oldinode ||
51057 + match->device != olddevice ||
51058 + !(match->mode & GR_DELETED)))
51059 + match = match->next;
51060 +
51061 + if (match && (match->inode == oldinode)
51062 + && (match->device == olddevice)
51063 + && (match->mode & GR_DELETED)) {
51064 + if (match->prev == NULL) {
51065 + subj->obj_hash[index] = match->next;
51066 + if (match->next != NULL)
51067 + match->next->prev = NULL;
51068 + } else {
51069 + match->prev->next = match->next;
51070 + if (match->next != NULL)
51071 + match->next->prev = match->prev;
51072 + }
51073 + match->prev = NULL;
51074 + match->next = NULL;
51075 + match->inode = newinode;
51076 + match->device = newdevice;
51077 + match->mode &= ~GR_DELETED;
51078 +
51079 + insert_acl_obj_label(match, subj);
51080 + }
51081 +
51082 + return;
51083 +}
51084 +
51085 +static void
51086 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
51087 + const ino_t newinode, const dev_t newdevice,
51088 + struct acl_role_label *role)
51089 +{
51090 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
51091 + struct acl_subject_label *match;
51092 +
51093 + match = role->subj_hash[index];
51094 +
51095 + while (match && (match->inode != oldinode ||
51096 + match->device != olddevice ||
51097 + !(match->mode & GR_DELETED)))
51098 + match = match->next;
51099 +
51100 + if (match && (match->inode == oldinode)
51101 + && (match->device == olddevice)
51102 + && (match->mode & GR_DELETED)) {
51103 + if (match->prev == NULL) {
51104 + role->subj_hash[index] = match->next;
51105 + if (match->next != NULL)
51106 + match->next->prev = NULL;
51107 + } else {
51108 + match->prev->next = match->next;
51109 + if (match->next != NULL)
51110 + match->next->prev = match->prev;
51111 + }
51112 + match->prev = NULL;
51113 + match->next = NULL;
51114 + match->inode = newinode;
51115 + match->device = newdevice;
51116 + match->mode &= ~GR_DELETED;
51117 +
51118 + insert_acl_subj_label(match, role);
51119 + }
51120 +
51121 + return;
51122 +}
51123 +
51124 +static void
51125 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
51126 + const ino_t newinode, const dev_t newdevice)
51127 +{
51128 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
51129 + struct inodev_entry *match;
51130 +
51131 + match = inodev_set.i_hash[index];
51132 +
51133 + while (match && (match->nentry->inode != oldinode ||
51134 + match->nentry->device != olddevice || !match->nentry->deleted))
51135 + match = match->next;
51136 +
51137 + if (match && (match->nentry->inode == oldinode)
51138 + && (match->nentry->device == olddevice) &&
51139 + match->nentry->deleted) {
51140 + if (match->prev == NULL) {
51141 + inodev_set.i_hash[index] = match->next;
51142 + if (match->next != NULL)
51143 + match->next->prev = NULL;
51144 + } else {
51145 + match->prev->next = match->next;
51146 + if (match->next != NULL)
51147 + match->next->prev = match->prev;
51148 + }
51149 + match->prev = NULL;
51150 + match->next = NULL;
51151 + match->nentry->inode = newinode;
51152 + match->nentry->device = newdevice;
51153 + match->nentry->deleted = 0;
51154 +
51155 + insert_inodev_entry(match);
51156 + }
51157 +
51158 + return;
51159 +}
51160 +
51161 +static void
51162 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
51163 +{
51164 + struct acl_subject_label *subj;
51165 + struct acl_role_label *role;
51166 + unsigned int x;
51167 +
51168 + FOR_EACH_ROLE_START(role)
51169 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
51170 +
51171 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
51172 + if ((subj->inode == ino) && (subj->device == dev)) {
51173 + subj->inode = ino;
51174 + subj->device = dev;
51175 + }
51176 + FOR_EACH_NESTED_SUBJECT_END(subj)
51177 + FOR_EACH_SUBJECT_START(role, subj, x)
51178 + update_acl_obj_label(matchn->inode, matchn->device,
51179 + ino, dev, subj);
51180 + FOR_EACH_SUBJECT_END(subj,x)
51181 + FOR_EACH_ROLE_END(role)
51182 +
51183 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
51184 +
51185 + return;
51186 +}
51187 +
51188 +static void
51189 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
51190 + const struct vfsmount *mnt)
51191 +{
51192 + ino_t ino = dentry->d_inode->i_ino;
51193 + dev_t dev = __get_dev(dentry);
51194 +
51195 + __do_handle_create(matchn, ino, dev);
51196 +
51197 + return;
51198 +}
51199 +
51200 +void
51201 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
51202 +{
51203 + struct name_entry *matchn;
51204 +
51205 + if (unlikely(!(gr_status & GR_READY)))
51206 + return;
51207 +
51208 + preempt_disable();
51209 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
51210 +
51211 + if (unlikely((unsigned long)matchn)) {
51212 + write_lock(&gr_inode_lock);
51213 + do_handle_create(matchn, dentry, mnt);
51214 + write_unlock(&gr_inode_lock);
51215 + }
51216 + preempt_enable();
51217 +
51218 + return;
51219 +}
51220 +
51221 +void
51222 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
51223 +{
51224 + struct name_entry *matchn;
51225 +
51226 + if (unlikely(!(gr_status & GR_READY)))
51227 + return;
51228 +
51229 + preempt_disable();
51230 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
51231 +
51232 + if (unlikely((unsigned long)matchn)) {
51233 + write_lock(&gr_inode_lock);
51234 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
51235 + write_unlock(&gr_inode_lock);
51236 + }
51237 + preempt_enable();
51238 +
51239 + return;
51240 +}
51241 +
51242 +void
51243 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
51244 + struct dentry *old_dentry,
51245 + struct dentry *new_dentry,
51246 + struct vfsmount *mnt, const __u8 replace)
51247 +{
51248 + struct name_entry *matchn;
51249 + struct inodev_entry *inodev;
51250 + struct inode *inode = new_dentry->d_inode;
51251 + ino_t old_ino = old_dentry->d_inode->i_ino;
51252 + dev_t old_dev = __get_dev(old_dentry);
51253 +
51254 + /* vfs_rename swaps the name and parent link for old_dentry and
51255 + new_dentry
51256 + at this point, old_dentry has the new name, parent link, and inode
51257 + for the renamed file
51258 + if a file is being replaced by a rename, new_dentry has the inode
51259 + and name for the replaced file
51260 + */
51261 +
51262 + if (unlikely(!(gr_status & GR_READY)))
51263 + return;
51264 +
51265 + preempt_disable();
51266 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
51267 +
51268 + /* we wouldn't have to check d_inode if it weren't for
51269 + NFS silly-renaming
51270 + */
51271 +
51272 + write_lock(&gr_inode_lock);
51273 + if (unlikely(replace && inode)) {
51274 + ino_t new_ino = inode->i_ino;
51275 + dev_t new_dev = __get_dev(new_dentry);
51276 +
51277 + inodev = lookup_inodev_entry(new_ino, new_dev);
51278 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
51279 + do_handle_delete(inodev, new_ino, new_dev);
51280 + }
51281 +
51282 + inodev = lookup_inodev_entry(old_ino, old_dev);
51283 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
51284 + do_handle_delete(inodev, old_ino, old_dev);
51285 +
51286 + if (unlikely((unsigned long)matchn))
51287 + do_handle_create(matchn, old_dentry, mnt);
51288 +
51289 + write_unlock(&gr_inode_lock);
51290 + preempt_enable();
51291 +
51292 + return;
51293 +}
51294 +
51295 +static int
51296 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
51297 + unsigned char **sum)
51298 +{
51299 + struct acl_role_label *r;
51300 + struct role_allowed_ip *ipp;
51301 + struct role_transition *trans;
51302 + unsigned int i;
51303 + int found = 0;
51304 + u32 curr_ip = current->signal->curr_ip;
51305 +
51306 + current->signal->saved_ip = curr_ip;
51307 +
51308 + /* check transition table */
51309 +
51310 + for (trans = current->role->transitions; trans; trans = trans->next) {
51311 + if (!strcmp(rolename, trans->rolename)) {
51312 + found = 1;
51313 + break;
51314 + }
51315 + }
51316 +
51317 + if (!found)
51318 + return 0;
51319 +
51320 + /* handle special roles that do not require authentication
51321 + and check ip */
51322 +
51323 + FOR_EACH_ROLE_START(r)
51324 + if (!strcmp(rolename, r->rolename) &&
51325 + (r->roletype & GR_ROLE_SPECIAL)) {
51326 + found = 0;
51327 + if (r->allowed_ips != NULL) {
51328 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
51329 + if ((ntohl(curr_ip) & ipp->netmask) ==
51330 + (ntohl(ipp->addr) & ipp->netmask))
51331 + found = 1;
51332 + }
51333 + } else
51334 + found = 2;
51335 + if (!found)
51336 + return 0;
51337 +
51338 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
51339 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
51340 + *salt = NULL;
51341 + *sum = NULL;
51342 + return 1;
51343 + }
51344 + }
51345 + FOR_EACH_ROLE_END(r)
51346 +
51347 + for (i = 0; i < num_sprole_pws; i++) {
51348 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
51349 + *salt = acl_special_roles[i]->salt;
51350 + *sum = acl_special_roles[i]->sum;
51351 + return 1;
51352 + }
51353 + }
51354 +
51355 + return 0;
51356 +}
51357 +
51358 +static void
51359 +assign_special_role(char *rolename)
51360 +{
51361 + struct acl_object_label *obj;
51362 + struct acl_role_label *r;
51363 + struct acl_role_label *assigned = NULL;
51364 + struct task_struct *tsk;
51365 + struct file *filp;
51366 +
51367 + FOR_EACH_ROLE_START(r)
51368 + if (!strcmp(rolename, r->rolename) &&
51369 + (r->roletype & GR_ROLE_SPECIAL)) {
51370 + assigned = r;
51371 + break;
51372 + }
51373 + FOR_EACH_ROLE_END(r)
51374 +
51375 + if (!assigned)
51376 + return;
51377 +
51378 + read_lock(&tasklist_lock);
51379 + read_lock(&grsec_exec_file_lock);
51380 +
51381 + tsk = current->real_parent;
51382 + if (tsk == NULL)
51383 + goto out_unlock;
51384 +
51385 + filp = tsk->exec_file;
51386 + if (filp == NULL)
51387 + goto out_unlock;
51388 +
51389 + tsk->is_writable = 0;
51390 +
51391 + tsk->acl_sp_role = 1;
51392 + tsk->acl_role_id = ++acl_sp_role_value;
51393 + tsk->role = assigned;
51394 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
51395 +
51396 + /* ignore additional mmap checks for processes that are writable
51397 + by the default ACL */
51398 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51399 + if (unlikely(obj->mode & GR_WRITE))
51400 + tsk->is_writable = 1;
51401 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
51402 + if (unlikely(obj->mode & GR_WRITE))
51403 + tsk->is_writable = 1;
51404 +
51405 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51406 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
51407 +#endif
51408 +
51409 +out_unlock:
51410 + read_unlock(&grsec_exec_file_lock);
51411 + read_unlock(&tasklist_lock);
51412 + return;
51413 +}
51414 +
51415 +int gr_check_secure_terminal(struct task_struct *task)
51416 +{
51417 + struct task_struct *p, *p2, *p3;
51418 + struct files_struct *files;
51419 + struct fdtable *fdt;
51420 + struct file *our_file = NULL, *file;
51421 + int i;
51422 +
51423 + if (task->signal->tty == NULL)
51424 + return 1;
51425 +
51426 + files = get_files_struct(task);
51427 + if (files != NULL) {
51428 + rcu_read_lock();
51429 + fdt = files_fdtable(files);
51430 + for (i=0; i < fdt->max_fds; i++) {
51431 + file = fcheck_files(files, i);
51432 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
51433 + get_file(file);
51434 + our_file = file;
51435 + }
51436 + }
51437 + rcu_read_unlock();
51438 + put_files_struct(files);
51439 + }
51440 +
51441 + if (our_file == NULL)
51442 + return 1;
51443 +
51444 + read_lock(&tasklist_lock);
51445 + do_each_thread(p2, p) {
51446 + files = get_files_struct(p);
51447 + if (files == NULL ||
51448 + (p->signal && p->signal->tty == task->signal->tty)) {
51449 + if (files != NULL)
51450 + put_files_struct(files);
51451 + continue;
51452 + }
51453 + rcu_read_lock();
51454 + fdt = files_fdtable(files);
51455 + for (i=0; i < fdt->max_fds; i++) {
51456 + file = fcheck_files(files, i);
51457 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
51458 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
51459 + p3 = task;
51460 + while (p3->pid > 0) {
51461 + if (p3 == p)
51462 + break;
51463 + p3 = p3->real_parent;
51464 + }
51465 + if (p3 == p)
51466 + break;
51467 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
51468 + gr_handle_alertkill(p);
51469 + rcu_read_unlock();
51470 + put_files_struct(files);
51471 + read_unlock(&tasklist_lock);
51472 + fput(our_file);
51473 + return 0;
51474 + }
51475 + }
51476 + rcu_read_unlock();
51477 + put_files_struct(files);
51478 + } while_each_thread(p2, p);
51479 + read_unlock(&tasklist_lock);
51480 +
51481 + fput(our_file);
51482 + return 1;
51483 +}
51484 +
51485 +ssize_t
51486 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
51487 +{
51488 + struct gr_arg_wrapper uwrap;
51489 + unsigned char *sprole_salt = NULL;
51490 + unsigned char *sprole_sum = NULL;
51491 + int error = sizeof (struct gr_arg_wrapper);
51492 + int error2 = 0;
51493 +
51494 + mutex_lock(&gr_dev_mutex);
51495 +
51496 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
51497 + error = -EPERM;
51498 + goto out;
51499 + }
51500 +
51501 + if (count != sizeof (struct gr_arg_wrapper)) {
51502 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
51503 + error = -EINVAL;
51504 + goto out;
51505 + }
51506 +
51507 +
51508 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
51509 + gr_auth_expires = 0;
51510 + gr_auth_attempts = 0;
51511 + }
51512 +
51513 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
51514 + error = -EFAULT;
51515 + goto out;
51516 + }
51517 +
51518 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
51519 + error = -EINVAL;
51520 + goto out;
51521 + }
51522 +
51523 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
51524 + error = -EFAULT;
51525 + goto out;
51526 + }
51527 +
51528 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
51529 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
51530 + time_after(gr_auth_expires, get_seconds())) {
51531 + error = -EBUSY;
51532 + goto out;
51533 + }
51534 +
51535 + /* if non-root trying to do anything other than use a special role,
51536 + do not attempt authentication, do not count towards authentication
51537 + locking
51538 + */
51539 +
51540 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
51541 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
51542 + current_uid()) {
51543 + error = -EPERM;
51544 + goto out;
51545 + }
51546 +
51547 + /* ensure pw and special role name are null terminated */
51548 +
51549 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
51550 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
51551 +
51552 + /* Okay.
51553 + * We have our enough of the argument structure..(we have yet
51554 + * to copy_from_user the tables themselves) . Copy the tables
51555 + * only if we need them, i.e. for loading operations. */
51556 +
51557 + switch (gr_usermode->mode) {
51558 + case GR_STATUS:
51559 + if (gr_status & GR_READY) {
51560 + error = 1;
51561 + if (!gr_check_secure_terminal(current))
51562 + error = 3;
51563 + } else
51564 + error = 2;
51565 + goto out;
51566 + case GR_SHUTDOWN:
51567 + if ((gr_status & GR_READY)
51568 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51569 + pax_open_kernel();
51570 + gr_status &= ~GR_READY;
51571 + pax_close_kernel();
51572 +
51573 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
51574 + free_variables();
51575 + memset(gr_usermode, 0, sizeof (struct gr_arg));
51576 + memset(gr_system_salt, 0, GR_SALT_LEN);
51577 + memset(gr_system_sum, 0, GR_SHA_LEN);
51578 + } else if (gr_status & GR_READY) {
51579 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
51580 + error = -EPERM;
51581 + } else {
51582 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
51583 + error = -EAGAIN;
51584 + }
51585 + break;
51586 + case GR_ENABLE:
51587 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
51588 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
51589 + else {
51590 + if (gr_status & GR_READY)
51591 + error = -EAGAIN;
51592 + else
51593 + error = error2;
51594 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
51595 + }
51596 + break;
51597 + case GR_RELOAD:
51598 + if (!(gr_status & GR_READY)) {
51599 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
51600 + error = -EAGAIN;
51601 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51602 + preempt_disable();
51603 +
51604 + pax_open_kernel();
51605 + gr_status &= ~GR_READY;
51606 + pax_close_kernel();
51607 +
51608 + free_variables();
51609 + if (!(error2 = gracl_init(gr_usermode))) {
51610 + preempt_enable();
51611 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
51612 + } else {
51613 + preempt_enable();
51614 + error = error2;
51615 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
51616 + }
51617 + } else {
51618 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
51619 + error = -EPERM;
51620 + }
51621 + break;
51622 + case GR_SEGVMOD:
51623 + if (unlikely(!(gr_status & GR_READY))) {
51624 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
51625 + error = -EAGAIN;
51626 + break;
51627 + }
51628 +
51629 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
51630 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
51631 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
51632 + struct acl_subject_label *segvacl;
51633 + segvacl =
51634 + lookup_acl_subj_label(gr_usermode->segv_inode,
51635 + gr_usermode->segv_device,
51636 + current->role);
51637 + if (segvacl) {
51638 + segvacl->crashes = 0;
51639 + segvacl->expires = 0;
51640 + }
51641 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
51642 + gr_remove_uid(gr_usermode->segv_uid);
51643 + }
51644 + } else {
51645 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
51646 + error = -EPERM;
51647 + }
51648 + break;
51649 + case GR_SPROLE:
51650 + case GR_SPROLEPAM:
51651 + if (unlikely(!(gr_status & GR_READY))) {
51652 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
51653 + error = -EAGAIN;
51654 + break;
51655 + }
51656 +
51657 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
51658 + current->role->expires = 0;
51659 + current->role->auth_attempts = 0;
51660 + }
51661 +
51662 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
51663 + time_after(current->role->expires, get_seconds())) {
51664 + error = -EBUSY;
51665 + goto out;
51666 + }
51667 +
51668 + if (lookup_special_role_auth
51669 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
51670 + && ((!sprole_salt && !sprole_sum)
51671 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
51672 + char *p = "";
51673 + assign_special_role(gr_usermode->sp_role);
51674 + read_lock(&tasklist_lock);
51675 + if (current->real_parent)
51676 + p = current->real_parent->role->rolename;
51677 + read_unlock(&tasklist_lock);
51678 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
51679 + p, acl_sp_role_value);
51680 + } else {
51681 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
51682 + error = -EPERM;
51683 + if(!(current->role->auth_attempts++))
51684 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
51685 +
51686 + goto out;
51687 + }
51688 + break;
51689 + case GR_UNSPROLE:
51690 + if (unlikely(!(gr_status & GR_READY))) {
51691 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
51692 + error = -EAGAIN;
51693 + break;
51694 + }
51695 +
51696 + if (current->role->roletype & GR_ROLE_SPECIAL) {
51697 + char *p = "";
51698 + int i = 0;
51699 +
51700 + read_lock(&tasklist_lock);
51701 + if (current->real_parent) {
51702 + p = current->real_parent->role->rolename;
51703 + i = current->real_parent->acl_role_id;
51704 + }
51705 + read_unlock(&tasklist_lock);
51706 +
51707 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
51708 + gr_set_acls(1);
51709 + } else {
51710 + error = -EPERM;
51711 + goto out;
51712 + }
51713 + break;
51714 + default:
51715 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
51716 + error = -EINVAL;
51717 + break;
51718 + }
51719 +
51720 + if (error != -EPERM)
51721 + goto out;
51722 +
51723 + if(!(gr_auth_attempts++))
51724 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
51725 +
51726 + out:
51727 + mutex_unlock(&gr_dev_mutex);
51728 + return error;
51729 +}
51730 +
51731 +/* must be called with
51732 + rcu_read_lock();
51733 + read_lock(&tasklist_lock);
51734 + read_lock(&grsec_exec_file_lock);
51735 +*/
51736 +int gr_apply_subject_to_task(struct task_struct *task)
51737 +{
51738 + struct acl_object_label *obj;
51739 + char *tmpname;
51740 + struct acl_subject_label *tmpsubj;
51741 + struct file *filp;
51742 + struct name_entry *nmatch;
51743 +
51744 + filp = task->exec_file;
51745 + if (filp == NULL)
51746 + return 0;
51747 +
51748 + /* the following is to apply the correct subject
51749 + on binaries running when the RBAC system
51750 + is enabled, when the binaries have been
51751 + replaced or deleted since their execution
51752 + -----
51753 + when the RBAC system starts, the inode/dev
51754 + from exec_file will be one the RBAC system
51755 + is unaware of. It only knows the inode/dev
51756 + of the present file on disk, or the absence
51757 + of it.
51758 + */
51759 + preempt_disable();
51760 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
51761 +
51762 + nmatch = lookup_name_entry(tmpname);
51763 + preempt_enable();
51764 + tmpsubj = NULL;
51765 + if (nmatch) {
51766 + if (nmatch->deleted)
51767 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
51768 + else
51769 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
51770 + if (tmpsubj != NULL)
51771 + task->acl = tmpsubj;
51772 + }
51773 + if (tmpsubj == NULL)
51774 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
51775 + task->role);
51776 + if (task->acl) {
51777 + task->is_writable = 0;
51778 + /* ignore additional mmap checks for processes that are writable
51779 + by the default ACL */
51780 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
51781 + if (unlikely(obj->mode & GR_WRITE))
51782 + task->is_writable = 1;
51783 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
51784 + if (unlikely(obj->mode & GR_WRITE))
51785 + task->is_writable = 1;
51786 +
51787 + gr_set_proc_res(task);
51788 +
51789 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
51790 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
51791 +#endif
51792 + } else {
51793 + return 1;
51794 + }
51795 +
51796 + return 0;
51797 +}
51798 +
51799 +int
51800 +gr_set_acls(const int type)
51801 +{
51802 + struct task_struct *task, *task2;
51803 + struct acl_role_label *role = current->role;
51804 + __u16 acl_role_id = current->acl_role_id;
51805 + const struct cred *cred;
51806 + int ret;
51807 +
51808 + rcu_read_lock();
51809 + read_lock(&tasklist_lock);
51810 + read_lock(&grsec_exec_file_lock);
51811 + do_each_thread(task2, task) {
51812 + /* check to see if we're called from the exit handler,
51813 + if so, only replace ACLs that have inherited the admin
51814 + ACL */
51815 +
51816 + if (type && (task->role != role ||
51817 + task->acl_role_id != acl_role_id))
51818 + continue;
51819 +
51820 + task->acl_role_id = 0;
51821 + task->acl_sp_role = 0;
51822 +
51823 + if (task->exec_file) {
51824 + cred = __task_cred(task);
51825 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
51826 + ret = gr_apply_subject_to_task(task);
51827 + if (ret) {
51828 + read_unlock(&grsec_exec_file_lock);
51829 + read_unlock(&tasklist_lock);
51830 + rcu_read_unlock();
51831 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
51832 + return ret;
51833 + }
51834 + } else {
51835 + // it's a kernel process
51836 + task->role = kernel_role;
51837 + task->acl = kernel_role->root_label;
51838 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
51839 + task->acl->mode &= ~GR_PROCFIND;
51840 +#endif
51841 + }
51842 + } while_each_thread(task2, task);
51843 + read_unlock(&grsec_exec_file_lock);
51844 + read_unlock(&tasklist_lock);
51845 + rcu_read_unlock();
51846 +
51847 + return 0;
51848 +}
51849 +
51850 +void
51851 +gr_learn_resource(const struct task_struct *task,
51852 + const int res, const unsigned long wanted, const int gt)
51853 +{
51854 + struct acl_subject_label *acl;
51855 + const struct cred *cred;
51856 +
51857 + if (unlikely((gr_status & GR_READY) &&
51858 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
51859 + goto skip_reslog;
51860 +
51861 +#ifdef CONFIG_GRKERNSEC_RESLOG
51862 + gr_log_resource(task, res, wanted, gt);
51863 +#endif
51864 + skip_reslog:
51865 +
51866 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
51867 + return;
51868 +
51869 + acl = task->acl;
51870 +
51871 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
51872 + !(acl->resmask & (1 << (unsigned short) res))))
51873 + return;
51874 +
51875 + if (wanted >= acl->res[res].rlim_cur) {
51876 + unsigned long res_add;
51877 +
51878 + res_add = wanted;
51879 + switch (res) {
51880 + case RLIMIT_CPU:
51881 + res_add += GR_RLIM_CPU_BUMP;
51882 + break;
51883 + case RLIMIT_FSIZE:
51884 + res_add += GR_RLIM_FSIZE_BUMP;
51885 + break;
51886 + case RLIMIT_DATA:
51887 + res_add += GR_RLIM_DATA_BUMP;
51888 + break;
51889 + case RLIMIT_STACK:
51890 + res_add += GR_RLIM_STACK_BUMP;
51891 + break;
51892 + case RLIMIT_CORE:
51893 + res_add += GR_RLIM_CORE_BUMP;
51894 + break;
51895 + case RLIMIT_RSS:
51896 + res_add += GR_RLIM_RSS_BUMP;
51897 + break;
51898 + case RLIMIT_NPROC:
51899 + res_add += GR_RLIM_NPROC_BUMP;
51900 + break;
51901 + case RLIMIT_NOFILE:
51902 + res_add += GR_RLIM_NOFILE_BUMP;
51903 + break;
51904 + case RLIMIT_MEMLOCK:
51905 + res_add += GR_RLIM_MEMLOCK_BUMP;
51906 + break;
51907 + case RLIMIT_AS:
51908 + res_add += GR_RLIM_AS_BUMP;
51909 + break;
51910 + case RLIMIT_LOCKS:
51911 + res_add += GR_RLIM_LOCKS_BUMP;
51912 + break;
51913 + case RLIMIT_SIGPENDING:
51914 + res_add += GR_RLIM_SIGPENDING_BUMP;
51915 + break;
51916 + case RLIMIT_MSGQUEUE:
51917 + res_add += GR_RLIM_MSGQUEUE_BUMP;
51918 + break;
51919 + case RLIMIT_NICE:
51920 + res_add += GR_RLIM_NICE_BUMP;
51921 + break;
51922 + case RLIMIT_RTPRIO:
51923 + res_add += GR_RLIM_RTPRIO_BUMP;
51924 + break;
51925 + case RLIMIT_RTTIME:
51926 + res_add += GR_RLIM_RTTIME_BUMP;
51927 + break;
51928 + }
51929 +
51930 + acl->res[res].rlim_cur = res_add;
51931 +
51932 + if (wanted > acl->res[res].rlim_max)
51933 + acl->res[res].rlim_max = res_add;
51934 +
51935 + /* only log the subject filename, since resource logging is supported for
51936 + single-subject learning only */
51937 + rcu_read_lock();
51938 + cred = __task_cred(task);
51939 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
51940 + task->role->roletype, cred->uid, cred->gid, acl->filename,
51941 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
51942 + "", (unsigned long) res, &task->signal->saved_ip);
51943 + rcu_read_unlock();
51944 + }
51945 +
51946 + return;
51947 +}
51948 +
51949 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
51950 +void
51951 +pax_set_initial_flags(struct linux_binprm *bprm)
51952 +{
51953 + struct task_struct *task = current;
51954 + struct acl_subject_label *proc;
51955 + unsigned long flags;
51956 +
51957 + if (unlikely(!(gr_status & GR_READY)))
51958 + return;
51959 +
51960 + flags = pax_get_flags(task);
51961 +
51962 + proc = task->acl;
51963 +
51964 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
51965 + flags &= ~MF_PAX_PAGEEXEC;
51966 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
51967 + flags &= ~MF_PAX_SEGMEXEC;
51968 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
51969 + flags &= ~MF_PAX_RANDMMAP;
51970 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
51971 + flags &= ~MF_PAX_EMUTRAMP;
51972 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
51973 + flags &= ~MF_PAX_MPROTECT;
51974 +
51975 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
51976 + flags |= MF_PAX_PAGEEXEC;
51977 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
51978 + flags |= MF_PAX_SEGMEXEC;
51979 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
51980 + flags |= MF_PAX_RANDMMAP;
51981 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
51982 + flags |= MF_PAX_EMUTRAMP;
51983 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
51984 + flags |= MF_PAX_MPROTECT;
51985 +
51986 + pax_set_flags(task, flags);
51987 +
51988 + return;
51989 +}
51990 +#endif
51991 +
51992 +#ifdef CONFIG_SYSCTL
51993 +/* Eric Biederman likes breaking userland ABI and every inode-based security
51994 + system to save 35kb of memory */
51995 +
51996 +/* we modify the passed in filename, but adjust it back before returning */
51997 +static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
51998 +{
51999 + struct name_entry *nmatch;
52000 + char *p, *lastp = NULL;
52001 + struct acl_object_label *obj = NULL, *tmp;
52002 + struct acl_subject_label *tmpsubj;
52003 + char c = '\0';
52004 +
52005 + read_lock(&gr_inode_lock);
52006 +
52007 + p = name + len - 1;
52008 + do {
52009 + nmatch = lookup_name_entry(name);
52010 + if (lastp != NULL)
52011 + *lastp = c;
52012 +
52013 + if (nmatch == NULL)
52014 + goto next_component;
52015 + tmpsubj = current->acl;
52016 + do {
52017 + obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
52018 + if (obj != NULL) {
52019 + tmp = obj->globbed;
52020 + while (tmp) {
52021 + if (!glob_match(tmp->filename, name)) {
52022 + obj = tmp;
52023 + goto found_obj;
52024 + }
52025 + tmp = tmp->next;
52026 + }
52027 + goto found_obj;
52028 + }
52029 + } while ((tmpsubj = tmpsubj->parent_subject));
52030 +next_component:
52031 + /* end case */
52032 + if (p == name)
52033 + break;
52034 +
52035 + while (*p != '/')
52036 + p--;
52037 + if (p == name)
52038 + lastp = p + 1;
52039 + else {
52040 + lastp = p;
52041 + p--;
52042 + }
52043 + c = *lastp;
52044 + *lastp = '\0';
52045 + } while (1);
52046 +found_obj:
52047 + read_unlock(&gr_inode_lock);
52048 + /* obj returned will always be non-null */
52049 + return obj;
52050 +}
52051 +
52052 +/* returns 0 when allowing, non-zero on error
52053 + op of 0 is used for readdir, so we don't log the names of hidden files
52054 +*/
52055 +__u32
52056 +gr_handle_sysctl(const struct ctl_table *table, const int op)
52057 +{
52058 + struct ctl_table *tmp;
52059 + const char *proc_sys = "/proc/sys";
52060 + char *path;
52061 + struct acl_object_label *obj;
52062 + unsigned short len = 0, pos = 0, depth = 0, i;
52063 + __u32 err = 0;
52064 + __u32 mode = 0;
52065 +
52066 + if (unlikely(!(gr_status & GR_READY)))
52067 + return 0;
52068 +
52069 + /* for now, ignore operations on non-sysctl entries if it's not a
52070 + readdir*/
52071 + if (table->child != NULL && op != 0)
52072 + return 0;
52073 +
52074 + mode |= GR_FIND;
52075 + /* it's only a read if it's an entry, read on dirs is for readdir */
52076 + if (op & MAY_READ)
52077 + mode |= GR_READ;
52078 + if (op & MAY_WRITE)
52079 + mode |= GR_WRITE;
52080 +
52081 + preempt_disable();
52082 +
52083 + path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52084 +
52085 + /* it's only a read/write if it's an actual entry, not a dir
52086 + (which are opened for readdir)
52087 + */
52088 +
52089 + /* convert the requested sysctl entry into a pathname */
52090 +
52091 + for (tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
52092 + len += strlen(tmp->procname);
52093 + len++;
52094 + depth++;
52095 + }
52096 +
52097 + if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
52098 + /* deny */
52099 + goto out;
52100 + }
52101 +
52102 + memset(path, 0, PAGE_SIZE);
52103 +
52104 + memcpy(path, proc_sys, strlen(proc_sys));
52105 +
52106 + pos += strlen(proc_sys);
52107 +
52108 + for (; depth > 0; depth--) {
52109 + path[pos] = '/';
52110 + pos++;
52111 + for (i = 1, tmp = (struct ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
52112 + if (depth == i) {
52113 + memcpy(path + pos, tmp->procname,
52114 + strlen(tmp->procname));
52115 + pos += strlen(tmp->procname);
52116 + }
52117 + i++;
52118 + }
52119 + }
52120 +
52121 + obj = gr_lookup_by_name(path, pos);
52122 + err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
52123 +
52124 + if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
52125 + ((err & mode) != mode))) {
52126 + __u32 new_mode = mode;
52127 +
52128 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
52129 +
52130 + err = 0;
52131 + gr_log_learn_sysctl(path, new_mode);
52132 + } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
52133 + gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
52134 + err = -ENOENT;
52135 + } else if (!(err & GR_FIND)) {
52136 + err = -ENOENT;
52137 + } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
52138 + gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
52139 + path, (mode & GR_READ) ? " reading" : "",
52140 + (mode & GR_WRITE) ? " writing" : "");
52141 + err = -EACCES;
52142 + } else if ((err & mode) != mode) {
52143 + err = -EACCES;
52144 + } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
52145 + gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
52146 + path, (mode & GR_READ) ? " reading" : "",
52147 + (mode & GR_WRITE) ? " writing" : "");
52148 + err = 0;
52149 + } else
52150 + err = 0;
52151 +
52152 + out:
52153 + preempt_enable();
52154 +
52155 + return err;
52156 +}
52157 +#endif
52158 +
52159 +int
52160 +gr_handle_proc_ptrace(struct task_struct *task)
52161 +{
52162 + struct file *filp;
52163 + struct task_struct *tmp = task;
52164 + struct task_struct *curtemp = current;
52165 + __u32 retmode;
52166 +
52167 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
52168 + if (unlikely(!(gr_status & GR_READY)))
52169 + return 0;
52170 +#endif
52171 +
52172 + read_lock(&tasklist_lock);
52173 + read_lock(&grsec_exec_file_lock);
52174 + filp = task->exec_file;
52175 +
52176 + while (tmp->pid > 0) {
52177 + if (tmp == curtemp)
52178 + break;
52179 + tmp = tmp->real_parent;
52180 + }
52181 +
52182 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
52183 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
52184 + read_unlock(&grsec_exec_file_lock);
52185 + read_unlock(&tasklist_lock);
52186 + return 1;
52187 + }
52188 +
52189 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52190 + if (!(gr_status & GR_READY)) {
52191 + read_unlock(&grsec_exec_file_lock);
52192 + read_unlock(&tasklist_lock);
52193 + return 0;
52194 + }
52195 +#endif
52196 +
52197 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
52198 + read_unlock(&grsec_exec_file_lock);
52199 + read_unlock(&tasklist_lock);
52200 +
52201 + if (retmode & GR_NOPTRACE)
52202 + return 1;
52203 +
52204 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
52205 + && (current->acl != task->acl || (current->acl != current->role->root_label
52206 + && current->pid != task->pid)))
52207 + return 1;
52208 +
52209 + return 0;
52210 +}
52211 +
52212 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
52213 +{
52214 + if (unlikely(!(gr_status & GR_READY)))
52215 + return;
52216 +
52217 + if (!(current->role->roletype & GR_ROLE_GOD))
52218 + return;
52219 +
52220 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
52221 + p->role->rolename, gr_task_roletype_to_char(p),
52222 + p->acl->filename);
52223 +}
52224 +
52225 +int
52226 +gr_handle_ptrace(struct task_struct *task, const long request)
52227 +{
52228 + struct task_struct *tmp = task;
52229 + struct task_struct *curtemp = current;
52230 + __u32 retmode;
52231 +
52232 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
52233 + if (unlikely(!(gr_status & GR_READY)))
52234 + return 0;
52235 +#endif
52236 +
52237 + read_lock(&tasklist_lock);
52238 + while (tmp->pid > 0) {
52239 + if (tmp == curtemp)
52240 + break;
52241 + tmp = tmp->real_parent;
52242 + }
52243 +
52244 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && current_uid() && !(gr_status & GR_READY)) ||
52245 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
52246 + read_unlock(&tasklist_lock);
52247 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52248 + return 1;
52249 + }
52250 + read_unlock(&tasklist_lock);
52251 +
52252 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
52253 + if (!(gr_status & GR_READY))
52254 + return 0;
52255 +#endif
52256 +
52257 + read_lock(&grsec_exec_file_lock);
52258 + if (unlikely(!task->exec_file)) {
52259 + read_unlock(&grsec_exec_file_lock);
52260 + return 0;
52261 + }
52262 +
52263 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
52264 + read_unlock(&grsec_exec_file_lock);
52265 +
52266 + if (retmode & GR_NOPTRACE) {
52267 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52268 + return 1;
52269 + }
52270 +
52271 + if (retmode & GR_PTRACERD) {
52272 + switch (request) {
52273 + case PTRACE_SEIZE:
52274 + case PTRACE_POKETEXT:
52275 + case PTRACE_POKEDATA:
52276 + case PTRACE_POKEUSR:
52277 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
52278 + case PTRACE_SETREGS:
52279 + case PTRACE_SETFPREGS:
52280 +#endif
52281 +#ifdef CONFIG_X86
52282 + case PTRACE_SETFPXREGS:
52283 +#endif
52284 +#ifdef CONFIG_ALTIVEC
52285 + case PTRACE_SETVRREGS:
52286 +#endif
52287 + return 1;
52288 + default:
52289 + return 0;
52290 + }
52291 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
52292 + !(current->role->roletype & GR_ROLE_GOD) &&
52293 + (current->acl != task->acl)) {
52294 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
52295 + return 1;
52296 + }
52297 +
52298 + return 0;
52299 +}
52300 +
52301 +static int is_writable_mmap(const struct file *filp)
52302 +{
52303 + struct task_struct *task = current;
52304 + struct acl_object_label *obj, *obj2;
52305 +
52306 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
52307 + !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))) {
52308 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
52309 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
52310 + task->role->root_label);
52311 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
52312 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
52313 + return 1;
52314 + }
52315 + }
52316 + return 0;
52317 +}
52318 +
52319 +int
52320 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
52321 +{
52322 + __u32 mode;
52323 +
52324 + if (unlikely(!file || !(prot & PROT_EXEC)))
52325 + return 1;
52326 +
52327 + if (is_writable_mmap(file))
52328 + return 0;
52329 +
52330 + mode =
52331 + gr_search_file(file->f_path.dentry,
52332 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
52333 + file->f_path.mnt);
52334 +
52335 + if (!gr_tpe_allow(file))
52336 + return 0;
52337 +
52338 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
52339 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52340 + return 0;
52341 + } else if (unlikely(!(mode & GR_EXEC))) {
52342 + return 0;
52343 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
52344 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52345 + return 1;
52346 + }
52347 +
52348 + return 1;
52349 +}
52350 +
52351 +int
52352 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
52353 +{
52354 + __u32 mode;
52355 +
52356 + if (unlikely(!file || !(prot & PROT_EXEC)))
52357 + return 1;
52358 +
52359 + if (is_writable_mmap(file))
52360 + return 0;
52361 +
52362 + mode =
52363 + gr_search_file(file->f_path.dentry,
52364 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
52365 + file->f_path.mnt);
52366 +
52367 + if (!gr_tpe_allow(file))
52368 + return 0;
52369 +
52370 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
52371 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52372 + return 0;
52373 + } else if (unlikely(!(mode & GR_EXEC))) {
52374 + return 0;
52375 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
52376 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
52377 + return 1;
52378 + }
52379 +
52380 + return 1;
52381 +}
52382 +
52383 +void
52384 +gr_acl_handle_psacct(struct task_struct *task, const long code)
52385 +{
52386 + unsigned long runtime;
52387 + unsigned long cputime;
52388 + unsigned int wday, cday;
52389 + __u8 whr, chr;
52390 + __u8 wmin, cmin;
52391 + __u8 wsec, csec;
52392 + struct timespec timeval;
52393 +
52394 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
52395 + !(task->acl->mode & GR_PROCACCT)))
52396 + return;
52397 +
52398 + do_posix_clock_monotonic_gettime(&timeval);
52399 + runtime = timeval.tv_sec - task->start_time.tv_sec;
52400 + wday = runtime / (3600 * 24);
52401 + runtime -= wday * (3600 * 24);
52402 + whr = runtime / 3600;
52403 + runtime -= whr * 3600;
52404 + wmin = runtime / 60;
52405 + runtime -= wmin * 60;
52406 + wsec = runtime;
52407 +
52408 + cputime = (task->utime + task->stime) / HZ;
52409 + cday = cputime / (3600 * 24);
52410 + cputime -= cday * (3600 * 24);
52411 + chr = cputime / 3600;
52412 + cputime -= chr * 3600;
52413 + cmin = cputime / 60;
52414 + cputime -= cmin * 60;
52415 + csec = cputime;
52416 +
52417 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
52418 +
52419 + return;
52420 +}
52421 +
52422 +void gr_set_kernel_label(struct task_struct *task)
52423 +{
52424 + if (gr_status & GR_READY) {
52425 + task->role = kernel_role;
52426 + task->acl = kernel_role->root_label;
52427 + }
52428 + return;
52429 +}
52430 +
52431 +#ifdef CONFIG_TASKSTATS
52432 +int gr_is_taskstats_denied(int pid)
52433 +{
52434 + struct task_struct *task;
52435 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52436 + const struct cred *cred;
52437 +#endif
52438 + int ret = 0;
52439 +
52440 + /* restrict taskstats viewing to un-chrooted root users
52441 + who have the 'view' subject flag if the RBAC system is enabled
52442 + */
52443 +
52444 + rcu_read_lock();
52445 + read_lock(&tasklist_lock);
52446 + task = find_task_by_vpid(pid);
52447 + if (task) {
52448 +#ifdef CONFIG_GRKERNSEC_CHROOT
52449 + if (proc_is_chrooted(task))
52450 + ret = -EACCES;
52451 +#endif
52452 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52453 + cred = __task_cred(task);
52454 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52455 + if (cred->uid != 0)
52456 + ret = -EACCES;
52457 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52458 + if (cred->uid != 0 && !groups_search(cred->group_info, CONFIG_GRKERNSEC_PROC_GID))
52459 + ret = -EACCES;
52460 +#endif
52461 +#endif
52462 + if (gr_status & GR_READY) {
52463 + if (!(task->acl->mode & GR_VIEW))
52464 + ret = -EACCES;
52465 + }
52466 + } else
52467 + ret = -ENOENT;
52468 +
52469 + read_unlock(&tasklist_lock);
52470 + rcu_read_unlock();
52471 +
52472 + return ret;
52473 +}
52474 +#endif
52475 +
52476 +/* AUXV entries are filled via a descendant of search_binary_handler
52477 + after we've already applied the subject for the target
52478 +*/
52479 +int gr_acl_enable_at_secure(void)
52480 +{
52481 + if (unlikely(!(gr_status & GR_READY)))
52482 + return 0;
52483 +
52484 + if (current->acl->mode & GR_ATSECURE)
52485 + return 1;
52486 +
52487 + return 0;
52488 +}
52489 +
52490 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
52491 +{
52492 + struct task_struct *task = current;
52493 + struct dentry *dentry = file->f_path.dentry;
52494 + struct vfsmount *mnt = file->f_path.mnt;
52495 + struct acl_object_label *obj, *tmp;
52496 + struct acl_subject_label *subj;
52497 + unsigned int bufsize;
52498 + int is_not_root;
52499 + char *path;
52500 + dev_t dev = __get_dev(dentry);
52501 +
52502 + if (unlikely(!(gr_status & GR_READY)))
52503 + return 1;
52504 +
52505 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
52506 + return 1;
52507 +
52508 + /* ignore Eric Biederman */
52509 + if (IS_PRIVATE(dentry->d_inode))
52510 + return 1;
52511 +
52512 + subj = task->acl;
52513 + do {
52514 + obj = lookup_acl_obj_label(ino, dev, subj);
52515 + if (obj != NULL)
52516 + return (obj->mode & GR_FIND) ? 1 : 0;
52517 + } while ((subj = subj->parent_subject));
52518 +
52519 + /* this is purely an optimization since we're looking for an object
52520 + for the directory we're doing a readdir on
52521 + if it's possible for any globbed object to match the entry we're
52522 + filling into the directory, then the object we find here will be
52523 + an anchor point with attached globbed objects
52524 + */
52525 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
52526 + if (obj->globbed == NULL)
52527 + return (obj->mode & GR_FIND) ? 1 : 0;
52528 +
52529 + is_not_root = ((obj->filename[0] == '/') &&
52530 + (obj->filename[1] == '\0')) ? 0 : 1;
52531 + bufsize = PAGE_SIZE - namelen - is_not_root;
52532 +
52533 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
52534 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
52535 + return 1;
52536 +
52537 + preempt_disable();
52538 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52539 + bufsize);
52540 +
52541 + bufsize = strlen(path);
52542 +
52543 + /* if base is "/", don't append an additional slash */
52544 + if (is_not_root)
52545 + *(path + bufsize) = '/';
52546 + memcpy(path + bufsize + is_not_root, name, namelen);
52547 + *(path + bufsize + namelen + is_not_root) = '\0';
52548 +
52549 + tmp = obj->globbed;
52550 + while (tmp) {
52551 + if (!glob_match(tmp->filename, path)) {
52552 + preempt_enable();
52553 + return (tmp->mode & GR_FIND) ? 1 : 0;
52554 + }
52555 + tmp = tmp->next;
52556 + }
52557 + preempt_enable();
52558 + return (obj->mode & GR_FIND) ? 1 : 0;
52559 +}
52560 +
52561 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
52562 +EXPORT_SYMBOL(gr_acl_is_enabled);
52563 +#endif
52564 +EXPORT_SYMBOL(gr_learn_resource);
52565 +EXPORT_SYMBOL(gr_set_kernel_label);
52566 +#ifdef CONFIG_SECURITY
52567 +EXPORT_SYMBOL(gr_check_user_change);
52568 +EXPORT_SYMBOL(gr_check_group_change);
52569 +#endif
52570 +
52571 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
52572 new file mode 100644
52573 index 0000000..34fefda
52574 --- /dev/null
52575 +++ b/grsecurity/gracl_alloc.c
52576 @@ -0,0 +1,105 @@
52577 +#include <linux/kernel.h>
52578 +#include <linux/mm.h>
52579 +#include <linux/slab.h>
52580 +#include <linux/vmalloc.h>
52581 +#include <linux/gracl.h>
52582 +#include <linux/grsecurity.h>
52583 +
52584 +static unsigned long alloc_stack_next = 1;
52585 +static unsigned long alloc_stack_size = 1;
52586 +static void **alloc_stack;
52587 +
52588 +static __inline__ int
52589 +alloc_pop(void)
52590 +{
52591 + if (alloc_stack_next == 1)
52592 + return 0;
52593 +
52594 + kfree(alloc_stack[alloc_stack_next - 2]);
52595 +
52596 + alloc_stack_next--;
52597 +
52598 + return 1;
52599 +}
52600 +
52601 +static __inline__ int
52602 +alloc_push(void *buf)
52603 +{
52604 + if (alloc_stack_next >= alloc_stack_size)
52605 + return 1;
52606 +
52607 + alloc_stack[alloc_stack_next - 1] = buf;
52608 +
52609 + alloc_stack_next++;
52610 +
52611 + return 0;
52612 +}
52613 +
52614 +void *
52615 +acl_alloc(unsigned long len)
52616 +{
52617 + void *ret = NULL;
52618 +
52619 + if (!len || len > PAGE_SIZE)
52620 + goto out;
52621 +
52622 + ret = kmalloc(len, GFP_KERNEL);
52623 +
52624 + if (ret) {
52625 + if (alloc_push(ret)) {
52626 + kfree(ret);
52627 + ret = NULL;
52628 + }
52629 + }
52630 +
52631 +out:
52632 + return ret;
52633 +}
52634 +
52635 +void *
52636 +acl_alloc_num(unsigned long num, unsigned long len)
52637 +{
52638 + if (!len || (num > (PAGE_SIZE / len)))
52639 + return NULL;
52640 +
52641 + return acl_alloc(num * len);
52642 +}
52643 +
52644 +void
52645 +acl_free_all(void)
52646 +{
52647 + if (gr_acl_is_enabled() || !alloc_stack)
52648 + return;
52649 +
52650 + while (alloc_pop()) ;
52651 +
52652 + if (alloc_stack) {
52653 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
52654 + kfree(alloc_stack);
52655 + else
52656 + vfree(alloc_stack);
52657 + }
52658 +
52659 + alloc_stack = NULL;
52660 + alloc_stack_size = 1;
52661 + alloc_stack_next = 1;
52662 +
52663 + return;
52664 +}
52665 +
52666 +int
52667 +acl_alloc_stack_init(unsigned long size)
52668 +{
52669 + if ((size * sizeof (void *)) <= PAGE_SIZE)
52670 + alloc_stack =
52671 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
52672 + else
52673 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
52674 +
52675 + alloc_stack_size = size;
52676 +
52677 + if (!alloc_stack)
52678 + return 0;
52679 + else
52680 + return 1;
52681 +}
52682 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
52683 new file mode 100644
52684 index 0000000..955ddfb
52685 --- /dev/null
52686 +++ b/grsecurity/gracl_cap.c
52687 @@ -0,0 +1,101 @@
52688 +#include <linux/kernel.h>
52689 +#include <linux/module.h>
52690 +#include <linux/sched.h>
52691 +#include <linux/gracl.h>
52692 +#include <linux/grsecurity.h>
52693 +#include <linux/grinternal.h>
52694 +
52695 +extern const char *captab_log[];
52696 +extern int captab_log_entries;
52697 +
52698 +int
52699 +gr_acl_is_capable(const int cap)
52700 +{
52701 + struct task_struct *task = current;
52702 + const struct cred *cred = current_cred();
52703 + struct acl_subject_label *curracl;
52704 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
52705 + kernel_cap_t cap_audit = __cap_empty_set;
52706 +
52707 + if (!gr_acl_is_enabled())
52708 + return 1;
52709 +
52710 + curracl = task->acl;
52711 +
52712 + cap_drop = curracl->cap_lower;
52713 + cap_mask = curracl->cap_mask;
52714 + cap_audit = curracl->cap_invert_audit;
52715 +
52716 + while ((curracl = curracl->parent_subject)) {
52717 + /* if the cap isn't specified in the current computed mask but is specified in the
52718 + current level subject, and is lowered in the current level subject, then add
52719 + it to the set of dropped capabilities
52720 + otherwise, add the current level subject's mask to the current computed mask
52721 + */
52722 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
52723 + cap_raise(cap_mask, cap);
52724 + if (cap_raised(curracl->cap_lower, cap))
52725 + cap_raise(cap_drop, cap);
52726 + if (cap_raised(curracl->cap_invert_audit, cap))
52727 + cap_raise(cap_audit, cap);
52728 + }
52729 + }
52730 +
52731 + if (!cap_raised(cap_drop, cap)) {
52732 + if (cap_raised(cap_audit, cap))
52733 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
52734 + return 1;
52735 + }
52736 +
52737 + curracl = task->acl;
52738 +
52739 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
52740 + && cap_raised(cred->cap_effective, cap)) {
52741 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
52742 + task->role->roletype, cred->uid,
52743 + cred->gid, task->exec_file ?
52744 + gr_to_filename(task->exec_file->f_path.dentry,
52745 + task->exec_file->f_path.mnt) : curracl->filename,
52746 + curracl->filename, 0UL,
52747 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
52748 + return 1;
52749 + }
52750 +
52751 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
52752 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
52753 + return 0;
52754 +}
52755 +
52756 +int
52757 +gr_acl_is_capable_nolog(const int cap)
52758 +{
52759 + struct acl_subject_label *curracl;
52760 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
52761 +
52762 + if (!gr_acl_is_enabled())
52763 + return 1;
52764 +
52765 + curracl = current->acl;
52766 +
52767 + cap_drop = curracl->cap_lower;
52768 + cap_mask = curracl->cap_mask;
52769 +
52770 + while ((curracl = curracl->parent_subject)) {
52771 + /* if the cap isn't specified in the current computed mask but is specified in the
52772 + current level subject, and is lowered in the current level subject, then add
52773 + it to the set of dropped capabilities
52774 + otherwise, add the current level subject's mask to the current computed mask
52775 + */
52776 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
52777 + cap_raise(cap_mask, cap);
52778 + if (cap_raised(curracl->cap_lower, cap))
52779 + cap_raise(cap_drop, cap);
52780 + }
52781 + }
52782 +
52783 + if (!cap_raised(cap_drop, cap))
52784 + return 1;
52785 +
52786 + return 0;
52787 +}
52788 +
52789 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
52790 new file mode 100644
52791 index 0000000..88d0e87
52792 --- /dev/null
52793 +++ b/grsecurity/gracl_fs.c
52794 @@ -0,0 +1,435 @@
52795 +#include <linux/kernel.h>
52796 +#include <linux/sched.h>
52797 +#include <linux/types.h>
52798 +#include <linux/fs.h>
52799 +#include <linux/file.h>
52800 +#include <linux/stat.h>
52801 +#include <linux/grsecurity.h>
52802 +#include <linux/grinternal.h>
52803 +#include <linux/gracl.h>
52804 +
52805 +umode_t
52806 +gr_acl_umask(void)
52807 +{
52808 + if (unlikely(!gr_acl_is_enabled()))
52809 + return 0;
52810 +
52811 + return current->role->umask;
52812 +}
52813 +
52814 +__u32
52815 +gr_acl_handle_hidden_file(const struct dentry * dentry,
52816 + const struct vfsmount * mnt)
52817 +{
52818 + __u32 mode;
52819 +
52820 + if (unlikely(!dentry->d_inode))
52821 + return GR_FIND;
52822 +
52823 + mode =
52824 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
52825 +
52826 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
52827 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
52828 + return mode;
52829 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
52830 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
52831 + return 0;
52832 + } else if (unlikely(!(mode & GR_FIND)))
52833 + return 0;
52834 +
52835 + return GR_FIND;
52836 +}
52837 +
52838 +__u32
52839 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
52840 + int acc_mode)
52841 +{
52842 + __u32 reqmode = GR_FIND;
52843 + __u32 mode;
52844 +
52845 + if (unlikely(!dentry->d_inode))
52846 + return reqmode;
52847 +
52848 + if (acc_mode & MAY_APPEND)
52849 + reqmode |= GR_APPEND;
52850 + else if (acc_mode & MAY_WRITE)
52851 + reqmode |= GR_WRITE;
52852 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
52853 + reqmode |= GR_READ;
52854 +
52855 + mode =
52856 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
52857 + mnt);
52858 +
52859 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52860 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
52861 + reqmode & GR_READ ? " reading" : "",
52862 + reqmode & GR_WRITE ? " writing" : reqmode &
52863 + GR_APPEND ? " appending" : "");
52864 + return reqmode;
52865 + } else
52866 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52867 + {
52868 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
52869 + reqmode & GR_READ ? " reading" : "",
52870 + reqmode & GR_WRITE ? " writing" : reqmode &
52871 + GR_APPEND ? " appending" : "");
52872 + return 0;
52873 + } else if (unlikely((mode & reqmode) != reqmode))
52874 + return 0;
52875 +
52876 + return reqmode;
52877 +}
52878 +
52879 +__u32
52880 +gr_acl_handle_creat(const struct dentry * dentry,
52881 + const struct dentry * p_dentry,
52882 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
52883 + const int imode)
52884 +{
52885 + __u32 reqmode = GR_WRITE | GR_CREATE;
52886 + __u32 mode;
52887 +
52888 + if (acc_mode & MAY_APPEND)
52889 + reqmode |= GR_APPEND;
52890 + // if a directory was required or the directory already exists, then
52891 + // don't count this open as a read
52892 + if ((acc_mode & MAY_READ) &&
52893 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
52894 + reqmode |= GR_READ;
52895 + if ((open_flags & O_CREAT) && (imode & (S_ISUID | S_ISGID)))
52896 + reqmode |= GR_SETID;
52897 +
52898 + mode =
52899 + gr_check_create(dentry, p_dentry, p_mnt,
52900 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
52901 +
52902 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52903 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
52904 + reqmode & GR_READ ? " reading" : "",
52905 + reqmode & GR_WRITE ? " writing" : reqmode &
52906 + GR_APPEND ? " appending" : "");
52907 + return reqmode;
52908 + } else
52909 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52910 + {
52911 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
52912 + reqmode & GR_READ ? " reading" : "",
52913 + reqmode & GR_WRITE ? " writing" : reqmode &
52914 + GR_APPEND ? " appending" : "");
52915 + return 0;
52916 + } else if (unlikely((mode & reqmode) != reqmode))
52917 + return 0;
52918 +
52919 + return reqmode;
52920 +}
52921 +
52922 +__u32
52923 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
52924 + const int fmode)
52925 +{
52926 + __u32 mode, reqmode = GR_FIND;
52927 +
52928 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
52929 + reqmode |= GR_EXEC;
52930 + if (fmode & S_IWOTH)
52931 + reqmode |= GR_WRITE;
52932 + if (fmode & S_IROTH)
52933 + reqmode |= GR_READ;
52934 +
52935 + mode =
52936 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
52937 + mnt);
52938 +
52939 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
52940 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
52941 + reqmode & GR_READ ? " reading" : "",
52942 + reqmode & GR_WRITE ? " writing" : "",
52943 + reqmode & GR_EXEC ? " executing" : "");
52944 + return reqmode;
52945 + } else
52946 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
52947 + {
52948 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
52949 + reqmode & GR_READ ? " reading" : "",
52950 + reqmode & GR_WRITE ? " writing" : "",
52951 + reqmode & GR_EXEC ? " executing" : "");
52952 + return 0;
52953 + } else if (unlikely((mode & reqmode) != reqmode))
52954 + return 0;
52955 +
52956 + return reqmode;
52957 +}
52958 +
52959 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
52960 +{
52961 + __u32 mode;
52962 +
52963 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
52964 +
52965 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
52966 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
52967 + return mode;
52968 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
52969 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
52970 + return 0;
52971 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
52972 + return 0;
52973 +
52974 + return (reqmode);
52975 +}
52976 +
52977 +__u32
52978 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
52979 +{
52980 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
52981 +}
52982 +
52983 +__u32
52984 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
52985 +{
52986 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
52987 +}
52988 +
52989 +__u32
52990 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
52991 +{
52992 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
52993 +}
52994 +
52995 +__u32
52996 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
52997 +{
52998 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
52999 +}
53000 +
53001 +__u32
53002 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
53003 + umode_t *modeptr)
53004 +{
53005 + umode_t mode;
53006 +
53007 + *modeptr &= ~gr_acl_umask();
53008 + mode = *modeptr;
53009 +
53010 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
53011 + return 1;
53012 +
53013 + if (unlikely(mode & (S_ISUID | S_ISGID))) {
53014 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
53015 + GR_CHMOD_ACL_MSG);
53016 + } else {
53017 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
53018 + }
53019 +}
53020 +
53021 +__u32
53022 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
53023 +{
53024 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
53025 +}
53026 +
53027 +__u32
53028 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
53029 +{
53030 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
53031 +}
53032 +
53033 +__u32
53034 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
53035 +{
53036 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
53037 +}
53038 +
53039 +__u32
53040 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
53041 +{
53042 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
53043 + GR_UNIXCONNECT_ACL_MSG);
53044 +}
53045 +
53046 +/* hardlinks require at minimum create and link permission,
53047 + any additional privilege required is based on the
53048 + privilege of the file being linked to
53049 +*/
53050 +__u32
53051 +gr_acl_handle_link(const struct dentry * new_dentry,
53052 + const struct dentry * parent_dentry,
53053 + const struct vfsmount * parent_mnt,
53054 + const struct dentry * old_dentry,
53055 + const struct vfsmount * old_mnt, const char *to)
53056 +{
53057 + __u32 mode;
53058 + __u32 needmode = GR_CREATE | GR_LINK;
53059 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
53060 +
53061 + mode =
53062 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
53063 + old_mnt);
53064 +
53065 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
53066 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
53067 + return mode;
53068 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
53069 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
53070 + return 0;
53071 + } else if (unlikely((mode & needmode) != needmode))
53072 + return 0;
53073 +
53074 + return 1;
53075 +}
53076 +
53077 +__u32
53078 +gr_acl_handle_symlink(const struct dentry * new_dentry,
53079 + const struct dentry * parent_dentry,
53080 + const struct vfsmount * parent_mnt, const char *from)
53081 +{
53082 + __u32 needmode = GR_WRITE | GR_CREATE;
53083 + __u32 mode;
53084 +
53085 + mode =
53086 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
53087 + GR_CREATE | GR_AUDIT_CREATE |
53088 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
53089 +
53090 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
53091 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
53092 + return mode;
53093 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
53094 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
53095 + return 0;
53096 + } else if (unlikely((mode & needmode) != needmode))
53097 + return 0;
53098 +
53099 + return (GR_WRITE | GR_CREATE);
53100 +}
53101 +
53102 +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)
53103 +{
53104 + __u32 mode;
53105 +
53106 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
53107 +
53108 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
53109 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
53110 + return mode;
53111 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
53112 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
53113 + return 0;
53114 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
53115 + return 0;
53116 +
53117 + return (reqmode);
53118 +}
53119 +
53120 +__u32
53121 +gr_acl_handle_mknod(const struct dentry * new_dentry,
53122 + const struct dentry * parent_dentry,
53123 + const struct vfsmount * parent_mnt,
53124 + const int mode)
53125 +{
53126 + __u32 reqmode = GR_WRITE | GR_CREATE;
53127 + if (unlikely(mode & (S_ISUID | S_ISGID)))
53128 + reqmode |= GR_SETID;
53129 +
53130 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
53131 + reqmode, GR_MKNOD_ACL_MSG);
53132 +}
53133 +
53134 +__u32
53135 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
53136 + const struct dentry *parent_dentry,
53137 + const struct vfsmount *parent_mnt)
53138 +{
53139 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
53140 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
53141 +}
53142 +
53143 +#define RENAME_CHECK_SUCCESS(old, new) \
53144 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
53145 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
53146 +
53147 +int
53148 +gr_acl_handle_rename(struct dentry *new_dentry,
53149 + struct dentry *parent_dentry,
53150 + const struct vfsmount *parent_mnt,
53151 + struct dentry *old_dentry,
53152 + struct inode *old_parent_inode,
53153 + struct vfsmount *old_mnt, const char *newname)
53154 +{
53155 + __u32 comp1, comp2;
53156 + int error = 0;
53157 +
53158 + if (unlikely(!gr_acl_is_enabled()))
53159 + return 0;
53160 +
53161 + if (!new_dentry->d_inode) {
53162 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
53163 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
53164 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
53165 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
53166 + GR_DELETE | GR_AUDIT_DELETE |
53167 + GR_AUDIT_READ | GR_AUDIT_WRITE |
53168 + GR_SUPPRESS, old_mnt);
53169 + } else {
53170 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
53171 + GR_CREATE | GR_DELETE |
53172 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
53173 + GR_AUDIT_READ | GR_AUDIT_WRITE |
53174 + GR_SUPPRESS, parent_mnt);
53175 + comp2 =
53176 + gr_search_file(old_dentry,
53177 + GR_READ | GR_WRITE | GR_AUDIT_READ |
53178 + GR_DELETE | GR_AUDIT_DELETE |
53179 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
53180 + }
53181 +
53182 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
53183 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
53184 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
53185 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
53186 + && !(comp2 & GR_SUPPRESS)) {
53187 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
53188 + error = -EACCES;
53189 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
53190 + error = -EACCES;
53191 +
53192 + return error;
53193 +}
53194 +
53195 +void
53196 +gr_acl_handle_exit(void)
53197 +{
53198 + u16 id;
53199 + char *rolename;
53200 + struct file *exec_file;
53201 +
53202 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
53203 + !(current->role->roletype & GR_ROLE_PERSIST))) {
53204 + id = current->acl_role_id;
53205 + rolename = current->role->rolename;
53206 + gr_set_acls(1);
53207 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
53208 + }
53209 +
53210 + write_lock(&grsec_exec_file_lock);
53211 + exec_file = current->exec_file;
53212 + current->exec_file = NULL;
53213 + write_unlock(&grsec_exec_file_lock);
53214 +
53215 + if (exec_file)
53216 + fput(exec_file);
53217 +}
53218 +
53219 +int
53220 +gr_acl_handle_procpidmem(const struct task_struct *task)
53221 +{
53222 + if (unlikely(!gr_acl_is_enabled()))
53223 + return 0;
53224 +
53225 + if (task != current && task->acl->mode & GR_PROTPROCFD)
53226 + return -EACCES;
53227 +
53228 + return 0;
53229 +}
53230 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
53231 new file mode 100644
53232 index 0000000..17050ca
53233 --- /dev/null
53234 +++ b/grsecurity/gracl_ip.c
53235 @@ -0,0 +1,381 @@
53236 +#include <linux/kernel.h>
53237 +#include <asm/uaccess.h>
53238 +#include <asm/errno.h>
53239 +#include <net/sock.h>
53240 +#include <linux/file.h>
53241 +#include <linux/fs.h>
53242 +#include <linux/net.h>
53243 +#include <linux/in.h>
53244 +#include <linux/skbuff.h>
53245 +#include <linux/ip.h>
53246 +#include <linux/udp.h>
53247 +#include <linux/types.h>
53248 +#include <linux/sched.h>
53249 +#include <linux/netdevice.h>
53250 +#include <linux/inetdevice.h>
53251 +#include <linux/gracl.h>
53252 +#include <linux/grsecurity.h>
53253 +#include <linux/grinternal.h>
53254 +
53255 +#define GR_BIND 0x01
53256 +#define GR_CONNECT 0x02
53257 +#define GR_INVERT 0x04
53258 +#define GR_BINDOVERRIDE 0x08
53259 +#define GR_CONNECTOVERRIDE 0x10
53260 +#define GR_SOCK_FAMILY 0x20
53261 +
53262 +static const char * gr_protocols[IPPROTO_MAX] = {
53263 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
53264 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
53265 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
53266 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
53267 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
53268 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
53269 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
53270 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
53271 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
53272 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
53273 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
53274 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
53275 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
53276 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
53277 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
53278 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
53279 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
53280 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
53281 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
53282 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
53283 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
53284 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
53285 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
53286 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
53287 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
53288 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
53289 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
53290 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
53291 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
53292 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
53293 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
53294 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
53295 + };
53296 +
53297 +static const char * gr_socktypes[SOCK_MAX] = {
53298 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
53299 + "unknown:7", "unknown:8", "unknown:9", "packet"
53300 + };
53301 +
53302 +static const char * gr_sockfamilies[AF_MAX+1] = {
53303 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
53304 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
53305 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
53306 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
53307 + };
53308 +
53309 +const char *
53310 +gr_proto_to_name(unsigned char proto)
53311 +{
53312 + return gr_protocols[proto];
53313 +}
53314 +
53315 +const char *
53316 +gr_socktype_to_name(unsigned char type)
53317 +{
53318 + return gr_socktypes[type];
53319 +}
53320 +
53321 +const char *
53322 +gr_sockfamily_to_name(unsigned char family)
53323 +{
53324 + return gr_sockfamilies[family];
53325 +}
53326 +
53327 +int
53328 +gr_search_socket(const int domain, const int type, const int protocol)
53329 +{
53330 + struct acl_subject_label *curr;
53331 + const struct cred *cred = current_cred();
53332 +
53333 + if (unlikely(!gr_acl_is_enabled()))
53334 + goto exit;
53335 +
53336 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
53337 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
53338 + goto exit; // let the kernel handle it
53339 +
53340 + curr = current->acl;
53341 +
53342 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
53343 + /* the family is allowed, if this is PF_INET allow it only if
53344 + the extra sock type/protocol checks pass */
53345 + if (domain == PF_INET)
53346 + goto inet_check;
53347 + goto exit;
53348 + } else {
53349 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53350 + __u32 fakeip = 0;
53351 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53352 + current->role->roletype, cred->uid,
53353 + cred->gid, current->exec_file ?
53354 + gr_to_filename(current->exec_file->f_path.dentry,
53355 + current->exec_file->f_path.mnt) :
53356 + curr->filename, curr->filename,
53357 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
53358 + &current->signal->saved_ip);
53359 + goto exit;
53360 + }
53361 + goto exit_fail;
53362 + }
53363 +
53364 +inet_check:
53365 + /* the rest of this checking is for IPv4 only */
53366 + if (!curr->ips)
53367 + goto exit;
53368 +
53369 + if ((curr->ip_type & (1 << type)) &&
53370 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
53371 + goto exit;
53372 +
53373 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53374 + /* we don't place acls on raw sockets , and sometimes
53375 + dgram/ip sockets are opened for ioctl and not
53376 + bind/connect, so we'll fake a bind learn log */
53377 + if (type == SOCK_RAW || type == SOCK_PACKET) {
53378 + __u32 fakeip = 0;
53379 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53380 + current->role->roletype, cred->uid,
53381 + cred->gid, current->exec_file ?
53382 + gr_to_filename(current->exec_file->f_path.dentry,
53383 + current->exec_file->f_path.mnt) :
53384 + curr->filename, curr->filename,
53385 + &fakeip, 0, type,
53386 + protocol, GR_CONNECT, &current->signal->saved_ip);
53387 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
53388 + __u32 fakeip = 0;
53389 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53390 + current->role->roletype, cred->uid,
53391 + cred->gid, current->exec_file ?
53392 + gr_to_filename(current->exec_file->f_path.dentry,
53393 + current->exec_file->f_path.mnt) :
53394 + curr->filename, curr->filename,
53395 + &fakeip, 0, type,
53396 + protocol, GR_BIND, &current->signal->saved_ip);
53397 + }
53398 + /* we'll log when they use connect or bind */
53399 + goto exit;
53400 + }
53401 +
53402 +exit_fail:
53403 + if (domain == PF_INET)
53404 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
53405 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
53406 + else
53407 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
53408 + gr_socktype_to_name(type), protocol);
53409 +
53410 + return 0;
53411 +exit:
53412 + return 1;
53413 +}
53414 +
53415 +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)
53416 +{
53417 + if ((ip->mode & mode) &&
53418 + (ip_port >= ip->low) &&
53419 + (ip_port <= ip->high) &&
53420 + ((ntohl(ip_addr) & our_netmask) ==
53421 + (ntohl(our_addr) & our_netmask))
53422 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
53423 + && (ip->type & (1 << type))) {
53424 + if (ip->mode & GR_INVERT)
53425 + return 2; // specifically denied
53426 + else
53427 + return 1; // allowed
53428 + }
53429 +
53430 + return 0; // not specifically allowed, may continue parsing
53431 +}
53432 +
53433 +static int
53434 +gr_search_connectbind(const int full_mode, struct sock *sk,
53435 + struct sockaddr_in *addr, const int type)
53436 +{
53437 + char iface[IFNAMSIZ] = {0};
53438 + struct acl_subject_label *curr;
53439 + struct acl_ip_label *ip;
53440 + struct inet_sock *isk;
53441 + struct net_device *dev;
53442 + struct in_device *idev;
53443 + unsigned long i;
53444 + int ret;
53445 + int mode = full_mode & (GR_BIND | GR_CONNECT);
53446 + __u32 ip_addr = 0;
53447 + __u32 our_addr;
53448 + __u32 our_netmask;
53449 + char *p;
53450 + __u16 ip_port = 0;
53451 + const struct cred *cred = current_cred();
53452 +
53453 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
53454 + return 0;
53455 +
53456 + curr = current->acl;
53457 + isk = inet_sk(sk);
53458 +
53459 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
53460 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
53461 + addr->sin_addr.s_addr = curr->inaddr_any_override;
53462 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
53463 + struct sockaddr_in saddr;
53464 + int err;
53465 +
53466 + saddr.sin_family = AF_INET;
53467 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
53468 + saddr.sin_port = isk->inet_sport;
53469 +
53470 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
53471 + if (err)
53472 + return err;
53473 +
53474 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
53475 + if (err)
53476 + return err;
53477 + }
53478 +
53479 + if (!curr->ips)
53480 + return 0;
53481 +
53482 + ip_addr = addr->sin_addr.s_addr;
53483 + ip_port = ntohs(addr->sin_port);
53484 +
53485 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
53486 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
53487 + current->role->roletype, cred->uid,
53488 + cred->gid, current->exec_file ?
53489 + gr_to_filename(current->exec_file->f_path.dentry,
53490 + current->exec_file->f_path.mnt) :
53491 + curr->filename, curr->filename,
53492 + &ip_addr, ip_port, type,
53493 + sk->sk_protocol, mode, &current->signal->saved_ip);
53494 + return 0;
53495 + }
53496 +
53497 + for (i = 0; i < curr->ip_num; i++) {
53498 + ip = *(curr->ips + i);
53499 + if (ip->iface != NULL) {
53500 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
53501 + p = strchr(iface, ':');
53502 + if (p != NULL)
53503 + *p = '\0';
53504 + dev = dev_get_by_name(sock_net(sk), iface);
53505 + if (dev == NULL)
53506 + continue;
53507 + idev = in_dev_get(dev);
53508 + if (idev == NULL) {
53509 + dev_put(dev);
53510 + continue;
53511 + }
53512 + rcu_read_lock();
53513 + for_ifa(idev) {
53514 + if (!strcmp(ip->iface, ifa->ifa_label)) {
53515 + our_addr = ifa->ifa_address;
53516 + our_netmask = 0xffffffff;
53517 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
53518 + if (ret == 1) {
53519 + rcu_read_unlock();
53520 + in_dev_put(idev);
53521 + dev_put(dev);
53522 + return 0;
53523 + } else if (ret == 2) {
53524 + rcu_read_unlock();
53525 + in_dev_put(idev);
53526 + dev_put(dev);
53527 + goto denied;
53528 + }
53529 + }
53530 + } endfor_ifa(idev);
53531 + rcu_read_unlock();
53532 + in_dev_put(idev);
53533 + dev_put(dev);
53534 + } else {
53535 + our_addr = ip->addr;
53536 + our_netmask = ip->netmask;
53537 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
53538 + if (ret == 1)
53539 + return 0;
53540 + else if (ret == 2)
53541 + goto denied;
53542 + }
53543 + }
53544 +
53545 +denied:
53546 + if (mode == GR_BIND)
53547 + 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));
53548 + else if (mode == GR_CONNECT)
53549 + 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));
53550 +
53551 + return -EACCES;
53552 +}
53553 +
53554 +int
53555 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
53556 +{
53557 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
53558 +}
53559 +
53560 +int
53561 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
53562 +{
53563 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
53564 +}
53565 +
53566 +int gr_search_listen(struct socket *sock)
53567 +{
53568 + struct sock *sk = sock->sk;
53569 + struct sockaddr_in addr;
53570 +
53571 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
53572 + addr.sin_port = inet_sk(sk)->inet_sport;
53573 +
53574 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
53575 +}
53576 +
53577 +int gr_search_accept(struct socket *sock)
53578 +{
53579 + struct sock *sk = sock->sk;
53580 + struct sockaddr_in addr;
53581 +
53582 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
53583 + addr.sin_port = inet_sk(sk)->inet_sport;
53584 +
53585 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
53586 +}
53587 +
53588 +int
53589 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
53590 +{
53591 + if (addr)
53592 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
53593 + else {
53594 + struct sockaddr_in sin;
53595 + const struct inet_sock *inet = inet_sk(sk);
53596 +
53597 + sin.sin_addr.s_addr = inet->inet_daddr;
53598 + sin.sin_port = inet->inet_dport;
53599 +
53600 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
53601 + }
53602 +}
53603 +
53604 +int
53605 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
53606 +{
53607 + struct sockaddr_in sin;
53608 +
53609 + if (unlikely(skb->len < sizeof (struct udphdr)))
53610 + return 0; // skip this packet
53611 +
53612 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
53613 + sin.sin_port = udp_hdr(skb)->source;
53614 +
53615 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
53616 +}
53617 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
53618 new file mode 100644
53619 index 0000000..25f54ef
53620 --- /dev/null
53621 +++ b/grsecurity/gracl_learn.c
53622 @@ -0,0 +1,207 @@
53623 +#include <linux/kernel.h>
53624 +#include <linux/mm.h>
53625 +#include <linux/sched.h>
53626 +#include <linux/poll.h>
53627 +#include <linux/string.h>
53628 +#include <linux/file.h>
53629 +#include <linux/types.h>
53630 +#include <linux/vmalloc.h>
53631 +#include <linux/grinternal.h>
53632 +
53633 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
53634 + size_t count, loff_t *ppos);
53635 +extern int gr_acl_is_enabled(void);
53636 +
53637 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
53638 +static int gr_learn_attached;
53639 +
53640 +/* use a 512k buffer */
53641 +#define LEARN_BUFFER_SIZE (512 * 1024)
53642 +
53643 +static DEFINE_SPINLOCK(gr_learn_lock);
53644 +static DEFINE_MUTEX(gr_learn_user_mutex);
53645 +
53646 +/* we need to maintain two buffers, so that the kernel context of grlearn
53647 + uses a semaphore around the userspace copying, and the other kernel contexts
53648 + use a spinlock when copying into the buffer, since they cannot sleep
53649 +*/
53650 +static char *learn_buffer;
53651 +static char *learn_buffer_user;
53652 +static int learn_buffer_len;
53653 +static int learn_buffer_user_len;
53654 +
53655 +static ssize_t
53656 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
53657 +{
53658 + DECLARE_WAITQUEUE(wait, current);
53659 + ssize_t retval = 0;
53660 +
53661 + add_wait_queue(&learn_wait, &wait);
53662 + set_current_state(TASK_INTERRUPTIBLE);
53663 + do {
53664 + mutex_lock(&gr_learn_user_mutex);
53665 + spin_lock(&gr_learn_lock);
53666 + if (learn_buffer_len)
53667 + break;
53668 + spin_unlock(&gr_learn_lock);
53669 + mutex_unlock(&gr_learn_user_mutex);
53670 + if (file->f_flags & O_NONBLOCK) {
53671 + retval = -EAGAIN;
53672 + goto out;
53673 + }
53674 + if (signal_pending(current)) {
53675 + retval = -ERESTARTSYS;
53676 + goto out;
53677 + }
53678 +
53679 + schedule();
53680 + } while (1);
53681 +
53682 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
53683 + learn_buffer_user_len = learn_buffer_len;
53684 + retval = learn_buffer_len;
53685 + learn_buffer_len = 0;
53686 +
53687 + spin_unlock(&gr_learn_lock);
53688 +
53689 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
53690 + retval = -EFAULT;
53691 +
53692 + mutex_unlock(&gr_learn_user_mutex);
53693 +out:
53694 + set_current_state(TASK_RUNNING);
53695 + remove_wait_queue(&learn_wait, &wait);
53696 + return retval;
53697 +}
53698 +
53699 +static unsigned int
53700 +poll_learn(struct file * file, poll_table * wait)
53701 +{
53702 + poll_wait(file, &learn_wait, wait);
53703 +
53704 + if (learn_buffer_len)
53705 + return (POLLIN | POLLRDNORM);
53706 +
53707 + return 0;
53708 +}
53709 +
53710 +void
53711 +gr_clear_learn_entries(void)
53712 +{
53713 + char *tmp;
53714 +
53715 + mutex_lock(&gr_learn_user_mutex);
53716 + spin_lock(&gr_learn_lock);
53717 + tmp = learn_buffer;
53718 + learn_buffer = NULL;
53719 + spin_unlock(&gr_learn_lock);
53720 + if (tmp)
53721 + vfree(tmp);
53722 + if (learn_buffer_user != NULL) {
53723 + vfree(learn_buffer_user);
53724 + learn_buffer_user = NULL;
53725 + }
53726 + learn_buffer_len = 0;
53727 + mutex_unlock(&gr_learn_user_mutex);
53728 +
53729 + return;
53730 +}
53731 +
53732 +void
53733 +gr_add_learn_entry(const char *fmt, ...)
53734 +{
53735 + va_list args;
53736 + unsigned int len;
53737 +
53738 + if (!gr_learn_attached)
53739 + return;
53740 +
53741 + spin_lock(&gr_learn_lock);
53742 +
53743 + /* leave a gap at the end so we know when it's "full" but don't have to
53744 + compute the exact length of the string we're trying to append
53745 + */
53746 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
53747 + spin_unlock(&gr_learn_lock);
53748 + wake_up_interruptible(&learn_wait);
53749 + return;
53750 + }
53751 + if (learn_buffer == NULL) {
53752 + spin_unlock(&gr_learn_lock);
53753 + return;
53754 + }
53755 +
53756 + va_start(args, fmt);
53757 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
53758 + va_end(args);
53759 +
53760 + learn_buffer_len += len + 1;
53761 +
53762 + spin_unlock(&gr_learn_lock);
53763 + wake_up_interruptible(&learn_wait);
53764 +
53765 + return;
53766 +}
53767 +
53768 +static int
53769 +open_learn(struct inode *inode, struct file *file)
53770 +{
53771 + if (file->f_mode & FMODE_READ && gr_learn_attached)
53772 + return -EBUSY;
53773 + if (file->f_mode & FMODE_READ) {
53774 + int retval = 0;
53775 + mutex_lock(&gr_learn_user_mutex);
53776 + if (learn_buffer == NULL)
53777 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
53778 + if (learn_buffer_user == NULL)
53779 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
53780 + if (learn_buffer == NULL) {
53781 + retval = -ENOMEM;
53782 + goto out_error;
53783 + }
53784 + if (learn_buffer_user == NULL) {
53785 + retval = -ENOMEM;
53786 + goto out_error;
53787 + }
53788 + learn_buffer_len = 0;
53789 + learn_buffer_user_len = 0;
53790 + gr_learn_attached = 1;
53791 +out_error:
53792 + mutex_unlock(&gr_learn_user_mutex);
53793 + return retval;
53794 + }
53795 + return 0;
53796 +}
53797 +
53798 +static int
53799 +close_learn(struct inode *inode, struct file *file)
53800 +{
53801 + if (file->f_mode & FMODE_READ) {
53802 + char *tmp = NULL;
53803 + mutex_lock(&gr_learn_user_mutex);
53804 + spin_lock(&gr_learn_lock);
53805 + tmp = learn_buffer;
53806 + learn_buffer = NULL;
53807 + spin_unlock(&gr_learn_lock);
53808 + if (tmp)
53809 + vfree(tmp);
53810 + if (learn_buffer_user != NULL) {
53811 + vfree(learn_buffer_user);
53812 + learn_buffer_user = NULL;
53813 + }
53814 + learn_buffer_len = 0;
53815 + learn_buffer_user_len = 0;
53816 + gr_learn_attached = 0;
53817 + mutex_unlock(&gr_learn_user_mutex);
53818 + }
53819 +
53820 + return 0;
53821 +}
53822 +
53823 +const struct file_operations grsec_fops = {
53824 + .read = read_learn,
53825 + .write = write_grsec_handler,
53826 + .open = open_learn,
53827 + .release = close_learn,
53828 + .poll = poll_learn,
53829 +};
53830 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
53831 new file mode 100644
53832 index 0000000..39645c9
53833 --- /dev/null
53834 +++ b/grsecurity/gracl_res.c
53835 @@ -0,0 +1,68 @@
53836 +#include <linux/kernel.h>
53837 +#include <linux/sched.h>
53838 +#include <linux/gracl.h>
53839 +#include <linux/grinternal.h>
53840 +
53841 +static const char *restab_log[] = {
53842 + [RLIMIT_CPU] = "RLIMIT_CPU",
53843 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
53844 + [RLIMIT_DATA] = "RLIMIT_DATA",
53845 + [RLIMIT_STACK] = "RLIMIT_STACK",
53846 + [RLIMIT_CORE] = "RLIMIT_CORE",
53847 + [RLIMIT_RSS] = "RLIMIT_RSS",
53848 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
53849 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
53850 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
53851 + [RLIMIT_AS] = "RLIMIT_AS",
53852 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
53853 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
53854 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
53855 + [RLIMIT_NICE] = "RLIMIT_NICE",
53856 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
53857 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
53858 + [GR_CRASH_RES] = "RLIMIT_CRASH"
53859 +};
53860 +
53861 +void
53862 +gr_log_resource(const struct task_struct *task,
53863 + const int res, const unsigned long wanted, const int gt)
53864 +{
53865 + const struct cred *cred;
53866 + unsigned long rlim;
53867 +
53868 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
53869 + return;
53870 +
53871 + // not yet supported resource
53872 + if (unlikely(!restab_log[res]))
53873 + return;
53874 +
53875 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
53876 + rlim = task_rlimit_max(task, res);
53877 + else
53878 + rlim = task_rlimit(task, res);
53879 +
53880 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
53881 + return;
53882 +
53883 + rcu_read_lock();
53884 + cred = __task_cred(task);
53885 +
53886 + if (res == RLIMIT_NPROC &&
53887 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
53888 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
53889 + goto out_rcu_unlock;
53890 + else if (res == RLIMIT_MEMLOCK &&
53891 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
53892 + goto out_rcu_unlock;
53893 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
53894 + goto out_rcu_unlock;
53895 + rcu_read_unlock();
53896 +
53897 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
53898 +
53899 + return;
53900 +out_rcu_unlock:
53901 + rcu_read_unlock();
53902 + return;
53903 +}
53904 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
53905 new file mode 100644
53906 index 0000000..5556be3
53907 --- /dev/null
53908 +++ b/grsecurity/gracl_segv.c
53909 @@ -0,0 +1,299 @@
53910 +#include <linux/kernel.h>
53911 +#include <linux/mm.h>
53912 +#include <asm/uaccess.h>
53913 +#include <asm/errno.h>
53914 +#include <asm/mman.h>
53915 +#include <net/sock.h>
53916 +#include <linux/file.h>
53917 +#include <linux/fs.h>
53918 +#include <linux/net.h>
53919 +#include <linux/in.h>
53920 +#include <linux/slab.h>
53921 +#include <linux/types.h>
53922 +#include <linux/sched.h>
53923 +#include <linux/timer.h>
53924 +#include <linux/gracl.h>
53925 +#include <linux/grsecurity.h>
53926 +#include <linux/grinternal.h>
53927 +
53928 +static struct crash_uid *uid_set;
53929 +static unsigned short uid_used;
53930 +static DEFINE_SPINLOCK(gr_uid_lock);
53931 +extern rwlock_t gr_inode_lock;
53932 +extern struct acl_subject_label *
53933 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
53934 + struct acl_role_label *role);
53935 +
53936 +#ifdef CONFIG_BTRFS_FS
53937 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53938 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53939 +#endif
53940 +
53941 +static inline dev_t __get_dev(const struct dentry *dentry)
53942 +{
53943 +#ifdef CONFIG_BTRFS_FS
53944 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53945 + return get_btrfs_dev_from_inode(dentry->d_inode);
53946 + else
53947 +#endif
53948 + return dentry->d_inode->i_sb->s_dev;
53949 +}
53950 +
53951 +int
53952 +gr_init_uidset(void)
53953 +{
53954 + uid_set =
53955 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
53956 + uid_used = 0;
53957 +
53958 + return uid_set ? 1 : 0;
53959 +}
53960 +
53961 +void
53962 +gr_free_uidset(void)
53963 +{
53964 + if (uid_set)
53965 + kfree(uid_set);
53966 +
53967 + return;
53968 +}
53969 +
53970 +int
53971 +gr_find_uid(const uid_t uid)
53972 +{
53973 + struct crash_uid *tmp = uid_set;
53974 + uid_t buid;
53975 + int low = 0, high = uid_used - 1, mid;
53976 +
53977 + while (high >= low) {
53978 + mid = (low + high) >> 1;
53979 + buid = tmp[mid].uid;
53980 + if (buid == uid)
53981 + return mid;
53982 + if (buid > uid)
53983 + high = mid - 1;
53984 + if (buid < uid)
53985 + low = mid + 1;
53986 + }
53987 +
53988 + return -1;
53989 +}
53990 +
53991 +static __inline__ void
53992 +gr_insertsort(void)
53993 +{
53994 + unsigned short i, j;
53995 + struct crash_uid index;
53996 +
53997 + for (i = 1; i < uid_used; i++) {
53998 + index = uid_set[i];
53999 + j = i;
54000 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
54001 + uid_set[j] = uid_set[j - 1];
54002 + j--;
54003 + }
54004 + uid_set[j] = index;
54005 + }
54006 +
54007 + return;
54008 +}
54009 +
54010 +static __inline__ void
54011 +gr_insert_uid(const uid_t uid, const unsigned long expires)
54012 +{
54013 + int loc;
54014 +
54015 + if (uid_used == GR_UIDTABLE_MAX)
54016 + return;
54017 +
54018 + loc = gr_find_uid(uid);
54019 +
54020 + if (loc >= 0) {
54021 + uid_set[loc].expires = expires;
54022 + return;
54023 + }
54024 +
54025 + uid_set[uid_used].uid = uid;
54026 + uid_set[uid_used].expires = expires;
54027 + uid_used++;
54028 +
54029 + gr_insertsort();
54030 +
54031 + return;
54032 +}
54033 +
54034 +void
54035 +gr_remove_uid(const unsigned short loc)
54036 +{
54037 + unsigned short i;
54038 +
54039 + for (i = loc + 1; i < uid_used; i++)
54040 + uid_set[i - 1] = uid_set[i];
54041 +
54042 + uid_used--;
54043 +
54044 + return;
54045 +}
54046 +
54047 +int
54048 +gr_check_crash_uid(const uid_t uid)
54049 +{
54050 + int loc;
54051 + int ret = 0;
54052 +
54053 + if (unlikely(!gr_acl_is_enabled()))
54054 + return 0;
54055 +
54056 + spin_lock(&gr_uid_lock);
54057 + loc = gr_find_uid(uid);
54058 +
54059 + if (loc < 0)
54060 + goto out_unlock;
54061 +
54062 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
54063 + gr_remove_uid(loc);
54064 + else
54065 + ret = 1;
54066 +
54067 +out_unlock:
54068 + spin_unlock(&gr_uid_lock);
54069 + return ret;
54070 +}
54071 +
54072 +static __inline__ int
54073 +proc_is_setxid(const struct cred *cred)
54074 +{
54075 + if (cred->uid != cred->euid || cred->uid != cred->suid ||
54076 + cred->uid != cred->fsuid)
54077 + return 1;
54078 + if (cred->gid != cred->egid || cred->gid != cred->sgid ||
54079 + cred->gid != cred->fsgid)
54080 + return 1;
54081 +
54082 + return 0;
54083 +}
54084 +
54085 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
54086 +
54087 +void
54088 +gr_handle_crash(struct task_struct *task, const int sig)
54089 +{
54090 + struct acl_subject_label *curr;
54091 + struct task_struct *tsk, *tsk2;
54092 + const struct cred *cred;
54093 + const struct cred *cred2;
54094 +
54095 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
54096 + return;
54097 +
54098 + if (unlikely(!gr_acl_is_enabled()))
54099 + return;
54100 +
54101 + curr = task->acl;
54102 +
54103 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
54104 + return;
54105 +
54106 + if (time_before_eq(curr->expires, get_seconds())) {
54107 + curr->expires = 0;
54108 + curr->crashes = 0;
54109 + }
54110 +
54111 + curr->crashes++;
54112 +
54113 + if (!curr->expires)
54114 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
54115 +
54116 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
54117 + time_after(curr->expires, get_seconds())) {
54118 + rcu_read_lock();
54119 + cred = __task_cred(task);
54120 + if (cred->uid && proc_is_setxid(cred)) {
54121 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
54122 + spin_lock(&gr_uid_lock);
54123 + gr_insert_uid(cred->uid, curr->expires);
54124 + spin_unlock(&gr_uid_lock);
54125 + curr->expires = 0;
54126 + curr->crashes = 0;
54127 + read_lock(&tasklist_lock);
54128 + do_each_thread(tsk2, tsk) {
54129 + cred2 = __task_cred(tsk);
54130 + if (tsk != task && cred2->uid == cred->uid)
54131 + gr_fake_force_sig(SIGKILL, tsk);
54132 + } while_each_thread(tsk2, tsk);
54133 + read_unlock(&tasklist_lock);
54134 + } else {
54135 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
54136 + read_lock(&tasklist_lock);
54137 + read_lock(&grsec_exec_file_lock);
54138 + do_each_thread(tsk2, tsk) {
54139 + if (likely(tsk != task)) {
54140 + // if this thread has the same subject as the one that triggered
54141 + // RES_CRASH and it's the same binary, kill it
54142 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
54143 + gr_fake_force_sig(SIGKILL, tsk);
54144 + }
54145 + } while_each_thread(tsk2, tsk);
54146 + read_unlock(&grsec_exec_file_lock);
54147 + read_unlock(&tasklist_lock);
54148 + }
54149 + rcu_read_unlock();
54150 + }
54151 +
54152 + return;
54153 +}
54154 +
54155 +int
54156 +gr_check_crash_exec(const struct file *filp)
54157 +{
54158 + struct acl_subject_label *curr;
54159 +
54160 + if (unlikely(!gr_acl_is_enabled()))
54161 + return 0;
54162 +
54163 + read_lock(&gr_inode_lock);
54164 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
54165 + __get_dev(filp->f_path.dentry),
54166 + current->role);
54167 + read_unlock(&gr_inode_lock);
54168 +
54169 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
54170 + (!curr->crashes && !curr->expires))
54171 + return 0;
54172 +
54173 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
54174 + time_after(curr->expires, get_seconds()))
54175 + return 1;
54176 + else if (time_before_eq(curr->expires, get_seconds())) {
54177 + curr->crashes = 0;
54178 + curr->expires = 0;
54179 + }
54180 +
54181 + return 0;
54182 +}
54183 +
54184 +void
54185 +gr_handle_alertkill(struct task_struct *task)
54186 +{
54187 + struct acl_subject_label *curracl;
54188 + __u32 curr_ip;
54189 + struct task_struct *p, *p2;
54190 +
54191 + if (unlikely(!gr_acl_is_enabled()))
54192 + return;
54193 +
54194 + curracl = task->acl;
54195 + curr_ip = task->signal->curr_ip;
54196 +
54197 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
54198 + read_lock(&tasklist_lock);
54199 + do_each_thread(p2, p) {
54200 + if (p->signal->curr_ip == curr_ip)
54201 + gr_fake_force_sig(SIGKILL, p);
54202 + } while_each_thread(p2, p);
54203 + read_unlock(&tasklist_lock);
54204 + } else if (curracl->mode & GR_KILLPROC)
54205 + gr_fake_force_sig(SIGKILL, task);
54206 +
54207 + return;
54208 +}
54209 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
54210 new file mode 100644
54211 index 0000000..9d83a69
54212 --- /dev/null
54213 +++ b/grsecurity/gracl_shm.c
54214 @@ -0,0 +1,40 @@
54215 +#include <linux/kernel.h>
54216 +#include <linux/mm.h>
54217 +#include <linux/sched.h>
54218 +#include <linux/file.h>
54219 +#include <linux/ipc.h>
54220 +#include <linux/gracl.h>
54221 +#include <linux/grsecurity.h>
54222 +#include <linux/grinternal.h>
54223 +
54224 +int
54225 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54226 + const time_t shm_createtime, const uid_t cuid, const int shmid)
54227 +{
54228 + struct task_struct *task;
54229 +
54230 + if (!gr_acl_is_enabled())
54231 + return 1;
54232 +
54233 + rcu_read_lock();
54234 + read_lock(&tasklist_lock);
54235 +
54236 + task = find_task_by_vpid(shm_cprid);
54237 +
54238 + if (unlikely(!task))
54239 + task = find_task_by_vpid(shm_lapid);
54240 +
54241 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
54242 + (task->pid == shm_lapid)) &&
54243 + (task->acl->mode & GR_PROTSHM) &&
54244 + (task->acl != current->acl))) {
54245 + read_unlock(&tasklist_lock);
54246 + rcu_read_unlock();
54247 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
54248 + return 0;
54249 + }
54250 + read_unlock(&tasklist_lock);
54251 + rcu_read_unlock();
54252 +
54253 + return 1;
54254 +}
54255 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
54256 new file mode 100644
54257 index 0000000..bc0be01
54258 --- /dev/null
54259 +++ b/grsecurity/grsec_chdir.c
54260 @@ -0,0 +1,19 @@
54261 +#include <linux/kernel.h>
54262 +#include <linux/sched.h>
54263 +#include <linux/fs.h>
54264 +#include <linux/file.h>
54265 +#include <linux/grsecurity.h>
54266 +#include <linux/grinternal.h>
54267 +
54268 +void
54269 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
54270 +{
54271 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
54272 + if ((grsec_enable_chdir && grsec_enable_group &&
54273 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
54274 + !grsec_enable_group)) {
54275 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
54276 + }
54277 +#endif
54278 + return;
54279 +}
54280 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
54281 new file mode 100644
54282 index 0000000..a2dc675
54283 --- /dev/null
54284 +++ b/grsecurity/grsec_chroot.c
54285 @@ -0,0 +1,351 @@
54286 +#include <linux/kernel.h>
54287 +#include <linux/module.h>
54288 +#include <linux/sched.h>
54289 +#include <linux/file.h>
54290 +#include <linux/fs.h>
54291 +#include <linux/mount.h>
54292 +#include <linux/types.h>
54293 +#include <linux/pid_namespace.h>
54294 +#include <linux/grsecurity.h>
54295 +#include <linux/grinternal.h>
54296 +
54297 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
54298 +{
54299 +#ifdef CONFIG_GRKERNSEC
54300 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
54301 + path->dentry != task->nsproxy->mnt_ns->root->mnt_root)
54302 + task->gr_is_chrooted = 1;
54303 + else
54304 + task->gr_is_chrooted = 0;
54305 +
54306 + task->gr_chroot_dentry = path->dentry;
54307 +#endif
54308 + return;
54309 +}
54310 +
54311 +void gr_clear_chroot_entries(struct task_struct *task)
54312 +{
54313 +#ifdef CONFIG_GRKERNSEC
54314 + task->gr_is_chrooted = 0;
54315 + task->gr_chroot_dentry = NULL;
54316 +#endif
54317 + return;
54318 +}
54319 +
54320 +int
54321 +gr_handle_chroot_unix(const pid_t pid)
54322 +{
54323 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
54324 + struct task_struct *p;
54325 +
54326 + if (unlikely(!grsec_enable_chroot_unix))
54327 + return 1;
54328 +
54329 + if (likely(!proc_is_chrooted(current)))
54330 + return 1;
54331 +
54332 + rcu_read_lock();
54333 + read_lock(&tasklist_lock);
54334 + p = find_task_by_vpid_unrestricted(pid);
54335 + if (unlikely(p && !have_same_root(current, p))) {
54336 + read_unlock(&tasklist_lock);
54337 + rcu_read_unlock();
54338 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
54339 + return 0;
54340 + }
54341 + read_unlock(&tasklist_lock);
54342 + rcu_read_unlock();
54343 +#endif
54344 + return 1;
54345 +}
54346 +
54347 +int
54348 +gr_handle_chroot_nice(void)
54349 +{
54350 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54351 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
54352 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
54353 + return -EPERM;
54354 + }
54355 +#endif
54356 + return 0;
54357 +}
54358 +
54359 +int
54360 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
54361 +{
54362 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
54363 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
54364 + && proc_is_chrooted(current)) {
54365 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
54366 + return -EACCES;
54367 + }
54368 +#endif
54369 + return 0;
54370 +}
54371 +
54372 +int
54373 +gr_handle_chroot_rawio(const struct inode *inode)
54374 +{
54375 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54376 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54377 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
54378 + return 1;
54379 +#endif
54380 + return 0;
54381 +}
54382 +
54383 +int
54384 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
54385 +{
54386 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54387 + struct task_struct *p;
54388 + int ret = 0;
54389 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
54390 + return ret;
54391 +
54392 + read_lock(&tasklist_lock);
54393 + do_each_pid_task(pid, type, p) {
54394 + if (!have_same_root(current, p)) {
54395 + ret = 1;
54396 + goto out;
54397 + }
54398 + } while_each_pid_task(pid, type, p);
54399 +out:
54400 + read_unlock(&tasklist_lock);
54401 + return ret;
54402 +#endif
54403 + return 0;
54404 +}
54405 +
54406 +int
54407 +gr_pid_is_chrooted(struct task_struct *p)
54408 +{
54409 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
54410 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
54411 + return 0;
54412 +
54413 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
54414 + !have_same_root(current, p)) {
54415 + return 1;
54416 + }
54417 +#endif
54418 + return 0;
54419 +}
54420 +
54421 +EXPORT_SYMBOL(gr_pid_is_chrooted);
54422 +
54423 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
54424 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
54425 +{
54426 + struct path path, currentroot;
54427 + int ret = 0;
54428 +
54429 + path.dentry = (struct dentry *)u_dentry;
54430 + path.mnt = (struct vfsmount *)u_mnt;
54431 + get_fs_root(current->fs, &currentroot);
54432 + if (path_is_under(&path, &currentroot))
54433 + ret = 1;
54434 + path_put(&currentroot);
54435 +
54436 + return ret;
54437 +}
54438 +#endif
54439 +
54440 +int
54441 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
54442 +{
54443 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
54444 + if (!grsec_enable_chroot_fchdir)
54445 + return 1;
54446 +
54447 + if (!proc_is_chrooted(current))
54448 + return 1;
54449 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
54450 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
54451 + return 0;
54452 + }
54453 +#endif
54454 + return 1;
54455 +}
54456 +
54457 +int
54458 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54459 + const time_t shm_createtime)
54460 +{
54461 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
54462 + struct task_struct *p;
54463 + time_t starttime;
54464 +
54465 + if (unlikely(!grsec_enable_chroot_shmat))
54466 + return 1;
54467 +
54468 + if (likely(!proc_is_chrooted(current)))
54469 + return 1;
54470 +
54471 + rcu_read_lock();
54472 + read_lock(&tasklist_lock);
54473 +
54474 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
54475 + starttime = p->start_time.tv_sec;
54476 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
54477 + if (have_same_root(current, p)) {
54478 + goto allow;
54479 + } else {
54480 + read_unlock(&tasklist_lock);
54481 + rcu_read_unlock();
54482 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
54483 + return 0;
54484 + }
54485 + }
54486 + /* creator exited, pid reuse, fall through to next check */
54487 + }
54488 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
54489 + if (unlikely(!have_same_root(current, p))) {
54490 + read_unlock(&tasklist_lock);
54491 + rcu_read_unlock();
54492 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
54493 + return 0;
54494 + }
54495 + }
54496 +
54497 +allow:
54498 + read_unlock(&tasklist_lock);
54499 + rcu_read_unlock();
54500 +#endif
54501 + return 1;
54502 +}
54503 +
54504 +void
54505 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
54506 +{
54507 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
54508 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
54509 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
54510 +#endif
54511 + return;
54512 +}
54513 +
54514 +int
54515 +gr_handle_chroot_mknod(const struct dentry *dentry,
54516 + const struct vfsmount *mnt, const int mode)
54517 +{
54518 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
54519 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
54520 + proc_is_chrooted(current)) {
54521 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
54522 + return -EPERM;
54523 + }
54524 +#endif
54525 + return 0;
54526 +}
54527 +
54528 +int
54529 +gr_handle_chroot_mount(const struct dentry *dentry,
54530 + const struct vfsmount *mnt, const char *dev_name)
54531 +{
54532 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
54533 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
54534 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
54535 + return -EPERM;
54536 + }
54537 +#endif
54538 + return 0;
54539 +}
54540 +
54541 +int
54542 +gr_handle_chroot_pivot(void)
54543 +{
54544 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
54545 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
54546 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
54547 + return -EPERM;
54548 + }
54549 +#endif
54550 + return 0;
54551 +}
54552 +
54553 +int
54554 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
54555 +{
54556 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
54557 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
54558 + !gr_is_outside_chroot(dentry, mnt)) {
54559 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
54560 + return -EPERM;
54561 + }
54562 +#endif
54563 + return 0;
54564 +}
54565 +
54566 +extern const char *captab_log[];
54567 +extern int captab_log_entries;
54568 +
54569 +int
54570 +gr_chroot_is_capable(const int cap)
54571 +{
54572 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54573 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
54574 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
54575 + if (cap_raised(chroot_caps, cap)) {
54576 + const struct cred *creds = current_cred();
54577 + if (cap_raised(creds->cap_effective, cap) && cap < captab_log_entries) {
54578 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, current, captab_log[cap]);
54579 + }
54580 + return 0;
54581 + }
54582 + }
54583 +#endif
54584 + return 1;
54585 +}
54586 +
54587 +int
54588 +gr_chroot_is_capable_nolog(const int cap)
54589 +{
54590 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54591 + if (grsec_enable_chroot_caps && proc_is_chrooted(current)) {
54592 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
54593 + if (cap_raised(chroot_caps, cap)) {
54594 + return 0;
54595 + }
54596 + }
54597 +#endif
54598 + return 1;
54599 +}
54600 +
54601 +int
54602 +gr_handle_chroot_sysctl(const int op)
54603 +{
54604 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
54605 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
54606 + proc_is_chrooted(current))
54607 + return -EACCES;
54608 +#endif
54609 + return 0;
54610 +}
54611 +
54612 +void
54613 +gr_handle_chroot_chdir(struct path *path)
54614 +{
54615 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
54616 + if (grsec_enable_chroot_chdir)
54617 + set_fs_pwd(current->fs, path);
54618 +#endif
54619 + return;
54620 +}
54621 +
54622 +int
54623 +gr_handle_chroot_chmod(const struct dentry *dentry,
54624 + const struct vfsmount *mnt, const int mode)
54625 +{
54626 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
54627 + /* allow chmod +s on directories, but not files */
54628 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
54629 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
54630 + proc_is_chrooted(current)) {
54631 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
54632 + return -EPERM;
54633 + }
54634 +#endif
54635 + return 0;
54636 +}
54637 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
54638 new file mode 100644
54639 index 0000000..213ad8b
54640 --- /dev/null
54641 +++ b/grsecurity/grsec_disabled.c
54642 @@ -0,0 +1,437 @@
54643 +#include <linux/kernel.h>
54644 +#include <linux/module.h>
54645 +#include <linux/sched.h>
54646 +#include <linux/file.h>
54647 +#include <linux/fs.h>
54648 +#include <linux/kdev_t.h>
54649 +#include <linux/net.h>
54650 +#include <linux/in.h>
54651 +#include <linux/ip.h>
54652 +#include <linux/skbuff.h>
54653 +#include <linux/sysctl.h>
54654 +
54655 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54656 +void
54657 +pax_set_initial_flags(struct linux_binprm *bprm)
54658 +{
54659 + return;
54660 +}
54661 +#endif
54662 +
54663 +#ifdef CONFIG_SYSCTL
54664 +__u32
54665 +gr_handle_sysctl(const struct ctl_table * table, const int op)
54666 +{
54667 + return 0;
54668 +}
54669 +#endif
54670 +
54671 +#ifdef CONFIG_TASKSTATS
54672 +int gr_is_taskstats_denied(int pid)
54673 +{
54674 + return 0;
54675 +}
54676 +#endif
54677 +
54678 +int
54679 +gr_acl_is_enabled(void)
54680 +{
54681 + return 0;
54682 +}
54683 +
54684 +void
54685 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54686 +{
54687 + return;
54688 +}
54689 +
54690 +int
54691 +gr_handle_rawio(const struct inode *inode)
54692 +{
54693 + return 0;
54694 +}
54695 +
54696 +void
54697 +gr_acl_handle_psacct(struct task_struct *task, const long code)
54698 +{
54699 + return;
54700 +}
54701 +
54702 +int
54703 +gr_handle_ptrace(struct task_struct *task, const long request)
54704 +{
54705 + return 0;
54706 +}
54707 +
54708 +int
54709 +gr_handle_proc_ptrace(struct task_struct *task)
54710 +{
54711 + return 0;
54712 +}
54713 +
54714 +void
54715 +gr_learn_resource(const struct task_struct *task,
54716 + const int res, const unsigned long wanted, const int gt)
54717 +{
54718 + return;
54719 +}
54720 +
54721 +int
54722 +gr_set_acls(const int type)
54723 +{
54724 + return 0;
54725 +}
54726 +
54727 +int
54728 +gr_check_hidden_task(const struct task_struct *tsk)
54729 +{
54730 + return 0;
54731 +}
54732 +
54733 +int
54734 +gr_check_protected_task(const struct task_struct *task)
54735 +{
54736 + return 0;
54737 +}
54738 +
54739 +int
54740 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54741 +{
54742 + return 0;
54743 +}
54744 +
54745 +void
54746 +gr_copy_label(struct task_struct *tsk)
54747 +{
54748 + return;
54749 +}
54750 +
54751 +void
54752 +gr_set_pax_flags(struct task_struct *task)
54753 +{
54754 + return;
54755 +}
54756 +
54757 +int
54758 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54759 + const int unsafe_share)
54760 +{
54761 + return 0;
54762 +}
54763 +
54764 +void
54765 +gr_handle_delete(const ino_t ino, const dev_t dev)
54766 +{
54767 + return;
54768 +}
54769 +
54770 +void
54771 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54772 +{
54773 + return;
54774 +}
54775 +
54776 +void
54777 +gr_handle_crash(struct task_struct *task, const int sig)
54778 +{
54779 + return;
54780 +}
54781 +
54782 +int
54783 +gr_check_crash_exec(const struct file *filp)
54784 +{
54785 + return 0;
54786 +}
54787 +
54788 +int
54789 +gr_check_crash_uid(const uid_t uid)
54790 +{
54791 + return 0;
54792 +}
54793 +
54794 +void
54795 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54796 + struct dentry *old_dentry,
54797 + struct dentry *new_dentry,
54798 + struct vfsmount *mnt, const __u8 replace)
54799 +{
54800 + return;
54801 +}
54802 +
54803 +int
54804 +gr_search_socket(const int family, const int type, const int protocol)
54805 +{
54806 + return 1;
54807 +}
54808 +
54809 +int
54810 +gr_search_connectbind(const int mode, const struct socket *sock,
54811 + const struct sockaddr_in *addr)
54812 +{
54813 + return 0;
54814 +}
54815 +
54816 +void
54817 +gr_handle_alertkill(struct task_struct *task)
54818 +{
54819 + return;
54820 +}
54821 +
54822 +__u32
54823 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
54824 +{
54825 + return 1;
54826 +}
54827 +
54828 +__u32
54829 +gr_acl_handle_hidden_file(const struct dentry * dentry,
54830 + const struct vfsmount * mnt)
54831 +{
54832 + return 1;
54833 +}
54834 +
54835 +__u32
54836 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
54837 + int acc_mode)
54838 +{
54839 + return 1;
54840 +}
54841 +
54842 +__u32
54843 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
54844 +{
54845 + return 1;
54846 +}
54847 +
54848 +__u32
54849 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
54850 +{
54851 + return 1;
54852 +}
54853 +
54854 +int
54855 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
54856 + unsigned int *vm_flags)
54857 +{
54858 + return 1;
54859 +}
54860 +
54861 +__u32
54862 +gr_acl_handle_truncate(const struct dentry * dentry,
54863 + const struct vfsmount * mnt)
54864 +{
54865 + return 1;
54866 +}
54867 +
54868 +__u32
54869 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
54870 +{
54871 + return 1;
54872 +}
54873 +
54874 +__u32
54875 +gr_acl_handle_access(const struct dentry * dentry,
54876 + const struct vfsmount * mnt, const int fmode)
54877 +{
54878 + return 1;
54879 +}
54880 +
54881 +__u32
54882 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
54883 + umode_t *mode)
54884 +{
54885 + return 1;
54886 +}
54887 +
54888 +__u32
54889 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
54890 +{
54891 + return 1;
54892 +}
54893 +
54894 +__u32
54895 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
54896 +{
54897 + return 1;
54898 +}
54899 +
54900 +void
54901 +grsecurity_init(void)
54902 +{
54903 + return;
54904 +}
54905 +
54906 +umode_t gr_acl_umask(void)
54907 +{
54908 + return 0;
54909 +}
54910 +
54911 +__u32
54912 +gr_acl_handle_mknod(const struct dentry * new_dentry,
54913 + const struct dentry * parent_dentry,
54914 + const struct vfsmount * parent_mnt,
54915 + const int mode)
54916 +{
54917 + return 1;
54918 +}
54919 +
54920 +__u32
54921 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
54922 + const struct dentry * parent_dentry,
54923 + const struct vfsmount * parent_mnt)
54924 +{
54925 + return 1;
54926 +}
54927 +
54928 +__u32
54929 +gr_acl_handle_symlink(const struct dentry * new_dentry,
54930 + const struct dentry * parent_dentry,
54931 + const struct vfsmount * parent_mnt, const char *from)
54932 +{
54933 + return 1;
54934 +}
54935 +
54936 +__u32
54937 +gr_acl_handle_link(const struct dentry * new_dentry,
54938 + const struct dentry * parent_dentry,
54939 + const struct vfsmount * parent_mnt,
54940 + const struct dentry * old_dentry,
54941 + const struct vfsmount * old_mnt, const char *to)
54942 +{
54943 + return 1;
54944 +}
54945 +
54946 +int
54947 +gr_acl_handle_rename(const struct dentry *new_dentry,
54948 + const struct dentry *parent_dentry,
54949 + const struct vfsmount *parent_mnt,
54950 + const struct dentry *old_dentry,
54951 + const struct inode *old_parent_inode,
54952 + const struct vfsmount *old_mnt, const char *newname)
54953 +{
54954 + return 0;
54955 +}
54956 +
54957 +int
54958 +gr_acl_handle_filldir(const struct file *file, const char *name,
54959 + const int namelen, const ino_t ino)
54960 +{
54961 + return 1;
54962 +}
54963 +
54964 +int
54965 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
54966 + const time_t shm_createtime, const uid_t cuid, const int shmid)
54967 +{
54968 + return 1;
54969 +}
54970 +
54971 +int
54972 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
54973 +{
54974 + return 0;
54975 +}
54976 +
54977 +int
54978 +gr_search_accept(const struct socket *sock)
54979 +{
54980 + return 0;
54981 +}
54982 +
54983 +int
54984 +gr_search_listen(const struct socket *sock)
54985 +{
54986 + return 0;
54987 +}
54988 +
54989 +int
54990 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
54991 +{
54992 + return 0;
54993 +}
54994 +
54995 +__u32
54996 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
54997 +{
54998 + return 1;
54999 +}
55000 +
55001 +__u32
55002 +gr_acl_handle_creat(const struct dentry * dentry,
55003 + const struct dentry * p_dentry,
55004 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55005 + const int imode)
55006 +{
55007 + return 1;
55008 +}
55009 +
55010 +void
55011 +gr_acl_handle_exit(void)
55012 +{
55013 + return;
55014 +}
55015 +
55016 +int
55017 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55018 +{
55019 + return 1;
55020 +}
55021 +
55022 +void
55023 +gr_set_role_label(const uid_t uid, const gid_t gid)
55024 +{
55025 + return;
55026 +}
55027 +
55028 +int
55029 +gr_acl_handle_procpidmem(const struct task_struct *task)
55030 +{
55031 + return 0;
55032 +}
55033 +
55034 +int
55035 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
55036 +{
55037 + return 0;
55038 +}
55039 +
55040 +int
55041 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
55042 +{
55043 + return 0;
55044 +}
55045 +
55046 +void
55047 +gr_set_kernel_label(struct task_struct *task)
55048 +{
55049 + return;
55050 +}
55051 +
55052 +int
55053 +gr_check_user_change(int real, int effective, int fs)
55054 +{
55055 + return 0;
55056 +}
55057 +
55058 +int
55059 +gr_check_group_change(int real, int effective, int fs)
55060 +{
55061 + return 0;
55062 +}
55063 +
55064 +int gr_acl_enable_at_secure(void)
55065 +{
55066 + return 0;
55067 +}
55068 +
55069 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
55070 +{
55071 + return dentry->d_inode->i_sb->s_dev;
55072 +}
55073 +
55074 +EXPORT_SYMBOL(gr_learn_resource);
55075 +EXPORT_SYMBOL(gr_set_kernel_label);
55076 +#ifdef CONFIG_SECURITY
55077 +EXPORT_SYMBOL(gr_check_user_change);
55078 +EXPORT_SYMBOL(gr_check_group_change);
55079 +#endif
55080 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
55081 new file mode 100644
55082 index 0000000..2b05ada
55083 --- /dev/null
55084 +++ b/grsecurity/grsec_exec.c
55085 @@ -0,0 +1,146 @@
55086 +#include <linux/kernel.h>
55087 +#include <linux/sched.h>
55088 +#include <linux/file.h>
55089 +#include <linux/binfmts.h>
55090 +#include <linux/fs.h>
55091 +#include <linux/types.h>
55092 +#include <linux/grdefs.h>
55093 +#include <linux/grsecurity.h>
55094 +#include <linux/grinternal.h>
55095 +#include <linux/capability.h>
55096 +#include <linux/module.h>
55097 +
55098 +#include <asm/uaccess.h>
55099 +
55100 +#ifdef CONFIG_GRKERNSEC_EXECLOG
55101 +static char gr_exec_arg_buf[132];
55102 +static DEFINE_MUTEX(gr_exec_arg_mutex);
55103 +#endif
55104 +
55105 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
55106 +
55107 +void
55108 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
55109 +{
55110 +#ifdef CONFIG_GRKERNSEC_EXECLOG
55111 + char *grarg = gr_exec_arg_buf;
55112 + unsigned int i, x, execlen = 0;
55113 + char c;
55114 +
55115 + if (!((grsec_enable_execlog && grsec_enable_group &&
55116 + in_group_p(grsec_audit_gid))
55117 + || (grsec_enable_execlog && !grsec_enable_group)))
55118 + return;
55119 +
55120 + mutex_lock(&gr_exec_arg_mutex);
55121 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
55122 +
55123 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
55124 + const char __user *p;
55125 + unsigned int len;
55126 +
55127 + p = get_user_arg_ptr(argv, i);
55128 + if (IS_ERR(p))
55129 + goto log;
55130 +
55131 + len = strnlen_user(p, 128 - execlen);
55132 + if (len > 128 - execlen)
55133 + len = 128 - execlen;
55134 + else if (len > 0)
55135 + len--;
55136 + if (copy_from_user(grarg + execlen, p, len))
55137 + goto log;
55138 +
55139 + /* rewrite unprintable characters */
55140 + for (x = 0; x < len; x++) {
55141 + c = *(grarg + execlen + x);
55142 + if (c < 32 || c > 126)
55143 + *(grarg + execlen + x) = ' ';
55144 + }
55145 +
55146 + execlen += len;
55147 + *(grarg + execlen) = ' ';
55148 + *(grarg + execlen + 1) = '\0';
55149 + execlen++;
55150 + }
55151 +
55152 + log:
55153 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
55154 + bprm->file->f_path.mnt, grarg);
55155 + mutex_unlock(&gr_exec_arg_mutex);
55156 +#endif
55157 + return;
55158 +}
55159 +
55160 +#ifdef CONFIG_GRKERNSEC
55161 +extern int gr_acl_is_capable(const int cap);
55162 +extern int gr_acl_is_capable_nolog(const int cap);
55163 +extern int gr_chroot_is_capable(const int cap);
55164 +extern int gr_chroot_is_capable_nolog(const int cap);
55165 +#endif
55166 +
55167 +const char *captab_log[] = {
55168 + "CAP_CHOWN",
55169 + "CAP_DAC_OVERRIDE",
55170 + "CAP_DAC_READ_SEARCH",
55171 + "CAP_FOWNER",
55172 + "CAP_FSETID",
55173 + "CAP_KILL",
55174 + "CAP_SETGID",
55175 + "CAP_SETUID",
55176 + "CAP_SETPCAP",
55177 + "CAP_LINUX_IMMUTABLE",
55178 + "CAP_NET_BIND_SERVICE",
55179 + "CAP_NET_BROADCAST",
55180 + "CAP_NET_ADMIN",
55181 + "CAP_NET_RAW",
55182 + "CAP_IPC_LOCK",
55183 + "CAP_IPC_OWNER",
55184 + "CAP_SYS_MODULE",
55185 + "CAP_SYS_RAWIO",
55186 + "CAP_SYS_CHROOT",
55187 + "CAP_SYS_PTRACE",
55188 + "CAP_SYS_PACCT",
55189 + "CAP_SYS_ADMIN",
55190 + "CAP_SYS_BOOT",
55191 + "CAP_SYS_NICE",
55192 + "CAP_SYS_RESOURCE",
55193 + "CAP_SYS_TIME",
55194 + "CAP_SYS_TTY_CONFIG",
55195 + "CAP_MKNOD",
55196 + "CAP_LEASE",
55197 + "CAP_AUDIT_WRITE",
55198 + "CAP_AUDIT_CONTROL",
55199 + "CAP_SETFCAP",
55200 + "CAP_MAC_OVERRIDE",
55201 + "CAP_MAC_ADMIN",
55202 + "CAP_SYSLOG",
55203 + "CAP_WAKE_ALARM"
55204 +};
55205 +
55206 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
55207 +
55208 +int gr_is_capable(const int cap)
55209 +{
55210 +#ifdef CONFIG_GRKERNSEC
55211 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
55212 + return 1;
55213 + return 0;
55214 +#else
55215 + return 1;
55216 +#endif
55217 +}
55218 +
55219 +int gr_is_capable_nolog(const int cap)
55220 +{
55221 +#ifdef CONFIG_GRKERNSEC
55222 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
55223 + return 1;
55224 + return 0;
55225 +#else
55226 + return 1;
55227 +#endif
55228 +}
55229 +
55230 +EXPORT_SYMBOL(gr_is_capable);
55231 +EXPORT_SYMBOL(gr_is_capable_nolog);
55232 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
55233 new file mode 100644
55234 index 0000000..d3ee748
55235 --- /dev/null
55236 +++ b/grsecurity/grsec_fifo.c
55237 @@ -0,0 +1,24 @@
55238 +#include <linux/kernel.h>
55239 +#include <linux/sched.h>
55240 +#include <linux/fs.h>
55241 +#include <linux/file.h>
55242 +#include <linux/grinternal.h>
55243 +
55244 +int
55245 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
55246 + const struct dentry *dir, const int flag, const int acc_mode)
55247 +{
55248 +#ifdef CONFIG_GRKERNSEC_FIFO
55249 + const struct cred *cred = current_cred();
55250 +
55251 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
55252 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
55253 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
55254 + (cred->fsuid != dentry->d_inode->i_uid)) {
55255 + if (!inode_permission(dentry->d_inode, acc_mode))
55256 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
55257 + return -EACCES;
55258 + }
55259 +#endif
55260 + return 0;
55261 +}
55262 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
55263 new file mode 100644
55264 index 0000000..8ca18bf
55265 --- /dev/null
55266 +++ b/grsecurity/grsec_fork.c
55267 @@ -0,0 +1,23 @@
55268 +#include <linux/kernel.h>
55269 +#include <linux/sched.h>
55270 +#include <linux/grsecurity.h>
55271 +#include <linux/grinternal.h>
55272 +#include <linux/errno.h>
55273 +
55274 +void
55275 +gr_log_forkfail(const int retval)
55276 +{
55277 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
55278 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
55279 + switch (retval) {
55280 + case -EAGAIN:
55281 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
55282 + break;
55283 + case -ENOMEM:
55284 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
55285 + break;
55286 + }
55287 + }
55288 +#endif
55289 + return;
55290 +}
55291 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
55292 new file mode 100644
55293 index 0000000..01ddde4
55294 --- /dev/null
55295 +++ b/grsecurity/grsec_init.c
55296 @@ -0,0 +1,277 @@
55297 +#include <linux/kernel.h>
55298 +#include <linux/sched.h>
55299 +#include <linux/mm.h>
55300 +#include <linux/gracl.h>
55301 +#include <linux/slab.h>
55302 +#include <linux/vmalloc.h>
55303 +#include <linux/percpu.h>
55304 +#include <linux/module.h>
55305 +
55306 +int grsec_enable_ptrace_readexec;
55307 +int grsec_enable_setxid;
55308 +int grsec_enable_brute;
55309 +int grsec_enable_link;
55310 +int grsec_enable_dmesg;
55311 +int grsec_enable_harden_ptrace;
55312 +int grsec_enable_fifo;
55313 +int grsec_enable_execlog;
55314 +int grsec_enable_signal;
55315 +int grsec_enable_forkfail;
55316 +int grsec_enable_audit_ptrace;
55317 +int grsec_enable_time;
55318 +int grsec_enable_audit_textrel;
55319 +int grsec_enable_group;
55320 +int grsec_audit_gid;
55321 +int grsec_enable_chdir;
55322 +int grsec_enable_mount;
55323 +int grsec_enable_rofs;
55324 +int grsec_enable_chroot_findtask;
55325 +int grsec_enable_chroot_mount;
55326 +int grsec_enable_chroot_shmat;
55327 +int grsec_enable_chroot_fchdir;
55328 +int grsec_enable_chroot_double;
55329 +int grsec_enable_chroot_pivot;
55330 +int grsec_enable_chroot_chdir;
55331 +int grsec_enable_chroot_chmod;
55332 +int grsec_enable_chroot_mknod;
55333 +int grsec_enable_chroot_nice;
55334 +int grsec_enable_chroot_execlog;
55335 +int grsec_enable_chroot_caps;
55336 +int grsec_enable_chroot_sysctl;
55337 +int grsec_enable_chroot_unix;
55338 +int grsec_enable_tpe;
55339 +int grsec_tpe_gid;
55340 +int grsec_enable_blackhole;
55341 +#ifdef CONFIG_IPV6_MODULE
55342 +EXPORT_SYMBOL(grsec_enable_blackhole);
55343 +#endif
55344 +int grsec_lastack_retries;
55345 +int grsec_enable_tpe_all;
55346 +int grsec_enable_tpe_invert;
55347 +int grsec_enable_socket_all;
55348 +int grsec_socket_all_gid;
55349 +int grsec_enable_socket_client;
55350 +int grsec_socket_client_gid;
55351 +int grsec_enable_socket_server;
55352 +int grsec_socket_server_gid;
55353 +int grsec_resource_logging;
55354 +int grsec_disable_privio;
55355 +int grsec_enable_log_rwxmaps;
55356 +int grsec_lock;
55357 +
55358 +DEFINE_SPINLOCK(grsec_alert_lock);
55359 +unsigned long grsec_alert_wtime = 0;
55360 +unsigned long grsec_alert_fyet = 0;
55361 +
55362 +DEFINE_SPINLOCK(grsec_audit_lock);
55363 +
55364 +DEFINE_RWLOCK(grsec_exec_file_lock);
55365 +
55366 +char *gr_shared_page[4];
55367 +
55368 +char *gr_alert_log_fmt;
55369 +char *gr_audit_log_fmt;
55370 +char *gr_alert_log_buf;
55371 +char *gr_audit_log_buf;
55372 +
55373 +extern struct gr_arg *gr_usermode;
55374 +extern unsigned char *gr_system_salt;
55375 +extern unsigned char *gr_system_sum;
55376 +
55377 +void __init
55378 +grsecurity_init(void)
55379 +{
55380 + int j;
55381 + /* create the per-cpu shared pages */
55382 +
55383 +#ifdef CONFIG_X86
55384 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
55385 +#endif
55386 +
55387 + for (j = 0; j < 4; j++) {
55388 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
55389 + if (gr_shared_page[j] == NULL) {
55390 + panic("Unable to allocate grsecurity shared page");
55391 + return;
55392 + }
55393 + }
55394 +
55395 + /* allocate log buffers */
55396 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
55397 + if (!gr_alert_log_fmt) {
55398 + panic("Unable to allocate grsecurity alert log format buffer");
55399 + return;
55400 + }
55401 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
55402 + if (!gr_audit_log_fmt) {
55403 + panic("Unable to allocate grsecurity audit log format buffer");
55404 + return;
55405 + }
55406 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
55407 + if (!gr_alert_log_buf) {
55408 + panic("Unable to allocate grsecurity alert log buffer");
55409 + return;
55410 + }
55411 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
55412 + if (!gr_audit_log_buf) {
55413 + panic("Unable to allocate grsecurity audit log buffer");
55414 + return;
55415 + }
55416 +
55417 + /* allocate memory for authentication structure */
55418 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
55419 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
55420 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
55421 +
55422 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
55423 + panic("Unable to allocate grsecurity authentication structure");
55424 + return;
55425 + }
55426 +
55427 +
55428 +#ifdef CONFIG_GRKERNSEC_IO
55429 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
55430 + grsec_disable_privio = 1;
55431 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
55432 + grsec_disable_privio = 1;
55433 +#else
55434 + grsec_disable_privio = 0;
55435 +#endif
55436 +#endif
55437 +
55438 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
55439 + /* for backward compatibility, tpe_invert always defaults to on if
55440 + enabled in the kernel
55441 + */
55442 + grsec_enable_tpe_invert = 1;
55443 +#endif
55444 +
55445 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
55446 +#ifndef CONFIG_GRKERNSEC_SYSCTL
55447 + grsec_lock = 1;
55448 +#endif
55449 +
55450 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
55451 + grsec_enable_audit_textrel = 1;
55452 +#endif
55453 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55454 + grsec_enable_log_rwxmaps = 1;
55455 +#endif
55456 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
55457 + grsec_enable_group = 1;
55458 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
55459 +#endif
55460 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
55461 + grsec_enable_ptrace_readexec = 1;
55462 +#endif
55463 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
55464 + grsec_enable_chdir = 1;
55465 +#endif
55466 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55467 + grsec_enable_harden_ptrace = 1;
55468 +#endif
55469 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
55470 + grsec_enable_mount = 1;
55471 +#endif
55472 +#ifdef CONFIG_GRKERNSEC_LINK
55473 + grsec_enable_link = 1;
55474 +#endif
55475 +#ifdef CONFIG_GRKERNSEC_BRUTE
55476 + grsec_enable_brute = 1;
55477 +#endif
55478 +#ifdef CONFIG_GRKERNSEC_DMESG
55479 + grsec_enable_dmesg = 1;
55480 +#endif
55481 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
55482 + grsec_enable_blackhole = 1;
55483 + grsec_lastack_retries = 4;
55484 +#endif
55485 +#ifdef CONFIG_GRKERNSEC_FIFO
55486 + grsec_enable_fifo = 1;
55487 +#endif
55488 +#ifdef CONFIG_GRKERNSEC_EXECLOG
55489 + grsec_enable_execlog = 1;
55490 +#endif
55491 +#ifdef CONFIG_GRKERNSEC_SETXID
55492 + grsec_enable_setxid = 1;
55493 +#endif
55494 +#ifdef CONFIG_GRKERNSEC_SIGNAL
55495 + grsec_enable_signal = 1;
55496 +#endif
55497 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
55498 + grsec_enable_forkfail = 1;
55499 +#endif
55500 +#ifdef CONFIG_GRKERNSEC_TIME
55501 + grsec_enable_time = 1;
55502 +#endif
55503 +#ifdef CONFIG_GRKERNSEC_RESLOG
55504 + grsec_resource_logging = 1;
55505 +#endif
55506 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
55507 + grsec_enable_chroot_findtask = 1;
55508 +#endif
55509 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
55510 + grsec_enable_chroot_unix = 1;
55511 +#endif
55512 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
55513 + grsec_enable_chroot_mount = 1;
55514 +#endif
55515 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
55516 + grsec_enable_chroot_fchdir = 1;
55517 +#endif
55518 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
55519 + grsec_enable_chroot_shmat = 1;
55520 +#endif
55521 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
55522 + grsec_enable_audit_ptrace = 1;
55523 +#endif
55524 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
55525 + grsec_enable_chroot_double = 1;
55526 +#endif
55527 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
55528 + grsec_enable_chroot_pivot = 1;
55529 +#endif
55530 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
55531 + grsec_enable_chroot_chdir = 1;
55532 +#endif
55533 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
55534 + grsec_enable_chroot_chmod = 1;
55535 +#endif
55536 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
55537 + grsec_enable_chroot_mknod = 1;
55538 +#endif
55539 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
55540 + grsec_enable_chroot_nice = 1;
55541 +#endif
55542 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
55543 + grsec_enable_chroot_execlog = 1;
55544 +#endif
55545 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
55546 + grsec_enable_chroot_caps = 1;
55547 +#endif
55548 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
55549 + grsec_enable_chroot_sysctl = 1;
55550 +#endif
55551 +#ifdef CONFIG_GRKERNSEC_TPE
55552 + grsec_enable_tpe = 1;
55553 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
55554 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
55555 + grsec_enable_tpe_all = 1;
55556 +#endif
55557 +#endif
55558 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
55559 + grsec_enable_socket_all = 1;
55560 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
55561 +#endif
55562 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
55563 + grsec_enable_socket_client = 1;
55564 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
55565 +#endif
55566 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
55567 + grsec_enable_socket_server = 1;
55568 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
55569 +#endif
55570 +#endif
55571 +
55572 + return;
55573 +}
55574 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
55575 new file mode 100644
55576 index 0000000..3efe141
55577 --- /dev/null
55578 +++ b/grsecurity/grsec_link.c
55579 @@ -0,0 +1,43 @@
55580 +#include <linux/kernel.h>
55581 +#include <linux/sched.h>
55582 +#include <linux/fs.h>
55583 +#include <linux/file.h>
55584 +#include <linux/grinternal.h>
55585 +
55586 +int
55587 +gr_handle_follow_link(const struct inode *parent,
55588 + const struct inode *inode,
55589 + const struct dentry *dentry, const struct vfsmount *mnt)
55590 +{
55591 +#ifdef CONFIG_GRKERNSEC_LINK
55592 + const struct cred *cred = current_cred();
55593 +
55594 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
55595 + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
55596 + (parent->i_mode & S_IWOTH) && (cred->fsuid != inode->i_uid)) {
55597 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
55598 + return -EACCES;
55599 + }
55600 +#endif
55601 + return 0;
55602 +}
55603 +
55604 +int
55605 +gr_handle_hardlink(const struct dentry *dentry,
55606 + const struct vfsmount *mnt,
55607 + struct inode *inode, const int mode, const char *to)
55608 +{
55609 +#ifdef CONFIG_GRKERNSEC_LINK
55610 + const struct cred *cred = current_cred();
55611 +
55612 + if (grsec_enable_link && cred->fsuid != inode->i_uid &&
55613 + (!S_ISREG(mode) || (mode & S_ISUID) ||
55614 + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
55615 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
55616 + !capable(CAP_FOWNER) && cred->uid) {
55617 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
55618 + return -EPERM;
55619 + }
55620 +#endif
55621 + return 0;
55622 +}
55623 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
55624 new file mode 100644
55625 index 0000000..a45d2e9
55626 --- /dev/null
55627 +++ b/grsecurity/grsec_log.c
55628 @@ -0,0 +1,322 @@
55629 +#include <linux/kernel.h>
55630 +#include <linux/sched.h>
55631 +#include <linux/file.h>
55632 +#include <linux/tty.h>
55633 +#include <linux/fs.h>
55634 +#include <linux/grinternal.h>
55635 +
55636 +#ifdef CONFIG_TREE_PREEMPT_RCU
55637 +#define DISABLE_PREEMPT() preempt_disable()
55638 +#define ENABLE_PREEMPT() preempt_enable()
55639 +#else
55640 +#define DISABLE_PREEMPT()
55641 +#define ENABLE_PREEMPT()
55642 +#endif
55643 +
55644 +#define BEGIN_LOCKS(x) \
55645 + DISABLE_PREEMPT(); \
55646 + rcu_read_lock(); \
55647 + read_lock(&tasklist_lock); \
55648 + read_lock(&grsec_exec_file_lock); \
55649 + if (x != GR_DO_AUDIT) \
55650 + spin_lock(&grsec_alert_lock); \
55651 + else \
55652 + spin_lock(&grsec_audit_lock)
55653 +
55654 +#define END_LOCKS(x) \
55655 + if (x != GR_DO_AUDIT) \
55656 + spin_unlock(&grsec_alert_lock); \
55657 + else \
55658 + spin_unlock(&grsec_audit_lock); \
55659 + read_unlock(&grsec_exec_file_lock); \
55660 + read_unlock(&tasklist_lock); \
55661 + rcu_read_unlock(); \
55662 + ENABLE_PREEMPT(); \
55663 + if (x == GR_DONT_AUDIT) \
55664 + gr_handle_alertkill(current)
55665 +
55666 +enum {
55667 + FLOODING,
55668 + NO_FLOODING
55669 +};
55670 +
55671 +extern char *gr_alert_log_fmt;
55672 +extern char *gr_audit_log_fmt;
55673 +extern char *gr_alert_log_buf;
55674 +extern char *gr_audit_log_buf;
55675 +
55676 +static int gr_log_start(int audit)
55677 +{
55678 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
55679 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
55680 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55681 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
55682 + unsigned long curr_secs = get_seconds();
55683 +
55684 + if (audit == GR_DO_AUDIT)
55685 + goto set_fmt;
55686 +
55687 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
55688 + grsec_alert_wtime = curr_secs;
55689 + grsec_alert_fyet = 0;
55690 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
55691 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
55692 + grsec_alert_fyet++;
55693 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
55694 + grsec_alert_wtime = curr_secs;
55695 + grsec_alert_fyet++;
55696 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
55697 + return FLOODING;
55698 + }
55699 + else return FLOODING;
55700 +
55701 +set_fmt:
55702 +#endif
55703 + memset(buf, 0, PAGE_SIZE);
55704 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
55705 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
55706 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
55707 + } else if (current->signal->curr_ip) {
55708 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
55709 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
55710 + } else if (gr_acl_is_enabled()) {
55711 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
55712 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
55713 + } else {
55714 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
55715 + strcpy(buf, fmt);
55716 + }
55717 +
55718 + return NO_FLOODING;
55719 +}
55720 +
55721 +static void gr_log_middle(int audit, const char *msg, va_list ap)
55722 + __attribute__ ((format (printf, 2, 0)));
55723 +
55724 +static void gr_log_middle(int audit, const char *msg, va_list ap)
55725 +{
55726 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55727 + unsigned int len = strlen(buf);
55728 +
55729 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
55730 +
55731 + return;
55732 +}
55733 +
55734 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
55735 + __attribute__ ((format (printf, 2, 3)));
55736 +
55737 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
55738 +{
55739 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55740 + unsigned int len = strlen(buf);
55741 + va_list ap;
55742 +
55743 + va_start(ap, msg);
55744 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
55745 + va_end(ap);
55746 +
55747 + return;
55748 +}
55749 +
55750 +static void gr_log_end(int audit, int append_default)
55751 +{
55752 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
55753 +
55754 + if (append_default) {
55755 + unsigned int len = strlen(buf);
55756 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
55757 + }
55758 +
55759 + printk("%s\n", buf);
55760 +
55761 + return;
55762 +}
55763 +
55764 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
55765 +{
55766 + int logtype;
55767 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
55768 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
55769 + void *voidptr = NULL;
55770 + int num1 = 0, num2 = 0;
55771 + unsigned long ulong1 = 0, ulong2 = 0;
55772 + struct dentry *dentry = NULL;
55773 + struct vfsmount *mnt = NULL;
55774 + struct file *file = NULL;
55775 + struct task_struct *task = NULL;
55776 + const struct cred *cred, *pcred;
55777 + va_list ap;
55778 +
55779 + BEGIN_LOCKS(audit);
55780 + logtype = gr_log_start(audit);
55781 + if (logtype == FLOODING) {
55782 + END_LOCKS(audit);
55783 + return;
55784 + }
55785 + va_start(ap, argtypes);
55786 + switch (argtypes) {
55787 + case GR_TTYSNIFF:
55788 + task = va_arg(ap, struct task_struct *);
55789 + 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);
55790 + break;
55791 + case GR_SYSCTL_HIDDEN:
55792 + str1 = va_arg(ap, char *);
55793 + gr_log_middle_varargs(audit, msg, result, str1);
55794 + break;
55795 + case GR_RBAC:
55796 + dentry = va_arg(ap, struct dentry *);
55797 + mnt = va_arg(ap, struct vfsmount *);
55798 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
55799 + break;
55800 + case GR_RBAC_STR:
55801 + dentry = va_arg(ap, struct dentry *);
55802 + mnt = va_arg(ap, struct vfsmount *);
55803 + str1 = va_arg(ap, char *);
55804 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
55805 + break;
55806 + case GR_STR_RBAC:
55807 + str1 = va_arg(ap, char *);
55808 + dentry = va_arg(ap, struct dentry *);
55809 + mnt = va_arg(ap, struct vfsmount *);
55810 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
55811 + break;
55812 + case GR_RBAC_MODE2:
55813 + dentry = va_arg(ap, struct dentry *);
55814 + mnt = va_arg(ap, struct vfsmount *);
55815 + str1 = va_arg(ap, char *);
55816 + str2 = va_arg(ap, char *);
55817 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
55818 + break;
55819 + case GR_RBAC_MODE3:
55820 + dentry = va_arg(ap, struct dentry *);
55821 + mnt = va_arg(ap, struct vfsmount *);
55822 + str1 = va_arg(ap, char *);
55823 + str2 = va_arg(ap, char *);
55824 + str3 = va_arg(ap, char *);
55825 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
55826 + break;
55827 + case GR_FILENAME:
55828 + dentry = va_arg(ap, struct dentry *);
55829 + mnt = va_arg(ap, struct vfsmount *);
55830 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
55831 + break;
55832 + case GR_STR_FILENAME:
55833 + str1 = va_arg(ap, char *);
55834 + dentry = va_arg(ap, struct dentry *);
55835 + mnt = va_arg(ap, struct vfsmount *);
55836 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
55837 + break;
55838 + case GR_FILENAME_STR:
55839 + dentry = va_arg(ap, struct dentry *);
55840 + mnt = va_arg(ap, struct vfsmount *);
55841 + str1 = va_arg(ap, char *);
55842 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
55843 + break;
55844 + case GR_FILENAME_TWO_INT:
55845 + dentry = va_arg(ap, struct dentry *);
55846 + mnt = va_arg(ap, struct vfsmount *);
55847 + num1 = va_arg(ap, int);
55848 + num2 = va_arg(ap, int);
55849 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
55850 + break;
55851 + case GR_FILENAME_TWO_INT_STR:
55852 + dentry = va_arg(ap, struct dentry *);
55853 + mnt = va_arg(ap, struct vfsmount *);
55854 + num1 = va_arg(ap, int);
55855 + num2 = va_arg(ap, int);
55856 + str1 = va_arg(ap, char *);
55857 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
55858 + break;
55859 + case GR_TEXTREL:
55860 + file = va_arg(ap, struct file *);
55861 + ulong1 = va_arg(ap, unsigned long);
55862 + ulong2 = va_arg(ap, unsigned long);
55863 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
55864 + break;
55865 + case GR_PTRACE:
55866 + task = va_arg(ap, struct task_struct *);
55867 + 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);
55868 + break;
55869 + case GR_RESOURCE:
55870 + task = va_arg(ap, struct task_struct *);
55871 + cred = __task_cred(task);
55872 + pcred = __task_cred(task->real_parent);
55873 + ulong1 = va_arg(ap, unsigned long);
55874 + str1 = va_arg(ap, char *);
55875 + ulong2 = va_arg(ap, unsigned long);
55876 + 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);
55877 + break;
55878 + case GR_CAP:
55879 + task = va_arg(ap, struct task_struct *);
55880 + cred = __task_cred(task);
55881 + pcred = __task_cred(task->real_parent);
55882 + str1 = va_arg(ap, char *);
55883 + 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);
55884 + break;
55885 + case GR_SIG:
55886 + str1 = va_arg(ap, char *);
55887 + voidptr = va_arg(ap, void *);
55888 + gr_log_middle_varargs(audit, msg, str1, voidptr);
55889 + break;
55890 + case GR_SIG2:
55891 + task = va_arg(ap, struct task_struct *);
55892 + cred = __task_cred(task);
55893 + pcred = __task_cred(task->real_parent);
55894 + num1 = va_arg(ap, int);
55895 + 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);
55896 + break;
55897 + case GR_CRASH1:
55898 + task = va_arg(ap, struct task_struct *);
55899 + cred = __task_cred(task);
55900 + pcred = __task_cred(task->real_parent);
55901 + ulong1 = va_arg(ap, unsigned long);
55902 + 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);
55903 + break;
55904 + case GR_CRASH2:
55905 + task = va_arg(ap, struct task_struct *);
55906 + cred = __task_cred(task);
55907 + pcred = __task_cred(task->real_parent);
55908 + ulong1 = va_arg(ap, unsigned long);
55909 + 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);
55910 + break;
55911 + case GR_RWXMAP:
55912 + file = va_arg(ap, struct file *);
55913 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
55914 + break;
55915 + case GR_PSACCT:
55916 + {
55917 + unsigned int wday, cday;
55918 + __u8 whr, chr;
55919 + __u8 wmin, cmin;
55920 + __u8 wsec, csec;
55921 + char cur_tty[64] = { 0 };
55922 + char parent_tty[64] = { 0 };
55923 +
55924 + task = va_arg(ap, struct task_struct *);
55925 + wday = va_arg(ap, unsigned int);
55926 + cday = va_arg(ap, unsigned int);
55927 + whr = va_arg(ap, int);
55928 + chr = va_arg(ap, int);
55929 + wmin = va_arg(ap, int);
55930 + cmin = va_arg(ap, int);
55931 + wsec = va_arg(ap, int);
55932 + csec = va_arg(ap, int);
55933 + ulong1 = va_arg(ap, unsigned long);
55934 + cred = __task_cred(task);
55935 + pcred = __task_cred(task->real_parent);
55936 +
55937 + 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);
55938 + }
55939 + break;
55940 + default:
55941 + gr_log_middle(audit, msg, ap);
55942 + }
55943 + va_end(ap);
55944 + // these don't need DEFAULTSECARGS printed on the end
55945 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
55946 + gr_log_end(audit, 0);
55947 + else
55948 + gr_log_end(audit, 1);
55949 + END_LOCKS(audit);
55950 +}
55951 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
55952 new file mode 100644
55953 index 0000000..f536303
55954 --- /dev/null
55955 +++ b/grsecurity/grsec_mem.c
55956 @@ -0,0 +1,40 @@
55957 +#include <linux/kernel.h>
55958 +#include <linux/sched.h>
55959 +#include <linux/mm.h>
55960 +#include <linux/mman.h>
55961 +#include <linux/grinternal.h>
55962 +
55963 +void
55964 +gr_handle_ioperm(void)
55965 +{
55966 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
55967 + return;
55968 +}
55969 +
55970 +void
55971 +gr_handle_iopl(void)
55972 +{
55973 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
55974 + return;
55975 +}
55976 +
55977 +void
55978 +gr_handle_mem_readwrite(u64 from, u64 to)
55979 +{
55980 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
55981 + return;
55982 +}
55983 +
55984 +void
55985 +gr_handle_vm86(void)
55986 +{
55987 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
55988 + return;
55989 +}
55990 +
55991 +void
55992 +gr_log_badprocpid(const char *entry)
55993 +{
55994 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
55995 + return;
55996 +}
55997 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
55998 new file mode 100644
55999 index 0000000..2131422
56000 --- /dev/null
56001 +++ b/grsecurity/grsec_mount.c
56002 @@ -0,0 +1,62 @@
56003 +#include <linux/kernel.h>
56004 +#include <linux/sched.h>
56005 +#include <linux/mount.h>
56006 +#include <linux/grsecurity.h>
56007 +#include <linux/grinternal.h>
56008 +
56009 +void
56010 +gr_log_remount(const char *devname, const int retval)
56011 +{
56012 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56013 + if (grsec_enable_mount && (retval >= 0))
56014 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
56015 +#endif
56016 + return;
56017 +}
56018 +
56019 +void
56020 +gr_log_unmount(const char *devname, const int retval)
56021 +{
56022 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56023 + if (grsec_enable_mount && (retval >= 0))
56024 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
56025 +#endif
56026 + return;
56027 +}
56028 +
56029 +void
56030 +gr_log_mount(const char *from, const char *to, const int retval)
56031 +{
56032 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56033 + if (grsec_enable_mount && (retval >= 0))
56034 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
56035 +#endif
56036 + return;
56037 +}
56038 +
56039 +int
56040 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
56041 +{
56042 +#ifdef CONFIG_GRKERNSEC_ROFS
56043 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
56044 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
56045 + return -EPERM;
56046 + } else
56047 + return 0;
56048 +#endif
56049 + return 0;
56050 +}
56051 +
56052 +int
56053 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
56054 +{
56055 +#ifdef CONFIG_GRKERNSEC_ROFS
56056 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
56057 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
56058 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
56059 + return -EPERM;
56060 + } else
56061 + return 0;
56062 +#endif
56063 + return 0;
56064 +}
56065 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
56066 new file mode 100644
56067 index 0000000..a3b12a0
56068 --- /dev/null
56069 +++ b/grsecurity/grsec_pax.c
56070 @@ -0,0 +1,36 @@
56071 +#include <linux/kernel.h>
56072 +#include <linux/sched.h>
56073 +#include <linux/mm.h>
56074 +#include <linux/file.h>
56075 +#include <linux/grinternal.h>
56076 +#include <linux/grsecurity.h>
56077 +
56078 +void
56079 +gr_log_textrel(struct vm_area_struct * vma)
56080 +{
56081 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56082 + if (grsec_enable_audit_textrel)
56083 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
56084 +#endif
56085 + return;
56086 +}
56087 +
56088 +void
56089 +gr_log_rwxmmap(struct file *file)
56090 +{
56091 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56092 + if (grsec_enable_log_rwxmaps)
56093 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
56094 +#endif
56095 + return;
56096 +}
56097 +
56098 +void
56099 +gr_log_rwxmprotect(struct file *file)
56100 +{
56101 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56102 + if (grsec_enable_log_rwxmaps)
56103 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
56104 +#endif
56105 + return;
56106 +}
56107 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
56108 new file mode 100644
56109 index 0000000..f7f29aa
56110 --- /dev/null
56111 +++ b/grsecurity/grsec_ptrace.c
56112 @@ -0,0 +1,30 @@
56113 +#include <linux/kernel.h>
56114 +#include <linux/sched.h>
56115 +#include <linux/grinternal.h>
56116 +#include <linux/security.h>
56117 +
56118 +void
56119 +gr_audit_ptrace(struct task_struct *task)
56120 +{
56121 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
56122 + if (grsec_enable_audit_ptrace)
56123 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
56124 +#endif
56125 + return;
56126 +}
56127 +
56128 +int
56129 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
56130 +{
56131 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56132 + const struct dentry *dentry = file->f_path.dentry;
56133 + const struct vfsmount *mnt = file->f_path.mnt;
56134 +
56135 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
56136 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
56137 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
56138 + return -EACCES;
56139 + }
56140 +#endif
56141 + return 0;
56142 +}
56143 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
56144 new file mode 100644
56145 index 0000000..7a5b2de
56146 --- /dev/null
56147 +++ b/grsecurity/grsec_sig.c
56148 @@ -0,0 +1,207 @@
56149 +#include <linux/kernel.h>
56150 +#include <linux/sched.h>
56151 +#include <linux/delay.h>
56152 +#include <linux/grsecurity.h>
56153 +#include <linux/grinternal.h>
56154 +#include <linux/hardirq.h>
56155 +
56156 +char *signames[] = {
56157 + [SIGSEGV] = "Segmentation fault",
56158 + [SIGILL] = "Illegal instruction",
56159 + [SIGABRT] = "Abort",
56160 + [SIGBUS] = "Invalid alignment/Bus error"
56161 +};
56162 +
56163 +void
56164 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
56165 +{
56166 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56167 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
56168 + (sig == SIGABRT) || (sig == SIGBUS))) {
56169 + if (t->pid == current->pid) {
56170 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
56171 + } else {
56172 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
56173 + }
56174 + }
56175 +#endif
56176 + return;
56177 +}
56178 +
56179 +int
56180 +gr_handle_signal(const struct task_struct *p, const int sig)
56181 +{
56182 +#ifdef CONFIG_GRKERNSEC
56183 + /* ignore the 0 signal for protected task checks */
56184 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
56185 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
56186 + return -EPERM;
56187 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
56188 + return -EPERM;
56189 + }
56190 +#endif
56191 + return 0;
56192 +}
56193 +
56194 +#ifdef CONFIG_GRKERNSEC
56195 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
56196 +
56197 +int gr_fake_force_sig(int sig, struct task_struct *t)
56198 +{
56199 + unsigned long int flags;
56200 + int ret, blocked, ignored;
56201 + struct k_sigaction *action;
56202 +
56203 + spin_lock_irqsave(&t->sighand->siglock, flags);
56204 + action = &t->sighand->action[sig-1];
56205 + ignored = action->sa.sa_handler == SIG_IGN;
56206 + blocked = sigismember(&t->blocked, sig);
56207 + if (blocked || ignored) {
56208 + action->sa.sa_handler = SIG_DFL;
56209 + if (blocked) {
56210 + sigdelset(&t->blocked, sig);
56211 + recalc_sigpending_and_wake(t);
56212 + }
56213 + }
56214 + if (action->sa.sa_handler == SIG_DFL)
56215 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
56216 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
56217 +
56218 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
56219 +
56220 + return ret;
56221 +}
56222 +#endif
56223 +
56224 +#ifdef CONFIG_GRKERNSEC_BRUTE
56225 +#define GR_USER_BAN_TIME (15 * 60)
56226 +
56227 +static int __get_dumpable(unsigned long mm_flags)
56228 +{
56229 + int ret;
56230 +
56231 + ret = mm_flags & MMF_DUMPABLE_MASK;
56232 + return (ret >= 2) ? 2 : ret;
56233 +}
56234 +#endif
56235 +
56236 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
56237 +{
56238 +#ifdef CONFIG_GRKERNSEC_BRUTE
56239 + uid_t uid = 0;
56240 +
56241 + if (!grsec_enable_brute)
56242 + return;
56243 +
56244 + rcu_read_lock();
56245 + read_lock(&tasklist_lock);
56246 + read_lock(&grsec_exec_file_lock);
56247 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
56248 + p->real_parent->brute = 1;
56249 + else {
56250 + const struct cred *cred = __task_cred(p), *cred2;
56251 + struct task_struct *tsk, *tsk2;
56252 +
56253 + if (!__get_dumpable(mm_flags) && cred->uid) {
56254 + struct user_struct *user;
56255 +
56256 + uid = cred->uid;
56257 +
56258 + /* this is put upon execution past expiration */
56259 + user = find_user(uid);
56260 + if (user == NULL)
56261 + goto unlock;
56262 + user->banned = 1;
56263 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
56264 + if (user->ban_expires == ~0UL)
56265 + user->ban_expires--;
56266 +
56267 + do_each_thread(tsk2, tsk) {
56268 + cred2 = __task_cred(tsk);
56269 + if (tsk != p && cred2->uid == uid)
56270 + gr_fake_force_sig(SIGKILL, tsk);
56271 + } while_each_thread(tsk2, tsk);
56272 + }
56273 + }
56274 +unlock:
56275 + read_unlock(&grsec_exec_file_lock);
56276 + read_unlock(&tasklist_lock);
56277 + rcu_read_unlock();
56278 +
56279 + if (uid)
56280 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n", uid, GR_USER_BAN_TIME / 60);
56281 +
56282 +#endif
56283 + return;
56284 +}
56285 +
56286 +void gr_handle_brute_check(void)
56287 +{
56288 +#ifdef CONFIG_GRKERNSEC_BRUTE
56289 + if (current->brute)
56290 + msleep(30 * 1000);
56291 +#endif
56292 + return;
56293 +}
56294 +
56295 +void gr_handle_kernel_exploit(void)
56296 +{
56297 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
56298 + const struct cred *cred;
56299 + struct task_struct *tsk, *tsk2;
56300 + struct user_struct *user;
56301 + uid_t uid;
56302 +
56303 + if (in_irq() || in_serving_softirq() || in_nmi())
56304 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
56305 +
56306 + uid = current_uid();
56307 +
56308 + if (uid == 0)
56309 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
56310 + else {
56311 + /* kill all the processes of this user, hold a reference
56312 + to their creds struct, and prevent them from creating
56313 + another process until system reset
56314 + */
56315 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n", uid);
56316 + /* we intentionally leak this ref */
56317 + user = get_uid(current->cred->user);
56318 + if (user) {
56319 + user->banned = 1;
56320 + user->ban_expires = ~0UL;
56321 + }
56322 +
56323 + read_lock(&tasklist_lock);
56324 + do_each_thread(tsk2, tsk) {
56325 + cred = __task_cred(tsk);
56326 + if (cred->uid == uid)
56327 + gr_fake_force_sig(SIGKILL, tsk);
56328 + } while_each_thread(tsk2, tsk);
56329 + read_unlock(&tasklist_lock);
56330 + }
56331 +#endif
56332 +}
56333 +
56334 +int __gr_process_user_ban(struct user_struct *user)
56335 +{
56336 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56337 + if (unlikely(user->banned)) {
56338 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
56339 + user->banned = 0;
56340 + user->ban_expires = 0;
56341 + free_uid(user);
56342 + } else
56343 + return -EPERM;
56344 + }
56345 +#endif
56346 + return 0;
56347 +}
56348 +
56349 +int gr_process_user_ban(void)
56350 +{
56351 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56352 + return __gr_process_user_ban(current->cred->user);
56353 +#endif
56354 + return 0;
56355 +}
56356 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
56357 new file mode 100644
56358 index 0000000..4030d57
56359 --- /dev/null
56360 +++ b/grsecurity/grsec_sock.c
56361 @@ -0,0 +1,244 @@
56362 +#include <linux/kernel.h>
56363 +#include <linux/module.h>
56364 +#include <linux/sched.h>
56365 +#include <linux/file.h>
56366 +#include <linux/net.h>
56367 +#include <linux/in.h>
56368 +#include <linux/ip.h>
56369 +#include <net/sock.h>
56370 +#include <net/inet_sock.h>
56371 +#include <linux/grsecurity.h>
56372 +#include <linux/grinternal.h>
56373 +#include <linux/gracl.h>
56374 +
56375 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
56376 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
56377 +
56378 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
56379 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
56380 +
56381 +#ifdef CONFIG_UNIX_MODULE
56382 +EXPORT_SYMBOL(gr_acl_handle_unix);
56383 +EXPORT_SYMBOL(gr_acl_handle_mknod);
56384 +EXPORT_SYMBOL(gr_handle_chroot_unix);
56385 +EXPORT_SYMBOL(gr_handle_create);
56386 +#endif
56387 +
56388 +#ifdef CONFIG_GRKERNSEC
56389 +#define gr_conn_table_size 32749
56390 +struct conn_table_entry {
56391 + struct conn_table_entry *next;
56392 + struct signal_struct *sig;
56393 +};
56394 +
56395 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
56396 +DEFINE_SPINLOCK(gr_conn_table_lock);
56397 +
56398 +extern const char * gr_socktype_to_name(unsigned char type);
56399 +extern const char * gr_proto_to_name(unsigned char proto);
56400 +extern const char * gr_sockfamily_to_name(unsigned char family);
56401 +
56402 +static __inline__ int
56403 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
56404 +{
56405 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
56406 +}
56407 +
56408 +static __inline__ int
56409 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
56410 + __u16 sport, __u16 dport)
56411 +{
56412 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
56413 + sig->gr_sport == sport && sig->gr_dport == dport))
56414 + return 1;
56415 + else
56416 + return 0;
56417 +}
56418 +
56419 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
56420 +{
56421 + struct conn_table_entry **match;
56422 + unsigned int index;
56423 +
56424 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
56425 + sig->gr_sport, sig->gr_dport,
56426 + gr_conn_table_size);
56427 +
56428 + newent->sig = sig;
56429 +
56430 + match = &gr_conn_table[index];
56431 + newent->next = *match;
56432 + *match = newent;
56433 +
56434 + return;
56435 +}
56436 +
56437 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
56438 +{
56439 + struct conn_table_entry *match, *last = NULL;
56440 + unsigned int index;
56441 +
56442 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
56443 + sig->gr_sport, sig->gr_dport,
56444 + gr_conn_table_size);
56445 +
56446 + match = gr_conn_table[index];
56447 + while (match && !conn_match(match->sig,
56448 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
56449 + sig->gr_dport)) {
56450 + last = match;
56451 + match = match->next;
56452 + }
56453 +
56454 + if (match) {
56455 + if (last)
56456 + last->next = match->next;
56457 + else
56458 + gr_conn_table[index] = NULL;
56459 + kfree(match);
56460 + }
56461 +
56462 + return;
56463 +}
56464 +
56465 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
56466 + __u16 sport, __u16 dport)
56467 +{
56468 + struct conn_table_entry *match;
56469 + unsigned int index;
56470 +
56471 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
56472 +
56473 + match = gr_conn_table[index];
56474 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
56475 + match = match->next;
56476 +
56477 + if (match)
56478 + return match->sig;
56479 + else
56480 + return NULL;
56481 +}
56482 +
56483 +#endif
56484 +
56485 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
56486 +{
56487 +#ifdef CONFIG_GRKERNSEC
56488 + struct signal_struct *sig = task->signal;
56489 + struct conn_table_entry *newent;
56490 +
56491 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
56492 + if (newent == NULL)
56493 + return;
56494 + /* no bh lock needed since we are called with bh disabled */
56495 + spin_lock(&gr_conn_table_lock);
56496 + gr_del_task_from_ip_table_nolock(sig);
56497 + sig->gr_saddr = inet->inet_rcv_saddr;
56498 + sig->gr_daddr = inet->inet_daddr;
56499 + sig->gr_sport = inet->inet_sport;
56500 + sig->gr_dport = inet->inet_dport;
56501 + gr_add_to_task_ip_table_nolock(sig, newent);
56502 + spin_unlock(&gr_conn_table_lock);
56503 +#endif
56504 + return;
56505 +}
56506 +
56507 +void gr_del_task_from_ip_table(struct task_struct *task)
56508 +{
56509 +#ifdef CONFIG_GRKERNSEC
56510 + spin_lock_bh(&gr_conn_table_lock);
56511 + gr_del_task_from_ip_table_nolock(task->signal);
56512 + spin_unlock_bh(&gr_conn_table_lock);
56513 +#endif
56514 + return;
56515 +}
56516 +
56517 +void
56518 +gr_attach_curr_ip(const struct sock *sk)
56519 +{
56520 +#ifdef CONFIG_GRKERNSEC
56521 + struct signal_struct *p, *set;
56522 + const struct inet_sock *inet = inet_sk(sk);
56523 +
56524 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
56525 + return;
56526 +
56527 + set = current->signal;
56528 +
56529 + spin_lock_bh(&gr_conn_table_lock);
56530 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
56531 + inet->inet_dport, inet->inet_sport);
56532 + if (unlikely(p != NULL)) {
56533 + set->curr_ip = p->curr_ip;
56534 + set->used_accept = 1;
56535 + gr_del_task_from_ip_table_nolock(p);
56536 + spin_unlock_bh(&gr_conn_table_lock);
56537 + return;
56538 + }
56539 + spin_unlock_bh(&gr_conn_table_lock);
56540 +
56541 + set->curr_ip = inet->inet_daddr;
56542 + set->used_accept = 1;
56543 +#endif
56544 + return;
56545 +}
56546 +
56547 +int
56548 +gr_handle_sock_all(const int family, const int type, const int protocol)
56549 +{
56550 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56551 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
56552 + (family != AF_UNIX)) {
56553 + if (family == AF_INET)
56554 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
56555 + else
56556 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
56557 + return -EACCES;
56558 + }
56559 +#endif
56560 + return 0;
56561 +}
56562 +
56563 +int
56564 +gr_handle_sock_server(const struct sockaddr *sck)
56565 +{
56566 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56567 + if (grsec_enable_socket_server &&
56568 + in_group_p(grsec_socket_server_gid) &&
56569 + sck && (sck->sa_family != AF_UNIX) &&
56570 + (sck->sa_family != AF_LOCAL)) {
56571 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
56572 + return -EACCES;
56573 + }
56574 +#endif
56575 + return 0;
56576 +}
56577 +
56578 +int
56579 +gr_handle_sock_server_other(const struct sock *sck)
56580 +{
56581 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56582 + if (grsec_enable_socket_server &&
56583 + in_group_p(grsec_socket_server_gid) &&
56584 + sck && (sck->sk_family != AF_UNIX) &&
56585 + (sck->sk_family != AF_LOCAL)) {
56586 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
56587 + return -EACCES;
56588 + }
56589 +#endif
56590 + return 0;
56591 +}
56592 +
56593 +int
56594 +gr_handle_sock_client(const struct sockaddr *sck)
56595 +{
56596 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56597 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
56598 + sck && (sck->sa_family != AF_UNIX) &&
56599 + (sck->sa_family != AF_LOCAL)) {
56600 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
56601 + return -EACCES;
56602 + }
56603 +#endif
56604 + return 0;
56605 +}
56606 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
56607 new file mode 100644
56608 index 0000000..a1aedd7
56609 --- /dev/null
56610 +++ b/grsecurity/grsec_sysctl.c
56611 @@ -0,0 +1,451 @@
56612 +#include <linux/kernel.h>
56613 +#include <linux/sched.h>
56614 +#include <linux/sysctl.h>
56615 +#include <linux/grsecurity.h>
56616 +#include <linux/grinternal.h>
56617 +
56618 +int
56619 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
56620 +{
56621 +#ifdef CONFIG_GRKERNSEC_SYSCTL
56622 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
56623 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
56624 + return -EACCES;
56625 + }
56626 +#endif
56627 + return 0;
56628 +}
56629 +
56630 +#ifdef CONFIG_GRKERNSEC_ROFS
56631 +static int __maybe_unused one = 1;
56632 +#endif
56633 +
56634 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
56635 +struct ctl_table grsecurity_table[] = {
56636 +#ifdef CONFIG_GRKERNSEC_SYSCTL
56637 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
56638 +#ifdef CONFIG_GRKERNSEC_IO
56639 + {
56640 + .procname = "disable_priv_io",
56641 + .data = &grsec_disable_privio,
56642 + .maxlen = sizeof(int),
56643 + .mode = 0600,
56644 + .proc_handler = &proc_dointvec,
56645 + },
56646 +#endif
56647 +#endif
56648 +#ifdef CONFIG_GRKERNSEC_LINK
56649 + {
56650 + .procname = "linking_restrictions",
56651 + .data = &grsec_enable_link,
56652 + .maxlen = sizeof(int),
56653 + .mode = 0600,
56654 + .proc_handler = &proc_dointvec,
56655 + },
56656 +#endif
56657 +#ifdef CONFIG_GRKERNSEC_BRUTE
56658 + {
56659 + .procname = "deter_bruteforce",
56660 + .data = &grsec_enable_brute,
56661 + .maxlen = sizeof(int),
56662 + .mode = 0600,
56663 + .proc_handler = &proc_dointvec,
56664 + },
56665 +#endif
56666 +#ifdef CONFIG_GRKERNSEC_FIFO
56667 + {
56668 + .procname = "fifo_restrictions",
56669 + .data = &grsec_enable_fifo,
56670 + .maxlen = sizeof(int),
56671 + .mode = 0600,
56672 + .proc_handler = &proc_dointvec,
56673 + },
56674 +#endif
56675 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
56676 + {
56677 + .procname = "ptrace_readexec",
56678 + .data = &grsec_enable_ptrace_readexec,
56679 + .maxlen = sizeof(int),
56680 + .mode = 0600,
56681 + .proc_handler = &proc_dointvec,
56682 + },
56683 +#endif
56684 +#ifdef CONFIG_GRKERNSEC_SETXID
56685 + {
56686 + .procname = "consistent_setxid",
56687 + .data = &grsec_enable_setxid,
56688 + .maxlen = sizeof(int),
56689 + .mode = 0600,
56690 + .proc_handler = &proc_dointvec,
56691 + },
56692 +#endif
56693 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
56694 + {
56695 + .procname = "ip_blackhole",
56696 + .data = &grsec_enable_blackhole,
56697 + .maxlen = sizeof(int),
56698 + .mode = 0600,
56699 + .proc_handler = &proc_dointvec,
56700 + },
56701 + {
56702 + .procname = "lastack_retries",
56703 + .data = &grsec_lastack_retries,
56704 + .maxlen = sizeof(int),
56705 + .mode = 0600,
56706 + .proc_handler = &proc_dointvec,
56707 + },
56708 +#endif
56709 +#ifdef CONFIG_GRKERNSEC_EXECLOG
56710 + {
56711 + .procname = "exec_logging",
56712 + .data = &grsec_enable_execlog,
56713 + .maxlen = sizeof(int),
56714 + .mode = 0600,
56715 + .proc_handler = &proc_dointvec,
56716 + },
56717 +#endif
56718 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56719 + {
56720 + .procname = "rwxmap_logging",
56721 + .data = &grsec_enable_log_rwxmaps,
56722 + .maxlen = sizeof(int),
56723 + .mode = 0600,
56724 + .proc_handler = &proc_dointvec,
56725 + },
56726 +#endif
56727 +#ifdef CONFIG_GRKERNSEC_SIGNAL
56728 + {
56729 + .procname = "signal_logging",
56730 + .data = &grsec_enable_signal,
56731 + .maxlen = sizeof(int),
56732 + .mode = 0600,
56733 + .proc_handler = &proc_dointvec,
56734 + },
56735 +#endif
56736 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
56737 + {
56738 + .procname = "forkfail_logging",
56739 + .data = &grsec_enable_forkfail,
56740 + .maxlen = sizeof(int),
56741 + .mode = 0600,
56742 + .proc_handler = &proc_dointvec,
56743 + },
56744 +#endif
56745 +#ifdef CONFIG_GRKERNSEC_TIME
56746 + {
56747 + .procname = "timechange_logging",
56748 + .data = &grsec_enable_time,
56749 + .maxlen = sizeof(int),
56750 + .mode = 0600,
56751 + .proc_handler = &proc_dointvec,
56752 + },
56753 +#endif
56754 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
56755 + {
56756 + .procname = "chroot_deny_shmat",
56757 + .data = &grsec_enable_chroot_shmat,
56758 + .maxlen = sizeof(int),
56759 + .mode = 0600,
56760 + .proc_handler = &proc_dointvec,
56761 + },
56762 +#endif
56763 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
56764 + {
56765 + .procname = "chroot_deny_unix",
56766 + .data = &grsec_enable_chroot_unix,
56767 + .maxlen = sizeof(int),
56768 + .mode = 0600,
56769 + .proc_handler = &proc_dointvec,
56770 + },
56771 +#endif
56772 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
56773 + {
56774 + .procname = "chroot_deny_mount",
56775 + .data = &grsec_enable_chroot_mount,
56776 + .maxlen = sizeof(int),
56777 + .mode = 0600,
56778 + .proc_handler = &proc_dointvec,
56779 + },
56780 +#endif
56781 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
56782 + {
56783 + .procname = "chroot_deny_fchdir",
56784 + .data = &grsec_enable_chroot_fchdir,
56785 + .maxlen = sizeof(int),
56786 + .mode = 0600,
56787 + .proc_handler = &proc_dointvec,
56788 + },
56789 +#endif
56790 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
56791 + {
56792 + .procname = "chroot_deny_chroot",
56793 + .data = &grsec_enable_chroot_double,
56794 + .maxlen = sizeof(int),
56795 + .mode = 0600,
56796 + .proc_handler = &proc_dointvec,
56797 + },
56798 +#endif
56799 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
56800 + {
56801 + .procname = "chroot_deny_pivot",
56802 + .data = &grsec_enable_chroot_pivot,
56803 + .maxlen = sizeof(int),
56804 + .mode = 0600,
56805 + .proc_handler = &proc_dointvec,
56806 + },
56807 +#endif
56808 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
56809 + {
56810 + .procname = "chroot_enforce_chdir",
56811 + .data = &grsec_enable_chroot_chdir,
56812 + .maxlen = sizeof(int),
56813 + .mode = 0600,
56814 + .proc_handler = &proc_dointvec,
56815 + },
56816 +#endif
56817 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
56818 + {
56819 + .procname = "chroot_deny_chmod",
56820 + .data = &grsec_enable_chroot_chmod,
56821 + .maxlen = sizeof(int),
56822 + .mode = 0600,
56823 + .proc_handler = &proc_dointvec,
56824 + },
56825 +#endif
56826 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
56827 + {
56828 + .procname = "chroot_deny_mknod",
56829 + .data = &grsec_enable_chroot_mknod,
56830 + .maxlen = sizeof(int),
56831 + .mode = 0600,
56832 + .proc_handler = &proc_dointvec,
56833 + },
56834 +#endif
56835 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
56836 + {
56837 + .procname = "chroot_restrict_nice",
56838 + .data = &grsec_enable_chroot_nice,
56839 + .maxlen = sizeof(int),
56840 + .mode = 0600,
56841 + .proc_handler = &proc_dointvec,
56842 + },
56843 +#endif
56844 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
56845 + {
56846 + .procname = "chroot_execlog",
56847 + .data = &grsec_enable_chroot_execlog,
56848 + .maxlen = sizeof(int),
56849 + .mode = 0600,
56850 + .proc_handler = &proc_dointvec,
56851 + },
56852 +#endif
56853 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56854 + {
56855 + .procname = "chroot_caps",
56856 + .data = &grsec_enable_chroot_caps,
56857 + .maxlen = sizeof(int),
56858 + .mode = 0600,
56859 + .proc_handler = &proc_dointvec,
56860 + },
56861 +#endif
56862 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
56863 + {
56864 + .procname = "chroot_deny_sysctl",
56865 + .data = &grsec_enable_chroot_sysctl,
56866 + .maxlen = sizeof(int),
56867 + .mode = 0600,
56868 + .proc_handler = &proc_dointvec,
56869 + },
56870 +#endif
56871 +#ifdef CONFIG_GRKERNSEC_TPE
56872 + {
56873 + .procname = "tpe",
56874 + .data = &grsec_enable_tpe,
56875 + .maxlen = sizeof(int),
56876 + .mode = 0600,
56877 + .proc_handler = &proc_dointvec,
56878 + },
56879 + {
56880 + .procname = "tpe_gid",
56881 + .data = &grsec_tpe_gid,
56882 + .maxlen = sizeof(int),
56883 + .mode = 0600,
56884 + .proc_handler = &proc_dointvec,
56885 + },
56886 +#endif
56887 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
56888 + {
56889 + .procname = "tpe_invert",
56890 + .data = &grsec_enable_tpe_invert,
56891 + .maxlen = sizeof(int),
56892 + .mode = 0600,
56893 + .proc_handler = &proc_dointvec,
56894 + },
56895 +#endif
56896 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
56897 + {
56898 + .procname = "tpe_restrict_all",
56899 + .data = &grsec_enable_tpe_all,
56900 + .maxlen = sizeof(int),
56901 + .mode = 0600,
56902 + .proc_handler = &proc_dointvec,
56903 + },
56904 +#endif
56905 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
56906 + {
56907 + .procname = "socket_all",
56908 + .data = &grsec_enable_socket_all,
56909 + .maxlen = sizeof(int),
56910 + .mode = 0600,
56911 + .proc_handler = &proc_dointvec,
56912 + },
56913 + {
56914 + .procname = "socket_all_gid",
56915 + .data = &grsec_socket_all_gid,
56916 + .maxlen = sizeof(int),
56917 + .mode = 0600,
56918 + .proc_handler = &proc_dointvec,
56919 + },
56920 +#endif
56921 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
56922 + {
56923 + .procname = "socket_client",
56924 + .data = &grsec_enable_socket_client,
56925 + .maxlen = sizeof(int),
56926 + .mode = 0600,
56927 + .proc_handler = &proc_dointvec,
56928 + },
56929 + {
56930 + .procname = "socket_client_gid",
56931 + .data = &grsec_socket_client_gid,
56932 + .maxlen = sizeof(int),
56933 + .mode = 0600,
56934 + .proc_handler = &proc_dointvec,
56935 + },
56936 +#endif
56937 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
56938 + {
56939 + .procname = "socket_server",
56940 + .data = &grsec_enable_socket_server,
56941 + .maxlen = sizeof(int),
56942 + .mode = 0600,
56943 + .proc_handler = &proc_dointvec,
56944 + },
56945 + {
56946 + .procname = "socket_server_gid",
56947 + .data = &grsec_socket_server_gid,
56948 + .maxlen = sizeof(int),
56949 + .mode = 0600,
56950 + .proc_handler = &proc_dointvec,
56951 + },
56952 +#endif
56953 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
56954 + {
56955 + .procname = "audit_group",
56956 + .data = &grsec_enable_group,
56957 + .maxlen = sizeof(int),
56958 + .mode = 0600,
56959 + .proc_handler = &proc_dointvec,
56960 + },
56961 + {
56962 + .procname = "audit_gid",
56963 + .data = &grsec_audit_gid,
56964 + .maxlen = sizeof(int),
56965 + .mode = 0600,
56966 + .proc_handler = &proc_dointvec,
56967 + },
56968 +#endif
56969 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
56970 + {
56971 + .procname = "audit_chdir",
56972 + .data = &grsec_enable_chdir,
56973 + .maxlen = sizeof(int),
56974 + .mode = 0600,
56975 + .proc_handler = &proc_dointvec,
56976 + },
56977 +#endif
56978 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
56979 + {
56980 + .procname = "audit_mount",
56981 + .data = &grsec_enable_mount,
56982 + .maxlen = sizeof(int),
56983 + .mode = 0600,
56984 + .proc_handler = &proc_dointvec,
56985 + },
56986 +#endif
56987 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
56988 + {
56989 + .procname = "audit_textrel",
56990 + .data = &grsec_enable_audit_textrel,
56991 + .maxlen = sizeof(int),
56992 + .mode = 0600,
56993 + .proc_handler = &proc_dointvec,
56994 + },
56995 +#endif
56996 +#ifdef CONFIG_GRKERNSEC_DMESG
56997 + {
56998 + .procname = "dmesg",
56999 + .data = &grsec_enable_dmesg,
57000 + .maxlen = sizeof(int),
57001 + .mode = 0600,
57002 + .proc_handler = &proc_dointvec,
57003 + },
57004 +#endif
57005 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57006 + {
57007 + .procname = "chroot_findtask",
57008 + .data = &grsec_enable_chroot_findtask,
57009 + .maxlen = sizeof(int),
57010 + .mode = 0600,
57011 + .proc_handler = &proc_dointvec,
57012 + },
57013 +#endif
57014 +#ifdef CONFIG_GRKERNSEC_RESLOG
57015 + {
57016 + .procname = "resource_logging",
57017 + .data = &grsec_resource_logging,
57018 + .maxlen = sizeof(int),
57019 + .mode = 0600,
57020 + .proc_handler = &proc_dointvec,
57021 + },
57022 +#endif
57023 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
57024 + {
57025 + .procname = "audit_ptrace",
57026 + .data = &grsec_enable_audit_ptrace,
57027 + .maxlen = sizeof(int),
57028 + .mode = 0600,
57029 + .proc_handler = &proc_dointvec,
57030 + },
57031 +#endif
57032 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
57033 + {
57034 + .procname = "harden_ptrace",
57035 + .data = &grsec_enable_harden_ptrace,
57036 + .maxlen = sizeof(int),
57037 + .mode = 0600,
57038 + .proc_handler = &proc_dointvec,
57039 + },
57040 +#endif
57041 + {
57042 + .procname = "grsec_lock",
57043 + .data = &grsec_lock,
57044 + .maxlen = sizeof(int),
57045 + .mode = 0600,
57046 + .proc_handler = &proc_dointvec,
57047 + },
57048 +#endif
57049 +#ifdef CONFIG_GRKERNSEC_ROFS
57050 + {
57051 + .procname = "romount_protect",
57052 + .data = &grsec_enable_rofs,
57053 + .maxlen = sizeof(int),
57054 + .mode = 0600,
57055 + .proc_handler = &proc_dointvec_minmax,
57056 + .extra1 = &one,
57057 + .extra2 = &one,
57058 + },
57059 +#endif
57060 + { }
57061 +};
57062 +#endif
57063 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
57064 new file mode 100644
57065 index 0000000..0dc13c3
57066 --- /dev/null
57067 +++ b/grsecurity/grsec_time.c
57068 @@ -0,0 +1,16 @@
57069 +#include <linux/kernel.h>
57070 +#include <linux/sched.h>
57071 +#include <linux/grinternal.h>
57072 +#include <linux/module.h>
57073 +
57074 +void
57075 +gr_log_timechange(void)
57076 +{
57077 +#ifdef CONFIG_GRKERNSEC_TIME
57078 + if (grsec_enable_time)
57079 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
57080 +#endif
57081 + return;
57082 +}
57083 +
57084 +EXPORT_SYMBOL(gr_log_timechange);
57085 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
57086 new file mode 100644
57087 index 0000000..07e0dc0
57088 --- /dev/null
57089 +++ b/grsecurity/grsec_tpe.c
57090 @@ -0,0 +1,73 @@
57091 +#include <linux/kernel.h>
57092 +#include <linux/sched.h>
57093 +#include <linux/file.h>
57094 +#include <linux/fs.h>
57095 +#include <linux/grinternal.h>
57096 +
57097 +extern int gr_acl_tpe_check(void);
57098 +
57099 +int
57100 +gr_tpe_allow(const struct file *file)
57101 +{
57102 +#ifdef CONFIG_GRKERNSEC
57103 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
57104 + const struct cred *cred = current_cred();
57105 + char *msg = NULL;
57106 + char *msg2 = NULL;
57107 +
57108 + // never restrict root
57109 + if (!cred->uid)
57110 + return 1;
57111 +
57112 + if (grsec_enable_tpe) {
57113 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
57114 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
57115 + msg = "not being in trusted group";
57116 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
57117 + msg = "being in untrusted group";
57118 +#else
57119 + if (in_group_p(grsec_tpe_gid))
57120 + msg = "being in untrusted group";
57121 +#endif
57122 + }
57123 + if (!msg && gr_acl_tpe_check())
57124 + msg = "being in untrusted role";
57125 +
57126 + // not in any affected group/role
57127 + if (!msg)
57128 + goto next_check;
57129 +
57130 + if (inode->i_uid)
57131 + msg2 = "file in non-root-owned directory";
57132 + else if (inode->i_mode & S_IWOTH)
57133 + msg2 = "file in world-writable directory";
57134 + else if (inode->i_mode & S_IWGRP)
57135 + msg2 = "file in group-writable directory";
57136 +
57137 + if (msg && msg2) {
57138 + char fullmsg[70] = {0};
57139 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
57140 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
57141 + return 0;
57142 + }
57143 + msg = NULL;
57144 +next_check:
57145 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
57146 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
57147 + return 1;
57148 +
57149 + if (inode->i_uid && (inode->i_uid != cred->uid))
57150 + msg = "directory not owned by user";
57151 + else if (inode->i_mode & S_IWOTH)
57152 + msg = "file in world-writable directory";
57153 + else if (inode->i_mode & S_IWGRP)
57154 + msg = "file in group-writable directory";
57155 +
57156 + if (msg) {
57157 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
57158 + return 0;
57159 + }
57160 +#endif
57161 +#endif
57162 + return 1;
57163 +}
57164 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
57165 new file mode 100644
57166 index 0000000..9f7b1ac
57167 --- /dev/null
57168 +++ b/grsecurity/grsum.c
57169 @@ -0,0 +1,61 @@
57170 +#include <linux/err.h>
57171 +#include <linux/kernel.h>
57172 +#include <linux/sched.h>
57173 +#include <linux/mm.h>
57174 +#include <linux/scatterlist.h>
57175 +#include <linux/crypto.h>
57176 +#include <linux/gracl.h>
57177 +
57178 +
57179 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
57180 +#error "crypto and sha256 must be built into the kernel"
57181 +#endif
57182 +
57183 +int
57184 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
57185 +{
57186 + char *p;
57187 + struct crypto_hash *tfm;
57188 + struct hash_desc desc;
57189 + struct scatterlist sg;
57190 + unsigned char temp_sum[GR_SHA_LEN];
57191 + volatile int retval = 0;
57192 + volatile int dummy = 0;
57193 + unsigned int i;
57194 +
57195 + sg_init_table(&sg, 1);
57196 +
57197 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
57198 + if (IS_ERR(tfm)) {
57199 + /* should never happen, since sha256 should be built in */
57200 + return 1;
57201 + }
57202 +
57203 + desc.tfm = tfm;
57204 + desc.flags = 0;
57205 +
57206 + crypto_hash_init(&desc);
57207 +
57208 + p = salt;
57209 + sg_set_buf(&sg, p, GR_SALT_LEN);
57210 + crypto_hash_update(&desc, &sg, sg.length);
57211 +
57212 + p = entry->pw;
57213 + sg_set_buf(&sg, p, strlen(p));
57214 +
57215 + crypto_hash_update(&desc, &sg, sg.length);
57216 +
57217 + crypto_hash_final(&desc, temp_sum);
57218 +
57219 + memset(entry->pw, 0, GR_PW_LEN);
57220 +
57221 + for (i = 0; i < GR_SHA_LEN; i++)
57222 + if (sum[i] != temp_sum[i])
57223 + retval = 1;
57224 + else
57225 + dummy = 1; // waste a cycle
57226 +
57227 + crypto_free_hash(tfm);
57228 +
57229 + return retval;
57230 +}
57231 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
57232 index 6cd5b64..f620d2d 100644
57233 --- a/include/acpi/acpi_bus.h
57234 +++ b/include/acpi/acpi_bus.h
57235 @@ -107,7 +107,7 @@ struct acpi_device_ops {
57236 acpi_op_bind bind;
57237 acpi_op_unbind unbind;
57238 acpi_op_notify notify;
57239 -};
57240 +} __no_const;
57241
57242 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
57243
57244 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
57245 index b7babf0..71e4e74 100644
57246 --- a/include/asm-generic/atomic-long.h
57247 +++ b/include/asm-generic/atomic-long.h
57248 @@ -22,6 +22,12 @@
57249
57250 typedef atomic64_t atomic_long_t;
57251
57252 +#ifdef CONFIG_PAX_REFCOUNT
57253 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
57254 +#else
57255 +typedef atomic64_t atomic_long_unchecked_t;
57256 +#endif
57257 +
57258 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
57259
57260 static inline long atomic_long_read(atomic_long_t *l)
57261 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
57262 return (long)atomic64_read(v);
57263 }
57264
57265 +#ifdef CONFIG_PAX_REFCOUNT
57266 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57267 +{
57268 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57269 +
57270 + return (long)atomic64_read_unchecked(v);
57271 +}
57272 +#endif
57273 +
57274 static inline void atomic_long_set(atomic_long_t *l, long i)
57275 {
57276 atomic64_t *v = (atomic64_t *)l;
57277 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
57278 atomic64_set(v, i);
57279 }
57280
57281 +#ifdef CONFIG_PAX_REFCOUNT
57282 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57283 +{
57284 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57285 +
57286 + atomic64_set_unchecked(v, i);
57287 +}
57288 +#endif
57289 +
57290 static inline void atomic_long_inc(atomic_long_t *l)
57291 {
57292 atomic64_t *v = (atomic64_t *)l;
57293 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
57294 atomic64_inc(v);
57295 }
57296
57297 +#ifdef CONFIG_PAX_REFCOUNT
57298 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57299 +{
57300 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57301 +
57302 + atomic64_inc_unchecked(v);
57303 +}
57304 +#endif
57305 +
57306 static inline void atomic_long_dec(atomic_long_t *l)
57307 {
57308 atomic64_t *v = (atomic64_t *)l;
57309 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
57310 atomic64_dec(v);
57311 }
57312
57313 +#ifdef CONFIG_PAX_REFCOUNT
57314 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57315 +{
57316 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57317 +
57318 + atomic64_dec_unchecked(v);
57319 +}
57320 +#endif
57321 +
57322 static inline void atomic_long_add(long i, atomic_long_t *l)
57323 {
57324 atomic64_t *v = (atomic64_t *)l;
57325 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
57326 atomic64_add(i, v);
57327 }
57328
57329 +#ifdef CONFIG_PAX_REFCOUNT
57330 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57331 +{
57332 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57333 +
57334 + atomic64_add_unchecked(i, v);
57335 +}
57336 +#endif
57337 +
57338 static inline void atomic_long_sub(long i, atomic_long_t *l)
57339 {
57340 atomic64_t *v = (atomic64_t *)l;
57341 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
57342 atomic64_sub(i, v);
57343 }
57344
57345 +#ifdef CONFIG_PAX_REFCOUNT
57346 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
57347 +{
57348 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57349 +
57350 + atomic64_sub_unchecked(i, v);
57351 +}
57352 +#endif
57353 +
57354 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
57355 {
57356 atomic64_t *v = (atomic64_t *)l;
57357 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
57358 return (long)atomic64_inc_return(v);
57359 }
57360
57361 +#ifdef CONFIG_PAX_REFCOUNT
57362 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57363 +{
57364 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
57365 +
57366 + return (long)atomic64_inc_return_unchecked(v);
57367 +}
57368 +#endif
57369 +
57370 static inline long atomic_long_dec_return(atomic_long_t *l)
57371 {
57372 atomic64_t *v = (atomic64_t *)l;
57373 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
57374
57375 typedef atomic_t atomic_long_t;
57376
57377 +#ifdef CONFIG_PAX_REFCOUNT
57378 +typedef atomic_unchecked_t atomic_long_unchecked_t;
57379 +#else
57380 +typedef atomic_t atomic_long_unchecked_t;
57381 +#endif
57382 +
57383 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
57384 static inline long atomic_long_read(atomic_long_t *l)
57385 {
57386 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
57387 return (long)atomic_read(v);
57388 }
57389
57390 +#ifdef CONFIG_PAX_REFCOUNT
57391 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
57392 +{
57393 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57394 +
57395 + return (long)atomic_read_unchecked(v);
57396 +}
57397 +#endif
57398 +
57399 static inline void atomic_long_set(atomic_long_t *l, long i)
57400 {
57401 atomic_t *v = (atomic_t *)l;
57402 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
57403 atomic_set(v, i);
57404 }
57405
57406 +#ifdef CONFIG_PAX_REFCOUNT
57407 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
57408 +{
57409 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57410 +
57411 + atomic_set_unchecked(v, i);
57412 +}
57413 +#endif
57414 +
57415 static inline void atomic_long_inc(atomic_long_t *l)
57416 {
57417 atomic_t *v = (atomic_t *)l;
57418 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
57419 atomic_inc(v);
57420 }
57421
57422 +#ifdef CONFIG_PAX_REFCOUNT
57423 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
57424 +{
57425 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57426 +
57427 + atomic_inc_unchecked(v);
57428 +}
57429 +#endif
57430 +
57431 static inline void atomic_long_dec(atomic_long_t *l)
57432 {
57433 atomic_t *v = (atomic_t *)l;
57434 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
57435 atomic_dec(v);
57436 }
57437
57438 +#ifdef CONFIG_PAX_REFCOUNT
57439 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
57440 +{
57441 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57442 +
57443 + atomic_dec_unchecked(v);
57444 +}
57445 +#endif
57446 +
57447 static inline void atomic_long_add(long i, atomic_long_t *l)
57448 {
57449 atomic_t *v = (atomic_t *)l;
57450 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
57451 atomic_add(i, v);
57452 }
57453
57454 +#ifdef CONFIG_PAX_REFCOUNT
57455 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
57456 +{
57457 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57458 +
57459 + atomic_add_unchecked(i, v);
57460 +}
57461 +#endif
57462 +
57463 static inline void atomic_long_sub(long i, atomic_long_t *l)
57464 {
57465 atomic_t *v = (atomic_t *)l;
57466 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
57467 atomic_sub(i, v);
57468 }
57469
57470 +#ifdef CONFIG_PAX_REFCOUNT
57471 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
57472 +{
57473 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57474 +
57475 + atomic_sub_unchecked(i, v);
57476 +}
57477 +#endif
57478 +
57479 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
57480 {
57481 atomic_t *v = (atomic_t *)l;
57482 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
57483 return (long)atomic_inc_return(v);
57484 }
57485
57486 +#ifdef CONFIG_PAX_REFCOUNT
57487 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
57488 +{
57489 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
57490 +
57491 + return (long)atomic_inc_return_unchecked(v);
57492 +}
57493 +#endif
57494 +
57495 static inline long atomic_long_dec_return(atomic_long_t *l)
57496 {
57497 atomic_t *v = (atomic_t *)l;
57498 @@ -255,4 +393,49 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
57499
57500 #endif /* BITS_PER_LONG == 64 */
57501
57502 +#ifdef CONFIG_PAX_REFCOUNT
57503 +static inline void pax_refcount_needs_these_functions(void)
57504 +{
57505 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
57506 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
57507 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
57508 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
57509 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
57510 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
57511 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
57512 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
57513 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
57514 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
57515 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
57516 +
57517 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
57518 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
57519 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
57520 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
57521 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
57522 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
57523 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
57524 +}
57525 +#else
57526 +#define atomic_read_unchecked(v) atomic_read(v)
57527 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
57528 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
57529 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
57530 +#define atomic_inc_unchecked(v) atomic_inc(v)
57531 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
57532 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
57533 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
57534 +#define atomic_dec_unchecked(v) atomic_dec(v)
57535 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
57536 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
57537 +
57538 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
57539 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
57540 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
57541 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
57542 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
57543 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
57544 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
57545 +#endif
57546 +
57547 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
57548 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
57549 index b18ce4f..2ee2843 100644
57550 --- a/include/asm-generic/atomic64.h
57551 +++ b/include/asm-generic/atomic64.h
57552 @@ -16,6 +16,8 @@ typedef struct {
57553 long long counter;
57554 } atomic64_t;
57555
57556 +typedef atomic64_t atomic64_unchecked_t;
57557 +
57558 #define ATOMIC64_INIT(i) { (i) }
57559
57560 extern long long atomic64_read(const atomic64_t *v);
57561 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
57562 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
57563 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
57564
57565 +#define atomic64_read_unchecked(v) atomic64_read(v)
57566 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
57567 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
57568 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
57569 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
57570 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
57571 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
57572 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
57573 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
57574 +
57575 #endif /* _ASM_GENERIC_ATOMIC64_H */
57576 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
57577 index 1bfcfe5..e04c5c9 100644
57578 --- a/include/asm-generic/cache.h
57579 +++ b/include/asm-generic/cache.h
57580 @@ -6,7 +6,7 @@
57581 * cache lines need to provide their own cache.h.
57582 */
57583
57584 -#define L1_CACHE_SHIFT 5
57585 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
57586 +#define L1_CACHE_SHIFT 5UL
57587 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
57588
57589 #endif /* __ASM_GENERIC_CACHE_H */
57590 diff --git a/include/asm-generic/int-l64.h b/include/asm-generic/int-l64.h
57591 index 1ca3efc..e3dc852 100644
57592 --- a/include/asm-generic/int-l64.h
57593 +++ b/include/asm-generic/int-l64.h
57594 @@ -46,6 +46,8 @@ typedef unsigned int u32;
57595 typedef signed long s64;
57596 typedef unsigned long u64;
57597
57598 +typedef unsigned int intoverflow_t __attribute__ ((mode(TI)));
57599 +
57600 #define S8_C(x) x
57601 #define U8_C(x) x ## U
57602 #define S16_C(x) x
57603 diff --git a/include/asm-generic/int-ll64.h b/include/asm-generic/int-ll64.h
57604 index f394147..b6152b9 100644
57605 --- a/include/asm-generic/int-ll64.h
57606 +++ b/include/asm-generic/int-ll64.h
57607 @@ -51,6 +51,8 @@ typedef unsigned int u32;
57608 typedef signed long long s64;
57609 typedef unsigned long long u64;
57610
57611 +typedef unsigned long long intoverflow_t;
57612 +
57613 #define S8_C(x) x
57614 #define U8_C(x) x ## U
57615 #define S16_C(x) x
57616 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
57617 index 0232ccb..13d9165 100644
57618 --- a/include/asm-generic/kmap_types.h
57619 +++ b/include/asm-generic/kmap_types.h
57620 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
57621 KMAP_D(17) KM_NMI,
57622 KMAP_D(18) KM_NMI_PTE,
57623 KMAP_D(19) KM_KDB,
57624 +KMAP_D(20) KM_CLEARPAGE,
57625 /*
57626 * Remember to update debug_kmap_atomic() when adding new kmap types!
57627 */
57628 -KMAP_D(20) KM_TYPE_NR
57629 +KMAP_D(21) KM_TYPE_NR
57630 };
57631
57632 #undef KMAP_D
57633 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
57634 index 725612b..9cc513a 100644
57635 --- a/include/asm-generic/pgtable-nopmd.h
57636 +++ b/include/asm-generic/pgtable-nopmd.h
57637 @@ -1,14 +1,19 @@
57638 #ifndef _PGTABLE_NOPMD_H
57639 #define _PGTABLE_NOPMD_H
57640
57641 -#ifndef __ASSEMBLY__
57642 -
57643 #include <asm-generic/pgtable-nopud.h>
57644
57645 -struct mm_struct;
57646 -
57647 #define __PAGETABLE_PMD_FOLDED
57648
57649 +#define PMD_SHIFT PUD_SHIFT
57650 +#define PTRS_PER_PMD 1
57651 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
57652 +#define PMD_MASK (~(PMD_SIZE-1))
57653 +
57654 +#ifndef __ASSEMBLY__
57655 +
57656 +struct mm_struct;
57657 +
57658 /*
57659 * Having the pmd type consist of a pud gets the size right, and allows
57660 * us to conceptually access the pud entry that this pmd is folded into
57661 @@ -16,11 +21,6 @@ struct mm_struct;
57662 */
57663 typedef struct { pud_t pud; } pmd_t;
57664
57665 -#define PMD_SHIFT PUD_SHIFT
57666 -#define PTRS_PER_PMD 1
57667 -#define PMD_SIZE (1UL << PMD_SHIFT)
57668 -#define PMD_MASK (~(PMD_SIZE-1))
57669 -
57670 /*
57671 * The "pud_xxx()" functions here are trivial for a folded two-level
57672 * setup: the pmd is never bad, and a pmd always exists (as it's folded
57673 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
57674 index 810431d..ccc3638 100644
57675 --- a/include/asm-generic/pgtable-nopud.h
57676 +++ b/include/asm-generic/pgtable-nopud.h
57677 @@ -1,10 +1,15 @@
57678 #ifndef _PGTABLE_NOPUD_H
57679 #define _PGTABLE_NOPUD_H
57680
57681 -#ifndef __ASSEMBLY__
57682 -
57683 #define __PAGETABLE_PUD_FOLDED
57684
57685 +#define PUD_SHIFT PGDIR_SHIFT
57686 +#define PTRS_PER_PUD 1
57687 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
57688 +#define PUD_MASK (~(PUD_SIZE-1))
57689 +
57690 +#ifndef __ASSEMBLY__
57691 +
57692 /*
57693 * Having the pud type consist of a pgd gets the size right, and allows
57694 * us to conceptually access the pgd entry that this pud is folded into
57695 @@ -12,11 +17,6 @@
57696 */
57697 typedef struct { pgd_t pgd; } pud_t;
57698
57699 -#define PUD_SHIFT PGDIR_SHIFT
57700 -#define PTRS_PER_PUD 1
57701 -#define PUD_SIZE (1UL << PUD_SHIFT)
57702 -#define PUD_MASK (~(PUD_SIZE-1))
57703 -
57704 /*
57705 * The "pgd_xxx()" functions here are trivial for a folded two-level
57706 * setup: the pud is never bad, and a pud always exists (as it's folded
57707 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
57708 index 76bff2b..c7a14e2 100644
57709 --- a/include/asm-generic/pgtable.h
57710 +++ b/include/asm-generic/pgtable.h
57711 @@ -443,6 +443,14 @@ static inline int pmd_write(pmd_t pmd)
57712 #endif /* __HAVE_ARCH_PMD_WRITE */
57713 #endif
57714
57715 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
57716 +static inline unsigned long pax_open_kernel(void) { return 0; }
57717 +#endif
57718 +
57719 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
57720 +static inline unsigned long pax_close_kernel(void) { return 0; }
57721 +#endif
57722 +
57723 #endif /* !__ASSEMBLY__ */
57724
57725 #endif /* _ASM_GENERIC_PGTABLE_H */
57726 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
57727 index b5e2e4c..6a5373e 100644
57728 --- a/include/asm-generic/vmlinux.lds.h
57729 +++ b/include/asm-generic/vmlinux.lds.h
57730 @@ -217,6 +217,7 @@
57731 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
57732 VMLINUX_SYMBOL(__start_rodata) = .; \
57733 *(.rodata) *(.rodata.*) \
57734 + *(.data..read_only) \
57735 *(__vermagic) /* Kernel version magic */ \
57736 . = ALIGN(8); \
57737 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
57738 @@ -722,17 +723,18 @@
57739 * section in the linker script will go there too. @phdr should have
57740 * a leading colon.
57741 *
57742 - * Note that this macros defines __per_cpu_load as an absolute symbol.
57743 + * Note that this macros defines per_cpu_load as an absolute symbol.
57744 * If there is no need to put the percpu section at a predetermined
57745 * address, use PERCPU_SECTION.
57746 */
57747 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
57748 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
57749 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
57750 + per_cpu_load = .; \
57751 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
57752 - LOAD_OFFSET) { \
57753 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
57754 PERCPU_INPUT(cacheline) \
57755 } phdr \
57756 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
57757 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
57758
57759 /**
57760 * PERCPU_SECTION - define output section for percpu area, simple version
57761 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
57762 index bf4b2dc..2d0762f 100644
57763 --- a/include/drm/drmP.h
57764 +++ b/include/drm/drmP.h
57765 @@ -72,6 +72,7 @@
57766 #include <linux/workqueue.h>
57767 #include <linux/poll.h>
57768 #include <asm/pgalloc.h>
57769 +#include <asm/local.h>
57770 #include "drm.h"
57771
57772 #include <linux/idr.h>
57773 @@ -1038,7 +1039,7 @@ struct drm_device {
57774
57775 /** \name Usage Counters */
57776 /*@{ */
57777 - int open_count; /**< Outstanding files open */
57778 + local_t open_count; /**< Outstanding files open */
57779 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
57780 atomic_t vma_count; /**< Outstanding vma areas open */
57781 int buf_use; /**< Buffers in use -- cannot alloc */
57782 @@ -1049,7 +1050,7 @@ struct drm_device {
57783 /*@{ */
57784 unsigned long counters;
57785 enum drm_stat_type types[15];
57786 - atomic_t counts[15];
57787 + atomic_unchecked_t counts[15];
57788 /*@} */
57789
57790 struct list_head filelist;
57791 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
57792 index 73b0712..0b7ef2f 100644
57793 --- a/include/drm/drm_crtc_helper.h
57794 +++ b/include/drm/drm_crtc_helper.h
57795 @@ -74,7 +74,7 @@ struct drm_crtc_helper_funcs {
57796
57797 /* disable crtc when not in use - more explicit than dpms off */
57798 void (*disable)(struct drm_crtc *crtc);
57799 -};
57800 +} __no_const;
57801
57802 struct drm_encoder_helper_funcs {
57803 void (*dpms)(struct drm_encoder *encoder, int mode);
57804 @@ -95,7 +95,7 @@ struct drm_encoder_helper_funcs {
57805 struct drm_connector *connector);
57806 /* disable encoder when not in use - more explicit than dpms off */
57807 void (*disable)(struct drm_encoder *encoder);
57808 -};
57809 +} __no_const;
57810
57811 struct drm_connector_helper_funcs {
57812 int (*get_modes)(struct drm_connector *connector);
57813 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
57814 index 26c1f78..6722682 100644
57815 --- a/include/drm/ttm/ttm_memory.h
57816 +++ b/include/drm/ttm/ttm_memory.h
57817 @@ -47,7 +47,7 @@
57818
57819 struct ttm_mem_shrink {
57820 int (*do_shrink) (struct ttm_mem_shrink *);
57821 -};
57822 +} __no_const;
57823
57824 /**
57825 * struct ttm_mem_global - Global memory accounting structure.
57826 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
57827 index e86dfca..40cc55f 100644
57828 --- a/include/linux/a.out.h
57829 +++ b/include/linux/a.out.h
57830 @@ -39,6 +39,14 @@ enum machine_type {
57831 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
57832 };
57833
57834 +/* Constants for the N_FLAGS field */
57835 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
57836 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
57837 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
57838 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
57839 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
57840 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
57841 +
57842 #if !defined (N_MAGIC)
57843 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
57844 #endif
57845 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
57846 index 49a83ca..df96b54 100644
57847 --- a/include/linux/atmdev.h
57848 +++ b/include/linux/atmdev.h
57849 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
57850 #endif
57851
57852 struct k_atm_aal_stats {
57853 -#define __HANDLE_ITEM(i) atomic_t i
57854 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
57855 __AAL_STAT_ITEMS
57856 #undef __HANDLE_ITEM
57857 };
57858 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
57859 index fd88a39..8a801b4 100644
57860 --- a/include/linux/binfmts.h
57861 +++ b/include/linux/binfmts.h
57862 @@ -18,7 +18,7 @@ struct pt_regs;
57863 #define BINPRM_BUF_SIZE 128
57864
57865 #ifdef __KERNEL__
57866 -#include <linux/list.h>
57867 +#include <linux/sched.h>
57868
57869 #define CORENAME_MAX_SIZE 128
57870
57871 @@ -58,6 +58,7 @@ struct linux_binprm {
57872 unsigned interp_flags;
57873 unsigned interp_data;
57874 unsigned long loader, exec;
57875 + char tcomm[TASK_COMM_LEN];
57876 };
57877
57878 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
57879 @@ -88,6 +89,7 @@ struct linux_binfmt {
57880 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
57881 int (*load_shlib)(struct file *);
57882 int (*core_dump)(struct coredump_params *cprm);
57883 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
57884 unsigned long min_coredump; /* minimal dump size */
57885 };
57886
57887 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
57888 index 0ed1eb0..3ab569b 100644
57889 --- a/include/linux/blkdev.h
57890 +++ b/include/linux/blkdev.h
57891 @@ -1315,7 +1315,7 @@ struct block_device_operations {
57892 /* this callback is with swap_lock and sometimes page table lock held */
57893 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
57894 struct module *owner;
57895 -};
57896 +} __do_const;
57897
57898 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
57899 unsigned long);
57900 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
57901 index 4d1a074..88f929a 100644
57902 --- a/include/linux/blktrace_api.h
57903 +++ b/include/linux/blktrace_api.h
57904 @@ -162,7 +162,7 @@ struct blk_trace {
57905 struct dentry *dir;
57906 struct dentry *dropped_file;
57907 struct dentry *msg_file;
57908 - atomic_t dropped;
57909 + atomic_unchecked_t dropped;
57910 };
57911
57912 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
57913 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
57914 index 83195fb..0b0f77d 100644
57915 --- a/include/linux/byteorder/little_endian.h
57916 +++ b/include/linux/byteorder/little_endian.h
57917 @@ -42,51 +42,51 @@
57918
57919 static inline __le64 __cpu_to_le64p(const __u64 *p)
57920 {
57921 - return (__force __le64)*p;
57922 + return (__force const __le64)*p;
57923 }
57924 static inline __u64 __le64_to_cpup(const __le64 *p)
57925 {
57926 - return (__force __u64)*p;
57927 + return (__force const __u64)*p;
57928 }
57929 static inline __le32 __cpu_to_le32p(const __u32 *p)
57930 {
57931 - return (__force __le32)*p;
57932 + return (__force const __le32)*p;
57933 }
57934 static inline __u32 __le32_to_cpup(const __le32 *p)
57935 {
57936 - return (__force __u32)*p;
57937 + return (__force const __u32)*p;
57938 }
57939 static inline __le16 __cpu_to_le16p(const __u16 *p)
57940 {
57941 - return (__force __le16)*p;
57942 + return (__force const __le16)*p;
57943 }
57944 static inline __u16 __le16_to_cpup(const __le16 *p)
57945 {
57946 - return (__force __u16)*p;
57947 + return (__force const __u16)*p;
57948 }
57949 static inline __be64 __cpu_to_be64p(const __u64 *p)
57950 {
57951 - return (__force __be64)__swab64p(p);
57952 + return (__force const __be64)__swab64p(p);
57953 }
57954 static inline __u64 __be64_to_cpup(const __be64 *p)
57955 {
57956 - return __swab64p((__u64 *)p);
57957 + return __swab64p((const __u64 *)p);
57958 }
57959 static inline __be32 __cpu_to_be32p(const __u32 *p)
57960 {
57961 - return (__force __be32)__swab32p(p);
57962 + return (__force const __be32)__swab32p(p);
57963 }
57964 static inline __u32 __be32_to_cpup(const __be32 *p)
57965 {
57966 - return __swab32p((__u32 *)p);
57967 + return __swab32p((const __u32 *)p);
57968 }
57969 static inline __be16 __cpu_to_be16p(const __u16 *p)
57970 {
57971 - return (__force __be16)__swab16p(p);
57972 + return (__force const __be16)__swab16p(p);
57973 }
57974 static inline __u16 __be16_to_cpup(const __be16 *p)
57975 {
57976 - return __swab16p((__u16 *)p);
57977 + return __swab16p((const __u16 *)p);
57978 }
57979 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
57980 #define __le64_to_cpus(x) do { (void)(x); } while (0)
57981 diff --git a/include/linux/cache.h b/include/linux/cache.h
57982 index 4c57065..4307975 100644
57983 --- a/include/linux/cache.h
57984 +++ b/include/linux/cache.h
57985 @@ -16,6 +16,10 @@
57986 #define __read_mostly
57987 #endif
57988
57989 +#ifndef __read_only
57990 +#define __read_only __read_mostly
57991 +#endif
57992 +
57993 #ifndef ____cacheline_aligned
57994 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
57995 #endif
57996 diff --git a/include/linux/capability.h b/include/linux/capability.h
57997 index a63d13d..069bfd5 100644
57998 --- a/include/linux/capability.h
57999 +++ b/include/linux/capability.h
58000 @@ -548,6 +548,9 @@ extern bool capable(int cap);
58001 extern bool ns_capable(struct user_namespace *ns, int cap);
58002 extern bool task_ns_capable(struct task_struct *t, int cap);
58003 extern bool nsown_capable(int cap);
58004 +extern bool task_ns_capable_nolog(struct task_struct *t, int cap);
58005 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
58006 +extern bool capable_nolog(int cap);
58007
58008 /* audit system wants to get cap info from files as well */
58009 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
58010 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
58011 index 04ffb2e..6799180 100644
58012 --- a/include/linux/cleancache.h
58013 +++ b/include/linux/cleancache.h
58014 @@ -31,7 +31,7 @@ struct cleancache_ops {
58015 void (*flush_page)(int, struct cleancache_filekey, pgoff_t);
58016 void (*flush_inode)(int, struct cleancache_filekey);
58017 void (*flush_fs)(int);
58018 -};
58019 +} __no_const;
58020
58021 extern struct cleancache_ops
58022 cleancache_register_ops(struct cleancache_ops *ops);
58023 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
58024 index dfadc96..c0e70c1 100644
58025 --- a/include/linux/compiler-gcc4.h
58026 +++ b/include/linux/compiler-gcc4.h
58027 @@ -31,6 +31,12 @@
58028
58029
58030 #if __GNUC_MINOR__ >= 5
58031 +
58032 +#ifdef CONSTIFY_PLUGIN
58033 +#define __no_const __attribute__((no_const))
58034 +#define __do_const __attribute__((do_const))
58035 +#endif
58036 +
58037 /*
58038 * Mark a position in code as unreachable. This can be used to
58039 * suppress control flow warnings after asm blocks that transfer
58040 @@ -46,6 +52,11 @@
58041 #define __noclone __attribute__((__noclone__))
58042
58043 #endif
58044 +
58045 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
58046 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
58047 +#define __bos0(ptr) __bos((ptr), 0)
58048 +#define __bos1(ptr) __bos((ptr), 1)
58049 #endif
58050
58051 #if __GNUC_MINOR__ > 0
58052 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
58053 index 320d6c9..8573a1c 100644
58054 --- a/include/linux/compiler.h
58055 +++ b/include/linux/compiler.h
58056 @@ -5,31 +5,62 @@
58057
58058 #ifdef __CHECKER__
58059 # define __user __attribute__((noderef, address_space(1)))
58060 +# define __force_user __force __user
58061 # define __kernel __attribute__((address_space(0)))
58062 +# define __force_kernel __force __kernel
58063 # define __safe __attribute__((safe))
58064 # define __force __attribute__((force))
58065 # define __nocast __attribute__((nocast))
58066 # define __iomem __attribute__((noderef, address_space(2)))
58067 +# define __force_iomem __force __iomem
58068 # define __acquires(x) __attribute__((context(x,0,1)))
58069 # define __releases(x) __attribute__((context(x,1,0)))
58070 # define __acquire(x) __context__(x,1)
58071 # define __release(x) __context__(x,-1)
58072 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
58073 # define __percpu __attribute__((noderef, address_space(3)))
58074 +# define __force_percpu __force __percpu
58075 #ifdef CONFIG_SPARSE_RCU_POINTER
58076 # define __rcu __attribute__((noderef, address_space(4)))
58077 +# define __force_rcu __force __rcu
58078 #else
58079 # define __rcu
58080 +# define __force_rcu
58081 #endif
58082 extern void __chk_user_ptr(const volatile void __user *);
58083 extern void __chk_io_ptr(const volatile void __iomem *);
58084 +#elif defined(CHECKER_PLUGIN)
58085 +//# define __user
58086 +//# define __force_user
58087 +//# define __kernel
58088 +//# define __force_kernel
58089 +# define __safe
58090 +# define __force
58091 +# define __nocast
58092 +# define __iomem
58093 +# define __force_iomem
58094 +# define __chk_user_ptr(x) (void)0
58095 +# define __chk_io_ptr(x) (void)0
58096 +# define __builtin_warning(x, y...) (1)
58097 +# define __acquires(x)
58098 +# define __releases(x)
58099 +# define __acquire(x) (void)0
58100 +# define __release(x) (void)0
58101 +# define __cond_lock(x,c) (c)
58102 +# define __percpu
58103 +# define __force_percpu
58104 +# define __rcu
58105 +# define __force_rcu
58106 #else
58107 # define __user
58108 +# define __force_user
58109 # define __kernel
58110 +# define __force_kernel
58111 # define __safe
58112 # define __force
58113 # define __nocast
58114 # define __iomem
58115 +# define __force_iomem
58116 # define __chk_user_ptr(x) (void)0
58117 # define __chk_io_ptr(x) (void)0
58118 # define __builtin_warning(x, y...) (1)
58119 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
58120 # define __release(x) (void)0
58121 # define __cond_lock(x,c) (c)
58122 # define __percpu
58123 +# define __force_percpu
58124 # define __rcu
58125 +# define __force_rcu
58126 #endif
58127
58128 #ifdef __KERNEL__
58129 @@ -264,6 +297,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
58130 # define __attribute_const__ /* unimplemented */
58131 #endif
58132
58133 +#ifndef __no_const
58134 +# define __no_const
58135 +#endif
58136 +
58137 +#ifndef __do_const
58138 +# define __do_const
58139 +#endif
58140 +
58141 /*
58142 * Tell gcc if a function is cold. The compiler will assume any path
58143 * directly leading to the call is unlikely.
58144 @@ -273,6 +314,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
58145 #define __cold
58146 #endif
58147
58148 +#ifndef __alloc_size
58149 +#define __alloc_size(...)
58150 +#endif
58151 +
58152 +#ifndef __bos
58153 +#define __bos(ptr, arg)
58154 +#endif
58155 +
58156 +#ifndef __bos0
58157 +#define __bos0(ptr)
58158 +#endif
58159 +
58160 +#ifndef __bos1
58161 +#define __bos1(ptr)
58162 +#endif
58163 +
58164 /* Simple shorthand for a section definition */
58165 #ifndef __section
58166 # define __section(S) __attribute__ ((__section__(#S)))
58167 @@ -306,6 +363,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
58168 * use is to mediate communication between process-level code and irq/NMI
58169 * handlers, all running on the same CPU.
58170 */
58171 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
58172 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
58173 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
58174
58175 #endif /* __LINUX_COMPILER_H */
58176 diff --git a/include/linux/cpuset.h b/include/linux/cpuset.h
58177 index e9eaec5..bfeb9bb 100644
58178 --- a/include/linux/cpuset.h
58179 +++ b/include/linux/cpuset.h
58180 @@ -118,7 +118,7 @@ static inline void put_mems_allowed(void)
58181 * nodemask.
58182 */
58183 smp_mb();
58184 - --ACCESS_ONCE(current->mems_allowed_change_disable);
58185 + --ACCESS_ONCE_RW(current->mems_allowed_change_disable);
58186 }
58187
58188 static inline void set_mems_allowed(nodemask_t nodemask)
58189 diff --git a/include/linux/cred.h b/include/linux/cred.h
58190 index 4030896..8d6f342 100644
58191 --- a/include/linux/cred.h
58192 +++ b/include/linux/cred.h
58193 @@ -207,6 +207,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
58194 static inline void validate_process_creds(void)
58195 {
58196 }
58197 +static inline void validate_task_creds(struct task_struct *task)
58198 +{
58199 +}
58200 #endif
58201
58202 /**
58203 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
58204 index 8a94217..15d49e3 100644
58205 --- a/include/linux/crypto.h
58206 +++ b/include/linux/crypto.h
58207 @@ -365,7 +365,7 @@ struct cipher_tfm {
58208 const u8 *key, unsigned int keylen);
58209 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58210 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
58211 -};
58212 +} __no_const;
58213
58214 struct hash_tfm {
58215 int (*init)(struct hash_desc *desc);
58216 @@ -386,13 +386,13 @@ struct compress_tfm {
58217 int (*cot_decompress)(struct crypto_tfm *tfm,
58218 const u8 *src, unsigned int slen,
58219 u8 *dst, unsigned int *dlen);
58220 -};
58221 +} __no_const;
58222
58223 struct rng_tfm {
58224 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
58225 unsigned int dlen);
58226 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
58227 -};
58228 +} __no_const;
58229
58230 #define crt_ablkcipher crt_u.ablkcipher
58231 #define crt_aead crt_u.aead
58232 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
58233 index 7925bf0..d5143d2 100644
58234 --- a/include/linux/decompress/mm.h
58235 +++ b/include/linux/decompress/mm.h
58236 @@ -77,7 +77,7 @@ static void free(void *where)
58237 * warnings when not needed (indeed large_malloc / large_free are not
58238 * needed by inflate */
58239
58240 -#define malloc(a) kmalloc(a, GFP_KERNEL)
58241 +#define malloc(a) kmalloc((a), GFP_KERNEL)
58242 #define free(a) kfree(a)
58243
58244 #define large_malloc(a) vmalloc(a)
58245 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
58246 index e13117c..e9fc938 100644
58247 --- a/include/linux/dma-mapping.h
58248 +++ b/include/linux/dma-mapping.h
58249 @@ -46,7 +46,7 @@ struct dma_map_ops {
58250 u64 (*get_required_mask)(struct device *dev);
58251 #endif
58252 int is_phys;
58253 -};
58254 +} __do_const;
58255
58256 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
58257
58258 diff --git a/include/linux/efi.h b/include/linux/efi.h
58259 index 2362a0b..cfaf8fcc 100644
58260 --- a/include/linux/efi.h
58261 +++ b/include/linux/efi.h
58262 @@ -446,7 +446,7 @@ struct efivar_operations {
58263 efi_get_variable_t *get_variable;
58264 efi_get_next_variable_t *get_next_variable;
58265 efi_set_variable_t *set_variable;
58266 -};
58267 +} __no_const;
58268
58269 struct efivars {
58270 /*
58271 diff --git a/include/linux/elf.h b/include/linux/elf.h
58272 index 31f0508..5421c01 100644
58273 --- a/include/linux/elf.h
58274 +++ b/include/linux/elf.h
58275 @@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
58276 #define PT_GNU_EH_FRAME 0x6474e550
58277
58278 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
58279 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
58280 +
58281 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
58282 +
58283 +/* Constants for the e_flags field */
58284 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
58285 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
58286 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
58287 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
58288 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
58289 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
58290
58291 /*
58292 * Extended Numbering
58293 @@ -106,6 +117,8 @@ typedef __s64 Elf64_Sxword;
58294 #define DT_DEBUG 21
58295 #define DT_TEXTREL 22
58296 #define DT_JMPREL 23
58297 +#define DT_FLAGS 30
58298 + #define DF_TEXTREL 0x00000004
58299 #define DT_ENCODING 32
58300 #define OLD_DT_LOOS 0x60000000
58301 #define DT_LOOS 0x6000000d
58302 @@ -252,6 +265,19 @@ typedef struct elf64_hdr {
58303 #define PF_W 0x2
58304 #define PF_X 0x1
58305
58306 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
58307 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
58308 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
58309 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
58310 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
58311 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
58312 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
58313 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
58314 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
58315 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
58316 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
58317 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
58318 +
58319 typedef struct elf32_phdr{
58320 Elf32_Word p_type;
58321 Elf32_Off p_offset;
58322 @@ -344,6 +370,8 @@ typedef struct elf64_shdr {
58323 #define EI_OSABI 7
58324 #define EI_PAD 8
58325
58326 +#define EI_PAX 14
58327 +
58328 #define ELFMAG0 0x7f /* EI_MAG */
58329 #define ELFMAG1 'E'
58330 #define ELFMAG2 'L'
58331 @@ -423,6 +451,7 @@ extern Elf32_Dyn _DYNAMIC [];
58332 #define elf_note elf32_note
58333 #define elf_addr_t Elf32_Off
58334 #define Elf_Half Elf32_Half
58335 +#define elf_dyn Elf32_Dyn
58336
58337 #else
58338
58339 @@ -433,6 +462,7 @@ extern Elf64_Dyn _DYNAMIC [];
58340 #define elf_note elf64_note
58341 #define elf_addr_t Elf64_Off
58342 #define Elf_Half Elf64_Half
58343 +#define elf_dyn Elf64_Dyn
58344
58345 #endif
58346
58347 diff --git a/include/linux/filter.h b/include/linux/filter.h
58348 index 8eeb205..d59bfa2 100644
58349 --- a/include/linux/filter.h
58350 +++ b/include/linux/filter.h
58351 @@ -134,6 +134,7 @@ struct sock_fprog { /* Required for SO_ATTACH_FILTER. */
58352
58353 struct sk_buff;
58354 struct sock;
58355 +struct bpf_jit_work;
58356
58357 struct sk_filter
58358 {
58359 @@ -141,6 +142,9 @@ struct sk_filter
58360 unsigned int len; /* Number of filter blocks */
58361 unsigned int (*bpf_func)(const struct sk_buff *skb,
58362 const struct sock_filter *filter);
58363 +#ifdef CONFIG_BPF_JIT
58364 + struct bpf_jit_work *work;
58365 +#endif
58366 struct rcu_head rcu;
58367 struct sock_filter insns[0];
58368 };
58369 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
58370 index 84ccf8e..2e9b14c 100644
58371 --- a/include/linux/firewire.h
58372 +++ b/include/linux/firewire.h
58373 @@ -428,7 +428,7 @@ struct fw_iso_context {
58374 union {
58375 fw_iso_callback_t sc;
58376 fw_iso_mc_callback_t mc;
58377 - } callback;
58378 + } __no_const callback;
58379 void *callback_data;
58380 };
58381
58382 diff --git a/include/linux/fs.h b/include/linux/fs.h
58383 index e0bc4ff..d79c2fa 100644
58384 --- a/include/linux/fs.h
58385 +++ b/include/linux/fs.h
58386 @@ -1608,7 +1608,8 @@ struct file_operations {
58387 int (*setlease)(struct file *, long, struct file_lock **);
58388 long (*fallocate)(struct file *file, int mode, loff_t offset,
58389 loff_t len);
58390 -};
58391 +} __do_const;
58392 +typedef struct file_operations __no_const file_operations_no_const;
58393
58394 struct inode_operations {
58395 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
58396 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
58397 index 003dc0f..3c4ea97 100644
58398 --- a/include/linux/fs_struct.h
58399 +++ b/include/linux/fs_struct.h
58400 @@ -6,7 +6,7 @@
58401 #include <linux/seqlock.h>
58402
58403 struct fs_struct {
58404 - int users;
58405 + atomic_t users;
58406 spinlock_t lock;
58407 seqcount_t seq;
58408 int umask;
58409 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
58410 index ce31408..b1ad003 100644
58411 --- a/include/linux/fscache-cache.h
58412 +++ b/include/linux/fscache-cache.h
58413 @@ -102,7 +102,7 @@ struct fscache_operation {
58414 fscache_operation_release_t release;
58415 };
58416
58417 -extern atomic_t fscache_op_debug_id;
58418 +extern atomic_unchecked_t fscache_op_debug_id;
58419 extern void fscache_op_work_func(struct work_struct *work);
58420
58421 extern void fscache_enqueue_operation(struct fscache_operation *);
58422 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
58423 {
58424 INIT_WORK(&op->work, fscache_op_work_func);
58425 atomic_set(&op->usage, 1);
58426 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58427 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58428 op->processor = processor;
58429 op->release = release;
58430 INIT_LIST_HEAD(&op->pend_link);
58431 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
58432 index 2a53f10..0187fdf 100644
58433 --- a/include/linux/fsnotify.h
58434 +++ b/include/linux/fsnotify.h
58435 @@ -314,7 +314,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
58436 */
58437 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
58438 {
58439 - return kstrdup(name, GFP_KERNEL);
58440 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
58441 }
58442
58443 /*
58444 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
58445 index 91d0e0a3..035666b 100644
58446 --- a/include/linux/fsnotify_backend.h
58447 +++ b/include/linux/fsnotify_backend.h
58448 @@ -105,6 +105,7 @@ struct fsnotify_ops {
58449 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
58450 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
58451 };
58452 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
58453
58454 /*
58455 * A group is a "thing" that wants to receive notification about filesystem
58456 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
58457 index c3da42d..c70e0df 100644
58458 --- a/include/linux/ftrace_event.h
58459 +++ b/include/linux/ftrace_event.h
58460 @@ -97,7 +97,7 @@ struct trace_event_functions {
58461 trace_print_func raw;
58462 trace_print_func hex;
58463 trace_print_func binary;
58464 -};
58465 +} __no_const;
58466
58467 struct trace_event {
58468 struct hlist_node node;
58469 @@ -254,7 +254,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
58470 extern int trace_add_event_call(struct ftrace_event_call *call);
58471 extern void trace_remove_event_call(struct ftrace_event_call *call);
58472
58473 -#define is_signed_type(type) (((type)(-1)) < 0)
58474 +#define is_signed_type(type) (((type)(-1)) < (type)1)
58475
58476 int trace_set_clr_event(const char *system, const char *event, int set);
58477
58478 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
58479 index 6d18f35..ab71e2c 100644
58480 --- a/include/linux/genhd.h
58481 +++ b/include/linux/genhd.h
58482 @@ -185,7 +185,7 @@ struct gendisk {
58483 struct kobject *slave_dir;
58484
58485 struct timer_rand_state *random;
58486 - atomic_t sync_io; /* RAID */
58487 + atomic_unchecked_t sync_io; /* RAID */
58488 struct disk_events *ev;
58489 #ifdef CONFIG_BLK_DEV_INTEGRITY
58490 struct blk_integrity *integrity;
58491 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
58492 new file mode 100644
58493 index 0000000..8a130b6
58494 --- /dev/null
58495 +++ b/include/linux/gracl.h
58496 @@ -0,0 +1,319 @@
58497 +#ifndef GR_ACL_H
58498 +#define GR_ACL_H
58499 +
58500 +#include <linux/grdefs.h>
58501 +#include <linux/resource.h>
58502 +#include <linux/capability.h>
58503 +#include <linux/dcache.h>
58504 +#include <asm/resource.h>
58505 +
58506 +/* Major status information */
58507 +
58508 +#define GR_VERSION "grsecurity 2.9"
58509 +#define GRSECURITY_VERSION 0x2900
58510 +
58511 +enum {
58512 + GR_SHUTDOWN = 0,
58513 + GR_ENABLE = 1,
58514 + GR_SPROLE = 2,
58515 + GR_RELOAD = 3,
58516 + GR_SEGVMOD = 4,
58517 + GR_STATUS = 5,
58518 + GR_UNSPROLE = 6,
58519 + GR_PASSSET = 7,
58520 + GR_SPROLEPAM = 8,
58521 +};
58522 +
58523 +/* Password setup definitions
58524 + * kernel/grhash.c */
58525 +enum {
58526 + GR_PW_LEN = 128,
58527 + GR_SALT_LEN = 16,
58528 + GR_SHA_LEN = 32,
58529 +};
58530 +
58531 +enum {
58532 + GR_SPROLE_LEN = 64,
58533 +};
58534 +
58535 +enum {
58536 + GR_NO_GLOB = 0,
58537 + GR_REG_GLOB,
58538 + GR_CREATE_GLOB
58539 +};
58540 +
58541 +#define GR_NLIMITS 32
58542 +
58543 +/* Begin Data Structures */
58544 +
58545 +struct sprole_pw {
58546 + unsigned char *rolename;
58547 + unsigned char salt[GR_SALT_LEN];
58548 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
58549 +};
58550 +
58551 +struct name_entry {
58552 + __u32 key;
58553 + ino_t inode;
58554 + dev_t device;
58555 + char *name;
58556 + __u16 len;
58557 + __u8 deleted;
58558 + struct name_entry *prev;
58559 + struct name_entry *next;
58560 +};
58561 +
58562 +struct inodev_entry {
58563 + struct name_entry *nentry;
58564 + struct inodev_entry *prev;
58565 + struct inodev_entry *next;
58566 +};
58567 +
58568 +struct acl_role_db {
58569 + struct acl_role_label **r_hash;
58570 + __u32 r_size;
58571 +};
58572 +
58573 +struct inodev_db {
58574 + struct inodev_entry **i_hash;
58575 + __u32 i_size;
58576 +};
58577 +
58578 +struct name_db {
58579 + struct name_entry **n_hash;
58580 + __u32 n_size;
58581 +};
58582 +
58583 +struct crash_uid {
58584 + uid_t uid;
58585 + unsigned long expires;
58586 +};
58587 +
58588 +struct gr_hash_struct {
58589 + void **table;
58590 + void **nametable;
58591 + void *first;
58592 + __u32 table_size;
58593 + __u32 used_size;
58594 + int type;
58595 +};
58596 +
58597 +/* Userspace Grsecurity ACL data structures */
58598 +
58599 +struct acl_subject_label {
58600 + char *filename;
58601 + ino_t inode;
58602 + dev_t device;
58603 + __u32 mode;
58604 + kernel_cap_t cap_mask;
58605 + kernel_cap_t cap_lower;
58606 + kernel_cap_t cap_invert_audit;
58607 +
58608 + struct rlimit res[GR_NLIMITS];
58609 + __u32 resmask;
58610 +
58611 + __u8 user_trans_type;
58612 + __u8 group_trans_type;
58613 + uid_t *user_transitions;
58614 + gid_t *group_transitions;
58615 + __u16 user_trans_num;
58616 + __u16 group_trans_num;
58617 +
58618 + __u32 sock_families[2];
58619 + __u32 ip_proto[8];
58620 + __u32 ip_type;
58621 + struct acl_ip_label **ips;
58622 + __u32 ip_num;
58623 + __u32 inaddr_any_override;
58624 +
58625 + __u32 crashes;
58626 + unsigned long expires;
58627 +
58628 + struct acl_subject_label *parent_subject;
58629 + struct gr_hash_struct *hash;
58630 + struct acl_subject_label *prev;
58631 + struct acl_subject_label *next;
58632 +
58633 + struct acl_object_label **obj_hash;
58634 + __u32 obj_hash_size;
58635 + __u16 pax_flags;
58636 +};
58637 +
58638 +struct role_allowed_ip {
58639 + __u32 addr;
58640 + __u32 netmask;
58641 +
58642 + struct role_allowed_ip *prev;
58643 + struct role_allowed_ip *next;
58644 +};
58645 +
58646 +struct role_transition {
58647 + char *rolename;
58648 +
58649 + struct role_transition *prev;
58650 + struct role_transition *next;
58651 +};
58652 +
58653 +struct acl_role_label {
58654 + char *rolename;
58655 + uid_t uidgid;
58656 + __u16 roletype;
58657 +
58658 + __u16 auth_attempts;
58659 + unsigned long expires;
58660 +
58661 + struct acl_subject_label *root_label;
58662 + struct gr_hash_struct *hash;
58663 +
58664 + struct acl_role_label *prev;
58665 + struct acl_role_label *next;
58666 +
58667 + struct role_transition *transitions;
58668 + struct role_allowed_ip *allowed_ips;
58669 + uid_t *domain_children;
58670 + __u16 domain_child_num;
58671 +
58672 + umode_t umask;
58673 +
58674 + struct acl_subject_label **subj_hash;
58675 + __u32 subj_hash_size;
58676 +};
58677 +
58678 +struct user_acl_role_db {
58679 + struct acl_role_label **r_table;
58680 + __u32 num_pointers; /* Number of allocations to track */
58681 + __u32 num_roles; /* Number of roles */
58682 + __u32 num_domain_children; /* Number of domain children */
58683 + __u32 num_subjects; /* Number of subjects */
58684 + __u32 num_objects; /* Number of objects */
58685 +};
58686 +
58687 +struct acl_object_label {
58688 + char *filename;
58689 + ino_t inode;
58690 + dev_t device;
58691 + __u32 mode;
58692 +
58693 + struct acl_subject_label *nested;
58694 + struct acl_object_label *globbed;
58695 +
58696 + /* next two structures not used */
58697 +
58698 + struct acl_object_label *prev;
58699 + struct acl_object_label *next;
58700 +};
58701 +
58702 +struct acl_ip_label {
58703 + char *iface;
58704 + __u32 addr;
58705 + __u32 netmask;
58706 + __u16 low, high;
58707 + __u8 mode;
58708 + __u32 type;
58709 + __u32 proto[8];
58710 +
58711 + /* next two structures not used */
58712 +
58713 + struct acl_ip_label *prev;
58714 + struct acl_ip_label *next;
58715 +};
58716 +
58717 +struct gr_arg {
58718 + struct user_acl_role_db role_db;
58719 + unsigned char pw[GR_PW_LEN];
58720 + unsigned char salt[GR_SALT_LEN];
58721 + unsigned char sum[GR_SHA_LEN];
58722 + unsigned char sp_role[GR_SPROLE_LEN];
58723 + struct sprole_pw *sprole_pws;
58724 + dev_t segv_device;
58725 + ino_t segv_inode;
58726 + uid_t segv_uid;
58727 + __u16 num_sprole_pws;
58728 + __u16 mode;
58729 +};
58730 +
58731 +struct gr_arg_wrapper {
58732 + struct gr_arg *arg;
58733 + __u32 version;
58734 + __u32 size;
58735 +};
58736 +
58737 +struct subject_map {
58738 + struct acl_subject_label *user;
58739 + struct acl_subject_label *kernel;
58740 + struct subject_map *prev;
58741 + struct subject_map *next;
58742 +};
58743 +
58744 +struct acl_subj_map_db {
58745 + struct subject_map **s_hash;
58746 + __u32 s_size;
58747 +};
58748 +
58749 +/* End Data Structures Section */
58750 +
58751 +/* Hash functions generated by empirical testing by Brad Spengler
58752 + Makes good use of the low bits of the inode. Generally 0-1 times
58753 + in loop for successful match. 0-3 for unsuccessful match.
58754 + Shift/add algorithm with modulus of table size and an XOR*/
58755 +
58756 +static __inline__ unsigned int
58757 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
58758 +{
58759 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
58760 +}
58761 +
58762 + static __inline__ unsigned int
58763 +shash(const struct acl_subject_label *userp, const unsigned int sz)
58764 +{
58765 + return ((const unsigned long)userp % sz);
58766 +}
58767 +
58768 +static __inline__ unsigned int
58769 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
58770 +{
58771 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
58772 +}
58773 +
58774 +static __inline__ unsigned int
58775 +nhash(const char *name, const __u16 len, const unsigned int sz)
58776 +{
58777 + return full_name_hash((const unsigned char *)name, len) % sz;
58778 +}
58779 +
58780 +#define FOR_EACH_ROLE_START(role) \
58781 + role = role_list; \
58782 + while (role) {
58783 +
58784 +#define FOR_EACH_ROLE_END(role) \
58785 + role = role->prev; \
58786 + }
58787 +
58788 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
58789 + subj = NULL; \
58790 + iter = 0; \
58791 + while (iter < role->subj_hash_size) { \
58792 + if (subj == NULL) \
58793 + subj = role->subj_hash[iter]; \
58794 + if (subj == NULL) { \
58795 + iter++; \
58796 + continue; \
58797 + }
58798 +
58799 +#define FOR_EACH_SUBJECT_END(subj,iter) \
58800 + subj = subj->next; \
58801 + if (subj == NULL) \
58802 + iter++; \
58803 + }
58804 +
58805 +
58806 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
58807 + subj = role->hash->first; \
58808 + while (subj != NULL) {
58809 +
58810 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
58811 + subj = subj->next; \
58812 + }
58813 +
58814 +#endif
58815 +
58816 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
58817 new file mode 100644
58818 index 0000000..323ecf2
58819 --- /dev/null
58820 +++ b/include/linux/gralloc.h
58821 @@ -0,0 +1,9 @@
58822 +#ifndef __GRALLOC_H
58823 +#define __GRALLOC_H
58824 +
58825 +void acl_free_all(void);
58826 +int acl_alloc_stack_init(unsigned long size);
58827 +void *acl_alloc(unsigned long len);
58828 +void *acl_alloc_num(unsigned long num, unsigned long len);
58829 +
58830 +#endif
58831 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
58832 new file mode 100644
58833 index 0000000..b30e9bc
58834 --- /dev/null
58835 +++ b/include/linux/grdefs.h
58836 @@ -0,0 +1,140 @@
58837 +#ifndef GRDEFS_H
58838 +#define GRDEFS_H
58839 +
58840 +/* Begin grsecurity status declarations */
58841 +
58842 +enum {
58843 + GR_READY = 0x01,
58844 + GR_STATUS_INIT = 0x00 // disabled state
58845 +};
58846 +
58847 +/* Begin ACL declarations */
58848 +
58849 +/* Role flags */
58850 +
58851 +enum {
58852 + GR_ROLE_USER = 0x0001,
58853 + GR_ROLE_GROUP = 0x0002,
58854 + GR_ROLE_DEFAULT = 0x0004,
58855 + GR_ROLE_SPECIAL = 0x0008,
58856 + GR_ROLE_AUTH = 0x0010,
58857 + GR_ROLE_NOPW = 0x0020,
58858 + GR_ROLE_GOD = 0x0040,
58859 + GR_ROLE_LEARN = 0x0080,
58860 + GR_ROLE_TPE = 0x0100,
58861 + GR_ROLE_DOMAIN = 0x0200,
58862 + GR_ROLE_PAM = 0x0400,
58863 + GR_ROLE_PERSIST = 0x0800
58864 +};
58865 +
58866 +/* ACL Subject and Object mode flags */
58867 +enum {
58868 + GR_DELETED = 0x80000000
58869 +};
58870 +
58871 +/* ACL Object-only mode flags */
58872 +enum {
58873 + GR_READ = 0x00000001,
58874 + GR_APPEND = 0x00000002,
58875 + GR_WRITE = 0x00000004,
58876 + GR_EXEC = 0x00000008,
58877 + GR_FIND = 0x00000010,
58878 + GR_INHERIT = 0x00000020,
58879 + GR_SETID = 0x00000040,
58880 + GR_CREATE = 0x00000080,
58881 + GR_DELETE = 0x00000100,
58882 + GR_LINK = 0x00000200,
58883 + GR_AUDIT_READ = 0x00000400,
58884 + GR_AUDIT_APPEND = 0x00000800,
58885 + GR_AUDIT_WRITE = 0x00001000,
58886 + GR_AUDIT_EXEC = 0x00002000,
58887 + GR_AUDIT_FIND = 0x00004000,
58888 + GR_AUDIT_INHERIT= 0x00008000,
58889 + GR_AUDIT_SETID = 0x00010000,
58890 + GR_AUDIT_CREATE = 0x00020000,
58891 + GR_AUDIT_DELETE = 0x00040000,
58892 + GR_AUDIT_LINK = 0x00080000,
58893 + GR_PTRACERD = 0x00100000,
58894 + GR_NOPTRACE = 0x00200000,
58895 + GR_SUPPRESS = 0x00400000,
58896 + GR_NOLEARN = 0x00800000,
58897 + GR_INIT_TRANSFER= 0x01000000
58898 +};
58899 +
58900 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
58901 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
58902 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
58903 +
58904 +/* ACL subject-only mode flags */
58905 +enum {
58906 + GR_KILL = 0x00000001,
58907 + GR_VIEW = 0x00000002,
58908 + GR_PROTECTED = 0x00000004,
58909 + GR_LEARN = 0x00000008,
58910 + GR_OVERRIDE = 0x00000010,
58911 + /* just a placeholder, this mode is only used in userspace */
58912 + GR_DUMMY = 0x00000020,
58913 + GR_PROTSHM = 0x00000040,
58914 + GR_KILLPROC = 0x00000080,
58915 + GR_KILLIPPROC = 0x00000100,
58916 + /* just a placeholder, this mode is only used in userspace */
58917 + GR_NOTROJAN = 0x00000200,
58918 + GR_PROTPROCFD = 0x00000400,
58919 + GR_PROCACCT = 0x00000800,
58920 + GR_RELAXPTRACE = 0x00001000,
58921 + GR_NESTED = 0x00002000,
58922 + GR_INHERITLEARN = 0x00004000,
58923 + GR_PROCFIND = 0x00008000,
58924 + GR_POVERRIDE = 0x00010000,
58925 + GR_KERNELAUTH = 0x00020000,
58926 + GR_ATSECURE = 0x00040000,
58927 + GR_SHMEXEC = 0x00080000
58928 +};
58929 +
58930 +enum {
58931 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
58932 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
58933 + GR_PAX_ENABLE_MPROTECT = 0x0004,
58934 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
58935 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
58936 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
58937 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
58938 + GR_PAX_DISABLE_MPROTECT = 0x0400,
58939 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
58940 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
58941 +};
58942 +
58943 +enum {
58944 + GR_ID_USER = 0x01,
58945 + GR_ID_GROUP = 0x02,
58946 +};
58947 +
58948 +enum {
58949 + GR_ID_ALLOW = 0x01,
58950 + GR_ID_DENY = 0x02,
58951 +};
58952 +
58953 +#define GR_CRASH_RES 31
58954 +#define GR_UIDTABLE_MAX 500
58955 +
58956 +/* begin resource learning section */
58957 +enum {
58958 + GR_RLIM_CPU_BUMP = 60,
58959 + GR_RLIM_FSIZE_BUMP = 50000,
58960 + GR_RLIM_DATA_BUMP = 10000,
58961 + GR_RLIM_STACK_BUMP = 1000,
58962 + GR_RLIM_CORE_BUMP = 10000,
58963 + GR_RLIM_RSS_BUMP = 500000,
58964 + GR_RLIM_NPROC_BUMP = 1,
58965 + GR_RLIM_NOFILE_BUMP = 5,
58966 + GR_RLIM_MEMLOCK_BUMP = 50000,
58967 + GR_RLIM_AS_BUMP = 500000,
58968 + GR_RLIM_LOCKS_BUMP = 2,
58969 + GR_RLIM_SIGPENDING_BUMP = 5,
58970 + GR_RLIM_MSGQUEUE_BUMP = 10000,
58971 + GR_RLIM_NICE_BUMP = 1,
58972 + GR_RLIM_RTPRIO_BUMP = 1,
58973 + GR_RLIM_RTTIME_BUMP = 1000000
58974 +};
58975 +
58976 +#endif
58977 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
58978 new file mode 100644
58979 index 0000000..da390f1
58980 --- /dev/null
58981 +++ b/include/linux/grinternal.h
58982 @@ -0,0 +1,221 @@
58983 +#ifndef __GRINTERNAL_H
58984 +#define __GRINTERNAL_H
58985 +
58986 +#ifdef CONFIG_GRKERNSEC
58987 +
58988 +#include <linux/fs.h>
58989 +#include <linux/mnt_namespace.h>
58990 +#include <linux/nsproxy.h>
58991 +#include <linux/gracl.h>
58992 +#include <linux/grdefs.h>
58993 +#include <linux/grmsg.h>
58994 +
58995 +void gr_add_learn_entry(const char *fmt, ...)
58996 + __attribute__ ((format (printf, 1, 2)));
58997 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
58998 + const struct vfsmount *mnt);
58999 +__u32 gr_check_create(const struct dentry *new_dentry,
59000 + const struct dentry *parent,
59001 + const struct vfsmount *mnt, const __u32 mode);
59002 +int gr_check_protected_task(const struct task_struct *task);
59003 +__u32 to_gr_audit(const __u32 reqmode);
59004 +int gr_set_acls(const int type);
59005 +int gr_apply_subject_to_task(struct task_struct *task);
59006 +int gr_acl_is_enabled(void);
59007 +char gr_roletype_to_char(void);
59008 +
59009 +void gr_handle_alertkill(struct task_struct *task);
59010 +char *gr_to_filename(const struct dentry *dentry,
59011 + const struct vfsmount *mnt);
59012 +char *gr_to_filename1(const struct dentry *dentry,
59013 + const struct vfsmount *mnt);
59014 +char *gr_to_filename2(const struct dentry *dentry,
59015 + const struct vfsmount *mnt);
59016 +char *gr_to_filename3(const struct dentry *dentry,
59017 + const struct vfsmount *mnt);
59018 +
59019 +extern int grsec_enable_ptrace_readexec;
59020 +extern int grsec_enable_harden_ptrace;
59021 +extern int grsec_enable_link;
59022 +extern int grsec_enable_fifo;
59023 +extern int grsec_enable_execve;
59024 +extern int grsec_enable_shm;
59025 +extern int grsec_enable_execlog;
59026 +extern int grsec_enable_signal;
59027 +extern int grsec_enable_audit_ptrace;
59028 +extern int grsec_enable_forkfail;
59029 +extern int grsec_enable_time;
59030 +extern int grsec_enable_rofs;
59031 +extern int grsec_enable_chroot_shmat;
59032 +extern int grsec_enable_chroot_mount;
59033 +extern int grsec_enable_chroot_double;
59034 +extern int grsec_enable_chroot_pivot;
59035 +extern int grsec_enable_chroot_chdir;
59036 +extern int grsec_enable_chroot_chmod;
59037 +extern int grsec_enable_chroot_mknod;
59038 +extern int grsec_enable_chroot_fchdir;
59039 +extern int grsec_enable_chroot_nice;
59040 +extern int grsec_enable_chroot_execlog;
59041 +extern int grsec_enable_chroot_caps;
59042 +extern int grsec_enable_chroot_sysctl;
59043 +extern int grsec_enable_chroot_unix;
59044 +extern int grsec_enable_tpe;
59045 +extern int grsec_tpe_gid;
59046 +extern int grsec_enable_tpe_all;
59047 +extern int grsec_enable_tpe_invert;
59048 +extern int grsec_enable_socket_all;
59049 +extern int grsec_socket_all_gid;
59050 +extern int grsec_enable_socket_client;
59051 +extern int grsec_socket_client_gid;
59052 +extern int grsec_enable_socket_server;
59053 +extern int grsec_socket_server_gid;
59054 +extern int grsec_audit_gid;
59055 +extern int grsec_enable_group;
59056 +extern int grsec_enable_audit_textrel;
59057 +extern int grsec_enable_log_rwxmaps;
59058 +extern int grsec_enable_mount;
59059 +extern int grsec_enable_chdir;
59060 +extern int grsec_resource_logging;
59061 +extern int grsec_enable_blackhole;
59062 +extern int grsec_lastack_retries;
59063 +extern int grsec_enable_brute;
59064 +extern int grsec_lock;
59065 +
59066 +extern spinlock_t grsec_alert_lock;
59067 +extern unsigned long grsec_alert_wtime;
59068 +extern unsigned long grsec_alert_fyet;
59069 +
59070 +extern spinlock_t grsec_audit_lock;
59071 +
59072 +extern rwlock_t grsec_exec_file_lock;
59073 +
59074 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
59075 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
59076 + (tsk)->exec_file->f_vfsmnt) : "/")
59077 +
59078 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
59079 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
59080 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
59081 +
59082 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
59083 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
59084 + (tsk)->exec_file->f_vfsmnt) : "/")
59085 +
59086 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
59087 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
59088 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
59089 +
59090 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
59091 +
59092 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
59093 +
59094 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
59095 + (task)->pid, (cred)->uid, \
59096 + (cred)->euid, (cred)->gid, (cred)->egid, \
59097 + gr_parent_task_fullpath(task), \
59098 + (task)->real_parent->comm, (task)->real_parent->pid, \
59099 + (pcred)->uid, (pcred)->euid, \
59100 + (pcred)->gid, (pcred)->egid
59101 +
59102 +#define GR_CHROOT_CAPS {{ \
59103 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
59104 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
59105 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
59106 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
59107 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
59108 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
59109 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
59110 +
59111 +#define security_learn(normal_msg,args...) \
59112 +({ \
59113 + read_lock(&grsec_exec_file_lock); \
59114 + gr_add_learn_entry(normal_msg "\n", ## args); \
59115 + read_unlock(&grsec_exec_file_lock); \
59116 +})
59117 +
59118 +enum {
59119 + GR_DO_AUDIT,
59120 + GR_DONT_AUDIT,
59121 + /* used for non-audit messages that we shouldn't kill the task on */
59122 + GR_DONT_AUDIT_GOOD
59123 +};
59124 +
59125 +enum {
59126 + GR_TTYSNIFF,
59127 + GR_RBAC,
59128 + GR_RBAC_STR,
59129 + GR_STR_RBAC,
59130 + GR_RBAC_MODE2,
59131 + GR_RBAC_MODE3,
59132 + GR_FILENAME,
59133 + GR_SYSCTL_HIDDEN,
59134 + GR_NOARGS,
59135 + GR_ONE_INT,
59136 + GR_ONE_INT_TWO_STR,
59137 + GR_ONE_STR,
59138 + GR_STR_INT,
59139 + GR_TWO_STR_INT,
59140 + GR_TWO_INT,
59141 + GR_TWO_U64,
59142 + GR_THREE_INT,
59143 + GR_FIVE_INT_TWO_STR,
59144 + GR_TWO_STR,
59145 + GR_THREE_STR,
59146 + GR_FOUR_STR,
59147 + GR_STR_FILENAME,
59148 + GR_FILENAME_STR,
59149 + GR_FILENAME_TWO_INT,
59150 + GR_FILENAME_TWO_INT_STR,
59151 + GR_TEXTREL,
59152 + GR_PTRACE,
59153 + GR_RESOURCE,
59154 + GR_CAP,
59155 + GR_SIG,
59156 + GR_SIG2,
59157 + GR_CRASH1,
59158 + GR_CRASH2,
59159 + GR_PSACCT,
59160 + GR_RWXMAP
59161 +};
59162 +
59163 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
59164 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
59165 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
59166 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
59167 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
59168 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
59169 +#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)
59170 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
59171 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
59172 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
59173 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
59174 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
59175 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
59176 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
59177 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
59178 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
59179 +#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)
59180 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
59181 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
59182 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
59183 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
59184 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
59185 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
59186 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
59187 +#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)
59188 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
59189 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
59190 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
59191 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
59192 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
59193 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
59194 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
59195 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
59196 +#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)
59197 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
59198 +
59199 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
59200 +
59201 +#endif
59202 +
59203 +#endif
59204 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
59205 new file mode 100644
59206 index 0000000..f885406
59207 --- /dev/null
59208 +++ b/include/linux/grmsg.h
59209 @@ -0,0 +1,109 @@
59210 +#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"
59211 +#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"
59212 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
59213 +#define GR_STOPMOD_MSG "denied modification of module state by "
59214 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
59215 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
59216 +#define GR_IOPERM_MSG "denied use of ioperm() by "
59217 +#define GR_IOPL_MSG "denied use of iopl() by "
59218 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
59219 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
59220 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
59221 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
59222 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
59223 +#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"
59224 +#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"
59225 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
59226 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
59227 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
59228 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
59229 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
59230 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
59231 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
59232 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
59233 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
59234 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
59235 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
59236 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
59237 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
59238 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
59239 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
59240 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
59241 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
59242 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
59243 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
59244 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
59245 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
59246 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
59247 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
59248 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
59249 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
59250 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
59251 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
59252 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
59253 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
59254 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
59255 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
59256 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
59257 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
59258 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
59259 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
59260 +#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"
59261 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
59262 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
59263 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
59264 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
59265 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
59266 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
59267 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
59268 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
59269 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
59270 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
59271 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
59272 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
59273 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
59274 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
59275 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
59276 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
59277 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
59278 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
59279 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
59280 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
59281 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
59282 +#define GR_NICE_CHROOT_MSG "denied priority change by "
59283 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
59284 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
59285 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
59286 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
59287 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
59288 +#define GR_TIME_MSG "time set by "
59289 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
59290 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
59291 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
59292 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
59293 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
59294 +#define GR_BIND_MSG "denied bind() by "
59295 +#define GR_CONNECT_MSG "denied connect() by "
59296 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
59297 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
59298 +#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"
59299 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
59300 +#define GR_CAP_ACL_MSG "use of %s denied for "
59301 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
59302 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
59303 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
59304 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
59305 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
59306 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
59307 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
59308 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
59309 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
59310 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
59311 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
59312 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
59313 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
59314 +#define GR_VM86_MSG "denied use of vm86 by "
59315 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
59316 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
59317 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
59318 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
59319 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
59320 new file mode 100644
59321 index 0000000..2ccf677
59322 --- /dev/null
59323 +++ b/include/linux/grsecurity.h
59324 @@ -0,0 +1,229 @@
59325 +#ifndef GR_SECURITY_H
59326 +#define GR_SECURITY_H
59327 +#include <linux/fs.h>
59328 +#include <linux/fs_struct.h>
59329 +#include <linux/binfmts.h>
59330 +#include <linux/gracl.h>
59331 +
59332 +/* notify of brain-dead configs */
59333 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59334 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
59335 +#endif
59336 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
59337 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
59338 +#endif
59339 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
59340 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
59341 +#endif
59342 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
59343 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
59344 +#endif
59345 +
59346 +#include <linux/compat.h>
59347 +
59348 +struct user_arg_ptr {
59349 +#ifdef CONFIG_COMPAT
59350 + bool is_compat;
59351 +#endif
59352 + union {
59353 + const char __user *const __user *native;
59354 +#ifdef CONFIG_COMPAT
59355 + compat_uptr_t __user *compat;
59356 +#endif
59357 + } ptr;
59358 +};
59359 +
59360 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
59361 +void gr_handle_brute_check(void);
59362 +void gr_handle_kernel_exploit(void);
59363 +int gr_process_user_ban(void);
59364 +
59365 +char gr_roletype_to_char(void);
59366 +
59367 +int gr_acl_enable_at_secure(void);
59368 +
59369 +int gr_check_user_change(int real, int effective, int fs);
59370 +int gr_check_group_change(int real, int effective, int fs);
59371 +
59372 +void gr_del_task_from_ip_table(struct task_struct *p);
59373 +
59374 +int gr_pid_is_chrooted(struct task_struct *p);
59375 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
59376 +int gr_handle_chroot_nice(void);
59377 +int gr_handle_chroot_sysctl(const int op);
59378 +int gr_handle_chroot_setpriority(struct task_struct *p,
59379 + const int niceval);
59380 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
59381 +int gr_handle_chroot_chroot(const struct dentry *dentry,
59382 + const struct vfsmount *mnt);
59383 +void gr_handle_chroot_chdir(struct path *path);
59384 +int gr_handle_chroot_chmod(const struct dentry *dentry,
59385 + const struct vfsmount *mnt, const int mode);
59386 +int gr_handle_chroot_mknod(const struct dentry *dentry,
59387 + const struct vfsmount *mnt, const int mode);
59388 +int gr_handle_chroot_mount(const struct dentry *dentry,
59389 + const struct vfsmount *mnt,
59390 + const char *dev_name);
59391 +int gr_handle_chroot_pivot(void);
59392 +int gr_handle_chroot_unix(const pid_t pid);
59393 +
59394 +int gr_handle_rawio(const struct inode *inode);
59395 +
59396 +void gr_handle_ioperm(void);
59397 +void gr_handle_iopl(void);
59398 +
59399 +umode_t gr_acl_umask(void);
59400 +
59401 +int gr_tpe_allow(const struct file *file);
59402 +
59403 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
59404 +void gr_clear_chroot_entries(struct task_struct *task);
59405 +
59406 +void gr_log_forkfail(const int retval);
59407 +void gr_log_timechange(void);
59408 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
59409 +void gr_log_chdir(const struct dentry *dentry,
59410 + const struct vfsmount *mnt);
59411 +void gr_log_chroot_exec(const struct dentry *dentry,
59412 + const struct vfsmount *mnt);
59413 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
59414 +void gr_log_remount(const char *devname, const int retval);
59415 +void gr_log_unmount(const char *devname, const int retval);
59416 +void gr_log_mount(const char *from, const char *to, const int retval);
59417 +void gr_log_textrel(struct vm_area_struct *vma);
59418 +void gr_log_rwxmmap(struct file *file);
59419 +void gr_log_rwxmprotect(struct file *file);
59420 +
59421 +int gr_handle_follow_link(const struct inode *parent,
59422 + const struct inode *inode,
59423 + const struct dentry *dentry,
59424 + const struct vfsmount *mnt);
59425 +int gr_handle_fifo(const struct dentry *dentry,
59426 + const struct vfsmount *mnt,
59427 + const struct dentry *dir, const int flag,
59428 + const int acc_mode);
59429 +int gr_handle_hardlink(const struct dentry *dentry,
59430 + const struct vfsmount *mnt,
59431 + struct inode *inode,
59432 + const int mode, const char *to);
59433 +
59434 +int gr_is_capable(const int cap);
59435 +int gr_is_capable_nolog(const int cap);
59436 +void gr_learn_resource(const struct task_struct *task, const int limit,
59437 + const unsigned long wanted, const int gt);
59438 +void gr_copy_label(struct task_struct *tsk);
59439 +void gr_handle_crash(struct task_struct *task, const int sig);
59440 +int gr_handle_signal(const struct task_struct *p, const int sig);
59441 +int gr_check_crash_uid(const uid_t uid);
59442 +int gr_check_protected_task(const struct task_struct *task);
59443 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
59444 +int gr_acl_handle_mmap(const struct file *file,
59445 + const unsigned long prot);
59446 +int gr_acl_handle_mprotect(const struct file *file,
59447 + const unsigned long prot);
59448 +int gr_check_hidden_task(const struct task_struct *tsk);
59449 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
59450 + const struct vfsmount *mnt);
59451 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
59452 + const struct vfsmount *mnt);
59453 +__u32 gr_acl_handle_access(const struct dentry *dentry,
59454 + const struct vfsmount *mnt, const int fmode);
59455 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
59456 + const struct vfsmount *mnt, umode_t *mode);
59457 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
59458 + const struct vfsmount *mnt);
59459 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
59460 + const struct vfsmount *mnt);
59461 +int gr_handle_ptrace(struct task_struct *task, const long request);
59462 +int gr_handle_proc_ptrace(struct task_struct *task);
59463 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
59464 + const struct vfsmount *mnt);
59465 +int gr_check_crash_exec(const struct file *filp);
59466 +int gr_acl_is_enabled(void);
59467 +void gr_set_kernel_label(struct task_struct *task);
59468 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
59469 + const gid_t gid);
59470 +int gr_set_proc_label(const struct dentry *dentry,
59471 + const struct vfsmount *mnt,
59472 + const int unsafe_flags);
59473 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
59474 + const struct vfsmount *mnt);
59475 +__u32 gr_acl_handle_open(const struct dentry *dentry,
59476 + const struct vfsmount *mnt, int acc_mode);
59477 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
59478 + const struct dentry *p_dentry,
59479 + const struct vfsmount *p_mnt,
59480 + int open_flags, int acc_mode, const int imode);
59481 +void gr_handle_create(const struct dentry *dentry,
59482 + const struct vfsmount *mnt);
59483 +void gr_handle_proc_create(const struct dentry *dentry,
59484 + const struct inode *inode);
59485 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
59486 + const struct dentry *parent_dentry,
59487 + const struct vfsmount *parent_mnt,
59488 + const int mode);
59489 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
59490 + const struct dentry *parent_dentry,
59491 + const struct vfsmount *parent_mnt);
59492 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
59493 + const struct vfsmount *mnt);
59494 +void gr_handle_delete(const ino_t ino, const dev_t dev);
59495 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
59496 + const struct vfsmount *mnt);
59497 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
59498 + const struct dentry *parent_dentry,
59499 + const struct vfsmount *parent_mnt,
59500 + const char *from);
59501 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
59502 + const struct dentry *parent_dentry,
59503 + const struct vfsmount *parent_mnt,
59504 + const struct dentry *old_dentry,
59505 + const struct vfsmount *old_mnt, const char *to);
59506 +int gr_acl_handle_rename(struct dentry *new_dentry,
59507 + struct dentry *parent_dentry,
59508 + const struct vfsmount *parent_mnt,
59509 + struct dentry *old_dentry,
59510 + struct inode *old_parent_inode,
59511 + struct vfsmount *old_mnt, const char *newname);
59512 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59513 + struct dentry *old_dentry,
59514 + struct dentry *new_dentry,
59515 + struct vfsmount *mnt, const __u8 replace);
59516 +__u32 gr_check_link(const struct dentry *new_dentry,
59517 + const struct dentry *parent_dentry,
59518 + const struct vfsmount *parent_mnt,
59519 + const struct dentry *old_dentry,
59520 + const struct vfsmount *old_mnt);
59521 +int gr_acl_handle_filldir(const struct file *file, const char *name,
59522 + const unsigned int namelen, const ino_t ino);
59523 +
59524 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
59525 + const struct vfsmount *mnt);
59526 +void gr_acl_handle_exit(void);
59527 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
59528 +int gr_acl_handle_procpidmem(const struct task_struct *task);
59529 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
59530 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
59531 +void gr_audit_ptrace(struct task_struct *task);
59532 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
59533 +
59534 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
59535 +
59536 +#ifdef CONFIG_GRKERNSEC
59537 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
59538 +void gr_handle_vm86(void);
59539 +void gr_handle_mem_readwrite(u64 from, u64 to);
59540 +
59541 +void gr_log_badprocpid(const char *entry);
59542 +
59543 +extern int grsec_enable_dmesg;
59544 +extern int grsec_disable_privio;
59545 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59546 +extern int grsec_enable_chroot_findtask;
59547 +#endif
59548 +#ifdef CONFIG_GRKERNSEC_SETXID
59549 +extern int grsec_enable_setxid;
59550 +#endif
59551 +#endif
59552 +
59553 +#endif
59554 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
59555 new file mode 100644
59556 index 0000000..e7ffaaf
59557 --- /dev/null
59558 +++ b/include/linux/grsock.h
59559 @@ -0,0 +1,19 @@
59560 +#ifndef __GRSOCK_H
59561 +#define __GRSOCK_H
59562 +
59563 +extern void gr_attach_curr_ip(const struct sock *sk);
59564 +extern int gr_handle_sock_all(const int family, const int type,
59565 + const int protocol);
59566 +extern int gr_handle_sock_server(const struct sockaddr *sck);
59567 +extern int gr_handle_sock_server_other(const struct sock *sck);
59568 +extern int gr_handle_sock_client(const struct sockaddr *sck);
59569 +extern int gr_search_connect(struct socket * sock,
59570 + struct sockaddr_in * addr);
59571 +extern int gr_search_bind(struct socket * sock,
59572 + struct sockaddr_in * addr);
59573 +extern int gr_search_listen(struct socket * sock);
59574 +extern int gr_search_accept(struct socket * sock);
59575 +extern int gr_search_socket(const int domain, const int type,
59576 + const int protocol);
59577 +
59578 +#endif
59579 diff --git a/include/linux/hid.h b/include/linux/hid.h
59580 index c235e4e..f0cf7a0 100644
59581 --- a/include/linux/hid.h
59582 +++ b/include/linux/hid.h
59583 @@ -679,7 +679,7 @@ struct hid_ll_driver {
59584 unsigned int code, int value);
59585
59586 int (*parse)(struct hid_device *hdev);
59587 -};
59588 +} __no_const;
59589
59590 #define PM_HINT_FULLON 1<<5
59591 #define PM_HINT_NORMAL 1<<1
59592 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
59593 index 3a93f73..b19d0b3 100644
59594 --- a/include/linux/highmem.h
59595 +++ b/include/linux/highmem.h
59596 @@ -185,6 +185,18 @@ static inline void clear_highpage(struct page *page)
59597 kunmap_atomic(kaddr, KM_USER0);
59598 }
59599
59600 +static inline void sanitize_highpage(struct page *page)
59601 +{
59602 + void *kaddr;
59603 + unsigned long flags;
59604 +
59605 + local_irq_save(flags);
59606 + kaddr = kmap_atomic(page, KM_CLEARPAGE);
59607 + clear_page(kaddr);
59608 + kunmap_atomic(kaddr, KM_CLEARPAGE);
59609 + local_irq_restore(flags);
59610 +}
59611 +
59612 static inline void zero_user_segments(struct page *page,
59613 unsigned start1, unsigned end1,
59614 unsigned start2, unsigned end2)
59615 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
59616 index 07d103a..04ec65b 100644
59617 --- a/include/linux/i2c.h
59618 +++ b/include/linux/i2c.h
59619 @@ -364,6 +364,7 @@ struct i2c_algorithm {
59620 /* To determine what the adapter supports */
59621 u32 (*functionality) (struct i2c_adapter *);
59622 };
59623 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
59624
59625 /*
59626 * i2c_adapter is the structure used to identify a physical i2c bus along
59627 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
59628 index a6deef4..c56a7f2 100644
59629 --- a/include/linux/i2o.h
59630 +++ b/include/linux/i2o.h
59631 @@ -564,7 +564,7 @@ struct i2o_controller {
59632 struct i2o_device *exec; /* Executive */
59633 #if BITS_PER_LONG == 64
59634 spinlock_t context_list_lock; /* lock for context_list */
59635 - atomic_t context_list_counter; /* needed for unique contexts */
59636 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
59637 struct list_head context_list; /* list of context id's
59638 and pointers */
59639 #endif
59640 diff --git a/include/linux/init.h b/include/linux/init.h
59641 index 9146f39..885354d 100644
59642 --- a/include/linux/init.h
59643 +++ b/include/linux/init.h
59644 @@ -293,13 +293,13 @@ void __init parse_early_options(char *cmdline);
59645
59646 /* Each module must use one module_init(). */
59647 #define module_init(initfn) \
59648 - static inline initcall_t __inittest(void) \
59649 + static inline __used initcall_t __inittest(void) \
59650 { return initfn; } \
59651 int init_module(void) __attribute__((alias(#initfn)));
59652
59653 /* This is only required if you want to be unloadable. */
59654 #define module_exit(exitfn) \
59655 - static inline exitcall_t __exittest(void) \
59656 + static inline __used exitcall_t __exittest(void) \
59657 { return exitfn; } \
59658 void cleanup_module(void) __attribute__((alias(#exitfn)));
59659
59660 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
59661 index 32574ee..00d4ef1 100644
59662 --- a/include/linux/init_task.h
59663 +++ b/include/linux/init_task.h
59664 @@ -128,6 +128,12 @@ extern struct cred init_cred;
59665
59666 #define INIT_TASK_COMM "swapper"
59667
59668 +#ifdef CONFIG_X86
59669 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
59670 +#else
59671 +#define INIT_TASK_THREAD_INFO
59672 +#endif
59673 +
59674 /*
59675 * INIT_TASK is used to set up the first task table, touch at
59676 * your own risk!. Base=0, limit=0x1fffff (=2MB)
59677 @@ -166,6 +172,7 @@ extern struct cred init_cred;
59678 RCU_INIT_POINTER(.cred, &init_cred), \
59679 .comm = INIT_TASK_COMM, \
59680 .thread = INIT_THREAD, \
59681 + INIT_TASK_THREAD_INFO \
59682 .fs = &init_fs, \
59683 .files = &init_files, \
59684 .signal = &init_signals, \
59685 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
59686 index e6ca56d..8583707 100644
59687 --- a/include/linux/intel-iommu.h
59688 +++ b/include/linux/intel-iommu.h
59689 @@ -296,7 +296,7 @@ struct iommu_flush {
59690 u8 fm, u64 type);
59691 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
59692 unsigned int size_order, u64 type);
59693 -};
59694 +} __no_const;
59695
59696 enum {
59697 SR_DMAR_FECTL_REG,
59698 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
59699 index a64b00e..464d8bc 100644
59700 --- a/include/linux/interrupt.h
59701 +++ b/include/linux/interrupt.h
59702 @@ -441,7 +441,7 @@ enum
59703 /* map softirq index to softirq name. update 'softirq_to_name' in
59704 * kernel/softirq.c when adding a new softirq.
59705 */
59706 -extern char *softirq_to_name[NR_SOFTIRQS];
59707 +extern const char * const softirq_to_name[NR_SOFTIRQS];
59708
59709 /* softirq mask and active fields moved to irq_cpustat_t in
59710 * asm/hardirq.h to get better cache usage. KAO
59711 @@ -449,12 +449,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
59712
59713 struct softirq_action
59714 {
59715 - void (*action)(struct softirq_action *);
59716 + void (*action)(void);
59717 };
59718
59719 asmlinkage void do_softirq(void);
59720 asmlinkage void __do_softirq(void);
59721 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
59722 +extern void open_softirq(int nr, void (*action)(void));
59723 extern void softirq_init(void);
59724 static inline void __raise_softirq_irqoff(unsigned int nr)
59725 {
59726 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
59727 index 3875719..4cd454c 100644
59728 --- a/include/linux/kallsyms.h
59729 +++ b/include/linux/kallsyms.h
59730 @@ -15,7 +15,8 @@
59731
59732 struct module;
59733
59734 -#ifdef CONFIG_KALLSYMS
59735 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
59736 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59737 /* Lookup the address for a symbol. Returns 0 if not found. */
59738 unsigned long kallsyms_lookup_name(const char *name);
59739
59740 @@ -99,6 +100,16 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
59741 /* Stupid that this does nothing, but I didn't create this mess. */
59742 #define __print_symbol(fmt, addr)
59743 #endif /*CONFIG_KALLSYMS*/
59744 +#else /* when included by kallsyms.c, vsnprintf.c, or
59745 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
59746 +extern void __print_symbol(const char *fmt, unsigned long address);
59747 +extern int sprint_backtrace(char *buffer, unsigned long address);
59748 +extern int sprint_symbol(char *buffer, unsigned long address);
59749 +const char *kallsyms_lookup(unsigned long addr,
59750 + unsigned long *symbolsize,
59751 + unsigned long *offset,
59752 + char **modname, char *namebuf);
59753 +#endif
59754
59755 /* This macro allows us to keep printk typechecking */
59756 static __printf(1, 2)
59757 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
59758 index fa39183..40160be 100644
59759 --- a/include/linux/kgdb.h
59760 +++ b/include/linux/kgdb.h
59761 @@ -53,7 +53,7 @@ extern int kgdb_connected;
59762 extern int kgdb_io_module_registered;
59763
59764 extern atomic_t kgdb_setting_breakpoint;
59765 -extern atomic_t kgdb_cpu_doing_single_step;
59766 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
59767
59768 extern struct task_struct *kgdb_usethread;
59769 extern struct task_struct *kgdb_contthread;
59770 @@ -251,7 +251,7 @@ struct kgdb_arch {
59771 void (*disable_hw_break)(struct pt_regs *regs);
59772 void (*remove_all_hw_break)(void);
59773 void (*correct_hw_break)(void);
59774 -};
59775 +} __do_const;
59776
59777 /**
59778 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
59779 @@ -276,7 +276,7 @@ struct kgdb_io {
59780 void (*pre_exception) (void);
59781 void (*post_exception) (void);
59782 int is_console;
59783 -};
59784 +} __do_const;
59785
59786 extern struct kgdb_arch arch_kgdb_ops;
59787
59788 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
59789 index b16f653..eb908f4 100644
59790 --- a/include/linux/kmod.h
59791 +++ b/include/linux/kmod.h
59792 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
59793 * usually useless though. */
59794 extern __printf(2, 3)
59795 int __request_module(bool wait, const char *name, ...);
59796 +extern __printf(3, 4)
59797 +int ___request_module(bool wait, char *param_name, const char *name, ...);
59798 #define request_module(mod...) __request_module(true, mod)
59799 #define request_module_nowait(mod...) __request_module(false, mod)
59800 #define try_then_request_module(x, mod...) \
59801 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
59802 index d526231..086e89b 100644
59803 --- a/include/linux/kvm_host.h
59804 +++ b/include/linux/kvm_host.h
59805 @@ -308,7 +308,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
59806 void vcpu_load(struct kvm_vcpu *vcpu);
59807 void vcpu_put(struct kvm_vcpu *vcpu);
59808
59809 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
59810 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
59811 struct module *module);
59812 void kvm_exit(void);
59813
59814 @@ -454,7 +454,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
59815 struct kvm_guest_debug *dbg);
59816 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
59817
59818 -int kvm_arch_init(void *opaque);
59819 +int kvm_arch_init(const void *opaque);
59820 void kvm_arch_exit(void);
59821
59822 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
59823 diff --git a/include/linux/libata.h b/include/linux/libata.h
59824 index cafc09a..d7e7829 100644
59825 --- a/include/linux/libata.h
59826 +++ b/include/linux/libata.h
59827 @@ -909,7 +909,7 @@ struct ata_port_operations {
59828 * fields must be pointers.
59829 */
59830 const struct ata_port_operations *inherits;
59831 -};
59832 +} __do_const;
59833
59834 struct ata_port_info {
59835 unsigned long flags;
59836 diff --git a/include/linux/mca.h b/include/linux/mca.h
59837 index 3797270..7765ede 100644
59838 --- a/include/linux/mca.h
59839 +++ b/include/linux/mca.h
59840 @@ -80,7 +80,7 @@ struct mca_bus_accessor_functions {
59841 int region);
59842 void * (*mca_transform_memory)(struct mca_device *,
59843 void *memory);
59844 -};
59845 +} __no_const;
59846
59847 struct mca_bus {
59848 u64 default_dma_mask;
59849 diff --git a/include/linux/memory.h b/include/linux/memory.h
59850 index 935699b..11042cc 100644
59851 --- a/include/linux/memory.h
59852 +++ b/include/linux/memory.h
59853 @@ -144,7 +144,7 @@ struct memory_accessor {
59854 size_t count);
59855 ssize_t (*write)(struct memory_accessor *, const char *buf,
59856 off_t offset, size_t count);
59857 -};
59858 +} __no_const;
59859
59860 /*
59861 * Kernel text modification mutex, used for code patching. Users of this lock
59862 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
59863 index 9970337..9444122 100644
59864 --- a/include/linux/mfd/abx500.h
59865 +++ b/include/linux/mfd/abx500.h
59866 @@ -188,6 +188,7 @@ struct abx500_ops {
59867 int (*event_registers_startup_state_get) (struct device *, u8 *);
59868 int (*startup_irq_enabled) (struct device *, unsigned int);
59869 };
59870 +typedef struct abx500_ops __no_const abx500_ops_no_const;
59871
59872 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
59873 void abx500_remove_ops(struct device *dev);
59874 diff --git a/include/linux/mm.h b/include/linux/mm.h
59875 index 4baadd1..2e0b45e 100644
59876 --- a/include/linux/mm.h
59877 +++ b/include/linux/mm.h
59878 @@ -115,7 +115,14 @@ extern unsigned int kobjsize(const void *objp);
59879
59880 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
59881 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
59882 +
59883 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
59884 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
59885 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
59886 +#else
59887 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
59888 +#endif
59889 +
59890 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
59891 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
59892
59893 @@ -1012,34 +1019,6 @@ int set_page_dirty(struct page *page);
59894 int set_page_dirty_lock(struct page *page);
59895 int clear_page_dirty_for_io(struct page *page);
59896
59897 -/* Is the vma a continuation of the stack vma above it? */
59898 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
59899 -{
59900 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
59901 -}
59902 -
59903 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
59904 - unsigned long addr)
59905 -{
59906 - return (vma->vm_flags & VM_GROWSDOWN) &&
59907 - (vma->vm_start == addr) &&
59908 - !vma_growsdown(vma->vm_prev, addr);
59909 -}
59910 -
59911 -/* Is the vma a continuation of the stack vma below it? */
59912 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
59913 -{
59914 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
59915 -}
59916 -
59917 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
59918 - unsigned long addr)
59919 -{
59920 - return (vma->vm_flags & VM_GROWSUP) &&
59921 - (vma->vm_end == addr) &&
59922 - !vma_growsup(vma->vm_next, addr);
59923 -}
59924 -
59925 extern unsigned long move_page_tables(struct vm_area_struct *vma,
59926 unsigned long old_addr, struct vm_area_struct *new_vma,
59927 unsigned long new_addr, unsigned long len);
59928 @@ -1134,6 +1113,15 @@ static inline void sync_mm_rss(struct task_struct *task, struct mm_struct *mm)
59929 }
59930 #endif
59931
59932 +#ifdef CONFIG_MMU
59933 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
59934 +#else
59935 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
59936 +{
59937 + return __pgprot(0);
59938 +}
59939 +#endif
59940 +
59941 int vma_wants_writenotify(struct vm_area_struct *vma);
59942
59943 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
59944 @@ -1419,6 +1407,7 @@ out:
59945 }
59946
59947 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
59948 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
59949
59950 extern unsigned long do_brk(unsigned long, unsigned long);
59951
59952 @@ -1476,6 +1465,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
59953 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
59954 struct vm_area_struct **pprev);
59955
59956 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
59957 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
59958 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
59959 +
59960 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
59961 NULL if none. Assume start_addr < end_addr. */
59962 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
59963 @@ -1492,15 +1485,6 @@ static inline unsigned long vma_pages(struct vm_area_struct *vma)
59964 return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
59965 }
59966
59967 -#ifdef CONFIG_MMU
59968 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
59969 -#else
59970 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
59971 -{
59972 - return __pgprot(0);
59973 -}
59974 -#endif
59975 -
59976 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
59977 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
59978 unsigned long pfn, unsigned long size, pgprot_t);
59979 @@ -1614,7 +1598,7 @@ extern int unpoison_memory(unsigned long pfn);
59980 extern int sysctl_memory_failure_early_kill;
59981 extern int sysctl_memory_failure_recovery;
59982 extern void shake_page(struct page *p, int access);
59983 -extern atomic_long_t mce_bad_pages;
59984 +extern atomic_long_unchecked_t mce_bad_pages;
59985 extern int soft_offline_page(struct page *page, int flags);
59986
59987 extern void dump_page(struct page *page);
59988 @@ -1628,5 +1612,11 @@ extern void copy_user_huge_page(struct page *dst, struct page *src,
59989 unsigned int pages_per_huge_page);
59990 #endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
59991
59992 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59993 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
59994 +#else
59995 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
59996 +#endif
59997 +
59998 #endif /* __KERNEL__ */
59999 #endif /* _LINUX_MM_H */
60000 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
60001 index 5b42f1b..759e4b4 100644
60002 --- a/include/linux/mm_types.h
60003 +++ b/include/linux/mm_types.h
60004 @@ -253,6 +253,8 @@ struct vm_area_struct {
60005 #ifdef CONFIG_NUMA
60006 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
60007 #endif
60008 +
60009 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
60010 };
60011
60012 struct core_thread {
60013 @@ -389,6 +391,24 @@ struct mm_struct {
60014 #ifdef CONFIG_CPUMASK_OFFSTACK
60015 struct cpumask cpumask_allocation;
60016 #endif
60017 +
60018 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60019 + unsigned long pax_flags;
60020 +#endif
60021 +
60022 +#ifdef CONFIG_PAX_DLRESOLVE
60023 + unsigned long call_dl_resolve;
60024 +#endif
60025 +
60026 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
60027 + unsigned long call_syscall;
60028 +#endif
60029 +
60030 +#ifdef CONFIG_PAX_ASLR
60031 + unsigned long delta_mmap; /* randomized offset */
60032 + unsigned long delta_stack; /* randomized offset */
60033 +#endif
60034 +
60035 };
60036
60037 static inline void mm_init_cpumask(struct mm_struct *mm)
60038 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
60039 index 1d1b1e1..2a13c78 100644
60040 --- a/include/linux/mmu_notifier.h
60041 +++ b/include/linux/mmu_notifier.h
60042 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
60043 */
60044 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
60045 ({ \
60046 - pte_t __pte; \
60047 + pte_t ___pte; \
60048 struct vm_area_struct *___vma = __vma; \
60049 unsigned long ___address = __address; \
60050 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
60051 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
60052 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
60053 - __pte; \
60054 + ___pte; \
60055 })
60056
60057 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
60058 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
60059 index 188cb2f..d78409b 100644
60060 --- a/include/linux/mmzone.h
60061 +++ b/include/linux/mmzone.h
60062 @@ -369,7 +369,7 @@ struct zone {
60063 unsigned long flags; /* zone flags, see below */
60064
60065 /* Zone statistics */
60066 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
60067 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
60068
60069 /*
60070 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
60071 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
60072 index 468819c..17b9db3 100644
60073 --- a/include/linux/mod_devicetable.h
60074 +++ b/include/linux/mod_devicetable.h
60075 @@ -12,7 +12,7 @@
60076 typedef unsigned long kernel_ulong_t;
60077 #endif
60078
60079 -#define PCI_ANY_ID (~0)
60080 +#define PCI_ANY_ID ((__u16)~0)
60081
60082 struct pci_device_id {
60083 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
60084 @@ -131,7 +131,7 @@ struct usb_device_id {
60085 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
60086 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
60087
60088 -#define HID_ANY_ID (~0)
60089 +#define HID_ANY_ID (~0U)
60090
60091 struct hid_device_id {
60092 __u16 bus;
60093 diff --git a/include/linux/module.h b/include/linux/module.h
60094 index 3cb7839..511cb87 100644
60095 --- a/include/linux/module.h
60096 +++ b/include/linux/module.h
60097 @@ -17,6 +17,7 @@
60098 #include <linux/moduleparam.h>
60099 #include <linux/tracepoint.h>
60100 #include <linux/export.h>
60101 +#include <linux/fs.h>
60102
60103 #include <linux/percpu.h>
60104 #include <asm/module.h>
60105 @@ -261,19 +262,16 @@ struct module
60106 int (*init)(void);
60107
60108 /* If this is non-NULL, vfree after init() returns */
60109 - void *module_init;
60110 + void *module_init_rx, *module_init_rw;
60111
60112 /* Here is the actual code + data, vfree'd on unload. */
60113 - void *module_core;
60114 + void *module_core_rx, *module_core_rw;
60115
60116 /* Here are the sizes of the init and core sections */
60117 - unsigned int init_size, core_size;
60118 + unsigned int init_size_rw, core_size_rw;
60119
60120 /* The size of the executable code in each section. */
60121 - unsigned int init_text_size, core_text_size;
60122 -
60123 - /* Size of RO sections of the module (text+rodata) */
60124 - unsigned int init_ro_size, core_ro_size;
60125 + unsigned int init_size_rx, core_size_rx;
60126
60127 /* Arch-specific module values */
60128 struct mod_arch_specific arch;
60129 @@ -329,6 +327,10 @@ struct module
60130 #ifdef CONFIG_EVENT_TRACING
60131 struct ftrace_event_call **trace_events;
60132 unsigned int num_trace_events;
60133 + struct file_operations trace_id;
60134 + struct file_operations trace_enable;
60135 + struct file_operations trace_format;
60136 + struct file_operations trace_filter;
60137 #endif
60138 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
60139 unsigned int num_ftrace_callsites;
60140 @@ -379,16 +381,46 @@ bool is_module_address(unsigned long addr);
60141 bool is_module_percpu_address(unsigned long addr);
60142 bool is_module_text_address(unsigned long addr);
60143
60144 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
60145 +{
60146 +
60147 +#ifdef CONFIG_PAX_KERNEXEC
60148 + if (ktla_ktva(addr) >= (unsigned long)start &&
60149 + ktla_ktva(addr) < (unsigned long)start + size)
60150 + return 1;
60151 +#endif
60152 +
60153 + return ((void *)addr >= start && (void *)addr < start + size);
60154 +}
60155 +
60156 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
60157 +{
60158 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
60159 +}
60160 +
60161 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
60162 +{
60163 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
60164 +}
60165 +
60166 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
60167 +{
60168 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
60169 +}
60170 +
60171 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
60172 +{
60173 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
60174 +}
60175 +
60176 static inline int within_module_core(unsigned long addr, struct module *mod)
60177 {
60178 - return (unsigned long)mod->module_core <= addr &&
60179 - addr < (unsigned long)mod->module_core + mod->core_size;
60180 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
60181 }
60182
60183 static inline int within_module_init(unsigned long addr, struct module *mod)
60184 {
60185 - return (unsigned long)mod->module_init <= addr &&
60186 - addr < (unsigned long)mod->module_init + mod->init_size;
60187 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
60188 }
60189
60190 /* Search for module by name: must hold module_mutex. */
60191 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
60192 index b2be02e..6a9fdb1 100644
60193 --- a/include/linux/moduleloader.h
60194 +++ b/include/linux/moduleloader.h
60195 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
60196 sections. Returns NULL on failure. */
60197 void *module_alloc(unsigned long size);
60198
60199 +#ifdef CONFIG_PAX_KERNEXEC
60200 +void *module_alloc_exec(unsigned long size);
60201 +#else
60202 +#define module_alloc_exec(x) module_alloc(x)
60203 +#endif
60204 +
60205 /* Free memory returned from module_alloc. */
60206 void module_free(struct module *mod, void *module_region);
60207
60208 +#ifdef CONFIG_PAX_KERNEXEC
60209 +void module_free_exec(struct module *mod, void *module_region);
60210 +#else
60211 +#define module_free_exec(x, y) module_free((x), (y))
60212 +#endif
60213 +
60214 /* Apply the given relocation to the (simplified) ELF. Return -error
60215 or 0. */
60216 int apply_relocate(Elf_Shdr *sechdrs,
60217 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
60218 index 7939f63..ec6df57 100644
60219 --- a/include/linux/moduleparam.h
60220 +++ b/include/linux/moduleparam.h
60221 @@ -260,7 +260,7 @@ static inline void __kernel_param_unlock(void)
60222 * @len is usually just sizeof(string).
60223 */
60224 #define module_param_string(name, string, len, perm) \
60225 - static const struct kparam_string __param_string_##name \
60226 + static const struct kparam_string __param_string_##name __used \
60227 = { len, string }; \
60228 __module_param_call(MODULE_PARAM_PREFIX, name, \
60229 &param_ops_string, \
60230 @@ -395,7 +395,7 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
60231 * module_param_named() for why this might be necessary.
60232 */
60233 #define module_param_array_named(name, array, type, nump, perm) \
60234 - static const struct kparam_array __param_arr_##name \
60235 + static const struct kparam_array __param_arr_##name __used \
60236 = { .max = ARRAY_SIZE(array), .num = nump, \
60237 .ops = &param_ops_##type, \
60238 .elemsize = sizeof(array[0]), .elem = array }; \
60239 diff --git a/include/linux/namei.h b/include/linux/namei.h
60240 index ffc0213..2c1f2cb 100644
60241 --- a/include/linux/namei.h
60242 +++ b/include/linux/namei.h
60243 @@ -24,7 +24,7 @@ struct nameidata {
60244 unsigned seq;
60245 int last_type;
60246 unsigned depth;
60247 - char *saved_names[MAX_NESTED_LINKS + 1];
60248 + const char *saved_names[MAX_NESTED_LINKS + 1];
60249
60250 /* Intent data */
60251 union {
60252 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
60253 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
60254 extern void unlock_rename(struct dentry *, struct dentry *);
60255
60256 -static inline void nd_set_link(struct nameidata *nd, char *path)
60257 +static inline void nd_set_link(struct nameidata *nd, const char *path)
60258 {
60259 nd->saved_names[nd->depth] = path;
60260 }
60261
60262 -static inline char *nd_get_link(struct nameidata *nd)
60263 +static inline const char *nd_get_link(const struct nameidata *nd)
60264 {
60265 return nd->saved_names[nd->depth];
60266 }
60267 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
60268 index a82ad4d..90d15b7 100644
60269 --- a/include/linux/netdevice.h
60270 +++ b/include/linux/netdevice.h
60271 @@ -949,6 +949,7 @@ struct net_device_ops {
60272 int (*ndo_set_features)(struct net_device *dev,
60273 u32 features);
60274 };
60275 +typedef struct net_device_ops __no_const net_device_ops_no_const;
60276
60277 /*
60278 * The DEVICE structure.
60279 @@ -1088,7 +1089,7 @@ struct net_device {
60280 int iflink;
60281
60282 struct net_device_stats stats;
60283 - atomic_long_t rx_dropped; /* dropped packets by core network
60284 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
60285 * Do not use this in drivers.
60286 */
60287
60288 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
60289 new file mode 100644
60290 index 0000000..33f4af8
60291 --- /dev/null
60292 +++ b/include/linux/netfilter/xt_gradm.h
60293 @@ -0,0 +1,9 @@
60294 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
60295 +#define _LINUX_NETFILTER_XT_GRADM_H 1
60296 +
60297 +struct xt_gradm_mtinfo {
60298 + __u16 flags;
60299 + __u16 invflags;
60300 +};
60301 +
60302 +#endif
60303 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
60304 index c65a18a..0c05f3a 100644
60305 --- a/include/linux/of_pdt.h
60306 +++ b/include/linux/of_pdt.h
60307 @@ -32,7 +32,7 @@ struct of_pdt_ops {
60308
60309 /* return 0 on success; fill in 'len' with number of bytes in path */
60310 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
60311 -};
60312 +} __no_const;
60313
60314 extern void *prom_early_alloc(unsigned long size);
60315
60316 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
60317 index a4c5624..79d6d88 100644
60318 --- a/include/linux/oprofile.h
60319 +++ b/include/linux/oprofile.h
60320 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
60321 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
60322 char const * name, ulong * val);
60323
60324 -/** Create a file for read-only access to an atomic_t. */
60325 +/** Create a file for read-only access to an atomic_unchecked_t. */
60326 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
60327 - char const * name, atomic_t * val);
60328 + char const * name, atomic_unchecked_t * val);
60329
60330 /** create a directory */
60331 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
60332 diff --git a/include/linux/padata.h b/include/linux/padata.h
60333 index 4633b2f..988bc08 100644
60334 --- a/include/linux/padata.h
60335 +++ b/include/linux/padata.h
60336 @@ -129,7 +129,7 @@ struct parallel_data {
60337 struct padata_instance *pinst;
60338 struct padata_parallel_queue __percpu *pqueue;
60339 struct padata_serial_queue __percpu *squeue;
60340 - atomic_t seq_nr;
60341 + atomic_unchecked_t seq_nr;
60342 atomic_t reorder_objects;
60343 atomic_t refcnt;
60344 unsigned int max_seq_nr;
60345 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
60346 index b1f8912..c955bff 100644
60347 --- a/include/linux/perf_event.h
60348 +++ b/include/linux/perf_event.h
60349 @@ -748,8 +748,8 @@ struct perf_event {
60350
60351 enum perf_event_active_state state;
60352 unsigned int attach_state;
60353 - local64_t count;
60354 - atomic64_t child_count;
60355 + local64_t count; /* PaX: fix it one day */
60356 + atomic64_unchecked_t child_count;
60357
60358 /*
60359 * These are the total time in nanoseconds that the event
60360 @@ -800,8 +800,8 @@ struct perf_event {
60361 * These accumulate total time (in nanoseconds) that children
60362 * events have been enabled and running, respectively.
60363 */
60364 - atomic64_t child_total_time_enabled;
60365 - atomic64_t child_total_time_running;
60366 + atomic64_unchecked_t child_total_time_enabled;
60367 + atomic64_unchecked_t child_total_time_running;
60368
60369 /*
60370 * Protect attach/detach and child_list:
60371 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
60372 index 77257c9..51d473a 100644
60373 --- a/include/linux/pipe_fs_i.h
60374 +++ b/include/linux/pipe_fs_i.h
60375 @@ -46,9 +46,9 @@ struct pipe_buffer {
60376 struct pipe_inode_info {
60377 wait_queue_head_t wait;
60378 unsigned int nrbufs, curbuf, buffers;
60379 - unsigned int readers;
60380 - unsigned int writers;
60381 - unsigned int waiting_writers;
60382 + atomic_t readers;
60383 + atomic_t writers;
60384 + atomic_t waiting_writers;
60385 unsigned int r_counter;
60386 unsigned int w_counter;
60387 struct page *tmp_page;
60388 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
60389 index d3085e7..fd01052 100644
60390 --- a/include/linux/pm_runtime.h
60391 +++ b/include/linux/pm_runtime.h
60392 @@ -95,7 +95,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
60393
60394 static inline void pm_runtime_mark_last_busy(struct device *dev)
60395 {
60396 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
60397 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
60398 }
60399
60400 #else /* !CONFIG_PM_RUNTIME */
60401 diff --git a/include/linux/poison.h b/include/linux/poison.h
60402 index 79159de..f1233a9 100644
60403 --- a/include/linux/poison.h
60404 +++ b/include/linux/poison.h
60405 @@ -19,8 +19,8 @@
60406 * under normal circumstances, used to verify that nobody uses
60407 * non-initialized list entries.
60408 */
60409 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
60410 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
60411 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
60412 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
60413
60414 /********** include/linux/timer.h **********/
60415 /*
60416 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
60417 index 58969b2..ead129b 100644
60418 --- a/include/linux/preempt.h
60419 +++ b/include/linux/preempt.h
60420 @@ -123,7 +123,7 @@ struct preempt_ops {
60421 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
60422 void (*sched_out)(struct preempt_notifier *notifier,
60423 struct task_struct *next);
60424 -};
60425 +} __no_const;
60426
60427 /**
60428 * preempt_notifier - key for installing preemption notifiers
60429 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
60430 index 643b96c..ef55a9c 100644
60431 --- a/include/linux/proc_fs.h
60432 +++ b/include/linux/proc_fs.h
60433 @@ -155,6 +155,19 @@ static inline struct proc_dir_entry *proc_create(const char *name, mode_t mode,
60434 return proc_create_data(name, mode, parent, proc_fops, NULL);
60435 }
60436
60437 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
60438 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
60439 +{
60440 +#ifdef CONFIG_GRKERNSEC_PROC_USER
60441 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
60442 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60443 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
60444 +#else
60445 + return proc_create_data(name, mode, parent, proc_fops, NULL);
60446 +#endif
60447 +}
60448 +
60449 +
60450 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
60451 mode_t mode, struct proc_dir_entry *base,
60452 read_proc_t *read_proc, void * data)
60453 @@ -258,7 +271,7 @@ union proc_op {
60454 int (*proc_show)(struct seq_file *m,
60455 struct pid_namespace *ns, struct pid *pid,
60456 struct task_struct *task);
60457 -};
60458 +} __no_const;
60459
60460 struct ctl_table_header;
60461 struct ctl_table;
60462 diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h
60463 index 800f113..e9ee2e3 100644
60464 --- a/include/linux/ptrace.h
60465 +++ b/include/linux/ptrace.h
60466 @@ -129,10 +129,12 @@ extern void __ptrace_unlink(struct task_struct *child);
60467 extern void exit_ptrace(struct task_struct *tracer);
60468 #define PTRACE_MODE_READ 1
60469 #define PTRACE_MODE_ATTACH 2
60470 -/* Returns 0 on success, -errno on denial. */
60471 -extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
60472 /* Returns true on success, false on denial. */
60473 extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
60474 +/* Returns true on success, false on denial. */
60475 +extern bool ptrace_may_access_log(struct task_struct *task, unsigned int mode);
60476 +/* Returns true on success, false on denial. */
60477 +extern bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode);
60478
60479 static inline int ptrace_reparented(struct task_struct *child)
60480 {
60481 diff --git a/include/linux/random.h b/include/linux/random.h
60482 index 8f74538..02a1012 100644
60483 --- a/include/linux/random.h
60484 +++ b/include/linux/random.h
60485 @@ -69,12 +69,17 @@ void srandom32(u32 seed);
60486
60487 u32 prandom32(struct rnd_state *);
60488
60489 +static inline unsigned long pax_get_random_long(void)
60490 +{
60491 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
60492 +}
60493 +
60494 /*
60495 * Handle minimum values for seeds
60496 */
60497 static inline u32 __seed(u32 x, u32 m)
60498 {
60499 - return (x < m) ? x + m : x;
60500 + return (x <= m) ? x + m + 1 : x;
60501 }
60502
60503 /**
60504 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
60505 index e0879a7..a12f962 100644
60506 --- a/include/linux/reboot.h
60507 +++ b/include/linux/reboot.h
60508 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
60509 * Architecture-specific implementations of sys_reboot commands.
60510 */
60511
60512 -extern void machine_restart(char *cmd);
60513 -extern void machine_halt(void);
60514 -extern void machine_power_off(void);
60515 +extern void machine_restart(char *cmd) __noreturn;
60516 +extern void machine_halt(void) __noreturn;
60517 +extern void machine_power_off(void) __noreturn;
60518
60519 extern void machine_shutdown(void);
60520 struct pt_regs;
60521 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
60522 */
60523
60524 extern void kernel_restart_prepare(char *cmd);
60525 -extern void kernel_restart(char *cmd);
60526 -extern void kernel_halt(void);
60527 -extern void kernel_power_off(void);
60528 +extern void kernel_restart(char *cmd) __noreturn;
60529 +extern void kernel_halt(void) __noreturn;
60530 +extern void kernel_power_off(void) __noreturn;
60531
60532 extern int C_A_D; /* for sysctl */
60533 void ctrl_alt_del(void);
60534 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
60535 * Emergency restart, callable from an interrupt handler.
60536 */
60537
60538 -extern void emergency_restart(void);
60539 +extern void emergency_restart(void) __noreturn;
60540 #include <asm/emergency-restart.h>
60541
60542 #endif
60543 diff --git a/include/linux/reiserfs_fs.h b/include/linux/reiserfs_fs.h
60544 index 96d465f..b084e05 100644
60545 --- a/include/linux/reiserfs_fs.h
60546 +++ b/include/linux/reiserfs_fs.h
60547 @@ -1406,7 +1406,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60548 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60549
60550 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60551 -#define get_generation(s) atomic_read (&fs_generation(s))
60552 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60553 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60554 #define __fs_changed(gen,s) (gen != get_generation (s))
60555 #define fs_changed(gen,s) \
60556 diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h
60557 index 52c83b6..18ed7eb 100644
60558 --- a/include/linux/reiserfs_fs_sb.h
60559 +++ b/include/linux/reiserfs_fs_sb.h
60560 @@ -386,7 +386,7 @@ struct reiserfs_sb_info {
60561 /* Comment? -Hans */
60562 wait_queue_head_t s_wait;
60563 /* To be obsoleted soon by per buffer seals.. -Hans */
60564 - atomic_t s_generation_counter; // increased by one every time the
60565 + atomic_unchecked_t s_generation_counter; // increased by one every time the
60566 // tree gets re-balanced
60567 unsigned long s_properties; /* File system properties. Currently holds
60568 on-disk FS format */
60569 diff --git a/include/linux/relay.h b/include/linux/relay.h
60570 index 14a86bc..17d0700 100644
60571 --- a/include/linux/relay.h
60572 +++ b/include/linux/relay.h
60573 @@ -159,7 +159,7 @@ struct rchan_callbacks
60574 * The callback should return 0 if successful, negative if not.
60575 */
60576 int (*remove_buf_file)(struct dentry *dentry);
60577 -};
60578 +} __no_const;
60579
60580 /*
60581 * CONFIG_RELAY kernel API, kernel/relay.c
60582 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
60583 index c6c6084..5bf1212 100644
60584 --- a/include/linux/rfkill.h
60585 +++ b/include/linux/rfkill.h
60586 @@ -147,6 +147,7 @@ struct rfkill_ops {
60587 void (*query)(struct rfkill *rfkill, void *data);
60588 int (*set_block)(void *data, bool blocked);
60589 };
60590 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
60591
60592 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
60593 /**
60594 diff --git a/include/linux/rio.h b/include/linux/rio.h
60595 index 4d50611..c6858a2 100644
60596 --- a/include/linux/rio.h
60597 +++ b/include/linux/rio.h
60598 @@ -315,7 +315,7 @@ struct rio_ops {
60599 int mbox, void *buffer, size_t len);
60600 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
60601 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
60602 -};
60603 +} __no_const;
60604
60605 #define RIO_RESOURCE_MEM 0x00000100
60606 #define RIO_RESOURCE_DOORBELL 0x00000200
60607 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
60608 index 2148b12..519b820 100644
60609 --- a/include/linux/rmap.h
60610 +++ b/include/linux/rmap.h
60611 @@ -119,8 +119,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
60612 void anon_vma_init(void); /* create anon_vma_cachep */
60613 int anon_vma_prepare(struct vm_area_struct *);
60614 void unlink_anon_vmas(struct vm_area_struct *);
60615 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
60616 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
60617 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
60618 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
60619 void __anon_vma_link(struct vm_area_struct *);
60620
60621 static inline void anon_vma_merge(struct vm_area_struct *vma,
60622 diff --git a/include/linux/sched.h b/include/linux/sched.h
60623 index 1c4f3e9..b4e4851 100644
60624 --- a/include/linux/sched.h
60625 +++ b/include/linux/sched.h
60626 @@ -101,6 +101,7 @@ struct bio_list;
60627 struct fs_struct;
60628 struct perf_event_context;
60629 struct blk_plug;
60630 +struct linux_binprm;
60631
60632 /*
60633 * List of flags we want to share for kernel threads,
60634 @@ -380,10 +381,13 @@ struct user_namespace;
60635 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
60636
60637 extern int sysctl_max_map_count;
60638 +extern unsigned long sysctl_heap_stack_gap;
60639
60640 #include <linux/aio.h>
60641
60642 #ifdef CONFIG_MMU
60643 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
60644 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
60645 extern void arch_pick_mmap_layout(struct mm_struct *mm);
60646 extern unsigned long
60647 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
60648 @@ -629,6 +633,17 @@ struct signal_struct {
60649 #ifdef CONFIG_TASKSTATS
60650 struct taskstats *stats;
60651 #endif
60652 +
60653 +#ifdef CONFIG_GRKERNSEC
60654 + u32 curr_ip;
60655 + u32 saved_ip;
60656 + u32 gr_saddr;
60657 + u32 gr_daddr;
60658 + u16 gr_sport;
60659 + u16 gr_dport;
60660 + u8 used_accept:1;
60661 +#endif
60662 +
60663 #ifdef CONFIG_AUDIT
60664 unsigned audit_tty;
60665 struct tty_audit_buf *tty_audit_buf;
60666 @@ -710,6 +725,11 @@ struct user_struct {
60667 struct key *session_keyring; /* UID's default session keyring */
60668 #endif
60669
60670 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60671 + unsigned int banned;
60672 + unsigned long ban_expires;
60673 +#endif
60674 +
60675 /* Hash table maintenance information */
60676 struct hlist_node uidhash_node;
60677 uid_t uid;
60678 @@ -1337,8 +1357,8 @@ struct task_struct {
60679 struct list_head thread_group;
60680
60681 struct completion *vfork_done; /* for vfork() */
60682 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
60683 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60684 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
60685 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
60686
60687 cputime_t utime, stime, utimescaled, stimescaled;
60688 cputime_t gtime;
60689 @@ -1354,13 +1374,6 @@ struct task_struct {
60690 struct task_cputime cputime_expires;
60691 struct list_head cpu_timers[3];
60692
60693 -/* process credentials */
60694 - const struct cred __rcu *real_cred; /* objective and real subjective task
60695 - * credentials (COW) */
60696 - const struct cred __rcu *cred; /* effective (overridable) subjective task
60697 - * credentials (COW) */
60698 - struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60699 -
60700 char comm[TASK_COMM_LEN]; /* executable name excluding path
60701 - access with [gs]et_task_comm (which lock
60702 it with task_lock())
60703 @@ -1377,8 +1390,16 @@ struct task_struct {
60704 #endif
60705 /* CPU-specific state of this task */
60706 struct thread_struct thread;
60707 +/* thread_info moved to task_struct */
60708 +#ifdef CONFIG_X86
60709 + struct thread_info tinfo;
60710 +#endif
60711 /* filesystem information */
60712 struct fs_struct *fs;
60713 +
60714 + const struct cred __rcu *cred; /* effective (overridable) subjective task
60715 + * credentials (COW) */
60716 +
60717 /* open file information */
60718 struct files_struct *files;
60719 /* namespaces */
60720 @@ -1425,6 +1446,11 @@ struct task_struct {
60721 struct rt_mutex_waiter *pi_blocked_on;
60722 #endif
60723
60724 +/* process credentials */
60725 + const struct cred __rcu *real_cred; /* objective and real subjective task
60726 + * credentials (COW) */
60727 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
60728 +
60729 #ifdef CONFIG_DEBUG_MUTEXES
60730 /* mutex deadlock detection */
60731 struct mutex_waiter *blocked_on;
60732 @@ -1540,6 +1566,27 @@ struct task_struct {
60733 unsigned long default_timer_slack_ns;
60734
60735 struct list_head *scm_work_list;
60736 +
60737 +#ifdef CONFIG_GRKERNSEC
60738 + /* grsecurity */
60739 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60740 + u64 exec_id;
60741 +#endif
60742 +#ifdef CONFIG_GRKERNSEC_SETXID
60743 + const struct cred *delayed_cred;
60744 +#endif
60745 + struct dentry *gr_chroot_dentry;
60746 + struct acl_subject_label *acl;
60747 + struct acl_role_label *role;
60748 + struct file *exec_file;
60749 + u16 acl_role_id;
60750 + /* is this the task that authenticated to the special role */
60751 + u8 acl_sp_role;
60752 + u8 is_writable;
60753 + u8 brute;
60754 + u8 gr_is_chrooted;
60755 +#endif
60756 +
60757 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
60758 /* Index of current stored address in ret_stack */
60759 int curr_ret_stack;
60760 @@ -1574,6 +1621,51 @@ struct task_struct {
60761 #endif
60762 };
60763
60764 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
60765 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
60766 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
60767 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
60768 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
60769 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
60770 +
60771 +#ifdef CONFIG_PAX_SOFTMODE
60772 +extern int pax_softmode;
60773 +#endif
60774 +
60775 +extern int pax_check_flags(unsigned long *);
60776 +
60777 +/* if tsk != current then task_lock must be held on it */
60778 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
60779 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
60780 +{
60781 + if (likely(tsk->mm))
60782 + return tsk->mm->pax_flags;
60783 + else
60784 + return 0UL;
60785 +}
60786 +
60787 +/* if tsk != current then task_lock must be held on it */
60788 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
60789 +{
60790 + if (likely(tsk->mm)) {
60791 + tsk->mm->pax_flags = flags;
60792 + return 0;
60793 + }
60794 + return -EINVAL;
60795 +}
60796 +#endif
60797 +
60798 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60799 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
60800 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
60801 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
60802 +#endif
60803 +
60804 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
60805 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
60806 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
60807 +extern NORET_TYPE void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type) ATTRIB_NORET;
60808 +
60809 /* Future-safe accessor for struct task_struct's cpus_allowed. */
60810 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
60811
60812 @@ -2081,7 +2173,9 @@ void yield(void);
60813 extern struct exec_domain default_exec_domain;
60814
60815 union thread_union {
60816 +#ifndef CONFIG_X86
60817 struct thread_info thread_info;
60818 +#endif
60819 unsigned long stack[THREAD_SIZE/sizeof(long)];
60820 };
60821
60822 @@ -2114,6 +2208,7 @@ extern struct pid_namespace init_pid_ns;
60823 */
60824
60825 extern struct task_struct *find_task_by_vpid(pid_t nr);
60826 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
60827 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
60828 struct pid_namespace *ns);
60829
60830 @@ -2235,6 +2330,12 @@ static inline void mmdrop(struct mm_struct * mm)
60831 extern void mmput(struct mm_struct *);
60832 /* Grab a reference to a task's mm, if it is not already going away */
60833 extern struct mm_struct *get_task_mm(struct task_struct *task);
60834 +/*
60835 + * Grab a reference to a task's mm, if it is not already going away
60836 + * and ptrace_may_access with the mode parameter passed to it
60837 + * succeeds.
60838 + */
60839 +extern struct mm_struct *mm_access(struct task_struct *task, unsigned int mode);
60840 /* Remove the current tasks stale references to the old mm_struct */
60841 extern void mm_release(struct task_struct *, struct mm_struct *);
60842 /* Allocate a new mm structure and copy contents from tsk->mm */
60843 @@ -2251,7 +2352,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
60844 extern void exit_itimers(struct signal_struct *);
60845 extern void flush_itimer_signals(void);
60846
60847 -extern NORET_TYPE void do_group_exit(int);
60848 +extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
60849
60850 extern void daemonize(const char *, ...);
60851 extern int allow_signal(int);
60852 @@ -2416,13 +2517,17 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
60853
60854 #endif
60855
60856 -static inline int object_is_on_stack(void *obj)
60857 +static inline int object_starts_on_stack(void *obj)
60858 {
60859 - void *stack = task_stack_page(current);
60860 + const void *stack = task_stack_page(current);
60861
60862 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
60863 }
60864
60865 +#ifdef CONFIG_PAX_USERCOPY
60866 +extern int object_is_on_stack(const void *obj, unsigned long len);
60867 +#endif
60868 +
60869 extern void thread_info_cache_init(void);
60870
60871 #ifdef CONFIG_DEBUG_STACK_USAGE
60872 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
60873 index 899fbb4..1cb4138 100644
60874 --- a/include/linux/screen_info.h
60875 +++ b/include/linux/screen_info.h
60876 @@ -43,7 +43,8 @@ struct screen_info {
60877 __u16 pages; /* 0x32 */
60878 __u16 vesa_attributes; /* 0x34 */
60879 __u32 capabilities; /* 0x36 */
60880 - __u8 _reserved[6]; /* 0x3a */
60881 + __u16 vesapm_size; /* 0x3a */
60882 + __u8 _reserved[4]; /* 0x3c */
60883 } __attribute__((packed));
60884
60885 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
60886 diff --git a/include/linux/security.h b/include/linux/security.h
60887 index e8c619d..e0cbd1c 100644
60888 --- a/include/linux/security.h
60889 +++ b/include/linux/security.h
60890 @@ -37,6 +37,7 @@
60891 #include <linux/xfrm.h>
60892 #include <linux/slab.h>
60893 #include <linux/xattr.h>
60894 +#include <linux/grsecurity.h>
60895 #include <net/flow.h>
60896
60897 /* Maximum number of letters for an LSM name string */
60898 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
60899 index 0b69a46..b2ffa4c 100644
60900 --- a/include/linux/seq_file.h
60901 +++ b/include/linux/seq_file.h
60902 @@ -24,6 +24,9 @@ struct seq_file {
60903 struct mutex lock;
60904 const struct seq_operations *op;
60905 int poll_event;
60906 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60907 + u64 exec_id;
60908 +#endif
60909 void *private;
60910 };
60911
60912 @@ -33,6 +36,7 @@ struct seq_operations {
60913 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
60914 int (*show) (struct seq_file *m, void *v);
60915 };
60916 +typedef struct seq_operations __no_const seq_operations_no_const;
60917
60918 #define SEQ_SKIP 1
60919
60920 diff --git a/include/linux/shm.h b/include/linux/shm.h
60921 index 92808b8..c28cac4 100644
60922 --- a/include/linux/shm.h
60923 +++ b/include/linux/shm.h
60924 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
60925
60926 /* The task created the shm object. NULL if the task is dead. */
60927 struct task_struct *shm_creator;
60928 +#ifdef CONFIG_GRKERNSEC
60929 + time_t shm_createtime;
60930 + pid_t shm_lapid;
60931 +#endif
60932 };
60933
60934 /* shm_mode upper byte flags */
60935 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
60936 index fe86488..1563c1c 100644
60937 --- a/include/linux/skbuff.h
60938 +++ b/include/linux/skbuff.h
60939 @@ -642,7 +642,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
60940 */
60941 static inline int skb_queue_empty(const struct sk_buff_head *list)
60942 {
60943 - return list->next == (struct sk_buff *)list;
60944 + return list->next == (const struct sk_buff *)list;
60945 }
60946
60947 /**
60948 @@ -655,7 +655,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
60949 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
60950 const struct sk_buff *skb)
60951 {
60952 - return skb->next == (struct sk_buff *)list;
60953 + return skb->next == (const struct sk_buff *)list;
60954 }
60955
60956 /**
60957 @@ -668,7 +668,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
60958 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
60959 const struct sk_buff *skb)
60960 {
60961 - return skb->prev == (struct sk_buff *)list;
60962 + return skb->prev == (const struct sk_buff *)list;
60963 }
60964
60965 /**
60966 @@ -1523,7 +1523,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
60967 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
60968 */
60969 #ifndef NET_SKB_PAD
60970 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
60971 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
60972 #endif
60973
60974 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
60975 diff --git a/include/linux/slab.h b/include/linux/slab.h
60976 index 573c809..e84c132 100644
60977 --- a/include/linux/slab.h
60978 +++ b/include/linux/slab.h
60979 @@ -11,12 +11,20 @@
60980
60981 #include <linux/gfp.h>
60982 #include <linux/types.h>
60983 +#include <linux/err.h>
60984
60985 /*
60986 * Flags to pass to kmem_cache_create().
60987 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
60988 */
60989 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
60990 +
60991 +#ifdef CONFIG_PAX_USERCOPY
60992 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
60993 +#else
60994 +#define SLAB_USERCOPY 0x00000000UL
60995 +#endif
60996 +
60997 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
60998 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
60999 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
61000 @@ -87,10 +95,13 @@
61001 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
61002 * Both make kfree a no-op.
61003 */
61004 -#define ZERO_SIZE_PTR ((void *)16)
61005 +#define ZERO_SIZE_PTR \
61006 +({ \
61007 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
61008 + (void *)(-MAX_ERRNO-1L); \
61009 +})
61010
61011 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
61012 - (unsigned long)ZERO_SIZE_PTR)
61013 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
61014
61015 /*
61016 * struct kmem_cache related prototypes
61017 @@ -161,6 +172,7 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
61018 void kfree(const void *);
61019 void kzfree(const void *);
61020 size_t ksize(const void *);
61021 +void check_object_size(const void *ptr, unsigned long n, bool to);
61022
61023 /*
61024 * Allocator specific definitions. These are mainly used to establish optimized
61025 @@ -353,4 +365,59 @@ static inline void *kzalloc_node(size_t size, gfp_t flags, int node)
61026
61027 void __init kmem_cache_init_late(void);
61028
61029 +#define kmalloc(x, y) \
61030 +({ \
61031 + void *___retval; \
61032 + intoverflow_t ___x = (intoverflow_t)x; \
61033 + if (WARN(___x > ULONG_MAX, "kmalloc size overflow\n")) \
61034 + ___retval = NULL; \
61035 + else \
61036 + ___retval = kmalloc((size_t)___x, (y)); \
61037 + ___retval; \
61038 +})
61039 +
61040 +#define kmalloc_node(x, y, z) \
61041 +({ \
61042 + void *___retval; \
61043 + intoverflow_t ___x = (intoverflow_t)x; \
61044 + if (WARN(___x > ULONG_MAX, "kmalloc_node size overflow\n"))\
61045 + ___retval = NULL; \
61046 + else \
61047 + ___retval = kmalloc_node((size_t)___x, (y), (z));\
61048 + ___retval; \
61049 +})
61050 +
61051 +#define kzalloc(x, y) \
61052 +({ \
61053 + void *___retval; \
61054 + intoverflow_t ___x = (intoverflow_t)x; \
61055 + if (WARN(___x > ULONG_MAX, "kzalloc size overflow\n")) \
61056 + ___retval = NULL; \
61057 + else \
61058 + ___retval = kzalloc((size_t)___x, (y)); \
61059 + ___retval; \
61060 +})
61061 +
61062 +#define __krealloc(x, y, z) \
61063 +({ \
61064 + void *___retval; \
61065 + intoverflow_t ___y = (intoverflow_t)y; \
61066 + if (WARN(___y > ULONG_MAX, "__krealloc size overflow\n"))\
61067 + ___retval = NULL; \
61068 + else \
61069 + ___retval = __krealloc((x), (size_t)___y, (z)); \
61070 + ___retval; \
61071 +})
61072 +
61073 +#define krealloc(x, y, z) \
61074 +({ \
61075 + void *___retval; \
61076 + intoverflow_t ___y = (intoverflow_t)y; \
61077 + if (WARN(___y > ULONG_MAX, "krealloc size overflow\n")) \
61078 + ___retval = NULL; \
61079 + else \
61080 + ___retval = krealloc((x), (size_t)___y, (z)); \
61081 + ___retval; \
61082 +})
61083 +
61084 #endif /* _LINUX_SLAB_H */
61085 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
61086 index d00e0ba..1b3bf7b 100644
61087 --- a/include/linux/slab_def.h
61088 +++ b/include/linux/slab_def.h
61089 @@ -68,10 +68,10 @@ struct kmem_cache {
61090 unsigned long node_allocs;
61091 unsigned long node_frees;
61092 unsigned long node_overflow;
61093 - atomic_t allochit;
61094 - atomic_t allocmiss;
61095 - atomic_t freehit;
61096 - atomic_t freemiss;
61097 + atomic_unchecked_t allochit;
61098 + atomic_unchecked_t allocmiss;
61099 + atomic_unchecked_t freehit;
61100 + atomic_unchecked_t freemiss;
61101
61102 /*
61103 * If debugging is enabled, then the allocator can add additional
61104 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
61105 index a32bcfd..53b71f4 100644
61106 --- a/include/linux/slub_def.h
61107 +++ b/include/linux/slub_def.h
61108 @@ -89,7 +89,7 @@ struct kmem_cache {
61109 struct kmem_cache_order_objects max;
61110 struct kmem_cache_order_objects min;
61111 gfp_t allocflags; /* gfp flags to use on each alloc */
61112 - int refcount; /* Refcount for slab cache destroy */
61113 + atomic_t refcount; /* Refcount for slab cache destroy */
61114 void (*ctor)(void *);
61115 int inuse; /* Offset to metadata */
61116 int align; /* Alignment */
61117 @@ -215,7 +215,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
61118 }
61119
61120 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
61121 -void *__kmalloc(size_t size, gfp_t flags);
61122 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
61123
61124 static __always_inline void *
61125 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
61126 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
61127 index de8832d..0147b46 100644
61128 --- a/include/linux/sonet.h
61129 +++ b/include/linux/sonet.h
61130 @@ -61,7 +61,7 @@ struct sonet_stats {
61131 #include <linux/atomic.h>
61132
61133 struct k_sonet_stats {
61134 -#define __HANDLE_ITEM(i) atomic_t i
61135 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61136 __SONET_ITEMS
61137 #undef __HANDLE_ITEM
61138 };
61139 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
61140 index 3d8f9c4..69f1c0a 100644
61141 --- a/include/linux/sunrpc/clnt.h
61142 +++ b/include/linux/sunrpc/clnt.h
61143 @@ -172,9 +172,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
61144 {
61145 switch (sap->sa_family) {
61146 case AF_INET:
61147 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
61148 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
61149 case AF_INET6:
61150 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
61151 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
61152 }
61153 return 0;
61154 }
61155 @@ -207,7 +207,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
61156 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
61157 const struct sockaddr *src)
61158 {
61159 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
61160 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
61161 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
61162
61163 dsin->sin_family = ssin->sin_family;
61164 @@ -310,7 +310,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
61165 if (sa->sa_family != AF_INET6)
61166 return 0;
61167
61168 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
61169 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
61170 }
61171
61172 #endif /* __KERNEL__ */
61173 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
61174 index e775689..9e206d9 100644
61175 --- a/include/linux/sunrpc/sched.h
61176 +++ b/include/linux/sunrpc/sched.h
61177 @@ -105,6 +105,7 @@ struct rpc_call_ops {
61178 void (*rpc_call_done)(struct rpc_task *, void *);
61179 void (*rpc_release)(void *);
61180 };
61181 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
61182
61183 struct rpc_task_setup {
61184 struct rpc_task *task;
61185 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
61186 index c14fe86..393245e 100644
61187 --- a/include/linux/sunrpc/svc_rdma.h
61188 +++ b/include/linux/sunrpc/svc_rdma.h
61189 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
61190 extern unsigned int svcrdma_max_requests;
61191 extern unsigned int svcrdma_max_req_size;
61192
61193 -extern atomic_t rdma_stat_recv;
61194 -extern atomic_t rdma_stat_read;
61195 -extern atomic_t rdma_stat_write;
61196 -extern atomic_t rdma_stat_sq_starve;
61197 -extern atomic_t rdma_stat_rq_starve;
61198 -extern atomic_t rdma_stat_rq_poll;
61199 -extern atomic_t rdma_stat_rq_prod;
61200 -extern atomic_t rdma_stat_sq_poll;
61201 -extern atomic_t rdma_stat_sq_prod;
61202 +extern atomic_unchecked_t rdma_stat_recv;
61203 +extern atomic_unchecked_t rdma_stat_read;
61204 +extern atomic_unchecked_t rdma_stat_write;
61205 +extern atomic_unchecked_t rdma_stat_sq_starve;
61206 +extern atomic_unchecked_t rdma_stat_rq_starve;
61207 +extern atomic_unchecked_t rdma_stat_rq_poll;
61208 +extern atomic_unchecked_t rdma_stat_rq_prod;
61209 +extern atomic_unchecked_t rdma_stat_sq_poll;
61210 +extern atomic_unchecked_t rdma_stat_sq_prod;
61211
61212 #define RPCRDMA_VERSION 1
61213
61214 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
61215 index 703cfa3..0b8ca72ac 100644
61216 --- a/include/linux/sysctl.h
61217 +++ b/include/linux/sysctl.h
61218 @@ -155,7 +155,11 @@ enum
61219 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
61220 };
61221
61222 -
61223 +#ifdef CONFIG_PAX_SOFTMODE
61224 +enum {
61225 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
61226 +};
61227 +#endif
61228
61229 /* CTL_VM names: */
61230 enum
61231 @@ -968,6 +972,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
61232
61233 extern int proc_dostring(struct ctl_table *, int,
61234 void __user *, size_t *, loff_t *);
61235 +extern int proc_dostring_modpriv(struct ctl_table *, int,
61236 + void __user *, size_t *, loff_t *);
61237 extern int proc_dointvec(struct ctl_table *, int,
61238 void __user *, size_t *, loff_t *);
61239 extern int proc_dointvec_minmax(struct ctl_table *, int,
61240 diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
61241 index a71a292..51bd91d 100644
61242 --- a/include/linux/tracehook.h
61243 +++ b/include/linux/tracehook.h
61244 @@ -54,12 +54,12 @@ struct linux_binprm;
61245 /*
61246 * ptrace report for syscall entry and exit looks identical.
61247 */
61248 -static inline void ptrace_report_syscall(struct pt_regs *regs)
61249 +static inline int ptrace_report_syscall(struct pt_regs *regs)
61250 {
61251 int ptrace = current->ptrace;
61252
61253 if (!(ptrace & PT_PTRACED))
61254 - return;
61255 + return 0;
61256
61257 ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0));
61258
61259 @@ -72,6 +72,8 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
61260 send_sig(current->exit_code, current, 1);
61261 current->exit_code = 0;
61262 }
61263 +
61264 + return fatal_signal_pending(current);
61265 }
61266
61267 /**
61268 @@ -96,8 +98,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs)
61269 static inline __must_check int tracehook_report_syscall_entry(
61270 struct pt_regs *regs)
61271 {
61272 - ptrace_report_syscall(regs);
61273 - return 0;
61274 + return ptrace_report_syscall(regs);
61275 }
61276
61277 /**
61278 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
61279 index ff7dc08..893e1bd 100644
61280 --- a/include/linux/tty_ldisc.h
61281 +++ b/include/linux/tty_ldisc.h
61282 @@ -148,7 +148,7 @@ struct tty_ldisc_ops {
61283
61284 struct module *owner;
61285
61286 - int refcount;
61287 + atomic_t refcount;
61288 };
61289
61290 struct tty_ldisc {
61291 diff --git a/include/linux/types.h b/include/linux/types.h
61292 index 57a9723..dbe234a 100644
61293 --- a/include/linux/types.h
61294 +++ b/include/linux/types.h
61295 @@ -213,10 +213,26 @@ typedef struct {
61296 int counter;
61297 } atomic_t;
61298
61299 +#ifdef CONFIG_PAX_REFCOUNT
61300 +typedef struct {
61301 + int counter;
61302 +} atomic_unchecked_t;
61303 +#else
61304 +typedef atomic_t atomic_unchecked_t;
61305 +#endif
61306 +
61307 #ifdef CONFIG_64BIT
61308 typedef struct {
61309 long counter;
61310 } atomic64_t;
61311 +
61312 +#ifdef CONFIG_PAX_REFCOUNT
61313 +typedef struct {
61314 + long counter;
61315 +} atomic64_unchecked_t;
61316 +#else
61317 +typedef atomic64_t atomic64_unchecked_t;
61318 +#endif
61319 #endif
61320
61321 struct list_head {
61322 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
61323 index 5ca0951..ab496a5 100644
61324 --- a/include/linux/uaccess.h
61325 +++ b/include/linux/uaccess.h
61326 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
61327 long ret; \
61328 mm_segment_t old_fs = get_fs(); \
61329 \
61330 - set_fs(KERNEL_DS); \
61331 pagefault_disable(); \
61332 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
61333 - pagefault_enable(); \
61334 + set_fs(KERNEL_DS); \
61335 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
61336 set_fs(old_fs); \
61337 + pagefault_enable(); \
61338 ret; \
61339 })
61340
61341 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
61342 index 99c1b4d..bb94261 100644
61343 --- a/include/linux/unaligned/access_ok.h
61344 +++ b/include/linux/unaligned/access_ok.h
61345 @@ -6,32 +6,32 @@
61346
61347 static inline u16 get_unaligned_le16(const void *p)
61348 {
61349 - return le16_to_cpup((__le16 *)p);
61350 + return le16_to_cpup((const __le16 *)p);
61351 }
61352
61353 static inline u32 get_unaligned_le32(const void *p)
61354 {
61355 - return le32_to_cpup((__le32 *)p);
61356 + return le32_to_cpup((const __le32 *)p);
61357 }
61358
61359 static inline u64 get_unaligned_le64(const void *p)
61360 {
61361 - return le64_to_cpup((__le64 *)p);
61362 + return le64_to_cpup((const __le64 *)p);
61363 }
61364
61365 static inline u16 get_unaligned_be16(const void *p)
61366 {
61367 - return be16_to_cpup((__be16 *)p);
61368 + return be16_to_cpup((const __be16 *)p);
61369 }
61370
61371 static inline u32 get_unaligned_be32(const void *p)
61372 {
61373 - return be32_to_cpup((__be32 *)p);
61374 + return be32_to_cpup((const __be32 *)p);
61375 }
61376
61377 static inline u64 get_unaligned_be64(const void *p)
61378 {
61379 - return be64_to_cpup((__be64 *)p);
61380 + return be64_to_cpup((const __be64 *)p);
61381 }
61382
61383 static inline void put_unaligned_le16(u16 val, void *p)
61384 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
61385 index e5a40c3..20ab0f6 100644
61386 --- a/include/linux/usb/renesas_usbhs.h
61387 +++ b/include/linux/usb/renesas_usbhs.h
61388 @@ -39,7 +39,7 @@ enum {
61389 */
61390 struct renesas_usbhs_driver_callback {
61391 int (*notify_hotplug)(struct platform_device *pdev);
61392 -};
61393 +} __no_const;
61394
61395 /*
61396 * callback functions for platform
61397 @@ -89,7 +89,7 @@ struct renesas_usbhs_platform_callback {
61398 * VBUS control is needed for Host
61399 */
61400 int (*set_vbus)(struct platform_device *pdev, int enable);
61401 -};
61402 +} __no_const;
61403
61404 /*
61405 * parameters for renesas usbhs
61406 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
61407 index 6f8fbcf..8259001 100644
61408 --- a/include/linux/vermagic.h
61409 +++ b/include/linux/vermagic.h
61410 @@ -25,9 +25,35 @@
61411 #define MODULE_ARCH_VERMAGIC ""
61412 #endif
61413
61414 +#ifdef CONFIG_PAX_REFCOUNT
61415 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
61416 +#else
61417 +#define MODULE_PAX_REFCOUNT ""
61418 +#endif
61419 +
61420 +#ifdef CONSTIFY_PLUGIN
61421 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
61422 +#else
61423 +#define MODULE_CONSTIFY_PLUGIN ""
61424 +#endif
61425 +
61426 +#ifdef STACKLEAK_PLUGIN
61427 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
61428 +#else
61429 +#define MODULE_STACKLEAK_PLUGIN ""
61430 +#endif
61431 +
61432 +#ifdef CONFIG_GRKERNSEC
61433 +#define MODULE_GRSEC "GRSEC "
61434 +#else
61435 +#define MODULE_GRSEC ""
61436 +#endif
61437 +
61438 #define VERMAGIC_STRING \
61439 UTS_RELEASE " " \
61440 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
61441 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
61442 - MODULE_ARCH_VERMAGIC
61443 + MODULE_ARCH_VERMAGIC \
61444 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
61445 + MODULE_GRSEC
61446
61447 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
61448 index 4bde182..aec92c1 100644
61449 --- a/include/linux/vmalloc.h
61450 +++ b/include/linux/vmalloc.h
61451 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
61452 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
61453 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
61454 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
61455 +
61456 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
61457 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
61458 +#endif
61459 +
61460 /* bits [20..32] reserved for arch specific ioremap internals */
61461
61462 /*
61463 @@ -156,4 +161,103 @@ pcpu_free_vm_areas(struct vm_struct **vms, int nr_vms)
61464 # endif
61465 #endif
61466
61467 +#define vmalloc(x) \
61468 +({ \
61469 + void *___retval; \
61470 + intoverflow_t ___x = (intoverflow_t)x; \
61471 + if (WARN(___x > ULONG_MAX, "vmalloc size overflow\n")) \
61472 + ___retval = NULL; \
61473 + else \
61474 + ___retval = vmalloc((unsigned long)___x); \
61475 + ___retval; \
61476 +})
61477 +
61478 +#define vzalloc(x) \
61479 +({ \
61480 + void *___retval; \
61481 + intoverflow_t ___x = (intoverflow_t)x; \
61482 + if (WARN(___x > ULONG_MAX, "vzalloc size overflow\n")) \
61483 + ___retval = NULL; \
61484 + else \
61485 + ___retval = vzalloc((unsigned long)___x); \
61486 + ___retval; \
61487 +})
61488 +
61489 +#define __vmalloc(x, y, z) \
61490 +({ \
61491 + void *___retval; \
61492 + intoverflow_t ___x = (intoverflow_t)x; \
61493 + if (WARN(___x > ULONG_MAX, "__vmalloc size overflow\n"))\
61494 + ___retval = NULL; \
61495 + else \
61496 + ___retval = __vmalloc((unsigned long)___x, (y), (z));\
61497 + ___retval; \
61498 +})
61499 +
61500 +#define vmalloc_user(x) \
61501 +({ \
61502 + void *___retval; \
61503 + intoverflow_t ___x = (intoverflow_t)x; \
61504 + if (WARN(___x > ULONG_MAX, "vmalloc_user size overflow\n"))\
61505 + ___retval = NULL; \
61506 + else \
61507 + ___retval = vmalloc_user((unsigned long)___x); \
61508 + ___retval; \
61509 +})
61510 +
61511 +#define vmalloc_exec(x) \
61512 +({ \
61513 + void *___retval; \
61514 + intoverflow_t ___x = (intoverflow_t)x; \
61515 + if (WARN(___x > ULONG_MAX, "vmalloc_exec size overflow\n"))\
61516 + ___retval = NULL; \
61517 + else \
61518 + ___retval = vmalloc_exec((unsigned long)___x); \
61519 + ___retval; \
61520 +})
61521 +
61522 +#define vmalloc_node(x, y) \
61523 +({ \
61524 + void *___retval; \
61525 + intoverflow_t ___x = (intoverflow_t)x; \
61526 + if (WARN(___x > ULONG_MAX, "vmalloc_node size overflow\n"))\
61527 + ___retval = NULL; \
61528 + else \
61529 + ___retval = vmalloc_node((unsigned long)___x, (y));\
61530 + ___retval; \
61531 +})
61532 +
61533 +#define vzalloc_node(x, y) \
61534 +({ \
61535 + void *___retval; \
61536 + intoverflow_t ___x = (intoverflow_t)x; \
61537 + if (WARN(___x > ULONG_MAX, "vzalloc_node size overflow\n"))\
61538 + ___retval = NULL; \
61539 + else \
61540 + ___retval = vzalloc_node((unsigned long)___x, (y));\
61541 + ___retval; \
61542 +})
61543 +
61544 +#define vmalloc_32(x) \
61545 +({ \
61546 + void *___retval; \
61547 + intoverflow_t ___x = (intoverflow_t)x; \
61548 + if (WARN(___x > ULONG_MAX, "vmalloc_32 size overflow\n"))\
61549 + ___retval = NULL; \
61550 + else \
61551 + ___retval = vmalloc_32((unsigned long)___x); \
61552 + ___retval; \
61553 +})
61554 +
61555 +#define vmalloc_32_user(x) \
61556 +({ \
61557 +void *___retval; \
61558 + intoverflow_t ___x = (intoverflow_t)x; \
61559 + if (WARN(___x > ULONG_MAX, "vmalloc_32_user size overflow\n"))\
61560 + ___retval = NULL; \
61561 + else \
61562 + ___retval = vmalloc_32_user((unsigned long)___x);\
61563 + ___retval; \
61564 +})
61565 +
61566 #endif /* _LINUX_VMALLOC_H */
61567 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
61568 index 65efb92..137adbb 100644
61569 --- a/include/linux/vmstat.h
61570 +++ b/include/linux/vmstat.h
61571 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
61572 /*
61573 * Zone based page accounting with per cpu differentials.
61574 */
61575 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61576 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
61577
61578 static inline void zone_page_state_add(long x, struct zone *zone,
61579 enum zone_stat_item item)
61580 {
61581 - atomic_long_add(x, &zone->vm_stat[item]);
61582 - atomic_long_add(x, &vm_stat[item]);
61583 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
61584 + atomic_long_add_unchecked(x, &vm_stat[item]);
61585 }
61586
61587 static inline unsigned long global_page_state(enum zone_stat_item item)
61588 {
61589 - long x = atomic_long_read(&vm_stat[item]);
61590 + long x = atomic_long_read_unchecked(&vm_stat[item]);
61591 #ifdef CONFIG_SMP
61592 if (x < 0)
61593 x = 0;
61594 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
61595 static inline unsigned long zone_page_state(struct zone *zone,
61596 enum zone_stat_item item)
61597 {
61598 - long x = atomic_long_read(&zone->vm_stat[item]);
61599 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61600 #ifdef CONFIG_SMP
61601 if (x < 0)
61602 x = 0;
61603 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
61604 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
61605 enum zone_stat_item item)
61606 {
61607 - long x = atomic_long_read(&zone->vm_stat[item]);
61608 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
61609
61610 #ifdef CONFIG_SMP
61611 int cpu;
61612 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
61613
61614 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
61615 {
61616 - atomic_long_inc(&zone->vm_stat[item]);
61617 - atomic_long_inc(&vm_stat[item]);
61618 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
61619 + atomic_long_inc_unchecked(&vm_stat[item]);
61620 }
61621
61622 static inline void __inc_zone_page_state(struct page *page,
61623 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
61624
61625 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
61626 {
61627 - atomic_long_dec(&zone->vm_stat[item]);
61628 - atomic_long_dec(&vm_stat[item]);
61629 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
61630 + atomic_long_dec_unchecked(&vm_stat[item]);
61631 }
61632
61633 static inline void __dec_zone_page_state(struct page *page,
61634 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
61635 index e5d1220..ef6e406 100644
61636 --- a/include/linux/xattr.h
61637 +++ b/include/linux/xattr.h
61638 @@ -57,6 +57,11 @@
61639 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
61640 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
61641
61642 +/* User namespace */
61643 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
61644 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
61645 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
61646 +
61647 #ifdef __KERNEL__
61648
61649 #include <linux/types.h>
61650 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
61651 index 4aeff96..b378cdc 100644
61652 --- a/include/media/saa7146_vv.h
61653 +++ b/include/media/saa7146_vv.h
61654 @@ -163,7 +163,7 @@ struct saa7146_ext_vv
61655 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
61656
61657 /* the extension can override this */
61658 - struct v4l2_ioctl_ops ops;
61659 + v4l2_ioctl_ops_no_const ops;
61660 /* pointer to the saa7146 core ops */
61661 const struct v4l2_ioctl_ops *core_ops;
61662
61663 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
61664 index c7c40f1..4f01585 100644
61665 --- a/include/media/v4l2-dev.h
61666 +++ b/include/media/v4l2-dev.h
61667 @@ -56,7 +56,7 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority local);
61668
61669
61670 struct v4l2_file_operations {
61671 - struct module *owner;
61672 + struct module * const owner;
61673 ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
61674 ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
61675 unsigned int (*poll) (struct file *, struct poll_table_struct *);
61676 @@ -68,6 +68,7 @@ struct v4l2_file_operations {
61677 int (*open) (struct file *);
61678 int (*release) (struct file *);
61679 };
61680 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
61681
61682 /*
61683 * Newer version of video_device, handled by videodev2.c
61684 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
61685 index 4d1c74a..65e1221 100644
61686 --- a/include/media/v4l2-ioctl.h
61687 +++ b/include/media/v4l2-ioctl.h
61688 @@ -274,7 +274,7 @@ struct v4l2_ioctl_ops {
61689 long (*vidioc_default) (struct file *file, void *fh,
61690 bool valid_prio, int cmd, void *arg);
61691 };
61692 -
61693 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
61694
61695 /* v4l debugging and diagnostics */
61696
61697 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
61698 index 8d55251..dfe5b0a 100644
61699 --- a/include/net/caif/caif_hsi.h
61700 +++ b/include/net/caif/caif_hsi.h
61701 @@ -98,7 +98,7 @@ struct cfhsi_drv {
61702 void (*rx_done_cb) (struct cfhsi_drv *drv);
61703 void (*wake_up_cb) (struct cfhsi_drv *drv);
61704 void (*wake_down_cb) (struct cfhsi_drv *drv);
61705 -};
61706 +} __no_const;
61707
61708 /* Structure implemented by HSI device. */
61709 struct cfhsi_dev {
61710 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
61711 index 9e5425b..8136ffc 100644
61712 --- a/include/net/caif/cfctrl.h
61713 +++ b/include/net/caif/cfctrl.h
61714 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
61715 void (*radioset_rsp)(void);
61716 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
61717 struct cflayer *client_layer);
61718 -};
61719 +} __no_const;
61720
61721 /* Link Setup Parameters for CAIF-Links. */
61722 struct cfctrl_link_param {
61723 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
61724 struct cfctrl {
61725 struct cfsrvl serv;
61726 struct cfctrl_rsp res;
61727 - atomic_t req_seq_no;
61728 - atomic_t rsp_seq_no;
61729 + atomic_unchecked_t req_seq_no;
61730 + atomic_unchecked_t rsp_seq_no;
61731 struct list_head list;
61732 /* Protects from simultaneous access to first_req list */
61733 spinlock_t info_list_lock;
61734 diff --git a/include/net/flow.h b/include/net/flow.h
61735 index 57f15a7..0de26c6 100644
61736 --- a/include/net/flow.h
61737 +++ b/include/net/flow.h
61738 @@ -208,6 +208,6 @@ extern struct flow_cache_object *flow_cache_lookup(
61739
61740 extern void flow_cache_flush(void);
61741 extern void flow_cache_flush_deferred(void);
61742 -extern atomic_t flow_cache_genid;
61743 +extern atomic_unchecked_t flow_cache_genid;
61744
61745 #endif
61746 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
61747 index e9ff3fc..9d3e5c7 100644
61748 --- a/include/net/inetpeer.h
61749 +++ b/include/net/inetpeer.h
61750 @@ -48,8 +48,8 @@ struct inet_peer {
61751 */
61752 union {
61753 struct {
61754 - atomic_t rid; /* Frag reception counter */
61755 - atomic_t ip_id_count; /* IP ID for the next packet */
61756 + atomic_unchecked_t rid; /* Frag reception counter */
61757 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
61758 __u32 tcp_ts;
61759 __u32 tcp_ts_stamp;
61760 };
61761 @@ -113,11 +113,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
61762 more++;
61763 inet_peer_refcheck(p);
61764 do {
61765 - old = atomic_read(&p->ip_id_count);
61766 + old = atomic_read_unchecked(&p->ip_id_count);
61767 new = old + more;
61768 if (!new)
61769 new = 1;
61770 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
61771 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
61772 return new;
61773 }
61774
61775 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
61776 index 10422ef..662570f 100644
61777 --- a/include/net/ip_fib.h
61778 +++ b/include/net/ip_fib.h
61779 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
61780
61781 #define FIB_RES_SADDR(net, res) \
61782 ((FIB_RES_NH(res).nh_saddr_genid == \
61783 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
61784 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
61785 FIB_RES_NH(res).nh_saddr : \
61786 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
61787 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
61788 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
61789 index e5a7b9a..f4fc44b 100644
61790 --- a/include/net/ip_vs.h
61791 +++ b/include/net/ip_vs.h
61792 @@ -509,7 +509,7 @@ struct ip_vs_conn {
61793 struct ip_vs_conn *control; /* Master control connection */
61794 atomic_t n_control; /* Number of controlled ones */
61795 struct ip_vs_dest *dest; /* real server */
61796 - atomic_t in_pkts; /* incoming packet counter */
61797 + atomic_unchecked_t in_pkts; /* incoming packet counter */
61798
61799 /* packet transmitter for different forwarding methods. If it
61800 mangles the packet, it must return NF_DROP or better NF_STOLEN,
61801 @@ -647,7 +647,7 @@ struct ip_vs_dest {
61802 __be16 port; /* port number of the server */
61803 union nf_inet_addr addr; /* IP address of the server */
61804 volatile unsigned flags; /* dest status flags */
61805 - atomic_t conn_flags; /* flags to copy to conn */
61806 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
61807 atomic_t weight; /* server weight */
61808
61809 atomic_t refcnt; /* reference counter */
61810 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
61811 index 69b610a..fe3962c 100644
61812 --- a/include/net/irda/ircomm_core.h
61813 +++ b/include/net/irda/ircomm_core.h
61814 @@ -51,7 +51,7 @@ typedef struct {
61815 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
61816 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
61817 struct ircomm_info *);
61818 -} call_t;
61819 +} __no_const call_t;
61820
61821 struct ircomm_cb {
61822 irda_queue_t queue;
61823 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
61824 index 59ba38bc..d515662 100644
61825 --- a/include/net/irda/ircomm_tty.h
61826 +++ b/include/net/irda/ircomm_tty.h
61827 @@ -35,6 +35,7 @@
61828 #include <linux/termios.h>
61829 #include <linux/timer.h>
61830 #include <linux/tty.h> /* struct tty_struct */
61831 +#include <asm/local.h>
61832
61833 #include <net/irda/irias_object.h>
61834 #include <net/irda/ircomm_core.h>
61835 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
61836 unsigned short close_delay;
61837 unsigned short closing_wait; /* time to wait before closing */
61838
61839 - int open_count;
61840 - int blocked_open; /* # of blocked opens */
61841 + local_t open_count;
61842 + local_t blocked_open; /* # of blocked opens */
61843
61844 /* Protect concurent access to :
61845 * o self->open_count
61846 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
61847 index f2419cf..473679f 100644
61848 --- a/include/net/iucv/af_iucv.h
61849 +++ b/include/net/iucv/af_iucv.h
61850 @@ -139,7 +139,7 @@ struct iucv_sock {
61851 struct iucv_sock_list {
61852 struct hlist_head head;
61853 rwlock_t lock;
61854 - atomic_t autobind_name;
61855 + atomic_unchecked_t autobind_name;
61856 };
61857
61858 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
61859 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
61860 index 2720884..3aa5c25 100644
61861 --- a/include/net/neighbour.h
61862 +++ b/include/net/neighbour.h
61863 @@ -122,7 +122,7 @@ struct neigh_ops {
61864 void (*error_report)(struct neighbour *, struct sk_buff *);
61865 int (*output)(struct neighbour *, struct sk_buff *);
61866 int (*connected_output)(struct neighbour *, struct sk_buff *);
61867 -};
61868 +} __do_const;
61869
61870 struct pneigh_entry {
61871 struct pneigh_entry *next;
61872 diff --git a/include/net/netlink.h b/include/net/netlink.h
61873 index cb1f350..3279d2c 100644
61874 --- a/include/net/netlink.h
61875 +++ b/include/net/netlink.h
61876 @@ -569,7 +569,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
61877 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
61878 {
61879 if (mark)
61880 - skb_trim(skb, (unsigned char *) mark - skb->data);
61881 + skb_trim(skb, (const unsigned char *) mark - skb->data);
61882 }
61883
61884 /**
61885 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
61886 index d786b4f..4c3dd41 100644
61887 --- a/include/net/netns/ipv4.h
61888 +++ b/include/net/netns/ipv4.h
61889 @@ -56,8 +56,8 @@ struct netns_ipv4 {
61890
61891 unsigned int sysctl_ping_group_range[2];
61892
61893 - atomic_t rt_genid;
61894 - atomic_t dev_addr_genid;
61895 + atomic_unchecked_t rt_genid;
61896 + atomic_unchecked_t dev_addr_genid;
61897
61898 #ifdef CONFIG_IP_MROUTE
61899 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
61900 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
61901 index 6a72a58..e6a127d 100644
61902 --- a/include/net/sctp/sctp.h
61903 +++ b/include/net/sctp/sctp.h
61904 @@ -318,9 +318,9 @@ do { \
61905
61906 #else /* SCTP_DEBUG */
61907
61908 -#define SCTP_DEBUG_PRINTK(whatever...)
61909 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
61910 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
61911 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
61912 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
61913 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
61914 #define SCTP_ENABLE_DEBUG
61915 #define SCTP_DISABLE_DEBUG
61916 #define SCTP_ASSERT(expr, str, func)
61917 diff --git a/include/net/sock.h b/include/net/sock.h
61918 index 32e3937..87a1dbc 100644
61919 --- a/include/net/sock.h
61920 +++ b/include/net/sock.h
61921 @@ -277,7 +277,7 @@ struct sock {
61922 #ifdef CONFIG_RPS
61923 __u32 sk_rxhash;
61924 #endif
61925 - atomic_t sk_drops;
61926 + atomic_unchecked_t sk_drops;
61927 int sk_rcvbuf;
61928
61929 struct sk_filter __rcu *sk_filter;
61930 @@ -1402,7 +1402,7 @@ static inline void sk_nocaps_add(struct sock *sk, int flags)
61931 }
61932
61933 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
61934 - char __user *from, char *to,
61935 + char __user *from, unsigned char *to,
61936 int copy, int offset)
61937 {
61938 if (skb->ip_summed == CHECKSUM_NONE) {
61939 diff --git a/include/net/tcp.h b/include/net/tcp.h
61940 index bb18c4d..bb87972 100644
61941 --- a/include/net/tcp.h
61942 +++ b/include/net/tcp.h
61943 @@ -1409,7 +1409,7 @@ struct tcp_seq_afinfo {
61944 char *name;
61945 sa_family_t family;
61946 const struct file_operations *seq_fops;
61947 - struct seq_operations seq_ops;
61948 + seq_operations_no_const seq_ops;
61949 };
61950
61951 struct tcp_iter_state {
61952 diff --git a/include/net/udp.h b/include/net/udp.h
61953 index 3b285f4..0219639 100644
61954 --- a/include/net/udp.h
61955 +++ b/include/net/udp.h
61956 @@ -237,7 +237,7 @@ struct udp_seq_afinfo {
61957 sa_family_t family;
61958 struct udp_table *udp_table;
61959 const struct file_operations *seq_fops;
61960 - struct seq_operations seq_ops;
61961 + seq_operations_no_const seq_ops;
61962 };
61963
61964 struct udp_iter_state {
61965 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
61966 index b203e14..1df3991 100644
61967 --- a/include/net/xfrm.h
61968 +++ b/include/net/xfrm.h
61969 @@ -505,7 +505,7 @@ struct xfrm_policy {
61970 struct timer_list timer;
61971
61972 struct flow_cache_object flo;
61973 - atomic_t genid;
61974 + atomic_unchecked_t genid;
61975 u32 priority;
61976 u32 index;
61977 struct xfrm_mark mark;
61978 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
61979 index 1a046b1..ee0bef0 100644
61980 --- a/include/rdma/iw_cm.h
61981 +++ b/include/rdma/iw_cm.h
61982 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
61983 int backlog);
61984
61985 int (*destroy_listen)(struct iw_cm_id *cm_id);
61986 -};
61987 +} __no_const;
61988
61989 /**
61990 * iw_create_cm_id - Create an IW CM identifier.
61991 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
61992 index 5d1a758..1dbf795 100644
61993 --- a/include/scsi/libfc.h
61994 +++ b/include/scsi/libfc.h
61995 @@ -748,6 +748,7 @@ struct libfc_function_template {
61996 */
61997 void (*disc_stop_final) (struct fc_lport *);
61998 };
61999 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
62000
62001 /**
62002 * struct fc_disc - Discovery context
62003 @@ -851,7 +852,7 @@ struct fc_lport {
62004 struct fc_vport *vport;
62005
62006 /* Operational Information */
62007 - struct libfc_function_template tt;
62008 + libfc_function_template_no_const tt;
62009 u8 link_up;
62010 u8 qfull;
62011 enum fc_lport_state state;
62012 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
62013 index 5591ed5..13eb457 100644
62014 --- a/include/scsi/scsi_device.h
62015 +++ b/include/scsi/scsi_device.h
62016 @@ -161,9 +161,9 @@ struct scsi_device {
62017 unsigned int max_device_blocked; /* what device_blocked counts down from */
62018 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
62019
62020 - atomic_t iorequest_cnt;
62021 - atomic_t iodone_cnt;
62022 - atomic_t ioerr_cnt;
62023 + atomic_unchecked_t iorequest_cnt;
62024 + atomic_unchecked_t iodone_cnt;
62025 + atomic_unchecked_t ioerr_cnt;
62026
62027 struct device sdev_gendev,
62028 sdev_dev;
62029 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
62030 index 2a65167..91e01f8 100644
62031 --- a/include/scsi/scsi_transport_fc.h
62032 +++ b/include/scsi/scsi_transport_fc.h
62033 @@ -711,7 +711,7 @@ struct fc_function_template {
62034 unsigned long show_host_system_hostname:1;
62035
62036 unsigned long disable_target_scan:1;
62037 -};
62038 +} __do_const;
62039
62040
62041 /**
62042 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
62043 index 030b87c..98a6954 100644
62044 --- a/include/sound/ak4xxx-adda.h
62045 +++ b/include/sound/ak4xxx-adda.h
62046 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
62047 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
62048 unsigned char val);
62049 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
62050 -};
62051 +} __no_const;
62052
62053 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
62054
62055 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
62056 index 8c05e47..2b5df97 100644
62057 --- a/include/sound/hwdep.h
62058 +++ b/include/sound/hwdep.h
62059 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
62060 struct snd_hwdep_dsp_status *status);
62061 int (*dsp_load)(struct snd_hwdep *hw,
62062 struct snd_hwdep_dsp_image *image);
62063 -};
62064 +} __no_const;
62065
62066 struct snd_hwdep {
62067 struct snd_card *card;
62068 diff --git a/include/sound/info.h b/include/sound/info.h
62069 index 5492cc4..1a65278 100644
62070 --- a/include/sound/info.h
62071 +++ b/include/sound/info.h
62072 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
62073 struct snd_info_buffer *buffer);
62074 void (*write)(struct snd_info_entry *entry,
62075 struct snd_info_buffer *buffer);
62076 -};
62077 +} __no_const;
62078
62079 struct snd_info_entry_ops {
62080 int (*open)(struct snd_info_entry *entry,
62081 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
62082 index 0cf91b2..b70cae4 100644
62083 --- a/include/sound/pcm.h
62084 +++ b/include/sound/pcm.h
62085 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
62086 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
62087 int (*ack)(struct snd_pcm_substream *substream);
62088 };
62089 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
62090
62091 /*
62092 *
62093 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
62094 index af1b49e..a5d55a5 100644
62095 --- a/include/sound/sb16_csp.h
62096 +++ b/include/sound/sb16_csp.h
62097 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
62098 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
62099 int (*csp_stop) (struct snd_sb_csp * p);
62100 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
62101 -};
62102 +} __no_const;
62103
62104 /*
62105 * CSP private data
62106 diff --git a/include/sound/soc.h b/include/sound/soc.h
62107 index 11cfb59..e3f93f4 100644
62108 --- a/include/sound/soc.h
62109 +++ b/include/sound/soc.h
62110 @@ -683,7 +683,7 @@ struct snd_soc_platform_driver {
62111 /* platform IO - used for platform DAPM */
62112 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
62113 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
62114 -};
62115 +} __do_const;
62116
62117 struct snd_soc_platform {
62118 const char *name;
62119 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
62120 index 444cd6b..3327cc5 100644
62121 --- a/include/sound/ymfpci.h
62122 +++ b/include/sound/ymfpci.h
62123 @@ -358,7 +358,7 @@ struct snd_ymfpci {
62124 spinlock_t reg_lock;
62125 spinlock_t voice_lock;
62126 wait_queue_head_t interrupt_sleep;
62127 - atomic_t interrupt_sleep_count;
62128 + atomic_unchecked_t interrupt_sleep_count;
62129 struct snd_info_entry *proc_entry;
62130 const struct firmware *dsp_microcode;
62131 const struct firmware *controller_microcode;
62132 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
62133 index a79886c..b483af6 100644
62134 --- a/include/target/target_core_base.h
62135 +++ b/include/target/target_core_base.h
62136 @@ -346,7 +346,7 @@ struct t10_reservation_ops {
62137 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
62138 int (*t10_pr_register)(struct se_cmd *);
62139 int (*t10_pr_clear)(struct se_cmd *);
62140 -};
62141 +} __no_const;
62142
62143 struct t10_reservation {
62144 /* Reservation effects all target ports */
62145 @@ -465,8 +465,8 @@ struct se_cmd {
62146 atomic_t t_se_count;
62147 atomic_t t_task_cdbs_left;
62148 atomic_t t_task_cdbs_ex_left;
62149 - atomic_t t_task_cdbs_sent;
62150 - atomic_t t_transport_aborted;
62151 + atomic_unchecked_t t_task_cdbs_sent;
62152 + atomic_unchecked_t t_transport_aborted;
62153 atomic_t t_transport_active;
62154 atomic_t t_transport_complete;
62155 atomic_t t_transport_queue_active;
62156 @@ -704,7 +704,7 @@ struct se_device {
62157 /* Active commands on this virtual SE device */
62158 atomic_t simple_cmds;
62159 atomic_t depth_left;
62160 - atomic_t dev_ordered_id;
62161 + atomic_unchecked_t dev_ordered_id;
62162 atomic_t execute_tasks;
62163 atomic_t dev_ordered_sync;
62164 atomic_t dev_qf_count;
62165 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
62166 index 1c09820..7f5ec79 100644
62167 --- a/include/trace/events/irq.h
62168 +++ b/include/trace/events/irq.h
62169 @@ -36,7 +36,7 @@ struct softirq_action;
62170 */
62171 TRACE_EVENT(irq_handler_entry,
62172
62173 - TP_PROTO(int irq, struct irqaction *action),
62174 + TP_PROTO(int irq, const struct irqaction *action),
62175
62176 TP_ARGS(irq, action),
62177
62178 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
62179 */
62180 TRACE_EVENT(irq_handler_exit,
62181
62182 - TP_PROTO(int irq, struct irqaction *action, int ret),
62183 + TP_PROTO(int irq, const struct irqaction *action, int ret),
62184
62185 TP_ARGS(irq, action, ret),
62186
62187 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
62188 index c41f308..6918de3 100644
62189 --- a/include/video/udlfb.h
62190 +++ b/include/video/udlfb.h
62191 @@ -52,10 +52,10 @@ struct dlfb_data {
62192 u32 pseudo_palette[256];
62193 int blank_mode; /*one of FB_BLANK_ */
62194 /* blit-only rendering path metrics, exposed through sysfs */
62195 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
62196 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
62197 - atomic_t bytes_sent; /* to usb, after compression including overhead */
62198 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
62199 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
62200 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
62201 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
62202 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
62203 };
62204
62205 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
62206 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
62207 index 0993a22..32ba2fe 100644
62208 --- a/include/video/uvesafb.h
62209 +++ b/include/video/uvesafb.h
62210 @@ -177,6 +177,7 @@ struct uvesafb_par {
62211 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
62212 u8 pmi_setpal; /* PMI for palette changes */
62213 u16 *pmi_base; /* protected mode interface location */
62214 + u8 *pmi_code; /* protected mode code location */
62215 void *pmi_start;
62216 void *pmi_pal;
62217 u8 *vbe_state_orig; /*
62218 diff --git a/init/Kconfig b/init/Kconfig
62219 index 43298f9..2f56c12 100644
62220 --- a/init/Kconfig
62221 +++ b/init/Kconfig
62222 @@ -1214,7 +1214,7 @@ config SLUB_DEBUG
62223
62224 config COMPAT_BRK
62225 bool "Disable heap randomization"
62226 - default y
62227 + default n
62228 help
62229 Randomizing heap placement makes heap exploits harder, but it
62230 also breaks ancient binaries (including anything libc5 based).
62231 diff --git a/init/do_mounts.c b/init/do_mounts.c
62232 index db6e5ee..7677ff7 100644
62233 --- a/init/do_mounts.c
62234 +++ b/init/do_mounts.c
62235 @@ -325,11 +325,11 @@ static void __init get_fs_names(char *page)
62236
62237 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
62238 {
62239 - int err = sys_mount(name, "/root", fs, flags, data);
62240 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
62241 if (err)
62242 return err;
62243
62244 - sys_chdir((const char __user __force *)"/root");
62245 + sys_chdir((const char __force_user*)"/root");
62246 ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
62247 printk(KERN_INFO
62248 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
62249 @@ -448,18 +448,18 @@ void __init change_floppy(char *fmt, ...)
62250 va_start(args, fmt);
62251 vsprintf(buf, fmt, args);
62252 va_end(args);
62253 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
62254 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
62255 if (fd >= 0) {
62256 sys_ioctl(fd, FDEJECT, 0);
62257 sys_close(fd);
62258 }
62259 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
62260 - fd = sys_open("/dev/console", O_RDWR, 0);
62261 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
62262 if (fd >= 0) {
62263 sys_ioctl(fd, TCGETS, (long)&termios);
62264 termios.c_lflag &= ~ICANON;
62265 sys_ioctl(fd, TCSETSF, (long)&termios);
62266 - sys_read(fd, &c, 1);
62267 + sys_read(fd, (char __user *)&c, 1);
62268 termios.c_lflag |= ICANON;
62269 sys_ioctl(fd, TCSETSF, (long)&termios);
62270 sys_close(fd);
62271 @@ -553,6 +553,6 @@ void __init prepare_namespace(void)
62272 mount_root();
62273 out:
62274 devtmpfs_mount("dev");
62275 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
62276 - sys_chroot((const char __user __force *)".");
62277 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
62278 + sys_chroot((const char __force_user *)".");
62279 }
62280 diff --git a/init/do_mounts.h b/init/do_mounts.h
62281 index f5b978a..69dbfe8 100644
62282 --- a/init/do_mounts.h
62283 +++ b/init/do_mounts.h
62284 @@ -15,15 +15,15 @@ extern int root_mountflags;
62285
62286 static inline int create_dev(char *name, dev_t dev)
62287 {
62288 - sys_unlink(name);
62289 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
62290 + sys_unlink((char __force_user *)name);
62291 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
62292 }
62293
62294 #if BITS_PER_LONG == 32
62295 static inline u32 bstat(char *name)
62296 {
62297 struct stat64 stat;
62298 - if (sys_stat64(name, &stat) != 0)
62299 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
62300 return 0;
62301 if (!S_ISBLK(stat.st_mode))
62302 return 0;
62303 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
62304 static inline u32 bstat(char *name)
62305 {
62306 struct stat stat;
62307 - if (sys_newstat(name, &stat) != 0)
62308 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
62309 return 0;
62310 if (!S_ISBLK(stat.st_mode))
62311 return 0;
62312 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
62313 index 3098a38..253064e 100644
62314 --- a/init/do_mounts_initrd.c
62315 +++ b/init/do_mounts_initrd.c
62316 @@ -44,13 +44,13 @@ static void __init handle_initrd(void)
62317 create_dev("/dev/root.old", Root_RAM0);
62318 /* mount initrd on rootfs' /root */
62319 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
62320 - sys_mkdir("/old", 0700);
62321 - root_fd = sys_open("/", 0, 0);
62322 - old_fd = sys_open("/old", 0, 0);
62323 + sys_mkdir((const char __force_user *)"/old", 0700);
62324 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
62325 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
62326 /* move initrd over / and chdir/chroot in initrd root */
62327 - sys_chdir("/root");
62328 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
62329 - sys_chroot(".");
62330 + sys_chdir((const char __force_user *)"/root");
62331 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
62332 + sys_chroot((const char __force_user *)".");
62333
62334 /*
62335 * In case that a resume from disk is carried out by linuxrc or one of
62336 @@ -67,15 +67,15 @@ static void __init handle_initrd(void)
62337
62338 /* move initrd to rootfs' /old */
62339 sys_fchdir(old_fd);
62340 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
62341 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
62342 /* switch root and cwd back to / of rootfs */
62343 sys_fchdir(root_fd);
62344 - sys_chroot(".");
62345 + sys_chroot((const char __force_user *)".");
62346 sys_close(old_fd);
62347 sys_close(root_fd);
62348
62349 if (new_decode_dev(real_root_dev) == Root_RAM0) {
62350 - sys_chdir("/old");
62351 + sys_chdir((const char __force_user *)"/old");
62352 return;
62353 }
62354
62355 @@ -83,17 +83,17 @@ static void __init handle_initrd(void)
62356 mount_root();
62357
62358 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
62359 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
62360 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
62361 if (!error)
62362 printk("okay\n");
62363 else {
62364 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
62365 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
62366 if (error == -ENOENT)
62367 printk("/initrd does not exist. Ignored.\n");
62368 else
62369 printk("failed\n");
62370 printk(KERN_NOTICE "Unmounting old root\n");
62371 - sys_umount("/old", MNT_DETACH);
62372 + sys_umount((char __force_user *)"/old", MNT_DETACH);
62373 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
62374 if (fd < 0) {
62375 error = fd;
62376 @@ -116,11 +116,11 @@ int __init initrd_load(void)
62377 * mounted in the normal path.
62378 */
62379 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
62380 - sys_unlink("/initrd.image");
62381 + sys_unlink((const char __force_user *)"/initrd.image");
62382 handle_initrd();
62383 return 1;
62384 }
62385 }
62386 - sys_unlink("/initrd.image");
62387 + sys_unlink((const char __force_user *)"/initrd.image");
62388 return 0;
62389 }
62390 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
62391 index 32c4799..c27ee74 100644
62392 --- a/init/do_mounts_md.c
62393 +++ b/init/do_mounts_md.c
62394 @@ -170,7 +170,7 @@ static void __init md_setup_drive(void)
62395 partitioned ? "_d" : "", minor,
62396 md_setup_args[ent].device_names);
62397
62398 - fd = sys_open(name, 0, 0);
62399 + fd = sys_open((char __force_user *)name, 0, 0);
62400 if (fd < 0) {
62401 printk(KERN_ERR "md: open failed - cannot start "
62402 "array %s\n", name);
62403 @@ -233,7 +233,7 @@ static void __init md_setup_drive(void)
62404 * array without it
62405 */
62406 sys_close(fd);
62407 - fd = sys_open(name, 0, 0);
62408 + fd = sys_open((char __force_user *)name, 0, 0);
62409 sys_ioctl(fd, BLKRRPART, 0);
62410 }
62411 sys_close(fd);
62412 @@ -283,7 +283,7 @@ static void __init autodetect_raid(void)
62413
62414 wait_for_device_probe();
62415
62416 - fd = sys_open((const char __user __force *) "/dev/md0", 0, 0);
62417 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
62418 if (fd >= 0) {
62419 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
62420 sys_close(fd);
62421 diff --git a/init/initramfs.c b/init/initramfs.c
62422 index 2531811..040d4d4 100644
62423 --- a/init/initramfs.c
62424 +++ b/init/initramfs.c
62425 @@ -74,7 +74,7 @@ static void __init free_hash(void)
62426 }
62427 }
62428
62429 -static long __init do_utime(char __user *filename, time_t mtime)
62430 +static long __init do_utime(__force char __user *filename, time_t mtime)
62431 {
62432 struct timespec t[2];
62433
62434 @@ -109,7 +109,7 @@ static void __init dir_utime(void)
62435 struct dir_entry *de, *tmp;
62436 list_for_each_entry_safe(de, tmp, &dir_list, list) {
62437 list_del(&de->list);
62438 - do_utime(de->name, de->mtime);
62439 + do_utime((char __force_user *)de->name, de->mtime);
62440 kfree(de->name);
62441 kfree(de);
62442 }
62443 @@ -271,7 +271,7 @@ static int __init maybe_link(void)
62444 if (nlink >= 2) {
62445 char *old = find_link(major, minor, ino, mode, collected);
62446 if (old)
62447 - return (sys_link(old, collected) < 0) ? -1 : 1;
62448 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
62449 }
62450 return 0;
62451 }
62452 @@ -280,11 +280,11 @@ static void __init clean_path(char *path, mode_t mode)
62453 {
62454 struct stat st;
62455
62456 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
62457 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
62458 if (S_ISDIR(st.st_mode))
62459 - sys_rmdir(path);
62460 + sys_rmdir((char __force_user *)path);
62461 else
62462 - sys_unlink(path);
62463 + sys_unlink((char __force_user *)path);
62464 }
62465 }
62466
62467 @@ -305,7 +305,7 @@ static int __init do_name(void)
62468 int openflags = O_WRONLY|O_CREAT;
62469 if (ml != 1)
62470 openflags |= O_TRUNC;
62471 - wfd = sys_open(collected, openflags, mode);
62472 + wfd = sys_open((char __force_user *)collected, openflags, mode);
62473
62474 if (wfd >= 0) {
62475 sys_fchown(wfd, uid, gid);
62476 @@ -317,17 +317,17 @@ static int __init do_name(void)
62477 }
62478 }
62479 } else if (S_ISDIR(mode)) {
62480 - sys_mkdir(collected, mode);
62481 - sys_chown(collected, uid, gid);
62482 - sys_chmod(collected, mode);
62483 + sys_mkdir((char __force_user *)collected, mode);
62484 + sys_chown((char __force_user *)collected, uid, gid);
62485 + sys_chmod((char __force_user *)collected, mode);
62486 dir_add(collected, mtime);
62487 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
62488 S_ISFIFO(mode) || S_ISSOCK(mode)) {
62489 if (maybe_link() == 0) {
62490 - sys_mknod(collected, mode, rdev);
62491 - sys_chown(collected, uid, gid);
62492 - sys_chmod(collected, mode);
62493 - do_utime(collected, mtime);
62494 + sys_mknod((char __force_user *)collected, mode, rdev);
62495 + sys_chown((char __force_user *)collected, uid, gid);
62496 + sys_chmod((char __force_user *)collected, mode);
62497 + do_utime((char __force_user *)collected, mtime);
62498 }
62499 }
62500 return 0;
62501 @@ -336,15 +336,15 @@ static int __init do_name(void)
62502 static int __init do_copy(void)
62503 {
62504 if (count >= body_len) {
62505 - sys_write(wfd, victim, body_len);
62506 + sys_write(wfd, (char __force_user *)victim, body_len);
62507 sys_close(wfd);
62508 - do_utime(vcollected, mtime);
62509 + do_utime((char __force_user *)vcollected, mtime);
62510 kfree(vcollected);
62511 eat(body_len);
62512 state = SkipIt;
62513 return 0;
62514 } else {
62515 - sys_write(wfd, victim, count);
62516 + sys_write(wfd, (char __force_user *)victim, count);
62517 body_len -= count;
62518 eat(count);
62519 return 1;
62520 @@ -355,9 +355,9 @@ static int __init do_symlink(void)
62521 {
62522 collected[N_ALIGN(name_len) + body_len] = '\0';
62523 clean_path(collected, 0);
62524 - sys_symlink(collected + N_ALIGN(name_len), collected);
62525 - sys_lchown(collected, uid, gid);
62526 - do_utime(collected, mtime);
62527 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
62528 + sys_lchown((char __force_user *)collected, uid, gid);
62529 + do_utime((char __force_user *)collected, mtime);
62530 state = SkipIt;
62531 next_state = Reset;
62532 return 0;
62533 diff --git a/init/main.c b/init/main.c
62534 index 217ed23..ec5406f 100644
62535 --- a/init/main.c
62536 +++ b/init/main.c
62537 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
62538 extern void tc_init(void);
62539 #endif
62540
62541 +extern void grsecurity_init(void);
62542 +
62543 /*
62544 * Debug helper: via this flag we know that we are in 'early bootup code'
62545 * where only the boot processor is running with IRQ disabled. This means
62546 @@ -149,6 +151,49 @@ static int __init set_reset_devices(char *str)
62547
62548 __setup("reset_devices", set_reset_devices);
62549
62550 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
62551 +extern char pax_enter_kernel_user[];
62552 +extern char pax_exit_kernel_user[];
62553 +extern pgdval_t clone_pgd_mask;
62554 +#endif
62555 +
62556 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
62557 +static int __init setup_pax_nouderef(char *str)
62558 +{
62559 +#ifdef CONFIG_X86_32
62560 + unsigned int cpu;
62561 + struct desc_struct *gdt;
62562 +
62563 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
62564 + gdt = get_cpu_gdt_table(cpu);
62565 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
62566 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
62567 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
62568 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
62569 + }
62570 + asm("mov %0, %%ds; mov %0, %%es; mov %0, %%ss" : : "r" (__KERNEL_DS) : "memory");
62571 +#else
62572 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
62573 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
62574 + clone_pgd_mask = ~(pgdval_t)0UL;
62575 +#endif
62576 +
62577 + return 0;
62578 +}
62579 +early_param("pax_nouderef", setup_pax_nouderef);
62580 +#endif
62581 +
62582 +#ifdef CONFIG_PAX_SOFTMODE
62583 +int pax_softmode;
62584 +
62585 +static int __init setup_pax_softmode(char *str)
62586 +{
62587 + get_option(&str, &pax_softmode);
62588 + return 1;
62589 +}
62590 +__setup("pax_softmode=", setup_pax_softmode);
62591 +#endif
62592 +
62593 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
62594 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
62595 static const char *panic_later, *panic_param;
62596 @@ -681,6 +726,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
62597 {
62598 int count = preempt_count();
62599 int ret;
62600 + const char *msg1 = "", *msg2 = "";
62601
62602 if (initcall_debug)
62603 ret = do_one_initcall_debug(fn);
62604 @@ -693,15 +739,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
62605 sprintf(msgbuf, "error code %d ", ret);
62606
62607 if (preempt_count() != count) {
62608 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
62609 + msg1 = " preemption imbalance";
62610 preempt_count() = count;
62611 }
62612 if (irqs_disabled()) {
62613 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
62614 + msg2 = " disabled interrupts";
62615 local_irq_enable();
62616 }
62617 - if (msgbuf[0]) {
62618 - printk("initcall %pF returned with %s\n", fn, msgbuf);
62619 + if (msgbuf[0] || *msg1 || *msg2) {
62620 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
62621 }
62622
62623 return ret;
62624 @@ -820,7 +866,7 @@ static int __init kernel_init(void * unused)
62625 do_basic_setup();
62626
62627 /* Open the /dev/console on the rootfs, this should never fail */
62628 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
62629 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
62630 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
62631
62632 (void) sys_dup(0);
62633 @@ -833,11 +879,13 @@ static int __init kernel_init(void * unused)
62634 if (!ramdisk_execute_command)
62635 ramdisk_execute_command = "/init";
62636
62637 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
62638 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
62639 ramdisk_execute_command = NULL;
62640 prepare_namespace();
62641 }
62642
62643 + grsecurity_init();
62644 +
62645 /*
62646 * Ok, we have completed the initial bootup, and
62647 * we're essentially up and running. Get rid of the
62648 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
62649 index 5b4293d..f179875 100644
62650 --- a/ipc/mqueue.c
62651 +++ b/ipc/mqueue.c
62652 @@ -156,6 +156,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
62653 mq_bytes = (mq_msg_tblsz +
62654 (info->attr.mq_maxmsg * info->attr.mq_msgsize));
62655
62656 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
62657 spin_lock(&mq_lock);
62658 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
62659 u->mq_bytes + mq_bytes > task_rlimit(p, RLIMIT_MSGQUEUE)) {
62660 diff --git a/ipc/msg.c b/ipc/msg.c
62661 index 7385de2..a8180e0 100644
62662 --- a/ipc/msg.c
62663 +++ b/ipc/msg.c
62664 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
62665 return security_msg_queue_associate(msq, msgflg);
62666 }
62667
62668 +static struct ipc_ops msg_ops = {
62669 + .getnew = newque,
62670 + .associate = msg_security,
62671 + .more_checks = NULL
62672 +};
62673 +
62674 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
62675 {
62676 struct ipc_namespace *ns;
62677 - struct ipc_ops msg_ops;
62678 struct ipc_params msg_params;
62679
62680 ns = current->nsproxy->ipc_ns;
62681
62682 - msg_ops.getnew = newque;
62683 - msg_ops.associate = msg_security;
62684 - msg_ops.more_checks = NULL;
62685 -
62686 msg_params.key = key;
62687 msg_params.flg = msgflg;
62688
62689 diff --git a/ipc/sem.c b/ipc/sem.c
62690 index 5215a81..cfc0cac 100644
62691 --- a/ipc/sem.c
62692 +++ b/ipc/sem.c
62693 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
62694 return 0;
62695 }
62696
62697 +static struct ipc_ops sem_ops = {
62698 + .getnew = newary,
62699 + .associate = sem_security,
62700 + .more_checks = sem_more_checks
62701 +};
62702 +
62703 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62704 {
62705 struct ipc_namespace *ns;
62706 - struct ipc_ops sem_ops;
62707 struct ipc_params sem_params;
62708
62709 ns = current->nsproxy->ipc_ns;
62710 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
62711 if (nsems < 0 || nsems > ns->sc_semmsl)
62712 return -EINVAL;
62713
62714 - sem_ops.getnew = newary;
62715 - sem_ops.associate = sem_security;
62716 - sem_ops.more_checks = sem_more_checks;
62717 -
62718 sem_params.key = key;
62719 sem_params.flg = semflg;
62720 sem_params.u.nsems = nsems;
62721 diff --git a/ipc/shm.c b/ipc/shm.c
62722 index b76be5b..859e750 100644
62723 --- a/ipc/shm.c
62724 +++ b/ipc/shm.c
62725 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
62726 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
62727 #endif
62728
62729 +#ifdef CONFIG_GRKERNSEC
62730 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62731 + const time_t shm_createtime, const uid_t cuid,
62732 + const int shmid);
62733 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62734 + const time_t shm_createtime);
62735 +#endif
62736 +
62737 void shm_init_ns(struct ipc_namespace *ns)
62738 {
62739 ns->shm_ctlmax = SHMMAX;
62740 @@ -508,6 +516,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
62741 shp->shm_lprid = 0;
62742 shp->shm_atim = shp->shm_dtim = 0;
62743 shp->shm_ctim = get_seconds();
62744 +#ifdef CONFIG_GRKERNSEC
62745 + {
62746 + struct timespec timeval;
62747 + do_posix_clock_monotonic_gettime(&timeval);
62748 +
62749 + shp->shm_createtime = timeval.tv_sec;
62750 + }
62751 +#endif
62752 shp->shm_segsz = size;
62753 shp->shm_nattch = 0;
62754 shp->shm_file = file;
62755 @@ -559,18 +575,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
62756 return 0;
62757 }
62758
62759 +static struct ipc_ops shm_ops = {
62760 + .getnew = newseg,
62761 + .associate = shm_security,
62762 + .more_checks = shm_more_checks
62763 +};
62764 +
62765 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
62766 {
62767 struct ipc_namespace *ns;
62768 - struct ipc_ops shm_ops;
62769 struct ipc_params shm_params;
62770
62771 ns = current->nsproxy->ipc_ns;
62772
62773 - shm_ops.getnew = newseg;
62774 - shm_ops.associate = shm_security;
62775 - shm_ops.more_checks = shm_more_checks;
62776 -
62777 shm_params.key = key;
62778 shm_params.flg = shmflg;
62779 shm_params.u.size = size;
62780 @@ -988,6 +1005,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
62781 f_mode = FMODE_READ | FMODE_WRITE;
62782 }
62783 if (shmflg & SHM_EXEC) {
62784 +
62785 +#ifdef CONFIG_PAX_MPROTECT
62786 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
62787 + goto out;
62788 +#endif
62789 +
62790 prot |= PROT_EXEC;
62791 acc_mode |= S_IXUGO;
62792 }
62793 @@ -1011,9 +1034,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
62794 if (err)
62795 goto out_unlock;
62796
62797 +#ifdef CONFIG_GRKERNSEC
62798 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
62799 + shp->shm_perm.cuid, shmid) ||
62800 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
62801 + err = -EACCES;
62802 + goto out_unlock;
62803 + }
62804 +#endif
62805 +
62806 path = shp->shm_file->f_path;
62807 path_get(&path);
62808 shp->shm_nattch++;
62809 +#ifdef CONFIG_GRKERNSEC
62810 + shp->shm_lapid = current->pid;
62811 +#endif
62812 size = i_size_read(path.dentry->d_inode);
62813 shm_unlock(shp);
62814
62815 diff --git a/kernel/acct.c b/kernel/acct.c
62816 index fa7eb3d..7faf116 100644
62817 --- a/kernel/acct.c
62818 +++ b/kernel/acct.c
62819 @@ -570,7 +570,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
62820 */
62821 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
62822 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
62823 - file->f_op->write(file, (char *)&ac,
62824 + file->f_op->write(file, (char __force_user *)&ac,
62825 sizeof(acct_t), &file->f_pos);
62826 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
62827 set_fs(fs);
62828 diff --git a/kernel/audit.c b/kernel/audit.c
62829 index 09fae26..ed71d5b 100644
62830 --- a/kernel/audit.c
62831 +++ b/kernel/audit.c
62832 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
62833 3) suppressed due to audit_rate_limit
62834 4) suppressed due to audit_backlog_limit
62835 */
62836 -static atomic_t audit_lost = ATOMIC_INIT(0);
62837 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
62838
62839 /* The netlink socket. */
62840 static struct sock *audit_sock;
62841 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
62842 unsigned long now;
62843 int print;
62844
62845 - atomic_inc(&audit_lost);
62846 + atomic_inc_unchecked(&audit_lost);
62847
62848 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
62849
62850 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
62851 printk(KERN_WARNING
62852 "audit: audit_lost=%d audit_rate_limit=%d "
62853 "audit_backlog_limit=%d\n",
62854 - atomic_read(&audit_lost),
62855 + atomic_read_unchecked(&audit_lost),
62856 audit_rate_limit,
62857 audit_backlog_limit);
62858 audit_panic(message);
62859 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
62860 status_set.pid = audit_pid;
62861 status_set.rate_limit = audit_rate_limit;
62862 status_set.backlog_limit = audit_backlog_limit;
62863 - status_set.lost = atomic_read(&audit_lost);
62864 + status_set.lost = atomic_read_unchecked(&audit_lost);
62865 status_set.backlog = skb_queue_len(&audit_skb_queue);
62866 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
62867 &status_set, sizeof(status_set));
62868 @@ -1260,12 +1260,13 @@ static void audit_log_vformat(struct audit_buffer *ab, const char *fmt,
62869 avail = audit_expand(ab,
62870 max_t(unsigned, AUDIT_BUFSIZ, 1+len-avail));
62871 if (!avail)
62872 - goto out;
62873 + goto out_va_end;
62874 len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
62875 }
62876 - va_end(args2);
62877 if (len > 0)
62878 skb_put(skb, len);
62879 +out_va_end:
62880 + va_end(args2);
62881 out:
62882 return;
62883 }
62884 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
62885 index 47b7fc1..c003c33 100644
62886 --- a/kernel/auditsc.c
62887 +++ b/kernel/auditsc.c
62888 @@ -1166,8 +1166,8 @@ static void audit_log_execve_info(struct audit_context *context,
62889 struct audit_buffer **ab,
62890 struct audit_aux_data_execve *axi)
62891 {
62892 - int i;
62893 - size_t len, len_sent = 0;
62894 + int i, len;
62895 + size_t len_sent = 0;
62896 const char __user *p;
62897 char *buf;
62898
62899 @@ -2118,7 +2118,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
62900 }
62901
62902 /* global counter which is incremented every time something logs in */
62903 -static atomic_t session_id = ATOMIC_INIT(0);
62904 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
62905
62906 /**
62907 * audit_set_loginuid - set a task's audit_context loginuid
62908 @@ -2131,7 +2131,7 @@ static atomic_t session_id = ATOMIC_INIT(0);
62909 */
62910 int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
62911 {
62912 - unsigned int sessionid = atomic_inc_return(&session_id);
62913 + unsigned int sessionid = atomic_inc_return_unchecked(&session_id);
62914 struct audit_context *context = task->audit_context;
62915
62916 if (context && context->in_syscall) {
62917 diff --git a/kernel/capability.c b/kernel/capability.c
62918 index b463871..fa3ea1f 100644
62919 --- a/kernel/capability.c
62920 +++ b/kernel/capability.c
62921 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
62922 * before modification is attempted and the application
62923 * fails.
62924 */
62925 + if (tocopy > ARRAY_SIZE(kdata))
62926 + return -EFAULT;
62927 +
62928 if (copy_to_user(dataptr, kdata, tocopy
62929 * sizeof(struct __user_cap_data_struct))) {
62930 return -EFAULT;
62931 @@ -374,7 +377,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
62932 BUG();
62933 }
62934
62935 - if (security_capable(ns, current_cred(), cap) == 0) {
62936 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable(cap)) {
62937 current->flags |= PF_SUPERPRIV;
62938 return true;
62939 }
62940 @@ -382,6 +385,27 @@ bool ns_capable(struct user_namespace *ns, int cap)
62941 }
62942 EXPORT_SYMBOL(ns_capable);
62943
62944 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
62945 +{
62946 + if (unlikely(!cap_valid(cap))) {
62947 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
62948 + BUG();
62949 + }
62950 +
62951 + if (security_capable(ns, current_cred(), cap) == 0 && gr_is_capable_nolog(cap)) {
62952 + current->flags |= PF_SUPERPRIV;
62953 + return true;
62954 + }
62955 + return false;
62956 +}
62957 +EXPORT_SYMBOL(ns_capable_nolog);
62958 +
62959 +bool capable_nolog(int cap)
62960 +{
62961 + return ns_capable_nolog(&init_user_ns, cap);
62962 +}
62963 +EXPORT_SYMBOL(capable_nolog);
62964 +
62965 /**
62966 * task_ns_capable - Determine whether current task has a superior
62967 * capability targeted at a specific task's user namespace.
62968 @@ -396,6 +420,12 @@ bool task_ns_capable(struct task_struct *t, int cap)
62969 }
62970 EXPORT_SYMBOL(task_ns_capable);
62971
62972 +bool task_ns_capable_nolog(struct task_struct *t, int cap)
62973 +{
62974 + return ns_capable_nolog(task_cred_xxx(t, user)->user_ns, cap);
62975 +}
62976 +EXPORT_SYMBOL(task_ns_capable_nolog);
62977 +
62978 /**
62979 * nsown_capable - Check superior capability to one's own user_ns
62980 * @cap: The capability in question
62981 diff --git a/kernel/compat.c b/kernel/compat.c
62982 index f346ced..aa2b1f4 100644
62983 --- a/kernel/compat.c
62984 +++ b/kernel/compat.c
62985 @@ -13,6 +13,7 @@
62986
62987 #include <linux/linkage.h>
62988 #include <linux/compat.h>
62989 +#include <linux/module.h>
62990 #include <linux/errno.h>
62991 #include <linux/time.h>
62992 #include <linux/signal.h>
62993 @@ -168,7 +169,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
62994 mm_segment_t oldfs;
62995 long ret;
62996
62997 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
62998 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
62999 oldfs = get_fs();
63000 set_fs(KERNEL_DS);
63001 ret = hrtimer_nanosleep_restart(restart);
63002 @@ -200,7 +201,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
63003 oldfs = get_fs();
63004 set_fs(KERNEL_DS);
63005 ret = hrtimer_nanosleep(&tu,
63006 - rmtp ? (struct timespec __user *)&rmt : NULL,
63007 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
63008 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
63009 set_fs(oldfs);
63010
63011 @@ -309,7 +310,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
63012 mm_segment_t old_fs = get_fs();
63013
63014 set_fs(KERNEL_DS);
63015 - ret = sys_sigpending((old_sigset_t __user *) &s);
63016 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
63017 set_fs(old_fs);
63018 if (ret == 0)
63019 ret = put_user(s, set);
63020 @@ -332,8 +333,8 @@ asmlinkage long compat_sys_sigprocmask(int how, compat_old_sigset_t __user *set,
63021 old_fs = get_fs();
63022 set_fs(KERNEL_DS);
63023 ret = sys_sigprocmask(how,
63024 - set ? (old_sigset_t __user *) &s : NULL,
63025 - oset ? (old_sigset_t __user *) &s : NULL);
63026 + set ? (old_sigset_t __force_user *) &s : NULL,
63027 + oset ? (old_sigset_t __force_user *) &s : NULL);
63028 set_fs(old_fs);
63029 if (ret == 0)
63030 if (oset)
63031 @@ -370,7 +371,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
63032 mm_segment_t old_fs = get_fs();
63033
63034 set_fs(KERNEL_DS);
63035 - ret = sys_old_getrlimit(resource, &r);
63036 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
63037 set_fs(old_fs);
63038
63039 if (!ret) {
63040 @@ -442,7 +443,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
63041 mm_segment_t old_fs = get_fs();
63042
63043 set_fs(KERNEL_DS);
63044 - ret = sys_getrusage(who, (struct rusage __user *) &r);
63045 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
63046 set_fs(old_fs);
63047
63048 if (ret)
63049 @@ -469,8 +470,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
63050 set_fs (KERNEL_DS);
63051 ret = sys_wait4(pid,
63052 (stat_addr ?
63053 - (unsigned int __user *) &status : NULL),
63054 - options, (struct rusage __user *) &r);
63055 + (unsigned int __force_user *) &status : NULL),
63056 + options, (struct rusage __force_user *) &r);
63057 set_fs (old_fs);
63058
63059 if (ret > 0) {
63060 @@ -495,8 +496,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
63061 memset(&info, 0, sizeof(info));
63062
63063 set_fs(KERNEL_DS);
63064 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
63065 - uru ? (struct rusage __user *)&ru : NULL);
63066 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
63067 + uru ? (struct rusage __force_user *)&ru : NULL);
63068 set_fs(old_fs);
63069
63070 if ((ret < 0) || (info.si_signo == 0))
63071 @@ -626,8 +627,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
63072 oldfs = get_fs();
63073 set_fs(KERNEL_DS);
63074 err = sys_timer_settime(timer_id, flags,
63075 - (struct itimerspec __user *) &newts,
63076 - (struct itimerspec __user *) &oldts);
63077 + (struct itimerspec __force_user *) &newts,
63078 + (struct itimerspec __force_user *) &oldts);
63079 set_fs(oldfs);
63080 if (!err && old && put_compat_itimerspec(old, &oldts))
63081 return -EFAULT;
63082 @@ -644,7 +645,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
63083 oldfs = get_fs();
63084 set_fs(KERNEL_DS);
63085 err = sys_timer_gettime(timer_id,
63086 - (struct itimerspec __user *) &ts);
63087 + (struct itimerspec __force_user *) &ts);
63088 set_fs(oldfs);
63089 if (!err && put_compat_itimerspec(setting, &ts))
63090 return -EFAULT;
63091 @@ -663,7 +664,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
63092 oldfs = get_fs();
63093 set_fs(KERNEL_DS);
63094 err = sys_clock_settime(which_clock,
63095 - (struct timespec __user *) &ts);
63096 + (struct timespec __force_user *) &ts);
63097 set_fs(oldfs);
63098 return err;
63099 }
63100 @@ -678,7 +679,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
63101 oldfs = get_fs();
63102 set_fs(KERNEL_DS);
63103 err = sys_clock_gettime(which_clock,
63104 - (struct timespec __user *) &ts);
63105 + (struct timespec __force_user *) &ts);
63106 set_fs(oldfs);
63107 if (!err && put_compat_timespec(&ts, tp))
63108 return -EFAULT;
63109 @@ -698,7 +699,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
63110
63111 oldfs = get_fs();
63112 set_fs(KERNEL_DS);
63113 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
63114 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
63115 set_fs(oldfs);
63116
63117 err = compat_put_timex(utp, &txc);
63118 @@ -718,7 +719,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
63119 oldfs = get_fs();
63120 set_fs(KERNEL_DS);
63121 err = sys_clock_getres(which_clock,
63122 - (struct timespec __user *) &ts);
63123 + (struct timespec __force_user *) &ts);
63124 set_fs(oldfs);
63125 if (!err && tp && put_compat_timespec(&ts, tp))
63126 return -EFAULT;
63127 @@ -730,9 +731,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
63128 long err;
63129 mm_segment_t oldfs;
63130 struct timespec tu;
63131 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
63132 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
63133
63134 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
63135 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
63136 oldfs = get_fs();
63137 set_fs(KERNEL_DS);
63138 err = clock_nanosleep_restart(restart);
63139 @@ -764,8 +765,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
63140 oldfs = get_fs();
63141 set_fs(KERNEL_DS);
63142 err = sys_clock_nanosleep(which_clock, flags,
63143 - (struct timespec __user *) &in,
63144 - (struct timespec __user *) &out);
63145 + (struct timespec __force_user *) &in,
63146 + (struct timespec __force_user *) &out);
63147 set_fs(oldfs);
63148
63149 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
63150 diff --git a/kernel/configs.c b/kernel/configs.c
63151 index 42e8fa0..9e7406b 100644
63152 --- a/kernel/configs.c
63153 +++ b/kernel/configs.c
63154 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
63155 struct proc_dir_entry *entry;
63156
63157 /* create the current config file */
63158 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63159 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
63160 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
63161 + &ikconfig_file_ops);
63162 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63163 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
63164 + &ikconfig_file_ops);
63165 +#endif
63166 +#else
63167 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
63168 &ikconfig_file_ops);
63169 +#endif
63170 +
63171 if (!entry)
63172 return -ENOMEM;
63173
63174 diff --git a/kernel/cred.c b/kernel/cred.c
63175 index 5791612..a3c04dc 100644
63176 --- a/kernel/cred.c
63177 +++ b/kernel/cred.c
63178 @@ -204,6 +204,15 @@ void exit_creds(struct task_struct *tsk)
63179 validate_creds(cred);
63180 put_cred(cred);
63181 }
63182 +
63183 +#ifdef CONFIG_GRKERNSEC_SETXID
63184 + cred = (struct cred *) tsk->delayed_cred;
63185 + if (cred) {
63186 + tsk->delayed_cred = NULL;
63187 + validate_creds(cred);
63188 + put_cred(cred);
63189 + }
63190 +#endif
63191 }
63192
63193 /**
63194 @@ -470,7 +479,7 @@ error_put:
63195 * Always returns 0 thus allowing this function to be tail-called at the end
63196 * of, say, sys_setgid().
63197 */
63198 -int commit_creds(struct cred *new)
63199 +static int __commit_creds(struct cred *new)
63200 {
63201 struct task_struct *task = current;
63202 const struct cred *old = task->real_cred;
63203 @@ -489,6 +498,8 @@ int commit_creds(struct cred *new)
63204
63205 get_cred(new); /* we will require a ref for the subj creds too */
63206
63207 + gr_set_role_label(task, new->uid, new->gid);
63208 +
63209 /* dumpability changes */
63210 if (old->euid != new->euid ||
63211 old->egid != new->egid ||
63212 @@ -538,6 +549,92 @@ int commit_creds(struct cred *new)
63213 put_cred(old);
63214 return 0;
63215 }
63216 +#ifdef CONFIG_GRKERNSEC_SETXID
63217 +extern int set_user(struct cred *new);
63218 +
63219 +void gr_delayed_cred_worker(void)
63220 +{
63221 + const struct cred *new = current->delayed_cred;
63222 + struct cred *ncred;
63223 +
63224 + current->delayed_cred = NULL;
63225 +
63226 + if (current_uid() && new != NULL) {
63227 + // from doing get_cred on it when queueing this
63228 + put_cred(new);
63229 + return;
63230 + } else if (new == NULL)
63231 + return;
63232 +
63233 + ncred = prepare_creds();
63234 + if (!ncred)
63235 + goto die;
63236 + // uids
63237 + ncred->uid = new->uid;
63238 + ncred->euid = new->euid;
63239 + ncred->suid = new->suid;
63240 + ncred->fsuid = new->fsuid;
63241 + // gids
63242 + ncred->gid = new->gid;
63243 + ncred->egid = new->egid;
63244 + ncred->sgid = new->sgid;
63245 + ncred->fsgid = new->fsgid;
63246 + // groups
63247 + if (set_groups(ncred, new->group_info) < 0) {
63248 + abort_creds(ncred);
63249 + goto die;
63250 + }
63251 + // caps
63252 + ncred->securebits = new->securebits;
63253 + ncred->cap_inheritable = new->cap_inheritable;
63254 + ncred->cap_permitted = new->cap_permitted;
63255 + ncred->cap_effective = new->cap_effective;
63256 + ncred->cap_bset = new->cap_bset;
63257 +
63258 + if (set_user(ncred)) {
63259 + abort_creds(ncred);
63260 + goto die;
63261 + }
63262 +
63263 + // from doing get_cred on it when queueing this
63264 + put_cred(new);
63265 +
63266 + __commit_creds(ncred);
63267 + return;
63268 +die:
63269 + // from doing get_cred on it when queueing this
63270 + put_cred(new);
63271 + do_group_exit(SIGKILL);
63272 +}
63273 +#endif
63274 +
63275 +int commit_creds(struct cred *new)
63276 +{
63277 +#ifdef CONFIG_GRKERNSEC_SETXID
63278 + struct task_struct *t;
63279 +
63280 + /* we won't get called with tasklist_lock held for writing
63281 + and interrupts disabled as the cred struct in that case is
63282 + init_cred
63283 + */
63284 + if (grsec_enable_setxid && !current_is_single_threaded() &&
63285 + !current_uid() && new->uid) {
63286 + rcu_read_lock();
63287 + read_lock(&tasklist_lock);
63288 + for (t = next_thread(current); t != current;
63289 + t = next_thread(t)) {
63290 + if (t->delayed_cred == NULL) {
63291 + t->delayed_cred = get_cred(new);
63292 + set_tsk_need_resched(t);
63293 + }
63294 + }
63295 + read_unlock(&tasklist_lock);
63296 + rcu_read_unlock();
63297 + }
63298 +#endif
63299 + return __commit_creds(new);
63300 +}
63301 +
63302 EXPORT_SYMBOL(commit_creds);
63303
63304 /**
63305 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
63306 index 0d7c087..01b8cef 100644
63307 --- a/kernel/debug/debug_core.c
63308 +++ b/kernel/debug/debug_core.c
63309 @@ -119,7 +119,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
63310 */
63311 static atomic_t masters_in_kgdb;
63312 static atomic_t slaves_in_kgdb;
63313 -static atomic_t kgdb_break_tasklet_var;
63314 +static atomic_unchecked_t kgdb_break_tasklet_var;
63315 atomic_t kgdb_setting_breakpoint;
63316
63317 struct task_struct *kgdb_usethread;
63318 @@ -129,7 +129,7 @@ int kgdb_single_step;
63319 static pid_t kgdb_sstep_pid;
63320
63321 /* to keep track of the CPU which is doing the single stepping*/
63322 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63323 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
63324
63325 /*
63326 * If you are debugging a problem where roundup (the collection of
63327 @@ -542,7 +542,7 @@ return_normal:
63328 * kernel will only try for the value of sstep_tries before
63329 * giving up and continuing on.
63330 */
63331 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
63332 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
63333 (kgdb_info[cpu].task &&
63334 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
63335 atomic_set(&kgdb_active, -1);
63336 @@ -636,8 +636,8 @@ cpu_master_loop:
63337 }
63338
63339 kgdb_restore:
63340 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
63341 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
63342 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
63343 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
63344 if (kgdb_info[sstep_cpu].task)
63345 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
63346 else
63347 @@ -834,18 +834,18 @@ static void kgdb_unregister_callbacks(void)
63348 static void kgdb_tasklet_bpt(unsigned long ing)
63349 {
63350 kgdb_breakpoint();
63351 - atomic_set(&kgdb_break_tasklet_var, 0);
63352 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
63353 }
63354
63355 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
63356
63357 void kgdb_schedule_breakpoint(void)
63358 {
63359 - if (atomic_read(&kgdb_break_tasklet_var) ||
63360 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
63361 atomic_read(&kgdb_active) != -1 ||
63362 atomic_read(&kgdb_setting_breakpoint))
63363 return;
63364 - atomic_inc(&kgdb_break_tasklet_var);
63365 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
63366 tasklet_schedule(&kgdb_tasklet_breakpoint);
63367 }
63368 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
63369 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
63370 index 63786e7..0780cac 100644
63371 --- a/kernel/debug/kdb/kdb_main.c
63372 +++ b/kernel/debug/kdb/kdb_main.c
63373 @@ -1980,7 +1980,7 @@ static int kdb_lsmod(int argc, const char **argv)
63374 list_for_each_entry(mod, kdb_modules, list) {
63375
63376 kdb_printf("%-20s%8u 0x%p ", mod->name,
63377 - mod->core_size, (void *)mod);
63378 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
63379 #ifdef CONFIG_MODULE_UNLOAD
63380 kdb_printf("%4d ", module_refcount(mod));
63381 #endif
63382 @@ -1990,7 +1990,7 @@ static int kdb_lsmod(int argc, const char **argv)
63383 kdb_printf(" (Loading)");
63384 else
63385 kdb_printf(" (Live)");
63386 - kdb_printf(" 0x%p", mod->module_core);
63387 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
63388
63389 #ifdef CONFIG_MODULE_UNLOAD
63390 {
63391 diff --git a/kernel/events/core.c b/kernel/events/core.c
63392 index 58690af..d903d75 100644
63393 --- a/kernel/events/core.c
63394 +++ b/kernel/events/core.c
63395 @@ -173,7 +173,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
63396 return 0;
63397 }
63398
63399 -static atomic64_t perf_event_id;
63400 +static atomic64_unchecked_t perf_event_id;
63401
63402 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
63403 enum event_type_t event_type);
63404 @@ -2540,7 +2540,7 @@ static void __perf_event_read(void *info)
63405
63406 static inline u64 perf_event_count(struct perf_event *event)
63407 {
63408 - return local64_read(&event->count) + atomic64_read(&event->child_count);
63409 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
63410 }
63411
63412 static u64 perf_event_read(struct perf_event *event)
63413 @@ -3065,9 +3065,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
63414 mutex_lock(&event->child_mutex);
63415 total += perf_event_read(event);
63416 *enabled += event->total_time_enabled +
63417 - atomic64_read(&event->child_total_time_enabled);
63418 + atomic64_read_unchecked(&event->child_total_time_enabled);
63419 *running += event->total_time_running +
63420 - atomic64_read(&event->child_total_time_running);
63421 + atomic64_read_unchecked(&event->child_total_time_running);
63422
63423 list_for_each_entry(child, &event->child_list, child_list) {
63424 total += perf_event_read(child);
63425 @@ -3474,10 +3474,10 @@ void perf_event_update_userpage(struct perf_event *event)
63426 userpg->offset -= local64_read(&event->hw.prev_count);
63427
63428 userpg->time_enabled = enabled +
63429 - atomic64_read(&event->child_total_time_enabled);
63430 + atomic64_read_unchecked(&event->child_total_time_enabled);
63431
63432 userpg->time_running = running +
63433 - atomic64_read(&event->child_total_time_running);
63434 + atomic64_read_unchecked(&event->child_total_time_running);
63435
63436 barrier();
63437 ++userpg->lock;
63438 @@ -3906,11 +3906,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
63439 values[n++] = perf_event_count(event);
63440 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
63441 values[n++] = enabled +
63442 - atomic64_read(&event->child_total_time_enabled);
63443 + atomic64_read_unchecked(&event->child_total_time_enabled);
63444 }
63445 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
63446 values[n++] = running +
63447 - atomic64_read(&event->child_total_time_running);
63448 + atomic64_read_unchecked(&event->child_total_time_running);
63449 }
63450 if (read_format & PERF_FORMAT_ID)
63451 values[n++] = primary_event_id(event);
63452 @@ -4561,12 +4561,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
63453 * need to add enough zero bytes after the string to handle
63454 * the 64bit alignment we do later.
63455 */
63456 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
63457 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
63458 if (!buf) {
63459 name = strncpy(tmp, "//enomem", sizeof(tmp));
63460 goto got_name;
63461 }
63462 - name = d_path(&file->f_path, buf, PATH_MAX);
63463 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
63464 if (IS_ERR(name)) {
63465 name = strncpy(tmp, "//toolong", sizeof(tmp));
63466 goto got_name;
63467 @@ -5921,7 +5921,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
63468 event->parent = parent_event;
63469
63470 event->ns = get_pid_ns(current->nsproxy->pid_ns);
63471 - event->id = atomic64_inc_return(&perf_event_id);
63472 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
63473
63474 event->state = PERF_EVENT_STATE_INACTIVE;
63475
63476 @@ -6443,10 +6443,10 @@ static void sync_child_event(struct perf_event *child_event,
63477 /*
63478 * Add back the child's count to the parent's count:
63479 */
63480 - atomic64_add(child_val, &parent_event->child_count);
63481 - atomic64_add(child_event->total_time_enabled,
63482 + atomic64_add_unchecked(child_val, &parent_event->child_count);
63483 + atomic64_add_unchecked(child_event->total_time_enabled,
63484 &parent_event->child_total_time_enabled);
63485 - atomic64_add(child_event->total_time_running,
63486 + atomic64_add_unchecked(child_event->total_time_running,
63487 &parent_event->child_total_time_running);
63488
63489 /*
63490 diff --git a/kernel/exit.c b/kernel/exit.c
63491 index e6e01b9..619f837 100644
63492 --- a/kernel/exit.c
63493 +++ b/kernel/exit.c
63494 @@ -57,6 +57,10 @@
63495 #include <asm/pgtable.h>
63496 #include <asm/mmu_context.h>
63497
63498 +#ifdef CONFIG_GRKERNSEC
63499 +extern rwlock_t grsec_exec_file_lock;
63500 +#endif
63501 +
63502 static void exit_mm(struct task_struct * tsk);
63503
63504 static void __unhash_process(struct task_struct *p, bool group_dead)
63505 @@ -168,6 +172,10 @@ void release_task(struct task_struct * p)
63506 struct task_struct *leader;
63507 int zap_leader;
63508 repeat:
63509 +#ifdef CONFIG_NET
63510 + gr_del_task_from_ip_table(p);
63511 +#endif
63512 +
63513 /* don't need to get the RCU readlock here - the process is dead and
63514 * can't be modifying its own credentials. But shut RCU-lockdep up */
63515 rcu_read_lock();
63516 @@ -380,7 +388,7 @@ int allow_signal(int sig)
63517 * know it'll be handled, so that they don't get converted to
63518 * SIGKILL or just silently dropped.
63519 */
63520 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
63521 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
63522 recalc_sigpending();
63523 spin_unlock_irq(&current->sighand->siglock);
63524 return 0;
63525 @@ -416,6 +424,17 @@ void daemonize(const char *name, ...)
63526 vsnprintf(current->comm, sizeof(current->comm), name, args);
63527 va_end(args);
63528
63529 +#ifdef CONFIG_GRKERNSEC
63530 + write_lock(&grsec_exec_file_lock);
63531 + if (current->exec_file) {
63532 + fput(current->exec_file);
63533 + current->exec_file = NULL;
63534 + }
63535 + write_unlock(&grsec_exec_file_lock);
63536 +#endif
63537 +
63538 + gr_set_kernel_label(current);
63539 +
63540 /*
63541 * If we were started as result of loading a module, close all of the
63542 * user space pages. We don't need them, and if we didn't close them
63543 @@ -893,6 +912,8 @@ NORET_TYPE void do_exit(long code)
63544 struct task_struct *tsk = current;
63545 int group_dead;
63546
63547 + set_fs(USER_DS);
63548 +
63549 profile_task_exit(tsk);
63550
63551 WARN_ON(blk_needs_flush_plug(tsk));
63552 @@ -909,7 +930,6 @@ NORET_TYPE void do_exit(long code)
63553 * mm_release()->clear_child_tid() from writing to a user-controlled
63554 * kernel address.
63555 */
63556 - set_fs(USER_DS);
63557
63558 ptrace_event(PTRACE_EVENT_EXIT, code);
63559
63560 @@ -971,6 +991,9 @@ NORET_TYPE void do_exit(long code)
63561 tsk->exit_code = code;
63562 taskstats_exit(tsk, group_dead);
63563
63564 + gr_acl_handle_psacct(tsk, code);
63565 + gr_acl_handle_exit();
63566 +
63567 exit_mm(tsk);
63568
63569 if (group_dead)
63570 diff --git a/kernel/fork.c b/kernel/fork.c
63571 index da4a6a1..0973380 100644
63572 --- a/kernel/fork.c
63573 +++ b/kernel/fork.c
63574 @@ -280,7 +280,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
63575 *stackend = STACK_END_MAGIC; /* for overflow detection */
63576
63577 #ifdef CONFIG_CC_STACKPROTECTOR
63578 - tsk->stack_canary = get_random_int();
63579 + tsk->stack_canary = pax_get_random_long();
63580 #endif
63581
63582 /*
63583 @@ -304,13 +304,77 @@ out:
63584 }
63585
63586 #ifdef CONFIG_MMU
63587 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct vm_area_struct *mpnt)
63588 +{
63589 + struct vm_area_struct *tmp;
63590 + unsigned long charge;
63591 + struct mempolicy *pol;
63592 + struct file *file;
63593 +
63594 + charge = 0;
63595 + if (mpnt->vm_flags & VM_ACCOUNT) {
63596 + unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
63597 + if (security_vm_enough_memory(len))
63598 + goto fail_nomem;
63599 + charge = len;
63600 + }
63601 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
63602 + if (!tmp)
63603 + goto fail_nomem;
63604 + *tmp = *mpnt;
63605 + tmp->vm_mm = mm;
63606 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
63607 + pol = mpol_dup(vma_policy(mpnt));
63608 + if (IS_ERR(pol))
63609 + goto fail_nomem_policy;
63610 + vma_set_policy(tmp, pol);
63611 + if (anon_vma_fork(tmp, mpnt))
63612 + goto fail_nomem_anon_vma_fork;
63613 + tmp->vm_flags &= ~VM_LOCKED;
63614 + tmp->vm_next = tmp->vm_prev = NULL;
63615 + tmp->vm_mirror = NULL;
63616 + file = tmp->vm_file;
63617 + if (file) {
63618 + struct inode *inode = file->f_path.dentry->d_inode;
63619 + struct address_space *mapping = file->f_mapping;
63620 +
63621 + get_file(file);
63622 + if (tmp->vm_flags & VM_DENYWRITE)
63623 + atomic_dec(&inode->i_writecount);
63624 + mutex_lock(&mapping->i_mmap_mutex);
63625 + if (tmp->vm_flags & VM_SHARED)
63626 + mapping->i_mmap_writable++;
63627 + flush_dcache_mmap_lock(mapping);
63628 + /* insert tmp into the share list, just after mpnt */
63629 + vma_prio_tree_add(tmp, mpnt);
63630 + flush_dcache_mmap_unlock(mapping);
63631 + mutex_unlock(&mapping->i_mmap_mutex);
63632 + }
63633 +
63634 + /*
63635 + * Clear hugetlb-related page reserves for children. This only
63636 + * affects MAP_PRIVATE mappings. Faults generated by the child
63637 + * are not guaranteed to succeed, even if read-only
63638 + */
63639 + if (is_vm_hugetlb_page(tmp))
63640 + reset_vma_resv_huge_pages(tmp);
63641 +
63642 + return tmp;
63643 +
63644 +fail_nomem_anon_vma_fork:
63645 + mpol_put(pol);
63646 +fail_nomem_policy:
63647 + kmem_cache_free(vm_area_cachep, tmp);
63648 +fail_nomem:
63649 + vm_unacct_memory(charge);
63650 + return NULL;
63651 +}
63652 +
63653 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63654 {
63655 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
63656 struct rb_node **rb_link, *rb_parent;
63657 int retval;
63658 - unsigned long charge;
63659 - struct mempolicy *pol;
63660
63661 down_write(&oldmm->mmap_sem);
63662 flush_cache_dup_mm(oldmm);
63663 @@ -322,8 +386,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63664 mm->locked_vm = 0;
63665 mm->mmap = NULL;
63666 mm->mmap_cache = NULL;
63667 - mm->free_area_cache = oldmm->mmap_base;
63668 - mm->cached_hole_size = ~0UL;
63669 + mm->free_area_cache = oldmm->free_area_cache;
63670 + mm->cached_hole_size = oldmm->cached_hole_size;
63671 mm->map_count = 0;
63672 cpumask_clear(mm_cpumask(mm));
63673 mm->mm_rb = RB_ROOT;
63674 @@ -339,8 +403,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63675
63676 prev = NULL;
63677 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
63678 - struct file *file;
63679 -
63680 if (mpnt->vm_flags & VM_DONTCOPY) {
63681 long pages = vma_pages(mpnt);
63682 mm->total_vm -= pages;
63683 @@ -348,53 +410,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63684 -pages);
63685 continue;
63686 }
63687 - charge = 0;
63688 - if (mpnt->vm_flags & VM_ACCOUNT) {
63689 - unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
63690 - if (security_vm_enough_memory(len))
63691 - goto fail_nomem;
63692 - charge = len;
63693 + tmp = dup_vma(mm, mpnt);
63694 + if (!tmp) {
63695 + retval = -ENOMEM;
63696 + goto out;
63697 }
63698 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
63699 - if (!tmp)
63700 - goto fail_nomem;
63701 - *tmp = *mpnt;
63702 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
63703 - pol = mpol_dup(vma_policy(mpnt));
63704 - retval = PTR_ERR(pol);
63705 - if (IS_ERR(pol))
63706 - goto fail_nomem_policy;
63707 - vma_set_policy(tmp, pol);
63708 - tmp->vm_mm = mm;
63709 - if (anon_vma_fork(tmp, mpnt))
63710 - goto fail_nomem_anon_vma_fork;
63711 - tmp->vm_flags &= ~VM_LOCKED;
63712 - tmp->vm_next = tmp->vm_prev = NULL;
63713 - file = tmp->vm_file;
63714 - if (file) {
63715 - struct inode *inode = file->f_path.dentry->d_inode;
63716 - struct address_space *mapping = file->f_mapping;
63717 -
63718 - get_file(file);
63719 - if (tmp->vm_flags & VM_DENYWRITE)
63720 - atomic_dec(&inode->i_writecount);
63721 - mutex_lock(&mapping->i_mmap_mutex);
63722 - if (tmp->vm_flags & VM_SHARED)
63723 - mapping->i_mmap_writable++;
63724 - flush_dcache_mmap_lock(mapping);
63725 - /* insert tmp into the share list, just after mpnt */
63726 - vma_prio_tree_add(tmp, mpnt);
63727 - flush_dcache_mmap_unlock(mapping);
63728 - mutex_unlock(&mapping->i_mmap_mutex);
63729 - }
63730 -
63731 - /*
63732 - * Clear hugetlb-related page reserves for children. This only
63733 - * affects MAP_PRIVATE mappings. Faults generated by the child
63734 - * are not guaranteed to succeed, even if read-only
63735 - */
63736 - if (is_vm_hugetlb_page(tmp))
63737 - reset_vma_resv_huge_pages(tmp);
63738
63739 /*
63740 * Link in the new vma and copy the page table entries.
63741 @@ -417,6 +437,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
63742 if (retval)
63743 goto out;
63744 }
63745 +
63746 +#ifdef CONFIG_PAX_SEGMEXEC
63747 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
63748 + struct vm_area_struct *mpnt_m;
63749 +
63750 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
63751 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
63752 +
63753 + if (!mpnt->vm_mirror)
63754 + continue;
63755 +
63756 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
63757 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
63758 + mpnt->vm_mirror = mpnt_m;
63759 + } else {
63760 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
63761 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
63762 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
63763 + mpnt->vm_mirror->vm_mirror = mpnt;
63764 + }
63765 + }
63766 + BUG_ON(mpnt_m);
63767 + }
63768 +#endif
63769 +
63770 /* a new mm has just been created */
63771 arch_dup_mmap(oldmm, mm);
63772 retval = 0;
63773 @@ -425,14 +470,6 @@ out:
63774 flush_tlb_mm(oldmm);
63775 up_write(&oldmm->mmap_sem);
63776 return retval;
63777 -fail_nomem_anon_vma_fork:
63778 - mpol_put(pol);
63779 -fail_nomem_policy:
63780 - kmem_cache_free(vm_area_cachep, tmp);
63781 -fail_nomem:
63782 - retval = -ENOMEM;
63783 - vm_unacct_memory(charge);
63784 - goto out;
63785 }
63786
63787 static inline int mm_alloc_pgd(struct mm_struct *mm)
63788 @@ -644,6 +681,26 @@ struct mm_struct *get_task_mm(struct task_struct *task)
63789 }
63790 EXPORT_SYMBOL_GPL(get_task_mm);
63791
63792 +struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
63793 +{
63794 + struct mm_struct *mm;
63795 + int err;
63796 +
63797 + err = mutex_lock_killable(&task->signal->cred_guard_mutex);
63798 + if (err)
63799 + return ERR_PTR(err);
63800 +
63801 + mm = get_task_mm(task);
63802 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
63803 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
63804 + mmput(mm);
63805 + mm = ERR_PTR(-EACCES);
63806 + }
63807 + mutex_unlock(&task->signal->cred_guard_mutex);
63808 +
63809 + return mm;
63810 +}
63811 +
63812 /* Please note the differences between mmput and mm_release.
63813 * mmput is called whenever we stop holding onto a mm_struct,
63814 * error success whatever.
63815 @@ -829,13 +886,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
63816 spin_unlock(&fs->lock);
63817 return -EAGAIN;
63818 }
63819 - fs->users++;
63820 + atomic_inc(&fs->users);
63821 spin_unlock(&fs->lock);
63822 return 0;
63823 }
63824 tsk->fs = copy_fs_struct(fs);
63825 if (!tsk->fs)
63826 return -ENOMEM;
63827 + gr_set_chroot_entries(tsk, &tsk->fs->root);
63828 return 0;
63829 }
63830
63831 @@ -1097,6 +1155,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
63832 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
63833 #endif
63834 retval = -EAGAIN;
63835 +
63836 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
63837 +
63838 if (atomic_read(&p->real_cred->user->processes) >=
63839 task_rlimit(p, RLIMIT_NPROC)) {
63840 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
63841 @@ -1256,6 +1317,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
63842 if (clone_flags & CLONE_THREAD)
63843 p->tgid = current->tgid;
63844
63845 + gr_copy_label(p);
63846 +
63847 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
63848 /*
63849 * Clear TID on mm_release()?
63850 @@ -1418,6 +1481,8 @@ bad_fork_cleanup_count:
63851 bad_fork_free:
63852 free_task(p);
63853 fork_out:
63854 + gr_log_forkfail(retval);
63855 +
63856 return ERR_PTR(retval);
63857 }
63858
63859 @@ -1518,6 +1583,8 @@ long do_fork(unsigned long clone_flags,
63860 if (clone_flags & CLONE_PARENT_SETTID)
63861 put_user(nr, parent_tidptr);
63862
63863 + gr_handle_brute_check();
63864 +
63865 if (clone_flags & CLONE_VFORK) {
63866 p->vfork_done = &vfork;
63867 init_completion(&vfork);
63868 @@ -1627,7 +1694,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
63869 return 0;
63870
63871 /* don't need lock here; in the worst case we'll do useless copy */
63872 - if (fs->users == 1)
63873 + if (atomic_read(&fs->users) == 1)
63874 return 0;
63875
63876 *new_fsp = copy_fs_struct(fs);
63877 @@ -1716,7 +1783,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
63878 fs = current->fs;
63879 spin_lock(&fs->lock);
63880 current->fs = new_fs;
63881 - if (--fs->users)
63882 + gr_set_chroot_entries(current, &current->fs->root);
63883 + if (atomic_dec_return(&fs->users))
63884 new_fs = NULL;
63885 else
63886 new_fs = fs;
63887 diff --git a/kernel/futex.c b/kernel/futex.c
63888 index 1614be2..37abc7e 100644
63889 --- a/kernel/futex.c
63890 +++ b/kernel/futex.c
63891 @@ -54,6 +54,7 @@
63892 #include <linux/mount.h>
63893 #include <linux/pagemap.h>
63894 #include <linux/syscalls.h>
63895 +#include <linux/ptrace.h>
63896 #include <linux/signal.h>
63897 #include <linux/export.h>
63898 #include <linux/magic.h>
63899 @@ -238,6 +239,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
63900 struct page *page, *page_head;
63901 int err, ro = 0;
63902
63903 +#ifdef CONFIG_PAX_SEGMEXEC
63904 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
63905 + return -EFAULT;
63906 +#endif
63907 +
63908 /*
63909 * The futex address must be "naturally" aligned.
63910 */
63911 @@ -2459,6 +2465,10 @@ SYSCALL_DEFINE3(get_robust_list, int, pid,
63912 if (!p)
63913 goto err_unlock;
63914 ret = -EPERM;
63915 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63916 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
63917 + goto err_unlock;
63918 +#endif
63919 pcred = __task_cred(p);
63920 /* If victim is in different user_ns, then uids are not
63921 comparable, so we must have CAP_SYS_PTRACE */
63922 @@ -2724,6 +2734,7 @@ static int __init futex_init(void)
63923 {
63924 u32 curval;
63925 int i;
63926 + mm_segment_t oldfs;
63927
63928 /*
63929 * This will fail and we want it. Some arch implementations do
63930 @@ -2735,8 +2746,11 @@ static int __init futex_init(void)
63931 * implementation, the non-functional ones will return
63932 * -ENOSYS.
63933 */
63934 + oldfs = get_fs();
63935 + set_fs(USER_DS);
63936 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
63937 futex_cmpxchg_enabled = 1;
63938 + set_fs(oldfs);
63939
63940 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
63941 plist_head_init(&futex_queues[i].chain);
63942 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
63943 index 5f9e689..582d46d 100644
63944 --- a/kernel/futex_compat.c
63945 +++ b/kernel/futex_compat.c
63946 @@ -10,6 +10,7 @@
63947 #include <linux/compat.h>
63948 #include <linux/nsproxy.h>
63949 #include <linux/futex.h>
63950 +#include <linux/ptrace.h>
63951
63952 #include <asm/uaccess.h>
63953
63954 @@ -136,7 +137,8 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
63955 {
63956 struct compat_robust_list_head __user *head;
63957 unsigned long ret;
63958 - const struct cred *cred = current_cred(), *pcred;
63959 + const struct cred *cred = current_cred();
63960 + const struct cred *pcred;
63961
63962 if (!futex_cmpxchg_enabled)
63963 return -ENOSYS;
63964 @@ -152,6 +154,10 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
63965 if (!p)
63966 goto err_unlock;
63967 ret = -EPERM;
63968 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63969 + if (!ptrace_may_access(p, PTRACE_MODE_READ))
63970 + goto err_unlock;
63971 +#endif
63972 pcred = __task_cred(p);
63973 /* If victim is in different user_ns, then uids are not
63974 comparable, so we must have CAP_SYS_PTRACE */
63975 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
63976 index 9b22d03..6295b62 100644
63977 --- a/kernel/gcov/base.c
63978 +++ b/kernel/gcov/base.c
63979 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
63980 }
63981
63982 #ifdef CONFIG_MODULES
63983 -static inline int within(void *addr, void *start, unsigned long size)
63984 -{
63985 - return ((addr >= start) && (addr < start + size));
63986 -}
63987 -
63988 /* Update list and generate events when modules are unloaded. */
63989 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
63990 void *data)
63991 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
63992 prev = NULL;
63993 /* Remove entries located in module from linked list. */
63994 for (info = gcov_info_head; info; info = info->next) {
63995 - if (within(info, mod->module_core, mod->core_size)) {
63996 + if (within_module_core_rw((unsigned long)info, mod)) {
63997 if (prev)
63998 prev->next = info->next;
63999 else
64000 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
64001 index ae34bf5..4e2f3d0 100644
64002 --- a/kernel/hrtimer.c
64003 +++ b/kernel/hrtimer.c
64004 @@ -1393,7 +1393,7 @@ void hrtimer_peek_ahead_timers(void)
64005 local_irq_restore(flags);
64006 }
64007
64008 -static void run_hrtimer_softirq(struct softirq_action *h)
64009 +static void run_hrtimer_softirq(void)
64010 {
64011 hrtimer_peek_ahead_timers();
64012 }
64013 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
64014 index 66ff710..05a5128 100644
64015 --- a/kernel/jump_label.c
64016 +++ b/kernel/jump_label.c
64017 @@ -55,7 +55,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
64018
64019 size = (((unsigned long)stop - (unsigned long)start)
64020 / sizeof(struct jump_entry));
64021 + pax_open_kernel();
64022 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
64023 + pax_close_kernel();
64024 }
64025
64026 static void jump_label_update(struct jump_label_key *key, int enable);
64027 @@ -303,10 +305,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
64028 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
64029 struct jump_entry *iter;
64030
64031 + pax_open_kernel();
64032 for (iter = iter_start; iter < iter_stop; iter++) {
64033 if (within_module_init(iter->code, mod))
64034 iter->code = 0;
64035 }
64036 + pax_close_kernel();
64037 }
64038
64039 static int
64040 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
64041 index 079f1d3..a407562 100644
64042 --- a/kernel/kallsyms.c
64043 +++ b/kernel/kallsyms.c
64044 @@ -11,6 +11,9 @@
64045 * Changed the compression method from stem compression to "table lookup"
64046 * compression (see scripts/kallsyms.c for a more complete description)
64047 */
64048 +#ifdef CONFIG_GRKERNSEC_HIDESYM
64049 +#define __INCLUDED_BY_HIDESYM 1
64050 +#endif
64051 #include <linux/kallsyms.h>
64052 #include <linux/module.h>
64053 #include <linux/init.h>
64054 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
64055
64056 static inline int is_kernel_inittext(unsigned long addr)
64057 {
64058 + if (system_state != SYSTEM_BOOTING)
64059 + return 0;
64060 +
64061 if (addr >= (unsigned long)_sinittext
64062 && addr <= (unsigned long)_einittext)
64063 return 1;
64064 return 0;
64065 }
64066
64067 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
64068 +#ifdef CONFIG_MODULES
64069 +static inline int is_module_text(unsigned long addr)
64070 +{
64071 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
64072 + return 1;
64073 +
64074 + addr = ktla_ktva(addr);
64075 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
64076 +}
64077 +#else
64078 +static inline int is_module_text(unsigned long addr)
64079 +{
64080 + return 0;
64081 +}
64082 +#endif
64083 +#endif
64084 +
64085 static inline int is_kernel_text(unsigned long addr)
64086 {
64087 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
64088 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
64089
64090 static inline int is_kernel(unsigned long addr)
64091 {
64092 +
64093 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
64094 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
64095 + return 1;
64096 +
64097 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
64098 +#else
64099 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
64100 +#endif
64101 +
64102 return 1;
64103 return in_gate_area_no_mm(addr);
64104 }
64105
64106 static int is_ksym_addr(unsigned long addr)
64107 {
64108 +
64109 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
64110 + if (is_module_text(addr))
64111 + return 0;
64112 +#endif
64113 +
64114 if (all_var)
64115 return is_kernel(addr);
64116
64117 @@ -454,7 +493,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
64118
64119 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
64120 {
64121 - iter->name[0] = '\0';
64122 iter->nameoff = get_symbol_offset(new_pos);
64123 iter->pos = new_pos;
64124 }
64125 @@ -502,6 +540,11 @@ static int s_show(struct seq_file *m, void *p)
64126 {
64127 struct kallsym_iter *iter = m->private;
64128
64129 +#ifdef CONFIG_GRKERNSEC_HIDESYM
64130 + if (current_uid())
64131 + return 0;
64132 +#endif
64133 +
64134 /* Some debugging symbols have no name. Ignore them. */
64135 if (!iter->name[0])
64136 return 0;
64137 @@ -540,7 +583,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
64138 struct kallsym_iter *iter;
64139 int ret;
64140
64141 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
64142 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
64143 if (!iter)
64144 return -ENOMEM;
64145 reset_iter(iter, 0);
64146 diff --git a/kernel/kexec.c b/kernel/kexec.c
64147 index dc7bc08..4601964 100644
64148 --- a/kernel/kexec.c
64149 +++ b/kernel/kexec.c
64150 @@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
64151 unsigned long flags)
64152 {
64153 struct compat_kexec_segment in;
64154 - struct kexec_segment out, __user *ksegments;
64155 + struct kexec_segment out;
64156 + struct kexec_segment __user *ksegments;
64157 unsigned long i, result;
64158
64159 /* Don't allow clients that don't understand the native
64160 diff --git a/kernel/kmod.c b/kernel/kmod.c
64161 index a4bea97..7a1ae9a 100644
64162 --- a/kernel/kmod.c
64163 +++ b/kernel/kmod.c
64164 @@ -73,13 +73,12 @@ char modprobe_path[KMOD_PATH_LEN] = "/sbin/modprobe";
64165 * If module auto-loading support is disabled then this function
64166 * becomes a no-operation.
64167 */
64168 -int __request_module(bool wait, const char *fmt, ...)
64169 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
64170 {
64171 - va_list args;
64172 char module_name[MODULE_NAME_LEN];
64173 unsigned int max_modprobes;
64174 int ret;
64175 - char *argv[] = { modprobe_path, "-q", "--", module_name, NULL };
64176 + char *argv[] = { modprobe_path, "-q", "--", module_name, module_param, NULL };
64177 static char *envp[] = { "HOME=/",
64178 "TERM=linux",
64179 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
64180 @@ -88,9 +87,7 @@ int __request_module(bool wait, const char *fmt, ...)
64181 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
64182 static int kmod_loop_msg;
64183
64184 - va_start(args, fmt);
64185 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
64186 - va_end(args);
64187 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
64188 if (ret >= MODULE_NAME_LEN)
64189 return -ENAMETOOLONG;
64190
64191 @@ -98,6 +95,20 @@ int __request_module(bool wait, const char *fmt, ...)
64192 if (ret)
64193 return ret;
64194
64195 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64196 + if (!current_uid()) {
64197 + /* hack to workaround consolekit/udisks stupidity */
64198 + read_lock(&tasklist_lock);
64199 + if (!strcmp(current->comm, "mount") &&
64200 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
64201 + read_unlock(&tasklist_lock);
64202 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
64203 + return -EPERM;
64204 + }
64205 + read_unlock(&tasklist_lock);
64206 + }
64207 +#endif
64208 +
64209 /* If modprobe needs a service that is in a module, we get a recursive
64210 * loop. Limit the number of running kmod threads to max_threads/2 or
64211 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
64212 @@ -133,6 +144,47 @@ int __request_module(bool wait, const char *fmt, ...)
64213 atomic_dec(&kmod_concurrent);
64214 return ret;
64215 }
64216 +
64217 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
64218 +{
64219 + va_list args;
64220 + int ret;
64221 +
64222 + va_start(args, fmt);
64223 + ret = ____request_module(wait, module_param, fmt, args);
64224 + va_end(args);
64225 +
64226 + return ret;
64227 +}
64228 +
64229 +int __request_module(bool wait, const char *fmt, ...)
64230 +{
64231 + va_list args;
64232 + int ret;
64233 +
64234 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64235 + if (current_uid()) {
64236 + char module_param[MODULE_NAME_LEN];
64237 +
64238 + memset(module_param, 0, sizeof(module_param));
64239 +
64240 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
64241 +
64242 + va_start(args, fmt);
64243 + ret = ____request_module(wait, module_param, fmt, args);
64244 + va_end(args);
64245 +
64246 + return ret;
64247 + }
64248 +#endif
64249 +
64250 + va_start(args, fmt);
64251 + ret = ____request_module(wait, NULL, fmt, args);
64252 + va_end(args);
64253 +
64254 + return ret;
64255 +}
64256 +
64257 EXPORT_SYMBOL(__request_module);
64258 #endif /* CONFIG_MODULES */
64259
64260 @@ -222,7 +274,7 @@ static int wait_for_helper(void *data)
64261 *
64262 * Thus the __user pointer cast is valid here.
64263 */
64264 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
64265 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
64266
64267 /*
64268 * If ret is 0, either ____call_usermodehelper failed and the
64269 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
64270 index faa39d1..d7ad37e 100644
64271 --- a/kernel/kprobes.c
64272 +++ b/kernel/kprobes.c
64273 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
64274 * kernel image and loaded module images reside. This is required
64275 * so x86_64 can correctly handle the %rip-relative fixups.
64276 */
64277 - kip->insns = module_alloc(PAGE_SIZE);
64278 + kip->insns = module_alloc_exec(PAGE_SIZE);
64279 if (!kip->insns) {
64280 kfree(kip);
64281 return NULL;
64282 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
64283 */
64284 if (!list_is_singular(&kip->list)) {
64285 list_del(&kip->list);
64286 - module_free(NULL, kip->insns);
64287 + module_free_exec(NULL, kip->insns);
64288 kfree(kip);
64289 }
64290 return 1;
64291 @@ -1953,7 +1953,7 @@ static int __init init_kprobes(void)
64292 {
64293 int i, err = 0;
64294 unsigned long offset = 0, size = 0;
64295 - char *modname, namebuf[128];
64296 + char *modname, namebuf[KSYM_NAME_LEN];
64297 const char *symbol_name;
64298 void *addr;
64299 struct kprobe_blackpoint *kb;
64300 @@ -2079,7 +2079,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
64301 const char *sym = NULL;
64302 unsigned int i = *(loff_t *) v;
64303 unsigned long offset = 0;
64304 - char *modname, namebuf[128];
64305 + char *modname, namebuf[KSYM_NAME_LEN];
64306
64307 head = &kprobe_table[i];
64308 preempt_disable();
64309 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
64310 index b2e08c9..01d8049 100644
64311 --- a/kernel/lockdep.c
64312 +++ b/kernel/lockdep.c
64313 @@ -592,6 +592,10 @@ static int static_obj(void *obj)
64314 end = (unsigned long) &_end,
64315 addr = (unsigned long) obj;
64316
64317 +#ifdef CONFIG_PAX_KERNEXEC
64318 + start = ktla_ktva(start);
64319 +#endif
64320 +
64321 /*
64322 * static variable?
64323 */
64324 @@ -731,6 +735,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
64325 if (!static_obj(lock->key)) {
64326 debug_locks_off();
64327 printk("INFO: trying to register non-static key.\n");
64328 + printk("lock:%pS key:%pS.\n", lock, lock->key);
64329 printk("the code is fine but needs lockdep annotation.\n");
64330 printk("turning off the locking correctness validator.\n");
64331 dump_stack();
64332 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
64333 if (!class)
64334 return 0;
64335 }
64336 - atomic_inc((atomic_t *)&class->ops);
64337 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
64338 if (very_verbose(class)) {
64339 printk("\nacquire class [%p] %s", class->key, class->name);
64340 if (class->name_version > 1)
64341 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
64342 index 91c32a0..b2c71c5 100644
64343 --- a/kernel/lockdep_proc.c
64344 +++ b/kernel/lockdep_proc.c
64345 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
64346
64347 static void print_name(struct seq_file *m, struct lock_class *class)
64348 {
64349 - char str[128];
64350 + char str[KSYM_NAME_LEN];
64351 const char *name = class->name;
64352
64353 if (!name) {
64354 diff --git a/kernel/module.c b/kernel/module.c
64355 index 178333c..04e3408 100644
64356 --- a/kernel/module.c
64357 +++ b/kernel/module.c
64358 @@ -58,6 +58,7 @@
64359 #include <linux/jump_label.h>
64360 #include <linux/pfn.h>
64361 #include <linux/bsearch.h>
64362 +#include <linux/grsecurity.h>
64363
64364 #define CREATE_TRACE_POINTS
64365 #include <trace/events/module.h>
64366 @@ -119,7 +120,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
64367
64368 /* Bounds of module allocation, for speeding __module_address.
64369 * Protected by module_mutex. */
64370 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
64371 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
64372 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
64373
64374 int register_module_notifier(struct notifier_block * nb)
64375 {
64376 @@ -284,7 +286,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
64377 return true;
64378
64379 list_for_each_entry_rcu(mod, &modules, list) {
64380 - struct symsearch arr[] = {
64381 + struct symsearch modarr[] = {
64382 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
64383 NOT_GPL_ONLY, false },
64384 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
64385 @@ -306,7 +308,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
64386 #endif
64387 };
64388
64389 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
64390 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
64391 return true;
64392 }
64393 return false;
64394 @@ -438,7 +440,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
64395 static int percpu_modalloc(struct module *mod,
64396 unsigned long size, unsigned long align)
64397 {
64398 - if (align > PAGE_SIZE) {
64399 + if (align-1 >= PAGE_SIZE) {
64400 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
64401 mod->name, align, PAGE_SIZE);
64402 align = PAGE_SIZE;
64403 @@ -1183,7 +1185,7 @@ resolve_symbol_wait(struct module *mod,
64404 */
64405 #ifdef CONFIG_SYSFS
64406
64407 -#ifdef CONFIG_KALLSYMS
64408 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64409 static inline bool sect_empty(const Elf_Shdr *sect)
64410 {
64411 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
64412 @@ -1649,21 +1651,21 @@ static void set_section_ro_nx(void *base,
64413
64414 static void unset_module_core_ro_nx(struct module *mod)
64415 {
64416 - set_page_attributes(mod->module_core + mod->core_text_size,
64417 - mod->module_core + mod->core_size,
64418 + set_page_attributes(mod->module_core_rw,
64419 + mod->module_core_rw + mod->core_size_rw,
64420 set_memory_x);
64421 - set_page_attributes(mod->module_core,
64422 - mod->module_core + mod->core_ro_size,
64423 + set_page_attributes(mod->module_core_rx,
64424 + mod->module_core_rx + mod->core_size_rx,
64425 set_memory_rw);
64426 }
64427
64428 static void unset_module_init_ro_nx(struct module *mod)
64429 {
64430 - set_page_attributes(mod->module_init + mod->init_text_size,
64431 - mod->module_init + mod->init_size,
64432 + set_page_attributes(mod->module_init_rw,
64433 + mod->module_init_rw + mod->init_size_rw,
64434 set_memory_x);
64435 - set_page_attributes(mod->module_init,
64436 - mod->module_init + mod->init_ro_size,
64437 + set_page_attributes(mod->module_init_rx,
64438 + mod->module_init_rx + mod->init_size_rx,
64439 set_memory_rw);
64440 }
64441
64442 @@ -1674,14 +1676,14 @@ void set_all_modules_text_rw(void)
64443
64444 mutex_lock(&module_mutex);
64445 list_for_each_entry_rcu(mod, &modules, list) {
64446 - if ((mod->module_core) && (mod->core_text_size)) {
64447 - set_page_attributes(mod->module_core,
64448 - mod->module_core + mod->core_text_size,
64449 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
64450 + set_page_attributes(mod->module_core_rx,
64451 + mod->module_core_rx + mod->core_size_rx,
64452 set_memory_rw);
64453 }
64454 - if ((mod->module_init) && (mod->init_text_size)) {
64455 - set_page_attributes(mod->module_init,
64456 - mod->module_init + mod->init_text_size,
64457 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
64458 + set_page_attributes(mod->module_init_rx,
64459 + mod->module_init_rx + mod->init_size_rx,
64460 set_memory_rw);
64461 }
64462 }
64463 @@ -1695,14 +1697,14 @@ void set_all_modules_text_ro(void)
64464
64465 mutex_lock(&module_mutex);
64466 list_for_each_entry_rcu(mod, &modules, list) {
64467 - if ((mod->module_core) && (mod->core_text_size)) {
64468 - set_page_attributes(mod->module_core,
64469 - mod->module_core + mod->core_text_size,
64470 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
64471 + set_page_attributes(mod->module_core_rx,
64472 + mod->module_core_rx + mod->core_size_rx,
64473 set_memory_ro);
64474 }
64475 - if ((mod->module_init) && (mod->init_text_size)) {
64476 - set_page_attributes(mod->module_init,
64477 - mod->module_init + mod->init_text_size,
64478 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
64479 + set_page_attributes(mod->module_init_rx,
64480 + mod->module_init_rx + mod->init_size_rx,
64481 set_memory_ro);
64482 }
64483 }
64484 @@ -1748,16 +1750,19 @@ static void free_module(struct module *mod)
64485
64486 /* This may be NULL, but that's OK */
64487 unset_module_init_ro_nx(mod);
64488 - module_free(mod, mod->module_init);
64489 + module_free(mod, mod->module_init_rw);
64490 + module_free_exec(mod, mod->module_init_rx);
64491 kfree(mod->args);
64492 percpu_modfree(mod);
64493
64494 /* Free lock-classes: */
64495 - lockdep_free_key_range(mod->module_core, mod->core_size);
64496 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
64497 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
64498
64499 /* Finally, free the core (containing the module structure) */
64500 unset_module_core_ro_nx(mod);
64501 - module_free(mod, mod->module_core);
64502 + module_free_exec(mod, mod->module_core_rx);
64503 + module_free(mod, mod->module_core_rw);
64504
64505 #ifdef CONFIG_MPU
64506 update_protections(current->mm);
64507 @@ -1826,10 +1831,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64508 unsigned int i;
64509 int ret = 0;
64510 const struct kernel_symbol *ksym;
64511 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64512 + int is_fs_load = 0;
64513 + int register_filesystem_found = 0;
64514 + char *p;
64515 +
64516 + p = strstr(mod->args, "grsec_modharden_fs");
64517 + if (p) {
64518 + char *endptr = p + strlen("grsec_modharden_fs");
64519 + /* copy \0 as well */
64520 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
64521 + is_fs_load = 1;
64522 + }
64523 +#endif
64524
64525 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
64526 const char *name = info->strtab + sym[i].st_name;
64527
64528 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64529 + /* it's a real shame this will never get ripped and copied
64530 + upstream! ;(
64531 + */
64532 + if (is_fs_load && !strcmp(name, "register_filesystem"))
64533 + register_filesystem_found = 1;
64534 +#endif
64535 +
64536 switch (sym[i].st_shndx) {
64537 case SHN_COMMON:
64538 /* We compiled with -fno-common. These are not
64539 @@ -1850,7 +1876,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64540 ksym = resolve_symbol_wait(mod, info, name);
64541 /* Ok if resolved. */
64542 if (ksym && !IS_ERR(ksym)) {
64543 + pax_open_kernel();
64544 sym[i].st_value = ksym->value;
64545 + pax_close_kernel();
64546 break;
64547 }
64548
64549 @@ -1869,11 +1897,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
64550 secbase = (unsigned long)mod_percpu(mod);
64551 else
64552 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
64553 + pax_open_kernel();
64554 sym[i].st_value += secbase;
64555 + pax_close_kernel();
64556 break;
64557 }
64558 }
64559
64560 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64561 + if (is_fs_load && !register_filesystem_found) {
64562 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
64563 + ret = -EPERM;
64564 + }
64565 +#endif
64566 +
64567 return ret;
64568 }
64569
64570 @@ -1977,22 +2014,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
64571 || s->sh_entsize != ~0UL
64572 || strstarts(sname, ".init"))
64573 continue;
64574 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
64575 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64576 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
64577 + else
64578 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
64579 DEBUGP("\t%s\n", name);
64580 }
64581 - switch (m) {
64582 - case 0: /* executable */
64583 - mod->core_size = debug_align(mod->core_size);
64584 - mod->core_text_size = mod->core_size;
64585 - break;
64586 - case 1: /* RO: text and ro-data */
64587 - mod->core_size = debug_align(mod->core_size);
64588 - mod->core_ro_size = mod->core_size;
64589 - break;
64590 - case 3: /* whole core */
64591 - mod->core_size = debug_align(mod->core_size);
64592 - break;
64593 - }
64594 }
64595
64596 DEBUGP("Init section allocation order:\n");
64597 @@ -2006,23 +2033,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
64598 || s->sh_entsize != ~0UL
64599 || !strstarts(sname, ".init"))
64600 continue;
64601 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
64602 - | INIT_OFFSET_MASK);
64603 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
64604 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
64605 + else
64606 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
64607 + s->sh_entsize |= INIT_OFFSET_MASK;
64608 DEBUGP("\t%s\n", sname);
64609 }
64610 - switch (m) {
64611 - case 0: /* executable */
64612 - mod->init_size = debug_align(mod->init_size);
64613 - mod->init_text_size = mod->init_size;
64614 - break;
64615 - case 1: /* RO: text and ro-data */
64616 - mod->init_size = debug_align(mod->init_size);
64617 - mod->init_ro_size = mod->init_size;
64618 - break;
64619 - case 3: /* whole init */
64620 - mod->init_size = debug_align(mod->init_size);
64621 - break;
64622 - }
64623 }
64624 }
64625
64626 @@ -2187,7 +2204,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
64627
64628 /* Put symbol section at end of init part of module. */
64629 symsect->sh_flags |= SHF_ALLOC;
64630 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
64631 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
64632 info->index.sym) | INIT_OFFSET_MASK;
64633 DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
64634
64635 @@ -2204,19 +2221,19 @@ static void layout_symtab(struct module *mod, struct load_info *info)
64636 }
64637
64638 /* Append room for core symbols at end of core part. */
64639 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
64640 - mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
64641 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
64642 + mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
64643
64644 /* Put string table section at end of init part of module. */
64645 strsect->sh_flags |= SHF_ALLOC;
64646 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
64647 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
64648 info->index.str) | INIT_OFFSET_MASK;
64649 DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
64650
64651 /* Append room for core symbols' strings at end of core part. */
64652 - info->stroffs = mod->core_size;
64653 + info->stroffs = mod->core_size_rx;
64654 __set_bit(0, info->strmap);
64655 - mod->core_size += bitmap_weight(info->strmap, strsect->sh_size);
64656 + mod->core_size_rx += bitmap_weight(info->strmap, strsect->sh_size);
64657 }
64658
64659 static void add_kallsyms(struct module *mod, const struct load_info *info)
64660 @@ -2232,11 +2249,13 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
64661 /* Make sure we get permanent strtab: don't use info->strtab. */
64662 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
64663
64664 + pax_open_kernel();
64665 +
64666 /* Set types up while we still have access to sections. */
64667 for (i = 0; i < mod->num_symtab; i++)
64668 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
64669
64670 - mod->core_symtab = dst = mod->module_core + info->symoffs;
64671 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
64672 src = mod->symtab;
64673 *dst = *src;
64674 for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) {
64675 @@ -2249,10 +2268,12 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
64676 }
64677 mod->core_num_syms = ndst;
64678
64679 - mod->core_strtab = s = mod->module_core + info->stroffs;
64680 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
64681 for (*s = 0, i = 1; i < info->sechdrs[info->index.str].sh_size; ++i)
64682 if (test_bit(i, info->strmap))
64683 *++s = mod->strtab[i];
64684 +
64685 + pax_close_kernel();
64686 }
64687 #else
64688 static inline void layout_symtab(struct module *mod, struct load_info *info)
64689 @@ -2286,17 +2307,33 @@ void * __weak module_alloc(unsigned long size)
64690 return size == 0 ? NULL : vmalloc_exec(size);
64691 }
64692
64693 -static void *module_alloc_update_bounds(unsigned long size)
64694 +static void *module_alloc_update_bounds_rw(unsigned long size)
64695 {
64696 void *ret = module_alloc(size);
64697
64698 if (ret) {
64699 mutex_lock(&module_mutex);
64700 /* Update module bounds. */
64701 - if ((unsigned long)ret < module_addr_min)
64702 - module_addr_min = (unsigned long)ret;
64703 - if ((unsigned long)ret + size > module_addr_max)
64704 - module_addr_max = (unsigned long)ret + size;
64705 + if ((unsigned long)ret < module_addr_min_rw)
64706 + module_addr_min_rw = (unsigned long)ret;
64707 + if ((unsigned long)ret + size > module_addr_max_rw)
64708 + module_addr_max_rw = (unsigned long)ret + size;
64709 + mutex_unlock(&module_mutex);
64710 + }
64711 + return ret;
64712 +}
64713 +
64714 +static void *module_alloc_update_bounds_rx(unsigned long size)
64715 +{
64716 + void *ret = module_alloc_exec(size);
64717 +
64718 + if (ret) {
64719 + mutex_lock(&module_mutex);
64720 + /* Update module bounds. */
64721 + if ((unsigned long)ret < module_addr_min_rx)
64722 + module_addr_min_rx = (unsigned long)ret;
64723 + if ((unsigned long)ret + size > module_addr_max_rx)
64724 + module_addr_max_rx = (unsigned long)ret + size;
64725 mutex_unlock(&module_mutex);
64726 }
64727 return ret;
64728 @@ -2474,8 +2511,14 @@ static struct module *setup_load_info(struct load_info *info)
64729 static int check_modinfo(struct module *mod, struct load_info *info)
64730 {
64731 const char *modmagic = get_modinfo(info, "vermagic");
64732 + const char *license = get_modinfo(info, "license");
64733 int err;
64734
64735 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
64736 + if (!license || !license_is_gpl_compatible(license))
64737 + return -ENOEXEC;
64738 +#endif
64739 +
64740 /* This is allowed: modprobe --force will invalidate it. */
64741 if (!modmagic) {
64742 err = try_to_force_load(mod, "bad vermagic");
64743 @@ -2498,7 +2541,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
64744 }
64745
64746 /* Set up license info based on the info section */
64747 - set_license(mod, get_modinfo(info, "license"));
64748 + set_license(mod, license);
64749
64750 return 0;
64751 }
64752 @@ -2592,7 +2635,7 @@ static int move_module(struct module *mod, struct load_info *info)
64753 void *ptr;
64754
64755 /* Do the allocs. */
64756 - ptr = module_alloc_update_bounds(mod->core_size);
64757 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
64758 /*
64759 * The pointer to this block is stored in the module structure
64760 * which is inside the block. Just mark it as not being a
64761 @@ -2602,23 +2645,50 @@ static int move_module(struct module *mod, struct load_info *info)
64762 if (!ptr)
64763 return -ENOMEM;
64764
64765 - memset(ptr, 0, mod->core_size);
64766 - mod->module_core = ptr;
64767 + memset(ptr, 0, mod->core_size_rw);
64768 + mod->module_core_rw = ptr;
64769
64770 - ptr = module_alloc_update_bounds(mod->init_size);
64771 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
64772 /*
64773 * The pointer to this block is stored in the module structure
64774 * which is inside the block. This block doesn't need to be
64775 * scanned as it contains data and code that will be freed
64776 * after the module is initialized.
64777 */
64778 - kmemleak_ignore(ptr);
64779 - if (!ptr && mod->init_size) {
64780 - module_free(mod, mod->module_core);
64781 + kmemleak_not_leak(ptr);
64782 + if (!ptr && mod->init_size_rw) {
64783 + module_free(mod, mod->module_core_rw);
64784 return -ENOMEM;
64785 }
64786 - memset(ptr, 0, mod->init_size);
64787 - mod->module_init = ptr;
64788 + memset(ptr, 0, mod->init_size_rw);
64789 + mod->module_init_rw = ptr;
64790 +
64791 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
64792 + kmemleak_not_leak(ptr);
64793 + if (!ptr) {
64794 + module_free(mod, mod->module_init_rw);
64795 + module_free(mod, mod->module_core_rw);
64796 + return -ENOMEM;
64797 + }
64798 +
64799 + pax_open_kernel();
64800 + memset(ptr, 0, mod->core_size_rx);
64801 + pax_close_kernel();
64802 + mod->module_core_rx = ptr;
64803 +
64804 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
64805 + kmemleak_not_leak(ptr);
64806 + if (!ptr && mod->init_size_rx) {
64807 + module_free_exec(mod, mod->module_core_rx);
64808 + module_free(mod, mod->module_init_rw);
64809 + module_free(mod, mod->module_core_rw);
64810 + return -ENOMEM;
64811 + }
64812 +
64813 + pax_open_kernel();
64814 + memset(ptr, 0, mod->init_size_rx);
64815 + pax_close_kernel();
64816 + mod->module_init_rx = ptr;
64817
64818 /* Transfer each section which specifies SHF_ALLOC */
64819 DEBUGP("final section addresses:\n");
64820 @@ -2629,16 +2699,45 @@ static int move_module(struct module *mod, struct load_info *info)
64821 if (!(shdr->sh_flags & SHF_ALLOC))
64822 continue;
64823
64824 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
64825 - dest = mod->module_init
64826 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64827 - else
64828 - dest = mod->module_core + shdr->sh_entsize;
64829 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
64830 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
64831 + dest = mod->module_init_rw
64832 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64833 + else
64834 + dest = mod->module_init_rx
64835 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
64836 + } else {
64837 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
64838 + dest = mod->module_core_rw + shdr->sh_entsize;
64839 + else
64840 + dest = mod->module_core_rx + shdr->sh_entsize;
64841 + }
64842 +
64843 + if (shdr->sh_type != SHT_NOBITS) {
64844 +
64845 +#ifdef CONFIG_PAX_KERNEXEC
64846 +#ifdef CONFIG_X86_64
64847 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
64848 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
64849 +#endif
64850 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
64851 + pax_open_kernel();
64852 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
64853 + pax_close_kernel();
64854 + } else
64855 +#endif
64856
64857 - if (shdr->sh_type != SHT_NOBITS)
64858 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
64859 + }
64860 /* Update sh_addr to point to copy in image. */
64861 - shdr->sh_addr = (unsigned long)dest;
64862 +
64863 +#ifdef CONFIG_PAX_KERNEXEC
64864 + if (shdr->sh_flags & SHF_EXECINSTR)
64865 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
64866 + else
64867 +#endif
64868 +
64869 + shdr->sh_addr = (unsigned long)dest;
64870 DEBUGP("\t0x%lx %s\n",
64871 shdr->sh_addr, info->secstrings + shdr->sh_name);
64872 }
64873 @@ -2689,12 +2788,12 @@ static void flush_module_icache(const struct module *mod)
64874 * Do it before processing of module parameters, so the module
64875 * can provide parameter accessor functions of its own.
64876 */
64877 - if (mod->module_init)
64878 - flush_icache_range((unsigned long)mod->module_init,
64879 - (unsigned long)mod->module_init
64880 - + mod->init_size);
64881 - flush_icache_range((unsigned long)mod->module_core,
64882 - (unsigned long)mod->module_core + mod->core_size);
64883 + if (mod->module_init_rx)
64884 + flush_icache_range((unsigned long)mod->module_init_rx,
64885 + (unsigned long)mod->module_init_rx
64886 + + mod->init_size_rx);
64887 + flush_icache_range((unsigned long)mod->module_core_rx,
64888 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
64889
64890 set_fs(old_fs);
64891 }
64892 @@ -2774,8 +2873,10 @@ static void module_deallocate(struct module *mod, struct load_info *info)
64893 {
64894 kfree(info->strmap);
64895 percpu_modfree(mod);
64896 - module_free(mod, mod->module_init);
64897 - module_free(mod, mod->module_core);
64898 + module_free_exec(mod, mod->module_init_rx);
64899 + module_free_exec(mod, mod->module_core_rx);
64900 + module_free(mod, mod->module_init_rw);
64901 + module_free(mod, mod->module_core_rw);
64902 }
64903
64904 int __weak module_finalize(const Elf_Ehdr *hdr,
64905 @@ -2839,9 +2940,38 @@ static struct module *load_module(void __user *umod,
64906 if (err)
64907 goto free_unload;
64908
64909 + /* Now copy in args */
64910 + mod->args = strndup_user(uargs, ~0UL >> 1);
64911 + if (IS_ERR(mod->args)) {
64912 + err = PTR_ERR(mod->args);
64913 + goto free_unload;
64914 + }
64915 +
64916 /* Set up MODINFO_ATTR fields */
64917 setup_modinfo(mod, &info);
64918
64919 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
64920 + {
64921 + char *p, *p2;
64922 +
64923 + if (strstr(mod->args, "grsec_modharden_netdev")) {
64924 + 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);
64925 + err = -EPERM;
64926 + goto free_modinfo;
64927 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
64928 + p += strlen("grsec_modharden_normal");
64929 + p2 = strstr(p, "_");
64930 + if (p2) {
64931 + *p2 = '\0';
64932 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
64933 + *p2 = '_';
64934 + }
64935 + err = -EPERM;
64936 + goto free_modinfo;
64937 + }
64938 + }
64939 +#endif
64940 +
64941 /* Fix up syms, so that st_value is a pointer to location. */
64942 err = simplify_symbols(mod, &info);
64943 if (err < 0)
64944 @@ -2857,13 +2987,6 @@ static struct module *load_module(void __user *umod,
64945
64946 flush_module_icache(mod);
64947
64948 - /* Now copy in args */
64949 - mod->args = strndup_user(uargs, ~0UL >> 1);
64950 - if (IS_ERR(mod->args)) {
64951 - err = PTR_ERR(mod->args);
64952 - goto free_arch_cleanup;
64953 - }
64954 -
64955 /* Mark state as coming so strong_try_module_get() ignores us. */
64956 mod->state = MODULE_STATE_COMING;
64957
64958 @@ -2921,11 +3044,10 @@ static struct module *load_module(void __user *umod,
64959 unlock:
64960 mutex_unlock(&module_mutex);
64961 synchronize_sched();
64962 - kfree(mod->args);
64963 - free_arch_cleanup:
64964 module_arch_cleanup(mod);
64965 free_modinfo:
64966 free_modinfo(mod);
64967 + kfree(mod->args);
64968 free_unload:
64969 module_unload_free(mod);
64970 free_module:
64971 @@ -2966,16 +3088,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
64972 MODULE_STATE_COMING, mod);
64973
64974 /* Set RO and NX regions for core */
64975 - set_section_ro_nx(mod->module_core,
64976 - mod->core_text_size,
64977 - mod->core_ro_size,
64978 - mod->core_size);
64979 + set_section_ro_nx(mod->module_core_rx,
64980 + mod->core_size_rx,
64981 + mod->core_size_rx,
64982 + mod->core_size_rx);
64983
64984 /* Set RO and NX regions for init */
64985 - set_section_ro_nx(mod->module_init,
64986 - mod->init_text_size,
64987 - mod->init_ro_size,
64988 - mod->init_size);
64989 + set_section_ro_nx(mod->module_init_rx,
64990 + mod->init_size_rx,
64991 + mod->init_size_rx,
64992 + mod->init_size_rx);
64993
64994 do_mod_ctors(mod);
64995 /* Start the module */
64996 @@ -3021,11 +3143,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
64997 mod->strtab = mod->core_strtab;
64998 #endif
64999 unset_module_init_ro_nx(mod);
65000 - module_free(mod, mod->module_init);
65001 - mod->module_init = NULL;
65002 - mod->init_size = 0;
65003 - mod->init_ro_size = 0;
65004 - mod->init_text_size = 0;
65005 + module_free(mod, mod->module_init_rw);
65006 + module_free_exec(mod, mod->module_init_rx);
65007 + mod->module_init_rw = NULL;
65008 + mod->module_init_rx = NULL;
65009 + mod->init_size_rw = 0;
65010 + mod->init_size_rx = 0;
65011 mutex_unlock(&module_mutex);
65012
65013 return 0;
65014 @@ -3056,10 +3179,16 @@ static const char *get_ksymbol(struct module *mod,
65015 unsigned long nextval;
65016
65017 /* At worse, next value is at end of module */
65018 - if (within_module_init(addr, mod))
65019 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
65020 + if (within_module_init_rx(addr, mod))
65021 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
65022 + else if (within_module_init_rw(addr, mod))
65023 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
65024 + else if (within_module_core_rx(addr, mod))
65025 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
65026 + else if (within_module_core_rw(addr, mod))
65027 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
65028 else
65029 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
65030 + return NULL;
65031
65032 /* Scan for closest preceding symbol, and next symbol. (ELF
65033 starts real symbols at 1). */
65034 @@ -3307,7 +3436,7 @@ static int m_show(struct seq_file *m, void *p)
65035 char buf[8];
65036
65037 seq_printf(m, "%s %u",
65038 - mod->name, mod->init_size + mod->core_size);
65039 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
65040 print_unload_info(m, mod);
65041
65042 /* Informative for users. */
65043 @@ -3316,7 +3445,7 @@ static int m_show(struct seq_file *m, void *p)
65044 mod->state == MODULE_STATE_COMING ? "Loading":
65045 "Live");
65046 /* Used by oprofile and other similar tools. */
65047 - seq_printf(m, " 0x%pK", mod->module_core);
65048 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
65049
65050 /* Taints info */
65051 if (mod->taints)
65052 @@ -3352,7 +3481,17 @@ static const struct file_operations proc_modules_operations = {
65053
65054 static int __init proc_modules_init(void)
65055 {
65056 +#ifndef CONFIG_GRKERNSEC_HIDESYM
65057 +#ifdef CONFIG_GRKERNSEC_PROC_USER
65058 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
65059 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65060 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
65061 +#else
65062 proc_create("modules", 0, NULL, &proc_modules_operations);
65063 +#endif
65064 +#else
65065 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
65066 +#endif
65067 return 0;
65068 }
65069 module_init(proc_modules_init);
65070 @@ -3411,12 +3550,12 @@ struct module *__module_address(unsigned long addr)
65071 {
65072 struct module *mod;
65073
65074 - if (addr < module_addr_min || addr > module_addr_max)
65075 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
65076 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
65077 return NULL;
65078
65079 list_for_each_entry_rcu(mod, &modules, list)
65080 - if (within_module_core(addr, mod)
65081 - || within_module_init(addr, mod))
65082 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
65083 return mod;
65084 return NULL;
65085 }
65086 @@ -3450,11 +3589,20 @@ bool is_module_text_address(unsigned long addr)
65087 */
65088 struct module *__module_text_address(unsigned long addr)
65089 {
65090 - struct module *mod = __module_address(addr);
65091 + struct module *mod;
65092 +
65093 +#ifdef CONFIG_X86_32
65094 + addr = ktla_ktva(addr);
65095 +#endif
65096 +
65097 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
65098 + return NULL;
65099 +
65100 + mod = __module_address(addr);
65101 +
65102 if (mod) {
65103 /* Make sure it's within the text section. */
65104 - if (!within(addr, mod->module_init, mod->init_text_size)
65105 - && !within(addr, mod->module_core, mod->core_text_size))
65106 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
65107 mod = NULL;
65108 }
65109 return mod;
65110 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
65111 index 7e3443f..b2a1e6b 100644
65112 --- a/kernel/mutex-debug.c
65113 +++ b/kernel/mutex-debug.c
65114 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
65115 }
65116
65117 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
65118 - struct thread_info *ti)
65119 + struct task_struct *task)
65120 {
65121 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
65122
65123 /* Mark the current thread as blocked on the lock: */
65124 - ti->task->blocked_on = waiter;
65125 + task->blocked_on = waiter;
65126 }
65127
65128 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
65129 - struct thread_info *ti)
65130 + struct task_struct *task)
65131 {
65132 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
65133 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
65134 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
65135 - ti->task->blocked_on = NULL;
65136 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
65137 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
65138 + task->blocked_on = NULL;
65139
65140 list_del_init(&waiter->list);
65141 waiter->task = NULL;
65142 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
65143 index 0799fd3..d06ae3b 100644
65144 --- a/kernel/mutex-debug.h
65145 +++ b/kernel/mutex-debug.h
65146 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
65147 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
65148 extern void debug_mutex_add_waiter(struct mutex *lock,
65149 struct mutex_waiter *waiter,
65150 - struct thread_info *ti);
65151 + struct task_struct *task);
65152 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
65153 - struct thread_info *ti);
65154 + struct task_struct *task);
65155 extern void debug_mutex_unlock(struct mutex *lock);
65156 extern void debug_mutex_init(struct mutex *lock, const char *name,
65157 struct lock_class_key *key);
65158 diff --git a/kernel/mutex.c b/kernel/mutex.c
65159 index 89096dd..f91ebc5 100644
65160 --- a/kernel/mutex.c
65161 +++ b/kernel/mutex.c
65162 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
65163 spin_lock_mutex(&lock->wait_lock, flags);
65164
65165 debug_mutex_lock_common(lock, &waiter);
65166 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
65167 + debug_mutex_add_waiter(lock, &waiter, task);
65168
65169 /* add waiting tasks to the end of the waitqueue (FIFO): */
65170 list_add_tail(&waiter.list, &lock->wait_list);
65171 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
65172 * TASK_UNINTERRUPTIBLE case.)
65173 */
65174 if (unlikely(signal_pending_state(state, task))) {
65175 - mutex_remove_waiter(lock, &waiter,
65176 - task_thread_info(task));
65177 + mutex_remove_waiter(lock, &waiter, task);
65178 mutex_release(&lock->dep_map, 1, ip);
65179 spin_unlock_mutex(&lock->wait_lock, flags);
65180
65181 @@ -249,7 +248,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
65182 done:
65183 lock_acquired(&lock->dep_map, ip);
65184 /* got the lock - rejoice! */
65185 - mutex_remove_waiter(lock, &waiter, current_thread_info());
65186 + mutex_remove_waiter(lock, &waiter, task);
65187 mutex_set_owner(lock);
65188
65189 /* set it to 0 if there are no waiters left: */
65190 diff --git a/kernel/padata.c b/kernel/padata.c
65191 index b452599..5d68f4e 100644
65192 --- a/kernel/padata.c
65193 +++ b/kernel/padata.c
65194 @@ -132,10 +132,10 @@ int padata_do_parallel(struct padata_instance *pinst,
65195 padata->pd = pd;
65196 padata->cb_cpu = cb_cpu;
65197
65198 - if (unlikely(atomic_read(&pd->seq_nr) == pd->max_seq_nr))
65199 - atomic_set(&pd->seq_nr, -1);
65200 + if (unlikely(atomic_read_unchecked(&pd->seq_nr) == pd->max_seq_nr))
65201 + atomic_set_unchecked(&pd->seq_nr, -1);
65202
65203 - padata->seq_nr = atomic_inc_return(&pd->seq_nr);
65204 + padata->seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
65205
65206 target_cpu = padata_cpu_hash(padata);
65207 queue = per_cpu_ptr(pd->pqueue, target_cpu);
65208 @@ -444,7 +444,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
65209 padata_init_pqueues(pd);
65210 padata_init_squeues(pd);
65211 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
65212 - atomic_set(&pd->seq_nr, -1);
65213 + atomic_set_unchecked(&pd->seq_nr, -1);
65214 atomic_set(&pd->reorder_objects, 0);
65215 atomic_set(&pd->refcnt, 0);
65216 pd->pinst = pinst;
65217 diff --git a/kernel/panic.c b/kernel/panic.c
65218 index 3458469..342c500 100644
65219 --- a/kernel/panic.c
65220 +++ b/kernel/panic.c
65221 @@ -78,7 +78,11 @@ NORET_TYPE void panic(const char * fmt, ...)
65222 va_end(args);
65223 printk(KERN_EMERG "Kernel panic - not syncing: %s\n",buf);
65224 #ifdef CONFIG_DEBUG_BUGVERBOSE
65225 - dump_stack();
65226 + /*
65227 + * Avoid nested stack-dumping if a panic occurs during oops processing
65228 + */
65229 + if (!oops_in_progress)
65230 + dump_stack();
65231 #endif
65232
65233 /*
65234 @@ -382,7 +386,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
65235 const char *board;
65236
65237 printk(KERN_WARNING "------------[ cut here ]------------\n");
65238 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
65239 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
65240 board = dmi_get_system_info(DMI_PRODUCT_NAME);
65241 if (board)
65242 printk(KERN_WARNING "Hardware name: %s\n", board);
65243 @@ -437,7 +441,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
65244 */
65245 void __stack_chk_fail(void)
65246 {
65247 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
65248 + dump_stack();
65249 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
65250 __builtin_return_address(0));
65251 }
65252 EXPORT_SYMBOL(__stack_chk_fail);
65253 diff --git a/kernel/pid.c b/kernel/pid.c
65254 index fa5f722..0c93e57 100644
65255 --- a/kernel/pid.c
65256 +++ b/kernel/pid.c
65257 @@ -33,6 +33,7 @@
65258 #include <linux/rculist.h>
65259 #include <linux/bootmem.h>
65260 #include <linux/hash.h>
65261 +#include <linux/security.h>
65262 #include <linux/pid_namespace.h>
65263 #include <linux/init_task.h>
65264 #include <linux/syscalls.h>
65265 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
65266
65267 int pid_max = PID_MAX_DEFAULT;
65268
65269 -#define RESERVED_PIDS 300
65270 +#define RESERVED_PIDS 500
65271
65272 int pid_max_min = RESERVED_PIDS + 1;
65273 int pid_max_max = PID_MAX_LIMIT;
65274 @@ -418,10 +419,18 @@ EXPORT_SYMBOL(pid_task);
65275 */
65276 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
65277 {
65278 + struct task_struct *task;
65279 +
65280 rcu_lockdep_assert(rcu_read_lock_held(),
65281 "find_task_by_pid_ns() needs rcu_read_lock()"
65282 " protection");
65283 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65284 +
65285 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
65286 +
65287 + if (gr_pid_is_chrooted(task))
65288 + return NULL;
65289 +
65290 + return task;
65291 }
65292
65293 struct task_struct *find_task_by_vpid(pid_t vnr)
65294 @@ -429,6 +438,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
65295 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
65296 }
65297
65298 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
65299 +{
65300 + rcu_lockdep_assert(rcu_read_lock_held(),
65301 + "find_task_by_pid_ns() needs rcu_read_lock()"
65302 + " protection");
65303 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
65304 +}
65305 +
65306 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
65307 {
65308 struct pid *pid;
65309 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
65310 index e7cb76d..75eceb3 100644
65311 --- a/kernel/posix-cpu-timers.c
65312 +++ b/kernel/posix-cpu-timers.c
65313 @@ -6,6 +6,7 @@
65314 #include <linux/posix-timers.h>
65315 #include <linux/errno.h>
65316 #include <linux/math64.h>
65317 +#include <linux/security.h>
65318 #include <asm/uaccess.h>
65319 #include <linux/kernel_stat.h>
65320 #include <trace/events/timer.h>
65321 @@ -1606,14 +1607,14 @@ struct k_clock clock_posix_cpu = {
65322
65323 static __init int init_posix_cpu_timers(void)
65324 {
65325 - struct k_clock process = {
65326 + static struct k_clock process = {
65327 .clock_getres = process_cpu_clock_getres,
65328 .clock_get = process_cpu_clock_get,
65329 .timer_create = process_cpu_timer_create,
65330 .nsleep = process_cpu_nsleep,
65331 .nsleep_restart = process_cpu_nsleep_restart,
65332 };
65333 - struct k_clock thread = {
65334 + static struct k_clock thread = {
65335 .clock_getres = thread_cpu_clock_getres,
65336 .clock_get = thread_cpu_clock_get,
65337 .timer_create = thread_cpu_timer_create,
65338 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
65339 index 69185ae..cc2847a 100644
65340 --- a/kernel/posix-timers.c
65341 +++ b/kernel/posix-timers.c
65342 @@ -43,6 +43,7 @@
65343 #include <linux/idr.h>
65344 #include <linux/posix-clock.h>
65345 #include <linux/posix-timers.h>
65346 +#include <linux/grsecurity.h>
65347 #include <linux/syscalls.h>
65348 #include <linux/wait.h>
65349 #include <linux/workqueue.h>
65350 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
65351 * which we beg off on and pass to do_sys_settimeofday().
65352 */
65353
65354 -static struct k_clock posix_clocks[MAX_CLOCKS];
65355 +static struct k_clock *posix_clocks[MAX_CLOCKS];
65356
65357 /*
65358 * These ones are defined below.
65359 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
65360 */
65361 static __init int init_posix_timers(void)
65362 {
65363 - struct k_clock clock_realtime = {
65364 + static struct k_clock clock_realtime = {
65365 .clock_getres = hrtimer_get_res,
65366 .clock_get = posix_clock_realtime_get,
65367 .clock_set = posix_clock_realtime_set,
65368 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
65369 .timer_get = common_timer_get,
65370 .timer_del = common_timer_del,
65371 };
65372 - struct k_clock clock_monotonic = {
65373 + static struct k_clock clock_monotonic = {
65374 .clock_getres = hrtimer_get_res,
65375 .clock_get = posix_ktime_get_ts,
65376 .nsleep = common_nsleep,
65377 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
65378 .timer_get = common_timer_get,
65379 .timer_del = common_timer_del,
65380 };
65381 - struct k_clock clock_monotonic_raw = {
65382 + static struct k_clock clock_monotonic_raw = {
65383 .clock_getres = hrtimer_get_res,
65384 .clock_get = posix_get_monotonic_raw,
65385 };
65386 - struct k_clock clock_realtime_coarse = {
65387 + static struct k_clock clock_realtime_coarse = {
65388 .clock_getres = posix_get_coarse_res,
65389 .clock_get = posix_get_realtime_coarse,
65390 };
65391 - struct k_clock clock_monotonic_coarse = {
65392 + static struct k_clock clock_monotonic_coarse = {
65393 .clock_getres = posix_get_coarse_res,
65394 .clock_get = posix_get_monotonic_coarse,
65395 };
65396 - struct k_clock clock_boottime = {
65397 + static struct k_clock clock_boottime = {
65398 .clock_getres = hrtimer_get_res,
65399 .clock_get = posix_get_boottime,
65400 .nsleep = common_nsleep,
65401 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
65402 return;
65403 }
65404
65405 - posix_clocks[clock_id] = *new_clock;
65406 + posix_clocks[clock_id] = new_clock;
65407 }
65408 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
65409
65410 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
65411 return (id & CLOCKFD_MASK) == CLOCKFD ?
65412 &clock_posix_dynamic : &clock_posix_cpu;
65413
65414 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
65415 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
65416 return NULL;
65417 - return &posix_clocks[id];
65418 + return posix_clocks[id];
65419 }
65420
65421 static int common_timer_create(struct k_itimer *new_timer)
65422 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
65423 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
65424 return -EFAULT;
65425
65426 + /* only the CLOCK_REALTIME clock can be set, all other clocks
65427 + have their clock_set fptr set to a nosettime dummy function
65428 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
65429 + call common_clock_set, which calls do_sys_settimeofday, which
65430 + we hook
65431 + */
65432 +
65433 return kc->clock_set(which_clock, &new_tp);
65434 }
65435
65436 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
65437 index d523593..68197a4 100644
65438 --- a/kernel/power/poweroff.c
65439 +++ b/kernel/power/poweroff.c
65440 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
65441 .enable_mask = SYSRQ_ENABLE_BOOT,
65442 };
65443
65444 -static int pm_sysrq_init(void)
65445 +static int __init pm_sysrq_init(void)
65446 {
65447 register_sysrq_key('o', &sysrq_poweroff_op);
65448 return 0;
65449 diff --git a/kernel/power/process.c b/kernel/power/process.c
65450 index 3d4b954..11af930 100644
65451 --- a/kernel/power/process.c
65452 +++ b/kernel/power/process.c
65453 @@ -41,6 +41,7 @@ static int try_to_freeze_tasks(bool sig_only)
65454 u64 elapsed_csecs64;
65455 unsigned int elapsed_csecs;
65456 bool wakeup = false;
65457 + bool timedout = false;
65458
65459 do_gettimeofday(&start);
65460
65461 @@ -51,6 +52,8 @@ static int try_to_freeze_tasks(bool sig_only)
65462
65463 while (true) {
65464 todo = 0;
65465 + if (time_after(jiffies, end_time))
65466 + timedout = true;
65467 read_lock(&tasklist_lock);
65468 do_each_thread(g, p) {
65469 if (frozen(p) || !freezable(p))
65470 @@ -71,9 +74,13 @@ static int try_to_freeze_tasks(bool sig_only)
65471 * try_to_stop() after schedule() in ptrace/signal
65472 * stop sees TIF_FREEZE.
65473 */
65474 - if (!task_is_stopped_or_traced(p) &&
65475 - !freezer_should_skip(p))
65476 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
65477 todo++;
65478 + if (timedout) {
65479 + printk(KERN_ERR "Task refusing to freeze:\n");
65480 + sched_show_task(p);
65481 + }
65482 + }
65483 } while_each_thread(g, p);
65484 read_unlock(&tasklist_lock);
65485
65486 @@ -82,7 +89,7 @@ static int try_to_freeze_tasks(bool sig_only)
65487 todo += wq_busy;
65488 }
65489
65490 - if (!todo || time_after(jiffies, end_time))
65491 + if (!todo || timedout)
65492 break;
65493
65494 if (pm_wakeup_pending()) {
65495 diff --git a/kernel/printk.c b/kernel/printk.c
65496 index 7982a0a..2095fdc 100644
65497 --- a/kernel/printk.c
65498 +++ b/kernel/printk.c
65499 @@ -313,6 +313,11 @@ static int check_syslog_permissions(int type, bool from_file)
65500 if (from_file && type != SYSLOG_ACTION_OPEN)
65501 return 0;
65502
65503 +#ifdef CONFIG_GRKERNSEC_DMESG
65504 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
65505 + return -EPERM;
65506 +#endif
65507 +
65508 if (syslog_action_restricted(type)) {
65509 if (capable(CAP_SYSLOG))
65510 return 0;
65511 diff --git a/kernel/profile.c b/kernel/profile.c
65512 index 76b8e77..a2930e8 100644
65513 --- a/kernel/profile.c
65514 +++ b/kernel/profile.c
65515 @@ -39,7 +39,7 @@ struct profile_hit {
65516 /* Oprofile timer tick hook */
65517 static int (*timer_hook)(struct pt_regs *) __read_mostly;
65518
65519 -static atomic_t *prof_buffer;
65520 +static atomic_unchecked_t *prof_buffer;
65521 static unsigned long prof_len, prof_shift;
65522
65523 int prof_on __read_mostly;
65524 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
65525 hits[i].pc = 0;
65526 continue;
65527 }
65528 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65529 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65530 hits[i].hits = hits[i].pc = 0;
65531 }
65532 }
65533 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
65534 * Add the current hit(s) and flush the write-queue out
65535 * to the global buffer:
65536 */
65537 - atomic_add(nr_hits, &prof_buffer[pc]);
65538 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
65539 for (i = 0; i < NR_PROFILE_HIT; ++i) {
65540 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
65541 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
65542 hits[i].pc = hits[i].hits = 0;
65543 }
65544 out:
65545 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
65546 {
65547 unsigned long pc;
65548 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
65549 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65550 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
65551 }
65552 #endif /* !CONFIG_SMP */
65553
65554 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
65555 return -EFAULT;
65556 buf++; p++; count--; read++;
65557 }
65558 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
65559 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
65560 if (copy_to_user(buf, (void *)pnt, count))
65561 return -EFAULT;
65562 read += count;
65563 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
65564 }
65565 #endif
65566 profile_discard_flip_buffers();
65567 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
65568 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
65569 return count;
65570 }
65571
65572 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
65573 index 78ab24a..332c915 100644
65574 --- a/kernel/ptrace.c
65575 +++ b/kernel/ptrace.c
65576 @@ -172,7 +172,8 @@ int ptrace_check_attach(struct task_struct *child, bool ignore_state)
65577 return ret;
65578 }
65579
65580 -int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65581 +static int __ptrace_may_access(struct task_struct *task, unsigned int mode,
65582 + unsigned int log)
65583 {
65584 const struct cred *cred = current_cred(), *tcred;
65585
65586 @@ -198,7 +199,8 @@ int __ptrace_may_access(struct task_struct *task, unsigned int mode)
65587 cred->gid == tcred->sgid &&
65588 cred->gid == tcred->gid))
65589 goto ok;
65590 - if (ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE))
65591 + if ((!log && ns_capable_nolog(tcred->user->user_ns, CAP_SYS_PTRACE)) ||
65592 + (log && ns_capable(tcred->user->user_ns, CAP_SYS_PTRACE)))
65593 goto ok;
65594 rcu_read_unlock();
65595 return -EPERM;
65596 @@ -207,7 +209,9 @@ ok:
65597 smp_rmb();
65598 if (task->mm)
65599 dumpable = get_dumpable(task->mm);
65600 - if (!dumpable && !task_ns_capable(task, CAP_SYS_PTRACE))
65601 + if (!dumpable &&
65602 + ((!log && !task_ns_capable_nolog(task, CAP_SYS_PTRACE)) ||
65603 + (log && !task_ns_capable(task, CAP_SYS_PTRACE))))
65604 return -EPERM;
65605
65606 return security_ptrace_access_check(task, mode);
65607 @@ -217,7 +221,21 @@ bool ptrace_may_access(struct task_struct *task, unsigned int mode)
65608 {
65609 int err;
65610 task_lock(task);
65611 - err = __ptrace_may_access(task, mode);
65612 + err = __ptrace_may_access(task, mode, 0);
65613 + task_unlock(task);
65614 + return !err;
65615 +}
65616 +
65617 +bool ptrace_may_access_nolock(struct task_struct *task, unsigned int mode)
65618 +{
65619 + return __ptrace_may_access(task, mode, 0);
65620 +}
65621 +
65622 +bool ptrace_may_access_log(struct task_struct *task, unsigned int mode)
65623 +{
65624 + int err;
65625 + task_lock(task);
65626 + err = __ptrace_may_access(task, mode, 1);
65627 task_unlock(task);
65628 return !err;
65629 }
65630 @@ -262,7 +280,7 @@ static int ptrace_attach(struct task_struct *task, long request,
65631 goto out;
65632
65633 task_lock(task);
65634 - retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
65635 + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH, 1);
65636 task_unlock(task);
65637 if (retval)
65638 goto unlock_creds;
65639 @@ -277,7 +295,7 @@ static int ptrace_attach(struct task_struct *task, long request,
65640 task->ptrace = PT_PTRACED;
65641 if (seize)
65642 task->ptrace |= PT_SEIZED;
65643 - if (task_ns_capable(task, CAP_SYS_PTRACE))
65644 + if (task_ns_capable_nolog(task, CAP_SYS_PTRACE))
65645 task->ptrace |= PT_PTRACE_CAP;
65646
65647 __ptrace_link(task, current);
65648 @@ -483,7 +501,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
65649 break;
65650 return -EIO;
65651 }
65652 - if (copy_to_user(dst, buf, retval))
65653 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
65654 return -EFAULT;
65655 copied += retval;
65656 src += retval;
65657 @@ -680,7 +698,7 @@ int ptrace_request(struct task_struct *child, long request,
65658 bool seized = child->ptrace & PT_SEIZED;
65659 int ret = -EIO;
65660 siginfo_t siginfo, *si;
65661 - void __user *datavp = (void __user *) data;
65662 + void __user *datavp = (__force void __user *) data;
65663 unsigned long __user *datalp = datavp;
65664 unsigned long flags;
65665
65666 @@ -882,14 +900,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
65667 goto out;
65668 }
65669
65670 + if (gr_handle_ptrace(child, request)) {
65671 + ret = -EPERM;
65672 + goto out_put_task_struct;
65673 + }
65674 +
65675 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65676 ret = ptrace_attach(child, request, data);
65677 /*
65678 * Some architectures need to do book-keeping after
65679 * a ptrace attach.
65680 */
65681 - if (!ret)
65682 + if (!ret) {
65683 arch_ptrace_attach(child);
65684 + gr_audit_ptrace(child);
65685 + }
65686 goto out_put_task_struct;
65687 }
65688
65689 @@ -915,7 +940,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
65690 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
65691 if (copied != sizeof(tmp))
65692 return -EIO;
65693 - return put_user(tmp, (unsigned long __user *)data);
65694 + return put_user(tmp, (__force unsigned long __user *)data);
65695 }
65696
65697 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
65698 @@ -1025,14 +1050,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
65699 goto out;
65700 }
65701
65702 + if (gr_handle_ptrace(child, request)) {
65703 + ret = -EPERM;
65704 + goto out_put_task_struct;
65705 + }
65706 +
65707 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65708 ret = ptrace_attach(child, request, data);
65709 /*
65710 * Some architectures need to do book-keeping after
65711 * a ptrace attach.
65712 */
65713 - if (!ret)
65714 + if (!ret) {
65715 arch_ptrace_attach(child);
65716 + gr_audit_ptrace(child);
65717 + }
65718 goto out_put_task_struct;
65719 }
65720
65721 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
65722 index 764825c..3aa6ac4 100644
65723 --- a/kernel/rcutorture.c
65724 +++ b/kernel/rcutorture.c
65725 @@ -138,12 +138,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
65726 { 0 };
65727 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
65728 { 0 };
65729 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65730 -static atomic_t n_rcu_torture_alloc;
65731 -static atomic_t n_rcu_torture_alloc_fail;
65732 -static atomic_t n_rcu_torture_free;
65733 -static atomic_t n_rcu_torture_mberror;
65734 -static atomic_t n_rcu_torture_error;
65735 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
65736 +static atomic_unchecked_t n_rcu_torture_alloc;
65737 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
65738 +static atomic_unchecked_t n_rcu_torture_free;
65739 +static atomic_unchecked_t n_rcu_torture_mberror;
65740 +static atomic_unchecked_t n_rcu_torture_error;
65741 static long n_rcu_torture_boost_ktrerror;
65742 static long n_rcu_torture_boost_rterror;
65743 static long n_rcu_torture_boost_failure;
65744 @@ -223,11 +223,11 @@ rcu_torture_alloc(void)
65745
65746 spin_lock_bh(&rcu_torture_lock);
65747 if (list_empty(&rcu_torture_freelist)) {
65748 - atomic_inc(&n_rcu_torture_alloc_fail);
65749 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
65750 spin_unlock_bh(&rcu_torture_lock);
65751 return NULL;
65752 }
65753 - atomic_inc(&n_rcu_torture_alloc);
65754 + atomic_inc_unchecked(&n_rcu_torture_alloc);
65755 p = rcu_torture_freelist.next;
65756 list_del_init(p);
65757 spin_unlock_bh(&rcu_torture_lock);
65758 @@ -240,7 +240,7 @@ rcu_torture_alloc(void)
65759 static void
65760 rcu_torture_free(struct rcu_torture *p)
65761 {
65762 - atomic_inc(&n_rcu_torture_free);
65763 + atomic_inc_unchecked(&n_rcu_torture_free);
65764 spin_lock_bh(&rcu_torture_lock);
65765 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
65766 spin_unlock_bh(&rcu_torture_lock);
65767 @@ -360,7 +360,7 @@ rcu_torture_cb(struct rcu_head *p)
65768 i = rp->rtort_pipe_count;
65769 if (i > RCU_TORTURE_PIPE_LEN)
65770 i = RCU_TORTURE_PIPE_LEN;
65771 - atomic_inc(&rcu_torture_wcount[i]);
65772 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65773 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65774 rp->rtort_mbtest = 0;
65775 rcu_torture_free(rp);
65776 @@ -407,7 +407,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
65777 i = rp->rtort_pipe_count;
65778 if (i > RCU_TORTURE_PIPE_LEN)
65779 i = RCU_TORTURE_PIPE_LEN;
65780 - atomic_inc(&rcu_torture_wcount[i]);
65781 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65782 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
65783 rp->rtort_mbtest = 0;
65784 list_del(&rp->rtort_free);
65785 @@ -872,7 +872,7 @@ rcu_torture_writer(void *arg)
65786 i = old_rp->rtort_pipe_count;
65787 if (i > RCU_TORTURE_PIPE_LEN)
65788 i = RCU_TORTURE_PIPE_LEN;
65789 - atomic_inc(&rcu_torture_wcount[i]);
65790 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
65791 old_rp->rtort_pipe_count++;
65792 cur_ops->deferred_free(old_rp);
65793 }
65794 @@ -940,7 +940,7 @@ static void rcu_torture_timer(unsigned long unused)
65795 return;
65796 }
65797 if (p->rtort_mbtest == 0)
65798 - atomic_inc(&n_rcu_torture_mberror);
65799 + atomic_inc_unchecked(&n_rcu_torture_mberror);
65800 spin_lock(&rand_lock);
65801 cur_ops->read_delay(&rand);
65802 n_rcu_torture_timers++;
65803 @@ -1001,7 +1001,7 @@ rcu_torture_reader(void *arg)
65804 continue;
65805 }
65806 if (p->rtort_mbtest == 0)
65807 - atomic_inc(&n_rcu_torture_mberror);
65808 + atomic_inc_unchecked(&n_rcu_torture_mberror);
65809 cur_ops->read_delay(&rand);
65810 preempt_disable();
65811 pipe_count = p->rtort_pipe_count;
65812 @@ -1060,16 +1060,16 @@ rcu_torture_printk(char *page)
65813 rcu_torture_current,
65814 rcu_torture_current_version,
65815 list_empty(&rcu_torture_freelist),
65816 - atomic_read(&n_rcu_torture_alloc),
65817 - atomic_read(&n_rcu_torture_alloc_fail),
65818 - atomic_read(&n_rcu_torture_free),
65819 - atomic_read(&n_rcu_torture_mberror),
65820 + atomic_read_unchecked(&n_rcu_torture_alloc),
65821 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
65822 + atomic_read_unchecked(&n_rcu_torture_free),
65823 + atomic_read_unchecked(&n_rcu_torture_mberror),
65824 n_rcu_torture_boost_ktrerror,
65825 n_rcu_torture_boost_rterror,
65826 n_rcu_torture_boost_failure,
65827 n_rcu_torture_boosts,
65828 n_rcu_torture_timers);
65829 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
65830 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
65831 n_rcu_torture_boost_ktrerror != 0 ||
65832 n_rcu_torture_boost_rterror != 0 ||
65833 n_rcu_torture_boost_failure != 0)
65834 @@ -1077,7 +1077,7 @@ rcu_torture_printk(char *page)
65835 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
65836 if (i > 1) {
65837 cnt += sprintf(&page[cnt], "!!! ");
65838 - atomic_inc(&n_rcu_torture_error);
65839 + atomic_inc_unchecked(&n_rcu_torture_error);
65840 WARN_ON_ONCE(1);
65841 }
65842 cnt += sprintf(&page[cnt], "Reader Pipe: ");
65843 @@ -1091,7 +1091,7 @@ rcu_torture_printk(char *page)
65844 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
65845 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65846 cnt += sprintf(&page[cnt], " %d",
65847 - atomic_read(&rcu_torture_wcount[i]));
65848 + atomic_read_unchecked(&rcu_torture_wcount[i]));
65849 }
65850 cnt += sprintf(&page[cnt], "\n");
65851 if (cur_ops->stats)
65852 @@ -1401,7 +1401,7 @@ rcu_torture_cleanup(void)
65853
65854 if (cur_ops->cleanup)
65855 cur_ops->cleanup();
65856 - if (atomic_read(&n_rcu_torture_error))
65857 + if (atomic_read_unchecked(&n_rcu_torture_error))
65858 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
65859 else
65860 rcu_torture_print_module_parms(cur_ops, "End of test: SUCCESS");
65861 @@ -1465,17 +1465,17 @@ rcu_torture_init(void)
65862
65863 rcu_torture_current = NULL;
65864 rcu_torture_current_version = 0;
65865 - atomic_set(&n_rcu_torture_alloc, 0);
65866 - atomic_set(&n_rcu_torture_alloc_fail, 0);
65867 - atomic_set(&n_rcu_torture_free, 0);
65868 - atomic_set(&n_rcu_torture_mberror, 0);
65869 - atomic_set(&n_rcu_torture_error, 0);
65870 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
65871 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
65872 + atomic_set_unchecked(&n_rcu_torture_free, 0);
65873 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
65874 + atomic_set_unchecked(&n_rcu_torture_error, 0);
65875 n_rcu_torture_boost_ktrerror = 0;
65876 n_rcu_torture_boost_rterror = 0;
65877 n_rcu_torture_boost_failure = 0;
65878 n_rcu_torture_boosts = 0;
65879 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
65880 - atomic_set(&rcu_torture_wcount[i], 0);
65881 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
65882 for_each_possible_cpu(cpu) {
65883 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
65884 per_cpu(rcu_torture_count, cpu)[i] = 0;
65885 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
65886 index 6b76d81..7afc1b3 100644
65887 --- a/kernel/rcutree.c
65888 +++ b/kernel/rcutree.c
65889 @@ -367,9 +367,9 @@ void rcu_enter_nohz(void)
65890 trace_rcu_dyntick("Start");
65891 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
65892 smp_mb__before_atomic_inc(); /* See above. */
65893 - atomic_inc(&rdtp->dynticks);
65894 + atomic_inc_unchecked(&rdtp->dynticks);
65895 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
65896 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
65897 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
65898 local_irq_restore(flags);
65899 }
65900
65901 @@ -391,10 +391,10 @@ void rcu_exit_nohz(void)
65902 return;
65903 }
65904 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
65905 - atomic_inc(&rdtp->dynticks);
65906 + atomic_inc_unchecked(&rdtp->dynticks);
65907 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
65908 smp_mb__after_atomic_inc(); /* See above. */
65909 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
65910 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
65911 trace_rcu_dyntick("End");
65912 local_irq_restore(flags);
65913 }
65914 @@ -411,14 +411,14 @@ void rcu_nmi_enter(void)
65915 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
65916
65917 if (rdtp->dynticks_nmi_nesting == 0 &&
65918 - (atomic_read(&rdtp->dynticks) & 0x1))
65919 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
65920 return;
65921 rdtp->dynticks_nmi_nesting++;
65922 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
65923 - atomic_inc(&rdtp->dynticks);
65924 + atomic_inc_unchecked(&rdtp->dynticks);
65925 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
65926 smp_mb__after_atomic_inc(); /* See above. */
65927 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
65928 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
65929 }
65930
65931 /**
65932 @@ -437,9 +437,9 @@ void rcu_nmi_exit(void)
65933 return;
65934 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
65935 smp_mb__before_atomic_inc(); /* See above. */
65936 - atomic_inc(&rdtp->dynticks);
65937 + atomic_inc_unchecked(&rdtp->dynticks);
65938 smp_mb__after_atomic_inc(); /* Force delay to next write. */
65939 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
65940 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
65941 }
65942
65943 /**
65944 @@ -474,7 +474,7 @@ void rcu_irq_exit(void)
65945 */
65946 static int dyntick_save_progress_counter(struct rcu_data *rdp)
65947 {
65948 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
65949 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
65950 return 0;
65951 }
65952
65953 @@ -489,7 +489,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
65954 unsigned int curr;
65955 unsigned int snap;
65956
65957 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
65958 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
65959 snap = (unsigned int)rdp->dynticks_snap;
65960
65961 /*
65962 @@ -1552,7 +1552,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
65963 /*
65964 * Do RCU core processing for the current CPU.
65965 */
65966 -static void rcu_process_callbacks(struct softirq_action *unused)
65967 +static void rcu_process_callbacks(void)
65968 {
65969 trace_rcu_utilization("Start RCU core");
65970 __rcu_process_callbacks(&rcu_sched_state,
65971 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
65972 index 849ce9e..74bc9de 100644
65973 --- a/kernel/rcutree.h
65974 +++ b/kernel/rcutree.h
65975 @@ -86,7 +86,7 @@
65976 struct rcu_dynticks {
65977 int dynticks_nesting; /* Track irq/process nesting level. */
65978 int dynticks_nmi_nesting; /* Track NMI nesting level. */
65979 - atomic_t dynticks; /* Even value for dynticks-idle, else odd. */
65980 + atomic_unchecked_t dynticks; /* Even value for dynticks-idle, else odd. */
65981 };
65982
65983 /* RCU's kthread states for tracing. */
65984 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
65985 index 4b9b9f8..2326053 100644
65986 --- a/kernel/rcutree_plugin.h
65987 +++ b/kernel/rcutree_plugin.h
65988 @@ -842,7 +842,7 @@ void synchronize_rcu_expedited(void)
65989
65990 /* Clean up and exit. */
65991 smp_mb(); /* ensure expedited GP seen before counter increment. */
65992 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
65993 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
65994 unlock_mb_ret:
65995 mutex_unlock(&sync_rcu_preempt_exp_mutex);
65996 mb_ret:
65997 @@ -1815,8 +1815,8 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
65998
65999 #else /* #ifndef CONFIG_SMP */
66000
66001 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
66002 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
66003 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
66004 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
66005
66006 static int synchronize_sched_expedited_cpu_stop(void *data)
66007 {
66008 @@ -1871,7 +1871,7 @@ void synchronize_sched_expedited(void)
66009 int firstsnap, s, snap, trycount = 0;
66010
66011 /* Note that atomic_inc_return() implies full memory barrier. */
66012 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
66013 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
66014 get_online_cpus();
66015
66016 /*
66017 @@ -1892,7 +1892,7 @@ void synchronize_sched_expedited(void)
66018 }
66019
66020 /* Check to see if someone else did our work for us. */
66021 - s = atomic_read(&sync_sched_expedited_done);
66022 + s = atomic_read_unchecked(&sync_sched_expedited_done);
66023 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
66024 smp_mb(); /* ensure test happens before caller kfree */
66025 return;
66026 @@ -1907,7 +1907,7 @@ void synchronize_sched_expedited(void)
66027 * grace period works for us.
66028 */
66029 get_online_cpus();
66030 - snap = atomic_read(&sync_sched_expedited_started) - 1;
66031 + snap = atomic_read_unchecked(&sync_sched_expedited_started) - 1;
66032 smp_mb(); /* ensure read is before try_stop_cpus(). */
66033 }
66034
66035 @@ -1918,12 +1918,12 @@ void synchronize_sched_expedited(void)
66036 * than we did beat us to the punch.
66037 */
66038 do {
66039 - s = atomic_read(&sync_sched_expedited_done);
66040 + s = atomic_read_unchecked(&sync_sched_expedited_done);
66041 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
66042 smp_mb(); /* ensure test happens before caller kfree */
66043 break;
66044 }
66045 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
66046 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
66047
66048 put_online_cpus();
66049 }
66050 @@ -1985,7 +1985,7 @@ int rcu_needs_cpu(int cpu)
66051 for_each_online_cpu(thatcpu) {
66052 if (thatcpu == cpu)
66053 continue;
66054 - snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
66055 + snap = atomic_add_return_unchecked(0, &per_cpu(rcu_dynticks,
66056 thatcpu).dynticks);
66057 smp_mb(); /* Order sampling of snap with end of grace period. */
66058 if ((snap & 0x1) != 0) {
66059 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
66060 index 9feffa4..54058df 100644
66061 --- a/kernel/rcutree_trace.c
66062 +++ b/kernel/rcutree_trace.c
66063 @@ -69,7 +69,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
66064 rdp->qs_pending);
66065 #ifdef CONFIG_NO_HZ
66066 seq_printf(m, " dt=%d/%d/%d df=%lu",
66067 - atomic_read(&rdp->dynticks->dynticks),
66068 + atomic_read_unchecked(&rdp->dynticks->dynticks),
66069 rdp->dynticks->dynticks_nesting,
66070 rdp->dynticks->dynticks_nmi_nesting,
66071 rdp->dynticks_fqs);
66072 @@ -143,7 +143,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
66073 rdp->qs_pending);
66074 #ifdef CONFIG_NO_HZ
66075 seq_printf(m, ",%d,%d,%d,%lu",
66076 - atomic_read(&rdp->dynticks->dynticks),
66077 + atomic_read_unchecked(&rdp->dynticks->dynticks),
66078 rdp->dynticks->dynticks_nesting,
66079 rdp->dynticks->dynticks_nmi_nesting,
66080 rdp->dynticks_fqs);
66081 diff --git a/kernel/resource.c b/kernel/resource.c
66082 index 7640b3a..5879283 100644
66083 --- a/kernel/resource.c
66084 +++ b/kernel/resource.c
66085 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
66086
66087 static int __init ioresources_init(void)
66088 {
66089 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
66090 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66091 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
66092 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
66093 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66094 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
66095 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
66096 +#endif
66097 +#else
66098 proc_create("ioports", 0, NULL, &proc_ioports_operations);
66099 proc_create("iomem", 0, NULL, &proc_iomem_operations);
66100 +#endif
66101 return 0;
66102 }
66103 __initcall(ioresources_init);
66104 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
66105 index 3d9f31c..7fefc9e 100644
66106 --- a/kernel/rtmutex-tester.c
66107 +++ b/kernel/rtmutex-tester.c
66108 @@ -20,7 +20,7 @@
66109 #define MAX_RT_TEST_MUTEXES 8
66110
66111 static spinlock_t rttest_lock;
66112 -static atomic_t rttest_event;
66113 +static atomic_unchecked_t rttest_event;
66114
66115 struct test_thread_data {
66116 int opcode;
66117 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66118
66119 case RTTEST_LOCKCONT:
66120 td->mutexes[td->opdata] = 1;
66121 - td->event = atomic_add_return(1, &rttest_event);
66122 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66123 return 0;
66124
66125 case RTTEST_RESET:
66126 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66127 return 0;
66128
66129 case RTTEST_RESETEVENT:
66130 - atomic_set(&rttest_event, 0);
66131 + atomic_set_unchecked(&rttest_event, 0);
66132 return 0;
66133
66134 default:
66135 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66136 return ret;
66137
66138 td->mutexes[id] = 1;
66139 - td->event = atomic_add_return(1, &rttest_event);
66140 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66141 rt_mutex_lock(&mutexes[id]);
66142 - td->event = atomic_add_return(1, &rttest_event);
66143 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66144 td->mutexes[id] = 4;
66145 return 0;
66146
66147 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66148 return ret;
66149
66150 td->mutexes[id] = 1;
66151 - td->event = atomic_add_return(1, &rttest_event);
66152 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66153 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
66154 - td->event = atomic_add_return(1, &rttest_event);
66155 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66156 td->mutexes[id] = ret ? 0 : 4;
66157 return ret ? -EINTR : 0;
66158
66159 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
66160 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
66161 return ret;
66162
66163 - td->event = atomic_add_return(1, &rttest_event);
66164 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66165 rt_mutex_unlock(&mutexes[id]);
66166 - td->event = atomic_add_return(1, &rttest_event);
66167 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66168 td->mutexes[id] = 0;
66169 return 0;
66170
66171 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66172 break;
66173
66174 td->mutexes[dat] = 2;
66175 - td->event = atomic_add_return(1, &rttest_event);
66176 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66177 break;
66178
66179 default:
66180 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66181 return;
66182
66183 td->mutexes[dat] = 3;
66184 - td->event = atomic_add_return(1, &rttest_event);
66185 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66186 break;
66187
66188 case RTTEST_LOCKNOWAIT:
66189 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
66190 return;
66191
66192 td->mutexes[dat] = 1;
66193 - td->event = atomic_add_return(1, &rttest_event);
66194 + td->event = atomic_add_return_unchecked(1, &rttest_event);
66195 return;
66196
66197 default:
66198 diff --git a/kernel/sched.c b/kernel/sched.c
66199 index d6b149c..896cbb8 100644
66200 --- a/kernel/sched.c
66201 +++ b/kernel/sched.c
66202 @@ -4389,6 +4389,19 @@ pick_next_task(struct rq *rq)
66203 BUG(); /* the idle class will always have a runnable task */
66204 }
66205
66206 +#ifdef CONFIG_GRKERNSEC_SETXID
66207 +extern void gr_delayed_cred_worker(void);
66208 +static inline void gr_cred_schedule(void)
66209 +{
66210 + if (unlikely(current->delayed_cred))
66211 + gr_delayed_cred_worker();
66212 +}
66213 +#else
66214 +static inline void gr_cred_schedule(void)
66215 +{
66216 +}
66217 +#endif
66218 +
66219 /*
66220 * __schedule() is the main scheduler function.
66221 */
66222 @@ -4408,6 +4421,8 @@ need_resched:
66223
66224 schedule_debug(prev);
66225
66226 + gr_cred_schedule();
66227 +
66228 if (sched_feat(HRTICK))
66229 hrtick_clear(rq);
66230
66231 @@ -5098,6 +5113,8 @@ int can_nice(const struct task_struct *p, const int nice)
66232 /* convert nice value [19,-20] to rlimit style value [1,40] */
66233 int nice_rlim = 20 - nice;
66234
66235 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
66236 +
66237 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
66238 capable(CAP_SYS_NICE));
66239 }
66240 @@ -5131,7 +5148,8 @@ SYSCALL_DEFINE1(nice, int, increment)
66241 if (nice > 19)
66242 nice = 19;
66243
66244 - if (increment < 0 && !can_nice(current, nice))
66245 + if (increment < 0 && (!can_nice(current, nice) ||
66246 + gr_handle_chroot_nice()))
66247 return -EPERM;
66248
66249 retval = security_task_setnice(current, nice);
66250 @@ -5288,6 +5306,7 @@ recheck:
66251 unsigned long rlim_rtprio =
66252 task_rlimit(p, RLIMIT_RTPRIO);
66253
66254 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
66255 /* can't set/change the rt policy */
66256 if (policy != p->policy && !rlim_rtprio)
66257 return -EPERM;
66258 diff --git a/kernel/sched_autogroup.c b/kernel/sched_autogroup.c
66259 index 429242f..d7cca82 100644
66260 --- a/kernel/sched_autogroup.c
66261 +++ b/kernel/sched_autogroup.c
66262 @@ -7,7 +7,7 @@
66263
66264 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
66265 static struct autogroup autogroup_default;
66266 -static atomic_t autogroup_seq_nr;
66267 +static atomic_unchecked_t autogroup_seq_nr;
66268
66269 static void __init autogroup_init(struct task_struct *init_task)
66270 {
66271 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
66272
66273 kref_init(&ag->kref);
66274 init_rwsem(&ag->lock);
66275 - ag->id = atomic_inc_return(&autogroup_seq_nr);
66276 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
66277 ag->tg = tg;
66278 #ifdef CONFIG_RT_GROUP_SCHED
66279 /*
66280 diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
66281 index 8a39fa3..34f3dbc 100644
66282 --- a/kernel/sched_fair.c
66283 +++ b/kernel/sched_fair.c
66284 @@ -4801,7 +4801,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
66285 * run_rebalance_domains is triggered when needed from the scheduler tick.
66286 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
66287 */
66288 -static void run_rebalance_domains(struct softirq_action *h)
66289 +static void run_rebalance_domains(void)
66290 {
66291 int this_cpu = smp_processor_id();
66292 struct rq *this_rq = cpu_rq(this_cpu);
66293 diff --git a/kernel/signal.c b/kernel/signal.c
66294 index 2065515..aed2987 100644
66295 --- a/kernel/signal.c
66296 +++ b/kernel/signal.c
66297 @@ -45,12 +45,12 @@ static struct kmem_cache *sigqueue_cachep;
66298
66299 int print_fatal_signals __read_mostly;
66300
66301 -static void __user *sig_handler(struct task_struct *t, int sig)
66302 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
66303 {
66304 return t->sighand->action[sig - 1].sa.sa_handler;
66305 }
66306
66307 -static int sig_handler_ignored(void __user *handler, int sig)
66308 +static int sig_handler_ignored(__sighandler_t handler, int sig)
66309 {
66310 /* Is it explicitly or implicitly ignored? */
66311 return handler == SIG_IGN ||
66312 @@ -60,7 +60,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
66313 static int sig_task_ignored(struct task_struct *t, int sig,
66314 int from_ancestor_ns)
66315 {
66316 - void __user *handler;
66317 + __sighandler_t handler;
66318
66319 handler = sig_handler(t, sig);
66320
66321 @@ -364,6 +364,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
66322 atomic_inc(&user->sigpending);
66323 rcu_read_unlock();
66324
66325 + if (!override_rlimit)
66326 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
66327 +
66328 if (override_rlimit ||
66329 atomic_read(&user->sigpending) <=
66330 task_rlimit(t, RLIMIT_SIGPENDING)) {
66331 @@ -488,7 +491,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
66332
66333 int unhandled_signal(struct task_struct *tsk, int sig)
66334 {
66335 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
66336 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
66337 if (is_global_init(tsk))
66338 return 1;
66339 if (handler != SIG_IGN && handler != SIG_DFL)
66340 @@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
66341 }
66342 }
66343
66344 + /* allow glibc communication via tgkill to other threads in our
66345 + thread group */
66346 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
66347 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
66348 + && gr_handle_signal(t, sig))
66349 + return -EPERM;
66350 +
66351 return security_task_kill(t, info, sig, 0);
66352 }
66353
66354 @@ -1165,7 +1175,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
66355 return send_signal(sig, info, p, 1);
66356 }
66357
66358 -static int
66359 +int
66360 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66361 {
66362 return send_signal(sig, info, t, 0);
66363 @@ -1202,6 +1212,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66364 unsigned long int flags;
66365 int ret, blocked, ignored;
66366 struct k_sigaction *action;
66367 + int is_unhandled = 0;
66368
66369 spin_lock_irqsave(&t->sighand->siglock, flags);
66370 action = &t->sighand->action[sig-1];
66371 @@ -1216,9 +1227,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
66372 }
66373 if (action->sa.sa_handler == SIG_DFL)
66374 t->signal->flags &= ~SIGNAL_UNKILLABLE;
66375 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
66376 + is_unhandled = 1;
66377 ret = specific_send_sig_info(sig, info, t);
66378 spin_unlock_irqrestore(&t->sighand->siglock, flags);
66379
66380 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
66381 + normal operation */
66382 + if (is_unhandled) {
66383 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
66384 + gr_handle_crash(t, sig);
66385 + }
66386 +
66387 return ret;
66388 }
66389
66390 @@ -1285,8 +1305,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
66391 ret = check_kill_permission(sig, info, p);
66392 rcu_read_unlock();
66393
66394 - if (!ret && sig)
66395 + if (!ret && sig) {
66396 ret = do_send_sig_info(sig, info, p, true);
66397 + if (!ret)
66398 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
66399 + }
66400
66401 return ret;
66402 }
66403 @@ -2754,7 +2777,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
66404 int error = -ESRCH;
66405
66406 rcu_read_lock();
66407 - p = find_task_by_vpid(pid);
66408 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66409 + /* allow glibc communication via tgkill to other threads in our
66410 + thread group */
66411 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
66412 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
66413 + p = find_task_by_vpid_unrestricted(pid);
66414 + else
66415 +#endif
66416 + p = find_task_by_vpid(pid);
66417 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
66418 error = check_kill_permission(sig, info, p);
66419 /*
66420 diff --git a/kernel/smp.c b/kernel/smp.c
66421 index db197d6..17aef0b 100644
66422 --- a/kernel/smp.c
66423 +++ b/kernel/smp.c
66424 @@ -580,22 +580,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
66425 }
66426 EXPORT_SYMBOL(smp_call_function);
66427
66428 -void ipi_call_lock(void)
66429 +void ipi_call_lock(void) __acquires(call_function.lock)
66430 {
66431 raw_spin_lock(&call_function.lock);
66432 }
66433
66434 -void ipi_call_unlock(void)
66435 +void ipi_call_unlock(void) __releases(call_function.lock)
66436 {
66437 raw_spin_unlock(&call_function.lock);
66438 }
66439
66440 -void ipi_call_lock_irq(void)
66441 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
66442 {
66443 raw_spin_lock_irq(&call_function.lock);
66444 }
66445
66446 -void ipi_call_unlock_irq(void)
66447 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
66448 {
66449 raw_spin_unlock_irq(&call_function.lock);
66450 }
66451 diff --git a/kernel/softirq.c b/kernel/softirq.c
66452 index 2c71d91..1021f81 100644
66453 --- a/kernel/softirq.c
66454 +++ b/kernel/softirq.c
66455 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
66456
66457 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
66458
66459 -char *softirq_to_name[NR_SOFTIRQS] = {
66460 +const char * const softirq_to_name[NR_SOFTIRQS] = {
66461 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
66462 "TASKLET", "SCHED", "HRTIMER", "RCU"
66463 };
66464 @@ -235,7 +235,7 @@ restart:
66465 kstat_incr_softirqs_this_cpu(vec_nr);
66466
66467 trace_softirq_entry(vec_nr);
66468 - h->action(h);
66469 + h->action();
66470 trace_softirq_exit(vec_nr);
66471 if (unlikely(prev_count != preempt_count())) {
66472 printk(KERN_ERR "huh, entered softirq %u %s %p"
66473 @@ -385,9 +385,11 @@ void raise_softirq(unsigned int nr)
66474 local_irq_restore(flags);
66475 }
66476
66477 -void open_softirq(int nr, void (*action)(struct softirq_action *))
66478 +void open_softirq(int nr, void (*action)(void))
66479 {
66480 - softirq_vec[nr].action = action;
66481 + pax_open_kernel();
66482 + *(void **)&softirq_vec[nr].action = action;
66483 + pax_close_kernel();
66484 }
66485
66486 /*
66487 @@ -441,7 +443,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
66488
66489 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
66490
66491 -static void tasklet_action(struct softirq_action *a)
66492 +static void tasklet_action(void)
66493 {
66494 struct tasklet_struct *list;
66495
66496 @@ -476,7 +478,7 @@ static void tasklet_action(struct softirq_action *a)
66497 }
66498 }
66499
66500 -static void tasklet_hi_action(struct softirq_action *a)
66501 +static void tasklet_hi_action(void)
66502 {
66503 struct tasklet_struct *list;
66504
66505 diff --git a/kernel/sys.c b/kernel/sys.c
66506 index 481611f..0754d86 100644
66507 --- a/kernel/sys.c
66508 +++ b/kernel/sys.c
66509 @@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
66510 error = -EACCES;
66511 goto out;
66512 }
66513 +
66514 + if (gr_handle_chroot_setpriority(p, niceval)) {
66515 + error = -EACCES;
66516 + goto out;
66517 + }
66518 +
66519 no_nice = security_task_setnice(p, niceval);
66520 if (no_nice) {
66521 error = no_nice;
66522 @@ -572,6 +578,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
66523 goto error;
66524 }
66525
66526 + if (gr_check_group_change(new->gid, new->egid, -1))
66527 + goto error;
66528 +
66529 if (rgid != (gid_t) -1 ||
66530 (egid != (gid_t) -1 && egid != old->gid))
66531 new->sgid = new->egid;
66532 @@ -601,6 +610,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
66533 old = current_cred();
66534
66535 retval = -EPERM;
66536 +
66537 + if (gr_check_group_change(gid, gid, gid))
66538 + goto error;
66539 +
66540 if (nsown_capable(CAP_SETGID))
66541 new->gid = new->egid = new->sgid = new->fsgid = gid;
66542 else if (gid == old->gid || gid == old->sgid)
66543 @@ -618,7 +631,7 @@ error:
66544 /*
66545 * change the user struct in a credentials set to match the new UID
66546 */
66547 -static int set_user(struct cred *new)
66548 +int set_user(struct cred *new)
66549 {
66550 struct user_struct *new_user;
66551
66552 @@ -688,6 +701,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
66553 goto error;
66554 }
66555
66556 + if (gr_check_user_change(new->uid, new->euid, -1))
66557 + goto error;
66558 +
66559 if (new->uid != old->uid) {
66560 retval = set_user(new);
66561 if (retval < 0)
66562 @@ -732,6 +748,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
66563 old = current_cred();
66564
66565 retval = -EPERM;
66566 +
66567 + if (gr_check_crash_uid(uid))
66568 + goto error;
66569 + if (gr_check_user_change(uid, uid, uid))
66570 + goto error;
66571 +
66572 if (nsown_capable(CAP_SETUID)) {
66573 new->suid = new->uid = uid;
66574 if (uid != old->uid) {
66575 @@ -786,6 +808,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
66576 goto error;
66577 }
66578
66579 + if (gr_check_user_change(ruid, euid, -1))
66580 + goto error;
66581 +
66582 if (ruid != (uid_t) -1) {
66583 new->uid = ruid;
66584 if (ruid != old->uid) {
66585 @@ -850,6 +875,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
66586 goto error;
66587 }
66588
66589 + if (gr_check_group_change(rgid, egid, -1))
66590 + goto error;
66591 +
66592 if (rgid != (gid_t) -1)
66593 new->gid = rgid;
66594 if (egid != (gid_t) -1)
66595 @@ -896,6 +924,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66596 old = current_cred();
66597 old_fsuid = old->fsuid;
66598
66599 + if (gr_check_user_change(-1, -1, uid))
66600 + goto error;
66601 +
66602 if (uid == old->uid || uid == old->euid ||
66603 uid == old->suid || uid == old->fsuid ||
66604 nsown_capable(CAP_SETUID)) {
66605 @@ -906,6 +937,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
66606 }
66607 }
66608
66609 +error:
66610 abort_creds(new);
66611 return old_fsuid;
66612
66613 @@ -932,12 +964,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
66614 if (gid == old->gid || gid == old->egid ||
66615 gid == old->sgid || gid == old->fsgid ||
66616 nsown_capable(CAP_SETGID)) {
66617 + if (gr_check_group_change(-1, -1, gid))
66618 + goto error;
66619 +
66620 if (gid != old_fsgid) {
66621 new->fsgid = gid;
66622 goto change_okay;
66623 }
66624 }
66625
66626 +error:
66627 abort_creds(new);
66628 return old_fsgid;
66629
66630 @@ -1189,7 +1225,10 @@ static int override_release(char __user *release, int len)
66631 }
66632 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
66633 snprintf(buf, len, "2.6.%u%s", v, rest);
66634 - ret = copy_to_user(release, buf, len);
66635 + if (len > sizeof(buf))
66636 + ret = -EFAULT;
66637 + else
66638 + ret = copy_to_user(release, buf, len);
66639 }
66640 return ret;
66641 }
66642 @@ -1243,19 +1282,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
66643 return -EFAULT;
66644
66645 down_read(&uts_sem);
66646 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
66647 + error = __copy_to_user(name->sysname, &utsname()->sysname,
66648 __OLD_UTS_LEN);
66649 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
66650 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
66651 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
66652 __OLD_UTS_LEN);
66653 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
66654 - error |= __copy_to_user(&name->release, &utsname()->release,
66655 + error |= __copy_to_user(name->release, &utsname()->release,
66656 __OLD_UTS_LEN);
66657 error |= __put_user(0, name->release + __OLD_UTS_LEN);
66658 - error |= __copy_to_user(&name->version, &utsname()->version,
66659 + error |= __copy_to_user(name->version, &utsname()->version,
66660 __OLD_UTS_LEN);
66661 error |= __put_user(0, name->version + __OLD_UTS_LEN);
66662 - error |= __copy_to_user(&name->machine, &utsname()->machine,
66663 + error |= __copy_to_user(name->machine, &utsname()->machine,
66664 __OLD_UTS_LEN);
66665 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
66666 up_read(&uts_sem);
66667 @@ -1720,7 +1759,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
66668 error = get_dumpable(me->mm);
66669 break;
66670 case PR_SET_DUMPABLE:
66671 - if (arg2 < 0 || arg2 > 1) {
66672 + if (arg2 > 1) {
66673 error = -EINVAL;
66674 break;
66675 }
66676 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
66677 index ae27196..7506d69 100644
66678 --- a/kernel/sysctl.c
66679 +++ b/kernel/sysctl.c
66680 @@ -86,6 +86,13 @@
66681
66682
66683 #if defined(CONFIG_SYSCTL)
66684 +#include <linux/grsecurity.h>
66685 +#include <linux/grinternal.h>
66686 +
66687 +extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
66688 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66689 + const int op);
66690 +extern int gr_handle_chroot_sysctl(const int op);
66691
66692 /* External variables not in a header file. */
66693 extern int sysctl_overcommit_memory;
66694 @@ -191,6 +198,7 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
66695 }
66696
66697 #endif
66698 +extern struct ctl_table grsecurity_table[];
66699
66700 static struct ctl_table root_table[];
66701 static struct ctl_table_root sysctl_table_root;
66702 @@ -220,6 +228,20 @@ extern struct ctl_table epoll_table[];
66703 int sysctl_legacy_va_layout;
66704 #endif
66705
66706 +#ifdef CONFIG_PAX_SOFTMODE
66707 +static ctl_table pax_table[] = {
66708 + {
66709 + .procname = "softmode",
66710 + .data = &pax_softmode,
66711 + .maxlen = sizeof(unsigned int),
66712 + .mode = 0600,
66713 + .proc_handler = &proc_dointvec,
66714 + },
66715 +
66716 + { }
66717 +};
66718 +#endif
66719 +
66720 /* The default sysctl tables: */
66721
66722 static struct ctl_table root_table[] = {
66723 @@ -266,6 +288,22 @@ static int max_extfrag_threshold = 1000;
66724 #endif
66725
66726 static struct ctl_table kern_table[] = {
66727 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66728 + {
66729 + .procname = "grsecurity",
66730 + .mode = 0500,
66731 + .child = grsecurity_table,
66732 + },
66733 +#endif
66734 +
66735 +#ifdef CONFIG_PAX_SOFTMODE
66736 + {
66737 + .procname = "pax",
66738 + .mode = 0500,
66739 + .child = pax_table,
66740 + },
66741 +#endif
66742 +
66743 {
66744 .procname = "sched_child_runs_first",
66745 .data = &sysctl_sched_child_runs_first,
66746 @@ -550,7 +588,7 @@ static struct ctl_table kern_table[] = {
66747 .data = &modprobe_path,
66748 .maxlen = KMOD_PATH_LEN,
66749 .mode = 0644,
66750 - .proc_handler = proc_dostring,
66751 + .proc_handler = proc_dostring_modpriv,
66752 },
66753 {
66754 .procname = "modules_disabled",
66755 @@ -717,16 +755,20 @@ static struct ctl_table kern_table[] = {
66756 .extra1 = &zero,
66757 .extra2 = &one,
66758 },
66759 +#endif
66760 {
66761 .procname = "kptr_restrict",
66762 .data = &kptr_restrict,
66763 .maxlen = sizeof(int),
66764 .mode = 0644,
66765 .proc_handler = proc_dmesg_restrict,
66766 +#ifdef CONFIG_GRKERNSEC_HIDESYM
66767 + .extra1 = &two,
66768 +#else
66769 .extra1 = &zero,
66770 +#endif
66771 .extra2 = &two,
66772 },
66773 -#endif
66774 {
66775 .procname = "ngroups_max",
66776 .data = &ngroups_max,
66777 @@ -1216,6 +1258,13 @@ static struct ctl_table vm_table[] = {
66778 .proc_handler = proc_dointvec_minmax,
66779 .extra1 = &zero,
66780 },
66781 + {
66782 + .procname = "heap_stack_gap",
66783 + .data = &sysctl_heap_stack_gap,
66784 + .maxlen = sizeof(sysctl_heap_stack_gap),
66785 + .mode = 0644,
66786 + .proc_handler = proc_doulongvec_minmax,
66787 + },
66788 #else
66789 {
66790 .procname = "nr_trim_pages",
66791 @@ -1720,6 +1769,17 @@ static int test_perm(int mode, int op)
66792 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
66793 {
66794 int mode;
66795 + int error;
66796 +
66797 + if (table->parent != NULL && table->parent->procname != NULL &&
66798 + table->procname != NULL &&
66799 + gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
66800 + return -EACCES;
66801 + if (gr_handle_chroot_sysctl(op))
66802 + return -EACCES;
66803 + error = gr_handle_sysctl(table, op);
66804 + if (error)
66805 + return error;
66806
66807 if (root->permissions)
66808 mode = root->permissions(root, current->nsproxy, table);
66809 @@ -2124,6 +2184,16 @@ int proc_dostring(struct ctl_table *table, int write,
66810 buffer, lenp, ppos);
66811 }
66812
66813 +int proc_dostring_modpriv(struct ctl_table *table, int write,
66814 + void __user *buffer, size_t *lenp, loff_t *ppos)
66815 +{
66816 + if (write && !capable(CAP_SYS_MODULE))
66817 + return -EPERM;
66818 +
66819 + return _proc_do_string(table->data, table->maxlen, write,
66820 + buffer, lenp, ppos);
66821 +}
66822 +
66823 static size_t proc_skip_spaces(char **buf)
66824 {
66825 size_t ret;
66826 @@ -2229,6 +2299,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
66827 len = strlen(tmp);
66828 if (len > *size)
66829 len = *size;
66830 + if (len > sizeof(tmp))
66831 + len = sizeof(tmp);
66832 if (copy_to_user(*buf, tmp, len))
66833 return -EFAULT;
66834 *size -= len;
66835 @@ -2545,8 +2617,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
66836 *i = val;
66837 } else {
66838 val = convdiv * (*i) / convmul;
66839 - if (!first)
66840 + if (!first) {
66841 err = proc_put_char(&buffer, &left, '\t');
66842 + if (err)
66843 + break;
66844 + }
66845 err = proc_put_long(&buffer, &left, val, false);
66846 if (err)
66847 break;
66848 @@ -2941,6 +3016,12 @@ int proc_dostring(struct ctl_table *table, int write,
66849 return -ENOSYS;
66850 }
66851
66852 +int proc_dostring_modpriv(struct ctl_table *table, int write,
66853 + void __user *buffer, size_t *lenp, loff_t *ppos)
66854 +{
66855 + return -ENOSYS;
66856 +}
66857 +
66858 int proc_dointvec(struct ctl_table *table, int write,
66859 void __user *buffer, size_t *lenp, loff_t *ppos)
66860 {
66861 @@ -2997,6 +3078,7 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
66862 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
66863 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
66864 EXPORT_SYMBOL(proc_dostring);
66865 +EXPORT_SYMBOL(proc_dostring_modpriv);
66866 EXPORT_SYMBOL(proc_doulongvec_minmax);
66867 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
66868 EXPORT_SYMBOL(register_sysctl_table);
66869 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
66870 index a650694..aaeeb20 100644
66871 --- a/kernel/sysctl_binary.c
66872 +++ b/kernel/sysctl_binary.c
66873 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
66874 int i;
66875
66876 set_fs(KERNEL_DS);
66877 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
66878 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
66879 set_fs(old_fs);
66880 if (result < 0)
66881 goto out_kfree;
66882 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
66883 }
66884
66885 set_fs(KERNEL_DS);
66886 - result = vfs_write(file, buffer, str - buffer, &pos);
66887 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
66888 set_fs(old_fs);
66889 if (result < 0)
66890 goto out_kfree;
66891 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
66892 int i;
66893
66894 set_fs(KERNEL_DS);
66895 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
66896 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
66897 set_fs(old_fs);
66898 if (result < 0)
66899 goto out_kfree;
66900 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
66901 }
66902
66903 set_fs(KERNEL_DS);
66904 - result = vfs_write(file, buffer, str - buffer, &pos);
66905 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
66906 set_fs(old_fs);
66907 if (result < 0)
66908 goto out_kfree;
66909 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
66910 int i;
66911
66912 set_fs(KERNEL_DS);
66913 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
66914 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
66915 set_fs(old_fs);
66916 if (result < 0)
66917 goto out;
66918 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
66919 __le16 dnaddr;
66920
66921 set_fs(KERNEL_DS);
66922 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
66923 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
66924 set_fs(old_fs);
66925 if (result < 0)
66926 goto out;
66927 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
66928 le16_to_cpu(dnaddr) & 0x3ff);
66929
66930 set_fs(KERNEL_DS);
66931 - result = vfs_write(file, buf, len, &pos);
66932 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
66933 set_fs(old_fs);
66934 if (result < 0)
66935 goto out;
66936 diff --git a/kernel/sysctl_check.c b/kernel/sysctl_check.c
66937 index 362da65..ab8ef8c 100644
66938 --- a/kernel/sysctl_check.c
66939 +++ b/kernel/sysctl_check.c
66940 @@ -129,6 +129,7 @@ int sysctl_check_table(struct nsproxy *namespaces, struct ctl_table *table)
66941 set_fail(&fail, table, "Directory with extra2");
66942 } else {
66943 if ((table->proc_handler == proc_dostring) ||
66944 + (table->proc_handler == proc_dostring_modpriv) ||
66945 (table->proc_handler == proc_dointvec) ||
66946 (table->proc_handler == proc_dointvec_minmax) ||
66947 (table->proc_handler == proc_dointvec_jiffies) ||
66948 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
66949 index e660464..c8b9e67 100644
66950 --- a/kernel/taskstats.c
66951 +++ b/kernel/taskstats.c
66952 @@ -27,9 +27,12 @@
66953 #include <linux/cgroup.h>
66954 #include <linux/fs.h>
66955 #include <linux/file.h>
66956 +#include <linux/grsecurity.h>
66957 #include <net/genetlink.h>
66958 #include <linux/atomic.h>
66959
66960 +extern int gr_is_taskstats_denied(int pid);
66961 +
66962 /*
66963 * Maximum length of a cpumask that can be specified in
66964 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
66965 @@ -556,6 +559,9 @@ err:
66966
66967 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
66968 {
66969 + if (gr_is_taskstats_denied(current->pid))
66970 + return -EACCES;
66971 +
66972 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
66973 return cmd_attr_register_cpumask(info);
66974 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
66975 diff --git a/kernel/time.c b/kernel/time.c
66976 index 73e416d..cfc6f69 100644
66977 --- a/kernel/time.c
66978 +++ b/kernel/time.c
66979 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
66980 return error;
66981
66982 if (tz) {
66983 + /* we log in do_settimeofday called below, so don't log twice
66984 + */
66985 + if (!tv)
66986 + gr_log_timechange();
66987 +
66988 /* SMP safe, global irq locking makes it work. */
66989 sys_tz = *tz;
66990 update_vsyscall_tz();
66991 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
66992 index 8a46f5d..bbe6f9c 100644
66993 --- a/kernel/time/alarmtimer.c
66994 +++ b/kernel/time/alarmtimer.c
66995 @@ -773,7 +773,7 @@ static int __init alarmtimer_init(void)
66996 struct platform_device *pdev;
66997 int error = 0;
66998 int i;
66999 - struct k_clock alarm_clock = {
67000 + static struct k_clock alarm_clock = {
67001 .clock_getres = alarm_clock_getres,
67002 .clock_get = alarm_clock_get,
67003 .timer_create = alarm_timer_create,
67004 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
67005 index fd4a7b1..fae5c2a 100644
67006 --- a/kernel/time/tick-broadcast.c
67007 +++ b/kernel/time/tick-broadcast.c
67008 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
67009 * then clear the broadcast bit.
67010 */
67011 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
67012 - int cpu = smp_processor_id();
67013 + cpu = smp_processor_id();
67014
67015 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
67016 tick_broadcast_clear_oneshot(cpu);
67017 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
67018 index 2378413..be455fd 100644
67019 --- a/kernel/time/timekeeping.c
67020 +++ b/kernel/time/timekeeping.c
67021 @@ -14,6 +14,7 @@
67022 #include <linux/init.h>
67023 #include <linux/mm.h>
67024 #include <linux/sched.h>
67025 +#include <linux/grsecurity.h>
67026 #include <linux/syscore_ops.h>
67027 #include <linux/clocksource.h>
67028 #include <linux/jiffies.h>
67029 @@ -365,6 +366,8 @@ int do_settimeofday(const struct timespec *tv)
67030 if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
67031 return -EINVAL;
67032
67033 + gr_log_timechange();
67034 +
67035 write_seqlock_irqsave(&xtime_lock, flags);
67036
67037 timekeeping_forward_now();
67038 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
67039 index 3258455..f35227d 100644
67040 --- a/kernel/time/timer_list.c
67041 +++ b/kernel/time/timer_list.c
67042 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
67043
67044 static void print_name_offset(struct seq_file *m, void *sym)
67045 {
67046 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67047 + SEQ_printf(m, "<%p>", NULL);
67048 +#else
67049 char symname[KSYM_NAME_LEN];
67050
67051 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
67052 SEQ_printf(m, "<%pK>", sym);
67053 else
67054 SEQ_printf(m, "%s", symname);
67055 +#endif
67056 }
67057
67058 static void
67059 @@ -112,7 +116,11 @@ next_one:
67060 static void
67061 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
67062 {
67063 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67064 + SEQ_printf(m, " .base: %p\n", NULL);
67065 +#else
67066 SEQ_printf(m, " .base: %pK\n", base);
67067 +#endif
67068 SEQ_printf(m, " .index: %d\n",
67069 base->index);
67070 SEQ_printf(m, " .resolution: %Lu nsecs\n",
67071 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
67072 {
67073 struct proc_dir_entry *pe;
67074
67075 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67076 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
67077 +#else
67078 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
67079 +#endif
67080 if (!pe)
67081 return -ENOMEM;
67082 return 0;
67083 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
67084 index 0b537f2..9e71eca 100644
67085 --- a/kernel/time/timer_stats.c
67086 +++ b/kernel/time/timer_stats.c
67087 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
67088 static unsigned long nr_entries;
67089 static struct entry entries[MAX_ENTRIES];
67090
67091 -static atomic_t overflow_count;
67092 +static atomic_unchecked_t overflow_count;
67093
67094 /*
67095 * The entries are in a hash-table, for fast lookup:
67096 @@ -140,7 +140,7 @@ static void reset_entries(void)
67097 nr_entries = 0;
67098 memset(entries, 0, sizeof(entries));
67099 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
67100 - atomic_set(&overflow_count, 0);
67101 + atomic_set_unchecked(&overflow_count, 0);
67102 }
67103
67104 static struct entry *alloc_entry(void)
67105 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
67106 if (likely(entry))
67107 entry->count++;
67108 else
67109 - atomic_inc(&overflow_count);
67110 + atomic_inc_unchecked(&overflow_count);
67111
67112 out_unlock:
67113 raw_spin_unlock_irqrestore(lock, flags);
67114 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
67115
67116 static void print_name_offset(struct seq_file *m, unsigned long addr)
67117 {
67118 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67119 + seq_printf(m, "<%p>", NULL);
67120 +#else
67121 char symname[KSYM_NAME_LEN];
67122
67123 if (lookup_symbol_name(addr, symname) < 0)
67124 seq_printf(m, "<%p>", (void *)addr);
67125 else
67126 seq_printf(m, "%s", symname);
67127 +#endif
67128 }
67129
67130 static int tstats_show(struct seq_file *m, void *v)
67131 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
67132
67133 seq_puts(m, "Timer Stats Version: v0.2\n");
67134 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
67135 - if (atomic_read(&overflow_count))
67136 + if (atomic_read_unchecked(&overflow_count))
67137 seq_printf(m, "Overflow: %d entries\n",
67138 - atomic_read(&overflow_count));
67139 + atomic_read_unchecked(&overflow_count));
67140
67141 for (i = 0; i < nr_entries; i++) {
67142 entry = entries + i;
67143 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
67144 {
67145 struct proc_dir_entry *pe;
67146
67147 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
67148 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
67149 +#else
67150 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
67151 +#endif
67152 if (!pe)
67153 return -ENOMEM;
67154 return 0;
67155 diff --git a/kernel/timer.c b/kernel/timer.c
67156 index 9c3c62b..441690e 100644
67157 --- a/kernel/timer.c
67158 +++ b/kernel/timer.c
67159 @@ -1304,7 +1304,7 @@ void update_process_times(int user_tick)
67160 /*
67161 * This function runs timers and the timer-tq in bottom half context.
67162 */
67163 -static void run_timer_softirq(struct softirq_action *h)
67164 +static void run_timer_softirq(void)
67165 {
67166 struct tvec_base *base = __this_cpu_read(tvec_bases);
67167
67168 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
67169 index 16fc34a..efd8bb8 100644
67170 --- a/kernel/trace/blktrace.c
67171 +++ b/kernel/trace/blktrace.c
67172 @@ -324,7 +324,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
67173 struct blk_trace *bt = filp->private_data;
67174 char buf[16];
67175
67176 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
67177 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
67178
67179 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
67180 }
67181 @@ -389,7 +389,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
67182 return 1;
67183
67184 bt = buf->chan->private_data;
67185 - atomic_inc(&bt->dropped);
67186 + atomic_inc_unchecked(&bt->dropped);
67187 return 0;
67188 }
67189
67190 @@ -490,7 +490,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
67191
67192 bt->dir = dir;
67193 bt->dev = dev;
67194 - atomic_set(&bt->dropped, 0);
67195 + atomic_set_unchecked(&bt->dropped, 0);
67196
67197 ret = -EIO;
67198 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
67199 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
67200 index 25b4f4d..6f4772d 100644
67201 --- a/kernel/trace/ftrace.c
67202 +++ b/kernel/trace/ftrace.c
67203 @@ -1587,12 +1587,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
67204 if (unlikely(ftrace_disabled))
67205 return 0;
67206
67207 + ret = ftrace_arch_code_modify_prepare();
67208 + FTRACE_WARN_ON(ret);
67209 + if (ret)
67210 + return 0;
67211 +
67212 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
67213 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
67214 if (ret) {
67215 ftrace_bug(ret, ip);
67216 - return 0;
67217 }
67218 - return 1;
67219 + return ret ? 0 : 1;
67220 }
67221
67222 /*
67223 @@ -2608,7 +2613,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
67224
67225 int
67226 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
67227 - void *data)
67228 + void *data)
67229 {
67230 struct ftrace_func_probe *entry;
67231 struct ftrace_page *pg;
67232 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
67233 index f2bd275..adaf3a2 100644
67234 --- a/kernel/trace/trace.c
67235 +++ b/kernel/trace/trace.c
67236 @@ -4201,10 +4201,9 @@ static const struct file_operations tracing_dyn_info_fops = {
67237 };
67238 #endif
67239
67240 -static struct dentry *d_tracer;
67241 -
67242 struct dentry *tracing_init_dentry(void)
67243 {
67244 + static struct dentry *d_tracer;
67245 static int once;
67246
67247 if (d_tracer)
67248 @@ -4224,10 +4223,9 @@ struct dentry *tracing_init_dentry(void)
67249 return d_tracer;
67250 }
67251
67252 -static struct dentry *d_percpu;
67253 -
67254 struct dentry *tracing_dentry_percpu(void)
67255 {
67256 + static struct dentry *d_percpu;
67257 static int once;
67258 struct dentry *d_tracer;
67259
67260 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
67261 index c212a7f..7b02394 100644
67262 --- a/kernel/trace/trace_events.c
67263 +++ b/kernel/trace/trace_events.c
67264 @@ -1299,10 +1299,6 @@ static LIST_HEAD(ftrace_module_file_list);
67265 struct ftrace_module_file_ops {
67266 struct list_head list;
67267 struct module *mod;
67268 - struct file_operations id;
67269 - struct file_operations enable;
67270 - struct file_operations format;
67271 - struct file_operations filter;
67272 };
67273
67274 static struct ftrace_module_file_ops *
67275 @@ -1323,17 +1319,12 @@ trace_create_file_ops(struct module *mod)
67276
67277 file_ops->mod = mod;
67278
67279 - file_ops->id = ftrace_event_id_fops;
67280 - file_ops->id.owner = mod;
67281 -
67282 - file_ops->enable = ftrace_enable_fops;
67283 - file_ops->enable.owner = mod;
67284 -
67285 - file_ops->filter = ftrace_event_filter_fops;
67286 - file_ops->filter.owner = mod;
67287 -
67288 - file_ops->format = ftrace_event_format_fops;
67289 - file_ops->format.owner = mod;
67290 + pax_open_kernel();
67291 + *(void **)&mod->trace_id.owner = mod;
67292 + *(void **)&mod->trace_enable.owner = mod;
67293 + *(void **)&mod->trace_filter.owner = mod;
67294 + *(void **)&mod->trace_format.owner = mod;
67295 + pax_close_kernel();
67296
67297 list_add(&file_ops->list, &ftrace_module_file_list);
67298
67299 @@ -1357,8 +1348,8 @@ static void trace_module_add_events(struct module *mod)
67300
67301 for_each_event(call, start, end) {
67302 __trace_add_event_call(*call, mod,
67303 - &file_ops->id, &file_ops->enable,
67304 - &file_ops->filter, &file_ops->format);
67305 + &mod->trace_id, &mod->trace_enable,
67306 + &mod->trace_filter, &mod->trace_format);
67307 }
67308 }
67309
67310 diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
67311 index 00d527c..7c5b1a3 100644
67312 --- a/kernel/trace/trace_kprobe.c
67313 +++ b/kernel/trace/trace_kprobe.c
67314 @@ -217,7 +217,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67315 long ret;
67316 int maxlen = get_rloc_len(*(u32 *)dest);
67317 u8 *dst = get_rloc_data(dest);
67318 - u8 *src = addr;
67319 + const u8 __user *src = (const u8 __force_user *)addr;
67320 mm_segment_t old_fs = get_fs();
67321 if (!maxlen)
67322 return;
67323 @@ -229,7 +229,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67324 pagefault_disable();
67325 do
67326 ret = __copy_from_user_inatomic(dst++, src++, 1);
67327 - while (dst[-1] && ret == 0 && src - (u8 *)addr < maxlen);
67328 + while (dst[-1] && ret == 0 && src - (const u8 __force_user *)addr < maxlen);
67329 dst[-1] = '\0';
67330 pagefault_enable();
67331 set_fs(old_fs);
67332 @@ -238,7 +238,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string)(struct pt_regs *regs,
67333 ((u8 *)get_rloc_data(dest))[0] = '\0';
67334 *(u32 *)dest = make_data_rloc(0, get_rloc_offs(*(u32 *)dest));
67335 } else
67336 - *(u32 *)dest = make_data_rloc(src - (u8 *)addr,
67337 + *(u32 *)dest = make_data_rloc(src - (const u8 __force_user *)addr,
67338 get_rloc_offs(*(u32 *)dest));
67339 }
67340 /* Return the length of string -- including null terminal byte */
67341 @@ -252,7 +252,7 @@ static __kprobes void FETCH_FUNC_NAME(memory, string_size)(struct pt_regs *regs,
67342 set_fs(KERNEL_DS);
67343 pagefault_disable();
67344 do {
67345 - ret = __copy_from_user_inatomic(&c, (u8 *)addr + len, 1);
67346 + ret = __copy_from_user_inatomic(&c, (const u8 __force_user *)addr + len, 1);
67347 len++;
67348 } while (c && ret == 0 && len < MAX_STRING_SIZE);
67349 pagefault_enable();
67350 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
67351 index fd3c8aa..5f324a6 100644
67352 --- a/kernel/trace/trace_mmiotrace.c
67353 +++ b/kernel/trace/trace_mmiotrace.c
67354 @@ -24,7 +24,7 @@ struct header_iter {
67355 static struct trace_array *mmio_trace_array;
67356 static bool overrun_detected;
67357 static unsigned long prev_overruns;
67358 -static atomic_t dropped_count;
67359 +static atomic_unchecked_t dropped_count;
67360
67361 static void mmio_reset_data(struct trace_array *tr)
67362 {
67363 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
67364
67365 static unsigned long count_overruns(struct trace_iterator *iter)
67366 {
67367 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
67368 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
67369 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
67370
67371 if (over > prev_overruns)
67372 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
67373 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
67374 sizeof(*entry), 0, pc);
67375 if (!event) {
67376 - atomic_inc(&dropped_count);
67377 + atomic_inc_unchecked(&dropped_count);
67378 return;
67379 }
67380 entry = ring_buffer_event_data(event);
67381 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
67382 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
67383 sizeof(*entry), 0, pc);
67384 if (!event) {
67385 - atomic_inc(&dropped_count);
67386 + atomic_inc_unchecked(&dropped_count);
67387 return;
67388 }
67389 entry = ring_buffer_event_data(event);
67390 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
67391 index 5199930..26c73a0 100644
67392 --- a/kernel/trace/trace_output.c
67393 +++ b/kernel/trace/trace_output.c
67394 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, struct path *path)
67395
67396 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
67397 if (!IS_ERR(p)) {
67398 - p = mangle_path(s->buffer + s->len, p, "\n");
67399 + p = mangle_path(s->buffer + s->len, p, "\n\\");
67400 if (p) {
67401 s->len = p - s->buffer;
67402 return 1;
67403 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
67404 index 77575b3..6e623d1 100644
67405 --- a/kernel/trace/trace_stack.c
67406 +++ b/kernel/trace/trace_stack.c
67407 @@ -50,7 +50,7 @@ static inline void check_stack(void)
67408 return;
67409
67410 /* we do not handle interrupt stacks yet */
67411 - if (!object_is_on_stack(&this_size))
67412 + if (!object_starts_on_stack(&this_size))
67413 return;
67414
67415 local_irq_save(flags);
67416 diff --git a/kernel/trace/trace_workqueue.c b/kernel/trace/trace_workqueue.c
67417 index 209b379..7f76423 100644
67418 --- a/kernel/trace/trace_workqueue.c
67419 +++ b/kernel/trace/trace_workqueue.c
67420 @@ -22,7 +22,7 @@ struct cpu_workqueue_stats {
67421 int cpu;
67422 pid_t pid;
67423 /* Can be inserted from interrupt or user context, need to be atomic */
67424 - atomic_t inserted;
67425 + atomic_unchecked_t inserted;
67426 /*
67427 * Don't need to be atomic, works are serialized in a single workqueue thread
67428 * on a single CPU.
67429 @@ -60,7 +60,7 @@ probe_workqueue_insertion(void *ignore,
67430 spin_lock_irqsave(&workqueue_cpu_stat(cpu)->lock, flags);
67431 list_for_each_entry(node, &workqueue_cpu_stat(cpu)->list, list) {
67432 if (node->pid == wq_thread->pid) {
67433 - atomic_inc(&node->inserted);
67434 + atomic_inc_unchecked(&node->inserted);
67435 goto found;
67436 }
67437 }
67438 @@ -210,7 +210,7 @@ static int workqueue_stat_show(struct seq_file *s, void *p)
67439 tsk = get_pid_task(pid, PIDTYPE_PID);
67440 if (tsk) {
67441 seq_printf(s, "%3d %6d %6u %s\n", cws->cpu,
67442 - atomic_read(&cws->inserted), cws->executed,
67443 + atomic_read_unchecked(&cws->inserted), cws->executed,
67444 tsk->comm);
67445 put_task_struct(tsk);
67446 }
67447 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
67448 index 82928f5..92da771 100644
67449 --- a/lib/Kconfig.debug
67450 +++ b/lib/Kconfig.debug
67451 @@ -1103,6 +1103,7 @@ config LATENCYTOP
67452 depends on DEBUG_KERNEL
67453 depends on STACKTRACE_SUPPORT
67454 depends on PROC_FS
67455 + depends on !GRKERNSEC_HIDESYM
67456 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
67457 select KALLSYMS
67458 select KALLSYMS_ALL
67459 diff --git a/lib/bitmap.c b/lib/bitmap.c
67460 index 0d4a127..33a06c7 100644
67461 --- a/lib/bitmap.c
67462 +++ b/lib/bitmap.c
67463 @@ -419,7 +419,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
67464 {
67465 int c, old_c, totaldigits, ndigits, nchunks, nbits;
67466 u32 chunk;
67467 - const char __user __force *ubuf = (const char __user __force *)buf;
67468 + const char __user *ubuf = (const char __force_user *)buf;
67469
67470 bitmap_zero(maskp, nmaskbits);
67471
67472 @@ -504,7 +504,7 @@ int bitmap_parse_user(const char __user *ubuf,
67473 {
67474 if (!access_ok(VERIFY_READ, ubuf, ulen))
67475 return -EFAULT;
67476 - return __bitmap_parse((const char __force *)ubuf,
67477 + return __bitmap_parse((const char __force_kernel *)ubuf,
67478 ulen, 1, maskp, nmaskbits);
67479
67480 }
67481 @@ -596,7 +596,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
67482 {
67483 unsigned a, b;
67484 int c, old_c, totaldigits;
67485 - const char __user __force *ubuf = (const char __user __force *)buf;
67486 + const char __user *ubuf = (const char __force_user *)buf;
67487 int exp_digit, in_range;
67488
67489 totaldigits = c = 0;
67490 @@ -696,7 +696,7 @@ int bitmap_parselist_user(const char __user *ubuf,
67491 {
67492 if (!access_ok(VERIFY_READ, ubuf, ulen))
67493 return -EFAULT;
67494 - return __bitmap_parselist((const char __force *)ubuf,
67495 + return __bitmap_parselist((const char __force_kernel *)ubuf,
67496 ulen, 1, maskp, nmaskbits);
67497 }
67498 EXPORT_SYMBOL(bitmap_parselist_user);
67499 diff --git a/lib/bug.c b/lib/bug.c
67500 index 1955209..cbbb2ad 100644
67501 --- a/lib/bug.c
67502 +++ b/lib/bug.c
67503 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
67504 return BUG_TRAP_TYPE_NONE;
67505
67506 bug = find_bug(bugaddr);
67507 + if (!bug)
67508 + return BUG_TRAP_TYPE_NONE;
67509
67510 file = NULL;
67511 line = 0;
67512 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
67513 index a78b7c6..2c73084 100644
67514 --- a/lib/debugobjects.c
67515 +++ b/lib/debugobjects.c
67516 @@ -284,7 +284,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
67517 if (limit > 4)
67518 return;
67519
67520 - is_on_stack = object_is_on_stack(addr);
67521 + is_on_stack = object_starts_on_stack(addr);
67522 if (is_on_stack == onstack)
67523 return;
67524
67525 diff --git a/lib/devres.c b/lib/devres.c
67526 index 7c0e953..f642b5c 100644
67527 --- a/lib/devres.c
67528 +++ b/lib/devres.c
67529 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
67530 void devm_iounmap(struct device *dev, void __iomem *addr)
67531 {
67532 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
67533 - (void *)addr));
67534 + (void __force *)addr));
67535 iounmap(addr);
67536 }
67537 EXPORT_SYMBOL(devm_iounmap);
67538 @@ -141,7 +141,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
67539 {
67540 ioport_unmap(addr);
67541 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
67542 - devm_ioport_map_match, (void *)addr));
67543 + devm_ioport_map_match, (void __force *)addr));
67544 }
67545 EXPORT_SYMBOL(devm_ioport_unmap);
67546
67547 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
67548 index fea790a..ebb0e82 100644
67549 --- a/lib/dma-debug.c
67550 +++ b/lib/dma-debug.c
67551 @@ -925,7 +925,7 @@ out:
67552
67553 static void check_for_stack(struct device *dev, void *addr)
67554 {
67555 - if (object_is_on_stack(addr))
67556 + if (object_starts_on_stack(addr))
67557 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
67558 "stack [addr=%p]\n", addr);
67559 }
67560 diff --git a/lib/extable.c b/lib/extable.c
67561 index 4cac81e..63e9b8f 100644
67562 --- a/lib/extable.c
67563 +++ b/lib/extable.c
67564 @@ -13,6 +13,7 @@
67565 #include <linux/init.h>
67566 #include <linux/sort.h>
67567 #include <asm/uaccess.h>
67568 +#include <asm/pgtable.h>
67569
67570 #ifndef ARCH_HAS_SORT_EXTABLE
67571 /*
67572 @@ -36,8 +37,10 @@ static int cmp_ex(const void *a, const void *b)
67573 void sort_extable(struct exception_table_entry *start,
67574 struct exception_table_entry *finish)
67575 {
67576 + pax_open_kernel();
67577 sort(start, finish - start, sizeof(struct exception_table_entry),
67578 cmp_ex, NULL);
67579 + pax_close_kernel();
67580 }
67581
67582 #ifdef CONFIG_MODULES
67583 diff --git a/lib/inflate.c b/lib/inflate.c
67584 index 013a761..c28f3fc 100644
67585 --- a/lib/inflate.c
67586 +++ b/lib/inflate.c
67587 @@ -269,7 +269,7 @@ static void free(void *where)
67588 malloc_ptr = free_mem_ptr;
67589 }
67590 #else
67591 -#define malloc(a) kmalloc(a, GFP_KERNEL)
67592 +#define malloc(a) kmalloc((a), GFP_KERNEL)
67593 #define free(a) kfree(a)
67594 #endif
67595
67596 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
67597 index bd2bea9..6b3c95e 100644
67598 --- a/lib/is_single_threaded.c
67599 +++ b/lib/is_single_threaded.c
67600 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
67601 struct task_struct *p, *t;
67602 bool ret;
67603
67604 + if (!mm)
67605 + return true;
67606 +
67607 if (atomic_read(&task->signal->live) != 1)
67608 return false;
67609
67610 diff --git a/lib/kref.c b/lib/kref.c
67611 index 3efb882..8492f4c 100644
67612 --- a/lib/kref.c
67613 +++ b/lib/kref.c
67614 @@ -52,7 +52,7 @@ void kref_get(struct kref *kref)
67615 */
67616 int kref_put(struct kref *kref, void (*release)(struct kref *kref))
67617 {
67618 - WARN_ON(release == NULL);
67619 + BUG_ON(release == NULL);
67620 WARN_ON(release == (void (*)(struct kref *))kfree);
67621
67622 if (atomic_dec_and_test(&kref->refcount)) {
67623 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
67624 index d9df745..e73c2fe 100644
67625 --- a/lib/radix-tree.c
67626 +++ b/lib/radix-tree.c
67627 @@ -80,7 +80,7 @@ struct radix_tree_preload {
67628 int nr;
67629 struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
67630 };
67631 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
67632 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
67633
67634 static inline void *ptr_to_indirect(void *ptr)
67635 {
67636 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
67637 index 993599e..84dc70e 100644
67638 --- a/lib/vsprintf.c
67639 +++ b/lib/vsprintf.c
67640 @@ -16,6 +16,9 @@
67641 * - scnprintf and vscnprintf
67642 */
67643
67644 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67645 +#define __INCLUDED_BY_HIDESYM 1
67646 +#endif
67647 #include <stdarg.h>
67648 #include <linux/module.h>
67649 #include <linux/types.h>
67650 @@ -413,7 +416,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
67651 char sym[KSYM_SYMBOL_LEN];
67652 if (ext == 'B')
67653 sprint_backtrace(sym, value);
67654 - else if (ext != 'f' && ext != 's')
67655 + else if (ext != 'f' && ext != 's' && ext != 'a')
67656 sprint_symbol(sym, value);
67657 else
67658 kallsyms_lookup(value, NULL, NULL, NULL, sym);
67659 @@ -777,7 +780,11 @@ char *uuid_string(char *buf, char *end, const u8 *addr,
67660 return string(buf, end, uuid, spec);
67661 }
67662
67663 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67664 +int kptr_restrict __read_mostly = 2;
67665 +#else
67666 int kptr_restrict __read_mostly;
67667 +#endif
67668
67669 /*
67670 * Show a '%p' thing. A kernel extension is that the '%p' is followed
67671 @@ -791,6 +798,8 @@ int kptr_restrict __read_mostly;
67672 * - 'S' For symbolic direct pointers with offset
67673 * - 's' For symbolic direct pointers without offset
67674 * - 'B' For backtraced symbolic direct pointers with offset
67675 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
67676 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
67677 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
67678 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
67679 * - 'M' For a 6-byte MAC address, it prints the address in the
67680 @@ -835,12 +844,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67681 {
67682 if (!ptr && *fmt != 'K') {
67683 /*
67684 - * Print (null) with the same width as a pointer so it makes
67685 + * Print (nil) with the same width as a pointer so it makes
67686 * tabular output look nice.
67687 */
67688 if (spec.field_width == -1)
67689 spec.field_width = 2 * sizeof(void *);
67690 - return string(buf, end, "(null)", spec);
67691 + return string(buf, end, "(nil)", spec);
67692 }
67693
67694 switch (*fmt) {
67695 @@ -850,6 +859,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
67696 /* Fallthrough */
67697 case 'S':
67698 case 's':
67699 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67700 + break;
67701 +#else
67702 + return symbol_string(buf, end, ptr, spec, *fmt);
67703 +#endif
67704 + case 'A':
67705 + case 'a':
67706 case 'B':
67707 return symbol_string(buf, end, ptr, spec, *fmt);
67708 case 'R':
67709 @@ -1608,11 +1624,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
67710 typeof(type) value; \
67711 if (sizeof(type) == 8) { \
67712 args = PTR_ALIGN(args, sizeof(u32)); \
67713 - *(u32 *)&value = *(u32 *)args; \
67714 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
67715 + *(u32 *)&value = *(const u32 *)args; \
67716 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
67717 } else { \
67718 args = PTR_ALIGN(args, sizeof(type)); \
67719 - value = *(typeof(type) *)args; \
67720 + value = *(const typeof(type) *)args; \
67721 } \
67722 args += sizeof(type); \
67723 value; \
67724 @@ -1675,7 +1691,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
67725 case FORMAT_TYPE_STR: {
67726 const char *str_arg = args;
67727 args += strlen(str_arg) + 1;
67728 - str = string(str, end, (char *)str_arg, spec);
67729 + str = string(str, end, str_arg, spec);
67730 break;
67731 }
67732
67733 diff --git a/localversion-grsec b/localversion-grsec
67734 new file mode 100644
67735 index 0000000..7cd6065
67736 --- /dev/null
67737 +++ b/localversion-grsec
67738 @@ -0,0 +1 @@
67739 +-grsec
67740 diff --git a/mm/Kconfig b/mm/Kconfig
67741 index 011b110..b492af2 100644
67742 --- a/mm/Kconfig
67743 +++ b/mm/Kconfig
67744 @@ -241,10 +241,10 @@ config KSM
67745 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
67746
67747 config DEFAULT_MMAP_MIN_ADDR
67748 - int "Low address space to protect from user allocation"
67749 + int "Low address space to protect from user allocation"
67750 depends on MMU
67751 - default 4096
67752 - help
67753 + default 65536
67754 + help
67755 This is the portion of low virtual memory which should be protected
67756 from userspace allocation. Keeping a user from writing to low pages
67757 can help reduce the impact of kernel NULL pointer bugs.
67758 diff --git a/mm/filemap.c b/mm/filemap.c
67759 index 03c5b0e..a01e793 100644
67760 --- a/mm/filemap.c
67761 +++ b/mm/filemap.c
67762 @@ -1770,7 +1770,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
67763 struct address_space *mapping = file->f_mapping;
67764
67765 if (!mapping->a_ops->readpage)
67766 - return -ENOEXEC;
67767 + return -ENODEV;
67768 file_accessed(file);
67769 vma->vm_ops = &generic_file_vm_ops;
67770 vma->vm_flags |= VM_CAN_NONLINEAR;
67771 @@ -2176,6 +2176,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
67772 *pos = i_size_read(inode);
67773
67774 if (limit != RLIM_INFINITY) {
67775 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
67776 if (*pos >= limit) {
67777 send_sig(SIGXFSZ, current, 0);
67778 return -EFBIG;
67779 diff --git a/mm/fremap.c b/mm/fremap.c
67780 index 9ed4fd4..c42648d 100644
67781 --- a/mm/fremap.c
67782 +++ b/mm/fremap.c
67783 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
67784 retry:
67785 vma = find_vma(mm, start);
67786
67787 +#ifdef CONFIG_PAX_SEGMEXEC
67788 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
67789 + goto out;
67790 +#endif
67791 +
67792 /*
67793 * Make sure the vma is shared, that it supports prefaulting,
67794 * and that the remapped range is valid and fully within
67795 diff --git a/mm/highmem.c b/mm/highmem.c
67796 index 57d82c6..e9e0552 100644
67797 --- a/mm/highmem.c
67798 +++ b/mm/highmem.c
67799 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
67800 * So no dangers, even with speculative execution.
67801 */
67802 page = pte_page(pkmap_page_table[i]);
67803 + pax_open_kernel();
67804 pte_clear(&init_mm, (unsigned long)page_address(page),
67805 &pkmap_page_table[i]);
67806 -
67807 + pax_close_kernel();
67808 set_page_address(page, NULL);
67809 need_flush = 1;
67810 }
67811 @@ -186,9 +187,11 @@ start:
67812 }
67813 }
67814 vaddr = PKMAP_ADDR(last_pkmap_nr);
67815 +
67816 + pax_open_kernel();
67817 set_pte_at(&init_mm, vaddr,
67818 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
67819 -
67820 + pax_close_kernel();
67821 pkmap_count[last_pkmap_nr] = 1;
67822 set_page_address(page, (void *)vaddr);
67823
67824 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
67825 index 33141f5..e56bef9 100644
67826 --- a/mm/huge_memory.c
67827 +++ b/mm/huge_memory.c
67828 @@ -703,7 +703,7 @@ out:
67829 * run pte_offset_map on the pmd, if an huge pmd could
67830 * materialize from under us from a different thread.
67831 */
67832 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
67833 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
67834 return VM_FAULT_OOM;
67835 /* if an huge pmd materialized from under us just retry later */
67836 if (unlikely(pmd_trans_huge(*pmd)))
67837 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
67838 index 2316840..b418671 100644
67839 --- a/mm/hugetlb.c
67840 +++ b/mm/hugetlb.c
67841 @@ -2347,6 +2347,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
67842 return 1;
67843 }
67844
67845 +#ifdef CONFIG_PAX_SEGMEXEC
67846 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
67847 +{
67848 + struct mm_struct *mm = vma->vm_mm;
67849 + struct vm_area_struct *vma_m;
67850 + unsigned long address_m;
67851 + pte_t *ptep_m;
67852 +
67853 + vma_m = pax_find_mirror_vma(vma);
67854 + if (!vma_m)
67855 + return;
67856 +
67857 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
67858 + address_m = address + SEGMEXEC_TASK_SIZE;
67859 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
67860 + get_page(page_m);
67861 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
67862 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
67863 +}
67864 +#endif
67865 +
67866 /*
67867 * Hugetlb_cow() should be called with page lock of the original hugepage held.
67868 */
67869 @@ -2450,6 +2471,11 @@ retry_avoidcopy:
67870 make_huge_pte(vma, new_page, 1));
67871 page_remove_rmap(old_page);
67872 hugepage_add_new_anon_rmap(new_page, vma, address);
67873 +
67874 +#ifdef CONFIG_PAX_SEGMEXEC
67875 + pax_mirror_huge_pte(vma, address, new_page);
67876 +#endif
67877 +
67878 /* Make the old page be freed below */
67879 new_page = old_page;
67880 mmu_notifier_invalidate_range_end(mm,
67881 @@ -2601,6 +2627,10 @@ retry:
67882 && (vma->vm_flags & VM_SHARED)));
67883 set_huge_pte_at(mm, address, ptep, new_pte);
67884
67885 +#ifdef CONFIG_PAX_SEGMEXEC
67886 + pax_mirror_huge_pte(vma, address, page);
67887 +#endif
67888 +
67889 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
67890 /* Optimization, do the COW without a second fault */
67891 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
67892 @@ -2630,6 +2660,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
67893 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
67894 struct hstate *h = hstate_vma(vma);
67895
67896 +#ifdef CONFIG_PAX_SEGMEXEC
67897 + struct vm_area_struct *vma_m;
67898 +#endif
67899 +
67900 ptep = huge_pte_offset(mm, address);
67901 if (ptep) {
67902 entry = huge_ptep_get(ptep);
67903 @@ -2641,6 +2675,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
67904 VM_FAULT_SET_HINDEX(h - hstates);
67905 }
67906
67907 +#ifdef CONFIG_PAX_SEGMEXEC
67908 + vma_m = pax_find_mirror_vma(vma);
67909 + if (vma_m) {
67910 + unsigned long address_m;
67911 +
67912 + if (vma->vm_start > vma_m->vm_start) {
67913 + address_m = address;
67914 + address -= SEGMEXEC_TASK_SIZE;
67915 + vma = vma_m;
67916 + h = hstate_vma(vma);
67917 + } else
67918 + address_m = address + SEGMEXEC_TASK_SIZE;
67919 +
67920 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
67921 + return VM_FAULT_OOM;
67922 + address_m &= HPAGE_MASK;
67923 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
67924 + }
67925 +#endif
67926 +
67927 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
67928 if (!ptep)
67929 return VM_FAULT_OOM;
67930 diff --git a/mm/internal.h b/mm/internal.h
67931 index 2189af4..f2ca332 100644
67932 --- a/mm/internal.h
67933 +++ b/mm/internal.h
67934 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
67935 * in mm/page_alloc.c
67936 */
67937 extern void __free_pages_bootmem(struct page *page, unsigned int order);
67938 +extern void free_compound_page(struct page *page);
67939 extern void prep_compound_page(struct page *page, unsigned long order);
67940 #ifdef CONFIG_MEMORY_FAILURE
67941 extern bool is_free_buddy_page(struct page *page);
67942 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
67943 index f3b2a00..61da94d 100644
67944 --- a/mm/kmemleak.c
67945 +++ b/mm/kmemleak.c
67946 @@ -357,7 +357,7 @@ static void print_unreferenced(struct seq_file *seq,
67947
67948 for (i = 0; i < object->trace_len; i++) {
67949 void *ptr = (void *)object->trace[i];
67950 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
67951 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
67952 }
67953 }
67954
67955 diff --git a/mm/maccess.c b/mm/maccess.c
67956 index d53adf9..03a24bf 100644
67957 --- a/mm/maccess.c
67958 +++ b/mm/maccess.c
67959 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
67960 set_fs(KERNEL_DS);
67961 pagefault_disable();
67962 ret = __copy_from_user_inatomic(dst,
67963 - (__force const void __user *)src, size);
67964 + (const void __force_user *)src, size);
67965 pagefault_enable();
67966 set_fs(old_fs);
67967
67968 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
67969
67970 set_fs(KERNEL_DS);
67971 pagefault_disable();
67972 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
67973 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
67974 pagefault_enable();
67975 set_fs(old_fs);
67976
67977 diff --git a/mm/madvise.c b/mm/madvise.c
67978 index 74bf193..feb6fd3 100644
67979 --- a/mm/madvise.c
67980 +++ b/mm/madvise.c
67981 @@ -45,6 +45,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
67982 pgoff_t pgoff;
67983 unsigned long new_flags = vma->vm_flags;
67984
67985 +#ifdef CONFIG_PAX_SEGMEXEC
67986 + struct vm_area_struct *vma_m;
67987 +#endif
67988 +
67989 switch (behavior) {
67990 case MADV_NORMAL:
67991 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
67992 @@ -110,6 +114,13 @@ success:
67993 /*
67994 * vm_flags is protected by the mmap_sem held in write mode.
67995 */
67996 +
67997 +#ifdef CONFIG_PAX_SEGMEXEC
67998 + vma_m = pax_find_mirror_vma(vma);
67999 + if (vma_m)
68000 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
68001 +#endif
68002 +
68003 vma->vm_flags = new_flags;
68004
68005 out:
68006 @@ -168,6 +179,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
68007 struct vm_area_struct ** prev,
68008 unsigned long start, unsigned long end)
68009 {
68010 +
68011 +#ifdef CONFIG_PAX_SEGMEXEC
68012 + struct vm_area_struct *vma_m;
68013 +#endif
68014 +
68015 *prev = vma;
68016 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
68017 return -EINVAL;
68018 @@ -180,6 +196,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
68019 zap_page_range(vma, start, end - start, &details);
68020 } else
68021 zap_page_range(vma, start, end - start, NULL);
68022 +
68023 +#ifdef CONFIG_PAX_SEGMEXEC
68024 + vma_m = pax_find_mirror_vma(vma);
68025 + if (vma_m) {
68026 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
68027 + struct zap_details details = {
68028 + .nonlinear_vma = vma_m,
68029 + .last_index = ULONG_MAX,
68030 + };
68031 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
68032 + } else
68033 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
68034 + }
68035 +#endif
68036 +
68037 return 0;
68038 }
68039
68040 @@ -376,6 +407,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
68041 if (end < start)
68042 goto out;
68043
68044 +#ifdef CONFIG_PAX_SEGMEXEC
68045 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
68046 + if (end > SEGMEXEC_TASK_SIZE)
68047 + goto out;
68048 + } else
68049 +#endif
68050 +
68051 + if (end > TASK_SIZE)
68052 + goto out;
68053 +
68054 error = 0;
68055 if (end == start)
68056 goto out;
68057 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
68058 index 06d3479..0778eef 100644
68059 --- a/mm/memory-failure.c
68060 +++ b/mm/memory-failure.c
68061 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
68062
68063 int sysctl_memory_failure_recovery __read_mostly = 1;
68064
68065 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
68066 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
68067
68068 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
68069
68070 @@ -202,7 +202,7 @@ static int kill_proc_ao(struct task_struct *t, unsigned long addr, int trapno,
68071 si.si_signo = SIGBUS;
68072 si.si_errno = 0;
68073 si.si_code = BUS_MCEERR_AO;
68074 - si.si_addr = (void *)addr;
68075 + si.si_addr = (void __user *)addr;
68076 #ifdef __ARCH_SI_TRAPNO
68077 si.si_trapno = trapno;
68078 #endif
68079 @@ -1010,7 +1010,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
68080 }
68081
68082 nr_pages = 1 << compound_trans_order(hpage);
68083 - atomic_long_add(nr_pages, &mce_bad_pages);
68084 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
68085
68086 /*
68087 * We need/can do nothing about count=0 pages.
68088 @@ -1040,7 +1040,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
68089 if (!PageHWPoison(hpage)
68090 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
68091 || (p != hpage && TestSetPageHWPoison(hpage))) {
68092 - atomic_long_sub(nr_pages, &mce_bad_pages);
68093 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
68094 return 0;
68095 }
68096 set_page_hwpoison_huge_page(hpage);
68097 @@ -1098,7 +1098,7 @@ int __memory_failure(unsigned long pfn, int trapno, int flags)
68098 }
68099 if (hwpoison_filter(p)) {
68100 if (TestClearPageHWPoison(p))
68101 - atomic_long_sub(nr_pages, &mce_bad_pages);
68102 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
68103 unlock_page(hpage);
68104 put_page(hpage);
68105 return 0;
68106 @@ -1315,7 +1315,7 @@ int unpoison_memory(unsigned long pfn)
68107 return 0;
68108 }
68109 if (TestClearPageHWPoison(p))
68110 - atomic_long_sub(nr_pages, &mce_bad_pages);
68111 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
68112 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
68113 return 0;
68114 }
68115 @@ -1329,7 +1329,7 @@ int unpoison_memory(unsigned long pfn)
68116 */
68117 if (TestClearPageHWPoison(page)) {
68118 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
68119 - atomic_long_sub(nr_pages, &mce_bad_pages);
68120 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
68121 freeit = 1;
68122 if (PageHuge(page))
68123 clear_page_hwpoison_huge_page(page);
68124 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
68125 }
68126 done:
68127 if (!PageHWPoison(hpage))
68128 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
68129 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
68130 set_page_hwpoison_huge_page(hpage);
68131 dequeue_hwpoisoned_huge_page(hpage);
68132 /* keep elevated page count for bad page */
68133 @@ -1573,7 +1573,7 @@ int soft_offline_page(struct page *page, int flags)
68134 return ret;
68135
68136 done:
68137 - atomic_long_add(1, &mce_bad_pages);
68138 + atomic_long_add_unchecked(1, &mce_bad_pages);
68139 SetPageHWPoison(page);
68140 /* keep elevated page count for bad page */
68141 return ret;
68142 diff --git a/mm/memory.c b/mm/memory.c
68143 index 829d437..3d3926a 100644
68144 --- a/mm/memory.c
68145 +++ b/mm/memory.c
68146 @@ -457,8 +457,12 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
68147 return;
68148
68149 pmd = pmd_offset(pud, start);
68150 +
68151 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
68152 pud_clear(pud);
68153 pmd_free_tlb(tlb, pmd, start);
68154 +#endif
68155 +
68156 }
68157
68158 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
68159 @@ -489,9 +493,12 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
68160 if (end - 1 > ceiling - 1)
68161 return;
68162
68163 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
68164 pud = pud_offset(pgd, start);
68165 pgd_clear(pgd);
68166 pud_free_tlb(tlb, pud, start);
68167 +#endif
68168 +
68169 }
68170
68171 /*
68172 @@ -1566,12 +1573,6 @@ no_page_table:
68173 return page;
68174 }
68175
68176 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
68177 -{
68178 - return stack_guard_page_start(vma, addr) ||
68179 - stack_guard_page_end(vma, addr+PAGE_SIZE);
68180 -}
68181 -
68182 /**
68183 * __get_user_pages() - pin user pages in memory
68184 * @tsk: task_struct of target task
68185 @@ -1644,10 +1645,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68186 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
68187 i = 0;
68188
68189 - do {
68190 + while (nr_pages) {
68191 struct vm_area_struct *vma;
68192
68193 - vma = find_extend_vma(mm, start);
68194 + vma = find_vma(mm, start);
68195 if (!vma && in_gate_area(mm, start)) {
68196 unsigned long pg = start & PAGE_MASK;
68197 pgd_t *pgd;
68198 @@ -1695,7 +1696,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68199 goto next_page;
68200 }
68201
68202 - if (!vma ||
68203 + if (!vma || start < vma->vm_start ||
68204 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
68205 !(vm_flags & vma->vm_flags))
68206 return i ? : -EFAULT;
68207 @@ -1722,11 +1723,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
68208 int ret;
68209 unsigned int fault_flags = 0;
68210
68211 - /* For mlock, just skip the stack guard page. */
68212 - if (foll_flags & FOLL_MLOCK) {
68213 - if (stack_guard_page(vma, start))
68214 - goto next_page;
68215 - }
68216 if (foll_flags & FOLL_WRITE)
68217 fault_flags |= FAULT_FLAG_WRITE;
68218 if (nonblocking)
68219 @@ -1800,7 +1796,7 @@ next_page:
68220 start += PAGE_SIZE;
68221 nr_pages--;
68222 } while (nr_pages && start < vma->vm_end);
68223 - } while (nr_pages);
68224 + }
68225 return i;
68226 }
68227 EXPORT_SYMBOL(__get_user_pages);
68228 @@ -2007,6 +2003,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
68229 page_add_file_rmap(page);
68230 set_pte_at(mm, addr, pte, mk_pte(page, prot));
68231
68232 +#ifdef CONFIG_PAX_SEGMEXEC
68233 + pax_mirror_file_pte(vma, addr, page, ptl);
68234 +#endif
68235 +
68236 retval = 0;
68237 pte_unmap_unlock(pte, ptl);
68238 return retval;
68239 @@ -2041,10 +2041,22 @@ out:
68240 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
68241 struct page *page)
68242 {
68243 +
68244 +#ifdef CONFIG_PAX_SEGMEXEC
68245 + struct vm_area_struct *vma_m;
68246 +#endif
68247 +
68248 if (addr < vma->vm_start || addr >= vma->vm_end)
68249 return -EFAULT;
68250 if (!page_count(page))
68251 return -EINVAL;
68252 +
68253 +#ifdef CONFIG_PAX_SEGMEXEC
68254 + vma_m = pax_find_mirror_vma(vma);
68255 + if (vma_m)
68256 + vma_m->vm_flags |= VM_INSERTPAGE;
68257 +#endif
68258 +
68259 vma->vm_flags |= VM_INSERTPAGE;
68260 return insert_page(vma, addr, page, vma->vm_page_prot);
68261 }
68262 @@ -2130,6 +2142,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
68263 unsigned long pfn)
68264 {
68265 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
68266 + BUG_ON(vma->vm_mirror);
68267
68268 if (addr < vma->vm_start || addr >= vma->vm_end)
68269 return -EFAULT;
68270 @@ -2445,6 +2458,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
68271 copy_user_highpage(dst, src, va, vma);
68272 }
68273
68274 +#ifdef CONFIG_PAX_SEGMEXEC
68275 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
68276 +{
68277 + struct mm_struct *mm = vma->vm_mm;
68278 + spinlock_t *ptl;
68279 + pte_t *pte, entry;
68280 +
68281 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
68282 + entry = *pte;
68283 + if (!pte_present(entry)) {
68284 + if (!pte_none(entry)) {
68285 + BUG_ON(pte_file(entry));
68286 + free_swap_and_cache(pte_to_swp_entry(entry));
68287 + pte_clear_not_present_full(mm, address, pte, 0);
68288 + }
68289 + } else {
68290 + struct page *page;
68291 +
68292 + flush_cache_page(vma, address, pte_pfn(entry));
68293 + entry = ptep_clear_flush(vma, address, pte);
68294 + BUG_ON(pte_dirty(entry));
68295 + page = vm_normal_page(vma, address, entry);
68296 + if (page) {
68297 + update_hiwater_rss(mm);
68298 + if (PageAnon(page))
68299 + dec_mm_counter_fast(mm, MM_ANONPAGES);
68300 + else
68301 + dec_mm_counter_fast(mm, MM_FILEPAGES);
68302 + page_remove_rmap(page);
68303 + page_cache_release(page);
68304 + }
68305 + }
68306 + pte_unmap_unlock(pte, ptl);
68307 +}
68308 +
68309 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
68310 + *
68311 + * the ptl of the lower mapped page is held on entry and is not released on exit
68312 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
68313 + */
68314 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68315 +{
68316 + struct mm_struct *mm = vma->vm_mm;
68317 + unsigned long address_m;
68318 + spinlock_t *ptl_m;
68319 + struct vm_area_struct *vma_m;
68320 + pmd_t *pmd_m;
68321 + pte_t *pte_m, entry_m;
68322 +
68323 + BUG_ON(!page_m || !PageAnon(page_m));
68324 +
68325 + vma_m = pax_find_mirror_vma(vma);
68326 + if (!vma_m)
68327 + return;
68328 +
68329 + BUG_ON(!PageLocked(page_m));
68330 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68331 + address_m = address + SEGMEXEC_TASK_SIZE;
68332 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68333 + pte_m = pte_offset_map(pmd_m, address_m);
68334 + ptl_m = pte_lockptr(mm, pmd_m);
68335 + if (ptl != ptl_m) {
68336 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68337 + if (!pte_none(*pte_m))
68338 + goto out;
68339 + }
68340 +
68341 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68342 + page_cache_get(page_m);
68343 + page_add_anon_rmap(page_m, vma_m, address_m);
68344 + inc_mm_counter_fast(mm, MM_ANONPAGES);
68345 + set_pte_at(mm, address_m, pte_m, entry_m);
68346 + update_mmu_cache(vma_m, address_m, entry_m);
68347 +out:
68348 + if (ptl != ptl_m)
68349 + spin_unlock(ptl_m);
68350 + pte_unmap(pte_m);
68351 + unlock_page(page_m);
68352 +}
68353 +
68354 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
68355 +{
68356 + struct mm_struct *mm = vma->vm_mm;
68357 + unsigned long address_m;
68358 + spinlock_t *ptl_m;
68359 + struct vm_area_struct *vma_m;
68360 + pmd_t *pmd_m;
68361 + pte_t *pte_m, entry_m;
68362 +
68363 + BUG_ON(!page_m || PageAnon(page_m));
68364 +
68365 + vma_m = pax_find_mirror_vma(vma);
68366 + if (!vma_m)
68367 + return;
68368 +
68369 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68370 + address_m = address + SEGMEXEC_TASK_SIZE;
68371 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68372 + pte_m = pte_offset_map(pmd_m, address_m);
68373 + ptl_m = pte_lockptr(mm, pmd_m);
68374 + if (ptl != ptl_m) {
68375 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68376 + if (!pte_none(*pte_m))
68377 + goto out;
68378 + }
68379 +
68380 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
68381 + page_cache_get(page_m);
68382 + page_add_file_rmap(page_m);
68383 + inc_mm_counter_fast(mm, MM_FILEPAGES);
68384 + set_pte_at(mm, address_m, pte_m, entry_m);
68385 + update_mmu_cache(vma_m, address_m, entry_m);
68386 +out:
68387 + if (ptl != ptl_m)
68388 + spin_unlock(ptl_m);
68389 + pte_unmap(pte_m);
68390 +}
68391 +
68392 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
68393 +{
68394 + struct mm_struct *mm = vma->vm_mm;
68395 + unsigned long address_m;
68396 + spinlock_t *ptl_m;
68397 + struct vm_area_struct *vma_m;
68398 + pmd_t *pmd_m;
68399 + pte_t *pte_m, entry_m;
68400 +
68401 + vma_m = pax_find_mirror_vma(vma);
68402 + if (!vma_m)
68403 + return;
68404 +
68405 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
68406 + address_m = address + SEGMEXEC_TASK_SIZE;
68407 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
68408 + pte_m = pte_offset_map(pmd_m, address_m);
68409 + ptl_m = pte_lockptr(mm, pmd_m);
68410 + if (ptl != ptl_m) {
68411 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
68412 + if (!pte_none(*pte_m))
68413 + goto out;
68414 + }
68415 +
68416 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
68417 + set_pte_at(mm, address_m, pte_m, entry_m);
68418 +out:
68419 + if (ptl != ptl_m)
68420 + spin_unlock(ptl_m);
68421 + pte_unmap(pte_m);
68422 +}
68423 +
68424 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
68425 +{
68426 + struct page *page_m;
68427 + pte_t entry;
68428 +
68429 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
68430 + goto out;
68431 +
68432 + entry = *pte;
68433 + page_m = vm_normal_page(vma, address, entry);
68434 + if (!page_m)
68435 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
68436 + else if (PageAnon(page_m)) {
68437 + if (pax_find_mirror_vma(vma)) {
68438 + pte_unmap_unlock(pte, ptl);
68439 + lock_page(page_m);
68440 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
68441 + if (pte_same(entry, *pte))
68442 + pax_mirror_anon_pte(vma, address, page_m, ptl);
68443 + else
68444 + unlock_page(page_m);
68445 + }
68446 + } else
68447 + pax_mirror_file_pte(vma, address, page_m, ptl);
68448 +
68449 +out:
68450 + pte_unmap_unlock(pte, ptl);
68451 +}
68452 +#endif
68453 +
68454 /*
68455 * This routine handles present pages, when users try to write
68456 * to a shared page. It is done by copying the page to a new address
68457 @@ -2656,6 +2849,12 @@ gotten:
68458 */
68459 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68460 if (likely(pte_same(*page_table, orig_pte))) {
68461 +
68462 +#ifdef CONFIG_PAX_SEGMEXEC
68463 + if (pax_find_mirror_vma(vma))
68464 + BUG_ON(!trylock_page(new_page));
68465 +#endif
68466 +
68467 if (old_page) {
68468 if (!PageAnon(old_page)) {
68469 dec_mm_counter_fast(mm, MM_FILEPAGES);
68470 @@ -2707,6 +2906,10 @@ gotten:
68471 page_remove_rmap(old_page);
68472 }
68473
68474 +#ifdef CONFIG_PAX_SEGMEXEC
68475 + pax_mirror_anon_pte(vma, address, new_page, ptl);
68476 +#endif
68477 +
68478 /* Free the old page.. */
68479 new_page = old_page;
68480 ret |= VM_FAULT_WRITE;
68481 @@ -2986,6 +3189,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
68482 swap_free(entry);
68483 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
68484 try_to_free_swap(page);
68485 +
68486 +#ifdef CONFIG_PAX_SEGMEXEC
68487 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
68488 +#endif
68489 +
68490 unlock_page(page);
68491 if (swapcache) {
68492 /*
68493 @@ -3009,6 +3217,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
68494
68495 /* No need to invalidate - it was non-present before */
68496 update_mmu_cache(vma, address, page_table);
68497 +
68498 +#ifdef CONFIG_PAX_SEGMEXEC
68499 + pax_mirror_anon_pte(vma, address, page, ptl);
68500 +#endif
68501 +
68502 unlock:
68503 pte_unmap_unlock(page_table, ptl);
68504 out:
68505 @@ -3028,40 +3241,6 @@ out_release:
68506 }
68507
68508 /*
68509 - * This is like a special single-page "expand_{down|up}wards()",
68510 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
68511 - * doesn't hit another vma.
68512 - */
68513 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
68514 -{
68515 - address &= PAGE_MASK;
68516 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
68517 - struct vm_area_struct *prev = vma->vm_prev;
68518 -
68519 - /*
68520 - * Is there a mapping abutting this one below?
68521 - *
68522 - * That's only ok if it's the same stack mapping
68523 - * that has gotten split..
68524 - */
68525 - if (prev && prev->vm_end == address)
68526 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
68527 -
68528 - expand_downwards(vma, address - PAGE_SIZE);
68529 - }
68530 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
68531 - struct vm_area_struct *next = vma->vm_next;
68532 -
68533 - /* As VM_GROWSDOWN but s/below/above/ */
68534 - if (next && next->vm_start == address + PAGE_SIZE)
68535 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
68536 -
68537 - expand_upwards(vma, address + PAGE_SIZE);
68538 - }
68539 - return 0;
68540 -}
68541 -
68542 -/*
68543 * We enter with non-exclusive mmap_sem (to exclude vma changes,
68544 * but allow concurrent faults), and pte mapped but not yet locked.
68545 * We return with mmap_sem still held, but pte unmapped and unlocked.
68546 @@ -3070,27 +3249,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
68547 unsigned long address, pte_t *page_table, pmd_t *pmd,
68548 unsigned int flags)
68549 {
68550 - struct page *page;
68551 + struct page *page = NULL;
68552 spinlock_t *ptl;
68553 pte_t entry;
68554
68555 - pte_unmap(page_table);
68556 -
68557 - /* Check if we need to add a guard page to the stack */
68558 - if (check_stack_guard_page(vma, address) < 0)
68559 - return VM_FAULT_SIGBUS;
68560 -
68561 - /* Use the zero-page for reads */
68562 if (!(flags & FAULT_FLAG_WRITE)) {
68563 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
68564 vma->vm_page_prot));
68565 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
68566 + ptl = pte_lockptr(mm, pmd);
68567 + spin_lock(ptl);
68568 if (!pte_none(*page_table))
68569 goto unlock;
68570 goto setpte;
68571 }
68572
68573 /* Allocate our own private page. */
68574 + pte_unmap(page_table);
68575 +
68576 if (unlikely(anon_vma_prepare(vma)))
68577 goto oom;
68578 page = alloc_zeroed_user_highpage_movable(vma, address);
68579 @@ -3109,6 +3284,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
68580 if (!pte_none(*page_table))
68581 goto release;
68582
68583 +#ifdef CONFIG_PAX_SEGMEXEC
68584 + if (pax_find_mirror_vma(vma))
68585 + BUG_ON(!trylock_page(page));
68586 +#endif
68587 +
68588 inc_mm_counter_fast(mm, MM_ANONPAGES);
68589 page_add_new_anon_rmap(page, vma, address);
68590 setpte:
68591 @@ -3116,6 +3296,12 @@ setpte:
68592
68593 /* No need to invalidate - it was non-present before */
68594 update_mmu_cache(vma, address, page_table);
68595 +
68596 +#ifdef CONFIG_PAX_SEGMEXEC
68597 + if (page)
68598 + pax_mirror_anon_pte(vma, address, page, ptl);
68599 +#endif
68600 +
68601 unlock:
68602 pte_unmap_unlock(page_table, ptl);
68603 return 0;
68604 @@ -3259,6 +3445,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68605 */
68606 /* Only go through if we didn't race with anybody else... */
68607 if (likely(pte_same(*page_table, orig_pte))) {
68608 +
68609 +#ifdef CONFIG_PAX_SEGMEXEC
68610 + if (anon && pax_find_mirror_vma(vma))
68611 + BUG_ON(!trylock_page(page));
68612 +#endif
68613 +
68614 flush_icache_page(vma, page);
68615 entry = mk_pte(page, vma->vm_page_prot);
68616 if (flags & FAULT_FLAG_WRITE)
68617 @@ -3278,6 +3470,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68618
68619 /* no need to invalidate: a not-present page won't be cached */
68620 update_mmu_cache(vma, address, page_table);
68621 +
68622 +#ifdef CONFIG_PAX_SEGMEXEC
68623 + if (anon)
68624 + pax_mirror_anon_pte(vma, address, page, ptl);
68625 + else
68626 + pax_mirror_file_pte(vma, address, page, ptl);
68627 +#endif
68628 +
68629 } else {
68630 if (cow_page)
68631 mem_cgroup_uncharge_page(cow_page);
68632 @@ -3431,6 +3631,12 @@ int handle_pte_fault(struct mm_struct *mm,
68633 if (flags & FAULT_FLAG_WRITE)
68634 flush_tlb_fix_spurious_fault(vma, address);
68635 }
68636 +
68637 +#ifdef CONFIG_PAX_SEGMEXEC
68638 + pax_mirror_pte(vma, address, pte, pmd, ptl);
68639 + return 0;
68640 +#endif
68641 +
68642 unlock:
68643 pte_unmap_unlock(pte, ptl);
68644 return 0;
68645 @@ -3447,6 +3653,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68646 pmd_t *pmd;
68647 pte_t *pte;
68648
68649 +#ifdef CONFIG_PAX_SEGMEXEC
68650 + struct vm_area_struct *vma_m;
68651 +#endif
68652 +
68653 __set_current_state(TASK_RUNNING);
68654
68655 count_vm_event(PGFAULT);
68656 @@ -3458,6 +3668,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68657 if (unlikely(is_vm_hugetlb_page(vma)))
68658 return hugetlb_fault(mm, vma, address, flags);
68659
68660 +#ifdef CONFIG_PAX_SEGMEXEC
68661 + vma_m = pax_find_mirror_vma(vma);
68662 + if (vma_m) {
68663 + unsigned long address_m;
68664 + pgd_t *pgd_m;
68665 + pud_t *pud_m;
68666 + pmd_t *pmd_m;
68667 +
68668 + if (vma->vm_start > vma_m->vm_start) {
68669 + address_m = address;
68670 + address -= SEGMEXEC_TASK_SIZE;
68671 + vma = vma_m;
68672 + } else
68673 + address_m = address + SEGMEXEC_TASK_SIZE;
68674 +
68675 + pgd_m = pgd_offset(mm, address_m);
68676 + pud_m = pud_alloc(mm, pgd_m, address_m);
68677 + if (!pud_m)
68678 + return VM_FAULT_OOM;
68679 + pmd_m = pmd_alloc(mm, pud_m, address_m);
68680 + if (!pmd_m)
68681 + return VM_FAULT_OOM;
68682 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
68683 + return VM_FAULT_OOM;
68684 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
68685 + }
68686 +#endif
68687 +
68688 pgd = pgd_offset(mm, address);
68689 pud = pud_alloc(mm, pgd, address);
68690 if (!pud)
68691 @@ -3487,7 +3725,7 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
68692 * run pte_offset_map on the pmd, if an huge pmd could
68693 * materialize from under us from a different thread.
68694 */
68695 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
68696 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
68697 return VM_FAULT_OOM;
68698 /* if an huge pmd materialized from under us just retry later */
68699 if (unlikely(pmd_trans_huge(*pmd)))
68700 @@ -3591,7 +3829,7 @@ static int __init gate_vma_init(void)
68701 gate_vma.vm_start = FIXADDR_USER_START;
68702 gate_vma.vm_end = FIXADDR_USER_END;
68703 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
68704 - gate_vma.vm_page_prot = __P101;
68705 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
68706 /*
68707 * Make sure the vDSO gets into every core dump.
68708 * Dumping its contents makes post-mortem fully interpretable later
68709 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
68710 index c3fdbcb..2e8ef90 100644
68711 --- a/mm/mempolicy.c
68712 +++ b/mm/mempolicy.c
68713 @@ -640,6 +640,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
68714 unsigned long vmstart;
68715 unsigned long vmend;
68716
68717 +#ifdef CONFIG_PAX_SEGMEXEC
68718 + struct vm_area_struct *vma_m;
68719 +#endif
68720 +
68721 vma = find_vma_prev(mm, start, &prev);
68722 if (!vma || vma->vm_start > start)
68723 return -EFAULT;
68724 @@ -678,6 +682,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
68725 err = policy_vma(vma, new_pol);
68726 if (err)
68727 goto out;
68728 +
68729 +#ifdef CONFIG_PAX_SEGMEXEC
68730 + vma_m = pax_find_mirror_vma(vma);
68731 + if (vma_m) {
68732 + err = policy_vma(vma_m, new_pol);
68733 + if (err)
68734 + goto out;
68735 + }
68736 +#endif
68737 +
68738 }
68739
68740 out:
68741 @@ -1111,6 +1125,17 @@ static long do_mbind(unsigned long start, unsigned long len,
68742
68743 if (end < start)
68744 return -EINVAL;
68745 +
68746 +#ifdef CONFIG_PAX_SEGMEXEC
68747 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
68748 + if (end > SEGMEXEC_TASK_SIZE)
68749 + return -EINVAL;
68750 + } else
68751 +#endif
68752 +
68753 + if (end > TASK_SIZE)
68754 + return -EINVAL;
68755 +
68756 if (end == start)
68757 return 0;
68758
68759 @@ -1329,6 +1354,14 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
68760 if (!mm)
68761 goto out;
68762
68763 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68764 + if (mm != current->mm &&
68765 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68766 + err = -EPERM;
68767 + goto out;
68768 + }
68769 +#endif
68770 +
68771 /*
68772 * Check if this process has the right to modify the specified
68773 * process. The right exists if the process has administrative
68774 @@ -1338,8 +1371,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
68775 rcu_read_lock();
68776 tcred = __task_cred(task);
68777 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68778 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
68779 - !capable(CAP_SYS_NICE)) {
68780 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68781 rcu_read_unlock();
68782 err = -EPERM;
68783 goto out;
68784 diff --git a/mm/migrate.c b/mm/migrate.c
68785 index 177aca4..ab3a744 100644
68786 --- a/mm/migrate.c
68787 +++ b/mm/migrate.c
68788 @@ -1313,6 +1313,14 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
68789 if (!mm)
68790 return -EINVAL;
68791
68792 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
68793 + if (mm != current->mm &&
68794 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
68795 + err = -EPERM;
68796 + goto out;
68797 + }
68798 +#endif
68799 +
68800 /*
68801 * Check if this process has the right to modify the specified
68802 * process. The right exists if the process has administrative
68803 @@ -1322,8 +1330,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
68804 rcu_read_lock();
68805 tcred = __task_cred(task);
68806 if (cred->euid != tcred->suid && cred->euid != tcred->uid &&
68807 - cred->uid != tcred->suid && cred->uid != tcred->uid &&
68808 - !capable(CAP_SYS_NICE)) {
68809 + cred->uid != tcred->suid && !capable(CAP_SYS_NICE)) {
68810 rcu_read_unlock();
68811 err = -EPERM;
68812 goto out;
68813 diff --git a/mm/mlock.c b/mm/mlock.c
68814 index 4f4f53b..9511904 100644
68815 --- a/mm/mlock.c
68816 +++ b/mm/mlock.c
68817 @@ -13,6 +13,7 @@
68818 #include <linux/pagemap.h>
68819 #include <linux/mempolicy.h>
68820 #include <linux/syscalls.h>
68821 +#include <linux/security.h>
68822 #include <linux/sched.h>
68823 #include <linux/export.h>
68824 #include <linux/rmap.h>
68825 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
68826 return -EINVAL;
68827 if (end == start)
68828 return 0;
68829 + if (end > TASK_SIZE)
68830 + return -EINVAL;
68831 +
68832 vma = find_vma_prev(current->mm, start, &prev);
68833 if (!vma || vma->vm_start > start)
68834 return -ENOMEM;
68835 @@ -395,6 +399,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
68836 for (nstart = start ; ; ) {
68837 vm_flags_t newflags;
68838
68839 +#ifdef CONFIG_PAX_SEGMEXEC
68840 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68841 + break;
68842 +#endif
68843 +
68844 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
68845
68846 newflags = vma->vm_flags | VM_LOCKED;
68847 @@ -500,6 +509,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
68848 lock_limit >>= PAGE_SHIFT;
68849
68850 /* check against resource limits */
68851 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
68852 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
68853 error = do_mlock(start, len, 1);
68854 up_write(&current->mm->mmap_sem);
68855 @@ -523,17 +533,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
68856 static int do_mlockall(int flags)
68857 {
68858 struct vm_area_struct * vma, * prev = NULL;
68859 - unsigned int def_flags = 0;
68860
68861 if (flags & MCL_FUTURE)
68862 - def_flags = VM_LOCKED;
68863 - current->mm->def_flags = def_flags;
68864 + current->mm->def_flags |= VM_LOCKED;
68865 + else
68866 + current->mm->def_flags &= ~VM_LOCKED;
68867 if (flags == MCL_FUTURE)
68868 goto out;
68869
68870 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
68871 vm_flags_t newflags;
68872
68873 +#ifdef CONFIG_PAX_SEGMEXEC
68874 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
68875 + break;
68876 +#endif
68877 +
68878 + BUG_ON(vma->vm_end > TASK_SIZE);
68879 newflags = vma->vm_flags | VM_LOCKED;
68880 if (!(flags & MCL_CURRENT))
68881 newflags &= ~VM_LOCKED;
68882 @@ -566,6 +582,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
68883 lock_limit >>= PAGE_SHIFT;
68884
68885 ret = -ENOMEM;
68886 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
68887 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
68888 capable(CAP_IPC_LOCK))
68889 ret = do_mlockall(flags);
68890 diff --git a/mm/mmap.c b/mm/mmap.c
68891 index eae90af..44552cf 100644
68892 --- a/mm/mmap.c
68893 +++ b/mm/mmap.c
68894 @@ -46,6 +46,16 @@
68895 #define arch_rebalance_pgtables(addr, len) (addr)
68896 #endif
68897
68898 +static inline void verify_mm_writelocked(struct mm_struct *mm)
68899 +{
68900 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
68901 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
68902 + up_read(&mm->mmap_sem);
68903 + BUG();
68904 + }
68905 +#endif
68906 +}
68907 +
68908 static void unmap_region(struct mm_struct *mm,
68909 struct vm_area_struct *vma, struct vm_area_struct *prev,
68910 unsigned long start, unsigned long end);
68911 @@ -71,22 +81,32 @@ static void unmap_region(struct mm_struct *mm,
68912 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
68913 *
68914 */
68915 -pgprot_t protection_map[16] = {
68916 +pgprot_t protection_map[16] __read_only = {
68917 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
68918 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
68919 };
68920
68921 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
68922 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
68923 {
68924 - return __pgprot(pgprot_val(protection_map[vm_flags &
68925 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
68926 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
68927 pgprot_val(arch_vm_get_page_prot(vm_flags)));
68928 +
68929 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68930 + if (!(__supported_pte_mask & _PAGE_NX) &&
68931 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
68932 + (vm_flags & (VM_READ | VM_WRITE)))
68933 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
68934 +#endif
68935 +
68936 + return prot;
68937 }
68938 EXPORT_SYMBOL(vm_get_page_prot);
68939
68940 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
68941 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
68942 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
68943 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
68944 /*
68945 * Make sure vm_committed_as in one cacheline and not cacheline shared with
68946 * other variables. It can be updated by several CPUs frequently.
68947 @@ -228,6 +248,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
68948 struct vm_area_struct *next = vma->vm_next;
68949
68950 might_sleep();
68951 + BUG_ON(vma->vm_mirror);
68952 if (vma->vm_ops && vma->vm_ops->close)
68953 vma->vm_ops->close(vma);
68954 if (vma->vm_file) {
68955 @@ -272,6 +293,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
68956 * not page aligned -Ram Gupta
68957 */
68958 rlim = rlimit(RLIMIT_DATA);
68959 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
68960 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
68961 (mm->end_data - mm->start_data) > rlim)
68962 goto out;
68963 @@ -689,6 +711,12 @@ static int
68964 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
68965 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68966 {
68967 +
68968 +#ifdef CONFIG_PAX_SEGMEXEC
68969 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
68970 + return 0;
68971 +#endif
68972 +
68973 if (is_mergeable_vma(vma, file, vm_flags) &&
68974 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
68975 if (vma->vm_pgoff == vm_pgoff)
68976 @@ -708,6 +736,12 @@ static int
68977 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
68978 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
68979 {
68980 +
68981 +#ifdef CONFIG_PAX_SEGMEXEC
68982 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
68983 + return 0;
68984 +#endif
68985 +
68986 if (is_mergeable_vma(vma, file, vm_flags) &&
68987 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
68988 pgoff_t vm_pglen;
68989 @@ -750,13 +784,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
68990 struct vm_area_struct *vma_merge(struct mm_struct *mm,
68991 struct vm_area_struct *prev, unsigned long addr,
68992 unsigned long end, unsigned long vm_flags,
68993 - struct anon_vma *anon_vma, struct file *file,
68994 + struct anon_vma *anon_vma, struct file *file,
68995 pgoff_t pgoff, struct mempolicy *policy)
68996 {
68997 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
68998 struct vm_area_struct *area, *next;
68999 int err;
69000
69001 +#ifdef CONFIG_PAX_SEGMEXEC
69002 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
69003 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
69004 +
69005 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
69006 +#endif
69007 +
69008 /*
69009 * We later require that vma->vm_flags == vm_flags,
69010 * so this tests vma->vm_flags & VM_SPECIAL, too.
69011 @@ -772,6 +813,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
69012 if (next && next->vm_end == end) /* cases 6, 7, 8 */
69013 next = next->vm_next;
69014
69015 +#ifdef CONFIG_PAX_SEGMEXEC
69016 + if (prev)
69017 + prev_m = pax_find_mirror_vma(prev);
69018 + if (area)
69019 + area_m = pax_find_mirror_vma(area);
69020 + if (next)
69021 + next_m = pax_find_mirror_vma(next);
69022 +#endif
69023 +
69024 /*
69025 * Can it merge with the predecessor?
69026 */
69027 @@ -791,9 +841,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
69028 /* cases 1, 6 */
69029 err = vma_adjust(prev, prev->vm_start,
69030 next->vm_end, prev->vm_pgoff, NULL);
69031 - } else /* cases 2, 5, 7 */
69032 +
69033 +#ifdef CONFIG_PAX_SEGMEXEC
69034 + if (!err && prev_m)
69035 + err = vma_adjust(prev_m, prev_m->vm_start,
69036 + next_m->vm_end, prev_m->vm_pgoff, NULL);
69037 +#endif
69038 +
69039 + } else { /* cases 2, 5, 7 */
69040 err = vma_adjust(prev, prev->vm_start,
69041 end, prev->vm_pgoff, NULL);
69042 +
69043 +#ifdef CONFIG_PAX_SEGMEXEC
69044 + if (!err && prev_m)
69045 + err = vma_adjust(prev_m, prev_m->vm_start,
69046 + end_m, prev_m->vm_pgoff, NULL);
69047 +#endif
69048 +
69049 + }
69050 if (err)
69051 return NULL;
69052 khugepaged_enter_vma_merge(prev);
69053 @@ -807,12 +872,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
69054 mpol_equal(policy, vma_policy(next)) &&
69055 can_vma_merge_before(next, vm_flags,
69056 anon_vma, file, pgoff+pglen)) {
69057 - if (prev && addr < prev->vm_end) /* case 4 */
69058 + if (prev && addr < prev->vm_end) { /* case 4 */
69059 err = vma_adjust(prev, prev->vm_start,
69060 addr, prev->vm_pgoff, NULL);
69061 - else /* cases 3, 8 */
69062 +
69063 +#ifdef CONFIG_PAX_SEGMEXEC
69064 + if (!err && prev_m)
69065 + err = vma_adjust(prev_m, prev_m->vm_start,
69066 + addr_m, prev_m->vm_pgoff, NULL);
69067 +#endif
69068 +
69069 + } else { /* cases 3, 8 */
69070 err = vma_adjust(area, addr, next->vm_end,
69071 next->vm_pgoff - pglen, NULL);
69072 +
69073 +#ifdef CONFIG_PAX_SEGMEXEC
69074 + if (!err && area_m)
69075 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
69076 + next_m->vm_pgoff - pglen, NULL);
69077 +#endif
69078 +
69079 + }
69080 if (err)
69081 return NULL;
69082 khugepaged_enter_vma_merge(area);
69083 @@ -921,14 +1001,11 @@ none:
69084 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
69085 struct file *file, long pages)
69086 {
69087 - const unsigned long stack_flags
69088 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
69089 -
69090 if (file) {
69091 mm->shared_vm += pages;
69092 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
69093 mm->exec_vm += pages;
69094 - } else if (flags & stack_flags)
69095 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
69096 mm->stack_vm += pages;
69097 if (flags & (VM_RESERVED|VM_IO))
69098 mm->reserved_vm += pages;
69099 @@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69100 * (the exception is when the underlying filesystem is noexec
69101 * mounted, in which case we dont add PROT_EXEC.)
69102 */
69103 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
69104 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
69105 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
69106 prot |= PROT_EXEC;
69107
69108 @@ -981,7 +1058,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69109 /* Obtain the address to map to. we verify (or select) it and ensure
69110 * that it represents a valid section of the address space.
69111 */
69112 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
69113 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
69114 if (addr & ~PAGE_MASK)
69115 return addr;
69116
69117 @@ -992,6 +1069,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69118 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
69119 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
69120
69121 +#ifdef CONFIG_PAX_MPROTECT
69122 + if (mm->pax_flags & MF_PAX_MPROTECT) {
69123 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
69124 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
69125 + gr_log_rwxmmap(file);
69126 +
69127 +#ifdef CONFIG_PAX_EMUPLT
69128 + vm_flags &= ~VM_EXEC;
69129 +#else
69130 + return -EPERM;
69131 +#endif
69132 +
69133 + }
69134 +
69135 + if (!(vm_flags & VM_EXEC))
69136 + vm_flags &= ~VM_MAYEXEC;
69137 +#else
69138 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
69139 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
69140 +#endif
69141 + else
69142 + vm_flags &= ~VM_MAYWRITE;
69143 + }
69144 +#endif
69145 +
69146 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69147 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
69148 + vm_flags &= ~VM_PAGEEXEC;
69149 +#endif
69150 +
69151 if (flags & MAP_LOCKED)
69152 if (!can_do_mlock())
69153 return -EPERM;
69154 @@ -1003,6 +1110,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69155 locked += mm->locked_vm;
69156 lock_limit = rlimit(RLIMIT_MEMLOCK);
69157 lock_limit >>= PAGE_SHIFT;
69158 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
69159 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
69160 return -EAGAIN;
69161 }
69162 @@ -1073,6 +1181,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
69163 if (error)
69164 return error;
69165
69166 + if (!gr_acl_handle_mmap(file, prot))
69167 + return -EACCES;
69168 +
69169 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
69170 }
69171 EXPORT_SYMBOL(do_mmap_pgoff);
69172 @@ -1153,7 +1264,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
69173 vm_flags_t vm_flags = vma->vm_flags;
69174
69175 /* If it was private or non-writable, the write bit is already clear */
69176 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
69177 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
69178 return 0;
69179
69180 /* The backer wishes to know when pages are first written to? */
69181 @@ -1202,14 +1313,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
69182 unsigned long charged = 0;
69183 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
69184
69185 +#ifdef CONFIG_PAX_SEGMEXEC
69186 + struct vm_area_struct *vma_m = NULL;
69187 +#endif
69188 +
69189 + /*
69190 + * mm->mmap_sem is required to protect against another thread
69191 + * changing the mappings in case we sleep.
69192 + */
69193 + verify_mm_writelocked(mm);
69194 +
69195 /* Clear old maps */
69196 error = -ENOMEM;
69197 -munmap_back:
69198 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69199 if (vma && vma->vm_start < addr + len) {
69200 if (do_munmap(mm, addr, len))
69201 return -ENOMEM;
69202 - goto munmap_back;
69203 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
69204 + BUG_ON(vma && vma->vm_start < addr + len);
69205 }
69206
69207 /* Check against address space limit. */
69208 @@ -1258,6 +1379,16 @@ munmap_back:
69209 goto unacct_error;
69210 }
69211
69212 +#ifdef CONFIG_PAX_SEGMEXEC
69213 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
69214 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
69215 + if (!vma_m) {
69216 + error = -ENOMEM;
69217 + goto free_vma;
69218 + }
69219 + }
69220 +#endif
69221 +
69222 vma->vm_mm = mm;
69223 vma->vm_start = addr;
69224 vma->vm_end = addr + len;
69225 @@ -1281,6 +1412,19 @@ munmap_back:
69226 error = file->f_op->mmap(file, vma);
69227 if (error)
69228 goto unmap_and_free_vma;
69229 +
69230 +#ifdef CONFIG_PAX_SEGMEXEC
69231 + if (vma_m && (vm_flags & VM_EXECUTABLE))
69232 + added_exe_file_vma(mm);
69233 +#endif
69234 +
69235 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
69236 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
69237 + vma->vm_flags |= VM_PAGEEXEC;
69238 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
69239 + }
69240 +#endif
69241 +
69242 if (vm_flags & VM_EXECUTABLE)
69243 added_exe_file_vma(mm);
69244
69245 @@ -1316,6 +1460,11 @@ munmap_back:
69246 vma_link(mm, vma, prev, rb_link, rb_parent);
69247 file = vma->vm_file;
69248
69249 +#ifdef CONFIG_PAX_SEGMEXEC
69250 + if (vma_m)
69251 + BUG_ON(pax_mirror_vma(vma_m, vma));
69252 +#endif
69253 +
69254 /* Once vma denies write, undo our temporary denial count */
69255 if (correct_wcount)
69256 atomic_inc(&inode->i_writecount);
69257 @@ -1324,6 +1473,7 @@ out:
69258
69259 mm->total_vm += len >> PAGE_SHIFT;
69260 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
69261 + track_exec_limit(mm, addr, addr + len, vm_flags);
69262 if (vm_flags & VM_LOCKED) {
69263 if (!mlock_vma_pages_range(vma, addr, addr + len))
69264 mm->locked_vm += (len >> PAGE_SHIFT);
69265 @@ -1341,6 +1491,12 @@ unmap_and_free_vma:
69266 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
69267 charged = 0;
69268 free_vma:
69269 +
69270 +#ifdef CONFIG_PAX_SEGMEXEC
69271 + if (vma_m)
69272 + kmem_cache_free(vm_area_cachep, vma_m);
69273 +#endif
69274 +
69275 kmem_cache_free(vm_area_cachep, vma);
69276 unacct_error:
69277 if (charged)
69278 @@ -1348,6 +1504,44 @@ unacct_error:
69279 return error;
69280 }
69281
69282 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
69283 +{
69284 + if (!vma) {
69285 +#ifdef CONFIG_STACK_GROWSUP
69286 + if (addr > sysctl_heap_stack_gap)
69287 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
69288 + else
69289 + vma = find_vma(current->mm, 0);
69290 + if (vma && (vma->vm_flags & VM_GROWSUP))
69291 + return false;
69292 +#endif
69293 + return true;
69294 + }
69295 +
69296 + if (addr + len > vma->vm_start)
69297 + return false;
69298 +
69299 + if (vma->vm_flags & VM_GROWSDOWN)
69300 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
69301 +#ifdef CONFIG_STACK_GROWSUP
69302 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
69303 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
69304 +#endif
69305 +
69306 + return true;
69307 +}
69308 +
69309 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
69310 +{
69311 + if (vma->vm_start < len)
69312 + return -ENOMEM;
69313 + if (!(vma->vm_flags & VM_GROWSDOWN))
69314 + return vma->vm_start - len;
69315 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
69316 + return vma->vm_start - len - sysctl_heap_stack_gap;
69317 + return -ENOMEM;
69318 +}
69319 +
69320 /* Get an address range which is currently unmapped.
69321 * For shmat() with addr=0.
69322 *
69323 @@ -1374,18 +1568,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
69324 if (flags & MAP_FIXED)
69325 return addr;
69326
69327 +#ifdef CONFIG_PAX_RANDMMAP
69328 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69329 +#endif
69330 +
69331 if (addr) {
69332 addr = PAGE_ALIGN(addr);
69333 - vma = find_vma(mm, addr);
69334 - if (TASK_SIZE - len >= addr &&
69335 - (!vma || addr + len <= vma->vm_start))
69336 - return addr;
69337 + if (TASK_SIZE - len >= addr) {
69338 + vma = find_vma(mm, addr);
69339 + if (check_heap_stack_gap(vma, addr, len))
69340 + return addr;
69341 + }
69342 }
69343 if (len > mm->cached_hole_size) {
69344 - start_addr = addr = mm->free_area_cache;
69345 + start_addr = addr = mm->free_area_cache;
69346 } else {
69347 - start_addr = addr = TASK_UNMAPPED_BASE;
69348 - mm->cached_hole_size = 0;
69349 + start_addr = addr = mm->mmap_base;
69350 + mm->cached_hole_size = 0;
69351 }
69352
69353 full_search:
69354 @@ -1396,34 +1595,40 @@ full_search:
69355 * Start a new search - just in case we missed
69356 * some holes.
69357 */
69358 - if (start_addr != TASK_UNMAPPED_BASE) {
69359 - addr = TASK_UNMAPPED_BASE;
69360 - start_addr = addr;
69361 + if (start_addr != mm->mmap_base) {
69362 + start_addr = addr = mm->mmap_base;
69363 mm->cached_hole_size = 0;
69364 goto full_search;
69365 }
69366 return -ENOMEM;
69367 }
69368 - if (!vma || addr + len <= vma->vm_start) {
69369 - /*
69370 - * Remember the place where we stopped the search:
69371 - */
69372 - mm->free_area_cache = addr + len;
69373 - return addr;
69374 - }
69375 + if (check_heap_stack_gap(vma, addr, len))
69376 + break;
69377 if (addr + mm->cached_hole_size < vma->vm_start)
69378 mm->cached_hole_size = vma->vm_start - addr;
69379 addr = vma->vm_end;
69380 }
69381 +
69382 + /*
69383 + * Remember the place where we stopped the search:
69384 + */
69385 + mm->free_area_cache = addr + len;
69386 + return addr;
69387 }
69388 #endif
69389
69390 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
69391 {
69392 +
69393 +#ifdef CONFIG_PAX_SEGMEXEC
69394 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69395 + return;
69396 +#endif
69397 +
69398 /*
69399 * Is this a new hole at the lowest possible address?
69400 */
69401 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
69402 + if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
69403 mm->free_area_cache = addr;
69404 mm->cached_hole_size = ~0UL;
69405 }
69406 @@ -1441,7 +1646,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69407 {
69408 struct vm_area_struct *vma;
69409 struct mm_struct *mm = current->mm;
69410 - unsigned long addr = addr0;
69411 + unsigned long base = mm->mmap_base, addr = addr0;
69412
69413 /* requested length too big for entire address space */
69414 if (len > TASK_SIZE)
69415 @@ -1450,13 +1655,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69416 if (flags & MAP_FIXED)
69417 return addr;
69418
69419 +#ifdef CONFIG_PAX_RANDMMAP
69420 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
69421 +#endif
69422 +
69423 /* requesting a specific address */
69424 if (addr) {
69425 addr = PAGE_ALIGN(addr);
69426 - vma = find_vma(mm, addr);
69427 - if (TASK_SIZE - len >= addr &&
69428 - (!vma || addr + len <= vma->vm_start))
69429 - return addr;
69430 + if (TASK_SIZE - len >= addr) {
69431 + vma = find_vma(mm, addr);
69432 + if (check_heap_stack_gap(vma, addr, len))
69433 + return addr;
69434 + }
69435 }
69436
69437 /* check if free_area_cache is useful for us */
69438 @@ -1471,7 +1681,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69439 /* make sure it can fit in the remaining address space */
69440 if (addr > len) {
69441 vma = find_vma(mm, addr-len);
69442 - if (!vma || addr <= vma->vm_start)
69443 + if (check_heap_stack_gap(vma, addr - len, len))
69444 /* remember the address as a hint for next time */
69445 return (mm->free_area_cache = addr-len);
69446 }
69447 @@ -1488,7 +1698,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69448 * return with success:
69449 */
69450 vma = find_vma(mm, addr);
69451 - if (!vma || addr+len <= vma->vm_start)
69452 + if (check_heap_stack_gap(vma, addr, len))
69453 /* remember the address as a hint for next time */
69454 return (mm->free_area_cache = addr);
69455
69456 @@ -1497,8 +1707,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
69457 mm->cached_hole_size = vma->vm_start - addr;
69458
69459 /* try just below the current vma->vm_start */
69460 - addr = vma->vm_start-len;
69461 - } while (len < vma->vm_start);
69462 + addr = skip_heap_stack_gap(vma, len);
69463 + } while (!IS_ERR_VALUE(addr));
69464
69465 bottomup:
69466 /*
69467 @@ -1507,13 +1717,21 @@ bottomup:
69468 * can happen with large stack limits and large mmap()
69469 * allocations.
69470 */
69471 + mm->mmap_base = TASK_UNMAPPED_BASE;
69472 +
69473 +#ifdef CONFIG_PAX_RANDMMAP
69474 + if (mm->pax_flags & MF_PAX_RANDMMAP)
69475 + mm->mmap_base += mm->delta_mmap;
69476 +#endif
69477 +
69478 + mm->free_area_cache = mm->mmap_base;
69479 mm->cached_hole_size = ~0UL;
69480 - mm->free_area_cache = TASK_UNMAPPED_BASE;
69481 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
69482 /*
69483 * Restore the topdown base:
69484 */
69485 - mm->free_area_cache = mm->mmap_base;
69486 + mm->mmap_base = base;
69487 + mm->free_area_cache = base;
69488 mm->cached_hole_size = ~0UL;
69489
69490 return addr;
69491 @@ -1522,6 +1740,12 @@ bottomup:
69492
69493 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69494 {
69495 +
69496 +#ifdef CONFIG_PAX_SEGMEXEC
69497 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
69498 + return;
69499 +#endif
69500 +
69501 /*
69502 * Is this a new hole at the highest possible address?
69503 */
69504 @@ -1529,8 +1753,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
69505 mm->free_area_cache = addr;
69506
69507 /* dont allow allocations above current base */
69508 - if (mm->free_area_cache > mm->mmap_base)
69509 + if (mm->free_area_cache > mm->mmap_base) {
69510 mm->free_area_cache = mm->mmap_base;
69511 + mm->cached_hole_size = ~0UL;
69512 + }
69513 }
69514
69515 unsigned long
69516 @@ -1603,40 +1829,42 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
69517
69518 EXPORT_SYMBOL(find_vma);
69519
69520 -/* Same as find_vma, but also return a pointer to the previous VMA in *pprev. */
69521 +/*
69522 + * Same as find_vma, but also return a pointer to the previous VMA in *pprev.
69523 + * Note: pprev is set to NULL when return value is NULL.
69524 + */
69525 struct vm_area_struct *
69526 find_vma_prev(struct mm_struct *mm, unsigned long addr,
69527 struct vm_area_struct **pprev)
69528 {
69529 - struct vm_area_struct *vma = NULL, *prev = NULL;
69530 - struct rb_node *rb_node;
69531 - if (!mm)
69532 - goto out;
69533 + struct vm_area_struct *vma;
69534
69535 - /* Guard against addr being lower than the first VMA */
69536 - vma = mm->mmap;
69537 + vma = find_vma(mm, addr);
69538 + *pprev = vma ? vma->vm_prev : NULL;
69539 + return vma;
69540 +}
69541
69542 - /* Go through the RB tree quickly. */
69543 - rb_node = mm->mm_rb.rb_node;
69544 +#ifdef CONFIG_PAX_SEGMEXEC
69545 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
69546 +{
69547 + struct vm_area_struct *vma_m;
69548
69549 - while (rb_node) {
69550 - struct vm_area_struct *vma_tmp;
69551 - vma_tmp = rb_entry(rb_node, struct vm_area_struct, vm_rb);
69552 -
69553 - if (addr < vma_tmp->vm_end) {
69554 - rb_node = rb_node->rb_left;
69555 - } else {
69556 - prev = vma_tmp;
69557 - if (!prev->vm_next || (addr < prev->vm_next->vm_end))
69558 - break;
69559 - rb_node = rb_node->rb_right;
69560 - }
69561 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
69562 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
69563 + BUG_ON(vma->vm_mirror);
69564 + return NULL;
69565 }
69566 -
69567 -out:
69568 - *pprev = prev;
69569 - return prev ? prev->vm_next : vma;
69570 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
69571 + vma_m = vma->vm_mirror;
69572 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
69573 + BUG_ON(vma->vm_file != vma_m->vm_file);
69574 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
69575 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
69576 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
69577 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
69578 + return vma_m;
69579 }
69580 +#endif
69581
69582 /*
69583 * Verify that the stack growth is acceptable and
69584 @@ -1654,6 +1882,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69585 return -ENOMEM;
69586
69587 /* Stack limit test */
69588 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
69589 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
69590 return -ENOMEM;
69591
69592 @@ -1664,6 +1893,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69593 locked = mm->locked_vm + grow;
69594 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
69595 limit >>= PAGE_SHIFT;
69596 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
69597 if (locked > limit && !capable(CAP_IPC_LOCK))
69598 return -ENOMEM;
69599 }
69600 @@ -1694,37 +1924,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
69601 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
69602 * vma is the last one with address > vma->vm_end. Have to extend vma.
69603 */
69604 +#ifndef CONFIG_IA64
69605 +static
69606 +#endif
69607 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69608 {
69609 int error;
69610 + bool locknext;
69611
69612 if (!(vma->vm_flags & VM_GROWSUP))
69613 return -EFAULT;
69614
69615 + /* Also guard against wrapping around to address 0. */
69616 + if (address < PAGE_ALIGN(address+1))
69617 + address = PAGE_ALIGN(address+1);
69618 + else
69619 + return -ENOMEM;
69620 +
69621 /*
69622 * We must make sure the anon_vma is allocated
69623 * so that the anon_vma locking is not a noop.
69624 */
69625 if (unlikely(anon_vma_prepare(vma)))
69626 return -ENOMEM;
69627 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
69628 + if (locknext && anon_vma_prepare(vma->vm_next))
69629 + return -ENOMEM;
69630 vma_lock_anon_vma(vma);
69631 + if (locknext)
69632 + vma_lock_anon_vma(vma->vm_next);
69633
69634 /*
69635 * vma->vm_start/vm_end cannot change under us because the caller
69636 * is required to hold the mmap_sem in read mode. We need the
69637 - * anon_vma lock to serialize against concurrent expand_stacks.
69638 - * Also guard against wrapping around to address 0.
69639 + * anon_vma locks to serialize against concurrent expand_stacks
69640 + * and expand_upwards.
69641 */
69642 - if (address < PAGE_ALIGN(address+4))
69643 - address = PAGE_ALIGN(address+4);
69644 - else {
69645 - vma_unlock_anon_vma(vma);
69646 - return -ENOMEM;
69647 - }
69648 error = 0;
69649
69650 /* Somebody else might have raced and expanded it already */
69651 - if (address > vma->vm_end) {
69652 + 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)
69653 + error = -ENOMEM;
69654 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
69655 unsigned long size, grow;
69656
69657 size = address - vma->vm_start;
69658 @@ -1739,6 +1980,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
69659 }
69660 }
69661 }
69662 + if (locknext)
69663 + vma_unlock_anon_vma(vma->vm_next);
69664 vma_unlock_anon_vma(vma);
69665 khugepaged_enter_vma_merge(vma);
69666 return error;
69667 @@ -1752,6 +1995,8 @@ int expand_downwards(struct vm_area_struct *vma,
69668 unsigned long address)
69669 {
69670 int error;
69671 + bool lockprev = false;
69672 + struct vm_area_struct *prev;
69673
69674 /*
69675 * We must make sure the anon_vma is allocated
69676 @@ -1765,6 +2010,15 @@ int expand_downwards(struct vm_area_struct *vma,
69677 if (error)
69678 return error;
69679
69680 + prev = vma->vm_prev;
69681 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
69682 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
69683 +#endif
69684 + if (lockprev && anon_vma_prepare(prev))
69685 + return -ENOMEM;
69686 + if (lockprev)
69687 + vma_lock_anon_vma(prev);
69688 +
69689 vma_lock_anon_vma(vma);
69690
69691 /*
69692 @@ -1774,9 +2028,17 @@ int expand_downwards(struct vm_area_struct *vma,
69693 */
69694
69695 /* Somebody else might have raced and expanded it already */
69696 - if (address < vma->vm_start) {
69697 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
69698 + error = -ENOMEM;
69699 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
69700 unsigned long size, grow;
69701
69702 +#ifdef CONFIG_PAX_SEGMEXEC
69703 + struct vm_area_struct *vma_m;
69704 +
69705 + vma_m = pax_find_mirror_vma(vma);
69706 +#endif
69707 +
69708 size = vma->vm_end - address;
69709 grow = (vma->vm_start - address) >> PAGE_SHIFT;
69710
69711 @@ -1786,11 +2048,22 @@ int expand_downwards(struct vm_area_struct *vma,
69712 if (!error) {
69713 vma->vm_start = address;
69714 vma->vm_pgoff -= grow;
69715 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
69716 +
69717 +#ifdef CONFIG_PAX_SEGMEXEC
69718 + if (vma_m) {
69719 + vma_m->vm_start -= grow << PAGE_SHIFT;
69720 + vma_m->vm_pgoff -= grow;
69721 + }
69722 +#endif
69723 +
69724 perf_event_mmap(vma);
69725 }
69726 }
69727 }
69728 vma_unlock_anon_vma(vma);
69729 + if (lockprev)
69730 + vma_unlock_anon_vma(prev);
69731 khugepaged_enter_vma_merge(vma);
69732 return error;
69733 }
69734 @@ -1860,6 +2133,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
69735 do {
69736 long nrpages = vma_pages(vma);
69737
69738 +#ifdef CONFIG_PAX_SEGMEXEC
69739 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
69740 + vma = remove_vma(vma);
69741 + continue;
69742 + }
69743 +#endif
69744 +
69745 mm->total_vm -= nrpages;
69746 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
69747 vma = remove_vma(vma);
69748 @@ -1905,6 +2185,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
69749 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
69750 vma->vm_prev = NULL;
69751 do {
69752 +
69753 +#ifdef CONFIG_PAX_SEGMEXEC
69754 + if (vma->vm_mirror) {
69755 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
69756 + vma->vm_mirror->vm_mirror = NULL;
69757 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
69758 + vma->vm_mirror = NULL;
69759 + }
69760 +#endif
69761 +
69762 rb_erase(&vma->vm_rb, &mm->mm_rb);
69763 mm->map_count--;
69764 tail_vma = vma;
69765 @@ -1933,14 +2223,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69766 struct vm_area_struct *new;
69767 int err = -ENOMEM;
69768
69769 +#ifdef CONFIG_PAX_SEGMEXEC
69770 + struct vm_area_struct *vma_m, *new_m = NULL;
69771 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
69772 +#endif
69773 +
69774 if (is_vm_hugetlb_page(vma) && (addr &
69775 ~(huge_page_mask(hstate_vma(vma)))))
69776 return -EINVAL;
69777
69778 +#ifdef CONFIG_PAX_SEGMEXEC
69779 + vma_m = pax_find_mirror_vma(vma);
69780 +#endif
69781 +
69782 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69783 if (!new)
69784 goto out_err;
69785
69786 +#ifdef CONFIG_PAX_SEGMEXEC
69787 + if (vma_m) {
69788 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69789 + if (!new_m) {
69790 + kmem_cache_free(vm_area_cachep, new);
69791 + goto out_err;
69792 + }
69793 + }
69794 +#endif
69795 +
69796 /* most fields are the same, copy all, and then fixup */
69797 *new = *vma;
69798
69799 @@ -1953,6 +2262,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69800 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
69801 }
69802
69803 +#ifdef CONFIG_PAX_SEGMEXEC
69804 + if (vma_m) {
69805 + *new_m = *vma_m;
69806 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
69807 + new_m->vm_mirror = new;
69808 + new->vm_mirror = new_m;
69809 +
69810 + if (new_below)
69811 + new_m->vm_end = addr_m;
69812 + else {
69813 + new_m->vm_start = addr_m;
69814 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
69815 + }
69816 + }
69817 +#endif
69818 +
69819 pol = mpol_dup(vma_policy(vma));
69820 if (IS_ERR(pol)) {
69821 err = PTR_ERR(pol);
69822 @@ -1978,6 +2303,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69823 else
69824 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
69825
69826 +#ifdef CONFIG_PAX_SEGMEXEC
69827 + if (!err && vma_m) {
69828 + if (anon_vma_clone(new_m, vma_m))
69829 + goto out_free_mpol;
69830 +
69831 + mpol_get(pol);
69832 + vma_set_policy(new_m, pol);
69833 +
69834 + if (new_m->vm_file) {
69835 + get_file(new_m->vm_file);
69836 + if (vma_m->vm_flags & VM_EXECUTABLE)
69837 + added_exe_file_vma(mm);
69838 + }
69839 +
69840 + if (new_m->vm_ops && new_m->vm_ops->open)
69841 + new_m->vm_ops->open(new_m);
69842 +
69843 + if (new_below)
69844 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
69845 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
69846 + else
69847 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
69848 +
69849 + if (err) {
69850 + if (new_m->vm_ops && new_m->vm_ops->close)
69851 + new_m->vm_ops->close(new_m);
69852 + if (new_m->vm_file) {
69853 + if (vma_m->vm_flags & VM_EXECUTABLE)
69854 + removed_exe_file_vma(mm);
69855 + fput(new_m->vm_file);
69856 + }
69857 + mpol_put(pol);
69858 + }
69859 + }
69860 +#endif
69861 +
69862 /* Success. */
69863 if (!err)
69864 return 0;
69865 @@ -1990,10 +2351,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69866 removed_exe_file_vma(mm);
69867 fput(new->vm_file);
69868 }
69869 - unlink_anon_vmas(new);
69870 out_free_mpol:
69871 mpol_put(pol);
69872 out_free_vma:
69873 +
69874 +#ifdef CONFIG_PAX_SEGMEXEC
69875 + if (new_m) {
69876 + unlink_anon_vmas(new_m);
69877 + kmem_cache_free(vm_area_cachep, new_m);
69878 + }
69879 +#endif
69880 +
69881 + unlink_anon_vmas(new);
69882 kmem_cache_free(vm_area_cachep, new);
69883 out_err:
69884 return err;
69885 @@ -2006,6 +2375,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
69886 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
69887 unsigned long addr, int new_below)
69888 {
69889 +
69890 +#ifdef CONFIG_PAX_SEGMEXEC
69891 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
69892 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
69893 + if (mm->map_count >= sysctl_max_map_count-1)
69894 + return -ENOMEM;
69895 + } else
69896 +#endif
69897 +
69898 if (mm->map_count >= sysctl_max_map_count)
69899 return -ENOMEM;
69900
69901 @@ -2017,11 +2395,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
69902 * work. This now handles partial unmappings.
69903 * Jeremy Fitzhardinge <jeremy@goop.org>
69904 */
69905 +#ifdef CONFIG_PAX_SEGMEXEC
69906 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69907 {
69908 + int ret = __do_munmap(mm, start, len);
69909 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
69910 + return ret;
69911 +
69912 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
69913 +}
69914 +
69915 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69916 +#else
69917 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69918 +#endif
69919 +{
69920 unsigned long end;
69921 struct vm_area_struct *vma, *prev, *last;
69922
69923 + /*
69924 + * mm->mmap_sem is required to protect against another thread
69925 + * changing the mappings in case we sleep.
69926 + */
69927 + verify_mm_writelocked(mm);
69928 +
69929 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
69930 return -EINVAL;
69931
69932 @@ -2096,6 +2493,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
69933 /* Fix up all other VM information */
69934 remove_vma_list(mm, vma);
69935
69936 + track_exec_limit(mm, start, end, 0UL);
69937 +
69938 return 0;
69939 }
69940
69941 @@ -2108,22 +2507,18 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
69942
69943 profile_munmap(addr);
69944
69945 +#ifdef CONFIG_PAX_SEGMEXEC
69946 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
69947 + (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
69948 + return -EINVAL;
69949 +#endif
69950 +
69951 down_write(&mm->mmap_sem);
69952 ret = do_munmap(mm, addr, len);
69953 up_write(&mm->mmap_sem);
69954 return ret;
69955 }
69956
69957 -static inline void verify_mm_writelocked(struct mm_struct *mm)
69958 -{
69959 -#ifdef CONFIG_DEBUG_VM
69960 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
69961 - WARN_ON(1);
69962 - up_read(&mm->mmap_sem);
69963 - }
69964 -#endif
69965 -}
69966 -
69967 /*
69968 * this is really a simplified "do_mmap". it only handles
69969 * anonymous maps. eventually we may be able to do some
69970 @@ -2137,6 +2532,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69971 struct rb_node ** rb_link, * rb_parent;
69972 pgoff_t pgoff = addr >> PAGE_SHIFT;
69973 int error;
69974 + unsigned long charged;
69975
69976 len = PAGE_ALIGN(len);
69977 if (!len)
69978 @@ -2148,16 +2544,30 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
69979
69980 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
69981
69982 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
69983 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
69984 + flags &= ~VM_EXEC;
69985 +
69986 +#ifdef CONFIG_PAX_MPROTECT
69987 + if (mm->pax_flags & MF_PAX_MPROTECT)
69988 + flags &= ~VM_MAYEXEC;
69989 +#endif
69990 +
69991 + }
69992 +#endif
69993 +
69994 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
69995 if (error & ~PAGE_MASK)
69996 return error;
69997
69998 + charged = len >> PAGE_SHIFT;
69999 +
70000 /*
70001 * mlock MCL_FUTURE?
70002 */
70003 if (mm->def_flags & VM_LOCKED) {
70004 unsigned long locked, lock_limit;
70005 - locked = len >> PAGE_SHIFT;
70006 + locked = charged;
70007 locked += mm->locked_vm;
70008 lock_limit = rlimit(RLIMIT_MEMLOCK);
70009 lock_limit >>= PAGE_SHIFT;
70010 @@ -2174,22 +2584,22 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
70011 /*
70012 * Clear old maps. this also does some error checking for us
70013 */
70014 - munmap_back:
70015 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70016 if (vma && vma->vm_start < addr + len) {
70017 if (do_munmap(mm, addr, len))
70018 return -ENOMEM;
70019 - goto munmap_back;
70020 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
70021 + BUG_ON(vma && vma->vm_start < addr + len);
70022 }
70023
70024 /* Check against address space limits *after* clearing old maps... */
70025 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
70026 + if (!may_expand_vm(mm, charged))
70027 return -ENOMEM;
70028
70029 if (mm->map_count > sysctl_max_map_count)
70030 return -ENOMEM;
70031
70032 - if (security_vm_enough_memory(len >> PAGE_SHIFT))
70033 + if (security_vm_enough_memory(charged))
70034 return -ENOMEM;
70035
70036 /* Can we just expand an old private anonymous mapping? */
70037 @@ -2203,7 +2613,7 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
70038 */
70039 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70040 if (!vma) {
70041 - vm_unacct_memory(len >> PAGE_SHIFT);
70042 + vm_unacct_memory(charged);
70043 return -ENOMEM;
70044 }
70045
70046 @@ -2217,11 +2627,12 @@ unsigned long do_brk(unsigned long addr, unsigned long len)
70047 vma_link(mm, vma, prev, rb_link, rb_parent);
70048 out:
70049 perf_event_mmap(vma);
70050 - mm->total_vm += len >> PAGE_SHIFT;
70051 + mm->total_vm += charged;
70052 if (flags & VM_LOCKED) {
70053 if (!mlock_vma_pages_range(vma, addr, addr + len))
70054 - mm->locked_vm += (len >> PAGE_SHIFT);
70055 + mm->locked_vm += charged;
70056 }
70057 + track_exec_limit(mm, addr, addr + len, flags);
70058 return addr;
70059 }
70060
70061 @@ -2268,8 +2679,10 @@ void exit_mmap(struct mm_struct *mm)
70062 * Walk the list again, actually closing and freeing it,
70063 * with preemption enabled, without holding any MM locks.
70064 */
70065 - while (vma)
70066 + while (vma) {
70067 + vma->vm_mirror = NULL;
70068 vma = remove_vma(vma);
70069 + }
70070
70071 BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
70072 }
70073 @@ -2283,6 +2696,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
70074 struct vm_area_struct * __vma, * prev;
70075 struct rb_node ** rb_link, * rb_parent;
70076
70077 +#ifdef CONFIG_PAX_SEGMEXEC
70078 + struct vm_area_struct *vma_m = NULL;
70079 +#endif
70080 +
70081 + if (security_file_mmap(NULL, 0, 0, 0, vma->vm_start, 1))
70082 + return -EPERM;
70083 +
70084 /*
70085 * The vm_pgoff of a purely anonymous vma should be irrelevant
70086 * until its first write fault, when page's anon_vma and index
70087 @@ -2305,7 +2725,22 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
70088 if ((vma->vm_flags & VM_ACCOUNT) &&
70089 security_vm_enough_memory_mm(mm, vma_pages(vma)))
70090 return -ENOMEM;
70091 +
70092 +#ifdef CONFIG_PAX_SEGMEXEC
70093 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
70094 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70095 + if (!vma_m)
70096 + return -ENOMEM;
70097 + }
70098 +#endif
70099 +
70100 vma_link(mm, vma, prev, rb_link, rb_parent);
70101 +
70102 +#ifdef CONFIG_PAX_SEGMEXEC
70103 + if (vma_m)
70104 + BUG_ON(pax_mirror_vma(vma_m, vma));
70105 +#endif
70106 +
70107 return 0;
70108 }
70109
70110 @@ -2323,6 +2758,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
70111 struct rb_node **rb_link, *rb_parent;
70112 struct mempolicy *pol;
70113
70114 + BUG_ON(vma->vm_mirror);
70115 +
70116 /*
70117 * If anonymous vma has not yet been faulted, update new pgoff
70118 * to match new location, to increase its chance of merging.
70119 @@ -2373,6 +2810,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
70120 return NULL;
70121 }
70122
70123 +#ifdef CONFIG_PAX_SEGMEXEC
70124 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
70125 +{
70126 + struct vm_area_struct *prev_m;
70127 + struct rb_node **rb_link_m, *rb_parent_m;
70128 + struct mempolicy *pol_m;
70129 +
70130 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
70131 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
70132 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
70133 + *vma_m = *vma;
70134 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
70135 + if (anon_vma_clone(vma_m, vma))
70136 + return -ENOMEM;
70137 + pol_m = vma_policy(vma_m);
70138 + mpol_get(pol_m);
70139 + vma_set_policy(vma_m, pol_m);
70140 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
70141 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
70142 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
70143 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
70144 + if (vma_m->vm_file)
70145 + get_file(vma_m->vm_file);
70146 + if (vma_m->vm_ops && vma_m->vm_ops->open)
70147 + vma_m->vm_ops->open(vma_m);
70148 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
70149 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
70150 + vma_m->vm_mirror = vma;
70151 + vma->vm_mirror = vma_m;
70152 + return 0;
70153 +}
70154 +#endif
70155 +
70156 /*
70157 * Return true if the calling process may expand its vm space by the passed
70158 * number of pages
70159 @@ -2383,7 +2853,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
70160 unsigned long lim;
70161
70162 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
70163 -
70164 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
70165 if (cur + npages > lim)
70166 return 0;
70167 return 1;
70168 @@ -2454,6 +2924,22 @@ int install_special_mapping(struct mm_struct *mm,
70169 vma->vm_start = addr;
70170 vma->vm_end = addr + len;
70171
70172 +#ifdef CONFIG_PAX_MPROTECT
70173 + if (mm->pax_flags & MF_PAX_MPROTECT) {
70174 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
70175 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
70176 + return -EPERM;
70177 + if (!(vm_flags & VM_EXEC))
70178 + vm_flags &= ~VM_MAYEXEC;
70179 +#else
70180 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
70181 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
70182 +#endif
70183 + else
70184 + vm_flags &= ~VM_MAYWRITE;
70185 + }
70186 +#endif
70187 +
70188 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
70189 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
70190
70191 diff --git a/mm/mprotect.c b/mm/mprotect.c
70192 index 5a688a2..27e031c 100644
70193 --- a/mm/mprotect.c
70194 +++ b/mm/mprotect.c
70195 @@ -23,10 +23,16 @@
70196 #include <linux/mmu_notifier.h>
70197 #include <linux/migrate.h>
70198 #include <linux/perf_event.h>
70199 +
70200 +#ifdef CONFIG_PAX_MPROTECT
70201 +#include <linux/elf.h>
70202 +#endif
70203 +
70204 #include <asm/uaccess.h>
70205 #include <asm/pgtable.h>
70206 #include <asm/cacheflush.h>
70207 #include <asm/tlbflush.h>
70208 +#include <asm/mmu_context.h>
70209
70210 #ifndef pgprot_modify
70211 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
70212 @@ -141,6 +147,48 @@ static void change_protection(struct vm_area_struct *vma,
70213 flush_tlb_range(vma, start, end);
70214 }
70215
70216 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70217 +/* called while holding the mmap semaphor for writing except stack expansion */
70218 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
70219 +{
70220 + unsigned long oldlimit, newlimit = 0UL;
70221 +
70222 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
70223 + return;
70224 +
70225 + spin_lock(&mm->page_table_lock);
70226 + oldlimit = mm->context.user_cs_limit;
70227 + if ((prot & VM_EXEC) && oldlimit < end)
70228 + /* USER_CS limit moved up */
70229 + newlimit = end;
70230 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
70231 + /* USER_CS limit moved down */
70232 + newlimit = start;
70233 +
70234 + if (newlimit) {
70235 + mm->context.user_cs_limit = newlimit;
70236 +
70237 +#ifdef CONFIG_SMP
70238 + wmb();
70239 + cpus_clear(mm->context.cpu_user_cs_mask);
70240 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
70241 +#endif
70242 +
70243 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
70244 + }
70245 + spin_unlock(&mm->page_table_lock);
70246 + if (newlimit == end) {
70247 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
70248 +
70249 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
70250 + if (is_vm_hugetlb_page(vma))
70251 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
70252 + else
70253 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
70254 + }
70255 +}
70256 +#endif
70257 +
70258 int
70259 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70260 unsigned long start, unsigned long end, unsigned long newflags)
70261 @@ -153,11 +201,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70262 int error;
70263 int dirty_accountable = 0;
70264
70265 +#ifdef CONFIG_PAX_SEGMEXEC
70266 + struct vm_area_struct *vma_m = NULL;
70267 + unsigned long start_m, end_m;
70268 +
70269 + start_m = start + SEGMEXEC_TASK_SIZE;
70270 + end_m = end + SEGMEXEC_TASK_SIZE;
70271 +#endif
70272 +
70273 if (newflags == oldflags) {
70274 *pprev = vma;
70275 return 0;
70276 }
70277
70278 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
70279 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
70280 +
70281 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
70282 + return -ENOMEM;
70283 +
70284 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
70285 + return -ENOMEM;
70286 + }
70287 +
70288 /*
70289 * If we make a private mapping writable we increase our commit;
70290 * but (without finer accounting) cannot reduce our commit if we
70291 @@ -174,6 +240,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
70292 }
70293 }
70294
70295 +#ifdef CONFIG_PAX_SEGMEXEC
70296 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
70297 + if (start != vma->vm_start) {
70298 + error = split_vma(mm, vma, start, 1);
70299 + if (error)
70300 + goto fail;
70301 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
70302 + *pprev = (*pprev)->vm_next;
70303 + }
70304 +
70305 + if (end != vma->vm_end) {
70306 + error = split_vma(mm, vma, end, 0);
70307 + if (error)
70308 + goto fail;
70309 + }
70310 +
70311 + if (pax_find_mirror_vma(vma)) {
70312 + error = __do_munmap(mm, start_m, end_m - start_m);
70313 + if (error)
70314 + goto fail;
70315 + } else {
70316 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
70317 + if (!vma_m) {
70318 + error = -ENOMEM;
70319 + goto fail;
70320 + }
70321 + vma->vm_flags = newflags;
70322 + error = pax_mirror_vma(vma_m, vma);
70323 + if (error) {
70324 + vma->vm_flags = oldflags;
70325 + goto fail;
70326 + }
70327 + }
70328 + }
70329 +#endif
70330 +
70331 /*
70332 * First try to merge with previous and/or next vma.
70333 */
70334 @@ -204,9 +306,21 @@ success:
70335 * vm_flags and vm_page_prot are protected by the mmap_sem
70336 * held in write mode.
70337 */
70338 +
70339 +#ifdef CONFIG_PAX_SEGMEXEC
70340 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
70341 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
70342 +#endif
70343 +
70344 vma->vm_flags = newflags;
70345 +
70346 +#ifdef CONFIG_PAX_MPROTECT
70347 + if (mm->binfmt && mm->binfmt->handle_mprotect)
70348 + mm->binfmt->handle_mprotect(vma, newflags);
70349 +#endif
70350 +
70351 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
70352 - vm_get_page_prot(newflags));
70353 + vm_get_page_prot(vma->vm_flags));
70354
70355 if (vma_wants_writenotify(vma)) {
70356 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
70357 @@ -248,6 +362,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70358 end = start + len;
70359 if (end <= start)
70360 return -ENOMEM;
70361 +
70362 +#ifdef CONFIG_PAX_SEGMEXEC
70363 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
70364 + if (end > SEGMEXEC_TASK_SIZE)
70365 + return -EINVAL;
70366 + } else
70367 +#endif
70368 +
70369 + if (end > TASK_SIZE)
70370 + return -EINVAL;
70371 +
70372 if (!arch_validate_prot(prot))
70373 return -EINVAL;
70374
70375 @@ -255,7 +380,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70376 /*
70377 * Does the application expect PROT_READ to imply PROT_EXEC:
70378 */
70379 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
70380 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
70381 prot |= PROT_EXEC;
70382
70383 vm_flags = calc_vm_prot_bits(prot);
70384 @@ -287,6 +412,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70385 if (start > vma->vm_start)
70386 prev = vma;
70387
70388 +#ifdef CONFIG_PAX_MPROTECT
70389 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
70390 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
70391 +#endif
70392 +
70393 for (nstart = start ; ; ) {
70394 unsigned long newflags;
70395
70396 @@ -296,6 +426,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70397
70398 /* newflags >> 4 shift VM_MAY% in place of VM_% */
70399 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
70400 + if (prot & (PROT_WRITE | PROT_EXEC))
70401 + gr_log_rwxmprotect(vma->vm_file);
70402 +
70403 + error = -EACCES;
70404 + goto out;
70405 + }
70406 +
70407 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
70408 error = -EACCES;
70409 goto out;
70410 }
70411 @@ -310,6 +448,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
70412 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
70413 if (error)
70414 goto out;
70415 +
70416 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
70417 +
70418 nstart = tmp;
70419
70420 if (nstart < prev->vm_end)
70421 diff --git a/mm/mremap.c b/mm/mremap.c
70422 index d6959cb..18a402a 100644
70423 --- a/mm/mremap.c
70424 +++ b/mm/mremap.c
70425 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
70426 continue;
70427 pte = ptep_get_and_clear(mm, old_addr, old_pte);
70428 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
70429 +
70430 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70431 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
70432 + pte = pte_exprotect(pte);
70433 +#endif
70434 +
70435 set_pte_at(mm, new_addr, new_pte, pte);
70436 }
70437
70438 @@ -290,6 +296,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
70439 if (is_vm_hugetlb_page(vma))
70440 goto Einval;
70441
70442 +#ifdef CONFIG_PAX_SEGMEXEC
70443 + if (pax_find_mirror_vma(vma))
70444 + goto Einval;
70445 +#endif
70446 +
70447 /* We can't remap across vm area boundaries */
70448 if (old_len > vma->vm_end - addr)
70449 goto Efault;
70450 @@ -346,20 +357,25 @@ static unsigned long mremap_to(unsigned long addr,
70451 unsigned long ret = -EINVAL;
70452 unsigned long charged = 0;
70453 unsigned long map_flags;
70454 + unsigned long pax_task_size = TASK_SIZE;
70455
70456 if (new_addr & ~PAGE_MASK)
70457 goto out;
70458
70459 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
70460 +#ifdef CONFIG_PAX_SEGMEXEC
70461 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
70462 + pax_task_size = SEGMEXEC_TASK_SIZE;
70463 +#endif
70464 +
70465 + pax_task_size -= PAGE_SIZE;
70466 +
70467 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
70468 goto out;
70469
70470 /* Check if the location we're moving into overlaps the
70471 * old location at all, and fail if it does.
70472 */
70473 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
70474 - goto out;
70475 -
70476 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
70477 + if (addr + old_len > new_addr && new_addr + new_len > addr)
70478 goto out;
70479
70480 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70481 @@ -431,6 +447,7 @@ unsigned long do_mremap(unsigned long addr,
70482 struct vm_area_struct *vma;
70483 unsigned long ret = -EINVAL;
70484 unsigned long charged = 0;
70485 + unsigned long pax_task_size = TASK_SIZE;
70486
70487 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
70488 goto out;
70489 @@ -449,6 +466,17 @@ unsigned long do_mremap(unsigned long addr,
70490 if (!new_len)
70491 goto out;
70492
70493 +#ifdef CONFIG_PAX_SEGMEXEC
70494 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
70495 + pax_task_size = SEGMEXEC_TASK_SIZE;
70496 +#endif
70497 +
70498 + pax_task_size -= PAGE_SIZE;
70499 +
70500 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
70501 + old_len > pax_task_size || addr > pax_task_size-old_len)
70502 + goto out;
70503 +
70504 if (flags & MREMAP_FIXED) {
70505 if (flags & MREMAP_MAYMOVE)
70506 ret = mremap_to(addr, old_len, new_addr, new_len);
70507 @@ -498,6 +526,7 @@ unsigned long do_mremap(unsigned long addr,
70508 addr + new_len);
70509 }
70510 ret = addr;
70511 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
70512 goto out;
70513 }
70514 }
70515 @@ -524,7 +553,13 @@ unsigned long do_mremap(unsigned long addr,
70516 ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
70517 if (ret)
70518 goto out;
70519 +
70520 + map_flags = vma->vm_flags;
70521 ret = move_vma(vma, addr, old_len, new_len, new_addr);
70522 + if (!(ret & ~PAGE_MASK)) {
70523 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
70524 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
70525 + }
70526 }
70527 out:
70528 if (ret & ~PAGE_MASK)
70529 diff --git a/mm/nobootmem.c b/mm/nobootmem.c
70530 index 7fa41b4..6087460 100644
70531 --- a/mm/nobootmem.c
70532 +++ b/mm/nobootmem.c
70533 @@ -110,19 +110,30 @@ static void __init __free_pages_memory(unsigned long start, unsigned long end)
70534 unsigned long __init free_all_memory_core_early(int nodeid)
70535 {
70536 int i;
70537 - u64 start, end;
70538 + u64 start, end, startrange, endrange;
70539 unsigned long count = 0;
70540 - struct range *range = NULL;
70541 + struct range *range = NULL, rangerange = { 0, 0 };
70542 int nr_range;
70543
70544 nr_range = get_free_all_memory_range(&range, nodeid);
70545 + startrange = __pa(range) >> PAGE_SHIFT;
70546 + endrange = (__pa(range + nr_range) - 1) >> PAGE_SHIFT;
70547
70548 for (i = 0; i < nr_range; i++) {
70549 start = range[i].start;
70550 end = range[i].end;
70551 + if (start <= endrange && startrange < end) {
70552 + BUG_ON(rangerange.start | rangerange.end);
70553 + rangerange = range[i];
70554 + continue;
70555 + }
70556 count += end - start;
70557 __free_pages_memory(start, end);
70558 }
70559 + start = rangerange.start;
70560 + end = rangerange.end;
70561 + count += end - start;
70562 + __free_pages_memory(start, end);
70563
70564 return count;
70565 }
70566 diff --git a/mm/nommu.c b/mm/nommu.c
70567 index b982290..7d73f53 100644
70568 --- a/mm/nommu.c
70569 +++ b/mm/nommu.c
70570 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
70571 int sysctl_overcommit_ratio = 50; /* default is 50% */
70572 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
70573 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
70574 -int heap_stack_gap = 0;
70575
70576 atomic_long_t mmap_pages_allocated;
70577
70578 @@ -825,15 +824,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
70579 EXPORT_SYMBOL(find_vma);
70580
70581 /*
70582 - * find a VMA
70583 - * - we don't extend stack VMAs under NOMMU conditions
70584 - */
70585 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
70586 -{
70587 - return find_vma(mm, addr);
70588 -}
70589 -
70590 -/*
70591 * expand a stack to a given address
70592 * - not supported under NOMMU conditions
70593 */
70594 @@ -1553,6 +1543,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
70595
70596 /* most fields are the same, copy all, and then fixup */
70597 *new = *vma;
70598 + INIT_LIST_HEAD(&new->anon_vma_chain);
70599 *region = *vma->vm_region;
70600 new->vm_region = region;
70601
70602 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
70603 index 485be89..c059ad3 100644
70604 --- a/mm/page_alloc.c
70605 +++ b/mm/page_alloc.c
70606 @@ -341,7 +341,7 @@ out:
70607 * This usage means that zero-order pages may not be compound.
70608 */
70609
70610 -static void free_compound_page(struct page *page)
70611 +void free_compound_page(struct page *page)
70612 {
70613 __free_pages_ok(page, compound_order(page));
70614 }
70615 @@ -654,6 +654,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
70616 int i;
70617 int bad = 0;
70618
70619 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
70620 + unsigned long index = 1UL << order;
70621 +#endif
70622 +
70623 trace_mm_page_free_direct(page, order);
70624 kmemcheck_free_shadow(page, order);
70625
70626 @@ -669,6 +673,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
70627 debug_check_no_obj_freed(page_address(page),
70628 PAGE_SIZE << order);
70629 }
70630 +
70631 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
70632 + for (; index; --index)
70633 + sanitize_highpage(page + index - 1);
70634 +#endif
70635 +
70636 arch_free_page(page, order);
70637 kernel_map_pages(page, 1 << order, 0);
70638
70639 @@ -784,8 +794,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
70640 arch_alloc_page(page, order);
70641 kernel_map_pages(page, 1 << order, 1);
70642
70643 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
70644 if (gfp_flags & __GFP_ZERO)
70645 prep_zero_page(page, order, gfp_flags);
70646 +#endif
70647
70648 if (order && (gfp_flags & __GFP_COMP))
70649 prep_compound_page(page, order);
70650 @@ -3357,7 +3369,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
70651 unsigned long pfn;
70652
70653 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
70654 +#ifdef CONFIG_X86_32
70655 + /* boot failures in VMware 8 on 32bit vanilla since
70656 + this change */
70657 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
70658 +#else
70659 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
70660 +#endif
70661 return 1;
70662 }
70663 return 0;
70664 diff --git a/mm/percpu.c b/mm/percpu.c
70665 index 716eb4a..8d10419 100644
70666 --- a/mm/percpu.c
70667 +++ b/mm/percpu.c
70668 @@ -121,7 +121,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
70669 static unsigned int pcpu_high_unit_cpu __read_mostly;
70670
70671 /* the address of the first chunk which starts with the kernel static area */
70672 -void *pcpu_base_addr __read_mostly;
70673 +void *pcpu_base_addr __read_only;
70674 EXPORT_SYMBOL_GPL(pcpu_base_addr);
70675
70676 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
70677 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
70678 index e920aa3..137702a 100644
70679 --- a/mm/process_vm_access.c
70680 +++ b/mm/process_vm_access.c
70681 @@ -13,6 +13,7 @@
70682 #include <linux/uio.h>
70683 #include <linux/sched.h>
70684 #include <linux/highmem.h>
70685 +#include <linux/security.h>
70686 #include <linux/ptrace.h>
70687 #include <linux/slab.h>
70688 #include <linux/syscalls.h>
70689 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
70690 size_t iov_l_curr_offset = 0;
70691 ssize_t iov_len;
70692
70693 + return -ENOSYS; // PaX: until properly audited
70694 +
70695 /*
70696 * Work out how many pages of struct pages we're going to need
70697 * when eventually calling get_user_pages
70698 */
70699 for (i = 0; i < riovcnt; i++) {
70700 iov_len = rvec[i].iov_len;
70701 - if (iov_len > 0) {
70702 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
70703 - + iov_len)
70704 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
70705 - / PAGE_SIZE + 1;
70706 - nr_pages = max(nr_pages, nr_pages_iov);
70707 - }
70708 + if (iov_len <= 0)
70709 + continue;
70710 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
70711 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
70712 + nr_pages = max(nr_pages, nr_pages_iov);
70713 }
70714
70715 if (nr_pages == 0)
70716 @@ -298,23 +299,23 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
70717 goto free_proc_pages;
70718 }
70719
70720 - task_lock(task);
70721 - if (__ptrace_may_access(task, PTRACE_MODE_ATTACH)) {
70722 - task_unlock(task);
70723 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
70724 rc = -EPERM;
70725 goto put_task_struct;
70726 }
70727 - mm = task->mm;
70728
70729 - if (!mm || (task->flags & PF_KTHREAD)) {
70730 - task_unlock(task);
70731 - rc = -EINVAL;
70732 + mm = mm_access(task, PTRACE_MODE_ATTACH);
70733 + if (!mm || IS_ERR(mm)) {
70734 + rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
70735 + /*
70736 + * Explicitly map EACCES to EPERM as EPERM is a more a
70737 + * appropriate error code for process_vw_readv/writev
70738 + */
70739 + if (rc == -EACCES)
70740 + rc = -EPERM;
70741 goto put_task_struct;
70742 }
70743
70744 - atomic_inc(&mm->mm_users);
70745 - task_unlock(task);
70746 -
70747 for (i = 0; i < riovcnt && iov_l_curr_idx < liovcnt; i++) {
70748 rc = process_vm_rw_single_vec(
70749 (unsigned long)rvec[i].iov_base, rvec[i].iov_len,
70750 diff --git a/mm/rmap.c b/mm/rmap.c
70751 index a4fd368..e0ffec7 100644
70752 --- a/mm/rmap.c
70753 +++ b/mm/rmap.c
70754 @@ -152,6 +152,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70755 struct anon_vma *anon_vma = vma->anon_vma;
70756 struct anon_vma_chain *avc;
70757
70758 +#ifdef CONFIG_PAX_SEGMEXEC
70759 + struct anon_vma_chain *avc_m = NULL;
70760 +#endif
70761 +
70762 might_sleep();
70763 if (unlikely(!anon_vma)) {
70764 struct mm_struct *mm = vma->vm_mm;
70765 @@ -161,6 +165,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70766 if (!avc)
70767 goto out_enomem;
70768
70769 +#ifdef CONFIG_PAX_SEGMEXEC
70770 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
70771 + if (!avc_m)
70772 + goto out_enomem_free_avc;
70773 +#endif
70774 +
70775 anon_vma = find_mergeable_anon_vma(vma);
70776 allocated = NULL;
70777 if (!anon_vma) {
70778 @@ -174,6 +184,21 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70779 /* page_table_lock to protect against threads */
70780 spin_lock(&mm->page_table_lock);
70781 if (likely(!vma->anon_vma)) {
70782 +
70783 +#ifdef CONFIG_PAX_SEGMEXEC
70784 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
70785 +
70786 + if (vma_m) {
70787 + BUG_ON(vma_m->anon_vma);
70788 + vma_m->anon_vma = anon_vma;
70789 + avc_m->anon_vma = anon_vma;
70790 + avc_m->vma = vma;
70791 + list_add(&avc_m->same_vma, &vma_m->anon_vma_chain);
70792 + list_add(&avc_m->same_anon_vma, &anon_vma->head);
70793 + avc_m = NULL;
70794 + }
70795 +#endif
70796 +
70797 vma->anon_vma = anon_vma;
70798 avc->anon_vma = anon_vma;
70799 avc->vma = vma;
70800 @@ -187,12 +212,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
70801
70802 if (unlikely(allocated))
70803 put_anon_vma(allocated);
70804 +
70805 +#ifdef CONFIG_PAX_SEGMEXEC
70806 + if (unlikely(avc_m))
70807 + anon_vma_chain_free(avc_m);
70808 +#endif
70809 +
70810 if (unlikely(avc))
70811 anon_vma_chain_free(avc);
70812 }
70813 return 0;
70814
70815 out_enomem_free_avc:
70816 +
70817 +#ifdef CONFIG_PAX_SEGMEXEC
70818 + if (avc_m)
70819 + anon_vma_chain_free(avc_m);
70820 +#endif
70821 +
70822 anon_vma_chain_free(avc);
70823 out_enomem:
70824 return -ENOMEM;
70825 @@ -243,7 +280,7 @@ static void anon_vma_chain_link(struct vm_area_struct *vma,
70826 * Attach the anon_vmas from src to dst.
70827 * Returns 0 on success, -ENOMEM on failure.
70828 */
70829 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
70830 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
70831 {
70832 struct anon_vma_chain *avc, *pavc;
70833 struct anon_vma *root = NULL;
70834 @@ -276,7 +313,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
70835 * the corresponding VMA in the parent process is attached to.
70836 * Returns 0 on success, non-zero on failure.
70837 */
70838 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
70839 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
70840 {
70841 struct anon_vma_chain *avc;
70842 struct anon_vma *anon_vma;
70843 diff --git a/mm/shmem.c b/mm/shmem.c
70844 index 6c253f7..367e20a 100644
70845 --- a/mm/shmem.c
70846 +++ b/mm/shmem.c
70847 @@ -31,7 +31,7 @@
70848 #include <linux/export.h>
70849 #include <linux/swap.h>
70850
70851 -static struct vfsmount *shm_mnt;
70852 +struct vfsmount *shm_mnt;
70853
70854 #ifdef CONFIG_SHMEM
70855 /*
70856 @@ -74,7 +74,7 @@ static struct vfsmount *shm_mnt;
70857 #define BOGO_DIRENT_SIZE 20
70858
70859 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
70860 -#define SHORT_SYMLINK_LEN 128
70861 +#define SHORT_SYMLINK_LEN 64
70862
70863 struct shmem_xattr {
70864 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
70865 @@ -2180,8 +2180,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
70866 int err = -ENOMEM;
70867
70868 /* Round up to L1_CACHE_BYTES to resist false sharing */
70869 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
70870 - L1_CACHE_BYTES), GFP_KERNEL);
70871 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
70872 if (!sbinfo)
70873 return -ENOMEM;
70874
70875 diff --git a/mm/slab.c b/mm/slab.c
70876 index 83311c9a..fcf8f86 100644
70877 --- a/mm/slab.c
70878 +++ b/mm/slab.c
70879 @@ -151,7 +151,7 @@
70880
70881 /* Legal flag mask for kmem_cache_create(). */
70882 #if DEBUG
70883 -# define CREATE_MASK (SLAB_RED_ZONE | \
70884 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
70885 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
70886 SLAB_CACHE_DMA | \
70887 SLAB_STORE_USER | \
70888 @@ -159,7 +159,7 @@
70889 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
70890 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
70891 #else
70892 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
70893 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
70894 SLAB_CACHE_DMA | \
70895 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
70896 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
70897 @@ -288,7 +288,7 @@ struct kmem_list3 {
70898 * Need this for bootstrapping a per node allocator.
70899 */
70900 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
70901 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
70902 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
70903 #define CACHE_CACHE 0
70904 #define SIZE_AC MAX_NUMNODES
70905 #define SIZE_L3 (2 * MAX_NUMNODES)
70906 @@ -389,10 +389,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
70907 if ((x)->max_freeable < i) \
70908 (x)->max_freeable = i; \
70909 } while (0)
70910 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
70911 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
70912 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
70913 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
70914 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
70915 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
70916 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
70917 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
70918 #else
70919 #define STATS_INC_ACTIVE(x) do { } while (0)
70920 #define STATS_DEC_ACTIVE(x) do { } while (0)
70921 @@ -538,7 +538,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
70922 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
70923 */
70924 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
70925 - const struct slab *slab, void *obj)
70926 + const struct slab *slab, const void *obj)
70927 {
70928 u32 offset = (obj - slab->s_mem);
70929 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
70930 @@ -564,7 +564,7 @@ struct cache_names {
70931 static struct cache_names __initdata cache_names[] = {
70932 #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
70933 #include <linux/kmalloc_sizes.h>
70934 - {NULL,}
70935 + {NULL}
70936 #undef CACHE
70937 };
70938
70939 @@ -1572,7 +1572,7 @@ void __init kmem_cache_init(void)
70940 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
70941 sizes[INDEX_AC].cs_size,
70942 ARCH_KMALLOC_MINALIGN,
70943 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70944 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70945 NULL);
70946
70947 if (INDEX_AC != INDEX_L3) {
70948 @@ -1580,7 +1580,7 @@ void __init kmem_cache_init(void)
70949 kmem_cache_create(names[INDEX_L3].name,
70950 sizes[INDEX_L3].cs_size,
70951 ARCH_KMALLOC_MINALIGN,
70952 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70953 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70954 NULL);
70955 }
70956
70957 @@ -1598,7 +1598,7 @@ void __init kmem_cache_init(void)
70958 sizes->cs_cachep = kmem_cache_create(names->name,
70959 sizes->cs_size,
70960 ARCH_KMALLOC_MINALIGN,
70961 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
70962 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
70963 NULL);
70964 }
70965 #ifdef CONFIG_ZONE_DMA
70966 @@ -4322,10 +4322,10 @@ static int s_show(struct seq_file *m, void *p)
70967 }
70968 /* cpu stats */
70969 {
70970 - unsigned long allochit = atomic_read(&cachep->allochit);
70971 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
70972 - unsigned long freehit = atomic_read(&cachep->freehit);
70973 - unsigned long freemiss = atomic_read(&cachep->freemiss);
70974 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
70975 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
70976 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
70977 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
70978
70979 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
70980 allochit, allocmiss, freehit, freemiss);
70981 @@ -4584,13 +4584,62 @@ static int __init slab_proc_init(void)
70982 {
70983 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
70984 #ifdef CONFIG_DEBUG_SLAB_LEAK
70985 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
70986 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
70987 #endif
70988 return 0;
70989 }
70990 module_init(slab_proc_init);
70991 #endif
70992
70993 +void check_object_size(const void *ptr, unsigned long n, bool to)
70994 +{
70995 +
70996 +#ifdef CONFIG_PAX_USERCOPY
70997 + struct page *page;
70998 + struct kmem_cache *cachep = NULL;
70999 + struct slab *slabp;
71000 + unsigned int objnr;
71001 + unsigned long offset;
71002 + const char *type;
71003 +
71004 + if (!n)
71005 + return;
71006 +
71007 + type = "<null>";
71008 + if (ZERO_OR_NULL_PTR(ptr))
71009 + goto report;
71010 +
71011 + if (!virt_addr_valid(ptr))
71012 + return;
71013 +
71014 + page = virt_to_head_page(ptr);
71015 +
71016 + type = "<process stack>";
71017 + if (!PageSlab(page)) {
71018 + if (object_is_on_stack(ptr, n) == -1)
71019 + goto report;
71020 + return;
71021 + }
71022 +
71023 + cachep = page_get_cache(page);
71024 + type = cachep->name;
71025 + if (!(cachep->flags & SLAB_USERCOPY))
71026 + goto report;
71027 +
71028 + slabp = page_get_slab(page);
71029 + objnr = obj_to_index(cachep, slabp, ptr);
71030 + BUG_ON(objnr >= cachep->num);
71031 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
71032 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
71033 + return;
71034 +
71035 +report:
71036 + pax_report_usercopy(ptr, n, to, type);
71037 +#endif
71038 +
71039 +}
71040 +EXPORT_SYMBOL(check_object_size);
71041 +
71042 /**
71043 * ksize - get the actual amount of memory allocated for a given object
71044 * @objp: Pointer to the object
71045 diff --git a/mm/slob.c b/mm/slob.c
71046 index 8105be4..e045f96 100644
71047 --- a/mm/slob.c
71048 +++ b/mm/slob.c
71049 @@ -29,7 +29,7 @@
71050 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
71051 * alloc_pages() directly, allocating compound pages so the page order
71052 * does not have to be separately tracked, and also stores the exact
71053 - * allocation size in page->private so that it can be used to accurately
71054 + * allocation size in slob_page->size so that it can be used to accurately
71055 * provide ksize(). These objects are detected in kfree() because slob_page()
71056 * is false for them.
71057 *
71058 @@ -58,6 +58,7 @@
71059 */
71060
71061 #include <linux/kernel.h>
71062 +#include <linux/sched.h>
71063 #include <linux/slab.h>
71064 #include <linux/mm.h>
71065 #include <linux/swap.h> /* struct reclaim_state */
71066 @@ -102,7 +103,8 @@ struct slob_page {
71067 unsigned long flags; /* mandatory */
71068 atomic_t _count; /* mandatory */
71069 slobidx_t units; /* free units left in page */
71070 - unsigned long pad[2];
71071 + unsigned long pad[1];
71072 + unsigned long size; /* size when >=PAGE_SIZE */
71073 slob_t *free; /* first free slob_t in page */
71074 struct list_head list; /* linked list of free pages */
71075 };
71076 @@ -135,7 +137,7 @@ static LIST_HEAD(free_slob_large);
71077 */
71078 static inline int is_slob_page(struct slob_page *sp)
71079 {
71080 - return PageSlab((struct page *)sp);
71081 + return PageSlab((struct page *)sp) && !sp->size;
71082 }
71083
71084 static inline void set_slob_page(struct slob_page *sp)
71085 @@ -150,7 +152,7 @@ static inline void clear_slob_page(struct slob_page *sp)
71086
71087 static inline struct slob_page *slob_page(const void *addr)
71088 {
71089 - return (struct slob_page *)virt_to_page(addr);
71090 + return (struct slob_page *)virt_to_head_page(addr);
71091 }
71092
71093 /*
71094 @@ -210,7 +212,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
71095 /*
71096 * Return the size of a slob block.
71097 */
71098 -static slobidx_t slob_units(slob_t *s)
71099 +static slobidx_t slob_units(const slob_t *s)
71100 {
71101 if (s->units > 0)
71102 return s->units;
71103 @@ -220,7 +222,7 @@ static slobidx_t slob_units(slob_t *s)
71104 /*
71105 * Return the next free slob block pointer after this one.
71106 */
71107 -static slob_t *slob_next(slob_t *s)
71108 +static slob_t *slob_next(const slob_t *s)
71109 {
71110 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
71111 slobidx_t next;
71112 @@ -235,7 +237,7 @@ static slob_t *slob_next(slob_t *s)
71113 /*
71114 * Returns true if s is the last free block in its page.
71115 */
71116 -static int slob_last(slob_t *s)
71117 +static int slob_last(const slob_t *s)
71118 {
71119 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
71120 }
71121 @@ -254,6 +256,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
71122 if (!page)
71123 return NULL;
71124
71125 + set_slob_page(page);
71126 return page_address(page);
71127 }
71128
71129 @@ -370,11 +373,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
71130 if (!b)
71131 return NULL;
71132 sp = slob_page(b);
71133 - set_slob_page(sp);
71134
71135 spin_lock_irqsave(&slob_lock, flags);
71136 sp->units = SLOB_UNITS(PAGE_SIZE);
71137 sp->free = b;
71138 + sp->size = 0;
71139 INIT_LIST_HEAD(&sp->list);
71140 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
71141 set_slob_page_free(sp, slob_list);
71142 @@ -476,10 +479,9 @@ out:
71143 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
71144 */
71145
71146 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
71147 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
71148 {
71149 - unsigned int *m;
71150 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71151 + slob_t *m;
71152 void *ret;
71153
71154 gfp &= gfp_allowed_mask;
71155 @@ -494,7 +496,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
71156
71157 if (!m)
71158 return NULL;
71159 - *m = size;
71160 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
71161 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
71162 + m[0].units = size;
71163 + m[1].units = align;
71164 ret = (void *)m + align;
71165
71166 trace_kmalloc_node(_RET_IP_, ret,
71167 @@ -506,16 +511,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
71168 gfp |= __GFP_COMP;
71169 ret = slob_new_pages(gfp, order, node);
71170 if (ret) {
71171 - struct page *page;
71172 - page = virt_to_page(ret);
71173 - page->private = size;
71174 + struct slob_page *sp;
71175 + sp = slob_page(ret);
71176 + sp->size = size;
71177 }
71178
71179 trace_kmalloc_node(_RET_IP_, ret,
71180 size, PAGE_SIZE << order, gfp, node);
71181 }
71182
71183 - kmemleak_alloc(ret, size, 1, gfp);
71184 + return ret;
71185 +}
71186 +
71187 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
71188 +{
71189 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71190 + void *ret = __kmalloc_node_align(size, gfp, node, align);
71191 +
71192 + if (!ZERO_OR_NULL_PTR(ret))
71193 + kmemleak_alloc(ret, size, 1, gfp);
71194 return ret;
71195 }
71196 EXPORT_SYMBOL(__kmalloc_node);
71197 @@ -533,13 +547,92 @@ void kfree(const void *block)
71198 sp = slob_page(block);
71199 if (is_slob_page(sp)) {
71200 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71201 - unsigned int *m = (unsigned int *)(block - align);
71202 - slob_free(m, *m + align);
71203 - } else
71204 + slob_t *m = (slob_t *)(block - align);
71205 + slob_free(m, m[0].units + align);
71206 + } else {
71207 + clear_slob_page(sp);
71208 + free_slob_page(sp);
71209 + sp->size = 0;
71210 put_page(&sp->page);
71211 + }
71212 }
71213 EXPORT_SYMBOL(kfree);
71214
71215 +void check_object_size(const void *ptr, unsigned long n, bool to)
71216 +{
71217 +
71218 +#ifdef CONFIG_PAX_USERCOPY
71219 + struct slob_page *sp;
71220 + const slob_t *free;
71221 + const void *base;
71222 + unsigned long flags;
71223 + const char *type;
71224 +
71225 + if (!n)
71226 + return;
71227 +
71228 + type = "<null>";
71229 + if (ZERO_OR_NULL_PTR(ptr))
71230 + goto report;
71231 +
71232 + if (!virt_addr_valid(ptr))
71233 + return;
71234 +
71235 + type = "<process stack>";
71236 + sp = slob_page(ptr);
71237 + if (!PageSlab((struct page *)sp)) {
71238 + if (object_is_on_stack(ptr, n) == -1)
71239 + goto report;
71240 + return;
71241 + }
71242 +
71243 + type = "<slob>";
71244 + if (sp->size) {
71245 + base = page_address(&sp->page);
71246 + if (base <= ptr && n <= sp->size - (ptr - base))
71247 + return;
71248 + goto report;
71249 + }
71250 +
71251 + /* some tricky double walking to find the chunk */
71252 + spin_lock_irqsave(&slob_lock, flags);
71253 + base = (void *)((unsigned long)ptr & PAGE_MASK);
71254 + free = sp->free;
71255 +
71256 + while (!slob_last(free) && (void *)free <= ptr) {
71257 + base = free + slob_units(free);
71258 + free = slob_next(free);
71259 + }
71260 +
71261 + while (base < (void *)free) {
71262 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
71263 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
71264 + int offset;
71265 +
71266 + if (ptr < base + align)
71267 + break;
71268 +
71269 + offset = ptr - base - align;
71270 + if (offset >= m) {
71271 + base += size;
71272 + continue;
71273 + }
71274 +
71275 + if (n > m - offset)
71276 + break;
71277 +
71278 + spin_unlock_irqrestore(&slob_lock, flags);
71279 + return;
71280 + }
71281 +
71282 + spin_unlock_irqrestore(&slob_lock, flags);
71283 +report:
71284 + pax_report_usercopy(ptr, n, to, type);
71285 +#endif
71286 +
71287 +}
71288 +EXPORT_SYMBOL(check_object_size);
71289 +
71290 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
71291 size_t ksize(const void *block)
71292 {
71293 @@ -552,10 +645,10 @@ size_t ksize(const void *block)
71294 sp = slob_page(block);
71295 if (is_slob_page(sp)) {
71296 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
71297 - unsigned int *m = (unsigned int *)(block - align);
71298 - return SLOB_UNITS(*m) * SLOB_UNIT;
71299 + slob_t *m = (slob_t *)(block - align);
71300 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
71301 } else
71302 - return sp->page.private;
71303 + return sp->size;
71304 }
71305 EXPORT_SYMBOL(ksize);
71306
71307 @@ -571,8 +664,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71308 {
71309 struct kmem_cache *c;
71310
71311 +#ifdef CONFIG_PAX_USERCOPY
71312 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
71313 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
71314 +#else
71315 c = slob_alloc(sizeof(struct kmem_cache),
71316 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
71317 +#endif
71318
71319 if (c) {
71320 c->name = name;
71321 @@ -614,17 +712,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
71322
71323 lockdep_trace_alloc(flags);
71324
71325 +#ifdef CONFIG_PAX_USERCOPY
71326 + b = __kmalloc_node_align(c->size, flags, node, c->align);
71327 +#else
71328 if (c->size < PAGE_SIZE) {
71329 b = slob_alloc(c->size, flags, c->align, node);
71330 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
71331 SLOB_UNITS(c->size) * SLOB_UNIT,
71332 flags, node);
71333 } else {
71334 + struct slob_page *sp;
71335 +
71336 b = slob_new_pages(flags, get_order(c->size), node);
71337 + sp = slob_page(b);
71338 + sp->size = c->size;
71339 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
71340 PAGE_SIZE << get_order(c->size),
71341 flags, node);
71342 }
71343 +#endif
71344
71345 if (c->ctor)
71346 c->ctor(b);
71347 @@ -636,10 +742,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
71348
71349 static void __kmem_cache_free(void *b, int size)
71350 {
71351 - if (size < PAGE_SIZE)
71352 + struct slob_page *sp = slob_page(b);
71353 +
71354 + if (is_slob_page(sp))
71355 slob_free(b, size);
71356 - else
71357 + else {
71358 + clear_slob_page(sp);
71359 + free_slob_page(sp);
71360 + sp->size = 0;
71361 slob_free_pages(b, get_order(size));
71362 + }
71363 }
71364
71365 static void kmem_rcu_free(struct rcu_head *head)
71366 @@ -652,17 +764,31 @@ static void kmem_rcu_free(struct rcu_head *head)
71367
71368 void kmem_cache_free(struct kmem_cache *c, void *b)
71369 {
71370 + int size = c->size;
71371 +
71372 +#ifdef CONFIG_PAX_USERCOPY
71373 + if (size + c->align < PAGE_SIZE) {
71374 + size += c->align;
71375 + b -= c->align;
71376 + }
71377 +#endif
71378 +
71379 kmemleak_free_recursive(b, c->flags);
71380 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
71381 struct slob_rcu *slob_rcu;
71382 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
71383 - slob_rcu->size = c->size;
71384 + slob_rcu = b + (size - sizeof(struct slob_rcu));
71385 + slob_rcu->size = size;
71386 call_rcu(&slob_rcu->head, kmem_rcu_free);
71387 } else {
71388 - __kmem_cache_free(b, c->size);
71389 + __kmem_cache_free(b, size);
71390 }
71391
71392 +#ifdef CONFIG_PAX_USERCOPY
71393 + trace_kfree(_RET_IP_, b);
71394 +#else
71395 trace_kmem_cache_free(_RET_IP_, b);
71396 +#endif
71397 +
71398 }
71399 EXPORT_SYMBOL(kmem_cache_free);
71400
71401 diff --git a/mm/slub.c b/mm/slub.c
71402 index 1a919f0..1739c9b 100644
71403 --- a/mm/slub.c
71404 +++ b/mm/slub.c
71405 @@ -208,7 +208,7 @@ struct track {
71406
71407 enum track_item { TRACK_ALLOC, TRACK_FREE };
71408
71409 -#ifdef CONFIG_SYSFS
71410 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71411 static int sysfs_slab_add(struct kmem_cache *);
71412 static int sysfs_slab_alias(struct kmem_cache *, const char *);
71413 static void sysfs_slab_remove(struct kmem_cache *);
71414 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
71415 if (!t->addr)
71416 return;
71417
71418 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
71419 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
71420 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
71421 #ifdef CONFIG_STACKTRACE
71422 {
71423 @@ -2559,6 +2559,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
71424
71425 page = virt_to_head_page(x);
71426
71427 + BUG_ON(!PageSlab(page));
71428 +
71429 slab_free(s, page, x, _RET_IP_);
71430
71431 trace_kmem_cache_free(_RET_IP_, x);
71432 @@ -2592,7 +2594,7 @@ static int slub_min_objects;
71433 * Merge control. If this is set then no merging of slab caches will occur.
71434 * (Could be removed. This was introduced to pacify the merge skeptics.)
71435 */
71436 -static int slub_nomerge;
71437 +static int slub_nomerge = 1;
71438
71439 /*
71440 * Calculate the order of allocation given an slab object size.
71441 @@ -3042,7 +3044,7 @@ static int kmem_cache_open(struct kmem_cache *s,
71442 else
71443 s->cpu_partial = 30;
71444
71445 - s->refcount = 1;
71446 + atomic_set(&s->refcount, 1);
71447 #ifdef CONFIG_NUMA
71448 s->remote_node_defrag_ratio = 1000;
71449 #endif
71450 @@ -3146,8 +3148,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
71451 void kmem_cache_destroy(struct kmem_cache *s)
71452 {
71453 down_write(&slub_lock);
71454 - s->refcount--;
71455 - if (!s->refcount) {
71456 + if (atomic_dec_and_test(&s->refcount)) {
71457 list_del(&s->list);
71458 up_write(&slub_lock);
71459 if (kmem_cache_close(s)) {
71460 @@ -3358,6 +3359,50 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
71461 EXPORT_SYMBOL(__kmalloc_node);
71462 #endif
71463
71464 +void check_object_size(const void *ptr, unsigned long n, bool to)
71465 +{
71466 +
71467 +#ifdef CONFIG_PAX_USERCOPY
71468 + struct page *page;
71469 + struct kmem_cache *s = NULL;
71470 + unsigned long offset;
71471 + const char *type;
71472 +
71473 + if (!n)
71474 + return;
71475 +
71476 + type = "<null>";
71477 + if (ZERO_OR_NULL_PTR(ptr))
71478 + goto report;
71479 +
71480 + if (!virt_addr_valid(ptr))
71481 + return;
71482 +
71483 + page = virt_to_head_page(ptr);
71484 +
71485 + type = "<process stack>";
71486 + if (!PageSlab(page)) {
71487 + if (object_is_on_stack(ptr, n) == -1)
71488 + goto report;
71489 + return;
71490 + }
71491 +
71492 + s = page->slab;
71493 + type = s->name;
71494 + if (!(s->flags & SLAB_USERCOPY))
71495 + goto report;
71496 +
71497 + offset = (ptr - page_address(page)) % s->size;
71498 + if (offset <= s->objsize && n <= s->objsize - offset)
71499 + return;
71500 +
71501 +report:
71502 + pax_report_usercopy(ptr, n, to, type);
71503 +#endif
71504 +
71505 +}
71506 +EXPORT_SYMBOL(check_object_size);
71507 +
71508 size_t ksize(const void *object)
71509 {
71510 struct page *page;
71511 @@ -3632,7 +3677,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
71512 int node;
71513
71514 list_add(&s->list, &slab_caches);
71515 - s->refcount = -1;
71516 + atomic_set(&s->refcount, -1);
71517
71518 for_each_node_state(node, N_NORMAL_MEMORY) {
71519 struct kmem_cache_node *n = get_node(s, node);
71520 @@ -3749,17 +3794,17 @@ void __init kmem_cache_init(void)
71521
71522 /* Caches that are not of the two-to-the-power-of size */
71523 if (KMALLOC_MIN_SIZE <= 32) {
71524 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
71525 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
71526 caches++;
71527 }
71528
71529 if (KMALLOC_MIN_SIZE <= 64) {
71530 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
71531 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
71532 caches++;
71533 }
71534
71535 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
71536 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
71537 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
71538 caches++;
71539 }
71540
71541 @@ -3827,7 +3872,7 @@ static int slab_unmergeable(struct kmem_cache *s)
71542 /*
71543 * We may have set a slab to be unmergeable during bootstrap.
71544 */
71545 - if (s->refcount < 0)
71546 + if (atomic_read(&s->refcount) < 0)
71547 return 1;
71548
71549 return 0;
71550 @@ -3886,7 +3931,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71551 down_write(&slub_lock);
71552 s = find_mergeable(size, align, flags, name, ctor);
71553 if (s) {
71554 - s->refcount++;
71555 + atomic_inc(&s->refcount);
71556 /*
71557 * Adjust the object sizes so that we clear
71558 * the complete object on kzalloc.
71559 @@ -3895,7 +3940,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
71560 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
71561
71562 if (sysfs_slab_alias(s, name)) {
71563 - s->refcount--;
71564 + atomic_dec(&s->refcount);
71565 goto err;
71566 }
71567 up_write(&slub_lock);
71568 @@ -4023,7 +4068,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
71569 }
71570 #endif
71571
71572 -#ifdef CONFIG_SYSFS
71573 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71574 static int count_inuse(struct page *page)
71575 {
71576 return page->inuse;
71577 @@ -4410,12 +4455,12 @@ static void resiliency_test(void)
71578 validate_slab_cache(kmalloc_caches[9]);
71579 }
71580 #else
71581 -#ifdef CONFIG_SYSFS
71582 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71583 static void resiliency_test(void) {};
71584 #endif
71585 #endif
71586
71587 -#ifdef CONFIG_SYSFS
71588 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71589 enum slab_stat_type {
71590 SL_ALL, /* All slabs */
71591 SL_PARTIAL, /* Only partially allocated slabs */
71592 @@ -4656,7 +4701,7 @@ SLAB_ATTR_RO(ctor);
71593
71594 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
71595 {
71596 - return sprintf(buf, "%d\n", s->refcount - 1);
71597 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
71598 }
71599 SLAB_ATTR_RO(aliases);
71600
71601 @@ -5223,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
71602 return name;
71603 }
71604
71605 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71606 static int sysfs_slab_add(struct kmem_cache *s)
71607 {
71608 int err;
71609 @@ -5285,6 +5331,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
71610 kobject_del(&s->kobj);
71611 kobject_put(&s->kobj);
71612 }
71613 +#endif
71614
71615 /*
71616 * Need to buffer aliases during bootup until sysfs becomes
71617 @@ -5298,6 +5345,7 @@ struct saved_alias {
71618
71619 static struct saved_alias *alias_list;
71620
71621 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
71622 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
71623 {
71624 struct saved_alias *al;
71625 @@ -5320,6 +5368,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
71626 alias_list = al;
71627 return 0;
71628 }
71629 +#endif
71630
71631 static int __init slab_sysfs_init(void)
71632 {
71633 diff --git a/mm/swap.c b/mm/swap.c
71634 index 55b266d..a532537 100644
71635 --- a/mm/swap.c
71636 +++ b/mm/swap.c
71637 @@ -31,6 +31,7 @@
71638 #include <linux/backing-dev.h>
71639 #include <linux/memcontrol.h>
71640 #include <linux/gfp.h>
71641 +#include <linux/hugetlb.h>
71642
71643 #include "internal.h"
71644
71645 @@ -71,6 +72,8 @@ static void __put_compound_page(struct page *page)
71646
71647 __page_cache_release(page);
71648 dtor = get_compound_page_dtor(page);
71649 + if (!PageHuge(page))
71650 + BUG_ON(dtor != free_compound_page);
71651 (*dtor)(page);
71652 }
71653
71654 diff --git a/mm/swapfile.c b/mm/swapfile.c
71655 index b1cd120..aaae885 100644
71656 --- a/mm/swapfile.c
71657 +++ b/mm/swapfile.c
71658 @@ -61,7 +61,7 @@ static DEFINE_MUTEX(swapon_mutex);
71659
71660 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
71661 /* Activity counter to indicate that a swapon or swapoff has occurred */
71662 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
71663 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
71664
71665 static inline unsigned char swap_count(unsigned char ent)
71666 {
71667 @@ -1670,7 +1670,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
71668 }
71669 filp_close(swap_file, NULL);
71670 err = 0;
71671 - atomic_inc(&proc_poll_event);
71672 + atomic_inc_unchecked(&proc_poll_event);
71673 wake_up_interruptible(&proc_poll_wait);
71674
71675 out_dput:
71676 @@ -1686,8 +1686,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
71677
71678 poll_wait(file, &proc_poll_wait, wait);
71679
71680 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
71681 - seq->poll_event = atomic_read(&proc_poll_event);
71682 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
71683 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
71684 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
71685 }
71686
71687 @@ -1785,7 +1785,7 @@ static int swaps_open(struct inode *inode, struct file *file)
71688 return ret;
71689
71690 seq = file->private_data;
71691 - seq->poll_event = atomic_read(&proc_poll_event);
71692 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
71693 return 0;
71694 }
71695
71696 @@ -2123,7 +2123,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
71697 (p->flags & SWP_DISCARDABLE) ? "D" : "");
71698
71699 mutex_unlock(&swapon_mutex);
71700 - atomic_inc(&proc_poll_event);
71701 + atomic_inc_unchecked(&proc_poll_event);
71702 wake_up_interruptible(&proc_poll_wait);
71703
71704 if (S_ISREG(inode->i_mode))
71705 diff --git a/mm/util.c b/mm/util.c
71706 index 136ac4f..5117eef 100644
71707 --- a/mm/util.c
71708 +++ b/mm/util.c
71709 @@ -114,6 +114,7 @@ EXPORT_SYMBOL(memdup_user);
71710 * allocated buffer. Use this if you don't want to free the buffer immediately
71711 * like, for example, with RCU.
71712 */
71713 +#undef __krealloc
71714 void *__krealloc(const void *p, size_t new_size, gfp_t flags)
71715 {
71716 void *ret;
71717 @@ -147,6 +148,7 @@ EXPORT_SYMBOL(__krealloc);
71718 * behaves exactly like kmalloc(). If @size is 0 and @p is not a
71719 * %NULL pointer, the object pointed to is freed.
71720 */
71721 +#undef krealloc
71722 void *krealloc(const void *p, size_t new_size, gfp_t flags)
71723 {
71724 void *ret;
71725 @@ -243,6 +245,12 @@ void __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma,
71726 void arch_pick_mmap_layout(struct mm_struct *mm)
71727 {
71728 mm->mmap_base = TASK_UNMAPPED_BASE;
71729 +
71730 +#ifdef CONFIG_PAX_RANDMMAP
71731 + if (mm->pax_flags & MF_PAX_RANDMMAP)
71732 + mm->mmap_base += mm->delta_mmap;
71733 +#endif
71734 +
71735 mm->get_unmapped_area = arch_get_unmapped_area;
71736 mm->unmap_area = arch_unmap_area;
71737 }
71738 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
71739 index 27be2f0..0aef2c2 100644
71740 --- a/mm/vmalloc.c
71741 +++ b/mm/vmalloc.c
71742 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
71743
71744 pte = pte_offset_kernel(pmd, addr);
71745 do {
71746 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71747 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71748 +
71749 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71750 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
71751 + BUG_ON(!pte_exec(*pte));
71752 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
71753 + continue;
71754 + }
71755 +#endif
71756 +
71757 + {
71758 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
71759 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
71760 + }
71761 } while (pte++, addr += PAGE_SIZE, addr != end);
71762 }
71763
71764 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
71765 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
71766 {
71767 pte_t *pte;
71768 + int ret = -ENOMEM;
71769
71770 /*
71771 * nr is a running index into the array which helps higher level
71772 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
71773 pte = pte_alloc_kernel(pmd, addr);
71774 if (!pte)
71775 return -ENOMEM;
71776 +
71777 + pax_open_kernel();
71778 do {
71779 struct page *page = pages[*nr];
71780
71781 - if (WARN_ON(!pte_none(*pte)))
71782 - return -EBUSY;
71783 - if (WARN_ON(!page))
71784 - return -ENOMEM;
71785 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71786 + if (pgprot_val(prot) & _PAGE_NX)
71787 +#endif
71788 +
71789 + if (WARN_ON(!pte_none(*pte))) {
71790 + ret = -EBUSY;
71791 + goto out;
71792 + }
71793 + if (WARN_ON(!page)) {
71794 + ret = -ENOMEM;
71795 + goto out;
71796 + }
71797 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
71798 (*nr)++;
71799 } while (pte++, addr += PAGE_SIZE, addr != end);
71800 - return 0;
71801 + ret = 0;
71802 +out:
71803 + pax_close_kernel();
71804 + return ret;
71805 }
71806
71807 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
71808 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
71809 * and fall back on vmalloc() if that fails. Others
71810 * just put it in the vmalloc space.
71811 */
71812 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
71813 +#ifdef CONFIG_MODULES
71814 +#ifdef MODULES_VADDR
71815 unsigned long addr = (unsigned long)x;
71816 if (addr >= MODULES_VADDR && addr < MODULES_END)
71817 return 1;
71818 #endif
71819 +
71820 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
71821 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
71822 + return 1;
71823 +#endif
71824 +
71825 +#endif
71826 +
71827 return is_vmalloc_addr(x);
71828 }
71829
71830 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
71831
71832 if (!pgd_none(*pgd)) {
71833 pud_t *pud = pud_offset(pgd, addr);
71834 +#ifdef CONFIG_X86
71835 + if (!pud_large(*pud))
71836 +#endif
71837 if (!pud_none(*pud)) {
71838 pmd_t *pmd = pmd_offset(pud, addr);
71839 +#ifdef CONFIG_X86
71840 + if (!pmd_large(*pmd))
71841 +#endif
71842 if (!pmd_none(*pmd)) {
71843 pte_t *ptep, pte;
71844
71845 @@ -1294,6 +1334,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
71846 struct vm_struct *area;
71847
71848 BUG_ON(in_interrupt());
71849 +
71850 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71851 + if (flags & VM_KERNEXEC) {
71852 + if (start != VMALLOC_START || end != VMALLOC_END)
71853 + return NULL;
71854 + start = (unsigned long)MODULES_EXEC_VADDR;
71855 + end = (unsigned long)MODULES_EXEC_END;
71856 + }
71857 +#endif
71858 +
71859 if (flags & VM_IOREMAP) {
71860 int bit = fls(size);
71861
71862 @@ -1526,6 +1576,11 @@ void *vmap(struct page **pages, unsigned int count,
71863 if (count > totalram_pages)
71864 return NULL;
71865
71866 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71867 + if (!(pgprot_val(prot) & _PAGE_NX))
71868 + flags |= VM_KERNEXEC;
71869 +#endif
71870 +
71871 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
71872 __builtin_return_address(0));
71873 if (!area)
71874 @@ -1627,6 +1682,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
71875 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
71876 goto fail;
71877
71878 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
71879 + if (!(pgprot_val(prot) & _PAGE_NX))
71880 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
71881 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
71882 + else
71883 +#endif
71884 +
71885 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
71886 start, end, node, gfp_mask, caller);
71887 if (!area)
71888 @@ -1679,6 +1741,7 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
71889 gfp_mask, prot, node, caller);
71890 }
71891
71892 +#undef __vmalloc
71893 void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot)
71894 {
71895 return __vmalloc_node(size, 1, gfp_mask, prot, -1,
71896 @@ -1702,6 +1765,7 @@ static inline void *__vmalloc_node_flags(unsigned long size,
71897 * For tight control over page level allocator and protection flags
71898 * use __vmalloc() instead.
71899 */
71900 +#undef vmalloc
71901 void *vmalloc(unsigned long size)
71902 {
71903 return __vmalloc_node_flags(size, -1, GFP_KERNEL | __GFP_HIGHMEM);
71904 @@ -1718,6 +1782,7 @@ EXPORT_SYMBOL(vmalloc);
71905 * For tight control over page level allocator and protection flags
71906 * use __vmalloc() instead.
71907 */
71908 +#undef vzalloc
71909 void *vzalloc(unsigned long size)
71910 {
71911 return __vmalloc_node_flags(size, -1,
71912 @@ -1732,6 +1797,7 @@ EXPORT_SYMBOL(vzalloc);
71913 * The resulting memory area is zeroed so it can be mapped to userspace
71914 * without leaking data.
71915 */
71916 +#undef vmalloc_user
71917 void *vmalloc_user(unsigned long size)
71918 {
71919 struct vm_struct *area;
71920 @@ -1759,6 +1825,7 @@ EXPORT_SYMBOL(vmalloc_user);
71921 * For tight control over page level allocator and protection flags
71922 * use __vmalloc() instead.
71923 */
71924 +#undef vmalloc_node
71925 void *vmalloc_node(unsigned long size, int node)
71926 {
71927 return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL,
71928 @@ -1778,6 +1845,7 @@ EXPORT_SYMBOL(vmalloc_node);
71929 * For tight control over page level allocator and protection flags
71930 * use __vmalloc_node() instead.
71931 */
71932 +#undef vzalloc_node
71933 void *vzalloc_node(unsigned long size, int node)
71934 {
71935 return __vmalloc_node_flags(size, node,
71936 @@ -1800,10 +1868,10 @@ EXPORT_SYMBOL(vzalloc_node);
71937 * For tight control over page level allocator and protection flags
71938 * use __vmalloc() instead.
71939 */
71940 -
71941 +#undef vmalloc_exec
71942 void *vmalloc_exec(unsigned long size)
71943 {
71944 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
71945 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
71946 -1, __builtin_return_address(0));
71947 }
71948
71949 @@ -1822,6 +1890,7 @@ void *vmalloc_exec(unsigned long size)
71950 * Allocate enough 32bit PA addressable pages to cover @size from the
71951 * page level allocator and map them into contiguous kernel virtual space.
71952 */
71953 +#undef vmalloc_32
71954 void *vmalloc_32(unsigned long size)
71955 {
71956 return __vmalloc_node(size, 1, GFP_VMALLOC32, PAGE_KERNEL,
71957 @@ -1836,6 +1905,7 @@ EXPORT_SYMBOL(vmalloc_32);
71958 * The resulting memory area is 32bit addressable and zeroed so it can be
71959 * mapped to userspace without leaking data.
71960 */
71961 +#undef vmalloc_32_user
71962 void *vmalloc_32_user(unsigned long size)
71963 {
71964 struct vm_struct *area;
71965 @@ -2098,6 +2168,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
71966 unsigned long uaddr = vma->vm_start;
71967 unsigned long usize = vma->vm_end - vma->vm_start;
71968
71969 + BUG_ON(vma->vm_mirror);
71970 +
71971 if ((PAGE_SIZE-1) & (unsigned long)addr)
71972 return -EINVAL;
71973
71974 diff --git a/mm/vmstat.c b/mm/vmstat.c
71975 index 8fd603b..cf0d930 100644
71976 --- a/mm/vmstat.c
71977 +++ b/mm/vmstat.c
71978 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
71979 *
71980 * vm_stat contains the global counters
71981 */
71982 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
71983 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
71984 EXPORT_SYMBOL(vm_stat);
71985
71986 #ifdef CONFIG_SMP
71987 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
71988 v = p->vm_stat_diff[i];
71989 p->vm_stat_diff[i] = 0;
71990 local_irq_restore(flags);
71991 - atomic_long_add(v, &zone->vm_stat[i]);
71992 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
71993 global_diff[i] += v;
71994 #ifdef CONFIG_NUMA
71995 /* 3 seconds idle till flush */
71996 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
71997
71998 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
71999 if (global_diff[i])
72000 - atomic_long_add(global_diff[i], &vm_stat[i]);
72001 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
72002 }
72003
72004 #endif
72005 @@ -1208,10 +1208,20 @@ static int __init setup_vmstat(void)
72006 start_cpu_timer(cpu);
72007 #endif
72008 #ifdef CONFIG_PROC_FS
72009 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
72010 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
72011 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
72012 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
72013 + {
72014 + mode_t gr_mode = S_IRUGO;
72015 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
72016 + gr_mode = S_IRUSR;
72017 +#endif
72018 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
72019 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
72020 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72021 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
72022 +#else
72023 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
72024 +#endif
72025 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
72026 + }
72027 #endif
72028 return 0;
72029 }
72030 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
72031 index 5471628..cef8398 100644
72032 --- a/net/8021q/vlan.c
72033 +++ b/net/8021q/vlan.c
72034 @@ -588,8 +588,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
72035 err = -EPERM;
72036 if (!capable(CAP_NET_ADMIN))
72037 break;
72038 - if ((args.u.name_type >= 0) &&
72039 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
72040 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
72041 struct vlan_net *vn;
72042
72043 vn = net_generic(net, vlan_net_id);
72044 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
72045 index fdfdb57..38d368c 100644
72046 --- a/net/9p/trans_fd.c
72047 +++ b/net/9p/trans_fd.c
72048 @@ -423,7 +423,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
72049 oldfs = get_fs();
72050 set_fs(get_ds());
72051 /* The cast to a user pointer is valid due to the set_fs() */
72052 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
72053 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
72054 set_fs(oldfs);
72055
72056 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
72057 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
72058 index f41f026..fe76ea8 100644
72059 --- a/net/atm/atm_misc.c
72060 +++ b/net/atm/atm_misc.c
72061 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
72062 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
72063 return 1;
72064 atm_return(vcc, truesize);
72065 - atomic_inc(&vcc->stats->rx_drop);
72066 + atomic_inc_unchecked(&vcc->stats->rx_drop);
72067 return 0;
72068 }
72069 EXPORT_SYMBOL(atm_charge);
72070 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
72071 }
72072 }
72073 atm_return(vcc, guess);
72074 - atomic_inc(&vcc->stats->rx_drop);
72075 + atomic_inc_unchecked(&vcc->stats->rx_drop);
72076 return NULL;
72077 }
72078 EXPORT_SYMBOL(atm_alloc_charge);
72079 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
72080
72081 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
72082 {
72083 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
72084 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
72085 __SONET_ITEMS
72086 #undef __HANDLE_ITEM
72087 }
72088 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
72089
72090 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
72091 {
72092 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
72093 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
72094 __SONET_ITEMS
72095 #undef __HANDLE_ITEM
72096 }
72097 diff --git a/net/atm/lec.h b/net/atm/lec.h
72098 index dfc0719..47c5322 100644
72099 --- a/net/atm/lec.h
72100 +++ b/net/atm/lec.h
72101 @@ -48,7 +48,7 @@ struct lane2_ops {
72102 const u8 *tlvs, u32 sizeoftlvs);
72103 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
72104 const u8 *tlvs, u32 sizeoftlvs);
72105 -};
72106 +} __no_const;
72107
72108 /*
72109 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
72110 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
72111 index 0919a88..a23d54e 100644
72112 --- a/net/atm/mpc.h
72113 +++ b/net/atm/mpc.h
72114 @@ -33,7 +33,7 @@ struct mpoa_client {
72115 struct mpc_parameters parameters; /* parameters for this client */
72116
72117 const struct net_device_ops *old_ops;
72118 - struct net_device_ops new_ops;
72119 + net_device_ops_no_const new_ops;
72120 };
72121
72122
72123 diff --git a/net/atm/proc.c b/net/atm/proc.c
72124 index 0d020de..011c7bb 100644
72125 --- a/net/atm/proc.c
72126 +++ b/net/atm/proc.c
72127 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
72128 const struct k_atm_aal_stats *stats)
72129 {
72130 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
72131 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
72132 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
72133 - atomic_read(&stats->rx_drop));
72134 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
72135 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
72136 + atomic_read_unchecked(&stats->rx_drop));
72137 }
72138
72139 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
72140 diff --git a/net/atm/resources.c b/net/atm/resources.c
72141 index 23f45ce..c748f1a 100644
72142 --- a/net/atm/resources.c
72143 +++ b/net/atm/resources.c
72144 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
72145 static void copy_aal_stats(struct k_atm_aal_stats *from,
72146 struct atm_aal_stats *to)
72147 {
72148 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
72149 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
72150 __AAL_STAT_ITEMS
72151 #undef __HANDLE_ITEM
72152 }
72153 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
72154 static void subtract_aal_stats(struct k_atm_aal_stats *from,
72155 struct atm_aal_stats *to)
72156 {
72157 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
72158 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
72159 __AAL_STAT_ITEMS
72160 #undef __HANDLE_ITEM
72161 }
72162 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
72163 index 3512e25..2b33401 100644
72164 --- a/net/batman-adv/bat_iv_ogm.c
72165 +++ b/net/batman-adv/bat_iv_ogm.c
72166 @@ -541,7 +541,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
72167
72168 /* change sequence number to network order */
72169 batman_ogm_packet->seqno =
72170 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
72171 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
72172
72173 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
72174 batman_ogm_packet->tt_crc = htons((uint16_t)
72175 @@ -561,7 +561,7 @@ void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes)
72176 else
72177 batman_ogm_packet->gw_flags = NO_FLAGS;
72178
72179 - atomic_inc(&hard_iface->seqno);
72180 + atomic_inc_unchecked(&hard_iface->seqno);
72181
72182 slide_own_bcast_window(hard_iface);
72183 bat_ogm_queue_add(bat_priv, hard_iface->packet_buff,
72184 @@ -922,7 +922,7 @@ static void bat_ogm_process(const struct ethhdr *ethhdr,
72185 return;
72186
72187 /* could be changed by schedule_own_packet() */
72188 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
72189 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
72190
72191 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
72192
72193 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
72194 index 7704df4..beb4e16 100644
72195 --- a/net/batman-adv/hard-interface.c
72196 +++ b/net/batman-adv/hard-interface.c
72197 @@ -326,8 +326,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
72198 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
72199 dev_add_pack(&hard_iface->batman_adv_ptype);
72200
72201 - atomic_set(&hard_iface->seqno, 1);
72202 - atomic_set(&hard_iface->frag_seqno, 1);
72203 + atomic_set_unchecked(&hard_iface->seqno, 1);
72204 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
72205 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
72206 hard_iface->net_dev->name);
72207
72208 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
72209 index f9cc957..efd9dae 100644
72210 --- a/net/batman-adv/soft-interface.c
72211 +++ b/net/batman-adv/soft-interface.c
72212 @@ -634,7 +634,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
72213
72214 /* set broadcast sequence number */
72215 bcast_packet->seqno =
72216 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
72217 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
72218
72219 add_bcast_packet_to_list(bat_priv, skb, 1);
72220
72221 @@ -828,7 +828,7 @@ struct net_device *softif_create(const char *name)
72222 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
72223
72224 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
72225 - atomic_set(&bat_priv->bcast_seqno, 1);
72226 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
72227 atomic_set(&bat_priv->ttvn, 0);
72228 atomic_set(&bat_priv->tt_local_changes, 0);
72229 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
72230 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
72231 index ab8d0fe..ceba3fd 100644
72232 --- a/net/batman-adv/types.h
72233 +++ b/net/batman-adv/types.h
72234 @@ -38,8 +38,8 @@ struct hard_iface {
72235 int16_t if_num;
72236 char if_status;
72237 struct net_device *net_dev;
72238 - atomic_t seqno;
72239 - atomic_t frag_seqno;
72240 + atomic_unchecked_t seqno;
72241 + atomic_unchecked_t frag_seqno;
72242 unsigned char *packet_buff;
72243 int packet_len;
72244 struct kobject *hardif_obj;
72245 @@ -154,7 +154,7 @@ struct bat_priv {
72246 atomic_t orig_interval; /* uint */
72247 atomic_t hop_penalty; /* uint */
72248 atomic_t log_level; /* uint */
72249 - atomic_t bcast_seqno;
72250 + atomic_unchecked_t bcast_seqno;
72251 atomic_t bcast_queue_left;
72252 atomic_t batman_queue_left;
72253 atomic_t ttvn; /* translation table version number */
72254 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
72255 index 07d1c1d..7e9bea9 100644
72256 --- a/net/batman-adv/unicast.c
72257 +++ b/net/batman-adv/unicast.c
72258 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
72259 frag1->flags = UNI_FRAG_HEAD | large_tail;
72260 frag2->flags = large_tail;
72261
72262 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
72263 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
72264 frag1->seqno = htons(seqno - 1);
72265 frag2->seqno = htons(seqno);
72266
72267 diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
72268 index c1c597e..05ebb40 100644
72269 --- a/net/bluetooth/hci_conn.c
72270 +++ b/net/bluetooth/hci_conn.c
72271 @@ -234,7 +234,7 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16])
72272 memset(&cp, 0, sizeof(cp));
72273
72274 cp.handle = cpu_to_le16(conn->handle);
72275 - memcpy(cp.ltk, ltk, sizeof(ltk));
72276 + memcpy(cp.ltk, ltk, sizeof(cp.ltk));
72277
72278 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
72279 }
72280 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
72281 index 17b5b1c..826d872 100644
72282 --- a/net/bluetooth/l2cap_core.c
72283 +++ b/net/bluetooth/l2cap_core.c
72284 @@ -2176,8 +2176,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
72285 break;
72286
72287 case L2CAP_CONF_RFC:
72288 - if (olen == sizeof(rfc))
72289 - memcpy(&rfc, (void *)val, olen);
72290 + if (olen != sizeof(rfc))
72291 + break;
72292 +
72293 + memcpy(&rfc, (void *)val, olen);
72294
72295 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
72296 rfc.mode != chan->mode)
72297 @@ -2265,8 +2267,10 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
72298
72299 switch (type) {
72300 case L2CAP_CONF_RFC:
72301 - if (olen == sizeof(rfc))
72302 - memcpy(&rfc, (void *)val, olen);
72303 + if (olen != sizeof(rfc))
72304 + break;
72305 +
72306 + memcpy(&rfc, (void *)val, olen);
72307 goto done;
72308 }
72309 }
72310 diff --git a/net/bridge/br_multicast.c b/net/bridge/br_multicast.c
72311 index a5f4e57..910ee6d 100644
72312 --- a/net/bridge/br_multicast.c
72313 +++ b/net/bridge/br_multicast.c
72314 @@ -1485,7 +1485,7 @@ static int br_multicast_ipv6_rcv(struct net_bridge *br,
72315 nexthdr = ip6h->nexthdr;
72316 offset = ipv6_skip_exthdr(skb, sizeof(*ip6h), &nexthdr);
72317
72318 - if (offset < 0 || nexthdr != IPPROTO_ICMPV6)
72319 + if (nexthdr != IPPROTO_ICMPV6)
72320 return 0;
72321
72322 /* Okay, we found ICMPv6 header */
72323 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
72324 index 5864cc4..121f3a3 100644
72325 --- a/net/bridge/netfilter/ebtables.c
72326 +++ b/net/bridge/netfilter/ebtables.c
72327 @@ -1513,7 +1513,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
72328 tmp.valid_hooks = t->table->valid_hooks;
72329 }
72330 mutex_unlock(&ebt_mutex);
72331 - if (copy_to_user(user, &tmp, *len) != 0){
72332 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
72333 BUGPRINT("c2u Didn't work\n");
72334 ret = -EFAULT;
72335 break;
72336 diff --git a/net/caif/caif_socket.c b/net/caif/caif_socket.c
72337 index a986280..13444a1 100644
72338 --- a/net/caif/caif_socket.c
72339 +++ b/net/caif/caif_socket.c
72340 @@ -48,19 +48,20 @@ static struct dentry *debugfsdir;
72341 #ifdef CONFIG_DEBUG_FS
72342 struct debug_fs_counter {
72343 atomic_t caif_nr_socks;
72344 - atomic_t caif_sock_create;
72345 - atomic_t num_connect_req;
72346 - atomic_t num_connect_resp;
72347 - atomic_t num_connect_fail_resp;
72348 - atomic_t num_disconnect;
72349 - atomic_t num_remote_shutdown_ind;
72350 - atomic_t num_tx_flow_off_ind;
72351 - atomic_t num_tx_flow_on_ind;
72352 - atomic_t num_rx_flow_off;
72353 - atomic_t num_rx_flow_on;
72354 + atomic_unchecked_t caif_sock_create;
72355 + atomic_unchecked_t num_connect_req;
72356 + atomic_unchecked_t num_connect_resp;
72357 + atomic_unchecked_t num_connect_fail_resp;
72358 + atomic_unchecked_t num_disconnect;
72359 + atomic_unchecked_t num_remote_shutdown_ind;
72360 + atomic_unchecked_t num_tx_flow_off_ind;
72361 + atomic_unchecked_t num_tx_flow_on_ind;
72362 + atomic_unchecked_t num_rx_flow_off;
72363 + atomic_unchecked_t num_rx_flow_on;
72364 };
72365 static struct debug_fs_counter cnt;
72366 #define dbfs_atomic_inc(v) atomic_inc_return(v)
72367 +#define dbfs_atomic_inc_unchecked(v) atomic_inc_return_unchecked(v)
72368 #define dbfs_atomic_dec(v) atomic_dec_return(v)
72369 #else
72370 #define dbfs_atomic_inc(v) 0
72371 @@ -161,7 +162,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72372 atomic_read(&cf_sk->sk.sk_rmem_alloc),
72373 sk_rcvbuf_lowwater(cf_sk));
72374 set_rx_flow_off(cf_sk);
72375 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
72376 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
72377 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
72378 }
72379
72380 @@ -172,7 +173,7 @@ static int caif_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72381 set_rx_flow_off(cf_sk);
72382 if (net_ratelimit())
72383 pr_debug("sending flow OFF due to rmem_schedule\n");
72384 - dbfs_atomic_inc(&cnt.num_rx_flow_off);
72385 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_off);
72386 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_OFF_REQ);
72387 }
72388 skb->dev = NULL;
72389 @@ -233,14 +234,14 @@ static void caif_ctrl_cb(struct cflayer *layr,
72390 switch (flow) {
72391 case CAIF_CTRLCMD_FLOW_ON_IND:
72392 /* OK from modem to start sending again */
72393 - dbfs_atomic_inc(&cnt.num_tx_flow_on_ind);
72394 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_on_ind);
72395 set_tx_flow_on(cf_sk);
72396 cf_sk->sk.sk_state_change(&cf_sk->sk);
72397 break;
72398
72399 case CAIF_CTRLCMD_FLOW_OFF_IND:
72400 /* Modem asks us to shut up */
72401 - dbfs_atomic_inc(&cnt.num_tx_flow_off_ind);
72402 + dbfs_atomic_inc_unchecked(&cnt.num_tx_flow_off_ind);
72403 set_tx_flow_off(cf_sk);
72404 cf_sk->sk.sk_state_change(&cf_sk->sk);
72405 break;
72406 @@ -249,7 +250,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72407 /* We're now connected */
72408 caif_client_register_refcnt(&cf_sk->layer,
72409 cfsk_hold, cfsk_put);
72410 - dbfs_atomic_inc(&cnt.num_connect_resp);
72411 + dbfs_atomic_inc_unchecked(&cnt.num_connect_resp);
72412 cf_sk->sk.sk_state = CAIF_CONNECTED;
72413 set_tx_flow_on(cf_sk);
72414 cf_sk->sk.sk_state_change(&cf_sk->sk);
72415 @@ -263,7 +264,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72416
72417 case CAIF_CTRLCMD_INIT_FAIL_RSP:
72418 /* Connect request failed */
72419 - dbfs_atomic_inc(&cnt.num_connect_fail_resp);
72420 + dbfs_atomic_inc_unchecked(&cnt.num_connect_fail_resp);
72421 cf_sk->sk.sk_err = ECONNREFUSED;
72422 cf_sk->sk.sk_state = CAIF_DISCONNECTED;
72423 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
72424 @@ -277,7 +278,7 @@ static void caif_ctrl_cb(struct cflayer *layr,
72425
72426 case CAIF_CTRLCMD_REMOTE_SHUTDOWN_IND:
72427 /* Modem has closed this connection, or device is down. */
72428 - dbfs_atomic_inc(&cnt.num_remote_shutdown_ind);
72429 + dbfs_atomic_inc_unchecked(&cnt.num_remote_shutdown_ind);
72430 cf_sk->sk.sk_shutdown = SHUTDOWN_MASK;
72431 cf_sk->sk.sk_err = ECONNRESET;
72432 set_rx_flow_on(cf_sk);
72433 @@ -297,7 +298,7 @@ static void caif_check_flow_release(struct sock *sk)
72434 return;
72435
72436 if (atomic_read(&sk->sk_rmem_alloc) <= sk_rcvbuf_lowwater(cf_sk)) {
72437 - dbfs_atomic_inc(&cnt.num_rx_flow_on);
72438 + dbfs_atomic_inc_unchecked(&cnt.num_rx_flow_on);
72439 set_rx_flow_on(cf_sk);
72440 caif_flow_ctrl(sk, CAIF_MODEMCMD_FLOW_ON_REQ);
72441 }
72442 @@ -854,7 +855,7 @@ static int caif_connect(struct socket *sock, struct sockaddr *uaddr,
72443 /*ifindex = id of the interface.*/
72444 cf_sk->conn_req.ifindex = cf_sk->sk.sk_bound_dev_if;
72445
72446 - dbfs_atomic_inc(&cnt.num_connect_req);
72447 + dbfs_atomic_inc_unchecked(&cnt.num_connect_req);
72448 cf_sk->layer.receive = caif_sktrecv_cb;
72449
72450 err = caif_connect_client(sock_net(sk), &cf_sk->conn_req,
72451 @@ -943,7 +944,7 @@ static int caif_release(struct socket *sock)
72452 spin_unlock_bh(&sk->sk_receive_queue.lock);
72453 sock->sk = NULL;
72454
72455 - dbfs_atomic_inc(&cnt.num_disconnect);
72456 + dbfs_atomic_inc_unchecked(&cnt.num_disconnect);
72457
72458 WARN_ON(IS_ERR(cf_sk->debugfs_socket_dir));
72459 if (cf_sk->debugfs_socket_dir != NULL)
72460 @@ -1122,7 +1123,7 @@ static int caif_create(struct net *net, struct socket *sock, int protocol,
72461 cf_sk->conn_req.protocol = protocol;
72462 /* Increase the number of sockets created. */
72463 dbfs_atomic_inc(&cnt.caif_nr_socks);
72464 - num = dbfs_atomic_inc(&cnt.caif_sock_create);
72465 + num = dbfs_atomic_inc_unchecked(&cnt.caif_sock_create);
72466 #ifdef CONFIG_DEBUG_FS
72467 if (!IS_ERR(debugfsdir)) {
72468
72469 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
72470 index 5cf5222..6f704ad 100644
72471 --- a/net/caif/cfctrl.c
72472 +++ b/net/caif/cfctrl.c
72473 @@ -9,6 +9,7 @@
72474 #include <linux/stddef.h>
72475 #include <linux/spinlock.h>
72476 #include <linux/slab.h>
72477 +#include <linux/sched.h>
72478 #include <net/caif/caif_layer.h>
72479 #include <net/caif/cfpkt.h>
72480 #include <net/caif/cfctrl.h>
72481 @@ -42,8 +43,8 @@ struct cflayer *cfctrl_create(void)
72482 memset(&dev_info, 0, sizeof(dev_info));
72483 dev_info.id = 0xff;
72484 cfsrvl_init(&this->serv, 0, &dev_info, false);
72485 - atomic_set(&this->req_seq_no, 1);
72486 - atomic_set(&this->rsp_seq_no, 1);
72487 + atomic_set_unchecked(&this->req_seq_no, 1);
72488 + atomic_set_unchecked(&this->rsp_seq_no, 1);
72489 this->serv.layer.receive = cfctrl_recv;
72490 sprintf(this->serv.layer.name, "ctrl");
72491 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
72492 @@ -129,8 +130,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
72493 struct cfctrl_request_info *req)
72494 {
72495 spin_lock_bh(&ctrl->info_list_lock);
72496 - atomic_inc(&ctrl->req_seq_no);
72497 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
72498 + atomic_inc_unchecked(&ctrl->req_seq_no);
72499 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
72500 list_add_tail(&req->list, &ctrl->list);
72501 spin_unlock_bh(&ctrl->info_list_lock);
72502 }
72503 @@ -148,7 +149,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
72504 if (p != first)
72505 pr_warn("Requests are not received in order\n");
72506
72507 - atomic_set(&ctrl->rsp_seq_no,
72508 + atomic_set_unchecked(&ctrl->rsp_seq_no,
72509 p->sequence_no);
72510 list_del(&p->list);
72511 goto out;
72512 diff --git a/net/can/gw.c b/net/can/gw.c
72513 index 3d79b12..8de85fa 100644
72514 --- a/net/can/gw.c
72515 +++ b/net/can/gw.c
72516 @@ -96,7 +96,7 @@ struct cf_mod {
72517 struct {
72518 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
72519 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
72520 - } csumfunc;
72521 + } __no_const csumfunc;
72522 };
72523
72524
72525 diff --git a/net/compat.c b/net/compat.c
72526 index 6def90e..c6992fa 100644
72527 --- a/net/compat.c
72528 +++ b/net/compat.c
72529 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
72530 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
72531 __get_user(kmsg->msg_flags, &umsg->msg_flags))
72532 return -EFAULT;
72533 - kmsg->msg_name = compat_ptr(tmp1);
72534 - kmsg->msg_iov = compat_ptr(tmp2);
72535 - kmsg->msg_control = compat_ptr(tmp3);
72536 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
72537 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
72538 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
72539 return 0;
72540 }
72541
72542 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72543
72544 if (kern_msg->msg_namelen) {
72545 if (mode == VERIFY_READ) {
72546 - int err = move_addr_to_kernel(kern_msg->msg_name,
72547 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
72548 kern_msg->msg_namelen,
72549 kern_address);
72550 if (err < 0)
72551 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72552 kern_msg->msg_name = NULL;
72553
72554 tot_len = iov_from_user_compat_to_kern(kern_iov,
72555 - (struct compat_iovec __user *)kern_msg->msg_iov,
72556 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
72557 kern_msg->msg_iovlen);
72558 if (tot_len >= 0)
72559 kern_msg->msg_iov = kern_iov;
72560 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
72561
72562 #define CMSG_COMPAT_FIRSTHDR(msg) \
72563 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
72564 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
72565 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
72566 (struct compat_cmsghdr __user *)NULL)
72567
72568 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
72569 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
72570 (ucmlen) <= (unsigned long) \
72571 ((mhdr)->msg_controllen - \
72572 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
72573 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
72574
72575 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
72576 struct compat_cmsghdr __user *cmsg, int cmsg_len)
72577 {
72578 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
72579 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
72580 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
72581 msg->msg_controllen)
72582 return NULL;
72583 return (struct compat_cmsghdr __user *)ptr;
72584 @@ -221,7 +221,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
72585 {
72586 struct compat_timeval ctv;
72587 struct compat_timespec cts[3];
72588 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
72589 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
72590 struct compat_cmsghdr cmhdr;
72591 int cmlen;
72592
72593 @@ -273,7 +273,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
72594
72595 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
72596 {
72597 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
72598 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
72599 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
72600 int fdnum = scm->fp->count;
72601 struct file **fp = scm->fp->fp;
72602 @@ -370,7 +370,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
72603 return -EFAULT;
72604 old_fs = get_fs();
72605 set_fs(KERNEL_DS);
72606 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
72607 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
72608 set_fs(old_fs);
72609
72610 return err;
72611 @@ -431,7 +431,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
72612 len = sizeof(ktime);
72613 old_fs = get_fs();
72614 set_fs(KERNEL_DS);
72615 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
72616 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
72617 set_fs(old_fs);
72618
72619 if (!err) {
72620 @@ -566,7 +566,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72621 case MCAST_JOIN_GROUP:
72622 case MCAST_LEAVE_GROUP:
72623 {
72624 - struct compat_group_req __user *gr32 = (void *)optval;
72625 + struct compat_group_req __user *gr32 = (void __user *)optval;
72626 struct group_req __user *kgr =
72627 compat_alloc_user_space(sizeof(struct group_req));
72628 u32 interface;
72629 @@ -587,7 +587,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72630 case MCAST_BLOCK_SOURCE:
72631 case MCAST_UNBLOCK_SOURCE:
72632 {
72633 - struct compat_group_source_req __user *gsr32 = (void *)optval;
72634 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
72635 struct group_source_req __user *kgsr = compat_alloc_user_space(
72636 sizeof(struct group_source_req));
72637 u32 interface;
72638 @@ -608,7 +608,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
72639 }
72640 case MCAST_MSFILTER:
72641 {
72642 - struct compat_group_filter __user *gf32 = (void *)optval;
72643 + struct compat_group_filter __user *gf32 = (void __user *)optval;
72644 struct group_filter __user *kgf;
72645 u32 interface, fmode, numsrc;
72646
72647 @@ -646,7 +646,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
72648 char __user *optval, int __user *optlen,
72649 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
72650 {
72651 - struct compat_group_filter __user *gf32 = (void *)optval;
72652 + struct compat_group_filter __user *gf32 = (void __user *)optval;
72653 struct group_filter __user *kgf;
72654 int __user *koptlen;
72655 u32 interface, fmode, numsrc;
72656 diff --git a/net/core/datagram.c b/net/core/datagram.c
72657 index 68bbf9f..5ef0d12 100644
72658 --- a/net/core/datagram.c
72659 +++ b/net/core/datagram.c
72660 @@ -285,7 +285,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
72661 }
72662
72663 kfree_skb(skb);
72664 - atomic_inc(&sk->sk_drops);
72665 + atomic_inc_unchecked(&sk->sk_drops);
72666 sk_mem_reclaim_partial(sk);
72667
72668 return err;
72669 diff --git a/net/core/dev.c b/net/core/dev.c
72670 index 5a13edf..a6f2bd2 100644
72671 --- a/net/core/dev.c
72672 +++ b/net/core/dev.c
72673 @@ -1139,10 +1139,14 @@ void dev_load(struct net *net, const char *name)
72674 if (no_module && capable(CAP_NET_ADMIN))
72675 no_module = request_module("netdev-%s", name);
72676 if (no_module && capable(CAP_SYS_MODULE)) {
72677 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
72678 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
72679 +#else
72680 if (!request_module("%s", name))
72681 pr_err("Loading kernel module for a network device "
72682 "with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s "
72683 "instead\n", name);
72684 +#endif
72685 }
72686 }
72687 EXPORT_SYMBOL(dev_load);
72688 @@ -1573,7 +1577,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
72689 {
72690 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
72691 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
72692 - atomic_long_inc(&dev->rx_dropped);
72693 + atomic_long_inc_unchecked(&dev->rx_dropped);
72694 kfree_skb(skb);
72695 return NET_RX_DROP;
72696 }
72697 @@ -1583,7 +1587,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
72698 nf_reset(skb);
72699
72700 if (unlikely(!is_skb_forwardable(dev, skb))) {
72701 - atomic_long_inc(&dev->rx_dropped);
72702 + atomic_long_inc_unchecked(&dev->rx_dropped);
72703 kfree_skb(skb);
72704 return NET_RX_DROP;
72705 }
72706 @@ -2036,7 +2040,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
72707
72708 struct dev_gso_cb {
72709 void (*destructor)(struct sk_buff *skb);
72710 -};
72711 +} __no_const;
72712
72713 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
72714
72715 @@ -2970,7 +2974,7 @@ enqueue:
72716
72717 local_irq_restore(flags);
72718
72719 - atomic_long_inc(&skb->dev->rx_dropped);
72720 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
72721 kfree_skb(skb);
72722 return NET_RX_DROP;
72723 }
72724 @@ -3044,7 +3048,7 @@ int netif_rx_ni(struct sk_buff *skb)
72725 }
72726 EXPORT_SYMBOL(netif_rx_ni);
72727
72728 -static void net_tx_action(struct softirq_action *h)
72729 +static void net_tx_action(void)
72730 {
72731 struct softnet_data *sd = &__get_cpu_var(softnet_data);
72732
72733 @@ -3333,7 +3337,7 @@ ncls:
72734 if (pt_prev) {
72735 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
72736 } else {
72737 - atomic_long_inc(&skb->dev->rx_dropped);
72738 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
72739 kfree_skb(skb);
72740 /* Jamal, now you will not able to escape explaining
72741 * me how you were going to use this. :-)
72742 @@ -3891,7 +3895,7 @@ void netif_napi_del(struct napi_struct *napi)
72743 }
72744 EXPORT_SYMBOL(netif_napi_del);
72745
72746 -static void net_rx_action(struct softirq_action *h)
72747 +static void net_rx_action(void)
72748 {
72749 struct softnet_data *sd = &__get_cpu_var(softnet_data);
72750 unsigned long time_limit = jiffies + 2;
72751 @@ -5949,7 +5953,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
72752 } else {
72753 netdev_stats_to_stats64(storage, &dev->stats);
72754 }
72755 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
72756 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
72757 return storage;
72758 }
72759 EXPORT_SYMBOL(dev_get_stats);
72760 diff --git a/net/core/flow.c b/net/core/flow.c
72761 index e318c7e..168b1d0 100644
72762 --- a/net/core/flow.c
72763 +++ b/net/core/flow.c
72764 @@ -61,7 +61,7 @@ struct flow_cache {
72765 struct timer_list rnd_timer;
72766 };
72767
72768 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
72769 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
72770 EXPORT_SYMBOL(flow_cache_genid);
72771 static struct flow_cache flow_cache_global;
72772 static struct kmem_cache *flow_cachep __read_mostly;
72773 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
72774
72775 static int flow_entry_valid(struct flow_cache_entry *fle)
72776 {
72777 - if (atomic_read(&flow_cache_genid) != fle->genid)
72778 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
72779 return 0;
72780 if (fle->object && !fle->object->ops->check(fle->object))
72781 return 0;
72782 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
72783 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
72784 fcp->hash_count++;
72785 }
72786 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
72787 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
72788 flo = fle->object;
72789 if (!flo)
72790 goto ret_object;
72791 @@ -280,7 +280,7 @@ nocache:
72792 }
72793 flo = resolver(net, key, family, dir, flo, ctx);
72794 if (fle) {
72795 - fle->genid = atomic_read(&flow_cache_genid);
72796 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
72797 if (!IS_ERR(flo))
72798 fle->object = flo;
72799 else
72800 diff --git a/net/core/iovec.c b/net/core/iovec.c
72801 index c40f27e..7f49254 100644
72802 --- a/net/core/iovec.c
72803 +++ b/net/core/iovec.c
72804 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
72805 if (m->msg_namelen) {
72806 if (mode == VERIFY_READ) {
72807 void __user *namep;
72808 - namep = (void __user __force *) m->msg_name;
72809 + namep = (void __force_user *) m->msg_name;
72810 err = move_addr_to_kernel(namep, m->msg_namelen,
72811 address);
72812 if (err < 0)
72813 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr *address,
72814 }
72815
72816 size = m->msg_iovlen * sizeof(struct iovec);
72817 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
72818 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
72819 return -EFAULT;
72820
72821 m->msg_iov = iov;
72822 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
72823 index 9083e82..1673203 100644
72824 --- a/net/core/rtnetlink.c
72825 +++ b/net/core/rtnetlink.c
72826 @@ -57,7 +57,7 @@ struct rtnl_link {
72827 rtnl_doit_func doit;
72828 rtnl_dumpit_func dumpit;
72829 rtnl_calcit_func calcit;
72830 -};
72831 +} __no_const;
72832
72833 static DEFINE_MUTEX(rtnl_mutex);
72834 static u16 min_ifinfo_dump_size;
72835 diff --git a/net/core/scm.c b/net/core/scm.c
72836 index ff52ad0..aff1c0f 100644
72837 --- a/net/core/scm.c
72838 +++ b/net/core/scm.c
72839 @@ -220,7 +220,7 @@ EXPORT_SYMBOL(__scm_send);
72840 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
72841 {
72842 struct cmsghdr __user *cm
72843 - = (__force struct cmsghdr __user *)msg->msg_control;
72844 + = (struct cmsghdr __force_user *)msg->msg_control;
72845 struct cmsghdr cmhdr;
72846 int cmlen = CMSG_LEN(len);
72847 int err;
72848 @@ -243,7 +243,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
72849 err = -EFAULT;
72850 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
72851 goto out;
72852 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
72853 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
72854 goto out;
72855 cmlen = CMSG_SPACE(len);
72856 if (msg->msg_controllen < cmlen)
72857 @@ -259,7 +259,7 @@ EXPORT_SYMBOL(put_cmsg);
72858 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
72859 {
72860 struct cmsghdr __user *cm
72861 - = (__force struct cmsghdr __user*)msg->msg_control;
72862 + = (struct cmsghdr __force_user *)msg->msg_control;
72863
72864 int fdmax = 0;
72865 int fdnum = scm->fp->count;
72866 @@ -279,7 +279,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
72867 if (fdnum < fdmax)
72868 fdmax = fdnum;
72869
72870 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
72871 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
72872 i++, cmfptr++)
72873 {
72874 int new_fd;
72875 diff --git a/net/core/sock.c b/net/core/sock.c
72876 index b23f174..b9a0d26 100644
72877 --- a/net/core/sock.c
72878 +++ b/net/core/sock.c
72879 @@ -289,7 +289,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72880 struct sk_buff_head *list = &sk->sk_receive_queue;
72881
72882 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
72883 - atomic_inc(&sk->sk_drops);
72884 + atomic_inc_unchecked(&sk->sk_drops);
72885 trace_sock_rcvqueue_full(sk, skb);
72886 return -ENOMEM;
72887 }
72888 @@ -299,7 +299,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72889 return err;
72890
72891 if (!sk_rmem_schedule(sk, skb->truesize)) {
72892 - atomic_inc(&sk->sk_drops);
72893 + atomic_inc_unchecked(&sk->sk_drops);
72894 return -ENOBUFS;
72895 }
72896
72897 @@ -319,7 +319,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
72898 skb_dst_force(skb);
72899
72900 spin_lock_irqsave(&list->lock, flags);
72901 - skb->dropcount = atomic_read(&sk->sk_drops);
72902 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
72903 __skb_queue_tail(list, skb);
72904 spin_unlock_irqrestore(&list->lock, flags);
72905
72906 @@ -339,7 +339,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
72907 skb->dev = NULL;
72908
72909 if (sk_rcvqueues_full(sk, skb)) {
72910 - atomic_inc(&sk->sk_drops);
72911 + atomic_inc_unchecked(&sk->sk_drops);
72912 goto discard_and_relse;
72913 }
72914 if (nested)
72915 @@ -357,7 +357,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
72916 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
72917 } else if (sk_add_backlog(sk, skb)) {
72918 bh_unlock_sock(sk);
72919 - atomic_inc(&sk->sk_drops);
72920 + atomic_inc_unchecked(&sk->sk_drops);
72921 goto discard_and_relse;
72922 }
72923
72924 @@ -917,7 +917,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72925 if (len > sizeof(peercred))
72926 len = sizeof(peercred);
72927 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
72928 - if (copy_to_user(optval, &peercred, len))
72929 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
72930 return -EFAULT;
72931 goto lenout;
72932 }
72933 @@ -930,7 +930,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72934 return -ENOTCONN;
72935 if (lv < len)
72936 return -EINVAL;
72937 - if (copy_to_user(optval, address, len))
72938 + if (len > sizeof(address) || copy_to_user(optval, address, len))
72939 return -EFAULT;
72940 goto lenout;
72941 }
72942 @@ -963,7 +963,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
72943
72944 if (len > lv)
72945 len = lv;
72946 - if (copy_to_user(optval, &v, len))
72947 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
72948 return -EFAULT;
72949 lenout:
72950 if (put_user(len, optlen))
72951 @@ -2020,7 +2020,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
72952 */
72953 smp_wmb();
72954 atomic_set(&sk->sk_refcnt, 1);
72955 - atomic_set(&sk->sk_drops, 0);
72956 + atomic_set_unchecked(&sk->sk_drops, 0);
72957 }
72958 EXPORT_SYMBOL(sock_init_data);
72959
72960 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
72961 index 02e75d1..9a57a7c 100644
72962 --- a/net/decnet/sysctl_net_decnet.c
72963 +++ b/net/decnet/sysctl_net_decnet.c
72964 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
72965
72966 if (len > *lenp) len = *lenp;
72967
72968 - if (copy_to_user(buffer, addr, len))
72969 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
72970 return -EFAULT;
72971
72972 *lenp = len;
72973 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
72974
72975 if (len > *lenp) len = *lenp;
72976
72977 - if (copy_to_user(buffer, devname, len))
72978 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
72979 return -EFAULT;
72980
72981 *lenp = len;
72982 diff --git a/net/econet/Kconfig b/net/econet/Kconfig
72983 index 39a2d29..f39c0fe 100644
72984 --- a/net/econet/Kconfig
72985 +++ b/net/econet/Kconfig
72986 @@ -4,7 +4,7 @@
72987
72988 config ECONET
72989 tristate "Acorn Econet/AUN protocols (EXPERIMENTAL)"
72990 - depends on EXPERIMENTAL && INET
72991 + depends on EXPERIMENTAL && INET && BROKEN
72992 ---help---
72993 Econet is a fairly old and slow networking protocol mainly used by
72994 Acorn computers to access file and print servers. It uses native
72995 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
72996 index 92fc5f6..b790d91 100644
72997 --- a/net/ipv4/fib_frontend.c
72998 +++ b/net/ipv4/fib_frontend.c
72999 @@ -970,12 +970,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
73000 #ifdef CONFIG_IP_ROUTE_MULTIPATH
73001 fib_sync_up(dev);
73002 #endif
73003 - atomic_inc(&net->ipv4.dev_addr_genid);
73004 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
73005 rt_cache_flush(dev_net(dev), -1);
73006 break;
73007 case NETDEV_DOWN:
73008 fib_del_ifaddr(ifa, NULL);
73009 - atomic_inc(&net->ipv4.dev_addr_genid);
73010 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
73011 if (ifa->ifa_dev->ifa_list == NULL) {
73012 /* Last address was deleted from this interface.
73013 * Disable IP.
73014 @@ -1011,7 +1011,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
73015 #ifdef CONFIG_IP_ROUTE_MULTIPATH
73016 fib_sync_up(dev);
73017 #endif
73018 - atomic_inc(&net->ipv4.dev_addr_genid);
73019 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
73020 rt_cache_flush(dev_net(dev), -1);
73021 break;
73022 case NETDEV_DOWN:
73023 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
73024 index 80106d8..232e898 100644
73025 --- a/net/ipv4/fib_semantics.c
73026 +++ b/net/ipv4/fib_semantics.c
73027 @@ -699,7 +699,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
73028 nh->nh_saddr = inet_select_addr(nh->nh_dev,
73029 nh->nh_gw,
73030 nh->nh_parent->fib_scope);
73031 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
73032 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
73033
73034 return nh->nh_saddr;
73035 }
73036 diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
73037 index ccee270..db23c3c 100644
73038 --- a/net/ipv4/inet_diag.c
73039 +++ b/net/ipv4/inet_diag.c
73040 @@ -114,8 +114,14 @@ static int inet_csk_diag_fill(struct sock *sk,
73041 r->idiag_retrans = 0;
73042
73043 r->id.idiag_if = sk->sk_bound_dev_if;
73044 +
73045 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73046 + r->id.idiag_cookie[0] = 0;
73047 + r->id.idiag_cookie[1] = 0;
73048 +#else
73049 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
73050 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
73051 +#endif
73052
73053 r->id.idiag_sport = inet->inet_sport;
73054 r->id.idiag_dport = inet->inet_dport;
73055 @@ -210,8 +216,15 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
73056 r->idiag_family = tw->tw_family;
73057 r->idiag_retrans = 0;
73058 r->id.idiag_if = tw->tw_bound_dev_if;
73059 +
73060 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73061 + r->id.idiag_cookie[0] = 0;
73062 + r->id.idiag_cookie[1] = 0;
73063 +#else
73064 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
73065 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
73066 +#endif
73067 +
73068 r->id.idiag_sport = tw->tw_sport;
73069 r->id.idiag_dport = tw->tw_dport;
73070 r->id.idiag_src[0] = tw->tw_rcv_saddr;
73071 @@ -294,12 +307,14 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
73072 if (sk == NULL)
73073 goto unlock;
73074
73075 +#ifndef CONFIG_GRKERNSEC_HIDESYM
73076 err = -ESTALE;
73077 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
73078 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
73079 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
73080 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
73081 goto out;
73082 +#endif
73083
73084 err = -ENOMEM;
73085 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
73086 @@ -589,8 +604,14 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
73087 r->idiag_retrans = req->retrans;
73088
73089 r->id.idiag_if = sk->sk_bound_dev_if;
73090 +
73091 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73092 + r->id.idiag_cookie[0] = 0;
73093 + r->id.idiag_cookie[1] = 0;
73094 +#else
73095 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
73096 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
73097 +#endif
73098
73099 tmo = req->expires - jiffies;
73100 if (tmo < 0)
73101 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
73102 index 984ec65..97ac518 100644
73103 --- a/net/ipv4/inet_hashtables.c
73104 +++ b/net/ipv4/inet_hashtables.c
73105 @@ -18,12 +18,15 @@
73106 #include <linux/sched.h>
73107 #include <linux/slab.h>
73108 #include <linux/wait.h>
73109 +#include <linux/security.h>
73110
73111 #include <net/inet_connection_sock.h>
73112 #include <net/inet_hashtables.h>
73113 #include <net/secure_seq.h>
73114 #include <net/ip.h>
73115
73116 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
73117 +
73118 /*
73119 * Allocate and initialize a new local port bind bucket.
73120 * The bindhash mutex for snum's hash chain must be held here.
73121 @@ -530,6 +533,8 @@ ok:
73122 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
73123 spin_unlock(&head->lock);
73124
73125 + gr_update_task_in_ip_table(current, inet_sk(sk));
73126 +
73127 if (tw) {
73128 inet_twsk_deschedule(tw, death_row);
73129 while (twrefcnt) {
73130 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
73131 index 86f13c67..59a35b5 100644
73132 --- a/net/ipv4/inetpeer.c
73133 +++ b/net/ipv4/inetpeer.c
73134 @@ -436,8 +436,8 @@ relookup:
73135 if (p) {
73136 p->daddr = *daddr;
73137 atomic_set(&p->refcnt, 1);
73138 - atomic_set(&p->rid, 0);
73139 - atomic_set(&p->ip_id_count,
73140 + atomic_set_unchecked(&p->rid, 0);
73141 + atomic_set_unchecked(&p->ip_id_count,
73142 (daddr->family == AF_INET) ?
73143 secure_ip_id(daddr->addr.a4) :
73144 secure_ipv6_id(daddr->addr.a6));
73145 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
73146 index fdaabf2..0ec3205 100644
73147 --- a/net/ipv4/ip_fragment.c
73148 +++ b/net/ipv4/ip_fragment.c
73149 @@ -316,7 +316,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
73150 return 0;
73151
73152 start = qp->rid;
73153 - end = atomic_inc_return(&peer->rid);
73154 + end = atomic_inc_return_unchecked(&peer->rid);
73155 qp->rid = end;
73156
73157 rc = qp->q.fragments && (end - start) > max;
73158 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
73159 index 09ff51b..d3968eb 100644
73160 --- a/net/ipv4/ip_sockglue.c
73161 +++ b/net/ipv4/ip_sockglue.c
73162 @@ -1111,7 +1111,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
73163 len = min_t(unsigned int, len, opt->optlen);
73164 if (put_user(len, optlen))
73165 return -EFAULT;
73166 - if (copy_to_user(optval, opt->__data, len))
73167 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
73168 + copy_to_user(optval, opt->__data, len))
73169 return -EFAULT;
73170 return 0;
73171 }
73172 @@ -1239,7 +1240,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
73173 if (sk->sk_type != SOCK_STREAM)
73174 return -ENOPROTOOPT;
73175
73176 - msg.msg_control = optval;
73177 + msg.msg_control = (void __force_kernel *)optval;
73178 msg.msg_controllen = len;
73179 msg.msg_flags = flags;
73180
73181 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
73182 index 99ec116..c5628fe 100644
73183 --- a/net/ipv4/ipconfig.c
73184 +++ b/net/ipv4/ipconfig.c
73185 @@ -318,7 +318,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
73186
73187 mm_segment_t oldfs = get_fs();
73188 set_fs(get_ds());
73189 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
73190 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
73191 set_fs(oldfs);
73192 return res;
73193 }
73194 @@ -329,7 +329,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
73195
73196 mm_segment_t oldfs = get_fs();
73197 set_fs(get_ds());
73198 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
73199 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
73200 set_fs(oldfs);
73201 return res;
73202 }
73203 @@ -340,7 +340,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
73204
73205 mm_segment_t oldfs = get_fs();
73206 set_fs(get_ds());
73207 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
73208 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
73209 set_fs(oldfs);
73210 return res;
73211 }
73212 diff --git a/net/ipv4/netfilter/nf_nat_snmp_basic.c b/net/ipv4/netfilter/nf_nat_snmp_basic.c
73213 index 2133c30..5c4b40b 100644
73214 --- a/net/ipv4/netfilter/nf_nat_snmp_basic.c
73215 +++ b/net/ipv4/netfilter/nf_nat_snmp_basic.c
73216 @@ -399,7 +399,7 @@ static unsigned char asn1_octets_decode(struct asn1_ctx *ctx,
73217
73218 *len = 0;
73219
73220 - *octets = kmalloc(eoc - ctx->pointer, GFP_ATOMIC);
73221 + *octets = kmalloc((eoc - ctx->pointer), GFP_ATOMIC);
73222 if (*octets == NULL)
73223 return 0;
73224
73225 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
73226 index 43d4c3b..1914409 100644
73227 --- a/net/ipv4/ping.c
73228 +++ b/net/ipv4/ping.c
73229 @@ -836,7 +836,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
73230 sk_rmem_alloc_get(sp),
73231 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73232 atomic_read(&sp->sk_refcnt), sp,
73233 - atomic_read(&sp->sk_drops), len);
73234 + atomic_read_unchecked(&sp->sk_drops), len);
73235 }
73236
73237 static int ping_seq_show(struct seq_file *seq, void *v)
73238 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
73239 index 007e2eb..85a18a0 100644
73240 --- a/net/ipv4/raw.c
73241 +++ b/net/ipv4/raw.c
73242 @@ -303,7 +303,7 @@ static int raw_rcv_skb(struct sock * sk, struct sk_buff * skb)
73243 int raw_rcv(struct sock *sk, struct sk_buff *skb)
73244 {
73245 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
73246 - atomic_inc(&sk->sk_drops);
73247 + atomic_inc_unchecked(&sk->sk_drops);
73248 kfree_skb(skb);
73249 return NET_RX_DROP;
73250 }
73251 @@ -738,16 +738,20 @@ static int raw_init(struct sock *sk)
73252
73253 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
73254 {
73255 + struct icmp_filter filter;
73256 +
73257 if (optlen > sizeof(struct icmp_filter))
73258 optlen = sizeof(struct icmp_filter);
73259 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
73260 + if (copy_from_user(&filter, optval, optlen))
73261 return -EFAULT;
73262 + raw_sk(sk)->filter = filter;
73263 return 0;
73264 }
73265
73266 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
73267 {
73268 int len, ret = -EFAULT;
73269 + struct icmp_filter filter;
73270
73271 if (get_user(len, optlen))
73272 goto out;
73273 @@ -757,8 +761,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
73274 if (len > sizeof(struct icmp_filter))
73275 len = sizeof(struct icmp_filter);
73276 ret = -EFAULT;
73277 - if (put_user(len, optlen) ||
73278 - copy_to_user(optval, &raw_sk(sk)->filter, len))
73279 + filter = raw_sk(sk)->filter;
73280 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
73281 goto out;
73282 ret = 0;
73283 out: return ret;
73284 @@ -986,7 +990,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
73285 sk_wmem_alloc_get(sp),
73286 sk_rmem_alloc_get(sp),
73287 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73288 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
73289 + atomic_read(&sp->sk_refcnt),
73290 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73291 + NULL,
73292 +#else
73293 + sp,
73294 +#endif
73295 + atomic_read_unchecked(&sp->sk_drops));
73296 }
73297
73298 static int raw_seq_show(struct seq_file *seq, void *v)
73299 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
73300 index 94cdbc5..0cb0063 100644
73301 --- a/net/ipv4/route.c
73302 +++ b/net/ipv4/route.c
73303 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
73304
73305 static inline int rt_genid(struct net *net)
73306 {
73307 - return atomic_read(&net->ipv4.rt_genid);
73308 + return atomic_read_unchecked(&net->ipv4.rt_genid);
73309 }
73310
73311 #ifdef CONFIG_PROC_FS
73312 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
73313 unsigned char shuffle;
73314
73315 get_random_bytes(&shuffle, sizeof(shuffle));
73316 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
73317 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
73318 redirect_genid++;
73319 }
73320
73321 @@ -3022,7 +3022,7 @@ static int rt_fill_info(struct net *net,
73322 error = rt->dst.error;
73323 if (peer) {
73324 inet_peer_refcheck(rt->peer);
73325 - id = atomic_read(&peer->ip_id_count) & 0xffff;
73326 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
73327 if (peer->tcp_ts_stamp) {
73328 ts = peer->tcp_ts;
73329 tsage = get_seconds() - peer->tcp_ts_stamp;
73330 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
73331 index c89e354..8bd55c8 100644
73332 --- a/net/ipv4/tcp_ipv4.c
73333 +++ b/net/ipv4/tcp_ipv4.c
73334 @@ -87,6 +87,9 @@ int sysctl_tcp_tw_reuse __read_mostly;
73335 int sysctl_tcp_low_latency __read_mostly;
73336 EXPORT_SYMBOL(sysctl_tcp_low_latency);
73337
73338 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73339 +extern int grsec_enable_blackhole;
73340 +#endif
73341
73342 #ifdef CONFIG_TCP_MD5SIG
73343 static struct tcp_md5sig_key *tcp_v4_md5_do_lookup(struct sock *sk,
73344 @@ -1627,6 +1630,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
73345 return 0;
73346
73347 reset:
73348 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73349 + if (!grsec_enable_blackhole)
73350 +#endif
73351 tcp_v4_send_reset(rsk, skb);
73352 discard:
73353 kfree_skb(skb);
73354 @@ -1689,12 +1695,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
73355 TCP_SKB_CB(skb)->sacked = 0;
73356
73357 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73358 - if (!sk)
73359 + if (!sk) {
73360 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73361 + ret = 1;
73362 +#endif
73363 goto no_tcp_socket;
73364 -
73365 + }
73366 process:
73367 - if (sk->sk_state == TCP_TIME_WAIT)
73368 + if (sk->sk_state == TCP_TIME_WAIT) {
73369 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73370 + ret = 2;
73371 +#endif
73372 goto do_time_wait;
73373 + }
73374
73375 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
73376 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
73377 @@ -1744,6 +1757,10 @@ no_tcp_socket:
73378 bad_packet:
73379 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73380 } else {
73381 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73382 + if (!grsec_enable_blackhole || (ret == 1 &&
73383 + (skb->dev->flags & IFF_LOOPBACK)))
73384 +#endif
73385 tcp_v4_send_reset(NULL, skb);
73386 }
73387
73388 @@ -2404,7 +2421,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
73389 0, /* non standard timer */
73390 0, /* open_requests have no inode */
73391 atomic_read(&sk->sk_refcnt),
73392 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73393 + NULL,
73394 +#else
73395 req,
73396 +#endif
73397 len);
73398 }
73399
73400 @@ -2454,7 +2475,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
73401 sock_i_uid(sk),
73402 icsk->icsk_probes_out,
73403 sock_i_ino(sk),
73404 - atomic_read(&sk->sk_refcnt), sk,
73405 + atomic_read(&sk->sk_refcnt),
73406 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73407 + NULL,
73408 +#else
73409 + sk,
73410 +#endif
73411 jiffies_to_clock_t(icsk->icsk_rto),
73412 jiffies_to_clock_t(icsk->icsk_ack.ato),
73413 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
73414 @@ -2482,7 +2508,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
73415 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
73416 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
73417 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
73418 - atomic_read(&tw->tw_refcnt), tw, len);
73419 + atomic_read(&tw->tw_refcnt),
73420 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73421 + NULL,
73422 +#else
73423 + tw,
73424 +#endif
73425 + len);
73426 }
73427
73428 #define TMPSZ 150
73429 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
73430 index 66363b6..b0654a3 100644
73431 --- a/net/ipv4/tcp_minisocks.c
73432 +++ b/net/ipv4/tcp_minisocks.c
73433 @@ -27,6 +27,10 @@
73434 #include <net/inet_common.h>
73435 #include <net/xfrm.h>
73436
73437 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73438 +extern int grsec_enable_blackhole;
73439 +#endif
73440 +
73441 int sysctl_tcp_syncookies __read_mostly = 1;
73442 EXPORT_SYMBOL(sysctl_tcp_syncookies);
73443
73444 @@ -751,6 +755,10 @@ listen_overflow:
73445
73446 embryonic_reset:
73447 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
73448 +
73449 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73450 + if (!grsec_enable_blackhole)
73451 +#endif
73452 if (!(flg & TCP_FLAG_RST))
73453 req->rsk_ops->send_reset(sk, skb);
73454
73455 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
73456 index 85ee7eb..53277ab 100644
73457 --- a/net/ipv4/tcp_probe.c
73458 +++ b/net/ipv4/tcp_probe.c
73459 @@ -202,7 +202,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
73460 if (cnt + width >= len)
73461 break;
73462
73463 - if (copy_to_user(buf + cnt, tbuf, width))
73464 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
73465 return -EFAULT;
73466 cnt += width;
73467 }
73468 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
73469 index 2e0f0af..e2948bf 100644
73470 --- a/net/ipv4/tcp_timer.c
73471 +++ b/net/ipv4/tcp_timer.c
73472 @@ -22,6 +22,10 @@
73473 #include <linux/gfp.h>
73474 #include <net/tcp.h>
73475
73476 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73477 +extern int grsec_lastack_retries;
73478 +#endif
73479 +
73480 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
73481 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
73482 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
73483 @@ -199,6 +203,13 @@ static int tcp_write_timeout(struct sock *sk)
73484 }
73485 }
73486
73487 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73488 + if ((sk->sk_state == TCP_LAST_ACK) &&
73489 + (grsec_lastack_retries > 0) &&
73490 + (grsec_lastack_retries < retry_until))
73491 + retry_until = grsec_lastack_retries;
73492 +#endif
73493 +
73494 if (retransmits_timed_out(sk, retry_until,
73495 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
73496 /* Has it gone just too far? */
73497 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
73498 index 5a65eea..bd913a1 100644
73499 --- a/net/ipv4/udp.c
73500 +++ b/net/ipv4/udp.c
73501 @@ -86,6 +86,7 @@
73502 #include <linux/types.h>
73503 #include <linux/fcntl.h>
73504 #include <linux/module.h>
73505 +#include <linux/security.h>
73506 #include <linux/socket.h>
73507 #include <linux/sockios.h>
73508 #include <linux/igmp.h>
73509 @@ -108,6 +109,10 @@
73510 #include <trace/events/udp.h>
73511 #include "udp_impl.h"
73512
73513 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73514 +extern int grsec_enable_blackhole;
73515 +#endif
73516 +
73517 struct udp_table udp_table __read_mostly;
73518 EXPORT_SYMBOL(udp_table);
73519
73520 @@ -565,6 +570,9 @@ found:
73521 return s;
73522 }
73523
73524 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
73525 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
73526 +
73527 /*
73528 * This routine is called by the ICMP module when it gets some
73529 * sort of error condition. If err < 0 then the socket should
73530 @@ -856,9 +864,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
73531 dport = usin->sin_port;
73532 if (dport == 0)
73533 return -EINVAL;
73534 +
73535 + err = gr_search_udp_sendmsg(sk, usin);
73536 + if (err)
73537 + return err;
73538 } else {
73539 if (sk->sk_state != TCP_ESTABLISHED)
73540 return -EDESTADDRREQ;
73541 +
73542 + err = gr_search_udp_sendmsg(sk, NULL);
73543 + if (err)
73544 + return err;
73545 +
73546 daddr = inet->inet_daddr;
73547 dport = inet->inet_dport;
73548 /* Open fast path for connected socket.
73549 @@ -1099,7 +1116,7 @@ static unsigned int first_packet_length(struct sock *sk)
73550 udp_lib_checksum_complete(skb)) {
73551 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
73552 IS_UDPLITE(sk));
73553 - atomic_inc(&sk->sk_drops);
73554 + atomic_inc_unchecked(&sk->sk_drops);
73555 __skb_unlink(skb, rcvq);
73556 __skb_queue_tail(&list_kill, skb);
73557 }
73558 @@ -1185,6 +1202,10 @@ try_again:
73559 if (!skb)
73560 goto out;
73561
73562 + err = gr_search_udp_recvmsg(sk, skb);
73563 + if (err)
73564 + goto out_free;
73565 +
73566 ulen = skb->len - sizeof(struct udphdr);
73567 copied = len;
73568 if (copied > ulen)
73569 @@ -1487,7 +1508,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
73570
73571 drop:
73572 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
73573 - atomic_inc(&sk->sk_drops);
73574 + atomic_inc_unchecked(&sk->sk_drops);
73575 kfree_skb(skb);
73576 return -1;
73577 }
73578 @@ -1506,7 +1527,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
73579 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
73580
73581 if (!skb1) {
73582 - atomic_inc(&sk->sk_drops);
73583 + atomic_inc_unchecked(&sk->sk_drops);
73584 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
73585 IS_UDPLITE(sk));
73586 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
73587 @@ -1675,6 +1696,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73588 goto csum_error;
73589
73590 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
73591 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73592 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
73593 +#endif
73594 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
73595
73596 /*
73597 @@ -2098,8 +2122,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
73598 sk_wmem_alloc_get(sp),
73599 sk_rmem_alloc_get(sp),
73600 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
73601 - atomic_read(&sp->sk_refcnt), sp,
73602 - atomic_read(&sp->sk_drops), len);
73603 + atomic_read(&sp->sk_refcnt),
73604 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73605 + NULL,
73606 +#else
73607 + sp,
73608 +#endif
73609 + atomic_read_unchecked(&sp->sk_drops), len);
73610 }
73611
73612 int udp4_seq_show(struct seq_file *seq, void *v)
73613 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
73614 index 836c4ea..cbb74dc 100644
73615 --- a/net/ipv6/addrconf.c
73616 +++ b/net/ipv6/addrconf.c
73617 @@ -2149,7 +2149,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
73618 p.iph.ihl = 5;
73619 p.iph.protocol = IPPROTO_IPV6;
73620 p.iph.ttl = 64;
73621 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
73622 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
73623
73624 if (ops->ndo_do_ioctl) {
73625 mm_segment_t oldfs = get_fs();
73626 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
73627 index 1567fb1..29af910 100644
73628 --- a/net/ipv6/inet6_connection_sock.c
73629 +++ b/net/ipv6/inet6_connection_sock.c
73630 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
73631 #ifdef CONFIG_XFRM
73632 {
73633 struct rt6_info *rt = (struct rt6_info *)dst;
73634 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
73635 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
73636 }
73637 #endif
73638 }
73639 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
73640 #ifdef CONFIG_XFRM
73641 if (dst) {
73642 struct rt6_info *rt = (struct rt6_info *)dst;
73643 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
73644 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
73645 __sk_dst_reset(sk);
73646 dst = NULL;
73647 }
73648 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
73649 index 26cb08c..8af9877 100644
73650 --- a/net/ipv6/ipv6_sockglue.c
73651 +++ b/net/ipv6/ipv6_sockglue.c
73652 @@ -960,7 +960,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
73653 if (sk->sk_type != SOCK_STREAM)
73654 return -ENOPROTOOPT;
73655
73656 - msg.msg_control = optval;
73657 + msg.msg_control = (void __force_kernel *)optval;
73658 msg.msg_controllen = len;
73659 msg.msg_flags = flags;
73660
73661 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
73662 index 361ebf3..d5628fb 100644
73663 --- a/net/ipv6/raw.c
73664 +++ b/net/ipv6/raw.c
73665 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
73666 {
73667 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
73668 skb_checksum_complete(skb)) {
73669 - atomic_inc(&sk->sk_drops);
73670 + atomic_inc_unchecked(&sk->sk_drops);
73671 kfree_skb(skb);
73672 return NET_RX_DROP;
73673 }
73674 @@ -404,7 +404,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
73675 struct raw6_sock *rp = raw6_sk(sk);
73676
73677 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
73678 - atomic_inc(&sk->sk_drops);
73679 + atomic_inc_unchecked(&sk->sk_drops);
73680 kfree_skb(skb);
73681 return NET_RX_DROP;
73682 }
73683 @@ -428,7 +428,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
73684
73685 if (inet->hdrincl) {
73686 if (skb_checksum_complete(skb)) {
73687 - atomic_inc(&sk->sk_drops);
73688 + atomic_inc_unchecked(&sk->sk_drops);
73689 kfree_skb(skb);
73690 return NET_RX_DROP;
73691 }
73692 @@ -601,7 +601,7 @@ out:
73693 return err;
73694 }
73695
73696 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
73697 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
73698 struct flowi6 *fl6, struct dst_entry **dstp,
73699 unsigned int flags)
73700 {
73701 @@ -909,12 +909,15 @@ do_confirm:
73702 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
73703 char __user *optval, int optlen)
73704 {
73705 + struct icmp6_filter filter;
73706 +
73707 switch (optname) {
73708 case ICMPV6_FILTER:
73709 if (optlen > sizeof(struct icmp6_filter))
73710 optlen = sizeof(struct icmp6_filter);
73711 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
73712 + if (copy_from_user(&filter, optval, optlen))
73713 return -EFAULT;
73714 + raw6_sk(sk)->filter = filter;
73715 return 0;
73716 default:
73717 return -ENOPROTOOPT;
73718 @@ -927,6 +930,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73719 char __user *optval, int __user *optlen)
73720 {
73721 int len;
73722 + struct icmp6_filter filter;
73723
73724 switch (optname) {
73725 case ICMPV6_FILTER:
73726 @@ -938,7 +942,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
73727 len = sizeof(struct icmp6_filter);
73728 if (put_user(len, optlen))
73729 return -EFAULT;
73730 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
73731 + filter = raw6_sk(sk)->filter;
73732 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
73733 return -EFAULT;
73734 return 0;
73735 default:
73736 @@ -1245,7 +1250,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
73737 0, 0L, 0,
73738 sock_i_uid(sp), 0,
73739 sock_i_ino(sp),
73740 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
73741 + atomic_read(&sp->sk_refcnt),
73742 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73743 + NULL,
73744 +#else
73745 + sp,
73746 +#endif
73747 + atomic_read_unchecked(&sp->sk_drops));
73748 }
73749
73750 static int raw6_seq_show(struct seq_file *seq, void *v)
73751 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
73752 index b859e4a..f9d1589 100644
73753 --- a/net/ipv6/tcp_ipv6.c
73754 +++ b/net/ipv6/tcp_ipv6.c
73755 @@ -93,6 +93,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
73756 }
73757 #endif
73758
73759 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73760 +extern int grsec_enable_blackhole;
73761 +#endif
73762 +
73763 static void tcp_v6_hash(struct sock *sk)
73764 {
73765 if (sk->sk_state != TCP_CLOSE) {
73766 @@ -1651,6 +1655,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
73767 return 0;
73768
73769 reset:
73770 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73771 + if (!grsec_enable_blackhole)
73772 +#endif
73773 tcp_v6_send_reset(sk, skb);
73774 discard:
73775 if (opt_skb)
73776 @@ -1730,12 +1737,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
73777 TCP_SKB_CB(skb)->sacked = 0;
73778
73779 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
73780 - if (!sk)
73781 + if (!sk) {
73782 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73783 + ret = 1;
73784 +#endif
73785 goto no_tcp_socket;
73786 + }
73787
73788 process:
73789 - if (sk->sk_state == TCP_TIME_WAIT)
73790 + if (sk->sk_state == TCP_TIME_WAIT) {
73791 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73792 + ret = 2;
73793 +#endif
73794 goto do_time_wait;
73795 + }
73796
73797 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
73798 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
73799 @@ -1783,6 +1798,10 @@ no_tcp_socket:
73800 bad_packet:
73801 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
73802 } else {
73803 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73804 + if (!grsec_enable_blackhole || (ret == 1 &&
73805 + (skb->dev->flags & IFF_LOOPBACK)))
73806 +#endif
73807 tcp_v6_send_reset(NULL, skb);
73808 }
73809
73810 @@ -2043,7 +2062,13 @@ static void get_openreq6(struct seq_file *seq,
73811 uid,
73812 0, /* non standard timer */
73813 0, /* open_requests have no inode */
73814 - 0, req);
73815 + 0,
73816 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73817 + NULL
73818 +#else
73819 + req
73820 +#endif
73821 + );
73822 }
73823
73824 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
73825 @@ -2093,7 +2118,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
73826 sock_i_uid(sp),
73827 icsk->icsk_probes_out,
73828 sock_i_ino(sp),
73829 - atomic_read(&sp->sk_refcnt), sp,
73830 + atomic_read(&sp->sk_refcnt),
73831 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73832 + NULL,
73833 +#else
73834 + sp,
73835 +#endif
73836 jiffies_to_clock_t(icsk->icsk_rto),
73837 jiffies_to_clock_t(icsk->icsk_ack.ato),
73838 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
73839 @@ -2128,7 +2158,13 @@ static void get_timewait6_sock(struct seq_file *seq,
73840 dest->s6_addr32[2], dest->s6_addr32[3], destp,
73841 tw->tw_substate, 0, 0,
73842 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
73843 - atomic_read(&tw->tw_refcnt), tw);
73844 + atomic_read(&tw->tw_refcnt),
73845 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73846 + NULL
73847 +#else
73848 + tw
73849 +#endif
73850 + );
73851 }
73852
73853 static int tcp6_seq_show(struct seq_file *seq, void *v)
73854 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
73855 index 8c25419..47a51ae 100644
73856 --- a/net/ipv6/udp.c
73857 +++ b/net/ipv6/udp.c
73858 @@ -50,6 +50,10 @@
73859 #include <linux/seq_file.h>
73860 #include "udp_impl.h"
73861
73862 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73863 +extern int grsec_enable_blackhole;
73864 +#endif
73865 +
73866 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
73867 {
73868 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
73869 @@ -549,7 +553,7 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb)
73870
73871 return 0;
73872 drop:
73873 - atomic_inc(&sk->sk_drops);
73874 + atomic_inc_unchecked(&sk->sk_drops);
73875 drop_no_sk_drops_inc:
73876 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
73877 kfree_skb(skb);
73878 @@ -625,7 +629,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
73879 continue;
73880 }
73881 drop:
73882 - atomic_inc(&sk->sk_drops);
73883 + atomic_inc_unchecked(&sk->sk_drops);
73884 UDP6_INC_STATS_BH(sock_net(sk),
73885 UDP_MIB_RCVBUFERRORS, IS_UDPLITE(sk));
73886 UDP6_INC_STATS_BH(sock_net(sk),
73887 @@ -780,6 +784,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73888 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS,
73889 proto == IPPROTO_UDPLITE);
73890
73891 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73892 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
73893 +#endif
73894 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
73895
73896 kfree_skb(skb);
73897 @@ -796,7 +803,7 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
73898 if (!sock_owned_by_user(sk))
73899 udpv6_queue_rcv_skb(sk, skb);
73900 else if (sk_add_backlog(sk, skb)) {
73901 - atomic_inc(&sk->sk_drops);
73902 + atomic_inc_unchecked(&sk->sk_drops);
73903 bh_unlock_sock(sk);
73904 sock_put(sk);
73905 goto discard;
73906 @@ -1407,8 +1414,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
73907 0, 0L, 0,
73908 sock_i_uid(sp), 0,
73909 sock_i_ino(sp),
73910 - atomic_read(&sp->sk_refcnt), sp,
73911 - atomic_read(&sp->sk_drops));
73912 + atomic_read(&sp->sk_refcnt),
73913 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73914 + NULL,
73915 +#else
73916 + sp,
73917 +#endif
73918 + atomic_read_unchecked(&sp->sk_drops));
73919 }
73920
73921 int udp6_seq_show(struct seq_file *seq, void *v)
73922 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
73923 index 253695d..9481ce8 100644
73924 --- a/net/irda/ircomm/ircomm_tty.c
73925 +++ b/net/irda/ircomm/ircomm_tty.c
73926 @@ -282,16 +282,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73927 add_wait_queue(&self->open_wait, &wait);
73928
73929 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
73930 - __FILE__,__LINE__, tty->driver->name, self->open_count );
73931 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
73932
73933 /* As far as I can see, we protect open_count - Jean II */
73934 spin_lock_irqsave(&self->spinlock, flags);
73935 if (!tty_hung_up_p(filp)) {
73936 extra_count = 1;
73937 - self->open_count--;
73938 + local_dec(&self->open_count);
73939 }
73940 spin_unlock_irqrestore(&self->spinlock, flags);
73941 - self->blocked_open++;
73942 + local_inc(&self->blocked_open);
73943
73944 while (1) {
73945 if (tty->termios->c_cflag & CBAUD) {
73946 @@ -331,7 +331,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73947 }
73948
73949 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
73950 - __FILE__,__LINE__, tty->driver->name, self->open_count );
73951 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
73952
73953 schedule();
73954 }
73955 @@ -342,13 +342,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
73956 if (extra_count) {
73957 /* ++ is not atomic, so this should be protected - Jean II */
73958 spin_lock_irqsave(&self->spinlock, flags);
73959 - self->open_count++;
73960 + local_inc(&self->open_count);
73961 spin_unlock_irqrestore(&self->spinlock, flags);
73962 }
73963 - self->blocked_open--;
73964 + local_dec(&self->blocked_open);
73965
73966 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
73967 - __FILE__,__LINE__, tty->driver->name, self->open_count);
73968 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
73969
73970 if (!retval)
73971 self->flags |= ASYNC_NORMAL_ACTIVE;
73972 @@ -417,14 +417,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
73973 }
73974 /* ++ is not atomic, so this should be protected - Jean II */
73975 spin_lock_irqsave(&self->spinlock, flags);
73976 - self->open_count++;
73977 + local_inc(&self->open_count);
73978
73979 tty->driver_data = self;
73980 self->tty = tty;
73981 spin_unlock_irqrestore(&self->spinlock, flags);
73982
73983 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
73984 - self->line, self->open_count);
73985 + self->line, local_read(&self->open_count));
73986
73987 /* Not really used by us, but lets do it anyway */
73988 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
73989 @@ -510,7 +510,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
73990 return;
73991 }
73992
73993 - if ((tty->count == 1) && (self->open_count != 1)) {
73994 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
73995 /*
73996 * Uh, oh. tty->count is 1, which means that the tty
73997 * structure will be freed. state->count should always
73998 @@ -520,16 +520,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
73999 */
74000 IRDA_DEBUG(0, "%s(), bad serial port count; "
74001 "tty->count is 1, state->count is %d\n", __func__ ,
74002 - self->open_count);
74003 - self->open_count = 1;
74004 + local_read(&self->open_count));
74005 + local_set(&self->open_count, 1);
74006 }
74007
74008 - if (--self->open_count < 0) {
74009 + if (local_dec_return(&self->open_count) < 0) {
74010 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
74011 - __func__, self->line, self->open_count);
74012 - self->open_count = 0;
74013 + __func__, self->line, local_read(&self->open_count));
74014 + local_set(&self->open_count, 0);
74015 }
74016 - if (self->open_count) {
74017 + if (local_read(&self->open_count)) {
74018 spin_unlock_irqrestore(&self->spinlock, flags);
74019
74020 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
74021 @@ -561,7 +561,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
74022 tty->closing = 0;
74023 self->tty = NULL;
74024
74025 - if (self->blocked_open) {
74026 + if (local_read(&self->blocked_open)) {
74027 if (self->close_delay)
74028 schedule_timeout_interruptible(self->close_delay);
74029 wake_up_interruptible(&self->open_wait);
74030 @@ -1013,7 +1013,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
74031 spin_lock_irqsave(&self->spinlock, flags);
74032 self->flags &= ~ASYNC_NORMAL_ACTIVE;
74033 self->tty = NULL;
74034 - self->open_count = 0;
74035 + local_set(&self->open_count, 0);
74036 spin_unlock_irqrestore(&self->spinlock, flags);
74037
74038 wake_up_interruptible(&self->open_wait);
74039 @@ -1360,7 +1360,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
74040 seq_putc(m, '\n');
74041
74042 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
74043 - seq_printf(m, "Open count: %d\n", self->open_count);
74044 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
74045 seq_printf(m, "Max data size: %d\n", self->max_data_size);
74046 seq_printf(m, "Max header size: %d\n", self->max_header_size);
74047
74048 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
74049 index 274d150..656a144 100644
74050 --- a/net/iucv/af_iucv.c
74051 +++ b/net/iucv/af_iucv.c
74052 @@ -787,10 +787,10 @@ static int iucv_sock_autobind(struct sock *sk)
74053
74054 write_lock_bh(&iucv_sk_list.lock);
74055
74056 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
74057 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
74058 while (__iucv_get_sock_by_name(name)) {
74059 sprintf(name, "%08x",
74060 - atomic_inc_return(&iucv_sk_list.autobind_name));
74061 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
74062 }
74063
74064 write_unlock_bh(&iucv_sk_list.lock);
74065 diff --git a/net/key/af_key.c b/net/key/af_key.c
74066 index 1e733e9..3d73c9f 100644
74067 --- a/net/key/af_key.c
74068 +++ b/net/key/af_key.c
74069 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
74070 static u32 get_acqseq(void)
74071 {
74072 u32 res;
74073 - static atomic_t acqseq;
74074 + static atomic_unchecked_t acqseq;
74075
74076 do {
74077 - res = atomic_inc_return(&acqseq);
74078 + res = atomic_inc_return_unchecked(&acqseq);
74079 } while (!res);
74080 return res;
74081 }
74082 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
74083 index 73495f1..ad51356 100644
74084 --- a/net/mac80211/ieee80211_i.h
74085 +++ b/net/mac80211/ieee80211_i.h
74086 @@ -27,6 +27,7 @@
74087 #include <net/ieee80211_radiotap.h>
74088 #include <net/cfg80211.h>
74089 #include <net/mac80211.h>
74090 +#include <asm/local.h>
74091 #include "key.h"
74092 #include "sta_info.h"
74093
74094 @@ -764,7 +765,7 @@ struct ieee80211_local {
74095 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
74096 spinlock_t queue_stop_reason_lock;
74097
74098 - int open_count;
74099 + local_t open_count;
74100 int monitors, cooked_mntrs;
74101 /* number of interfaces with corresponding FIF_ flags */
74102 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
74103 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
74104 index 30d7355..e260095 100644
74105 --- a/net/mac80211/iface.c
74106 +++ b/net/mac80211/iface.c
74107 @@ -211,7 +211,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
74108 break;
74109 }
74110
74111 - if (local->open_count == 0) {
74112 + if (local_read(&local->open_count) == 0) {
74113 res = drv_start(local);
74114 if (res)
74115 goto err_del_bss;
74116 @@ -235,7 +235,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
74117 memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
74118
74119 if (!is_valid_ether_addr(dev->dev_addr)) {
74120 - if (!local->open_count)
74121 + if (!local_read(&local->open_count))
74122 drv_stop(local);
74123 return -EADDRNOTAVAIL;
74124 }
74125 @@ -327,7 +327,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
74126 mutex_unlock(&local->mtx);
74127
74128 if (coming_up)
74129 - local->open_count++;
74130 + local_inc(&local->open_count);
74131
74132 if (hw_reconf_flags) {
74133 ieee80211_hw_config(local, hw_reconf_flags);
74134 @@ -347,7 +347,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
74135 err_del_interface:
74136 drv_remove_interface(local, &sdata->vif);
74137 err_stop:
74138 - if (!local->open_count)
74139 + if (!local_read(&local->open_count))
74140 drv_stop(local);
74141 err_del_bss:
74142 sdata->bss = NULL;
74143 @@ -472,7 +472,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
74144 }
74145
74146 if (going_down)
74147 - local->open_count--;
74148 + local_dec(&local->open_count);
74149
74150 switch (sdata->vif.type) {
74151 case NL80211_IFTYPE_AP_VLAN:
74152 @@ -531,7 +531,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
74153
74154 ieee80211_recalc_ps(local, -1);
74155
74156 - if (local->open_count == 0) {
74157 + if (local_read(&local->open_count) == 0) {
74158 if (local->ops->napi_poll)
74159 napi_disable(&local->napi);
74160 ieee80211_clear_tx_pending(local);
74161 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
74162 index a7536fd..4039cc0 100644
74163 --- a/net/mac80211/main.c
74164 +++ b/net/mac80211/main.c
74165 @@ -163,7 +163,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
74166 local->hw.conf.power_level = power;
74167 }
74168
74169 - if (changed && local->open_count) {
74170 + if (changed && local_read(&local->open_count)) {
74171 ret = drv_config(local, changed);
74172 /*
74173 * Goal:
74174 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
74175 index 9ee7164..56c5061 100644
74176 --- a/net/mac80211/pm.c
74177 +++ b/net/mac80211/pm.c
74178 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
74179 struct ieee80211_sub_if_data *sdata;
74180 struct sta_info *sta;
74181
74182 - if (!local->open_count)
74183 + if (!local_read(&local->open_count))
74184 goto suspend;
74185
74186 ieee80211_scan_cancel(local);
74187 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
74188 cancel_work_sync(&local->dynamic_ps_enable_work);
74189 del_timer_sync(&local->dynamic_ps_timer);
74190
74191 - local->wowlan = wowlan && local->open_count;
74192 + local->wowlan = wowlan && local_read(&local->open_count);
74193 if (local->wowlan) {
74194 int err = drv_suspend(local, wowlan);
74195 if (err < 0) {
74196 @@ -129,7 +129,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
74197 }
74198
74199 /* stop hardware - this must stop RX */
74200 - if (local->open_count)
74201 + if (local_read(&local->open_count))
74202 ieee80211_stop_device(local);
74203
74204 suspend:
74205 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
74206 index 5a5a776..9600b11 100644
74207 --- a/net/mac80211/rate.c
74208 +++ b/net/mac80211/rate.c
74209 @@ -401,7 +401,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
74210
74211 ASSERT_RTNL();
74212
74213 - if (local->open_count)
74214 + if (local_read(&local->open_count))
74215 return -EBUSY;
74216
74217 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
74218 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
74219 index c97a065..ff61928 100644
74220 --- a/net/mac80211/rc80211_pid_debugfs.c
74221 +++ b/net/mac80211/rc80211_pid_debugfs.c
74222 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
74223
74224 spin_unlock_irqrestore(&events->lock, status);
74225
74226 - if (copy_to_user(buf, pb, p))
74227 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
74228 return -EFAULT;
74229
74230 return p;
74231 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
74232 index d5230ec..c604b21 100644
74233 --- a/net/mac80211/util.c
74234 +++ b/net/mac80211/util.c
74235 @@ -1000,7 +1000,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
74236 drv_set_coverage_class(local, hw->wiphy->coverage_class);
74237
74238 /* everything else happens only if HW was up & running */
74239 - if (!local->open_count)
74240 + if (!local_read(&local->open_count))
74241 goto wake_up;
74242
74243 /*
74244 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
74245 index d5597b7..ab6d39c 100644
74246 --- a/net/netfilter/Kconfig
74247 +++ b/net/netfilter/Kconfig
74248 @@ -779,6 +779,16 @@ config NETFILTER_XT_MATCH_ESP
74249
74250 To compile it as a module, choose M here. If unsure, say N.
74251
74252 +config NETFILTER_XT_MATCH_GRADM
74253 + tristate '"gradm" match support'
74254 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
74255 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
74256 + ---help---
74257 + The gradm match allows to match on grsecurity RBAC being enabled.
74258 + It is useful when iptables rules are applied early on bootup to
74259 + prevent connections to the machine (except from a trusted host)
74260 + while the RBAC system is disabled.
74261 +
74262 config NETFILTER_XT_MATCH_HASHLIMIT
74263 tristate '"hashlimit" match support'
74264 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
74265 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
74266 index 1a02853..5d8c22e 100644
74267 --- a/net/netfilter/Makefile
74268 +++ b/net/netfilter/Makefile
74269 @@ -81,6 +81,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DCCP) += xt_dccp.o
74270 obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
74271 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
74272 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
74273 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
74274 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
74275 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
74276 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
74277 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
74278 index 29fa5ba..8debc79 100644
74279 --- a/net/netfilter/ipvs/ip_vs_conn.c
74280 +++ b/net/netfilter/ipvs/ip_vs_conn.c
74281 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
74282 /* Increase the refcnt counter of the dest */
74283 atomic_inc(&dest->refcnt);
74284
74285 - conn_flags = atomic_read(&dest->conn_flags);
74286 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
74287 if (cp->protocol != IPPROTO_UDP)
74288 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
74289 /* Bind with the destination and its corresponding transmitter */
74290 @@ -869,7 +869,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
74291 atomic_set(&cp->refcnt, 1);
74292
74293 atomic_set(&cp->n_control, 0);
74294 - atomic_set(&cp->in_pkts, 0);
74295 + atomic_set_unchecked(&cp->in_pkts, 0);
74296
74297 atomic_inc(&ipvs->conn_count);
74298 if (flags & IP_VS_CONN_F_NO_CPORT)
74299 @@ -1149,7 +1149,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
74300
74301 /* Don't drop the entry if its number of incoming packets is not
74302 located in [0, 8] */
74303 - i = atomic_read(&cp->in_pkts);
74304 + i = atomic_read_unchecked(&cp->in_pkts);
74305 if (i > 8 || i < 0) return 0;
74306
74307 if (!todrop_rate[i]) return 0;
74308 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
74309 index 093cc32..9209ae1 100644
74310 --- a/net/netfilter/ipvs/ip_vs_core.c
74311 +++ b/net/netfilter/ipvs/ip_vs_core.c
74312 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
74313 ret = cp->packet_xmit(skb, cp, pd->pp);
74314 /* do not touch skb anymore */
74315
74316 - atomic_inc(&cp->in_pkts);
74317 + atomic_inc_unchecked(&cp->in_pkts);
74318 ip_vs_conn_put(cp);
74319 return ret;
74320 }
74321 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
74322 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
74323 pkts = sysctl_sync_threshold(ipvs);
74324 else
74325 - pkts = atomic_add_return(1, &cp->in_pkts);
74326 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
74327
74328 if ((ipvs->sync_state & IP_VS_STATE_MASTER) &&
74329 cp->protocol == IPPROTO_SCTP) {
74330 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
74331 index e1a66cf..0910076 100644
74332 --- a/net/netfilter/ipvs/ip_vs_ctl.c
74333 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
74334 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
74335 ip_vs_rs_hash(ipvs, dest);
74336 write_unlock_bh(&ipvs->rs_lock);
74337 }
74338 - atomic_set(&dest->conn_flags, conn_flags);
74339 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
74340
74341 /* bind the service */
74342 if (!dest->svc) {
74343 @@ -2028,7 +2028,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
74344 " %-7s %-6d %-10d %-10d\n",
74345 &dest->addr.in6,
74346 ntohs(dest->port),
74347 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
74348 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
74349 atomic_read(&dest->weight),
74350 atomic_read(&dest->activeconns),
74351 atomic_read(&dest->inactconns));
74352 @@ -2039,7 +2039,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
74353 "%-7s %-6d %-10d %-10d\n",
74354 ntohl(dest->addr.ip),
74355 ntohs(dest->port),
74356 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
74357 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
74358 atomic_read(&dest->weight),
74359 atomic_read(&dest->activeconns),
74360 atomic_read(&dest->inactconns));
74361 @@ -2509,7 +2509,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
74362
74363 entry.addr = dest->addr.ip;
74364 entry.port = dest->port;
74365 - entry.conn_flags = atomic_read(&dest->conn_flags);
74366 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
74367 entry.weight = atomic_read(&dest->weight);
74368 entry.u_threshold = dest->u_threshold;
74369 entry.l_threshold = dest->l_threshold;
74370 @@ -3042,7 +3042,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
74371 NLA_PUT_U16(skb, IPVS_DEST_ATTR_PORT, dest->port);
74372
74373 NLA_PUT_U32(skb, IPVS_DEST_ATTR_FWD_METHOD,
74374 - atomic_read(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
74375 + atomic_read_unchecked(&dest->conn_flags) & IP_VS_CONN_F_FWD_MASK);
74376 NLA_PUT_U32(skb, IPVS_DEST_ATTR_WEIGHT, atomic_read(&dest->weight));
74377 NLA_PUT_U32(skb, IPVS_DEST_ATTR_U_THRESH, dest->u_threshold);
74378 NLA_PUT_U32(skb, IPVS_DEST_ATTR_L_THRESH, dest->l_threshold);
74379 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
74380 index 2b6678c0..aaa41fc 100644
74381 --- a/net/netfilter/ipvs/ip_vs_sync.c
74382 +++ b/net/netfilter/ipvs/ip_vs_sync.c
74383 @@ -649,7 +649,7 @@ control:
74384 * i.e only increment in_pkts for Templates.
74385 */
74386 if (cp->flags & IP_VS_CONN_F_TEMPLATE) {
74387 - int pkts = atomic_add_return(1, &cp->in_pkts);
74388 + int pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
74389
74390 if (pkts % sysctl_sync_period(ipvs) != 1)
74391 return;
74392 @@ -795,7 +795,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
74393
74394 if (opt)
74395 memcpy(&cp->in_seq, opt, sizeof(*opt));
74396 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
74397 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
74398 cp->state = state;
74399 cp->old_state = cp->state;
74400 /*
74401 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
74402 index aa2d720..d8aa111 100644
74403 --- a/net/netfilter/ipvs/ip_vs_xmit.c
74404 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
74405 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
74406 else
74407 rc = NF_ACCEPT;
74408 /* do not touch skb anymore */
74409 - atomic_inc(&cp->in_pkts);
74410 + atomic_inc_unchecked(&cp->in_pkts);
74411 goto out;
74412 }
74413
74414 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
74415 else
74416 rc = NF_ACCEPT;
74417 /* do not touch skb anymore */
74418 - atomic_inc(&cp->in_pkts);
74419 + atomic_inc_unchecked(&cp->in_pkts);
74420 goto out;
74421 }
74422
74423 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
74424 index 66b2c54..c7884e3 100644
74425 --- a/net/netfilter/nfnetlink_log.c
74426 +++ b/net/netfilter/nfnetlink_log.c
74427 @@ -70,7 +70,7 @@ struct nfulnl_instance {
74428 };
74429
74430 static DEFINE_SPINLOCK(instances_lock);
74431 -static atomic_t global_seq;
74432 +static atomic_unchecked_t global_seq;
74433
74434 #define INSTANCE_BUCKETS 16
74435 static struct hlist_head instance_table[INSTANCE_BUCKETS];
74436 @@ -502,7 +502,7 @@ __build_packet_message(struct nfulnl_instance *inst,
74437 /* global sequence number */
74438 if (inst->flags & NFULNL_CFG_F_SEQ_GLOBAL)
74439 NLA_PUT_BE32(inst->skb, NFULA_SEQ_GLOBAL,
74440 - htonl(atomic_inc_return(&global_seq)));
74441 + htonl(atomic_inc_return_unchecked(&global_seq)));
74442
74443 if (data_len) {
74444 struct nlattr *nla;
74445 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
74446 new file mode 100644
74447 index 0000000..6905327
74448 --- /dev/null
74449 +++ b/net/netfilter/xt_gradm.c
74450 @@ -0,0 +1,51 @@
74451 +/*
74452 + * gradm match for netfilter
74453 + * Copyright © Zbigniew Krzystolik, 2010
74454 + *
74455 + * This program is free software; you can redistribute it and/or modify
74456 + * it under the terms of the GNU General Public License; either version
74457 + * 2 or 3 as published by the Free Software Foundation.
74458 + */
74459 +#include <linux/module.h>
74460 +#include <linux/moduleparam.h>
74461 +#include <linux/skbuff.h>
74462 +#include <linux/netfilter/x_tables.h>
74463 +#include <linux/grsecurity.h>
74464 +#include <linux/netfilter/xt_gradm.h>
74465 +
74466 +static bool
74467 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
74468 +{
74469 + const struct xt_gradm_mtinfo *info = par->matchinfo;
74470 + bool retval = false;
74471 + if (gr_acl_is_enabled())
74472 + retval = true;
74473 + return retval ^ info->invflags;
74474 +}
74475 +
74476 +static struct xt_match gradm_mt_reg __read_mostly = {
74477 + .name = "gradm",
74478 + .revision = 0,
74479 + .family = NFPROTO_UNSPEC,
74480 + .match = gradm_mt,
74481 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
74482 + .me = THIS_MODULE,
74483 +};
74484 +
74485 +static int __init gradm_mt_init(void)
74486 +{
74487 + return xt_register_match(&gradm_mt_reg);
74488 +}
74489 +
74490 +static void __exit gradm_mt_exit(void)
74491 +{
74492 + xt_unregister_match(&gradm_mt_reg);
74493 +}
74494 +
74495 +module_init(gradm_mt_init);
74496 +module_exit(gradm_mt_exit);
74497 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
74498 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
74499 +MODULE_LICENSE("GPL");
74500 +MODULE_ALIAS("ipt_gradm");
74501 +MODULE_ALIAS("ip6t_gradm");
74502 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
74503 index 4fe4fb4..87a89e5 100644
74504 --- a/net/netfilter/xt_statistic.c
74505 +++ b/net/netfilter/xt_statistic.c
74506 @@ -19,7 +19,7 @@
74507 #include <linux/module.h>
74508
74509 struct xt_statistic_priv {
74510 - atomic_t count;
74511 + atomic_unchecked_t count;
74512 } ____cacheline_aligned_in_smp;
74513
74514 MODULE_LICENSE("GPL");
74515 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
74516 break;
74517 case XT_STATISTIC_MODE_NTH:
74518 do {
74519 - oval = atomic_read(&info->master->count);
74520 + oval = atomic_read_unchecked(&info->master->count);
74521 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
74522 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
74523 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
74524 if (nval == 0)
74525 ret = !ret;
74526 break;
74527 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
74528 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
74529 if (info->master == NULL)
74530 return -ENOMEM;
74531 - atomic_set(&info->master->count, info->u.nth.count);
74532 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
74533
74534 return 0;
74535 }
74536 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
74537 index 1201b6d..bcff8c6 100644
74538 --- a/net/netlink/af_netlink.c
74539 +++ b/net/netlink/af_netlink.c
74540 @@ -742,7 +742,7 @@ static void netlink_overrun(struct sock *sk)
74541 sk->sk_error_report(sk);
74542 }
74543 }
74544 - atomic_inc(&sk->sk_drops);
74545 + atomic_inc_unchecked(&sk->sk_drops);
74546 }
74547
74548 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
74549 @@ -1999,7 +1999,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
74550 sk_wmem_alloc_get(s),
74551 nlk->cb,
74552 atomic_read(&s->sk_refcnt),
74553 - atomic_read(&s->sk_drops),
74554 + atomic_read_unchecked(&s->sk_drops),
74555 sock_i_ino(s)
74556 );
74557
74558 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
74559 index 732152f..60bb09e 100644
74560 --- a/net/netrom/af_netrom.c
74561 +++ b/net/netrom/af_netrom.c
74562 @@ -839,6 +839,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
74563 struct sock *sk = sock->sk;
74564 struct nr_sock *nr = nr_sk(sk);
74565
74566 + memset(sax, 0, sizeof(*sax));
74567 lock_sock(sk);
74568 if (peer != 0) {
74569 if (sk->sk_state != TCP_ESTABLISHED) {
74570 @@ -853,7 +854,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
74571 *uaddr_len = sizeof(struct full_sockaddr_ax25);
74572 } else {
74573 sax->fsa_ax25.sax25_family = AF_NETROM;
74574 - sax->fsa_ax25.sax25_ndigis = 0;
74575 sax->fsa_ax25.sax25_call = nr->source_addr;
74576 *uaddr_len = sizeof(struct sockaddr_ax25);
74577 }
74578 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
74579 index d9d4970..d5a6a68 100644
74580 --- a/net/packet/af_packet.c
74581 +++ b/net/packet/af_packet.c
74582 @@ -1675,7 +1675,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
74583
74584 spin_lock(&sk->sk_receive_queue.lock);
74585 po->stats.tp_packets++;
74586 - skb->dropcount = atomic_read(&sk->sk_drops);
74587 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
74588 __skb_queue_tail(&sk->sk_receive_queue, skb);
74589 spin_unlock(&sk->sk_receive_queue.lock);
74590 sk->sk_data_ready(sk, skb->len);
74591 @@ -1684,7 +1684,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
74592 drop_n_acct:
74593 spin_lock(&sk->sk_receive_queue.lock);
74594 po->stats.tp_drops++;
74595 - atomic_inc(&sk->sk_drops);
74596 + atomic_inc_unchecked(&sk->sk_drops);
74597 spin_unlock(&sk->sk_receive_queue.lock);
74598
74599 drop_n_restore:
74600 @@ -3266,7 +3266,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
74601 case PACKET_HDRLEN:
74602 if (len > sizeof(int))
74603 len = sizeof(int);
74604 - if (copy_from_user(&val, optval, len))
74605 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
74606 return -EFAULT;
74607 switch (val) {
74608 case TPACKET_V1:
74609 @@ -3316,7 +3316,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
74610
74611 if (put_user(len, optlen))
74612 return -EFAULT;
74613 - if (copy_to_user(optval, data, len))
74614 + if (len > sizeof(st) || copy_to_user(optval, data, len))
74615 return -EFAULT;
74616 return 0;
74617 }
74618 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
74619 index d65f699..05aa6ce 100644
74620 --- a/net/phonet/af_phonet.c
74621 +++ b/net/phonet/af_phonet.c
74622 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
74623 {
74624 struct phonet_protocol *pp;
74625
74626 - if (protocol >= PHONET_NPROTO)
74627 + if (protocol < 0 || protocol >= PHONET_NPROTO)
74628 return NULL;
74629
74630 rcu_read_lock();
74631 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
74632 {
74633 int err = 0;
74634
74635 - if (protocol >= PHONET_NPROTO)
74636 + if (protocol < 0 || protocol >= PHONET_NPROTO)
74637 return -EINVAL;
74638
74639 err = proto_register(pp->prot, 1);
74640 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
74641 index 2ba6e9f..409573f 100644
74642 --- a/net/phonet/pep.c
74643 +++ b/net/phonet/pep.c
74644 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
74645
74646 case PNS_PEP_CTRL_REQ:
74647 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
74648 - atomic_inc(&sk->sk_drops);
74649 + atomic_inc_unchecked(&sk->sk_drops);
74650 break;
74651 }
74652 __skb_pull(skb, 4);
74653 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
74654 }
74655
74656 if (pn->rx_credits == 0) {
74657 - atomic_inc(&sk->sk_drops);
74658 + atomic_inc_unchecked(&sk->sk_drops);
74659 err = -ENOBUFS;
74660 break;
74661 }
74662 @@ -557,7 +557,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
74663 }
74664
74665 if (pn->rx_credits == 0) {
74666 - atomic_inc(&sk->sk_drops);
74667 + atomic_inc_unchecked(&sk->sk_drops);
74668 err = NET_RX_DROP;
74669 break;
74670 }
74671 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
74672 index 4c7eff3..59c727f 100644
74673 --- a/net/phonet/socket.c
74674 +++ b/net/phonet/socket.c
74675 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
74676 pn->resource, sk->sk_state,
74677 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
74678 sock_i_uid(sk), sock_i_ino(sk),
74679 - atomic_read(&sk->sk_refcnt), sk,
74680 - atomic_read(&sk->sk_drops), &len);
74681 + atomic_read(&sk->sk_refcnt),
74682 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74683 + NULL,
74684 +#else
74685 + sk,
74686 +#endif
74687 + atomic_read_unchecked(&sk->sk_drops), &len);
74688 }
74689 seq_printf(seq, "%*s\n", 127 - len, "");
74690 return 0;
74691 diff --git a/net/rds/cong.c b/net/rds/cong.c
74692 index e5b65ac..f3b6fb7 100644
74693 --- a/net/rds/cong.c
74694 +++ b/net/rds/cong.c
74695 @@ -78,7 +78,7 @@
74696 * finds that the saved generation number is smaller than the global generation
74697 * number, it wakes up the process.
74698 */
74699 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
74700 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
74701
74702 /*
74703 * Congestion monitoring
74704 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
74705 rdsdebug("waking map %p for %pI4\n",
74706 map, &map->m_addr);
74707 rds_stats_inc(s_cong_update_received);
74708 - atomic_inc(&rds_cong_generation);
74709 + atomic_inc_unchecked(&rds_cong_generation);
74710 if (waitqueue_active(&map->m_waitq))
74711 wake_up(&map->m_waitq);
74712 if (waitqueue_active(&rds_poll_waitq))
74713 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
74714
74715 int rds_cong_updated_since(unsigned long *recent)
74716 {
74717 - unsigned long gen = atomic_read(&rds_cong_generation);
74718 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
74719
74720 if (likely(*recent == gen))
74721 return 0;
74722 diff --git a/net/rds/ib.h b/net/rds/ib.h
74723 index edfaaaf..8c89879 100644
74724 --- a/net/rds/ib.h
74725 +++ b/net/rds/ib.h
74726 @@ -128,7 +128,7 @@ struct rds_ib_connection {
74727 /* sending acks */
74728 unsigned long i_ack_flags;
74729 #ifdef KERNEL_HAS_ATOMIC64
74730 - atomic64_t i_ack_next; /* next ACK to send */
74731 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
74732 #else
74733 spinlock_t i_ack_lock; /* protect i_ack_next */
74734 u64 i_ack_next; /* next ACK to send */
74735 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
74736 index 51c8689..36c555f 100644
74737 --- a/net/rds/ib_cm.c
74738 +++ b/net/rds/ib_cm.c
74739 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
74740 /* Clear the ACK state */
74741 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
74742 #ifdef KERNEL_HAS_ATOMIC64
74743 - atomic64_set(&ic->i_ack_next, 0);
74744 + atomic64_set_unchecked(&ic->i_ack_next, 0);
74745 #else
74746 ic->i_ack_next = 0;
74747 #endif
74748 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
74749 index e29e0ca..fa3a6a3 100644
74750 --- a/net/rds/ib_recv.c
74751 +++ b/net/rds/ib_recv.c
74752 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
74753 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
74754 int ack_required)
74755 {
74756 - atomic64_set(&ic->i_ack_next, seq);
74757 + atomic64_set_unchecked(&ic->i_ack_next, seq);
74758 if (ack_required) {
74759 smp_mb__before_clear_bit();
74760 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74761 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
74762 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74763 smp_mb__after_clear_bit();
74764
74765 - return atomic64_read(&ic->i_ack_next);
74766 + return atomic64_read_unchecked(&ic->i_ack_next);
74767 }
74768 #endif
74769
74770 diff --git a/net/rds/iw.h b/net/rds/iw.h
74771 index 04ce3b1..48119a6 100644
74772 --- a/net/rds/iw.h
74773 +++ b/net/rds/iw.h
74774 @@ -134,7 +134,7 @@ struct rds_iw_connection {
74775 /* sending acks */
74776 unsigned long i_ack_flags;
74777 #ifdef KERNEL_HAS_ATOMIC64
74778 - atomic64_t i_ack_next; /* next ACK to send */
74779 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
74780 #else
74781 spinlock_t i_ack_lock; /* protect i_ack_next */
74782 u64 i_ack_next; /* next ACK to send */
74783 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
74784 index 9556d28..f046d0e 100644
74785 --- a/net/rds/iw_cm.c
74786 +++ b/net/rds/iw_cm.c
74787 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
74788 /* Clear the ACK state */
74789 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
74790 #ifdef KERNEL_HAS_ATOMIC64
74791 - atomic64_set(&ic->i_ack_next, 0);
74792 + atomic64_set_unchecked(&ic->i_ack_next, 0);
74793 #else
74794 ic->i_ack_next = 0;
74795 #endif
74796 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
74797 index 5e57347..3916042 100644
74798 --- a/net/rds/iw_recv.c
74799 +++ b/net/rds/iw_recv.c
74800 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
74801 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
74802 int ack_required)
74803 {
74804 - atomic64_set(&ic->i_ack_next, seq);
74805 + atomic64_set_unchecked(&ic->i_ack_next, seq);
74806 if (ack_required) {
74807 smp_mb__before_clear_bit();
74808 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74809 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
74810 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
74811 smp_mb__after_clear_bit();
74812
74813 - return atomic64_read(&ic->i_ack_next);
74814 + return atomic64_read_unchecked(&ic->i_ack_next);
74815 }
74816 #endif
74817
74818 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
74819 index edac9ef..16bcb98 100644
74820 --- a/net/rds/tcp.c
74821 +++ b/net/rds/tcp.c
74822 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
74823 int val = 1;
74824
74825 set_fs(KERNEL_DS);
74826 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
74827 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
74828 sizeof(val));
74829 set_fs(oldfs);
74830 }
74831 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
74832 index 1b4fd68..2234175 100644
74833 --- a/net/rds/tcp_send.c
74834 +++ b/net/rds/tcp_send.c
74835 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
74836
74837 oldfs = get_fs();
74838 set_fs(KERNEL_DS);
74839 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
74840 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
74841 sizeof(val));
74842 set_fs(oldfs);
74843 }
74844 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
74845 index 74c064c..fdec26f 100644
74846 --- a/net/rxrpc/af_rxrpc.c
74847 +++ b/net/rxrpc/af_rxrpc.c
74848 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
74849 __be32 rxrpc_epoch;
74850
74851 /* current debugging ID */
74852 -atomic_t rxrpc_debug_id;
74853 +atomic_unchecked_t rxrpc_debug_id;
74854
74855 /* count of skbs currently in use */
74856 atomic_t rxrpc_n_skbs;
74857 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
74858 index f99cfce..cc529dd 100644
74859 --- a/net/rxrpc/ar-ack.c
74860 +++ b/net/rxrpc/ar-ack.c
74861 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
74862
74863 _enter("{%d,%d,%d,%d},",
74864 call->acks_hard, call->acks_unacked,
74865 - atomic_read(&call->sequence),
74866 + atomic_read_unchecked(&call->sequence),
74867 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
74868
74869 stop = 0;
74870 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
74871
74872 /* each Tx packet has a new serial number */
74873 sp->hdr.serial =
74874 - htonl(atomic_inc_return(&call->conn->serial));
74875 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
74876
74877 hdr = (struct rxrpc_header *) txb->head;
74878 hdr->serial = sp->hdr.serial;
74879 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
74880 */
74881 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
74882 {
74883 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
74884 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
74885 }
74886
74887 /*
74888 @@ -629,7 +629,7 @@ process_further:
74889
74890 latest = ntohl(sp->hdr.serial);
74891 hard = ntohl(ack.firstPacket);
74892 - tx = atomic_read(&call->sequence);
74893 + tx = atomic_read_unchecked(&call->sequence);
74894
74895 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
74896 latest,
74897 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
74898 goto maybe_reschedule;
74899
74900 send_ACK_with_skew:
74901 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
74902 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
74903 ntohl(ack.serial));
74904 send_ACK:
74905 mtu = call->conn->trans->peer->if_mtu;
74906 @@ -1173,7 +1173,7 @@ send_ACK:
74907 ackinfo.rxMTU = htonl(5692);
74908 ackinfo.jumbo_max = htonl(4);
74909
74910 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
74911 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
74912 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
74913 ntohl(hdr.serial),
74914 ntohs(ack.maxSkew),
74915 @@ -1191,7 +1191,7 @@ send_ACK:
74916 send_message:
74917 _debug("send message");
74918
74919 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
74920 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
74921 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
74922 send_message_2:
74923
74924 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
74925 index bf656c2..48f9d27 100644
74926 --- a/net/rxrpc/ar-call.c
74927 +++ b/net/rxrpc/ar-call.c
74928 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
74929 spin_lock_init(&call->lock);
74930 rwlock_init(&call->state_lock);
74931 atomic_set(&call->usage, 1);
74932 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
74933 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74934 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
74935
74936 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
74937 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
74938 index 4106ca9..a338d7a 100644
74939 --- a/net/rxrpc/ar-connection.c
74940 +++ b/net/rxrpc/ar-connection.c
74941 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
74942 rwlock_init(&conn->lock);
74943 spin_lock_init(&conn->state_lock);
74944 atomic_set(&conn->usage, 1);
74945 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
74946 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
74947 conn->avail_calls = RXRPC_MAXCALLS;
74948 conn->size_align = 4;
74949 conn->header_size = sizeof(struct rxrpc_header);
74950 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
74951 index e7ed43a..6afa140 100644
74952 --- a/net/rxrpc/ar-connevent.c
74953 +++ b/net/rxrpc/ar-connevent.c
74954 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
74955
74956 len = iov[0].iov_len + iov[1].iov_len;
74957
74958 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
74959 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
74960 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
74961
74962 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
74963 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
74964 index 1a2b0633..e8d1382 100644
74965 --- a/net/rxrpc/ar-input.c
74966 +++ b/net/rxrpc/ar-input.c
74967 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
74968 /* track the latest serial number on this connection for ACK packet
74969 * information */
74970 serial = ntohl(sp->hdr.serial);
74971 - hi_serial = atomic_read(&call->conn->hi_serial);
74972 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
74973 while (serial > hi_serial)
74974 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
74975 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
74976 serial);
74977
74978 /* request ACK generation for any ACK or DATA packet that requests
74979 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
74980 index 8e22bd3..f66d1c0 100644
74981 --- a/net/rxrpc/ar-internal.h
74982 +++ b/net/rxrpc/ar-internal.h
74983 @@ -272,8 +272,8 @@ struct rxrpc_connection {
74984 int error; /* error code for local abort */
74985 int debug_id; /* debug ID for printks */
74986 unsigned call_counter; /* call ID counter */
74987 - atomic_t serial; /* packet serial number counter */
74988 - atomic_t hi_serial; /* highest serial number received */
74989 + atomic_unchecked_t serial; /* packet serial number counter */
74990 + atomic_unchecked_t hi_serial; /* highest serial number received */
74991 u8 avail_calls; /* number of calls available */
74992 u8 size_align; /* data size alignment (for security) */
74993 u8 header_size; /* rxrpc + security header size */
74994 @@ -346,7 +346,7 @@ struct rxrpc_call {
74995 spinlock_t lock;
74996 rwlock_t state_lock; /* lock for state transition */
74997 atomic_t usage;
74998 - atomic_t sequence; /* Tx data packet sequence counter */
74999 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
75000 u32 abort_code; /* local/remote abort code */
75001 enum { /* current state of call */
75002 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
75003 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
75004 */
75005 extern atomic_t rxrpc_n_skbs;
75006 extern __be32 rxrpc_epoch;
75007 -extern atomic_t rxrpc_debug_id;
75008 +extern atomic_unchecked_t rxrpc_debug_id;
75009 extern struct workqueue_struct *rxrpc_workqueue;
75010
75011 /*
75012 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
75013 index 87f7135..74d3703 100644
75014 --- a/net/rxrpc/ar-local.c
75015 +++ b/net/rxrpc/ar-local.c
75016 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
75017 spin_lock_init(&local->lock);
75018 rwlock_init(&local->services_lock);
75019 atomic_set(&local->usage, 1);
75020 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
75021 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
75022 memcpy(&local->srx, srx, sizeof(*srx));
75023 }
75024
75025 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
75026 index 338d793..47391d0 100644
75027 --- a/net/rxrpc/ar-output.c
75028 +++ b/net/rxrpc/ar-output.c
75029 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
75030 sp->hdr.cid = call->cid;
75031 sp->hdr.callNumber = call->call_id;
75032 sp->hdr.seq =
75033 - htonl(atomic_inc_return(&call->sequence));
75034 + htonl(atomic_inc_return_unchecked(&call->sequence));
75035 sp->hdr.serial =
75036 - htonl(atomic_inc_return(&conn->serial));
75037 + htonl(atomic_inc_return_unchecked(&conn->serial));
75038 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
75039 sp->hdr.userStatus = 0;
75040 sp->hdr.securityIndex = conn->security_ix;
75041 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
75042 index 2754f09..b20e38f 100644
75043 --- a/net/rxrpc/ar-peer.c
75044 +++ b/net/rxrpc/ar-peer.c
75045 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
75046 INIT_LIST_HEAD(&peer->error_targets);
75047 spin_lock_init(&peer->lock);
75048 atomic_set(&peer->usage, 1);
75049 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
75050 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
75051 memcpy(&peer->srx, srx, sizeof(*srx));
75052
75053 rxrpc_assess_MTU_size(peer);
75054 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
75055 index 38047f7..9f48511 100644
75056 --- a/net/rxrpc/ar-proc.c
75057 +++ b/net/rxrpc/ar-proc.c
75058 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
75059 atomic_read(&conn->usage),
75060 rxrpc_conn_states[conn->state],
75061 key_serial(conn->key),
75062 - atomic_read(&conn->serial),
75063 - atomic_read(&conn->hi_serial));
75064 + atomic_read_unchecked(&conn->serial),
75065 + atomic_read_unchecked(&conn->hi_serial));
75066
75067 return 0;
75068 }
75069 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
75070 index 92df566..87ec1bf 100644
75071 --- a/net/rxrpc/ar-transport.c
75072 +++ b/net/rxrpc/ar-transport.c
75073 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
75074 spin_lock_init(&trans->client_lock);
75075 rwlock_init(&trans->conn_lock);
75076 atomic_set(&trans->usage, 1);
75077 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
75078 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
75079
75080 if (peer->srx.transport.family == AF_INET) {
75081 switch (peer->srx.transport_type) {
75082 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
75083 index 7635107..4670276 100644
75084 --- a/net/rxrpc/rxkad.c
75085 +++ b/net/rxrpc/rxkad.c
75086 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
75087
75088 len = iov[0].iov_len + iov[1].iov_len;
75089
75090 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
75091 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
75092 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
75093
75094 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
75095 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
75096
75097 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
75098
75099 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
75100 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
75101 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
75102
75103 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
75104 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
75105 index 1e2eee8..ce3967e 100644
75106 --- a/net/sctp/proc.c
75107 +++ b/net/sctp/proc.c
75108 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
75109 seq_printf(seq,
75110 "%8pK %8pK %-3d %-3d %-2d %-4d "
75111 "%4d %8d %8d %7d %5lu %-5d %5d ",
75112 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
75113 + assoc, sk,
75114 + sctp_sk(sk)->type, sk->sk_state,
75115 assoc->state, hash,
75116 assoc->assoc_id,
75117 assoc->sndbuf_used,
75118 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
75119 index 54a7cd2..944edae 100644
75120 --- a/net/sctp/socket.c
75121 +++ b/net/sctp/socket.c
75122 @@ -4574,7 +4574,7 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
75123 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
75124 if (space_left < addrlen)
75125 return -ENOMEM;
75126 - if (copy_to_user(to, &temp, addrlen))
75127 + if (addrlen > sizeof(temp) || copy_to_user(to, &temp, addrlen))
75128 return -EFAULT;
75129 to += addrlen;
75130 cnt++;
75131 diff --git a/net/socket.c b/net/socket.c
75132 index 2dce67a..1e91168 100644
75133 --- a/net/socket.c
75134 +++ b/net/socket.c
75135 @@ -88,6 +88,7 @@
75136 #include <linux/nsproxy.h>
75137 #include <linux/magic.h>
75138 #include <linux/slab.h>
75139 +#include <linux/in.h>
75140
75141 #include <asm/uaccess.h>
75142 #include <asm/unistd.h>
75143 @@ -105,6 +106,8 @@
75144 #include <linux/sockios.h>
75145 #include <linux/atalk.h>
75146
75147 +#include <linux/grsock.h>
75148 +
75149 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
75150 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
75151 unsigned long nr_segs, loff_t pos);
75152 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
75153 &sockfs_dentry_operations, SOCKFS_MAGIC);
75154 }
75155
75156 -static struct vfsmount *sock_mnt __read_mostly;
75157 +struct vfsmount *sock_mnt __read_mostly;
75158
75159 static struct file_system_type sock_fs_type = {
75160 .name = "sockfs",
75161 @@ -1187,6 +1190,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
75162 return -EAFNOSUPPORT;
75163 if (type < 0 || type >= SOCK_MAX)
75164 return -EINVAL;
75165 + if (protocol < 0)
75166 + return -EINVAL;
75167
75168 /* Compatibility.
75169
75170 @@ -1319,6 +1324,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
75171 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
75172 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
75173
75174 + if(!gr_search_socket(family, type, protocol)) {
75175 + retval = -EACCES;
75176 + goto out;
75177 + }
75178 +
75179 + if (gr_handle_sock_all(family, type, protocol)) {
75180 + retval = -EACCES;
75181 + goto out;
75182 + }
75183 +
75184 retval = sock_create(family, type, protocol, &sock);
75185 if (retval < 0)
75186 goto out;
75187 @@ -1431,6 +1446,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
75188 if (sock) {
75189 err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
75190 if (err >= 0) {
75191 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
75192 + err = -EACCES;
75193 + goto error;
75194 + }
75195 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
75196 + if (err)
75197 + goto error;
75198 +
75199 err = security_socket_bind(sock,
75200 (struct sockaddr *)&address,
75201 addrlen);
75202 @@ -1439,6 +1462,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
75203 (struct sockaddr *)
75204 &address, addrlen);
75205 }
75206 +error:
75207 fput_light(sock->file, fput_needed);
75208 }
75209 return err;
75210 @@ -1462,10 +1486,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
75211 if ((unsigned)backlog > somaxconn)
75212 backlog = somaxconn;
75213
75214 + if (gr_handle_sock_server_other(sock->sk)) {
75215 + err = -EPERM;
75216 + goto error;
75217 + }
75218 +
75219 + err = gr_search_listen(sock);
75220 + if (err)
75221 + goto error;
75222 +
75223 err = security_socket_listen(sock, backlog);
75224 if (!err)
75225 err = sock->ops->listen(sock, backlog);
75226
75227 +error:
75228 fput_light(sock->file, fput_needed);
75229 }
75230 return err;
75231 @@ -1509,6 +1543,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
75232 newsock->type = sock->type;
75233 newsock->ops = sock->ops;
75234
75235 + if (gr_handle_sock_server_other(sock->sk)) {
75236 + err = -EPERM;
75237 + sock_release(newsock);
75238 + goto out_put;
75239 + }
75240 +
75241 + err = gr_search_accept(sock);
75242 + if (err) {
75243 + sock_release(newsock);
75244 + goto out_put;
75245 + }
75246 +
75247 /*
75248 * We don't need try_module_get here, as the listening socket (sock)
75249 * has the protocol module (sock->ops->owner) held.
75250 @@ -1547,6 +1593,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
75251 fd_install(newfd, newfile);
75252 err = newfd;
75253
75254 + gr_attach_curr_ip(newsock->sk);
75255 +
75256 out_put:
75257 fput_light(sock->file, fput_needed);
75258 out:
75259 @@ -1579,6 +1627,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
75260 int, addrlen)
75261 {
75262 struct socket *sock;
75263 + struct sockaddr *sck;
75264 struct sockaddr_storage address;
75265 int err, fput_needed;
75266
75267 @@ -1589,6 +1638,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
75268 if (err < 0)
75269 goto out_put;
75270
75271 + sck = (struct sockaddr *)&address;
75272 +
75273 + if (gr_handle_sock_client(sck)) {
75274 + err = -EACCES;
75275 + goto out_put;
75276 + }
75277 +
75278 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
75279 + if (err)
75280 + goto out_put;
75281 +
75282 err =
75283 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
75284 if (err)
75285 @@ -1950,7 +2010,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
75286 * checking falls down on this.
75287 */
75288 if (copy_from_user(ctl_buf,
75289 - (void __user __force *)msg_sys->msg_control,
75290 + (void __force_user *)msg_sys->msg_control,
75291 ctl_len))
75292 goto out_freectl;
75293 msg_sys->msg_control = ctl_buf;
75294 @@ -2120,7 +2180,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
75295 * kernel msghdr to use the kernel address space)
75296 */
75297
75298 - uaddr = (__force void __user *)msg_sys->msg_name;
75299 + uaddr = (void __force_user *)msg_sys->msg_name;
75300 uaddr_len = COMPAT_NAMELEN(msg);
75301 if (MSG_CMSG_COMPAT & flags) {
75302 err = verify_compat_iovec(msg_sys, iov,
75303 @@ -2748,7 +2808,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75304 }
75305
75306 ifr = compat_alloc_user_space(buf_size);
75307 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
75308 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
75309
75310 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
75311 return -EFAULT;
75312 @@ -2772,12 +2832,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75313 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
75314
75315 if (copy_in_user(rxnfc, compat_rxnfc,
75316 - (void *)(&rxnfc->fs.m_ext + 1) -
75317 - (void *)rxnfc) ||
75318 + (void __user *)(&rxnfc->fs.m_ext + 1) -
75319 + (void __user *)rxnfc) ||
75320 copy_in_user(&rxnfc->fs.ring_cookie,
75321 &compat_rxnfc->fs.ring_cookie,
75322 - (void *)(&rxnfc->fs.location + 1) -
75323 - (void *)&rxnfc->fs.ring_cookie) ||
75324 + (void __user *)(&rxnfc->fs.location + 1) -
75325 + (void __user *)&rxnfc->fs.ring_cookie) ||
75326 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
75327 sizeof(rxnfc->rule_cnt)))
75328 return -EFAULT;
75329 @@ -2789,12 +2849,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
75330
75331 if (convert_out) {
75332 if (copy_in_user(compat_rxnfc, rxnfc,
75333 - (const void *)(&rxnfc->fs.m_ext + 1) -
75334 - (const void *)rxnfc) ||
75335 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
75336 + (const void __user *)rxnfc) ||
75337 copy_in_user(&compat_rxnfc->fs.ring_cookie,
75338 &rxnfc->fs.ring_cookie,
75339 - (const void *)(&rxnfc->fs.location + 1) -
75340 - (const void *)&rxnfc->fs.ring_cookie) ||
75341 + (const void __user *)(&rxnfc->fs.location + 1) -
75342 + (const void __user *)&rxnfc->fs.ring_cookie) ||
75343 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
75344 sizeof(rxnfc->rule_cnt)))
75345 return -EFAULT;
75346 @@ -2864,7 +2924,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
75347 old_fs = get_fs();
75348 set_fs(KERNEL_DS);
75349 err = dev_ioctl(net, cmd,
75350 - (struct ifreq __user __force *) &kifr);
75351 + (struct ifreq __force_user *) &kifr);
75352 set_fs(old_fs);
75353
75354 return err;
75355 @@ -2973,7 +3033,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
75356
75357 old_fs = get_fs();
75358 set_fs(KERNEL_DS);
75359 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
75360 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
75361 set_fs(old_fs);
75362
75363 if (cmd == SIOCGIFMAP && !err) {
75364 @@ -3078,7 +3138,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
75365 ret |= __get_user(rtdev, &(ur4->rt_dev));
75366 if (rtdev) {
75367 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
75368 - r4.rt_dev = (char __user __force *)devname;
75369 + r4.rt_dev = (char __force_user *)devname;
75370 devname[15] = 0;
75371 } else
75372 r4.rt_dev = NULL;
75373 @@ -3318,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
75374 int __user *uoptlen;
75375 int err;
75376
75377 - uoptval = (char __user __force *) optval;
75378 - uoptlen = (int __user __force *) optlen;
75379 + uoptval = (char __force_user *) optval;
75380 + uoptlen = (int __force_user *) optlen;
75381
75382 set_fs(KERNEL_DS);
75383 if (level == SOL_SOCKET)
75384 @@ -3339,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
75385 char __user *uoptval;
75386 int err;
75387
75388 - uoptval = (char __user __force *) optval;
75389 + uoptval = (char __force_user *) optval;
75390
75391 set_fs(KERNEL_DS);
75392 if (level == SOL_SOCKET)
75393 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
75394 index 00a1a2a..6a0138a 100644
75395 --- a/net/sunrpc/sched.c
75396 +++ b/net/sunrpc/sched.c
75397 @@ -238,9 +238,9 @@ static int rpc_wait_bit_killable(void *word)
75398 #ifdef RPC_DEBUG
75399 static void rpc_task_set_debuginfo(struct rpc_task *task)
75400 {
75401 - static atomic_t rpc_pid;
75402 + static atomic_unchecked_t rpc_pid;
75403
75404 - task->tk_pid = atomic_inc_return(&rpc_pid);
75405 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
75406 }
75407 #else
75408 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
75409 diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
75410 index 71bed1c..5dff36d 100644
75411 --- a/net/sunrpc/svcsock.c
75412 +++ b/net/sunrpc/svcsock.c
75413 @@ -396,7 +396,7 @@ static int svc_partial_recvfrom(struct svc_rqst *rqstp,
75414 int buflen, unsigned int base)
75415 {
75416 size_t save_iovlen;
75417 - void __user *save_iovbase;
75418 + void *save_iovbase;
75419 unsigned int i;
75420 int ret;
75421
75422 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
75423 index 09af4fa..77110a9 100644
75424 --- a/net/sunrpc/xprtrdma/svc_rdma.c
75425 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
75426 @@ -61,15 +61,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
75427 static unsigned int min_max_inline = 4096;
75428 static unsigned int max_max_inline = 65536;
75429
75430 -atomic_t rdma_stat_recv;
75431 -atomic_t rdma_stat_read;
75432 -atomic_t rdma_stat_write;
75433 -atomic_t rdma_stat_sq_starve;
75434 -atomic_t rdma_stat_rq_starve;
75435 -atomic_t rdma_stat_rq_poll;
75436 -atomic_t rdma_stat_rq_prod;
75437 -atomic_t rdma_stat_sq_poll;
75438 -atomic_t rdma_stat_sq_prod;
75439 +atomic_unchecked_t rdma_stat_recv;
75440 +atomic_unchecked_t rdma_stat_read;
75441 +atomic_unchecked_t rdma_stat_write;
75442 +atomic_unchecked_t rdma_stat_sq_starve;
75443 +atomic_unchecked_t rdma_stat_rq_starve;
75444 +atomic_unchecked_t rdma_stat_rq_poll;
75445 +atomic_unchecked_t rdma_stat_rq_prod;
75446 +atomic_unchecked_t rdma_stat_sq_poll;
75447 +atomic_unchecked_t rdma_stat_sq_prod;
75448
75449 /* Temporary NFS request map and context caches */
75450 struct kmem_cache *svc_rdma_map_cachep;
75451 @@ -109,7 +109,7 @@ static int read_reset_stat(ctl_table *table, int write,
75452 len -= *ppos;
75453 if (len > *lenp)
75454 len = *lenp;
75455 - if (len && copy_to_user(buffer, str_buf, len))
75456 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
75457 return -EFAULT;
75458 *lenp = len;
75459 *ppos += len;
75460 @@ -150,63 +150,63 @@ static ctl_table svcrdma_parm_table[] = {
75461 {
75462 .procname = "rdma_stat_read",
75463 .data = &rdma_stat_read,
75464 - .maxlen = sizeof(atomic_t),
75465 + .maxlen = sizeof(atomic_unchecked_t),
75466 .mode = 0644,
75467 .proc_handler = read_reset_stat,
75468 },
75469 {
75470 .procname = "rdma_stat_recv",
75471 .data = &rdma_stat_recv,
75472 - .maxlen = sizeof(atomic_t),
75473 + .maxlen = sizeof(atomic_unchecked_t),
75474 .mode = 0644,
75475 .proc_handler = read_reset_stat,
75476 },
75477 {
75478 .procname = "rdma_stat_write",
75479 .data = &rdma_stat_write,
75480 - .maxlen = sizeof(atomic_t),
75481 + .maxlen = sizeof(atomic_unchecked_t),
75482 .mode = 0644,
75483 .proc_handler = read_reset_stat,
75484 },
75485 {
75486 .procname = "rdma_stat_sq_starve",
75487 .data = &rdma_stat_sq_starve,
75488 - .maxlen = sizeof(atomic_t),
75489 + .maxlen = sizeof(atomic_unchecked_t),
75490 .mode = 0644,
75491 .proc_handler = read_reset_stat,
75492 },
75493 {
75494 .procname = "rdma_stat_rq_starve",
75495 .data = &rdma_stat_rq_starve,
75496 - .maxlen = sizeof(atomic_t),
75497 + .maxlen = sizeof(atomic_unchecked_t),
75498 .mode = 0644,
75499 .proc_handler = read_reset_stat,
75500 },
75501 {
75502 .procname = "rdma_stat_rq_poll",
75503 .data = &rdma_stat_rq_poll,
75504 - .maxlen = sizeof(atomic_t),
75505 + .maxlen = sizeof(atomic_unchecked_t),
75506 .mode = 0644,
75507 .proc_handler = read_reset_stat,
75508 },
75509 {
75510 .procname = "rdma_stat_rq_prod",
75511 .data = &rdma_stat_rq_prod,
75512 - .maxlen = sizeof(atomic_t),
75513 + .maxlen = sizeof(atomic_unchecked_t),
75514 .mode = 0644,
75515 .proc_handler = read_reset_stat,
75516 },
75517 {
75518 .procname = "rdma_stat_sq_poll",
75519 .data = &rdma_stat_sq_poll,
75520 - .maxlen = sizeof(atomic_t),
75521 + .maxlen = sizeof(atomic_unchecked_t),
75522 .mode = 0644,
75523 .proc_handler = read_reset_stat,
75524 },
75525 {
75526 .procname = "rdma_stat_sq_prod",
75527 .data = &rdma_stat_sq_prod,
75528 - .maxlen = sizeof(atomic_t),
75529 + .maxlen = sizeof(atomic_unchecked_t),
75530 .mode = 0644,
75531 .proc_handler = read_reset_stat,
75532 },
75533 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75534 index df67211..c354b13 100644
75535 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75536 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
75537 @@ -499,7 +499,7 @@ next_sge:
75538 svc_rdma_put_context(ctxt, 0);
75539 goto out;
75540 }
75541 - atomic_inc(&rdma_stat_read);
75542 + atomic_inc_unchecked(&rdma_stat_read);
75543
75544 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
75545 chl_map->ch[ch_no].count -= read_wr.num_sge;
75546 @@ -609,7 +609,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
75547 dto_q);
75548 list_del_init(&ctxt->dto_q);
75549 } else {
75550 - atomic_inc(&rdma_stat_rq_starve);
75551 + atomic_inc_unchecked(&rdma_stat_rq_starve);
75552 clear_bit(XPT_DATA, &xprt->xpt_flags);
75553 ctxt = NULL;
75554 }
75555 @@ -629,7 +629,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
75556 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
75557 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
75558 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
75559 - atomic_inc(&rdma_stat_recv);
75560 + atomic_inc_unchecked(&rdma_stat_recv);
75561
75562 /* Build up the XDR from the receive buffers. */
75563 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
75564 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75565 index 249a835..fb2794b 100644
75566 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75567 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
75568 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
75569 write_wr.wr.rdma.remote_addr = to;
75570
75571 /* Post It */
75572 - atomic_inc(&rdma_stat_write);
75573 + atomic_inc_unchecked(&rdma_stat_write);
75574 if (svc_rdma_send(xprt, &write_wr))
75575 goto err;
75576 return 0;
75577 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
75578 index ba1296d..0fec1a5 100644
75579 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
75580 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
75581 @@ -300,7 +300,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
75582 return;
75583
75584 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
75585 - atomic_inc(&rdma_stat_rq_poll);
75586 + atomic_inc_unchecked(&rdma_stat_rq_poll);
75587
75588 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
75589 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
75590 @@ -322,7 +322,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
75591 }
75592
75593 if (ctxt)
75594 - atomic_inc(&rdma_stat_rq_prod);
75595 + atomic_inc_unchecked(&rdma_stat_rq_prod);
75596
75597 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
75598 /*
75599 @@ -394,7 +394,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
75600 return;
75601
75602 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
75603 - atomic_inc(&rdma_stat_sq_poll);
75604 + atomic_inc_unchecked(&rdma_stat_sq_poll);
75605 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
75606 if (wc.status != IB_WC_SUCCESS)
75607 /* Close the transport */
75608 @@ -412,7 +412,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
75609 }
75610
75611 if (ctxt)
75612 - atomic_inc(&rdma_stat_sq_prod);
75613 + atomic_inc_unchecked(&rdma_stat_sq_prod);
75614 }
75615
75616 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
75617 @@ -1274,7 +1274,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
75618 spin_lock_bh(&xprt->sc_lock);
75619 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
75620 spin_unlock_bh(&xprt->sc_lock);
75621 - atomic_inc(&rdma_stat_sq_starve);
75622 + atomic_inc_unchecked(&rdma_stat_sq_starve);
75623
75624 /* See if we can opportunistically reap SQ WR to make room */
75625 sq_cq_reap(xprt);
75626 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
75627 index e758139..d29ea47 100644
75628 --- a/net/sysctl_net.c
75629 +++ b/net/sysctl_net.c
75630 @@ -47,7 +47,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
75631 struct ctl_table *table)
75632 {
75633 /* Allow network administrator to have same access as root. */
75634 - if (capable(CAP_NET_ADMIN)) {
75635 + if (capable_nolog(CAP_NET_ADMIN)) {
75636 int mode = (table->mode >> 6) & 7;
75637 return (mode << 6) | (mode << 3) | mode;
75638 }
75639 diff --git a/net/tipc/link.c b/net/tipc/link.c
75640 index ae98a72..7bb6056 100644
75641 --- a/net/tipc/link.c
75642 +++ b/net/tipc/link.c
75643 @@ -1203,7 +1203,7 @@ static int link_send_sections_long(struct tipc_port *sender,
75644 struct tipc_msg fragm_hdr;
75645 struct sk_buff *buf, *buf_chain, *prev;
75646 u32 fragm_crs, fragm_rest, hsz, sect_rest;
75647 - const unchar *sect_crs;
75648 + const unchar __user *sect_crs;
75649 int curr_sect;
75650 u32 fragm_no;
75651
75652 @@ -1247,7 +1247,7 @@ again:
75653
75654 if (!sect_rest) {
75655 sect_rest = msg_sect[++curr_sect].iov_len;
75656 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
75657 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
75658 }
75659
75660 if (sect_rest < fragm_rest)
75661 @@ -1266,7 +1266,7 @@ error:
75662 }
75663 } else
75664 skb_copy_to_linear_data_offset(buf, fragm_crs,
75665 - sect_crs, sz);
75666 + (const void __force_kernel *)sect_crs, sz);
75667 sect_crs += sz;
75668 sect_rest -= sz;
75669 fragm_crs += sz;
75670 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
75671 index 83d5096..dcba497 100644
75672 --- a/net/tipc/msg.c
75673 +++ b/net/tipc/msg.c
75674 @@ -99,7 +99,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
75675 msg_sect[cnt].iov_len);
75676 else
75677 skb_copy_to_linear_data_offset(*buf, pos,
75678 - msg_sect[cnt].iov_base,
75679 + (const void __force_kernel *)msg_sect[cnt].iov_base,
75680 msg_sect[cnt].iov_len);
75681 pos += msg_sect[cnt].iov_len;
75682 }
75683 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
75684 index 1983717..4d6102c 100644
75685 --- a/net/tipc/subscr.c
75686 +++ b/net/tipc/subscr.c
75687 @@ -101,7 +101,7 @@ static void subscr_send_event(struct subscription *sub,
75688 {
75689 struct iovec msg_sect;
75690
75691 - msg_sect.iov_base = (void *)&sub->evt;
75692 + msg_sect.iov_base = (void __force_user *)&sub->evt;
75693 msg_sect.iov_len = sizeof(struct tipc_event);
75694
75695 sub->evt.event = htohl(event, sub->swap);
75696 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
75697 index d99678a..3514a21 100644
75698 --- a/net/unix/af_unix.c
75699 +++ b/net/unix/af_unix.c
75700 @@ -767,6 +767,12 @@ static struct sock *unix_find_other(struct net *net,
75701 err = -ECONNREFUSED;
75702 if (!S_ISSOCK(inode->i_mode))
75703 goto put_fail;
75704 +
75705 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
75706 + err = -EACCES;
75707 + goto put_fail;
75708 + }
75709 +
75710 u = unix_find_socket_byinode(inode);
75711 if (!u)
75712 goto put_fail;
75713 @@ -787,6 +793,13 @@ static struct sock *unix_find_other(struct net *net,
75714 if (u) {
75715 struct dentry *dentry;
75716 dentry = unix_sk(u)->dentry;
75717 +
75718 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
75719 + err = -EPERM;
75720 + sock_put(u);
75721 + goto fail;
75722 + }
75723 +
75724 if (dentry)
75725 touch_atime(unix_sk(u)->mnt, dentry);
75726 } else
75727 @@ -869,11 +882,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
75728 err = security_path_mknod(&path, dentry, mode, 0);
75729 if (err)
75730 goto out_mknod_drop_write;
75731 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
75732 + err = -EACCES;
75733 + goto out_mknod_drop_write;
75734 + }
75735 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
75736 out_mknod_drop_write:
75737 mnt_drop_write(path.mnt);
75738 if (err)
75739 goto out_mknod_dput;
75740 +
75741 + gr_handle_create(dentry, path.mnt);
75742 +
75743 mutex_unlock(&path.dentry->d_inode->i_mutex);
75744 dput(path.dentry);
75745 path.dentry = dentry;
75746 diff --git a/net/wireless/core.h b/net/wireless/core.h
75747 index b9ec306..b4a563e 100644
75748 --- a/net/wireless/core.h
75749 +++ b/net/wireless/core.h
75750 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
75751 struct mutex mtx;
75752
75753 /* rfkill support */
75754 - struct rfkill_ops rfkill_ops;
75755 + rfkill_ops_no_const rfkill_ops;
75756 struct rfkill *rfkill;
75757 struct work_struct rfkill_sync;
75758
75759 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
75760 index 0af7f54..c916d2f 100644
75761 --- a/net/wireless/wext-core.c
75762 +++ b/net/wireless/wext-core.c
75763 @@ -747,8 +747,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
75764 */
75765
75766 /* Support for very large requests */
75767 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
75768 - (user_length > descr->max_tokens)) {
75769 + if (user_length > descr->max_tokens) {
75770 /* Allow userspace to GET more than max so
75771 * we can support any size GET requests.
75772 * There is still a limit : -ENOMEM.
75773 @@ -785,22 +784,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
75774 }
75775 }
75776
75777 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
75778 - /*
75779 - * If this is a GET, but not NOMAX, it means that the extra
75780 - * data is not bounded by userspace, but by max_tokens. Thus
75781 - * set the length to max_tokens. This matches the extra data
75782 - * allocation.
75783 - * The driver should fill it with the number of tokens it
75784 - * provided, and it may check iwp->length rather than having
75785 - * knowledge of max_tokens. If the driver doesn't change the
75786 - * iwp->length, this ioctl just copies back max_token tokens
75787 - * filled with zeroes. Hopefully the driver isn't claiming
75788 - * them to be valid data.
75789 - */
75790 - iwp->length = descr->max_tokens;
75791 - }
75792 -
75793 err = handler(dev, info, (union iwreq_data *) iwp, extra);
75794
75795 iwp->length += essid_compat;
75796 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
75797 index 9049a5c..cfa6f5c 100644
75798 --- a/net/xfrm/xfrm_policy.c
75799 +++ b/net/xfrm/xfrm_policy.c
75800 @@ -299,7 +299,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
75801 {
75802 policy->walk.dead = 1;
75803
75804 - atomic_inc(&policy->genid);
75805 + atomic_inc_unchecked(&policy->genid);
75806
75807 if (del_timer(&policy->timer))
75808 xfrm_pol_put(policy);
75809 @@ -583,7 +583,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
75810 hlist_add_head(&policy->bydst, chain);
75811 xfrm_pol_hold(policy);
75812 net->xfrm.policy_count[dir]++;
75813 - atomic_inc(&flow_cache_genid);
75814 + atomic_inc_unchecked(&flow_cache_genid);
75815 if (delpol)
75816 __xfrm_policy_unlink(delpol, dir);
75817 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
75818 @@ -1530,7 +1530,7 @@ free_dst:
75819 goto out;
75820 }
75821
75822 -static int inline
75823 +static inline int
75824 xfrm_dst_alloc_copy(void **target, const void *src, int size)
75825 {
75826 if (!*target) {
75827 @@ -1542,7 +1542,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
75828 return 0;
75829 }
75830
75831 -static int inline
75832 +static inline int
75833 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
75834 {
75835 #ifdef CONFIG_XFRM_SUB_POLICY
75836 @@ -1554,7 +1554,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
75837 #endif
75838 }
75839
75840 -static int inline
75841 +static inline int
75842 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
75843 {
75844 #ifdef CONFIG_XFRM_SUB_POLICY
75845 @@ -1648,7 +1648,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
75846
75847 xdst->num_pols = num_pols;
75848 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
75849 - xdst->policy_genid = atomic_read(&pols[0]->genid);
75850 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
75851
75852 return xdst;
75853 }
75854 @@ -2345,7 +2345,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
75855 if (xdst->xfrm_genid != dst->xfrm->genid)
75856 return 0;
75857 if (xdst->num_pols > 0 &&
75858 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
75859 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
75860 return 0;
75861
75862 mtu = dst_mtu(dst->child);
75863 @@ -2882,7 +2882,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
75864 sizeof(pol->xfrm_vec[i].saddr));
75865 pol->xfrm_vec[i].encap_family = mp->new_family;
75866 /* flush bundles */
75867 - atomic_inc(&pol->genid);
75868 + atomic_inc_unchecked(&pol->genid);
75869 }
75870 }
75871
75872 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
75873 index d2b366c..51ff91e 100644
75874 --- a/scripts/Makefile.build
75875 +++ b/scripts/Makefile.build
75876 @@ -109,7 +109,7 @@ endif
75877 endif
75878
75879 # Do not include host rules unless needed
75880 -ifneq ($(hostprogs-y)$(hostprogs-m),)
75881 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m),)
75882 include scripts/Makefile.host
75883 endif
75884
75885 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
75886 index 686cb0d..9d653bf 100644
75887 --- a/scripts/Makefile.clean
75888 +++ b/scripts/Makefile.clean
75889 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
75890 __clean-files := $(extra-y) $(always) \
75891 $(targets) $(clean-files) \
75892 $(host-progs) \
75893 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
75894 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
75895 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
75896
75897 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
75898
75899 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
75900 index 1ac414f..a1c1451 100644
75901 --- a/scripts/Makefile.host
75902 +++ b/scripts/Makefile.host
75903 @@ -31,6 +31,7 @@
75904 # Note: Shared libraries consisting of C++ files are not supported
75905
75906 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
75907 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
75908
75909 # C code
75910 # Executables compiled from a single .c file
75911 @@ -54,6 +55,7 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
75912 # Shared libaries (only .c supported)
75913 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
75914 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
75915 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
75916 # Remove .so files from "xxx-objs"
75917 host-cobjs := $(filter-out %.so,$(host-cobjs))
75918
75919 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
75920 index cb1f50c..cef2a7c 100644
75921 --- a/scripts/basic/fixdep.c
75922 +++ b/scripts/basic/fixdep.c
75923 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
75924 /*
75925 * Lookup a value in the configuration string.
75926 */
75927 -static int is_defined_config(const char *name, int len, unsigned int hash)
75928 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
75929 {
75930 struct item *aux;
75931
75932 @@ -211,10 +211,10 @@ static void clear_config(void)
75933 /*
75934 * Record the use of a CONFIG_* word.
75935 */
75936 -static void use_config(const char *m, int slen)
75937 +static void use_config(const char *m, unsigned int slen)
75938 {
75939 unsigned int hash = strhash(m, slen);
75940 - int c, i;
75941 + unsigned int c, i;
75942
75943 if (is_defined_config(m, slen, hash))
75944 return;
75945 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
75946
75947 static void parse_config_file(const char *map, size_t len)
75948 {
75949 - const int *end = (const int *) (map + len);
75950 + const unsigned int *end = (const unsigned int *) (map + len);
75951 /* start at +1, so that p can never be < map */
75952 - const int *m = (const int *) map + 1;
75953 + const unsigned int *m = (const unsigned int *) map + 1;
75954 const char *p, *q;
75955
75956 for (; m < end; m++) {
75957 @@ -406,7 +406,7 @@ static void print_deps(void)
75958 static void traps(void)
75959 {
75960 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
75961 - int *p = (int *)test;
75962 + unsigned int *p = (unsigned int *)test;
75963
75964 if (*p != INT_CONF) {
75965 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
75966 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
75967 new file mode 100644
75968 index 0000000..8729101
75969 --- /dev/null
75970 +++ b/scripts/gcc-plugin.sh
75971 @@ -0,0 +1,2 @@
75972 +#!/bin/sh
75973 +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"
75974 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
75975 index f936d1f..a66d95f 100644
75976 --- a/scripts/mod/file2alias.c
75977 +++ b/scripts/mod/file2alias.c
75978 @@ -72,7 +72,7 @@ static void device_id_check(const char *modname, const char *device_id,
75979 unsigned long size, unsigned long id_size,
75980 void *symval)
75981 {
75982 - int i;
75983 + unsigned int i;
75984
75985 if (size % id_size || size < id_size) {
75986 if (cross_build != 0)
75987 @@ -102,7 +102,7 @@ static void device_id_check(const char *modname, const char *device_id,
75988 /* USB is special because the bcdDevice can be matched against a numeric range */
75989 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
75990 static void do_usb_entry(struct usb_device_id *id,
75991 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
75992 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
75993 unsigned char range_lo, unsigned char range_hi,
75994 unsigned char max, struct module *mod)
75995 {
75996 @@ -203,7 +203,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
75997 {
75998 unsigned int devlo, devhi;
75999 unsigned char chi, clo, max;
76000 - int ndigits;
76001 + unsigned int ndigits;
76002
76003 id->match_flags = TO_NATIVE(id->match_flags);
76004 id->idVendor = TO_NATIVE(id->idVendor);
76005 @@ -437,7 +437,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
76006 for (i = 0; i < count; i++) {
76007 const char *id = (char *)devs[i].id;
76008 char acpi_id[sizeof(devs[0].id)];
76009 - int j;
76010 + unsigned int j;
76011
76012 buf_printf(&mod->dev_table_buf,
76013 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
76014 @@ -467,7 +467,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
76015
76016 for (j = 0; j < PNP_MAX_DEVICES; j++) {
76017 const char *id = (char *)card->devs[j].id;
76018 - int i2, j2;
76019 + unsigned int i2, j2;
76020 int dup = 0;
76021
76022 if (!id[0])
76023 @@ -493,7 +493,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
76024 /* add an individual alias for every device entry */
76025 if (!dup) {
76026 char acpi_id[sizeof(card->devs[0].id)];
76027 - int k;
76028 + unsigned int k;
76029
76030 buf_printf(&mod->dev_table_buf,
76031 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
76032 @@ -807,7 +807,7 @@ static void dmi_ascii_filter(char *d, const char *s)
76033 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
76034 char *alias)
76035 {
76036 - int i, j;
76037 + unsigned int i, j;
76038
76039 sprintf(alias, "dmi*");
76040
76041 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
76042 index 2bd594e..d43245e 100644
76043 --- a/scripts/mod/modpost.c
76044 +++ b/scripts/mod/modpost.c
76045 @@ -919,6 +919,7 @@ enum mismatch {
76046 ANY_INIT_TO_ANY_EXIT,
76047 ANY_EXIT_TO_ANY_INIT,
76048 EXPORT_TO_INIT_EXIT,
76049 + DATA_TO_TEXT
76050 };
76051
76052 struct sectioncheck {
76053 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
76054 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
76055 .mismatch = EXPORT_TO_INIT_EXIT,
76056 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
76057 +},
76058 +/* Do not reference code from writable data */
76059 +{
76060 + .fromsec = { DATA_SECTIONS, NULL },
76061 + .tosec = { TEXT_SECTIONS, NULL },
76062 + .mismatch = DATA_TO_TEXT
76063 }
76064 };
76065
76066 @@ -1149,10 +1156,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
76067 continue;
76068 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
76069 continue;
76070 - if (sym->st_value == addr)
76071 - return sym;
76072 /* Find a symbol nearby - addr are maybe negative */
76073 d = sym->st_value - addr;
76074 + if (d == 0)
76075 + return sym;
76076 if (d < 0)
76077 d = addr - sym->st_value;
76078 if (d < distance) {
76079 @@ -1431,6 +1438,14 @@ static void report_sec_mismatch(const char *modname,
76080 tosym, prl_to, prl_to, tosym);
76081 free(prl_to);
76082 break;
76083 + case DATA_TO_TEXT:
76084 +/*
76085 + fprintf(stderr,
76086 + "The variable %s references\n"
76087 + "the %s %s%s%s\n",
76088 + fromsym, to, sec2annotation(tosec), tosym, to_p);
76089 +*/
76090 + break;
76091 }
76092 fprintf(stderr, "\n");
76093 }
76094 @@ -1656,7 +1671,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
76095 static void check_sec_ref(struct module *mod, const char *modname,
76096 struct elf_info *elf)
76097 {
76098 - int i;
76099 + unsigned int i;
76100 Elf_Shdr *sechdrs = elf->sechdrs;
76101
76102 /* Walk through all sections */
76103 @@ -1754,7 +1769,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
76104 va_end(ap);
76105 }
76106
76107 -void buf_write(struct buffer *buf, const char *s, int len)
76108 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
76109 {
76110 if (buf->size - buf->pos < len) {
76111 buf->size += len + SZ;
76112 @@ -1972,7 +1987,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
76113 if (fstat(fileno(file), &st) < 0)
76114 goto close_write;
76115
76116 - if (st.st_size != b->pos)
76117 + if (st.st_size != (off_t)b->pos)
76118 goto close_write;
76119
76120 tmp = NOFAIL(malloc(b->pos));
76121 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
76122 index 2031119..b5433af 100644
76123 --- a/scripts/mod/modpost.h
76124 +++ b/scripts/mod/modpost.h
76125 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
76126
76127 struct buffer {
76128 char *p;
76129 - int pos;
76130 - int size;
76131 + unsigned int pos;
76132 + unsigned int size;
76133 };
76134
76135 void __attribute__((format(printf, 2, 3)))
76136 buf_printf(struct buffer *buf, const char *fmt, ...);
76137
76138 void
76139 -buf_write(struct buffer *buf, const char *s, int len);
76140 +buf_write(struct buffer *buf, const char *s, unsigned int len);
76141
76142 struct module {
76143 struct module *next;
76144 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
76145 index 9dfcd6d..099068e 100644
76146 --- a/scripts/mod/sumversion.c
76147 +++ b/scripts/mod/sumversion.c
76148 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
76149 goto out;
76150 }
76151
76152 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
76153 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
76154 warn("writing sum in %s failed: %s\n",
76155 filename, strerror(errno));
76156 goto out;
76157 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
76158 index 5c11312..72742b5 100644
76159 --- a/scripts/pnmtologo.c
76160 +++ b/scripts/pnmtologo.c
76161 @@ -237,14 +237,14 @@ static void write_header(void)
76162 fprintf(out, " * Linux logo %s\n", logoname);
76163 fputs(" */\n\n", out);
76164 fputs("#include <linux/linux_logo.h>\n\n", out);
76165 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
76166 + fprintf(out, "static unsigned char %s_data[] = {\n",
76167 logoname);
76168 }
76169
76170 static void write_footer(void)
76171 {
76172 fputs("\n};\n\n", out);
76173 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
76174 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
76175 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
76176 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
76177 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
76178 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
76179 fputs("\n};\n\n", out);
76180
76181 /* write logo clut */
76182 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
76183 + fprintf(out, "static unsigned char %s_clut[] = {\n",
76184 logoname);
76185 write_hex_cnt = 0;
76186 for (i = 0; i < logo_clutsize; i++) {
76187 diff --git a/security/Kconfig b/security/Kconfig
76188 index 51bd5a0..eeabc9f 100644
76189 --- a/security/Kconfig
76190 +++ b/security/Kconfig
76191 @@ -4,6 +4,627 @@
76192
76193 menu "Security options"
76194
76195 +source grsecurity/Kconfig
76196 +
76197 +menu "PaX"
76198 +
76199 + config ARCH_TRACK_EXEC_LIMIT
76200 + bool
76201 +
76202 + config PAX_KERNEXEC_PLUGIN
76203 + bool
76204 +
76205 + config PAX_PER_CPU_PGD
76206 + bool
76207 +
76208 + config TASK_SIZE_MAX_SHIFT
76209 + int
76210 + depends on X86_64
76211 + default 47 if !PAX_PER_CPU_PGD
76212 + default 42 if PAX_PER_CPU_PGD
76213 +
76214 + config PAX_ENABLE_PAE
76215 + bool
76216 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
76217 +
76218 +config PAX
76219 + bool "Enable various PaX features"
76220 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
76221 + help
76222 + This allows you to enable various PaX features. PaX adds
76223 + intrusion prevention mechanisms to the kernel that reduce
76224 + the risks posed by exploitable memory corruption bugs.
76225 +
76226 +menu "PaX Control"
76227 + depends on PAX
76228 +
76229 +config PAX_SOFTMODE
76230 + bool 'Support soft mode'
76231 + help
76232 + Enabling this option will allow you to run PaX in soft mode, that
76233 + is, PaX features will not be enforced by default, only on executables
76234 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
76235 + support as they are the only way to mark executables for soft mode use.
76236 +
76237 + Soft mode can be activated by using the "pax_softmode=1" kernel command
76238 + line option on boot. Furthermore you can control various PaX features
76239 + at runtime via the entries in /proc/sys/kernel/pax.
76240 +
76241 +config PAX_EI_PAX
76242 + bool 'Use legacy ELF header marking'
76243 + help
76244 + Enabling this option will allow you to control PaX features on
76245 + a per executable basis via the 'chpax' utility available at
76246 + http://pax.grsecurity.net/. The control flags will be read from
76247 + an otherwise reserved part of the ELF header. This marking has
76248 + numerous drawbacks (no support for soft-mode, toolchain does not
76249 + know about the non-standard use of the ELF header) therefore it
76250 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
76251 + support.
76252 +
76253 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76254 + header and you cannot use XATTR_PAX_FLAGS then you MUST enable this
76255 + option otherwise they will not get any protection.
76256 +
76257 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
76258 + support as well, they will override the legacy EI_PAX marks.
76259 +
76260 +config PAX_PT_PAX_FLAGS
76261 + bool 'Use ELF program header marking'
76262 + help
76263 + Enabling this option will allow you to control PaX features on
76264 + a per executable basis via the 'paxctl' utility available at
76265 + http://pax.grsecurity.net/. The control flags will be read from
76266 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
76267 + has the benefits of supporting both soft mode and being fully
76268 + integrated into the toolchain (the binutils patch is available
76269 + from http://pax.grsecurity.net).
76270 +
76271 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76272 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
76273 + support otherwise they will not get any protection.
76274 +
76275 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
76276 + must make sure that the marks are the same if a binary has both marks.
76277 +
76278 + Note that if you enable the legacy EI_PAX marking support as well,
76279 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
76280 +
76281 +config PAX_XATTR_PAX_FLAGS
76282 + bool 'Use filesystem extended attributes marking'
76283 + depends on EXPERT
76284 + select CIFS_XATTR if CIFS
76285 + select EXT2_FS_XATTR if EXT2_FS
76286 + select EXT3_FS_XATTR if EXT3_FS
76287 + select EXT4_FS_XATTR if EXT4_FS
76288 + select JFFS2_FS_XATTR if JFFS2_FS
76289 + select REISERFS_FS_XATTR if REISERFS_FS
76290 + select SQUASHFS_XATTR if SQUASHFS
76291 + select TMPFS_XATTR if TMPFS
76292 + select UBIFS_FS_XATTR if UBIFS_FS
76293 + help
76294 + Enabling this option will allow you to control PaX features on
76295 + a per executable basis via the 'setfattr' utility. The control
76296 + flags will be read from the user.pax.flags extended attribute of
76297 + the file. This marking has the benefit of supporting binary-only
76298 + applications that self-check themselves (e.g., skype) and would
76299 + not tolerate chpax/paxctl changes. The main drawback is that
76300 + extended attributes are not supported by some filesystems (e.g.,
76301 + isofs, udf, vfat) so copying files through such filesystems will
76302 + lose the extended attributes and these PaX markings.
76303 +
76304 + If you have applications not marked by the PT_PAX_FLAGS ELF program
76305 + header then you MUST enable either XATTR_PAX_FLAGS or EI_PAX marking
76306 + support otherwise they will not get any protection.
76307 +
76308 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
76309 + must make sure that the marks are the same if a binary has both marks.
76310 +
76311 + Note that if you enable the legacy EI_PAX marking support as well,
76312 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
76313 +
76314 +choice
76315 + prompt 'MAC system integration'
76316 + default PAX_HAVE_ACL_FLAGS
76317 + help
76318 + Mandatory Access Control systems have the option of controlling
76319 + PaX flags on a per executable basis, choose the method supported
76320 + by your particular system.
76321 +
76322 + - "none": if your MAC system does not interact with PaX,
76323 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
76324 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
76325 +
76326 + NOTE: this option is for developers/integrators only.
76327 +
76328 + config PAX_NO_ACL_FLAGS
76329 + bool 'none'
76330 +
76331 + config PAX_HAVE_ACL_FLAGS
76332 + bool 'direct'
76333 +
76334 + config PAX_HOOK_ACL_FLAGS
76335 + bool 'hook'
76336 +endchoice
76337 +
76338 +endmenu
76339 +
76340 +menu "Non-executable pages"
76341 + depends on PAX
76342 +
76343 +config PAX_NOEXEC
76344 + bool "Enforce non-executable pages"
76345 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
76346 + help
76347 + By design some architectures do not allow for protecting memory
76348 + pages against execution or even if they do, Linux does not make
76349 + use of this feature. In practice this means that if a page is
76350 + readable (such as the stack or heap) it is also executable.
76351 +
76352 + There is a well known exploit technique that makes use of this
76353 + fact and a common programming mistake where an attacker can
76354 + introduce code of his choice somewhere in the attacked program's
76355 + memory (typically the stack or the heap) and then execute it.
76356 +
76357 + If the attacked program was running with different (typically
76358 + higher) privileges than that of the attacker, then he can elevate
76359 + his own privilege level (e.g. get a root shell, write to files for
76360 + which he does not have write access to, etc).
76361 +
76362 + Enabling this option will let you choose from various features
76363 + that prevent the injection and execution of 'foreign' code in
76364 + a program.
76365 +
76366 + This will also break programs that rely on the old behaviour and
76367 + expect that dynamically allocated memory via the malloc() family
76368 + of functions is executable (which it is not). Notable examples
76369 + are the XFree86 4.x server, the java runtime and wine.
76370 +
76371 +config PAX_PAGEEXEC
76372 + bool "Paging based non-executable pages"
76373 + 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)
76374 + select S390_SWITCH_AMODE if S390
76375 + select S390_EXEC_PROTECT if S390
76376 + select ARCH_TRACK_EXEC_LIMIT if X86_32
76377 + help
76378 + This implementation is based on the paging feature of the CPU.
76379 + On i386 without hardware non-executable bit support there is a
76380 + variable but usually low performance impact, however on Intel's
76381 + P4 core based CPUs it is very high so you should not enable this
76382 + for kernels meant to be used on such CPUs.
76383 +
76384 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
76385 + with hardware non-executable bit support there is no performance
76386 + impact, on ppc the impact is negligible.
76387 +
76388 + Note that several architectures require various emulations due to
76389 + badly designed userland ABIs, this will cause a performance impact
76390 + but will disappear as soon as userland is fixed. For example, ppc
76391 + userland MUST have been built with secure-plt by a recent toolchain.
76392 +
76393 +config PAX_SEGMEXEC
76394 + bool "Segmentation based non-executable pages"
76395 + depends on PAX_NOEXEC && X86_32
76396 + help
76397 + This implementation is based on the segmentation feature of the
76398 + CPU and has a very small performance impact, however applications
76399 + will be limited to a 1.5 GB address space instead of the normal
76400 + 3 GB.
76401 +
76402 +config PAX_EMUTRAMP
76403 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
76404 + default y if PARISC
76405 + help
76406 + There are some programs and libraries that for one reason or
76407 + another attempt to execute special small code snippets from
76408 + non-executable memory pages. Most notable examples are the
76409 + signal handler return code generated by the kernel itself and
76410 + the GCC trampolines.
76411 +
76412 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
76413 + such programs will no longer work under your kernel.
76414 +
76415 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
76416 + utilities to enable trampoline emulation for the affected programs
76417 + yet still have the protection provided by the non-executable pages.
76418 +
76419 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
76420 + your system will not even boot.
76421 +
76422 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
76423 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
76424 + for the affected files.
76425 +
76426 + NOTE: enabling this feature *may* open up a loophole in the
76427 + protection provided by non-executable pages that an attacker
76428 + could abuse. Therefore the best solution is to not have any
76429 + files on your system that would require this option. This can
76430 + be achieved by not using libc5 (which relies on the kernel
76431 + signal handler return code) and not using or rewriting programs
76432 + that make use of the nested function implementation of GCC.
76433 + Skilled users can just fix GCC itself so that it implements
76434 + nested function calls in a way that does not interfere with PaX.
76435 +
76436 +config PAX_EMUSIGRT
76437 + bool "Automatically emulate sigreturn trampolines"
76438 + depends on PAX_EMUTRAMP && PARISC
76439 + default y
76440 + help
76441 + Enabling this option will have the kernel automatically detect
76442 + and emulate signal return trampolines executing on the stack
76443 + that would otherwise lead to task termination.
76444 +
76445 + This solution is intended as a temporary one for users with
76446 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
76447 + Modula-3 runtime, etc) or executables linked to such, basically
76448 + everything that does not specify its own SA_RESTORER function in
76449 + normal executable memory like glibc 2.1+ does.
76450 +
76451 + On parisc you MUST enable this option, otherwise your system will
76452 + not even boot.
76453 +
76454 + NOTE: this feature cannot be disabled on a per executable basis
76455 + and since it *does* open up a loophole in the protection provided
76456 + by non-executable pages, the best solution is to not have any
76457 + files on your system that would require this option.
76458 +
76459 +config PAX_MPROTECT
76460 + bool "Restrict mprotect()"
76461 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
76462 + help
76463 + Enabling this option will prevent programs from
76464 + - changing the executable status of memory pages that were
76465 + not originally created as executable,
76466 + - making read-only executable pages writable again,
76467 + - creating executable pages from anonymous memory,
76468 + - making read-only-after-relocations (RELRO) data pages writable again.
76469 +
76470 + You should say Y here to complete the protection provided by
76471 + the enforcement of non-executable pages.
76472 +
76473 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
76474 + this feature on a per file basis.
76475 +
76476 +config PAX_MPROTECT_COMPAT
76477 + bool "Use legacy/compat protection demoting (read help)"
76478 + depends on PAX_MPROTECT
76479 + default n
76480 + help
76481 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
76482 + by sending the proper error code to the application. For some broken
76483 + userland, this can cause problems with Python or other applications. The
76484 + current implementation however allows for applications like clamav to
76485 + detect if JIT compilation/execution is allowed and to fall back gracefully
76486 + to an interpreter-based mode if it does not. While we encourage everyone
76487 + to use the current implementation as-is and push upstream to fix broken
76488 + userland (note that the RWX logging option can assist with this), in some
76489 + environments this may not be possible. Having to disable MPROTECT
76490 + completely on certain binaries reduces the security benefit of PaX,
76491 + so this option is provided for those environments to revert to the old
76492 + behavior.
76493 +
76494 +config PAX_ELFRELOCS
76495 + bool "Allow ELF text relocations (read help)"
76496 + depends on PAX_MPROTECT
76497 + default n
76498 + help
76499 + Non-executable pages and mprotect() restrictions are effective
76500 + in preventing the introduction of new executable code into an
76501 + attacked task's address space. There remain only two venues
76502 + for this kind of attack: if the attacker can execute already
76503 + existing code in the attacked task then he can either have it
76504 + create and mmap() a file containing his code or have it mmap()
76505 + an already existing ELF library that does not have position
76506 + independent code in it and use mprotect() on it to make it
76507 + writable and copy his code there. While protecting against
76508 + the former approach is beyond PaX, the latter can be prevented
76509 + by having only PIC ELF libraries on one's system (which do not
76510 + need to relocate their code). If you are sure this is your case,
76511 + as is the case with all modern Linux distributions, then leave
76512 + this option disabled. You should say 'n' here.
76513 +
76514 +config PAX_ETEXECRELOCS
76515 + bool "Allow ELF ET_EXEC text relocations"
76516 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
76517 + select PAX_ELFRELOCS
76518 + default y
76519 + help
76520 + On some architectures there are incorrectly created applications
76521 + that require text relocations and would not work without enabling
76522 + this option. If you are an alpha, ia64 or parisc user, you should
76523 + enable this option and disable it once you have made sure that
76524 + none of your applications need it.
76525 +
76526 +config PAX_EMUPLT
76527 + bool "Automatically emulate ELF PLT"
76528 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
76529 + default y
76530 + help
76531 + Enabling this option will have the kernel automatically detect
76532 + and emulate the Procedure Linkage Table entries in ELF files.
76533 + On some architectures such entries are in writable memory, and
76534 + become non-executable leading to task termination. Therefore
76535 + it is mandatory that you enable this option on alpha, parisc,
76536 + sparc and sparc64, otherwise your system would not even boot.
76537 +
76538 + NOTE: this feature *does* open up a loophole in the protection
76539 + provided by the non-executable pages, therefore the proper
76540 + solution is to modify the toolchain to produce a PLT that does
76541 + not need to be writable.
76542 +
76543 +config PAX_DLRESOLVE
76544 + bool 'Emulate old glibc resolver stub'
76545 + depends on PAX_EMUPLT && SPARC
76546 + default n
76547 + help
76548 + This option is needed if userland has an old glibc (before 2.4)
76549 + that puts a 'save' instruction into the runtime generated resolver
76550 + stub that needs special emulation.
76551 +
76552 +config PAX_KERNEXEC
76553 + bool "Enforce non-executable kernel pages"
76554 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
76555 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
76556 + select PAX_KERNEXEC_PLUGIN if X86_64
76557 + help
76558 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
76559 + that is, enabling this option will make it harder to inject
76560 + and execute 'foreign' code in kernel memory itself.
76561 +
76562 + Note that on x86_64 kernels there is a known regression when
76563 + this feature and KVM/VMX are both enabled in the host kernel.
76564 +
76565 +choice
76566 + prompt "Return Address Instrumentation Method"
76567 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
76568 + depends on PAX_KERNEXEC_PLUGIN
76569 + help
76570 + Select the method used to instrument function pointer dereferences.
76571 + Note that binary modules cannot be instrumented by this approach.
76572 +
76573 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
76574 + bool "bts"
76575 + help
76576 + This method is compatible with binary only modules but has
76577 + a higher runtime overhead.
76578 +
76579 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
76580 + bool "or"
76581 + depends on !PARAVIRT
76582 + help
76583 + This method is incompatible with binary only modules but has
76584 + a lower runtime overhead.
76585 +endchoice
76586 +
76587 +config PAX_KERNEXEC_PLUGIN_METHOD
76588 + string
76589 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
76590 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
76591 + default ""
76592 +
76593 +config PAX_KERNEXEC_MODULE_TEXT
76594 + int "Minimum amount of memory reserved for module code"
76595 + default "4"
76596 + depends on PAX_KERNEXEC && X86_32 && MODULES
76597 + help
76598 + Due to implementation details the kernel must reserve a fixed
76599 + amount of memory for module code at compile time that cannot be
76600 + changed at runtime. Here you can specify the minimum amount
76601 + in MB that will be reserved. Due to the same implementation
76602 + details this size will always be rounded up to the next 2/4 MB
76603 + boundary (depends on PAE) so the actually available memory for
76604 + module code will usually be more than this minimum.
76605 +
76606 + The default 4 MB should be enough for most users but if you have
76607 + an excessive number of modules (e.g., most distribution configs
76608 + compile many drivers as modules) or use huge modules such as
76609 + nvidia's kernel driver, you will need to adjust this amount.
76610 + A good rule of thumb is to look at your currently loaded kernel
76611 + modules and add up their sizes.
76612 +
76613 +endmenu
76614 +
76615 +menu "Address Space Layout Randomization"
76616 + depends on PAX
76617 +
76618 +config PAX_ASLR
76619 + bool "Address Space Layout Randomization"
76620 + help
76621 + Many if not most exploit techniques rely on the knowledge of
76622 + certain addresses in the attacked program. The following options
76623 + will allow the kernel to apply a certain amount of randomization
76624 + to specific parts of the program thereby forcing an attacker to
76625 + guess them in most cases. Any failed guess will most likely crash
76626 + the attacked program which allows the kernel to detect such attempts
76627 + and react on them. PaX itself provides no reaction mechanisms,
76628 + instead it is strongly encouraged that you make use of Nergal's
76629 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
76630 + (http://www.grsecurity.net/) built-in crash detection features or
76631 + develop one yourself.
76632 +
76633 + By saying Y here you can choose to randomize the following areas:
76634 + - top of the task's kernel stack
76635 + - top of the task's userland stack
76636 + - base address for mmap() requests that do not specify one
76637 + (this includes all libraries)
76638 + - base address of the main executable
76639 +
76640 + It is strongly recommended to say Y here as address space layout
76641 + randomization has negligible impact on performance yet it provides
76642 + a very effective protection.
76643 +
76644 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
76645 + this feature on a per file basis.
76646 +
76647 +config PAX_RANDKSTACK
76648 + bool "Randomize kernel stack base"
76649 + depends on X86_TSC && X86
76650 + help
76651 + By saying Y here the kernel will randomize every task's kernel
76652 + stack on every system call. This will not only force an attacker
76653 + to guess it but also prevent him from making use of possible
76654 + leaked information about it.
76655 +
76656 + Since the kernel stack is a rather scarce resource, randomization
76657 + may cause unexpected stack overflows, therefore you should very
76658 + carefully test your system. Note that once enabled in the kernel
76659 + configuration, this feature cannot be disabled on a per file basis.
76660 +
76661 +config PAX_RANDUSTACK
76662 + bool "Randomize user stack base"
76663 + depends on PAX_ASLR
76664 + help
76665 + By saying Y here the kernel will randomize every task's userland
76666 + stack. The randomization is done in two steps where the second
76667 + one may apply a big amount of shift to the top of the stack and
76668 + cause problems for programs that want to use lots of memory (more
76669 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
76670 + For this reason the second step can be controlled by 'chpax' or
76671 + 'paxctl' on a per file basis.
76672 +
76673 +config PAX_RANDMMAP
76674 + bool "Randomize mmap() base"
76675 + depends on PAX_ASLR
76676 + help
76677 + By saying Y here the kernel will use a randomized base address for
76678 + mmap() requests that do not specify one themselves. As a result
76679 + all dynamically loaded libraries will appear at random addresses
76680 + and therefore be harder to exploit by a technique where an attacker
76681 + attempts to execute library code for his purposes (e.g. spawn a
76682 + shell from an exploited program that is running at an elevated
76683 + privilege level).
76684 +
76685 + Furthermore, if a program is relinked as a dynamic ELF file, its
76686 + base address will be randomized as well, completing the full
76687 + randomization of the address space layout. Attacking such programs
76688 + becomes a guess game. You can find an example of doing this at
76689 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
76690 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
76691 +
76692 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
76693 + feature on a per file basis.
76694 +
76695 +endmenu
76696 +
76697 +menu "Miscellaneous hardening features"
76698 +
76699 +config PAX_MEMORY_SANITIZE
76700 + bool "Sanitize all freed memory"
76701 + depends on !HIBERNATION
76702 + help
76703 + By saying Y here the kernel will erase memory pages as soon as they
76704 + are freed. This in turn reduces the lifetime of data stored in the
76705 + pages, making it less likely that sensitive information such as
76706 + passwords, cryptographic secrets, etc stay in memory for too long.
76707 +
76708 + This is especially useful for programs whose runtime is short, long
76709 + lived processes and the kernel itself benefit from this as long as
76710 + they operate on whole memory pages and ensure timely freeing of pages
76711 + that may hold sensitive information.
76712 +
76713 + The tradeoff is performance impact, on a single CPU system kernel
76714 + compilation sees a 3% slowdown, other systems and workloads may vary
76715 + and you are advised to test this feature on your expected workload
76716 + before deploying it.
76717 +
76718 + Note that this feature does not protect data stored in live pages,
76719 + e.g., process memory swapped to disk may stay there for a long time.
76720 +
76721 +config PAX_MEMORY_STACKLEAK
76722 + bool "Sanitize kernel stack"
76723 + depends on X86
76724 + help
76725 + By saying Y here the kernel will erase the kernel stack before it
76726 + returns from a system call. This in turn reduces the information
76727 + that a kernel stack leak bug can reveal.
76728 +
76729 + Note that such a bug can still leak information that was put on
76730 + the stack by the current system call (the one eventually triggering
76731 + the bug) but traces of earlier system calls on the kernel stack
76732 + cannot leak anymore.
76733 +
76734 + The tradeoff is performance impact: on a single CPU system kernel
76735 + compilation sees a 1% slowdown, other systems and workloads may vary
76736 + and you are advised to test this feature on your expected workload
76737 + before deploying it.
76738 +
76739 + Note: full support for this feature requires gcc with plugin support
76740 + so make sure your compiler is at least gcc 4.5.0. Using older gcc
76741 + versions means that functions with large enough stack frames may
76742 + leave uninitialized memory behind that may be exposed to a later
76743 + syscall leaking the stack.
76744 +
76745 +config PAX_MEMORY_UDEREF
76746 + bool "Prevent invalid userland pointer dereference"
76747 + depends on X86 && !UML_X86 && !XEN
76748 + select PAX_PER_CPU_PGD if X86_64
76749 + help
76750 + By saying Y here the kernel will be prevented from dereferencing
76751 + userland pointers in contexts where the kernel expects only kernel
76752 + pointers. This is both a useful runtime debugging feature and a
76753 + security measure that prevents exploiting a class of kernel bugs.
76754 +
76755 + The tradeoff is that some virtualization solutions may experience
76756 + a huge slowdown and therefore you should not enable this feature
76757 + for kernels meant to run in such environments. Whether a given VM
76758 + solution is affected or not is best determined by simply trying it
76759 + out, the performance impact will be obvious right on boot as this
76760 + mechanism engages from very early on. A good rule of thumb is that
76761 + VMs running on CPUs without hardware virtualization support (i.e.,
76762 + the majority of IA-32 CPUs) will likely experience the slowdown.
76763 +
76764 +config PAX_REFCOUNT
76765 + bool "Prevent various kernel object reference counter overflows"
76766 + depends on GRKERNSEC && (X86 || SPARC64)
76767 + help
76768 + By saying Y here the kernel will detect and prevent overflowing
76769 + various (but not all) kinds of object reference counters. Such
76770 + overflows can normally occur due to bugs only and are often, if
76771 + not always, exploitable.
76772 +
76773 + The tradeoff is that data structures protected by an overflowed
76774 + refcount will never be freed and therefore will leak memory. Note
76775 + that this leak also happens even without this protection but in
76776 + that case the overflow can eventually trigger the freeing of the
76777 + data structure while it is still being used elsewhere, resulting
76778 + in the exploitable situation that this feature prevents.
76779 +
76780 + Since this has a negligible performance impact, you should enable
76781 + this feature.
76782 +
76783 +config PAX_USERCOPY
76784 + bool "Harden heap object copies between kernel and userland"
76785 + depends on X86 || PPC || SPARC || ARM
76786 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
76787 + help
76788 + By saying Y here the kernel will enforce the size of heap objects
76789 + when they are copied in either direction between the kernel and
76790 + userland, even if only a part of the heap object is copied.
76791 +
76792 + Specifically, this checking prevents information leaking from the
76793 + kernel heap during kernel to userland copies (if the kernel heap
76794 + object is otherwise fully initialized) and prevents kernel heap
76795 + overflows during userland to kernel copies.
76796 +
76797 + Note that the current implementation provides the strictest bounds
76798 + checks for the SLUB allocator.
76799 +
76800 + Enabling this option also enables per-slab cache protection against
76801 + data in a given cache being copied into/out of via userland
76802 + accessors. Though the whitelist of regions will be reduced over
76803 + time, it notably protects important data structures like task structs.
76804 +
76805 + If frame pointers are enabled on x86, this option will also restrict
76806 + copies into and out of the kernel stack to local variables within a
76807 + single frame.
76808 +
76809 + Since this has a negligible performance impact, you should enable
76810 + this feature.
76811 +
76812 +endmenu
76813 +
76814 +endmenu
76815 +
76816 config KEYS
76817 bool "Enable access key retention support"
76818 help
76819 @@ -169,7 +790,7 @@ config INTEL_TXT
76820 config LSM_MMAP_MIN_ADDR
76821 int "Low address space for LSM to protect from user allocation"
76822 depends on SECURITY && SECURITY_SELINUX
76823 - default 32768 if ARM
76824 + default 32768 if ALPHA || ARM || PARISC || SPARC32
76825 default 65536
76826 help
76827 This is the portion of low virtual memory which should be protected
76828 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
76829 index 3783202..1852837 100644
76830 --- a/security/apparmor/lsm.c
76831 +++ b/security/apparmor/lsm.c
76832 @@ -621,7 +621,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
76833 return error;
76834 }
76835
76836 -static struct security_operations apparmor_ops = {
76837 +static struct security_operations apparmor_ops __read_only = {
76838 .name = "apparmor",
76839
76840 .ptrace_access_check = apparmor_ptrace_access_check,
76841 diff --git a/security/commoncap.c b/security/commoncap.c
76842 index ee4f848..a320c64 100644
76843 --- a/security/commoncap.c
76844 +++ b/security/commoncap.c
76845 @@ -28,6 +28,7 @@
76846 #include <linux/prctl.h>
76847 #include <linux/securebits.h>
76848 #include <linux/user_namespace.h>
76849 +#include <net/sock.h>
76850
76851 /*
76852 * If a non-root user executes a setuid-root binary in
76853 @@ -58,7 +59,7 @@ int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
76854
76855 int cap_netlink_recv(struct sk_buff *skb, int cap)
76856 {
76857 - if (!cap_raised(current_cap(), cap))
76858 + if (!cap_raised(current_cap(), cap) || !gr_is_capable(cap))
76859 return -EPERM;
76860 return 0;
76861 }
76862 @@ -579,6 +580,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
76863 {
76864 const struct cred *cred = current_cred();
76865
76866 + if (gr_acl_enable_at_secure())
76867 + return 1;
76868 +
76869 if (cred->uid != 0) {
76870 if (bprm->cap_effective)
76871 return 1;
76872 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
76873 index 3ccf7ac..d73ad64 100644
76874 --- a/security/integrity/ima/ima.h
76875 +++ b/security/integrity/ima/ima.h
76876 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
76877 extern spinlock_t ima_queue_lock;
76878
76879 struct ima_h_table {
76880 - atomic_long_t len; /* number of stored measurements in the list */
76881 - atomic_long_t violations;
76882 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
76883 + atomic_long_unchecked_t violations;
76884 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
76885 };
76886 extern struct ima_h_table ima_htable;
76887 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
76888 index 88a2788..581ab92 100644
76889 --- a/security/integrity/ima/ima_api.c
76890 +++ b/security/integrity/ima/ima_api.c
76891 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
76892 int result;
76893
76894 /* can overflow, only indicator */
76895 - atomic_long_inc(&ima_htable.violations);
76896 + atomic_long_inc_unchecked(&ima_htable.violations);
76897
76898 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
76899 if (!entry) {
76900 diff --git a/security/integrity/ima/ima_audit.c b/security/integrity/ima/ima_audit.c
76901 index c5c5a72..2ad942f 100644
76902 --- a/security/integrity/ima/ima_audit.c
76903 +++ b/security/integrity/ima/ima_audit.c
76904 @@ -56,9 +56,11 @@ void integrity_audit_msg(int audit_msgno, struct inode *inode,
76905 audit_log_format(ab, " name=");
76906 audit_log_untrustedstring(ab, fname);
76907 }
76908 - if (inode)
76909 - audit_log_format(ab, " dev=%s ino=%lu",
76910 - inode->i_sb->s_id, inode->i_ino);
76911 + if (inode) {
76912 + audit_log_format(ab, " dev=");
76913 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
76914 + audit_log_format(ab, " ino=%lu", inode->i_ino);
76915 + }
76916 audit_log_format(ab, " res=%d", !result ? 0 : 1);
76917 audit_log_end(ab);
76918 }
76919 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
76920 index e1aa2b4..52027bf 100644
76921 --- a/security/integrity/ima/ima_fs.c
76922 +++ b/security/integrity/ima/ima_fs.c
76923 @@ -28,12 +28,12 @@
76924 static int valid_policy = 1;
76925 #define TMPBUFLEN 12
76926 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
76927 - loff_t *ppos, atomic_long_t *val)
76928 + loff_t *ppos, atomic_long_unchecked_t *val)
76929 {
76930 char tmpbuf[TMPBUFLEN];
76931 ssize_t len;
76932
76933 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
76934 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
76935 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
76936 }
76937
76938 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
76939 index 55a6271..ad829c3 100644
76940 --- a/security/integrity/ima/ima_queue.c
76941 +++ b/security/integrity/ima/ima_queue.c
76942 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
76943 INIT_LIST_HEAD(&qe->later);
76944 list_add_tail_rcu(&qe->later, &ima_measurements);
76945
76946 - atomic_long_inc(&ima_htable.len);
76947 + atomic_long_inc_unchecked(&ima_htable.len);
76948 key = ima_hash_key(entry->digest);
76949 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
76950 return 0;
76951 diff --git a/security/keys/compat.c b/security/keys/compat.c
76952 index 4c48e13..7abdac9 100644
76953 --- a/security/keys/compat.c
76954 +++ b/security/keys/compat.c
76955 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
76956 if (ret == 0)
76957 goto no_payload_free;
76958
76959 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
76960 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
76961
76962 if (iov != iovstack)
76963 kfree(iov);
76964 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
76965 index 0b3f5d7..892c8a6 100644
76966 --- a/security/keys/keyctl.c
76967 +++ b/security/keys/keyctl.c
76968 @@ -921,7 +921,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
76969 /*
76970 * Copy the iovec data from userspace
76971 */
76972 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
76973 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
76974 unsigned ioc)
76975 {
76976 for (; ioc > 0; ioc--) {
76977 @@ -943,7 +943,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
76978 * If successful, 0 will be returned.
76979 */
76980 long keyctl_instantiate_key_common(key_serial_t id,
76981 - const struct iovec *payload_iov,
76982 + const struct iovec __user *payload_iov,
76983 unsigned ioc,
76984 size_t plen,
76985 key_serial_t ringid)
76986 @@ -1038,7 +1038,7 @@ long keyctl_instantiate_key(key_serial_t id,
76987 [0].iov_len = plen
76988 };
76989
76990 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
76991 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
76992 }
76993
76994 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
76995 @@ -1071,7 +1071,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
76996 if (ret == 0)
76997 goto no_payload_free;
76998
76999 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
77000 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
77001
77002 if (iov != iovstack)
77003 kfree(iov);
77004 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
77005 index 37a7f3b..86dc19f 100644
77006 --- a/security/keys/keyring.c
77007 +++ b/security/keys/keyring.c
77008 @@ -214,15 +214,15 @@ static long keyring_read(const struct key *keyring,
77009 ret = -EFAULT;
77010
77011 for (loop = 0; loop < klist->nkeys; loop++) {
77012 + key_serial_t serial;
77013 key = klist->keys[loop];
77014 + serial = key->serial;
77015
77016 tmp = sizeof(key_serial_t);
77017 if (tmp > buflen)
77018 tmp = buflen;
77019
77020 - if (copy_to_user(buffer,
77021 - &key->serial,
77022 - tmp) != 0)
77023 + if (copy_to_user(buffer, &serial, tmp))
77024 goto error;
77025
77026 buflen -= tmp;
77027 diff --git a/security/lsm_audit.c b/security/lsm_audit.c
77028 index 893af8a..ba9237c 100644
77029 --- a/security/lsm_audit.c
77030 +++ b/security/lsm_audit.c
77031 @@ -234,10 +234,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
77032 audit_log_d_path(ab, "path=", &a->u.path);
77033
77034 inode = a->u.path.dentry->d_inode;
77035 - if (inode)
77036 - audit_log_format(ab, " dev=%s ino=%lu",
77037 - inode->i_sb->s_id,
77038 - inode->i_ino);
77039 + if (inode) {
77040 + audit_log_format(ab, " dev=");
77041 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
77042 + audit_log_format(ab, " ino=%lu", inode->i_ino);
77043 + }
77044 break;
77045 }
77046 case LSM_AUDIT_DATA_DENTRY: {
77047 @@ -247,10 +248,11 @@ static void dump_common_audit_data(struct audit_buffer *ab,
77048 audit_log_untrustedstring(ab, a->u.dentry->d_name.name);
77049
77050 inode = a->u.dentry->d_inode;
77051 - if (inode)
77052 - audit_log_format(ab, " dev=%s ino=%lu",
77053 - inode->i_sb->s_id,
77054 - inode->i_ino);
77055 + if (inode) {
77056 + audit_log_format(ab, " dev=");
77057 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
77058 + audit_log_format(ab, " ino=%lu", inode->i_ino);
77059 + }
77060 break;
77061 }
77062 case LSM_AUDIT_DATA_INODE: {
77063 @@ -265,8 +267,9 @@ static void dump_common_audit_data(struct audit_buffer *ab,
77064 dentry->d_name.name);
77065 dput(dentry);
77066 }
77067 - audit_log_format(ab, " dev=%s ino=%lu", inode->i_sb->s_id,
77068 - inode->i_ino);
77069 + audit_log_format(ab, " dev=");
77070 + audit_log_untrustedstring(ab, inode->i_sb->s_id);
77071 + audit_log_format(ab, " ino=%lu", inode->i_ino);
77072 break;
77073 }
77074 case LSM_AUDIT_DATA_TASK:
77075 diff --git a/security/min_addr.c b/security/min_addr.c
77076 index f728728..6457a0c 100644
77077 --- a/security/min_addr.c
77078 +++ b/security/min_addr.c
77079 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
77080 */
77081 static void update_mmap_min_addr(void)
77082 {
77083 +#ifndef SPARC
77084 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
77085 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
77086 mmap_min_addr = dac_mmap_min_addr;
77087 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
77088 #else
77089 mmap_min_addr = dac_mmap_min_addr;
77090 #endif
77091 +#endif
77092 }
77093
77094 /*
77095 diff --git a/security/security.c b/security/security.c
77096 index e2f684a..8d62ef5 100644
77097 --- a/security/security.c
77098 +++ b/security/security.c
77099 @@ -26,8 +26,8 @@
77100 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
77101 CONFIG_DEFAULT_SECURITY;
77102
77103 -static struct security_operations *security_ops;
77104 -static struct security_operations default_security_ops = {
77105 +static struct security_operations *security_ops __read_only;
77106 +static struct security_operations default_security_ops __read_only = {
77107 .name = "default",
77108 };
77109
77110 @@ -68,7 +68,9 @@ int __init security_init(void)
77111
77112 void reset_security_ops(void)
77113 {
77114 + pax_open_kernel();
77115 security_ops = &default_security_ops;
77116 + pax_close_kernel();
77117 }
77118
77119 /* Save user chosen LSM */
77120 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
77121 index 1126c10..effb32b 100644
77122 --- a/security/selinux/hooks.c
77123 +++ b/security/selinux/hooks.c
77124 @@ -94,8 +94,6 @@
77125
77126 #define NUM_SEL_MNT_OPTS 5
77127
77128 -extern struct security_operations *security_ops;
77129 -
77130 /* SECMARK reference count */
77131 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
77132
77133 @@ -5449,7 +5447,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
77134
77135 #endif
77136
77137 -static struct security_operations selinux_ops = {
77138 +static struct security_operations selinux_ops __read_only = {
77139 .name = "selinux",
77140
77141 .ptrace_access_check = selinux_ptrace_access_check,
77142 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
77143 index b43813c..74be837 100644
77144 --- a/security/selinux/include/xfrm.h
77145 +++ b/security/selinux/include/xfrm.h
77146 @@ -48,7 +48,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
77147
77148 static inline void selinux_xfrm_notify_policyload(void)
77149 {
77150 - atomic_inc(&flow_cache_genid);
77151 + atomic_inc_unchecked(&flow_cache_genid);
77152 }
77153 #else
77154 static inline int selinux_xfrm_enabled(void)
77155 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
77156 index 7db62b4..ee4d949 100644
77157 --- a/security/smack/smack_lsm.c
77158 +++ b/security/smack/smack_lsm.c
77159 @@ -3481,7 +3481,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
77160 return 0;
77161 }
77162
77163 -struct security_operations smack_ops = {
77164 +struct security_operations smack_ops __read_only = {
77165 .name = "smack",
77166
77167 .ptrace_access_check = smack_ptrace_access_check,
77168 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
77169 index 4b327b6..646c57a 100644
77170 --- a/security/tomoyo/tomoyo.c
77171 +++ b/security/tomoyo/tomoyo.c
77172 @@ -504,7 +504,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
77173 * tomoyo_security_ops is a "struct security_operations" which is used for
77174 * registering TOMOYO.
77175 */
77176 -static struct security_operations tomoyo_security_ops = {
77177 +static struct security_operations tomoyo_security_ops __read_only = {
77178 .name = "tomoyo",
77179 .cred_alloc_blank = tomoyo_cred_alloc_blank,
77180 .cred_prepare = tomoyo_cred_prepare,
77181 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
77182 index 762af68..7103453 100644
77183 --- a/sound/aoa/codecs/onyx.c
77184 +++ b/sound/aoa/codecs/onyx.c
77185 @@ -54,7 +54,7 @@ struct onyx {
77186 spdif_locked:1,
77187 analog_locked:1,
77188 original_mute:2;
77189 - int open_count;
77190 + local_t open_count;
77191 struct codec_info *codec_info;
77192
77193 /* mutex serializes concurrent access to the device
77194 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
77195 struct onyx *onyx = cii->codec_data;
77196
77197 mutex_lock(&onyx->mutex);
77198 - onyx->open_count++;
77199 + local_inc(&onyx->open_count);
77200 mutex_unlock(&onyx->mutex);
77201
77202 return 0;
77203 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
77204 struct onyx *onyx = cii->codec_data;
77205
77206 mutex_lock(&onyx->mutex);
77207 - onyx->open_count--;
77208 - if (!onyx->open_count)
77209 + if (local_dec_and_test(&onyx->open_count))
77210 onyx->spdif_locked = onyx->analog_locked = 0;
77211 mutex_unlock(&onyx->mutex);
77212
77213 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
77214 index ffd2025..df062c9 100644
77215 --- a/sound/aoa/codecs/onyx.h
77216 +++ b/sound/aoa/codecs/onyx.h
77217 @@ -11,6 +11,7 @@
77218 #include <linux/i2c.h>
77219 #include <asm/pmac_low_i2c.h>
77220 #include <asm/prom.h>
77221 +#include <asm/local.h>
77222
77223 /* PCM3052 register definitions */
77224
77225 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
77226 index 3cc4b86..af0a951 100644
77227 --- a/sound/core/oss/pcm_oss.c
77228 +++ b/sound/core/oss/pcm_oss.c
77229 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
77230 if (in_kernel) {
77231 mm_segment_t fs;
77232 fs = snd_enter_user();
77233 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
77234 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
77235 snd_leave_user(fs);
77236 } else {
77237 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
77238 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
77239 }
77240 if (ret != -EPIPE && ret != -ESTRPIPE)
77241 break;
77242 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
77243 if (in_kernel) {
77244 mm_segment_t fs;
77245 fs = snd_enter_user();
77246 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
77247 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
77248 snd_leave_user(fs);
77249 } else {
77250 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
77251 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
77252 }
77253 if (ret == -EPIPE) {
77254 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
77255 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
77256 struct snd_pcm_plugin_channel *channels;
77257 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
77258 if (!in_kernel) {
77259 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
77260 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
77261 return -EFAULT;
77262 buf = runtime->oss.buffer;
77263 }
77264 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
77265 }
77266 } else {
77267 tmp = snd_pcm_oss_write2(substream,
77268 - (const char __force *)buf,
77269 + (const char __force_kernel *)buf,
77270 runtime->oss.period_bytes, 0);
77271 if (tmp <= 0)
77272 goto err;
77273 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
77274 struct snd_pcm_runtime *runtime = substream->runtime;
77275 snd_pcm_sframes_t frames, frames1;
77276 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
77277 - char __user *final_dst = (char __force __user *)buf;
77278 + char __user *final_dst = (char __force_user *)buf;
77279 if (runtime->oss.plugin_first) {
77280 struct snd_pcm_plugin_channel *channels;
77281 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
77282 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
77283 xfer += tmp;
77284 runtime->oss.buffer_used -= tmp;
77285 } else {
77286 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
77287 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
77288 runtime->oss.period_bytes, 0);
77289 if (tmp <= 0)
77290 goto err;
77291 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
77292 size1);
77293 size1 /= runtime->channels; /* frames */
77294 fs = snd_enter_user();
77295 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
77296 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
77297 snd_leave_user(fs);
77298 }
77299 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
77300 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
77301 index 91cdf94..4085161 100644
77302 --- a/sound/core/pcm_compat.c
77303 +++ b/sound/core/pcm_compat.c
77304 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
77305 int err;
77306
77307 fs = snd_enter_user();
77308 - err = snd_pcm_delay(substream, &delay);
77309 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
77310 snd_leave_user(fs);
77311 if (err < 0)
77312 return err;
77313 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
77314 index 25ed9fe..24c46e9 100644
77315 --- a/sound/core/pcm_native.c
77316 +++ b/sound/core/pcm_native.c
77317 @@ -2765,11 +2765,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
77318 switch (substream->stream) {
77319 case SNDRV_PCM_STREAM_PLAYBACK:
77320 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
77321 - (void __user *)arg);
77322 + (void __force_user *)arg);
77323 break;
77324 case SNDRV_PCM_STREAM_CAPTURE:
77325 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
77326 - (void __user *)arg);
77327 + (void __force_user *)arg);
77328 break;
77329 default:
77330 result = -EINVAL;
77331 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
77332 index 5cf8d65..912a79c 100644
77333 --- a/sound/core/seq/seq_device.c
77334 +++ b/sound/core/seq/seq_device.c
77335 @@ -64,7 +64,7 @@ struct ops_list {
77336 int argsize; /* argument size */
77337
77338 /* operators */
77339 - struct snd_seq_dev_ops ops;
77340 + struct snd_seq_dev_ops *ops;
77341
77342 /* registred devices */
77343 struct list_head dev_list; /* list of devices */
77344 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
77345
77346 mutex_lock(&ops->reg_mutex);
77347 /* copy driver operators */
77348 - ops->ops = *entry;
77349 + ops->ops = entry;
77350 ops->driver |= DRIVER_LOADED;
77351 ops->argsize = argsize;
77352
77353 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
77354 dev->name, ops->id, ops->argsize, dev->argsize);
77355 return -EINVAL;
77356 }
77357 - if (ops->ops.init_device(dev) >= 0) {
77358 + if (ops->ops->init_device(dev) >= 0) {
77359 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
77360 ops->num_init_devices++;
77361 } else {
77362 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
77363 dev->name, ops->id, ops->argsize, dev->argsize);
77364 return -EINVAL;
77365 }
77366 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
77367 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
77368 dev->status = SNDRV_SEQ_DEVICE_FREE;
77369 dev->driver_data = NULL;
77370 ops->num_init_devices--;
77371 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
77372 index f24bf9a..1f7b67c 100644
77373 --- a/sound/drivers/mts64.c
77374 +++ b/sound/drivers/mts64.c
77375 @@ -29,6 +29,7 @@
77376 #include <sound/initval.h>
77377 #include <sound/rawmidi.h>
77378 #include <sound/control.h>
77379 +#include <asm/local.h>
77380
77381 #define CARD_NAME "Miditerminal 4140"
77382 #define DRIVER_NAME "MTS64"
77383 @@ -67,7 +68,7 @@ struct mts64 {
77384 struct pardevice *pardev;
77385 int pardev_claimed;
77386
77387 - int open_count;
77388 + local_t open_count;
77389 int current_midi_output_port;
77390 int current_midi_input_port;
77391 u8 mode[MTS64_NUM_INPUT_PORTS];
77392 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
77393 {
77394 struct mts64 *mts = substream->rmidi->private_data;
77395
77396 - if (mts->open_count == 0) {
77397 + if (local_read(&mts->open_count) == 0) {
77398 /* We don't need a spinlock here, because this is just called
77399 if the device has not been opened before.
77400 So there aren't any IRQs from the device */
77401 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
77402
77403 msleep(50);
77404 }
77405 - ++(mts->open_count);
77406 + local_inc(&mts->open_count);
77407
77408 return 0;
77409 }
77410 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
77411 struct mts64 *mts = substream->rmidi->private_data;
77412 unsigned long flags;
77413
77414 - --(mts->open_count);
77415 - if (mts->open_count == 0) {
77416 + if (local_dec_return(&mts->open_count) == 0) {
77417 /* We need the spinlock_irqsave here because we can still
77418 have IRQs at this point */
77419 spin_lock_irqsave(&mts->lock, flags);
77420 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
77421
77422 msleep(500);
77423
77424 - } else if (mts->open_count < 0)
77425 - mts->open_count = 0;
77426 + } else if (local_read(&mts->open_count) < 0)
77427 + local_set(&mts->open_count, 0);
77428
77429 return 0;
77430 }
77431 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
77432 index b953fb4..1999c01 100644
77433 --- a/sound/drivers/opl4/opl4_lib.c
77434 +++ b/sound/drivers/opl4/opl4_lib.c
77435 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
77436 MODULE_DESCRIPTION("OPL4 driver");
77437 MODULE_LICENSE("GPL");
77438
77439 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
77440 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
77441 {
77442 int timeout = 10;
77443 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
77444 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
77445 index f664823..590c745 100644
77446 --- a/sound/drivers/portman2x4.c
77447 +++ b/sound/drivers/portman2x4.c
77448 @@ -48,6 +48,7 @@
77449 #include <sound/initval.h>
77450 #include <sound/rawmidi.h>
77451 #include <sound/control.h>
77452 +#include <asm/local.h>
77453
77454 #define CARD_NAME "Portman 2x4"
77455 #define DRIVER_NAME "portman"
77456 @@ -85,7 +86,7 @@ struct portman {
77457 struct pardevice *pardev;
77458 int pardev_claimed;
77459
77460 - int open_count;
77461 + local_t open_count;
77462 int mode[PORTMAN_NUM_INPUT_PORTS];
77463 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
77464 };
77465 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
77466 index 87657dd..a8268d4 100644
77467 --- a/sound/firewire/amdtp.c
77468 +++ b/sound/firewire/amdtp.c
77469 @@ -371,7 +371,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
77470 ptr = s->pcm_buffer_pointer + data_blocks;
77471 if (ptr >= pcm->runtime->buffer_size)
77472 ptr -= pcm->runtime->buffer_size;
77473 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
77474 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
77475
77476 s->pcm_period_pointer += data_blocks;
77477 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
77478 @@ -511,7 +511,7 @@ EXPORT_SYMBOL(amdtp_out_stream_start);
77479 */
77480 void amdtp_out_stream_update(struct amdtp_out_stream *s)
77481 {
77482 - ACCESS_ONCE(s->source_node_id_field) =
77483 + ACCESS_ONCE_RW(s->source_node_id_field) =
77484 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
77485 }
77486 EXPORT_SYMBOL(amdtp_out_stream_update);
77487 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
77488 index 537a9cb..8e8c8e9 100644
77489 --- a/sound/firewire/amdtp.h
77490 +++ b/sound/firewire/amdtp.h
77491 @@ -146,7 +146,7 @@ static inline void amdtp_out_stream_pcm_prepare(struct amdtp_out_stream *s)
77492 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
77493 struct snd_pcm_substream *pcm)
77494 {
77495 - ACCESS_ONCE(s->pcm) = pcm;
77496 + ACCESS_ONCE_RW(s->pcm) = pcm;
77497 }
77498
77499 /**
77500 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
77501 index cd094ec..eca1277 100644
77502 --- a/sound/firewire/isight.c
77503 +++ b/sound/firewire/isight.c
77504 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
77505 ptr += count;
77506 if (ptr >= runtime->buffer_size)
77507 ptr -= runtime->buffer_size;
77508 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
77509 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
77510
77511 isight->period_counter += count;
77512 if (isight->period_counter >= runtime->period_size) {
77513 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
77514 if (err < 0)
77515 return err;
77516
77517 - ACCESS_ONCE(isight->pcm_active) = true;
77518 + ACCESS_ONCE_RW(isight->pcm_active) = true;
77519
77520 return 0;
77521 }
77522 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
77523 {
77524 struct isight *isight = substream->private_data;
77525
77526 - ACCESS_ONCE(isight->pcm_active) = false;
77527 + ACCESS_ONCE_RW(isight->pcm_active) = false;
77528
77529 mutex_lock(&isight->mutex);
77530 isight_stop_streaming(isight);
77531 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
77532
77533 switch (cmd) {
77534 case SNDRV_PCM_TRIGGER_START:
77535 - ACCESS_ONCE(isight->pcm_running) = true;
77536 + ACCESS_ONCE_RW(isight->pcm_running) = true;
77537 break;
77538 case SNDRV_PCM_TRIGGER_STOP:
77539 - ACCESS_ONCE(isight->pcm_running) = false;
77540 + ACCESS_ONCE_RW(isight->pcm_running) = false;
77541 break;
77542 default:
77543 return -EINVAL;
77544 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
77545 index c94578d..0794ac1 100644
77546 --- a/sound/isa/cmi8330.c
77547 +++ b/sound/isa/cmi8330.c
77548 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
77549
77550 struct snd_pcm *pcm;
77551 struct snd_cmi8330_stream {
77552 - struct snd_pcm_ops ops;
77553 + snd_pcm_ops_no_const ops;
77554 snd_pcm_open_callback_t open;
77555 void *private_data; /* sb or wss */
77556 } streams[2];
77557 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
77558 index 733b014..56ce96f 100644
77559 --- a/sound/oss/sb_audio.c
77560 +++ b/sound/oss/sb_audio.c
77561 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
77562 buf16 = (signed short *)(localbuf + localoffs);
77563 while (c)
77564 {
77565 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
77566 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
77567 if (copy_from_user(lbuf8,
77568 userbuf+useroffs + p,
77569 locallen))
77570 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
77571 index 09d4648..cf234c7 100644
77572 --- a/sound/oss/swarm_cs4297a.c
77573 +++ b/sound/oss/swarm_cs4297a.c
77574 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
77575 {
77576 struct cs4297a_state *s;
77577 u32 pwr, id;
77578 - mm_segment_t fs;
77579 int rval;
77580 #ifndef CONFIG_BCM_CS4297A_CSWARM
77581 u64 cfg;
77582 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
77583 if (!rval) {
77584 char *sb1250_duart_present;
77585
77586 +#if 0
77587 + mm_segment_t fs;
77588 fs = get_fs();
77589 set_fs(KERNEL_DS);
77590 -#if 0
77591 val = SOUND_MASK_LINE;
77592 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
77593 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
77594 val = initvol[i].vol;
77595 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
77596 }
77597 + set_fs(fs);
77598 // cs4297a_write_ac97(s, 0x18, 0x0808);
77599 #else
77600 // cs4297a_write_ac97(s, 0x5e, 0x180);
77601 cs4297a_write_ac97(s, 0x02, 0x0808);
77602 cs4297a_write_ac97(s, 0x18, 0x0808);
77603 #endif
77604 - set_fs(fs);
77605
77606 list_add(&s->list, &cs4297a_devs);
77607
77608 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
77609 index 5644711..a2aebc1 100644
77610 --- a/sound/pci/hda/hda_codec.h
77611 +++ b/sound/pci/hda/hda_codec.h
77612 @@ -611,7 +611,7 @@ struct hda_bus_ops {
77613 /* notify power-up/down from codec to controller */
77614 void (*pm_notify)(struct hda_bus *bus);
77615 #endif
77616 -};
77617 +} __no_const;
77618
77619 /* template to pass to the bus constructor */
77620 struct hda_bus_template {
77621 @@ -713,6 +713,7 @@ struct hda_codec_ops {
77622 #endif
77623 void (*reboot_notify)(struct hda_codec *codec);
77624 };
77625 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
77626
77627 /* record for amp information cache */
77628 struct hda_cache_head {
77629 @@ -743,7 +744,7 @@ struct hda_pcm_ops {
77630 struct snd_pcm_substream *substream);
77631 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
77632 struct snd_pcm_substream *substream);
77633 -};
77634 +} __no_const;
77635
77636 /* PCM information for each substream */
77637 struct hda_pcm_stream {
77638 @@ -801,7 +802,7 @@ struct hda_codec {
77639 const char *modelname; /* model name for preset */
77640
77641 /* set by patch */
77642 - struct hda_codec_ops patch_ops;
77643 + hda_codec_ops_no_const patch_ops;
77644
77645 /* PCM to create, set by patch_ops.build_pcms callback */
77646 unsigned int num_pcms;
77647 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
77648 index 0da778a..bc38b84 100644
77649 --- a/sound/pci/ice1712/ice1712.h
77650 +++ b/sound/pci/ice1712/ice1712.h
77651 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
77652 unsigned int mask_flags; /* total mask bits */
77653 struct snd_akm4xxx_ops {
77654 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
77655 - } ops;
77656 + } __no_const ops;
77657 };
77658
77659 struct snd_ice1712_spdif {
77660 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
77661 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77662 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77663 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
77664 - } ops;
77665 + } __no_const ops;
77666 };
77667
77668
77669 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
77670 index 03ee4e3..be86b46 100644
77671 --- a/sound/pci/ymfpci/ymfpci_main.c
77672 +++ b/sound/pci/ymfpci/ymfpci_main.c
77673 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
77674 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
77675 break;
77676 }
77677 - if (atomic_read(&chip->interrupt_sleep_count)) {
77678 - atomic_set(&chip->interrupt_sleep_count, 0);
77679 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
77680 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77681 wake_up(&chip->interrupt_sleep);
77682 }
77683 __end:
77684 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
77685 continue;
77686 init_waitqueue_entry(&wait, current);
77687 add_wait_queue(&chip->interrupt_sleep, &wait);
77688 - atomic_inc(&chip->interrupt_sleep_count);
77689 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
77690 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
77691 remove_wait_queue(&chip->interrupt_sleep, &wait);
77692 }
77693 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
77694 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
77695 spin_unlock(&chip->reg_lock);
77696
77697 - if (atomic_read(&chip->interrupt_sleep_count)) {
77698 - atomic_set(&chip->interrupt_sleep_count, 0);
77699 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
77700 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77701 wake_up(&chip->interrupt_sleep);
77702 }
77703 }
77704 @@ -2382,7 +2382,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
77705 spin_lock_init(&chip->reg_lock);
77706 spin_lock_init(&chip->voice_lock);
77707 init_waitqueue_head(&chip->interrupt_sleep);
77708 - atomic_set(&chip->interrupt_sleep_count, 0);
77709 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
77710 chip->card = card;
77711 chip->pci = pci;
77712 chip->irq = -1;
77713 diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c
77714 index ee15337..e2187a6 100644
77715 --- a/sound/soc/soc-pcm.c
77716 +++ b/sound/soc/soc-pcm.c
77717 @@ -583,7 +583,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
77718 }
77719
77720 /* ASoC PCM operations */
77721 -static struct snd_pcm_ops soc_pcm_ops = {
77722 +static snd_pcm_ops_no_const soc_pcm_ops = {
77723 .open = soc_pcm_open,
77724 .close = soc_pcm_close,
77725 .hw_params = soc_pcm_hw_params,
77726 diff --git a/sound/usb/card.h b/sound/usb/card.h
77727 index a39edcc..1014050 100644
77728 --- a/sound/usb/card.h
77729 +++ b/sound/usb/card.h
77730 @@ -44,6 +44,7 @@ struct snd_urb_ops {
77731 int (*prepare_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
77732 int (*retire_sync)(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime, struct urb *u);
77733 };
77734 +typedef struct snd_urb_ops __no_const snd_urb_ops_no_const;
77735
77736 struct snd_usb_substream {
77737 struct snd_usb_stream *stream;
77738 @@ -93,7 +94,7 @@ struct snd_usb_substream {
77739 struct snd_pcm_hw_constraint_list rate_list; /* limited rates */
77740 spinlock_t lock;
77741
77742 - struct snd_urb_ops ops; /* callbacks (must be filled at init) */
77743 + snd_urb_ops_no_const ops; /* callbacks (must be filled at init) */
77744 int last_frame_number; /* stored frame number */
77745 int last_delay; /* stored delay */
77746 };
77747 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
77748 new file mode 100644
77749 index 0000000..b044b80
77750 --- /dev/null
77751 +++ b/tools/gcc/Makefile
77752 @@ -0,0 +1,21 @@
77753 +#CC := gcc
77754 +#PLUGIN_SOURCE_FILES := pax_plugin.c
77755 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
77756 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
77757 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W
77758 +
77759 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include
77760 +
77761 +hostlibs-y := constify_plugin.so
77762 +hostlibs-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
77763 +hostlibs-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
77764 +hostlibs-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
77765 +hostlibs-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
77766 +
77767 +always := $(hostlibs-y)
77768 +
77769 +constify_plugin-objs := constify_plugin.o
77770 +stackleak_plugin-objs := stackleak_plugin.o
77771 +kallocstat_plugin-objs := kallocstat_plugin.o
77772 +kernexec_plugin-objs := kernexec_plugin.o
77773 +checker_plugin-objs := checker_plugin.o
77774 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
77775 new file mode 100644
77776 index 0000000..d41b5af
77777 --- /dev/null
77778 +++ b/tools/gcc/checker_plugin.c
77779 @@ -0,0 +1,171 @@
77780 +/*
77781 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
77782 + * Licensed under the GPL v2
77783 + *
77784 + * Note: the choice of the license means that the compilation process is
77785 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
77786 + * but for the kernel it doesn't matter since it doesn't link against
77787 + * any of the gcc libraries
77788 + *
77789 + * gcc plugin to implement various sparse (source code checker) features
77790 + *
77791 + * TODO:
77792 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
77793 + *
77794 + * BUGS:
77795 + * - none known
77796 + */
77797 +#include "gcc-plugin.h"
77798 +#include "config.h"
77799 +#include "system.h"
77800 +#include "coretypes.h"
77801 +#include "tree.h"
77802 +#include "tree-pass.h"
77803 +#include "flags.h"
77804 +#include "intl.h"
77805 +#include "toplev.h"
77806 +#include "plugin.h"
77807 +//#include "expr.h" where are you...
77808 +#include "diagnostic.h"
77809 +#include "plugin-version.h"
77810 +#include "tm.h"
77811 +#include "function.h"
77812 +#include "basic-block.h"
77813 +#include "gimple.h"
77814 +#include "rtl.h"
77815 +#include "emit-rtl.h"
77816 +#include "tree-flow.h"
77817 +#include "target.h"
77818 +
77819 +extern void c_register_addr_space (const char *str, addr_space_t as);
77820 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
77821 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
77822 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
77823 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
77824 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
77825 +
77826 +extern void print_gimple_stmt(FILE *, gimple, int, int);
77827 +extern rtx emit_move_insn(rtx x, rtx y);
77828 +
77829 +int plugin_is_GPL_compatible;
77830 +
77831 +static struct plugin_info checker_plugin_info = {
77832 + .version = "201111150100",
77833 +};
77834 +
77835 +#define ADDR_SPACE_KERNEL 0
77836 +#define ADDR_SPACE_FORCE_KERNEL 1
77837 +#define ADDR_SPACE_USER 2
77838 +#define ADDR_SPACE_FORCE_USER 3
77839 +#define ADDR_SPACE_IOMEM 0
77840 +#define ADDR_SPACE_FORCE_IOMEM 0
77841 +#define ADDR_SPACE_PERCPU 0
77842 +#define ADDR_SPACE_FORCE_PERCPU 0
77843 +#define ADDR_SPACE_RCU 0
77844 +#define ADDR_SPACE_FORCE_RCU 0
77845 +
77846 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
77847 +{
77848 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
77849 +}
77850 +
77851 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
77852 +{
77853 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
77854 +}
77855 +
77856 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
77857 +{
77858 + return default_addr_space_valid_pointer_mode(mode, as);
77859 +}
77860 +
77861 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
77862 +{
77863 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
77864 +}
77865 +
77866 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
77867 +{
77868 + return default_addr_space_legitimize_address(x, oldx, mode, as);
77869 +}
77870 +
77871 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
77872 +{
77873 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
77874 + return true;
77875 +
77876 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
77877 + return true;
77878 +
77879 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
77880 + return true;
77881 +
77882 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
77883 + return true;
77884 +
77885 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
77886 + return true;
77887 +
77888 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
77889 + return true;
77890 +
77891 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
77892 + return true;
77893 +
77894 + return subset == superset;
77895 +}
77896 +
77897 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
77898 +{
77899 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
77900 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
77901 +
77902 + return op;
77903 +}
77904 +
77905 +static void register_checker_address_spaces(void *event_data, void *data)
77906 +{
77907 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
77908 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
77909 + c_register_addr_space("__user", ADDR_SPACE_USER);
77910 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
77911 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
77912 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
77913 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
77914 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
77915 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
77916 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
77917 +
77918 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
77919 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
77920 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
77921 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
77922 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
77923 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
77924 + targetm.addr_space.convert = checker_addr_space_convert;
77925 +}
77926 +
77927 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
77928 +{
77929 + const char * const plugin_name = plugin_info->base_name;
77930 + const int argc = plugin_info->argc;
77931 + const struct plugin_argument * const argv = plugin_info->argv;
77932 + int i;
77933 +
77934 + if (!plugin_default_version_check(version, &gcc_version)) {
77935 + error(G_("incompatible gcc/plugin versions"));
77936 + return 1;
77937 + }
77938 +
77939 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
77940 +
77941 + for (i = 0; i < argc; ++i)
77942 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
77943 +
77944 + if (TARGET_64BIT == 0)
77945 + return 0;
77946 +
77947 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
77948 +
77949 + return 0;
77950 +}
77951 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
77952 new file mode 100644
77953 index 0000000..704a564
77954 --- /dev/null
77955 +++ b/tools/gcc/constify_plugin.c
77956 @@ -0,0 +1,303 @@
77957 +/*
77958 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
77959 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
77960 + * Licensed under the GPL v2, or (at your option) v3
77961 + *
77962 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
77963 + *
77964 + * Homepage:
77965 + * http://www.grsecurity.net/~ephox/const_plugin/
77966 + *
77967 + * Usage:
77968 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
77969 + * $ gcc -fplugin=constify_plugin.so test.c -O2
77970 + */
77971 +
77972 +#include "gcc-plugin.h"
77973 +#include "config.h"
77974 +#include "system.h"
77975 +#include "coretypes.h"
77976 +#include "tree.h"
77977 +#include "tree-pass.h"
77978 +#include "flags.h"
77979 +#include "intl.h"
77980 +#include "toplev.h"
77981 +#include "plugin.h"
77982 +#include "diagnostic.h"
77983 +#include "plugin-version.h"
77984 +#include "tm.h"
77985 +#include "function.h"
77986 +#include "basic-block.h"
77987 +#include "gimple.h"
77988 +#include "rtl.h"
77989 +#include "emit-rtl.h"
77990 +#include "tree-flow.h"
77991 +
77992 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
77993 +
77994 +int plugin_is_GPL_compatible;
77995 +
77996 +static struct plugin_info const_plugin_info = {
77997 + .version = "201111150100",
77998 + .help = "no-constify\tturn off constification\n",
77999 +};
78000 +
78001 +static void constify_type(tree type);
78002 +static bool walk_struct(tree node);
78003 +
78004 +static tree deconstify_type(tree old_type)
78005 +{
78006 + tree new_type, field;
78007 +
78008 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
78009 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
78010 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
78011 + DECL_FIELD_CONTEXT(field) = new_type;
78012 + TYPE_READONLY(new_type) = 0;
78013 + C_TYPE_FIELDS_READONLY(new_type) = 0;
78014 + return new_type;
78015 +}
78016 +
78017 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
78018 +{
78019 + tree type;
78020 +
78021 + *no_add_attrs = true;
78022 + if (TREE_CODE(*node) == FUNCTION_DECL) {
78023 + error("%qE attribute does not apply to functions", name);
78024 + return NULL_TREE;
78025 + }
78026 +
78027 + if (TREE_CODE(*node) == VAR_DECL) {
78028 + error("%qE attribute does not apply to variables", name);
78029 + return NULL_TREE;
78030 + }
78031 +
78032 + if (TYPE_P(*node)) {
78033 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
78034 + *no_add_attrs = false;
78035 + else
78036 + error("%qE attribute applies to struct and union types only", name);
78037 + return NULL_TREE;
78038 + }
78039 +
78040 + type = TREE_TYPE(*node);
78041 +
78042 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
78043 + error("%qE attribute applies to struct and union types only", name);
78044 + return NULL_TREE;
78045 + }
78046 +
78047 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
78048 + error("%qE attribute is already applied to the type", name);
78049 + return NULL_TREE;
78050 + }
78051 +
78052 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
78053 + error("%qE attribute used on type that is not constified", name);
78054 + return NULL_TREE;
78055 + }
78056 +
78057 + if (TREE_CODE(*node) == TYPE_DECL) {
78058 + TREE_TYPE(*node) = deconstify_type(type);
78059 + TREE_READONLY(*node) = 0;
78060 + return NULL_TREE;
78061 + }
78062 +
78063 + return NULL_TREE;
78064 +}
78065 +
78066 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
78067 +{
78068 + *no_add_attrs = true;
78069 + if (!TYPE_P(*node)) {
78070 + error("%qE attribute applies to types only", name);
78071 + return NULL_TREE;
78072 + }
78073 +
78074 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
78075 + error("%qE attribute applies to struct and union types only", name);
78076 + return NULL_TREE;
78077 + }
78078 +
78079 + *no_add_attrs = false;
78080 + constify_type(*node);
78081 + return NULL_TREE;
78082 +}
78083 +
78084 +static struct attribute_spec no_const_attr = {
78085 + .name = "no_const",
78086 + .min_length = 0,
78087 + .max_length = 0,
78088 + .decl_required = false,
78089 + .type_required = false,
78090 + .function_type_required = false,
78091 + .handler = handle_no_const_attribute,
78092 +#if BUILDING_GCC_VERSION >= 4007
78093 + .affects_type_identity = true
78094 +#endif
78095 +};
78096 +
78097 +static struct attribute_spec do_const_attr = {
78098 + .name = "do_const",
78099 + .min_length = 0,
78100 + .max_length = 0,
78101 + .decl_required = false,
78102 + .type_required = false,
78103 + .function_type_required = false,
78104 + .handler = handle_do_const_attribute,
78105 +#if BUILDING_GCC_VERSION >= 4007
78106 + .affects_type_identity = true
78107 +#endif
78108 +};
78109 +
78110 +static void register_attributes(void *event_data, void *data)
78111 +{
78112 + register_attribute(&no_const_attr);
78113 + register_attribute(&do_const_attr);
78114 +}
78115 +
78116 +static void constify_type(tree type)
78117 +{
78118 + TYPE_READONLY(type) = 1;
78119 + C_TYPE_FIELDS_READONLY(type) = 1;
78120 +}
78121 +
78122 +static bool is_fptr(tree field)
78123 +{
78124 + tree ptr = TREE_TYPE(field);
78125 +
78126 + if (TREE_CODE(ptr) != POINTER_TYPE)
78127 + return false;
78128 +
78129 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
78130 +}
78131 +
78132 +static bool walk_struct(tree node)
78133 +{
78134 + tree field;
78135 +
78136 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node)))
78137 + return false;
78138 +
78139 + if (TYPE_FIELDS(node) == NULL_TREE)
78140 + return false;
78141 +
78142 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
78143 + tree type = TREE_TYPE(field);
78144 + enum tree_code code = TREE_CODE(type);
78145 + if (code == RECORD_TYPE || code == UNION_TYPE) {
78146 + if (!(walk_struct(type)))
78147 + return false;
78148 + } else if (!is_fptr(field) && !TREE_READONLY(field))
78149 + return false;
78150 + }
78151 + return true;
78152 +}
78153 +
78154 +static void finish_type(void *event_data, void *data)
78155 +{
78156 + tree type = (tree)event_data;
78157 +
78158 + if (type == NULL_TREE)
78159 + return;
78160 +
78161 + if (TYPE_READONLY(type))
78162 + return;
78163 +
78164 + if (walk_struct(type))
78165 + constify_type(type);
78166 +}
78167 +
78168 +static unsigned int check_local_variables(void);
78169 +
78170 +struct gimple_opt_pass pass_local_variable = {
78171 + {
78172 + .type = GIMPLE_PASS,
78173 + .name = "check_local_variables",
78174 + .gate = NULL,
78175 + .execute = check_local_variables,
78176 + .sub = NULL,
78177 + .next = NULL,
78178 + .static_pass_number = 0,
78179 + .tv_id = TV_NONE,
78180 + .properties_required = 0,
78181 + .properties_provided = 0,
78182 + .properties_destroyed = 0,
78183 + .todo_flags_start = 0,
78184 + .todo_flags_finish = 0
78185 + }
78186 +};
78187 +
78188 +static unsigned int check_local_variables(void)
78189 +{
78190 + tree var;
78191 + referenced_var_iterator rvi;
78192 +
78193 +#if BUILDING_GCC_VERSION == 4005
78194 + FOR_EACH_REFERENCED_VAR(var, rvi) {
78195 +#else
78196 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
78197 +#endif
78198 + tree type = TREE_TYPE(var);
78199 +
78200 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
78201 + continue;
78202 +
78203 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
78204 + continue;
78205 +
78206 + if (!TYPE_READONLY(type))
78207 + continue;
78208 +
78209 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
78210 +// continue;
78211 +
78212 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
78213 +// continue;
78214 +
78215 + if (walk_struct(type)) {
78216 + error("constified variable %qE cannot be local", var);
78217 + return 1;
78218 + }
78219 + }
78220 + return 0;
78221 +}
78222 +
78223 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78224 +{
78225 + const char * const plugin_name = plugin_info->base_name;
78226 + const int argc = plugin_info->argc;
78227 + const struct plugin_argument * const argv = plugin_info->argv;
78228 + int i;
78229 + bool constify = true;
78230 +
78231 + struct register_pass_info local_variable_pass_info = {
78232 + .pass = &pass_local_variable.pass,
78233 + .reference_pass_name = "*referenced_vars",
78234 + .ref_pass_instance_number = 0,
78235 + .pos_op = PASS_POS_INSERT_AFTER
78236 + };
78237 +
78238 + if (!plugin_default_version_check(version, &gcc_version)) {
78239 + error(G_("incompatible gcc/plugin versions"));
78240 + return 1;
78241 + }
78242 +
78243 + for (i = 0; i < argc; ++i) {
78244 + if (!(strcmp(argv[i].key, "no-constify"))) {
78245 + constify = false;
78246 + continue;
78247 + }
78248 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78249 + }
78250 +
78251 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
78252 + if (constify) {
78253 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
78254 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
78255 + }
78256 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
78257 +
78258 + return 0;
78259 +}
78260 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
78261 new file mode 100644
78262 index 0000000..a5eabce
78263 --- /dev/null
78264 +++ b/tools/gcc/kallocstat_plugin.c
78265 @@ -0,0 +1,167 @@
78266 +/*
78267 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78268 + * Licensed under the GPL v2
78269 + *
78270 + * Note: the choice of the license means that the compilation process is
78271 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78272 + * but for the kernel it doesn't matter since it doesn't link against
78273 + * any of the gcc libraries
78274 + *
78275 + * gcc plugin to find the distribution of k*alloc sizes
78276 + *
78277 + * TODO:
78278 + *
78279 + * BUGS:
78280 + * - none known
78281 + */
78282 +#include "gcc-plugin.h"
78283 +#include "config.h"
78284 +#include "system.h"
78285 +#include "coretypes.h"
78286 +#include "tree.h"
78287 +#include "tree-pass.h"
78288 +#include "flags.h"
78289 +#include "intl.h"
78290 +#include "toplev.h"
78291 +#include "plugin.h"
78292 +//#include "expr.h" where are you...
78293 +#include "diagnostic.h"
78294 +#include "plugin-version.h"
78295 +#include "tm.h"
78296 +#include "function.h"
78297 +#include "basic-block.h"
78298 +#include "gimple.h"
78299 +#include "rtl.h"
78300 +#include "emit-rtl.h"
78301 +
78302 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78303 +
78304 +int plugin_is_GPL_compatible;
78305 +
78306 +static const char * const kalloc_functions[] = {
78307 + "__kmalloc",
78308 + "kmalloc",
78309 + "kmalloc_large",
78310 + "kmalloc_node",
78311 + "kmalloc_order",
78312 + "kmalloc_order_trace",
78313 + "kmalloc_slab",
78314 + "kzalloc",
78315 + "kzalloc_node",
78316 +};
78317 +
78318 +static struct plugin_info kallocstat_plugin_info = {
78319 + .version = "201111150100",
78320 +};
78321 +
78322 +static unsigned int execute_kallocstat(void);
78323 +
78324 +static struct gimple_opt_pass kallocstat_pass = {
78325 + .pass = {
78326 + .type = GIMPLE_PASS,
78327 + .name = "kallocstat",
78328 + .gate = NULL,
78329 + .execute = execute_kallocstat,
78330 + .sub = NULL,
78331 + .next = NULL,
78332 + .static_pass_number = 0,
78333 + .tv_id = TV_NONE,
78334 + .properties_required = 0,
78335 + .properties_provided = 0,
78336 + .properties_destroyed = 0,
78337 + .todo_flags_start = 0,
78338 + .todo_flags_finish = 0
78339 + }
78340 +};
78341 +
78342 +static bool is_kalloc(const char *fnname)
78343 +{
78344 + size_t i;
78345 +
78346 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
78347 + if (!strcmp(fnname, kalloc_functions[i]))
78348 + return true;
78349 + return false;
78350 +}
78351 +
78352 +static unsigned int execute_kallocstat(void)
78353 +{
78354 + basic_block bb;
78355 +
78356 + // 1. loop through BBs and GIMPLE statements
78357 + FOR_EACH_BB(bb) {
78358 + gimple_stmt_iterator gsi;
78359 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78360 + // gimple match:
78361 + tree fndecl, size;
78362 + gimple call_stmt;
78363 + const char *fnname;
78364 +
78365 + // is it a call
78366 + call_stmt = gsi_stmt(gsi);
78367 + if (!is_gimple_call(call_stmt))
78368 + continue;
78369 + fndecl = gimple_call_fndecl(call_stmt);
78370 + if (fndecl == NULL_TREE)
78371 + continue;
78372 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
78373 + continue;
78374 +
78375 + // is it a call to k*alloc
78376 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
78377 + if (!is_kalloc(fnname))
78378 + continue;
78379 +
78380 + // is the size arg the result of a simple const assignment
78381 + size = gimple_call_arg(call_stmt, 0);
78382 + while (true) {
78383 + gimple def_stmt;
78384 + expanded_location xloc;
78385 + size_t size_val;
78386 +
78387 + if (TREE_CODE(size) != SSA_NAME)
78388 + break;
78389 + def_stmt = SSA_NAME_DEF_STMT(size);
78390 + if (!def_stmt || !is_gimple_assign(def_stmt))
78391 + break;
78392 + if (gimple_num_ops(def_stmt) != 2)
78393 + break;
78394 + size = gimple_assign_rhs1(def_stmt);
78395 + if (!TREE_CONSTANT(size))
78396 + continue;
78397 + xloc = expand_location(gimple_location(def_stmt));
78398 + if (!xloc.file)
78399 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
78400 + size_val = TREE_INT_CST_LOW(size);
78401 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
78402 + break;
78403 + }
78404 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
78405 +//debug_tree(gimple_call_fn(call_stmt));
78406 +//print_node(stderr, "pax", fndecl, 4);
78407 + }
78408 + }
78409 +
78410 + return 0;
78411 +}
78412 +
78413 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78414 +{
78415 + const char * const plugin_name = plugin_info->base_name;
78416 + struct register_pass_info kallocstat_pass_info = {
78417 + .pass = &kallocstat_pass.pass,
78418 + .reference_pass_name = "ssa",
78419 + .ref_pass_instance_number = 0,
78420 + .pos_op = PASS_POS_INSERT_AFTER
78421 + };
78422 +
78423 + if (!plugin_default_version_check(version, &gcc_version)) {
78424 + error(G_("incompatible gcc/plugin versions"));
78425 + return 1;
78426 + }
78427 +
78428 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
78429 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
78430 +
78431 + return 0;
78432 +}
78433 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
78434 new file mode 100644
78435 index 0000000..008f159
78436 --- /dev/null
78437 +++ b/tools/gcc/kernexec_plugin.c
78438 @@ -0,0 +1,427 @@
78439 +/*
78440 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78441 + * Licensed under the GPL v2
78442 + *
78443 + * Note: the choice of the license means that the compilation process is
78444 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78445 + * but for the kernel it doesn't matter since it doesn't link against
78446 + * any of the gcc libraries
78447 + *
78448 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
78449 + *
78450 + * TODO:
78451 + *
78452 + * BUGS:
78453 + * - none known
78454 + */
78455 +#include "gcc-plugin.h"
78456 +#include "config.h"
78457 +#include "system.h"
78458 +#include "coretypes.h"
78459 +#include "tree.h"
78460 +#include "tree-pass.h"
78461 +#include "flags.h"
78462 +#include "intl.h"
78463 +#include "toplev.h"
78464 +#include "plugin.h"
78465 +//#include "expr.h" where are you...
78466 +#include "diagnostic.h"
78467 +#include "plugin-version.h"
78468 +#include "tm.h"
78469 +#include "function.h"
78470 +#include "basic-block.h"
78471 +#include "gimple.h"
78472 +#include "rtl.h"
78473 +#include "emit-rtl.h"
78474 +#include "tree-flow.h"
78475 +
78476 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78477 +extern rtx emit_move_insn(rtx x, rtx y);
78478 +
78479 +int plugin_is_GPL_compatible;
78480 +
78481 +static struct plugin_info kernexec_plugin_info = {
78482 + .version = "201111291120",
78483 + .help = "method=[bts|or]\tinstrumentation method\n"
78484 +};
78485 +
78486 +static unsigned int execute_kernexec_reload(void);
78487 +static unsigned int execute_kernexec_fptr(void);
78488 +static unsigned int execute_kernexec_retaddr(void);
78489 +static bool kernexec_cmodel_check(void);
78490 +
78491 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
78492 +static void (*kernexec_instrument_retaddr)(rtx);
78493 +
78494 +static struct gimple_opt_pass kernexec_reload_pass = {
78495 + .pass = {
78496 + .type = GIMPLE_PASS,
78497 + .name = "kernexec_reload",
78498 + .gate = kernexec_cmodel_check,
78499 + .execute = execute_kernexec_reload,
78500 + .sub = NULL,
78501 + .next = NULL,
78502 + .static_pass_number = 0,
78503 + .tv_id = TV_NONE,
78504 + .properties_required = 0,
78505 + .properties_provided = 0,
78506 + .properties_destroyed = 0,
78507 + .todo_flags_start = 0,
78508 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
78509 + }
78510 +};
78511 +
78512 +static struct gimple_opt_pass kernexec_fptr_pass = {
78513 + .pass = {
78514 + .type = GIMPLE_PASS,
78515 + .name = "kernexec_fptr",
78516 + .gate = kernexec_cmodel_check,
78517 + .execute = execute_kernexec_fptr,
78518 + .sub = NULL,
78519 + .next = NULL,
78520 + .static_pass_number = 0,
78521 + .tv_id = TV_NONE,
78522 + .properties_required = 0,
78523 + .properties_provided = 0,
78524 + .properties_destroyed = 0,
78525 + .todo_flags_start = 0,
78526 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
78527 + }
78528 +};
78529 +
78530 +static struct rtl_opt_pass kernexec_retaddr_pass = {
78531 + .pass = {
78532 + .type = RTL_PASS,
78533 + .name = "kernexec_retaddr",
78534 + .gate = kernexec_cmodel_check,
78535 + .execute = execute_kernexec_retaddr,
78536 + .sub = NULL,
78537 + .next = NULL,
78538 + .static_pass_number = 0,
78539 + .tv_id = TV_NONE,
78540 + .properties_required = 0,
78541 + .properties_provided = 0,
78542 + .properties_destroyed = 0,
78543 + .todo_flags_start = 0,
78544 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
78545 + }
78546 +};
78547 +
78548 +static bool kernexec_cmodel_check(void)
78549 +{
78550 + tree section;
78551 +
78552 + if (ix86_cmodel != CM_KERNEL)
78553 + return false;
78554 +
78555 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
78556 + if (!section || !TREE_VALUE(section))
78557 + return true;
78558 +
78559 + section = TREE_VALUE(TREE_VALUE(section));
78560 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
78561 + return true;
78562 +
78563 + return false;
78564 +}
78565 +
78566 +/*
78567 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
78568 + */
78569 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
78570 +{
78571 + gimple asm_movabs_stmt;
78572 +
78573 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
78574 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
78575 + gimple_asm_set_volatile(asm_movabs_stmt, true);
78576 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
78577 + update_stmt(asm_movabs_stmt);
78578 +}
78579 +
78580 +/*
78581 + * find all asm() stmts that clobber r10 and add a reload of r10
78582 + */
78583 +static unsigned int execute_kernexec_reload(void)
78584 +{
78585 + basic_block bb;
78586 +
78587 + // 1. loop through BBs and GIMPLE statements
78588 + FOR_EACH_BB(bb) {
78589 + gimple_stmt_iterator gsi;
78590 +
78591 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78592 + // gimple match: __asm__ ("" : : : "r10");
78593 + gimple asm_stmt;
78594 + size_t nclobbers;
78595 +
78596 + // is it an asm ...
78597 + asm_stmt = gsi_stmt(gsi);
78598 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
78599 + continue;
78600 +
78601 + // ... clobbering r10
78602 + nclobbers = gimple_asm_nclobbers(asm_stmt);
78603 + while (nclobbers--) {
78604 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
78605 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
78606 + continue;
78607 + kernexec_reload_fptr_mask(&gsi);
78608 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
78609 + break;
78610 + }
78611 + }
78612 + }
78613 +
78614 + return 0;
78615 +}
78616 +
78617 +/*
78618 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
78619 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
78620 + */
78621 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
78622 +{
78623 + gimple assign_intptr, assign_new_fptr, call_stmt;
78624 + tree intptr, old_fptr, new_fptr, kernexec_mask;
78625 +
78626 + call_stmt = gsi_stmt(*gsi);
78627 + old_fptr = gimple_call_fn(call_stmt);
78628 +
78629 + // create temporary unsigned long variable used for bitops and cast fptr to it
78630 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
78631 + add_referenced_var(intptr);
78632 + mark_sym_for_renaming(intptr);
78633 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
78634 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
78635 + update_stmt(assign_intptr);
78636 +
78637 + // apply logical or to temporary unsigned long and bitmask
78638 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
78639 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
78640 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
78641 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
78642 + update_stmt(assign_intptr);
78643 +
78644 + // cast temporary unsigned long back to a temporary fptr variable
78645 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec");
78646 + add_referenced_var(new_fptr);
78647 + mark_sym_for_renaming(new_fptr);
78648 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
78649 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
78650 + update_stmt(assign_new_fptr);
78651 +
78652 + // replace call stmt fn with the new fptr
78653 + gimple_call_set_fn(call_stmt, new_fptr);
78654 + update_stmt(call_stmt);
78655 +}
78656 +
78657 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
78658 +{
78659 + gimple asm_or_stmt, call_stmt;
78660 + tree old_fptr, new_fptr, input, output;
78661 + VEC(tree, gc) *inputs = NULL;
78662 + VEC(tree, gc) *outputs = NULL;
78663 +
78664 + call_stmt = gsi_stmt(*gsi);
78665 + old_fptr = gimple_call_fn(call_stmt);
78666 +
78667 + // create temporary fptr variable
78668 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
78669 + add_referenced_var(new_fptr);
78670 + mark_sym_for_renaming(new_fptr);
78671 +
78672 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
78673 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
78674 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
78675 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
78676 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
78677 + VEC_safe_push(tree, gc, inputs, input);
78678 + VEC_safe_push(tree, gc, outputs, output);
78679 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
78680 + gimple_asm_set_volatile(asm_or_stmt, true);
78681 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
78682 + update_stmt(asm_or_stmt);
78683 +
78684 + // replace call stmt fn with the new fptr
78685 + gimple_call_set_fn(call_stmt, new_fptr);
78686 + update_stmt(call_stmt);
78687 +}
78688 +
78689 +/*
78690 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
78691 + */
78692 +static unsigned int execute_kernexec_fptr(void)
78693 +{
78694 + basic_block bb;
78695 +
78696 + // 1. loop through BBs and GIMPLE statements
78697 + FOR_EACH_BB(bb) {
78698 + gimple_stmt_iterator gsi;
78699 +
78700 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
78701 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
78702 + tree fn;
78703 + gimple call_stmt;
78704 +
78705 + // is it a call ...
78706 + call_stmt = gsi_stmt(gsi);
78707 + if (!is_gimple_call(call_stmt))
78708 + continue;
78709 + fn = gimple_call_fn(call_stmt);
78710 + if (TREE_CODE(fn) == ADDR_EXPR)
78711 + continue;
78712 + if (TREE_CODE(fn) != SSA_NAME)
78713 + gcc_unreachable();
78714 +
78715 + // ... through a function pointer
78716 + fn = SSA_NAME_VAR(fn);
78717 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
78718 + continue;
78719 + fn = TREE_TYPE(fn);
78720 + if (TREE_CODE(fn) != POINTER_TYPE)
78721 + continue;
78722 + fn = TREE_TYPE(fn);
78723 + if (TREE_CODE(fn) != FUNCTION_TYPE)
78724 + continue;
78725 +
78726 + kernexec_instrument_fptr(&gsi);
78727 +
78728 +//debug_tree(gimple_call_fn(call_stmt));
78729 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
78730 + }
78731 + }
78732 +
78733 + return 0;
78734 +}
78735 +
78736 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
78737 +static void kernexec_instrument_retaddr_bts(rtx insn)
78738 +{
78739 + rtx btsq;
78740 + rtvec argvec, constraintvec, labelvec;
78741 + int line;
78742 +
78743 + // create asm volatile("btsq $63,(%%rsp)":::)
78744 + argvec = rtvec_alloc(0);
78745 + constraintvec = rtvec_alloc(0);
78746 + labelvec = rtvec_alloc(0);
78747 + line = expand_location(RTL_LOCATION(insn)).line;
78748 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
78749 + MEM_VOLATILE_P(btsq) = 1;
78750 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
78751 + emit_insn_before(btsq, insn);
78752 +}
78753 +
78754 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
78755 +static void kernexec_instrument_retaddr_or(rtx insn)
78756 +{
78757 + rtx orq;
78758 + rtvec argvec, constraintvec, labelvec;
78759 + int line;
78760 +
78761 + // create asm volatile("orq %%r10,(%%rsp)":::)
78762 + argvec = rtvec_alloc(0);
78763 + constraintvec = rtvec_alloc(0);
78764 + labelvec = rtvec_alloc(0);
78765 + line = expand_location(RTL_LOCATION(insn)).line;
78766 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
78767 + MEM_VOLATILE_P(orq) = 1;
78768 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
78769 + emit_insn_before(orq, insn);
78770 +}
78771 +
78772 +/*
78773 + * find all asm level function returns and forcibly set the highest bit of the return address
78774 + */
78775 +static unsigned int execute_kernexec_retaddr(void)
78776 +{
78777 + rtx insn;
78778 +
78779 + // 1. find function returns
78780 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
78781 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
78782 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
78783 + rtx body;
78784 +
78785 + // is it a retn
78786 + if (!JUMP_P(insn))
78787 + continue;
78788 + body = PATTERN(insn);
78789 + if (GET_CODE(body) == PARALLEL)
78790 + body = XVECEXP(body, 0, 0);
78791 + if (GET_CODE(body) != RETURN)
78792 + continue;
78793 + kernexec_instrument_retaddr(insn);
78794 + }
78795 +
78796 +// print_simple_rtl(stderr, get_insns());
78797 +// print_rtl(stderr, get_insns());
78798 +
78799 + return 0;
78800 +}
78801 +
78802 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
78803 +{
78804 + const char * const plugin_name = plugin_info->base_name;
78805 + const int argc = plugin_info->argc;
78806 + const struct plugin_argument * const argv = plugin_info->argv;
78807 + int i;
78808 + struct register_pass_info kernexec_reload_pass_info = {
78809 + .pass = &kernexec_reload_pass.pass,
78810 + .reference_pass_name = "ssa",
78811 + .ref_pass_instance_number = 0,
78812 + .pos_op = PASS_POS_INSERT_AFTER
78813 + };
78814 + struct register_pass_info kernexec_fptr_pass_info = {
78815 + .pass = &kernexec_fptr_pass.pass,
78816 + .reference_pass_name = "ssa",
78817 + .ref_pass_instance_number = 0,
78818 + .pos_op = PASS_POS_INSERT_AFTER
78819 + };
78820 + struct register_pass_info kernexec_retaddr_pass_info = {
78821 + .pass = &kernexec_retaddr_pass.pass,
78822 + .reference_pass_name = "pro_and_epilogue",
78823 + .ref_pass_instance_number = 0,
78824 + .pos_op = PASS_POS_INSERT_AFTER
78825 + };
78826 +
78827 + if (!plugin_default_version_check(version, &gcc_version)) {
78828 + error(G_("incompatible gcc/plugin versions"));
78829 + return 1;
78830 + }
78831 +
78832 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
78833 +
78834 + if (TARGET_64BIT == 0)
78835 + return 0;
78836 +
78837 + for (i = 0; i < argc; ++i) {
78838 + if (!strcmp(argv[i].key, "method")) {
78839 + if (!argv[i].value) {
78840 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78841 + continue;
78842 + }
78843 + if (!strcmp(argv[i].value, "bts")) {
78844 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
78845 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
78846 + } else if (!strcmp(argv[i].value, "or")) {
78847 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
78848 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
78849 + fix_register("r10", 1, 1);
78850 + } else
78851 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
78852 + continue;
78853 + }
78854 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
78855 + }
78856 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
78857 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
78858 +
78859 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
78860 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
78861 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
78862 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
78863 +
78864 + return 0;
78865 +}
78866 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
78867 new file mode 100644
78868 index 0000000..8b61031
78869 --- /dev/null
78870 +++ b/tools/gcc/stackleak_plugin.c
78871 @@ -0,0 +1,295 @@
78872 +/*
78873 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
78874 + * Licensed under the GPL v2
78875 + *
78876 + * Note: the choice of the license means that the compilation process is
78877 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
78878 + * but for the kernel it doesn't matter since it doesn't link against
78879 + * any of the gcc libraries
78880 + *
78881 + * gcc plugin to help implement various PaX features
78882 + *
78883 + * - track lowest stack pointer
78884 + *
78885 + * TODO:
78886 + * - initialize all local variables
78887 + *
78888 + * BUGS:
78889 + * - none known
78890 + */
78891 +#include "gcc-plugin.h"
78892 +#include "config.h"
78893 +#include "system.h"
78894 +#include "coretypes.h"
78895 +#include "tree.h"
78896 +#include "tree-pass.h"
78897 +#include "flags.h"
78898 +#include "intl.h"
78899 +#include "toplev.h"
78900 +#include "plugin.h"
78901 +//#include "expr.h" where are you...
78902 +#include "diagnostic.h"
78903 +#include "plugin-version.h"
78904 +#include "tm.h"
78905 +#include "function.h"
78906 +#include "basic-block.h"
78907 +#include "gimple.h"
78908 +#include "rtl.h"
78909 +#include "emit-rtl.h"
78910 +
78911 +extern void print_gimple_stmt(FILE *, gimple, int, int);
78912 +
78913 +int plugin_is_GPL_compatible;
78914 +
78915 +static int track_frame_size = -1;
78916 +static const char track_function[] = "pax_track_stack";
78917 +static const char check_function[] = "pax_check_alloca";
78918 +static bool init_locals;
78919 +
78920 +static struct plugin_info stackleak_plugin_info = {
78921 + .version = "201111150100",
78922 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
78923 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
78924 +};
78925 +
78926 +static bool gate_stackleak_track_stack(void);
78927 +static unsigned int execute_stackleak_tree_instrument(void);
78928 +static unsigned int execute_stackleak_final(void);
78929 +
78930 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
78931 + .pass = {
78932 + .type = GIMPLE_PASS,
78933 + .name = "stackleak_tree_instrument",
78934 + .gate = gate_stackleak_track_stack,
78935 + .execute = execute_stackleak_tree_instrument,
78936 + .sub = NULL,
78937 + .next = NULL,
78938 + .static_pass_number = 0,
78939 + .tv_id = TV_NONE,
78940 + .properties_required = PROP_gimple_leh | PROP_cfg,
78941 + .properties_provided = 0,
78942 + .properties_destroyed = 0,
78943 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
78944 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
78945 + }
78946 +};
78947 +
78948 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
78949 + .pass = {
78950 + .type = RTL_PASS,
78951 + .name = "stackleak_final",
78952 + .gate = gate_stackleak_track_stack,
78953 + .execute = execute_stackleak_final,
78954 + .sub = NULL,
78955 + .next = NULL,
78956 + .static_pass_number = 0,
78957 + .tv_id = TV_NONE,
78958 + .properties_required = 0,
78959 + .properties_provided = 0,
78960 + .properties_destroyed = 0,
78961 + .todo_flags_start = 0,
78962 + .todo_flags_finish = TODO_dump_func
78963 + }
78964 +};
78965 +
78966 +static bool gate_stackleak_track_stack(void)
78967 +{
78968 + return track_frame_size >= 0;
78969 +}
78970 +
78971 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
78972 +{
78973 + gimple check_alloca;
78974 + tree fndecl, fntype, alloca_size;
78975 +
78976 + // insert call to void pax_check_alloca(unsigned long size)
78977 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
78978 + fndecl = build_fn_decl(check_function, fntype);
78979 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
78980 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
78981 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
78982 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
78983 +}
78984 +
78985 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
78986 +{
78987 + gimple track_stack;
78988 + tree fndecl, fntype;
78989 +
78990 + // insert call to void pax_track_stack(void)
78991 + fntype = build_function_type_list(void_type_node, NULL_TREE);
78992 + fndecl = build_fn_decl(track_function, fntype);
78993 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
78994 + track_stack = gimple_build_call(fndecl, 0);
78995 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
78996 +}
78997 +
78998 +#if BUILDING_GCC_VERSION == 4005
78999 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
79000 +{
79001 + tree fndecl;
79002 +
79003 + if (!is_gimple_call(stmt))
79004 + return false;
79005 + fndecl = gimple_call_fndecl(stmt);
79006 + if (!fndecl)
79007 + return false;
79008 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
79009 + return false;
79010 +// print_node(stderr, "pax", fndecl, 4);
79011 + return DECL_FUNCTION_CODE(fndecl) == code;
79012 +}
79013 +#endif
79014 +
79015 +static bool is_alloca(gimple stmt)
79016 +{
79017 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
79018 + return true;
79019 +
79020 +#if BUILDING_GCC_VERSION >= 4007
79021 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
79022 + return true;
79023 +#endif
79024 +
79025 + return false;
79026 +}
79027 +
79028 +static unsigned int execute_stackleak_tree_instrument(void)
79029 +{
79030 + basic_block bb, entry_bb;
79031 + bool prologue_instrumented = false;
79032 +
79033 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
79034 +
79035 + // 1. loop through BBs and GIMPLE statements
79036 + FOR_EACH_BB(bb) {
79037 + gimple_stmt_iterator gsi;
79038 +
79039 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
79040 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
79041 + if (!is_alloca(gsi_stmt(gsi)))
79042 + continue;
79043 +
79044 + // 2. insert stack overflow check before each __builtin_alloca call
79045 + stackleak_check_alloca(&gsi);
79046 +
79047 + // 3. insert track call after each __builtin_alloca call
79048 + stackleak_add_instrumentation(&gsi);
79049 + if (bb == entry_bb)
79050 + prologue_instrumented = true;
79051 + }
79052 + }
79053 +
79054 + // 4. insert track call at the beginning
79055 + if (!prologue_instrumented) {
79056 + gimple_stmt_iterator gsi;
79057 +
79058 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
79059 + if (dom_info_available_p(CDI_DOMINATORS))
79060 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
79061 + gsi = gsi_start_bb(bb);
79062 + stackleak_add_instrumentation(&gsi);
79063 + }
79064 +
79065 + return 0;
79066 +}
79067 +
79068 +static unsigned int execute_stackleak_final(void)
79069 +{
79070 + rtx insn;
79071 +
79072 + if (cfun->calls_alloca)
79073 + return 0;
79074 +
79075 + // keep calls only if function frame is big enough
79076 + if (get_frame_size() >= track_frame_size)
79077 + return 0;
79078 +
79079 + // 1. find pax_track_stack calls
79080 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
79081 + // 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))
79082 + rtx body;
79083 +
79084 + if (!CALL_P(insn))
79085 + continue;
79086 + body = PATTERN(insn);
79087 + if (GET_CODE(body) != CALL)
79088 + continue;
79089 + body = XEXP(body, 0);
79090 + if (GET_CODE(body) != MEM)
79091 + continue;
79092 + body = XEXP(body, 0);
79093 + if (GET_CODE(body) != SYMBOL_REF)
79094 + continue;
79095 + if (strcmp(XSTR(body, 0), track_function))
79096 + continue;
79097 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
79098 + // 2. delete call
79099 + insn = delete_insn_and_edges(insn);
79100 +#if BUILDING_GCC_VERSION >= 4007
79101 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
79102 + insn = delete_insn_and_edges(insn);
79103 +#endif
79104 + }
79105 +
79106 +// print_simple_rtl(stderr, get_insns());
79107 +// print_rtl(stderr, get_insns());
79108 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
79109 +
79110 + return 0;
79111 +}
79112 +
79113 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
79114 +{
79115 + const char * const plugin_name = plugin_info->base_name;
79116 + const int argc = plugin_info->argc;
79117 + const struct plugin_argument * const argv = plugin_info->argv;
79118 + int i;
79119 + struct register_pass_info stackleak_tree_instrument_pass_info = {
79120 + .pass = &stackleak_tree_instrument_pass.pass,
79121 +// .reference_pass_name = "tree_profile",
79122 + .reference_pass_name = "optimized",
79123 + .ref_pass_instance_number = 0,
79124 + .pos_op = PASS_POS_INSERT_AFTER
79125 + };
79126 + struct register_pass_info stackleak_final_pass_info = {
79127 + .pass = &stackleak_final_rtl_opt_pass.pass,
79128 + .reference_pass_name = "final",
79129 + .ref_pass_instance_number = 0,
79130 + .pos_op = PASS_POS_INSERT_BEFORE
79131 + };
79132 +
79133 + if (!plugin_default_version_check(version, &gcc_version)) {
79134 + error(G_("incompatible gcc/plugin versions"));
79135 + return 1;
79136 + }
79137 +
79138 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
79139 +
79140 + for (i = 0; i < argc; ++i) {
79141 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
79142 + if (!argv[i].value) {
79143 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79144 + continue;
79145 + }
79146 + track_frame_size = atoi(argv[i].value);
79147 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
79148 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
79149 + continue;
79150 + }
79151 + if (!strcmp(argv[i].key, "initialize-locals")) {
79152 + if (argv[i].value) {
79153 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
79154 + continue;
79155 + }
79156 + init_locals = true;
79157 + continue;
79158 + }
79159 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
79160 + }
79161 +
79162 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
79163 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
79164 +
79165 + return 0;
79166 +}
79167 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
79168 index 6789d78..4afd019 100644
79169 --- a/tools/perf/util/include/asm/alternative-asm.h
79170 +++ b/tools/perf/util/include/asm/alternative-asm.h
79171 @@ -5,4 +5,7 @@
79172
79173 #define altinstruction_entry #
79174
79175 + .macro pax_force_retaddr rip=0, reload=0
79176 + .endm
79177 +
79178 #endif
79179 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
79180 index af0f22f..9a7d479 100644
79181 --- a/usr/gen_init_cpio.c
79182 +++ b/usr/gen_init_cpio.c
79183 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
79184 int retval;
79185 int rc = -1;
79186 int namesize;
79187 - int i;
79188 + unsigned int i;
79189
79190 mode |= S_IFREG;
79191
79192 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
79193 *env_var = *expanded = '\0';
79194 strncat(env_var, start + 2, end - start - 2);
79195 strncat(expanded, new_location, start - new_location);
79196 - strncat(expanded, getenv(env_var), PATH_MAX);
79197 - strncat(expanded, end + 1, PATH_MAX);
79198 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
79199 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
79200 strncpy(new_location, expanded, PATH_MAX);
79201 + new_location[PATH_MAX] = 0;
79202 } else
79203 break;
79204 }
79205 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
79206 index d9cfb78..4f27c10 100644
79207 --- a/virt/kvm/kvm_main.c
79208 +++ b/virt/kvm/kvm_main.c
79209 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
79210
79211 static cpumask_var_t cpus_hardware_enabled;
79212 static int kvm_usage_count = 0;
79213 -static atomic_t hardware_enable_failed;
79214 +static atomic_unchecked_t hardware_enable_failed;
79215
79216 struct kmem_cache *kvm_vcpu_cache;
79217 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
79218 @@ -2268,7 +2268,7 @@ static void hardware_enable_nolock(void *junk)
79219
79220 if (r) {
79221 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
79222 - atomic_inc(&hardware_enable_failed);
79223 + atomic_inc_unchecked(&hardware_enable_failed);
79224 printk(KERN_INFO "kvm: enabling virtualization on "
79225 "CPU%d failed\n", cpu);
79226 }
79227 @@ -2322,10 +2322,10 @@ static int hardware_enable_all(void)
79228
79229 kvm_usage_count++;
79230 if (kvm_usage_count == 1) {
79231 - atomic_set(&hardware_enable_failed, 0);
79232 + atomic_set_unchecked(&hardware_enable_failed, 0);
79233 on_each_cpu(hardware_enable_nolock, NULL, 1);
79234
79235 - if (atomic_read(&hardware_enable_failed)) {
79236 + if (atomic_read_unchecked(&hardware_enable_failed)) {
79237 hardware_disable_all_nolock();
79238 r = -EBUSY;
79239 }
79240 @@ -2676,7 +2676,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
79241 kvm_arch_vcpu_put(vcpu);
79242 }
79243
79244 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79245 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79246 struct module *module)
79247 {
79248 int r;
79249 @@ -2739,7 +2739,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79250 if (!vcpu_align)
79251 vcpu_align = __alignof__(struct kvm_vcpu);
79252 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
79253 - 0, NULL);
79254 + SLAB_USERCOPY, NULL);
79255 if (!kvm_vcpu_cache) {
79256 r = -ENOMEM;
79257 goto out_free_3;
79258 @@ -2749,9 +2749,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79259 if (r)
79260 goto out_free;
79261
79262 - kvm_chardev_ops.owner = module;
79263 - kvm_vm_fops.owner = module;
79264 - kvm_vcpu_fops.owner = module;
79265 + pax_open_kernel();
79266 + *(void **)&kvm_chardev_ops.owner = module;
79267 + *(void **)&kvm_vm_fops.owner = module;
79268 + *(void **)&kvm_vcpu_fops.owner = module;
79269 + pax_close_kernel();
79270
79271 r = misc_register(&kvm_dev);
79272 if (r) {